Skip to content
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

Default parameters and overloaded behavior: REPL vs. compiler difference #4591

Closed
scabug opened this issue May 15, 2011 · 3 comments
Closed

Comments

@scabug
Copy link

scabug commented May 15, 2011

=== What steps will reproduce the problem (please be specific and use wikiformatting)? ===

$$ scala
Welcome to Scala version 2.9.0.final (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_22).
Type in expressions to have them evaluated.
Type :help for more information.

scala> def repeat(count: Int = 1, x: Boolean = true)(thunk: => Double) : Unit = (0 until count).foreach(_ => thunk)
repeat: (count: Int, x: Boolean)(thunk: => Double)Unit

scala> def repeat(thunk: => Double) : Unit = repeat()(thunk)
<console>:8: error: not enough arguments for method repeat: (thunk: => Double)Unit.
Unspecified value parameter thunk.
       def repeat(thunk: => Double) : Unit = repeat()(thunk)
                                                   ^

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

Note that in the real implementation, I would use parameterized return type, but hard-binding to Double to reduce complexity.

I expected no error.

Interestingly, if I compile similar code with scalac, it compiles fine.

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)
}
scalac repeat.scala

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

I see error in REPL and no error through compiler.

=== Additional information ===
(for instance, a link to a relevant mailing list discussion)

=== What versions of the following are you using? ===

  • Scala: 2.0.final
  • Java: 1.5
  • Operating system: MacOS Snow Leopard
@scabug
Copy link
Author

scabug commented May 15, 2011

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

@scabug
Copy link
Author

scabug commented May 15, 2011

@paulp said:
You're not overloading the function, you're shadowing it.

@scabug
Copy link
Author

scabug commented May 15, 2011

Ramnivas Laddad (ramnivas) said:
Ok, I see. Thanks.

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

No branches or pull requests

1 participant