Implicit conversion allowed when "X must be of type T" AI00569/01 1
910926 BI WI
 !standard 03.06.01 (02) 910926 AI00569/01
 !standard 03.07.03 (03)
 !standard 04.01.01 (04)
 !standard 04.01.02 (03)
 !standard 04.03.02 (01)
 !standard 05.02 (01)
 !standard 05.04 (03)
 !standard 09.06 (03)
 !standard 04.06 (15)
 !class binding interpretation 880706 (provisional classification)
 !status workitem 910926
 !status received 880706
 !topic Implicit conversion allowed when "X must be of type T"

 !summary 910926 (DRAFT)

 When the Standard says that an expression "must be of" some type, and the
 elements of the expression can be implicitly converted to the specified type,
 the implicit conversion is allowed.

 !question 910926 (DRAFT)

 3.6.1(2) says:

 For a discrete range used in a constrained array definition ..., an
 implicit conversion to the predefined type INTEGER is assumed ...,
 and the type of both bounds (prior to the implicit conversion) MUST
 BE OF THE SAME DISCRETE TYPE, OTHER THAN universal_integer; ...

 This wording seems to exclude a discrete range of the form 1 .. INTEGER'(10)
 since the two bounds are not both of the same type; the words "other than
 universal_integer" can be read as meaning that each bound must be of a type
 other than universal_integer. Is this rule instead to be understood in
 conjunction with 4.6(15), i.e., if only one bound is of a universal type, is
 implicit conversion allowed?

 !recommendation 910926 (DRAFT)

 Rules stating that an expression "must be" of a certain type are to be
 understood as allowing implicit conversions to the required type. Such rules
 occur in 3.6.1(2), 3.7.3(3), 4.1.1(4), 4.1.2(3), 4.3.2(1), 5.2(1), 5.4(3),
 and 9.6(3).

 !discussion 910926 (DRAFT)

 Although a reader might assume that the words "must be" in 3.6.1(2) override
 the rules that allow an implicit conversion from a universal_integer type,
 this was clearly not intended.

 An examination of the RM shows that the following are the only places where
 implicit conversion is intended to be allowed even though the Standard
requires that an expression "must be" of a certain type.
DRAFT DRAFT DRAFT
Implicit conversion allowed when "X must be of type T" AI00569/01 2
910926 BI WI
 3.7.3(3) says, for variant parts:

 Each variant starts with a list of choices which must be of the same
 type as the discriminant of the variant part.

 4.1.1(4) says, for indexed components:

 Each expression must be of the type of the corresponding index.

 4.1.2(3) says, for slices:

 The bounds of the discrete range define those of the slice and must
 be of the type of the index;

 4.3.2(1) says, for aggregates:

 If the type of an aggregate is a onedimensional array type, then
 each choice must specify values of the index type, and the expression
 of each component association must be of the component type.

 5.2(1) says, for assignment statements:

 The named variable and the righthand side expression must be of the
 same type;

 5.4(3) says, for case statements:

 Each choice in a case statement alternative must be of the same type
 as the expression;

 9.6(3) says, for the delay statement:

 The simple expression must be of the predefined fixed point type DURATION;
!appendix 880216
 *****************************************************************************

 !section 03.06.01 (02) R P Wehrum, Siemens A.G., Muenchen 830602 8300253
 !version 1983
 !topic Index Constraints with mixed bounds

 In section 3.6.1(2) you can read, "For a discrete range used in a
 constrained array definition ..., an implicit conversion to the
 predefined type INTEGER is assumed..., and the type of both bounds (prior
 to the implicit conversion) is the type universal_integer. Otherwise,
 both bounds must be of the same discrete type, other than
 universal_integer; ...". This seems to exclude the possibility of having
 a "mixed" index constraint, i.e. one bound of type universal_integer and
 the other bound of some named integer type. But this is not true:
 implicit conversions have to take place according to the named type (of
DRAFT DRAFT DRAFT
Implicit conversion allowed when "X must be of type T" AI00569/01 3
910926 BI WI
 the other bound).

 This is an example where a semantic concept overrules a syntactical
 concept.

 In my opinion, a reformulation of the above rules is necessary.
*****************************************************************************
!section 04.06 (15) Norman Cohen 880216 8300958
!version 1983
!topic Rules of the form "X must be of type T"
The RM is replete with rules stating that a certain expression "must be"
of a given type. The natural reading of such a rule is that the
programmer must write an expression of the given type, but the intention
in the case of numeric types is generally that 4.6(15) applies, i.e., if
the expression "must be" of some integer/real type then the programmer
may write a universal_integer/universal_real expression instead, and the
words "must be" force an implicit conversion.
In other words, 4.6(15) overrides the plain reading of the words "must
be." Unfortunately, a reader could at least as easily presume that the
words "must be" override the usual rules allowing universal expressions
to appear in places where expressions of some other numeric type are
required.
The operative words in 4.6(15) are:
An implicit conversion of a convertible universal operand is
applied if and only if the innermost complete context (see 8.7)
determines a unique numeric target type for the implicit conversion,
and there is no legal interpretation of this context without this
conversion.
Therefore, in contexts where it is intended to allow implicit conversion,
rules of the form "X must be of type T" should be replaced by rules of
the form "The only legal interpretation of X is as a value of type T."
Example:
3.6.1(2) contains the following rule about the bounds of discrete ranges:
Otherwise [i.e., if at least one bound is not a literal, named
number, or attribute of type universal_integer], both bounds must be
of the same discrete type, other than universal_integer....
This rule has been widely misinterpreted as barring a discrete range of
the form 1 .. Integer'(10) because the two bounds are not both of the
same type; the words "other than universal_integer" can be read as
DRAFT DRAFT DRAFT
Implicit conversion allowed when "X must be of type T" AI00569/01 4
910926 BI WI
meaning that each bound must be of a type other than universal_integer,
i.e., forbidding implicit conversion in this context. The following
wording more clearly expresses the intent:
Otherwise, the bounds must not both be of type universal_integer;
the only legal interpretations of the bounds are as expressions
of the same discrete type.
DRAFT DRAFT DRAFT