diff mbox series

[Ada] Fix inadequate silencing of errors in expression functions

Message ID 20171020160754.GA9104@adacore.com
State New
Headers show
Series [Ada] Fix inadequate silencing of errors in expression functions | expand

Commit Message

Pierre-Marie de Rodat Oct. 20, 2017, 4:07 p.m. UTC
Errors where previously silenced on expression functions, which caused
some BUG BOX to be issued inside GNATprove, as the AST could be
ill-formed. Now fixed. There is no example code as this only has an effect
on GNATprove.

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

2017-10-20  Yannick Moy  <moy@adacore.com>

	* sem_ch6.adb (Analyze_Expression_Function.Freeze_Expr_Types): Remove
	inadequate silencing of errors.
	* sem_util.adb (Check_Part_Of_Reference): Do not issue an error when
	checking the subprogram body generated from an expression function,
	when this is done as part of the preanalysis done on expression
	functions, as the subprogram body may not yet be attached in the AST.
	The error if any will be issued later during the analysis of the body.
	(Is_Aliased_View): Trivial rewrite with Is_Formal_Object.
diff mbox series

Patch

Index: sem_ch6.adb
===================================================================
--- sem_ch6.adb	(revision 253938)
+++ sem_ch6.adb	(working copy)
@@ -442,18 +442,12 @@ 
       begin
          --  Preanalyze a duplicate of the expression to have available the
          --  minimum decoration needed to locate referenced unfrozen types
-         --  without adding any decoration to the function expression. This
-         --  preanalysis is performed with errors disabled to avoid reporting
-         --  spurious errors on Ghost entities (since the expression is not
-         --  fully analyzed).
+         --  without adding any decoration to the function expression.
 
          Push_Scope (Def_Id);
          Install_Formals (Def_Id);
-         Ignore_Errors_Enable := Ignore_Errors_Enable + 1;
 
          Preanalyze_Spec_Expression (Dup_Expr, Etype (Def_Id));
-
-         Ignore_Errors_Enable := Ignore_Errors_Enable - 1;
          End_Scope;
 
          --  Restore certain attributes of Def_Id since the preanalysis may
Index: sem_util.adb
===================================================================
--- sem_util.adb	(revision 253938)
+++ sem_util.adb	(working copy)
@@ -3354,10 +3354,13 @@ 
            and then not Comes_From_Source (Par)
          then
             --  Continue to examine the context if the reference appears in a
-            --  subprogram body which was previously an expression function.
+            --  subprogram body which was previously an expression function,
+            --  unless this is during preanalysis (when In_Spec_Expression is
+            --  True), as the body may not yet be inserted in the tree.
 
             if Nkind (Par) = N_Subprogram_Body
               and then Was_Expression_Function (Par)
+              and then not In_Spec_Expression
             then
                null;
 
@@ -12545,9 +12548,7 @@ 
                  or else (Present (Renamed_Object (E))
                            and then Is_Aliased_View (Renamed_Object (E)))))
 
-           or else ((Is_Formal (E)
-                      or else Ekind_In (E, E_Generic_In_Out_Parameter,
-                                           E_Generic_In_Parameter))
+           or else ((Is_Formal (E) or else Is_Formal_Object (E))
                     and then Is_Tagged_Type (Etype (E)))
 
            or else (Is_Concurrent_Type (E) and then In_Open_Scopes (E))