Skip to content

Commit

Permalink
Don't look through primitive casts; they actually do change the under…
Browse files Browse the repository at this point in the history
…lying type!

PiperOrigin-RevId: 564691382
  • Loading branch information
graememorgan authored and Error Prone Team committed Sep 13, 2023
1 parent 7552251 commit 759c410
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ protected Tree defaultAction(Tree node, Void unused) {

@Override
public Tree visitTypeCast(TypeCastTree node, Void unused) {
return node.getExpression().accept(this, null);
return getType(node).isPrimitive() ? node : node.getExpression().accept(this, null);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,20 @@ public void comparingElementsUsingRawCollection_noFinding() {
.doTest();
}

@Test
public void casts() {
compilationHelper
.addSourceLines(
"Test.java",
"import static com.google.common.truth.Truth.assertThat;",
"public class Test {",
" public void f(int a, long b, long c) {",
" assertThat((long) a).isAnyOf(b, c);",
" }",
"}")
.doTest();
}

@Test
public void subjectExhaustiveness(
@TestParameter(valuesProvider = SubjectMethods.class) Method method) {
Expand Down

0 comments on commit 759c410

Please sign in to comment.