Skip to content

ambiguous overload of two methods only in a certain combination with other apparently unrelated method #24871

@sjbiaga

Description

@sjbiaga

Compiler version

3.8.0-RC4

Minimized example

class C[T]

object X:
  def apply(xs: Int*)(d: Double) = Nil
  def apply[T](xs: Int*)(t: C[T])(d: Double) = Nil
  def apply()(d: Double) = List(List(d))
  def apply[T]()(t: C[T])(d: Double) = List(List(d))

for
  List(x) <- X()(.0)
yield
  x

Output Error/Warning message

-- [E051] Reference Error: -----------------------------------------------------
2 |  List(x) <- X()(.0)
  |             ^
  |Ambiguous overload. The overloaded alternatives of method apply in object X with types
  | ()(d: Double): List[List[Double]]
  | (xs: Int*)(d: Double): scala.collection.immutable.Nil.type
  |both match arguments ()((0.0d : Double))
  |
  | longer explanation available when compiling with `-explain`
1 error found

However, if the first apply method were commented out:

class C[T]

object X:
  //def apply(xs: Int*)(d: Double) = Nil
  def apply[T](xs: Int*)(t: C[T])(d: Double) = Nil
  def apply()(d: Double) = List(List(d))
  def apply[T]()(t: C[T])(d: Double) = List(List(d))

for
   List(x) <- X()(.0)
yield
   x

or the fourth apply method were commented out:

class C[T]

object X:
  def apply(xs: Int*)(d: Double) = Nil
  def apply[T](xs: Int*)(t: C[T])(d: Double) = Nil
  def apply()(d: Double) = List(List(d))
  //def apply[T]()(t: C[T])(d: Double) = List(List(d))

for
  List(x) <- X()(.0)
yield
  x

there would be no error. There is no error also if the first method were used instead:

class C[T]

object X:
  def apply(xs: Int*)(d: Double) = Nil
  def apply[T](xs: Int*)(t: C[T])(d: Double) = Nil
  def apply()(d: Double) = List(List(d))
  def apply[T]()(t: C[T])(d: Double) = List(List(d))

for
  List(x) <- X(1, 2, 3)(.0)
yield
  x

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:reportingError reporting including formatting, implicit suggestions, etcbetter-errorsIssues concerned with improving confusing/unhelpful diagnostic messagesitype:enhancement

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions