From mboxrd@z Thu Jan 1 00:00:00 1970
X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on
ip-172-31-65-14.ec2.internal
X-Spam-Level:
X-Spam-Status: No, score=-1.9 required=3.0 tests=BAYES_00,FREEMAIL_FROM,
T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Blady
Newsgroups: comp.lang.ada
Subject: Aggregate with derived types.
Date: Thu, 14 Sep 2023 16:02:39 +0200
Organization: A noiseless patient Spider
Message-ID:
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 14 Sep 2023 14:02:40 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="818daf88bc92539b44f05f222008836b";
logging-data="2790761"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/a/Aq/rWBELm2+ATWxTHQm"
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0)
Gecko/20100101 Thunderbird/102.15.0
Cancel-Lock: sha1:NjdJMto5dPVz6kvxZSNecEQPaYQ=
Content-Language: fr, en-US
Xref: news.eternal-september.org comp.lang.ada:65649
List-Id:
Hello,
I want to extend a container type like Vectors, I've written:
type My_Float_List2 is new My_Float_Lists.Vector with null record;
But the initialization gives an error line 6:
1. with Ada.Containers.Vectors;
2. with Ada.Text_IO;
3. procedure test_20230914_derived_agg is
4. package My_Float_Lists is new Ada.Containers.Vectors
(Positive, Float);
5. subtype My_Float_List1 is My_Float_Lists.Vector;
6. type My_Float_List2 is new My_Float_Lists.Vector with null
record;
7. ML1 : My_Float_List1 := [-3.1, -6.7, 3.3, -3.14, 0.0];
8. ML2 : My_Float_List2 := ([-3.1, -6.7, 3.3, -3.14, 0.0] with
null record);
|
>>> error: no unique type for this aggregate
9. begin
10. Ada.Text_IO.Put_Line (ML1.Element (3)'Image);
11. Ada.Text_IO.Put_Line (ML2.Element (3)'Image);
12. end test_20230914_derived_agg;
The RM says:
4.3.2 Extension Aggregates
1 [An extension_aggregate specifies a value for a type that is a record
extension by specifying a value or subtype for an ancestor of the type,
followed by associations for any components not determined by the
ancestor_part.]
Language Design Principles
1.a The model underlying this syntax is that a record extension can
also be viewed as a regular record type with an ancestor
"prefix".
The record_component_association_list corresponds to
exactly what
would be needed if there were no ancestor/prefix type. The
ancestor_part determines the value of the ancestor/prefix.
Syntax
2 extension_aggregate ::=
(ancestor_part with record_component_association_list)
3 ancestor_part ::= expression | subtype_mark
It is not so clear for me what could a unique type?
Any clue?
Thanks Pascal.