Open scabug opened 13 years ago
Imported From: https://issues.scala-lang.org/browse/SI-5000?orig=1 Reporter: Kipton Barros (kbarros) Affected Versions: 2.9.1
Michael Schmitz (schmmd) said (edited on Sep 23, 2011 1:09:21 AM UTC): This also causes the same error.
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: More interesting corners arise when classes and their companions reference one another.
@adriaanm said: Un-assigning to foster work stealing, as announced in https://groups.google.com/forum/?fromgroups=#!topic/scala-internals/o8WG4plpNkw
@adriaanm said: Unassigning and rescheduling to M6 as previous deadline was missed.
@gkossakowski said: The 2.11.2 is out so I'm rescheduling the issue for 2.11.3.
@retronym said: Updating fix-by version to 2.11.5.
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