1

A record type with a variant_part
specifies alternative lists of components. Each variant
defines the components for the value or values of the discriminant covered
by its discrete_choice_list.

1.a

1.b

The definition of “cover” in this
subclause and the rules about discrete choices are designed so that they
are also appropriate for array aggregates and case statements.

1.c

The rules of this subclause intentionally parallel
those for case statements.

2

3

4

5/3

{*AI05-0153-3*}
{*AI05-0158-1*}
discrete_choice ::= choice_expression expression | *discrete_*subtype_indication | range discrete_range | **others**

6

The *discriminant_*direct_name
shall resolve to denote a discriminant (called the *discriminant of
the **variant_part*)
specified in the known_discriminant_part
of the full_type_declaration
that contains the variant_part.
The expected type for each discrete_choice
in a variant
is the type of the discriminant of the variant_part.

6.a

7

The discriminant of the variant_part
shall be of a discrete type.

7.a

8/3

{*AI05-0153-3*}
The choice_expressions,
subtype_indications,
and ranges expressions
and discrete_ranges
given as discrete_choices
in a variant_part
shall be static. The discrete_choice
**others** shall appear alone in a discrete_choice_list,
and such a discrete_choice_list,
if it appears, shall be the last one in the enclosing construct.

9

10/3

{*AI05-0262-1*}
A discrete_choice
that is a choice_expression an
expression
covers a value if the value equals the value of the choice_expression expression
converted to the expected type.

10.1/3

{*AI05-0153-3*}
{*AI05-0262-1*}
A discrete_choice
that is a subtype_indication
covers all values (possibly none) that belong to the subtype and that
satisfy the static predicate of the subtype (see 3.2.4).

10.a/3

11/3

{*AI05-0153-3*}
A discrete_choice
that is a range discrete_range
covers all values (possibly none) that belong to the range.

12

The discrete_choice
**others** covers all values of its expected type that are not covered
by previous discrete_choice_lists
of the same construct.

12.a

13

14

The possible values
of the discriminant of a variant_part
shall be covered as follows:

15/3

{*AI05-0153-3*}
{*AI05-0188-1*}
{*AI05-0262-1*}
If the discriminant is of a static constrained scalar subtype,
then, except within an instance of a generic unit,
each non-**others** discrete_choice
shall cover only values in that subtype that satisfy
its predicate, and each value of that subtype that
satisfies its predicate shall be covered by some discrete_choice
[(either explicitly or by **others**)];

15.a/3

15.b/3

Foo : Float;

15.c/3

16/3

{*AI05-0264-1*}
If the type of the discriminant is a descendant of a generic formal scalar
type, then the variant_part
shall have an **others** discrete_choice;

16.a

17

Otherwise, each value of the base range of the
type of the discriminant shall be covered [(either explicitly or by **others**)].

18

Two distinct discrete_choices
of a variant_part
shall not cover the same value.

19

20

The discriminant
of a variant_part
is said to *govern* the variant_part
and its variants.
In addition, the discriminant of a derived type governs a variant_part
and its variants
if it corresponds (see 3.7) to the discriminant
of the variant_part.

21

A record value contains the values of the components
of a particular variant
only if the value of the discriminant governing the variant
is covered by the discrete_choice_list
of the variant.
This rule applies in turn to any further variant
that is, itself, included in the component_list
of the given variant.

22

The elaboration of a variant_part
consists of the elaboration of the component_list
of each variant
in the order in which they appear.

23

24

25

Status : State;

Line_Count : Integer

Cylinder : Cylinder_Index;

Track : Track_Number;

26

27

28

29

Writer : Peripheral(Unit => Printer);

Archive : Disk_Unit;

Archive : Disk_Unit;

29.a

In Ada 83, the discriminant
of a variant_part
is not allowed to be of a generic formal type. This restriction is removed
in Ada 95; an **others** discrete_choice
is required in this case.

29.b

The syntactic category choice
is removed. The syntax rules for variant,
array_aggregate,
and case_statement
now use discrete_choice_list
or discrete_choice
instead. The syntax rule for record_aggregate
now defines its own syntax for named associations.

29.c

We have added the term Discrete Choice to the
title since this is where they are talked about. This is analogous to
the name of the subclause "Index Constraints and Discrete Ranges"
in the clause on Array Types.

29.d

The rule requiring that the discriminant denote
a discriminant of the type being defined seems to have been left implicit
in RM83.

29.e/3

{*AI05-0158-1*}
Membership tests are no longer
allowed as a discrete_choice,
in order that those tests can be expanded to allow multiple tests in
a single expression without ambiguity. Since a membership test has a
boolean type, they are very unlikely to be used as a discrete_choice.

29.f/3

{*AI05-0153-3*}
Subtypes with static predicates
can be used in discrete_choices,
and the coverage rules are modified to respect the predicates.

29.g/3

{*AI05-0188-1*}
Variants in generic specifications are no longer
rejected if the subtype of the actual type does not include all of the
case choices. This probably isn't useful, but it is consistent with the
treatment of case_expressions.

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