-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix switch on enum false positive, add more tests
- Loading branch information
Showing
6 changed files
with
272 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
package pkg; | ||
|
||
public class TestPatternMatchingReturn { | ||
public String getPattern(Object obj) { | ||
if (obj instanceof String) {// 5 | ||
return (String)obj;// 6 | ||
} else { | ||
System.out.println("filler");// 9 | ||
return null;// 11 | ||
} | ||
} | ||
|
||
public String get(Object obj) { | ||
if (obj instanceof String) {// 15 | ||
return (String)obj;// 16 | ||
} else { | ||
System.out.println("filler");// 19 | ||
return null;// 21 | ||
} | ||
} | ||
} | ||
|
||
class 'pkg/TestPatternMatchingReturn' { | ||
method 'getPattern (Ljava/lang/Object;)Ljava/lang/String;' { | ||
0 4 | ||
2 4 | ||
3 4 | ||
4 4 | ||
5 4 | ||
6 4 | ||
7 4 | ||
8 4 | ||
9 5 | ||
a 5 | ||
b 5 | ||
c 5 | ||
f 5 | ||
10 7 | ||
11 7 | ||
12 7 | ||
13 7 | ||
14 7 | ||
15 7 | ||
16 7 | ||
17 7 | ||
18 8 | ||
19 8 | ||
} | ||
|
||
method 'get (Ljava/lang/Object;)Ljava/lang/String;' { | ||
0 13 | ||
1 13 | ||
2 13 | ||
3 13 | ||
4 13 | ||
5 13 | ||
6 13 | ||
7 14 | ||
8 14 | ||
9 14 | ||
a 14 | ||
b 14 | ||
c 16 | ||
d 16 | ||
e 16 | ||
f 16 | ||
10 16 | ||
11 16 | ||
12 16 | ||
13 16 | ||
14 17 | ||
15 17 | ||
} | ||
} | ||
|
||
Lines mapping: | ||
5 <-> 5 | ||
6 <-> 6 | ||
9 <-> 8 | ||
11 <-> 9 | ||
15 <-> 14 | ||
16 <-> 15 | ||
19 <-> 17 | ||
21 <-> 18 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
package pkg; | ||
|
||
public class TestSwitchOnEnumFake { | ||
public byte[] values = new byte[TestSwitchOnEnumFake.Values.values().length]; | ||
|
||
public int test(TestSwitchOnEnumFake.Values v) { | ||
int a = 0;// 14 | ||
int b = 0;// 15 | ||
byte var4; | ||
byte var5; | ||
switch (this.values[v.ordinal()]) {// 16 | ||
case 1: | ||
var4 = 1;// 18 | ||
var5 = 2;// 19 | ||
break;// 20 | ||
case 2: | ||
var4 = 2;// 22 | ||
var5 = 4;// 23 | ||
break;// 24 | ||
case 3: | ||
var4 = 3;// 26 | ||
var5 = 6;// 27 | ||
break;// 28 | ||
default: | ||
var4 = 1;// 30 | ||
var5 = 1;// 31 | ||
} | ||
|
||
return var4 + var5;// 35 | ||
} | ||
|
||
static enum Values { | ||
A, | ||
B, | ||
C, | ||
D; | ||
} | ||
} | ||
|
||
class 'pkg/TestSwitchOnEnumFake' { | ||
method 'test (Lpkg/TestSwitchOnEnumFake$Values;)I' { | ||
0 6 | ||
1 6 | ||
2 7 | ||
3 7 | ||
4 10 | ||
5 10 | ||
6 10 | ||
7 10 | ||
8 10 | ||
9 10 | ||
a 10 | ||
b 10 | ||
c 10 | ||
d 10 | ||
e 10 | ||
f 10 | ||
10 10 | ||
11 10 | ||
12 10 | ||
13 10 | ||
14 10 | ||
15 10 | ||
16 10 | ||
17 10 | ||
18 10 | ||
19 10 | ||
1a 10 | ||
1b 10 | ||
1c 10 | ||
1d 10 | ||
1e 10 | ||
1f 10 | ||
20 10 | ||
21 10 | ||
22 10 | ||
23 10 | ||
24 10 | ||
25 10 | ||
26 10 | ||
27 10 | ||
28 12 | ||
29 12 | ||
2a 13 | ||
2b 13 | ||
2c 14 | ||
2f 16 | ||
30 16 | ||
31 17 | ||
32 17 | ||
33 18 | ||
36 20 | ||
37 20 | ||
38 21 | ||
39 21 | ||
3a 21 | ||
3b 22 | ||
3e 24 | ||
3f 24 | ||
40 25 | ||
41 25 | ||
42 28 | ||
43 28 | ||
44 28 | ||
45 28 | ||
} | ||
} | ||
|
||
Lines mapping: | ||
14 <-> 7 | ||
15 <-> 8 | ||
16 <-> 11 | ||
18 <-> 13 | ||
19 <-> 14 | ||
20 <-> 15 | ||
22 <-> 17 | ||
23 <-> 18 | ||
24 <-> 19 | ||
26 <-> 21 | ||
27 <-> 22 | ||
28 <-> 23 | ||
30 <-> 25 | ||
31 <-> 26 | ||
35 <-> 29 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package pkg; | ||
|
||
public class TestPatternMatchingReturn { | ||
public String getPattern(Object obj) { | ||
if (obj instanceof String s) { | ||
return s; | ||
} | ||
|
||
System.out.println("filler"); | ||
|
||
return null; | ||
} | ||
|
||
public String get(Object obj) { | ||
if (obj instanceof String) { | ||
return (String) obj; | ||
} | ||
|
||
System.out.println("filler"); | ||
|
||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package pkg; | ||
|
||
public class TestSwitchOnEnumFake { | ||
enum Values { | ||
A, | ||
B, | ||
C, | ||
D | ||
} | ||
|
||
public byte[] values = new byte[Values.values().length]; | ||
|
||
public int test(Values v) { | ||
int a = 0; | ||
int b = 0; | ||
switch (values[v.ordinal()]) { | ||
case 1 -> { | ||
a = 1; | ||
b = 2; | ||
} | ||
case 2 -> { | ||
a = 2; | ||
b = 4; | ||
} | ||
case 3 -> { | ||
a = 3; | ||
b = 6; | ||
} | ||
default -> { | ||
a = 1; | ||
b = 1; | ||
} | ||
} | ||
|
||
return a + b; | ||
} | ||
} |