diff mbox

[Ada] Crash on overloaded function call with limited view

Message ID 20161012123415.GA119495@adacore.com
State New
Headers show

Commit Message

Arnaud Charlet Oct. 12, 2016, 12:34 p.m. UTC
This patch fixes a compiler abort on a call that is initially overloaded,
when the resolved function returns the limited view of a type.

The folllowing must compile quietly:

   gcc -c p.adb

---
with R;

package body P is

   function Get (A : Q.Ptr) return Integer is
   begin
      return R.Conv (A.Get);
   end;

end P;
---
with Q;

package P is

   function Get (A : Q.Ptr) return Integer;

end P;
---
limited with R;

package Q is

   type Int1 is limited interface;

   function Get (Self : access Int1) return Integer is abstract;

   type Int2 is limited interface and Int1;

   function Get (Self : access Int2) return R.Rec2 is abstract;

   type Ptr is access all Int2'Class;

end Q;
---
package R is

   type Rec1 is tagged null record;

   function Conv (Item : Rec1) return Integer;

   type Rec2 is new Rec1 with null record;

end R;

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

2016-10-12  Ed Schonberg  <schonberg@adacore.com>

	* sem_res.adb (Resolve_Call): If a function call returns a
	limited view of a type replace it with the non-limited view,
	which must be available when compiling call.  This was already
	done elsewhere for non-overloaded calls, but needs to be done
	after resolution if function name is overloaded.
diff mbox

Patch

Index: sem_res.adb
===================================================================
--- sem_res.adb	(revision 241024)
+++ sem_res.adb	(working copy)
@@ -6034,6 +6034,15 @@ 
          end;
 
       else
+         --  If the function returns the limited view of type, the call must
+         --  appear in a context in which the non-limited view is available.
+         --  As is done in Try_Object_Operation, use the available view to
+         --  prevent back-end confusion.
+
+         if From_Limited_With (Etype (Nam)) then
+            Set_Etype (Nam, Available_View (Etype (Nam)));
+         end if;
+
          Set_Etype (N, Etype (Nam));
       end if;