Skip to content

Commit edc4bc8

Browse files
committed
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
1 parent 48bb59c commit edc4bc8

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed

compiler/src/dotty/tools/dotc/typer/Applications.scala

+2-1
Original file line numberDiff line numberDiff line change
@@ -2219,7 +2219,8 @@ trait Applications extends Compatibility {
22192219
}
22202220
val mapped = reverseMapping.map(_._1)
22212221
overload.println(i"resolve mapped: ${mapped.map(_.widen)}%, % with $pt")
2222-
resolveOverloaded(mapped, pt).map(reverseMapping.toMap)
2222+
resolveOverloaded(mapped, pt)(using ctx.retractMode(Mode.SynthesizeExtMethodReceiver))
2223+
.map(reverseMapping.toMap)
22232224

22242225
/** Try to typecheck any arguments in `pt` that are function values missing a
22252226
* parameter type. If the formal parameter types corresponding to a closure argument

tests/pos/i18744.scala

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package dotty.tools.dotc.typer
2+
3+
object Color:
4+
def apply(): Int = ???
5+
6+
extension (u: Unit)
7+
def foo(that: String, f: Int => Int): Int = ???
8+
def foo(that: Long, f: Int => Int): Int = ???
9+
10+
def test =
11+
val c = Color()
12+
().foo("", (_: Int) => c)
13+
().foo("", (_: Int) => Color())

tests/pos/i18745.scala

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
object Color:
2+
def apply(i: Int): Int = i
3+
4+
type Plane
5+
6+
object Plane:
7+
extension (plane: Plane)
8+
def zipWith(that: String, f: Int => Int): Int = ???
9+
def zipWith(that: Int, f: Int => Int): Int = ???
10+
11+
import Plane.zipWith
12+
13+
def test(p: Plane) =
14+
p.zipWith("", (_: Int) => Color(25))

0 commit comments

Comments
 (0)