Add test for typeflow propagation through instanceof and pattern-case

This commit is contained in:
Chris Smowton
2023-11-09 16:19:37 +00:00
parent fa09be0459
commit 43c935024a
2 changed files with 20 additions and 0 deletions

View File

@@ -102,4 +102,20 @@ public class A extends ArrayList<Long> {
default -> { }
}
}
public void m10(Object o) {
String s = "Hello world!";
Object o2 = s; // Alas, the type information, it is lost
if (o2 instanceof CharSequence cs) {
// Partially recovered statically, but we should know cs is an alias of o and therefore it's really a string.
Object target = cs;
}
// The same applies to a pattern case
switch (o2) {
case CharSequence cs -> { Object target = cs; }
default -> { }
}
}
}

View File

@@ -14,5 +14,9 @@
| A.java:70:23:70:24 | x2 | Integer | false |
| A.java:92:18:92:18 | n | Integer | false |
| A.java:100:20:100:20 | n | Integer | false |
| A.java:110:9:110:10 | o2 | String | false |
| A.java:112:23:112:24 | cs | String | false |
| A.java:116:13:116:14 | o2 | String | false |
| A.java:117:49:117:50 | cs | String | false |
| UnionTypes.java:45:7:45:7 | x | Inter | false |
| UnionTypes.java:48:23:48:23 | x | Inter | false |