Comments
Patch
===================================================================
@@ -5843,6 +5843,7 @@ package body Sem_Ch3 is
Full_Der := New_Copy (Derived_Type);
Set_Comes_From_Source (Full_Decl, False);
Set_Comes_From_Source (Full_Der, False);
+ Set_Parent (Full_Der, Full_Decl);
Insert_After (N, Full_Decl);
@@ -5916,9 +5917,16 @@ package body Sem_Ch3 is
Set_Defining_Identifier (Full_Decl, Full_Der);
Build_Derived_Record_Type
(Full_Decl, Parent_Type, Full_Der, Derive_Subps);
- Set_Analyzed (Full_Decl);
end if;
+ -- The full declaration has been introduced into the tree and
+ -- processed in the step above. It should not be analyzed again
+ -- (when encountered later in the current list of declarations)
+ -- to prevent spurious name conflicts. The full entity remains
+ -- invisible.
+
+ Set_Analyzed (Full_Decl);
+
if Swapped then
Uninstall_Declarations (Par_Scope);
When deriving an unconstrained private type with discriminants whose full view is tagged, we create a record derivation of its full view, for use by gigi. This internal derivation does not introduce a new visible entity, but only allows the construction of the complete component list. The declaration node must be attached to the tree like any other implicit declaration, but it must not be analyzed like another derived type definition, because it carries an entity with the same name as that of the original derived type. Thus this declaration node must be marked analyzed after completing the construction of its attributes, so that it is not analyzed anew in the course of traversing the remaining declaration in the current list. Before this patch, there were paths on which the Analyzed flag was not set, leading to spurious semantic errors about redeclarations. THe follosing must compile quietly: gcc -c -gnat05 main.adb --- with Ada.Finalization; generic type Item is private; type Item_List is array (Positive range <>) of Item; package Streams is type Stream (Segment_Size: Positive) is private; private type Stream (Segment_Size: Positive) is new Ada.Finalization.Controlled with record Length : Natural := 0; end record; procedure Initialize (Object : in out Stream); procedure Adjust (Object : in out Stream); procedure Finalize (Object : in out Stream); end Streams; --- with Streams; package Pack is type Byte is new Integer range 0 .. 255; for Byte'Size use 8; type Byte_Array is array (Positive range <>) of Byte; package Byte_Streams is new Streams (Byte, Byte_Array); type Byte_Stream is new Byte_Streams.Stream; end Pack; --- with Pack; procedure Main is type Byte_Stream is new Pack.Byte_Stream; X : Byte_Stream (100); begin null; end Main; Tested on x86_64-pc-linux-gnu, committed on trunk 2010-09-10 Ed Schonberg <schonberg@adacore.com> * sem_ch3.adb (Build_Derived_Private_Type): Mark generated declaration of full view analyzed after analyzing the corresponding record declaration, to prevent spurious name conflicts with original declaration.