]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ada: Spurious error on abstract primitive with access formals
authorsquirek <squirek@adacore.com>
Tue, 13 Aug 2024 12:06:52 +0000 (12:06 +0000)
committerMarc Poulhiès <dkm@gcc.gnu.org>
Tue, 12 Nov 2024 13:00:49 +0000 (14:00 +0100)
This patch fixes an issue in the compiler whereby using anonymous access
types as abstract overridden subprogram formals for a derived abtract type
may lead to compile-time errors.

gcc/ada/ChangeLog:

* accessibility.adb (Type_Access_Level): Add handling for
subprogram aliases.

gcc/ada/accessibility.adb

index 298103377a7bcc9f15ce0dc2bc49b87b4253a256..a4129819109d9ec94150cf89c79fd734f6927c81 100644 (file)
@@ -2331,7 +2331,20 @@ package body Accessibility is
          return Scope_Depth (Standard_Standard);
       end if;
 
-      return Scope_Depth (Enclosing_Dynamic_Scope (Btyp));
+      --  It is possible that the current scope is an aliased subprogram -
+      --  this can happen when an abstract primitive from a root type is not
+      --  not visible.
+
+      if Is_Subprogram (Enclosing_Dynamic_Scope (Btyp))
+        and then Present (Alias (Enclosing_Dynamic_Scope (Btyp)))
+      then
+         return Scope_Depth (Ultimate_Alias (Enclosing_Dynamic_Scope (Btyp)));
+
+      --  Otherwise, simply use the enclosing dynamic scope
+
+      else
+         return Scope_Depth (Enclosing_Dynamic_Scope (Btyp));
+      end if;
    end Type_Access_Level;
 
 end Accessibility;