4.9.1 Statically Matching Constraints and Subtypes
Static Semantics
1/2
1.1/2
both are null constraints;
1.2/2
both are static and have
equal corresponding bounds or discriminant values;
1.3/2
1.4/2
2/3
{
AI95-00231-01}
{
AI95-00254-01}
{
AI05-0153-3}
A subtype
statically matches another subtype
of the same type if they have statically matching constraints
,
all predicate specifications that apply
to them come from the same declarations, 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.
2.a
Ramification: Statically matching constraints
and subtypes are the basis for subtype conformance of profiles (see
6.3.1).
2.b/2
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.
3
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.
3.a
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.
4/3
{
AI05-0086-1}
{
AI05-0153-3}
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.
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.
One subtype is statically compatible with
a second subtype if the constraint of the first is statically compatible
with the second subtype.
4.a
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.
4.b
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.
5/3
{
AI05-0153-3}
Two statically matching subtypes
are statically compatible with each other. In addition, a subtype S1
is statically compatible with a subtype S2 if:
6/3
the constraint of S1
is statically compatible with S2, and
7/3
8/3
either:
9/3
all predicate
specifications that apply to S2 apply also to S1, or
10/3
both subtypes
are static, and every value that obeys the predicate of S1 also
obeys the predicate of S2.
Wording Changes from Ada 83
10.a
This subclause is new to Ada 95.
Wording Changes from Ada 95
10.b/2
{
AI95-00231-01}
{
AI95-00254-01}
Added static matching rules for null exclusions
and anonymous access-to-subprogram types; both of these are new.
10.c/2
{
AI95-00311-01}
We clarify that the constraint of the first subtype
of a scalar formal type statically matches itself.
Incompatibilities With Ada 2005
10.d/3
{
AI05-0086-1}
Correction: Updated
the statically compatible rules to take null exclusions into account.
This is technically incompatible, as it could cause a legal Ada 2005
program to be rejected; however, such a program violates the intent of
the rules (for instance, 3.7(15)) and this
probably will simply detect bugs.
Wording Changes from Ada 2005
10.e/3
{
AI05-0153-3}
Modified static matching and static compatibility
to take predicate aspects (see 3.2.4) into
account.
Ada 2005 and 2012 Editions sponsored in part by Ada-Europe