-
Notifications
You must be signed in to change notification settings - Fork 21
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
Class constructor parameter with default value causes companion object initializer to fail #5000
Comments
Imported From: https://issues.scala-lang.org/browse/SI-5000?orig=1 |
Michael Schmitz (schmmd) said (edited on Sep 23, 2011 1:09:21 AM UTC): class Foo(t: Any)
class Bar(x: String)
object Bar extends Foo(Bar.param) {
val param = "bar"
} error: super constructor cannot be passed a self reference unless parameter is declared by-name |
@paulp said: |
@adriaanm said: |
@adriaanm said: |
@gkossakowski said: |
@retronym said: |
The following code fails to compile,
The error message is: "super constructor cannot be passed a self reference unless parameter is declared by-name". I would expect either the code to compile or a more informative error message.
javap reveals that the zero-parameter constructor for class Bar with default value
x = "bar"
is actually defined asinit$default$1
in the companion objectBar
. I assume the problem is thatextends Foo(new Bar())
is trying to accessBar.init$default$1
before objectBar
has been constructed.I couldn't find this restriction in the SLS. If the compile error is correct, perhaps the error message could be improved? Thanks.
Possibly related: #4278
Source: http://stackoverflow.com/questions/7448931/extending-a-class-with-many-implementation-that-each-have-main-methods-in-scala
The text was updated successfully, but these errors were encountered: