Next: Aggregates
Up: Expressions
Previous: Bound Methods
For uniquely indicating the type of an aggregate of a value type or the
value of a primary it may be prefixed with the type in a coercion.
Coercing a value v of type T to type T' is legal if any of the
following holds:
- T is a subtype of T'.
- T and T' are simple value types that both (transitively)
inherit the same predefined simple value type; T' must be
monomorphic.
- T is a numeric type (including UNIVERSAL_INT and
UNIVERSAL_REAL), and T' is a monomorphic numeric type.
- T is UNIVERSAL_BITS and T' is a numeric type, BYTE,
CHAR, ROW[n](S), ARR[*](S), ARRAY[*](S) or a
subtype of S, where S is again one of those types. The value is
zero-extended on the left to the actual size of T'. Otherwise the value is only reinterpreted. When coercing to an
ARR or ARRAY type, the size of the array is determined from the given
value.
- v can be coerced to some type S and the resulting value can
be coerced to T'.
In general, a coercion is only reinterpreting the given value in the
sense of its type. A value of a numeric type, including the universal
numeric types is coerced to another numeric type by converting integer
values to floating point values and adapting the length if necessary.
Rounding from floating point numbers to lower precision or to integers
must always be specified by explicit operations.
The resulting expression has exactly the type of the coercion. Hence,
in overloading resolution no further conformance is
checked.
A coercion is automatically inferred in the following cases:
- The value of an assignment's right hand side is coerced to the
type of the designator.
- The same rule applies during transmission of in-, once-, inout- and
out-parameters.
- A value of one of the universal types is automatically coerced as
described below.
Applied occurrences of overloaded identifiers are resolved as follows:
- If the applied occurrence is accompanied by arguments then the
number, types and kinds of the arguments are used for determining
the set of applicable feature definitions. If the feature belongs to
a class C specified by a generic parameter T and T
was declared with a typebound T < D then only the features in D
are considered.
- If multiple features are applicable, then numeric arguments
including universal types are coerced to the
first type in the schemes
, and
that can represent the value and
for which an applicable feature exists. - An overloaded feature may not have private as
well as non-private variants.
The program is illegal if
- after coercion, the resulting set of possible dynamic types is
empty or contains more than one type, or if
- after overloding
resolution the resulting set of applicable features is empty or contains
more than one feature.
Next: Aggregates
Up: Expressions
Previous: Bound Methods
Martin Trapp
Mon Feb 17 16:49:16 MET 1997