-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
wip: try to fix initialization warnings in NameKinds #15462
Closed
Closed
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
We do not need it any more because we store secondary constructor parameter values on `this`.
The three new warnings are:
|
Closing in favour of #15560. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Based on #15364.
Do not merge.
This is an attempt to refactor NameKinds to fix the initialization warnings.
The overall approach is to separate the two concerns in NameKinds: the definitions of the NameKind class hierarchy and the various vals, instances of various kinds of NameKinds. The PR moves the former out of
object NameKinds
and leaves the latter there. From the point of view of initialization, the goal is to remove the dependence of the classes in the NameKind class hierarchy on the outerobject NameKinds
.Such refactorings would be easier if we had some static-class annotation that would signal to the init checker that a particular class is not intended to use its outer. The init checker could then check that it indeed does not use its outer, and allow
this
to be promoted even though outer is not yet initialized.Some of the classes in the NameKind hierarchy were anonymous classes. Moving them out required making them named classes. A static-class annotation would enable us to avoid moving them and giving them names.
Since it was possible for me to move all the NameKind classes out of
object NameKinds
, it must be that they do not actually depend on their outer. Then it seems there must be some bug in the init checker: it should have been able to prove that they do not depend on their outer and allow this to be promoted, but it didn't. More detailed warnings about the reasons why the init checker thinks a class depends on outer would help diagnose this bug and also help programmers understand why the init checker cannot promote this.Two classes, ExpandedNameKind and UniqueNameKind, still give a warning because they have the pattern described in #15459 : a superclass that needs to leak this and a subclass that adds fields. It would be good to find some way of expressing this pattern, for a superclass to specify an action to be performed after subclasses have been initialized.
A third class, AvoidNameKind, also gives the same warning, probably for the same reason, but one can't be sure because it involves code generated from an enum and until we fix #15459, the warning does not provide enough information.
The overall outcome is that we remove the four initialization warnings from NameKinds about the leaking of
this
, but we introduce the three new ones described in the last two paragraphs.