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
Initialization order - calling apply
method from val
in case class companion object
#9971
Comments
Imported From: https://issues.scala-lang.org/browse/SI-9971?orig=1 |
@SethTisue said:
|
@som-snytt said (edited on Nov 12, 2016 11:51:19 PM UTC): class C { def c: C = ??? }
lazy val c: C = c.c // doesn't warn but the bug is that I also missed the part where order of local companions matters. The "existing object" must come first textually. The spec says "if a companion object exists already," but it's not obvious to me if that phrase means, "before a companion was synthesized" or "textually before this case class definition was processed by the compiler." I think the former is surely preferable but the latter got voted into office. |
these days Dotty gives |
Scala 3 ticket is scala/scala3#13162. (And also, re-discussed recently on #12435, now closed as duplicate.) |
There are suggestions on both scala and dotty tickets that the behavior is an implementation detail, but it is specified quite narrowly. https://scala-lang.org/files/archive/spec/2.13/05-classes-and-objects.html#object-definitions Note that the "lazy val" paradigm is paradigmatic, and top-level objects are the deviation. This commit only fixes the bug mentioned above and elsewhere. I was mistaken that order of the companions makes a difference, or that behavior has improved, or maybe I was commenting only on the specification. |
The following produces a stack-overflow:
The text was updated successfully, but these errors were encountered: