]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ada: Too-strict conformance checking for formal discriminated type
authorSteve Baird <baird@adacore.com>
Wed, 15 Nov 2023 21:13:04 +0000 (13:13 -0800)
committerMarc Poulhiès <poulhies@adacore.com>
Thu, 30 Nov 2023 10:12:46 +0000 (11:12 +0100)
The discriminant subtype conformance check for an actual parameter
corresponding to a generic formal discriminated type was too strict and
could incorrectly reject legal instantiations.

gcc/ada/

* sem_ch12.adb (Validate_Discriminated_Formal_Type): Replace
Entity_Id equality test with a call to Subtypes_Match. Distinct
subtypes which are statically matching should pass this test.
(Check_Discriminated_Formal): Replace Entity_Id equality test with
a call to Subtypes_Statically_Match (preceded by a check that the
preconditions for the call are satisfied).

gcc/ada/sem_ch12.adb

index 7c645c490aea495f70dea87bf45875b3709c6d19..ea85e88d753643b79ff5c9300c4f30c965d5129f 100644 (file)
@@ -14001,9 +14001,10 @@ package body Sem_Ch12 is
                     and then (Ekind (Base_Type (Etype (Actual_Discr)))) =
                                 E_Anonymous_Access_Type
                     and then
-                      Get_Instance_Of
-                        (Designated_Type (Base_Type (Formal_Subt))) =
-                           Designated_Type (Base_Type (Etype (Actual_Discr)))
+                      Subtypes_Match
+                        (Get_Instance_Of
+                           (Designated_Type (Base_Type (Formal_Subt))),
+                         Designated_Type (Base_Type (Etype (Actual_Discr))))
                   then
                      null;
 
@@ -17322,8 +17323,14 @@ package body Sem_Ch12 is
                     and then (Ekind (Base_Type (Etype (Actual_Discr)))) =
                                 E_Anonymous_Access_Type
                     and then
-                        Designated_Type (Base_Type (Formal_Subt)) =
-                           Designated_Type (Base_Type (Etype (Actual_Discr)))
+                        Base_Type
+                          (Designated_Type (Base_Type (Formal_Subt))) =
+                        Base_Type
+                          (Designated_Type (Base_Type (Etype (Actual_Discr))))
+                    and then
+                        Subtypes_Statically_Match
+                         (Designated_Type (Base_Type (Formal_Subt)),
+                          Designated_Type (Base_Type (Etype (Actual_Discr))))
                   then
                      null;