Skip to content

Misleading error message due to same signature definitions #11929

Open
@soronpo

Description

@soronpo

reproduction steps

Use the following code:

  trait TwoFaceInt[T] {
    type Out = T
  }
  object TwoFaceInt {
    def apply[T <: Int with Singleton](implicit value : T) : TwoFaceInt[T] = ???
    implicit def apply[T <: Int with Singleton](value : T) : TwoFaceInt[T] = ???
  }
  trait Fooish[T]
  class Foo {
    final def foo : Fooish[4] = ???
    final def foo[T](value : TwoFaceInt[T]) : Fooish[value.Out] = ???
  }
  val a = new Foo
  val b : Fooish[2] = a.foo(2)

problem

The error generated is very misleading:

Error: overloaded method value fooy with alternatives:
  [T](value: TwoFaceInt[T])Fooish[value.Out] <and>
  => Fooish[2]
 cannot be applied to (Int)
  val b : Fooish[2] = a.fooy(2)

It should be noted that if we remove final def foo : Fooish[4] = ???, no error would have been generated.

expectation

The actual source of the problem is that inside TwoFaceInt the two methods have the same signature.
In dotty we get an error as expected:

Double definition:
def apply: [T <: Int & Singleton](implicit value: T): TwoFaceInt[T] in object TwoFaceInt at line 10 and
implicit def apply: [T <: Int & Singleton](value: T): TwoFaceInt[T] in object TwoFaceInt at line 11
have the same type after erasure.

Metadata

Metadata

Assignees

No one assigned

    Labels

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

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions