This repository has been archived by the owner on Oct 10, 2024. It is now read-only.
Fix boxing and unboxing of annotated primitives #986
Merged
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.
TypeName#box currently relies on identity comparisons between
this
and one of the primitive TypeName constants. However, it is possible to have an instance of a primitive that isn't any of those constants by calling TypeName#annotated or TypeName#withoutAnnotations. The returned TypeName instance can no longer be boxed.TypeName#unbox and TypeName#isBoxedPrimitive have a similar issue.
this
is compared usingequals
instead of identity, but annotations are part of the compared string, so a boxed primitive with annotations is not found to be any of the existing constants. Annotated boxed TypeName instances can no longer be unboxed.This PR changes behavior of all 3 methods to do a more appropriate comparison when trying to find the (un)boxed version of
this
. After (un)boxing, the annotations fromthis
are copied onto the returned value. That way, boxing and unboxing works on both unannotated and annotated TypeNames, preserving any annotations. When no annotations are present, identity is preserved.I added unit tests to test both boxing and unboxing. Those tests fail without the code changes in TypeName.