From edc4bc88a4214f1353c292cc9931ac3b0cd5d147 Mon Sep 17 00:00:00 2001 From: odersky Date: Mon, 23 Oct 2023 14:57:14 +0200 Subject: [PATCH] Retract SynthesizeExtMethodReceiver mode when going deeper in overloading resolution The SynthesizeExtMethodReceiver mode is supposed to be turned on only for the direct application of of a synthesized receiver to the qualifier of an extension method selection. previously its lifetime was accidentally extended when overloading resolution looking at subsequent parameter lists because the first one was not enough to disambiguate. Fixes #18745 Fixes #18744 --- .../src/dotty/tools/dotc/typer/Applications.scala | 3 ++- tests/pos/i18744.scala | 13 +++++++++++++ tests/pos/i18745.scala | 14 ++++++++++++++ 3 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 tests/pos/i18744.scala create mode 100644 tests/pos/i18745.scala diff --git a/compiler/src/dotty/tools/dotc/typer/Applications.scala b/compiler/src/dotty/tools/dotc/typer/Applications.scala index 9501e51aeb6f..79c0d2a2b7b1 100644 --- a/compiler/src/dotty/tools/dotc/typer/Applications.scala +++ b/compiler/src/dotty/tools/dotc/typer/Applications.scala @@ -2219,7 +2219,8 @@ trait Applications extends Compatibility { } val mapped = reverseMapping.map(_._1) overload.println(i"resolve mapped: ${mapped.map(_.widen)}%, % with $pt") - resolveOverloaded(mapped, pt).map(reverseMapping.toMap) + resolveOverloaded(mapped, pt)(using ctx.retractMode(Mode.SynthesizeExtMethodReceiver)) + .map(reverseMapping.toMap) /** Try to typecheck any arguments in `pt` that are function values missing a * parameter type. If the formal parameter types corresponding to a closure argument diff --git a/tests/pos/i18744.scala b/tests/pos/i18744.scala new file mode 100644 index 000000000000..6e2d630c52b8 --- /dev/null +++ b/tests/pos/i18744.scala @@ -0,0 +1,13 @@ +package dotty.tools.dotc.typer + +object Color: + def apply(): Int = ??? + +extension (u: Unit) + def foo(that: String, f: Int => Int): Int = ??? + def foo(that: Long, f: Int => Int): Int = ??? + +def test = + val c = Color() + ().foo("", (_: Int) => c) + ().foo("", (_: Int) => Color()) \ No newline at end of file diff --git a/tests/pos/i18745.scala b/tests/pos/i18745.scala new file mode 100644 index 000000000000..2184acc4770f --- /dev/null +++ b/tests/pos/i18745.scala @@ -0,0 +1,14 @@ +object Color: + def apply(i: Int): Int = i + +type Plane + +object Plane: + extension (plane: Plane) + def zipWith(that: String, f: Int => Int): Int = ??? + def zipWith(that: Int, f: Int => Int): Int = ??? + +import Plane.zipWith + +def test(p: Plane) = + p.zipWith("", (_: Int) => Color(25)) \ No newline at end of file