diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2020-06-24 15:36:59 -0400 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2020-06-24 15:36:59 -0400 |
| commit | e42b7702eb2c74b923aa88492886c3f316188e99 (patch) | |
| tree | 7e4d18651c354ffb7f846316a9661059d963483d /test/compile_errors.zig | |
| parent | 14aa08fcd3ca6ef32fff9422969cb684cb81b9d7 (diff) | |
| parent | 129a4fb251f8eab22eacf219fbf81006baec3251 (diff) | |
| download | zig-e42b7702eb2c74b923aa88492886c3f316188e99.tar.gz zig-e42b7702eb2c74b923aa88492886c3f316188e99.zip | |
Merge remote-tracking branch 'origin/master' into zig-ast-to-zir
Diffstat (limited to 'test/compile_errors.zig')
| -rw-r--r-- | test/compile_errors.zig | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/test/compile_errors.zig b/test/compile_errors.zig index e3dd1f0d8f..e8b7e610ee 100644 --- a/test/compile_errors.zig +++ b/test/compile_errors.zig @@ -4362,6 +4362,40 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { "tmp.zig:5:14: note: previous value is here", }); + cases.add("switch expression - duplicate type", + \\fn foo(comptime T: type, x: T) u8 { + \\ return switch (T) { + \\ u32 => 0, + \\ u64 => 1, + \\ u32 => 2, + \\ else => 3, + \\ }; + \\} + \\export fn entry() usize { return @sizeOf(@TypeOf(foo(u32, 0))); } + , &[_][]const u8{ + "tmp.zig:5:9: error: duplicate switch value", + "tmp.zig:3:9: note: previous value is here", + }); + + cases.add("switch expression - duplicate type (struct alias)", + \\const Test = struct { + \\ bar: i32, + \\}; + \\const Test2 = Test; + \\fn foo(comptime T: type, x: T) u8 { + \\ return switch (T) { + \\ Test => 0, + \\ u64 => 1, + \\ Test2 => 2, + \\ else => 3, + \\ }; + \\} + \\export fn entry() usize { return @sizeOf(@TypeOf(foo(u32, 0))); } + , &[_][]const u8{ + "tmp.zig:9:9: error: duplicate switch value", + "tmp.zig:7:9: note: previous value is here", + }); + cases.add("switch expression - switch on pointer type with no else", \\fn foo(x: *u8) void { \\ switch (x) { |
