Lady Ada

Ada '83 Language Reference Manual

Copyright 1980, 1982, 1983 owned by the United States Government. Direct reproduction and usage requests to the Ada Information Clearinghouse.

8.7. The Context of Overload Resolution


Overloading is defined for subprograms, enumeration literals, operators, and single entries, and also for the operations that are inherent in several basic operations such as assignment, membership tests, allocators, the literal null, aggregates, and string literals.

For overloaded entities, overload resolution determines the actual meaning that an occurrence of an identifier has, whenever the visibility rules have determined that more than one meaning is acceptable at the place of this occurrence; overload resolution likewise determines the actual meaning of an occurrence of an operator or some basic operation.

At such a place all visible declarations are considered. The occurrence is only legal if there is exactly one interpretation of each constituent of the innermost complete context; a complete context is one of the following:

When considering possible interpretations of a complete context, the only rules considered are the syntax rules, the scope and visibility rules, and the rules of the form described below.

  1. Any rule that requires a name or expression to have a certain type, or to have the same type as another name or expression.

  2. Any rule that requires the type of a name or expression to be a type of a certain class; similarly, any rule that requires a certain type to be a discrete, integer, real, universal, character, boolean, or nonlimited type.

  3. Any rule that requires a prefix to be appropriate for a certain type.

  4. Any rule that specifies a certain type as the result type of a basic operation, and any rule that specifies that this type is of a certain class.

  5. The rules that require the type of an aggregate or string literal to be determinable solely from the enclosing complete context (see 4.3 and 4.2). Similarly, the rules that require the type of the prefix of an attribute, the type of the expression of a case statement, or the type of the operand of a type conversion, to be determinable independently of the context (see 4.1.4, 5.4, 4.6, and 6.4.1).

  6. The rules given in section 6.6, for the resolution of overloaded subprogram calls; in section 4.6, for the implicit conversions of universal expressions; in section 3.6.1, for the interpretation of discrete ranges with bounds having a universal type; and in section 4.1.3, for the interpretation of an expanded name whose prefix denotes a subprogram or an accept statement.
Subprogram names used as pragma arguments follow a different rule: the pragma can apply to several overloaded subprograms, as explained in section 6.3.2 for the pragma INLINE, in section 11.7 for the pragma SUPPRESS, and in section 13.9 for the pragma INTERFACE.

Similarly, the simple names given in context clauses (see 10.1.1) and in address clauses (see 13.5) follow different rules.


If there is only one possible interpretation, the identifier denotes the corresponding entity. However, this does not mean that the occurrence is necessarily legal since other requirements exist which are not considered for overload resolution; for example, the fact that an expression is static, the parameter modes, whether an object is constant, conformance rules, forcing occurrences for a representation clause, order of elaboration, and so on.

Similarly, subtypes are not considered for overload resolution (the violation of a constraint does not make a program illegal but raises an exception during program execution).

A loop parameter specification is a declaration, and hence a complete context.

Rules that require certain constructs to have the same parameter and result type profile fall under the category (a); the same holds for rules that require conformance of two constructs since conformance requires that corresponding names be given the same meaning by the visibility and overloading rules.

References: aggregate, allocator, assignment, basic operation, case statement, class of type, declaration, entry, enumeration literal, exception, expression, formal part, identifier, legal, literal, loop parameter specification, membership test, name, null literal, operation, operator, overloading, pragma, representation clause, statement, static expression, static subtype, subprogram, subtype, type conversion, visibility.

Rules of the form (a): address clause, assignment, choice, and 4.3.2, and 5.4, component association, and 4.3.2, conformance rules, default expression, and 3.7.1, and 6.1, and 12.1.1, delay statement, discrete range, and 5.5, and 9.5, discriminant constraint, enumeration representation clause, generic parameter association, index constraint, index expression, and 4.1.2, and 9.5, initial value, membership test, parameter association, parameter and result type profile, and 12.3.6, qualified expression, range constraint, renaming of an object, result expression.

Rules of the form (b): abort statement 9.10, assignment 5.2, case expression 5.4, condition 5.3 5.5 5.7 9.7.1, discrete range 3.6.1 5.5 9.5, fixed point type declaration 3.5.9, floating point type declaration 3.5.7, integer type declaration 3.5.4, length clause 13.2, membership test 4.4, number declaration 3.2.2, record representation clause 13.4, selected component 4.1.3, short-circuit control form 4.4, val attribute 3.5.5

Rules of the form (c): indexed component 4.1.1, selected component 4.1.3, slice 4.1.2

Rules of the form (d): aggregate 4.3, allocator 4.8, membership test 4.4, null literal 4.2, numeric literal 2.4, short-circuit control form 4.4, string literal 4.2

Rationale references: 11.5 Overload Resolution, 11.5.1 Context of Overload Resolution, 11.5.2 Information Used to Resolve Overloading, 11.5.3 Ambiguity

Style Guide references: 8.2.5 Overloading in Generic Units


[Ada Information Clearinghouse]

Address any questions or comments to