Skip to content
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

Check safe initialization of global objects #10550

Closed
wants to merge 34 commits into from

Conversation

liufengyun
Copy link
Contributor

Check safe initialization of global objects

Fix #10549, #9176

Example 1

Given the code below:

object A {
  val a: Int = B.b     // error
}

object B {
  val b: Int = A.a     // error
}

The checker produces the following warning:

-- Warning: tests/init/full/neg/global-cycle1.scala:2:6 ------------------------
2 |  val a: Int = B.b     // error
  |      ^
  |      Access non-initialized value a. Calling trace:
  |       -> val a: Int = B.b     // error	[ global-cycle1.scala:2 ]
  |        -> val b: Int = A.a     // error	[ global-cycle1.scala:6 ]
-- Warning: tests/init/full/neg/global-cycle1.scala:6:6 ------------------------
6 |  val b: Int = A.a     // error
  |      ^
  |      Access non-initialized value b. Calling trace:
  |       -> val b: Int = A.a     // error	[ global-cycle1.scala:6 ]
  |        -> val a: Int = B.b     // error	[ global-cycle1.scala:2 ]

Example 2

Given

class Foo(val opposite: Foo)
case object A extends Foo(B) // error
case object B extends Foo(A) // error

The checker reports:

-- Warning: tests/init/full/neg/i9176.scala:2:0 --------------------------------
2 |case object A extends Foo(B) // error
  |^
  |Access non-initialized object A. Calling trace:
  | -> case object A extends Foo(B) // error	[ i9176.scala:2 ]
  |  -> case object B extends Foo(A) // error	[ i9176.scala:3 ]
-- Warning: tests/init/full/neg/i9176.scala:3:0 --------------------------------
3 |case object B extends Foo(A) // error
  |^
  |Access non-initialized object B. Calling trace:
  | -> case object B extends Foo(A) // error	[ i9176.scala:3 ]
  |  -> case object A extends Foo(B) // error	[ i9176.scala:2 ]

- Fix crash tests/init/crash/i1990b.scala
- tests/init/neg/inner1.scala
  Now we support safe promotion
The non-termination is caused by typo in the level of `Outer`:
it should be `pot.level` instead of `pot.size`.
Handle NoPrefix properly
Those calls cannot have impact on initialization status of current object.
@liufengyun
Copy link
Contributor Author

Superseded by #11385, #11913, #11278 and #11533

@liufengyun liufengyun closed this Mar 26, 2021
@liufengyun liufengyun deleted the safe-object-init branch March 26, 2021 20:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
1 participant