From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,3039151bd3ba684d,start X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!postnews1.google.com!not-for-mail From: jpwoodruff@irisinternet.net (John Woodruff) Newsgroups: comp.lang.ada Subject: Two generic families: I'm confused by error msg Date: 2 Nov 2004 21:40:29 -0800 Organization: http://groups.google.com Message-ID: <34defe4d.0411022140.17304b1c@posting.google.com> NNTP-Posting-Host: 216.126.128.53 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Trace: posting.google.com 1099460430 13632 127.0.0.1 (3 Nov 2004 05:40:30 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Wed, 3 Nov 2004 05:40:30 +0000 (UTC) Xref: g2news1.google.com comp.lang.ada:5974 Date: 2004-11-02T21:40:29-08:00 List-Id: I'm puzzled by an Ada error. The error arises in the attached program, which uses two different (parent-child) pairs of generic packages. And the error seems to indicate a hard-for-me-to-understand issue of visibility. The first two packages (numeric_io and it's child *.matrix_io) do some IO on vectors and matrices of floating numbers. Just about like the new Ada.Numerics.Generic_Real_Arrays.Generic_IO. Two more packages (name_io and its child *.matrix_name_io) add services that parse name-directed input for object-oriented applications. This pair uses instances of numeric_io, so that vectors are the same regardless of which services are invoked. It all works fine, and I'm in the final stages of preparing this to share. Maybe on adaworld or adapower if they'll have me.... BUT Numeric_io defines a subtype "real" that is just the actual type given for its argument. That's how the two children manage to work on the same types (they are children of different, unrelated, parents). So along comes the client (I named it "Unreal" in this exhibit). It laces the two generic families together, and it works perfectly IF and ONLY IF it *happens* to use the identifier "Real" somewhere. This client does not need to declare any *usage* of the subtype "Real", nor use it in instantiating the generics. Unfortunately, poor client has no way of knowing he needs to declare "real". And I'm not sure what is the language-law that connects the type Scalar_IO.Real in the generic actual package with the subtype identifier Real in the client. Can someone help me make sense of this? Can someone suggest a way to rephrase these relationships so I don't require the client to "say the magic word"? <<< gnatchop the stuff after this line to see the puzzle >>> generic type Floating_Type is digits <> ; package Numeric_Io is subtype Real is Floating_Type ; end Numeric_Io ; generic type Vector_Ix is (<>) ; type Vector is array (Vector_Ix range <>) of Real ; package Numeric_Io.Matrix_IO is end Numeric_Io.Matrix_IO ; with Numeric_Io; generic type Floating_Type is digits <> ; with package Scalar_Io is new Numeric_Io (Floating_Type) ; package Name_Io is end Name_Io; with Numeric_Io.Matrix_Io ; generic type Vector_Ix is (<>) ; type Vector is array (Vector_Ix range <>) of Scalar_Io.Real ; with package Matrix_Io is new Scalar_Io.Matrix_Io (Vector_Ix, Vector) ; package Name_Io.Matrix_name_IO is end Name_Io.Matrix_name_IO ; with Numeric_Io.Matrix_Io ; with Name_Io.Matrix_Name_Io ; procedure Unreal is type Unreal is digits 6 ; -------------------------------------------------------------------------- -- If this line "subtype Real is Unreal" is ABSENT, then error at line 26: -- Component subtype of actual does not match that of formal "Vector" -------------------------------------------------------------------------- subtype Real is Unreal; type Vector is array (Integer range <>) of Unreal ; package Scalar_IO is new Numeric_IO (Unreal) ; package Matrix_IO is new Scalar_IO.Matrix_IO (Vector_Ix => Integer, Vector => Vector); package Nio is new Name_Io (Floating_Type => Unreal, Scalar_Io => Scalar_IO); package Mat_IO is new Nio.Matrix_Name_IO (Vector_Ix => Integer, Vector => Vector, -- the error is here Matrix_Io => Matrix_IO) ; begin null ; end Unreal ;