mirror of
https://github.com/github/codeql.git
synced 2025-12-24 04:36:35 +01:00
Add test for typeflow propagation through instanceof and pattern-case
This commit is contained in:
@@ -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 -> { }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 |
|
||||
|
||||
Reference in New Issue
Block a user