[Ada] Name resolution of class-wide operations with prefix notation
Arnaud Charlet
charlet@adacore.com
Thu Aug 4 13:06:00 GMT 2011
When resolving a prefixed call with class-wide actuals, we iterate over the
class-wide operations of all ancestors of the controlling type. If the context
is a function call any overloading is resolved by context. if the context is
a procedure call there must be only one candidate interpretation, and functions
must be excluded from the list of candidates.
The following must compile quietly:
---
with P;
procedure Test is
A : P.T;
begin
if A.X then
A.X;
end if;
end Test;
---
package P is
type T is tagged null record;
function X (Self : T'Class) return Boolean;
procedure X (Self : T'Class);
end P;
Tested on x86_64-pc-linux-gnu, committed on trunk
2011-08-04 Ed Schonberg <schonberg@adacore.com>
* sem_ch4.adb (Try_Class_Wide_Operation): if the context is a procedure
call, ignore functions.
-------------- next part --------------
Index: sem_ch4.adb
===================================================================
--- sem_ch4.adb (revision 177353)
+++ sem_ch4.adb (working copy)
@@ -6866,6 +6866,16 @@
(Designated_Type (Etype (First_Formal (Hom)))) =
Cls_Type))
then
+ -- If the context is a procedure call, ignore functions
+ -- in the name of the call.
+
+ if Ekind (Hom) = E_Function
+ and then Nkind (Parent (N)) = N_Procedure_Call_Statement
+ and then N = Name (Parent (N))
+ then
+ goto Next_Hom;
+ end if;
+
Set_Etype (Call_Node, Any_Type);
Set_Is_Overloaded (Call_Node, False);
Success := False;
@@ -6907,7 +6917,8 @@
end if;
end if;
- Hom := Homonym (Hom);
+ <<Next_Hom>>
+ Hom := Homonym (Hom);
end loop;
end Traverse_Homonyms;
More information about the Gcc-patches
mailing list