Fix switchCaseControls and hasBranchEdge to account for mixed patterns and constant cases

This commit is contained in:
Chris Smowton
2023-11-16 17:29:08 +00:00
parent c1814408f0
commit 668f445fb4
5 changed files with 45 additions and 19 deletions

View File

@@ -38,3 +38,19 @@ Test.java:
# 12| 0: [StringLiteral] "d"
# 13| 3: [DefaultCase] default
# 13| -1: [BlockStmt] { ... }
# 15| 2: [SwitchStmt] switch (...)
# 15| -1: [VarAccess] s
# 16| 0: [PatternCase] case T t ...
# 16| -3: [EQExpr] ... == ...
# 16| 0: [MethodCall] length(...)
# 16| -1: [VarAccess] s
# 16| 1: [IntegerLiteral] 4
# 16| -1: [BlockStmt] { ... }
#-----| 0: (Single Local Variable Declaration)
# 16| 0: [TypeAccess] String
# 16| 1: [LocalVariableDeclExpr] s2
# 17| 1: [ConstCase] case ...
# 17| -1: [BlockStmt] { ... }
# 17| 0: [StringLiteral] "e"
# 18| 2: [DefaultCase] default
# 18| -1: [BlockStmt] { ... }

View File

@@ -12,5 +12,10 @@ class Test {
case "d" -> { }
default -> { }
}
switch (s) {
case String s2 when s.length() == 4 -> { }
case "e" -> { }
default -> { }
}
}
}

View File

@@ -6,3 +6,5 @@
| Test.java:11:7:11:17 | case ... | Test.java:9:13:9:13 | s | Test.java:11:12:11:14 | "c" | true | true | Test.java:11:7:11:17 | case ... |
| Test.java:12:7:12:17 | case ... | Test.java:9:13:9:13 | s | Test.java:12:12:12:14 | "d" | true | false | Test.java:13:7:13:16 | default |
| Test.java:12:7:12:17 | case ... | Test.java:9:13:9:13 | s | Test.java:12:12:12:14 | "d" | true | true | Test.java:12:7:12:17 | case ... |
| Test.java:17:7:17:17 | case ... | Test.java:15:13:15:13 | s | Test.java:17:12:17:14 | "e" | true | false | Test.java:18:7:18:16 | default |
| Test.java:17:7:17:17 | case ... | Test.java:15:13:15:13 | s | Test.java:17:12:17:14 | "e" | true | true | Test.java:17:7:17:17 | case ... |

View File

@@ -1 +1 @@
//semmle-extractor-options: --javac-args -source 14 -target 14
//semmle-extractor-options: --javac-args --release 21