pragma Ada_2022;
with Ada.Text_IO;
procedure test1 is
hist1 : constant array(1..4) of Natural := [10,20,30,40];
x : constant float := float(hist1'Reduce("+",0));
begin
Ada.Text_IO.put_line("x: " & x'Image);
end test1;
When I compile, I get this message:
test1.adb:5:37: error: expected type universal integer
test1.adb:5:37: error: found type “Standard.Integer”
I’m pretty sure this is an implementation bug: Universal_Integer is a virtual/conceptual type (from which any integral type is derived/subtyped) that you cannot declare.
But I guess that by « it is not Ada », you mean « not original Ada ». Where should we put the bar between using strictly Ada83… and using new features.
Surely, the issue is also resolved with Integer'(0) instead of 0. I deduce the compiler claims it doesn’t want an (implicit) Standard.Integer… but is happy with an explicit Integer.
@pyj I don’t mean to complain about decade old decisions. I appreciate the quality of the Ada83 language design, and the inclusion of high level features like generics (C# and Java fail to include in the first versions !). However I think that there is a room for enhancement. Afterward, deciding if a new feature is worth been added can be subjective. Here we have more likely a bug of the implementation (gnat probably) which is different than a language design issue. But I have to admit that a 2022 feature is probably less well implemented than an earlier one.
@F-Loyer my comment wasn’t targeted at you at all, I quoted because I could see how someone might have gotten confused. Ada needs better tutorials and docs as demonstrated by difficulties of people trying to examine it. It’s disheartening to see people asking technical questions here and then the responses being increasingly more opining about the solution, than at accurately communicating it.
No, that’s the-other-way-'round: type-hinting to the compiler that the Universal_Integer that corresponds-with/-to and is literal 0 is, in fact, Integer. (Absent shadowing/scope, Standard.Integer.)
But it compiles like it. I was quite surprised since the error is about the compiler has found a Standard.Integer… (error: found type “Standard.Integer”) and with an explicit Integer, there is nothing wrong. Perhaps the error messages are exchanged.
Use Alire. It’s a package manager for GNAT and can download the correct GNAT version for you. Alire can also download cross compiler and Ada libraries. Alire is the way to go even if you don’t have a bug.
Nope, version 14 does not show up via toolchain, and
[[depends-on]]
gnat = ">=14"
in alire.toml just gives
gprconfig: can't find a native toolchain for language 'ada'
gprconfig: can't find a native toolchain for language 'ada'
test2.gpr:2:09: no compiler for language "Ada", cannot compile "test2_config.ads"
gprbuild: *** compilation phase failed
error: Command ["gprbuild", "-s", "-j0", "-p", "-P", "/home/reinert/test2/test2.gpr"] exited with code 4
error: Compilation failed.