authorgravatar for me@tadeo.caTadeo Kondrak <me@tadeo.ca> 2020-09-26 17:40:31-06:00
committergravatar for me@tadeo.caTadeo Kondrak <me@tadeo.ca> 2020-10-01 15:06:21-06:00
loge187ac09cbc23fedef40014f520b2e905033746b
tree80f33fbb95425757198ed920bbbaf9973ddf0b30
parenta12203d2be2ff1021d8faa9b87c53af091f0bd01
signature Commit is signed but in an unrecognized format.

Update compile error tests for alignment in StructField/UnionField


1 files changed, 51 insertions(+), 52 deletions(-)

test/compile_errors.zig+51-52
...@@ -38,20 +38,39 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -38,20 +38,39 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
38 "tmp.zig:2:20: error: TypeInfo.Enum.tag_type must be an integer type, not 'bool'",38 "tmp.zig:2:20: error: TypeInfo.Enum.tag_type must be an integer type, not 'bool'",
39 });39 });
4040
41 cases.add("slice sentinel mismatch",41 cases.add("@Type for tagged union with extra enum field",
42 \\export fn entry() void {42 \\const TypeInfo = @import("builtin").TypeInfo;
43 \\ const x = @import("std").meta.Vector(3, f32){ 25, 75, 5, 0 };43 \\const Tag = @Type(.{
44 \\}44 \\ .Enum = .{
45 , &[_][]const u8{45 \\ .layout = .Auto,
46 "tmp.zig:2:62: error: index 3 outside vector of size 3",46 \\ .tag_type = u2,
47 });47 \\ .fields = &[_]TypeInfo.EnumField{
4848 \\ .{ .name = "signed", .value = 0 },
49 cases.add("slice sentinel mismatch",49 \\ .{ .name = "unsigned", .value = 1 },
50 \\ .{ .name = "arst", .value = 2 },
51 \\ },
52 \\ .decls = &[_]TypeInfo.Declaration{},
53 \\ .is_exhaustive = true,
54 \\ },
55 \\});
56 \\const Tagged = @Type(.{
57 \\ .Union = .{
58 \\ .layout = .Auto,
59 \\ .tag_type = Tag,
60 \\ .fields = &[_]TypeInfo.UnionField{
61 \\ .{ .name = "signed", .field_type = i32, .alignment = @alignOf(i32) },
62 \\ .{ .name = "unsigned", .field_type = u32, .alignment = @alignOf(u32) },
63 \\ },
64 \\ .decls = &[_]TypeInfo.Declaration{},
65 \\ },
66 \\});
50 \\export fn entry() void {67 \\export fn entry() void {
51 \\ const y: [:1]const u8 = &[_:2]u8{ 1, 2 };68 \\ var tagged = Tagged{ .signed = -1 };
69 \\ tagged = .{ .unsigned = 1 };
52 \\}70 \\}
53 , &[_][]const u8{71 , &[_][]const u8{
54 "tmp.zig:2:37: error: expected type '[:1]const u8', found '*const [2:2]u8'",72 "tmp.zig:15:23: error: enum field missing: 'arst'",
73 "tmp.zig:27:24: note: referenced here",
55 });74 });
5675
57 cases.add("@Type for union with opaque field",76 cases.add("@Type for union with opaque field",
...@@ -61,7 +80,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -61,7 +80,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
61 \\ .layout = .Auto,80 \\ .layout = .Auto,
62 \\ .tag_type = null,81 \\ .tag_type = null,
63 \\ .fields = &[_]TypeInfo.UnionField{82 \\ .fields = &[_]TypeInfo.UnionField{
64 \\ .{ .name = "foo", .field_type = @Type(.Opaque) },83 \\ .{ .name = "foo", .field_type = @Type(.Opaque), .alignment = 1 },
65 \\ },84 \\ },
66 \\ .decls = &[_]TypeInfo.Declaration{},85 \\ .decls = &[_]TypeInfo.Declaration{},
67 \\ },86 \\ },
...@@ -74,6 +93,22 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -74,6 +93,22 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
74 "tmp.zig:13:17: note: referenced here",93 "tmp.zig:13:17: note: referenced here",
75 });94 });
7695
96 cases.add("slice sentinel mismatch",
97 \\export fn entry() void {
98 \\ const x = @import("std").meta.Vector(3, f32){ 25, 75, 5, 0 };
99 \\}
100 , &[_][]const u8{
101 "tmp.zig:2:62: error: index 3 outside vector of size 3",
102 });
103
104 cases.add("slice sentinel mismatch",
105 \\export fn entry() void {
106 \\ const y: [:1]const u8 = &[_:2]u8{ 1, 2 };
107 \\}
108 , &[_][]const u8{
109 "tmp.zig:2:37: error: expected type '[:1]const u8', found '*const [2:2]u8'",
110 });
111
77 cases.add("@Type for union with zero fields",112 cases.add("@Type for union with zero fields",
78 \\const TypeInfo = @import("builtin").TypeInfo;113 \\const TypeInfo = @import("builtin").TypeInfo;
79 \\const Untagged = @Type(.{114 \\const Untagged = @Type(.{
...@@ -130,9 +165,9 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -130,9 +165,9 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
130 \\ .layout = .Auto,165 \\ .layout = .Auto,
131 \\ .tag_type = Tag,166 \\ .tag_type = Tag,
132 \\ .fields = &[_]TypeInfo.UnionField{167 \\ .fields = &[_]TypeInfo.UnionField{
133 \\ .{ .name = "signed", .field_type = i32 },168 \\ .{ .name = "signed", .field_type = i32, .alignment = @alignOf(i32) },
134 \\ .{ .name = "unsigned", .field_type = u32 },169 \\ .{ .name = "unsigned", .field_type = u32, .alignment = @alignOf(u32) },
135 \\ .{ .name = "arst", .field_type = f32 },170 \\ .{ .name = "arst", .field_type = f32, .alignment = @alignOf(f32) },
136 \\ },171 \\ },
137 \\ .decls = &[_]TypeInfo.Declaration{},172 \\ .decls = &[_]TypeInfo.Declaration{},
138 \\ },173 \\ },
...@@ -147,42 +182,6 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -147,42 +182,6 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
147 "tmp.zig:27:24: note: referenced here",182 "tmp.zig:27:24: note: referenced here",
148 });183 });
149184
150 cases.add("@Type for tagged union with extra enum field",
151 \\const TypeInfo = @import("builtin").TypeInfo;
152 \\const Tag = @Type(.{
153 \\ .Enum = .{
154 \\ .layout = .Auto,
155 \\ .tag_type = u2,
156 \\ .fields = &[_]TypeInfo.EnumField{
157 \\ .{ .name = "signed", .value = 0 },
158 \\ .{ .name = "unsigned", .value = 1 },
159 \\ .{ .name = "arst", .field_type = 2 },
160 \\ },
161 \\ .decls = &[_]TypeInfo.Declaration{},
162 \\ .is_exhaustive = true,
163 \\ },
164 \\});
165 \\const Tagged = @Type(.{
166 \\ .Union = .{
167 \\ .layout = .Auto,
168 \\ .tag_type = Tag,
169 \\ .fields = &[_]TypeInfo.UnionField{
170 \\ .{ .name = "signed", .field_type = i32 },
171 \\ .{ .name = "unsigned", .field_type = u32 },
172 \\ },
173 \\ .decls = &[_]TypeInfo.Declaration{},
174 \\ },
175 \\});
176 \\export fn entry() void {
177 \\ var tagged = Tagged{ .signed = -1 };
178 \\ tagged = .{ .unsigned = 1 };
179 \\}
180 , &[_][]const u8{
181 "tmp.zig:9:32: error: no member named 'field_type' in struct 'std.builtin.EnumField'",
182 "tmp.zig:18:21: note: referenced here",
183 "tmp.zig:27:18: note: referenced here",
184 });
185
186 cases.add("@Type with undefined",185 cases.add("@Type with undefined",
187 \\comptime {186 \\comptime {
188 \\ _ = @Type(.{ .Array = .{ .len = 0, .child = u8, .sentinel = undefined } });187 \\ _ = @Type(.{ .Array = .{ .len = 0, .child = u8, .sentinel = undefined } });
...@@ -7592,7 +7591,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -7592,7 +7591,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
7592 });7591 });
75937592
7594 cases.add( // fixed bug #20327593 cases.add( // fixed bug #2032
7595 "compile diagnostic string for top level decl type",7594 "compile diagnostic string for top level decl type",
7596 \\export fn entry() void {7595 \\export fn entry() void {
7597 \\ var foo: u32 = @This(){};7596 \\ var foo: u32 = @This(){};
7598 \\}7597 \\}