-
Notifications
You must be signed in to change notification settings - Fork 356
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Dataflow: fall through never happens in switch rules. (#4984)
- Loading branch information
Showing
5 changed files
with
96 additions
and
5 deletions.
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
43 changes: 43 additions & 0 deletions
43
checker/tests/nullness/java17/NullnessSwitchStatementRules.java
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,43 @@ | ||
// @below-java17-jdk-skip-test | ||
import org.checkerframework.checker.nullness.qual.Nullable; | ||
|
||
public class NullnessSwitchStatementRules { | ||
@Nullable Object field = null; | ||
|
||
void method(int selector) { | ||
field = new Object(); | ||
switch (selector) { | ||
case 1 -> field = null; | ||
case 2 -> field.toString(); | ||
} | ||
|
||
field = new Object(); | ||
switch (selector) { | ||
case 1 -> { | ||
field = null; | ||
} | ||
case 2 -> { | ||
field.toString(); | ||
} | ||
} | ||
|
||
field = new Object(); | ||
switch (selector) { | ||
case 1 -> { | ||
field = null; | ||
} | ||
case 2 -> { | ||
field.toString(); | ||
} | ||
} | ||
|
||
field = new Object(); | ||
switch (selector) { | ||
case 1: | ||
field = null; | ||
case 2: | ||
// :: error: (dereference.of.nullable) | ||
field.toString(); | ||
} | ||
} | ||
} |
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
29 changes: 29 additions & 0 deletions
29
framework/tests/value/java17/ValueSwitchStatementRules.java
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,29 @@ | ||
// @below-java17-jdk-skip-test | ||
import org.checkerframework.common.value.qual.IntVal; | ||
|
||
public class ValueSwitchStatementRules { | ||
private int field; | ||
|
||
void method(int selector) { | ||
field = 300; | ||
switch (selector) { | ||
case 1: | ||
field = 42; | ||
@IntVal(42) int copyField = field; | ||
case 2: | ||
// :: error: (assignment) | ||
@IntVal(300) int copyField2 = field; | ||
} | ||
|
||
field = 300; | ||
switch (selector) { | ||
case 1 -> { | ||
field = 42; | ||
@IntVal(42) int copyField = field; | ||
} | ||
case 2 -> { | ||
@IntVal(300) int copyField = field; | ||
} | ||
} | ||
} | ||
} |