Ada Reference Manual (Ada 2022) — Legal Information

# 4.3.1 Record Aggregates

1
In a record_aggregate, a value is specified for each component of the record or record extension value, using either a named or a positional association.

#### Syntax

2
record_aggregate ::= (record_component_association_list)
3
record_component_association_list ::=
record_component_association {, record_component_association}
| null record
4/2
record_component_association ::=
[component_choice_list =>] expression
| component_choice_list => <>
5/5
component_choice_list ::=
component_selector_name {'|' component_selector_name}
| others
6
A record_component_association is a named component association if it has a component_choice_list; otherwise, it is a positional component association. Any positional component associations shall precede any named component associations. If there is a named association with a component_choice_list of others, it shall come last.
7
In the record_component_association_list for a record_aggregate, if there is only one association, it shall be a named association.

#### Name Resolution Rules

8/2
The expected type for a record_aggregate shall be a single record type or record extension.
9/5
For the record_component_association_list of a record_aggregate, all components of the composite value defined by the aggregate are needed; for the association list of an extension_aggregate, only those components not determined by the ancestor expression or subtype are needed (see 4.3.2). Each component_selector_name in a record_component_association of a record_aggregate or extension_aggregate shall denote a needed component (including possibly a discriminant). Each component_selector_name in a record_component_association of a record_delta_aggregate (see 4.3.4) shall denote a nondiscriminant component of the type of the aggregate.
10
The expected type for the expression of a record_component_association is the type of the associated component(s); the associated component(s) are as follows:
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;
12
For a named association with one or more component_selector_names, the named component(s);
13
For a named association with the reserved word others, all needed components that are not associated with some previous association.

#### Legality Rules

14
If the type of a record_aggregate is a record extension, then it shall be a descendant of a record type, through one or more record extensions (and no private extensions).
15/5
A record_component_association_list shall be null record only if the list occurs in a record_aggregate or extension_aggregate, and there are no components needed for that list.
16/5
For a record_aggregate or extension_aggregate, each record_component_association other than an others choice with a <> shall have at least one associated component, and each needed component shall be associated with exactly one record_component_association. For a record_delta_aggregate, each component_selector_name of each component_choice_list shall denote a distinct nondiscriminant component of the type of the aggregate.
16.1/5
If a record_component_association with an expression has two or more associated components, all of them shall be of the same type, or all of them shall be of anonymous access types whose subtypes statically match. In addition, Legality Rules are enforced separately for each associated component.
17/5
For a record_aggregate or extension_aggregate, if a variant_part P is nested within a variant V that is not selected by the discriminant value governing the variant_part enclosing V, then there is no restriction on the discriminant governing P. Otherwise, the value of the discriminant that governs P shall be given by a static expression, or by a nonstatic expression having a constrained static nominal subtype. In this latter case of a nonstatic expression, there shall be exactly one discrete_choice_list of P that covers each value that belongs to the nominal subtype and satisfies the predicates of the subtype, and there shall be at least one such value.
17.1/2
A record_component_association for a discriminant without a default_expression shall have an expression rather than <>.
17.2/5
A record_component_association of the record_component_association_list of a record_delta_aggregate shall not:
17.3/5
use the box compound delimiter <> rather than an expression;
17.4/5
have an expression of a limited type;
17.5/5
omit the component_choice_list; or
17.6/5
have a component_choice_list that is an others choice.
17.7/5
For a record_delta_aggregate, no two component_selector_names shall denote components declared within different variants of the same variant_part.

#### Dynamic Semantics

18
The evaluation of a record_aggregate consists of the evaluation of the record_component_association_list.
19/5
For the evaluation of a record_component_association_list, any per-object constraints (see 3.8) for components specified in the association list are elaborated and any expressions are evaluated and converted to the subtype of the associated component. Any constraint elaborations and expression evaluations (and conversions) occur in an arbitrary order, except that the expression for a discriminant is evaluated (and converted) prior to the elaboration of any per-object constraint that depends on it, which in turn occurs prior to the evaluation and conversion of the expression for the component with the per-object constraint. If the value of a discriminant that governs a selected variant_part is given by a nonstatic expression, and the evaluation of that expression yields a value that does not belong to the nominal subtype of the expression, then Constraint_Error is raised.
19.1/2
For a record_component_association with an expression, the expression defines the value for the associated component(s). For a record_component_association with <>, if the component_declaration has a default_expression, that default_expression defines the value for the associated component(s); otherwise, the associated component(s) are initialized by default as for a stand-alone object of the component subtype (see 3.3.1).
20
The expression of a record_component_association is evaluated (and converted) once for each associated component.
21/5
NOTE By the rules given above, for a record_aggregate with positional associations, expressions specifying discriminant values appear first and in the same order as their corresponding discriminant_specifications, since the known_discriminant_part occurs first in the declaration of the type.

#### Examples

22
Example of a record aggregate with positional associations:
23
(4, July, 1776) -- see 3.8
24
Examples of record aggregates with named associations:
25
(Day => 4, Month => July, Year => 1776)
(Month => July, Day => 4, Year => 1776)
26
(Disk, Closed, Track => 5, Cylinder => 12) -- see 3.8.1
(Unit => Disk, Status => Closed, Cylinder => 9, Track => 1)
27/2
Examples of component associations with several choices:
28
(Value => 0, Succ|Pred => new Cell'(0, null, null)) -- see 3.10.1
29
-- The allocator is evaluated twice:
-- Succ and Pred designate different cells
29.1/2
(Value => 0, Succ|Pred => <>) -- see 3.10.1
29.2/2
-- Succ and Pred will be set to null
30
Examples of record aggregates for tagged types (see 3.9 and 3.9.1):
31
Expression'(null record)
Literal'(Value => 0.0)
Painted_Point'(0.0, Pi/2.0, Paint => Red)

Ada 2005 and 2012 Editions sponsored in part by Ada-Europe