Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Type conversions and if expressions

Tags:

ada

ada2012

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
like image 913
Big Temp Avatar asked Oct 18 '25 12:10

Big Temp


1 Answers

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!

like image 104
Simon Wright Avatar answered Oct 22 '25 08:10

Simon Wright



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!