]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
[Ada] Fix small oversight in latest change for Replace_Discriminants
authorEric Botcazou <ebotcazou@adacore.com>
Fri, 13 Dec 2019 15:57:46 +0000 (16:57 +0100)
committerPierre-Marie de Rodat <derodat@adacore.com>
Tue, 2 Jun 2020 08:58:07 +0000 (04:58 -0400)
2020-06-02  Eric Botcazou  <ebotcazou@adacore.com>

gcc/ada/

* sem_ch3.adb (Replace_Discriminants): Preserve the Etype of the
Name of N_Variant_Part nodes when rewriting it.

gcc/ada/sem_ch3.adb

index e792072b45f4a5cd322483e5a376aac7d945b096..3fa2dd8e7a1e7d0933329a4f9ccde96411ca739f 100644 (file)
@@ -22334,7 +22334,18 @@ package body Sem_Ch3 is
                if Original_Record_Component (Comp) = Entity (Name (N))
                  or else Chars (Comp) = Chars (Name (N))
                then
-                  Set_Name (N, New_Occurrence_Of (Comp, Sloc (N)));
+                  --  Make sure to preserve the type coming from the parent on
+                  --  the Name, even if the subtype of the discriminant can be
+                  --  constrained, so that discrete choices inherited from the
+                  --  parent in the variant part are not flagged as violating
+                  --  the constraints of the subtype.
+
+                  declare
+                     Typ : constant Entity_Id := Etype (Name (N));
+                  begin
+                     Rewrite (Name (N), New_Occurrence_Of (Comp, Sloc (N)));
+                     Set_Etype (Name (N), Typ);
+                  end;
                   exit;
                end if;