forked from typetools/checker-framework
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'switch-statement-rule' into switch-expressions-jjjpv-3
- Loading branch information
Showing
21 changed files
with
882 additions
and
80 deletions.
There are no files selected for viewing
Empty file.
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
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(); | ||
} | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
checker/tests/nullness/java17/SwitchExpressionInvariant.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,27 @@ | ||
// @below-java17-jdk-skip-test | ||
import java.util.List; | ||
import org.checkerframework.checker.nullness.qual.NonNull; | ||
import org.checkerframework.checker.nullness.qual.Nullable; | ||
|
||
public class SwitchExpressionInvariant { | ||
public static boolean flag = false; | ||
|
||
void method( | ||
List<@NonNull String> nonnullStrings, List<@Nullable String> nullableStrings, int fenum) { | ||
|
||
List<@NonNull String> list = | ||
// :: error: (assignment) | ||
switch (fenum) { | ||
// :: error: (switch.expression) | ||
case 1 -> nonnullStrings; | ||
default -> nullableStrings; | ||
}; | ||
|
||
List<@Nullable String> list2 = | ||
switch (fenum) { | ||
// :: error: (switch.expression) | ||
case 1 -> nonnullStrings; | ||
default -> nullableStrings; | ||
}; | ||
} | ||
} |
Oops, something went wrong.