comp.lang.ada
 help / color / mirror / Atom feed
* Strange compile-time error  with Ada.Containers.Indefinite_Hashed_Maps
@ 2014-05-19 10:10 mockturtle
  2014-05-19 13:49 ` Simon Wright
  0 siblings, 1 reply; 11+ messages in thread
From: mockturtle @ 2014-05-19 10:10 UTC (permalink / raw)


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 "symbol table" that maps identifiers (implemented as bounded strings) into "symbol descriptors" (implemented as records with a discriminant that identifies the symbol type).  

I define the "identifier name" type in a package that is with-ed by the package that defines the symbol table.  The symbol table is just a Indefinite_Hash_Map (indefinite since the descriptor is indefinite).   When I try to compile the body of the symbol table package I get in the .ads the error 

    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 identifier 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 =>
               null;

            when Second =>
               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        => Ginger.Name_Type,
        Element_Type    => Descriptor,
        Hash            => Hash,
        Equivalent_Keys => 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;
   
   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 
   is
   begin
      
      return Ginger.To_String (Left) = Ginger.To_String (Right);
   end Equal;
        


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 =>
               null;

            when Second =>
               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 = Right);

   package Maps is
     new Ada.Containers.Indefinite_Hashed_Maps
       (Key_Type        => Name_Type,
        Element_Type    => Descriptor,
        Hash            => Hash,
        Equivalent_Keys => 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;


^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2014-05-26  8:53 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-05-19 10:10 Strange compile-time error with Ada.Containers.Indefinite_Hashed_Maps mockturtle
2014-05-19 13:49 ` Simon Wright
2014-05-19 16:00   ` mockturtle
2014-05-19 16:19     ` G.B.
2014-05-19 16:35     ` Simon Wright
2014-05-19 21:27     ` J-P. Rosen
2014-05-20  6:30       ` Simon Wright
2014-05-20 20:47       ` björn lundin
2014-05-21  5:04         ` J-P. Rosen
2014-05-25 18:28           ` björn lundin
2014-05-26  8:53             ` J-P. Rosen

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