[Ada] Handle explicit dereferences in expression functions

Message ID 20200707092736.GA41566@adacore.com
State New
Headers show
Series
  • [Ada] Handle explicit dereferences in expression functions
Related show

Commit Message

Pierre-Marie de Rodat July 7, 2020, 9:27 a.m.
An expression function that is a completion freezes the types that
appear in the expression. This includes the types of all entities
within. In most cases an access type does not freeze its designated
type, but implicit dereferences in a dispatching call do freeze the
designated type. Additionally, an explicit dereference also freezes the
corresponding designated type; this was not done previously.

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

gcc/ada/

	* freeze.adb (Freeze_Expr_Types): Freeze the designated type of
	the explicit dereference.

Patch

diff --git a/gcc/ada/freeze.adb b/gcc/ada/freeze.adb
--- a/gcc/ada/freeze.adb
+++ b/gcc/ada/freeze.adb
@@ -7934,6 +7934,15 @@  package body Freeze is
            and then Node = Controlling_Argument (Parent (Node))
          then
             Check_And_Freeze_Type (Designated_Type (Etype (Node)));
+
+         --  An explicit dereference freezes the designated type as well,
+         --  even though that type is not attached to an entity in the
+         --  expression.
+
+         elsif Nkind (Node) in N_Has_Etype
+           and then Nkind (Parent (Node)) = N_Explicit_Dereference
+         then
+            Check_And_Freeze_Type (Designated_Type (Etype (Node)));
          end if;
 
          --  No point in posting several errors on the same expression