+2018-04-04 Piotr Trojanek <trojanek@adacore.com>
+
+ * einfo.adb (Has_Discriminants): Stronger assertion.
+ (Set_Has_Discriminants): Stronger assertion.
+ * sem_ch13.adb (Push_Scope_And_Install_Discriminants): Adapt to respect
+ the stronger assertion on Has_Discriminant.
+ (Uninstall_Discriminants_And_Pop_Scope): Same as above.
+ * sem_util.adb (New_Copy_Tree): Same as above.
+ * sem_ch7.adb (Generate_Parent_References): Prevent calls to
+ Has_Discriminant on non-type entities that might happen when the
+ compiled code has errors.
+ * sem_ch3.adb (Derived_Type_Declaration): Only call
+ Set_Has_Discriminant on type entities.
+
2018-04-04 Arnaud Charlet <charlet@adacore.com>
* exp_unst.adb (Unnest_Subprogram): Unnest all subprograms relevant for
function Has_Discriminants (Id : E) return B is
begin
- pragma Assert (Nkind (Id) in N_Entity);
+ pragma Assert (Is_Type (Id));
return Flag5 (Id);
end Has_Discriminants;
procedure Set_Has_Discriminants (Id : E; V : B := True) is
begin
- pragma Assert (Nkind (Id) in N_Entity);
+ pragma Assert (Is_Type (Id));
Set_Flag5 (Id, V);
end Set_Has_Discriminants;
procedure Push_Scope_And_Install_Discriminants (E : Entity_Id) is
begin
- if Has_Discriminants (E) then
+ if Is_Type (E) and then Has_Discriminants (E) then
Push_Scope (E);
-- Make the discriminants visible for type declarations and protected
procedure Uninstall_Discriminants_And_Pop_Scope (E : Entity_Id) is
begin
- if Has_Discriminants (E) then
+ if Is_Type (E) and then Has_Discriminants (E) then
Uninstall_Discriminants (E);
Pop_Scope;
end if;
Error_Msg_N
("elementary or array type cannot have discriminants",
Defining_Identifier (First (Discriminant_Specifications (N))));
- Set_Has_Discriminants (T, False);
+
+ -- Unset Has_Discriminants flag to prevent cascaded errors, but
+ -- only if we are not already processing a malformed syntax tree.
+
+ if Is_Type (T) then
+ Set_Has_Discriminants (T, False);
+ end if;
-- The type is allowed to have discriminants
-- We are looking at an incomplete or private type declaration
-- with a known_discriminant_part whose full view is an
- -- Unchecked_Union.
+ -- Unchecked_Union. The seemingly useless check with Is_Type
+ -- prevents cascaded errors when routines defined only for type
+ -- entities are called with non-type entities.
if Nkind_In (Decl, N_Incomplete_Type_Declaration,
N_Private_Type_Declaration)
+ and then Is_Type (Defining_Identifier (Decl))
and then Has_Discriminants (Defining_Identifier (Decl))
and then Present (Full_View (Defining_Identifier (Decl)))
and then
begin
-- Discriminant_Constraint
- if Has_Discriminants (Base_Type (Id)) then
+ if Is_Type (Id)
+ and then Has_Discriminants (Base_Type (Id))
+ then
Set_Discriminant_Constraint (Id, Elist_Id (
Copy_Field_With_Replacement
(Field => Union_Id (Discriminant_Constraint (Id)),
-- Discriminant_Constraint
- if Has_Discriminants (Base_Type (Id)) then
+ if Is_Type (Id)
+ and then Has_Discriminants (Base_Type (Id))
+ then
Visit_Field
(Field => Union_Id (Discriminant_Constraint (Id)),
Semantic => True);