Skip to content

Commit

Permalink
Retract SynthesizeExtMethodReceiver mode when going deeper in overloa…
Browse files Browse the repository at this point in the history
…ding 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
  • Loading branch information
odersky committed Oct 23, 2023
1 parent 48bb59c commit edc4bc8
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
3 changes: 2 additions & 1 deletion compiler/src/dotty/tools/dotc/typer/Applications.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 13 additions & 0 deletions tests/pos/i18744.scala
Original file line number Diff line number Diff line change
@@ -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())
14 changes: 14 additions & 0 deletions tests/pos/i18745.scala
Original file line number Diff line number Diff line change
@@ -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))

0 comments on commit edc4bc8

Please sign in to comment.