diff mbox

[Ada] Spurious error in if_expression with universal then_expression

Message ID 20160420090512.GA123172@adacore.com
State New
Headers show

Commit Message

Arnaud Charlet April 20, 2016, 9:05 a.m. UTC
If the first branch of an if-expression is a literal, remaining expressions
can resolve to any integer type (or any real type depending on the literal).

Tested in ACATS 4.0J test B457007

Tested on x86_64-pc-linux-gnu, committed on trunk

2016-04-20  Ed Schonberg  <schonberg@adacore.com>

	* sem_res.adb (Resolve_If_Expression): If first expression is
	universal, resolve subsequent ones with the corresponding class
	type (Any_Integer or Any_Real).
diff mbox

Patch

Index: sem_res.adb
===================================================================
--- sem_res.adb	(revision 235200)
+++ sem_res.adb	(working copy)
@@ -8048,9 +8048,19 @@ 
       end if;
 
       --  If ELSE expression present, just resolve using the determined type
+      --  If type is universal, resolve to any member of the class.
 
       if Present (Else_Expr) then
-         Resolve (Else_Expr, Typ);
+         if Typ = Universal_Integer then
+            Resolve (Else_Expr, Any_Integer);
+
+         elsif Typ = Universal_Real then
+            Resolve (Else_Expr, Any_Real);
+
+         else
+            Resolve (Else_Expr, Typ);
+         end if;
+
          Else_Typ := Etype (Else_Expr);
 
          if Is_Scalar_Type (Else_Typ) and then Else_Typ /= Typ then