Skip to content

Bad interaction between overloading, default arguments and implicit search #3352

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
allanrenucci opened this issue Oct 19, 2017 · 0 comments
Closed

Comments

@allanrenucci
Copy link
Contributor

This code snippet does not compile with Dotty:

class Test {
  class Foo {
    def bar(x: String): Int = 1
  }

  implicit class FooOps(foo: Foo) {
    def bar(x: Int, y: Int = 2): Int = 2 // compiles with no default argument
  }

  def test(foo: Foo): Unit = {
    foo.bar(1)
  }
}
[info] Running dotty.tools.dotc.Main -d out Test.scala -classpath dotty-library_2.12-0.5.0-bin-SNAPSHOT-nonbootstrapped.jar
-- [E007] Type Mismatch Error: tests/allan/Test.scala:23:12 --------------------
23 |    foo.bar(1)
   |            ^
   |            found:    Int(1)
   |            required: String
   |

Maybe related to #3168

allanrenucci referenced this issue in dotty-staging/better-files Oct 19, 2017
liufengyun added a commit to dotty-staging/dotty that referenced this issue Oct 20, 2017
liufengyun added a commit to dotty-staging/dotty that referenced this issue Oct 23, 2017
liufengyun added a commit to dotty-staging/dotty that referenced this issue Oct 24, 2017
…ty check

In implicit search, if the expected type is applying type and the candidate
is a TermRef to a method with default parameters, we need the TermRef
to the method in order for `TestApplication` to insert default parameters.
Otherwise, by widening the TermRef to MethodType, the information about default
parameters is lost,  which may incorrectly disqualify a candidate.
odersky added a commit that referenced this issue Oct 26, 2017
Fix #3352: Avoid widening method TermRefs in compatibility checks
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

1 participant