You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The problem is illustrated by the example below:
``` Scala
class Foo(val opposite: Foo)
case object A extends Foo(B) // A -> B
case object B extends Foo(A) // B -> A
```
The check aims to be simple for programmers to understand, expressive,
fast, and sound.
The check is centered around two design ideas: (1) initialization-time
irrelevance; (2) partial ordering.
The check enforces the principle of _initialization-time irrelevance_,
which means that the time when a static object is initialized should not
change program semantics. For that purpose, it enforces the following
rule:
> **The initialization of a static object should not directly or
indirectly read or write mutable state owned by another static object**.
This principle not only puts the initialization of static objects on a
solid foundation but also avoids whole-program analysis.
Partial ordering means that the initialization dependencies of static
objects form a directed-acyclic graph (DAG). No cycles with length
bigger than 1 allowed --- which might lead to deadlocks in the presence
of concurrency and strong coupling & subtle contracts between objects.
Related Issues:
#16152#9176#11262scala/bug#9312scala/bug#9115scala/bug#9261scala/bug#5366scala/bug#9360
The following code compiles without errors but results in a field unexpectedly being null:
(May or may not be related to #9115 and/or #5366.)
The text was updated successfully, but these errors were encountered: