Skip to content

Overloading doesn't work with function types #7792

Closed
@anatoliykmetyuk

Description

@anatoliykmetyuk

minimized code

trait Foo {
  def g(f: Int => Int): Int = 1
  def g(f: String => String): String = "2"
}

@main def Test =
  val m: Foo = new Foo {}
  m.g(a => 1)
-- [E051] Reference Error: /Users/kmetiuk/Projects/scala3/pg/sandbox/iss4.scala:8:4
8 |  m.g(a => 1)
  |  ^^^
  |Ambiguous overload. The overloaded alternatives of method g in trait Foo with types
  | (f: String => String): String
  | (f: Int => Int): Int
  |both match arguments (? => ?)

It works in Scala 2. If you explicitly specify the type of the lambda argument, m.g((x: Int) => 1), it also works.

expectation

The code should correctly resolve the overload alternative.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions