Skip to content

New parameter type inference induces regression #11907

Open
@som-snytt

Description

@som-snytt

reproduction steps

trait T[-X, +Y] {
  def apply(x: X): Y
  def g[Z](t: T[Y, Z]): T[X, Z] = ???
  def g[Z](m: Y => Z): T[X, Z] = ???
  def f[W](t: T[W, X]): T[W, Y] = t.g(this)
}

problem

SO.scala:5: error: type mismatch;
 found   : T[X,Y]
 required: W => ?
  def f[W](t: T[W, X]): T[W, Y] = t.g(this)
                                      ^

expectation

By commenting out the apply method, overload resolution proceeds as expected.

Explicitly annotating t.g[Y](this) also works around the behavior.

Maybe if assisted type inference ("higher-order function type parameter inference") fails during overload resolution, it could fall back to the old behavior and type check with unexpected type and correspondingly low expectations.

Metadata

Metadata

Assignees

No one assigned

    Labels

    fixed in Scala 3This issue does not exist in the Scala 3 compiler (https://github.com/lampepfl/dotty/)inferoverloadingsam

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions