4.9.1 Statically Matching Constraints and Subtypes
Static Semantics
{
AI95-00311-01}
{statically matching (for constraints)}
A constraint
statically matches another constraint
if:
both are null constraints;
both are static and have equal corresponding bounds
or discriminant values;
{
AI95-00231-01}
{
AI95-00254-01}
{statically matching (for subtypes)}
A subtype
statically matches another subtype
of the same type if they have statically matching constraints, and, for
access subtypes, either both or neither exclude null. Two anonymous access-to-object
subtypes statically match if their designated subtypes statically match,
and either both or neither exclude null, and either both or neither are
access-to-constant. Two anonymous access-to-subprogram subtypes statically
match if their designated profiles are subtype conformant, and either
both or neither exclude null.
Ramification: Statically matching constraints
and subtypes are the basis for subtype conformance of profiles (see
6.3.1).
Reason: Even though anonymous access
types always represent different types, they can statically match. That's
important so that they can be used widely. For instance, if this wasn't
true, access parameters and access discriminants could never conform,
so they couldn't be used in separate specifications.
{statically matching
(for ranges)} Two ranges of the same type
statically match if both result from the same evaluation of a
range, or
if both are static and have equal corresponding bounds.
Ramification: The notion of static matching
of ranges is used in
12.5.3, “
Formal
Array Types”; the index ranges of formal and actual constrained
array subtypes have to statically match.
{statically compatible
(for a constraint and a scalar subtype)} A
constraint is
statically compatible with a scalar subtype if it
statically matches the constraint of the subtype, or if both are static
and the constraint is compatible with the subtype.
{statically
compatible (for a constraint and an access or composite subtype)}
A constraint is
statically compatible with
an access or composite subtype if it statically matches the constraint
of the subtype, or if the subtype is unconstrained.
{statically
compatible (for two subtypes)} One subtype
is
statically compatible with a second subtype if the constraint
of the first is statically compatible with the second subtype.
Discussion: Static compatibility is required
when constraining a parent subtype with a discriminant from a new
discriminant_part.
See
3.7. Static compatibility is also used
in matching generic formal derived types.
Note that statically compatible with a subtype
does not imply compatible with a type. It is OK since the terms are used
in different contexts.
Wording Changes from Ada 83
This subclause is new to Ada 95.
Wording Changes from Ada 95
{
AI95-00231-01}
{
AI95-00254-01}
Added static matching rules for null exclusions and anonymous access-to-subprogram
types; both of these are new in Ada 2005.
{
AI95-00311-01}
We clarify that the constraint of the first subtype of a scalar formal
type statically matches itself.