[comp.lang.ada] Ambiguity in Ada LRM about private types and type conversions

jonab@SDC-CAMARILLO.ARPA (Jonathan P. Biggar) (11/25/86)

The following code fragment demonstrates an ambiguity in the Ada Language
Reference Manual:

package EXPORT is
    type T is private;
private
    type T is range 0..100;
end EXPORT;

with EXPORT;
use  EXPORT;
procedure FOO is
    A: INTEGER;
    B: T;
begin
    A := INTEGER(B);
    B := T(A);
end FOO;

Upon examination of this code, one would expect that a compiler must reject
this, because to allow it would mean abrogating the data integrety
mechanism provided by private types.  If allowed, a user can convert
to and from a private type at will.

The LRM does not explicitly disallow this however.  In 7.4.2(1),
the operations declared by a private type declaration include
explicit conversions.  The intention seems to be to allow explicit
conversion between the private type and any types derived from that
private type.  It also seems to allow the type conversions in the above
code.

There needs to be a statement in the LRM to explicitly disallow explicit
conversions from a private type to types defined compatible to the private
type's implementation by 4.6 cases a, b or c.

Jon Biggar
jonab@SDC-CAMARILLO.ARPA
sdcrdcf!jonab