Supress safe-init warnings for NameKind HashMaps #14918
Closed
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.
This adds the
@unchecked
annotation to each of the four lines that add the object under construction to the relevant HashMap.In the
NameKinds.scala
file, all of theNameKind
s are created and added to one of four HashMaps based on their superclass. The lines that add the NameKind to the HashMaps are at the end of the relevant superclasses. This leads to a safe-init error since subclasses can add further fields and initialization logic that gets run after these lines.These warnings could be eliminated without the use of
@unchecked
, but it would require redundantly adding the same line to allNameKind
subclasses that get initialized. This means that anyone who changes this code in the future would need to remember to do this for all of the relevant subclasses. This could also be fixed without@unchecked
if there were a mechanism likeDelayedInit
in Scala3.Thus, instead of making a more involved change that would render the code redundant, overly verbose, and less maintainable, I opted for using
@unchecked
instead.