[Ada] Use uniform type resolution for membership tests

Pierre-Marie de Rodat derodat@adacore.com
Mon Jun 15 08:05:21 GMT 2020


This fixes an annoying discrepancy in the resolution of the type of
the elements of the choice list in a membership test.  Consider:

  Msg : String;

  if Msg not in "" | "bypass" then
    ...
  end if;

  if not (Msg in "" or else Msg in "bypass") then
    ...
  end if;

  function Func return String;
  function Func return Integer;

  if Func not in "" | "bypass" then
    ...
  end if;

In the former case, the type of the literals is resolved to the subtype
of Msg whereas, in the latter two cases, it is resolved to the base type.

Type resolution is a two-phase process here: first Analyze_Membership_Op
checks that the types (or the interpretations thereof) of the expression
and of all the elements of the choice list are compatible types; second,
Resolve_Membership_Op does the final resolution by picking a single type.

Resolve_Membership_Op invokes Intersect_Types to pick this single type,
which yields the base type in the case of strings, except in the former
case, where it directly uses the Etype of the left operand.

The change makes it so that Intersect_Types is invoked in all cases.

No functional changes.

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

2020-06-15  Eric Botcazou  <ebotcazou@adacore.com>

gcc/ada/

	* sem_res.adb (Resolve_Set_Membership): Remove local variable.
	In the non-overloaded case, call Intersect_Types on the left
	operand and the first alternative to get the resolution type.
	But test the subtype of the left operand to give the warning.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: patch.diff
Type: text/x-diff
Size: 3031 bytes
Desc: not available
URL: <https://gcc.gnu.org/pipermail/gcc-patches/attachments/20200615/252edda3/attachment-0001.bin>


More information about the Gcc-patches mailing list