test(metatype): lock duplicate-variant-name rejection (examples/1180)
Diagnostics example for the define duplicate-name guard (b2db2c5): two
'value' variants -> build-gating error naming the duplicate, exit 1.
This commit is contained in:
17
examples/1180-diagnostics-metatype-duplicate-variant.sx
Normal file
17
examples/1180-diagnostics-metatype-duplicate-variant.sx
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
// A comptime-constructed enum (declare/define) with two same-named variants is
|
||||||
|
// rejected loudly. Two `value` variants would make construction (`.value`) and
|
||||||
|
// matching ambiguous — `define` bails naming the duplicate, instead of silently
|
||||||
|
// minting a malformed enum that picks one arbitrarily.
|
||||||
|
#import "modules/std.sx";
|
||||||
|
#import "modules/std/meta.sx";
|
||||||
|
|
||||||
|
Bad :: define(declare("Bad"), .enum(.{ variants = .[
|
||||||
|
EnumVariant.{ name = "value", payload = i64 },
|
||||||
|
EnumVariant.{ name = "closed", payload = void },
|
||||||
|
EnumVariant.{ name = "value", payload = f64 }, // duplicate name
|
||||||
|
] }));
|
||||||
|
|
||||||
|
main :: () -> i32 {
|
||||||
|
b : Bad = ---;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
1
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
error: comptime type construction failed: comptime define(): duplicate variant name 'value'
|
||||||
|
--> examples/1180-diagnostics-metatype-duplicate-variant.sx:8:8
|
||||||
|
|
|
||||||
|
8 | Bad :: define(declare("Bad"), .enum(.{ variants = .[
|
||||||
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
9 | EnumVariant.{ name = "value", payload = i64 },
|
||||||
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
10 | EnumVariant.{ name = "closed", payload = void },
|
||||||
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
11 | EnumVariant.{ name = "value", payload = f64 }, // duplicate name
|
||||||
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
12 | ] }));
|
||||||
|
| ^^^^^
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
|
||||||
Reference in New Issue
Block a user