Open sttaft opened 5 months ago
This looks like a perfect solution. It disentangles the different categories of types. The entwinement was the prime reason for my confused message on Ada Comment.
with Ada.Text_IO;
use Ada.Text_IO;
with Interfaces;
use Interfaces;
procedure Sequence is
type T0 (D0: Integer_8) is tagged record
K0: Integer_8;
end record;
type T1 is new T0 (D0 => -1) with record
K1: Integer_8;
end record;
procedure P0 is
-- D0 K0
X: T0 := ( 1, -1);
begin
Put_Line ("P0");
Put_Line ("==");
Put_Line (X'Image);
New_Line;
end P0;
procedure P1 is
-- D0 K0 K1
X: T1 := (-1, -2, 8); -- D0 must be -1
begin
Put_Line ("P1");
Put_Line ("==");
Put_Line (X'Image);
New_Line;
end P1;
begin
P0;
P1;
end Sequence;
-----------------------
P0
==
(D0 => 1,
K0 => -1)
P1
==
(K0 => -2,
K1 => 8)
The reference to T'Write is admittedly confusing here. The intent was to avoid having to repeat the special case for Fortran-convention multi-dimensional arrays given in 13.13.2(9/5), and perhaps other parts of the definition of "canonical order," but because of the special case about discriminants, mentioning T'Write just further confuses things. Also, for multi-dimensional arrays, 'Image is expected to produce multiple levels of brackets, which again makes the mention of T'Write confusing. It sounds like we should simply repeat the relevant rules here, rather than trying to piggy-back on the T'Write description. Or perhaps better, separate out the definition of "canonical order" somewhere, and refer to that.
I'm confused. Canonical order should have been defined where positional aggregates are defined, somewhere in RM 4.3.
Currently canonical order for array components is defined in RM 5.5.2(11/5), which is a bit of a weird place for it. In any case, I agree with you that we should move the definition of canonical order of components to some reasonable place, and then refer to that.
For records, isn't this it? 4.3.1(11) For a positional association, the component (including possibly a discriminant) in the corresponding relative position (in the declarative region of the type), counting only the needed components;
For records, isn't this it? 4.3.1(11) For a positional association, the component (including possibly a discriminant) in the corresponding relative position (in the declarative region of the type), counting only the needed components;
Yes, that is the correct order. So we merely need to gather these various bits into a single place and use them to define the phrase "canonical order of components".
I will create an AI for this issue so we can review it at the next ARG meeting.
There are more clients for canonical orders:
I think it does not make sense to collect all those definitions at one place.
This issue was identified by Christoph Grein on 2023-12-22:
Discriminants can be effectively replaced or renamed in a derived type. See for example RM 3.7(34-35):
The current rules for Put_Image do not seem to properly handle this case for untagged derived types.
For tagged type extensions RM 4.10(16/5) specifies:
But for an untagged derived type RM 4.10(7/5) specifies:
This would produce an image for the Square type above displaying Rows and Columns rather than Size for the discriminants. To avoid this, there should be a rule similar to that for tagged type extensions, and in fact is probably most simply handled by simplifying paragraph (7/5) to only apply to elementary types, and updating paragraph (16/5) as follows:
Paragraph (21/5) would also need some minor rewording to cover the new cases when the default image is used for derived composite types.