]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ada: Spurious errors on class-wide preconditions of private types
authorJavier Miranda <miranda@adacore.com>
Fri, 17 Feb 2023 18:57:07 +0000 (18:57 +0000)
committerMarc Poulhiès <poulhies@adacore.com>
Tue, 23 May 2023 07:59:05 +0000 (09:59 +0200)
The compiler reports spurious errors processing the class-wide
preconditions of a dispatching primitive of a private type T, when
the class-wide precondition invokes another dispatching primitive
of T that has the same name as a record component of T.

gcc/ada/

* sem_prag.adb (Analyze_Pre_Post_Condition_In_Decl_Part): Remove
call to preanalyze class-wide conditions since here it is too
early; they must be preanalyzed when full views of private types
have been analyzed.
* sem_ch7.adb (Analyze_Package_Specification): Preanalyze
class-wide conditions of dispatching primitives defined in nested
packages.

gcc/ada/sem_ch7.adb
gcc/ada/sem_prag.adb

index 2610a7bba4dda0ca9d47b63d266b1cefd24ea78b..aed09f30934fa1f0340f43e299ef3bd392dbede8 100644 (file)
@@ -1936,6 +1936,20 @@ package body Sem_Ch7 is
             end;
          end if;
 
+         --  Preanalyze class-wide conditions of dispatching primitives defined
+         --  in nested packages. For library packages, class-wide pre- and
+         --  postconditions are preanalyzed when the primitives are frozen
+         --  (see Merge_Class_Conditions); for nested packages, the end of the
+         --  package does not cause freezing (and hence they must be analyzed
+         --  now to ensure the correct visibility of referenced entities).
+
+         if not Is_Compilation_Unit (Id)
+           and then Is_Dispatching_Operation (E)
+           and then Present (Contract (E))
+         then
+            Preanalyze_Class_Conditions (E);
+         end if;
+
          Next_Entity (E);
       end loop;
 
index 234b02d7b72df4d3af0258b55c20b73e36bfb377..ca55a6f8290bf98b556460d494332f414a98b510 100644 (file)
@@ -26269,20 +26269,6 @@ package body Sem_Prag is
       Check_Postcondition_Use_In_Inlined_Subprogram (N, Spec_Id);
       Set_Is_Analyzed_Pragma (N);
 
-      --  If the subprogram is frozen then its class-wide pre- and post-
-      --  conditions have been preanalyzed (see Merge_Class_Conditions);
-      --  otherwise they must be preanalyzed now to ensure the correct
-      --  visibility of their referenced entities. This scenario occurs
-      --  when the subprogram is defined in a nested package (since the
-      --  end of the package does not cause freezing).
-
-      if Class_Present (N)
-        and then Is_Dispatching_Operation (Spec_Id)
-        and then not Is_Frozen (Spec_Id)
-      then
-         Preanalyze_Class_Conditions (Spec_Id);
-      end if;
-
       Restore_Ghost_Region (Saved_GM, Saved_IGR);
    end Analyze_Pre_Post_Condition_In_Decl_Part;