Skip to content

Commit e498ccc

Browse files
oderskyWojciechMazur
authored andcommitted
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 [Cherry-picked edc4bc8]
1 parent 0bed02b commit e498ccc

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
@@ -2212,7 +2212,8 @@ trait Applications extends Compatibility {
22122212
}
22132213
val mapped = reverseMapping.map(_._1)
22142214
overload.println(i"resolve mapped: ${mapped.map(_.widen)}%, % with $pt")
2215-
resolveOverloaded(mapped, pt).map(reverseMapping.toMap)
2215+
resolveOverloaded(mapped, pt)(using ctx.retractMode(Mode.SynthesizeExtMethodReceiver))
2216+
.map(reverseMapping.toMap)
22162217

22172218
/** Try to typecheck any arguments in `pt` that are function values missing a
22182219
* 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)