Skip to content

Overloading resolution incorrectly drops alternative with match type result when a target type is provided #21410

Closed
@smarter

Description

@smarter

Compiler version

a2c53a1

Minimized code

(Minimized from the two map methods in https://github.com/aherlihy/tyql/blob/10401e8162f59543a6fe1b960d449f72c409612a/src/main/scala/repro/overloadedmap.scala that lead to q2 not compiling).

object Test:
  def foo[T](x: Option[T]): T = ???
  def foo[T <: Tuple](x: T): Tuple.Map[T, List] = ???

  val tup: (Int, String) = (1, "")

  val x = foo(tup)
  val y: (List[Int], List[String]) = x

  val x2: (List[Int], List[String]) = foo(tup) // error

Output

10 |  val x2: (List[Int], List[String]) = foo(tup)
   |                                          ^^^
   |                             Found:    (Test.tup : (Int, String))
   |                             Required: Option[(List[Int], List[String])]

Expectation

x2 should behave like x: overloading resolution should end up using the second overload since the first is clearly not appicable.

The overloading changes in #20054 do not have an impact on this issue (/cc @EugeneFlesselle).

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions