Files
c3c/test/test_suite/statements/switch_errors.c3
Christoffer Lerno 5c77c9a754 - Change distinct -> typedef.
- Order of attribute declaration is changed for `alias`.
- Added `LANGUAGE_DEV_VERSION` env constant.
- Rename `anyfault` -> `fault`.
- Changed `fault` -> `faultdef`.
- Added `attrdef` instead of `alias` for attribute aliases.
2025-03-15 20:10:47 +01:00

157 lines
2.4 KiB
Plaintext

enum Foo
{
A, B
}
enum Bar
{
B
}
fn void test_other_enum()
{
Foo f = A;
switch (f)
{
case Foo.A:
break;
case B:
break;
case Bar.B: // #error: to 'Foo'
break;
}
}
fn void test_check_nums()
{
Foo f = A;
switch (f)
{
case Foo.from_ordinal(1):
break;
case Foo.from_ordinal(0):
break;
}
}
fn void test_scope(int i)
{
switch (i)
{
case 1:
int a = 0;
break;
case 2:
test_scope(a + 1); // #error: 'a' could not be found, did you spell it right
}
}
fn void test_duplicate_case(int i)
{
switch (i)
{
case 1:
break;
case 2:
break;
case 1: // #error: same case value appears
break;
}
}
fn void test_duplicate_case2(Foo i)
{
switch (i)
{
case A:
break;
case Foo.from_ordinal(1):
break;
case A: // #error: same case value appears
break;
}
}
fn void test_duplicate_case3(Foo i)
{
switch (i)
{
case A:
break;
case Foo.from_ordinal(0): // #error: same case value appears
break;
}
}
enum Baz
{
A, B, C, D
}
fn void test_missing_all_cases(Baz x)
{
switch (x) // #error: not handled in the switch: A, B, C, ...
{
}
}
fn void test_missing_some_cases(Baz x)
{
switch (x) // #error: not handled in the switch: B, C and D
{
case A:
break;
}
}
fn void test_missing_some_cases2(Baz x)
{
switch (x) // #error: B and D
{
case C:
case A:
break;
}
}
fn void test_missing_some_cases3(Baz x)
{
switch (x) // #error: Enum value D was not handled in the switch
{
case B:
case C:
case A:
break;
}
}
fn void test_missing_no_cases(Baz x)
{
switch (x)
{
default:
break;
}
}
faultdef DIVISION_BY_ZERO;
// Rethrowing an error uses "!!" suffix
fn void? testMayError()
{
}
fn void main()
{
// Handle the error
switch (catch err = testMayError()) // #error: Catch unwrapping is only allowed
{
case DIVISION_BY_ZERO:
libc::printf("Division by zero\n");
return;
default:
libc::printf("Unexpected error!");
return;
}
}