Repository navigation
Keep casts that decide whether a conditional is numeric - #1279
Merged
Merged
Conversation
This file contains hidden or 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
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.
RemoveRedundantTypeCastremoved the casts inisFloat ? (Object) 0.0f : (Object) 0.0d. The casts make this a reference conditional. Without them it is a numeric conditional (JLS 15.25), so the float widens to a double. This broke openrewrite/rewrite-testing-frameworks#1346:JUnit3AssertionsVisitorpassed this expression as aJ.Literalvalue, and after the cleanup a0.0fliteral held aDouble.A cast that is the true or false part of a conditional is now kept when it changes the type and either side of the cast is a primitive or boxed type. Same-type casts such as
(Integer) valueon anIntegerare still removed. The local-variable form was already left alone only because no target type was found. The method-argument form fell through to the "cast type is assignable" fallback and lost its casts.Verified with
./gradlew test --tests '*RemoveRedundantTypeCast*'(56 tests pass, including three new ones inRemoveRedundantTypeCastConditionalTest; without the fix the method-argument case fails). The full./gradlew testrun has no Java failures. The only failures are TypeScript/Python tests whose 8.114.0 snapshot RPC packages could not be installed from npm/PyPI locally.