Skip to content

Can't select correct overloaded method with varargs and Seq #9050

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Arthurm1 opened this issue May 26, 2020 · 2 comments
Closed

Can't select correct overloaded method with varargs and Seq #9050

Arthurm1 opened this issue May 26, 2020 · 2 comments

Comments

@Arthurm1
Copy link

Using Scastie - this compiles on Scala 2.13.2 but not Dotty (0.24.0-RC1)

Minimized code

object Foo {
  val foo = scala.collection.mutable.ArrayBuffer.empty[Seq[Double]]
  val bar = Seq.empty[Double]
  foo.append(bar)
}

Output

cannot merge
  method append in trait Buffer of type (elems: A*): (Buffer.this : scala.collection.mutable.Buffer[A])  and
  method append in trait Buffer of type (elem: A): (Buffer.this : scala.collection.mutable.Buffer[A])
they are both defined in trait Buffer but have matching signatures
  (elems: Seq[Double]*): 
  (Foo.foo : scala.collection.mutable.ArrayBuffer[Seq[Double]]) and
  (elem: Seq[Double]): 
  (Foo.foo : scala.collection.mutable.ArrayBuffer[Seq[Double]])
as members of value foo

Expectation

For Dotty to pick the non-varargs method.

@smarter
Copy link
Member

smarter commented May 26, 2020

@odersky This looks like a non-trivial limitation of the usage of signatures for overload resolution, the signature of the Buffer#append methods are:

def append(elem: A): this.type
def append(elems: A*): this.type

As seen from a preifx of type ArrayBuffer[Seq[A]] we get:

def append(elem: Seq[A]): this.type
def append(elems: Seq[A]*): this.type

Those have the same signatures, but are otherwise unrelated. It would be good to figure out how to deal with this sooner rather than later since tasty critically relies on signatures for overload resolution.

This is the inverse of the problem detailed in #8929

@odersky
Copy link
Contributor

odersky commented May 27, 2020

I'd argue it's the wrong design. Buffer.append should have these signatures:

def append(elem: A): this.type
def append(elem: A, elems: A*): this.type

But it's true we will need to see how we can deal with it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants