-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Global object init checker gives warning when accessing an object before its super constructor finishes #24349
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
base: main
Are you sure you want to change the base?
Global object init checker gives warning when accessing an object before its super constructor finishes #24349
Conversation
3385505 to
4737d4f
Compare
4737d4f to
edf760c
Compare
| ObjectRef(classSym) | ||
| val obj = ObjectRef(classSym) | ||
| obj.setAfterSuperCall() | ||
| obj |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure about obj.setAfterSuperCall here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is when we don't have source, so we're not checking this object at all. Presumably in that case it should always be OK to access the object, so setAfterSuperCall makes sense to me.
| UnknownValue | ||
| else if ref.isInstanceOf[ObjectRef] && !ref.asObjectRef.isAfterSuperCall then | ||
| report.warning("Calling " + target + " of object " + ref.klass + " before the super constructor of the object finishes! " + Trace.show, Trace.position) | ||
| Bottom |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking whether the check should be moved to accessObject?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think so too.
edf760c to
0cb7497
Compare
0cb7497 to
cdcf91a
Compare
Accessing an object before its super constructor finishes returns
nulland may lead to exceptions when constructing the object (see #24201). This PR lets global object init checker gives warning for this case