Skip to content

Commit

Permalink
Add a test demonstrating a bug in PatternMatchingInstanceof.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 698500810
  • Loading branch information
kluever authored and Error Prone Team committed Nov 20, 2024
1 parent 4d239e8 commit d6f4888
Showing 1 changed file with 36 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -185,4 +185,40 @@ void test(Object x, String k) {
.expectUnchanged()
.doTest();
}

@Test
public void genericWithUpperBoundedWildcard() {
assume().that(Runtime.version().feature()).isAtLeast(21);
helper
.addInputLines(
"Test.java",
"""
import java.util.List;
class Test {
void test(Object object) {
if (object instanceof List) {
@SuppressWarnings("unchecked")
List<? extends CharSequence> list = (List) object;
System.err.println(list.get(0));
}
}
}
""")
// TODO: b/380054832 - this shouldn't get re-written
.addOutputLines(
"Test.java",
"""
import java.util.List;
class Test {
void test(Object object) {
if (object instanceof List list) {
System.err.println(list.get(0));
}
}
}
""")
.doTest();
}
}

0 comments on commit d6f4888

Please sign in to comment.