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

Closed
scabug opened this Issue May 15, 2011 · 4 comments

Comments

Projects
None yet
2 participants
@scabug
Copy link

scabug commented May 15, 2011

This seems related to #4591

object Control {
  def repeat[T](count: Int = 1, x: Boolean = true)(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)
  repeat(count=5,x=false)(3.14)
}

=== What is the expected behavior? ===

No error when compiling.

=== What do you see instead? ===

 scalac repeat.scala 
repeat.scala:8: error: not found: value count
  repeat(count=5)(3.14)
         ^
one error found

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? ===

  • Scala: 2.9.final
  • Java: 1.6
  • Operating system: MacOS Snow Leopard
@scabug

This comment has been minimized.

Copy link

scabug commented May 15, 2011

Imported From: https://issues.scala-lang.org/browse/SI-4592?orig=1
Reporter: Ramnivas Laddad (ramnivas)

@scabug

This comment has been minimized.

Copy link

scabug commented May 15, 2011

Ramnivas Laddad (ramnivas) said:
It gets weirder. When I remove the second parameter ("x"), it compiles fine.

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.

@scabug

This comment has been minimized.

Copy link

scabug commented May 17, 2011

Ramnivas Laddad (ramnivas) said:
Just wanted to add my thoughts on what may be going on here (partially) and why the bug exhibits only for methods with a type parameter. Hopefully, this helps you in analyzing and resolving the issue.

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.

@scabug

This comment has been minimized.

Copy link

scabug commented Aug 6, 2011

Commit Message Bot (anonymous) said:
(extempore in r25455) Fixed bug in the disambiguation of f(foo='bar') style method calls in
the presence of overloading, parameterization, and by-name arguments.
Took the opportunity to clean things up a little bit. Closes #4592,
review by rytz.

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