public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r15-242] ada: Fix bug in overloaded selected_components in aspect_specifications
@ 2024-05-07  7:58 Marc Poulhi?s
  0 siblings, 0 replies; only message in thread
From: Marc Poulhi?s @ 2024-05-07  7:58 UTC (permalink / raw)
  To: gcc-cvs

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

commit r15-242-gd4b41cc4b02e365fc749dc90975af4d2360a8fb3
Author: Bob Duff <duff@adacore.com>
Date:   Fri Jan 5 10:40:00 2024 -0500

    ada: Fix bug in overloaded selected_components in aspect_specifications
    
    This patch fixes a bug where if a selected_component X.Y appears in an
    aspect_specification, and there are two or more overloaded Y's in X,
    then it can choose the wrong one, leading to subsequent type errors.
    It was always picking the last declaration of Y, and leaving Entity
    set to that. We now reset Entity (as for the already-existing code
    for N_Identifier just below).
    
    Note that Resolve_Aspect_Expressions is called only for
    aspect_specifications, and not even all aspect_specifications,
    so the bug didn't occur for other names. For example,
    Resolve_Aspect_Expressions is not called for aspect_specifications
    in the visible part of a library package if there is no private part.
    
    gcc/ada/
    
            * sem_ch13.adb (Resolve_Name): This is called only for names in
            aspect_specifications. If the name is an overloaded
            selected_component, reset the Entity. Note that this was already
            done for N_Identifier in the code just below.

Diff:
---
 gcc/ada/sem_ch13.adb | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/gcc/ada/sem_ch13.adb b/gcc/ada/sem_ch13.adb
index ed0e61bd7b2..c16a7710594 100644
--- a/gcc/ada/sem_ch13.adb
+++ b/gcc/ada/sem_ch13.adb
@@ -15925,12 +15925,20 @@ package body Sem_Ch13 is
               and then Chars (Prefix (N)) /= Chars (E)
             then
                Find_Selected_Component (N);
+
+               --  Reset the Entity if N is overloaded since the entity might
+               --  not be the correct one; allow later resolution to set it
+               --  properly.
+
+               if Is_Overloaded (N) then
+                  Set_Entity (N, Empty);
+               end if;
             end if;
 
             return Skip;
 
-         --  Resolve identifiers that are not selectors in parameter
-         --  associations (these are never resolved by visibility).
+         --  Resolve identifiers, but not selectors in parameter associations;
+         --  the selectors are never resolved by visibility.
 
          elsif Nkind (N) = N_Identifier
            and then Chars (N) /= Chars (E)
@@ -15939,8 +15947,7 @@ package body Sem_Ch13 is
          then
             Find_Direct_Name (N);
 
-            --  Reset the Entity if N is overloaded since the entity may not
-            --  be the correct one.
+            --  Reset the Entity as above for selected_components
 
             if Is_Overloaded (N) then
                Set_Entity (N, Empty);

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

only message in thread, other threads:[~2024-05-07  7:58 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-05-07  7:58 [gcc r15-242] ada: Fix bug in overloaded selected_components in aspect_specifications Marc Poulhi?s

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).