Skip to content

Ambiguous overload: false detection #16618

Open
@satorg

Description

@satorg

Compiler version

Scala 3.2.1

Minimized code

case class Foo[A](a: A) {
  def bar(aa: A): Boolean = a == aa
  def bar(that: Foo[A]) = a == that.a
}

object Test {
  Foo(123).bar(Foo(456))
}

Output

The snippet compiles just fine on 2.12.17 and 2.13.9, but fails to compile on 3.2.1 with the following error:

7 |  Foo(123).bar(Foo(456))
  |  ^^^^^^^^^^^^
  |Ambiguous overload. The overloaded alternatives of method bar in class Foo with types
  | (that: Foo[A]): Boolean
  | (aa: A): Boolean
  |both match arguments (Foo[A])

However, if I change the Test object this way:

object Test {
  val foo123 = Foo(123)
  foo123.bar(Foo(456))
}

then it compiles on 3.2.1 without any error as well.

Expectation

Both cases should compile on 3.2.1.

Notes

May be similar to #14582 and #16067.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions