Index: prj-part.adb
===================================================================
--- prj-part.adb	(revision 206804)
+++ prj-part.adb	(working copy)
@@ -1325,11 +1325,20 @@
                         "cannot extend the same project file several times",
                         Token_Ptr);
                   end if;
-               else
+               elsif not A_Project_Name_And_Node.From_Extended then
                   Error_Msg
                     (Env.Flags,
                      "cannot extend an already imported project file",
                      Token_Ptr);
+
+               else
+                  --  Register this project as being extended
+
+                  A_Project_Name_And_Node.Extended := True;
+                  Tree_Private_Part.Projects_Htable.Set
+                    (In_Tree.Projects_HT,
+                     A_Project_Name_And_Node.Name,
+                     A_Project_Name_And_Node);
                end if;
 
             elsif A_Project_Name_And_Node.Extended then
@@ -1372,6 +1381,16 @@
                      "cannot import an already extended project file",
                      Token_Ptr);
                end if;
+
+            elsif A_Project_Name_And_Node.From_Extended then
+               --  This project is now imported from a non extending project.
+               --  Indicate this in has table Projects.HT.
+
+               A_Project_Name_And_Node.From_Extended := False;
+               Tree_Private_Part.Projects_Htable.Set
+                 (In_Tree.Projects_HT,
+                  A_Project_Name_And_Node.Name,
+                  A_Project_Name_And_Node);
             end if;
 
             Project := A_Project_Name_And_Node.Node;
@@ -1933,6 +1952,7 @@
                   Node           => Project,
                   Canonical_Path => Canonical_Path_Name,
                   Extended       => Extended,
+                  From_Extended  => From_Extended /= None,
                   Proj_Qualifier => Project_Qualifier_Of (Project, In_Tree)));
       end if;
 
Index: prj-tree.adb
===================================================================
--- prj-tree.adb	(revision 206804)
+++ prj-tree.adb	(working copy)
@@ -1321,8 +1321,7 @@
    begin
       pragma Assert
         (Present (Node)
-          and then
-            In_Tree.Project_Nodes.Table (Node).Kind = N_Term);
+          and then In_Tree.Project_Nodes.Table (Node).Kind = N_Term);
       return In_Tree.Project_Nodes.Table (Node).Field2;
    end Next_Term;
 
@@ -1332,18 +1331,17 @@
 
    function Next_Variable
      (Node    : Project_Node_Id;
-      In_Tree : Project_Node_Tree_Ref)
-      return Project_Node_Id
+      In_Tree : Project_Node_Tree_Ref) return Project_Node_Id
    is
    begin
       pragma Assert
         (Present (Node)
           and then
-           (In_Tree.Project_Nodes.Table (Node).Kind =
-              N_Typed_Variable_Declaration
+            (In_Tree.Project_Nodes.Table (Node).Kind =
+                                                  N_Typed_Variable_Declaration
                or else
-            In_Tree.Project_Nodes.Table (Node).Kind =
-              N_Variable_Declaration));
+             In_Tree.Project_Nodes.Table (Node).Kind =
+                                                  N_Variable_Declaration));
 
       return In_Tree.Project_Nodes.Table (Node).Field3;
    end Next_Variable;
@@ -2925,6 +2923,7 @@
                Canonical_Path => No_Path,
                Node           => Project,
                Extended       => False,
+               From_Extended  => False,
                Proj_Qualifier => Qualifier));
       end if;
 
Index: prj-tree.ads
===================================================================
--- prj-tree.ads	(revision 206804)
+++ prj-tree.ads	(working copy)
@@ -1476,6 +1476,10 @@
          Extended : Boolean;
          --  True when the project is being extended by another project
 
+         From_Extended : Boolean;
+         --  True when the project is only imported by projects that are
+         --  extended.
+
          Proj_Qualifier : Project_Qualifier;
          --  The project qualifier of the project, if any
       end record;
@@ -1486,6 +1490,7 @@
          Node           => Empty_Node,
          Canonical_Path => No_Path,
          Extended       => True,
+         From_Extended  => False,
          Proj_Qualifier => Unspecified);
 
       package Projects_Htable is new GNAT.Dynamic_HTables.Simple_HTable
