Update the KotlinUnsafeCastOperatorFilter for Kotlin 1.6.0 #6
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.
The Kotlin 1.6.0 compiler changed how "unsafe casts" are compiled. Consider the following Kotlin class:
The Kotlin 1.5.32 compiler compiles the
cast
function towhile the Kotlin 1.6.0 compiler produces:
The 1.6.0 compiler duplicates the variable that's being casted before checking whether it's null, and pops the extra copy from the stack in case it is null; previous compilers instead loaded the variable a second time if it wasn't null.
This change makes the
KotlinUnsafeCastOperatorFilter
not detect the unsafe cast anymore because of the extraPOP
instruction; allowing this instruction to be there but not requiring it makes the filter compatible with both variants.