mirror of
https://github.com/github/codeql.git
synced 2026-04-22 15:25:18 +02:00
Fix pretty-printing of anonymous vars and multiple patterns; add test
This commit is contained in:
@@ -400,7 +400,8 @@ private class PpInstanceOfExpr extends PpAst, InstanceOfExpr {
|
||||
|
||||
private class PpLocalVariableDeclExpr extends PpAst, LocalVariableDeclExpr {
|
||||
override string getPart(int i) {
|
||||
i = 0 and result = this.getName()
|
||||
i = 0 and
|
||||
(if this.isAnonymous() then result = "_" else result = this.getName())
|
||||
or
|
||||
i = 1 and result = " = " and exists(this.getInit())
|
||||
}
|
||||
@@ -793,7 +794,11 @@ private class PpPatternCase extends PpAst, PatternCase {
|
||||
or
|
||||
i = base + 2 and
|
||||
this.getPatternAtIndex(n) instanceof LocalVariableDeclExpr and
|
||||
not this.isAnonymousPattern(n) and
|
||||
(
|
||||
exists(this.getPatternAtIndex(n).asBindingOrUnnamedPattern().getTypeAccess())
|
||||
or
|
||||
not this.isAnonymousPattern(n)
|
||||
) and
|
||||
result = " "
|
||||
or
|
||||
i = base + 3 and
|
||||
@@ -815,9 +820,10 @@ private class PpPatternCase extends PpAst, PatternCase {
|
||||
|
||||
override PpAst getChild(int i) {
|
||||
exists(int n, int base | exists(this.getPatternAtIndex(n)) and base = n * 4 |
|
||||
i = 1 and result = this.getPatternAtIndex(n).asBindingOrUnnamedPattern().getTypeAccess()
|
||||
i = base + 1 and
|
||||
result = this.getPatternAtIndex(n).asBindingOrUnnamedPattern().getTypeAccess()
|
||||
or
|
||||
i = 1 and result = this.getPatternAtIndex(n).asRecordPattern()
|
||||
i = base + 1 and result = this.getPatternAtIndex(n).asRecordPattern()
|
||||
)
|
||||
or
|
||||
exists(int base | base = (max(int n | exists(this.getPatternAtIndex(n))) + 1) * 4 |
|
||||
|
||||
@@ -45,6 +45,13 @@ public class Test {
|
||||
|
||||
if (o instanceof R(S(var x), var y)) { }
|
||||
|
||||
switch(o) {
|
||||
case String _, Integer _:
|
||||
case R(S(_), _):
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1 +1 @@
|
||||
//semmle-extractor-options: --javac-args --release 21
|
||||
//semmle-extractor-options: --javac-args --release 22
|
||||
|
||||
@@ -84,5 +84,11 @@
|
||||
| Test.java:1:14:1:17 | Test | 83 | } |
|
||||
| Test.java:1:14:1:17 | Test | 84 | if (o instanceof R(S(var x), var y)) { |
|
||||
| Test.java:1:14:1:17 | Test | 85 | } |
|
||||
| Test.java:1:14:1:17 | Test | 86 | } |
|
||||
| Test.java:1:14:1:17 | Test | 87 | } |
|
||||
| Test.java:1:14:1:17 | Test | 86 | switch (o) { |
|
||||
| Test.java:1:14:1:17 | Test | 87 | case String _, Integer _: |
|
||||
| Test.java:1:14:1:17 | Test | 88 | case R(S(var _), var _): |
|
||||
| Test.java:1:14:1:17 | Test | 89 | default: |
|
||||
| Test.java:1:14:1:17 | Test | 90 | break; |
|
||||
| Test.java:1:14:1:17 | Test | 91 | } |
|
||||
| Test.java:1:14:1:17 | Test | 92 | } |
|
||||
| Test.java:1:14:1:17 | Test | 93 | } |
|
||||
|
||||
Reference in New Issue
Block a user