Skip to content

Commit

Permalink
Fix another edge case with primitives in RemoveRedundantTypeCast
Browse files Browse the repository at this point in the history
  • Loading branch information
knutwannheden committed Nov 2, 2023
1 parent d6dee9d commit 1e0ca37
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public J visitTypeCast(J.TypeCast typeCast, ExecutionContext ctx) {
JavaType expressionType = visitedTypeCast.getExpression().getType();
JavaType castType = visitedTypeCast.getType();

if (targetType == null || targetType instanceof JavaType.Primitive && castType != targetType) {
if (targetType == null || targetType instanceof JavaType.Primitive && castType != expressionType) {
// Not currently supported, this will be more accurate with dataflow analysis.
return visitedTypeCast;
} else if (!(targetType instanceof JavaType.Array) && TypeUtils.isOfClassType(targetType, "java.lang.Object") ||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ void primitiveCast() {
class Test {
void m(DataOutputStream out) {
out.writeByte((byte) 0xff);
out.writeDouble((double) 42);
}
}
"""
Expand Down

0 comments on commit 1e0ca37

Please sign in to comment.