comp.lang.ada
 help / color / mirror / Atom feed
* error: choice must be static?
@ 2024-02-11 12:29 Blady
  2024-02-11 20:56 ` Jeffrey R.Carter
  2024-02-13  2:12 ` Randy Brukardt
  0 siblings, 2 replies; 7+ messages in thread
From: Blady @ 2024-02-11 12:29 UTC (permalink / raw)


Hello,

I've got the following GNAT error:

$ gcc -c -gnat2022 -gnatl 2024/test_20240211_static_choice.adb
GNAT 13.2.0
      1. procedure test_20240211_static_choice is
      2.
      3.    package Maps is
      4.       type Map_Type is private
      5.         with Aggregate =>  (Empty     => Empty_Map,
      6.                             Add_Named => Add_To_Map);
      7.       procedure Add_To_Map (M : in out Map_Type; Key : in 
Integer; Value : in String);
      8.       Empty_Map : constant Map_Type;
      9.    private
     10.       type Map_Type is array (1..10) of String (1..10);
     11.       procedure Add_To_Map (M : in out Map_Type; Key : in 
Integer; Value : in String) is null;
     12.       Empty_Map : constant Map_Type := [1..10 => "          "]; 
-- error: choice must be static
                                                  |
         >>> error: choice must be static

     13.    end;
     14.
     15. begin
     16.    null;
     17. end;

I wonder what more static it should be.
Any clue ?

Thanks, Pascal.

Source code:
procedure test_20240211_static_choice is

    package Maps is
       type Map_Type is private
         with Aggregate =>  (Empty     => Empty_Map,
                             Add_Named => Add_To_Map);
       procedure Add_To_Map (M : in out Map_Type; Key : in Integer; 
Value : in String);
       Empty_Map : constant Map_Type;
    private
       type Map_Type is array (1..10) of String (1..10);
       procedure Add_To_Map (M : in out Map_Type; Key : in Integer; 
Value : in String) is null;
       Empty_Map : constant Map_Type := [1..10 => "          "]; -- 
error: choice must be static
    end;

begin
    null;
end;

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

* Re: error: choice must be static?
  2024-02-11 12:29 error: choice must be static? Blady
@ 2024-02-11 20:56 ` Jeffrey R.Carter
  2024-02-12  8:12   ` Dmitry A. Kazakov
  2024-02-13  2:12 ` Randy Brukardt
  1 sibling, 1 reply; 7+ messages in thread
From: Jeffrey R.Carter @ 2024-02-11 20:56 UTC (permalink / raw)


On 2024-02-11 13:29, Blady wrote:
> Hello,
> 
> I've got the following GNAT error:
> 
> $ gcc -c -gnat2022 -gnatl 2024/test_20240211_static_choice.adb
> GNAT 13.2.0
>       1. procedure test_20240211_static_choice is
>       2.
>       3.    package Maps is
>       4.       type Map_Type is private
>       5.         with Aggregate =>  (Empty     => Empty_Map,
>       6.                             Add_Named => Add_To_Map);
>       7.       procedure Add_To_Map (M : in out Map_Type; Key : in Integer; 
> Value : in String);
>       8.       Empty_Map : constant Map_Type;
>       9.    private
>      10.       type Map_Type is array (1..10) of String (1..10);
>      11.       procedure Add_To_Map (M : in out Map_Type; Key : in Integer; 
> Value : in String) is null;
>      12.       Empty_Map : constant Map_Type := [1..10 => "          "]; -- 
> error: choice must be static
>                                                   |
>          >>> error: choice must be static
> 
>      13.    end;
>      14.
>      15. begin
>      16.    null;
>      17. end;
> 
> I wonder what more static it should be.

I don't know what this means, but it's definitely related to the Aggregate 
aspect. This compiles:

procedure Test_20240211_Static_Choice is
    package Maps is
       type Map_Type is private
          with Aggregate =>  (Empty     => Empty_Map,
                              Add_Named => Add_To_Map);
       procedure Add_To_Map (M : in out Map_Type; Key : in Integer; Value : in 
String);
       Empty_Map : constant Map_Type;
    private
       type Map_Base is array (1 .. 10) of String (1 .. 10);
       type Map_Type is new Map_Base;
       procedure Add_To_Map (M : in out Map_Type; Key : in Integer; Value : in 
String) is null;
       Empty_Base : constant Map_Base := (1 .. 10 => (1 .. 10 => ' ') );
       Empty_Map  : constant Map_Type := Map_Type (Empty_Base);
    end Maps;
begin
    null;
end Test_20240211_Static_Choice;

-- 
Jeff Carter
"Nobody expects the Spanish Inquisition!"
Monty Python's Flying Circus
22

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

* Re: error: choice must be static?
  2024-02-11 20:56 ` Jeffrey R.Carter
@ 2024-02-12  8:12   ` Dmitry A. Kazakov
  0 siblings, 0 replies; 7+ messages in thread
From: Dmitry A. Kazakov @ 2024-02-12  8:12 UTC (permalink / raw)


On 2024-02-11 21:56, Jeffrey R.Carter wrote:

> I don't know what this means, but it's definitely related to the 
> Aggregate aspect.

Square brackets is the root of all evil! (:-))

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de

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

* Re: error: choice must be static?
  2024-02-11 12:29 error: choice must be static? Blady
  2024-02-11 20:56 ` Jeffrey R.Carter
@ 2024-02-13  2:12 ` Randy Brukardt
  2024-02-13 11:45   ` Simon Wright
  1 sibling, 1 reply; 7+ messages in thread
From: Randy Brukardt @ 2024-02-13  2:12 UTC (permalink / raw)


Looks like a compiler bug to me. The nonsense message gives that away... :-)

                     Randy.

"Blady" <p.p11@orange.fr> wrote in message 
news:uqaek7$vd8o$1@dont-email.me...
> Hello,
>
> I've got the following GNAT error:
>
> $ gcc -c -gnat2022 -gnatl 2024/test_20240211_static_choice.adb
> GNAT 13.2.0
>      1. procedure test_20240211_static_choice is
>      2.
>      3.    package Maps is
>      4.       type Map_Type is private
>      5.         with Aggregate =>  (Empty     => Empty_Map,
>      6.                             Add_Named => Add_To_Map);
>      7.       procedure Add_To_Map (M : in out Map_Type; Key : in Integer; 
> Value : in String);
>      8.       Empty_Map : constant Map_Type;
>      9.    private
>     10.       type Map_Type is array (1..10) of String (1..10);
>     11.       procedure Add_To_Map (M : in out Map_Type; Key : in Integer; 
> Value : in String) is null;
>     12.       Empty_Map : constant Map_Type := [1..10 => "          "]; --  
> error: choice must be static
>                                                  |
>         >>> error: choice must be static
>
>     13.    end;
>     14.
>     15. begin
>     16.    null;
>     17. end;
>
> I wonder what more static it should be.
> Any clue ?
>
> Thanks, Pascal.
>
> Source code:
> procedure test_20240211_static_choice is
>
>    package Maps is
>       type Map_Type is private
>         with Aggregate =>  (Empty     => Empty_Map,
>                             Add_Named => Add_To_Map);
>       procedure Add_To_Map (M : in out Map_Type; Key : in Integer; Value : 
> in String);
>       Empty_Map : constant Map_Type;
>    private
>       type Map_Type is array (1..10) of String (1..10);
>       procedure Add_To_Map (M : in out Map_Type; Key : in Integer; Value : 
> in String) is null;
>       Empty_Map : constant Map_Type := [1..10 => "          "]; -- 
> error: choice must be static
>    end;
>
> begin
>    null;
> end; 


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

* Re: error: choice must be static?
  2024-02-13  2:12 ` Randy Brukardt
@ 2024-02-13 11:45   ` Simon Wright
  2024-02-14  4:28     ` Randy Brukardt
  0 siblings, 1 reply; 7+ messages in thread
From: Simon Wright @ 2024-02-13 11:45 UTC (permalink / raw)


"Randy Brukardt" <randy@rrsoftware.com> writes:

> Looks like a compiler bug to me. The nonsense message gives that away... :-)

GCC 14.0.1 says

     1. procedure test_20240211_static_choice is
     2.
     3.    package Maps is
     4.       type Map_Type is private
     5.         with Aggregate =>  (Empty     => Empty_Map,
                     |
        >>> error: aspect "Aggregate" can only be applied to non-array type

     6.                             Add_Named => Add_To_Map);
     7.       procedure Add_To_Map (M : in out Map_Type; Key : in Integer;
     8.       Value : in String);
     9.       Empty_Map : constant Map_Type;
    10.    private
    11.       type Map_Type is array (1..10) of String (1..10);
    12.       procedure Add_To_Map (M : in out Map_Type; Key : in Integer;
    13.       Value : in String) is null;
    14.       Empty_Map : constant Map_Type := [1..10 => "          "];
                                                 |
        >>> error: choice must be static

    15.    end;
    16.
    17. begin
    18.    null;
    19. end;

I think the first is because of ARM 4.3.5(2), "For a type other than an
array type, the following type-related operational aspect may be
specified"[1] and the second is a "nonsense" consequence.

[1] http://www.ada-auth.org/standards/22rm/html/RM-4-3-5.html#p2

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

* Re: error: choice must be static?
  2024-02-13 11:45   ` Simon Wright
