From d036b2b8c29f8d53787417a1c0b0ddf814ab8b6b Mon Sep 17 00:00:00 2001 From: Hristian Kirtchev Date: Wed, 10 Jul 2019 09:02:31 +0000 Subject: [PATCH] [Ada] Spurious error on discriminant of incomplete type This patch corrects the conformance verification of discriminants to provide symmetry between the analysis of incomplete and full view discriminants. As a result, types of discriminants always resolve to the proper view. 2019-07-10 Hristian Kirtchev gcc/ada/ * sem_ch6.adb (Check_Discriminant_Conformance): Use Find_Type to discover the type of a full view discriminant. gcc/testsuite/ * gnat.dg/incomplete7.adb, gnat.dg/incomplete7.ads: New testcase. From-SVN: r273347 --- gcc/ada/ChangeLog | 5 +++++ gcc/ada/sem_ch6.adb | 2 +- gcc/testsuite/ChangeLog | 4 ++++ gcc/testsuite/gnat.dg/incomplete7.adb | 5 +++++ gcc/testsuite/gnat.dg/incomplete7.ads | 31 +++++++++++++++++++++++++++ 5 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gnat.dg/incomplete7.adb create mode 100644 gcc/testsuite/gnat.dg/incomplete7.ads diff --git a/gcc/ada/ChangeLog b/gcc/ada/ChangeLog index 246134c4192..86e35087f68 100644 --- a/gcc/ada/ChangeLog +++ b/gcc/ada/ChangeLog @@ -1,3 +1,8 @@ +2019-07-10 Hristian Kirtchev + + * sem_ch6.adb (Check_Discriminant_Conformance): Use Find_Type to + discover the type of a full view discriminant. + 2019-07-10 Arnaud Charlet * doc/gnat_ugn/gnat_and_program_execution.rst: Improve gnatmem's diff --git a/gcc/ada/sem_ch6.adb b/gcc/ada/sem_ch6.adb index e00cd57ea98..25ee7053ade 100644 --- a/gcc/ada/sem_ch6.adb +++ b/gcc/ada/sem_ch6.adb @@ -5960,7 +5960,7 @@ package body Sem_Ch6 is Access_Definition (N, Discriminant_Type (New_Discr)); else - Analyze (Discriminant_Type (New_Discr)); + Find_Type (Discriminant_Type (New_Discr)); New_Discr_Type := Etype (Discriminant_Type (New_Discr)); -- Ada 2005: if the discriminant definition carries a null diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 21c5e319c4f..b6588179ade 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2019-07-10 Hristian Kirtchev + + * gnat.dg/incomplete7.adb, gnat.dg/incomplete7.ads: New testcase. + 2019-07-10 Hristian Kirtchev * gnat.dg/limited2.adb, gnat.dg/limited2_pack_1.adb, diff --git a/gcc/testsuite/gnat.dg/incomplete7.adb b/gcc/testsuite/gnat.dg/incomplete7.adb new file mode 100644 index 00000000000..34accbe911e --- /dev/null +++ b/gcc/testsuite/gnat.dg/incomplete7.adb @@ -0,0 +1,5 @@ +-- { dg-do compile } + +package body Incomplete7 is + procedure Foo is null; +end Incomplete7; diff --git a/gcc/testsuite/gnat.dg/incomplete7.ads b/gcc/testsuite/gnat.dg/incomplete7.ads new file mode 100644 index 00000000000..3c1ade71179 --- /dev/null +++ b/gcc/testsuite/gnat.dg/incomplete7.ads @@ -0,0 +1,31 @@ +package Incomplete7 is + type Color; + type Color is (red, green, blue); + + type Action (C : Color := Color'(red)); + type Action (C : Color := Color'(red)) is record + case C is + when red => + Stop_Time : Positive; + + when others => + Go_For_It : Integer; + end case; + end record; + + type Num; + type Num is new Integer; + + type Rec (N : Num := Num'(1)); + type Rec (N : Num := Num'(1)) is record + case N is + when 1 => + One : Integer; + + when others => + null; + end case; + end record; + + procedure Foo; +end Incomplete7; -- 2.30.2