public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r13-189] [Ada] Properly handle unprefixed references to components
@ 2022-05-09  9:31 Pierre-Marie de Rodat
  0 siblings, 0 replies; only message in thread
From: Pierre-Marie de Rodat @ 2022-05-09  9:31 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:ea7967ebdf76969a54a47dda96115c04057c4aba

commit r13-189-gea7967ebdf76969a54a47dda96115c04057c4aba
Author: Steve Baird <baird@adacore.com>
Date:   Wed Dec 15 15:13:39 2021 -0800

    [Ada] Properly handle unprefixed references to components
    
    In some cases, the compiler would incorrectly reject unprefixed uses of
    component names in an aspect specification for the composite type.
    Correct this error.
    
    gcc/ada/
    
            * sem_ch13.adb (Replace_Type_Ref): In the case of an identifier
            that names a component of the type, simplify the test to decide
            whether to build a prefix for it (the prefix denotes the current
            instance of the enclosing type): if the identifier doesn't
            already have a prefix, then give it one. This isn't quite right
            in the corner case of a quantified expression or some other such
            expression that declares an object with the same name as a
            component, but it is still an improvement.

Diff:
---
 gcc/ada/sem_ch13.adb | 33 ++++++++++++++++-----------------
 1 file changed, 16 insertions(+), 17 deletions(-)

diff --git a/gcc/ada/sem_ch13.adb b/gcc/ada/sem_ch13.adb
index 78415e666f4..b29b1db6ff1 100644
--- a/gcc/ada/sem_ch13.adb
+++ b/gcc/ada/sem_ch13.adb
@@ -15176,27 +15176,26 @@ package body Sem_Ch13 is
                end if;
 
                --  The components of the type are directly visible and can
-               --  be referenced without a prefix.
-
-               if Nkind (Parent (N)) = N_Selected_Component then
-                  null;
-
-               --  In expression C (I), C may be a directly visible function
-               --  or a visible component that has an array type. Disambiguate
-               --  by examining the component type.
+               --  be referenced in the source code without a prefix.
+               --  If a name denoting a component doesn't already have a
+               --  prefix, then normalize it by adding a reference to the
+               --  current instance of the type as a prefix.
+               --
+               --  This isn't right in the pathological corner case of an
+               --  object-declaring expression (e.g., a quantified expression
+               --  or a declare expression) that declares an object with the
+               --  same name as a visible component declaration, thereby hiding
+               --  the component within that expression. For example, given a
+               --  record with a Boolean component "C" and a dynamic predicate
+               --  "C = (for some C in Character => Some_Function (C))", only
+               --  the first of the two uses of C should have a prefix added
+               --  here; instead, both will get prefixes.
 
-               elsif Nkind (Parent (N)) = N_Indexed_Component
-                 and then N = Prefix (Parent (N))
+               if Nkind (Parent (N)) /= N_Selected_Component
+                 or else N /= Selector_Name (Parent (N))
                then
                   Comp := Visible_Component (Chars (N));
 
-                  if Present (Comp) and then Is_Array_Type (Etype (Comp)) then
-                     Add_Prefix (N, Comp);
-                  end if;
-
-               else
-                  Comp := Visible_Component (Chars (N));
-
                   if Present (Comp) then
                      Add_Prefix (N, Comp);
                   end if;


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-05-09  9:31 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-09  9:31 [gcc r13-189] [Ada] Properly handle unprefixed references to components Pierre-Marie de Rodat

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).