-
Notifications
You must be signed in to change notification settings - Fork 1.1k
No "Reference to uninitialized value" warning #15883
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
Comments
https://docs.scala-lang.org/scala3/reference/other-new-features/safe-initialization.html exists, but requires a there's some older history on this (in Scala 2) at https://docs.scala-lang.org/tutorials/FAQ/initialization-order.html, linked from https://docs.scala-lang.org/tutorials/FAQ/index.html#why-is-my-abstract-or-overridden-val-null |
object test:
val a = b
val b = 1
@main def hello =
println(test.a)
|
Maybe -Ysafe-init can be changed so that it also works for toplevel code? |
I'll have a look, it should behave the same as top-level objects. |
Compiler version
3.1.3
Minimized code
Output
0
Expectation
Expected output:
1
. The natural expected behavior is that initialization would follow the dependency graph, and it would be a compiler error if it contains a cycle.At the very least, the compiler should issue an uninitialized value warning, as in Scala 2, a fortiori when
-Ysafe-init
is enabled.As it stands, referential transparency and
val
immutability are violated without so much as a warning.The text was updated successfully, but these errors were encountered: