Patchwork [Ada] Spurious error with overloaded operation and exponention operand

login
register
mail settings
Submitter Arnaud Charlet
Date Aug. 29, 2011, 1:48 p.m.
Message ID <20110829134855.GA15184@adacore.com>
Download mbox | patch
Permalink /patch/112056/
State New
Headers show

Comments

Arnaud Charlet - Aug. 29, 2011, 1:48 p.m.
This patch fixes a spurious error on an exponentation operand that has a
universal interpretation, when the parent node is overloaded and one of its
interpretations is a fixed-point type.

The following must compile quietly:

   gcc -c adt.adb

with Sim;
package adt is
   task type Cust;
end;

package sim is
   type Sim_Duration is new Duration delta 1.0 / 60.0;
   function "-"( x, y : sim_duration) return sim_duration;
   type LARGE_INTEGER is delta 1.0 range -2.0**63 .. 2.0**63 - 1.0;
end sim;

package body adt is
   task body Cust is
   begin
      null;
   end;
end;

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

2011-08-29  Ed Schonberg  <schonberg@adacore.com>

	* sem_res.adb (Resolve_Arithmetic_Op): If the node has a universal
	interpretation, set the type before resolving the operands, because
	legality checks on an exponention operand need to know the type of the
	context.

Patch

Index: sem_res.adb
===================================================================
--- sem_res.adb	(revision 178228)
+++ sem_res.adb	(working copy)
@@ -4640,13 +4640,16 @@ 
       --  universal real, since in this case we don't do a conversion to a
       --  specific fixed-point type (instead the expander handles the case).
 
+      --  Set the type of the node to its universal interpretation because
+      --  legality checks on an exponentiation operand need the context.
+
       elsif (B_Typ = Universal_Integer or else B_Typ = Universal_Real)
         and then Present (Universal_Interpretation (L))
         and then Present (Universal_Interpretation (R))
       then
+         Set_Etype (N, B_Typ);
          Resolve (L, Universal_Interpretation (L));
          Resolve (R, Universal_Interpretation (R));
-         Set_Etype (N, B_Typ);
 
       elsif (B_Typ = Universal_Real
               or else Etype (N) = Universal_Fixed