Skip to content

Ambiguous Overload when using default arguments with type parameters #7082

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
bishabosha opened this issue Aug 22, 2019 · 0 comments
Closed

Comments

@bishabosha
Copy link
Member

bishabosha commented Aug 22, 2019

minimized code

object Overloads {

  def foo[V](x: Int = 0, y: Int = 0, z: Int = 0): Nothing = ???

  def foo[V](x: Int, y: Int): Nothing = ???

  def foo[V](x: Int): Nothing = ???

  foo(1)

}

expectation

This compiles in Scala 2.13.0, but we have an error in Dotty (0.18.x on master), this would be an issue for porting Fastparse 2. It compiles in Dotty if we remove the type parameters on foo.

-- [E051] Reference Error: local/Overloads.scala:9:2 ---------------------------
9 |  foo(1)
  |  ^^^
  |Ambiguous overload. The overloaded alternatives of method foo in object Overloads with types
  | [V](x: Int): Nothing
  | [V](x: Int, y: Int): Nothing
  | [V](x: Int, y: Int, z: Int): Nothing
  |all match arguments (Int(1))

Explanation
===========
There are 3 methods that could be referenced as the compiler knows too little
about the expected type.
You may specify the expected type e.g. by
- assigning it to a value with a specified type, or
- adding a type ascription as in instance.myMethod: String => Int
@bishabosha bishabosha changed the title Ambiguous Overload when using default arguments Ambiguous Overload when using default arguments with type parameters Aug 22, 2019
@odersky odersky self-assigned this Aug 26, 2019
bishabosha added a commit that referenced this issue Aug 27, 2019
Fix #7082: Refine overloading resolution with default arguments
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

2 participants