[Ada] Enforce check on wrong usage names in aspect definitions

Message ID 20170912101627.GA9726@adacore.com
State New
Headers show
Series
  • [Ada] Enforce check on wrong usage names in aspect definitions
Related show

Commit Message

Arnaud Charlet Sept. 12, 2017, 10:16 a.m.
The frontend does not report an error on aspect clases defined in the
public part of a nested package that reference names defined in the
private part.

After this patch the error is reported on the following sources:

pragma Ada_2012;
with Ada.Text_IO;
use Ada.Text_IO;
procedure Small is
   package Pack is
      type T is tagged private
        with Constant_Indexing => F;   --  Error
   private
      function F
        (Obj : T; S : String; Pos : Positive) return Character;
      type T is tagged null record;
   end Pack;
   package body Pack is
      function F
        (Obj : T; S : String; Pos : Positive) return Character is
      begin
         return S (Pos);
      end F;
   end Pack;
   use Pack;
   V : T;
begin
   Put (V ("abcd", 1));
   Put (V ("abcd", 2));
   New_Line;
end;

Command: gcc -c small.adb
Output:
  small.adb:7:14: aspect must be fully defined before "T" is frozen
  small.adb:7:35: "F" is undefined

Tested on x86_64-pc-linux-gnu, committed on trunk

2017-09-12  Javier Miranda  <miranda@adacore.com>

	* sem_ch3.adb (Analyze_Declarations): In nested
	package declarations that have a private part enable missing check
	of the RM rule 13.1.1(11/3): usage names in aspect definitions are
	resolved at the end of the immediately enclosing declaration list.

Patch

Index: sem_ch3.adb
===================================================================
--- sem_ch3.adb	(revision 251998)
+++ sem_ch3.adb	(working copy)
@@ -2676,14 +2676,11 @@ 
               and then not Is_Child_Unit (Current_Scope)
               and then No (Generic_Parent (Parent (L)))
             then
-               --  This is needed in all cases to catch visibility errors in
-               --  aspect expressions, but several large user tests are now
-               --  rejected. Pending notification we restrict this call to
-               --  ASIS mode.
+               --  ARM rule 13.1.1(11/3): usage names in aspect definitions are
+               --  resolved at the end of the immediately enclosing declaration
+               --  list (AI05-0183-1).
 
-               if ASIS_Mode then
-                  Resolve_Aspects;
-               end if;
+               Resolve_Aspects;
 
             elsif L /= Visible_Declarations (Parent (L))
               or else No (Private_Declarations (Parent (L)))