diff options
| author | sriramm-nv <85252063+sriramm-nv@users.noreply.github.com> | 2024-04-03 15:10:16 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-04-03 15:10:16 -0700 |
| commit | f6c49fdb2cc7ead1943d944097220cedd142792f (patch) | |
| tree | 86f8a09544d89cab007f3168f10396bcee73d12e /tests | |
| parent | 2768e429e556f3978825beaf71cf361626057135 (diff) | |
Fix assertions due to malformed switch statements (#3858)
* Fix assertions due to malformed switch statements
Fixes the issue #2955
* Checks for multiple case statements with same values
* Checks for multiple default cases
* Constant-folds case exprs into an Integer value
* fix the comments, and updated error code
* one-line comment on diagnostic code
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/diagnostics/switch-duplicate-case.slang | 33 | ||||
| -rw-r--r-- | tests/diagnostics/switch-multiple-defaults.slang | 14 |
2 files changed, 47 insertions, 0 deletions
diff --git a/tests/diagnostics/switch-duplicate-case.slang b/tests/diagnostics/switch-duplicate-case.slang new file mode 100644 index 000000000..2d55dc4c8 --- /dev/null +++ b/tests/diagnostics/switch-duplicate-case.slang @@ -0,0 +1,33 @@ +//TEST:SIMPLE(filecheck=CHECK): + +// Tests to evaluate the behavior of code blocks within a switch statement. A switch statement with duplicate cases with same values is not allowed and should throw an error + +enum class Cases +{ + A, + B +}; + +void test1(Cases c) +{ + switch (c) + { + case Cases::A: break; + case Cases::B: break; + // CHECK: ([[# @LINE+1]]): error 30601: {{.*}} + case Cases::A: break; + } + return; +} + +void test2() +{ + switch (0) + { + case 1: break; + case 2: break; + // CHECK: ([[# @LINE+1]]): error 30601: {{.*}} + case 1: break; + } + return; +} diff --git a/tests/diagnostics/switch-multiple-defaults.slang b/tests/diagnostics/switch-multiple-defaults.slang new file mode 100644 index 000000000..bf164dd57 --- /dev/null +++ b/tests/diagnostics/switch-multiple-defaults.slang @@ -0,0 +1,14 @@ +//TEST:SIMPLE(filecheck=CHECK): + +// Test to evaluate the behavior of unreachable code blocks within a switch statement. A switch statement with multiple default cases is not allowed and should throw an error + +void test() +{ + switch (0) + { + default: break; + // CHECK: ([[# @LINE+1]]): error 30600: {{.*}} + default: break; + } + return; +} |
