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,FREEMAIL_FROM, T_FILL_THIS_FORM_SHORT autolearn=unavailable autolearn_force=no version=3.4.4 X-Received: by 10.66.144.228 with SMTP id sp4mr15635451pab.5.1400494207402; Mon, 19 May 2014 03:10:07 -0700 (PDT) X-Received: by 10.140.49.227 with SMTP id q90mr29837qga.22.1400494207284; Mon, 19 May 2014 03:10:07 -0700 (PDT) Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!news.eternal-september.org!news.eternal-september.org!feeder.eternal-september.org!news.glorb.com!c1no10357072igq.0!news-out.google.com!qf4ni2017igc.0!nntp.google.com!c1no10357063igq.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Mon, 19 May 2014 03:10:07 -0700 (PDT) Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=158.110.27.77; posting-account=9fwclgkAAAD6oQ5usUYhee1l39geVY99 NNTP-Posting-Host: 158.110.27.77 User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <9d912199-ff00-403f-b6e3-fb9632ec145e@googlegroups.com> Subject: Strange compile-time error with Ada.Containers.Indefinite_Hashed_Maps From: mockturtle Injection-Date: Mon, 19 May 2014 10:10:07 +0000 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Xref: news.eternal-september.org comp.lang.ada:19897 Date: 2014-05-19T03:10:07-07:00 List-Id: Dear all, I am stuck with an error that could be a compiler bug and I hope you could = give me some help. I am currently using GNAT 20140331 on 64 bit Linux. A brief introduction about what I am trying to do: I want to implement a "s= ymbol table" that maps identifiers (implemented as bounded strings) into "s= ymbol descriptors" (implemented as records with a discriminant that identif= ies the symbol type). =20 I define the "identifier name" type in a package that is with-ed by the pac= kage that defines the symbol table. The symbol table is just a Indefinite_= Hash_Map (indefinite since the descriptor is indefinite). When I try to c= ompile the body of the symbol table package I get in the .ads the error=20 instantiation error at a-cihama.adb:1043 invalid constraint: type has no discriminant I was able to replicate the error with a small set of files. At the end of= this message you will find three packages: Ginger (that defines the identi= fier type), Foo (that with-s Ginger) and Foo_2 (that is Foo merged together= with Ginger, so that it is self-sufficient). If I try to compile foo.adb, I get the error above; if I try to compile foo= -2.adb, I get no error. This makes me suspect that (i) I tripped over some= subtlety of the language or (ii) this is a bug. Any help? Thank you. Riccardo --------- -------------------- -- GINGER.ADS -- -------------------- with Ada.Strings.Bounded; package ginger is type Name_Type is private; function To_String(X:Name_Type) return String; private package Names is new Ada.Strings.Bounded.Generic_Bounded_Length (10); type Name_Type is new Names.Bounded_String; function To_String (X : Name_Type) return String is (Names.To_String (Names.Bounded_String (X))); end ginger; ----------------- -- FOO.ADS -- ----------------- with Ada.Containers.Indefinite_Hashed_Maps; with Ada.Strings.Hash; with Ginger; package foo is type My_Map is tagged private; type Name_Class is (First, Second); type Descriptor (Class : Name_Class) is record case Class is when First =3D> null; when Second =3D> X : Float; end case; end record; procedure Zizi (X: My_Map); private function Hash (Key : Ginger.Name_Type) return Ada.Containers.Hash_Type; function Equal (Left, Right : Ginger.Name_Type) return Boolean; package Maps is new Ada.Containers.Indefinite_Hashed_Maps (Key_Type =3D> Ginger.Name_Type, Element_Type =3D> Descriptor, Hash =3D> Hash, Equivalent_Keys =3D> Equal); type My_Map is new Maps.Map with null record; end foo; ----------------- -- FOO.ADB -- ----------------- package body foo is ---------- -- Zizi -- ---------- procedure Zizi (X: My_Map) is begin null; end Zizi; =20 function Hash (Key : Ginger.Name_Type) return Ada.Containers.Hash_Type is begin return Ada.Strings.Hash (Ginger.To_String (Key)); end Hash; function Equal (Left, Right : Ginger.Name_Type) return Boolean=20 is begin =20 return Ginger.To_String (Left) =3D Ginger.To_String (Right); end Equal; =20 end foo; ------------------- -- FOO_2.ADS -- ------------------- with Ada.Containers.Indefinite_Hashed_Maps; with Ada.Strings.Hash; with Ada.Strings.Bounded; package Foo_2 is type My_Map is tagged private; type Name_Class is (First, Second); type Descriptor (Class : Name_Class) is record case Class is when First =3D> null; when Second =3D> X : Float; end case; end record; procedure Zizi (X: My_Map); private package Names is new Ada.Strings.Bounded.Generic_Bounded_Length (10); type Name_Type is new Names.Bounded_String; function To_String (X : Name_Type) return String is (Names.To_String (Names.Bounded_String (X))); function Hash (Key : Name_Type) return Ada.Containers.Hash_Type is (Ada.Strings.Hash (To_String (Key))); function Equal (Left, Right : Name_Type) return Boolean is (Left =3D Right); package Maps is new Ada.Containers.Indefinite_Hashed_Maps (Key_Type =3D> Name_Type, Element_Type =3D> Descriptor, Hash =3D> Hash, Equivalent_Keys =3D> Equal); type My_Map is tagged record M : Maps.Map; end record; end Foo_2; ------------------- -- FOO_2.ADB -- ------------------- package body Foo_2 is ---------- -- Zizi -- ---------- procedure Zizi (X: My_Map) is begin null; end Zizi; end Foo_2;