4.7 Qualified Expressions
This Reference Manual output has not been verified, and may contain omissions or errors. Report any problems on the tracking issue
qualified_expression is used to state explicitly the type, and to verify the subtype, of an operand that is either an
expression or an
Name Resolution Rules3/5
The expected type for the operand (the
aggregate) is determined by the
subtype_mark . Furthermore, the operand shall resolve to be either the specified expected type or a universal type that covers it.
[If the operand of a
qualified_expression denotes an object, the
qualified_expression denotes a constant view of that object.] The nominal subtype of a
qualified_expression is the subtype denoted by the
The evaluation of a
qualified_expression evaluates the operand (and if of a universal type, converts it to the type determined by the
subtype_mark) and checks that its value belongs to the subtype denoted by the
subtype_mark. The exception Constraint_Error is raised if this check fails. Furthermore, if predicate checks are enabled for the subtype denoted by the
subtype_mark, a check is performed as defined in subclause 3.2.4, “Subtype Predicates” that the value satifies the predicates of the subtype.
qualified_expressionwith a constrained target subtype is essentially an assertion about the subtype of the operand, rather than a request for conversion. An explicit
type_conversioncan be used rather than a
qualified_expressionif subtype conversion is desired.
qualified_expressionnever allows something that the equivalent
type_conversionwould not allow.
qualified_expressioncan be used to do so. In particular, if an overloaded
aggregateis passed to an overloaded subprogram, it can be necessary to qualify the operand to resolve its type.
Examples of disambiguating expressions using qualification:
type Mask is (Fix, Dec, Exp, Signif); type Code is (Fix, Cla, Dec, Tnz, Sub); 8Print (Mask'(Dec)); -- Dec is of type Mask Print (Code'(Dec)); -- Dec is of type Code 9/5for J in Code'(Fix) .. Code'(Dec) loop ... -- qualification is necessary for either Fix or Dec for J in Code range Fix .. Dec loop ... -- qualification unnecessary for J in Code'(Fix) .. Dec loop ... -- qualification unnecessary for Dec 10Dozen'(1 | 3 | 5 | 7 => 2, others => 0) -- see 4.6
Wording Changes from Ada 2005
Inconsistencies With Ada 2012
qualified_expressionnow performs a predicate check for the named subtype (if it is enabled). Original Ada 2012 did not include that check (an omission). While this is formally inconsistent (an exception could be raised when none would be raised by original Ada 2012), cases where this scenario arises are likely to be rare (the qualified expression would have to have a stricter subtype than the following usage) and the check is more likely to detect bugs than be unexpected.
Wording Changes from Ada 2012
qualified_expressionhas an expected type. This eliminates an annoying inconsistency in the language definition.