This adds a missing guard before accessing the Underlying_Record_View field.

Tested on x86-64/Linux, applied on the mainline.


2025-07-14  Eric Botcazou  <ebotca...@adacore.com>

        PR ada/121056
        * sem_ch4.adb (Try_Object_Operation.Try_Primitive_Operation): Add
        test on Is_Record_Type before accessing Underlying_Record_View.


2025-07-14  Eric Botcazou  <ebotca...@adacore.com>

        * gnat.dg/deref4.adb: New test.
        * gnat.dg/deref4_pkg.ads: New helper.

-- 
Eric Botcazou
diff --git a/gcc/ada/sem_ch4.adb b/gcc/ada/sem_ch4.adb
index dc814676675..56dc7c6355c 100644
--- a/gcc/ada/sem_ch4.adb
+++ b/gcc/ada/sem_ch4.adb
@@ -10692,6 +10692,7 @@ package body Sem_Ch4 is
 
               or else
                 (Has_Unknown_Discriminants (Typ)
+                  and then Is_Record_Type (Base_Type (Obj_Type))
                   and then Typ = Underlying_Record_View (Base_Type (Obj_Type)))
 
                --  Prefix can be dereferenced
-- { dg-do compile }
-- { dg-options "-gnatX" }

with Deref4_Pkg; use Deref4_Pkg;

procedure Deref4 is
begin
  Obj.Proc (null);
end;
package Deref4_Pkg is

  type A is tagged null record;
  type A_Ptr is access A;
  procedure Proc (This : in out A'Class; Some_Parameter : A_Ptr) is null;
  Obj : A_Ptr;

end Deref4_Pkg;

Reply via email to