Commit Message

The Ada 2012 RM introduces the notion of an incomplete view of an ancestor
type: in a child unit, a derived type is within the derivation class of an
ancestor declared in a parent unit, even if there is an intermediate derivation
that does not see the full view of that ancestor. This makes some type
conversions legal even if other operations are not available for the type.
Compiling p-child.ads in the following example from RM 7.3.1 (5.2/3), must
yield the following errors and no others:
p-child.ads:8:12: invalid conversion, not compatible with type
universal integer
p-child.ads:9:12: expected type universal integer
p-child.ads:9:12: found private type "T3" defined at line 3
package P is
type T is private;
C: constant T;
private
type T is new Integer;
C: constant T := 42;
end P;
---
with P;
package Q is
type T2 is new P.T;
end Q;
with Q;
---
package P.Child is
type T3 is new Q.T2;
private
Int: Integer := 52;
V: T3 := T3 (P.C); -- legal
W: T3 := T3 (Int); -- legal
X: T3 := T3 ( 42); -- error, T3 not numeric
Y: T3 := X + 1; -- error, no visible "+"
Z: T3 := T3 (Integer (W) + 1); -- legal
end P.Child;
Tested on x86_64-pc-linux-gnu, committed on trunk
2013-04-11 Ed Schonberg <schonberg@adacore.com>
* sem_util.ads, sem_util.adb (Get_Incomplete_View_Of_Ancestor):
New function to implement the notion introduced in RM 7.3.1
(5.2/3): in a child unit, a derived type is within the derivation
class of an ancestor declared in a parent unit, even if there
is an intermediate derivation that does not see the full view
of that ancestor.
* sem_res.adb (Valid_Conversion): if all else fails, examine if an
incomplete view of an ancestor makes a numeric conversion legal.