summaryrefslogtreecommitdiffstats
path: root/tests/diagnostics/enum-implicit-conversion.slang
diff options
context:
space:
mode:
Diffstat (limited to 'tests/diagnostics/enum-implicit-conversion.slang')
-rw-r--r--tests/diagnostics/enum-implicit-conversion.slang30
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;
}