[Ada] Fix spurious ambiguity for if_expression containing operator
authorEric Botcazou <ebotcazou@adacore.com>
Wed, 2 Feb 2022 20:04:18 +0000 (21:04 +0100)
committerPierre-Marie de Rodat <derodat@adacore.com>
Wed, 11 May 2022 08:53:21 +0000 (08:53 +0000)
It comes from a discrepancy in the analysis of binary operators, between
the predefined ones for which we register an interpretation with the base
type and the user-defined ones for which we register an interpretation
with the subtype directly.

This is harmless in almost all cases because the two interpretations do not
differ by this type property only, but is problematic when the operation is
the dependent expression of a conditional expression, because it causes two
interpretations of the conditional expression to be registered, which this
time differ by this type property only, thus making them impossible to be
disambiguated later.

gcc/ada/

* sem_ch4.adb (Analyze_User_Defined_Binary_Op): Use the base type
in the interpretation of the operator.

gcc/ada/sem_ch4.adb

index c913e8b..ca8e1cd 100644 (file)
@@ -5934,7 +5934,7 @@ package body Sem_Ch4 is
            and then (Has_Compatible_Type (Right_Opnd (N), Etype (F2))
                       or else Etype (F2) = Any_Type)
          then
-            Add_One_Interp (N, Op_Id, Etype (Op_Id));
+            Add_One_Interp (N, Op_Id, Base_Type (Etype (Op_Id)));
 
             --  If the operands are overloaded, indicate that the current
             --  type is a viable candidate. This is redundant in most cases,