diff options
author | Javier Miranda <miranda@adacore.com> | 2024-06-10 17:17:59 +0000 |
---|---|---|
committer | Marc Poulhiès <dkm@gcc.gnu.org> | 2024-06-27 10:19:13 +0200 |
commit | fdbc04d13f0e993ecf1a36680c8f7768dfb522fb (patch) | |
tree | e7ede7010d2a1d20d5162448ea227a1c86179f9c /gcc/ada/sem_ch2.adb | |
parent | d4c990759bcdc1f2b3384397cae6d8cb76a4cdad (diff) | |
download | gcc-fdbc04d13f0e993ecf1a36680c8f7768dfb522fb.zip gcc-fdbc04d13f0e993ecf1a36680c8f7768dfb522fb.tar.gz gcc-fdbc04d13f0e993ecf1a36680c8f7768dfb522fb.tar.bz2 |
ada: Reject ambiguous function calls in interpolated string expressions
gcc/ada/
* sem_ch2.adb (Analyze_Interpolated_String_Literal): Report
interpretations of ambiguous parameterless function calls.
Diffstat (limited to 'gcc/ada/sem_ch2.adb')
-rw-r--r-- | gcc/ada/sem_ch2.adb | 80 |
1 files changed, 79 insertions, 1 deletions
diff --git a/gcc/ada/sem_ch2.adb b/gcc/ada/sem_ch2.adb index 08cc75c..ddbb329 100644 --- a/gcc/ada/sem_ch2.adb +++ b/gcc/ada/sem_ch2.adb @@ -38,6 +38,8 @@ with Rident; use Rident; with Sem; use Sem; with Sem_Ch8; use Sem_Ch8; with Sem_Dim; use Sem_Dim; +with Sem_Res; use Sem_Res; +with Sem_Type; use Sem_Type; with Sinfo; use Sinfo; with Sinfo.Nodes; use Sinfo.Nodes; with Sinfo.Utils; use Sinfo.Utils; @@ -135,20 +137,96 @@ package body Sem_Ch2 is ----------------------------------------- procedure Analyze_Interpolated_String_Literal (N : Node_Id) is + + procedure Check_Ambiguous_Parameterless_Call (Func_Call : Node_Id); + -- Examine the interpretations of the call to the given parameterless + -- function call and report the location of each interpretation. + + ---------------------------------------- + -- Check_Ambiguous_Parameterless_Call -- + ---------------------------------------- + + procedure Check_Ambiguous_Parameterless_Call (Func_Call : Node_Id) is + + procedure Report_Interpretation (E : Entity_Id); + -- Report an interpretation of the function call + + --------------------------- + -- Report_Interpretation -- + --------------------------- + + procedure Report_Interpretation (E : Entity_Id) is + begin + Error_Msg_Sloc := Sloc (E); + + if Nkind (Parent (E)) = N_Full_Type_Declaration then + Error_Msg_N ("interpretation (inherited) #!", Func_Call); + else + Error_Msg_N ("interpretation #!", Func_Call); + end if; + end Report_Interpretation; + + -- Local variables + + Error_Reported : Boolean; + I : Interp_Index; + It : Interp; + + -- Start of processing for Check_Ambiguous_Parameterless_Call + + begin + Error_Reported := False; + + -- Examine possible interpretations + + Get_First_Interp (Name (Func_Call), I, It); + while Present (It.Nam) loop + if It.Nam /= Entity (Name (Func_Call)) + and then Ekind (It.Nam) = E_Function + and then No (First_Formal (It.Nam)) + then + if not Error_Reported then + Error_Msg_NE + ("ambiguous call to&", Func_Call, + Entity (Name (Func_Call))); + Report_Interpretation (Entity (Name (Func_Call))); + Error_Reported := True; + end if; + + Report_Interpretation (It.Nam); + end if; + + Get_Next_Interp (I, It); + end loop; + end Check_Ambiguous_Parameterless_Call; + + -- Local variables + Str_Elem : Node_Id; + -- Start of processing for Analyze_Interpolated_String_Literal + begin Set_Etype (N, Any_String); Str_Elem := First (Expressions (N)); while Present (Str_Elem) loop + + -- Before analyzed, a function call that has parameter is an + -- N_Indexed_Component node, and a call to a function that has + -- no parameters is an N_Identifier node. + Analyze (Str_Elem); + -- After analyzed, if it is still an N_Identifier node then we + -- found ambiguity and could not rewrite it as N_Function_Call. + if Nkind (Str_Elem) = N_Identifier and then Ekind (Entity (Str_Elem)) = E_Function and then Is_Overloaded (Str_Elem) then - Error_Msg_NE ("ambiguous call to&", Str_Elem, Entity (Str_Elem)); + Check_Parameterless_Call (Str_Elem); + Check_Ambiguous_Parameterless_Call (Str_Elem); end if; Next (Str_Elem); |