end if;
-- If the type has a Defaut_Value/Default_Component_Value aspect,
- -- this is where we analye the expression (after the type is frozen,
+ -- this is where we analyze the expression (after the type is frozen,
-- since in the case of Default_Value, we are analyzing with the
-- type itself, and we treat Default_Component_Value similarly for
-- the sake of uniformity).
end if;
-- Ada 2012: If component is scalar with default value, use it
+ -- by converting it to Ctyp, so that subtype constraints are
+ -- checked.
elsif Is_Scalar_Type (Ctyp)
and then Has_Default_Aspect (Ctyp)
then
- Add_Association
- (Component => Component,
- Expr =>
- Default_Aspect_Value
- (First_Subtype (Underlying_Type (Ctyp))),
- Assoc_List => New_Assoc_List);
+ declare
+ Conv : constant Node_Id :=
+ Convert_To
+ (Typ => Ctyp,
+ Expr =>
+ New_Copy_Tree
+ (Default_Aspect_Value
+ (First_Subtype (Underlying_Type (Ctyp)))));
+
+ begin
+ Analyze_And_Resolve (Conv, Ctyp);
+ Add_Association
+ (Component => Component,
+ Expr => Conv,
+ Assoc_List => New_Assoc_List);
+ end;
elsif Has_Non_Null_Base_Init_Proc (Ctyp)
or else not Expander_Active