Ptyp := Entity (Pref);
- -- Ada 2020 allows 'Image on private types, so we need to fetch the
- -- underlying type.
+ -- Ada 2020 allows 'Image on private types, so fetch the underlying
+ -- type to obtain the structure of the type. We use the base type,
+ -- not the root type, to handle properly derived types.
- if Ada_Version >= Ada_2020 then
- Rtyp := Underlying_Type (Root_Type (Ptyp));
- else
- Rtyp := Root_Type (Ptyp);
- end if;
+ Rtyp := Underlying_Type (Base_Type (Ptyp));
-- Enable speed-optimized expansion of user-defined enumeration types
-- if we are compiling with optimizations enabled and enumeration type
T : Entity_Id;
begin
-- In Ada 2020 we need the underlying type here, because 'Image is
- -- allowed on private types.
+ -- allowed on private types. We have already checked the version
+ -- when resolving the attribute.
- if Ada_Version >= Ada_2020 then
+ if Is_Private_Type (Ptyp) then
T := Rtyp;
else
T := Ptyp;
declare
Conv : Node_Id;
begin
- if Ada_Version >= Ada_2020
- and then Is_Private_Type (Etype (Expr))
- then
+ if Is_Private_Type (Etype (Expr)) then
if Is_Fixed_Point_Type (Rtyp) then
Conv := Convert_To (Tent, OK_Convert_To (Rtyp, Expr));
else