comp.lang.ada
 help / color / mirror / Atom feed
From: jonab@SDC-CAMARILLO.ARPA (Jonathan P. Biggar)
Subject: Ambiguity in Ada LRM about private types and type conversions
Date: Mon, 24-Nov-86 16:26:41 EST	[thread overview]
Date: Mon Nov 24 16:26:41 1986
Message-ID: <8611242126.AA09478@PHOEBE.SDC.UUCP> (raw)

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

                 reply	other threads:[~1986-11-24 21:26 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox