• Compiler error (2) ?

    From reinert@21:1/5 to All on Sun Sep 25 23:54:33 2022
    Hello,

    This must reveal a compiler error : -------------------------------------------------------------------------------------------------------
    with Ada.Text_IO;
    with Ada.Containers.Vectors;
    procedure test1a is
    type s_name_type is (s0, s1, s2, s3, s4, s5, s6, s7, s8, s9);
    for s_name_type use
    (S0 => 0, S1 => 1, S2 => 2, S3 => 3, S4 => 4,
    S5 => 5, S6 => 6, S7 => 7, S8 => 8, S9 => 9);
    package s_names_p is new Ada.Containers.Vectors
    (Index_Type => Positive, Element_Type => s_name_type);
    k : integer := 7;

    -- n : constant integer := 7; -- uncomment this line and comment out the line below.
    n : constant integer := k;

    s_names: constant s_names_p.Vector := [for i in 3..n => S0];
    begin
    Ada.Text_IO.Put_Line(s_names'Image);
    end test1a; -------------------------------------------------------------------------------------------------------
    (compiled using alire and
    package Compiler is
    for Switches ("ada") use ("-gnatwa", "-gnata", "-gnatX", "-gnatwv");
    end Compiler; -------------------------------------------------------------------------------------------------------

    Right?

    reinert

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Simon Wright@21:1/5 to All on Mon Sep 26 09:12:05 2022
    I'm not sure what compiler error you mean.

    Agreed that the code as stands reports a strange issue,

    11. S_Names: constant S_Names_P.Vector := [for I in 3..N => S0];
    |
    >>> error: expected type "Standard.Integer"
    >>> error: found type "Ada.Containers.Count_Type"

    which does look like a compiler error (even if it's only misreporting a
    valid issue, I'm not sure).

    What's more interesting is what happens if you make your suggested
    change and it compiles. When you run it,

    $ ./reinert_2

    raised CONSTRAINT_ERROR : test1a.s_names_p.Replace_Element: Index is
    out of range

    Running this under the debugger, with 'catch exception',

    Catchpoint 1, CONSTRAINT_ERROR (test1a.s_names_p.Replace_Element: Index is out of range) at 0x0000000100008ae5 in test1a () at reinert_2.adb:15
    15 s_names: constant s_names_p.Vector := [for i in 3..n => S0];

    So, what's Index?

    (gdb) p index
    No definition of "index" in current context.

    Looing at the backtrace,

    (gdb) bt
    [...]
    #4 0x0000000100011711 in test1a.s_names_p.replace_element (container=...,
    index=6, new_item=s0)
    at /opt/gcc-12.1.0/lib/gcc/x86_64-apple-darwin15/12.1.0/adainclude/a-convec.adb:2522
    #5 0x0000000100008ae5 in test1a () at reinert_2.adb:15

    Frame 4 is in the runtime; maybe we can see what's going on,

    (gdb) fr 4
    #4 0x0000000100011711 in test1a.s_names_p.replace_element (container=...,
    index=6, new_item=s0)
    at /opt/gcc-12.1.0/lib/gcc/x86_64-apple-darwin15/12.1.0/adainclude/a-convec.adb:2522
    2522 raise Constraint_Error with "Index is out of range";
    (gdb) p index
    $1 = 6

    Hmm. What does the source say?

    (gdb) l
    2517 is
    2518 begin
    2519 TE_Check (Container.TC);
    2520
    2521 if Checks and then Index > Container.Last then
    2522 raise Constraint_Error with "Index is out of range";
    2523 end if;
    2524
    2525 Container.Elements.EA (Index) := New_Item;
    2526 end Replace_Element;

    So Index (6) is more than Container.Last:

    (gdb) p container
    $2 = (elements => 0x600000008000, last => 5, tc => (busy => 0, lock => 0))
    (gdb)

    6 is certainly more than 5. Where does 5 come from?

    Index is Positive. We were hoping to have our container with indices
    supporting values up to 7, but the first index of a container has to be Index_Type'First i.e. 1; the compiler has looked at the length of the
    aggregate (5) and created an empty Vector s_names of that length.

    Clearly you can't do slices in this context!

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From J-P. Rosen@21:1/5 to All on Mon Sep 26 10:34:19 2022
    Please give the exact error message, and why you think it could be a
    compiler error. Otherwise, it's hard to help...

    Le 26/09/2022 à 08:54, reinert a écrit :
    Hello,

    This must reveal a compiler error : -------------------------------------------------------------------------------------------------------
    with Ada.Text_IO;
    with Ada.Containers.Vectors;
    procedure test1a is
    type s_name_type is (s0, s1, s2, s3, s4, s5, s6, s7, s8, s9);
    for s_name_type use
    (S0 => 0, S1 => 1, S2 => 2, S3 => 3, S4 => 4,
    S5 => 5, S6 => 6, S7 => 7, S8 => 8, S9 => 9);
    package s_names_p is new Ada.Containers.Vectors
    (Index_Type => Positive, Element_Type => s_name_type);
    k : integer := 7;

    -- n : constant integer := 7; -- uncomment this line and comment out the line below.
    n : constant integer := k;

    s_names: constant s_names_p.Vector := [for i in 3..n => S0];
    begin
    Ada.Text_IO.Put_Line(s_names'Image);
    end test1a; -------------------------------------------------------------------------------------------------------
    (compiled using alire and
    package Compiler is
    for Switches ("ada") use ("-gnatwa", "-gnata", "-gnatX", "-gnatwv");
    end Compiler; -------------------------------------------------------------------------------------------------------

    Right?

    reinert

    --
    J-P. Rosen
    Adalog
    2 rue du Docteur Lombard, 92441 Issy-les-Moulineaux CEDEX
    Tel: +33 1 45 29 21 52
    https://www.adalog.fr

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From reinert@21:1/5 to All on Mon Sep 26 01:47:13 2022
    This is what I (also) get:

    test1a.adb:16:42: error: expected type "Standard.Integer"
    test1a.adb:16:42: error: found type "Ada.Containers.Count_Type"

    compilation of test1a.adb failed

    gprbuild: *** compilation phase failed
    error: Command ["gprbuild", "-s", "-j0", "-p", "-P", "/home/reinert/test1a/test1a.gpr"] exited with code 4
    error: Compilation failed. ---------------------------------------------------------------------------------------------------
    **However, the following version goes through the compiler and runs
    (using "subtype n_t is Positive range 3..Positive'Last;" for)
    in the package specification) - confirming what Simon says:

    with Ada.Text_IO;
    with Ada.Containers.Vectors;
    procedure test1a is
    type s_name_type is (s0, s1, s2, s3, s4, s5, s6, s7, s8, s9);
    for s_name_type use
    (S0 => 0, S1 => 1, S2 => 2, S3 => 3, S4 => 4,
    S5 => 5, S6 => 6, S7 => 7, S8 => 8, S9 => 9);
    subtype n_t is Positive range 3..Positive'Last;
    package s_names_p is new Ada.Containers.Vectors
    (Index_Type => n_t, Element_Type => s_name_type);
    k : integer := 7;

    n : constant integer := 7;
    -- n : constant integer := k; -- uncomment this line and comment out the line above.

    s_names: constant s_names_p.Vector := [for i in 3..n => S0];
    begin
    Ada.Text_IO.Put_Line(s_names'Image);
    end test1a;


    reinert




    mandag 26. september 2022 kl. 10:34:18 UTC+2 skrev J-P. Rosen:
    Please give the exact error message, and why you think it could be a compiler error. Otherwise, it's hard to help...
    Le 26/09/2022 à 08:54, reinert a écrit :
    Hello,

    This must reveal a compiler error : -------------------------------------------------------------------------------------------------------
    with Ada.Text_IO;
    with Ada.Containers.Vectors;
    procedure test1a is
    type s_name_type is (s0, s1, s2, s3, s4, s5, s6, s7, s8, s9);
    for s_name_type use
    (S0 => 0, S1 => 1, S2 => 2, S3 => 3, S4 => 4,
    S5 => 5, S6 => 6, S7 => 7, S8 => 8, S9 => 9);
    package s_names_p is new Ada.Containers.Vectors
    (Index_Type => Positive, Element_Type => s_name_type);
    k : integer := 7;

    -- n : constant integer := 7; -- uncomment this line and comment out the line below.
    n : constant integer := k;

    s_names: constant s_names_p.Vector := [for i in 3..n => S0];
    begin
    Ada.Text_IO.Put_Line(s_names'Image);
    end test1a; -------------------------------------------------------------------------------------------------------
    (compiled using alire and
    package Compiler is
    for Switches ("ada") use ("-gnatwa", "-gnata", "-gnatX", "-gnatwv");
    end Compiler; -------------------------------------------------------------------------------------------------------

    Right?

    reinert
    --
    J-P. Rosen
    Adalog
    2 rue du Docteur Lombard, 92441 Issy-les-Moulineaux CEDEX
    Tel: +33 1 45 29 21 52
    https://www.adalog.fr

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From reinert@21:1/5 to All on Mon Sep 26 02:59:24 2022
    Sorry for some typos in my latest post, but the intelligent reader should understand :-)

    reinert

    mandag 26. september 2022 kl. 10:47:16 UTC+2 skrev reinert:
    This is what I (also) get:

    test1a.adb:16:42: error: expected type "Standard.Integer"
    test1a.adb:16:42: error: found type "Ada.Containers.Count_Type"

    compilation of test1a.adb failed

    gprbuild: *** compilation phase failed
    error: Command ["gprbuild", "-s", "-j0", "-p", "-P", "/home/reinert/test1a/test1a.gpr"] exited with code 4
    error: Compilation failed. ---------------------------------------------------------------------------------------------------
    **However, the following version goes through the compiler and runs
    (using "subtype n_t is Positive range 3..Positive'Last;" for)
    in the package specification) - confirming what Simon says:

    with Ada.Text_IO;
    with Ada.Containers.Vectors;
    procedure test1a is
    type s_name_type is (s0, s1, s2, s3, s4, s5, s6, s7, s8, s9);
    for s_name_type use
    (S0 => 0, S1 => 1, S2 => 2, S3 => 3, S4 => 4,
    S5 => 5, S6 => 6, S7 => 7, S8 => 8, S9 => 9);
    subtype n_t is Positive range 3..Positive'Last;
    package s_names_p is new Ada.Containers.Vectors
    (Index_Type => n_t, Element_Type => s_name_type);
    k : integer := 7;
    n : constant integer := 7;
    -- n : constant integer := k; -- uncomment this line and comment out the line above.
    s_names: constant s_names_p.Vector := [for i in 3..n => S0];
    begin
    Ada.Text_IO.Put_Line(s_names'Image);
    end test1a;
    reinert
    mandag 26. september 2022 kl. 10:34:18 UTC+2 skrev J-P. Rosen:
    Please give the exact error message, and why you think it could be a compiler error. Otherwise, it's hard to help...
    Le 26/09/2022 à 08:54, reinert a écrit :
    Hello,

    This must reveal a compiler error : -------------------------------------------------------------------------------------------------------
    with Ada.Text_IO;
    with Ada.Containers.Vectors;
    procedure test1a is
    type s_name_type is (s0, s1, s2, s3, s4, s5, s6, s7, s8, s9);
    for s_name_type use
    (S0 => 0, S1 => 1, S2 => 2, S3 => 3, S4 => 4,
    S5 => 5, S6 => 6, S7 => 7, S8 => 8, S9 => 9);
    package s_names_p is new Ada.Containers.Vectors
    (Index_Type => Positive, Element_Type => s_name_type);
    k : integer := 7;

    -- n : constant integer := 7; -- uncomment this line and comment out the line below.
    n : constant integer := k;

    s_names: constant s_names_p.Vector := [for i in 3..n => S0];
    begin
    Ada.Text_IO.Put_Line(s_names'Image);
    end test1a; -------------------------------------------------------------------------------------------------------
    (compiled using alire and
    package Compiler is
    for Switches ("ada") use ("-gnatwa", "-gnata", "-gnatX", "-gnatwv");
    end Compiler; -------------------------------------------------------------------------------------------------------

    Right?

    reinert
    --
    J-P. Rosen
    Adalog
    2 rue du Docteur Lombard, 92441 Issy-les-Moulineaux CEDEX
    Tel: +33 1 45 29 21 52
    https://www.adalog.fr

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)