4

In this page, John Barnes writes:

If the conditional expression is the argument of a type conversion then effectively the conversion is considered pushed down to the dependent expressions. Thus

X := Float(if P then A else B);

is equivalent to

X := (if P then Float(A) else Float(B));

So why can't I compile the following program under GNAT 10.3.0?

procedure Main is
   P : Boolean := True;
   X : Float;
begin
   X := Float (if P then 0.5 else 32);
end Main;
Compile
   [Ada]          main.adb
main.adb:5:35: expected a real type
main.adb:5:35: found type universal integer
gprbuild: *** compilation phase failed
Big Temp
  • 434
  • 4
  • 12

1 Answers1

4

Because you’ve found a long-standing error in the compiler! (same behaviour in GCC 12.1.0).

John Barnes’ justification is at AARM 4.5.7(10ff).


thanks for providing real code and the error messages!

Simon Wright
  • 25,108
  • 2
  • 35
  • 62