@ 2024-02-14  4:28     ` Randy Brukardt
  2024-02-17  8:51       ` Blady
  0 siblings, 1 reply; 7+ messages in thread
From: Randy Brukardt @ 2024-02-14  4:28 UTC (permalink / raw)


Ah, yes, didn't notice that part. One cannot give the Aggregate aspect on an 
array type, directly or indirectly. That's because container aggregates are 
designed to work like array aggregates, and we didn't want visibility to 
determine the interpretation of an aggregate (especially where the same 
syntax could have a different meaning in different visibility).. Thus, there 
can be no point where a single type can have both array aggregates and 
container aggregates.

Note that record aggregates and container aggregates are always syntactally 
different, and thus it is OK to have both in a single location (that's one 
of the reasons that we adopted square brackets for container aggregates). 
That seemed important as the majority of private types are completed by 
record types, and not allowing record types in this context would be 
difficult to work around.

                  Randy.



"Simon Wright" <simon@pushface.org> wrote in message 
news:lybk8klh9u.fsf@pushface.org...
> "Randy Brukardt" <randy@rrsoftware.com> writes:
>
>> Looks like a compiler bug to me. The nonsense message gives that away... 
>> :-)
>
> GCC 14.0.1 says
>
>     1. procedure test_20240211_static_choice is
>     2.
>     3.    package Maps is
>     4.       type Map_Type is private
>     5.         with Aggregate =>  (Empty     => Empty_Map,
>                     |
>        >>> error: aspect "Aggregate" can only be applied to non-array type
>
>     6.                             Add_Named => Add_To_Map);
>     7.       procedure Add_To_Map (M : in out Map_Type; Key : in Integer;
>     8.       Value : in String);
>     9.       Empty_Map : constant Map_Type;
>    10.    private
>    11.       type Map_Type is array (1..10) of String (1..10);
>    12.       procedure Add_To_Map (M : in out Map_Type; Key : in Integer;
>    13.       Value : in String) is null;
>    14.       Empty_Map : constant Map_Type := [1..10 => "          "];
>                                                 |
>        >>> error: choice must be static
>
>    15.    end;
>    16.
>    17. begin
>    18.    null;
>    19. end;
>
> I think the first is because of ARM 4.3.5(2), "For a type other than an
> array type, the following type-related operational aspect may be
> specified"[1] and the second is a "nonsense" consequence.
>
> [1] http://www.ada-auth.org/standards/22rm/html/RM-4-3-5.html#p2 


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

* Re: error: choice must be static?
  2024-02-14  4:28     ` Randy Brukardt
@ 2024-02-17  8:51       ` Blady
  0 siblings, 0 replies; 7+ messages in thread
From: Blady @ 2024-02-17  8:51 UTC (permalink / raw)


Le 14/02/2024 à 05:28, Randy Brukardt a écrit :
> Ah, yes, didn't notice that part. One cannot give the Aggregate aspect on an
> array type, directly or indirectly. That's because container aggregates are
> designed to work like array aggregates, and we didn't want visibility to
> determine the interpretation of an aggregate (especially where the same
> syntax could have a different meaning in different visibility).. Thus, there
> can be no point where a single type can have both array aggregates and
> container aggregates.
> 
> Note that record aggregates and container aggregates are always syntactally
> different, and thus it is OK to have both in a single location (that's one
> of the reasons that we adopted square brackets for container aggregates).
> That seemed important as the majority of private types are completed by
> record types, and not allowing record types in this context would be
> difficult to work around.

Thanks Randy for the explanation, it helps.

Pascal.

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

end of thread, other threads:[~2024-02-17  8:51 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-11 12:29 error: choice must be static? Blady
2024-02-11 20:56 ` Jeffrey R.Carter
2024-02-12  8:12   ` Dmitry A. Kazakov
2024-02-13  2:12 ` Randy Brukardt
2024-02-13 11:45   ` Simon Wright
2024-02-14  4:28     ` Randy Brukardt
2024-02-17  8:51       ` Blady

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