[Ada] Error message on invalid prefixed procedure call

Message ID 20210503092945.GA77599@adacore.com
State New
Headers show
Series
  • [Ada] Error message on invalid prefixed procedure call
Related show

Commit Message

Pierre-Marie de Rodat May 3, 2021, 9:29 a.m.
When the prefix of a call denotes an overloaded primitive operation, all
possible interpretations are analyzed to determine the intended one. If
all of them fail, then if the All_Errors flag is on all interpretations
are analyzed anew to indicate why each one is illegal. If All_Errors is
not set then only one interpretation is reanalyzed, which in rare cases
will fail to provide a meaningful error message. This patch adds the
required message and prevents the construction of an invalid tree.

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

gcc/ada/

	* sem_ch4.adb (Try_Object_Operation): When a prefixed call is
	overloaded and illegal, and the All_Errors flag is off, generate
	an error message if the re-analysis of some candidate
	interpretation fails to produce one.

Patch

diff --git a/gcc/ada/sem_ch4.adb b/gcc/ada/sem_ch4.adb
--- a/gcc/ada/sem_ch4.adb
+++ b/gcc/ada/sem_ch4.adb
@@ -10215,6 +10215,16 @@  package body Sem_Ch4 is
                Report     => True,
                Success    => Success,
                Skip_First => True);
+
+            --  The error may hot have been reported yet for overloaded
+            --  prefixed calls, depending on the non-matching candidate,
+            --  in which case provide a concise error now.
+
+            if Serious_Errors_Detected = 0 then
+               Error_Msg_NE
+                 ("cannot resolve prefixed call to primitive operation of&",
+                   N, Entity (Prefix (N)));
+            end if;
          end if;
 
          --  No need for further errors