[Ada] Spurious error on private type in ghost expression function

Message ID 20200619082834.GA31352@adacore.com
State New
Headers show
Series
  • [Ada] Spurious error on private type in ghost expression function
Related show

Commit Message

Pierre-Marie de Rodat June 19, 2020, 8:28 a.m.
The compiler rejects an expression function declared in a generic
package with Ghost aspect, when the expression of the function includes
a reference to a private type declared outside of the package, whose
full view has not yet been analyzed, and the Ghost mode is Ignore.

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

2020-06-19  Ed Schonberg  <schonberg@adacore.com>

gcc/ada/

	* sem_ch6.adb (Analyze_Expression_Function): Do not indicate
	that the function has a completion if it appears within a Ghost
	generic package.

Patch

--- gcc/ada/sem_ch6.adb
+++ gcc/ada/sem_ch6.adb
@@ -499,9 +499,14 @@  package body Sem_Ch6 is
          --  Within a generic preanalyze the original expression for name
          --  capture. The body is also generated but plays no role in
          --  this because it is not part of the original source.
+         --  If this is an ignored Ghost entity, analysis of the generated
+         --  body is needed to hide external references (as is done in
+         --  Analyze_Subprogram_Body) after which the the subprogram profile
+         --  can be frozen, which is needed to expand calls to such an ignored
+         --  Ghost subprogram.
 
          if Inside_A_Generic then
-            Set_Has_Completion (Def_Id);
+            Set_Has_Completion (Def_Id, not Is_Ignored_Ghost_Entity (Def_Id));
             Push_Scope (Def_Id);
             Install_Formals (Def_Id);
             Preanalyze_Spec_Expression (Expr, Etype (Def_Id));