diff options
| author | Yong He <yonghe@outlook.com> | 2024-04-01 15:56:02 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-04-01 15:56:02 -0700 |
| commit | 2c4f9810327d58023e9ec44f579cd78adf56317b (patch) | |
| tree | b5498a74bd7d01fd2e4c321a0d2e551d5f024d6d /tests/diagnostics/enum-implicit-conversion.slang | |
| parent | 65ac9f3a9ddcb8bcfc099ffb29beaa9a92ba1f53 (diff) | |
Allow bit operators on enum types. (#3862)
* Allow bit operators on enum types.
* Fix.
Diffstat (limited to 'tests/diagnostics/enum-implicit-conversion.slang')
| -rw-r--r-- | tests/diagnostics/enum-implicit-conversion.slang | 30 |
1 files changed, 18 insertions, 12 deletions
diff --git a/tests/diagnostics/enum-implicit-conversion.slang b/tests/diagnostics/enum-implicit-conversion.slang index fc4757f7e..51082183e 100644 --- a/tests/diagnostics/enum-implicit-conversion.slang +++ b/tests/diagnostics/enum-implicit-conversion.slang @@ -1,6 +1,6 @@ // enum-implicit-conversion.slang -//DIAGNOSTIC_TEST:SIMPLE: +//DIAGNOSTIC_TEST:SIMPLE(filecheck=CHECK): // Confirm that suitable error messages are // generated for code that relies on implicit @@ -21,28 +21,34 @@ int bar(Color x) { return int(x) * 256; } int bar(int x) { return x * 256 * 256; } int bar(uint x) { return x * 256 * 256 * 16; } +int baz(Color x) { return (int)x; } int test(int val) { // Implicit conversion from `int` to `enum` isn't allowed. + // CHECK: ([[# @LINE+1]]): error Color c = val; - // TODO: explicit conversion to `enum` type should be allowed. -// Color cc = Color(val); - + // Implicit cast from enum to int types other than the tag type is not allowed. + // CHECK: ([[# @LINE+1]]): error + uint y = c; - // Implicit converion from `enum` to `int` isn't allowed. + // Call that expects implicit conversion from int to enum shouldn't be allowed. + // CHECK: ([[# @LINE+1]]): error + int z = baz(5); + + // CHECK-NOT: error + + // Call that has an explicit overload on `enum` type should succeed. + int zz = bar(c); + + Color cc = Color(val); + + // Implicit converion from `enum` to `int` is allowed. int x = c; - uint y = c; // Explicit converion is allowed. int xx = int(c); uint yy = uint(c); - // Call that expects implicit conversion should fail. - int z = foo(c); - - // Call that has an explicit overload on `enum` type should succeed. - int zz = bar(c); - return x + y + z; } |
