| ... | ... | @@ -2,6 +2,42 @@ const tests = @import("tests.zig"); |
| 2 | 2 | const std = @import("std"); |
| 3 | 3 | |
| 4 | 4 | pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5 | cases.add("@Type for exhaustive enum with undefined tag type", |
| 6 | \\const TypeInfo = @import("builtin").TypeInfo; |
| 7 | \\const Tag = @Type(.{ |
| 8 | \\ .Enum = .{ |
| 9 | \\ .layout = .Auto, |
| 10 | \\ .tag_type = undefined, |
| 11 | \\ .fields = &[_]TypeInfo.EnumField{}, |
| 12 | \\ .decls = &[_]TypeInfo.Declaration{}, |
| 13 | \\ .is_exhaustive = false, |
| 14 | \\ }, |
| 15 | \\}); |
| 16 | \\export fn entry() void { |
| 17 | \\ _ = @intToEnum(Tag, 0); |
| 18 | \\} |
| 19 | , &[_][]const u8{ |
| 20 | "tmp.zig:2:20: error: use of undefined value here causes undefined behavior", |
| 21 | }); |
| 22 | |
| 23 | cases.add("@Type for exhaustive enum with non-integer tag type", |
| 24 | \\const TypeInfo = @import("builtin").TypeInfo; |
| 25 | \\const Tag = @Type(.{ |
| 26 | \\ .Enum = .{ |
| 27 | \\ .layout = .Auto, |
| 28 | \\ .tag_type = bool, |
| 29 | \\ .fields = &[_]TypeInfo.EnumField{}, |
| 30 | \\ .decls = &[_]TypeInfo.Declaration{}, |
| 31 | \\ .is_exhaustive = false, |
| 32 | \\ }, |
| 33 | \\}); |
| 34 | \\export fn entry() void { |
| 35 | \\ _ = @intToEnum(Tag, 0); |
| 36 | \\} |
| 37 | , &[_][]const u8{ |
| 38 | "tmp.zig:2:20: error: TypeInfo.Enum.tag_type must be an integer type, not 'bool'", |
| 39 | }); |
| 40 | |
| 5 | 41 | cases.add("slice sentinel mismatch", |
| 6 | 42 | \\export fn entry() void { |
| 7 | 43 | \\ const x = @import("std").meta.Vector(3, f32){ 25, 75, 5, 0 }; |