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

initialization checker should list uninitialized fields in warning #15459

Closed
olhotak opened this issue Jun 16, 2022 · 0 comments · Fixed by #15488
Closed

initialization checker should list uninitialized fields in warning #15459

olhotak opened this issue Jun 16, 2022 · 0 comments · Fixed by #15488

Comments

@olhotak
Copy link
Contributor

olhotak commented Jun 16, 2022

Compiler version

main

Minimized code

def leak(a: Any) = ???

class Sup {
    val a = ???
    leak(this)
}

class Sub extends Sup {
    val b = ???
}

Output

-- Warning: Sup.scala:5:9 ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
5 |    leak(this)
  |         ^^^^
  |         Cannot prove the argument is fully initialized. Only fully initialized values are safe to leak. Calling trace:
  |         -> class Sub extends Sup {	[ Sup.scala:8 ]
  |            ^
  |         -> class Sup {	[ Sup.scala:3 ]
  |            ^
  |         -> leak(this)	[ Sup.scala:5 ]
  |                 ^^^^

Expectation

The warning would be more helpful if it could list the fields (in this case b) that are not initialized and the subclasses (in this case Sub) that they're in.

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