aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRonan Desplanques <desplanques@adacore.com>2025-04-04 10:31:27 +0200
committerEric Botcazou <ebotcazou@adacore.com>2025-06-12 13:03:10 +0200
commit3a4d64e1a81da321ecfda326fa541f3ea9bd6c5b (patch)
treebbaa6dbdc23457c4cffab495b07da8fc382def9f
parent67c494899585c26427dee8e9f562b87b7e502390 (diff)
downloadgcc-3a4d64e1a81da321ecfda326fa541f3ea9bd6c5b.zip
gcc-3a4d64e1a81da321ecfda326fa541f3ea9bd6c5b.tar.gz
gcc-3a4d64e1a81da321ecfda326fa541f3ea9bd6c5b.tar.bz2
ada: Fix wrong visibility over discriminants
This patch fixes an issue where the compiler was incorrectly allowing references to discriminants of the ancestor type in private type extensions. gcc/ada/ChangeLog: * sem_ch3.adb (Build_Derived_Private_Type): Fix test. (Build_Derived_Record_Type): Adjust error recovery paths.
-rw-r--r--gcc/ada/sem_ch3.adb16
1 files changed, 12 insertions, 4 deletions
diff --git a/gcc/ada/sem_ch3.adb b/gcc/ada/sem_ch3.adb
index 9a25ff7..e94b043 100644
--- a/gcc/ada/sem_ch3.adb
+++ b/gcc/ada/sem_ch3.adb
@@ -8488,11 +8488,19 @@ package body Sem_Ch3 is
Analyze (Decl);
- pragma Assert (Has_Discriminants (Full_Der)
- and then not Has_Unknown_Discriminants (Full_Der));
+ pragma
+ Assert
+ ((Has_Discriminants (Full_Der)
+ and then not Has_Unknown_Discriminants (Full_Der))
+ or else Serious_Errors_Detected > 0);
Uninstall_Declarations (Par_Scope);
+ if Etype (Full_Der) = Any_Type then
+ pragma Assert (Serious_Errors_Detected > 0);
+ return;
+ end if;
+
-- Freeze the underlying record view, to prevent generation of
-- useless dispatching information, which is simply shared with
-- the real derived type.
@@ -9457,8 +9465,8 @@ package body Sem_Ch3 is
if Constraint_Present then
if not Has_Discriminants (Parent_Base)
or else
- (Has_Unknown_Discriminants (Parent_Base)
- and then Is_Private_Type (Parent_Base))
+ (Has_Unknown_Discriminants (Parent_Type)
+ and then Is_Private_Type (Parent_Type))
then
Error_Msg_N
("invalid constraint: type has no discriminant",