* Formal Package Compiler Differences
@ 2023-07-14 19:17 Jeffrey R.Carter
2023-07-14 19:27 ` Jeffrey R.Carter
0 siblings, 1 reply; 2+ messages in thread
From: Jeffrey R.Carter @ 2023-07-14 19:17 UTC (permalink / raw)
I have a generic pkg;
with Ada.Containers.Vectors;
generic -- Vector_Conversions
type Index is range <>;
type Element is private;
type Fixed is array (Index range <>) of Element;
with function "=" (Left : in Element; Right : in Element) return Boolean
is <>;
with package Unbounded is new Ada.Containers.Vectors
(Index_Type => Index, Element_Type => Element);
package Vector_Conversions is
-- Empty
end Vector_Conversions;
and an instantiation of
with Ada.Containers.Vectors;
with Ada.Strings.Unbounded;
with Vector_Conversions;
procedure Instance_Test is
use Ada.Strings.Unbounded;
package String_Lists is new Ada.Containers.Vectors
(Index_Type => Positive, Element_Type => Unbounded_String);
type String_List is array (Positive range <>) of Unbounded_String;
package Conversions is new Vector_Conversions
(Index => Positive,
Element => Unbounded_String,
Fixed => String_List,
Unbounded => String_Lists);
begin -- Instance_Test
null;
end Instance_Test;
Compiler G compiles this and it works fine.
Compiler O fails to compile the instantiation with the error msg "The subprogram
actuals for the formal package and actual package must statically denote the
same entity", pointing to the Unbounded parameter association and referencing
ARM 12.7(8). If I add an explicit "=" with "is <>" to Vector_Conversions, then
compiler O compiles it and it works fine.
Possibly one of the compilers has an error, but possibly they're both correct,
and I'm wondering if it's possible to tell which is the case.
(If anyone is interested, the actual generic pkg where I encountered this is
PragmARC.Conversions.Vectors from the PragmAda Reusable Components
[https://github.com/jrcarter/PragmARC]), and I will supply the actual code that
instantiates it on demand. What I've presented is a first attempt at a minimal
reproducer.)
--
Jeff Carter
"Make sure your code 'does nothing' gracefully."
Elements of Programming Style
196
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: Formal Package Compiler Differences
2023-07-14 19:17 Formal Package Compiler Differences Jeffrey R.Carter
@ 2023-07-14 19:27 ` Jeffrey R.Carter
0 siblings, 0 replies; 2+ messages in thread
From: Jeffrey R.Carter @ 2023-07-14 19:27 UTC (permalink / raw)
On 2023-07-14 21:17, Jeffrey R.Carter wrote:
> I have a generic pkg;
>
> with Ada.Containers.Vectors;
>
> generic -- Vector_Conversions
> type Index is range <>;
> type Element is private;
> type Fixed is array (Index range <>) of Element;
>
> with function "=" (Left : in Element; Right : in Element) return Boolean
> is <>;
Oops! This "=" should be removed to get the behavior described.
>
> with package Unbounded is new Ada.Containers.Vectors
> (Index_Type => Index, Element_Type => Element);
> package Vector_Conversions is
> -- Empty
> end Vector_Conversions;
>
> and an instantiation of
>
> with Ada.Containers.Vectors;
> with Ada.Strings.Unbounded;
> with Vector_Conversions;
>
> procedure Instance_Test is
> use Ada.Strings.Unbounded;
>
> package String_Lists is new Ada.Containers.Vectors
> (Index_Type => Positive, Element_Type => Unbounded_String);
>
> type String_List is array (Positive range <>) of Unbounded_String;
>
> package Conversions is new Vector_Conversions
> (Index => Positive,
> Element => Unbounded_String,
> Fixed => String_List,
> Unbounded => String_Lists);
> begin -- Instance_Test
> null;
> end Instance_Test;
>
> Compiler G compiles this and it works fine.
>
> Compiler O fails to compile the instantiation with the error msg "The subprogram
> actuals for the formal package and actual package must statically denote the
> same entity", pointing to the Unbounded parameter association and referencing
> ARM 12.7(8). If I add an explicit "=" with "is <>" to Vector_Conversions, then
> compiler O compiles it and it works fine.
>
> Possibly one of the compilers has an error, but possibly they're both correct,
> and I'm wondering if it's possible to tell which is the case.
>
> (If anyone is interested, the actual generic pkg where I encountered this is
> PragmARC.Conversions.Vectors from the PragmAda Reusable Components
> [https://github.com/jrcarter/PragmARC]), and I will supply the actual code that
> instantiates it on demand. What I've presented is a first attempt at a minimal
> reproducer.)
>
--
Jeff Carter
"Make sure your code 'does nothing' gracefully."
Elements of Programming Style
196
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-07-14 19:27 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-07-14 19:17 Formal Package Compiler Differences Jeffrey R.Carter
2023-07-14 19:27 ` Jeffrey R.Carter
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox