[Ada] Error not detected in illegal selected component
Arnaud Charlet
charlet@adacore.com
Wed Jun 11 12:29:00 GMT 2014
This patch corrects an error in the resolution of selected components when the
prefix is overloaded and none of the interpretations matches the context.
Compiling resolve_func_deref_comp.adb must yield:
resolve_func_deref_comp.adb:14:18:
no interpretation matches type access to "T" defined at line 12
resolve_func_deref_comp.adb:14:18:
expected type must be a general access type
--
procedure Resolve_Func_Deref_Comp is
type T is null record;
type Acc_T is access T;
type Rec is record
T_Comp : Acc_T;
end record;
type Acc_Rec is access all Rec;
function F return Integer is (0);
function F return Acc_Rec is (null);
begin
declare
Some_T : access T;
begin
Some_T := F.T_Comp;
end;
end Resolve_Func_Deref_Comp;
Tested on x86_64-pc-linux-gnu, committed on trunk
2014-06-11 Ed Schonberg <schonberg@adacore.com>
* sem_res.adb (Resolve_Selected_Component): Handle properly a
selected component whose prefix is overloaded, when none of the
interpretations matches the expected type.
-------------- next part --------------
Index: sem_res.adb
===================================================================
--- sem_res.adb (revision 211445)
+++ sem_res.adb (working copy)
@@ -9159,7 +9159,7 @@
Comp := First_Entity (T);
while Present (Comp) loop
if Chars (Comp) = Chars (S)
- and then Covers (Etype (Comp), Typ)
+ and then Covers (Typ, Etype (Comp))
then
if not Found then
Found := True;
@@ -9213,6 +9213,9 @@
Get_Next_Interp (I, It);
end loop Search;
+ -- There must be a legal interpreations at this point.
+
+ pragma Assert (Found);
Resolve (P, It1.Typ);
Set_Etype (N, Typ);
Set_Entity_With_Checks (S, Comp1);
@@ -9240,6 +9243,7 @@
if Is_Access_Type (Etype (P)) then
T := Designated_Type (Etype (P));
Check_Fully_Declared_Prefix (T, P);
+
else
T := Etype (P);
end if;
More information about the Gcc-patches
mailing list