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

forcing cyclic evaluation of non static object causes infinite loop #9668

Open
bishabosha opened this issue Aug 28, 2020 · 1 comment
Open

Comments

@bishabosha
Copy link
Member

bishabosha commented Aug 28, 2020

Minimized code

class Outer {
  def force = {
    class E
    object E {
      final val A = new E()
      val ref = E.A
    }
    E
  }
}

@main def Test: Unit = new Outer().force

Output

java.lang.StackOverflowError
	at rs$line$3$Outer.E$lzyINIT1$1(rs$line$3:4)
	at rs$line$3$Outer.rs$line$3$Outer$$_$E$1(rs$line$3:4)
	at rs$line$3$E$1$.<init>(rs$line$3:6)
	at rs$line$3$Outer.E$lzyINIT1$1(rs$line$3:4)
	at rs$line$3$Outer.rs$line$3$Outer$$_$E$1(rs$line$3:4)
	at rs$line$3$E$1$.<init>(rs$line$3:6)
        ...

Expectation

This could be a candidate for checking initialisation

this example is inspired by a test case in scodec that defines a local enum and then immediately accesses values of the enum to serialise them

@liufengyun
Copy link
Contributor

The runtime semantics of the program is correct, and no non-initialized fields are accessed in this case.

However, the initialization checker can be enhanced to check non-termination related to object initialization. Related #9176

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants