comp.lang.ada
 help / color / mirror / Atom feed
From: Roland Laznik <roland.laznik@gmail.com>
Subject: Unexpected behavior with partial parameterization of formal packages
Date: Mon, 10 Jul 2017 14:47:49 -0700 (PDT)
Date: 2017-07-10T14:47:49-07:00	[thread overview]
Message-ID: <21ff0d1f-c5f3-4c23-b974-80fed8ebdf55@googlegroups.com> (raw)

I stumbled on an issue with partial parameterization of formal packages.
In my opinion, the following Ada 2012 code is legal:

======================== main.adb
pprocedure Main is                                            -- Line  1

   generic
   package As is
   end As;

   generic
      type T is private;
      with package A0 is new As;                              -- Line  9
   package Bs is
   end Bs;

   generic
      with package Xa is new As;
   package Xs is
      package Xb is new Bs(T => Integer, A0 => Xa);           -- Line 16
   end Xs;

   generic
      with package Yb is new Bs(T => Integer, others => <>);  -- Line 20
   package Ys is
   end Ys;

   package A is new As;
   package X is new Xs(Xa => A);                              -- Line 25
   package Y is new Ys(Yb => X.Xb);                           -- Line 26

begin
   null;
end Main;
========================

However, gnat reports an error:
========================
$ gnatmake main.adb 
gcc -c main.adb
main.adb:26:31: actual for "A0" in actual instance does not match formal
gnatmake: "main.adb" compilation error
========================

I expect A0 eventually being set to A because
- X    is new Xs(Xa => A)                 [Line 25], therefore
- X.Xb is new Bs(T => Integer, A0 => Xa)  [line 16], with Xa = A, therefore A0 = A

If the partial parametrization in line 20 is removed, the code compiles. But this should not change the setting for A0 and the same error should be reported.
========================
      with package Yb is new Bs(others => <>);  -- Modified Line 20
========================

gnat/gnatmake are from the 2017 version of GNAT GPL:
========================
$ gnatmake --version
GNATMAKE GPL 2017 (20170515-63)
Copyright (C) 1995-2017, Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
$ gcc --version
gcc (GCC) 6.3.1 20170510 (for GNAT GPL 2017 20170515)
Copyright (C) 2016 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
See your AdaCore support agreement for details of warranty and support.
If you do not have a current support agreement, then there is absolutely
no warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE.
========================

Did I get the semantics of partial parametrization wrong or is there a bug in gnat?

Thanks in advance,
Roland

             reply	other threads:[~2017-07-10 21:47 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-07-10 21:47 Roland Laznik [this message]
2017-07-11 15:45 ` Unexpected behavior with partial parameterization of formal packages AdaMagica
replies disabled

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