pragma Extensions_Allowed (All);
generic
type Element is private; -- assignment and equality predefined
package main is
type Data is record
X,Y: Positive;
E: Integer;
end record;
type ArrayInput is array (Positive range 1..<>) of Data with Predicate => (for all I in 2..ArrayInput'Last => ArrayInput(I).X < ArrayInput(I-1).X or ArrayInput(I-1).Y < ArrayInput(I).Y);
end main;
Remove the generic part, on which nothing depends anyway, and it compiles. Same with Dynamic_Predicate. Do I file a bug report ?
I am no Ada expert, so take what I am about to say with a huge grain of salt… But I believe generics can only be part of packages as they need to be instantiated and GNAT will, during compilation time, specialise the generic package/methods for the instantiated type. If you are doing this directly in the main file, GNAT may be going crazy and missreporting the error…
You get the same errors from GNAT 14.1 even if you use Ada:
generic
type Element is private; -- assignment and equality predefined
package Predicate_Test is
type Data is record
X,Y: Positive;
E: Integer;
end record;
type Arrayinput is array (Positive range <>) of Data with
Dynamic_Predicate => Arrayinput'First = 1 and then
(for all I in Arrayinput'First + 1 .. Arrayinput'Last => Arrayinput (I).X < Arrayinput (I - 1).X or
Arrayinput (I - 1).Y < Arrayinput (I).Y);
end Predicate_Test;
Not fixed in GNAT 15.0.0 20241102 (experimental) (but the errors are different).
Would you like [me] to raise a PR?
1. pragma Extensions_Allowed (On);
2. generic
3. package Main is
4. type Data is record
5. X, Y : Positive;
6. E : Integer;
7. end record;
8. type ArrayInput is array (Positive range 1 .. <>) of Data with
9. Predicate =>
10. (for all I in 2 .. ArrayInput'Last =>
11. ArrayInput (I).X < ArrayInput (I - 1).X or
1 2
>>> error: reference to current instance of type does not denote a type (RM 8.6)
>>> error: reference to current instance of type does not denote a type (RM 8.6)
12. ArrayInput (I - 1).Y < ArrayInput (I).Y);
1 2
>>> error: reference to current instance of type does not denote a type (RM 8.6)
>>> error: reference to current instance of type does not denote a type (RM 8.6)
13. end Main;
(by the way, that’s the output of -gnatl, very helpful for reporting errors (if verbose))
I’d suggest testing this on the Ada equivalent that I posted before reporting it. As you have GNAT 15.0 and I don’t, I think you should file the ticket.
Just a side note, that everyone with an internet connection can try at least small things out on the most recent GCC using https://godbolt.org/
Use the x86-64 gnat (trunk) target
I’ve submitted quite a few PRs showing the results from godbolt and they have been received well. If you ever want to see the current version, then in the compiler switches section you can throw in a --version switch (you may first have to to do: Add new... into Execution Only from the menu to see the compiler output)
It’s also useful to see when a bug started as godbolt provides multiple versions to test (not all, but a lot).
And tip: The default filename godbolt uses is example.adb so you can highlight all the default crap and replace it with
I tried both anyway
This all-compiler tool is extra useful, thank you jere. I can’t bring myself to open and study several books at once, so I haven’t come to debugging and debugging tools, or much of the compiler and associated ecosystem beyond default switches and gnatmake/alr run, so I can’t help much here. But I’m sure I’ll enjoy it when I’ll be there.
File it, by all means.
I was referring to the use of pragma Extensions_Allowed, the half-constrained array type notation, and the use of 'Predicate`. Really, when using the GNAT extensions, you’re using an Ada-like language with semantics determined by AdaCore, so maybe the error message is correct in that case.
I’ve tried the Ada version with GNAT 15 on godbolt with the same results.
ObjectAda 10.5 compiles the Ada version without error.
What ? No, removing the extensions produces the same error. I had tried that.
pragma Ada_2012;
generic
type Element is private; -- assignment and equality predefined
package main is
type Data is record
X,Y: Positive;
E: Integer;
end record;
type ArrayInput is array (Positive range <>) of Data with Dynamic_Predicate => (for all I in 2..ArrayInput'Last => ArrayInput(I).X < ArrayInput(I-1).X or ArrayInput(I-1).Y < ArrayInput(I).Y);
end main;