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
Unexpected error when combining default parameters, named arguments, currying, and parameterized type #4592
Comments
Imported From: https://issues.scala-lang.org/browse/SI-4592?orig=1 |
Ramnivas Laddad (ramnivas) said: object Control {
def repeat[T](count: Int = 1)(thunk: => T) : T = (0 until count).map(_ => thunk).last
def repeat[T](thunk: => T) : T = repeat()(thunk)
repeat(3.14)
repeat(count=5)(3.14)
} No error with scalac now. |
Ramnivas Laddad (ramnivas) said: First note that, compiler is quite happy with (reported with #4591): object Control {
def repeat(count: Int = 1, x: Boolean = true)(thunk: => Double) : Unit = (0 until count).foreach(_ => thunk)
def repeat(thunk: => Double) : Unit = repeat()(thunk)
repeat(3.14)
repeat(count=5)(3.14)
} In the second call, "count=5" would have returned Unit (if count were to be in scope) and that would have not matched the "Double" type of the thunk, so the "repeat(count: Int = 1, x: Boolean = true)(thunk: => Double)" was used and it all worked fine. With the type parameter version (code reported in the original issue report), the compiler is probably trying to match the call in error to "repeat[T](thunk: => T)" with T bound to Unit (the return type of expression "count=5"). Unlike the "=> Double" case, there is no issue in resolving the thunk to return Unit. But, of course, there is no "count" in the scope and hence the error. This still doesn't explain why removing "x: Boolean = true" made the error go away. Really curious how you approach this and resolve it. |
This seems related to #4591
=== What is the expected behavior? ===
No error when compiling.
=== What do you see instead? ===
Interestingly, in #4591 (which is similar code except the the use of type parameter), the error location is the definition itself (and not usage). Error message is confusing in any case.
=== Additional information ===
(for instance, a link to a relevant mailing list discussion)
=== What versions of the following are you using? ===
The text was updated successfully, but these errors were encountered: