authorgravatar for topolarity@tapscott.meCody Tapscott <topolarity@tapscott.me> 2022-03-23 22:28:08-07:00
committergravatar for topolarity@tapscott.meCody Tapscott <topolarity@tapscott.me> 2022-03-25 12:27:46-07:00
log0568b4577947f7af2e04cb9e9c95011b0fca88c8
treed7c5f3c3082aba2c3f8ec68ec1f84c07b43054a4
parent1de63ad79331aec9f53a7a9d95069fd0ca5f66f4

Move existing compile errors to independent files

Some cases had to stay behind, either because they required complex case configuration that we don't support in independent files yet, or because they have associated comments which we don't want to lose track of. To make sure I didn't drop any tests in the process, I logged all obj/test/exe test cases from a run of "zig build test" and compared before/after this change. All of the test cases match, with two exceptions: - "use of comptime-known undefined function value" was deleted, since it was a duplicate - "slice sentinel mismatch" was renamed to "vector index out of bounds", since it was incorrectly named

655 files changed, 8121 insertions(+), 8788 deletions(-)

test/compile_errors.zig+235-8788
...@@ -39,180 +39,6 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -39,180 +39,6 @@ pub fn addCases(ctx: *TestContext) !void {
39 try ctx.addErrorCasesFromDir("stage1", test_dir, .stage1, .Exe, true, one_test_case_per_file);39 try ctx.addErrorCasesFromDir("stage1", test_dir, .stage1, .Exe, true, one_test_case_per_file);
40 }40 }
41 }41 }
42 {
43 var case = ctx.obj("stage2 compile errors", .{});
44
45 case.addError(
46 \\export fn a() usize {
47 \\ return @embedFile("/root/foo").len;
48 \\}
49 , &[_][]const u8{
50 ":2:23: error: embed of file outside package path: '/root/foo'",
51 });
52
53 case.addError(
54 \\export fn a() usize {
55 \\ return @import("../../above.zig").len;
56 \\}
57 , &[_][]const u8{
58 ":2:20: error: import of file outside package path: '../../above.zig'",
59 });
60
61 case.addError(
62 \\comptime {
63 \\ var array = [_:0]u8{ 1, 2, 3, 4 };
64 \\ var src_slice: [:0]u8 = &array;
65 \\ var slice = src_slice[2..6];
66 \\ _ = slice;
67 \\}
68 \\comptime {
69 \\ var array = [_:0]u8{ 1, 2, 3, 4 };
70 \\ var slice = array[2..6];
71 \\ _ = slice;
72 \\}
73 \\comptime {
74 \\ var array = [_]u8{ 1, 2, 3, 4 };
75 \\ var slice = array[2..5];
76 \\ _ = slice;
77 \\}
78 \\comptime {
79 \\ var array = [_:0]u8{ 1, 2, 3, 4 };
80 \\ var slice = array[3..2];
81 \\ _ = slice;
82 \\}
83 , &[_][]const u8{
84 ":4:26: error: end index 6 out of bounds for slice of length 4 +1 (sentinel)",
85 ":9:22: error: end index 6 out of bounds for array of length 4 +1 (sentinel)",
86 ":14:22: error: end index 5 out of bounds for array of length 4",
87 ":19:22: error: start index 3 is larger than end index 2",
88 });
89 }
90
91 ctx.objErrStage1("exported enum without explicit integer tag type",
92 \\const E = enum { one, two };
93 \\comptime {
94 \\ @export(E, .{ .name = "E" });
95 \\}
96 \\const e: E = .two;
97 \\comptime {
98 \\ @export(e, .{ .name = "e" });
99 \\}
100 , &.{
101 "tmp.zig:3:13: error: exported enum without explicit integer tag type",
102 "tmp.zig:7:13: error: exported enum value without explicit integer tag type",
103 });
104
105 ctx.objErrStage1("issue #9346: return outside of function scope",
106 \\pub const empty = return 1;
107 , &.{"tmp.zig:1:19: error: 'return' outside function scope"});
108
109 ctx.exeErrStage1("std.fmt error for unused arguments",
110 \\pub fn main() !void {
111 \\ @import("std").debug.print("{d} {d} {d} {d} {d}", .{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15});
112 \\}
113 , &.{
114 "?:?:?: error: 10 unused arguments in '{d} {d} {d} {d} {d}'",
115 });
116
117 ctx.objErrStage1("lazy pointer with undefined element type",
118 \\export fn foo() void {
119 \\ comptime var T: type = undefined;
120 \\ const S = struct { x: *T };
121 \\ const I = @typeInfo(S);
122 \\ _ = I;
123 \\}
124 , &[_][]const u8{
125 ":3:28: error: use of undefined value here causes undefined behavior",
126 });
127
128 ctx.objErrStage1("pointer arithmetic on pointer-to-array",
129 \\export fn foo() void {
130 \\ var x: [10]u8 = undefined;
131 \\ var y = &x;
132 \\ var z = y + 1;
133 \\ _ = z;
134 \\}
135 , &[_][]const u8{
136 "tmp.zig:4:17: error: integer value 1 cannot be coerced to type '*[10]u8'",
137 });
138
139 ctx.objErrStage1("pointer attributes checked when coercing pointer to anon literal",
140 \\comptime {
141 \\ const c: [][]const u8 = &.{"hello", "world" };
142 \\ _ = c;
143 \\}
144 \\comptime {
145 \\ const c: *[2][]const u8 = &.{"hello", "world" };
146 \\ _ = c;
147 \\}
148 \\const S = struct {a: u8 = 1, b: u32 = 2};
149 \\comptime {
150 \\ const c: *S = &.{};
151 \\ _ = c;
152 \\}
153 , &[_][]const u8{
154 "tmp.zig:2:31: error: cannot cast pointer to array literal to slice type '[][]const u8'",
155 "tmp.zig:2:31: note: cast discards const qualifier",
156 "tmp.zig:6:33: error: cannot cast pointer to array literal to '*[2][]const u8'",
157 "tmp.zig:6:33: note: cast discards const qualifier",
158 "tmp.zig:11:21: error: expected type '*S', found '*const struct:11:21'",
159 "tmp.zig:11:21: note: cast discards const qualifier",
160 });
161
162 ctx.objErrStage1("@Type() union payload is undefined",
163 \\const Foo = @Type(.{
164 \\ .Struct = undefined,
165 \\});
166 \\comptime { _ = Foo; }
167 , &[_][]const u8{
168 "tmp.zig:1:20: error: use of undefined value here causes undefined behavior",
169 });
170
171 ctx.objErrStage1("wrong initializer for union payload of type 'type'",
172 \\const U = union(enum) {
173 \\ A: type,
174 \\};
175 \\const S = struct {
176 \\ u: U,
177 \\};
178 \\export fn entry() void {
179 \\ comptime var v: S = undefined;
180 \\ v.u.A = U{ .A = i32 };
181 \\}
182 , &[_][]const u8{
183 "tmp.zig:9:8: error: use of undefined value here causes undefined behavior",
184 });
185
186 ctx.objErrStage1("union with too small explicit signed tag type",
187 \\const U = union(enum(i2)) {
188 \\ A: u8,
189 \\ B: u8,
190 \\ C: u8,
191 \\ D: u8,
192 \\};
193 \\export fn entry() void {
194 \\ _ = U{ .D = 1 };
195 \\}
196 , &[_][]const u8{
197 "tmp.zig:1:22: error: specified integer tag type cannot represent every field",
198 "tmp.zig:1:22: note: type i2 cannot fit values in range 0...3",
199 });
200
201 ctx.objErrStage1("union with too small explicit unsigned tag type",
202 \\const U = union(enum(u2)) {
203 \\ A: u8,
204 \\ B: u8,
205 \\ C: u8,
206 \\ D: u8,
207 \\ E: u8,
208 \\};
209 \\export fn entry() void {
210 \\ _ = U{ .E = 1 };
211 \\}
212 , &[_][]const u8{
213 "tmp.zig:1:22: error: specified integer tag type cannot represent every field",
214 "tmp.zig:1:22: note: type u2 cannot fit values in range 0...4",
215 });
21642
217 {43 {
218 const case = ctx.obj("callconv(.Interrupt) on unsupported platform", .{44 const case = ctx.obj("callconv(.Interrupt) on unsupported platform", .{
...@@ -308,8493 +134,275 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -308,8493 +134,275 @@ pub fn addCases(ctx: *TestContext) !void {
308 });134 });
309 }135 }
310136
311 ctx.objErrStage1("unreachable executed at comptime",137 {
312 \\fn foo(comptime x: i32) i32 {138 const case = ctx.obj("call with new stack on unsupported target", .{
313 \\ comptime {139 .cpu_arch = .wasm32,
314 \\ if (x >= 0) return -x;140 .os_tag = .wasi,
315 \\ unreachable;141 .abi = .none,
316 \\ }142 });
317 \\}143 case.backend = .stage1;
318 \\export fn entry() void {144 case.addError(
319 \\ _ = foo(-42);145 \\var buf: [10]u8 align(16) = undefined;
320 \\}146 \\export fn entry() void {
321 , &[_][]const u8{147 \\ @call(.{.stack = &buf}, foo, .{});
322 "tmp.zig:4:9: error: reached unreachable code",148 \\}
323 "tmp.zig:8:12: note: called from here",149 \\fn foo() void {}
324 });150 , &[_][]const u8{
151 "tmp.zig:3:5: error: target arch 'wasm32' does not support calling with a new stack",
152 });
153 }
325154
326 ctx.objErrStage1("@Type with Type.Int",155 // Note: One of the error messages here is backwards. It would be nice to fix, but that's not
327 \\const builtin = @import("std").builtin;156 // going to stop me from merging this branch which fixes a bunch of other stuff.
328 \\export fn entry() void {157 ctx.objErrStage1("incompatible sentinels",
329 \\ _ = @Type(builtin.Type.Int{158 \\export fn entry1(ptr: [*:255]u8) [*:0]u8 {
330 \\ .signedness = .signed,159 \\ return ptr;
331 \\ .bits = 8,
332 \\ });
333 \\}160 \\}
334 , &[_][]const u8{161 \\export fn entry2(ptr: [*]u8) [*:0]u8 {
335 "tmp.zig:3:31: error: expected type 'std.builtin.Type', found 'std.builtin.Type.Int'",162 \\ return ptr;
336 });
337
338 ctx.objErrStage1("indexing a undefined slice at comptime",
339 \\comptime {
340 \\ var slice: []u8 = undefined;
341 \\ slice[0] = 2;
342 \\}163 \\}
343 , &[_][]const u8{164 \\export fn entry3() void {
344 "tmp.zig:3:10: error: index 0 outside slice of size 0",165 \\ var array: [2:0]u8 = [_:255]u8{1, 2};
345 });166 \\ _ = array;
346
347 ctx.objErrStage1("array in c exported function",
348 \\export fn zig_array(x: [10]u8) void {
349 \\ try std.testing.expect(std.mem.eql(u8, &x, "1234567890"));
350 \\}167 \\}
351 \\const std = @import("std");168 \\export fn entry4() void {
352 \\export fn zig_return_array() [10]u8 {169 \\ var array: [2:0]u8 = [_]u8{1, 2};
353 \\ return "1234567890".*;170 \\ _ = array;
354 \\}171 \\}
355 , &[_][]const u8{172 , &[_][]const u8{
356 "tmp.zig:1:24: error: parameter of type '[10]u8' not allowed in function with calling convention 'C'",173 "tmp.zig:2:12: error: expected type '[*:0]u8', found '[*:255]u8'",
357 "tmp.zig:5:30: error: return type '[10]u8' not allowed in function with calling convention 'C'",174 "tmp.zig:2:12: note: destination pointer requires a terminating '0' sentinel, but source pointer has a terminating '255' sentinel",
358 });175 "tmp.zig:5:12: error: expected type '[*:0]u8', found '[*]u8'",
176 "tmp.zig:5:12: note: destination pointer requires a terminating '0' sentinel",
359177
360 ctx.objErrStage1("@Type for exhaustive enum with undefined tag type",178 "tmp.zig:8:35: error: expected type '[2:255]u8', found '[2:0]u8'",
361 \\const Tag = @Type(.{179 "tmp.zig:8:35: note: destination array requires a terminating '255' sentinel, but source array has a terminating '0' sentinel",
362 \\ .Enum = .{180 "tmp.zig:12:31: error: expected type '[2:0]u8', found '[2]u8'",
363 \\ .layout = .Auto,181 "tmp.zig:12:31: note: destination array requires a terminating '0' sentinel",
364 \\ .tag_type = undefined,
365 \\ .fields = &.{},
366 \\ .decls = &.{},
367 \\ .is_exhaustive = false,
368 \\ },
369 \\});
370 \\export fn entry() void {
371 \\ _ = @intToEnum(Tag, 0);
372 \\}
373 , &[_][]const u8{
374 "tmp.zig:1:20: error: use of undefined value here causes undefined behavior",
375 });182 });
376183
377 ctx.objErrStage1("extern struct with non-extern-compatible integer tag type",184 {
378 \\pub const E = enum(u31) { A, B, C };185 const case = ctx.obj("variable in inline assembly template cannot be found", .{
379 \\pub const S = extern struct {186 .cpu_arch = .x86_64,
380 \\ e: E,187 .os_tag = .linux,
381 \\};188 .abi = .gnu,
382 \\export fn entry() void {189 });
383 \\ const s: S = undefined;190 case.backend = .stage1;
384 \\ _ = s;191 case.addError(
385 \\}192 \\export fn entry() void {
386 , &[_][]const u8{193 \\ var sp = asm volatile (
387 "tmp.zig:3:5: error: extern structs cannot contain fields of type 'E'",194 \\ "mov %[foo], sp"
388 });195 \\ : [bar] "=r" (-> usize)
196 \\ );
197 \\ _ = sp;
198 \\}
199 , &[_][]const u8{
200 "tmp.zig:2:14: error: could not find 'foo' in the inputs or outputs",
201 });
202 }
389203
390 ctx.objErrStage1("@Type for exhaustive enum with non-integer tag type",204 {
391 \\const Tag = @Type(.{205 const case = ctx.obj("bad alignment in @asyncCall", .{
392 \\ .Enum = .{206 .cpu_arch = .aarch64,
393 \\ .layout = .Auto,207 .os_tag = .linux,
394 \\ .tag_type = bool,208 .abi = .none,
395 \\ .fields = &.{},209 });
396 \\ .decls = &.{},210 case.backend = .stage1;
397 \\ .is_exhaustive = false,211 case.addError(
398 \\ },212 \\export fn entry() void {
399 \\});213 \\ var ptr: fn () callconv(.Async) void = func;
400 \\export fn entry() void {214 \\ var bytes: [64]u8 = undefined;
401 \\ _ = @intToEnum(Tag, 0);215 \\ _ = @asyncCall(&bytes, {}, ptr, .{});
402 \\}216 \\}
403 , &[_][]const u8{217 \\fn func() callconv(.Async) void {}
404 "tmp.zig:1:20: error: Type.Enum.tag_type must be an integer type, not 'bool'",218 , &[_][]const u8{
405 });219 "tmp.zig:4:21: error: expected type '[]align(8) u8', found '*[64]u8'",
220 });
221 }
406222
407 ctx.objErrStage1("extern struct with extern-compatible but inferred integer tag type",223 if (builtin.os.tag == .linux) {
408 \\pub const E = enum {224 ctx.testErrStage1("implicit dependency on libc",
409 \\@"0",@"1",@"2",@"3",@"4",@"5",@"6",@"7",@"8",@"9",@"10",@"11",@"12",225 \\extern "c" fn exit(u8) void;
410 \\@"13",@"14",@"15",@"16",@"17",@"18",@"19",@"20",@"21",@"22",@"23",226 \\export fn entry() void {
411 \\@"24",@"25",@"26",@"27",@"28",@"29",@"30",@"31",@"32",@"33",@"34",227 \\ exit(0);
412 \\@"35",@"36",@"37",@"38",@"39",@"40",@"41",@"42",@"43",@"44",@"45",228 \\}
413 \\@"46",@"47",@"48",@"49",@"50",@"51",@"52",@"53",@"54",@"55",@"56",229 , &[_][]const u8{
414 \\@"57",@"58",@"59",@"60",@"61",@"62",@"63",@"64",@"65",@"66",@"67",230 "tmp.zig:3:5: error: dependency on libc must be explicitly specified in the build command",
415 \\@"68",@"69",@"70",@"71",@"72",@"73",@"74",@"75",@"76",@"77",@"78",231 });
416 \\@"79",@"80",@"81",@"82",@"83",@"84",@"85",@"86",@"87",@"88",@"89",
417 \\@"90",@"91",@"92",@"93",@"94",@"95",@"96",@"97",@"98",@"99",@"100",
418 \\@"101",@"102",@"103",@"104",@"105",@"106",@"107",@"108",@"109",
419 \\@"110",@"111",@"112",@"113",@"114",@"115",@"116",@"117",@"118",
420 \\@"119",@"120",@"121",@"122",@"123",@"124",@"125",@"126",@"127",
421 \\@"128",@"129",@"130",@"131",@"132",@"133",@"134",@"135",@"136",
422 \\@"137",@"138",@"139",@"140",@"141",@"142",@"143",@"144",@"145",
423 \\@"146",@"147",@"148",@"149",@"150",@"151",@"152",@"153",@"154",
424 \\@"155",@"156",@"157",@"158",@"159",@"160",@"161",@"162",@"163",
425 \\@"164",@"165",@"166",@"167",@"168",@"169",@"170",@"171",@"172",
426 \\@"173",@"174",@"175",@"176",@"177",@"178",@"179",@"180",@"181",
427 \\@"182",@"183",@"184",@"185",@"186",@"187",@"188",@"189",@"190",
428 \\@"191",@"192",@"193",@"194",@"195",@"196",@"197",@"198",@"199",
429 \\@"200",@"201",@"202",@"203",@"204",@"205",@"206",@"207",@"208",
430 \\@"209",@"210",@"211",@"212",@"213",@"214",@"215",@"216",@"217",
431 \\@"218",@"219",@"220",@"221",@"222",@"223",@"224",@"225",@"226",
432 \\@"227",@"228",@"229",@"230",@"231",@"232",@"233",@"234",@"235",
433 \\@"236",@"237",@"238",@"239",@"240",@"241",@"242",@"243",@"244",
434 \\@"245",@"246",@"247",@"248",@"249",@"250",@"251",@"252",@"253",
435 \\@"254",@"255"
436 \\};
437 \\pub const S = extern struct {
438 \\ e: E,
439 \\};
440 \\export fn entry() void {
441 \\ if (@typeInfo(E).Enum.tag_type != u8) @compileError("did not infer u8 tag type");
442 \\ const s: S = undefined;
443 \\ _ = s;
444 \\}
445 , &[_][]const u8{
446 "tmp.zig:31:5: error: extern structs cannot contain fields of type 'E'",
447 });
448232
449 ctx.objErrStage1("@Type for tagged union with extra enum field",233 ctx.testErrStage1("libc headers note",
450 \\const Tag = @Type(.{234 \\const c = @cImport(@cInclude("stdio.h"));
451 \\ .Enum = .{235 \\export fn entry() void {
452 \\ .layout = .Auto,236 \\ _ = c.printf("hello, world!\n");
453 \\ .tag_type = u2,237 \\}
454 \\ .fields = &.{238 , &[_][]const u8{
455 \\ .{ .name = "signed", .value = 0 },239 "tmp.zig:1:11: error: C import failed",
456 \\ .{ .name = "unsigned", .value = 1 },240 "tmp.zig:1:11: note: libc headers not available; compilation does not link against libc",
457 \\ .{ .name = "arst", .value = 2 },241 });
458 \\ },242 }
459 \\ .decls = &.{},
460 \\ .is_exhaustive = true,
461 \\ },
462 \\});
463 \\const Tagged = @Type(.{
464 \\ .Union = .{
465 \\ .layout = .Auto,
466 \\ .tag_type = Tag,
467 \\ .fields = &.{
468 \\ .{ .name = "signed", .field_type = i32, .alignment = @alignOf(i32) },
469 \\ .{ .name = "unsigned", .field_type = u32, .alignment = @alignOf(u32) },
470 \\ },
471 \\ .decls = &.{},
472 \\ },
473 \\});
474 \\export fn entry() void {
475 \\ var tagged = Tagged{ .signed = -1 };
476 \\ tagged = .{ .unsigned = 1 };
477 \\}
478 , &[_][]const u8{
479 "tmp.zig:14:23: error: enum field missing: 'arst'",
480 });
481243
482 ctx.objErrStage1("field access of opaque type",244 {
483 \\const MyType = opaque {};245 const case = ctx.obj("wrong same named struct", .{});
484 \\246 case.backend = .stage1;
485 \\export fn entry() bool {
486 \\ var x: i32 = 1;
487 \\ return bar(@ptrCast(*MyType, &x));
488 \\}
489 \\
490 \\fn bar(x: *MyType) bool {
491 \\ return x.blah;
492 \\}
493 , &[_][]const u8{
494 "tmp.zig:9:13: error: no member named 'blah' in opaque type 'MyType'",
495 });
496247
497 ctx.objErrStage1("opaque type with field",248 case.addSourceFile("a.zig",
498 \\const Opaque = opaque { foo: i32 };249 \\pub const Foo = struct {
499 \\export fn entry() void {250 \\ x: i32,
500 \\ const foo: ?*Opaque = null;251 \\};
501 \\ _ = foo;252 );
502 \\}
503 , &[_][]const u8{
504 "tmp.zig:1:25: error: opaque types cannot have fields",
505 });
506253
507 ctx.objErrStage1("@Type(.Fn) with is_generic = true",254 case.addSourceFile("b.zig",
508 \\const Foo = @Type(.{255 \\pub const Foo = struct {
509 \\ .Fn = .{256 \\ z: f64,
510 \\ .calling_convention = .Unspecified,257 \\};
511 \\ .alignment = 0,258 );
512 \\ .is_generic = true,
513 \\ .is_var_args = false,
514 \\ .return_type = u0,
515 \\ .args = &.{},
516 \\ },
517 \\});
518 \\comptime { _ = Foo; }
519 , &[_][]const u8{
520 "tmp.zig:1:20: error: Type.Fn.is_generic must be false for @Type",
521 });
522259
523 ctx.objErrStage1("@Type(.Fn) with is_var_args = true and non-C callconv",260 case.addError(
524 \\const Foo = @Type(.{261 \\const a = @import("a.zig");
525 \\ .Fn = .{262 \\const b = @import("b.zig");
526 \\ .calling_convention = .Unspecified,263 \\
527 \\ .alignment = 0,264 \\export fn entry() void {
528 \\ .is_generic = false,265 \\ var a1: a.Foo = undefined;
529 \\ .is_var_args = true,266 \\ bar(&a1);
530 \\ .return_type = u0,267 \\}
531 \\ .args = &.{},268 \\
532 \\ },269 \\fn bar(x: *b.Foo) void {_ = x;}
533 \\});270 , &[_][]const u8{
534 \\comptime { _ = Foo; }271 "tmp.zig:6:10: error: expected type '*b.Foo', found '*a.Foo'",
535 , &[_][]const u8{272 "tmp.zig:6:10: note: pointer type child 'a.Foo' cannot cast into pointer type child 'b.Foo'",
536 "tmp.zig:1:20: error: varargs functions must have C calling convention",273 "a.zig:1:17: note: a.Foo declared here",
537 });274 "b.zig:1:17: note: b.Foo declared here",
275 });
276 }
538277
539 ctx.objErrStage1("@Type(.Fn) with return_type = null",278 {
540 \\const Foo = @Type(.{279 const case = ctx.obj("multiple files with private function error", .{});
541 \\ .Fn = .{280 case.backend = .stage1;
542 \\ .calling_convention = .Unspecified,
543 \\ .alignment = 0,
544 \\ .is_generic = false,
545 \\ .is_var_args = false,
546 \\ .return_type = null,
547 \\ .args = &.{},
548 \\ },
549 \\});
550 \\comptime { _ = Foo; }
551 , &[_][]const u8{
552 "tmp.zig:1:20: error: Type.Fn.return_type must be non-null for @Type",
553 });
554281
555 ctx.objErrStage1("@Type for union with opaque field",282 case.addSourceFile("foo.zig",
556 \\const Untagged = @Type(.{283 \\fn privateFunction() void { }
557 \\ .Union = .{284 );
558 \\ .layout = .Auto,
559 \\ .tag_type = null,
560 \\ .fields = &.{
561 \\ .{ .name = "foo", .field_type = opaque {}, .alignment = 1 },
562 \\ },
563 \\ .decls = &.{},
564 \\ },
565 \\});
566 \\export fn entry() void {
567 \\ _ = Untagged{};
568 \\}
569 , &[_][]const u8{
570 "tmp.zig:1:25: error: opaque types have unknown size and therefore cannot be directly embedded in unions",
571 });
572285
573 ctx.objErrStage1("slice sentinel mismatch",286 case.addError(
574 \\export fn entry() void {287 \\const foo = @import("foo.zig",);
575 \\ const x = @import("std").meta.Vector(3, f32){ 25, 75, 5, 0 };288 \\
576 \\ _ = x;289 \\export fn callPrivFunction() void {
577 \\}290 \\ foo.privateFunction();
578 , &[_][]const u8{291 \\}
579 "tmp.zig:2:62: error: index 3 outside vector of size 3",292 , &[_][]const u8{
580 });293 "tmp.zig:4:8: error: 'privateFunction' is private",
294 "foo.zig:1:1: note: declared here",
295 });
296 }
581297
582 ctx.objErrStage1("slice sentinel mismatch",298 {
583 \\export fn entry() void {299 const case = ctx.obj("multiple files with private member instance function (canonical invocation) error", .{});
584 \\ const y: [:1]const u8 = &[_:2]u8{ 1, 2 };300 case.backend = .stage1;
585 \\ _ = y;
586 \\}
587 , &[_][]const u8{
588 "tmp.zig:2:37: error: expected type '[:1]const u8', found '*const [2:2]u8'",
589 });
590301
591 ctx.objErrStage1("@Type for union with zero fields",302 case.addSourceFile("foo.zig",
592 \\const Untagged = @Type(.{303 \\pub const Foo = struct {
593 \\ .Union = .{304 \\ fn privateFunction(self: *Foo) void { _ = self; }
594 \\ .layout = .Auto,305 \\};
595 \\ .tag_type = null,306 );
596 \\ .fields = &.{},
597 \\ .decls = &.{},
598 \\ },
599 \\});
600 \\export fn entry() void {
601 \\ _ = Untagged{};
602 \\}
603 , &[_][]const u8{
604 "tmp.zig:1:25: error: unions must have 1 or more fields",
605 });
606307
607 ctx.objErrStage1("@Type for exhaustive enum with zero fields",308 case.addError(
608 \\const Tag = @Type(.{309 \\const Foo = @import("foo.zig",).Foo;
609 \\ .Enum = .{310 \\
610 \\ .layout = .Auto,311 \\export fn callPrivFunction() void {
611 \\ .tag_type = u1,312 \\ var foo = Foo{};
612 \\ .fields = &.{},313 \\ Foo.privateFunction(foo);
613 \\ .decls = &.{},314 \\}
614 \\ .is_exhaustive = true,315 , &[_][]const u8{
615 \\ },316 "tmp.zig:5:8: error: 'privateFunction' is private",
616 \\});317 "foo.zig:2:5: note: declared here",
617 \\export fn entry() void {318 });
618 \\ _ = @intToEnum(Tag, 0);319 }
619 \\}
620 , &[_][]const u8{
621 "tmp.zig:1:20: error: enums must have 1 or more fields",
622 });
623
624 ctx.objErrStage1("@Type for tagged union with extra union field",
625 \\const Tag = @Type(.{
626 \\ .Enum = .{
627 \\ .layout = .Auto,
628 \\ .tag_type = u1,
629 \\ .fields = &.{
630 \\ .{ .name = "signed", .value = 0 },
631 \\ .{ .name = "unsigned", .value = 1 },
632 \\ },
633 \\ .decls = &.{},
634 \\ .is_exhaustive = true,
635 \\ },
636 \\});
637 \\const Tagged = @Type(.{
638 \\ .Union = .{
639 \\ .layout = .Auto,
640 \\ .tag_type = Tag,
641 \\ .fields = &.{
642 \\ .{ .name = "signed", .field_type = i32, .alignment = @alignOf(i32) },
643 \\ .{ .name = "unsigned", .field_type = u32, .alignment = @alignOf(u32) },
644 \\ .{ .name = "arst", .field_type = f32, .alignment = @alignOf(f32) },
645 \\ },
646 \\ .decls = &.{},
647 \\ },
648 \\});
649 \\export fn entry() void {
650 \\ var tagged = Tagged{ .signed = -1 };
651 \\ tagged = .{ .unsigned = 1 };
652 \\}
653 , &[_][]const u8{
654 "tmp.zig:13:23: error: enum field not found: 'arst'",
655 "tmp.zig:1:20: note: enum declared here",
656 });
657
658 ctx.objErrStage1("@Type with undefined",
659 \\comptime {
660 \\ _ = @Type(.{ .Array = .{ .len = 0, .child = u8, .sentinel = undefined } });
661 \\}
662 \\comptime {
663 \\ _ = @Type(.{
664 \\ .Struct = .{
665 \\ .fields = undefined,
666 \\ .decls = undefined,
667 \\ .is_tuple = false,
668 \\ .layout = .Auto,
669 \\ },
670 \\ });
671 \\}
672 , &[_][]const u8{
673 "tmp.zig:2:16: error: use of undefined value here causes undefined behavior",
674 "tmp.zig:5:16: error: use of undefined value here causes undefined behavior",
675 });
676
677 ctx.objErrStage1("struct with declarations unavailable for @Type",
678 \\export fn entry() void {
679 \\ _ = @Type(@typeInfo(struct { const foo = 1; }));
680 \\}
681 , &[_][]const u8{
682 "tmp.zig:2:15: error: Type.Struct.decls must be empty for @Type",
683 });
684
685 ctx.objErrStage1("enum with declarations unavailable for @Type",
686 \\export fn entry() void {
687 \\ _ = @Type(@typeInfo(enum { foo, const bar = 1; }));
688 \\}
689 , &[_][]const u8{
690 "tmp.zig:2:15: error: Type.Enum.decls must be empty for @Type",
691 });
692
693 ctx.testErrStage1("reject extern variables with initializers",
694 \\extern var foo: int = 2;
695 , &[_][]const u8{
696 "tmp.zig:1:23: error: extern variables have no initializers",
697 });
698
699 ctx.testErrStage1("duplicate/unused labels",
700 \\comptime {
701 \\ blk: { blk: while (false) {} }
702 \\}
703 \\comptime {
704 \\ blk: while (false) { blk: for (@as([0]void, undefined)) |_| {} }
705 \\}
706 \\comptime {
707 \\ blk: for (@as([0]void, undefined)) |_| { blk: {} }
708 \\}
709 \\comptime {
710 \\ blk: {}
711 \\}
712 \\comptime {
713 \\ blk: while(false) {}
714 \\}
715 \\comptime {
716 \\ blk: for(@as([0]void, undefined)) |_| {}
717 \\}
718 , &[_][]const u8{
719 "tmp.zig:2:12: error: redefinition of label 'blk'",
720 "tmp.zig:2:5: note: previous definition here",
721 "tmp.zig:5:26: error: redefinition of label 'blk'",
722 "tmp.zig:5:5: note: previous definition here",
723 "tmp.zig:8:46: error: redefinition of label 'blk'",
724 "tmp.zig:8:5: note: previous definition here",
725 "tmp.zig:11:5: error: unused block label",
726 "tmp.zig:14:5: error: unused while loop label",
727 "tmp.zig:17:5: error: unused for loop label",
728 });
729
730 ctx.testErrStage1("@alignCast of zero sized types",
731 \\export fn foo() void {
732 \\ const a: *void = undefined;
733 \\ _ = @alignCast(2, a);
734 \\}
735 \\export fn bar() void {
736 \\ const a: ?*void = undefined;
737 \\ _ = @alignCast(2, a);
738 \\}
739 \\export fn baz() void {
740 \\ const a: []void = undefined;
741 \\ _ = @alignCast(2, a);
742 \\}
743 \\export fn qux() void {
744 \\ const a = struct {
745 \\ fn a(comptime b: u32) void { _ = b; }
746 \\ }.a;
747 \\ _ = @alignCast(2, a);
748 \\}
749 , &[_][]const u8{
750 "tmp.zig:3:23: error: cannot adjust alignment of zero sized type '*void'",
751 "tmp.zig:7:23: error: cannot adjust alignment of zero sized type '?*void'",
752 "tmp.zig:11:23: error: cannot adjust alignment of zero sized type '[]void'",
753 "tmp.zig:17:23: error: cannot adjust alignment of zero sized type 'fn(u32) anytype'",
754 });
755
756 ctx.testErrStage1("invalid non-exhaustive enum to union",
757 \\const E = enum(u8) {
758 \\ a,
759 \\ b,
760 \\ _,
761 \\};
762 \\const U = union(E) {
763 \\ a,
764 \\ b,
765 \\};
766 \\export fn foo() void {
767 \\ var e = @intToEnum(E, 15);
768 \\ var u: U = e;
769 \\ _ = u;
770 \\}
771 \\export fn bar() void {
772 \\ const e = @intToEnum(E, 15);
773 \\ var u: U = e;
774 \\ _ = u;
775 \\}
776 , &[_][]const u8{
777 "tmp.zig:12:16: error: runtime cast to union 'U' from non-exhaustive enum",
778 "tmp.zig:17:16: error: no tag by value 15",
779 });
780
781 ctx.testErrStage1("switching with exhaustive enum has '_' prong ",
782 \\const E = enum{
783 \\ a,
784 \\ b,
785 \\};
786 \\pub export fn entry() void {
787 \\ var e: E = .b;
788 \\ switch (e) {
789 \\ .a => {},
790 \\ .b => {},
791 \\ _ => {},
792 \\ }
793 \\}
794 , &[_][]const u8{
795 "tmp.zig:7:5: error: switch on exhaustive enum has `_` prong",
796 });
797
798 ctx.testErrStage1("invalid pointer with @Type",
799 \\export fn entry() void {
800 \\ _ = @Type(.{ .Pointer = .{
801 \\ .size = .One,
802 \\ .is_const = false,
803 \\ .is_volatile = false,
804 \\ .alignment = 1,
805 \\ .address_space = .generic,
806 \\ .child = u8,
807 \\ .is_allowzero = false,
808 \\ .sentinel = &@as(u8, 0),
809 \\ }});
810 \\}
811 , &[_][]const u8{
812 "tmp.zig:2:16: error: sentinels are only allowed on slices and unknown-length pointers",
813 });
814
815 ctx.objErrStage1("@Type(.Pointer) with invalid address space ",
816 \\export fn entry() void {
817 \\ _ = @Type(.{ .Pointer = .{
818 \\ .size = .One,
819 \\ .is_const = false,
820 \\ .is_volatile = false,
821 \\ .alignment = 1,
822 \\ .address_space = .gs,
823 \\ .child = u8,
824 \\ .is_allowzero = false,
825 \\ .sentinel = null,
826 \\ }});
827 \\}
828 , &[_][]const u8{
829 "tmp.zig:2:16: error: address space 'gs' not available in stage 1 compiler, must be .generic",
830 });
831
832 ctx.testErrStage1("helpful return type error message",
833 \\export fn foo() u32 {
834 \\ return error.Ohno;
835 \\}
836 \\fn bar() !u32 {
837 \\ return error.Ohno;
838 \\}
839 \\export fn baz() void {
840 \\ try bar();
841 \\}
842 \\export fn qux() u32 {
843 \\ return bar();
844 \\}
845 \\export fn quux() u32 {
846 \\ var buf: u32 = 0;
847 \\ buf = bar();
848 \\}
849 , &[_][]const u8{
850 "tmp.zig:2:17: error: expected type 'u32', found 'error{Ohno}'",
851 "tmp.zig:1:17: note: function cannot return an error",
852 "tmp.zig:8:5: error: expected type 'void', found '@typeInfo(@typeInfo(@TypeOf(bar)).Fn.return_type.?).ErrorUnion.error_set'",
853 "tmp.zig:7:17: note: function cannot return an error",
854 "tmp.zig:11:15: error: cannot convert error union to payload type. consider using `try`, `catch`, or `if`. expected type 'u32', found '@typeInfo(@typeInfo(@TypeOf(bar)).Fn.return_type.?).ErrorUnion.error_set!u32'",
855 "tmp.zig:10:17: note: function cannot return an error",
856 "tmp.zig:15:14: error: cannot convert error union to payload type. consider using `try`, `catch`, or `if`. expected type 'u32', found '@typeInfo(@typeInfo(@TypeOf(bar)).Fn.return_type.?).ErrorUnion.error_set!u32'",
857 "tmp.zig:14:5: note: cannot store an error in type 'u32'",
858 });
859
860 ctx.testErrStage1("int/float conversion to comptime_int/float",
861 \\export fn foo() void {
862 \\ var a: f32 = 2;
863 \\ _ = @floatToInt(comptime_int, a);
864 \\}
865 \\export fn bar() void {
866 \\ var a: u32 = 2;
867 \\ _ = @intToFloat(comptime_float, a);
868 \\}
869 , &[_][]const u8{
870 "tmp.zig:3:35: error: unable to evaluate constant expression",
871 "tmp.zig:7:37: error: unable to evaluate constant expression",
872 });
873
874 ctx.objErrStage1("extern variable has no type",
875 \\extern var foo;
876 \\pub export fn entry() void {
877 \\ foo;
878 \\}
879 , &[_][]const u8{
880 "tmp.zig:1:8: error: unable to infer variable type",
881 });
882
883 ctx.objErrStage1("@src outside function",
884 \\comptime {
885 \\ @src();
886 \\}
887 , &[_][]const u8{
888 "tmp.zig:2:5: error: @src outside function",
889 });
890
891 ctx.objErrStage1("call assigned to constant",
892 \\const Foo = struct {
893 \\ x: i32,
894 \\};
895 \\fn foo() Foo {
896 \\ return .{ .x = 42 };
897 \\}
898 \\fn bar(val: anytype) Foo {
899 \\ return .{ .x = val };
900 \\}
901 \\export fn entry() void {
902 \\ const baz: Foo = undefined;
903 \\ baz = foo();
904 \\}
905 \\export fn entry1() void {
906 \\ const baz: Foo = undefined;
907 \\ baz = bar(42);
908 \\}
909 , &[_][]const u8{
910 "tmp.zig:12:14: error: cannot assign to constant",
911 "tmp.zig:16:14: error: cannot assign to constant",
912 });
913
914 ctx.objErrStage1("invalid pointer syntax",
915 \\export fn foo() void {
916 \\ var guid: *:0 const u8 = undefined;
917 \\}
918 , &[_][]const u8{
919 "tmp.zig:2:16: error: expected type expression, found ':'",
920 });
921
922 ctx.objErrStage1("declaration between fields",
923 \\const S = struct {
924 \\ const foo = 2;
925 \\ const bar = 2;
926 \\ const baz = 2;
927 \\ a: struct {
928 \\ a: u32,
929 \\ b: u32,
930 \\ },
931 \\ const foo1 = 2;
932 \\ const bar1 = 2;
933 \\ const baz1 = 2;
934 \\ b: usize,
935 \\};
936 \\comptime {
937 \\ _ = S;
938 \\}
939 , &[_][]const u8{
940 "tmp.zig:9:5: error: declarations are not allowed between container fields",
941 "tmp.zig:5:5: note: field before declarations here",
942 "tmp.zig:12:5: note: field after declarations here",
943 });
944
945 ctx.objErrStage1("non-extern function with var args",
946 \\fn foo(args: ...) void {}
947 \\export fn entry() void {
948 \\ foo();
949 \\}
950 , &[_][]const u8{
951 "tmp.zig:1:14: error: expected type expression, found '...'",
952 });
953
954 ctx.testErrStage1("invalid int casts",
955 \\export fn foo() void {
956 \\ var a: u32 = 2;
957 \\ _ = @intCast(comptime_int, a);
958 \\}
959 \\export fn bar() void {
960 \\ var a: u32 = 2;
961 \\ _ = @intToFloat(u32, a);
962 \\}
963 \\export fn baz() void {
964 \\ var a: u32 = 2;
965 \\ _ = @floatToInt(u32, a);
966 \\}
967 \\export fn qux() void {
968 \\ var a: f32 = 2;
969 \\ _ = @intCast(u32, a);
970 \\}
971 , &[_][]const u8{
972 "tmp.zig:3:32: error: unable to evaluate constant expression",
973 "tmp.zig:7:21: error: expected float type, found 'u32'",
974 "tmp.zig:11:26: error: expected float type, found 'u32'",
975 "tmp.zig:15:23: error: expected integer type, found 'f32'",
976 });
977
978 ctx.testErrStage1("invalid float casts",
979 \\export fn foo() void {
980 \\ var a: f32 = 2;
981 \\ _ = @floatCast(comptime_float, a);
982 \\}
983 \\export fn bar() void {
984 \\ var a: f32 = 2;
985 \\ _ = @floatToInt(f32, a);
986 \\}
987 \\export fn baz() void {
988 \\ var a: f32 = 2;
989 \\ _ = @intToFloat(f32, a);
990 \\}
991 \\export fn qux() void {
992 \\ var a: u32 = 2;
993 \\ _ = @floatCast(f32, a);
994 \\}
995 , &[_][]const u8{
996 "tmp.zig:3:36: error: unable to evaluate constant expression",
997 "tmp.zig:7:21: error: expected integer type, found 'f32'",
998 "tmp.zig:11:26: error: expected int type, found 'f32'",
999 "tmp.zig:15:25: error: expected float type, found 'u32'",
1000 });
1001
1002 ctx.testErrStage1("invalid assignments",
1003 \\export fn entry1() void {
1004 \\ var a: []const u8 = "foo";
1005 \\ a[0..2] = "bar";
1006 \\}
1007 \\export fn entry2() void {
1008 \\ var a: u8 = 2;
1009 \\ a + 2 = 3;
1010 \\}
1011 \\export fn entry4() void {
1012 \\ 2 + 2 = 3;
1013 \\}
1014 , &[_][]const u8{
1015 "tmp.zig:3:6: error: invalid left-hand side to assignment",
1016 "tmp.zig:7:7: error: invalid left-hand side to assignment",
1017 "tmp.zig:10:7: error: invalid left-hand side to assignment",
1018 });
1019
1020 ctx.testErrStage1("reassign to array parameter",
1021 \\fn reassign(a: [3]f32) void {
1022 \\ a = [3]f32{4, 5, 6};
1023 \\}
1024 \\export fn entry() void {
1025 \\ reassign(.{1, 2, 3});
1026 \\}
1027 , &[_][]const u8{
1028 "tmp.zig:2:15: error: cannot assign to constant",
1029 });
1030
1031 ctx.testErrStage1("reassign to slice parameter",
1032 \\pub fn reassign(s: []const u8) void {
1033 \\ s = s[0..];
1034 \\}
1035 \\export fn entry() void {
1036 \\ reassign("foo");
1037 \\}
1038 , &[_][]const u8{
1039 "tmp.zig:2:10: error: cannot assign to constant",
1040 });
1041
1042 ctx.testErrStage1("reassign to struct parameter",
1043 \\const S = struct {
1044 \\ x: u32,
1045 \\};
1046 \\fn reassign(s: S) void {
1047 \\ s = S{.x = 2};
1048 \\}
1049 \\export fn entry() void {
1050 \\ reassign(S{.x = 3});
1051 \\}
1052 , &[_][]const u8{
1053 "tmp.zig:5:10: error: cannot assign to constant",
1054 });
1055
1056 ctx.testErrStage1("reference to const data",
1057 \\export fn foo() void {
1058 \\ var ptr = &[_]u8{0,0,0,0};
1059 \\ ptr[1] = 2;
1060 \\}
1061 \\export fn bar() void {
1062 \\ var ptr = &@as(u32, 2);
1063 \\ ptr.* = 2;
1064 \\}
1065 \\export fn baz() void {
1066 \\ var ptr = &true;
1067 \\ ptr.* = false;
1068 \\}
1069 \\export fn qux() void {
1070 \\ const S = struct{
1071 \\ x: usize,
1072 \\ y: usize,
1073 \\ };
1074 \\ var ptr = &S{.x=1,.y=2};
1075 \\ ptr.x = 2;
1076 \\}
1077 , &[_][]const u8{
1078 "tmp.zig:3:14: error: cannot assign to constant",
1079 "tmp.zig:7:13: error: cannot assign to constant",
1080 "tmp.zig:11:13: error: cannot assign to constant",
1081 "tmp.zig:19:13: error: cannot assign to constant",
1082 });
1083
1084 ctx.testErrStage1("cast between ?T where T is not a pointer",
1085 \\pub const fnty1 = ?fn (i8) void;
1086 \\pub const fnty2 = ?fn (u64) void;
1087 \\export fn entry() void {
1088 \\ var a: fnty1 = undefined;
1089 \\ var b: fnty2 = undefined;
1090 \\ a = b;
1091 \\}
1092 , &[_][]const u8{
1093 "tmp.zig:6:9: error: expected type '?fn(i8) void', found '?fn(u64) void'",
1094 "tmp.zig:6:9: note: optional type child 'fn(u64) void' cannot cast into optional type child 'fn(i8) void'",
1095 });
1096
1097 ctx.testErrStage1("unused variable error on errdefer",
1098 \\fn foo() !void {
1099 \\ errdefer |a| unreachable;
1100 \\ return error.A;
1101 \\}
1102 \\export fn entry() void {
1103 \\ foo() catch unreachable;
1104 \\}
1105 , &[_][]const u8{
1106 "tmp.zig:2:15: error: unused variable: 'a'",
1107 });
1108
1109 ctx.testErrStage1("comparison of non-tagged union and enum literal",
1110 \\export fn entry() void {
1111 \\ const U = union { A: u32, B: u64 };
1112 \\ var u = U{ .A = 42 };
1113 \\ var ok = u == .A;
1114 \\ _ = ok;
1115 \\}
1116 , &[_][]const u8{
1117 "tmp.zig:4:16: error: comparison of union and enum literal is only valid for tagged union types",
1118 "tmp.zig:2:15: note: type U is not a tagged union",
1119 });
1120
1121 ctx.testErrStage1("shift on type with non-power-of-two size",
1122 \\export fn entry() void {
1123 \\ const S = struct {
1124 \\ fn a() void {
1125 \\ var x: u24 = 42;
1126 \\ _ = x >> 24;
1127 \\ }
1128 \\ fn b() void {
1129 \\ var x: u24 = 42;
1130 \\ _ = x << 24;
1131 \\ }
1132 \\ fn c() void {
1133 \\ var x: u24 = 42;
1134 \\ _ = @shlExact(x, 24);
1135 \\ }
1136 \\ fn d() void {
1137 \\ var x: u24 = 42;
1138 \\ _ = @shrExact(x, 24);
1139 \\ }
1140 \\ };
1141 \\ S.a();
1142 \\ S.b();
1143 \\ S.c();
1144 \\ S.d();
1145 \\}
1146 , &[_][]const u8{
1147 "tmp.zig:5:19: error: RHS of shift is too large for LHS type",
1148 "tmp.zig:9:19: error: RHS of shift is too large for LHS type",
1149 "tmp.zig:13:17: error: RHS of shift is too large for LHS type",
1150 "tmp.zig:17:17: error: RHS of shift is too large for LHS type",
1151 });
1152
1153 ctx.testErrStage1("combination of nosuspend and async",
1154 \\export fn entry() void {
1155 \\ nosuspend {
1156 \\ const bar = async foo();
1157 \\ suspend {}
1158 \\ resume bar;
1159 \\ }
1160 \\}
1161 \\fn foo() void {}
1162 , &[_][]const u8{
1163 "tmp.zig:4:9: error: suspend inside nosuspend block",
1164 "tmp.zig:2:5: note: nosuspend block here",
1165 });
1166
1167 ctx.objErrStage1("atomicrmw with bool op not .Xchg",
1168 \\export fn entry() void {
1169 \\ var x = false;
1170 \\ _ = @atomicRmw(bool, &x, .Add, true, .SeqCst);
1171 \\}
1172 , &[_][]const u8{
1173 "tmp.zig:3:30: error: @atomicRmw with bool only allowed with .Xchg",
1174 });
1175
1176 ctx.testErrStage1("@TypeOf with no arguments",
1177 \\export fn entry() void {
1178 \\ _ = @TypeOf();
1179 \\}
1180 , &[_][]const u8{
1181 "tmp.zig:2:9: error: expected at least 1 argument, found 0",
1182 });
1183
1184 ctx.testErrStage1("@TypeOf with incompatible arguments",
1185 \\export fn entry() void {
1186 \\ var var_1: f32 = undefined;
1187 \\ var var_2: u32 = undefined;
1188 \\ _ = @TypeOf(var_1, var_2);
1189 \\}
1190 , &[_][]const u8{
1191 "tmp.zig:4:9: error: incompatible types: 'f32' and 'u32'",
1192 });
1193
1194 ctx.testErrStage1("type mismatch with tuple concatenation",
1195 \\export fn entry() void {
1196 \\ var x = .{};
1197 \\ x = x ++ .{ 1, 2, 3 };
1198 \\}
1199 , &[_][]const u8{
1200 "tmp.zig:3:11: error: expected type 'struct:2:14', found 'struct:3:11'",
1201 });
1202
1203 ctx.testErrStage1("@tagName on invalid value of non-exhaustive enum",
1204 \\test "enum" {
1205 \\ const E = enum(u8) {A, B, _};
1206 \\ _ = @tagName(@intToEnum(E, 5));
1207 \\}
1208 , &[_][]const u8{
1209 "tmp.zig:3:18: error: no tag by value 5",
1210 });
1211
1212 ctx.testErrStage1("@ptrToInt with pointer to zero-sized type",
1213 \\export fn entry() void {
1214 \\ var pointer: ?*u0 = null;
1215 \\ var x = @ptrToInt(pointer);
1216 \\ _ = x;
1217 \\}
1218 , &[_][]const u8{
1219 "tmp.zig:3:23: error: pointer to size 0 type has no address",
1220 });
1221
1222 ctx.testErrStage1("access invalid @typeInfo decl",
1223 \\const A = B;
1224 \\test "Crash" {
1225 \\ _ = @typeInfo(@This()).Struct.decls[0];
1226 \\}
1227 , &[_][]const u8{
1228 "tmp.zig:1:11: error: use of undeclared identifier 'B'",
1229 });
1230
1231 ctx.testErrStage1("reject extern function definitions with body",
1232 \\extern "c" fn definitelyNotInLibC(a: i32, b: i32) i32 {
1233 \\ return a + b;
1234 \\}
1235 , &[_][]const u8{
1236 "tmp.zig:1:1: error: extern functions have no body",
1237 });
1238
1239 ctx.testErrStage1("duplicate field in anonymous struct literal",
1240 \\export fn entry() void {
1241 \\ const anon = .{
1242 \\ .inner = .{
1243 \\ .a = .{
1244 \\ .something = "text",
1245 \\ },
1246 \\ .a = .{},
1247 \\ },
1248 \\ };
1249 \\ _ = anon;
1250 \\}
1251 , &[_][]const u8{
1252 "tmp.zig:7:13: error: duplicate field",
1253 "tmp.zig:4:13: note: other field here",
1254 });
1255
1256 ctx.testErrStage1("type mismatch in C prototype with varargs",
1257 \\const fn_ty = ?fn ([*c]u8, ...) callconv(.C) void;
1258 \\extern fn fn_decl(fmt: [*:0]u8, ...) void;
1259 \\
1260 \\export fn main() void {
1261 \\ const x: fn_ty = fn_decl;
1262 \\ _ = x;
1263 \\}
1264 , &[_][]const u8{
1265 "tmp.zig:5:22: error: expected type 'fn([*c]u8, ...) callconv(.C) void', found 'fn([*:0]u8, ...) callconv(.C) void'",
1266 });
1267
1268 ctx.objErrStage1("function call assigned to incorrect type",
1269 \\export fn entry() void {
1270 \\ var arr: [4]f32 = undefined;
1271 \\ arr = concat();
1272 \\}
1273 \\fn concat() [16]f32 {
1274 \\ return [1]f32{0}**16;
1275 \\}
1276 , &[_][]const u8{
1277 "tmp.zig:3:17: error: expected type '[4]f32', found '[16]f32'",
1278 });
1279
1280 ctx.objErrStage1("generic function call assigned to incorrect type",
1281 \\pub export fn entry() void {
1282 \\ var res: []i32 = undefined;
1283 \\ res = myAlloc(i32);
1284 \\}
1285 \\fn myAlloc(comptime arg: type) anyerror!arg{
1286 \\ unreachable;
1287 \\}
1288 , &[_][]const u8{
1289 "tmp.zig:3:18: error: expected type '[]i32', found 'anyerror!i32",
1290 });
1291
1292 ctx.testErrStage1("non-exhaustive enum marker assigned a value",
1293 \\const A = enum {
1294 \\ a,
1295 \\ b,
1296 \\ _ = 1,
1297 \\};
1298 \\const B = enum {
1299 \\ a,
1300 \\ b,
1301 \\ _,
1302 \\};
1303 \\comptime { _ = A; _ = B; }
1304 , &[_][]const u8{
1305 "tmp.zig:4:9: error: '_' is used to mark an enum as non-exhaustive and cannot be assigned a value",
1306 "tmp.zig:6:11: error: non-exhaustive enum missing integer tag type",
1307 "tmp.zig:9:5: note: marked non-exhaustive here",
1308 });
1309
1310 ctx.testErrStage1("non-exhaustive enums",
1311 \\const B = enum(u1) {
1312 \\ a,
1313 \\ _,
1314 \\ b,
1315 \\};
1316 \\const C = enum(u1) {
1317 \\ a,
1318 \\ b,
1319 \\ _,
1320 \\};
1321 \\pub export fn entry() void {
1322 \\ _ = B;
1323 \\ _ = C;
1324 \\}
1325 , &[_][]const u8{
1326 "tmp.zig:3:5: error: '_' field of non-exhaustive enum must be last",
1327 "tmp.zig:6:11: error: non-exhaustive enum specifies every value",
1328 });
1329
1330 ctx.testErrStage1("switching with non-exhaustive enums",
1331 \\const E = enum(u8) {
1332 \\ a,
1333 \\ b,
1334 \\ _,
1335 \\};
1336 \\const U = union(E) {
1337 \\ a: i32,
1338 \\ b: u32,
1339 \\};
1340 \\pub export fn entry() void {
1341 \\ var e: E = .b;
1342 \\ switch (e) { // error: switch not handling the tag `b`
1343 \\ .a => {},
1344 \\ _ => {},
1345 \\ }
1346 \\ switch (e) { // error: switch on non-exhaustive enum must include `else` or `_` prong
1347 \\ .a => {},
1348 \\ .b => {},
1349 \\ }
1350 \\ var u = U{.a = 2};
1351 \\ switch (u) { // error: `_` prong not allowed when switching on tagged union
1352 \\ .a => {},
1353 \\ .b => {},
1354 \\ _ => {},
1355 \\ }
1356 \\}
1357 , &[_][]const u8{
1358 "tmp.zig:12:5: error: enumeration value 'E.b' not handled in switch",
1359 "tmp.zig:16:5: error: switch on non-exhaustive enum must include `else` or `_` prong",
1360 "tmp.zig:21:5: error: `_` prong not allowed when switching on tagged union",
1361 });
1362
1363 ctx.objErrStage1("switch expression - unreachable else prong (bool)",
1364 \\fn foo(x: bool) void {
1365 \\ switch (x) {
1366 \\ true => {},
1367 \\ false => {},
1368 \\ else => {},
1369 \\ }
1370 \\}
1371 \\export fn entry() usize { return @sizeOf(@TypeOf(foo)); }
1372 , &[_][]const u8{
1373 "tmp.zig:5:9: error: unreachable else prong, all cases already handled",
1374 });
1375
1376 ctx.objErrStage1("switch expression - unreachable else prong (u1)",
1377 \\fn foo(x: u1) void {
1378 \\ switch (x) {
1379 \\ 0 => {},
1380 \\ 1 => {},
1381 \\ else => {},
1382 \\ }
1383 \\}
1384 \\export fn entry() usize { return @sizeOf(@TypeOf(foo)); }
1385 , &[_][]const u8{
1386 "tmp.zig:5:9: error: unreachable else prong, all cases already handled",
1387 });
1388
1389 ctx.objErrStage1("switch expression - unreachable else prong (u2)",
1390 \\fn foo(x: u2) void {
1391 \\ switch (x) {
1392 \\ 0 => {},
1393 \\ 1 => {},
1394 \\ 2 => {},
1395 \\ 3 => {},
1396 \\ else => {},
1397 \\ }
1398 \\}
1399 \\export fn entry() usize { return @sizeOf(@TypeOf(foo)); }
1400 , &[_][]const u8{
1401 "tmp.zig:7:9: error: unreachable else prong, all cases already handled",
1402 });
1403
1404 ctx.objErrStage1("switch expression - unreachable else prong (range u8)",
1405 \\fn foo(x: u8) void {
1406 \\ switch (x) {
1407 \\ 0 => {},
1408 \\ 1 => {},
1409 \\ 2 => {},
1410 \\ 3 => {},
1411 \\ 4...255 => {},
1412 \\ else => {},
1413 \\ }
1414 \\}
1415 \\export fn entry() usize { return @sizeOf(@TypeOf(foo)); }
1416 , &[_][]const u8{
1417 "tmp.zig:8:9: error: unreachable else prong, all cases already handled",
1418 });
1419
1420 ctx.objErrStage1("switch expression - unreachable else prong (range i8)",
1421 \\fn foo(x: i8) void {
1422 \\ switch (x) {
1423 \\ -128...0 => {},
1424 \\ 1 => {},
1425 \\ 2 => {},
1426 \\ 3 => {},
1427 \\ 4...127 => {},
1428 \\ else => {},
1429 \\ }
1430 \\}
1431 \\export fn entry() usize { return @sizeOf(@TypeOf(foo)); }
1432 , &[_][]const u8{
1433 "tmp.zig:8:9: error: unreachable else prong, all cases already handled",
1434 });
1435
1436 ctx.objErrStage1("switch expression - unreachable else prong (enum)",
1437 \\const TestEnum = enum{ T1, T2 };
1438 \\
1439 \\fn err(x: u8) TestEnum {
1440 \\ switch (x) {
1441 \\ 0 => return TestEnum.T1,
1442 \\ else => return TestEnum.T2,
1443 \\ }
1444 \\}
1445 \\
1446 \\fn foo(x: u8) void {
1447 \\ switch (err(x)) {
1448 \\ TestEnum.T1 => {},
1449 \\ TestEnum.T2 => {},
1450 \\ else => {},
1451 \\ }
1452 \\}
1453 \\
1454 \\export fn entry() usize { return @sizeOf(@TypeOf(foo)); }
1455 , &[_][]const u8{
1456 "tmp.zig:14:9: error: unreachable else prong, all cases already handled",
1457 });
1458
1459 ctx.testErrStage1("@export with empty name string",
1460 \\pub export fn entry() void { }
1461 \\comptime {
1462 \\ @export(entry, .{ .name = "" });
1463 \\}
1464 , &[_][]const u8{
1465 "tmp.zig:3:5: error: exported symbol name cannot be empty",
1466 });
1467
1468 ctx.testErrStage1("switch ranges endpoints are validated",
1469 \\pub export fn entry() void {
1470 \\ var x: i32 = 0;
1471 \\ switch (x) {
1472 \\ 6...1 => {},
1473 \\ -1...-5 => {},
1474 \\ else => unreachable,
1475 \\ }
1476 \\}
1477 , &[_][]const u8{
1478 "tmp.zig:4:9: error: range start value is greater than the end value",
1479 "tmp.zig:5:9: error: range start value is greater than the end value",
1480 });
1481
1482 ctx.testErrStage1("errors in for loop bodies are propagated",
1483 \\pub export fn entry() void {
1484 \\ var arr: [100]u8 = undefined;
1485 \\ for (arr) |bits| _ = @popCount(bits);
1486 \\}
1487 , &[_][]const u8{
1488 "tmp.zig:3:26: error: expected 2 arguments, found 1",
1489 });
1490
1491 ctx.testErrStage1("@call rejects non comptime-known fn - always_inline",
1492 \\pub export fn entry() void {
1493 \\ var call_me: fn () void = undefined;
1494 \\ @call(.{ .modifier = .always_inline }, call_me, .{});
1495 \\}
1496 , &[_][]const u8{
1497 "tmp.zig:3:5: error: the specified modifier requires a comptime-known function",
1498 });
1499
1500 ctx.testErrStage1("@call rejects non comptime-known fn - compile_time",
1501 \\pub export fn entry() void {
1502 \\ var call_me: fn () void = undefined;
1503 \\ @call(.{ .modifier = .compile_time }, call_me, .{});
1504 \\}
1505 , &[_][]const u8{
1506 "tmp.zig:3:5: error: the specified modifier requires a comptime-known function",
1507 });
1508
1509 ctx.testErrStage1("error in struct initializer doesn't crash the compiler",
1510 \\pub export fn entry() void {
1511 \\ const bitfield = struct {
1512 \\ e: u8,
1513 \\ e: u8,
1514 \\ };
1515 \\ var a = .{@sizeOf(bitfield)};
1516 \\ _ = a;
1517 \\}
1518 , &[_][]const u8{
1519 "tmp.zig:4:9: error: duplicate struct field: 'e'",
1520 });
1521
1522 ctx.testErrStage1("repeated invalid field access to generic function returning type crashes compiler. #2655",
1523 \\pub fn A() type {
1524 \\ return Q;
1525 \\}
1526 \\test "1" {
1527 \\ _ = A().a;
1528 \\ _ = A().a;
1529 \\}
1530 , &[_][]const u8{
1531 "tmp.zig:2:12: error: use of undeclared identifier 'Q'",
1532 });
1533
1534 ctx.objErrStage1("bitCast to enum type",
1535 \\export fn entry() void {
1536 \\ const y = @bitCast(enum(u32) { a, b }, @as(u32, 3));
1537 \\ _ = y;
1538 \\}
1539 , &[_][]const u8{
1540 "tmp.zig:2:24: error: cannot cast a value of type 'y'",
1541 });
1542
1543 ctx.objErrStage1("comparing against undefined produces undefined value",
1544 \\export fn entry() void {
1545 \\ if (2 == undefined) {}
1546 \\}
1547 , &[_][]const u8{
1548 "tmp.zig:2:11: error: use of undefined value here causes undefined behavior",
1549 });
1550
1551 ctx.objErrStage1("comptime ptrcast of zero-sized type",
1552 \\fn foo() void {
1553 \\ const node: struct {} = undefined;
1554 \\ const vla_ptr = @ptrCast([*]const u8, &node);
1555 \\ _ = vla_ptr;
1556 \\}
1557 \\comptime { foo(); }
1558 , &[_][]const u8{
1559 "tmp.zig:3:21: error: '*const struct:2:17' and '[*]const u8' do not have the same in-memory representation",
1560 });
1561
1562 ctx.objErrStage1("slice sentinel mismatch",
1563 \\fn foo() [:0]u8 {
1564 \\ var x: []u8 = undefined;
1565 \\ return x;
1566 \\}
1567 \\comptime { _ = foo; }
1568 , &[_][]const u8{
1569 "tmp.zig:3:12: error: expected type '[:0]u8', found '[]u8'",
1570 "tmp.zig:3:12: note: destination pointer requires a terminating '0' sentinel",
1571 });
1572
1573 ctx.objErrStage1("cmpxchg with float",
1574 \\export fn entry() void {
1575 \\ var x: f32 = 0;
1576 \\ _ = @cmpxchgWeak(f32, &x, 1, 2, .SeqCst, .SeqCst);
1577 \\}
1578 , &[_][]const u8{
1579 "tmp.zig:3:22: error: expected bool, integer, enum or pointer type, found 'f32'",
1580 });
1581
1582 ctx.objErrStage1("atomicrmw with float op not .Xchg, .Add or .Sub",
1583 \\export fn entry() void {
1584 \\ var x: f32 = 0;
1585 \\ _ = @atomicRmw(f32, &x, .And, 2, .SeqCst);
1586 \\}
1587 , &[_][]const u8{
1588 "tmp.zig:3:29: error: @atomicRmw with float only allowed with .Xchg, .Add and .Sub",
1589 });
1590
1591 ctx.objErrStage1("intToPtr with misaligned address",
1592 \\pub fn main() void {
1593 \\ var y = @intToPtr([*]align(4) u8, 5);
1594 \\ _ = y;
1595 \\}
1596 , &[_][]const u8{
1597 "tmp.zig:2:13: error: pointer type '[*]align(4) u8' requires aligned address",
1598 });
1599
1600 ctx.objErrStage1("invalid float literal",
1601 \\const std = @import("std");
1602 \\
1603 \\pub fn main() void {
1604 \\ var bad_float :f32 = 0.0;
1605 \\ bad_float = bad_float + .20;
1606 \\ std.debug.assert(bad_float < 1.0);
1607 \\}
1608 , &[_][]const u8{
1609 "tmp.zig:5:29: error: expected expression, found '.'",
1610 });
1611
1612 ctx.objErrStage1("invalid exponent in float literal - 1",
1613 \\fn main() void {
1614 \\ var bad: f128 = 0x1.0p1ab1;
1615 \\ _ = bad;
1616 \\}
1617 , &[_][]const u8{
1618 "tmp.zig:2:21: error: expected expression, found 'invalid bytes'",
1619 "tmp.zig:2:28: note: invalid byte: 'a'",
1620 });
1621
1622 ctx.objErrStage1("invalid exponent in float literal - 2",
1623 \\fn main() void {
1624 \\ var bad: f128 = 0x1.0p50F;
1625 \\ _ = bad;
1626 \\}
1627 , &[_][]const u8{
1628 "tmp.zig:2:21: error: expected expression, found 'invalid bytes'",
1629 "tmp.zig:2:29: note: invalid byte: 'F'",
1630 });
1631
1632 ctx.objErrStage1("invalid underscore placement in float literal - 1",
1633 \\fn main() void {
1634 \\ var bad: f128 = 0._0;
1635 \\ _ = bad;
1636 \\}
1637 , &[_][]const u8{
1638 "tmp.zig:2:21: error: expected expression, found 'invalid bytes'",
1639 "tmp.zig:2:23: note: invalid byte: '_'",
1640 });
1641
1642 ctx.objErrStage1("invalid underscore placement in float literal - 2",
1643 \\fn main() void {
1644 \\ var bad: f128 = 0_.0;
1645 \\ _ = bad;
1646 \\}
1647 , &[_][]const u8{
1648 "tmp.zig:2:21: error: expected expression, found 'invalid bytes'",
1649 "tmp.zig:2:23: note: invalid byte: '.'",
1650 });
1651
1652 ctx.objErrStage1("invalid underscore placement in float literal - 3",
1653 \\fn main() void {
1654 \\ var bad: f128 = 0.0_;
1655 \\ _ = bad;
1656 \\}
1657 , &[_][]const u8{
1658 "tmp.zig:2:21: error: expected expression, found 'invalid bytes'",
1659 "tmp.zig:2:25: note: invalid byte: ';'",
1660 });
1661
1662 ctx.objErrStage1("invalid underscore placement in float literal - 4",
1663 \\fn main() void {
1664 \\ var bad: f128 = 1.0e_1;
1665 \\ _ = bad;
1666 \\}
1667 , &[_][]const u8{
1668 "tmp.zig:2:21: error: expected expression, found 'invalid bytes'",
1669 "tmp.zig:2:25: note: invalid byte: '_'",
1670 });
1671
1672 ctx.objErrStage1("invalid underscore placement in float literal - 5",
1673 \\fn main() void {
1674 \\ var bad: f128 = 1.0e+_1;
1675 \\ _ = bad;
1676 \\}
1677 , &[_][]const u8{
1678 "tmp.zig:2:21: error: expected expression, found 'invalid bytes'",
1679 "tmp.zig:2:26: note: invalid byte: '_'",
1680 });
1681
1682 ctx.objErrStage1("invalid underscore placement in float literal - 6",
1683 \\fn main() void {
1684 \\ var bad: f128 = 1.0e-_1;
1685 \\ _ = bad;
1686 \\}
1687 , &[_][]const u8{
1688 "tmp.zig:2:21: error: expected expression, found 'invalid bytes'",
1689 "tmp.zig:2:26: note: invalid byte: '_'",
1690 });
1691
1692 ctx.objErrStage1("invalid underscore placement in float literal - 7",
1693 \\fn main() void {
1694 \\ var bad: f128 = 1.0e-1_;
1695 \\ _ = bad;
1696 \\}
1697 , &[_][]const u8{
1698 "tmp.zig:2:21: error: expected expression, found 'invalid bytes'",
1699 "tmp.zig:2:28: note: invalid byte: ';'",
1700 });
1701
1702 ctx.objErrStage1("invalid underscore placement in float literal - 9",
1703 \\fn main() void {
1704 \\ var bad: f128 = 1__0.0e-1;
1705 \\ _ = bad;
1706 \\}
1707 , &[_][]const u8{
1708 "tmp.zig:2:21: error: expected expression, found 'invalid bytes'",
1709 "tmp.zig:2:23: note: invalid byte: '_'",
1710 });
1711
1712 ctx.objErrStage1("invalid underscore placement in float literal - 10",
1713 \\fn main() void {
1714 \\ var bad: f128 = 1.0__0e-1;
1715 \\ _ = bad;
1716 \\}
1717 , &[_][]const u8{
1718 "tmp.zig:2:21: error: expected expression, found 'invalid bytes'",
1719 "tmp.zig:2:25: note: invalid byte: '_'",
1720 });
1721
1722 ctx.objErrStage1("invalid underscore placement in float literal - 11",
1723 \\fn main() void {
1724 \\ var bad: f128 = 1.0e-1__0;
1725 \\ _ = bad;
1726 \\}
1727 , &[_][]const u8{
1728 "tmp.zig:2:21: error: expected expression, found 'invalid bytes'",
1729 "tmp.zig:2:28: note: invalid byte: '_'",
1730 });
1731
1732 ctx.objErrStage1("invalid underscore placement in float literal - 12",
1733 \\fn main() void {
1734 \\ var bad: f128 = 0_x0.0;
1735 \\ _ = bad;
1736 \\}
1737 , &[_][]const u8{
1738 "tmp.zig:2:21: error: expected expression, found 'invalid bytes'",
1739 "tmp.zig:2:23: note: invalid byte: 'x'",
1740 });
1741
1742 ctx.objErrStage1("invalid underscore placement in float literal - 13",
1743 \\fn main() void {
1744 \\ var bad: f128 = 0x_0.0;
1745 \\ _ = bad;
1746 \\}
1747 , &[_][]const u8{
1748 "tmp.zig:2:21: error: expected expression, found 'invalid bytes'",
1749 "tmp.zig:2:23: note: invalid byte: '_'",
1750 });
1751
1752 ctx.objErrStage1("invalid underscore placement in float literal - 14",
1753 \\fn main() void {
1754 \\ var bad: f128 = 0x0.0_p1;
1755 \\ _ = bad;
1756 \\}
1757 , &[_][]const u8{
1758 "tmp.zig:2:21: error: expected expression, found 'invalid bytes'",
1759 "tmp.zig:2:27: note: invalid byte: 'p'",
1760 });
1761
1762 ctx.objErrStage1("invalid underscore placement in int literal - 1",
1763 \\fn main() void {
1764 \\ var bad: u128 = 0010_;
1765 \\ _ = bad;
1766 \\}
1767 , &[_][]const u8{
1768 "tmp.zig:2:21: error: expected expression, found 'invalid bytes'",
1769 "tmp.zig:2:26: note: invalid byte: ';'",
1770 });
1771
1772 ctx.objErrStage1("invalid underscore placement in int literal - 2",
1773 \\fn main() void {
1774 \\ var bad: u128 = 0b0010_;
1775 \\ _ = bad;
1776 \\}
1777 , &[_][]const u8{
1778 "tmp.zig:2:21: error: expected expression, found 'invalid bytes'",
1779 "tmp.zig:2:28: note: invalid byte: ';'",
1780 });
1781
1782 ctx.objErrStage1("invalid underscore placement in int literal - 3",
1783 \\fn main() void {
1784 \\ var bad: u128 = 0o0010_;
1785 \\ _ = bad;
1786 \\}
1787 , &[_][]const u8{
1788 "tmp.zig:2:21: error: expected expression, found 'invalid bytes'",
1789 "tmp.zig:2:28: note: invalid byte: ';'",
1790 });
1791
1792 ctx.objErrStage1("invalid underscore placement in int literal - 4",
1793 \\fn main() void {
1794 \\ var bad: u128 = 0x0010_;
1795 \\ _ = bad;
1796 \\}
1797 , &[_][]const u8{
1798 "tmp.zig:2:21: error: expected expression, found 'invalid bytes'",
1799 "tmp.zig:2:28: note: invalid byte: ';'",
1800 });
1801
1802 ctx.objErrStage1("comptime struct field, no init value",
1803 \\const Foo = struct {
1804 \\ comptime b: i32,
1805 \\};
1806 \\export fn entry() void {
1807 \\ var f: Foo = undefined;
1808 \\ _ = f;
1809 \\}
1810 , &[_][]const u8{
1811 "tmp.zig:2:5: error: comptime field without default initialization value",
1812 });
1813
1814 ctx.objErrStage1("bad usage of @call",
1815 \\export fn entry1() void {
1816 \\ @call(.{}, foo, {});
1817 \\}
1818 \\export fn entry2() void {
1819 \\ comptime @call(.{ .modifier = .never_inline }, foo, .{});
1820 \\}
1821 \\export fn entry3() void {
1822 \\ comptime @call(.{ .modifier = .never_tail }, foo, .{});
1823 \\}
1824 \\export fn entry4() void {
1825 \\ @call(.{ .modifier = .never_inline }, bar, .{});
1826 \\}
1827 \\export fn entry5(c: bool) void {
1828 \\ var baz = if (c) baz1 else baz2;
1829 \\ @call(.{ .modifier = .compile_time }, baz, .{});
1830 \\}
1831 \\fn foo() void {}
1832 \\fn bar() callconv(.Inline) void {}
1833 \\fn baz1() void {}
1834 \\fn baz2() void {}
1835 , &[_][]const u8{
1836 "tmp.zig:2:21: error: expected tuple or struct, found 'void'",
1837 "tmp.zig:5:14: error: unable to perform 'never_inline' call at compile-time",
1838 "tmp.zig:8:14: error: unable to perform 'never_tail' call at compile-time",
1839 "tmp.zig:11:5: error: no-inline call of inline function",
1840 "tmp.zig:15:5: error: the specified modifier requires a comptime-known function",
1841 });
1842
1843 ctx.objErrStage1("exported async function",
1844 \\export fn foo() callconv(.Async) void {}
1845 , &[_][]const u8{
1846 "tmp.zig:1:1: error: exported function cannot be async",
1847 });
1848
1849 ctx.exeErrStage1("main missing name",
1850 \\pub fn (main) void {}
1851 , &[_][]const u8{
1852 "tmp.zig:1:5: error: missing function name",
1853 });
1854
1855 {
1856 const case = ctx.obj("call with new stack on unsupported target", .{
1857 .cpu_arch = .wasm32,
1858 .os_tag = .wasi,
1859 .abi = .none,
1860 });
1861 case.backend = .stage1;
1862 case.addError(
1863 \\var buf: [10]u8 align(16) = undefined;
1864 \\export fn entry() void {
1865 \\ @call(.{.stack = &buf}, foo, .{});
1866 \\}
1867 \\fn foo() void {}
1868 , &[_][]const u8{
1869 "tmp.zig:3:5: error: target arch 'wasm32' does not support calling with a new stack",
1870 });
1871 }
1872
1873 // Note: One of the error messages here is backwards. It would be nice to fix, but that's not
1874 // going to stop me from merging this branch which fixes a bunch of other stuff.
1875 ctx.objErrStage1("incompatible sentinels",
1876 \\export fn entry1(ptr: [*:255]u8) [*:0]u8 {
1877 \\ return ptr;
1878 \\}
1879 \\export fn entry2(ptr: [*]u8) [*:0]u8 {
1880 \\ return ptr;
1881 \\}
1882 \\export fn entry3() void {
1883 \\ var array: [2:0]u8 = [_:255]u8{1, 2};
1884 \\ _ = array;
1885 \\}
1886 \\export fn entry4() void {
1887 \\ var array: [2:0]u8 = [_]u8{1, 2};
1888 \\ _ = array;
1889 \\}
1890 , &[_][]const u8{
1891 "tmp.zig:2:12: error: expected type '[*:0]u8', found '[*:255]u8'",
1892 "tmp.zig:2:12: note: destination pointer requires a terminating '0' sentinel, but source pointer has a terminating '255' sentinel",
1893 "tmp.zig:5:12: error: expected type '[*:0]u8', found '[*]u8'",
1894 "tmp.zig:5:12: note: destination pointer requires a terminating '0' sentinel",
1895
1896 "tmp.zig:8:35: error: expected type '[2:255]u8', found '[2:0]u8'",
1897 "tmp.zig:8:35: note: destination array requires a terminating '255' sentinel, but source array has a terminating '0' sentinel",
1898 "tmp.zig:12:31: error: expected type '[2:0]u8', found '[2]u8'",
1899 "tmp.zig:12:31: note: destination array requires a terminating '0' sentinel",
1900 });
1901
1902 ctx.objErrStage1("empty switch on an integer",
1903 \\export fn entry() void {
1904 \\ var x: u32 = 0;
1905 \\ switch(x) {}
1906 \\}
1907 , &[_][]const u8{
1908 "tmp.zig:3:5: error: switch must handle all possibilities",
1909 });
1910
1911 ctx.objErrStage1("incorrect return type",
1912 \\ pub export fn entry() void{
1913 \\ _ = foo();
1914 \\ }
1915 \\ const A = struct {
1916 \\ a: u32,
1917 \\ };
1918 \\ fn foo() A {
1919 \\ return bar();
1920 \\ }
1921 \\ const B = struct {
1922 \\ a: u32,
1923 \\ };
1924 \\ fn bar() B {
1925 \\ unreachable;
1926 \\ }
1927 , &[_][]const u8{
1928 "tmp.zig:8:16: error: expected type 'A', found 'B'",
1929 });
1930
1931 ctx.objErrStage1("regression test #2980: base type u32 is not type checked properly when assigning a value within a struct",
1932 \\const Foo = struct {
1933 \\ ptr: ?*usize,
1934 \\ uval: u32,
1935 \\};
1936 \\fn get_uval(x: u32) !u32 {
1937 \\ _ = x;
1938 \\ return error.NotFound;
1939 \\}
1940 \\export fn entry() void {
1941 \\ const afoo = Foo{
1942 \\ .ptr = null,
1943 \\ .uval = get_uval(42),
1944 \\ };
1945 \\ _ = afoo;
1946 \\}
1947 , &[_][]const u8{
1948 "tmp.zig:12:25: error: cannot convert error union to payload type. consider using `try`, `catch`, or `if`. expected type 'u32', found '@typeInfo(@typeInfo(@TypeOf(get_uval)).Fn.return_type.?).ErrorUnion.error_set!u32'",
1949 });
1950
1951 ctx.objErrStage1("assigning to struct or union fields that are not optionals with a function that returns an optional",
1952 \\fn maybe(is: bool) ?u8 {
1953 \\ if (is) return @as(u8, 10) else return null;
1954 \\}
1955 \\const U = union {
1956 \\ Ye: u8,
1957 \\};
1958 \\const S = struct {
1959 \\ num: u8,
1960 \\};
1961 \\export fn entry() void {
1962 \\ var u = U{ .Ye = maybe(false) };
1963 \\ var s = S{ .num = maybe(false) };
1964 \\ _ = u;
1965 \\ _ = s;
1966 \\}
1967 , &[_][]const u8{
1968 "tmp.zig:11:27: error: cannot convert optional to payload type. consider using `.?`, `orelse`, or `if`. expected type 'u8', found '?u8'",
1969 });
1970
1971 ctx.objErrStage1("missing result type for phi node",
1972 \\fn foo() !void {
1973 \\ return anyerror.Foo;
1974 \\}
1975 \\export fn entry() void {
1976 \\ foo() catch 0;
1977 \\}
1978 , &[_][]const u8{
1979 "tmp.zig:5:17: error: integer value 0 cannot be coerced to type 'void'",
1980 });
1981
1982 ctx.objErrStage1("atomicrmw with enum op not .Xchg",
1983 \\export fn entry() void {
1984 \\ const E = enum(u8) {
1985 \\ a,
1986 \\ b,
1987 \\ c,
1988 \\ d,
1989 \\ };
1990 \\ var x: E = .a;
1991 \\ _ = @atomicRmw(E, &x, .Add, .b, .SeqCst);
1992 \\}
1993 , &[_][]const u8{
1994 "tmp.zig:9:27: error: @atomicRmw with enum only allowed with .Xchg",
1995 });
1996
1997 ctx.objErrStage1("disallow coercion from non-null-terminated pointer to null-terminated pointer",
1998 \\extern fn puts(s: [*:0]const u8) c_int;
1999 \\pub fn main() void {
2000 \\ const no_zero_array = [_]u8{'h', 'e', 'l', 'l', 'o'};
2001 \\ const no_zero_ptr: [*]const u8 = &no_zero_array;
2002 \\ _ = puts(no_zero_ptr);
2003 \\}
2004 , &[_][]const u8{
2005 "tmp.zig:5:14: error: expected type '[*:0]const u8', found '[*]const u8'",
2006 });
2007
2008 ctx.objErrStage1("atomic orderings of atomicStore Acquire or AcqRel",
2009 \\export fn entry() void {
2010 \\ var x: u32 = 0;
2011 \\ @atomicStore(u32, &x, 1, .Acquire);
2012 \\}
2013 , &[_][]const u8{
2014 "tmp.zig:3:30: error: @atomicStore atomic ordering must not be Acquire or AcqRel",
2015 });
2016
2017 ctx.objErrStage1("missing const in slice with nested array type",
2018 \\const Geo3DTex2D = struct { vertices: [][2]f32 };
2019 \\pub fn getGeo3DTex2D() Geo3DTex2D {
2020 \\ return Geo3DTex2D{
2021 \\ .vertices = [_][2]f32{
2022 \\ [_]f32{ -0.5, -0.5},
2023 \\ },
2024 \\ };
2025 \\}
2026 \\export fn entry() void {
2027 \\ var geo_data = getGeo3DTex2D();
2028 \\ _ = geo_data;
2029 \\}
2030 , &[_][]const u8{
2031 "tmp.zig:4:30: error: array literal requires address-of operator (&) to coerce to slice type '[][2]f32'",
2032 });
2033
2034 ctx.objErrStage1("slicing of global undefined pointer",
2035 \\var buf: *[1]u8 = undefined;
2036 \\export fn entry() void {
2037 \\ _ = buf[0..1];
2038 \\}
2039 , &[_][]const u8{
2040 "tmp.zig:3:12: error: non-zero length slice of undefined pointer",
2041 });
2042
2043 ctx.objErrStage1("using invalid types in function call raises an error",
2044 \\const MenuEffect = enum {};
2045 \\fn func(effect: MenuEffect) void { _ = effect; }
2046 \\export fn entry() void {
2047 \\ func(MenuEffect.ThisDoesNotExist);
2048 \\}
2049 , &[_][]const u8{
2050 "tmp.zig:1:20: error: enum declarations must have at least one tag",
2051 });
2052
2053 ctx.objErrStage1("store vector pointer with unknown runtime index",
2054 \\export fn entry() void {
2055 \\ var v: @import("std").meta.Vector(4, i32) = [_]i32{ 1, 5, 3, undefined };
2056 \\
2057 \\ var i: u32 = 0;
2058 \\ storev(&v[i], 42);
2059 \\}
2060 \\
2061 \\fn storev(ptr: anytype, val: i32) void {
2062 \\ ptr.* = val;
2063 \\}
2064 , &[_][]const u8{
2065 "tmp.zig:9:8: error: unable to determine vector element index of type '*align(16:0:4:?) i32",
2066 });
2067
2068 ctx.objErrStage1("load vector pointer with unknown runtime index",
2069 \\export fn entry() void {
2070 \\ var v: @import("std").meta.Vector(4, i32) = [_]i32{ 1, 5, 3, undefined };
2071 \\
2072 \\ var i: u32 = 0;
2073 \\ var x = loadv(&v[i]);
2074 \\ _ = x;
2075 \\}
2076 \\
2077 \\fn loadv(ptr: anytype) i32 {
2078 \\ return ptr.*;
2079 \\}
2080 , &[_][]const u8{
2081 "tmp.zig:10:12: error: unable to determine vector element index of type '*align(16:0:4:?) i32",
2082 });
2083
2084 ctx.objErrStage1("using an unknown len ptr type instead of array",
2085 \\const resolutions = [*][*]const u8{
2086 \\ "[320 240 ]",
2087 \\ null,
2088 \\};
2089 \\comptime {
2090 \\ _ = resolutions;
2091 \\}
2092 , &[_][]const u8{
2093 "tmp.zig:1:21: error: expected array type or [_], found '[*][*]const u8'",
2094 });
2095
2096 ctx.objErrStage1("comparison with error union and error value",
2097 \\export fn entry() void {
2098 \\ var number_or_error: anyerror!i32 = error.SomethingAwful;
2099 \\ _ = number_or_error == error.SomethingAwful;
2100 \\}
2101 , &[_][]const u8{
2102 "tmp.zig:3:25: error: operator not allowed for type 'anyerror!i32'",
2103 });
2104
2105 ctx.objErrStage1("switch with overlapping case ranges",
2106 \\export fn entry() void {
2107 \\ var q: u8 = 0;
2108 \\ switch (q) {
2109 \\ 1...2 => {},
2110 \\ 0...255 => {},
2111 \\ }
2112 \\}
2113 , &[_][]const u8{
2114 "tmp.zig:5:9: error: duplicate switch value",
2115 });
2116
2117 ctx.objErrStage1("invalid optional type in extern struct",
2118 \\const stroo = extern struct {
2119 \\ moo: ?[*c]u8,
2120 \\};
2121 \\export fn testf(fluff: *stroo) void { _ = fluff; }
2122 , &[_][]const u8{
2123 "tmp.zig:2:5: error: extern structs cannot contain fields of type '?[*c]u8'",
2124 });
2125
2126 ctx.objErrStage1("attempt to negate a non-integer, non-float or non-vector type",
2127 \\fn foo() anyerror!u32 {
2128 \\ return 1;
2129 \\}
2130 \\
2131 \\export fn entry() void {
2132 \\ const x = -foo();
2133 \\ _ = x;
2134 \\}
2135 , &[_][]const u8{
2136 "tmp.zig:6:15: error: negation of type 'anyerror!u32'",
2137 });
2138
2139 ctx.objErrStage1("attempt to create 17 bit float type",
2140 \\const builtin = @import("std").builtin;
2141 \\comptime {
2142 \\ _ = @Type(.{ .Float = .{ .bits = 17 } });
2143 \\}
2144 , &[_][]const u8{
2145 "tmp.zig:3:16: error: 17-bit float unsupported",
2146 });
2147
2148 ctx.objErrStage1("wrong type for @Type",
2149 \\export fn entry() void {
2150 \\ _ = @Type(0);
2151 \\}
2152 , &[_][]const u8{
2153 "tmp.zig:2:15: error: expected type 'std.builtin.Type', found 'comptime_int'",
2154 });
2155
2156 ctx.objErrStage1("@Type with non-constant expression",
2157 \\const builtin = @import("std").builtin;
2158 \\var globalTypeInfo : builtin.Type = undefined;
2159 \\export fn entry() void {
2160 \\ _ = @Type(globalTypeInfo);
2161 \\}
2162 , &[_][]const u8{
2163 "tmp.zig:4:15: error: unable to evaluate constant expression",
2164 });
2165
2166 ctx.objErrStage1("wrong type for argument tuple to @asyncCall",
2167 \\export fn entry1() void {
2168 \\ var frame: @Frame(foo) = undefined;
2169 \\ @asyncCall(&frame, {}, foo, {});
2170 \\}
2171 \\
2172 \\fn foo() i32 {
2173 \\ return 0;
2174 \\}
2175 , &[_][]const u8{
2176 "tmp.zig:3:33: error: expected tuple or struct, found 'void'",
2177 });
2178
2179 ctx.objErrStage1("wrong type for result ptr to @asyncCall",
2180 \\export fn entry() void {
2181 \\ _ = async amain();
2182 \\}
2183 \\fn amain() i32 {
2184 \\ var frame: @Frame(foo) = undefined;
2185 \\ return await @asyncCall(&frame, false, foo, .{});
2186 \\}
2187 \\fn foo() i32 {
2188 \\ return 1234;
2189 \\}
2190 , &[_][]const u8{
2191 "tmp.zig:6:37: error: expected type '*i32', found 'bool'",
2192 });
2193
2194 ctx.objErrStage1("shift amount has to be an integer type",
2195 \\export fn entry() void {
2196 \\ const x = 1 << &@as(u8, 10);
2197 \\ _ = x;
2198 \\}
2199 , &[_][]const u8{
2200 "tmp.zig:2:21: error: shift amount has to be an integer type, but found '*const u8'",
2201 });
2202
2203 ctx.objErrStage1("bit shifting only works on integer types",
2204 \\export fn entry() void {
2205 \\ const x = &@as(u8, 1) << 10;
2206 \\ _ = x;
2207 \\}
2208 , &[_][]const u8{
2209 "tmp.zig:2:16: error: bit shifting operation expected integer type, found '*const u8'",
2210 });
2211
2212 ctx.objErrStage1("struct depends on itself via optional field",
2213 \\const LhsExpr = struct {
2214 \\ rhsExpr: ?AstObject,
2215 \\};
2216 \\const AstObject = union {
2217 \\ lhsExpr: LhsExpr,
2218 \\};
2219 \\export fn entry() void {
2220 \\ const lhsExpr = LhsExpr{ .rhsExpr = null };
2221 \\ const obj = AstObject{ .lhsExpr = lhsExpr };
2222 \\ _ = obj;
2223 \\}
2224 , &[_][]const u8{
2225 "tmp.zig:1:17: error: struct 'LhsExpr' depends on itself",
2226 "tmp.zig:5:5: note: while checking this field",
2227 "tmp.zig:2:5: note: while checking this field",
2228 });
2229
2230 ctx.objErrStage1("alignment of enum field specified",
2231 \\const Number = enum {
2232 \\ a,
2233 \\ b align(i32),
2234 \\};
2235 \\export fn entry1() void {
2236 \\ var x: Number = undefined;
2237 \\ _ = x;
2238 \\}
2239 , &[_][]const u8{
2240 "tmp.zig:3:7: error: expected ',' after field",
2241 });
2242
2243 ctx.objErrStage1("bad alignment type",
2244 \\export fn entry1() void {
2245 \\ var x: []align(true) i32 = undefined;
2246 \\ _ = x;
2247 \\}
2248 \\export fn entry2() void {
2249 \\ var x: *align(@as(f64, 12.34)) i32 = undefined;
2250 \\ _ = x;
2251 \\}
2252 , &[_][]const u8{
2253 "tmp.zig:2:20: error: expected type 'u29', found 'bool'",
2254 "tmp.zig:6:19: error: fractional component prevents float value 12.340000 from being casted to type 'u29'",
2255 });
2256
2257 {
2258 const case = ctx.obj("variable in inline assembly template cannot be found", .{
2259 .cpu_arch = .x86_64,
2260 .os_tag = .linux,
2261 .abi = .gnu,
2262 });
2263 case.backend = .stage1;
2264 case.addError(
2265 \\export fn entry() void {
2266 \\ var sp = asm volatile (
2267 \\ "mov %[foo], sp"
2268 \\ : [bar] "=r" (-> usize)
2269 \\ );
2270 \\ _ = sp;
2271 \\}
2272 , &[_][]const u8{
2273 "tmp.zig:2:14: error: could not find 'foo' in the inputs or outputs",
2274 });
2275 }
2276
2277 ctx.objErrStage1("indirect recursion of async functions detected",
2278 \\var frame: ?anyframe = null;
2279 \\
2280 \\export fn a() void {
2281 \\ _ = async rangeSum(10);
2282 \\ while (frame) |f| resume f;
2283 \\}
2284 \\
2285 \\fn rangeSum(x: i32) i32 {
2286 \\ suspend {
2287 \\ frame = @frame();
2288 \\ }
2289 \\ frame = null;
2290 \\
2291 \\ if (x == 0) return 0;
2292 \\ var child = rangeSumIndirect(x - 1);
2293 \\ return child + 1;
2294 \\}
2295 \\
2296 \\fn rangeSumIndirect(x: i32) i32 {
2297 \\ suspend {
2298 \\ frame = @frame();
2299 \\ }
2300 \\ frame = null;
2301 \\
2302 \\ if (x == 0) return 0;
2303 \\ var child = rangeSum(x - 1);
2304 \\ return child + 1;
2305 \\}
2306 , &[_][]const u8{
2307 "tmp.zig:8:1: error: '@Frame(rangeSum)' depends on itself",
2308 "tmp.zig:15:33: note: when analyzing type '@Frame(rangeSum)' here",
2309 "tmp.zig:26:25: note: when analyzing type '@Frame(rangeSumIndirect)' here",
2310 });
2311
2312 ctx.objErrStage1("non-async function pointer eventually is inferred to become async",
2313 \\export fn a() void {
2314 \\ var non_async_fn: fn () void = undefined;
2315 \\ non_async_fn = func;
2316 \\}
2317 \\fn func() void {
2318 \\ suspend {}
2319 \\}
2320 , &[_][]const u8{
2321 "tmp.zig:5:1: error: 'func' cannot be async",
2322 "tmp.zig:3:20: note: required to be non-async here",
2323 "tmp.zig:6:5: note: suspends here",
2324 });
2325
2326 {
2327 const case = ctx.obj("bad alignment in @asyncCall", .{
2328 .cpu_arch = .aarch64,
2329 .os_tag = .linux,
2330 .abi = .none,
2331 });
2332 case.backend = .stage1;
2333 case.addError(
2334 \\export fn entry() void {
2335 \\ var ptr: fn () callconv(.Async) void = func;
2336 \\ var bytes: [64]u8 = undefined;
2337 \\ _ = @asyncCall(&bytes, {}, ptr, .{});
2338 \\}
2339 \\fn func() callconv(.Async) void {}
2340 , &[_][]const u8{
2341 "tmp.zig:4:21: error: expected type '[]align(8) u8', found '*[64]u8'",
2342 });
2343 }
2344
2345 ctx.objErrStage1("atomic orderings of fence Acquire or stricter",
2346 \\export fn entry() void {
2347 \\ @fence(.Monotonic);
2348 \\}
2349 , &[_][]const u8{
2350 "tmp.zig:2:12: error: atomic ordering must be Acquire or stricter",
2351 });
2352
2353 ctx.objErrStage1("bad alignment in implicit cast from array pointer to slice",
2354 \\export fn a() void {
2355 \\ var x: [10]u8 = undefined;
2356 \\ var y: []align(16) u8 = &x;
2357 \\ _ = y;
2358 \\}
2359 , &[_][]const u8{
2360 "tmp.zig:3:30: error: expected type '[]align(16) u8', found '*[10]u8'",
2361 });
2362
2363 ctx.objErrStage1("result location incompatibility mismatching handle_is_ptr (generic call)",
2364 \\export fn entry() void {
2365 \\ var damn = Container{
2366 \\ .not_optional = getOptional(i32),
2367 \\ };
2368 \\ _ = damn;
2369 \\}
2370 \\pub fn getOptional(comptime T: type) ?T {
2371 \\ return 0;
2372 \\}
2373 \\pub const Container = struct {
2374 \\ not_optional: i32,
2375 \\};
2376 , &[_][]const u8{
2377 "tmp.zig:3:36: error: cannot convert optional to payload type. consider using `.?`, `orelse`, or `if`. expected type 'i32', found '?i32'",
2378 });
2379
2380 ctx.objErrStage1("result location incompatibility mismatching handle_is_ptr",
2381 \\export fn entry() void {
2382 \\ var damn = Container{
2383 \\ .not_optional = getOptional(),
2384 \\ };
2385 \\ _ = damn;
2386 \\}
2387 \\pub fn getOptional() ?i32 {
2388 \\ return 0;
2389 \\}
2390 \\pub const Container = struct {
2391 \\ not_optional: i32,
2392 \\};
2393 , &[_][]const u8{
2394 "tmp.zig:3:36: error: cannot convert optional to payload type. consider using `.?`, `orelse`, or `if`. expected type 'i32', found '?i32'",
2395 });
2396
2397 ctx.objErrStage1("const frame cast to anyframe",
2398 \\export fn a() void {
2399 \\ const f = async func();
2400 \\ resume f;
2401 \\}
2402 \\export fn b() void {
2403 \\ const f = async func();
2404 \\ var x: anyframe = &f;
2405 \\ _ = x;
2406 \\}
2407 \\fn func() void {
2408 \\ suspend {}
2409 \\}
2410 , &[_][]const u8{
2411 "tmp.zig:3:12: error: expected type 'anyframe', found '*const @Frame(func)'",
2412 "tmp.zig:7:24: error: expected type 'anyframe', found '*const @Frame(func)'",
2413 });
2414
2415 ctx.objErrStage1("prevent bad implicit casting of anyframe types",
2416 \\export fn a() void {
2417 \\ var x: anyframe = undefined;
2418 \\ var y: anyframe->i32 = x;
2419 \\ _ = y;
2420 \\}
2421 \\export fn b() void {
2422 \\ var x: i32 = undefined;
2423 \\ var y: anyframe->i32 = x;
2424 \\ _ = y;
2425 \\}
2426 \\export fn c() void {
2427 \\ var x: @Frame(func) = undefined;
2428 \\ var y: anyframe->i32 = &x;
2429 \\ _ = y;
2430 \\}
2431 \\fn func() void {}
2432 , &[_][]const u8{
2433 "tmp.zig:3:28: error: expected type 'anyframe->i32', found 'anyframe'",
2434 "tmp.zig:8:28: error: expected type 'anyframe->i32', found 'i32'",
2435 "tmp.zig:13:29: error: expected type 'anyframe->i32', found '*@Frame(func)'",
2436 });
2437
2438 ctx.objErrStage1("wrong frame type used for async call",
2439 \\export fn entry() void {
2440 \\ var frame: @Frame(foo) = undefined;
2441 \\ frame = async bar();
2442 \\}
2443 \\fn foo() void {
2444 \\ suspend {}
2445 \\}
2446 \\fn bar() void {
2447 \\ suspend {}
2448 \\}
2449 , &[_][]const u8{
2450 "tmp.zig:3:13: error: expected type '*@Frame(bar)', found '*@Frame(foo)'",
2451 });
2452
2453 ctx.objErrStage1("@Frame() of generic function",
2454 \\export fn entry() void {
2455 \\ var frame: @Frame(func) = undefined;
2456 \\ _ = frame;
2457 \\}
2458 \\fn func(comptime T: type) void {
2459 \\ var x: T = undefined;
2460 \\ _ = x;
2461 \\}
2462 , &[_][]const u8{
2463 "tmp.zig:2:16: error: @Frame() of generic function",
2464 });
2465
2466 ctx.objErrStage1("@frame() causes function to be async",
2467 \\export fn entry() void {
2468 \\ func();
2469 \\}
2470 \\fn func() void {
2471 \\ _ = @frame();
2472 \\}
2473 , &[_][]const u8{
2474 "tmp.zig:1:1: error: function with calling convention 'C' cannot be async",
2475 "tmp.zig:5:9: note: @frame() causes function to be async",
2476 });
2477
2478 ctx.objErrStage1("invalid suspend in exported function",
2479 \\export fn entry() void {
2480 \\ var frame = async func();
2481 \\ var result = await frame;
2482 \\ _ = result;
2483 \\}
2484 \\fn func() void {
2485 \\ suspend {}
2486 \\}
2487 , &[_][]const u8{
2488 "tmp.zig:1:1: error: function with calling convention 'C' cannot be async",
2489 "tmp.zig:3:18: note: await here is a suspend point",
2490 });
2491
2492 ctx.objErrStage1("async function indirectly depends on its own frame",
2493 \\export fn entry() void {
2494 \\ _ = async amain();
2495 \\}
2496 \\fn amain() callconv(.Async) void {
2497 \\ other();
2498 \\}
2499 \\fn other() void {
2500 \\ var x: [@sizeOf(@Frame(amain))]u8 = undefined;
2501 \\ _ = x;
2502 \\}
2503 , &[_][]const u8{
2504 "tmp.zig:4:1: error: unable to determine async function frame of 'amain'",
2505 "tmp.zig:5:10: note: analysis of function 'other' depends on the frame",
2506 });
2507
2508 ctx.objErrStage1("async function depends on its own frame",
2509 \\export fn entry() void {
2510 \\ _ = async amain();
2511 \\}
2512 \\fn amain() callconv(.Async) void {
2513 \\ var x: [@sizeOf(@Frame(amain))]u8 = undefined;
2514 \\ _ = x;
2515 \\}
2516 , &[_][]const u8{
2517 "tmp.zig:4:1: error: cannot resolve '@Frame(amain)': function not fully analyzed yet",
2518 });
2519
2520 ctx.objErrStage1("non async function pointer passed to @asyncCall",
2521 \\export fn entry() void {
2522 \\ var ptr = afunc;
2523 \\ var bytes: [100]u8 align(16) = undefined;
2524 \\ _ = @asyncCall(&bytes, {}, ptr, .{});
2525 \\}
2526 \\fn afunc() void { }
2527 , &[_][]const u8{
2528 "tmp.zig:4:32: error: expected async function, found 'fn() void'",
2529 });
2530
2531 ctx.objErrStage1("runtime-known async function called",
2532 \\export fn entry() void {
2533 \\ _ = async amain();
2534 \\}
2535 \\fn amain() void {
2536 \\ var ptr = afunc;
2537 \\ _ = ptr();
2538 \\}
2539 \\fn afunc() callconv(.Async) void {}
2540 , &[_][]const u8{
2541 "tmp.zig:6:12: error: function is not comptime-known; @asyncCall required",
2542 });
2543
2544 ctx.objErrStage1("runtime-known function called with async keyword",
2545 \\export fn entry() void {
2546 \\ var ptr = afunc;
2547 \\ _ = async ptr();
2548 \\}
2549 \\
2550 \\fn afunc() callconv(.Async) void { }
2551 , &[_][]const u8{
2552 "tmp.zig:3:15: error: function is not comptime-known; @asyncCall required",
2553 });
2554
2555 ctx.objErrStage1("function with ccc indirectly calling async function",
2556 \\export fn entry() void {
2557 \\ foo();
2558 \\}
2559 \\fn foo() void {
2560 \\ bar();
2561 \\}
2562 \\fn bar() void {
2563 \\ suspend {}
2564 \\}
2565 , &[_][]const u8{
2566 "tmp.zig:1:1: error: function with calling convention 'C' cannot be async",
2567 "tmp.zig:2:8: note: async function call here",
2568 "tmp.zig:5:8: note: async function call here",
2569 "tmp.zig:8:5: note: suspends here",
2570 });
2571
2572 ctx.objErrStage1("capture group on switch prong with incompatible payload types",
2573 \\const Union = union(enum) {
2574 \\ A: usize,
2575 \\ B: isize,
2576 \\};
2577 \\comptime {
2578 \\ var u = Union{ .A = 8 };
2579 \\ switch (u) {
2580 \\ .A, .B => |e| {
2581 \\ _ = e;
2582 \\ unreachable;
2583 \\ },
2584 \\ }
2585 \\}
2586 , &[_][]const u8{
2587 "tmp.zig:8:20: error: capture group with incompatible types",
2588 "tmp.zig:8:9: note: type 'usize' here",
2589 "tmp.zig:8:13: note: type 'isize' here",
2590 });
2591
2592 ctx.objErrStage1("wrong type to @hasField",
2593 \\export fn entry() bool {
2594 \\ return @hasField(i32, "hi");
2595 \\}
2596 , &[_][]const u8{
2597 "tmp.zig:2:22: error: type 'i32' does not support @hasField",
2598 });
2599
2600 ctx.objErrStage1("slice passed as array init type with elems",
2601 \\export fn entry() void {
2602 \\ const x = []u8{1, 2};
2603 \\ _ = x;
2604 \\}
2605 , &[_][]const u8{
2606 "tmp.zig:2:15: error: array literal requires address-of operator (&) to coerce to slice type '[]u8'",
2607 });
2608
2609 ctx.objErrStage1("slice passed as array init type",
2610 \\export fn entry() void {
2611 \\ const x = []u8{};
2612 \\ _ = x;
2613 \\}
2614 , &[_][]const u8{
2615 "tmp.zig:2:15: error: array literal requires address-of operator (&) to coerce to slice type '[]u8'",
2616 });
2617
2618 ctx.objErrStage1("inferred array size invalid here",
2619 \\export fn entry() void {
2620 \\ const x = [_]u8;
2621 \\ _ = x;
2622 \\}
2623 \\export fn entry2() void {
2624 \\ const S = struct { a: *const [_]u8 };
2625 \\ var a = .{ S{} };
2626 \\ _ = a;
2627 \\}
2628 , &[_][]const u8{
2629 "tmp.zig:2:16: error: unable to infer array size",
2630 "tmp.zig:6:35: error: unable to infer array size",
2631 });
2632
2633 ctx.objErrStage1("initializing array with struct syntax",
2634 \\export fn entry() void {
2635 \\ const x = [_]u8{ .y = 2 };
2636 \\ _ = x;
2637 \\}
2638 , &[_][]const u8{
2639 "tmp.zig:2:15: error: initializing array with struct syntax",
2640 });
2641
2642 ctx.objErrStage1("compile error in struct init expression",
2643 \\const Foo = struct {
2644 \\ a: i32 = crap,
2645 \\ b: i32,
2646 \\};
2647 \\export fn entry() void {
2648 \\ var x = Foo{
2649 \\ .b = 5,
2650 \\ };
2651 \\ _ = x;
2652 \\}
2653 , &[_][]const u8{
2654 "tmp.zig:2:14: error: use of undeclared identifier 'crap'",
2655 });
2656
2657 ctx.objErrStage1("undefined as field type is rejected",
2658 \\const Foo = struct {
2659 \\ a: undefined,
2660 \\};
2661 \\export fn entry1() void {
2662 \\ const foo: Foo = undefined;
2663 \\ _ = foo;
2664 \\}
2665 , &[_][]const u8{
2666 "tmp.zig:2:8: error: use of undefined value here causes undefined behavior",
2667 });
2668
2669 ctx.objErrStage1("@hasDecl with non-container",
2670 \\export fn entry() void {
2671 \\ _ = @hasDecl(i32, "hi");
2672 \\}
2673 , &[_][]const u8{
2674 "tmp.zig:2:18: error: expected struct, enum, or union; found 'i32'",
2675 });
2676
2677 ctx.objErrStage1("field access of slices",
2678 \\export fn entry() void {
2679 \\ var slice: []i32 = undefined;
2680 \\ const info = @TypeOf(slice).unknown;
2681 \\ _ = info;
2682 \\}
2683 , &[_][]const u8{
2684 "tmp.zig:3:32: error: type 'type' does not support field access",
2685 });
2686
2687 ctx.objErrStage1("peer cast then implicit cast const pointer to mutable C pointer",
2688 \\export fn func() void {
2689 \\ var strValue: [*c]u8 = undefined;
2690 \\ strValue = strValue orelse "";
2691 \\}
2692 , &[_][]const u8{
2693 "tmp.zig:3:32: error: expected type '[*c]u8', found '*const [0:0]u8'",
2694 "tmp.zig:3:32: note: cast discards const qualifier",
2695 });
2696
2697 ctx.objErrStage1("overflow in enum value allocation",
2698 \\const Moo = enum(u8) {
2699 \\ Last = 255,
2700 \\ Over,
2701 \\};
2702 \\pub fn main() void {
2703 \\ var y = Moo.Last;
2704 \\ _ = y;
2705 \\}
2706 , &[_][]const u8{
2707 "tmp.zig:3:5: error: enumeration value 256 too large for type 'u8'",
2708 });
2709
2710 ctx.objErrStage1("attempt to cast enum literal to error",
2711 \\export fn entry() void {
2712 \\ switch (error.Hi) {
2713 \\ .Hi => {},
2714 \\ }
2715 \\}
2716 , &[_][]const u8{
2717 "tmp.zig:3:9: error: expected type 'error{Hi}', found '@Type(.EnumLiteral)'",
2718 });
2719
2720 ctx.objErrStage1("@sizeOf bad type",
2721 \\export fn entry() usize {
2722 \\ return @sizeOf(@TypeOf(null));
2723 \\}
2724 , &[_][]const u8{
2725 "tmp.zig:2:20: error: no size available for type '@Type(.Null)'",
2726 });
2727
2728 ctx.objErrStage1("generic function where return type is self-referenced",
2729 \\fn Foo(comptime T: type) Foo(T) {
2730 \\ return struct{ x: T };
2731 \\}
2732 \\export fn entry() void {
2733 \\ const t = Foo(u32) {
2734 \\ .x = 1
2735 \\ };
2736 \\ _ = t;
2737 \\}
2738 , &[_][]const u8{
2739 "tmp.zig:1:29: error: evaluation exceeded 1000 backwards branches",
2740 });
2741
2742 ctx.objErrStage1("@ptrToInt 0 to non optional pointer",
2743 \\export fn entry() void {
2744 \\ var b = @intToPtr(*i32, 0);
2745 \\ _ = b;
2746 \\}
2747 , &[_][]const u8{
2748 "tmp.zig:2:13: error: pointer type '*i32' does not allow address zero",
2749 });
2750
2751 ctx.objErrStage1("cast enum literal to enum but it doesn't match",
2752 \\const Foo = enum {
2753 \\ a,
2754 \\ b,
2755 \\};
2756 \\export fn entry() void {
2757 \\ const x: Foo = .c;
2758 \\ _ = x;
2759 \\}
2760 , &[_][]const u8{
2761 "tmp.zig:6:20: error: enum 'Foo' has no field named 'c'",
2762 "tmp.zig:1:13: note: 'Foo' declared here",
2763 });
2764
2765 ctx.objErrStage1("discarding error value",
2766 \\export fn entry() void {
2767 \\ _ = foo();
2768 \\}
2769 \\fn foo() !void {
2770 \\ return error.OutOfMemory;
2771 \\}
2772 , &[_][]const u8{
2773 "tmp.zig:2:12: error: error is discarded. consider using `try`, `catch`, or `if`",
2774 });
2775
2776 ctx.objErrStage1("volatile on global assembly",
2777 \\comptime {
2778 \\ asm volatile ("");
2779 \\}
2780 , &[_][]const u8{
2781 "tmp.zig:2:9: error: volatile is meaningless on global assembly",
2782 });
2783
2784 ctx.objErrStage1("invalid multiple dereferences",
2785 \\export fn a() void {
2786 \\ var box = Box{ .field = 0 };
2787 \\ box.*.field = 1;
2788 \\}
2789 \\export fn b() void {
2790 \\ var box = Box{ .field = 0 };
2791 \\ var boxPtr = &box;
2792 \\ boxPtr.*.*.field = 1;
2793 \\}
2794 \\pub const Box = struct {
2795 \\ field: i32,
2796 \\};
2797 , &[_][]const u8{
2798 "tmp.zig:3:8: error: attempt to dereference non-pointer type 'Box'",
2799 "tmp.zig:8:13: error: attempt to dereference non-pointer type 'Box'",
2800 });
2801
2802 ctx.objErrStage1("usingnamespace with wrong type",
2803 \\usingnamespace void;
2804 , &[_][]const u8{
2805 "tmp.zig:1:1: error: expected struct, enum, or union; found 'void'",
2806 });
2807
2808 ctx.objErrStage1("ignored expression in while continuation",
2809 \\export fn a() void {
2810 \\ while (true) : (bad()) {}
2811 \\}
2812 \\export fn b() void {
2813 \\ var x: anyerror!i32 = 1234;
2814 \\ while (x) |_| : (bad()) {} else |_| {}
2815 \\}
2816 \\export fn c() void {
2817 \\ var x: ?i32 = 1234;
2818 \\ while (x) |_| : (bad()) {}
2819 \\}
2820 \\fn bad() anyerror!void {
2821 \\ return error.Bad;
2822 \\}
2823 , &[_][]const u8{
2824 "tmp.zig:2:24: error: error is ignored. consider using `try`, `catch`, or `if`",
2825 "tmp.zig:6:25: error: error is ignored. consider using `try`, `catch`, or `if`",
2826 "tmp.zig:10:25: error: error is ignored. consider using `try`, `catch`, or `if`",
2827 });
2828
2829 ctx.objErrStage1("empty while loop body",
2830 \\export fn a() void {
2831 \\ while(true);
2832 \\}
2833 , &[_][]const u8{
2834 "tmp.zig:2:16: error: expected block or assignment, found ';'",
2835 });
2836
2837 ctx.objErrStage1("empty for loop body",
2838 \\export fn a() void {
2839 \\ for(undefined) |x|;
2840 \\}
2841 , &[_][]const u8{
2842 "tmp.zig:2:23: error: expected block or assignment, found ';'",
2843 });
2844
2845 ctx.objErrStage1("empty if body",
2846 \\export fn a() void {
2847 \\ if(true);
2848 \\}
2849 , &[_][]const u8{
2850 "tmp.zig:2:13: error: expected block or assignment, found ';'",
2851 });
2852
2853 ctx.objErrStage1("import outside package path",
2854 \\comptime{
2855 \\ _ = @import("../a.zig");
2856 \\}
2857 , &[_][]const u8{
2858 "tmp.zig:2:9: error: import of file outside package path: '../a.zig'",
2859 });
2860
2861 ctx.objErrStage1("bogus compile var",
2862 \\const x = @import("builtin").bogus;
2863 \\export fn entry() usize { return @sizeOf(@TypeOf(x)); }
2864 , &[_][]const u8{
2865 "tmp.zig:1:29: error: container 'builtin' has no member called 'bogus'",
2866 });
2867
2868 ctx.objErrStage1("wrong panic signature, runtime function",
2869 \\test "" {}
2870 \\
2871 \\pub fn panic() void {}
2872 \\
2873 , &[_][]const u8{
2874 "error: expected type 'fn([]const u8, ?*std.builtin.StackTrace) noreturn', found 'fn() void'",
2875 });
2876
2877 ctx.objErrStage1("wrong panic signature, generic function",
2878 \\pub fn panic(comptime msg: []const u8, error_return_trace: ?*builtin.StackTrace) noreturn {
2879 \\ _ = msg; _ = error_return_trace;
2880 \\ while (true) {}
2881 \\}
2882 \\const builtin = @import("std").builtin;
2883 , &[_][]const u8{
2884 "error: expected type 'fn([]const u8, ?*std.builtin.StackTrace) noreturn', found 'fn([]const u8,anytype) anytype'",
2885 "note: only one of the functions is generic",
2886 });
2887
2888 ctx.objErrStage1("direct struct loop",
2889 \\const A = struct { a : A, };
2890 \\export fn entry() usize { return @sizeOf(A); }
2891 , &[_][]const u8{
2892 "tmp.zig:1:11: error: struct 'A' depends on itself",
2893 });
2894
2895 ctx.objErrStage1("indirect struct loop",
2896 \\const A = struct { b : B, };
2897 \\const B = struct { c : C, };
2898 \\const C = struct { a : A, };
2899 \\export fn entry() usize { return @sizeOf(A); }
2900 , &[_][]const u8{
2901 "tmp.zig:1:11: error: struct 'A' depends on itself",
2902 });
2903
2904 ctx.objErrStage1("instantiating an undefined value for an invalid struct that contains itself",
2905 \\const Foo = struct {
2906 \\ x: Foo,
2907 \\};
2908 \\
2909 \\var foo: Foo = undefined;
2910 \\
2911 \\export fn entry() usize {
2912 \\ return @sizeOf(@TypeOf(foo.x));
2913 \\}
2914 , &[_][]const u8{
2915 "tmp.zig:1:13: error: struct 'Foo' depends on itself",
2916 });
2917
2918 ctx.objErrStage1("enum field value references enum",
2919 \\pub const Foo = enum(c_int) {
2920 \\ A = Foo.B,
2921 \\ C = D,
2922 \\};
2923 \\export fn entry() void {
2924 \\ var s: Foo = Foo.E;
2925 \\ _ = s;
2926 \\}
2927 \\const D = 1;
2928 , &[_][]const u8{
2929 "tmp.zig:1:17: error: enum 'Foo' depends on itself",
2930 });
2931
2932 ctx.objErrStage1("top level decl dependency loop",
2933 \\const a : @TypeOf(b) = 0;
2934 \\const b : @TypeOf(a) = 0;
2935 \\export fn entry() void {
2936 \\ const c = a + b;
2937 \\ _ = c;
2938 \\}
2939 , &[_][]const u8{
2940 "tmp.zig:2:19: error: dependency loop detected",
2941 });
2942
2943 ctx.testErrStage1("not an enum type",
2944 \\export fn entry() void {
2945 \\ var self: Error = undefined;
2946 \\ switch (self) {
2947 \\ InvalidToken => |x| return x.token,
2948 \\ ExpectedVarDeclOrFn => |x| return x.token,
2949 \\ }
2950 \\}
2951 \\const Error = union(enum) {
2952 \\ A: InvalidToken,
2953 \\ B: ExpectedVarDeclOrFn,
2954 \\};
2955 \\const InvalidToken = struct {};
2956 \\const ExpectedVarDeclOrFn = struct {};
2957 , &[_][]const u8{
2958 "tmp.zig:4:9: error: expected type '@typeInfo(Error).Union.tag_type.?', found 'type'",
2959 });
2960
2961 ctx.testErrStage1("binary OR operator on error sets",
2962 \\pub const A = error.A;
2963 \\pub const AB = A | error.B;
2964 \\export fn entry() void {
2965 \\ var x: AB = undefined;
2966 \\ _ = x;
2967 \\}
2968 , &[_][]const u8{
2969 "tmp.zig:2:18: error: invalid operands to binary expression: 'error{A}' and 'error{B}'",
2970 });
2971
2972 if (builtin.os.tag == .linux) {
2973 ctx.testErrStage1("implicit dependency on libc",
2974 \\extern "c" fn exit(u8) void;
2975 \\export fn entry() void {
2976 \\ exit(0);
2977 \\}
2978 , &[_][]const u8{
2979 "tmp.zig:3:5: error: dependency on libc must be explicitly specified in the build command",
2980 });
2981
2982 ctx.testErrStage1("libc headers note",
2983 \\const c = @cImport(@cInclude("stdio.h"));
2984 \\export fn entry() void {
2985 \\ _ = c.printf("hello, world!\n");
2986 \\}
2987 , &[_][]const u8{
2988 "tmp.zig:1:11: error: C import failed",
2989 "tmp.zig:1:11: note: libc headers not available; compilation does not link against libc",
2990 });
2991 }
2992
2993 ctx.testErrStage1("comptime vector overflow shows the index",
2994 \\comptime {
2995 \\ var a: @import("std").meta.Vector(4, u8) = [_]u8{ 1, 2, 255, 4 };
2996 \\ var b: @import("std").meta.Vector(4, u8) = [_]u8{ 5, 6, 1, 8 };
2997 \\ var x = a + b;
2998 \\ _ = x;
2999 \\}
3000 , &[_][]const u8{
3001 "tmp.zig:4:15: error: operation caused overflow",
3002 "tmp.zig:4:15: note: when computing vector element at index 2",
3003 });
3004
3005 ctx.testErrStage1("packed struct with fields of not allowed types",
3006 \\const A = packed struct {
3007 \\ x: anyerror,
3008 \\};
3009 \\const B = packed struct {
3010 \\ x: [2]u24,
3011 \\};
3012 \\const C = packed struct {
3013 \\ x: [1]anyerror,
3014 \\};
3015 \\const D = packed struct {
3016 \\ x: [1]S,
3017 \\};
3018 \\const E = packed struct {
3019 \\ x: [1]U,
3020 \\};
3021 \\const F = packed struct {
3022 \\ x: ?anyerror,
3023 \\};
3024 \\const G = packed struct {
3025 \\ x: Enum,
3026 \\};
3027 \\export fn entry1() void {
3028 \\ var a: A = undefined;
3029 \\ _ = a;
3030 \\}
3031 \\export fn entry2() void {
3032 \\ var b: B = undefined;
3033 \\ _ = b;
3034 \\}
3035 \\export fn entry3() void {
3036 \\ var r: C = undefined;
3037 \\ _ = r;
3038 \\}
3039 \\export fn entry4() void {
3040 \\ var d: D = undefined;
3041 \\ _ = d;
3042 \\}
3043 \\export fn entry5() void {
3044 \\ var e: E = undefined;
3045 \\ _ = e;
3046 \\}
3047 \\export fn entry6() void {
3048 \\ var f: F = undefined;
3049 \\ _ = f;
3050 \\}
3051 \\export fn entry7() void {
3052 \\ var g: G = undefined;
3053 \\ _ = g;
3054 \\}
3055 \\const S = struct {
3056 \\ x: i32,
3057 \\};
3058 \\const U = struct {
3059 \\ A: i32,
3060 \\ B: u32,
3061 \\};
3062 \\const Enum = enum {
3063 \\ A,
3064 \\ B,
3065 \\};
3066 , &[_][]const u8{
3067 "tmp.zig:2:5: error: type 'anyerror' not allowed in packed struct; no guaranteed in-memory representation",
3068 "tmp.zig:5:5: error: array of 'u24' not allowed in packed struct due to padding bits (must be padded from 48 to 64 bits)",
3069 "tmp.zig:8:5: error: type 'anyerror' not allowed in packed struct; no guaranteed in-memory representation",
3070 "tmp.zig:11:5: error: non-packed, non-extern struct 'S' not allowed in packed struct; no guaranteed in-memory representation",
3071 "tmp.zig:14:5: error: non-packed, non-extern struct 'U' not allowed in packed struct; no guaranteed in-memory representation",
3072 "tmp.zig:17:5: error: type '?anyerror' not allowed in packed struct; no guaranteed in-memory representation",
3073 "tmp.zig:20:5: error: type 'Enum' not allowed in packed struct; no guaranteed in-memory representation",
3074 "tmp.zig:57:14: note: enum declaration does not specify an integer tag type",
3075 });
3076
3077 ctx.objErrStage1("deduplicate undeclared identifier",
3078 \\export fn a() void {
3079 \\ x += 1;
3080 \\}
3081 \\export fn b() void {
3082 \\ x += 1;
3083 \\}
3084 , &[_][]const u8{
3085 "tmp.zig:2:5: error: use of undeclared identifier 'x'",
3086 });
3087
3088 ctx.objErrStage1("export generic function",
3089 \\export fn foo(num: anytype) i32 {
3090 \\ _ = num;
3091 \\ return 0;
3092 \\}
3093 , &[_][]const u8{
3094 "tmp.zig:1:15: error: parameter of type 'anytype' not allowed in function with calling convention 'C'",
3095 });
3096
3097 ctx.objErrStage1("C pointer to anyopaque",
3098 \\export fn a() void {
3099 \\ var x: *anyopaque = undefined;
3100 \\ var y: [*c]anyopaque = x;
3101 \\ _ = y;
3102 \\}
3103 , &[_][]const u8{
3104 "tmp.zig:3:16: error: C pointers cannot point to opaque types",
3105 });
3106
3107 ctx.objErrStage1("directly embedding opaque type in struct and union",
3108 \\const O = opaque {};
3109 \\const Foo = struct {
3110 \\ o: O,
3111 \\};
3112 \\const Bar = union {
3113 \\ One: i32,
3114 \\ Two: O,
3115 \\};
3116 \\export fn a() void {
3117 \\ var foo: Foo = undefined;
3118 \\ _ = foo;
3119 \\}
3120 \\export fn b() void {
3121 \\ var bar: Bar = undefined;
3122 \\ _ = bar;
3123 \\}
3124 \\export fn c() void {
3125 \\ var baz: *opaque {} = undefined;
3126 \\ const qux = .{baz.*};
3127 \\ _ = qux;
3128 \\}
3129 , &[_][]const u8{
3130 "tmp.zig:3:5: error: opaque types have unknown size and therefore cannot be directly embedded in structs",
3131 "tmp.zig:7:5: error: opaque types have unknown size and therefore cannot be directly embedded in unions",
3132 "tmp.zig:19:22: error: opaque types have unknown size and therefore cannot be directly embedded in structs",
3133 });
3134
3135 ctx.objErrStage1("implicit cast between C pointer and Zig pointer - bad const/align/child",
3136 \\export fn a() void {
3137 \\ var x: [*c]u8 = undefined;
3138 \\ var y: *align(4) u8 = x;
3139 \\ _ = y;
3140 \\}
3141 \\export fn b() void {
3142 \\ var x: [*c]const u8 = undefined;
3143 \\ var y: *u8 = x;
3144 \\ _ = y;
3145 \\}
3146 \\export fn c() void {
3147 \\ var x: [*c]u8 = undefined;
3148 \\ var y: *u32 = x;
3149 \\ _ = y;
3150 \\}
3151 \\export fn d() void {
3152 \\ var y: *align(1) u32 = undefined;
3153 \\ var x: [*c]u32 = y;
3154 \\ _ = x;
3155 \\}
3156 \\export fn e() void {
3157 \\ var y: *const u8 = undefined;
3158 \\ var x: [*c]u8 = y;
3159 \\ _ = x;
3160 \\}
3161 \\export fn f() void {
3162 \\ var y: *u8 = undefined;
3163 \\ var x: [*c]u32 = y;
3164 \\ _ = x;
3165 \\}
3166 , &[_][]const u8{
3167 "tmp.zig:3:27: error: cast increases pointer alignment",
3168 "tmp.zig:8:18: error: cast discards const qualifier",
3169 "tmp.zig:13:19: error: expected type '*u32', found '[*c]u8'",
3170 "tmp.zig:13:19: note: pointer type child 'u8' cannot cast into pointer type child 'u32'",
3171 "tmp.zig:18:22: error: cast increases pointer alignment",
3172 "tmp.zig:23:21: error: cast discards const qualifier",
3173 "tmp.zig:28:22: error: expected type '[*c]u32', found '*u8'",
3174 });
3175
3176 ctx.objErrStage1("implicit casting null c pointer to zig pointer",
3177 \\comptime {
3178 \\ var c_ptr: [*c]u8 = 0;
3179 \\ var zig_ptr: *u8 = c_ptr;
3180 \\ _ = zig_ptr;
3181 \\}
3182 , &[_][]const u8{
3183 "tmp.zig:3:24: error: null pointer casted to type '*u8'",
3184 });
3185
3186 ctx.objErrStage1("implicit casting undefined c pointer to zig pointer",
3187 \\comptime {
3188 \\ var c_ptr: [*c]u8 = undefined;
3189 \\ var zig_ptr: *u8 = c_ptr;
3190 \\ _ = zig_ptr;
3191 \\}
3192 , &[_][]const u8{
3193 "tmp.zig:3:24: error: use of undefined value here causes undefined behavior",
3194 });
3195
3196 ctx.objErrStage1("implicit casting C pointers which would mess up null semantics",
3197 \\export fn entry() void {
3198 \\ var slice: []const u8 = "aoeu";
3199 \\ const opt_many_ptr: [*]const u8 = slice.ptr;
3200 \\ var ptr_opt_many_ptr = &opt_many_ptr;
3201 \\ var c_ptr: [*c]const [*c]const u8 = ptr_opt_many_ptr;
3202 \\ ptr_opt_many_ptr = c_ptr;
3203 \\}
3204 \\export fn entry2() void {
3205 \\ var buf: [4]u8 = "aoeu".*;
3206 \\ var slice: []u8 = &buf;
3207 \\ var opt_many_ptr: [*]u8 = slice.ptr;
3208 \\ var ptr_opt_many_ptr = &opt_many_ptr;
3209 \\ var c_ptr: [*c][*c]const u8 = ptr_opt_many_ptr;
3210 \\ _ = c_ptr;
3211 \\}
3212 , &[_][]const u8{
3213 "tmp.zig:6:24: error: expected type '*const [*]const u8', found '[*c]const [*c]const u8'",
3214 "tmp.zig:6:24: note: pointer type child '[*c]const u8' cannot cast into pointer type child '[*]const u8'",
3215 "tmp.zig:6:24: note: '[*c]const u8' could have null values which are illegal in type '[*]const u8'",
3216 "tmp.zig:13:35: error: expected type '[*c][*c]const u8', found '*[*]u8'",
3217 "tmp.zig:13:35: note: pointer type child '[*]u8' cannot cast into pointer type child '[*c]const u8'",
3218 "tmp.zig:13:35: note: mutable '[*c]const u8' allows illegal null values stored to type '[*]u8'",
3219 });
3220
3221 ctx.objErrStage1("implicit casting too big integers to C pointers",
3222 \\export fn a() void {
3223 \\ var ptr: [*c]u8 = (1 << 64) + 1;
3224 \\ _ = ptr;
3225 \\}
3226 \\export fn b() void {
3227 \\ var x: u65 = 0x1234;
3228 \\ var ptr: [*c]u8 = x;
3229 \\ _ = ptr;
3230 \\}
3231 , &[_][]const u8{
3232 "tmp.zig:2:33: error: integer value 18446744073709551617 cannot be coerced to type 'usize'",
3233 "tmp.zig:7:23: error: integer type 'u65' too big for implicit @intToPtr to type '[*c]u8'",
3234 });
3235
3236 ctx.objErrStage1("C pointer pointing to non C ABI compatible type or has align attr",
3237 \\const Foo = struct {};
3238 \\export fn a() void {
3239 \\ const T = [*c]Foo;
3240 \\ var t: T = undefined;
3241 \\ _ = t;
3242 \\}
3243 , &[_][]const u8{
3244 "tmp.zig:3:19: error: C pointers cannot point to non-C-ABI-compatible type 'Foo'",
3245 });
3246
3247 ctx.objErrStage1("compile log statement warning deduplication in generic fn",
3248 \\export fn entry() void {
3249 \\ inner(1);
3250 \\ inner(2);
3251 \\}
3252 \\fn inner(comptime n: usize) void {
3253 \\ comptime var i = 0;
3254 \\ inline while (i < n) : (i += 1) { @compileLog("!@#$"); }
3255 \\}
3256 , &[_][]const u8{
3257 "tmp.zig:7:39: error: found compile log statement",
3258 });
3259
3260 ctx.objErrStage1("assign to invalid dereference",
3261 \\export fn entry() void {
3262 \\ 'a'.* = 1;
3263 \\}
3264 , &[_][]const u8{
3265 "tmp.zig:2:8: error: attempt to dereference non-pointer type 'comptime_int'",
3266 });
3267
3268 ctx.objErrStage1("take slice of invalid dereference",
3269 \\export fn entry() void {
3270 \\ const x = 'a'.*[0..];
3271 \\ _ = x;
3272 \\}
3273 , &[_][]const u8{
3274 "tmp.zig:2:18: error: attempt to dereference non-pointer type 'comptime_int'",
3275 });
3276
3277 ctx.objErrStage1("@truncate undefined value",
3278 \\export fn entry() void {
3279 \\ var z = @truncate(u8, @as(u16, undefined));
3280 \\ _ = z;
3281 \\}
3282 , &[_][]const u8{
3283 "tmp.zig:2:27: error: use of undefined value here causes undefined behavior",
3284 });
3285
3286 ctx.testErrStage1("return invalid type from test",
3287 \\test "example" { return 1; }
3288 , &[_][]const u8{
3289 "tmp.zig:1:25: error: expected type 'void', found 'comptime_int'",
3290 });
3291
3292 ctx.objErrStage1("threadlocal qualifier on const",
3293 \\threadlocal const x: i32 = 1234;
3294 \\export fn entry() i32 {
3295 \\ return x;
3296 \\}
3297 , &[_][]const u8{
3298 "tmp.zig:1:1: error: threadlocal variable cannot be constant",
3299 });
3300
3301 ctx.objErrStage1("@bitCast same size but bit count mismatch",
3302 \\export fn entry(byte: u8) void {
3303 \\ var oops = @bitCast(u7, byte);
3304 \\ _ = oops;
3305 \\}
3306 , &[_][]const u8{
3307 "tmp.zig:2:25: error: destination type 'u7' has 7 bits but source type 'u8' has 8 bits",
3308 });
3309
3310 ctx.objErrStage1("@bitCast with different sizes inside an expression",
3311 \\export fn entry() void {
3312 \\ var foo = (@bitCast(u8, @as(f32, 1.0)) == 0xf);
3313 \\ _ = foo;
3314 \\}
3315 , &[_][]const u8{
3316 "tmp.zig:2:25: error: destination type 'u8' has size 1 but source type 'f32' has size 4",
3317 });
3318
3319 ctx.objErrStage1("attempted `&&`",
3320 \\export fn entry(a: bool, b: bool) i32 {
3321 \\ if (a && b) {
3322 \\ return 1234;
3323 \\ }
3324 \\ return 5678;
3325 \\}
3326 , &[_][]const u8{
3327 "tmp.zig:2:11: error: ambiguous use of '&&'; use 'and' for logical AND, or change whitespace to ' & &' for bitwise AND",
3328 });
3329
3330 ctx.objErrStage1("attempted `||` on boolean values",
3331 \\export fn entry(a: bool, b: bool) i32 {
3332 \\ if (a || b) {
3333 \\ return 1234;
3334 \\ }
3335 \\ return 5678;
3336 \\}
3337 , &[_][]const u8{
3338 "tmp.zig:2:9: error: expected error set type, found 'bool'",
3339 "tmp.zig:2:11: note: `||` merges error sets; `or` performs boolean OR",
3340 });
3341
3342 ctx.objErrStage1("compile log a pointer to an opaque value",
3343 \\export fn entry() void {
3344 \\ @compileLog(@ptrCast(*const anyopaque, &entry));
3345 \\}
3346 , &[_][]const u8{
3347 "tmp.zig:2:5: error: found compile log statement",
3348 });
3349
3350 ctx.objErrStage1("duplicate boolean switch value",
3351 \\comptime {
3352 \\ const x = switch (true) {
3353 \\ true => false,
3354 \\ false => true,
3355 \\ true => false,
3356 \\ };
3357 \\ _ = x;
3358 \\}
3359 \\comptime {
3360 \\ const x = switch (true) {
3361 \\ false => true,
3362 \\ true => false,
3363 \\ false => true,
3364 \\ };
3365 \\ _ = x;
3366 \\}
3367 , &[_][]const u8{
3368 "tmp.zig:5:9: error: duplicate switch value",
3369 "tmp.zig:13:9: error: duplicate switch value",
3370 });
3371
3372 ctx.objErrStage1("missing boolean switch value",
3373 \\comptime {
3374 \\ const x = switch (true) {
3375 \\ true => false,
3376 \\ };
3377 \\ _ = x;
3378 \\}
3379 \\comptime {
3380 \\ const x = switch (true) {
3381 \\ false => true,
3382 \\ };
3383 \\ _ = x;
3384 \\}
3385 , &[_][]const u8{
3386 "tmp.zig:2:15: error: switch must handle all possibilities",
3387 "tmp.zig:8:15: error: switch must handle all possibilities",
3388 });
3389
3390 ctx.objErrStage1("reading past end of pointer casted array",
3391 \\comptime {
3392 \\ const array: [4]u8 = "aoeu".*;
3393 \\ const sub_array = array[1..];
3394 \\ const int_ptr = @ptrCast(*const u24, sub_array);
3395 \\ const deref = int_ptr.*;
3396 \\ _ = deref;
3397 \\}
3398 , &[_][]const u8{
3399 "tmp.zig:5:26: error: attempt to read 4 bytes from [4]u8 at index 1 which is 3 bytes",
3400 });
3401
3402 ctx.objErrStage1("error note for function parameter incompatibility",
3403 \\fn do_the_thing(func: fn (arg: i32) void) void { _ = func; }
3404 \\fn bar(arg: bool) void { _ = arg; }
3405 \\export fn entry() void {
3406 \\ do_the_thing(bar);
3407 \\}
3408 , &[_][]const u8{
3409 "tmp.zig:4:18: error: expected type 'fn(i32) void', found 'fn(bool) void",
3410 "tmp.zig:4:18: note: parameter 0: 'bool' cannot cast into 'i32'",
3411 });
3412 ctx.objErrStage1("cast negative value to unsigned integer",
3413 \\comptime {
3414 \\ const value: i32 = -1;
3415 \\ const unsigned = @intCast(u32, value);
3416 \\ _ = unsigned;
3417 \\}
3418 \\export fn entry1() void {
3419 \\ const value: i32 = -1;
3420 \\ const unsigned: u32 = value;
3421 \\ _ = unsigned;
3422 \\}
3423 , &[_][]const u8{
3424 "tmp.zig:3:22: error: attempt to cast negative value to unsigned integer",
3425 "tmp.zig:8:27: error: cannot cast negative value -1 to unsigned integer type 'u32'",
3426 });
3427
3428 ctx.objErrStage1("integer cast truncates bits",
3429 \\export fn entry1() void {
3430 \\ const spartan_count: u16 = 300;
3431 \\ const byte = @intCast(u8, spartan_count);
3432 \\ _ = byte;
3433 \\}
3434 \\export fn entry2() void {
3435 \\ const spartan_count: u16 = 300;
3436 \\ const byte: u8 = spartan_count;
3437 \\ _ = byte;
3438 \\}
3439 \\export fn entry3() void {
3440 \\ var spartan_count: u16 = 300;
3441 \\ var byte: u8 = spartan_count;
3442 \\ _ = byte;
3443 \\}
3444 \\export fn entry4() void {
3445 \\ var signed: i8 = -1;
3446 \\ var unsigned: u64 = signed;
3447 \\ _ = unsigned;
3448 \\}
3449 , &[_][]const u8{
3450 "tmp.zig:3:18: error: cast from 'u16' to 'u8' truncates bits",
3451 "tmp.zig:8:22: error: integer value 300 cannot be coerced to type 'u8'",
3452 "tmp.zig:13:20: error: expected type 'u8', found 'u16'",
3453 "tmp.zig:13:20: note: unsigned 8-bit int cannot represent all possible unsigned 16-bit values",
3454 "tmp.zig:18:25: error: expected type 'u64', found 'i8'",
3455 "tmp.zig:18:25: note: unsigned 64-bit int cannot represent all possible signed 8-bit values",
3456 });
3457
3458 ctx.objErrStage1("comptime implicit cast f64 to f32",
3459 \\export fn entry() void {
3460 \\ const x: f64 = 16777217;
3461 \\ const y: f32 = x;
3462 \\ _ = y;
3463 \\}
3464 , &[_][]const u8{
3465 "tmp.zig:3:20: error: cast of value 16777217.000000 to type 'f32' loses information",
3466 });
3467
3468 ctx.objErrStage1("implicit cast from f64 to f32",
3469 \\var x: f64 = 1.0;
3470 \\var y: f32 = x;
3471 \\
3472 \\export fn entry() usize { return @sizeOf(@TypeOf(y)); }
3473 , &[_][]const u8{
3474 "tmp.zig:2:14: error: expected type 'f32', found 'f64'",
3475 });
3476
3477 ctx.objErrStage1("exceeded maximum bit width of integer",
3478 \\export fn entry1() void {
3479 \\ const T = u65536;
3480 \\ _ = T;
3481 \\}
3482 \\export fn entry2() void {
3483 \\ var x: i65536 = 1;
3484 \\ _ = x;
3485 \\}
3486 , &[_][]const u8{
3487 "tmp.zig:2:15: error: primitive integer type 'u65536' exceeds maximum bit width of 65535",
3488 "tmp.zig:6:12: error: primitive integer type 'i65536' exceeds maximum bit width of 65535",
3489 });
3490
3491 ctx.objErrStage1("compile error when evaluating return type of inferred error set",
3492 \\const Car = struct {
3493 \\ foo: *SymbolThatDoesNotExist,
3494 \\ pub fn init() !Car {}
3495 \\};
3496 \\export fn entry() void {
3497 \\ const car = Car.init();
3498 \\ _ = car;
3499 \\}
3500 , &[_][]const u8{
3501 "tmp.zig:2:11: error: use of undeclared identifier 'SymbolThatDoesNotExist'",
3502 });
3503
3504 ctx.objErrStage1("don't implicit cast double pointer to *anyopaque",
3505 \\export fn entry() void {
3506 \\ var a: u32 = 1;
3507 \\ var ptr: *align(@alignOf(u32)) anyopaque = &a;
3508 \\ var b: *u32 = @ptrCast(*u32, ptr);
3509 \\ var ptr2: *anyopaque = &b;
3510 \\ _ = ptr2;
3511 \\}
3512 , &[_][]const u8{
3513 "tmp.zig:5:29: error: expected type '*anyopaque', found '**u32'",
3514 });
3515
3516 ctx.objErrStage1("runtime index into comptime type slice",
3517 \\const Struct = struct {
3518 \\ a: u32,
3519 \\};
3520 \\fn getIndex() usize {
3521 \\ return 2;
3522 \\}
3523 \\export fn entry() void {
3524 \\ const index = getIndex();
3525 \\ const field = @typeInfo(Struct).Struct.fields[index];
3526 \\ _ = field;
3527 \\}
3528 , &[_][]const u8{
3529 "tmp.zig:9:51: error: values of type 'std.builtin.Type.StructField' must be comptime known, but index value is runtime known",
3530 });
3531
3532 ctx.objErrStage1("compile log statement inside function which must be comptime evaluated",
3533 \\fn Foo(comptime T: type) type {
3534 \\ @compileLog(@typeName(T));
3535 \\ return T;
3536 \\}
3537 \\export fn entry() void {
3538 \\ _ = Foo(i32);
3539 \\ _ = @typeName(Foo(i32));
3540 \\}
3541 , &[_][]const u8{
3542 "tmp.zig:2:5: error: found compile log statement",
3543 });
3544
3545 ctx.objErrStage1("comptime slice of an undefined slice",
3546 \\comptime {
3547 \\ var a: []u8 = undefined;
3548 \\ var b = a[0..10];
3549 \\ _ = b;
3550 \\}
3551 , &[_][]const u8{
3552 "tmp.zig:3:14: error: slice of undefined",
3553 });
3554
3555 ctx.objErrStage1("implicit cast const array to mutable slice",
3556 \\export fn entry() void {
3557 \\ const buffer: [1]u8 = [_]u8{8};
3558 \\ const sliceA: []u8 = &buffer;
3559 \\ _ = sliceA;
3560 \\}
3561 , &[_][]const u8{
3562 "tmp.zig:3:27: error: cannot cast pointer to array literal to slice type '[]u8'",
3563 "tmp.zig:3:27: note: cast discards const qualifier",
3564 });
3565
3566 ctx.objErrStage1("deref slice and get len field",
3567 \\export fn entry() void {
3568 \\ var a: []u8 = undefined;
3569 \\ _ = a.*.len;
3570 \\}
3571 , &[_][]const u8{
3572 "tmp.zig:3:10: error: attempt to dereference non-pointer type '[]u8'",
3573 });
3574
3575 ctx.objErrStage1("@ptrCast a 0 bit type to a non- 0 bit type",
3576 \\export fn entry() bool {
3577 \\ var x: u0 = 0;
3578 \\ const p = @ptrCast(?*u0, &x);
3579 \\ return p == null;
3580 \\}
3581 , &[_][]const u8{
3582 "tmp.zig:3:15: error: '*u0' and '?*u0' do not have the same in-memory representation",
3583 "tmp.zig:3:31: note: '*u0' has no in-memory bits",
3584 "tmp.zig:3:24: note: '?*u0' has in-memory bits",
3585 });
3586
3587 ctx.objErrStage1("comparing a non-optional pointer against null",
3588 \\export fn entry() void {
3589 \\ var x: i32 = 1;
3590 \\ _ = &x == null;
3591 \\}
3592 , &[_][]const u8{
3593 "tmp.zig:3:12: error: comparison of '*i32' with null",
3594 });
3595
3596 ctx.objErrStage1("non error sets used in merge error sets operator",
3597 \\export fn foo() void {
3598 \\ const Errors = u8 || u16;
3599 \\ _ = Errors;
3600 \\}
3601 \\export fn bar() void {
3602 \\ const Errors = error{} || u16;
3603 \\ _ = Errors;
3604 \\}
3605 , &[_][]const u8{
3606 "tmp.zig:2:20: error: expected error set type, found type 'u8'",
3607 "tmp.zig:2:23: note: `||` merges error sets; `or` performs boolean OR",
3608 "tmp.zig:6:31: error: expected error set type, found type 'u16'",
3609 "tmp.zig:6:28: note: `||` merges error sets; `or` performs boolean OR",
3610 });
3611
3612 ctx.objErrStage1("variable initialization compile error then referenced",
3613 \\fn Undeclared() type {
3614 \\ return T;
3615 \\}
3616 \\fn Gen() type {
3617 \\ const X = Undeclared();
3618 \\ return struct {
3619 \\ x: X,
3620 \\ };
3621 \\}
3622 \\export fn entry() void {
3623 \\ const S = Gen();
3624 \\ _ = S;
3625 \\}
3626 , &[_][]const u8{
3627 "tmp.zig:2:12: error: use of undeclared identifier 'T'",
3628 });
3629
3630 ctx.objErrStage1("refer to the type of a generic function",
3631 \\export fn entry() void {
3632 \\ const Func = fn (type) void;
3633 \\ const f: Func = undefined;
3634 \\ f(i32);
3635 \\}
3636 , &[_][]const u8{
3637 "tmp.zig:4:5: error: use of undefined value here causes undefined behavior",
3638 });
3639
3640 ctx.objErrStage1("accessing runtime parameter from outer function",
3641 \\fn outer(y: u32) fn (u32) u32 {
3642 \\ const st = struct {
3643 \\ fn get(z: u32) u32 {
3644 \\ return z + y;
3645 \\ }
3646 \\ };
3647 \\ return st.get;
3648 \\}
3649 \\export fn entry() void {
3650 \\ var func = outer(10);
3651 \\ var x = func(3);
3652 \\ _ = x;
3653 \\}
3654 , &[_][]const u8{
3655 "tmp.zig:4:24: error: 'y' not accessible from inner function",
3656 "tmp.zig:3:28: note: crossed function definition here",
3657 "tmp.zig:1:10: note: declared here",
3658 });
3659
3660 ctx.objErrStage1("non int passed to @intToFloat",
3661 \\export fn entry() void {
3662 \\ const x = @intToFloat(f32, 1.1);
3663 \\ _ = x;
3664 \\}
3665 , &[_][]const u8{
3666 "tmp.zig:2:32: error: expected int type, found 'comptime_float'",
3667 });
3668
3669 ctx.objErrStage1("non float passed to @floatToInt",
3670 \\export fn entry() void {
3671 \\ const x = @floatToInt(i32, @as(i32, 54));
3672 \\ _ = x;
3673 \\}
3674 , &[_][]const u8{
3675 "tmp.zig:2:32: error: expected float type, found 'i32'",
3676 });
3677
3678 ctx.objErrStage1("out of range comptime_int passed to @floatToInt",
3679 \\export fn entry() void {
3680 \\ const x = @floatToInt(i8, 200);
3681 \\ _ = x;
3682 \\}
3683 , &[_][]const u8{
3684 "tmp.zig:2:31: error: integer value 200 cannot be coerced to type 'i8'",
3685 });
3686
3687 ctx.objErrStage1("load too many bytes from comptime reinterpreted pointer",
3688 \\export fn entry() void {
3689 \\ const float: f32 = 5.99999999999994648725e-01;
3690 \\ const float_ptr = &float;
3691 \\ const int_ptr = @ptrCast(*const i64, float_ptr);
3692 \\ const int_val = int_ptr.*;
3693 \\ _ = int_val;
3694 \\}
3695 , &[_][]const u8{
3696 "tmp.zig:5:28: error: attempt to read 8 bytes from pointer to f32 which is 4 bytes",
3697 });
3698
3699 ctx.objErrStage1("invalid type used in array type",
3700 \\const Item = struct {
3701 \\ field: SomeNonexistentType,
3702 \\};
3703 \\var items: [100]Item = undefined;
3704 \\export fn entry() void {
3705 \\ const a = items[0];
3706 \\ _ = a;
3707 \\}
3708 , &[_][]const u8{
3709 "tmp.zig:2:12: error: use of undeclared identifier 'SomeNonexistentType'",
3710 });
3711
3712 ctx.objErrStage1("comptime continue inside runtime catch",
3713 \\export fn entry() void {
3714 \\ const ints = [_]u8{ 1, 2 };
3715 \\ inline for (ints) |_| {
3716 \\ bad() catch continue;
3717 \\ }
3718 \\}
3719 \\fn bad() !void {
3720 \\ return error.Bad;
3721 \\}
3722 , &[_][]const u8{
3723 "tmp.zig:4:21: error: comptime control flow inside runtime block",
3724 "tmp.zig:4:15: note: runtime block created here",
3725 });
3726
3727 ctx.objErrStage1("comptime continue inside runtime switch",
3728 \\export fn entry() void {
3729 \\ var p: i32 = undefined;
3730 \\ comptime var q = true;
3731 \\ inline while (q) {
3732 \\ switch (p) {
3733 \\ 11 => continue,
3734 \\ else => {},
3735 \\ }
3736 \\ q = false;
3737 \\ }
3738 \\}
3739 , &[_][]const u8{
3740 "tmp.zig:6:19: error: comptime control flow inside runtime block",
3741 "tmp.zig:5:9: note: runtime block created here",
3742 });
3743
3744 ctx.objErrStage1("comptime continue inside runtime while error",
3745 \\export fn entry() void {
3746 \\ var p: anyerror!usize = undefined;
3747 \\ comptime var q = true;
3748 \\ outer: inline while (q) {
3749 \\ while (p) |_| {
3750 \\ continue :outer;
3751 \\ } else |_| {}
3752 \\ q = false;
3753 \\ }
3754 \\}
3755 , &[_][]const u8{
3756 "tmp.zig:6:13: error: comptime control flow inside runtime block",
3757 "tmp.zig:5:9: note: runtime block created here",
3758 });
3759
3760 ctx.objErrStage1("comptime continue inside runtime while optional",
3761 \\export fn entry() void {
3762 \\ var p: ?usize = undefined;
3763 \\ comptime var q = true;
3764 \\ outer: inline while (q) {
3765 \\ while (p) |_| continue :outer;
3766 \\ q = false;
3767 \\ }
3768 \\}
3769 , &[_][]const u8{
3770 "tmp.zig:5:23: error: comptime control flow inside runtime block",
3771 "tmp.zig:5:9: note: runtime block created here",
3772 });
3773
3774 ctx.objErrStage1("comptime continue inside runtime while bool",
3775 \\export fn entry() void {
3776 \\ var p: usize = undefined;
3777 \\ comptime var q = true;
3778 \\ outer: inline while (q) {
3779 \\ while (p == 11) continue :outer;
3780 \\ q = false;
3781 \\ }
3782 \\}
3783 , &[_][]const u8{
3784 "tmp.zig:5:25: error: comptime control flow inside runtime block",
3785 "tmp.zig:5:9: note: runtime block created here",
3786 });
3787
3788 ctx.objErrStage1("comptime continue inside runtime if error",
3789 \\export fn entry() void {
3790 \\ var p: anyerror!i32 = undefined;
3791 \\ comptime var q = true;
3792 \\ inline while (q) {
3793 \\ if (p) |_| continue else |_| {}
3794 \\ q = false;
3795 \\ }
3796 \\}
3797 , &[_][]const u8{
3798 "tmp.zig:5:20: error: comptime control flow inside runtime block",
3799 "tmp.zig:5:9: note: runtime block created here",
3800 });
3801
3802 ctx.objErrStage1("comptime continue inside runtime if optional",
3803 \\export fn entry() void {
3804 \\ var p: ?i32 = undefined;
3805 \\ comptime var q = true;
3806 \\ inline while (q) {
3807 \\ if (p) |_| continue;
3808 \\ q = false;
3809 \\ }
3810 \\}
3811 , &[_][]const u8{
3812 "tmp.zig:5:20: error: comptime control flow inside runtime block",
3813 "tmp.zig:5:9: note: runtime block created here",
3814 });
3815
3816 ctx.objErrStage1("comptime continue inside runtime if bool",
3817 \\export fn entry() void {
3818 \\ var p: usize = undefined;
3819 \\ comptime var q = true;
3820 \\ inline while (q) {
3821 \\ if (p == 11) continue;
3822 \\ q = false;
3823 \\ }
3824 \\}
3825 , &[_][]const u8{
3826 "tmp.zig:5:22: error: comptime control flow inside runtime block",
3827 "tmp.zig:5:9: note: runtime block created here",
3828 });
3829
3830 ctx.objErrStage1("switch with invalid expression parameter",
3831 \\export fn entry() void {
3832 \\ Test(i32);
3833 \\}
3834 \\fn Test(comptime T: type) void {
3835 \\ const x = switch (T) {
3836 \\ []u8 => |x| x,
3837 \\ i32 => |x| x,
3838 \\ else => unreachable,
3839 \\ };
3840 \\ _ = x;
3841 \\}
3842 , &[_][]const u8{
3843 "tmp.zig:7:17: error: switch on type 'type' provides no expression parameter",
3844 });
3845
3846 ctx.objErrStage1("function prototype with no body",
3847 \\fn foo() void;
3848 \\export fn entry() void {
3849 \\ foo();
3850 \\}
3851 , &[_][]const u8{
3852 "tmp.zig:1:1: error: non-extern function has no body",
3853 });
3854
3855 ctx.objErrStage1("@frame() called outside of function definition",
3856 \\var handle_undef: anyframe = undefined;
3857 \\var handle_dummy: anyframe = @frame();
3858 \\export fn entry() bool {
3859 \\ return handle_undef == handle_dummy;
3860 \\}
3861 , &[_][]const u8{
3862 "tmp.zig:2:30: error: @frame() called outside of function definition",
3863 });
3864
3865 ctx.objErrStage1("`_` is not a declarable symbol",
3866 \\export fn f1() usize {
3867 \\ var _: usize = 2;
3868 \\ return _;
3869 \\}
3870 , &[_][]const u8{
3871 "tmp.zig:2:9: error: '_' used as an identifier without @\"_\" syntax",
3872 });
3873
3874 ctx.objErrStage1("`_` should not be usable inside for",
3875 \\export fn returns() void {
3876 \\ for ([_]void{}) |_, i| {
3877 \\ for ([_]void{}) |_, j| {
3878 \\ return _;
3879 \\ }
3880 \\ }
3881 \\}
3882 , &[_][]const u8{
3883 "tmp.zig:4:20: error: '_' used as an identifier without @\"_\" syntax",
3884 });
3885
3886 ctx.objErrStage1("`_` should not be usable inside while",
3887 \\export fn returns() void {
3888 \\ while (optionalReturn()) |_| {
3889 \\ while (optionalReturn()) |_| {
3890 \\ return _;
3891 \\ }
3892 \\ }
3893 \\}
3894 \\fn optionalReturn() ?u32 {
3895 \\ return 1;
3896 \\}
3897 , &[_][]const u8{
3898 "tmp.zig:4:20: error: '_' used as an identifier without @\"_\" syntax",
3899 });
3900
3901 ctx.objErrStage1("`_` should not be usable inside while else",
3902 \\export fn returns() void {
3903 \\ while (optionalReturnError()) |_| {
3904 \\ while (optionalReturnError()) |_| {
3905 \\ return;
3906 \\ } else |_| {
3907 \\ if (_ == error.optionalReturnError) return;
3908 \\ }
3909 \\ }
3910 \\}
3911 \\fn optionalReturnError() !?u32 {
3912 \\ return error.optionalReturnError;
3913 \\}
3914 , &[_][]const u8{
3915 "tmp.zig:6:17: error: '_' used as an identifier without @\"_\" syntax",
3916 });
3917
3918 ctx.objErrStage1("while loop body expression ignored",
3919 \\fn returns() usize {
3920 \\ return 2;
3921 \\}
3922 \\export fn f1() void {
3923 \\ while (true) returns();
3924 \\}
3925 \\export fn f2() void {
3926 \\ var x: ?i32 = null;
3927 \\ while (x) |_| returns();
3928 \\}
3929 \\export fn f3() void {
3930 \\ var x: anyerror!i32 = error.Bad;
3931 \\ while (x) |_| returns() else |_| unreachable;
3932 \\}
3933 , &[_][]const u8{
3934 "tmp.zig:5:25: error: expression value is ignored",
3935 "tmp.zig:9:26: error: expression value is ignored",
3936 "tmp.zig:13:26: error: expression value is ignored",
3937 });
3938
3939 ctx.objErrStage1("missing parameter name of generic function",
3940 \\fn dump(anytype) void {}
3941 \\export fn entry() void {
3942 \\ var a: u8 = 9;
3943 \\ dump(a);
3944 \\}
3945 , &[_][]const u8{
3946 "tmp.zig:1:9: error: missing parameter name",
3947 });
3948
3949 ctx.objErrStage1("non-inline for loop on a type that requires comptime",
3950 \\const Foo = struct {
3951 \\ name: []const u8,
3952 \\ T: type,
3953 \\};
3954 \\export fn entry() void {
3955 \\ const xx: [2]Foo = undefined;
3956 \\ for (xx) |f| { _ = f;}
3957 \\}
3958 , &[_][]const u8{
3959 "tmp.zig:7:5: error: values of type 'Foo' must be comptime known, but index value is runtime known",
3960 });
3961
3962 ctx.objErrStage1("generic fn as parameter without comptime keyword",
3963 \\fn f(_: fn (anytype) void) void {}
3964 \\fn g(_: anytype) void {}
3965 \\export fn entry() void {
3966 \\ f(g);
3967 \\}
3968 , &[_][]const u8{
3969 "tmp.zig:1:9: error: parameter of type 'fn(anytype) anytype' must be declared comptime",
3970 });
3971
3972 ctx.objErrStage1("optional pointer to void in extern struct",
3973 \\const Foo = extern struct {
3974 \\ x: ?*const void,
3975 \\};
3976 \\const Bar = extern struct {
3977 \\ foo: Foo,
3978 \\ y: i32,
3979 \\};
3980 \\export fn entry(bar: *Bar) void {_ = bar;}
3981 , &[_][]const u8{
3982 "tmp.zig:2:5: error: extern structs cannot contain fields of type '?*const void'",
3983 });
3984
3985 ctx.objErrStage1("use of comptime-known undefined function value",
3986 \\const Cmd = struct {
3987 \\ exec: fn () void,
3988 \\};
3989 \\export fn entry() void {
3990 \\ const command = Cmd{ .exec = undefined };
3991 \\ command.exec();
3992 \\}
3993 , &[_][]const u8{
3994 "tmp.zig:6:12: error: use of undefined value here causes undefined behavior",
3995 });
3996
3997 ctx.objErrStage1("use of comptime-known undefined function value",
3998 \\const Cmd = struct {
3999 \\ exec: fn () void,
4000 \\};
4001 \\export fn entry() void {
4002 \\ const command = Cmd{ .exec = undefined };
4003 \\ command.exec();
4004 \\}
4005 , &[_][]const u8{
4006 "tmp.zig:6:12: error: use of undefined value here causes undefined behavior",
4007 });
4008
4009 ctx.objErrStage1("bad @alignCast at comptime",
4010 \\comptime {
4011 \\ const ptr = @intToPtr(*align(1) i32, 0x1);
4012 \\ const aligned = @alignCast(4, ptr);
4013 \\ _ = aligned;
4014 \\}
4015 , &[_][]const u8{
4016 "tmp.zig:3:35: error: pointer address 0x1 is not aligned to 4 bytes",
4017 });
4018
4019 ctx.objErrStage1("@ptrToInt on *void",
4020 \\export fn entry() bool {
4021 \\ return @ptrToInt(&{}) == @ptrToInt(&{});
4022 \\}
4023 , &[_][]const u8{
4024 "tmp.zig:2:23: error: pointer to size 0 type has no address",
4025 });
4026
4027 ctx.objErrStage1("@popCount - non-integer",
4028 \\export fn entry(x: f32) u32 {
4029 \\ return @popCount(f32, x);
4030 \\}
4031 , &[_][]const u8{
4032 "tmp.zig:2:22: error: expected integer type, found 'f32'",
4033 });
4034
4035 {
4036 const case = ctx.obj("wrong same named struct", .{});
4037 case.backend = .stage1;
4038
4039 case.addSourceFile("a.zig",
4040 \\pub const Foo = struct {
4041 \\ x: i32,
4042 \\};
4043 );
4044
4045 case.addSourceFile("b.zig",
4046 \\pub const Foo = struct {
4047 \\ z: f64,
4048 \\};
4049 );
4050
4051 case.addError(
4052 \\const a = @import("a.zig");
4053 \\const b = @import("b.zig");
4054 \\
4055 \\export fn entry() void {
4056 \\ var a1: a.Foo = undefined;
4057 \\ bar(&a1);
4058 \\}
4059 \\
4060 \\fn bar(x: *b.Foo) void {_ = x;}
4061 , &[_][]const u8{
4062 "tmp.zig:6:10: error: expected type '*b.Foo', found '*a.Foo'",
4063 "tmp.zig:6:10: note: pointer type child 'a.Foo' cannot cast into pointer type child 'b.Foo'",
4064 "a.zig:1:17: note: a.Foo declared here",
4065 "b.zig:1:17: note: b.Foo declared here",
4066 });
4067 }
4068
4069 ctx.objErrStage1("@floatToInt comptime safety",
4070 \\comptime {
4071 \\ _ = @floatToInt(i8, @as(f32, -129.1));
4072 \\}
4073 \\comptime {
4074 \\ _ = @floatToInt(u8, @as(f32, -1.1));
4075 \\}
4076 \\comptime {
4077 \\ _ = @floatToInt(u8, @as(f32, 256.1));
4078 \\}
4079 , &[_][]const u8{
4080 "tmp.zig:2:9: error: integer value '-129' cannot be stored in type 'i8'",
4081 "tmp.zig:5:9: error: integer value '-1' cannot be stored in type 'u8'",
4082 "tmp.zig:8:9: error: integer value '256' cannot be stored in type 'u8'",
4083 });
4084
4085 ctx.objErrStage1("use anyopaque as return type of fn ptr",
4086 \\export fn entry() void {
4087 \\ const a: fn () anyopaque = undefined;
4088 \\ _ = a;
4089 \\}
4090 , &[_][]const u8{
4091 "tmp.zig:2:20: error: return type cannot be opaque",
4092 });
4093
4094 ctx.objErrStage1("use implicit casts to assign null to non-nullable pointer",
4095 \\export fn entry() void {
4096 \\ var x: i32 = 1234;
4097 \\ var p: *i32 = &x;
4098 \\ var pp: *?*i32 = &p;
4099 \\ pp.* = null;
4100 \\ var y = p.*;
4101 \\ _ = y;
4102 \\}
4103 , &[_][]const u8{
4104 "tmp.zig:4:23: error: expected type '*?*i32', found '**i32'",
4105 });
4106
4107 ctx.objErrStage1("attempted implicit cast from T to [*]const T",
4108 \\export fn entry() void {
4109 \\ const x: [*]const bool = true;
4110 \\ _ = x;
4111 \\}
4112 , &[_][]const u8{
4113 "tmp.zig:2:30: error: expected type '[*]const bool', found 'bool'",
4114 });
4115
4116 ctx.objErrStage1("dereference unknown length pointer",
4117 \\export fn entry(x: [*]i32) i32 {
4118 \\ return x.*;
4119 \\}
4120 , &[_][]const u8{
4121 "tmp.zig:2:13: error: index syntax required for unknown-length pointer type '[*]i32'",
4122 });
4123
4124 ctx.objErrStage1("field access of unknown length pointer",
4125 \\const Foo = extern struct {
4126 \\ a: i32,
4127 \\};
4128 \\
4129 \\export fn entry(foo: [*]Foo) void {
4130 \\ foo.a += 1;
4131 \\}
4132 , &[_][]const u8{
4133 "tmp.zig:6:8: error: type '[*]Foo' does not support field access",
4134 });
4135
4136 ctx.objErrStage1("unknown length pointer to opaque",
4137 \\export const T = [*]opaque {};
4138 , &[_][]const u8{
4139 "tmp.zig:1:21: error: unknown-length pointer to opaque",
4140 });
4141
4142 ctx.objErrStage1("error when evaluating return type",
4143 \\const Foo = struct {
4144 \\ map: @as(i32, i32),
4145 \\
4146 \\ fn init() Foo {
4147 \\ return undefined;
4148 \\ }
4149 \\};
4150 \\export fn entry() void {
4151 \\ var rule_set = try Foo.init();
4152 \\ _ = rule_set;
4153 \\}
4154 , &[_][]const u8{
4155 "tmp.zig:2:19: error: expected type 'i32', found 'type'",
4156 });
4157
4158 ctx.objErrStage1("slicing single-item pointer",
4159 \\export fn entry(ptr: *i32) void {
4160 \\ const slice = ptr[0..2];
4161 \\ _ = slice;
4162 \\}
4163 , &[_][]const u8{
4164 "tmp.zig:2:22: error: slice of single-item pointer",
4165 });
4166
4167 ctx.objErrStage1("indexing single-item pointer",
4168 \\export fn entry(ptr: *i32) i32 {
4169 \\ return ptr[1];
4170 \\}
4171 , &[_][]const u8{
4172 "tmp.zig:2:15: error: index of single-item pointer",
4173 });
4174
4175 ctx.objErrStage1("nested error set mismatch",
4176 \\const NextError = error{NextError};
4177 \\const OtherError = error{OutOfMemory};
4178 \\
4179 \\export fn entry() void {
4180 \\ const a: ?NextError!i32 = foo();
4181 \\ _ = a;
4182 \\}
4183 \\
4184 \\fn foo() ?OtherError!i32 {
4185 \\ return null;
4186 \\}
4187 , &[_][]const u8{
4188 "tmp.zig:5:34: error: expected type '?NextError!i32', found '?OtherError!i32'",
4189 "tmp.zig:5:34: note: optional type child 'OtherError!i32' cannot cast into optional type child 'NextError!i32'",
4190 "tmp.zig:5:34: note: error set 'OtherError' cannot cast into error set 'NextError'",
4191 "tmp.zig:2:26: note: 'error.OutOfMemory' not a member of destination error set",
4192 });
4193
4194 ctx.objErrStage1("invalid deref on switch target",
4195 \\comptime {
4196 \\ var tile = Tile.Empty;
4197 \\ switch (tile.*) {
4198 \\ Tile.Empty => {},
4199 \\ Tile.Filled => {},
4200 \\ }
4201 \\}
4202 \\const Tile = enum {
4203 \\ Empty,
4204 \\ Filled,
4205 \\};
4206 , &[_][]const u8{
4207 "tmp.zig:3:17: error: attempt to dereference non-pointer type 'Tile'",
4208 });
4209
4210 ctx.objErrStage1("invalid field access in comptime",
4211 \\comptime { var x = doesnt_exist.whatever; _ = x; }
4212 , &[_][]const u8{
4213 "tmp.zig:1:20: error: use of undeclared identifier 'doesnt_exist'",
4214 });
4215
4216 ctx.objErrStage1("suspend inside suspend block",
4217 \\export fn entry() void {
4218 \\ _ = async foo();
4219 \\}
4220 \\fn foo() void {
4221 \\ suspend {
4222 \\ suspend {
4223 \\ }
4224 \\ }
4225 \\}
4226 , &[_][]const u8{
4227 "tmp.zig:6:9: error: cannot suspend inside suspend block",
4228 "tmp.zig:5:5: note: other suspend block here",
4229 });
4230
4231 ctx.objErrStage1("assign inline fn to non-comptime var",
4232 \\export fn entry() void {
4233 \\ var a = b;
4234 \\ _ = a;
4235 \\}
4236 \\fn b() callconv(.Inline) void { }
4237 , &[_][]const u8{
4238 "tmp.zig:2:5: error: functions marked inline must be stored in const or comptime var",
4239 "tmp.zig:5:1: note: declared here",
4240 });
4241
4242 ctx.objErrStage1("wrong type passed to @panic",
4243 \\export fn entry() void {
4244 \\ var e = error.Foo;
4245 \\ @panic(e);
4246 \\}
4247 , &[_][]const u8{
4248 "tmp.zig:3:12: error: expected type '[]const u8', found 'error{Foo}'",
4249 });
4250
4251 ctx.objErrStage1("@tagName used on union with no associated enum tag",
4252 \\const FloatInt = extern union {
4253 \\ Float: f32,
4254 \\ Int: i32,
4255 \\};
4256 \\export fn entry() void {
4257 \\ var fi = FloatInt{.Float = 123.45};
4258 \\ var tagName = @tagName(fi);
4259 \\ _ = tagName;
4260 \\}
4261 , &[_][]const u8{
4262 "tmp.zig:7:19: error: union has no associated enum",
4263 "tmp.zig:1:18: note: declared here",
4264 });
4265
4266 ctx.objErrStage1("returning error from void async function",
4267 \\export fn entry() void {
4268 \\ _ = async amain();
4269 \\}
4270 \\fn amain() callconv(.Async) void {
4271 \\ return error.ShouldBeCompileError;
4272 \\}
4273 , &[_][]const u8{
4274 "tmp.zig:5:17: error: expected type 'void', found 'error{ShouldBeCompileError}'",
4275 });
4276
4277 ctx.objErrStage1("@ptrCast discards const qualifier",
4278 \\export fn entry() void {
4279 \\ const x: i32 = 1234;
4280 \\ const y = @ptrCast(*i32, &x);
4281 \\ _ = y;
4282 \\}
4283 , &[_][]const u8{
4284 "tmp.zig:3:15: error: cast discards const qualifier",
4285 });
4286
4287 ctx.objErrStage1("comptime slice of undefined pointer non-zero len",
4288 \\export fn entry() void {
4289 \\ const slice = @as([*]i32, undefined)[0..1];
4290 \\ _ = slice;
4291 \\}
4292 , &[_][]const u8{
4293 "tmp.zig:2:41: error: non-zero length slice of undefined pointer",
4294 });
4295
4296 ctx.objErrStage1("type checking function pointers",
4297 \\fn a(b: fn (*const u8) void) void {
4298 \\ b('a');
4299 \\}
4300 \\fn c(d: u8) void {_ = d;}
4301 \\export fn entry() void {
4302 \\ a(c);
4303 \\}
4304 , &[_][]const u8{
4305 "tmp.zig:6:7: error: expected type 'fn(*const u8) void', found 'fn(u8) void'",
4306 });
4307
4308 ctx.objErrStage1("no else prong on switch on global error set",
4309 \\export fn entry() void {
4310 \\ foo(error.A);
4311 \\}
4312 \\fn foo(a: anyerror) void {
4313 \\ switch (a) {
4314 \\ error.A => {},
4315 \\ }
4316 \\}
4317 , &[_][]const u8{
4318 "tmp.zig:5:5: error: else prong required when switching on type 'anyerror'",
4319 });
4320
4321 ctx.objErrStage1("error not handled in switch",
4322 \\export fn entry() void {
4323 \\ foo(452) catch |err| switch (err) {
4324 \\ error.Foo => {},
4325 \\ };
4326 \\}
4327 \\fn foo(x: i32) !void {
4328 \\ switch (x) {
4329 \\ 0 ... 10 => return error.Foo,
4330 \\ 11 ... 20 => return error.Bar,
4331 \\ 21 ... 30 => return error.Baz,
4332 \\ else => {},
4333 \\ }
4334 \\}
4335 , &[_][]const u8{
4336 "tmp.zig:2:26: error: error.Baz not handled in switch",
4337 "tmp.zig:2:26: error: error.Bar not handled in switch",
4338 });
4339
4340 ctx.objErrStage1("duplicate error in switch",
4341 \\export fn entry() void {
4342 \\ foo(452) catch |err| switch (err) {
4343 \\ error.Foo => {},
4344 \\ error.Bar => {},
4345 \\ error.Foo => {},
4346 \\ else => {},
4347 \\ };
4348 \\}
4349 \\fn foo(x: i32) !void {
4350 \\ switch (x) {
4351 \\ 0 ... 10 => return error.Foo,
4352 \\ 11 ... 20 => return error.Bar,
4353 \\ else => {},
4354 \\ }
4355 \\}
4356 , &[_][]const u8{
4357 "tmp.zig:5:14: error: duplicate switch value: '@typeInfo(@typeInfo(@TypeOf(foo)).Fn.return_type.?).ErrorUnion.error_set.Foo'",
4358 "tmp.zig:3:14: note: other value here",
4359 });
4360
4361 ctx.objErrStage1("invalid cast from integral type to enum",
4362 \\const E = enum(usize) { One, Two };
4363 \\
4364 \\export fn entry() void {
4365 \\ foo(1);
4366 \\}
4367 \\
4368 \\fn foo(x: usize) void {
4369 \\ switch (x) {
4370 \\ E.One => {},
4371 \\ }
4372 \\}
4373 , &[_][]const u8{
4374 "tmp.zig:9:10: error: expected type 'usize', found 'E'",
4375 });
4376
4377 ctx.objErrStage1("range operator in switch used on error set",
4378 \\export fn entry() void {
4379 \\ try foo(452) catch |err| switch (err) {
4380 \\ error.A ... error.B => {},
4381 \\ else => {},
4382 \\ };
4383 \\}
4384 \\fn foo(x: i32) !void {
4385 \\ switch (x) {
4386 \\ 0 ... 10 => return error.Foo,
4387 \\ 11 ... 20 => return error.Bar,
4388 \\ else => {},
4389 \\ }
4390 \\}
4391 , &[_][]const u8{
4392 "tmp.zig:3:17: error: operator not allowed for errors",
4393 });
4394
4395 ctx.objErrStage1("inferring error set of function pointer",
4396 \\comptime {
4397 \\ const z: ?fn()!void = null;
4398 \\}
4399 , &[_][]const u8{
4400 "tmp.zig:2:19: error: function prototype may not have inferred error set",
4401 });
4402
4403 ctx.objErrStage1("access non-existent member of error set",
4404 \\const Foo = error{A};
4405 \\comptime {
4406 \\ const z = Foo.Bar;
4407 \\ _ = z;
4408 \\}
4409 , &[_][]const u8{
4410 "tmp.zig:3:18: error: no error named 'Bar' in 'Foo'",
4411 });
4412
4413 ctx.objErrStage1("error union operator with non error set LHS",
4414 \\comptime {
4415 \\ const z = i32!i32;
4416 \\ var x: z = undefined;
4417 \\ _ = x;
4418 \\}
4419 , &[_][]const u8{
4420 "tmp.zig:2:15: error: expected error set type, found type 'i32'",
4421 });
4422
4423 ctx.objErrStage1("error equality but sets have no common members",
4424 \\const Set1 = error{A, C};
4425 \\const Set2 = error{B, D};
4426 \\export fn entry() void {
4427 \\ foo(Set1.A);
4428 \\}
4429 \\fn foo(x: Set1) void {
4430 \\ if (x == Set2.B) {
4431 \\
4432 \\ }
4433 \\}
4434 , &[_][]const u8{
4435 "tmp.zig:7:11: error: error sets 'Set1' and 'Set2' have no common errors",
4436 });
4437
4438 ctx.objErrStage1("only equality binary operator allowed for error sets",
4439 \\comptime {
4440 \\ const z = error.A > error.B;
4441 \\ _ = z;
4442 \\}
4443 , &[_][]const u8{
4444 "tmp.zig:2:23: error: operator not allowed for errors",
4445 });
4446
4447 ctx.objErrStage1("explicit error set cast known at comptime violates error sets",
4448 \\const Set1 = error {A, B};
4449 \\const Set2 = error {A, C};
4450 \\comptime {
4451 \\ var x = Set1.B;
4452 \\ var y = @errSetCast(Set2, x);
4453 \\ _ = y;
4454 \\}
4455 , &[_][]const u8{
4456 "tmp.zig:5:13: error: error.B not a member of error set 'Set2'",
4457 });
4458
4459 ctx.objErrStage1("cast error union of global error set to error union of smaller error set",
4460 \\const SmallErrorSet = error{A};
4461 \\export fn entry() void {
4462 \\ var x: SmallErrorSet!i32 = foo();
4463 \\ _ = x;
4464 \\}
4465 \\fn foo() anyerror!i32 {
4466 \\ return error.B;
4467 \\}
4468 , &[_][]const u8{
4469 "tmp.zig:3:35: error: expected type 'SmallErrorSet!i32', found 'anyerror!i32'",
4470 "tmp.zig:3:35: note: error set 'anyerror' cannot cast into error set 'SmallErrorSet'",
4471 "tmp.zig:3:35: note: cannot cast global error set into smaller set",
4472 });
4473
4474 ctx.objErrStage1("cast global error set to error set",
4475 \\const SmallErrorSet = error{A};
4476 \\export fn entry() void {
4477 \\ var x: SmallErrorSet = foo();
4478 \\ _ = x;
4479 \\}
4480 \\fn foo() anyerror {
4481 \\ return error.B;
4482 \\}
4483 , &[_][]const u8{
4484 "tmp.zig:3:31: error: expected type 'SmallErrorSet', found 'anyerror'",
4485 "tmp.zig:3:31: note: cannot cast global error set into smaller set",
4486 });
4487 ctx.objErrStage1("recursive inferred error set",
4488 \\export fn entry() void {
4489 \\ foo() catch unreachable;
4490 \\}
4491 \\fn foo() !void {
4492 \\ try foo();
4493 \\}
4494 , &[_][]const u8{
4495 "tmp.zig:5:5: error: cannot resolve inferred error set '@typeInfo(@typeInfo(@TypeOf(foo)).Fn.return_type.?).ErrorUnion.error_set': function 'foo' not fully analyzed yet",
4496 });
4497
4498 ctx.objErrStage1("implicit cast of error set not a subset",
4499 \\const Set1 = error{A, B};
4500 \\const Set2 = error{A, C};
4501 \\export fn entry() void {
4502 \\ foo(Set1.B);
4503 \\}
4504 \\fn foo(set1: Set1) void {
4505 \\ var x: Set2 = set1;
4506 \\ _ = x;
4507 \\}
4508 , &[_][]const u8{
4509 "tmp.zig:7:19: error: expected type 'Set2', found 'Set1'",
4510 "tmp.zig:1:23: note: 'error.B' not a member of destination error set",
4511 });
4512
4513 ctx.objErrStage1("int to err global invalid number",
4514 \\const Set1 = error{
4515 \\ A,
4516 \\ B,
4517 \\};
4518 \\comptime {
4519 \\ var x: u16 = 3;
4520 \\ var y = @intToError(x);
4521 \\ _ = y;
4522 \\}
4523 , &[_][]const u8{
4524 "tmp.zig:7:13: error: integer value 3 represents no error",
4525 });
4526
4527 ctx.objErrStage1("int to err non global invalid number",
4528 \\const Set1 = error{
4529 \\ A,
4530 \\ B,
4531 \\};
4532 \\const Set2 = error{
4533 \\ A,
4534 \\ C,
4535 \\};
4536 \\comptime {
4537 \\ var x = @errorToInt(Set1.B);
4538 \\ var y = @errSetCast(Set2, @intToError(x));
4539 \\ _ = y;
4540 \\}
4541 , &[_][]const u8{
4542 "tmp.zig:11:13: error: error.B not a member of error set 'Set2'",
4543 });
4544
4545 ctx.objErrStage1("duplicate error value in error set",
4546 \\const Foo = error {
4547 \\ Bar,
4548 \\ Bar,
4549 \\};
4550 \\export fn entry() void {
4551 \\ const a: Foo = undefined;
4552 \\ _ = a;
4553 \\}
4554 , &[_][]const u8{
4555 "tmp.zig:3:5: error: duplicate error set field 'Bar'",
4556 "tmp.zig:2:5: note: previous declaration here",
4557 });
4558
4559 ctx.objErrStage1("cast negative integer literal to usize",
4560 \\export fn entry() void {
4561 \\ const x = @as(usize, -10);
4562 \\ _ = x;
4563 \\}
4564 , &[_][]const u8{
4565 "tmp.zig:2:26: error: cannot cast negative value -10 to unsigned integer type 'usize'",
4566 });
4567
4568 ctx.objErrStage1("use invalid number literal as array index",
4569 \\var v = 25;
4570 \\export fn entry() void {
4571 \\ var arr: [v]u8 = undefined;
4572 \\ _ = arr;
4573 \\}
4574 , &[_][]const u8{
4575 "tmp.zig:1:1: error: unable to infer variable type",
4576 });
4577
4578 ctx.objErrStage1("duplicate struct field",
4579 \\const Foo = struct {
4580 \\ Bar: i32,
4581 \\ Bar: usize,
4582 \\};
4583 \\export fn entry() void {
4584 \\ const a: Foo = undefined;
4585 \\ _ = a;
4586 \\}
4587 , &[_][]const u8{
4588 "tmp.zig:3:5: error: duplicate struct field: 'Bar'",
4589 "tmp.zig:2:5: note: other field here",
4590 });
4591
4592 ctx.objErrStage1("duplicate union field",
4593 \\const Foo = union {
4594 \\ Bar: i32,
4595 \\ Bar: usize,
4596 \\};
4597 \\export fn entry() void {
4598 \\ const a: Foo = undefined;
4599 \\ _ = a;
4600 \\}
4601 , &[_][]const u8{
4602 "tmp.zig:3:5: error: duplicate union field: 'Bar'",
4603 "tmp.zig:2:5: note: other field here",
4604 });
4605
4606 ctx.objErrStage1("duplicate enum field",
4607 \\const Foo = enum {
4608 \\ Bar,
4609 \\ Bar,
4610 \\};
4611 \\
4612 \\export fn entry() void {
4613 \\ const a: Foo = undefined;
4614 \\ _ = a;
4615 \\}
4616 , &[_][]const u8{
4617 "tmp.zig:3:5: error: duplicate enum field: 'Bar'",
4618 "tmp.zig:2:5: note: other field here",
4619 });
4620
4621 ctx.objErrStage1("calling function with naked calling convention",
4622 \\export fn entry() void {
4623 \\ foo();
4624 \\}
4625 \\fn foo() callconv(.Naked) void { }
4626 , &[_][]const u8{
4627 "tmp.zig:2:5: error: unable to call function with naked calling convention",
4628 "tmp.zig:4:1: note: declared here",
4629 });
4630
4631 ctx.objErrStage1("function with invalid return type",
4632 \\export fn foo() boid {}
4633 , &[_][]const u8{
4634 "tmp.zig:1:17: error: use of undeclared identifier 'boid'",
4635 });
4636
4637 ctx.objErrStage1("function with non-extern non-packed enum parameter",
4638 \\const Foo = enum { A, B, C };
4639 \\export fn entry(foo: Foo) void { _ = foo; }
4640 , &[_][]const u8{
4641 "tmp.zig:2:22: error: parameter of type 'Foo' not allowed in function with calling convention 'C'",
4642 });
4643
4644 ctx.objErrStage1("function with non-extern non-packed struct parameter",
4645 \\const Foo = struct {
4646 \\ A: i32,
4647 \\ B: f32,
4648 \\ C: bool,
4649 \\};
4650 \\export fn entry(foo: Foo) void { _ = foo; }
4651 , &[_][]const u8{
4652 "tmp.zig:6:22: error: parameter of type 'Foo' not allowed in function with calling convention 'C'",
4653 });
4654
4655 ctx.objErrStage1("function with non-extern non-packed union parameter",
4656 \\const Foo = union {
4657 \\ A: i32,
4658 \\ B: f32,
4659 \\ C: bool,
4660 \\};
4661 \\export fn entry(foo: Foo) void { _ = foo; }
4662 , &[_][]const u8{
4663 "tmp.zig:6:22: error: parameter of type 'Foo' not allowed in function with calling convention 'C'",
4664 });
4665
4666 ctx.objErrStage1("switch on enum with 1 field with no prongs",
4667 \\const Foo = enum { M };
4668 \\
4669 \\export fn entry() void {
4670 \\ var f = Foo.M;
4671 \\ switch (f) {}
4672 \\}
4673 , &[_][]const u8{
4674 "tmp.zig:5:5: error: enumeration value 'Foo.M' not handled in switch",
4675 });
4676
4677 ctx.objErrStage1("shift by negative comptime integer",
4678 \\comptime {
4679 \\ var a = 1 >> -1;
4680 \\ _ = a;
4681 \\}
4682 , &[_][]const u8{
4683 "tmp.zig:2:18: error: shift by negative value -1",
4684 });
4685
4686 ctx.objErrStage1("@panic called at compile time",
4687 \\export fn entry() void {
4688 \\ comptime {
4689 \\ @panic("aoeu",);
4690 \\ }
4691 \\}
4692 , &[_][]const u8{
4693 "tmp.zig:3:9: error: encountered @panic at compile-time",
4694 });
4695
4696 ctx.objErrStage1("wrong return type for main",
4697 \\pub fn main() f32 { }
4698 , &[_][]const u8{
4699 "error: expected return type of main to be 'void', '!void', 'noreturn', 'u8', or '!u8'",
4700 });
4701
4702 ctx.objErrStage1("double ?? on main return value",
4703 \\pub fn main() ??void {
4704 \\}
4705 , &[_][]const u8{
4706 "error: expected return type of main to be 'void', '!void', 'noreturn', 'u8', or '!u8'",
4707 });
4708
4709 ctx.objErrStage1("bad identifier in function with struct defined inside function which references local const",
4710 \\export fn entry() void {
4711 \\ const BlockKind = u32;
4712 \\
4713 \\ const Block = struct {
4714 \\ kind: BlockKind,
4715 \\ };
4716 \\
4717 \\ bogus;
4718 \\
4719 \\ _ = Block;
4720 \\}
4721 , &[_][]const u8{
4722 "tmp.zig:8:5: error: use of undeclared identifier 'bogus'",
4723 });
4724
4725 ctx.objErrStage1("labeled break not found",
4726 \\export fn entry() void {
4727 \\ blah: while (true) {
4728 \\ while (true) {
4729 \\ break :outer;
4730 \\ }
4731 \\ }
4732 \\}
4733 , &[_][]const u8{
4734 "tmp.zig:4:20: error: label not found: 'outer'",
4735 });
4736
4737 ctx.objErrStage1("labeled continue not found",
4738 \\export fn entry() void {
4739 \\ var i: usize = 0;
4740 \\ blah: while (i < 10) : (i += 1) {
4741 \\ while (true) {
4742 \\ continue :outer;
4743 \\ }
4744 \\ }
4745 \\}
4746 , &[_][]const u8{
4747 "tmp.zig:5:23: error: label not found: 'outer'",
4748 });
4749
4750 ctx.objErrStage1("attempt to use 0 bit type in extern fn",
4751 \\extern fn foo(ptr: fn(*void) callconv(.C) void) void;
4752 \\
4753 \\export fn entry() void {
4754 \\ foo(bar);
4755 \\}
4756 \\
4757 \\fn bar(x: *void) callconv(.C) void { _ = x; }
4758 \\export fn entry2() void {
4759 \\ bar(&{});
4760 \\}
4761 , &[_][]const u8{
4762 "tmp.zig:1:23: error: parameter of type '*void' has 0 bits; not allowed in function with calling convention 'C'",
4763 "tmp.zig:7:11: error: parameter of type '*void' has 0 bits; not allowed in function with calling convention 'C'",
4764 });
4765
4766 ctx.objErrStage1("implicit semicolon - block statement",
4767 \\export fn entry() void {
4768 \\ {}
4769 \\ var good = {};
4770 \\ ({})
4771 \\ var bad = {};
4772 \\}
4773 , &[_][]const u8{
4774 "tmp.zig:4:9: error: expected ';' after statement",
4775 });
4776
4777 ctx.objErrStage1("implicit semicolon - block expr",
4778 \\export fn entry() void {
4779 \\ _ = {};
4780 \\ var good = {};
4781 \\ _ = {}
4782 \\ var bad = {};
4783 \\}
4784 , &[_][]const u8{
4785 "tmp.zig:4:11: error: expected ';' after statement",
4786 });
4787
4788 ctx.objErrStage1("implicit semicolon - comptime statement",
4789 \\export fn entry() void {
4790 \\ comptime {}
4791 \\ var good = {};
4792 \\ comptime ({})
4793 \\ var bad = {};
4794 \\}
4795 , &[_][]const u8{
4796 "tmp.zig:4:18: error: expected ';' after statement",
4797 });
4798
4799 ctx.objErrStage1("implicit semicolon - comptime expression",
4800 \\export fn entry() void {
4801 \\ _ = comptime {};
4802 \\ var good = {};
4803 \\ _ = comptime {}
4804 \\ var bad = {};
4805 \\}
4806 , &[_][]const u8{
4807 "tmp.zig:4:20: error: expected ';' after statement",
4808 });
4809
4810 ctx.objErrStage1("implicit semicolon - defer",
4811 \\export fn entry() void {
4812 \\ defer {}
4813 \\ var good = {};
4814 \\ defer ({})
4815 \\ var bad = {};
4816 \\}
4817 , &[_][]const u8{
4818 "tmp.zig:4:15: error: expected ';' after statement",
4819 });
4820
4821 ctx.objErrStage1("implicit semicolon - if statement",
4822 \\export fn entry() void {
4823 \\ if(true) {}
4824 \\ var good = {};
4825 \\ if(true) ({})
4826 \\ var bad = {};
4827 \\}
4828 , &[_][]const u8{
4829 "tmp.zig:4:18: error: expected ';' or 'else' after statement",
4830 });
4831
4832 ctx.objErrStage1("implicit semicolon - if expression",
4833 \\export fn entry() void {
4834 \\ _ = if(true) {};
4835 \\ var good = {};
4836 \\ _ = if(true) {}
4837 \\ var bad = {};
4838 \\}
4839 , &[_][]const u8{
4840 "tmp.zig:4:20: error: expected ';' after statement",
4841 });
4842
4843 ctx.objErrStage1("implicit semicolon - if-else statement",
4844 \\export fn entry() void {
4845 \\ if(true) {} else {}
4846 \\ var good = {};
4847 \\ if(true) ({}) else ({})
4848 \\ var bad = {};
4849 \\}
4850 , &[_][]const u8{
4851 "tmp.zig:4:28: error: expected ';' after statement",
4852 });
4853
4854 ctx.objErrStage1("implicit semicolon - if-else expression",
4855 \\export fn entry() void {
4856 \\ _ = if(true) {} else {};
4857 \\ var good = {};
4858 \\ _ = if(true) {} else {}
4859 \\ var bad = {};
4860 \\}
4861 , &[_][]const u8{
4862 "tmp.zig:4:28: error: expected ';' after statement",
4863 });
4864
4865 ctx.objErrStage1("implicit semicolon - if-else-if statement",
4866 \\export fn entry() void {
4867 \\ if(true) {} else if(true) {}
4868 \\ var good = {};
4869 \\ if(true) ({}) else if(true) ({})
4870 \\ var bad = {};
4871 \\}
4872 , &[_][]const u8{
4873 "tmp.zig:4:37: error: expected ';' or 'else' after statement",
4874 });
4875
4876 ctx.objErrStage1("implicit semicolon - if-else-if expression",
4877 \\export fn entry() void {
4878 \\ _ = if(true) {} else if(true) {};
4879 \\ var good = {};
4880 \\ _ = if(true) {} else if(true) {}
4881 \\ var bad = {};
4882 \\}
4883 , &[_][]const u8{
4884 "tmp.zig:4:37: error: expected ';' after statement",
4885 });
4886
4887 ctx.objErrStage1("implicit semicolon - if-else-if-else statement",
4888 \\export fn entry() void {
4889 \\ if(true) {} else if(true) {} else {}
4890 \\ var good = {};
4891 \\ if(true) ({}) else if(true) ({}) else ({})
4892 \\ var bad = {};
4893 \\}
4894 , &[_][]const u8{
4895 "tmp.zig:4:47: error: expected ';' after statement",
4896 });
4897
4898 ctx.objErrStage1("implicit semicolon - if-else-if-else expression",
4899 \\export fn entry() void {
4900 \\ _ = if(true) {} else if(true) {} else {};
4901 \\ var good = {};
4902 \\ _ = if(true) {} else if(true) {} else {}
4903 \\ var bad = {};
4904 \\}
4905 , &[_][]const u8{
4906 "tmp.zig:4:45: error: expected ';' after statement",
4907 });
4908
4909 ctx.objErrStage1("implicit semicolon - test statement",
4910 \\export fn entry() void {
4911 \\ if (foo()) |_| {}
4912 \\ var good = {};
4913 \\ if (foo()) |_| ({})
4914 \\ var bad = {};
4915 \\}
4916 , &[_][]const u8{
4917 "tmp.zig:4:24: error: expected ';' or 'else' after statement",
4918 });
4919
4920 ctx.objErrStage1("implicit semicolon - test expression",
4921 \\export fn entry() void {
4922 \\ _ = if (foo()) |_| {};
4923 \\ var good = {};
4924 \\ _ = if (foo()) |_| {}
4925 \\ var bad = {};
4926 \\}
4927 , &[_][]const u8{
4928 "tmp.zig:4:26: error: expected ';' after statement",
4929 });
4930
4931 ctx.objErrStage1("implicit semicolon - while statement",
4932 \\export fn entry() void {
4933 \\ while(true) {}
4934 \\ var good = {};
4935 \\ while(true) 1
4936 \\ var bad = {};
4937 \\}
4938 , &[_][]const u8{
4939 "tmp.zig:4:18: error: expected ';' or 'else' after statement",
4940 });
4941
4942 ctx.objErrStage1("implicit semicolon - while expression",
4943 \\export fn entry() void {
4944 \\ _ = while(true) {};
4945 \\ var good = {};
4946 \\ _ = while(true) {}
4947 \\ var bad = {};
4948 \\}
4949 , &[_][]const u8{
4950 "tmp.zig:4:23: error: expected ';' after statement",
4951 });
4952
4953 ctx.objErrStage1("implicit semicolon - while-continue statement",
4954 \\export fn entry() void {
4955 \\ while(true):({}) {}
4956 \\ var good = {};
4957 \\ while(true):({}) ({})
4958 \\ var bad = {};
4959 \\}
4960 , &[_][]const u8{
4961 "tmp.zig:4:26: error: expected ';' or 'else' after statement",
4962 });
4963
4964 ctx.objErrStage1("implicit semicolon - while-continue expression",
4965 \\export fn entry() void {
4966 \\ _ = while(true):({}) {};
4967 \\ var good = {};
4968 \\ _ = while(true):({}) {}
4969 \\ var bad = {};
4970 \\}
4971 , &[_][]const u8{
4972 "tmp.zig:4:28: error: expected ';' after statement",
4973 });
4974
4975 ctx.objErrStage1("implicit semicolon - for statement",
4976 \\export fn entry() void {
4977 \\ for(foo()) |_| {}
4978 \\ var good = {};
4979 \\ for(foo()) |_| ({})
4980 \\ var bad = {};
4981 \\}
4982 , &[_][]const u8{
4983 "tmp.zig:4:24: error: expected ';' or 'else' after statement",
4984 });
4985
4986 ctx.objErrStage1("implicit semicolon - for expression",
4987 \\export fn entry() void {
4988 \\ _ = for(foo()) |_| {};
4989 \\ var good = {};
4990 \\ _ = for(foo()) |_| {}
4991 \\ var bad = {};
4992 \\}
4993 , &[_][]const u8{
4994 "tmp.zig:4:26: error: expected ';' after statement",
4995 });
4996
4997 ctx.objErrStage1("multiple function definitions",
4998 \\fn a() void {}
4999 \\fn a() void {}
5000 \\export fn entry() void { a(); }
5001 , &[_][]const u8{
5002 "tmp.zig:2:1: error: redeclaration of 'a'",
5003 "tmp.zig:1:1: note: other declaration here",
5004 });
5005
5006 ctx.objErrStage1("unreachable with return",
5007 \\fn a() noreturn {return;}
5008 \\export fn entry() void { a(); }
5009 , &[_][]const u8{
5010 "tmp.zig:1:18: error: expected type 'noreturn', found 'void'",
5011 });
5012
5013 ctx.objErrStage1("control reaches end of non-void function",
5014 \\fn a() i32 {}
5015 \\export fn entry() void { _ = a(); }
5016 , &[_][]const u8{
5017 "tmp.zig:1:12: error: expected type 'i32', found 'void'",
5018 });
5019
5020 ctx.objErrStage1("undefined function call",
5021 \\export fn a() void {
5022 \\ b();
5023 \\}
5024 , &[_][]const u8{
5025 "tmp.zig:2:5: error: use of undeclared identifier 'b'",
5026 });
5027
5028 ctx.objErrStage1("wrong number of arguments",
5029 \\export fn a() void {
5030 \\ c(1);
5031 \\}
5032 \\fn c(d: i32, e: i32, f: i32) void { _ = d; _ = e; _ = f; }
5033 , &[_][]const u8{
5034 "tmp.zig:2:6: error: expected 3 argument(s), found 1",
5035 });
5036
5037 ctx.objErrStage1("invalid type",
5038 \\fn a() bogus {}
5039 \\export fn entry() void { _ = a(); }
5040 , &[_][]const u8{
5041 "tmp.zig:1:8: error: use of undeclared identifier 'bogus'",
5042 });
5043
5044 ctx.objErrStage1("pointer to noreturn",
5045 \\fn a() *noreturn {}
5046 \\export fn entry() void { _ = a(); }
5047 , &[_][]const u8{
5048 "tmp.zig:1:9: error: pointer to noreturn not allowed",
5049 });
5050
5051 ctx.objErrStage1("unreachable code",
5052 \\export fn a() void {
5053 \\ return;
5054 \\ b();
5055 \\}
5056 \\
5057 \\fn b() void {}
5058 , &[_][]const u8{
5059 "tmp.zig:3:6: error: unreachable code",
5060 "tmp.zig:2:5: note: control flow is diverted here",
5061 });
5062
5063 ctx.objErrStage1("unreachable code - nested returns",
5064 \\export fn a() i32 {
5065 \\ return return 1;
5066 \\}
5067 , &[_][]const u8{
5068 "tmp.zig:2:5: error: unreachable code",
5069 "tmp.zig:2:12: note: control flow is diverted here",
5070 });
5071
5072 ctx.objErrStage1("unreachable code - double break",
5073 \\export fn a() void {
5074 \\ const b = blk: {
5075 \\ break :blk break :blk @as(u32, 1);
5076 \\ };
5077 \\}
5078 , &[_][]const u8{
5079 "tmp.zig:3:9: error: unreachable code",
5080 "tmp.zig:3:20: note: control flow is diverted here",
5081 });
5082
5083 ctx.objErrStage1("chained comparison operators",
5084 \\export fn a(value: u32) bool {
5085 \\ return 1 < value < 1000;
5086 \\}
5087 , &[_][]const u8{
5088 "tmp.zig:2:22: error: comparison operators cannot be chained",
5089 });
5090
5091 ctx.objErrStage1("bad import",
5092 \\const bogus = @import("bogus-does-not-exist.zig",);
5093 , &[_][]const u8{
5094 "tmp.zig:1:23: error: unable to load '${DIR}bogus-does-not-exist.zig': FileNotFound",
5095 });
5096
5097 ctx.objErrStage1("undeclared identifier",
5098 \\export fn a() void {
5099 \\ return
5100 \\ b +
5101 \\ c;
5102 \\}
5103 , &[_][]const u8{
5104 "tmp.zig:3:5: error: use of undeclared identifier 'b'",
5105 });
5106
5107 ctx.objErrStage1("parameter redeclaration",
5108 \\fn f(a : i32, a : i32) void {
5109 \\}
5110 \\export fn entry() void { f(1, 2); }
5111 , &[_][]const u8{
5112 "tmp.zig:1:15: error: redeclaration of function parameter 'a'",
5113 "tmp.zig:1:6: note: previous declaration here",
5114 });
5115
5116 ctx.objErrStage1("local variable redeclaration",
5117 \\export fn f() void {
5118 \\ const a : i32 = 0;
5119 \\ var a = 0;
5120 \\}
5121 , &[_][]const u8{
5122 "tmp.zig:3:9: error: redeclaration of local constant 'a'",
5123 "tmp.zig:2:11: note: previous declaration here",
5124 });
5125
5126 ctx.objErrStage1("local variable redeclares parameter",
5127 \\fn f(a : i32) void {
5128 \\ const a = 0;
5129 \\}
5130 \\export fn entry() void { f(1); }
5131 , &[_][]const u8{
5132 "tmp.zig:2:11: error: redeclaration of function parameter 'a'",
5133 "tmp.zig:1:6: note: previous declaration here",
5134 });
5135
5136 ctx.objErrStage1("variable has wrong type",
5137 \\export fn f() i32 {
5138 \\ const a = "a";
5139 \\ return a;
5140 \\}
5141 , &[_][]const u8{
5142 "tmp.zig:3:12: error: expected type 'i32', found '*const [1:0]u8'",
5143 });
5144
5145 ctx.objErrStage1("if condition is bool, not int",
5146 \\export fn f() void {
5147 \\ if (0) {}
5148 \\}
5149 , &[_][]const u8{
5150 "tmp.zig:2:9: error: expected type 'bool', found 'comptime_int'",
5151 });
5152
5153 ctx.objErrStage1("assign unreachable",
5154 \\export fn f() void {
5155 \\ const a = return;
5156 \\}
5157 , &[_][]const u8{
5158 "tmp.zig:2:5: error: unreachable code",
5159 "tmp.zig:2:15: note: control flow is diverted here",
5160 });
5161
5162 ctx.objErrStage1("unreachable variable",
5163 \\export fn f() void {
5164 \\ const a: noreturn = {};
5165 \\ _ = a;
5166 \\}
5167 , &[_][]const u8{
5168 "tmp.zig:2:25: error: expected type 'noreturn', found 'void'",
5169 });
5170
5171 ctx.objErrStage1("unreachable parameter",
5172 \\fn f(a: noreturn) void { _ = a; }
5173 \\export fn entry() void { f(); }
5174 , &[_][]const u8{
5175 "tmp.zig:1:9: error: parameter of type 'noreturn' not allowed",
5176 });
5177
5178 ctx.objErrStage1("assign to constant variable",
5179 \\export fn f() void {
5180 \\ const a = 3;
5181 \\ a = 4;
5182 \\}
5183 , &[_][]const u8{
5184 "tmp.zig:3:9: error: cannot assign to constant",
5185 });
5186
5187 ctx.objErrStage1("use of undeclared identifier",
5188 \\export fn f() void {
5189 \\ b = 3;
5190 \\}
5191 , &[_][]const u8{
5192 "tmp.zig:2:5: error: use of undeclared identifier 'b'",
5193 });
5194
5195 ctx.objErrStage1("const is a statement, not an expression",
5196 \\export fn f() void {
5197 \\ (const a = 0);
5198 \\}
5199 , &[_][]const u8{
5200 "tmp.zig:2:6: error: expected expression, found 'const'",
5201 });
5202
5203 ctx.objErrStage1("array access of undeclared identifier",
5204 \\export fn f() void {
5205 \\ i[i] = i[i];
5206 \\}
5207 , &[_][]const u8{
5208 "tmp.zig:2:5: error: use of undeclared identifier 'i'",
5209 });
5210
5211 ctx.objErrStage1("array access of non array",
5212 \\export fn f() void {
5213 \\ var bad : bool = undefined;
5214 \\ bad[0] = bad[0];
5215 \\}
5216 \\export fn g() void {
5217 \\ var bad : bool = undefined;
5218 \\ _ = bad[0];
5219 \\}
5220 , &[_][]const u8{
5221 "tmp.zig:3:8: error: array access of non-array type 'bool'",
5222 "tmp.zig:7:12: error: array access of non-array type 'bool'",
5223 });
5224
5225 ctx.objErrStage1("array access with non integer index",
5226 \\export fn f() void {
5227 \\ var array = "aoeu";
5228 \\ var bad = false;
5229 \\ array[bad] = array[bad];
5230 \\}
5231 \\export fn g() void {
5232 \\ var array = "aoeu";
5233 \\ var bad = false;
5234 \\ _ = array[bad];
5235 \\}
5236 , &[_][]const u8{
5237 "tmp.zig:4:11: error: expected type 'usize', found 'bool'",
5238 "tmp.zig:9:15: error: expected type 'usize', found 'bool'",
5239 });
5240
5241 ctx.objErrStage1("write to const global variable",
5242 \\const x : i32 = 99;
5243 \\fn f() void {
5244 \\ x = 1;
5245 \\}
5246 \\export fn entry() void { f(); }
5247 , &[_][]const u8{
5248 "tmp.zig:3:9: error: cannot assign to constant",
5249 });
5250
5251 ctx.objErrStage1("missing else clause",
5252 \\fn f(b: bool) void {
5253 \\ const x : i32 = if (b) h: { break :h 1; };
5254 \\ _ = x;
5255 \\}
5256 \\fn g(b: bool) void {
5257 \\ const y = if (b) h: { break :h @as(i32, 1); };
5258 \\ _ = y;
5259 \\}
5260 \\export fn entry() void { f(true); g(true); }
5261 , &[_][]const u8{
5262 "tmp.zig:2:21: error: expected type 'i32', found 'void'",
5263 "tmp.zig:6:15: error: incompatible types: 'i32' and 'void'",
5264 });
5265
5266 ctx.objErrStage1("invalid struct field",
5267 \\const A = struct { x : i32, };
5268 \\export fn f() void {
5269 \\ var a : A = undefined;
5270 \\ a.foo = 1;
5271 \\ const y = a.bar;
5272 \\ _ = y;
5273 \\}
5274 \\export fn g() void {
5275 \\ var a : A = undefined;
5276 \\ const y = a.bar;
5277 \\ _ = y;
5278 \\}
5279 , &[_][]const u8{
5280 "tmp.zig:4:6: error: no member named 'foo' in struct 'A'",
5281 "tmp.zig:10:16: error: no member named 'bar' in struct 'A'",
5282 });
5283
5284 ctx.objErrStage1("redefinition of struct",
5285 \\const A = struct { x : i32, };
5286 \\const A = struct { y : i32, };
5287 , &[_][]const u8{
5288 "tmp.zig:2:1: error: redeclaration of 'A'",
5289 "tmp.zig:1:1: note: other declaration here",
5290 });
5291
5292 ctx.objErrStage1("redefinition of enums",
5293 \\const A = enum {x};
5294 \\const A = enum {x};
5295 , &[_][]const u8{
5296 "tmp.zig:2:1: error: redeclaration of 'A'",
5297 "tmp.zig:1:1: note: other declaration here",
5298 });
5299
5300 ctx.objErrStage1("redefinition of global variables",
5301 \\var a : i32 = 1;
5302 \\var a : i32 = 2;
5303 , &[_][]const u8{
5304 "tmp.zig:2:1: error: redeclaration of 'a'",
5305 "tmp.zig:1:1: note: other declaration here",
5306 });
5307
5308 ctx.objErrStage1("duplicate field in struct value expression",
5309 \\const A = struct {
5310 \\ x : i32,
5311 \\ y : i32,
5312 \\ z : i32,
5313 \\};
5314 \\export fn f() void {
5315 \\ const a = A {
5316 \\ .z = 1,
5317 \\ .y = 2,
5318 \\ .x = 3,
5319 \\ .z = 4,
5320 \\ };
5321 \\ _ = a;
5322 \\}
5323 , &[_][]const u8{
5324 "tmp.zig:11:9: error: duplicate field",
5325 });
5326
5327 ctx.objErrStage1("missing field in struct value expression",
5328 \\const A = struct {
5329 \\ x : i32,
5330 \\ y : i32,
5331 \\ z : i32,
5332 \\};
5333 \\export fn f() void {
5334 \\ // we want the error on the '{' not the 'A' because
5335 \\ // the A could be a complicated expression
5336 \\ const a = A {
5337 \\ .z = 4,
5338 \\ .y = 2,
5339 \\ };
5340 \\ _ = a;
5341 \\}
5342 , &[_][]const u8{
5343 "tmp.zig:9:17: error: missing field: 'x'",
5344 });
5345
5346 ctx.objErrStage1("invalid field in struct value expression",
5347 \\const A = struct {
5348 \\ x : i32,
5349 \\ y : i32,
5350 \\ z : i32,
5351 \\};
5352 \\export fn f() void {
5353 \\ const a = A {
5354 \\ .z = 4,
5355 \\ .y = 2,
5356 \\ .foo = 42,
5357 \\ };
5358 \\ _ = a;
5359 \\}
5360 , &[_][]const u8{
5361 "tmp.zig:10:9: error: no member named 'foo' in struct 'A'",
5362 });
5363
5364 ctx.objErrStage1("invalid break expression",
5365 \\export fn f() void {
5366 \\ break;
5367 \\}
5368 , &[_][]const u8{
5369 "tmp.zig:2:5: error: break expression outside loop",
5370 });
5371
5372 ctx.objErrStage1("invalid continue expression",
5373 \\export fn f() void {
5374 \\ continue;
5375 \\}
5376 , &[_][]const u8{
5377 "tmp.zig:2:5: error: continue expression outside loop",
5378 });
5379
5380 ctx.objErrStage1("invalid maybe type",
5381 \\export fn f() void {
5382 \\ if (true) |x| { _ = x; }
5383 \\}
5384 , &[_][]const u8{
5385 "tmp.zig:2:9: error: expected optional type, found 'bool'",
5386 });
5387
5388 ctx.objErrStage1("cast unreachable",
5389 \\fn f() i32 {
5390 \\ return @as(i32, return 1);
5391 \\}
5392 \\export fn entry() void { _ = f(); }
5393 , &[_][]const u8{
5394 "tmp.zig:2:12: error: unreachable code",
5395 "tmp.zig:2:21: note: control flow is diverted here",
5396 });
5397
5398 ctx.objErrStage1("invalid builtin fn",
5399 \\fn f() @bogus(foo) {
5400 \\}
5401 \\export fn entry() void { _ = f(); }
5402 , &[_][]const u8{
5403 "tmp.zig:1:8: error: invalid builtin function: '@bogus'",
5404 });
5405
5406 ctx.objErrStage1("noalias on non pointer param",
5407 \\fn f(noalias x: i32) void { _ = x; }
5408 \\export fn entry() void { f(1234); }
5409 , &[_][]const u8{
5410 "tmp.zig:1:6: error: noalias on non-pointer parameter",
5411 });
5412
5413 ctx.objErrStage1("struct init syntax for array",
5414 \\const foo = [3]u16{ .x = 1024 };
5415 \\comptime {
5416 \\ _ = foo;
5417 \\}
5418 , &[_][]const u8{
5419 "tmp.zig:1:13: error: initializing array with struct syntax",
5420 });
5421
5422 ctx.objErrStage1("type variables must be constant",
5423 \\var foo = u8;
5424 \\export fn entry() foo {
5425 \\ return 1;
5426 \\}
5427 , &[_][]const u8{
5428 "tmp.zig:1:1: error: variable of type 'type' must be constant",
5429 });
5430
5431 ctx.objErrStage1("parameter shadowing global",
5432 \\const Foo = struct {};
5433 \\fn f(Foo: i32) void {}
5434 \\export fn entry() void {
5435 \\ f(1234);
5436 \\}
5437 , &[_][]const u8{
5438 "tmp.zig:2:6: error: local shadows declaration of 'Foo'",
5439 "tmp.zig:1:1: note: declared here",
5440 });
5441
5442 ctx.objErrStage1("local variable shadowing global",
5443 \\const Foo = struct {};
5444 \\const Bar = struct {};
5445 \\
5446 \\export fn entry() void {
5447 \\ var Bar : i32 = undefined;
5448 \\ _ = Bar;
5449 \\}
5450 , &[_][]const u8{
5451 "tmp.zig:5:9: error: local shadows declaration of 'Bar'",
5452 "tmp.zig:2:1: note: declared here",
5453 });
5454
5455 ctx.objErrStage1("local shadows global that occurs later",
5456 \\pub fn main() void {
5457 \\ var foo = true;
5458 \\ _ = foo;
5459 \\}
5460 \\fn foo() void {}
5461 , &[_][]const u8{
5462 "tmp.zig:2:9: error: local shadows declaration of 'foo'",
5463 "tmp.zig:5:1: note: declared here",
5464 });
5465
5466 ctx.objErrStage1("switch expression - missing enumeration prong",
5467 \\const Number = enum {
5468 \\ One,
5469 \\ Two,
5470 \\ Three,
5471 \\ Four,
5472 \\};
5473 \\fn f(n: Number) i32 {
5474 \\ switch (n) {
5475 \\ Number.One => 1,
5476 \\ Number.Two => 2,
5477 \\ Number.Three => @as(i32, 3),
5478 \\ }
5479 \\}
5480 \\
5481 \\export fn entry() usize { return @sizeOf(@TypeOf(f)); }
5482 , &[_][]const u8{
5483 "tmp.zig:8:5: error: enumeration value 'Number.Four' not handled in switch",
5484 });
5485
5486 ctx.objErrStage1("switch expression - duplicate enumeration prong",
5487 \\const Number = enum {
5488 \\ One,
5489 \\ Two,
5490 \\ Three,
5491 \\ Four,
5492 \\};
5493 \\fn f(n: Number) i32 {
5494 \\ switch (n) {
5495 \\ Number.One => 1,
5496 \\ Number.Two => 2,
5497 \\ Number.Three => @as(i32, 3),
5498 \\ Number.Four => 4,
5499 \\ Number.Two => 2,
5500 \\ }
5501 \\}
5502 \\
5503 \\export fn entry() usize { return @sizeOf(@TypeOf(f)); }
5504 , &[_][]const u8{
5505 "tmp.zig:13:15: error: duplicate switch value",
5506 "tmp.zig:10:15: note: other value here",
5507 });
5508
5509 ctx.objErrStage1("switch expression - duplicate enumeration prong when else present",
5510 \\const Number = enum {
5511 \\ One,
5512 \\ Two,
5513 \\ Three,
5514 \\ Four,
5515 \\};
5516 \\fn f(n: Number) i32 {
5517 \\ switch (n) {
5518 \\ Number.One => 1,
5519 \\ Number.Two => 2,
5520 \\ Number.Three => @as(i32, 3),
5521 \\ Number.Four => 4,
5522 \\ Number.Two => 2,
5523 \\ else => 10,
5524 \\ }
5525 \\}
5526 \\
5527 \\export fn entry() usize { return @sizeOf(@TypeOf(f)); }
5528 , &[_][]const u8{
5529 "tmp.zig:13:15: error: duplicate switch value",
5530 "tmp.zig:10:15: note: other value here",
5531 });
5532
5533 ctx.objErrStage1("switch expression - multiple else prongs",
5534 \\fn f(x: u32) void {
5535 \\ const value: bool = switch (x) {
5536 \\ 1234 => false,
5537 \\ else => true,
5538 \\ else => true,
5539 \\ };
5540 \\}
5541 \\export fn entry() void {
5542 \\ f(1234);
5543 \\}
5544 , &[_][]const u8{
5545 "tmp.zig:5:9: error: multiple else prongs in switch expression",
5546 });
5547
5548 ctx.objErrStage1("switch expression - non exhaustive integer prongs",
5549 \\fn foo(x: u8) void {
5550 \\ switch (x) {
5551 \\ 0 => {},
5552 \\ }
5553 \\}
5554 \\export fn entry() usize { return @sizeOf(@TypeOf(foo)); }
5555 , &[_][]const u8{
5556 "tmp.zig:2:5: error: switch must handle all possibilities",
5557 });
5558
5559 ctx.objErrStage1("switch expression - duplicate or overlapping integer value",
5560 \\fn foo(x: u8) u8 {
5561 \\ return switch (x) {
5562 \\ 0 ... 100 => @as(u8, 0),
5563 \\ 101 ... 200 => 1,
5564 \\ 201, 203 ... 207 => 2,
5565 \\ 206 ... 255 => 3,
5566 \\ };
5567 \\}
5568 \\export fn entry() usize { return @sizeOf(@TypeOf(foo)); }
5569 , &[_][]const u8{
5570 "tmp.zig:6:9: error: duplicate switch value",
5571 "tmp.zig:5:14: note: previous value here",
5572 });
5573
5574 ctx.objErrStage1("switch expression - duplicate type",
5575 \\fn foo(comptime T: type, x: T) u8 {
5576 \\ _ = x;
5577 \\ return switch (T) {
5578 \\ u32 => 0,
5579 \\ u64 => 1,
5580 \\ u32 => 2,
5581 \\ else => 3,
5582 \\ };
5583 \\}
5584 \\export fn entry() usize { return @sizeOf(@TypeOf(foo(u32, 0))); }
5585 , &[_][]const u8{
5586 "tmp.zig:6:9: error: duplicate switch value",
5587 "tmp.zig:4:9: note: previous value here",
5588 });
5589
5590 ctx.objErrStage1("switch expression - duplicate type (struct alias)",
5591 \\const Test = struct {
5592 \\ bar: i32,
5593 \\};
5594 \\const Test2 = Test;
5595 \\fn foo(comptime T: type, x: T) u8 {
5596 \\ _ = x;
5597 \\ return switch (T) {
5598 \\ Test => 0,
5599 \\ u64 => 1,
5600 \\ Test2 => 2,
5601 \\ else => 3,
5602 \\ };
5603 \\}
5604 \\export fn entry() usize { return @sizeOf(@TypeOf(foo(u32, 0))); }
5605 , &[_][]const u8{
5606 "tmp.zig:10:9: error: duplicate switch value",
5607 "tmp.zig:8:9: note: previous value here",
5608 });
5609
5610 ctx.objErrStage1("switch expression - switch on pointer type with no else",
5611 \\fn foo(x: *u8) void {
5612 \\ switch (x) {
5613 \\ &y => {},
5614 \\ }
5615 \\}
5616 \\const y: u8 = 100;
5617 \\export fn entry() usize { return @sizeOf(@TypeOf(foo)); }
5618 , &[_][]const u8{
5619 "tmp.zig:2:5: error: else prong required when switching on type '*u8'",
5620 });
5621
5622 ctx.objErrStage1("global variable initializer must be constant expression",
5623 \\extern fn foo() i32;
5624 \\const x = foo();
5625 \\export fn entry() i32 { return x; }
5626 , &[_][]const u8{
5627 "tmp.zig:2:11: error: unable to evaluate constant expression",
5628 });
5629
5630 ctx.objErrStage1("array concatenation with wrong type",
5631 \\const src = "aoeu";
5632 \\const derp: usize = 1234;
5633 \\const a = derp ++ "foo";
5634 \\
5635 \\export fn entry() usize { return @sizeOf(@TypeOf(a)); }
5636 , &[_][]const u8{
5637 "tmp.zig:3:11: error: expected array, found 'usize'",
5638 });
5639
5640 ctx.objErrStage1("non compile time array concatenation",
5641 \\fn f() []u8 {
5642 \\ return s ++ "foo";
5643 \\}
5644 \\var s: [10]u8 = undefined;
5645 \\export fn entry() usize { return @sizeOf(@TypeOf(f)); }
5646 , &[_][]const u8{
5647 "tmp.zig:2:12: error: unable to evaluate constant expression",
5648 });
5649
5650 ctx.objErrStage1("@cImport with bogus include",
5651 \\const c = @cImport(@cInclude("bogus.h"));
5652 \\export fn entry() usize { return @sizeOf(@TypeOf(c.bogo)); }
5653 , &[_][]const u8{
5654 "tmp.zig:1:11: error: C import failed",
5655 ".h:1:10: note: 'bogus.h' file not found",
5656 });
5657
5658 ctx.objErrStage1("address of number literal",
5659 \\const x = 3;
5660 \\const y = &x;
5661 \\fn foo() *const i32 { return y; }
5662 \\export fn entry() usize { return @sizeOf(@TypeOf(foo)); }
5663 , &[_][]const u8{
5664 "tmp.zig:3:30: error: expected type '*const i32', found '*const comptime_int'",
5665 });
5666
5667 ctx.objErrStage1("integer overflow error",
5668 \\const x : u8 = 300;
5669 \\export fn entry() usize { return @sizeOf(@TypeOf(x)); }
5670 , &[_][]const u8{
5671 "tmp.zig:1:16: error: integer value 300 cannot be coerced to type 'u8'",
5672 });
5673
5674 ctx.objErrStage1("invalid shift amount error",
5675 \\const x : u8 = 2;
5676 \\fn f() u16 {
5677 \\ return x << 8;
5678 \\}
5679 \\export fn entry() u16 { return f(); }
5680 , &[_][]const u8{
5681 "tmp.zig:3:17: error: integer value 8 cannot be coerced to type 'u3'",
5682 });
5683
5684 ctx.objErrStage1("missing function call param",
5685 \\const Foo = struct {
5686 \\ a: i32,
5687 \\ b: i32,
5688 \\
5689 \\ fn member_a(foo: *const Foo) i32 {
5690 \\ return foo.a;
5691 \\ }
5692 \\ fn member_b(foo: *const Foo) i32 {
5693 \\ return foo.b;
5694 \\ }
5695 \\};
5696 \\
5697 \\const member_fn_type = @TypeOf(Foo.member_a);
5698 \\const members = [_]member_fn_type {
5699 \\ Foo.member_a,
5700 \\ Foo.member_b,
5701 \\};
5702 \\
5703 \\fn f(foo: *const Foo, index: usize) void {
5704 \\ const result = members[index]();
5705 \\ _ = foo;
5706 \\ _ = result;
5707 \\}
5708 \\
5709 \\export fn entry() usize { return @sizeOf(@TypeOf(f)); }
5710 , &[_][]const u8{
5711 "tmp.zig:20:34: error: expected 1 argument(s), found 0",
5712 });
5713
5714 ctx.objErrStage1("missing function name",
5715 \\fn () void {}
5716 \\export fn entry() usize { return @sizeOf(@TypeOf(f)); }
5717 , &[_][]const u8{
5718 "tmp.zig:1:1: error: missing function name",
5719 });
5720
5721 ctx.objErrStage1("missing param name",
5722 \\fn f(i32) void {}
5723 \\export fn entry() usize { return @sizeOf(@TypeOf(f)); }
5724 , &[_][]const u8{
5725 "tmp.zig:1:6: error: missing parameter name",
5726 });
5727
5728 ctx.objErrStage1("wrong function type",
5729 \\const fns = [_]fn() void { a, b, c };
5730 \\fn a() i32 {return 0;}
5731 \\fn b() i32 {return 1;}
5732 \\fn c() i32 {return 2;}
5733 \\export fn entry() usize { return @sizeOf(@TypeOf(fns)); }
5734 , &[_][]const u8{
5735 "tmp.zig:1:28: error: expected type 'fn() void', found 'fn() i32'",
5736 });
5737
5738 ctx.objErrStage1("extern function pointer mismatch",
5739 \\const fns = [_](fn(i32)i32) { a, b, c };
5740 \\pub fn a(x: i32) i32 {return x + 0;}
5741 \\pub fn b(x: i32) i32 {return x + 1;}
5742 \\export fn c(x: i32) i32 {return x + 2;}
5743 \\
5744 \\export fn entry() usize { return @sizeOf(@TypeOf(fns)); }
5745 , &[_][]const u8{
5746 "tmp.zig:1:37: error: expected type 'fn(i32) i32', found 'fn(i32) callconv(.C) i32'",
5747 });
5748
5749 ctx.objErrStage1("colliding invalid top level functions",
5750 \\fn func() bogus {}
5751 \\fn func() bogus {}
5752 \\export fn entry() usize { return @sizeOf(@TypeOf(func)); }
5753 , &[_][]const u8{
5754 "tmp.zig:2:1: error: redeclaration of 'func'",
5755 "tmp.zig:1:1: note: other declaration here",
5756 });
5757
5758 ctx.objErrStage1("non constant expression in array size",
5759 \\const Foo = struct {
5760 \\ y: [get()]u8,
5761 \\};
5762 \\var global_var: usize = 1;
5763 \\fn get() usize { return global_var; }
5764 \\
5765 \\export fn entry() usize { return @sizeOf(@TypeOf(Foo)); }
5766 , &[_][]const u8{
5767 "tmp.zig:5:25: error: cannot store runtime value in compile time variable",
5768 "tmp.zig:2:12: note: called from here",
5769 });
5770
5771 ctx.objErrStage1("addition with non numbers",
5772 \\const Foo = struct {
5773 \\ field: i32,
5774 \\};
5775 \\const x = Foo {.field = 1} + Foo {.field = 2};
5776 \\
5777 \\export fn entry() usize { return @sizeOf(@TypeOf(x)); }
5778 , &[_][]const u8{
5779 "tmp.zig:4:28: error: invalid operands to binary expression: 'Foo' and 'Foo'",
5780 });
5781
5782 ctx.objErrStage1("division by zero",
5783 \\const lit_int_x = 1 / 0;
5784 \\const lit_float_x = 1.0 / 0.0;
5785 \\const int_x = @as(u32, 1) / @as(u32, 0);
5786 \\const float_x = @as(f32, 1.0) / @as(f32, 0.0);
5787 \\
5788 \\export fn entry1() usize { return @sizeOf(@TypeOf(lit_int_x)); }
5789 \\export fn entry2() usize { return @sizeOf(@TypeOf(lit_float_x)); }
5790 \\export fn entry3() usize { return @sizeOf(@TypeOf(int_x)); }
5791 \\export fn entry4() usize { return @sizeOf(@TypeOf(float_x)); }
5792 , &[_][]const u8{
5793 "tmp.zig:1:21: error: division by zero",
5794 "tmp.zig:2:25: error: division by zero",
5795 "tmp.zig:3:27: error: division by zero",
5796 "tmp.zig:4:31: error: division by zero",
5797 });
5798
5799 ctx.objErrStage1("normal string with newline",
5800 \\const foo = "a
5801 \\b";
5802 , &[_][]const u8{
5803 "tmp.zig:1:13: error: expected expression, found 'invalid bytes'",
5804 "tmp.zig:1:15: note: invalid byte: '\\n'",
5805 });
5806
5807 ctx.objErrStage1("invalid comparison for function pointers",
5808 \\fn foo() void {}
5809 \\const invalid = foo > foo;
5810 \\
5811 \\export fn entry() usize { return @sizeOf(@TypeOf(invalid)); }
5812 , &[_][]const u8{
5813 "tmp.zig:2:21: error: operator not allowed for type 'fn() void'",
5814 });
5815
5816 ctx.objErrStage1("generic function instance with non-constant expression",
5817 \\fn foo(comptime x: i32, y: i32) i32 { return x + y; }
5818 \\fn test1(a: i32, b: i32) i32 {
5819 \\ return foo(a, b);
5820 \\}
5821 \\
5822 \\export fn entry() usize { return @sizeOf(@TypeOf(test1)); }
5823 , &[_][]const u8{
5824 "tmp.zig:3:16: error: runtime value cannot be passed to comptime arg",
5825 });
5826
5827 ctx.objErrStage1("assign null to non-optional pointer",
5828 \\const a: *u8 = null;
5829 \\
5830 \\export fn entry() usize { return @sizeOf(@TypeOf(a)); }
5831 , &[_][]const u8{
5832 "tmp.zig:1:16: error: expected type '*u8', found '@Type(.Null)'",
5833 });
5834
5835 ctx.objErrStage1("indexing an array of size zero",
5836 \\const array = [_]u8{};
5837 \\export fn foo() void {
5838 \\ const pointer = &array[0];
5839 \\ _ = pointer;
5840 \\}
5841 , &[_][]const u8{
5842 "tmp.zig:3:27: error: accessing a zero length array is not allowed",
5843 });
5844
5845 ctx.objErrStage1("indexing an array of size zero with runtime index",
5846 \\const array = [_]u8{};
5847 \\export fn foo() void {
5848 \\ var index: usize = 0;
5849 \\ const pointer = &array[index];
5850 \\ _ = pointer;
5851 \\}
5852 , &[_][]const u8{
5853 "tmp.zig:4:27: error: accessing a zero length array is not allowed",
5854 });
5855
5856 ctx.objErrStage1("compile time division by zero",
5857 \\const y = foo(0);
5858 \\fn foo(x: u32) u32 {
5859 \\ return 1 / x;
5860 \\}
5861 \\
5862 \\export fn entry() usize { return @sizeOf(@TypeOf(y)); }
5863 , &[_][]const u8{
5864 "tmp.zig:3:14: error: division by zero",
5865 });
5866
5867 ctx.objErrStage1("branch on undefined value",
5868 \\const x = if (undefined) true else false;
5869 \\
5870 \\export fn entry() usize { return @sizeOf(@TypeOf(x)); }
5871 , &[_][]const u8{
5872 "tmp.zig:1:15: error: use of undefined value here causes undefined behavior",
5873 });
5874
5875 ctx.objErrStage1("div on undefined value",
5876 \\comptime {
5877 \\ var a: i64 = undefined;
5878 \\ _ = a / a;
5879 \\}
5880 , &[_][]const u8{
5881 "tmp.zig:3:9: error: use of undefined value here causes undefined behavior",
5882 });
5883
5884 ctx.objErrStage1("div assign on undefined value",
5885 \\comptime {
5886 \\ var a: i64 = undefined;
5887 \\ a /= a;
5888 \\}
5889 , &[_][]const u8{
5890 "tmp.zig:3:5: error: use of undefined value here causes undefined behavior",
5891 });
5892
5893 ctx.objErrStage1("mod on undefined value",
5894 \\comptime {
5895 \\ var a: i64 = undefined;
5896 \\ _ = a % a;
5897 \\}
5898 , &[_][]const u8{
5899 "tmp.zig:3:9: error: use of undefined value here causes undefined behavior",
5900 });
5901
5902 ctx.objErrStage1("mod assign on undefined value",
5903 \\comptime {
5904 \\ var a: i64 = undefined;
5905 \\ a %= a;
5906 \\}
5907 , &[_][]const u8{
5908 "tmp.zig:3:5: error: use of undefined value here causes undefined behavior",
5909 });
5910
5911 ctx.objErrStage1("add on undefined value",
5912 \\comptime {
5913 \\ var a: i64 = undefined;
5914 \\ _ = a + a;
5915 \\}
5916 , &[_][]const u8{
5917 "tmp.zig:3:9: error: use of undefined value here causes undefined behavior",
5918 });
5919
5920 ctx.objErrStage1("add assign on undefined value",
5921 \\comptime {
5922 \\ var a: i64 = undefined;
5923 \\ a += a;
5924 \\}
5925 , &[_][]const u8{
5926 "tmp.zig:3:5: error: use of undefined value here causes undefined behavior",
5927 });
5928
5929 ctx.objErrStage1("add wrap on undefined value",
5930 \\comptime {
5931 \\ var a: i64 = undefined;
5932 \\ _ = a +% a;
5933 \\}
5934 , &[_][]const u8{
5935 "tmp.zig:3:9: error: use of undefined value here causes undefined behavior",
5936 });
5937
5938 ctx.objErrStage1("add wrap assign on undefined value",
5939 \\comptime {
5940 \\ var a: i64 = undefined;
5941 \\ a +%= a;
5942 \\}
5943 , &[_][]const u8{
5944 "tmp.zig:3:5: error: use of undefined value here causes undefined behavior",
5945 });
5946
5947 ctx.objErrStage1("sub on undefined value",
5948 \\comptime {
5949 \\ var a: i64 = undefined;
5950 \\ _ = a - a;
5951 \\}
5952 , &[_][]const u8{
5953 "tmp.zig:3:9: error: use of undefined value here causes undefined behavior",
5954 });
5955
5956 ctx.objErrStage1("sub assign on undefined value",
5957 \\comptime {
5958 \\ var a: i64 = undefined;
5959 \\ a -= a;
5960 \\}
5961 , &[_][]const u8{
5962 "tmp.zig:3:5: error: use of undefined value here causes undefined behavior",
5963 });
5964
5965 ctx.objErrStage1("sub wrap on undefined value",
5966 \\comptime {
5967 \\ var a: i64 = undefined;
5968 \\ _ = a -% a;
5969 \\}
5970 , &[_][]const u8{
5971 "tmp.zig:3:9: error: use of undefined value here causes undefined behavior",
5972 });
5973
5974 ctx.objErrStage1("sub wrap assign on undefined value",
5975 \\comptime {
5976 \\ var a: i64 = undefined;
5977 \\ a -%= a;
5978 \\}
5979 , &[_][]const u8{
5980 "tmp.zig:3:5: error: use of undefined value here causes undefined behavior",
5981 });
5982
5983 ctx.objErrStage1("mult on undefined value",
5984 \\comptime {
5985 \\ var a: i64 = undefined;
5986 \\ _ = a * a;
5987 \\}
5988 , &[_][]const u8{
5989 "tmp.zig:3:9: error: use of undefined value here causes undefined behavior",
5990 });
5991
5992 ctx.objErrStage1("mult assign on undefined value",
5993 \\comptime {
5994 \\ var a: i64 = undefined;
5995 \\ a *= a;
5996 \\}
5997 , &[_][]const u8{
5998 "tmp.zig:3:5: error: use of undefined value here causes undefined behavior",
5999 });
6000
6001 ctx.objErrStage1("mult wrap on undefined value",
6002 \\comptime {
6003 \\ var a: i64 = undefined;
6004 \\ _ = a *% a;
6005 \\}
6006 , &[_][]const u8{
6007 "tmp.zig:3:9: error: use of undefined value here causes undefined behavior",
6008 });
6009
6010 ctx.objErrStage1("mult wrap assign on undefined value",
6011 \\comptime {
6012 \\ var a: i64 = undefined;
6013 \\ a *%= a;
6014 \\}
6015 , &[_][]const u8{
6016 "tmp.zig:3:5: error: use of undefined value here causes undefined behavior",
6017 });
6018
6019 ctx.objErrStage1("shift left on undefined value",
6020 \\comptime {
6021 \\ var a: i64 = undefined;
6022 \\ _ = a << 2;
6023 \\}
6024 , &[_][]const u8{
6025 "tmp.zig:3:9: error: use of undefined value here causes undefined behavior",
6026 });
6027
6028 ctx.objErrStage1("shift left assign on undefined value",
6029 \\comptime {
6030 \\ var a: i64 = undefined;
6031 \\ a <<= 2;
6032 \\}
6033 , &[_][]const u8{
6034 "tmp.zig:3:5: error: use of undefined value here causes undefined behavior",
6035 });
6036
6037 ctx.objErrStage1("shift right on undefined value",
6038 \\comptime {
6039 \\ var a: i64 = undefined;
6040 \\ _ = a >> 2;
6041 \\}
6042 , &[_][]const u8{
6043 "tmp.zig:3:9: error: use of undefined value here causes undefined behavior",
6044 });
6045
6046 ctx.objErrStage1("shift left assign on undefined value",
6047 \\comptime {
6048 \\ var a: i64 = undefined;
6049 \\ a >>= 2;
6050 \\}
6051 , &[_][]const u8{
6052 "tmp.zig:3:5: error: use of undefined value here causes undefined behavior",
6053 });
6054
6055 ctx.objErrStage1("bin and on undefined value",
6056 \\comptime {
6057 \\ var a: i64 = undefined;
6058 \\ _ = a & a;
6059 \\}
6060 , &[_][]const u8{
6061 "tmp.zig:3:9: error: use of undefined value here causes undefined behavior",
6062 });
6063
6064 ctx.objErrStage1("bin and assign on undefined value",
6065 \\comptime {
6066 \\ var a: i64 = undefined;
6067 \\ a &= a;
6068 \\}
6069 , &[_][]const u8{
6070 "tmp.zig:3:5: error: use of undefined value here causes undefined behavior",
6071 });
6072
6073 ctx.objErrStage1("bin or on undefined value",
6074 \\comptime {
6075 \\ var a: i64 = undefined;
6076 \\ _ = a | a;
6077 \\}
6078 , &[_][]const u8{
6079 "tmp.zig:3:9: error: use of undefined value here causes undefined behavior",
6080 });
6081
6082 ctx.objErrStage1("bin or assign on undefined value",
6083 \\comptime {
6084 \\ var a: i64 = undefined;
6085 \\ a |= a;
6086 \\}
6087 , &[_][]const u8{
6088 "tmp.zig:3:5: error: use of undefined value here causes undefined behavior",
6089 });
6090
6091 ctx.objErrStage1("bin xor on undefined value",
6092 \\comptime {
6093 \\ var a: i64 = undefined;
6094 \\ _ = a ^ a;
6095 \\}
6096 , &[_][]const u8{
6097 "tmp.zig:3:9: error: use of undefined value here causes undefined behavior",
6098 });
6099
6100 ctx.objErrStage1("bin xor assign on undefined value",
6101 \\comptime {
6102 \\ var a: i64 = undefined;
6103 \\ a ^= a;
6104 \\}
6105 , &[_][]const u8{
6106 "tmp.zig:3:5: error: use of undefined value here causes undefined behavior",
6107 });
6108
6109 ctx.objErrStage1("comparison operators with undefined value",
6110 \\// operator ==
6111 \\comptime {
6112 \\ var a: i64 = undefined;
6113 \\ var x: i32 = 0;
6114 \\ if (a == a) x += 1;
6115 \\}
6116 \\// operator !=
6117 \\comptime {
6118 \\ var a: i64 = undefined;
6119 \\ var x: i32 = 0;
6120 \\ if (a != a) x += 1;
6121 \\}
6122 \\// operator >
6123 \\comptime {
6124 \\ var a: i64 = undefined;
6125 \\ var x: i32 = 0;
6126 \\ if (a > a) x += 1;
6127 \\}
6128 \\// operator <
6129 \\comptime {
6130 \\ var a: i64 = undefined;
6131 \\ var x: i32 = 0;
6132 \\ if (a < a) x += 1;
6133 \\}
6134 \\// operator >=
6135 \\comptime {
6136 \\ var a: i64 = undefined;
6137 \\ var x: i32 = 0;
6138 \\ if (a >= a) x += 1;
6139 \\}
6140 \\// operator <=
6141 \\comptime {
6142 \\ var a: i64 = undefined;
6143 \\ var x: i32 = 0;
6144 \\ if (a <= a) x += 1;
6145 \\}
6146 , &[_][]const u8{
6147 "tmp.zig:5:11: error: use of undefined value here causes undefined behavior",
6148 "tmp.zig:11:11: error: use of undefined value here causes undefined behavior",
6149 "tmp.zig:17:11: error: use of undefined value here causes undefined behavior",
6150 "tmp.zig:23:11: error: use of undefined value here causes undefined behavior",
6151 "tmp.zig:29:11: error: use of undefined value here causes undefined behavior",
6152 "tmp.zig:35:11: error: use of undefined value here causes undefined behavior",
6153 });
6154
6155 ctx.objErrStage1("and on undefined value",
6156 \\comptime {
6157 \\ var a: bool = undefined;
6158 \\ _ = a and a;
6159 \\}
6160 , &[_][]const u8{
6161 "tmp.zig:3:9: error: use of undefined value here causes undefined behavior",
6162 });
6163
6164 ctx.objErrStage1("or on undefined value",
6165 \\comptime {
6166 \\ var a: bool = undefined;
6167 \\ _ = a or a;
6168 \\}
6169 , &[_][]const u8{
6170 "tmp.zig:3:9: error: use of undefined value here causes undefined behavior",
6171 });
6172
6173 ctx.objErrStage1("negate on undefined value",
6174 \\comptime {
6175 \\ var a: i64 = undefined;
6176 \\ _ = -a;
6177 \\}
6178 , &[_][]const u8{
6179 "tmp.zig:3:10: error: use of undefined value here causes undefined behavior",
6180 });
6181
6182 ctx.objErrStage1("negate wrap on undefined value",
6183 \\comptime {
6184 \\ var a: i64 = undefined;
6185 \\ _ = -%a;
6186 \\}
6187 , &[_][]const u8{
6188 "tmp.zig:3:11: error: use of undefined value here causes undefined behavior",
6189 });
6190
6191 ctx.objErrStage1("bin not on undefined value",
6192 \\comptime {
6193 \\ var a: i64 = undefined;
6194 \\ _ = ~a;
6195 \\}
6196 , &[_][]const u8{
6197 "tmp.zig:3:10: error: use of undefined value here causes undefined behavior",
6198 });
6199
6200 ctx.objErrStage1("bool not on undefined value",
6201 \\comptime {
6202 \\ var a: bool = undefined;
6203 \\ _ = !a;
6204 \\}
6205 , &[_][]const u8{
6206 "tmp.zig:3:10: error: use of undefined value here causes undefined behavior",
6207 });
6208
6209 ctx.objErrStage1("orelse on undefined value",
6210 \\comptime {
6211 \\ var a: ?bool = undefined;
6212 \\ _ = a orelse false;
6213 \\}
6214 , &[_][]const u8{
6215 "tmp.zig:3:11: error: use of undefined value here causes undefined behavior",
6216 });
6217
6218 ctx.objErrStage1("catch on undefined value",
6219 \\comptime {
6220 \\ var a: anyerror!bool = undefined;
6221 \\ _ = a catch false;
6222 \\}
6223 , &[_][]const u8{
6224 "tmp.zig:3:11: error: use of undefined value here causes undefined behavior",
6225 });
6226
6227 ctx.objErrStage1("deref on undefined value",
6228 \\comptime {
6229 \\ var a: *u8 = undefined;
6230 \\ _ = a.*;
6231 \\}
6232 , &[_][]const u8{
6233 "tmp.zig:3:9: error: attempt to dereference undefined value",
6234 });
6235
6236 ctx.objErrStage1("endless loop in function evaluation",
6237 \\const seventh_fib_number = fibonacci(7);
6238 \\fn fibonacci(x: i32) i32 {
6239 \\ return fibonacci(x - 1) + fibonacci(x - 2);
6240 \\}
6241 \\
6242 \\export fn entry() usize { return @sizeOf(@TypeOf(seventh_fib_number)); }
6243 , &[_][]const u8{
6244 "tmp.zig:3:21: error: evaluation exceeded 1000 backwards branches",
6245 });
6246
6247 ctx.objErrStage1("@embedFile with bogus file",
6248 \\const resource = @embedFile("bogus.txt",);
6249 \\
6250 \\export fn entry() usize { return @sizeOf(@TypeOf(resource)); }
6251 , &[_][]const u8{
6252 "tmp.zig:1:29: error: unable to find '",
6253 });
6254
6255 ctx.objErrStage1("non-const expression in struct literal outside function",
6256 \\const Foo = struct {
6257 \\ x: i32,
6258 \\};
6259 \\const a = Foo {.x = get_it()};
6260 \\extern fn get_it() i32;
6261 \\
6262 \\export fn entry() usize { return @sizeOf(@TypeOf(a)); }
6263 , &[_][]const u8{
6264 "tmp.zig:4:21: error: unable to evaluate constant expression",
6265 });
6266
6267 ctx.objErrStage1("non-const expression function call with struct return value outside function",
6268 \\const Foo = struct {
6269 \\ x: i32,
6270 \\};
6271 \\const a = get_it();
6272 \\fn get_it() Foo {
6273 \\ global_side_effect = true;
6274 \\ return Foo {.x = 13};
6275 \\}
6276 \\var global_side_effect = false;
6277 \\
6278 \\export fn entry() usize { return @sizeOf(@TypeOf(a)); }
6279 , &[_][]const u8{
6280 "tmp.zig:6:26: error: unable to evaluate constant expression",
6281 });
6282
6283 ctx.objErrStage1("undeclared identifier error should mark fn as impure",
6284 \\export fn foo() void {
6285 \\ test_a_thing();
6286 \\}
6287 \\fn test_a_thing() void {
6288 \\ bad_fn_call();
6289 \\}
6290 , &[_][]const u8{
6291 "tmp.zig:5:5: error: use of undeclared identifier 'bad_fn_call'",
6292 });
6293
6294 ctx.objErrStage1("illegal comparison of types",
6295 \\fn bad_eql_1(a: []u8, b: []u8) bool {
6296 \\ return a == b;
6297 \\}
6298 \\const EnumWithData = union(enum) {
6299 \\ One: void,
6300 \\ Two: i32,
6301 \\};
6302 \\fn bad_eql_2(a: *const EnumWithData, b: *const EnumWithData) bool {
6303 \\ return a.* == b.*;
6304 \\}
6305 \\
6306 \\export fn entry1() usize { return @sizeOf(@TypeOf(bad_eql_1)); }
6307 \\export fn entry2() usize { return @sizeOf(@TypeOf(bad_eql_2)); }
6308 , &[_][]const u8{
6309 "tmp.zig:2:14: error: operator not allowed for type '[]u8'",
6310 "tmp.zig:9:16: error: operator not allowed for type 'EnumWithData'",
6311 });
6312
6313 ctx.objErrStage1("non-const switch number literal",
6314 \\export fn foo() void {
6315 \\ const x = switch (bar()) {
6316 \\ 1, 2 => 1,
6317 \\ 3, 4 => 2,
6318 \\ else => 3,
6319 \\ };
6320 \\ _ = x;
6321 \\}
6322 \\fn bar() i32 {
6323 \\ return 2;
6324 \\}
6325 , &[_][]const u8{
6326 "tmp.zig:5:17: error: cannot store runtime value in type 'comptime_int'",
6327 });
6328
6329 ctx.objErrStage1("atomic orderings of cmpxchg - failure stricter than success",
6330 \\const AtomicOrder = @import("std").builtin.AtomicOrder;
6331 \\export fn f() void {
6332 \\ var x: i32 = 1234;
6333 \\ while (!@cmpxchgWeak(i32, &x, 1234, 5678, AtomicOrder.Monotonic, AtomicOrder.SeqCst)) {}
6334 \\}
6335 , &[_][]const u8{
6336 "tmp.zig:4:81: error: failure atomic ordering must be no stricter than success",
6337 });
6338
6339 ctx.objErrStage1("atomic orderings of cmpxchg - success Monotonic or stricter",
6340 \\const AtomicOrder = @import("std").builtin.AtomicOrder;
6341 \\export fn f() void {
6342 \\ var x: i32 = 1234;
6343 \\ while (!@cmpxchgWeak(i32, &x, 1234, 5678, AtomicOrder.Unordered, AtomicOrder.Unordered)) {}
6344 \\}
6345 , &[_][]const u8{
6346 "tmp.zig:4:58: error: success atomic ordering must be Monotonic or stricter",
6347 });
6348
6349 ctx.objErrStage1("negation overflow in function evaluation",
6350 \\const y = neg(-128);
6351 \\fn neg(x: i8) i8 {
6352 \\ return -x;
6353 \\}
6354 \\
6355 \\export fn entry() usize { return @sizeOf(@TypeOf(y)); }
6356 , &[_][]const u8{
6357 "tmp.zig:3:12: error: negation caused overflow",
6358 });
6359
6360 ctx.objErrStage1("add overflow in function evaluation",
6361 \\const y = add(65530, 10);
6362 \\fn add(a: u16, b: u16) u16 {
6363 \\ return a + b;
6364 \\}
6365 \\
6366 \\export fn entry() usize { return @sizeOf(@TypeOf(y)); }
6367 , &[_][]const u8{
6368 "tmp.zig:3:14: error: operation caused overflow",
6369 });
6370
6371 ctx.objErrStage1("sub overflow in function evaluation",
6372 \\const y = sub(10, 20);
6373 \\fn sub(a: u16, b: u16) u16 {
6374 \\ return a - b;
6375 \\}
6376 \\
6377 \\export fn entry() usize { return @sizeOf(@TypeOf(y)); }
6378 , &[_][]const u8{
6379 "tmp.zig:3:14: error: operation caused overflow",
6380 });
6381
6382 ctx.objErrStage1("mul overflow in function evaluation",
6383 \\const y = mul(300, 6000);
6384 \\fn mul(a: u16, b: u16) u16 {
6385 \\ return a * b;
6386 \\}
6387 \\
6388 \\export fn entry() usize { return @sizeOf(@TypeOf(y)); }
6389 , &[_][]const u8{
6390 "tmp.zig:3:14: error: operation caused overflow",
6391 });
6392
6393 ctx.objErrStage1("truncate sign mismatch",
6394 \\export fn entry1() i8 {
6395 \\ var x: u32 = 10;
6396 \\ return @truncate(i8, x);
6397 \\}
6398 \\export fn entry2() u8 {
6399 \\ var x: i32 = -10;
6400 \\ return @truncate(u8, x);
6401 \\}
6402 \\export fn entry3() i8 {
6403 \\ comptime var x: u32 = 10;
6404 \\ return @truncate(i8, x);
6405 \\}
6406 \\export fn entry4() u8 {
6407 \\ comptime var x: i32 = -10;
6408 \\ return @truncate(u8, x);
6409 \\}
6410 , &[_][]const u8{
6411 "tmp.zig:3:26: error: expected signed integer type, found 'u32'",
6412 "tmp.zig:7:26: error: expected unsigned integer type, found 'i32'",
6413 "tmp.zig:11:26: error: expected signed integer type, found 'u32'",
6414 "tmp.zig:15:26: error: expected unsigned integer type, found 'i32'",
6415 });
6416
6417 ctx.objErrStage1("try in function with non error return type",
6418 \\export fn f() void {
6419 \\ try something();
6420 \\}
6421 \\fn something() anyerror!void { }
6422 , &[_][]const u8{
6423 "tmp.zig:2:5: error: expected type 'void', found 'anyerror'",
6424 });
6425
6426 ctx.objErrStage1("invalid pointer for var type",
6427 \\extern fn ext() usize;
6428 \\var bytes: [ext()]u8 = undefined;
6429 \\export fn f() void {
6430 \\ for (bytes) |*b, i| {
6431 \\ b.* = @as(u8, i);
6432 \\ }
6433 \\}
6434 , &[_][]const u8{
6435 "tmp.zig:2:13: error: unable to evaluate constant expression",
6436 });
6437
6438 ctx.objErrStage1("export function with comptime parameter",
6439 \\export fn foo(comptime x: i32, y: i32) i32{
6440 \\ return x + y;
6441 \\}
6442 , &[_][]const u8{
6443 "tmp.zig:1:15: error: comptime parameter not allowed in function with calling convention 'C'",
6444 });
6445
6446 ctx.objErrStage1("extern function with comptime parameter",
6447 \\extern fn foo(comptime x: i32, y: i32) i32;
6448 \\fn f() i32 {
6449 \\ return foo(1, 2);
6450 \\}
6451 \\export fn entry() usize { return @sizeOf(@TypeOf(f)); }
6452 , &[_][]const u8{
6453 "tmp.zig:1:15: error: comptime parameter not allowed in function with calling convention 'C'",
6454 });
6455
6456 ctx.objErrStage1("non-pure function returns type",
6457 \\var a: u32 = 0;
6458 \\pub fn List(comptime T: type) type {
6459 \\ a += 1;
6460 \\ return SmallList(T, 8);
6461 \\}
6462 \\
6463 \\pub fn SmallList(comptime T: type, comptime STATIC_SIZE: usize) type {
6464 \\ return struct {
6465 \\ items: []T,
6466 \\ length: usize,
6467 \\ prealloc_items: [STATIC_SIZE]T,
6468 \\ };
6469 \\}
6470 \\
6471 \\export fn function_with_return_type_type() void {
6472 \\ var list: List(i32) = undefined;
6473 \\ list.length = 10;
6474 \\}
6475 , &[_][]const u8{
6476 "tmp.zig:3:7: error: unable to evaluate constant expression",
6477 });
6478
6479 ctx.objErrStage1("bogus method call on slice",
6480 \\var self = "aoeu";
6481 \\fn f(m: []const u8) void {
6482 \\ m.copy(u8, self[0..], m);
6483 \\}
6484 \\export fn entry() usize { return @sizeOf(@TypeOf(f)); }
6485 , &[_][]const u8{
6486 "tmp.zig:3:6: error: no member named 'copy' in '[]const u8'",
6487 });
6488
6489 ctx.objErrStage1("wrong number of arguments for method fn call",
6490 \\const Foo = struct {
6491 \\ fn method(self: *const Foo, a: i32) void {_ = self; _ = a;}
6492 \\};
6493 \\fn f(foo: *const Foo) void {
6494 \\
6495 \\ foo.method(1, 2);
6496 \\}
6497 \\export fn entry() usize { return @sizeOf(@TypeOf(f)); }
6498 , &[_][]const u8{
6499 "tmp.zig:6:15: error: expected 2 argument(s), found 3",
6500 });
6501
6502 ctx.objErrStage1("assign through constant pointer",
6503 \\export fn f() void {
6504 \\ var cstr = "Hat";
6505 \\ cstr[0] = 'W';
6506 \\}
6507 , &[_][]const u8{
6508 "tmp.zig:3:13: error: cannot assign to constant",
6509 });
6510
6511 ctx.objErrStage1("assign through constant slice",
6512 \\export fn f() void {
6513 \\ var cstr: []const u8 = "Hat";
6514 \\ cstr[0] = 'W';
6515 \\}
6516 , &[_][]const u8{
6517 "tmp.zig:3:13: error: cannot assign to constant",
6518 });
6519
6520 ctx.objErrStage1("main function with bogus args type",
6521 \\pub fn main(args: [][]bogus) !void {_ = args;}
6522 , &[_][]const u8{
6523 "tmp.zig:1:23: error: use of undeclared identifier 'bogus'",
6524 });
6525
6526 ctx.objErrStage1("misspelled type with pointer only reference",
6527 \\const JasonHM = u8;
6528 \\const JasonList = *JsonNode;
6529 \\
6530 \\const JsonOA = union(enum) {
6531 \\ JSONArray: JsonList,
6532 \\ JSONObject: JasonHM,
6533 \\};
6534 \\
6535 \\const JsonType = union(enum) {
6536 \\ JSONNull: void,
6537 \\ JSONInteger: isize,
6538 \\ JSONDouble: f64,
6539 \\ JSONBool: bool,
6540 \\ JSONString: []u8,
6541 \\ JSONArray: void,
6542 \\ JSONObject: void,
6543 \\};
6544 \\
6545 \\pub const JsonNode = struct {
6546 \\ kind: JsonType,
6547 \\ jobject: ?JsonOA,
6548 \\};
6549 \\
6550 \\fn foo() void {
6551 \\ var jll: JasonList = undefined;
6552 \\ jll.init(1234);
6553 \\ var jd = JsonNode {.kind = JsonType.JSONArray , .jobject = JsonOA.JSONArray {jll} };
6554 \\ _ = jd;
6555 \\}
6556 \\
6557 \\export fn entry() usize { return @sizeOf(@TypeOf(foo)); }
6558 , &[_][]const u8{
6559 "tmp.zig:5:16: error: use of undeclared identifier 'JsonList'",
6560 });
6561
6562 ctx.objErrStage1("method call with first arg type primitive",
6563 \\const Foo = struct {
6564 \\ x: i32,
6565 \\
6566 \\ fn init(x: i32) Foo {
6567 \\ return Foo {
6568 \\ .x = x,
6569 \\ };
6570 \\ }
6571 \\};
6572 \\
6573 \\export fn f() void {
6574 \\ const derp = Foo.init(3);
6575 \\
6576 \\ derp.init();
6577 \\}
6578 , &[_][]const u8{
6579 "tmp.zig:14:5: error: expected type 'i32', found 'Foo'",
6580 });
6581
6582 ctx.objErrStage1("method call with first arg type wrong container",
6583 \\pub const List = struct {
6584 \\ len: usize,
6585 \\ allocator: *Allocator,
6586 \\
6587 \\ pub fn init(allocator: *Allocator) List {
6588 \\ return List {
6589 \\ .len = 0,
6590 \\ .allocator = allocator,
6591 \\ };
6592 \\ }
6593 \\};
6594 \\
6595 \\pub var global_allocator = Allocator {
6596 \\ .field = 1234,
6597 \\};
6598 \\
6599 \\pub const Allocator = struct {
6600 \\ field: i32,
6601 \\};
6602 \\
6603 \\export fn foo() void {
6604 \\ var x = List.init(&global_allocator);
6605 \\ x.init();
6606 \\}
6607 , &[_][]const u8{
6608 "tmp.zig:23:5: error: expected type '*Allocator', found '*List'",
6609 });
6610
6611 ctx.objErrStage1("binary not on number literal",
6612 \\const TINY_QUANTUM_SHIFT = 4;
6613 \\const TINY_QUANTUM_SIZE = 1 << TINY_QUANTUM_SHIFT;
6614 \\var block_aligned_stuff: usize = (4 + TINY_QUANTUM_SIZE) & ~(TINY_QUANTUM_SIZE - 1);
6615 \\
6616 \\export fn entry() usize { return @sizeOf(@TypeOf(block_aligned_stuff)); }
6617 , &[_][]const u8{
6618 "tmp.zig:3:60: error: unable to perform binary not operation on type 'comptime_int'",
6619 });
6620
6621 {
6622 const case = ctx.obj("multiple files with private function error", .{});
6623 case.backend = .stage1;
6624
6625 case.addSourceFile("foo.zig",
6626 \\fn privateFunction() void { }
6627 );
6628
6629 case.addError(
6630 \\const foo = @import("foo.zig",);
6631 \\
6632 \\export fn callPrivFunction() void {
6633 \\ foo.privateFunction();
6634 \\}
6635 , &[_][]const u8{
6636 "tmp.zig:4:8: error: 'privateFunction' is private",
6637 "foo.zig:1:1: note: declared here",
6638 });
6639 }
6640
6641 {
6642 const case = ctx.obj("multiple files with private member instance function (canonical invocation) error", .{});
6643 case.backend = .stage1;
6644
6645 case.addSourceFile("foo.zig",
6646 \\pub const Foo = struct {
6647 \\ fn privateFunction(self: *Foo) void { _ = self; }
6648 \\};
6649 );
6650
6651 case.addError(
6652 \\const Foo = @import("foo.zig",).Foo;
6653 \\
6654 \\export fn callPrivFunction() void {
6655 \\ var foo = Foo{};
6656 \\ Foo.privateFunction(foo);
6657 \\}
6658 , &[_][]const u8{
6659 "tmp.zig:5:8: error: 'privateFunction' is private",
6660 "foo.zig:2:5: note: declared here",
6661 });
6662 }
6663
6664 {
6665 const case = ctx.obj("multiple files with private member instance function error", .{});
6666 case.backend = .stage1;
6667
6668 case.addSourceFile("foo.zig",
6669 \\pub const Foo = struct {
6670 \\ fn privateFunction(self: *Foo) void { _ = self; }
6671 \\};
6672 );
6673
6674 case.addError(
6675 \\const Foo = @import("foo.zig",).Foo;
6676 \\
6677 \\export fn callPrivFunction() void {
6678 \\ var foo = Foo{};
6679 \\ foo.privateFunction();
6680 \\}
6681 , &[_][]const u8{
6682 "tmp.zig:5:8: error: 'privateFunction' is private",
6683 "foo.zig:2:5: note: declared here",
6684 });
6685 }
6686
6687 ctx.objErrStage1("container init with non-type",
6688 \\const zero: i32 = 0;
6689 \\const a = zero{1};
6690 \\
6691 \\export fn entry() usize { return @sizeOf(@TypeOf(a)); }
6692 , &[_][]const u8{
6693 "tmp.zig:2:11: error: expected type 'type', found 'i32'",
6694 });
6695
6696 ctx.objErrStage1("assign to constant field",
6697 \\const Foo = struct {
6698 \\ field: i32,
6699 \\};
6700 \\export fn derp() void {
6701 \\ const f = Foo {.field = 1234,};
6702 \\ f.field = 0;
6703 \\}
6704 , &[_][]const u8{
6705 "tmp.zig:6:15: error: cannot assign to constant",
6706 });
6707
6708 ctx.objErrStage1("return from defer expression",
6709 \\pub fn testTrickyDefer() !void {
6710 \\ defer canFail() catch {};
6711 \\
6712 \\ defer try canFail();
6713 \\
6714 \\ const a = maybeInt() orelse return;
6715 \\}
6716 \\
6717 \\fn canFail() anyerror!void { }
6718 \\
6719 \\pub fn maybeInt() ?i32 {
6720 \\ return 0;
6721 \\}
6722 \\
6723 \\export fn entry() usize { return @sizeOf(@TypeOf(testTrickyDefer)); }
6724 , &[_][]const u8{
6725 "tmp.zig:4:11: error: 'try' not allowed inside defer expression",
6726 });
6727
6728 ctx.objErrStage1("assign too big number to u16",
6729 \\export fn foo() void {
6730 \\ var vga_mem: u16 = 0xB8000;
6731 \\ _ = vga_mem;
6732 \\}
6733 , &[_][]const u8{
6734 "tmp.zig:2:24: error: integer value 753664 cannot be coerced to type 'u16'",
6735 });
6736
6737 ctx.objErrStage1("global variable alignment non power of 2",
6738 \\const some_data: [100]u8 align(3) = undefined;
6739 \\export fn entry() usize { return @sizeOf(@TypeOf(some_data)); }
6740 , &[_][]const u8{
6741 "tmp.zig:1:32: error: alignment value 3 is not a power of 2",
6742 });
6743
6744 ctx.objErrStage1("function alignment non power of 2",
6745 \\extern fn foo() align(3) void;
6746 \\export fn entry() void { return foo(); }
6747 , &[_][]const u8{
6748 "tmp.zig:1:23: error: alignment value 3 is not a power of 2",
6749 });
6750
6751 ctx.objErrStage1("compile log",
6752 \\export fn foo() void {
6753 \\ comptime bar(12, "hi",);
6754 \\}
6755 \\fn bar(a: i32, b: []const u8) void {
6756 \\ @compileLog("begin",);
6757 \\ @compileLog("a", a, "b", b);
6758 \\ @compileLog("end",);
6759 \\}
6760 , &[_][]const u8{
6761 "tmp.zig:5:5: error: found compile log statement",
6762 "tmp.zig:6:5: error: found compile log statement",
6763 "tmp.zig:7:5: error: found compile log statement",
6764 });
6765
6766 ctx.objErrStage1("casting bit offset pointer to regular pointer",
6767 \\const BitField = packed struct {
6768 \\ a: u3,
6769 \\ b: u3,
6770 \\ c: u2,
6771 \\};
6772 \\
6773 \\fn foo(bit_field: *const BitField) u3 {
6774 \\ return bar(&bit_field.b);
6775 \\}
6776 \\
6777 \\fn bar(x: *const u3) u3 {
6778 \\ return x.*;
6779 \\}
6780 \\
6781 \\export fn entry() usize { return @sizeOf(@TypeOf(foo)); }
6782 , &[_][]const u8{
6783 "tmp.zig:8:26: error: expected type '*const u3', found '*align(:3:1) const u3'",
6784 });
6785
6786 ctx.objErrStage1("referring to a struct that is invalid",
6787 \\const UsbDeviceRequest = struct {
6788 \\ Type: u8,
6789 \\};
6790 \\
6791 \\export fn foo() void {
6792 \\ comptime assert(@sizeOf(UsbDeviceRequest) == 0x8);
6793 \\}
6794 \\
6795 \\fn assert(ok: bool) void {
6796 \\ if (!ok) unreachable;
6797 \\}
6798 , &[_][]const u8{
6799 "tmp.zig:10:14: error: reached unreachable code",
6800 });
6801
6802 ctx.objErrStage1("control flow uses comptime var at runtime",
6803 \\export fn foo() void {
6804 \\ comptime var i = 0;
6805 \\ while (i < 5) : (i += 1) {
6806 \\ bar();
6807 \\ }
6808 \\}
6809 \\
6810 \\fn bar() void { }
6811 , &[_][]const u8{
6812 "tmp.zig:3:5: error: control flow attempts to use compile-time variable at runtime",
6813 "tmp.zig:3:24: note: compile-time variable assigned here",
6814 });
6815
6816 ctx.objErrStage1("ignored return value",
6817 \\export fn foo() void {
6818 \\ bar();
6819 \\}
6820 \\fn bar() i32 { return 0; }
6821 , &[_][]const u8{
6822 "tmp.zig:2:8: error: expression value is ignored",
6823 });
6824
6825 ctx.objErrStage1("ignored assert-err-ok return value",
6826 \\export fn foo() void {
6827 \\ bar() catch unreachable;
6828 \\}
6829 \\fn bar() anyerror!i32 { return 0; }
6830 , &[_][]const u8{
6831 "tmp.zig:2:11: error: expression value is ignored",
6832 });
6833
6834 ctx.objErrStage1("ignored statement value",
6835 \\export fn foo() void {
6836 \\ 1;
6837 \\}
6838 , &[_][]const u8{
6839 "tmp.zig:2:5: error: expression value is ignored",
6840 });
6841
6842 ctx.objErrStage1("ignored comptime statement value",
6843 \\export fn foo() void {
6844 \\ comptime {1;}
6845 \\}
6846 , &[_][]const u8{
6847 "tmp.zig:2:15: error: expression value is ignored",
6848 });
6849
6850 ctx.objErrStage1("ignored comptime value",
6851 \\export fn foo() void {
6852 \\ comptime 1;
6853 \\}
6854 , &[_][]const u8{
6855 "tmp.zig:2:5: error: expression value is ignored",
6856 });
6857
6858 ctx.objErrStage1("ignored deferred statement value",
6859 \\export fn foo() void {
6860 \\ defer {1;}
6861 \\}
6862 , &[_][]const u8{
6863 "tmp.zig:2:12: error: expression value is ignored",
6864 });
6865
6866 ctx.objErrStage1("ignored deferred function call",
6867 \\export fn foo() void {
6868 \\ defer bar();
6869 \\}
6870 \\fn bar() anyerror!i32 { return 0; }
6871 , &[_][]const u8{
6872 "tmp.zig:2:14: error: error is ignored. consider using `try`, `catch`, or `if`",
6873 });
6874
6875 ctx.objErrStage1("dereference an array",
6876 \\var s_buffer: [10]u8 = undefined;
6877 \\pub fn pass(in: []u8) []u8 {
6878 \\ var out = &s_buffer;
6879 \\ out.*.* = in[0];
6880 \\ return out.*[0..1];
6881 \\}
6882 \\
6883 \\export fn entry() usize { return @sizeOf(@TypeOf(pass)); }
6884 , &[_][]const u8{
6885 "tmp.zig:4:10: error: attempt to dereference non-pointer type '[10]u8'",
6886 });
6887
6888 ctx.objErrStage1("pass const ptr to mutable ptr fn",
6889 \\fn foo() bool {
6890 \\ const a = @as([]const u8, "a",);
6891 \\ const b = &a;
6892 \\ return ptrEql(b, b);
6893 \\}
6894 \\fn ptrEql(a: *[]const u8, b: *[]const u8) bool {
6895 \\ _ = a; _ = b;
6896 \\ return true;
6897 \\}
6898 \\
6899 \\export fn entry() usize { return @sizeOf(@TypeOf(foo)); }
6900 , &[_][]const u8{
6901 "tmp.zig:4:19: error: expected type '*[]const u8', found '*const []const u8'",
6902 });
6903
6904 {
6905 const case = ctx.obj("export collision", .{});
6906 case.backend = .stage1;
6907
6908 case.addSourceFile("foo.zig",
6909 \\export fn bar() void {}
6910 \\pub const baz = 1234;
6911 );
6912
6913 case.addError(
6914 \\const foo = @import("foo.zig",);
6915 \\
6916 \\export fn bar() usize {
6917 \\ return foo.baz;
6918 \\}
6919 , &[_][]const u8{
6920 "foo.zig:1:1: error: exported symbol collision: 'bar'",
6921 "tmp.zig:3:1: note: other symbol here",
6922 });
6923 }
6924
6925 ctx.objErrStage1("implicit cast from array to mutable slice",
6926 \\var global_array: [10]i32 = undefined;
6927 \\fn foo(param: []i32) void {_ = param;}
6928 \\export fn entry() void {
6929 \\ foo(global_array);
6930 \\}
6931 , &[_][]const u8{
6932 "tmp.zig:4:9: error: expected type '[]i32', found '[10]i32'",
6933 });
6934
6935 ctx.objErrStage1("ptrcast to non-pointer",
6936 \\export fn entry(a: *i32) usize {
6937 \\ return @ptrCast(usize, a);
6938 \\}
6939 , &[_][]const u8{
6940 "tmp.zig:2:21: error: expected pointer, found 'usize'",
6941 });
6942
6943 ctx.objErrStage1("asm at compile time",
6944 \\comptime {
6945 \\ doSomeAsm();
6946 \\}
6947 \\
6948 \\fn doSomeAsm() void {
6949 \\ asm volatile (
6950 \\ \\.globl aoeu;
6951 \\ \\.type aoeu, @function;
6952 \\ \\.set aoeu, derp;
6953 \\ );
6954 \\}
6955 , &[_][]const u8{
6956 "tmp.zig:6:5: error: unable to evaluate constant expression",
6957 });
6958
6959 ctx.objErrStage1("invalid member of builtin enum",
6960 \\const builtin = @import("std").builtin;
6961 \\export fn entry() void {
6962 \\ const foo = builtin.Mode.x86;
6963 \\ _ = foo;
6964 \\}
6965 , &[_][]const u8{
6966 "tmp.zig:3:29: error: container 'std.builtin.Mode' has no member called 'x86'",
6967 });
6968
6969 ctx.objErrStage1("int to ptr of 0 bits",
6970 \\export fn foo() void {
6971 \\ var x: usize = 0x1000;
6972 \\ var y: *void = @intToPtr(*void, x);
6973 \\ _ = y;
6974 \\}
6975 , &[_][]const u8{
6976 "tmp.zig:3:30: error: type '*void' has 0 bits and cannot store information",
6977 });
6978
6979 ctx.objErrStage1("@fieldParentPtr - non struct",
6980 \\const Foo = i32;
6981 \\export fn foo(a: *i32) *Foo {
6982 \\ return @fieldParentPtr(Foo, "a", a);
6983 \\}
6984 , &[_][]const u8{
6985 "tmp.zig:3:28: error: expected struct type, found 'i32'",
6986 });
6987
6988 ctx.objErrStage1("@fieldParentPtr - bad field name",
6989 \\const Foo = extern struct {
6990 \\ derp: i32,
6991 \\};
6992 \\export fn foo(a: *i32) *Foo {
6993 \\ return @fieldParentPtr(Foo, "a", a);
6994 \\}
6995 , &[_][]const u8{
6996 "tmp.zig:5:33: error: struct 'Foo' has no field 'a'",
6997 });
6998
6999 ctx.objErrStage1("@fieldParentPtr - field pointer is not pointer",
7000 \\const Foo = extern struct {
7001 \\ a: i32,
7002 \\};
7003 \\export fn foo(a: i32) *Foo {
7004 \\ return @fieldParentPtr(Foo, "a", a);
7005 \\}
7006 , &[_][]const u8{
7007 "tmp.zig:5:38: error: expected pointer, found 'i32'",
7008 });
7009
7010 ctx.objErrStage1("@fieldParentPtr - comptime field ptr not based on struct",
7011 \\const Foo = struct {
7012 \\ a: i32,
7013 \\ b: i32,
7014 \\};
7015 \\const foo = Foo { .a = 1, .b = 2, };
7016 \\
7017 \\comptime {
7018 \\ const field_ptr = @intToPtr(*i32, 0x1234);
7019 \\ const another_foo_ptr = @fieldParentPtr(Foo, "b", field_ptr);
7020 \\ _ = another_foo_ptr;
7021 \\}
7022 , &[_][]const u8{
7023 "tmp.zig:9:55: error: pointer value not based on parent struct",
7024 });
7025
7026 ctx.objErrStage1("@fieldParentPtr - comptime wrong field index",
7027 \\const Foo = struct {
7028 \\ a: i32,
7029 \\ b: i32,
7030 \\};
7031 \\const foo = Foo { .a = 1, .b = 2, };
7032 \\
7033 \\comptime {
7034 \\ const another_foo_ptr = @fieldParentPtr(Foo, "b", &foo.a);
7035 \\ _ = another_foo_ptr;
7036 \\}
7037 , &[_][]const u8{
7038 "tmp.zig:8:29: error: field 'b' has index 1 but pointer value is index 0 of struct 'Foo'",
7039 });
7040
7041 ctx.objErrStage1("@offsetOf - non struct",
7042 \\const Foo = i32;
7043 \\export fn foo() usize {
7044 \\ return @offsetOf(Foo, "a",);
7045 \\}
7046 , &[_][]const u8{
7047 "tmp.zig:3:22: error: expected struct type, found 'i32'",
7048 });
7049
7050 ctx.objErrStage1("@offsetOf - bad field name",
7051 \\const Foo = struct {
7052 \\ derp: i32,
7053 \\};
7054 \\export fn foo() usize {
7055 \\ return @offsetOf(Foo, "a",);
7056 \\}
7057 , &[_][]const u8{
7058 "tmp.zig:5:27: error: struct 'Foo' has no field 'a'",
7059 });
7060
7061 ctx.exeErrStage1("missing main fn in executable",
7062 \\
7063 , &[_][]const u8{
7064 "error: root source file has no member called 'main'",
7065 });
7066
7067 ctx.exeErrStage1("private main fn",
7068 \\fn main() void {}
7069 , &[_][]const u8{
7070 "error: 'main' is private",
7071 "tmp.zig:1:1: note: declared here",
7072 });
7073
7074 ctx.objErrStage1("setting a section on a local variable",
7075 \\export fn entry() i32 {
7076 \\ var foo: i32 linksection(".text2") = 1234;
7077 \\ return foo;
7078 \\}
7079 , &[_][]const u8{
7080 "tmp.zig:2:30: error: cannot set section of local variable 'foo'",
7081 });
7082
7083 ctx.objErrStage1("ambiguous decl reference",
7084 \\fn foo() void {}
7085 \\fn bar() void {
7086 \\ const S = struct {
7087 \\ fn baz() void {
7088 \\ foo();
7089 \\ }
7090 \\ fn foo() void {}
7091 \\ };
7092 \\ S.baz();
7093 \\}
7094 \\export fn entry() void {
7095 \\ bar();
7096 \\}
7097 , &[_][]const u8{
7098 "tmp.zig:5:13: error: ambiguous reference",
7099 "tmp.zig:7:9: note: declared here",
7100 "tmp.zig:1:1: note: also declared here",
7101 });
7102
7103 ctx.objErrStage1("while expected bool, got optional",
7104 \\export fn foo() void {
7105 \\ while (bar()) {}
7106 \\}
7107 \\fn bar() ?i32 { return 1; }
7108 , &[_][]const u8{
7109 "tmp.zig:2:15: error: expected type 'bool', found '?i32'",
7110 });
7111
7112 ctx.objErrStage1("while expected bool, got error union",
7113 \\export fn foo() void {
7114 \\ while (bar()) {}
7115 \\}
7116 \\fn bar() anyerror!i32 { return 1; }
7117 , &[_][]const u8{
7118 "tmp.zig:2:15: error: expected type 'bool', found 'anyerror!i32'",
7119 });
7120
7121 ctx.objErrStage1("while expected optional, got bool",
7122 \\export fn foo() void {
7123 \\ while (bar()) |x| {_ = x;}
7124 \\}
7125 \\fn bar() bool { return true; }
7126 , &[_][]const u8{
7127 "tmp.zig:2:15: error: expected optional type, found 'bool'",
7128 });
7129
7130 ctx.objErrStage1("while expected optional, got error union",
7131 \\export fn foo() void {
7132 \\ while (bar()) |x| {_ = x;}
7133 \\}
7134 \\fn bar() anyerror!i32 { return 1; }
7135 , &[_][]const u8{
7136 "tmp.zig:2:15: error: expected optional type, found 'anyerror!i32'",
7137 });
7138
7139 ctx.objErrStage1("while expected error union, got bool",
7140 \\export fn foo() void {
7141 \\ while (bar()) |x| {_ = x;} else |err| {_ = err;}
7142 \\}
7143 \\fn bar() bool { return true; }
7144 , &[_][]const u8{
7145 "tmp.zig:2:15: error: expected error union type, found 'bool'",
7146 });
7147
7148 ctx.objErrStage1("while expected error union, got optional",
7149 \\export fn foo() void {
7150 \\ while (bar()) |x| {_ = x;} else |err| {_ = err;}
7151 \\}
7152 \\fn bar() ?i32 { return 1; }
7153 , &[_][]const u8{
7154 "tmp.zig:2:15: error: expected error union type, found '?i32'",
7155 });
7156
7157 // TODO test this in stage2, but we won't even try in stage1
7158 //ctx.objErrStage1("inline fn calls itself indirectly",
7159 // \\export fn foo() void {
7160 // \\ bar();
7161 // \\}
7162 // \\fn bar() callconv(.Inline) void {
7163 // \\ baz();
7164 // \\ quux();
7165 // \\}
7166 // \\fn baz() callconv(.Inline) void {
7167 // \\ bar();
7168 // \\ quux();
7169 // \\}
7170 // \\extern fn quux() void;
7171 //, &[_][]const u8{
7172 // "tmp.zig:4:1: error: unable to inline function",
7173 //});
7174
7175 //ctx.objErrStage1("save reference to inline function",
7176 // \\export fn foo() void {
7177 // \\ quux(@ptrToInt(bar));
7178 // \\}
7179 // \\fn bar() callconv(.Inline) void { }
7180 // \\extern fn quux(usize) void;
7181 //, &[_][]const u8{
7182 // "tmp.zig:4:1: error: unable to inline function",
7183 //});
7184
7185 ctx.objErrStage1("signed integer division",
7186 \\export fn foo(a: i32, b: i32) i32 {
7187 \\ return a / b;
7188 \\}
7189 , &[_][]const u8{
7190 "tmp.zig:2:14: error: division with 'i32' and 'i32': signed integers must use @divTrunc, @divFloor, or @divExact",
7191 });
7192
7193 ctx.objErrStage1("signed integer remainder division",
7194 \\export fn foo(a: i32, b: i32) i32 {
7195 \\ return a % b;
7196 \\}
7197 , &[_][]const u8{
7198 "tmp.zig:2:14: error: remainder division with 'i32' and 'i32': signed integers and floats must use @rem or @mod",
7199 });
7200
7201 ctx.objErrStage1("compile-time division by zero",
7202 \\comptime {
7203 \\ const a: i32 = 1;
7204 \\ const b: i32 = 0;
7205 \\ const c = a / b;
7206 \\ _ = c;
7207 \\}
7208 , &[_][]const u8{
7209 "tmp.zig:4:17: error: division by zero",
7210 });
7211
7212 ctx.objErrStage1("compile-time remainder division by zero",
7213 \\comptime {
7214 \\ const a: i32 = 1;
7215 \\ const b: i32 = 0;
7216 \\ const c = a % b;
7217 \\ _ = c;
7218 \\}
7219 , &[_][]const u8{
7220 "tmp.zig:4:17: error: division by zero",
7221 });
7222
7223 ctx.objErrStage1("@setRuntimeSafety twice for same scope",
7224 \\export fn foo() void {
7225 \\ @setRuntimeSafety(false);
7226 \\ @setRuntimeSafety(false);
7227 \\}
7228 , &[_][]const u8{
7229 "tmp.zig:3:5: error: runtime safety set twice for same scope",
7230 "tmp.zig:2:5: note: first set here",
7231 });
7232
7233 ctx.objErrStage1("@setFloatMode twice for same scope",
7234 \\export fn foo() void {
7235 \\ @setFloatMode(@import("std").builtin.FloatMode.Optimized);
7236 \\ @setFloatMode(@import("std").builtin.FloatMode.Optimized);
7237 \\}
7238 , &[_][]const u8{
7239 "tmp.zig:3:5: error: float mode set twice for same scope",
7240 "tmp.zig:2:5: note: first set here",
7241 });
7242
7243 ctx.objErrStage1("array access of type",
7244 \\export fn foo() void {
7245 \\ var b: u8[40] = undefined;
7246 \\ _ = b;
7247 \\}
7248 , &[_][]const u8{
7249 "tmp.zig:2:14: error: array access of non-array type 'type'",
7250 });
7251
7252 ctx.objErrStage1("cannot break out of defer expression",
7253 \\export fn foo() void {
7254 \\ while (true) {
7255 \\ defer {
7256 \\ break;
7257 \\ }
7258 \\ }
7259 \\}
7260 , &[_][]const u8{
7261 "tmp.zig:4:13: error: cannot break out of defer expression",
7262 });
7263
7264 ctx.objErrStage1("cannot continue out of defer expression",
7265 \\export fn foo() void {
7266 \\ while (true) {
7267 \\ defer {
7268 \\ continue;
7269 \\ }
7270 \\ }
7271 \\}
7272 , &[_][]const u8{
7273 "tmp.zig:4:13: error: cannot continue out of defer expression",
7274 });
7275
7276 ctx.objErrStage1("calling a generic function only known at runtime",
7277 \\var foos = [_]fn(anytype) void { foo1, foo2 };
7278 \\
7279 \\fn foo1(arg: anytype) void {_ = arg;}
7280 \\fn foo2(arg: anytype) void {_ = arg;}
7281 \\
7282 \\pub fn main() !void {
7283 \\ foos[0](true);
7284 \\}
7285 , &[_][]const u8{
7286 "tmp.zig:7:9: error: calling a generic function requires compile-time known function value",
7287 });
7288
7289 ctx.objErrStage1("@compileError shows traceback of references that caused it",
7290 \\const foo = @compileError("aoeu",);
7291 \\
7292 \\const bar = baz + foo;
7293 \\const baz = 1;
7294 \\
7295 \\export fn entry() i32 {
7296 \\ return bar;
7297 \\}
7298 , &[_][]const u8{
7299 "tmp.zig:1:13: error: aoeu",
7300 });
7301
7302 ctx.objErrStage1("float literal too large error",
7303 \\comptime {
7304 \\ const a = 0x1.0p18495;
7305 \\ _ = a;
7306 \\}
7307 , &[_][]const u8{
7308 "tmp.zig:2:15: error: float literal out of range of any type",
7309 });
7310
7311 ctx.objErrStage1("float literal too small error (denormal)",
7312 \\comptime {
7313 \\ const a = 0x1.0p-19000;
7314 \\ _ = a;
7315 \\}
7316 , &[_][]const u8{
7317 "tmp.zig:2:15: error: float literal out of range of any type",
7318 });
7319
7320 ctx.objErrStage1("explicit cast float literal to integer when there is a fraction component",
7321 \\export fn entry() i32 {
7322 \\ return @as(i32, 12.34);
7323 \\}
7324 , &[_][]const u8{
7325 "tmp.zig:2:21: error: fractional component prevents float value 12.340000 from being casted to type 'i32'",
7326 });
7327
7328 ctx.objErrStage1("non pointer given to @ptrToInt",
7329 \\export fn entry(x: i32) usize {
7330 \\ return @ptrToInt(x);
7331 \\}
7332 , &[_][]const u8{
7333 "tmp.zig:2:22: error: expected pointer, found 'i32'",
7334 });
7335
7336 ctx.objErrStage1("@shlExact shifts out 1 bits",
7337 \\comptime {
7338 \\ const x = @shlExact(@as(u8, 0b01010101), 2);
7339 \\ _ = x;
7340 \\}
7341 , &[_][]const u8{
7342 "tmp.zig:2:15: error: operation caused overflow",
7343 });
7344
7345 ctx.objErrStage1("@shrExact shifts out 1 bits",
7346 \\comptime {
7347 \\ const x = @shrExact(@as(u8, 0b10101010), 2);
7348 \\ _ = x;
7349 \\}
7350 , &[_][]const u8{
7351 "tmp.zig:2:15: error: exact shift shifted out 1 bits",
7352 });
7353
7354 ctx.objErrStage1("shifting without int type or comptime known",
7355 \\export fn entry(x: u8) u8 {
7356 \\ return 0x11 << x;
7357 \\}
7358 , &[_][]const u8{
7359 "tmp.zig:2:17: error: LHS of shift must be a fixed-width integer type, or RHS must be compile-time known",
7360 });
7361
7362 ctx.objErrStage1("shifting RHS is log2 of LHS int bit width",
7363 \\export fn entry(x: u8, y: u8) u8 {
7364 \\ return x << y;
7365 \\}
7366 , &[_][]const u8{
7367 "tmp.zig:2:17: error: expected type 'u3', found 'u8'",
7368 });
7369
7370 ctx.objErrStage1("locally shadowing a primitive type",
7371 \\export fn foo() void {
7372 \\ const u8 = u16;
7373 \\ const a: u8 = 300;
7374 \\ _ = a;
7375 \\}
7376 , &[_][]const u8{
7377 "tmp.zig:2:11: error: name shadows primitive 'u8'",
7378 "tmp.zig:2:11: note: consider using @\"u8\" to disambiguate",
7379 });
7380
7381 ctx.objErrStage1("primitives take precedence over declarations",
7382 \\const @"u8" = u16;
7383 \\export fn entry() void {
7384 \\ const a: u8 = 300;
7385 \\ _ = a;
7386 \\}
7387 , &[_][]const u8{
7388 "tmp.zig:3:19: error: integer value 300 cannot be coerced to type 'u8'",
7389 });
7390
7391 ctx.objErrStage1("declaration with same name as primitive must use special syntax",
7392 \\const u8 = u16;
7393 \\export fn entry() void {
7394 \\ const a: u8 = 300;
7395 \\ _ = a;
7396 \\}
7397 , &[_][]const u8{
7398 "tmp.zig:1:7: error: name shadows primitive 'u8'",
7399 "tmp.zig:1:7: note: consider using @\"u8\" to disambiguate",
7400 });
7401
7402 ctx.objErrStage1("implicitly increasing pointer alignment",
7403 \\const Foo = packed struct {
7404 \\ a: u8,
7405 \\ b: u32,
7406 \\};
7407 \\
7408 \\export fn entry() void {
7409 \\ var foo = Foo { .a = 1, .b = 10 };
7410 \\ bar(&foo.b);
7411 \\}
7412 \\
7413 \\fn bar(x: *u32) void {
7414 \\ x.* += 1;
7415 \\}
7416 , &[_][]const u8{
7417 "tmp.zig:8:13: error: expected type '*u32', found '*align(1) u32'",
7418 });
7419
7420 ctx.objErrStage1("implicitly increasing slice alignment",
7421 \\const Foo = packed struct {
7422 \\ a: u8,
7423 \\ b: u32,
7424 \\};
7425 \\
7426 \\export fn entry() void {
7427 \\ var foo = Foo { .a = 1, .b = 10 };
7428 \\ foo.b += 1;
7429 \\ bar(@as(*[1]u32, &foo.b)[0..]);
7430 \\}
7431 \\
7432 \\fn bar(x: []u32) void {
7433 \\ x[0] += 1;
7434 \\}
7435 , &[_][]const u8{
7436 "tmp.zig:9:26: error: cast increases pointer alignment",
7437 "tmp.zig:9:26: note: '*align(1) u32' has alignment 1",
7438 "tmp.zig:9:26: note: '*[1]u32' has alignment 4",
7439 });
7440
7441 ctx.objErrStage1("increase pointer alignment in @ptrCast",
7442 \\export fn entry() u32 {
7443 \\ var bytes: [4]u8 = [_]u8{0x01, 0x02, 0x03, 0x04};
7444 \\ const ptr = @ptrCast(*u32, &bytes[0]);
7445 \\ return ptr.*;
7446 \\}
7447 , &[_][]const u8{
7448 "tmp.zig:3:17: error: cast increases pointer alignment",
7449 "tmp.zig:3:38: note: '*u8' has alignment 1",
7450 "tmp.zig:3:26: note: '*u32' has alignment 4",
7451 });
7452
7453 ctx.objErrStage1("@alignCast expects pointer or slice",
7454 \\export fn entry() void {
7455 \\ @alignCast(4, @as(u32, 3));
7456 \\}
7457 , &[_][]const u8{
7458 "tmp.zig:2:19: error: expected pointer or slice, found 'u32'",
7459 });
7460
7461 ctx.objErrStage1("passing an under-aligned function pointer",
7462 \\export fn entry() void {
7463 \\ testImplicitlyDecreaseFnAlign(alignedSmall, 1234);
7464 \\}
7465 \\fn testImplicitlyDecreaseFnAlign(ptr: fn () align(8) i32, answer: i32) void {
7466 \\ if (ptr() != answer) unreachable;
7467 \\}
7468 \\fn alignedSmall() align(4) i32 { return 1234; }
7469 , &[_][]const u8{
7470 "tmp.zig:2:35: error: expected type 'fn() align(8) i32', found 'fn() align(4) i32'",
7471 });
7472
7473 ctx.objErrStage1("passing a not-aligned-enough pointer to cmpxchg",
7474 \\const AtomicOrder = @import("std").builtin.AtomicOrder;
7475 \\export fn entry() bool {
7476 \\ var x: i32 align(1) = 1234;
7477 \\ while (!@cmpxchgWeak(i32, &x, 1234, 5678, AtomicOrder.SeqCst, AtomicOrder.SeqCst)) {}
7478 \\ return x == 5678;
7479 \\}
7480 , &[_][]const u8{
7481 "tmp.zig:4:32: error: expected type '*i32', found '*align(1) i32'",
7482 });
7483
7484 ctx.objErrStage1("wrong size to an array literal",
7485 \\comptime {
7486 \\ const array = [2]u8{1, 2, 3};
7487 \\ _ = array;
7488 \\}
7489 , &[_][]const u8{
7490 "tmp.zig:2:31: error: index 2 outside array of size 2",
7491 });
7492
7493 ctx.objErrStage1("wrong pointer coerced to pointer to opaque {}",
7494 \\const Derp = opaque {};
7495 \\extern fn bar(d: *Derp) void;
7496 \\export fn foo() void {
7497 \\ var x = @as(u8, 1);
7498 \\ bar(@ptrCast(*anyopaque, &x));
7499 \\}
7500 , &[_][]const u8{
7501 "tmp.zig:5:9: error: expected type '*Derp', found '*anyopaque'",
7502 });
7503
7504 ctx.objErrStage1("non-const variables of things that require const variables",
7505 \\export fn entry1() void {
7506 \\ var m2 = &2;
7507 \\ _ = m2;
7508 \\}
7509 \\export fn entry2() void {
7510 \\ var a = undefined;
7511 \\ _ = a;
7512 \\}
7513 \\export fn entry3() void {
7514 \\ var b = 1;
7515 \\ _ = b;
7516 \\}
7517 \\export fn entry4() void {
7518 \\ var c = 1.0;
7519 \\ _ = c;
7520 \\}
7521 \\export fn entry5() void {
7522 \\ var d = null;
7523 \\ _ = d;
7524 \\}
7525 \\export fn entry6(opaque_: *Opaque) void {
7526 \\ var e = opaque_.*;
7527 \\ _ = e;
7528 \\}
7529 \\export fn entry7() void {
7530 \\ var f = i32;
7531 \\ _ = f;
7532 \\}
7533 \\export fn entry8() void {
7534 \\ var h = (Foo {}).bar;
7535 \\ _ = h;
7536 \\}
7537 \\const Opaque = opaque {};
7538 \\const Foo = struct {
7539 \\ fn bar(self: *const Foo) void {_ = self;}
7540 \\};
7541 , &[_][]const u8{
7542 "tmp.zig:2:4: error: variable of type '*const comptime_int' must be const or comptime",
7543 "tmp.zig:6:4: error: variable of type '@Type(.Undefined)' must be const or comptime",
7544 "tmp.zig:10:4: error: variable of type 'comptime_int' must be const or comptime",
7545 "tmp.zig:10:4: note: to modify this variable at runtime, it must be given an explicit fixed-size number type",
7546 "tmp.zig:14:4: error: variable of type 'comptime_float' must be const or comptime",
7547 "tmp.zig:14:4: note: to modify this variable at runtime, it must be given an explicit fixed-size number type",
7548 "tmp.zig:18:4: error: variable of type '@Type(.Null)' must be const or comptime",
7549 "tmp.zig:22:4: error: variable of type 'Opaque' not allowed",
7550 "tmp.zig:26:4: error: variable of type 'type' must be const or comptime",
7551 "tmp.zig:30:4: error: variable of type '(bound fn(*const Foo) void)' must be const or comptime",
7552 });
7553
7554 ctx.objErrStage1("variable with type 'noreturn'",
7555 \\export fn entry9() void {
7556 \\ var z: noreturn = return;
7557 \\}
7558 , &[_][]const u8{
7559 "tmp.zig:2:5: error: unreachable code",
7560 "tmp.zig:2:23: note: control flow is diverted here",
7561 });
7562
7563 ctx.objErrStage1("wrong types given to atomic order args in cmpxchg",
7564 \\export fn entry() void {
7565 \\ var x: i32 = 1234;
7566 \\ while (!@cmpxchgWeak(i32, &x, 1234, 5678, @as(u32, 1234), @as(u32, 1234))) {}
7567 \\}
7568 , &[_][]const u8{
7569 "tmp.zig:3:47: error: expected type 'std.builtin.AtomicOrder', found 'u32'",
7570 });
7571
7572 ctx.objErrStage1("wrong types given to @export",
7573 \\fn entry() callconv(.C) void { }
7574 \\comptime {
7575 \\ @export(entry, .{.name = "entry", .linkage = @as(u32, 1234) });
7576 \\}
7577 , &[_][]const u8{
7578 "tmp.zig:3:59: error: expected type 'std.builtin.GlobalLinkage', found 'comptime_int'",
7579 });
7580
7581 ctx.objErrStage1("struct with invalid field",
7582 \\const std = @import("std",);
7583 \\const Allocator = std.mem.Allocator;
7584 \\const ArrayList = std.ArrayList;
7585 \\
7586 \\const HeaderWeight = enum {
7587 \\ H1, H2, H3, H4, H5, H6,
7588 \\};
7589 \\
7590 \\const MdText = ArrayList(u8);
7591 \\
7592 \\const MdNode = union(enum) {
7593 \\ Header: struct {
7594 \\ text: MdText,
7595 \\ weight: HeaderValue,
7596 \\ },
7597 \\};
7598 \\
7599 \\export fn entry() void {
7600 \\ const a = MdNode.Header {
7601 \\ .text = MdText.init(std.testing.allocator),
7602 \\ .weight = HeaderWeight.H1,
7603 \\ };
7604 \\ _ = a;
7605 \\}
7606 , &[_][]const u8{
7607 "tmp.zig:14:17: error: use of undeclared identifier 'HeaderValue'",
7608 });
7609
7610 ctx.objErrStage1("@setAlignStack outside function",
7611 \\comptime {
7612 \\ @setAlignStack(16);
7613 \\}
7614 , &[_][]const u8{
7615 "tmp.zig:2:5: error: @setAlignStack outside function",
7616 });
7617
7618 ctx.objErrStage1("@setAlignStack in naked function",
7619 \\export fn entry() callconv(.Naked) void {
7620 \\ @setAlignStack(16);
7621 \\}
7622 , &[_][]const u8{
7623 "tmp.zig:2:5: error: @setAlignStack in naked function",
7624 });
7625
7626 ctx.objErrStage1("@setAlignStack in inline function",
7627 \\export fn entry() void {
7628 \\ foo();
7629 \\}
7630 \\fn foo() callconv(.Inline) void {
7631 \\ @setAlignStack(16);
7632 \\}
7633 , &[_][]const u8{
7634 "tmp.zig:5:5: error: @setAlignStack in inline function",
7635 });
7636
7637 ctx.objErrStage1("@setAlignStack set twice",
7638 \\export fn entry() void {
7639 \\ @setAlignStack(16);
7640 \\ @setAlignStack(16);
7641 \\}
7642 , &[_][]const u8{
7643 "tmp.zig:3:5: error: alignstack set twice",
7644 "tmp.zig:2:5: note: first set here",
7645 });
7646
7647 ctx.objErrStage1("@setAlignStack too big",
7648 \\export fn entry() void {
7649 \\ @setAlignStack(511 + 1);
7650 \\}
7651 , &[_][]const u8{
7652 "tmp.zig:2:5: error: attempt to @setAlignStack(512); maximum is 256",
7653 });
7654
7655 ctx.objErrStage1("storing runtime value in compile time variable then using it",
7656 \\const Mode = @import("std").builtin.Mode;
7657 \\
7658 \\fn Free(comptime filename: []const u8) TestCase {
7659 \\ return TestCase {
7660 \\ .filename = filename,
7661 \\ .problem_type = ProblemType.Free,
7662 \\ };
7663 \\}
7664 \\
7665 \\fn LibC(comptime filename: []const u8) TestCase {
7666 \\ return TestCase {
7667 \\ .filename = filename,
7668 \\ .problem_type = ProblemType.LinkLibC,
7669 \\ };
7670 \\}
7671 \\
7672 \\const TestCase = struct {
7673 \\ filename: []const u8,
7674 \\ problem_type: ProblemType,
7675 \\};
7676 \\
7677 \\const ProblemType = enum {
7678 \\ Free,
7679 \\ LinkLibC,
7680 \\};
7681 \\
7682 \\export fn entry() void {
7683 \\ const tests = [_]TestCase {
7684 \\ Free("001"),
7685 \\ Free("002"),
7686 \\ LibC("078"),
7687 \\ Free("116"),
7688 \\ Free("117"),
7689 \\ };
7690 \\
7691 \\ for ([_]Mode { Mode.Debug, Mode.ReleaseSafe, Mode.ReleaseFast }) |mode| {
7692 \\ _ = mode;
7693 \\ inline for (tests) |test_case| {
7694 \\ const foo = test_case.filename ++ ".zig";
7695 \\ _ = foo;
7696 \\ }
7697 \\ }
7698 \\}
7699 , &[_][]const u8{
7700 "tmp.zig:38:29: error: cannot store runtime value in compile time variable",
7701 });
7702
7703 ctx.objErrStage1("invalid legacy unicode escape",
7704 \\export fn entry() void {
7705 \\ const a = '\U1234';
7706 \\}
7707 , &[_][]const u8{
7708 "tmp.zig:2:15: error: expected expression, found 'invalid bytes'",
7709 "tmp.zig:2:18: note: invalid byte: '1'",
7710 });
7711
7712 ctx.objErrStage1("invalid empty unicode escape",
7713 \\export fn entry() void {
7714 \\ const a = '\u{}';
7715 \\}
7716 , &[_][]const u8{
7717 "tmp.zig:2:19: error: empty unicode escape sequence",
7718 });
7719
7720 ctx.objErrStage1("non-printable invalid character", "\xff\xfe" ++
7721 "fn foo() bool {\r\n" ++
7722 " return true;\r\n" ++
7723 "}\r\n", &[_][]const u8{
7724 "tmp.zig:1:1: error: expected test, comptime, var decl, or container field, found 'invalid bytes'",
7725 "tmp.zig:1:1: note: invalid byte: '\\xff'",
7726 });
7727
7728 ctx.objErrStage1("non-printable invalid character with escape alternative", "fn foo() bool {\n" ++
7729 "\treturn true;\n" ++
7730 "}\n", &[_][]const u8{
7731 "tmp.zig:2:1: error: invalid character: '\\t'",
7732 });
7733
7734 ctx.objErrStage1("calling var args extern function, passing array instead of pointer",
7735 \\export fn entry() void {
7736 \\ foo("hello".*,);
7737 \\}
7738 \\pub extern fn foo(format: *const u8, ...) void;
7739 , &[_][]const u8{
7740 "tmp.zig:2:16: error: expected type '*const u8', found '[5:0]u8'",
7741 });
7742
7743 ctx.objErrStage1("constant inside comptime function has compile error",
7744 \\const ContextAllocator = MemoryPool(usize);
7745 \\
7746 \\pub fn MemoryPool(comptime T: type) type {
7747 \\ const free_list_t = @compileError("aoeu",);
7748 \\
7749 \\ return struct {
7750 \\ free_list: free_list_t,
7751 \\ };
7752 \\}
7753 \\
7754 \\export fn entry() void {
7755 \\ var allocator: ContextAllocator = undefined;
7756 \\}
7757 , &[_][]const u8{
7758 "tmp.zig:4:5: error: unreachable code",
7759 "tmp.zig:4:25: note: control flow is diverted here",
7760 "tmp.zig:12:9: error: unused local variable",
7761 });
7762
7763 ctx.objErrStage1("specify enum tag type that is too small",
7764 \\const Small = enum (u2) {
7765 \\ One,
7766 \\ Two,
7767 \\ Three,
7768 \\ Four,
7769 \\ Five,
7770 \\};
7771 \\
7772 \\export fn entry() void {
7773 \\ var x = Small.One;
7774 \\ _ = x;
7775 \\}
7776 , &[_][]const u8{
7777 "tmp.zig:6:5: error: enumeration value 4 too large for type 'u2'",
7778 });
7779
7780 ctx.objErrStage1("specify non-integer enum tag type",
7781 \\const Small = enum (f32) {
7782 \\ One,
7783 \\ Two,
7784 \\ Three,
7785 \\};
7786 \\
7787 \\export fn entry() void {
7788 \\ var x = Small.One;
7789 \\ _ = x;
7790 \\}
7791 , &[_][]const u8{
7792 "tmp.zig:1:21: error: expected integer, found 'f32'",
7793 });
7794
7795 ctx.objErrStage1("implicitly casting enum to tag type",
7796 \\const Small = enum(u2) {
7797 \\ One,
7798 \\ Two,
7799 \\ Three,
7800 \\ Four,
7801 \\};
7802 \\
7803 \\export fn entry() void {
7804 \\ var x: u2 = Small.Two;
7805 \\ _ = x;
7806 \\}
7807 , &[_][]const u8{
7808 "tmp.zig:9:22: error: expected type 'u2', found 'Small'",
7809 });
7810
7811 ctx.objErrStage1("explicitly casting non tag type to enum",
7812 \\const Small = enum(u2) {
7813 \\ One,
7814 \\ Two,
7815 \\ Three,
7816 \\ Four,
7817 \\};
7818 \\
7819 \\export fn entry() void {
7820 \\ var y = @as(f32, 3);
7821 \\ var x = @intToEnum(Small, y);
7822 \\ _ = x;
7823 \\}
7824 , &[_][]const u8{
7825 "tmp.zig:10:31: error: expected integer type, found 'f32'",
7826 });
7827
7828 ctx.objErrStage1("union fields with value assignments",
7829 \\const MultipleChoice = union {
7830 \\ A: i32 = 20,
7831 \\};
7832 \\export fn entry() void {
7833 \\ var x: MultipleChoice = undefined;
7834 \\ _ = x;
7835 \\}
7836 , &[_][]const u8{
7837 "tmp.zig:1:24: error: explicitly valued tagged union missing integer tag type",
7838 "tmp.zig:2:14: note: tag value specified here",
7839 });
7840
7841 ctx.objErrStage1("enum with 0 fields",
7842 \\const Foo = enum {};
7843 , &[_][]const u8{
7844 "tmp.zig:1:13: error: enum declarations must have at least one tag",
7845 });
7846
7847 ctx.objErrStage1("union with 0 fields",
7848 \\const Foo = union {};
7849 , &[_][]const u8{
7850 "tmp.zig:1:13: error: union declarations must have at least one tag",
7851 });
7852
7853 ctx.objErrStage1("enum value already taken",
7854 \\const MultipleChoice = enum(u32) {
7855 \\ A = 20,
7856 \\ B = 40,
7857 \\ C = 60,
7858 \\ D = 1000,
7859 \\ E = 60,
7860 \\};
7861 \\export fn entry() void {
7862 \\ var x = MultipleChoice.C;
7863 \\ _ = x;
7864 \\}
7865 , &[_][]const u8{
7866 "tmp.zig:6:5: error: enum tag value 60 already taken",
7867 "tmp.zig:4:5: note: other occurrence here",
7868 });
7869
7870 ctx.objErrStage1("union with specified enum omits field",
7871 \\const Letter = enum {
7872 \\ A,
7873 \\ B,
7874 \\ C,
7875 \\};
7876 \\const Payload = union(Letter) {
7877 \\ A: i32,
7878 \\ B: f64,
7879 \\};
7880 \\export fn entry() usize {
7881 \\ return @sizeOf(Payload);
7882 \\}
7883 , &[_][]const u8{
7884 "tmp.zig:6:17: error: enum field missing: 'C'",
7885 "tmp.zig:4:5: note: declared here",
7886 });
7887
7888 ctx.objErrStage1("non-integer tag type to automatic union enum",
7889 \\const Foo = union(enum(f32)) {
7890 \\ A: i32,
7891 \\};
7892 \\export fn entry() void {
7893 \\ const x = @typeInfo(Foo).Union.tag_type.?;
7894 \\ _ = x;
7895 \\}
7896 , &[_][]const u8{
7897 "tmp.zig:1:24: error: expected integer tag type, found 'f32'",
7898 });
7899
7900 ctx.objErrStage1("non-enum tag type passed to union",
7901 \\const Foo = union(u32) {
7902 \\ A: i32,
7903 \\};
7904 \\export fn entry() void {
7905 \\ const x = @typeInfo(Foo).Union.tag_type.?;
7906 \\ _ = x;
7907 \\}
7908 , &[_][]const u8{
7909 "tmp.zig:1:19: error: expected enum tag type, found 'u32'",
7910 });
7911
7912 ctx.objErrStage1("union auto-enum value already taken",
7913 \\const MultipleChoice = union(enum(u32)) {
7914 \\ A = 20,
7915 \\ B = 40,
7916 \\ C = 60,
7917 \\ D = 1000,
7918 \\ E = 60,
7919 \\};
7920 \\export fn entry() void {
7921 \\ var x = MultipleChoice { .C = {} };
7922 \\ _ = x;
7923 \\}
7924 , &[_][]const u8{
7925 "tmp.zig:6:9: error: enum tag value 60 already taken",
7926 "tmp.zig:4:9: note: other occurrence here",
7927 });
7928
7929 ctx.objErrStage1("union enum field does not match enum",
7930 \\const Letter = enum {
7931 \\ A,
7932 \\ B,
7933 \\ C,
7934 \\};
7935 \\const Payload = union(Letter) {
7936 \\ A: i32,
7937 \\ B: f64,
7938 \\ C: bool,
7939 \\ D: bool,
7940 \\};
7941 \\export fn entry() void {
7942 \\ var a = Payload {.A = 1234};
7943 \\ _ = a;
7944 \\}
7945 , &[_][]const u8{
7946 "tmp.zig:10:5: error: enum field not found: 'D'",
7947 "tmp.zig:1:16: note: enum declared here",
7948 });
7949
7950 ctx.objErrStage1("field type supplied in an enum",
7951 \\const Letter = enum {
7952 \\ A: void,
7953 \\ B,
7954 \\ C,
7955 \\};
7956 , &[_][]const u8{
7957 "tmp.zig:2:8: error: enum fields do not have types",
7958 "tmp.zig:1:16: note: consider 'union(enum)' here to make it a tagged union",
7959 });
7960
7961 ctx.objErrStage1("struct field missing type",
7962 \\const Letter = struct {
7963 \\ A,
7964 \\};
7965 \\export fn entry() void {
7966 \\ var a = Letter { .A = {} };
7967 \\ _ = a;
7968 \\}
7969 , &[_][]const u8{
7970 "tmp.zig:2:5: error: struct field missing type",
7971 });
7972
7973 ctx.objErrStage1("extern union field missing type",
7974 \\const Letter = extern union {
7975 \\ A,
7976 \\};
7977 \\export fn entry() void {
7978 \\ var a = Letter { .A = {} };
7979 \\ _ = a;
7980 \\}
7981 , &[_][]const u8{
7982 "tmp.zig:2:5: error: union field missing type",
7983 });
7984
7985 ctx.objErrStage1("extern union given enum tag type",
7986 \\const Letter = enum {
7987 \\ A,
7988 \\ B,
7989 \\ C,
7990 \\};
7991 \\const Payload = extern union(Letter) {
7992 \\ A: i32,
7993 \\ B: f64,
7994 \\ C: bool,
7995 \\};
7996 \\export fn entry() void {
7997 \\ var a = Payload { .A = 1234 };
7998 \\ _ = a;
7999 \\}
8000 , &[_][]const u8{
8001 "tmp.zig:6:30: error: extern union does not support enum tag type",
8002 });
8003
8004 ctx.objErrStage1("packed union given enum tag type",
8005 \\const Letter = enum {
8006 \\ A,
8007 \\ B,
8008 \\ C,
8009 \\};
8010 \\const Payload = packed union(Letter) {
8011 \\ A: i32,
8012 \\ B: f64,
8013 \\ C: bool,
8014 \\};
8015 \\export fn entry() void {
8016 \\ var a = Payload { .A = 1234 };
8017 \\ _ = a;
8018 \\}
8019 , &[_][]const u8{
8020 "tmp.zig:6:30: error: packed union does not support enum tag type",
8021 });
8022
8023 ctx.objErrStage1("packed union with automatic layout field",
8024 \\const Foo = struct {
8025 \\ a: u32,
8026 \\ b: f32,
8027 \\};
8028 \\const Payload = packed union {
8029 \\ A: Foo,
8030 \\ B: bool,
8031 \\};
8032 \\export fn entry() void {
8033 \\ var a = Payload { .B = true };
8034 \\ _ = a;
8035 \\}
8036 , &[_][]const u8{
8037 "tmp.zig:6:5: error: non-packed, non-extern struct 'Foo' not allowed in packed union; no guaranteed in-memory representation",
8038 });
8039
8040 ctx.objErrStage1("switch on union with no attached enum",
8041 \\const Payload = union {
8042 \\ A: i32,
8043 \\ B: f64,
8044 \\ C: bool,
8045 \\};
8046 \\export fn entry() void {
8047 \\ const a = Payload { .A = 1234 };
8048 \\ foo(a);
8049 \\}
8050 \\fn foo(a: *const Payload) void {
8051 \\ switch (a.*) {
8052 \\ Payload.A => {},
8053 \\ else => unreachable,
8054 \\ }
8055 \\}
8056 , &[_][]const u8{
8057 "tmp.zig:11:14: error: switch on union which has no attached enum",
8058 "tmp.zig:1:17: note: consider 'union(enum)' here",
8059 });
8060
8061 ctx.objErrStage1("enum in field count range but not matching tag",
8062 \\const Foo = enum(u32) {
8063 \\ A = 10,
8064 \\ B = 11,
8065 \\};
8066 \\export fn entry() void {
8067 \\ var x = @intToEnum(Foo, 0);
8068 \\ _ = x;
8069 \\}
8070 , &[_][]const u8{
8071 "tmp.zig:6:13: error: enum 'Foo' has no tag matching integer value 0",
8072 "tmp.zig:1:13: note: 'Foo' declared here",
8073 });
8074
8075 ctx.objErrStage1("comptime cast enum to union but field has payload",
8076 \\const Letter = enum { A, B, C };
8077 \\const Value = union(Letter) {
8078 \\ A: i32,
8079 \\ B,
8080 \\ C,
8081 \\};
8082 \\export fn entry() void {
8083 \\ var x: Value = Letter.A;
8084 \\ _ = x;
8085 \\}
8086 , &[_][]const u8{
8087 "tmp.zig:8:26: error: cast to union 'Value' must initialize 'i32' field 'A'",
8088 "tmp.zig:3:5: note: field 'A' declared here",
8089 });
8090
8091 ctx.objErrStage1("runtime cast to union which has non-void fields",
8092 \\const Letter = enum { A, B, C };
8093 \\const Value = union(Letter) {
8094 \\ A: i32,
8095 \\ B,
8096 \\ C,
8097 \\};
8098 \\export fn entry() void {
8099 \\ foo(Letter.A);
8100 \\}
8101 \\fn foo(l: Letter) void {
8102 \\ var x: Value = l;
8103 \\ _ = x;
8104 \\}
8105 , &[_][]const u8{
8106 "tmp.zig:11:20: error: runtime cast to union 'Value' which has non-void fields",
8107 "tmp.zig:3:5: note: field 'A' has type 'i32'",
8108 });
8109
8110 ctx.objErrStage1("taking byte offset of void field in struct",
8111 \\const Empty = struct {
8112 \\ val: void,
8113 \\};
8114 \\export fn foo() void {
8115 \\ const fieldOffset = @offsetOf(Empty, "val",);
8116 \\ _ = fieldOffset;
8117 \\}
8118 , &[_][]const u8{
8119 "tmp.zig:5:42: error: zero-bit field 'val' in struct 'Empty' has no offset",
8120 });
8121
8122 ctx.objErrStage1("taking bit offset of void field in struct",
8123 \\const Empty = struct {
8124 \\ val: void,
8125 \\};
8126 \\export fn foo() void {
8127 \\ const fieldOffset = @bitOffsetOf(Empty, "val",);
8128 \\ _ = fieldOffset;
8129 \\}
8130 , &[_][]const u8{
8131 "tmp.zig:5:45: error: zero-bit field 'val' in struct 'Empty' has no offset",
8132 });
8133
8134 ctx.objErrStage1("invalid union field access in comptime",
8135 \\const Foo = union {
8136 \\ Bar: u8,
8137 \\ Baz: void,
8138 \\};
8139 \\comptime {
8140 \\ var foo = Foo {.Baz = {}};
8141 \\ const bar_val = foo.Bar;
8142 \\ _ = bar_val;
8143 \\}
8144 , &[_][]const u8{
8145 "tmp.zig:7:24: error: accessing union field 'Bar' while field 'Baz' is set",
8146 });
8147
8148 ctx.objErrStage1("unsupported modifier at start of asm output constraint",
8149 \\export fn foo() void {
8150 \\ var bar: u32 = 3;
8151 \\ asm volatile ("" : [baz]"+r"(bar) : : "");
8152 \\}
8153 , &[_][]const u8{
8154 "tmp.zig:3:5: error: invalid modifier starting output constraint for 'baz': '+', only '=' is supported. Compiler TODO: see https://github.com/ziglang/zig/issues/215",
8155 });
8156
8157 ctx.objErrStage1("comptime_int in asm input",
8158 \\export fn foo() void {
8159 \\ asm volatile ("" : : [bar]"r"(3) : "");
8160 \\}
8161 , &[_][]const u8{
8162 "tmp.zig:2:35: error: expected sized integer or sized float, found comptime_int",
8163 });
8164
8165 ctx.objErrStage1("comptime_float in asm input",
8166 \\export fn foo() void {
8167 \\ asm volatile ("" : : [bar]"r"(3.17) : "");
8168 \\}
8169 , &[_][]const u8{
8170 "tmp.zig:2:35: error: expected sized integer or sized float, found comptime_float",
8171 });
8172
8173 ctx.objErrStage1("runtime assignment to comptime struct type",
8174 \\const Foo = struct {
8175 \\ Bar: u8,
8176 \\ Baz: type,
8177 \\};
8178 \\export fn f() void {
8179 \\ var x: u8 = 0;
8180 \\ const foo = Foo { .Bar = x, .Baz = u8 };
8181 \\ _ = foo;
8182 \\}
8183 , &[_][]const u8{
8184 "tmp.zig:7:23: error: unable to evaluate constant expression",
8185 });
8186
8187 ctx.objErrStage1("runtime assignment to comptime union type",
8188 \\const Foo = union {
8189 \\ Bar: u8,
8190 \\ Baz: type,
8191 \\};
8192 \\export fn f() void {
8193 \\ var x: u8 = 0;
8194 \\ const foo = Foo { .Bar = x };
8195 \\ _ = foo;
8196 \\}
8197 , &[_][]const u8{
8198 "tmp.zig:7:23: error: unable to evaluate constant expression",
8199 });
8200
8201 ctx.testErrStage1("@shuffle with selected index past first vector length",
8202 \\export fn entry() void {
8203 \\ const v: @import("std").meta.Vector(4, u32) = [4]u32{ 10, 11, 12, 13 };
8204 \\ const x: @import("std").meta.Vector(4, u32) = [4]u32{ 14, 15, 16, 17 };
8205 \\ var z = @shuffle(u32, v, x, [8]i32{ 0, 1, 2, 3, 7, 6, 5, 4 });
8206 \\ _ = z;
8207 \\}
8208 , &[_][]const u8{
8209 "tmp.zig:4:39: error: mask index '4' has out-of-bounds selection",
8210 "tmp.zig:4:27: note: selected index '7' out of bounds of @Vector(4, u32)",
8211 "tmp.zig:4:30: note: selections from the second vector are specified with negative numbers",
8212 });
8213
8214 ctx.testErrStage1("nested vectors",
8215 \\export fn entry() void {
8216 \\ const V1 = @import("std").meta.Vector(4, u8);
8217 \\ const V2 = @Type(.{ .Vector = .{ .len = 4, .child = V1 } });
8218 \\ var v: V2 = undefined;
8219 \\ _ = v;
8220 \\}
8221 , &[_][]const u8{
8222 "tmp.zig:3:23: error: vector element type must be integer, float, bool, or pointer; '@Vector(4, u8)' is invalid",
8223 });
8224
8225 ctx.testErrStage1("bad @splat type",
8226 \\export fn entry() void {
8227 \\ const c = 4;
8228 \\ var v = @splat(4, c);
8229 \\ _ = v;
8230 \\}
8231 , &[_][]const u8{
8232 "tmp.zig:3:23: error: vector element type must be integer, float, bool, or pointer; 'comptime_int' is invalid",
8233 });
8234
8235 ctx.objErrStage1("compileLog of tagged enum doesn't crash the compiler",
8236 \\const Bar = union(enum(u32)) {
8237 \\ X: i32 = 1
8238 \\};
8239 \\
8240 \\fn testCompileLog(x: Bar) void {
8241 \\ @compileLog(x);
8242 \\}
8243 \\
8244 \\pub fn main () void {
8245 \\ comptime testCompileLog(Bar{.X = 123});
8246 \\}
8247 , &[_][]const u8{
8248 "tmp.zig:6:5: error: found compile log statement",
8249 });
8250
8251 ctx.objErrStage1("attempted implicit cast from *const T to *[1]T",
8252 \\export fn entry(byte: u8) void {
8253 \\ const w: i32 = 1234;
8254 \\ var x: *const i32 = &w;
8255 \\ var y: *[1]i32 = x;
8256 \\ y[0] += 1;
8257 \\ _ = byte;
8258 \\}
8259 , &[_][]const u8{
8260 "tmp.zig:4:22: error: expected type '*[1]i32', found '*const i32'",
8261 "tmp.zig:4:22: note: cast discards const qualifier",
8262 });
8263
8264 ctx.objErrStage1("attempted implicit cast from *const T to []T",
8265 \\export fn entry() void {
8266 \\ const u: u32 = 42;
8267 \\ const x: []u32 = &u;
8268 \\ _ = x;
8269 \\}
8270 , &[_][]const u8{
8271 "tmp.zig:3:23: error: expected type '[]u32', found '*const u32'",
8272 });
8273
8274 ctx.objErrStage1("for loop body expression ignored",
8275 \\fn returns() usize {
8276 \\ return 2;
8277 \\}
8278 \\export fn f1() void {
8279 \\ for ("hello") |_| returns();
8280 \\}
8281 \\export fn f2() void {
8282 \\ var x: anyerror!i32 = error.Bad;
8283 \\ for ("hello") |_| returns() else unreachable;
8284 \\ _ = x;
8285 \\}
8286 , &[_][]const u8{
8287 "tmp.zig:5:30: error: expression value is ignored",
8288 "tmp.zig:9:30: error: expression value is ignored",
8289 });
8290
8291 ctx.objErrStage1("aligned variable of zero-bit type",
8292 \\export fn f() void {
8293 \\ var s: struct {} align(4) = undefined;
8294 \\ _ = s;
8295 \\}
8296 , &[_][]const u8{
8297 "tmp.zig:2:5: error: variable 's' of zero-bit type 'struct:2:12' has no in-memory representation, it cannot be aligned",
8298 });
8299
8300 ctx.objErrStage1("function returning opaque type",
8301 \\const FooType = opaque {};
8302 \\export fn bar() !FooType {
8303 \\ return error.InvalidValue;
8304 \\}
8305 \\export fn bav() !@TypeOf(null) {
8306 \\ return error.InvalidValue;
8307 \\}
8308 \\export fn baz() !@TypeOf(undefined) {
8309 \\ return error.InvalidValue;
8310 \\}
8311 , &[_][]const u8{
8312 "tmp.zig:2:18: error: Opaque return type 'FooType' not allowed",
8313 "tmp.zig:1:1: note: type declared here",
8314 "tmp.zig:5:18: error: Null return type '@Type(.Null)' not allowed",
8315 "tmp.zig:8:18: error: Undefined return type '@Type(.Undefined)' not allowed",
8316 });
8317
8318 ctx.objErrStage1("generic function returning opaque type",
8319 \\const FooType = opaque {};
8320 \\fn generic(comptime T: type) !T {
8321 \\ return undefined;
8322 \\}
8323 \\export fn bar() void {
8324 \\ _ = generic(FooType);
8325 \\}
8326 \\export fn bav() void {
8327 \\ _ = generic(@TypeOf(null));
8328 \\}
8329 \\export fn baz() void {
8330 \\ _ = generic(@TypeOf(undefined));
8331 \\}
8332 , &[_][]const u8{
8333 "tmp.zig:6:16: error: call to generic function with Opaque return type 'FooType' not allowed",
8334 "tmp.zig:2:1: note: function declared here",
8335 "tmp.zig:1:1: note: type declared here",
8336 "tmp.zig:9:16: error: call to generic function with Null return type '@Type(.Null)' not allowed",
8337 "tmp.zig:2:1: note: function declared here",
8338 "tmp.zig:12:16: error: call to generic function with Undefined return type '@Type(.Undefined)' not allowed",
8339 "tmp.zig:2:1: note: function declared here",
8340 });
8341
8342 ctx.objErrStage1("function parameter is opaque",
8343 \\const FooType = opaque {};
8344 \\export fn entry1() void {
8345 \\ const someFuncPtr: fn (FooType) void = undefined;
8346 \\ _ = someFuncPtr;
8347 \\}
8348 \\
8349 \\export fn entry2() void {
8350 \\ const someFuncPtr: fn (@TypeOf(null)) void = undefined;
8351 \\ _ = someFuncPtr;
8352 \\}
8353 \\
8354 \\fn foo(p: FooType) void {_ = p;}
8355 \\export fn entry3() void {
8356 \\ _ = foo;
8357 \\}
8358 \\
8359 \\fn bar(p: @TypeOf(null)) void {_ = p;}
8360 \\export fn entry4() void {
8361 \\ _ = bar;
8362 \\}
8363 , &[_][]const u8{
8364 "tmp.zig:3:28: error: parameter of opaque type 'FooType' not allowed",
8365 "tmp.zig:8:28: error: parameter of type '@Type(.Null)' not allowed",
8366 "tmp.zig:12:11: error: parameter of opaque type 'FooType' not allowed",
8367 "tmp.zig:17:11: error: parameter of type '@Type(.Null)' not allowed",
8368 });
8369
8370 ctx.objErrStage1( // fixed bug #2032
8371 "compile diagnostic string for top level decl type",
8372 \\export fn entry() void {
8373 \\ var foo: u32 = @This(){};
8374 \\ _ = foo;
8375 \\}
8376 , &[_][]const u8{
8377 "tmp.zig:2:27: error: type 'u32' does not support array initialization",
8378 });
8379
8380 ctx.objErrStage1("issue #2687: coerce from undefined array pointer to slice",
8381 \\export fn foo1() void {
8382 \\ const a: *[1]u8 = undefined;
8383 \\ var b: []u8 = a;
8384 \\ _ = b;
8385 \\}
8386 \\export fn foo2() void {
8387 \\ comptime {
8388 \\ var a: *[1]u8 = undefined;
8389 \\ var b: []u8 = a;
8390 \\ _ = b;
8391 \\ }
8392 \\}
8393 \\export fn foo3() void {
8394 \\ comptime {
8395 \\ const a: *[1]u8 = undefined;
8396 \\ var b: []u8 = a;
8397 \\ _ = b;
8398 \\ }
8399 \\}
8400 , &[_][]const u8{
8401 "tmp.zig:3:19: error: use of undefined value here causes undefined behavior",
8402 "tmp.zig:9:23: error: use of undefined value here causes undefined behavior",
8403 "tmp.zig:16:23: error: use of undefined value here causes undefined behavior",
8404 });
8405320
8406 ctx.objErrStage1("issue #3818: bitcast from parray/slice to u16",321 {
8407 \\export fn foo1() void {322 const case = ctx.obj("multiple files with private member instance function error", .{});
8408 \\ var bytes = [_]u8{1, 2};323 case.backend = .stage1;
8409 \\ const word: u16 = @bitCast(u16, bytes[0..]);
8410 \\ _ = word;
8411 \\}
8412 \\export fn foo2() void {
8413 \\ var bytes: []const u8 = &[_]u8{1, 2};
8414 \\ const word: u16 = @bitCast(u16, bytes);
8415 \\ _ = word;
8416 \\}
8417 , &[_][]const u8{
8418 "tmp.zig:3:42: error: unable to @bitCast from pointer type '*[2]u8'",
8419 "tmp.zig:8:32: error: destination type 'u16' has size 2 but source type '[]const u8' has size 16",
8420 });
8421324
8422 // issue #7810325 case.addSourceFile("foo.zig",
8423 ctx.objErrStage1("comptime slice-len increment beyond bounds",326 \\pub const Foo = struct {
8424 \\export fn foo_slice_len_increment_beyond_bounds() void {327 \\ fn privateFunction(self: *Foo) void { _ = self; }
8425 \\ comptime {328 \\};
8426 \\ var buf_storage: [8]u8 = undefined;329 );
8427 \\ var buf: []const u8 = buf_storage[0..];
8428 \\ buf.len += 1;
8429 \\ buf[8] = 42;
8430 \\ }
8431 \\}
8432 , &[_][]const u8{
8433 ":6:12: error: out of bounds slice",
8434 });
8435330
8436 ctx.objErrStage1("comptime slice-sentinel is out of bounds (unterminated)",331 case.addError(
8437 \\export fn foo_array() void {332 \\const Foo = @import("foo.zig",).Foo;
8438 \\ comptime {333 \\
8439 \\ var target = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;334 \\export fn callPrivFunction() void {
8440 \\ const slice = target[0..14 :0];335 \\ var foo = Foo{};
8441 \\ _ = slice;336 \\ foo.privateFunction();
8442 \\ }337 \\}
8443 \\}338 , &[_][]const u8{
8444 \\export fn foo_ptr_array() void {339 "tmp.zig:5:8: error: 'privateFunction' is private",
8445 \\ comptime {340 "foo.zig:2:5: note: declared here",
8446 \\ var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;341 });
8447 \\ var target = &buf;342 }
8448 \\ const slice = target[0..14 :0];
8449 \\ _ = slice;
8450 \\ }
8451 \\}
8452 \\export fn foo_vector_ConstPtrSpecialBaseArray() void {
8453 \\ comptime {
8454 \\ var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
8455 \\ var target: [*]u8 = &buf;
8456 \\ const slice = target[0..14 :0];
8457 \\ _ = slice;
8458 \\ }
8459 \\}
8460 \\export fn foo_vector_ConstPtrSpecialRef() void {
8461 \\ comptime {
8462 \\ var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
8463 \\ var target: [*]u8 = @ptrCast([*]u8, &buf);
8464 \\ const slice = target[0..14 :0];
8465 \\ _ = slice;
8466 \\ }
8467 \\}
8468 \\export fn foo_cvector_ConstPtrSpecialBaseArray() void {
8469 \\ comptime {
8470 \\ var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
8471 \\ var target: [*c]u8 = &buf;
8472 \\ const slice = target[0..14 :0];
8473 \\ _ = slice;
8474 \\ }
8475 \\}
8476 \\export fn foo_cvector_ConstPtrSpecialRef() void {
8477 \\ comptime {
8478 \\ var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
8479 \\ var target: [*c]u8 = @ptrCast([*c]u8, &buf);
8480 \\ const slice = target[0..14 :0];
8481 \\ _ = slice;
8482 \\ }
8483 \\}
8484 \\export fn foo_slice() void {
8485 \\ comptime {
8486 \\ var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
8487 \\ var target: []u8 = &buf;
8488 \\ const slice = target[0..14 :0];
8489 \\ _ = slice;
8490 \\ }
8491 \\}
8492 , &[_][]const u8{
8493 ":4:29: error: slice-sentinel is out of bounds",
8494 ":12:29: error: slice-sentinel is out of bounds",
8495 ":20:29: error: slice-sentinel is out of bounds",
8496 ":28:29: error: slice-sentinel is out of bounds",
8497 ":36:29: error: slice-sentinel is out of bounds",
8498 ":44:29: error: slice-sentinel is out of bounds",
8499 ":52:29: error: slice-sentinel is out of bounds",
8500 });
8501343
8502 ctx.objErrStage1("comptime slice-sentinel is out of bounds (terminated)",344 {
8503 \\export fn foo_array() void {345 const case = ctx.obj("export collision", .{});
8504 \\ comptime {346 case.backend = .stage1;
8505 \\ var target = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
8506 \\ const slice = target[0..15 :1];
8507 \\ _ = slice;
8508 \\ }
8509 \\}
8510 \\export fn foo_ptr_array() void {
8511 \\ comptime {
8512 \\ var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
8513 \\ var target = &buf;
8514 \\ const slice = target[0..15 :0];
8515 \\ _ = slice;
8516 \\ }
8517 \\}
8518 \\export fn foo_vector_ConstPtrSpecialBaseArray() void {
8519 \\ comptime {
8520 \\ var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
8521 \\ var target: [*]u8 = &buf;
8522 \\ const slice = target[0..15 :0];
8523 \\ _ = slice;
8524 \\ }
8525 \\}
8526 \\export fn foo_vector_ConstPtrSpecialRef() void {
8527 \\ comptime {
8528 \\ var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
8529 \\ var target: [*]u8 = @ptrCast([*]u8, &buf);
8530 \\ const slice = target[0..15 :0];
8531 \\ _ = slice;
8532 \\ }
8533 \\}
8534 \\export fn foo_cvector_ConstPtrSpecialBaseArray() void {
8535 \\ comptime {
8536 \\ var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
8537 \\ var target: [*c]u8 = &buf;
8538 \\ const slice = target[0..15 :0];
8539 \\ _ = slice;
8540 \\ }
8541 \\}
8542 \\export fn foo_cvector_ConstPtrSpecialRef() void {
8543 \\ comptime {
8544 \\ var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
8545 \\ var target: [*c]u8 = @ptrCast([*c]u8, &buf);
8546 \\ const slice = target[0..15 :0];
8547 \\ _ = slice;
8548 \\ }
8549 \\}
8550 \\export fn foo_slice() void {
8551 \\ comptime {
8552 \\ var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
8553 \\ var target: []u8 = &buf;
8554 \\ const slice = target[0..15 :0];
8555 \\ _ = slice;
8556 \\ }
8557 \\}
8558 , &[_][]const u8{
8559 ":4:29: error: out of bounds slice",
8560 ":12:29: error: out of bounds slice",
8561 ":20:29: error: out of bounds slice",
8562 ":28:29: error: out of bounds slice",
8563 ":36:29: error: out of bounds slice",
8564 ":44:29: error: out of bounds slice",
8565 ":52:29: error: out of bounds slice",
8566 });
8567347
8568 ctx.objErrStage1("comptime slice-sentinel does not match memory at target index (unterminated)",348 case.addSourceFile("foo.zig",
8569 \\export fn foo_array() void {349 \\export fn bar() void {}
8570 \\ comptime {350 \\pub const baz = 1234;
8571 \\ var target = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;351 );
8572 \\ const slice = target[0..3 :0];
8573 \\ _ = slice;
8574 \\ }
8575 \\}
8576 \\export fn foo_ptr_array() void {
8577 \\ comptime {
8578 \\ var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
8579 \\ var target = &buf;
8580 \\ const slice = target[0..3 :0];
8581 \\ _ = slice;
8582 \\ }
8583 \\}
8584 \\export fn foo_vector_ConstPtrSpecialBaseArray() void {
8585 \\ comptime {
8586 \\ var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
8587 \\ var target: [*]u8 = &buf;
8588 \\ const slice = target[0..3 :0];
8589 \\ _ = slice;
8590 \\ }
8591 \\}
8592 \\export fn foo_vector_ConstPtrSpecialRef() void {
8593 \\ comptime {
8594 \\ var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
8595 \\ var target: [*]u8 = @ptrCast([*]u8, &buf);
8596 \\ const slice = target[0..3 :0];
8597 \\ _ = slice;
8598 \\ }
8599 \\}
8600 \\export fn foo_cvector_ConstPtrSpecialBaseArray() void {
8601 \\ comptime {
8602 \\ var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
8603 \\ var target: [*c]u8 = &buf;
8604 \\ const slice = target[0..3 :0];
8605 \\ _ = slice;
8606 \\ }
8607 \\}
8608 \\export fn foo_cvector_ConstPtrSpecialRef() void {
8609 \\ comptime {
8610 \\ var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
8611 \\ var target: [*c]u8 = @ptrCast([*c]u8, &buf);
8612 \\ const slice = target[0..3 :0];
8613 \\ _ = slice;
8614 \\ }
8615 \\}
8616 \\export fn foo_slice() void {
8617 \\ comptime {
8618 \\ var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
8619 \\ var target: []u8 = &buf;
8620 \\ const slice = target[0..3 :0];
8621 \\ _ = slice;
8622 \\ }
8623 \\}
8624 , &[_][]const u8{
8625 ":4:29: error: slice-sentinel does not match memory at target index",
8626 ":12:29: error: slice-sentinel does not match memory at target index",
8627 ":20:29: error: slice-sentinel does not match memory at target index",
8628 ":28:29: error: slice-sentinel does not match memory at target index",
8629 ":36:29: error: slice-sentinel does not match memory at target index",
8630 ":44:29: error: slice-sentinel does not match memory at target index",
8631 ":52:29: error: slice-sentinel does not match memory at target index",
8632 });
8633352
8634 ctx.objErrStage1("comptime slice-sentinel does not match memory at target index (terminated)",353 case.addError(
8635 \\export fn foo_array() void {354 \\const foo = @import("foo.zig",);
8636 \\ comptime {355 \\
8637 \\ var target = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;356 \\export fn bar() usize {
8638 \\ const slice = target[0..3 :0];357 \\ return foo.baz;
8639 \\ _ = slice;358 \\}
8640 \\ }359 , &[_][]const u8{
8641 \\}360 "foo.zig:1:1: error: exported symbol collision: 'bar'",
8642 \\export fn foo_ptr_array() void {361 "tmp.zig:3:1: note: other symbol here",
8643 \\ comptime {362 });
8644 \\ var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;363 }
8645 \\ var target = &buf;
8646 \\ const slice = target[0..3 :0];
8647 \\ _ = slice;
8648 \\ }
8649 \\}
8650 \\export fn foo_vector_ConstPtrSpecialBaseArray() void {
8651 \\ comptime {
8652 \\ var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
8653 \\ var target: [*]u8 = &buf;
8654 \\ const slice = target[0..3 :0];
8655 \\ _ = slice;
8656 \\ }
8657 \\}
8658 \\export fn foo_vector_ConstPtrSpecialRef() void {
8659 \\ comptime {
8660 \\ var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
8661 \\ var target: [*]u8 = @ptrCast([*]u8, &buf);
8662 \\ const slice = target[0..3 :0];
8663 \\ _ = slice;
8664 \\ }
8665 \\}
8666 \\export fn foo_cvector_ConstPtrSpecialBaseArray() void {
8667 \\ comptime {
8668 \\ var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
8669 \\ var target: [*c]u8 = &buf;
8670 \\ const slice = target[0..3 :0];
8671 \\ _ = slice;
8672 \\ }
8673 \\}
8674 \\export fn foo_cvector_ConstPtrSpecialRef() void {
8675 \\ comptime {
8676 \\ var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
8677 \\ var target: [*c]u8 = @ptrCast([*c]u8, &buf);
8678 \\ const slice = target[0..3 :0];
8679 \\ _ = slice;
8680 \\ }
8681 \\}
8682 \\export fn foo_slice() void {
8683 \\ comptime {
8684 \\ var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
8685 \\ var target: []u8 = &buf;
8686 \\ const slice = target[0..3 :0];
8687 \\ _ = slice;
8688 \\ }
8689 \\}
8690 , &[_][]const u8{
8691 ":4:29: error: slice-sentinel does not match memory at target index",
8692 ":12:29: error: slice-sentinel does not match memory at target index",
8693 ":20:29: error: slice-sentinel does not match memory at target index",
8694 ":28:29: error: slice-sentinel does not match memory at target index",
8695 ":36:29: error: slice-sentinel does not match memory at target index",
8696 ":44:29: error: slice-sentinel does not match memory at target index",
8697 ":52:29: error: slice-sentinel does not match memory at target index",
8698 });
8699364
8700 ctx.objErrStage1("comptime slice-sentinel does not match target-sentinel",365 ctx.objErrStage1("non-printable invalid character", "\xff\xfe" ++
8701 \\export fn foo_array() void {366 "fn foo() bool {\r\n" ++
8702 \\ comptime {367 " return true;\r\n" ++
8703 \\ var target = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;368 "}\r\n", &[_][]const u8{
8704 \\ const slice = target[0..14 :255];369 "tmp.zig:1:1: error: expected test, comptime, var decl, or container field, found 'invalid bytes'",
8705 \\ _ = slice;370 "tmp.zig:1:1: note: invalid byte: '\\xff'",
8706 \\ }
8707 \\}
8708 \\export fn foo_ptr_array() void {
8709 \\ comptime {
8710 \\ var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
8711 \\ var target = &buf;
8712 \\ const slice = target[0..14 :255];
8713 \\ _ = slice;
8714 \\ }
8715 \\}
8716 \\export fn foo_vector_ConstPtrSpecialBaseArray() void {
8717 \\ comptime {
8718 \\ var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
8719 \\ var target: [*]u8 = &buf;
8720 \\ const slice = target[0..14 :255];
8721 \\ _ = slice;
8722 \\ }
8723 \\}
8724 \\export fn foo_vector_ConstPtrSpecialRef() void {
8725 \\ comptime {
8726 \\ var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
8727 \\ var target: [*]u8 = @ptrCast([*]u8, &buf);
8728 \\ const slice = target[0..14 :255];
8729 \\ _ = slice;
8730 \\ }
8731 \\}
8732 \\export fn foo_cvector_ConstPtrSpecialBaseArray() void {
8733 \\ comptime {
8734 \\ var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
8735 \\ var target: [*c]u8 = &buf;
8736 \\ const slice = target[0..14 :255];
8737 \\ _ = slice;
8738 \\ }
8739 \\}
8740 \\export fn foo_cvector_ConstPtrSpecialRef() void {
8741 \\ comptime {
8742 \\ var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
8743 \\ var target: [*c]u8 = @ptrCast([*c]u8, &buf);
8744 \\ const slice = target[0..14 :255];
8745 \\ _ = slice;
8746 \\ }
8747 \\}
8748 \\export fn foo_slice() void {
8749 \\ comptime {
8750 \\ var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
8751 \\ var target: []u8 = &buf;
8752 \\ const slice = target[0..14 :255];
8753 \\ _ = slice;
8754 \\ }
8755 \\}
8756 , &[_][]const u8{
8757 ":4:29: error: slice-sentinel does not match target-sentinel",
8758 ":12:29: error: slice-sentinel does not match target-sentinel",
8759 ":20:29: error: slice-sentinel does not match target-sentinel",
8760 ":28:29: error: slice-sentinel does not match target-sentinel",
8761 ":36:29: error: slice-sentinel does not match target-sentinel",
8762 ":44:29: error: slice-sentinel does not match target-sentinel",
8763 ":52:29: error: slice-sentinel does not match target-sentinel",
8764 });371 });
8765372
8766 ctx.objErrStage1("issue #4207: coerce from non-terminated-slice to terminated-pointer",373 ctx.objErrStage1("non-printable invalid character with escape alternative", "fn foo() bool {\n" ++
8767 \\export fn foo() [*:0]const u8 {374 "\treturn true;\n" ++
8768 \\ var buffer: [64]u8 = undefined;375 "}\n", &[_][]const u8{
8769 \\ return buffer[0..];376 "tmp.zig:2:1: error: invalid character: '\\t'",
8770 \\}
8771 , &[_][]const u8{
8772 ":3:18: error: expected type '[*:0]const u8', found '*[64]u8'",
8773 ":3:18: note: destination pointer requires a terminating '0' sentinel",
8774 });377 });
8775378
8776 ctx.objErrStage1("issue #5221: invalid struct init type referenced by @typeInfo and passed into function",379 // TODO test this in stage2, but we won't even try in stage1
8777 \\fn ignore(comptime param: anytype) void {_ = param;}380 //ctx.objErrStage1("inline fn calls itself indirectly",
8778 \\381 // \\export fn foo() void {
8779 \\export fn foo() void {382 // \\ bar();
8780 \\ const MyStruct = struct {383 // \\}
8781 \\ wrong_type: []u8 = "foo",384 // \\fn bar() callconv(.Inline) void {
8782 \\ };385 // \\ baz();
8783 \\386 // \\ quux();
8784 \\ comptime ignore(@typeInfo(MyStruct).Struct.fields[0]);387 // \\}
8785 \\}388 // \\fn baz() callconv(.Inline) void {
8786 , &[_][]const u8{389 // \\ bar();
8787 ":5:28: error: cannot cast pointer to array literal to slice type '[]u8'",390 // \\ quux();
8788 ":5:28: note: cast discards const qualifier",391 // \\}
8789 });392 // \\extern fn quux() void;
393 //, &[_][]const u8{
394 // "tmp.zig:4:1: error: unable to inline function",
395 //});
8790396
8791 ctx.objErrStage1("integer underflow error",397 //ctx.objErrStage1("save reference to inline function",
8792 \\export fn entry() void {398 // \\export fn foo() void {
8793 \\ _ = @intToPtr(*anyopaque, ~@as(usize, @import("std").math.maxInt(usize)) - 1);399 // \\ quux(@ptrToInt(bar));
8794 \\}400 // \\}
8795 , &[_][]const u8{401 // \\fn bar() callconv(.Inline) void { }
8796 ":2:78: error: operation caused overflow",402 // \\extern fn quux(usize) void;
8797 });403 //, &[_][]const u8{
404 // "tmp.zig:4:1: error: unable to inline function",
405 //});
8798406
8799 {407 {
8800 const case = ctx.obj("align(N) expr function pointers is a compile error", .{408 const case = ctx.obj("align(N) expr function pointers is a compile error", .{
...@@ -8812,165 +420,4 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -8812,165 +420,4 @@ pub fn addCases(ctx: *TestContext) !void {
8812 "tmp.zig:1:23: error: align(N) expr is not allowed on function prototypes in wasm32/wasm64",420 "tmp.zig:1:23: error: align(N) expr is not allowed on function prototypes in wasm32/wasm64",
8813 });421 });
8814 }422 }
8815
8816 ctx.objErrStage1("compare optional to non-optional with invalid types",
8817 \\export fn inconsistentChildType() void {
8818 \\ var x: ?i32 = undefined;
8819 \\ const y: comptime_int = 10;
8820 \\ _ = (x == y);
8821 \\}
8822 \\
8823 \\export fn optionalToOptional() void {
8824 \\ var x: ?i32 = undefined;
8825 \\ var y: ?i32 = undefined;
8826 \\ _ = (x == y);
8827 \\}
8828 \\
8829 \\export fn optionalVector() void {
8830 \\ var x: ?@Vector(10, i32) = undefined;
8831 \\ var y: @Vector(10, i32) = undefined;
8832 \\ _ = (x == y);
8833 \\}
8834 \\
8835 \\export fn invalidChildType() void {
8836 \\ var x: ?[3]i32 = undefined;
8837 \\ var y: [3]i32 = undefined;
8838 \\ _ = (x == y);
8839 \\}
8840 , &[_][]const u8{
8841 ":4:12: error: cannot compare types '?i32' and 'comptime_int'",
8842 ":4:12: note: optional child type 'i32' must be the same as non-optional type 'comptime_int'",
8843 ":10:12: error: cannot compare types '?i32' and '?i32'",
8844 ":10:12: note: optional to optional comparison is only supported for optional pointer types",
8845 ":16:12: error: TODO add comparison of optional vector",
8846 ":22:12: error: cannot compare types '?[3]i32' and '[3]i32'",
8847 ":22:12: note: operator not supported for type '[3]i32'",
8848 });
8849
8850 ctx.objErrStage1("slice cannot have its bytes reinterpreted",
8851 \\export fn foo() void {
8852 \\ const bytes = [1]u8{ 0xfa } ** 16;
8853 \\ var value = @ptrCast(*const []const u8, &bytes).*;
8854 \\ _ = value;
8855 \\}
8856 , &[_][]const u8{
8857 ":3:52: error: slice '[]const u8' cannot have its bytes reinterpreted",
8858 });
8859
8860 ctx.objErrStage1("wasmMemorySize is a compile error in non-Wasm targets",
8861 \\export fn foo() void {
8862 \\ _ = @wasmMemorySize(0);
8863 \\ return;
8864 \\}
8865 , &[_][]const u8{
8866 "tmp.zig:2:9: error: @wasmMemorySize is a wasm32 feature only",
8867 });
8868
8869 ctx.objErrStage1("wasmMemoryGrow is a compile error in non-Wasm targets",
8870 \\export fn foo() void {
8871 \\ _ = @wasmMemoryGrow(0, 1);
8872 \\ return;
8873 \\}
8874 , &[_][]const u8{
8875 "tmp.zig:2:9: error: @wasmMemoryGrow is a wasm32 feature only",
8876 });
8877 ctx.objErrStage1("Issue #5586: Make unary minus for unsigned types a compile error",
8878 \\export fn f1(x: u32) u32 {
8879 \\ const y = -%x;
8880 \\ return -y;
8881 \\}
8882 \\const V = @import("std").meta.Vector;
8883 \\export fn f2(x: V(4, u32)) V(4, u32) {
8884 \\ const y = -%x;
8885 \\ return -y;
8886 \\}
8887 , &[_][]const u8{
8888 "tmp.zig:3:12: error: negation of type 'u32'",
8889 "tmp.zig:8:12: error: negation of type 'u32'",
8890 });
8891
8892 ctx.objErrStage1("Issue #5618: coercion of ?*anyopaque to *anyopaque must fail.",
8893 \\export fn foo() void {
8894 \\ var u: ?*anyopaque = null;
8895 \\ var v: *anyopaque = undefined;
8896 \\ v = u;
8897 \\}
8898 , &[_][]const u8{
8899 "tmp.zig:4:9: error: cannot convert optional to payload type. consider using `.?`, `orelse`, or `if`. expected type '*anyopaque', found '?*anyopaque'",
8900 });
8901
8902 ctx.objErrStage1("Issue #6823: don't allow .* to be followed by **",
8903 \\fn foo() void {
8904 \\ var sequence = "repeat".*** 10;
8905 \\ _ = sequence;
8906 \\}
8907 , &[_][]const u8{
8908 // Ideally this would be column 30 but it's not very important.
8909 "tmp.zig:2:28: error: '.*' cannot be followed by '*'. Are you missing a space?",
8910 });
8911
8912 ctx.objErrStage1("Issue #9165: windows tcp server compilation error",
8913 \\const std = @import("std");
8914 \\const builtin = @import("builtin");
8915 \\pub const io_mode = .evented;
8916 \\pub fn main() !void {
8917 \\ if (builtin.os.tag == .windows) {
8918 \\ _ = try (std.net.StreamServer.init(.{})).accept();
8919 \\ } else {
8920 \\ @compileError("Unsupported OS");
8921 \\ }
8922 \\}
8923 , &[_][]const u8{
8924 "error: Unsupported OS",
8925 });
8926
8927 ctx.objErrStage1("attempt to close over comptime variable from outer scope",
8928 \\fn SimpleList(comptime L: usize) type {
8929 \\ var T = u8;
8930 \\ return struct {
8931 \\ array: [L]T,
8932 \\ };
8933 \\}
8934 , &[_][]const u8{
8935 "tmp.zig:4:19: error: mutable 'T' not accessible from here",
8936 "tmp.zig:2:9: note: declared mutable here",
8937 "tmp.zig:3:12: note: crosses namespace boundary here",
8938 });
8939
8940 ctx.objErrStage1("saturating arithmetic does not allow floats",
8941 \\export fn a() void {
8942 \\ _ = @as(f32, 1.0) +| @as(f32, 1.0);
8943 \\}
8944 , &[_][]const u8{
8945 "error: invalid operands to binary expression: 'f32' and 'f32'",
8946 });
8947
8948 ctx.objErrStage1("saturating shl does not allow negative rhs at comptime",
8949 \\export fn a() void {
8950 \\ _ = @as(i32, 1) <<| @as(i32, -2);
8951 \\}
8952 , &[_][]const u8{
8953 "error: shift by negative value -2",
8954 });
8955
8956 ctx.objErrStage1("saturating shl assign does not allow negative rhs at comptime",
8957 \\export fn a() void {
8958 \\ comptime {
8959 \\ var x = @as(i32, 1);
8960 \\ x <<|= @as(i32, -2);
8961 \\ }
8962 \\}
8963 , &[_][]const u8{
8964 "error: shift by negative value -2",
8965 });
8966
8967 ctx.objErrStage1("undeclared identifier in unanalyzed branch",
8968 \\export fn a() void {
8969 \\ if (false) {
8970 \\ lol_this_doesnt_exist = nonsense;
8971 \\ }
8972 \\}
8973 , &[_][]const u8{
8974 "tmp.zig:3:9: error: use of undeclared identifier 'lol_this_doesnt_exist'",
8975 });
8976}423}
test/compile_errors/stage1/exe/main_missing_name.zig created+5
...@@ -0,0 +1,5 @@
1pub fn (main) void {}
2
3// main missing name
4//
5// tmp.zig:1:5: error: missing function name
test/compile_errors/stage1/exe/missing_main_fn_in_executable.zig created+5
...@@ -0,0 +1,5 @@
1
2
3// missing main fn in executable
4//
5// error: root source file has no member called 'main'
test/compile_errors/stage1/exe/private_main_fn.zig created+6
...@@ -0,0 +1,6 @@
1fn main() void {}
2
3// private main fn
4//
5// error: 'main' is private
6// tmp.zig:1:1: note: declared here
test/compile_errors/stage1/exe/std.fmt_error_for_unused_arguments.zig created+7
...@@ -0,0 +1,7 @@
1pub fn main() !void {
2 @import("std").debug.print("{d} {d} {d} {d} {d}", .{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15});
3}
4
5// std.fmt error for unused arguments
6//
7// ?:?:?: error: 10 unused arguments in '{d} {d} {d} {d} {d}'
test/compile_errors/stage1/obj/C_pointer_pointing_to_non_C_ABI_compatible_type_or_has_align_attr.zig created+10
...@@ -0,0 +1,10 @@
1const Foo = struct {};
2export fn a() void {
3 const T = [*c]Foo;
4 var t: T = undefined;
5 _ = t;
6}
7
8// C pointer pointing to non C ABI compatible type or has align attr
9//
10// tmp.zig:3:19: error: C pointers cannot point to non-C-ABI-compatible type 'Foo'
test/compile_errors/stage1/obj/C_pointer_to_anyopaque.zig created+9
...@@ -0,0 +1,9 @@
1export fn a() void {
2 var x: *anyopaque = undefined;
3 var y: [*c]anyopaque = x;
4 _ = y;
5}
6
7// C pointer to anyopaque
8//
9// tmp.zig:3:16: error: C pointers cannot point to opaque types
test/compile_errors/stage1/obj/Frame_of_generic_function.zig created+12
...@@ -0,0 +1,12 @@
1export fn entry() void {
2 var frame: @Frame(func) = undefined;
3 _ = frame;
4}
5fn func(comptime T: type) void {
6 var x: T = undefined;
7 _ = x;
8}
9
10// @Frame() of generic function
11//
12// tmp.zig:2:16: error: @Frame() of generic function
test/compile_errors/stage1/obj/Issue_5586_Make_unary_minus_for_unsigned_types_a_compile_error.zig created+14
...@@ -0,0 +1,14 @@
1export fn f1(x: u32) u32 {
2 const y = -%x;
3 return -y;
4}
5const V = @import("std").meta.Vector;
6export fn f2(x: V(4, u32)) V(4, u32) {
7 const y = -%x;
8 return -y;
9}
10
11// Issue #5586: Make unary minus for unsigned types a compile error
12//
13// tmp.zig:3:12: error: negation of type 'u32'
14// tmp.zig:8:12: error: negation of type 'u32'
test/compile_errors/stage1/obj/Issue_6823_dont_allow_._to_be_followed_by_.zig created+8
...@@ -0,0 +1,8 @@
1fn foo() void {
2 var sequence = "repeat".*** 10;
3 _ = sequence;
4}
5
6// Issue #6823: don't allow .* to be followed by **
7//
8// tmp.zig:2:28: error: '.*' cannot be followed by '*'. Are you missing a space?
test/compile_errors/stage1/obj/Issue_9165_windows_tcp_server_compilation_error.zig created+14
...@@ -0,0 +1,14 @@
1const std = @import("std");
2const builtin = @import("builtin");
3pub const io_mode = .evented;
4pub fn main() !void {
5 if (builtin.os.tag == .windows) {
6 _ = try (std.net.StreamServer.init(.{})).accept();
7 } else {
8 @compileError("Unsupported OS");
9 }
10}
11
12// Issue #9165: windows tcp server compilation error
13//
14// error: Unsupported OS
test/compile_errors/stage1/obj/access_non-existent_member_of_error_set.zig created+9
...@@ -0,0 +1,9 @@
1const Foo = error{A};
2comptime {
3 const z = Foo.Bar;
4 _ = z;
5}
6
7// access non-existent member of error set
8//
9// tmp.zig:3:18: error: no error named 'Bar' in 'Foo'
test/compile_errors/stage1/obj/accessing_runtime_parameter_from_outer_function.zig created+19
...@@ -0,0 +1,19 @@
1fn outer(y: u32) fn (u32) u32 {
2 const st = struct {
3 fn get(z: u32) u32 {
4 return z + y;
5 }
6 };
7 return st.get;
8}
9export fn entry() void {
10 var func = outer(10);
11 var x = func(3);
12 _ = x;
13}
14
15// accessing runtime parameter from outer function
16//
17// tmp.zig:4:24: error: 'y' not accessible from inner function
18// tmp.zig:3:28: note: crossed function definition here
19// tmp.zig:1:10: note: declared here
test/compile_errors/stage1/obj/add_assign_on_undefined_value.zig created+8
...@@ -0,0 +1,8 @@
1comptime {
2 var a: i64 = undefined;
3 a += a;
4}
5
6// add assign on undefined value
7//
8// tmp.zig:3:5: error: use of undefined value here causes undefined behavior
test/compile_errors/stage1/obj/add_on_undefined_value.zig created+8
...@@ -0,0 +1,8 @@
1comptime {
2 var a: i64 = undefined;
3 _ = a + a;
4}
5
6// add on undefined value
7//
8// tmp.zig:3:9: error: use of undefined value here causes undefined behavior
test/compile_errors/stage1/obj/add_overflow_in_function_evaluation.zig created+10
...@@ -0,0 +1,10 @@
1const y = add(65530, 10);
2fn add(a: u16, b: u16) u16 {
3 return a + b;
4}
5
6export fn entry() usize { return @sizeOf(@TypeOf(y)); }
7
8// add overflow in function evaluation
9//
10// tmp.zig:3:14: error: operation caused overflow
test/compile_errors/stage1/obj/add_wrap_assign_on_undefined_value.zig created+8
...@@ -0,0 +1,8 @@
1comptime {
2 var a: i64 = undefined;
3 a +%= a;
4}
5
6// add wrap assign on undefined value
7//
8// tmp.zig:3:5: error: use of undefined value here causes undefined behavior
test/compile_errors/stage1/obj/add_wrap_on_undefined_value.zig created+8
...@@ -0,0 +1,8 @@
1comptime {
2 var a: i64 = undefined;
3 _ = a +% a;
4}
5
6// add wrap on undefined value
7//
8// tmp.zig:3:9: error: use of undefined value here causes undefined behavior
test/compile_errors/stage1/obj/addition_with_non_numbers.zig created+10
...@@ -0,0 +1,10 @@
1const Foo = struct {
2 field: i32,
3};
4const x = Foo {.field = 1} + Foo {.field = 2};
5
6export fn entry() usize { return @sizeOf(@TypeOf(x)); }
7
8// addition with non numbers
9//
10// tmp.zig:4:28: error: invalid operands to binary expression: 'Foo' and 'Foo'
test/compile_errors/stage1/obj/address_of_number_literal.zig created+8
...@@ -0,0 +1,8 @@
1const x = 3;
2const y = &x;
3fn foo() *const i32 { return y; }
4export fn entry() usize { return @sizeOf(@TypeOf(foo)); }
5
6// address of number literal
7//
8// tmp.zig:3:30: error: expected type '*const i32', found '*const comptime_int'
test/compile_errors/stage1/obj/alignCast_expects_pointer_or_slice.zig created+7
...@@ -0,0 +1,7 @@
1export fn entry() void {
2 @alignCast(4, @as(u32, 3));
3}
4
5// @alignCast expects pointer or slice
6//
7// tmp.zig:2:19: error: expected pointer or slice, found 'u32'
test/compile_errors/stage1/obj/aligned_variable_of_zero-bit_type.zig created+8
...@@ -0,0 +1,8 @@
1export fn f() void {
2 var s: struct {} align(4) = undefined;
3 _ = s;
4}
5
6// aligned variable of zero-bit type
7//
8// tmp.zig:2:5: error: variable 's' of zero-bit type 'struct:2:12' has no in-memory representation, it cannot be aligned
test/compile_errors/stage1/obj/alignment_of_enum_field_specified.zig created+12
...@@ -0,0 +1,12 @@
1const Number = enum {
2 a,
3 b align(i32),
4};
5export fn entry1() void {
6 var x: Number = undefined;
7 _ = x;
8}
9
10// alignment of enum field specified
11//
12// tmp.zig:3:7: error: expected ',' after field
test/compile_errors/stage1/obj/ambiguous_decl_reference.zig created+19
...@@ -0,0 +1,19 @@
1fn foo() void {}
2fn bar() void {
3 const S = struct {
4 fn baz() void {
5 foo();
6 }
7 fn foo() void {}
8 };
9 S.baz();
10}
11export fn entry() void {
12 bar();
13}
14
15// ambiguous decl reference
16//
17// tmp.zig:5:13: error: ambiguous reference
18// tmp.zig:7:9: note: declared here
19// tmp.zig:1:1: note: also declared here
test/compile_errors/stage1/obj/and_on_undefined_value.zig created+8
...@@ -0,0 +1,8 @@
1comptime {
2 var a: bool = undefined;
3 _ = a and a;
4}
5
6// and on undefined value
7//
8// tmp.zig:3:9: error: use of undefined value here causes undefined behavior
test/compile_errors/stage1/obj/array_access_of_non_array.zig created+13
...@@ -0,0 +1,13 @@
1export fn f() void {
2 var bad : bool = undefined;
3 bad[0] = bad[0];
4}
5export fn g() void {
6 var bad : bool = undefined;
7 _ = bad[0];
8}
9
10// array access of non array
11//
12// tmp.zig:3:8: error: array access of non-array type 'bool'
13// tmp.zig:7:12: error: array access of non-array type 'bool'
test/compile_errors/stage1/obj/array_access_of_type.zig created+8
...@@ -0,0 +1,8 @@
1export fn foo() void {
2 var b: u8[40] = undefined;
3 _ = b;
4}
5
6// array access of type
7//
8// tmp.zig:2:14: error: array access of non-array type 'type'
test/compile_errors/stage1/obj/array_access_of_undeclared_identifier.zig created+7
...@@ -0,0 +1,7 @@
1export fn f() void {
2 i[i] = i[i];
3}
4
5// array access of undeclared identifier
6//
7// tmp.zig:2:5: error: use of undeclared identifier 'i'
test/compile_errors/stage1/obj/array_access_with_non_integer_index.zig created+15
...@@ -0,0 +1,15 @@
1export fn f() void {
2 var array = "aoeu";
3 var bad = false;
4 array[bad] = array[bad];
5}
6export fn g() void {
7 var array = "aoeu";
8 var bad = false;
9 _ = array[bad];
10}
11
12// array access with non integer index
13//
14// tmp.zig:4:11: error: expected type 'usize', found 'bool'
15// tmp.zig:9:15: error: expected type 'usize', found 'bool'
test/compile_errors/stage1/obj/array_concatenation_with_wrong_type.zig created+9
...@@ -0,0 +1,9 @@
1const src = "aoeu";
2const derp: usize = 1234;
3const a = derp ++ "foo";
4
5export fn entry() usize { return @sizeOf(@TypeOf(a)); }
6
7// array concatenation with wrong type
8//
9// tmp.zig:3:11: error: expected array, found 'usize'
test/compile_errors/stage1/obj/array_in_c_exported_function.zig created+12
...@@ -0,0 +1,12 @@
1export fn zig_array(x: [10]u8) void {
2 try std.testing.expect(std.mem.eql(u8, &x, "1234567890"));
3}
4const std = @import("std");
5export fn zig_return_array() [10]u8 {
6 return "1234567890".*;
7}
8
9// array in c exported function
10//
11// tmp.zig:1:24: error: parameter of type '[10]u8' not allowed in function with calling convention 'C'
12// tmp.zig:5:30: error: return type '[10]u8' not allowed in function with calling convention 'C'
test/compile_errors/stage1/obj/asm_at_compile_time.zig created+15
...@@ -0,0 +1,15 @@
1comptime {
2 doSomeAsm();
3}
4
5fn doSomeAsm() void {
6 asm volatile (
7 \\.globl aoeu;
8 \\.type aoeu, @function;
9 \\.set aoeu, derp;
10 );
11}
12
13// asm at compile time
14//
15// tmp.zig:6:5: error: unable to evaluate constant expression
test/compile_errors/stage1/obj/assign_inline_fn_to_non-comptime_var.zig created+10
...@@ -0,0 +1,10 @@
1export fn entry() void {
2 var a = b;
3 _ = a;
4}
5fn b() callconv(.Inline) void { }
6
7// assign inline fn to non-comptime var
8//
9// tmp.zig:2:5: error: functions marked inline must be stored in const or comptime var
10// tmp.zig:5:1: note: declared here
test/compile_errors/stage1/obj/assign_null_to_non-optional_pointer.zig created+7
...@@ -0,0 +1,7 @@
1const a: *u8 = null;
2
3export fn entry() usize { return @sizeOf(@TypeOf(a)); }
4
5// assign null to non-optional pointer
6//
7// tmp.zig:1:16: error: expected type '*u8', found '@Type(.Null)'
test/compile_errors/stage1/obj/assign_through_constant_pointer.zig created+8
...@@ -0,0 +1,8 @@
1export fn f() void {
2 var cstr = "Hat";
3 cstr[0] = 'W';
4}
5
6// assign through constant pointer
7//
8// tmp.zig:3:13: error: cannot assign to constant
test/compile_errors/stage1/obj/assign_through_constant_slice.zig created+8
...@@ -0,0 +1,8 @@
1export fn f() void {
2 var cstr: []const u8 = "Hat";
3 cstr[0] = 'W';
4}
5
6// assign through constant slice
7//
8// tmp.zig:3:13: error: cannot assign to constant
test/compile_errors/stage1/obj/assign_to_constant_field.zig created+11
...@@ -0,0 +1,11 @@
1const Foo = struct {
2 field: i32,
3};
4export fn derp() void {
5 const f = Foo {.field = 1234,};
6 f.field = 0;
7}
8
9// assign to constant field
10//
11// tmp.zig:6:15: error: cannot assign to constant
test/compile_errors/stage1/obj/assign_to_constant_variable.zig created+8
...@@ -0,0 +1,8 @@
1export fn f() void {
2 const a = 3;
3 a = 4;
4}
5
6// assign to constant variable
7//
8// tmp.zig:3:9: error: cannot assign to constant
test/compile_errors/stage1/obj/assign_to_invalid_dereference.zig created+7
...@@ -0,0 +1,7 @@
1export fn entry() void {
2 'a'.* = 1;
3}
4
5// assign to invalid dereference
6//
7// tmp.zig:2:8: error: attempt to dereference non-pointer type 'comptime_int'
test/compile_errors/stage1/obj/assign_too_big_number_to_u16.zig created+8
...@@ -0,0 +1,8 @@
1export fn foo() void {
2 var vga_mem: u16 = 0xB8000;
3 _ = vga_mem;
4}
5
6// assign too big number to u16
7//
8// tmp.zig:2:24: error: integer value 753664 cannot be coerced to type 'u16'
test/compile_errors/stage1/obj/assign_unreachable.zig created+8
...@@ -0,0 +1,8 @@
1export fn f() void {
2 const a = return;
3}
4
5// assign unreachable
6//
7// tmp.zig:2:5: error: unreachable code
8// tmp.zig:2:15: note: control flow is diverted here
test/compile_errors/stage1/obj/assigning_to_struct_or_union_fields_that_are_not_optionals_with_a_function_that_returns_an_optional.zig created+19
...@@ -0,0 +1,19 @@
1fn maybe(is: bool) ?u8 {
2 if (is) return @as(u8, 10) else return null;
3}
4const U = union {
5 Ye: u8,
6};
7const S = struct {
8 num: u8,
9};
10export fn entry() void {
11 var u = U{ .Ye = maybe(false) };
12 var s = S{ .num = maybe(false) };
13 _ = u;
14 _ = s;
15}
16
17// assigning to struct or union fields that are not optionals with a function that returns an optional
18//
19// tmp.zig:11:27: error: cannot convert optional to payload type. consider using `.?`, `orelse`, or `if`. expected type 'u8', found '?u8'
test/compile_errors/stage1/obj/async_function_depends_on_its_own_frame.zig created+11
...@@ -0,0 +1,11 @@
1export fn entry() void {
2 _ = async amain();
3}
4fn amain() callconv(.Async) void {
5 var x: [@sizeOf(@Frame(amain))]u8 = undefined;
6 _ = x;
7}
8
9// async function depends on its own frame
10//
11// tmp.zig:4:1: error: cannot resolve '@Frame(amain)': function not fully analyzed yet
test/compile_errors/stage1/obj/async_function_indirectly_depends_on_its_own_frame.zig created+15
...@@ -0,0 +1,15 @@
1export fn entry() void {
2 _ = async amain();
3}
4fn amain() callconv(.Async) void {
5 other();
6}
7fn other() void {
8 var x: [@sizeOf(@Frame(amain))]u8 = undefined;
9 _ = x;
10}
11
12// async function indirectly depends on its own frame
13//
14// tmp.zig:4:1: error: unable to determine async function frame of 'amain'
15// tmp.zig:5:10: note: analysis of function 'other' depends on the frame
test/compile_errors/stage1/obj/atomic_orderings_of_atomicStore_Acquire_or_AcqRel.zig created+8
...@@ -0,0 +1,8 @@
1export fn entry() void {
2 var x: u32 = 0;
3 @atomicStore(u32, &x, 1, .Acquire);
4}
5
6// atomic orderings of atomicStore Acquire or AcqRel
7//
8// tmp.zig:3:30: error: @atomicStore atomic ordering must not be Acquire or AcqRel
test/compile_errors/stage1/obj/atomic_orderings_of_cmpxchg-failure_stricter_than_success.zig created+9
...@@ -0,0 +1,9 @@
1const AtomicOrder = @import("std").builtin.AtomicOrder;
2export fn f() void {
3 var x: i32 = 1234;
4 while (!@cmpxchgWeak(i32, &x, 1234, 5678, AtomicOrder.Monotonic, AtomicOrder.SeqCst)) {}
5}
6
7// atomic orderings of cmpxchg - failure stricter than success
8//
9// tmp.zig:4:81: error: failure atomic ordering must be no stricter than success
test/compile_errors/stage1/obj/atomic_orderings_of_cmpxchg-success_Monotonic_or_stricter.zig created+9
...@@ -0,0 +1,9 @@
1const AtomicOrder = @import("std").builtin.AtomicOrder;
2export fn f() void {
3 var x: i32 = 1234;
4 while (!@cmpxchgWeak(i32, &x, 1234, 5678, AtomicOrder.Unordered, AtomicOrder.Unordered)) {}
5}
6
7// atomic orderings of cmpxchg - success Monotonic or stricter
8//
9// tmp.zig:4:58: error: success atomic ordering must be Monotonic or stricter
test/compile_errors/stage1/obj/atomic_orderings_of_fence_Acquire_or_stricter.zig created+7
...@@ -0,0 +1,7 @@
1export fn entry() void {
2 @fence(.Monotonic);
3}
4
5// atomic orderings of fence Acquire or stricter
6//
7// tmp.zig:2:12: error: atomic ordering must be Acquire or stricter
test/compile_errors/stage1/obj/atomicrmw_with_bool_op_not_.Xchg.zig created+8
...@@ -0,0 +1,8 @@
1export fn entry() void {
2 var x = false;
3 _ = @atomicRmw(bool, &x, .Add, true, .SeqCst);
4}
5
6// atomicrmw with bool op not .Xchg
7//
8// tmp.zig:3:30: error: @atomicRmw with bool only allowed with .Xchg
test/compile_errors/stage1/obj/atomicrmw_with_enum_op_not_.Xchg.zig created+14
...@@ -0,0 +1,14 @@
1export fn entry() void {
2 const E = enum(u8) {
3 a,
4 b,
5 c,
6 d,
7 };
8 var x: E = .a;
9 _ = @atomicRmw(E, &x, .Add, .b, .SeqCst);
10}
11
12// atomicrmw with enum op not .Xchg
13//
14// tmp.zig:9:27: error: @atomicRmw with enum only allowed with .Xchg
test/compile_errors/stage1/obj/atomicrmw_with_float_op_not_.Xchg_.Add_or_.Sub.zig created+8
...@@ -0,0 +1,8 @@
1export fn entry() void {
2 var x: f32 = 0;
3 _ = @atomicRmw(f32, &x, .And, 2, .SeqCst);
4}
5
6// atomicrmw with float op not .Xchg, .Add or .Sub
7//
8// tmp.zig:3:29: error: @atomicRmw with float only allowed with .Xchg, .Add and .Sub
test/compile_errors/stage1/obj/attempt_to_cast_enum_literal_to_error.zig created+9
...@@ -0,0 +1,9 @@
1export fn entry() void {
2 switch (error.Hi) {
3 .Hi => {},
4 }
5}
6
7// attempt to cast enum literal to error
8//
9// tmp.zig:3:9: error: expected type 'error{Hi}', found '@Type(.EnumLiteral)'
test/compile_errors/stage1/obj/attempt_to_close_over_comptime_variable_from_outer_scope.zig created+12
...@@ -0,0 +1,12 @@
1fn SimpleList(comptime L: usize) type {
2 var T = u8;
3 return struct {
4 array: [L]T,
5 };
6}
7
8// attempt to close over comptime variable from outer scope
9//
10// tmp.zig:4:19: error: mutable 'T' not accessible from here
11// tmp.zig:2:9: note: declared mutable here
12// tmp.zig:3:12: note: crosses namespace boundary here
test/compile_errors/stage1/obj/attempt_to_create_17_bit_float_type.zig created+8
...@@ -0,0 +1,8 @@
1const builtin = @import("std").builtin;
2comptime {
3 _ = @Type(.{ .Float = .{ .bits = 17 } });
4}
5
6// attempt to create 17 bit float type
7//
8// tmp.zig:3:16: error: 17-bit float unsupported
test/compile_errors/stage1/obj/attempt_to_negate_a_non-integer_non-float_or_non-vector_type.zig created+12
...@@ -0,0 +1,12 @@
1fn foo() anyerror!u32 {
2 return 1;
3}
4
5export fn entry() void {
6 const x = -foo();
7 _ = x;
8}
9
10// attempt to negate a non-integer, non-float or non-vector type
11//
12// tmp.zig:6:15: error: negation of type 'anyerror!u32'
test/compile_errors/stage1/obj/attempt_to_use_0_bit_type_in_extern_fn.zig created+15
...@@ -0,0 +1,15 @@
1extern fn foo(ptr: fn(*void) callconv(.C) void) void;
2
3export fn entry() void {
4 foo(bar);
5}
6
7fn bar(x: *void) callconv(.C) void { _ = x; }
8export fn entry2() void {
9 bar(&{});
10}
11
12// attempt to use 0 bit type in extern fn
13//
14// tmp.zig:1:23: error: parameter of type '*void' has 0 bits; not allowed in function with calling convention 'C'
15// tmp.zig:7:11: error: parameter of type '*void' has 0 bits; not allowed in function with calling convention 'C'
test/compile_errors/stage1/obj/attempted_double_ampersand.zig created+10
...@@ -0,0 +1,10 @@
1export fn entry(a: bool, b: bool) i32 {
2 if (a && b) {
3 return 1234;
4 }
5 return 5678;
6}
7
8// attempted `&&`
9//
10// tmp.zig:2:11: error: ambiguous use of '&&'; use 'and' for logical AND, or change whitespace to ' & &' for bitwise AND
test/compile_errors/stage1/obj/attempted_double_pipe_on_boolean_values.zig created+11
...@@ -0,0 +1,11 @@
1export fn entry(a: bool, b: bool) i32 {
2 if (a || b) {
3 return 1234;
4 }
5 return 5678;
6}
7
8// attempted `||` on boolean values
9//
10// tmp.zig:2:9: error: expected error set type, found 'bool'
11// tmp.zig:2:11: note: `||` merges error sets; `or` performs boolean OR
test/compile_errors/stage1/obj/attempted_implicit_cast_from_T_to_slice_const_T.zig created+8
...@@ -0,0 +1,8 @@
1export fn entry() void {
2 const x: [*]const bool = true;
3 _ = x;
4}
5
6// attempted implicit cast from T to [*]const T
7//
8// tmp.zig:2:30: error: expected type '[*]const bool', found 'bool'
test/compile_errors/stage1/obj/attempted_implicit_cast_from_const_T_to_array_len_1_T.zig created+12
...@@ -0,0 +1,12 @@
1export fn entry(byte: u8) void {
2 const w: i32 = 1234;
3 var x: *const i32 = &w;
4 var y: *[1]i32 = x;
5 y[0] += 1;
6 _ = byte;
7}
8
9// attempted implicit cast from *const T to *[1]T
10//
11// tmp.zig:4:22: error: expected type '*[1]i32', found '*const i32'
12// tmp.zig:4:22: note: cast discards const qualifier
test/compile_errors/stage1/obj/attempted_implicit_cast_from_const_T_to_sliceT.zig created+9
...@@ -0,0 +1,9 @@
1export fn entry() void {
2 const u: u32 = 42;
3 const x: []u32 = &u;
4 _ = x;
5}
6
7// attempted implicit cast from *const T to []T
8//
9// tmp.zig:3:23: error: expected type '[]u32', found '*const u32'
test/compile_errors/stage1/obj/bad_alignCast_at_comptime.zig created+9
...@@ -0,0 +1,9 @@
1comptime {
2 const ptr = @intToPtr(*align(1) i32, 0x1);
3 const aligned = @alignCast(4, ptr);
4 _ = aligned;
5}
6
7// bad @alignCast at comptime
8//
9// tmp.zig:3:35: error: pointer address 0x1 is not aligned to 4 bytes
test/compile_errors/stage1/obj/bad_alignment_in_implicit_cast_from_array_pointer_to_slice.zig created+9
...@@ -0,0 +1,9 @@
1export fn a() void {
2 var x: [10]u8 = undefined;
3 var y: []align(16) u8 = &x;
4 _ = y;
5}
6
7// bad alignment in implicit cast from array pointer to slice
8//
9// tmp.zig:3:30: error: expected type '[]align(16) u8', found '*[10]u8'
test/compile_errors/stage1/obj/bad_alignment_type.zig created+13
...@@ -0,0 +1,13 @@
1export fn entry1() void {
2 var x: []align(true) i32 = undefined;
3 _ = x;
4}
5export fn entry2() void {
6 var x: *align(@as(f64, 12.34)) i32 = undefined;
7 _ = x;
8}
9
10// bad alignment type
11//
12// tmp.zig:2:20: error: expected type 'u29', found 'bool'
13// tmp.zig:6:19: error: fractional component prevents float value 12.340000 from being casted to type 'u29'
test/compile_errors/stage1/obj/bad_identifier_in_function_with_struct_defined_inside_function_which_references_local_const.zig created+15
...@@ -0,0 +1,15 @@
1export fn entry() void {
2 const BlockKind = u32;
3
4 const Block = struct {
5 kind: BlockKind,
6 };
7
8 bogus;
9
10 _ = Block;
11}
12
13// bad identifier in function with struct defined inside function which references local const
14//
15// tmp.zig:8:5: error: use of undeclared identifier 'bogus'
test/compile_errors/stage1/obj/bad_import.zig created+5
...@@ -0,0 +1,5 @@
1const bogus = @import("bogus-does-not-exist.zig",);
2
3// bad import
4//
5// tmp.zig:1:23: error: unable to load '${DIR}bogus-does-not-exist.zig': FileNotFound
test/compile_errors/stage1/obj/bad_usage_of_call.zig created+28
...@@ -0,0 +1,28 @@
1export fn entry1() void {
2 @call(.{}, foo, {});
3}
4export fn entry2() void {
5 comptime @call(.{ .modifier = .never_inline }, foo, .{});
6}
7export fn entry3() void {
8 comptime @call(.{ .modifier = .never_tail }, foo, .{});
9}
10export fn entry4() void {
11 @call(.{ .modifier = .never_inline }, bar, .{});
12}
13export fn entry5(c: bool) void {
14 var baz = if (c) baz1 else baz2;
15 @call(.{ .modifier = .compile_time }, baz, .{});
16}
17fn foo() void {}
18fn bar() callconv(.Inline) void {}
19fn baz1() void {}
20fn baz2() void {}
21
22// bad usage of @call
23//
24// tmp.zig:2:21: error: expected tuple or struct, found 'void'
25// tmp.zig:5:14: error: unable to perform 'never_inline' call at compile-time
26// tmp.zig:8:14: error: unable to perform 'never_tail' call at compile-time
27// tmp.zig:11:5: error: no-inline call of inline function
28// tmp.zig:15:5: error: the specified modifier requires a comptime-known function
test/compile_errors/stage1/obj/bin_and_assign_on_undefined_value.zig created+8
...@@ -0,0 +1,8 @@
1comptime {
2 var a: i64 = undefined;
3 a &= a;
4}
5
6// bin and assign on undefined value
7//
8// tmp.zig:3:5: error: use of undefined value here causes undefined behavior
test/compile_errors/stage1/obj/bin_and_on_undefined_value.zig created+8
...@@ -0,0 +1,8 @@
1comptime {
2 var a: i64 = undefined;
3 _ = a & a;
4}
5
6// bin and on undefined value
7//
8// tmp.zig:3:9: error: use of undefined value here causes undefined behavior
test/compile_errors/stage1/obj/bin_not_on_undefined_value.zig created+8
...@@ -0,0 +1,8 @@
1comptime {
2 var a: i64 = undefined;
3 _ = ~a;
4}
5
6// bin not on undefined value
7//
8// tmp.zig:3:10: error: use of undefined value here causes undefined behavior
test/compile_errors/stage1/obj/bin_or_assign_on_undefined_value.zig created+8
...@@ -0,0 +1,8 @@
1comptime {
2 var a: i64 = undefined;
3 a |= a;
4}
5
6// bin or assign on undefined value
7//
8// tmp.zig:3:5: error: use of undefined value here causes undefined behavior
test/compile_errors/stage1/obj/bin_or_on_undefined_value.zig created+8
...@@ -0,0 +1,8 @@
1comptime {
2 var a: i64 = undefined;
3 _ = a | a;
4}
5
6// bin or on undefined value
7//
8// tmp.zig:3:9: error: use of undefined value here causes undefined behavior
test/compile_errors/stage1/obj/bin_xor_assign_on_undefined_value.zig created+8
...@@ -0,0 +1,8 @@
1comptime {
2 var a: i64 = undefined;
3 a ^= a;
4}
5
6// bin xor assign on undefined value
7//
8// tmp.zig:3:5: error: use of undefined value here causes undefined behavior
test/compile_errors/stage1/obj/bin_xor_on_undefined_value.zig created+8
...@@ -0,0 +1,8 @@
1comptime {
2 var a: i64 = undefined;
3 _ = a ^ a;
4}
5
6// bin xor on undefined value
7//
8// tmp.zig:3:9: error: use of undefined value here causes undefined behavior
test/compile_errors/stage1/obj/binary_not_on_number_literal.zig created+9
...@@ -0,0 +1,9 @@
1const TINY_QUANTUM_SHIFT = 4;
2const TINY_QUANTUM_SIZE = 1 << TINY_QUANTUM_SHIFT;
3var block_aligned_stuff: usize = (4 + TINY_QUANTUM_SIZE) & ~(TINY_QUANTUM_SIZE - 1);
4
5export fn entry() usize { return @sizeOf(@TypeOf(block_aligned_stuff)); }
6
7// binary not on number literal
8//
9// tmp.zig:3:60: error: unable to perform binary not operation on type 'comptime_int'
test/compile_errors/stage1/obj/bitCast_same_size_but_bit_count_mismatch.zig created+8
...@@ -0,0 +1,8 @@
1export fn entry(byte: u8) void {
2 var oops = @bitCast(u7, byte);
3 _ = oops;
4}
5
6// @bitCast same size but bit count mismatch
7//
8// tmp.zig:2:25: error: destination type 'u7' has 7 bits but source type 'u8' has 8 bits
test/compile_errors/stage1/obj/bitCast_to_enum_type.zig created+8
...@@ -0,0 +1,8 @@
1export fn entry() void {
2 const y = @bitCast(enum(u32) { a, b }, @as(u32, 3));
3 _ = y;
4}
5
6// bitCast to enum type
7//
8// tmp.zig:2:24: error: cannot cast a value of type 'y'
test/compile_errors/stage1/obj/bitCast_with_different_sizes_inside_an_expression.zig created+8
...@@ -0,0 +1,8 @@
1export fn entry() void {
2 var foo = (@bitCast(u8, @as(f32, 1.0)) == 0xf);
3 _ = foo;
4}
5
6// @bitCast with different sizes inside an expression
7//
8// tmp.zig:2:25: error: destination type 'u8' has size 1 but source type 'f32' has size 4
test/compile_errors/stage1/obj/bit_shifting_only_works_on_integer_types.zig created+8
...@@ -0,0 +1,8 @@
1export fn entry() void {
2 const x = &@as(u8, 1) << 10;
3 _ = x;
4}
5
6// bit shifting only works on integer types
7//
8// tmp.zig:2:16: error: bit shifting operation expected integer type, found '*const u8'
test/compile_errors/stage1/obj/bogus_compile_var.zig created+6
...@@ -0,0 +1,6 @@
1const x = @import("builtin").bogus;
2export fn entry() usize { return @sizeOf(@TypeOf(x)); }
3
4// bogus compile var
5//
6// tmp.zig:1:29: error: container 'builtin' has no member called 'bogus'
test/compile_errors/stage1/obj/bogus_method_call_on_slice.zig created+9
...@@ -0,0 +1,9 @@
1var self = "aoeu";
2fn f(m: []const u8) void {
3 m.copy(u8, self[0..], m);
4}
5export fn entry() usize { return @sizeOf(@TypeOf(f)); }
6
7// bogus method call on slice
8//
9// tmp.zig:3:6: error: no member named 'copy' in '[]const u8'
test/compile_errors/stage1/obj/bool_not_on_undefined_value.zig created+8
...@@ -0,0 +1,8 @@
1comptime {
2 var a: bool = undefined;
3 _ = !a;
4}
5
6// bool not on undefined value
7//
8// tmp.zig:3:10: error: use of undefined value here causes undefined behavior
test/compile_errors/stage1/obj/branch_on_undefined_value.zig created+7
...@@ -0,0 +1,7 @@
1const x = if (undefined) true else false;
2
3export fn entry() usize { return @sizeOf(@TypeOf(x)); }
4
5// branch on undefined value
6//
7// tmp.zig:1:15: error: use of undefined value here causes undefined behavior
test/compile_errors/stage1/obj/cImport_with_bogus_include.zig created+7
...@@ -0,0 +1,7 @@
1const c = @cImport(@cInclude("bogus.h"));
2export fn entry() usize { return @sizeOf(@TypeOf(c.bogo)); }
3
4// @cImport with bogus include
5//
6// tmp.zig:1:11: error: C import failed
7// .h:1:10: note: 'bogus.h' file not found
test/compile_errors/stage1/obj/call_assigned_to_constant.zig created+22
...@@ -0,0 +1,22 @@
1const Foo = struct {
2 x: i32,
3};
4fn foo() Foo {
5 return .{ .x = 42 };
6}
7fn bar(val: anytype) Foo {
8 return .{ .x = val };
9}
10export fn entry() void {
11 const baz: Foo = undefined;
12 baz = foo();
13}
14export fn entry1() void {
15 const baz: Foo = undefined;
16 baz = bar(42);
17}
18
19// call assigned to constant
20//
21// tmp.zig:12:14: error: cannot assign to constant
22// tmp.zig:16:14: error: cannot assign to constant
test/compile_errors/stage1/obj/calling_a_generic_function_only_known_at_runtime.zig created+12
...@@ -0,0 +1,12 @@
1var foos = [_]fn(anytype) void { foo1, foo2 };
2
3fn foo1(arg: anytype) void {_ = arg;}
4fn foo2(arg: anytype) void {_ = arg;}
5
6pub fn main() !void {
7 foos[0](true);
8}
9
10// calling a generic function only known at runtime
11//
12// tmp.zig:7:9: error: calling a generic function requires compile-time known function value
test/compile_errors/stage1/obj/calling_function_with_naked_calling_convention.zig created+9
...@@ -0,0 +1,9 @@
1export fn entry() void {
2 foo();
3}
4fn foo() callconv(.Naked) void { }
5
6// calling function with naked calling convention
7//
8// tmp.zig:2:5: error: unable to call function with naked calling convention
9// tmp.zig:4:1: note: declared here
test/compile_errors/stage1/obj/calling_var_args_extern_function_passing_array_instead_of_pointer.zig created+8
...@@ -0,0 +1,8 @@
1export fn entry() void {
2 foo("hello".*,);
3}
4pub extern fn foo(format: *const u8, ...) void;
5
6// calling var args extern function, passing array instead of pointer
7//
8// tmp.zig:2:16: error: expected type '*const u8', found '[5:0]u8'
test/compile_errors/stage1/obj/cannot_break_out_of_defer_expression.zig created+11
...@@ -0,0 +1,11 @@
1export fn foo() void {
2 while (true) {
3 defer {
4 break;
5 }
6 }
7}
8
9// cannot break out of defer expression
10//
11// tmp.zig:4:13: error: cannot break out of defer expression
test/compile_errors/stage1/obj/cannot_continue_out_of_defer_expression.zig created+11
...@@ -0,0 +1,11 @@
1export fn foo() void {
2 while (true) {
3 defer {
4 continue;
5 }
6 }
7}
8
9// cannot continue out of defer expression
10//
11// tmp.zig:4:13: error: cannot continue out of defer expression
test/compile_errors/stage1/obj/capture_group_on_switch_prong_with_incompatible_payload_types.zig created+19
...@@ -0,0 +1,19 @@
1const Union = union(enum) {
2 A: usize,
3 B: isize,
4};
5comptime {
6 var u = Union{ .A = 8 };
7 switch (u) {
8 .A, .B => |e| {
9 _ = e;
10 unreachable;
11 },
12 }
13}
14
15// capture group on switch prong with incompatible payload types
16//
17// tmp.zig:8:20: error: capture group with incompatible types
18// tmp.zig:8:9: note: type 'usize' here
19// tmp.zig:8:13: note: type 'isize' here
test/compile_errors/stage1/obj/cast_enum_literal_to_enum_but_it_doesnt_match.zig created+13
...@@ -0,0 +1,13 @@
1const Foo = enum {
2 a,
3 b,
4};
5export fn entry() void {
6 const x: Foo = .c;
7 _ = x;
8}
9
10// cast enum literal to enum but it doesn't match
11//
12// tmp.zig:6:20: error: enum 'Foo' has no field named 'c'
13// tmp.zig:1:13: note: 'Foo' declared here
test/compile_errors/stage1/obj/cast_error_union_of_global_error_set_to_error_union_of_smaller_error_set.zig created+14
...@@ -0,0 +1,14 @@
1const SmallErrorSet = error{A};
2export fn entry() void {
3 var x: SmallErrorSet!i32 = foo();
4 _ = x;
5}
6fn foo() anyerror!i32 {
7 return error.B;
8}
9
10// cast error union of global error set to error union of smaller error set
11//
12// tmp.zig:3:35: error: expected type 'SmallErrorSet!i32', found 'anyerror!i32'
13// tmp.zig:3:35: note: error set 'anyerror' cannot cast into error set 'SmallErrorSet'
14// tmp.zig:3:35: note: cannot cast global error set into smaller set
test/compile_errors/stage1/obj/cast_global_error_set_to_error_set.zig created+13
...@@ -0,0 +1,13 @@
1const SmallErrorSet = error{A};
2export fn entry() void {
3 var x: SmallErrorSet = foo();
4 _ = x;
5}
6fn foo() anyerror {
7 return error.B;
8}
9
10// cast global error set to error set
11//
12// tmp.zig:3:31: error: expected type 'SmallErrorSet', found 'anyerror'
13// tmp.zig:3:31: note: cannot cast global error set into smaller set
test/compile_errors/stage1/obj/cast_negative_integer_literal_to_usize.zig created+8
...@@ -0,0 +1,8 @@
1export fn entry() void {
2 const x = @as(usize, -10);
3 _ = x;
4}
5
6// cast negative integer literal to usize
7//
8// tmp.zig:2:26: error: cannot cast negative value -10 to unsigned integer type 'usize'
test/compile_errors/stage1/obj/cast_negative_value_to_unsigned_integer.zig created+15
...@@ -0,0 +1,15 @@
1comptime {
2 const value: i32 = -1;
3 const unsigned = @intCast(u32, value);
4 _ = unsigned;
5}
6export fn entry1() void {
7 const value: i32 = -1;
8 const unsigned: u32 = value;
9 _ = unsigned;
10}
11
12// cast negative value to unsigned integer
13//
14// tmp.zig:3:22: error: attempt to cast negative value to unsigned integer
15// tmp.zig:8:27: error: cannot cast negative value -1 to unsigned integer type 'u32'
test/compile_errors/stage1/obj/cast_unreachable.zig created+9
...@@ -0,0 +1,9 @@
1fn f() i32 {
2 return @as(i32, return 1);
3}
4export fn entry() void { _ = f(); }
5
6// cast unreachable
7//
8// tmp.zig:2:12: error: unreachable code
9// tmp.zig:2:21: note: control flow is diverted here
test/compile_errors/stage1/obj/casting_bit_offset_pointer_to_regular_pointer.zig created+19
...@@ -0,0 +1,19 @@
1const BitField = packed struct {
2 a: u3,
3 b: u3,
4 c: u2,
5};
6
7fn foo(bit_field: *const BitField) u3 {
8 return bar(&bit_field.b);
9}
10
11fn bar(x: *const u3) u3 {
12 return x.*;
13}
14
15export fn entry() usize { return @sizeOf(@TypeOf(foo)); }
16
17// casting bit offset pointer to regular pointer
18//
19// tmp.zig:8:26: error: expected type '*const u3', found '*align(:3:1) const u3'
test/compile_errors/stage1/obj/catch_on_undefined_value.zig created+8
...@@ -0,0 +1,8 @@
1comptime {
2 var a: anyerror!bool = undefined;
3 _ = a catch false;
4}
5
6// catch on undefined value
7//
8// tmp.zig:3:11: error: use of undefined value here causes undefined behavior
test/compile_errors/stage1/obj/chained_comparison_operators.zig created+7
...@@ -0,0 +1,7 @@
1export fn a(value: u32) bool {
2 return 1 < value < 1000;
3}
4
5// chained comparison operators
6//
7// tmp.zig:2:22: error: comparison operators cannot be chained
test/compile_errors/stage1/obj/cmpxchg_with_float.zig created+8
...@@ -0,0 +1,8 @@
1export fn entry() void {
2 var x: f32 = 0;
3 _ = @cmpxchgWeak(f32, &x, 1, 2, .SeqCst, .SeqCst);
4}
5
6// cmpxchg with float
7//
8// tmp.zig:3:22: error: expected bool, integer, enum or pointer type, found 'f32'
test/compile_errors/stage1/obj/colliding_invalid_top_level_functions.zig created+8
...@@ -0,0 +1,8 @@
1fn func() bogus {}
2fn func() bogus {}
3export fn entry() usize { return @sizeOf(@TypeOf(func)); }
4
5// colliding invalid top level functions
6//
7// tmp.zig:2:1: error: redeclaration of 'func'
8// tmp.zig:1:1: note: other declaration here
test/compile_errors/stage1/obj/compare_optional_to_non-optional_with_invalid_types.zig created+33
...@@ -0,0 +1,33 @@
1export fn inconsistentChildType() void {
2 var x: ?i32 = undefined;
3 const y: comptime_int = 10;
4 _ = (x == y);
5}
6
7export fn optionalToOptional() void {
8 var x: ?i32 = undefined;
9 var y: ?i32 = undefined;
10 _ = (x == y);
11}
12
13export fn optionalVector() void {
14 var x: ?@Vector(10, i32) = undefined;
15 var y: @Vector(10, i32) = undefined;
16 _ = (x == y);
17}
18
19export fn invalidChildType() void {
20 var x: ?[3]i32 = undefined;
21 var y: [3]i32 = undefined;
22 _ = (x == y);
23}
24
25// compare optional to non-optional with invalid types
26//
27// :4:12: error: cannot compare types '?i32' and 'comptime_int'
28// :4:12: note: optional child type 'i32' must be the same as non-optional type 'comptime_int'
29// :10:12: error: cannot compare types '?i32' and '?i32'
30// :10:12: note: optional to optional comparison is only supported for optional pointer types
31// :16:12: error: TODO add comparison of optional vector
32// :22:12: error: cannot compare types '?[3]i32' and '[3]i32'
33// :22:12: note: operator not supported for type '[3]i32'
test/compile_errors/stage1/obj/comparing_a_non-optional_pointer_against_null.zig created+8
...@@ -0,0 +1,8 @@
1export fn entry() void {
2 var x: i32 = 1;
3 _ = &x == null;
4}
5
6// comparing a non-optional pointer against null
7//
8// tmp.zig:3:12: error: comparison of '*i32' with null
test/compile_errors/stage1/obj/comparing_against_undefined_produces_undefined_value.zig created+7
...@@ -0,0 +1,7 @@
1export fn entry() void {
2 if (2 == undefined) {}
3}
4
5// comparing against undefined produces undefined value
6//
7// tmp.zig:2:11: error: use of undefined value here causes undefined behavior
test/compile_errors/stage1/obj/comparison_operators_with_undefined_value.zig created+45
...@@ -0,0 +1,45 @@
1// operator ==
2comptime {
3 var a: i64 = undefined;
4 var x: i32 = 0;
5 if (a == a) x += 1;
6}
7// operator !=
8comptime {
9 var a: i64 = undefined;
10 var x: i32 = 0;
11 if (a != a) x += 1;
12}
13// operator >
14comptime {
15 var a: i64 = undefined;
16 var x: i32 = 0;
17 if (a > a) x += 1;
18}
19// operator <
20comptime {
21 var a: i64 = undefined;
22 var x: i32 = 0;
23 if (a < a) x += 1;
24}
25// operator >=
26comptime {
27 var a: i64 = undefined;
28 var x: i32 = 0;
29 if (a >= a) x += 1;
30}
31// operator <=
32comptime {
33 var a: i64 = undefined;
34 var x: i32 = 0;
35 if (a <= a) x += 1;
36}
37
38// comparison operators with undefined value
39//
40// tmp.zig:5:11: error: use of undefined value here causes undefined behavior
41// tmp.zig:11:11: error: use of undefined value here causes undefined behavior
42// tmp.zig:17:11: error: use of undefined value here causes undefined behavior
43// tmp.zig:23:11: error: use of undefined value here causes undefined behavior
44// tmp.zig:29:11: error: use of undefined value here causes undefined behavior
45// tmp.zig:35:11: error: use of undefined value here causes undefined behavior
test/compile_errors/stage1/obj/comparison_with_error_union_and_error_value.zig created+8
...@@ -0,0 +1,8 @@
1export fn entry() void {
2 var number_or_error: anyerror!i32 = error.SomethingAwful;
3 _ = number_or_error == error.SomethingAwful;
4}
5
6// comparison with error union and error value
7//
8// tmp.zig:3:25: error: operator not allowed for type 'anyerror!i32'
test/compile_errors/stage1/obj/compile-time_division_by_zero.zig created+10
...@@ -0,0 +1,10 @@
1comptime {
2 const a: i32 = 1;
3 const b: i32 = 0;
4 const c = a / b;
5 _ = c;
6}
7
8// compile-time division by zero
9//
10// tmp.zig:4:17: error: division by zero
test/compile_errors/stage1/obj/compile-time_remainder_division_by_zero.zig created+10
...@@ -0,0 +1,10 @@
1comptime {
2 const a: i32 = 1;
3 const b: i32 = 0;
4 const c = a % b;
5 _ = c;
6}
7
8// compile-time remainder division by zero
9//
10// tmp.zig:4:17: error: division by zero
test/compile_errors/stage1/obj/compileError_shows_traceback_of_references_that_caused_it.zig created+12
...@@ -0,0 +1,12 @@
1const foo = @compileError("aoeu",);
2
3const bar = baz + foo;
4const baz = 1;
5
6export fn entry() i32 {
7 return bar;
8}
9
10// @compileError shows traceback of references that caused it
11//
12// tmp.zig:1:13: error: aoeu
test/compile_errors/stage1/obj/compileLog_of_tagged_enum_doesnt_crash_the_compiler.zig created+15
...@@ -0,0 +1,15 @@
1const Bar = union(enum(u32)) {
2 X: i32 = 1
3};
4
5fn testCompileLog(x: Bar) void {
6 @compileLog(x);
7}
8
9pub fn main () void {
10 comptime testCompileLog(Bar{.X = 123});
11}
12
13// compileLog of tagged enum doesn't crash the compiler
14//
15// tmp.zig:6:5: error: found compile log statement
test/compile_errors/stage1/obj/compile_error_in_struct_init_expression.zig created+14
...@@ -0,0 +1,14 @@
1const Foo = struct {
2 a: i32 = crap,
3 b: i32,
4};
5export fn entry() void {
6 var x = Foo{
7 .b = 5,
8 };
9 _ = x;
10}
11
12// compile error in struct init expression
13//
14// tmp.zig:2:14: error: use of undeclared identifier 'crap'
test/compile_errors/stage1/obj/compile_error_when_evaluating_return_type_of_inferred_error_set.zig created+12
...@@ -0,0 +1,12 @@
1const Car = struct {
2 foo: *SymbolThatDoesNotExist,
3 pub fn init() !Car {}
4};
5export fn entry() void {
6 const car = Car.init();
7 _ = car;
8}
9
10// compile error when evaluating return type of inferred error set
11//
12// tmp.zig:2:11: error: use of undeclared identifier 'SymbolThatDoesNotExist'
test/compile_errors/stage1/obj/compile_log.zig created+14
...@@ -0,0 +1,14 @@
1export fn foo() void {
2 comptime bar(12, "hi",);
3}
4fn bar(a: i32, b: []const u8) void {
5 @compileLog("begin",);
6 @compileLog("a", a, "b", b);
7 @compileLog("end",);
8}
9
10// compile log
11//
12// tmp.zig:5:5: error: found compile log statement
13// tmp.zig:6:5: error: found compile log statement
14// tmp.zig:7:5: error: found compile log statement
test/compile_errors/stage1/obj/compile_log_a_pointer_to_an_opaque_value.zig created+7
...@@ -0,0 +1,7 @@
1export fn entry() void {
2 @compileLog(@ptrCast(*const anyopaque, &entry));
3}
4
5// compile log a pointer to an opaque value
6//
7// tmp.zig:2:5: error: found compile log statement
test/compile_errors/stage1/obj/compile_log_statement_inside_function_which_must_be_comptime_evaluated.zig created+12
...@@ -0,0 +1,12 @@
1fn Foo(comptime T: type) type {
2 @compileLog(@typeName(T));
3 return T;
4}
5export fn entry() void {
6 _ = Foo(i32);
7 _ = @typeName(Foo(i32));
8}
9
10// compile log statement inside function which must be comptime evaluated
11//
12// tmp.zig:2:5: error: found compile log statement
test/compile_errors/stage1/obj/compile_log_statement_warning_deduplication_in_generic_fn.zig created+12
...@@ -0,0 +1,12 @@
1export fn entry() void {
2 inner(1);
3 inner(2);
4}
5fn inner(comptime n: usize) void {
6 comptime var i = 0;
7 inline while (i < n) : (i += 1) { @compileLog("!@#$"); }
8}
9
10// compile log statement warning deduplication in generic fn
11//
12// tmp.zig:7:39: error: found compile log statement
test/compile_errors/stage1/obj/compile_time_division_by_zero.zig created+10
...@@ -0,0 +1,10 @@
1const y = foo(0);
2fn foo(x: u32) u32 {
3 return 1 / x;
4}
5
6export fn entry() usize { return @sizeOf(@TypeOf(y)); }
7
8// compile time division by zero
9//
10// tmp.zig:3:14: error: division by zero
test/compile_errors/stage1/obj/comptime_cast_enum_to_union_but_field_has_payload.zig created+15
...@@ -0,0 +1,15 @@
1const Letter = enum { A, B, C };
2const Value = union(Letter) {
3 A: i32,
4 B,
5 C,
6};
7export fn entry() void {
8 var x: Value = Letter.A;
9 _ = x;
10}
11
12// comptime cast enum to union but field has payload
13//
14// tmp.zig:8:26: error: cast to union 'Value' must initialize 'i32' field 'A'
15// tmp.zig:3:5: note: field 'A' declared here
test/compile_errors/stage1/obj/comptime_continue_inside_runtime_catch.zig created+14
...@@ -0,0 +1,14 @@
1export fn entry() void {
2 const ints = [_]u8{ 1, 2 };
3 inline for (ints) |_| {
4 bad() catch continue;
5 }
6}
7fn bad() !void {
8 return error.Bad;
9}
10
11// comptime continue inside runtime catch
12//
13// tmp.zig:4:21: error: comptime control flow inside runtime block
14// tmp.zig:4:15: note: runtime block created here
test/compile_errors/stage1/obj/comptime_continue_inside_runtime_if_bool.zig created+13
...@@ -0,0 +1,13 @@
1export fn entry() void {
2 var p: usize = undefined;
3 comptime var q = true;
4 inline while (q) {
5 if (p == 11) continue;
6 q = false;
7 }
8}
9
10// comptime continue inside runtime if bool
11//
12// tmp.zig:5:22: error: comptime control flow inside runtime block
13// tmp.zig:5:9: note: runtime block created here
test/compile_errors/stage1/obj/comptime_continue_inside_runtime_if_error.zig created+13
...@@ -0,0 +1,13 @@
1export fn entry() void {
2 var p: anyerror!i32 = undefined;
3 comptime var q = true;
4 inline while (q) {
5 if (p) |_| continue else |_| {}
6 q = false;
7 }
8}
9
10// comptime continue inside runtime if error
11//
12// tmp.zig:5:20: error: comptime control flow inside runtime block
13// tmp.zig:5:9: note: runtime block created here
test/compile_errors/stage1/obj/comptime_continue_inside_runtime_if_optional.zig created+13
...@@ -0,0 +1,13 @@
1export fn entry() void {
2 var p: ?i32 = undefined;
3 comptime var q = true;
4 inline while (q) {
5 if (p) |_| continue;
6 q = false;
7 }
8}
9
10// comptime continue inside runtime if optional
11//
12// tmp.zig:5:20: error: comptime control flow inside runtime block
13// tmp.zig:5:9: note: runtime block created here
test/compile_errors/stage1/obj/comptime_continue_inside_runtime_switch.zig created+16
...@@ -0,0 +1,16 @@
1export fn entry() void {
2 var p: i32 = undefined;
3 comptime var q = true;
4 inline while (q) {
5 switch (p) {
6 11 => continue,
7 else => {},
8 }
9 q = false;
10 }
11}
12
13// comptime continue inside runtime switch
14//
15// tmp.zig:6:19: error: comptime control flow inside runtime block
16// tmp.zig:5:9: note: runtime block created here
test/compile_errors/stage1/obj/comptime_continue_inside_runtime_while_bool.zig created+13
...@@ -0,0 +1,13 @@
1export fn entry() void {
2 var p: usize = undefined;
3 comptime var q = true;
4 outer: inline while (q) {
5 while (p == 11) continue :outer;
6 q = false;
7 }
8}
9
10// comptime continue inside runtime while bool
11//
12// tmp.zig:5:25: error: comptime control flow inside runtime block
13// tmp.zig:5:9: note: runtime block created here
test/compile_errors/stage1/obj/comptime_continue_inside_runtime_while_error.zig created+15
...@@ -0,0 +1,15 @@
1export fn entry() void {
2 var p: anyerror!usize = undefined;
3 comptime var q = true;
4 outer: inline while (q) {
5 while (p) |_| {
6 continue :outer;
7 } else |_| {}
8 q = false;
9 }
10}
11
12// comptime continue inside runtime while error
13//
14// tmp.zig:6:13: error: comptime control flow inside runtime block
15// tmp.zig:5:9: note: runtime block created here
test/compile_errors/stage1/obj/comptime_continue_inside_runtime_while_optional.zig created+13
...@@ -0,0 +1,13 @@
1export fn entry() void {
2 var p: ?usize = undefined;
3 comptime var q = true;
4 outer: inline while (q) {
5 while (p) |_| continue :outer;
6 q = false;
7 }
8}
9
10// comptime continue inside runtime while optional
11//
12// tmp.zig:5:23: error: comptime control flow inside runtime block
13// tmp.zig:5:9: note: runtime block created here
test/compile_errors/stage1/obj/comptime_float_in_asm_input.zig created+7
...@@ -0,0 +1,7 @@
1export fn foo() void {
2 asm volatile ("" : : [bar]"r"(3.17) : "");
3}
4
5// comptime_float in asm input
6//
7// tmp.zig:2:35: error: expected sized integer or sized float, found comptime_float
test/compile_errors/stage1/obj/comptime_implicit_cast_f64_to_f32.zig created+9
...@@ -0,0 +1,9 @@
1export fn entry() void {
2 const x: f64 = 16777217;
3 const y: f32 = x;
4 _ = y;
5}
6
7// comptime implicit cast f64 to f32
8//
9// tmp.zig:3:20: error: cast of value 16777217.000000 to type 'f32' loses information
test/compile_errors/stage1/obj/comptime_int_in_asm_input.zig created+7
...@@ -0,0 +1,7 @@
1export fn foo() void {
2 asm volatile ("" : : [bar]"r"(3) : "");
3}
4
5// comptime_int in asm input
6//
7// tmp.zig:2:35: error: expected sized integer or sized float, found comptime_int
test/compile_errors/stage1/obj/comptime_ptrcast_of_zero-sized_type.zig created+10
...@@ -0,0 +1,10 @@
1fn foo() void {
2 const node: struct {} = undefined;
3 const vla_ptr = @ptrCast([*]const u8, &node);
4 _ = vla_ptr;
5}
6comptime { foo(); }
7
8// comptime ptrcast of zero-sized type
9//
10// tmp.zig:3:21: error: '*const struct:2:17' and '[*]const u8' do not have the same in-memory representation
test/compile_errors/stage1/obj/comptime_slice-sentinel_does_not_match_memory_at_target_index_terminated.zig created+65
...@@ -0,0 +1,65 @@
1export fn foo_array() void {
2 comptime {
3 var target = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
4 const slice = target[0..3 :0];
5 _ = slice;
6 }
7}
8export fn foo_ptr_array() void {
9 comptime {
10 var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
11 var target = &buf;
12 const slice = target[0..3 :0];
13 _ = slice;
14 }
15}
16export fn foo_vector_ConstPtrSpecialBaseArray() void {
17 comptime {
18 var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
19 var target: [*]u8 = &buf;
20 const slice = target[0..3 :0];
21 _ = slice;
22 }
23}
24export fn foo_vector_ConstPtrSpecialRef() void {
25 comptime {
26 var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
27 var target: [*]u8 = @ptrCast([*]u8, &buf);
28 const slice = target[0..3 :0];
29 _ = slice;
30 }
31}
32export fn foo_cvector_ConstPtrSpecialBaseArray() void {
33 comptime {
34 var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
35 var target: [*c]u8 = &buf;
36 const slice = target[0..3 :0];
37 _ = slice;
38 }
39}
40export fn foo_cvector_ConstPtrSpecialRef() void {
41 comptime {
42 var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
43 var target: [*c]u8 = @ptrCast([*c]u8, &buf);
44 const slice = target[0..3 :0];
45 _ = slice;
46 }
47}
48export fn foo_slice() void {
49 comptime {
50 var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
51 var target: []u8 = &buf;
52 const slice = target[0..3 :0];
53 _ = slice;
54 }
55}
56
57// comptime slice-sentinel does not match memory at target index (terminated)
58//
59// :4:29: error: slice-sentinel does not match memory at target index
60// :12:29: error: slice-sentinel does not match memory at target index
61// :20:29: error: slice-sentinel does not match memory at target index
62// :28:29: error: slice-sentinel does not match memory at target index
63// :36:29: error: slice-sentinel does not match memory at target index
64// :44:29: error: slice-sentinel does not match memory at target index
65// :52:29: error: slice-sentinel does not match memory at target index
test/compile_errors/stage1/obj/comptime_slice-sentinel_does_not_match_memory_at_target_index_unterminated.zig created+65
...@@ -0,0 +1,65 @@
1export fn foo_array() void {
2 comptime {
3 var target = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
4 const slice = target[0..3 :0];
5 _ = slice;
6 }
7}
8export fn foo_ptr_array() void {
9 comptime {
10 var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
11 var target = &buf;
12 const slice = target[0..3 :0];
13 _ = slice;
14 }
15}
16export fn foo_vector_ConstPtrSpecialBaseArray() void {
17 comptime {
18 var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
19 var target: [*]u8 = &buf;
20 const slice = target[0..3 :0];
21 _ = slice;
22 }
23}
24export fn foo_vector_ConstPtrSpecialRef() void {
25 comptime {
26 var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
27 var target: [*]u8 = @ptrCast([*]u8, &buf);
28 const slice = target[0..3 :0];
29 _ = slice;
30 }
31}
32export fn foo_cvector_ConstPtrSpecialBaseArray() void {
33 comptime {
34 var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
35 var target: [*c]u8 = &buf;
36 const slice = target[0..3 :0];
37 _ = slice;
38 }
39}
40export fn foo_cvector_ConstPtrSpecialRef() void {
41 comptime {
42 var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
43 var target: [*c]u8 = @ptrCast([*c]u8, &buf);
44 const slice = target[0..3 :0];
45 _ = slice;
46 }
47}
48export fn foo_slice() void {
49 comptime {
50 var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
51 var target: []u8 = &buf;
52 const slice = target[0..3 :0];
53 _ = slice;
54 }
55}
56
57// comptime slice-sentinel does not match memory at target index (unterminated)
58//
59// :4:29: error: slice-sentinel does not match memory at target index
60// :12:29: error: slice-sentinel does not match memory at target index
61// :20:29: error: slice-sentinel does not match memory at target index
62// :28:29: error: slice-sentinel does not match memory at target index
63// :36:29: error: slice-sentinel does not match memory at target index
64// :44:29: error: slice-sentinel does not match memory at target index
65// :52:29: error: slice-sentinel does not match memory at target index
test/compile_errors/stage1/obj/comptime_slice-sentinel_does_not_match_target-sentinel.zig created+65
...@@ -0,0 +1,65 @@
1export fn foo_array() void {
2 comptime {
3 var target = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
4 const slice = target[0..14 :255];
5 _ = slice;
6 }
7}
8export fn foo_ptr_array() void {
9 comptime {
10 var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
11 var target = &buf;
12 const slice = target[0..14 :255];
13 _ = slice;
14 }
15}
16export fn foo_vector_ConstPtrSpecialBaseArray() void {
17 comptime {
18 var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
19 var target: [*]u8 = &buf;
20 const slice = target[0..14 :255];
21 _ = slice;
22 }
23}
24export fn foo_vector_ConstPtrSpecialRef() void {
25 comptime {
26 var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
27 var target: [*]u8 = @ptrCast([*]u8, &buf);
28 const slice = target[0..14 :255];
29 _ = slice;
30 }
31}
32export fn foo_cvector_ConstPtrSpecialBaseArray() void {
33 comptime {
34 var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
35 var target: [*c]u8 = &buf;
36 const slice = target[0..14 :255];
37 _ = slice;
38 }
39}
40export fn foo_cvector_ConstPtrSpecialRef() void {
41 comptime {
42 var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
43 var target: [*c]u8 = @ptrCast([*c]u8, &buf);
44 const slice = target[0..14 :255];
45 _ = slice;
46 }
47}
48export fn foo_slice() void {
49 comptime {
50 var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
51 var target: []u8 = &buf;
52 const slice = target[0..14 :255];
53 _ = slice;
54 }
55}
56
57// comptime slice-sentinel does not match target-sentinel
58//
59// :4:29: error: slice-sentinel does not match target-sentinel
60// :12:29: error: slice-sentinel does not match target-sentinel
61// :20:29: error: slice-sentinel does not match target-sentinel
62// :28:29: error: slice-sentinel does not match target-sentinel
63// :36:29: error: slice-sentinel does not match target-sentinel
64// :44:29: error: slice-sentinel does not match target-sentinel
65// :52:29: error: slice-sentinel does not match target-sentinel
test/compile_errors/stage1/obj/comptime_slice-sentinel_is_out_of_bounds_terminated.zig created+65
...@@ -0,0 +1,65 @@
1export fn foo_array() void {
2 comptime {
3 var target = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
4 const slice = target[0..15 :1];
5 _ = slice;
6 }
7}
8export fn foo_ptr_array() void {
9 comptime {
10 var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
11 var target = &buf;
12 const slice = target[0..15 :0];
13 _ = slice;
14 }
15}
16export fn foo_vector_ConstPtrSpecialBaseArray() void {
17 comptime {
18 var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
19 var target: [*]u8 = &buf;
20 const slice = target[0..15 :0];
21 _ = slice;
22 }
23}
24export fn foo_vector_ConstPtrSpecialRef() void {
25 comptime {
26 var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
27 var target: [*]u8 = @ptrCast([*]u8, &buf);
28 const slice = target[0..15 :0];
29 _ = slice;
30 }
31}
32export fn foo_cvector_ConstPtrSpecialBaseArray() void {
33 comptime {
34 var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
35 var target: [*c]u8 = &buf;
36 const slice = target[0..15 :0];
37 _ = slice;
38 }
39}
40export fn foo_cvector_ConstPtrSpecialRef() void {
41 comptime {
42 var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
43 var target: [*c]u8 = @ptrCast([*c]u8, &buf);
44 const slice = target[0..15 :0];
45 _ = slice;
46 }
47}
48export fn foo_slice() void {
49 comptime {
50 var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
51 var target: []u8 = &buf;
52 const slice = target[0..15 :0];
53 _ = slice;
54 }
55}
56
57// comptime slice-sentinel is out of bounds (terminated)
58//
59// :4:29: error: out of bounds slice
60// :12:29: error: out of bounds slice
61// :20:29: error: out of bounds slice
62// :28:29: error: out of bounds slice
63// :36:29: error: out of bounds slice
64// :44:29: error: out of bounds slice
65// :52:29: error: out of bounds slice
test/compile_errors/stage1/obj/comptime_slice-sentinel_is_out_of_bounds_unterminated.zig created+65
...@@ -0,0 +1,65 @@
1export fn foo_array() void {
2 comptime {
3 var target = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
4 const slice = target[0..14 :0];
5 _ = slice;
6 }
7}
8export fn foo_ptr_array() void {
9 comptime {
10 var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
11 var target = &buf;
12 const slice = target[0..14 :0];
13 _ = slice;
14 }
15}
16export fn foo_vector_ConstPtrSpecialBaseArray() void {
17 comptime {
18 var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
19 var target: [*]u8 = &buf;
20 const slice = target[0..14 :0];
21 _ = slice;
22 }
23}
24export fn foo_vector_ConstPtrSpecialRef() void {
25 comptime {
26 var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
27 var target: [*]u8 = @ptrCast([*]u8, &buf);
28 const slice = target[0..14 :0];
29 _ = slice;
30 }
31}
32export fn foo_cvector_ConstPtrSpecialBaseArray() void {
33 comptime {
34 var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
35 var target: [*c]u8 = &buf;
36 const slice = target[0..14 :0];
37 _ = slice;
38 }
39}
40export fn foo_cvector_ConstPtrSpecialRef() void {
41 comptime {
42 var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
43 var target: [*c]u8 = @ptrCast([*c]u8, &buf);
44 const slice = target[0..14 :0];
45 _ = slice;
46 }
47}
48export fn foo_slice() void {
49 comptime {
50 var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
51 var target: []u8 = &buf;
52 const slice = target[0..14 :0];
53 _ = slice;
54 }
55}
56
57// comptime slice-sentinel is out of bounds (unterminated)
58//
59// :4:29: error: slice-sentinel is out of bounds
60// :12:29: error: slice-sentinel is out of bounds
61// :20:29: error: slice-sentinel is out of bounds
62// :28:29: error: slice-sentinel is out of bounds
63// :36:29: error: slice-sentinel is out of bounds
64// :44:29: error: slice-sentinel is out of bounds
65// :52:29: error: slice-sentinel is out of bounds
test/compile_errors/stage1/obj/comptime_slice_of_an_undefined_slice.zig created+9
...@@ -0,0 +1,9 @@
1comptime {
2 var a: []u8 = undefined;
3 var b = a[0..10];
4 _ = b;
5}
6
7// comptime slice of an undefined slice
8//
9// tmp.zig:3:14: error: slice of undefined
test/compile_errors/stage1/obj/comptime_slice_of_undefined_pointer_non-zero_len.zig created+8
...@@ -0,0 +1,8 @@
1export fn entry() void {
2 const slice = @as([*]i32, undefined)[0..1];
3 _ = slice;
4}
5
6// comptime slice of undefined pointer non-zero len
7//
8// tmp.zig:2:41: error: non-zero length slice of undefined pointer
test/compile_errors/stage1/obj/comptime_struct_field_no_init_value.zig created+11
...@@ -0,0 +1,11 @@
1const Foo = struct {
2 comptime b: i32,
3};
4export fn entry() void {
5 var f: Foo = undefined;
6 _ = f;
7}
8
9// comptime struct field, no init value
10//
11// tmp.zig:2:5: error: comptime field without default initialization value
test/compile_errors/stage1/obj/const_frame_cast_to_anyframe.zig created+17
...@@ -0,0 +1,17 @@
1export fn a() void {
2 const f = async func();
3 resume f;
4}
5export fn b() void {
6 const f = async func();
7 var x: anyframe = &f;
8 _ = x;
9}
10fn func() void {
11 suspend {}
12}
13
14// const frame cast to anyframe
15//
16// tmp.zig:3:12: error: expected type 'anyframe', found '*const @Frame(func)'
17// tmp.zig:7:24: error: expected type 'anyframe', found '*const @Frame(func)'
test/compile_errors/stage1/obj/const_is_a_statement_not_an_expression.zig created+7
...@@ -0,0 +1,7 @@
1export fn f() void {
2 (const a = 0);
3}
4
5// const is a statement, not an expression
6//
7// tmp.zig:2:6: error: expected expression, found 'const'
test/compile_errors/stage1/obj/constant_inside_comptime_function_has_compile_error.zig created+19
...@@ -0,0 +1,19 @@
1const ContextAllocator = MemoryPool(usize);
2
3pub fn MemoryPool(comptime T: type) type {
4 const free_list_t = @compileError("aoeu",);
5
6 return struct {
7 free_list: free_list_t,
8 };
9}
10
11export fn entry() void {
12 var allocator: ContextAllocator = undefined;
13}
14
15// constant inside comptime function has compile error
16//
17// tmp.zig:4:5: error: unreachable code
18// tmp.zig:4:25: note: control flow is diverted here
19// tmp.zig:12:9: error: unused local variable
test/compile_errors/stage1/obj/container_init_with_non-type.zig created+8
...@@ -0,0 +1,8 @@
1const zero: i32 = 0;
2const a = zero{1};
3
4export fn entry() usize { return @sizeOf(@TypeOf(a)); }
5
6// container init with non-type
7//
8// tmp.zig:2:11: error: expected type 'type', found 'i32'
test/compile_errors/stage1/obj/control_flow_uses_comptime_var_at_runtime.zig created+13
...@@ -0,0 +1,13 @@
1export fn foo() void {
2 comptime var i = 0;
3 while (i < 5) : (i += 1) {
4 bar();
5 }
6}
7
8fn bar() void { }
9
10// control flow uses comptime var at runtime
11//
12// tmp.zig:3:5: error: control flow attempts to use compile-time variable at runtime
13// tmp.zig:3:24: note: compile-time variable assigned here
test/compile_errors/stage1/obj/control_reaches_end_of_non-void_function.zig created+6
...@@ -0,0 +1,6 @@
1fn a() i32 {}
2export fn entry() void { _ = a(); }
3
4// control reaches end of non-void function
5//
6// tmp.zig:1:12: error: expected type 'i32', found 'void'
test/compile_errors/stage1/obj/declaration_between_fields.zig created+22
...@@ -0,0 +1,22 @@
1const S = struct {
2 const foo = 2;
3 const bar = 2;
4 const baz = 2;
5 a: struct {
6 a: u32,
7 b: u32,
8 },
9 const foo1 = 2;
10 const bar1 = 2;
11 const baz1 = 2;
12 b: usize,
13};
14comptime {
15 _ = S;
16}
17
18// declaration between fields
19//
20// tmp.zig:9:5: error: declarations are not allowed between container fields
21// tmp.zig:5:5: note: field before declarations here
22// tmp.zig:12:5: note: field after declarations here
test/compile_errors/stage1/obj/declaration_with_same_name_as_primitive_must_use_special_syntax.zig created+10
...@@ -0,0 +1,10 @@
1const u8 = u16;
2export fn entry() void {
3 const a: u8 = 300;
4 _ = a;
5}
6
7// declaration with same name as primitive must use special syntax
8//
9// tmp.zig:1:7: error: name shadows primitive 'u8'
10// tmp.zig:1:7: note: consider using @"u8" to disambiguate
test/compile_errors/stage1/obj/deduplicate_undeclared_identifier.zig created+10
...@@ -0,0 +1,10 @@
1export fn a() void {
2 x += 1;
3}
4export fn b() void {
5 x += 1;
6}
7
8// deduplicate undeclared identifier
9//
10// tmp.zig:2:5: error: use of undeclared identifier 'x'
test/compile_errors/stage1/obj/deref_on_undefined_value.zig created+8
...@@ -0,0 +1,8 @@
1comptime {
2 var a: *u8 = undefined;
3 _ = a.*;
4}
5
6// deref on undefined value
7//
8// tmp.zig:3:9: error: attempt to dereference undefined value
test/compile_errors/stage1/obj/deref_slice_and_get_len_field.zig created+8
...@@ -0,0 +1,8 @@
1export fn entry() void {
2 var a: []u8 = undefined;
3 _ = a.*.len;
4}
5
6// deref slice and get len field
7//
8// tmp.zig:3:10: error: attempt to dereference non-pointer type '[]u8'
test/compile_errors/stage1/obj/dereference_an_array.zig created+12
...@@ -0,0 +1,12 @@
1var s_buffer: [10]u8 = undefined;
2pub fn pass(in: []u8) []u8 {
3 var out = &s_buffer;
4 out.*.* = in[0];
5 return out.*[0..1];
6}
7
8export fn entry() usize { return @sizeOf(@TypeOf(pass)); }
9
10// dereference an array
11//
12// tmp.zig:4:10: error: attempt to dereference non-pointer type '[10]u8'
test/compile_errors/stage1/obj/dereference_unknown_length_pointer.zig created+7
...@@ -0,0 +1,7 @@
1export fn entry(x: [*]i32) i32 {
2 return x.*;
3}
4
5// dereference unknown length pointer
6//
7// tmp.zig:2:13: error: index syntax required for unknown-length pointer type '[*]i32'
test/compile_errors/stage1/obj/direct_struct_loop.zig created+6
...@@ -0,0 +1,6 @@
1const A = struct { a : A, };
2export fn entry() usize { return @sizeOf(A); }
3
4// direct struct loop
5//
6// tmp.zig:1:11: error: struct 'A' depends on itself
test/compile_errors/stage1/obj/directly_embedding_opaque_type_in_struct_and_union.zig created+27
...@@ -0,0 +1,27 @@
1const O = opaque {};
2const Foo = struct {
3 o: O,
4};
5const Bar = union {
6 One: i32,
7 Two: O,
8};
9export fn a() void {
10 var foo: Foo = undefined;
11 _ = foo;
12}
13export fn b() void {
14 var bar: Bar = undefined;
15 _ = bar;
16}
17export fn c() void {
18 var baz: *opaque {} = undefined;
19 const qux = .{baz.*};
20 _ = qux;
21}
22
23// directly embedding opaque type in struct and union
24//
25// tmp.zig:3:5: error: opaque types have unknown size and therefore cannot be directly embedded in structs
26// tmp.zig:7:5: error: opaque types have unknown size and therefore cannot be directly embedded in unions
27// tmp.zig:19:22: error: opaque types have unknown size and therefore cannot be directly embedded in structs
test/compile_errors/stage1/obj/disallow_coercion_from_non-null-terminated_pointer_to_null-terminated_pointer.zig created+10
...@@ -0,0 +1,10 @@
1extern fn puts(s: [*:0]const u8) c_int;
2pub fn main() void {
3 const no_zero_array = [_]u8{'h', 'e', 'l', 'l', 'o'};
4 const no_zero_ptr: [*]const u8 = &no_zero_array;
5 _ = puts(no_zero_ptr);
6}
7
8// disallow coercion from non-null-terminated pointer to null-terminated pointer
9//
10// tmp.zig:5:14: error: expected type '[*:0]const u8', found '[*]const u8'
test/compile_errors/stage1/obj/discarding_error_value.zig created+10
...@@ -0,0 +1,10 @@
1export fn entry() void {
2 _ = foo();
3}
4fn foo() !void {
5 return error.OutOfMemory;
6}
7
8// discarding error value
9//
10// tmp.zig:2:12: error: error is discarded. consider using `try`, `catch`, or `if`
test/compile_errors/stage1/obj/div_assign_on_undefined_value.zig created+8
...@@ -0,0 +1,8 @@
1comptime {
2 var a: i64 = undefined;
3 a /= a;
4}
5
6// div assign on undefined value
7//
8// tmp.zig:3:5: error: use of undefined value here causes undefined behavior
test/compile_errors/stage1/obj/div_on_undefined_value.zig created+8
...@@ -0,0 +1,8 @@
1comptime {
2 var a: i64 = undefined;
3 _ = a / a;
4}
5
6// div on undefined value
7//
8// tmp.zig:3:9: error: use of undefined value here causes undefined behavior
test/compile_errors/stage1/obj/division_by_zero.zig created+16
...@@ -0,0 +1,16 @@
1const lit_int_x = 1 / 0;
2const lit_float_x = 1.0 / 0.0;
3const int_x = @as(u32, 1) / @as(u32, 0);
4const float_x = @as(f32, 1.0) / @as(f32, 0.0);
5
6export fn entry1() usize { return @sizeOf(@TypeOf(lit_int_x)); }
7export fn entry2() usize { return @sizeOf(@TypeOf(lit_float_x)); }
8export fn entry3() usize { return @sizeOf(@TypeOf(int_x)); }
9export fn entry4() usize { return @sizeOf(@TypeOf(float_x)); }
10
11// division by zero
12//
13// tmp.zig:1:21: error: division by zero
14// tmp.zig:2:25: error: division by zero
15// tmp.zig:3:27: error: division by zero
16// tmp.zig:4:31: error: division by zero
test/compile_errors/stage1/obj/dont_implicit_cast_double_pointer_to_anyopaque.zig created+11
...@@ -0,0 +1,11 @@
1export fn entry() void {
2 var a: u32 = 1;
3 var ptr: *align(@alignOf(u32)) anyopaque = &a;
4 var b: *u32 = @ptrCast(*u32, ptr);
5 var ptr2: *anyopaque = &b;
6 _ = ptr2;
7}
8
9// don't implicit cast double pointer to *anyopaque
10//
11// tmp.zig:5:29: error: expected type '*anyopaque', found '**u32'
test/compile_errors/stage1/obj/double_optional_on_main_return_value.zig created+6
...@@ -0,0 +1,6 @@
1pub fn main() ??void {
2}
3
4// double ?? on main return value
5//
6// error: expected return type of main to be 'void', '!void', 'noreturn', 'u8', or '!u8'
test/compile_errors/stage1/obj/duplicate_boolean_switch_value.zig created+21
...@@ -0,0 +1,21 @@
1comptime {
2 const x = switch (true) {
3 true => false,
4 false => true,
5 true => false,
6 };
7 _ = x;
8}
9comptime {
10 const x = switch (true) {
11 false => true,
12 true => false,
13 false => true,
14 };
15 _ = x;
16}
17
18// duplicate boolean switch value
19//
20// tmp.zig:5:9: error: duplicate switch value
21// tmp.zig:13:9: error: duplicate switch value
test/compile_errors/stage1/obj/duplicate_enum_field.zig created+14
...@@ -0,0 +1,14 @@
1const Foo = enum {
2 Bar,
3 Bar,
4};
5
6export fn entry() void {
7 const a: Foo = undefined;
8 _ = a;
9}
10
11// duplicate enum field
12//
13// tmp.zig:3:5: error: duplicate enum field: 'Bar'
14// tmp.zig:2:5: note: other field here
test/compile_errors/stage1/obj/duplicate_error_in_switch.zig created+20
...@@ -0,0 +1,20 @@
1export fn entry() void {
2 foo(452) catch |err| switch (err) {
3 error.Foo => {},
4 error.Bar => {},
5 error.Foo => {},
6 else => {},
7 };
8}
9fn foo(x: i32) !void {
10 switch (x) {
11 0 ... 10 => return error.Foo,
12 11 ... 20 => return error.Bar,
13 else => {},
14 }
15}
16
17// duplicate error in switch
18//
19// tmp.zig:5:14: error: duplicate switch value: '@typeInfo(@typeInfo(@TypeOf(foo)).Fn.return_type.?).ErrorUnion.error_set.Foo'
20// tmp.zig:3:14: note: other value here
test/compile_errors/stage1/obj/duplicate_error_value_in_error_set.zig created+13
...@@ -0,0 +1,13 @@
1const Foo = error {
2 Bar,
3 Bar,
4};
5export fn entry() void {
6 const a: Foo = undefined;
7 _ = a;
8}
9
10// duplicate error value in error set
11//
12// tmp.zig:3:5: error: duplicate error set field 'Bar'
13// tmp.zig:2:5: note: previous declaration here
test/compile_errors/stage1/obj/duplicate_field_in_struct_value_expression.zig created+18
...@@ -0,0 +1,18 @@
1const A = struct {
2 x : i32,
3 y : i32,
4 z : i32,
5};
6export fn f() void {
7 const a = A {
8 .z = 1,
9 .y = 2,
10 .x = 3,
11 .z = 4,
12 };
13 _ = a;
14}
15
16// duplicate field in struct value expression
17//
18// tmp.zig:11:9: error: duplicate field
test/compile_errors/stage1/obj/duplicate_struct_field.zig created+13
...@@ -0,0 +1,13 @@
1const Foo = struct {
2 Bar: i32,
3 Bar: usize,
4};
5export fn entry() void {
6 const a: Foo = undefined;
7 _ = a;
8}
9
10// duplicate struct field
11//
12// tmp.zig:3:5: error: duplicate struct field: 'Bar'
13// tmp.zig:2:5: note: other field here
test/compile_errors/stage1/obj/duplicate_union_field.zig created+13
...@@ -0,0 +1,13 @@
1const Foo = union {
2 Bar: i32,
3 Bar: usize,
4};
5export fn entry() void {
6 const a: Foo = undefined;
7 _ = a;
8}
9
10// duplicate union field
11//
12// tmp.zig:3:5: error: duplicate union field: 'Bar'
13// tmp.zig:2:5: note: other field here
test/compile_errors/stage1/obj/embedFile_with_bogus_file.zig created+7
...@@ -0,0 +1,7 @@
1const resource = @embedFile("bogus.txt",);
2
3export fn entry() usize { return @sizeOf(@TypeOf(resource)); }
4
5// @embedFile with bogus file
6//
7// tmp.zig:1:29: error: unable to find '
test/compile_errors/stage1/obj/empty_for_loop_body.zig created+7
...@@ -0,0 +1,7 @@
1export fn a() void {
2 for(undefined) |x|;
3}
4
5// empty for loop body
6//
7// tmp.zig:2:23: error: expected block or assignment, found ';'
test/compile_errors/stage1/obj/empty_if_body.zig created+7
...@@ -0,0 +1,7 @@
1export fn a() void {
2 if(true);
3}
4
5// empty if body
6//
7// tmp.zig:2:13: error: expected block or assignment, found ';'
test/compile_errors/stage1/obj/empty_switch_on_an_integer.zig created+8
...@@ -0,0 +1,8 @@
1export fn entry() void {
2 var x: u32 = 0;
3 switch(x) {}
4}
5
6// empty switch on an integer
7//
8// tmp.zig:3:5: error: switch must handle all possibilities
test/compile_errors/stage1/obj/empty_while_loop_body.zig created+7
...@@ -0,0 +1,7 @@
1export fn a() void {
2 while(true);
3}
4
5// empty while loop body
6//
7// tmp.zig:2:16: error: expected block or assignment, found ';'
test/compile_errors/stage1/obj/endless_loop_in_function_evaluation.zig created+10
...@@ -0,0 +1,10 @@
1const seventh_fib_number = fibonacci(7);
2fn fibonacci(x: i32) i32 {
3 return fibonacci(x - 1) + fibonacci(x - 2);
4}
5
6export fn entry() usize { return @sizeOf(@TypeOf(seventh_fib_number)); }
7
8// endless loop in function evaluation
9//
10// tmp.zig:3:21: error: evaluation exceeded 1000 backwards branches
test/compile_errors/stage1/obj/enum_field_value_references_enum.zig created+13
...@@ -0,0 +1,13 @@
1pub const Foo = enum(c_int) {
2 A = Foo.B,
3 C = D,
4};
5export fn entry() void {
6 var s: Foo = Foo.E;
7 _ = s;
8}
9const D = 1;
10
11// enum field value references enum
12//
13// tmp.zig:1:17: error: enum 'Foo' depends on itself
test/compile_errors/stage1/obj/enum_in_field_count_range_but_not_matching_tag.zig created+13
...@@ -0,0 +1,13 @@
1const Foo = enum(u32) {
2 A = 10,
3 B = 11,
4};
5export fn entry() void {
6 var x = @intToEnum(Foo, 0);
7 _ = x;
8}
9
10// enum in field count range but not matching tag
11//
12// tmp.zig:6:13: error: enum 'Foo' has no tag matching integer value 0
13// tmp.zig:1:13: note: 'Foo' declared here
test/compile_errors/stage1/obj/enum_value_already_taken.zig created+16
...@@ -0,0 +1,16 @@
1const MultipleChoice = enum(u32) {
2 A = 20,
3 B = 40,
4 C = 60,
5 D = 1000,
6 E = 60,
7};
8export fn entry() void {
9 var x = MultipleChoice.C;
10 _ = x;
11}
12
13// enum value already taken
14//
15// tmp.zig:6:5: error: enum tag value 60 already taken
16// tmp.zig:4:5: note: other occurrence here
test/compile_errors/stage1/obj/enum_with_0_fields.zig created+5
...@@ -0,0 +1,5 @@
1const Foo = enum {};
2
3// enum with 0 fields
4//
5// tmp.zig:1:13: error: enum declarations must have at least one tag
test/compile_errors/stage1/obj/enum_with_declarations_unavailable_for_reify_type.zig created+7
...@@ -0,0 +1,7 @@
1export fn entry() void {
2 _ = @Type(@typeInfo(enum { foo, const bar = 1; }));
3}
4
5// enum with declarations unavailable for @Type
6//
7// tmp.zig:2:15: error: Type.Enum.decls must be empty for @Type
test/compile_errors/stage1/obj/error_equality_but_sets_have_no_common_members.zig created+14
...@@ -0,0 +1,14 @@
1const Set1 = error{A, C};
2const Set2 = error{B, D};
3export fn entry() void {
4 foo(Set1.A);
5}
6fn foo(x: Set1) void {
7 if (x == Set2.B) {
8
9 }
10}
11
12// error equality but sets have no common members
13//
14// tmp.zig:7:11: error: error sets 'Set1' and 'Set2' have no common errors
test/compile_errors/stage1/obj/error_not_handled_in_switch.zig created+18
...@@ -0,0 +1,18 @@
1export fn entry() void {
2 foo(452) catch |err| switch (err) {
3 error.Foo => {},
4 };
5}
6fn foo(x: i32) !void {
7 switch (x) {
8 0 ... 10 => return error.Foo,
9 11 ... 20 => return error.Bar,
10 21 ... 30 => return error.Baz,
11 else => {},
12 }
13}
14
15// error not handled in switch
16//
17// tmp.zig:2:26: error: error.Baz not handled in switch
18// tmp.zig:2:26: error: error.Bar not handled in switch
test/compile_errors/stage1/obj/error_note_for_function_parameter_incompatibility.zig created+10
...@@ -0,0 +1,10 @@
1fn do_the_thing(func: fn (arg: i32) void) void { _ = func; }
2fn bar(arg: bool) void { _ = arg; }
3export fn entry() void {
4 do_the_thing(bar);
5}
6
7// error note for function parameter incompatibility
8//
9// tmp.zig:4:18: error: expected type 'fn(i32) void', found 'fn(bool) void
10// tmp.zig:4:18: note: parameter 0: 'bool' cannot cast into 'i32'
test/compile_errors/stage1/obj/error_union_operator_with_non_error_set_LHS.zig created+9
...@@ -0,0 +1,9 @@
1comptime {
2 const z = i32!i32;
3 var x: z = undefined;
4 _ = x;
5}
6
7// error union operator with non error set LHS
8//
9// tmp.zig:2:15: error: expected error set type, found type 'i32'
test/compile_errors/stage1/obj/error_when_evaluating_return_type.zig created+15
...@@ -0,0 +1,15 @@
1const Foo = struct {
2 map: @as(i32, i32),
3
4 fn init() Foo {
5 return undefined;
6 }
7};
8export fn entry() void {
9 var rule_set = try Foo.init();
10 _ = rule_set;
11}
12
13// error when evaluating return type
14//
15// tmp.zig:2:19: error: expected type 'i32', found 'type'
test/compile_errors/stage1/obj/exceeded_maximum_bit_width_of_integer.zig created+13
...@@ -0,0 +1,13 @@
1export fn entry1() void {
2 const T = u65536;
3 _ = T;
4}
5export fn entry2() void {
6 var x: i65536 = 1;
7 _ = x;
8}
9
10// exceeded maximum bit width of integer
11//
12// tmp.zig:2:15: error: primitive integer type 'u65536' exceeds maximum bit width of 65535
13// tmp.zig:6:12: error: primitive integer type 'i65536' exceeds maximum bit width of 65535
test/compile_errors/stage1/obj/explicit_cast_float_literal_to_integer_when_there_is_a_fraction_component.zig created+7
...@@ -0,0 +1,7 @@
1export fn entry() i32 {
2 return @as(i32, 12.34);
3}
4
5// explicit cast float literal to integer when there is a fraction component
6//
7// tmp.zig:2:21: error: fractional component prevents float value 12.340000 from being casted to type 'i32'
test/compile_errors/stage1/obj/explicit_error_set_cast_known_at_comptime_violates_error_sets.zig created+11
...@@ -0,0 +1,11 @@
1const Set1 = error {A, B};
2const Set2 = error {A, C};
3comptime {
4 var x = Set1.B;
5 var y = @errSetCast(Set2, x);
6 _ = y;
7}
8
9// explicit error set cast known at comptime violates error sets
10//
11// tmp.zig:5:13: error: error.B not a member of error set 'Set2'
test/compile_errors/stage1/obj/explicitly_casting_non_tag_type_to_enum.zig created+16
...@@ -0,0 +1,16 @@
1const Small = enum(u2) {
2 One,
3 Two,
4 Three,
5 Four,
6};
7
8export fn entry() void {
9 var y = @as(f32, 3);
10 var x = @intToEnum(Small, y);
11 _ = x;
12}
13
14// explicitly casting non tag type to enum
15//
16// tmp.zig:10:31: error: expected integer type, found 'f32'
test/compile_errors/stage1/obj/export_function_with_comptime_parameter.zig created+7
...@@ -0,0 +1,7 @@
1export fn foo(comptime x: i32, y: i32) i32{
2 return x + y;
3}
4
5// export function with comptime parameter
6//
7// tmp.zig:1:15: error: comptime parameter not allowed in function with calling convention 'C'
test/compile_errors/stage1/obj/export_generic_function.zig created+8
...@@ -0,0 +1,8 @@
1export fn foo(num: anytype) i32 {
2 _ = num;
3 return 0;
4}
5
6// export generic function
7//
8// tmp.zig:1:15: error: parameter of type 'anytype' not allowed in function with calling convention 'C'
test/compile_errors/stage1/obj/exported_async_function.zig created+5
...@@ -0,0 +1,5 @@
1export fn foo() callconv(.Async) void {}
2
3// exported async function
4//
5// tmp.zig:1:1: error: exported function cannot be async
test/compile_errors/stage1/obj/exported_enum_without_explicit_integer_tag_type.zig created+13
...@@ -0,0 +1,13 @@
1const E = enum { one, two };
2comptime {
3 @export(E, .{ .name = "E" });
4}
5const e: E = .two;
6comptime {
7 @export(e, .{ .name = "e" });
8}
9
10// exported enum without explicit integer tag type
11//
12// tmp.zig:3:13: error: exported enum without explicit integer tag type
13// tmp.zig:7:13: error: exported enum value without explicit integer tag type
test/compile_errors/stage1/obj/extern_function_pointer_mismatch.zig created+10
...@@ -0,0 +1,10 @@
1const fns = [_](fn(i32)i32) { a, b, c };
2pub fn a(x: i32) i32 {return x + 0;}
3pub fn b(x: i32) i32 {return x + 1;}
4export fn c(x: i32) i32 {return x + 2;}
5
6export fn entry() usize { return @sizeOf(@TypeOf(fns)); }
7
8// extern function pointer mismatch
9//
10// tmp.zig:1:37: error: expected type 'fn(i32) i32', found 'fn(i32) callconv(.C) i32'
test/compile_errors/stage1/obj/extern_function_with_comptime_parameter.zig created+9
...@@ -0,0 +1,9 @@
1extern fn foo(comptime x: i32, y: i32) i32;
2fn f() i32 {
3 return foo(1, 2);
4}
5export fn entry() usize { return @sizeOf(@TypeOf(f)); }
6
7// extern function with comptime parameter
8//
9// tmp.zig:1:15: error: comptime parameter not allowed in function with calling convention 'C'
test/compile_errors/stage1/obj/extern_struct_with_extern-compatible_but_inferred_integer_tag_type.zig created+41
...@@ -0,0 +1,41 @@
1pub const E = enum {
2@"0",@"1",@"2",@"3",@"4",@"5",@"6",@"7",@"8",@"9",@"10",@"11",@"12",
3@"13",@"14",@"15",@"16",@"17",@"18",@"19",@"20",@"21",@"22",@"23",
4@"24",@"25",@"26",@"27",@"28",@"29",@"30",@"31",@"32",@"33",@"34",
5@"35",@"36",@"37",@"38",@"39",@"40",@"41",@"42",@"43",@"44",@"45",
6@"46",@"47",@"48",@"49",@"50",@"51",@"52",@"53",@"54",@"55",@"56",
7@"57",@"58",@"59",@"60",@"61",@"62",@"63",@"64",@"65",@"66",@"67",
8@"68",@"69",@"70",@"71",@"72",@"73",@"74",@"75",@"76",@"77",@"78",
9@"79",@"80",@"81",@"82",@"83",@"84",@"85",@"86",@"87",@"88",@"89",
10@"90",@"91",@"92",@"93",@"94",@"95",@"96",@"97",@"98",@"99",@"100",
11@"101",@"102",@"103",@"104",@"105",@"106",@"107",@"108",@"109",
12@"110",@"111",@"112",@"113",@"114",@"115",@"116",@"117",@"118",
13@"119",@"120",@"121",@"122",@"123",@"124",@"125",@"126",@"127",
14@"128",@"129",@"130",@"131",@"132",@"133",@"134",@"135",@"136",
15@"137",@"138",@"139",@"140",@"141",@"142",@"143",@"144",@"145",
16@"146",@"147",@"148",@"149",@"150",@"151",@"152",@"153",@"154",
17@"155",@"156",@"157",@"158",@"159",@"160",@"161",@"162",@"163",
18@"164",@"165",@"166",@"167",@"168",@"169",@"170",@"171",@"172",
19@"173",@"174",@"175",@"176",@"177",@"178",@"179",@"180",@"181",
20@"182",@"183",@"184",@"185",@"186",@"187",@"188",@"189",@"190",
21@"191",@"192",@"193",@"194",@"195",@"196",@"197",@"198",@"199",
22@"200",@"201",@"202",@"203",@"204",@"205",@"206",@"207",@"208",
23@"209",@"210",@"211",@"212",@"213",@"214",@"215",@"216",@"217",
24@"218",@"219",@"220",@"221",@"222",@"223",@"224",@"225",@"226",
25@"227",@"228",@"229",@"230",@"231",@"232",@"233",@"234",@"235",
26@"236",@"237",@"238",@"239",@"240",@"241",@"242",@"243",@"244",
27@"245",@"246",@"247",@"248",@"249",@"250",@"251",@"252",@"253",
28@"254",@"255"
29};
30pub const S = extern struct {
31 e: E,
32};
33export fn entry() void {
34 if (@typeInfo(E).Enum.tag_type != u8) @compileError("did not infer u8 tag type");
35 const s: S = undefined;
36 _ = s;
37}
38
39// extern struct with extern-compatible but inferred integer tag type
40//
41// tmp.zig:31:5: error: extern structs cannot contain fields of type 'E'
test/compile_errors/stage1/obj/extern_struct_with_non-extern-compatible_integer_tag_type.zig created+12
...@@ -0,0 +1,12 @@
1pub const E = enum(u31) { A, B, C };
2pub const S = extern struct {
3 e: E,
4};
5export fn entry() void {
6 const s: S = undefined;
7 _ = s;
8}
9
10// extern struct with non-extern-compatible integer tag type
11//
12// tmp.zig:3:5: error: extern structs cannot contain fields of type 'E'
test/compile_errors/stage1/obj/extern_union_field_missing_type.zig created+11
...@@ -0,0 +1,11 @@
1const Letter = extern union {
2 A,
3};
4export fn entry() void {
5 var a = Letter { .A = {} };
6 _ = a;
7}
8
9// extern union field missing type
10//
11// tmp.zig:2:5: error: union field missing type
test/compile_errors/stage1/obj/extern_union_given_enum_tag_type.zig created+18
...@@ -0,0 +1,18 @@
1const Letter = enum {
2 A,
3 B,
4 C,
5};
6const Payload = extern union(Letter) {
7 A: i32,
8 B: f64,
9 C: bool,
10};
11export fn entry() void {
12 var a = Payload { .A = 1234 };
13 _ = a;
14}
15
16// extern union given enum tag type
17//
18// tmp.zig:6:30: error: extern union does not support enum tag type
test/compile_errors/stage1/obj/extern_variable_has_no_type.zig created+8
...@@ -0,0 +1,8 @@
1extern var foo;
2pub export fn entry() void {
3 foo;
4}
5
6// extern variable has no type
7//
8// tmp.zig:1:8: error: unable to infer variable type
test/compile_errors/stage1/obj/fieldParentPtr-bad_field_name.zig created+10
...@@ -0,0 +1,10 @@
1const Foo = extern struct {
2 derp: i32,
3};
4export fn foo(a: *i32) *Foo {
5 return @fieldParentPtr(Foo, "a", a);
6}
7
8// @fieldParentPtr - bad field name
9//
10// tmp.zig:5:33: error: struct 'Foo' has no field 'a'
test/compile_errors/stage1/obj/fieldParentPtr-comptime_field_ptr_not_based_on_struct.zig created+15
...@@ -0,0 +1,15 @@
1const Foo = struct {
2 a: i32,
3 b: i32,
4};
5const foo = Foo { .a = 1, .b = 2, };
6
7comptime {
8 const field_ptr = @intToPtr(*i32, 0x1234);
9 const another_foo_ptr = @fieldParentPtr(Foo, "b", field_ptr);
10 _ = another_foo_ptr;
11}
12
13// @fieldParentPtr - comptime field ptr not based on struct
14//
15// tmp.zig:9:55: error: pointer value not based on parent struct
test/compile_errors/stage1/obj/fieldParentPtr-comptime_wrong_field_index.zig created+14
...@@ -0,0 +1,14 @@
1const Foo = struct {
2 a: i32,
3 b: i32,
4};
5const foo = Foo { .a = 1, .b = 2, };
6
7comptime {
8 const another_foo_ptr = @fieldParentPtr(Foo, "b", &foo.a);
9 _ = another_foo_ptr;
10}
11
12// @fieldParentPtr - comptime wrong field index
13//
14// tmp.zig:8:29: error: field 'b' has index 1 but pointer value is index 0 of struct 'Foo'
test/compile_errors/stage1/obj/fieldParentPtr-field_pointer_is_not_pointer.zig created+10
...@@ -0,0 +1,10 @@
1const Foo = extern struct {
2 a: i32,
3};
4export fn foo(a: i32) *Foo {
5 return @fieldParentPtr(Foo, "a", a);
6}
7
8// @fieldParentPtr - field pointer is not pointer
9//
10// tmp.zig:5:38: error: expected pointer, found 'i32'
test/compile_errors/stage1/obj/fieldParentPtr-non_struct.zig created+8
...@@ -0,0 +1,8 @@
1const Foo = i32;
2export fn foo(a: *i32) *Foo {
3 return @fieldParentPtr(Foo, "a", a);
4}
5
6// @fieldParentPtr - non struct
7//
8// tmp.zig:3:28: error: expected struct type, found 'i32'
test/compile_errors/stage1/obj/field_access_of_opaque_type.zig created+14
...@@ -0,0 +1,14 @@
1const MyType = opaque {};
2
3export fn entry() bool {
4 var x: i32 = 1;
5 return bar(@ptrCast(*MyType, &x));
6}
7
8fn bar(x: *MyType) bool {
9 return x.blah;
10}
11
12// field access of opaque type
13//
14// tmp.zig:9:13: error: no member named 'blah' in opaque type 'MyType'
test/compile_errors/stage1/obj/field_access_of_slices.zig created+9
...@@ -0,0 +1,9 @@
1export fn entry() void {
2 var slice: []i32 = undefined;
3 const info = @TypeOf(slice).unknown;
4 _ = info;
5}
6
7// field access of slices
8//
9// tmp.zig:3:32: error: type 'type' does not support field access
test/compile_errors/stage1/obj/field_access_of_unknown_length_pointer.zig created+11
...@@ -0,0 +1,11 @@
1const Foo = extern struct {
2 a: i32,
3};
4
5export fn entry(foo: [*]Foo) void {
6 foo.a += 1;
7}
8
9// field access of unknown length pointer
10//
11// tmp.zig:6:8: error: type '[*]Foo' does not support field access
test/compile_errors/stage1/obj/field_type_supplied_in_an_enum.zig created+10
...@@ -0,0 +1,10 @@
1const Letter = enum {
2 A: void,
3 B,
4 C,
5};
6
7// field type supplied in an enum
8//
9// tmp.zig:2:8: error: enum fields do not have types
10// tmp.zig:1:16: note: consider 'union(enum)' here to make it a tagged union
test/compile_errors/stage1/obj/floatToInt_comptime_safety.zig created+15
...@@ -0,0 +1,15 @@
1comptime {
2 _ = @floatToInt(i8, @as(f32, -129.1));
3}
4comptime {
5 _ = @floatToInt(u8, @as(f32, -1.1));
6}
7comptime {
8 _ = @floatToInt(u8, @as(f32, 256.1));
9}
10
11// @floatToInt comptime safety
12//
13// tmp.zig:2:9: error: integer value '-129' cannot be stored in type 'i8'
14// tmp.zig:5:9: error: integer value '-1' cannot be stored in type 'u8'
15// tmp.zig:8:9: error: integer value '256' cannot be stored in type 'u8'
test/compile_errors/stage1/obj/float_literal_too_large_error.zig created+8
...@@ -0,0 +1,8 @@
1comptime {
2 const a = 0x1.0p18495;
3 _ = a;
4}
5
6// float literal too large error
7//
8// tmp.zig:2:15: error: float literal out of range of any type
test/compile_errors/stage1/obj/float_literal_too_small_error_denormal.zig created+8
...@@ -0,0 +1,8 @@
1comptime {
2 const a = 0x1.0p-19000;
3 _ = a;
4}
5
6// float literal too small error (denormal)
7//
8// tmp.zig:2:15: error: float literal out of range of any type
test/compile_errors/stage1/obj/for_loop_body_expression_ignored.zig created+16
...@@ -0,0 +1,16 @@
1fn returns() usize {
2 return 2;
3}
4export fn f1() void {
5 for ("hello") |_| returns();
6}
7export fn f2() void {
8 var x: anyerror!i32 = error.Bad;
9 for ("hello") |_| returns() else unreachable;
10 _ = x;
11}
12
13// for loop body expression ignored
14//
15// tmp.zig:5:30: error: expression value is ignored
16// tmp.zig:9:30: error: expression value is ignored
test/compile_errors/stage1/obj/frame_called_outside_of_function_definition.zig created+9
...@@ -0,0 +1,9 @@
1var handle_undef: anyframe = undefined;
2var handle_dummy: anyframe = @frame();
3export fn entry() bool {
4 return handle_undef == handle_dummy;
5}
6
7// @frame() called outside of function definition
8//
9// tmp.zig:2:30: error: @frame() called outside of function definition
test/compile_errors/stage1/obj/frame_causes_function_to_be_async.zig created+11
...@@ -0,0 +1,11 @@
1export fn entry() void {
2 func();
3}
4fn func() void {
5 _ = @frame();
6}
7
8// @frame() causes function to be async
9//
10// tmp.zig:1:1: error: function with calling convention 'C' cannot be async
11// tmp.zig:5:9: note: @frame() causes function to be async
test/compile_errors/stage1/obj/function_alignment_non_power_of_2.zig created+6
...@@ -0,0 +1,6 @@
1extern fn foo() align(3) void;
2export fn entry() void { return foo(); }
3
4// function alignment non power of 2
5//
6// tmp.zig:1:23: error: alignment value 3 is not a power of 2
test/compile_errors/stage1/obj/function_call_assigned_to_incorrect_type.zig created+11
...@@ -0,0 +1,11 @@
1export fn entry() void {
2 var arr: [4]f32 = undefined;
3 arr = concat();
4}
5fn concat() [16]f32 {
6 return [1]f32{0}**16;
7}
8
9// function call assigned to incorrect type
10//
11// tmp.zig:3:17: error: expected type '[4]f32', found '[16]f32'
test/compile_errors/stage1/obj/function_parameter_is_opaque.zig created+27
...@@ -0,0 +1,27 @@
1const FooType = opaque {};
2export fn entry1() void {
3 const someFuncPtr: fn (FooType) void = undefined;
4 _ = someFuncPtr;
5}
6
7export fn entry2() void {
8 const someFuncPtr: fn (@TypeOf(null)) void = undefined;
9 _ = someFuncPtr;
10}
11
12fn foo(p: FooType) void {_ = p;}
13export fn entry3() void {
14 _ = foo;
15}
16
17fn bar(p: @TypeOf(null)) void {_ = p;}
18export fn entry4() void {
19 _ = bar;
20}
21
22// function parameter is opaque
23//
24// tmp.zig:3:28: error: parameter of opaque type 'FooType' not allowed
25// tmp.zig:8:28: error: parameter of type '@Type(.Null)' not allowed
26// tmp.zig:12:11: error: parameter of opaque type 'FooType' not allowed
27// tmp.zig:17:11: error: parameter of type '@Type(.Null)' not allowed
test/compile_errors/stage1/obj/function_prototype_with_no_body.zig created+8
...@@ -0,0 +1,8 @@
1fn foo() void;
2export fn entry() void {
3 foo();
4}
5
6// function prototype with no body
7//
8// tmp.zig:1:1: error: non-extern function has no body
test/compile_errors/stage1/obj/function_returning_opaque_type.zig created+17
...@@ -0,0 +1,17 @@
1const FooType = opaque {};
2export fn bar() !FooType {
3 return error.InvalidValue;
4}
5export fn bav() !@TypeOf(null) {
6 return error.InvalidValue;
7}
8export fn baz() !@TypeOf(undefined) {
9 return error.InvalidValue;
10}
11
12// function returning opaque type
13//
14// tmp.zig:2:18: error: Opaque return type 'FooType' not allowed
15// tmp.zig:1:1: note: type declared here
16// tmp.zig:5:18: error: Null return type '@Type(.Null)' not allowed
17// tmp.zig:8:18: error: Undefined return type '@Type(.Undefined)' not allowed
test/compile_errors/stage1/obj/function_with_ccc_indirectly_calling_async_function.zig created+16
...@@ -0,0 +1,16 @@
1export fn entry() void {
2 foo();
3}
4fn foo() void {
5 bar();
6}
7fn bar() void {
8 suspend {}
9}
10
11// function with ccc indirectly calling async function
12//
13// tmp.zig:1:1: error: function with calling convention 'C' cannot be async
14// tmp.zig:2:8: note: async function call here
15// tmp.zig:5:8: note: async function call here
16// tmp.zig:8:5: note: suspends here
test/compile_errors/stage1/obj/function_with_invalid_return_type.zig created+5
...@@ -0,0 +1,5 @@
1export fn foo() boid {}
2
3// function with invalid return type
4//
5// tmp.zig:1:17: error: use of undeclared identifier 'boid'
test/compile_errors/stage1/obj/function_with_non-extern_non-packed_enum_parameter.zig created+6
...@@ -0,0 +1,6 @@
1const Foo = enum { A, B, C };
2export fn entry(foo: Foo) void { _ = foo; }
3
4// function with non-extern non-packed enum parameter
5//
6// tmp.zig:2:22: error: parameter of type 'Foo' not allowed in function with calling convention 'C'
test/compile_errors/stage1/obj/function_with_non-extern_non-packed_struct_parameter.zig created+10
...@@ -0,0 +1,10 @@
1const Foo = struct {
2 A: i32,
3 B: f32,
4 C: bool,
5};
6export fn entry(foo: Foo) void { _ = foo; }
7
8// function with non-extern non-packed struct parameter
9//
10// tmp.zig:6:22: error: parameter of type 'Foo' not allowed in function with calling convention 'C'
test/compile_errors/stage1/obj/function_with_non-extern_non-packed_union_parameter.zig created+10
...@@ -0,0 +1,10 @@
1const Foo = union {
2 A: i32,
3 B: f32,
4 C: bool,
5};
6export fn entry(foo: Foo) void { _ = foo; }
7
8// function with non-extern non-packed union parameter
9//
10// tmp.zig:6:22: error: parameter of type 'Foo' not allowed in function with calling convention 'C'
test/compile_errors/stage1/obj/generic_fn_as_parameter_without_comptime_keyword.zig created+9
...@@ -0,0 +1,9 @@
1fn f(_: fn (anytype) void) void {}
2fn g(_: anytype) void {}
3export fn entry() void {
4 f(g);
5}
6
7// generic fn as parameter without comptime keyword
8//
9// tmp.zig:1:9: error: parameter of type 'fn(anytype) anytype' must be declared comptime
test/compile_errors/stage1/obj/generic_function_call_assigned_to_incorrect_type.zig created+11
...@@ -0,0 +1,11 @@
1pub export fn entry() void {
2 var res: []i32 = undefined;
3 res = myAlloc(i32);
4}
5fn myAlloc(comptime arg: type) anyerror!arg{
6 unreachable;
7}
8
9// generic function call assigned to incorrect type
10//
11// tmp.zig:3:18: error: expected type '[]i32', found 'anyerror!i32
test/compile_errors/stage1/obj/generic_function_instance_with_non-constant_expression.zig created+10
...@@ -0,0 +1,10 @@
1fn foo(comptime x: i32, y: i32) i32 { return x + y; }
2fn test1(a: i32, b: i32) i32 {
3 return foo(a, b);
4}
5
6export fn entry() usize { return @sizeOf(@TypeOf(test1)); }
7
8// generic function instance with non-constant expression
9//
10// tmp.zig:3:16: error: runtime value cannot be passed to comptime arg
test/compile_errors/stage1/obj/generic_function_returning_opaque_type.zig created+23
...@@ -0,0 +1,23 @@
1const FooType = opaque {};
2fn generic(comptime T: type) !T {
3 return undefined;
4}
5export fn bar() void {
6 _ = generic(FooType);
7}
8export fn bav() void {
9 _ = generic(@TypeOf(null));
10}
11export fn baz() void {
12 _ = generic(@TypeOf(undefined));
13}
14
15// generic function returning opaque type
16//
17// tmp.zig:6:16: error: call to generic function with Opaque return type 'FooType' not allowed
18// tmp.zig:2:1: note: function declared here
19// tmp.zig:1:1: note: type declared here
20// tmp.zig:9:16: error: call to generic function with Null return type '@Type(.Null)' not allowed
21// tmp.zig:2:1: note: function declared here
22// tmp.zig:12:16: error: call to generic function with Undefined return type '@Type(.Undefined)' not allowed
23// tmp.zig:2:1: note: function declared here
test/compile_errors/stage1/obj/generic_function_where_return_type_is_self-referenced.zig created+13
...@@ -0,0 +1,13 @@
1fn Foo(comptime T: type) Foo(T) {
2 return struct{ x: T };
3}
4export fn entry() void {
5 const t = Foo(u32) {
6 .x = 1
7 };
8 _ = t;
9}
10
11// generic function where return type is self-referenced
12//
13// tmp.zig:1:29: error: evaluation exceeded 1000 backwards branches
test/compile_errors/stage1/obj/global_variable_alignment_non_power_of_2.zig created+6
...@@ -0,0 +1,6 @@
1const some_data: [100]u8 align(3) = undefined;
2export fn entry() usize { return @sizeOf(@TypeOf(some_data)); }
3
4// global variable alignment non power of 2
5//
6// tmp.zig:1:32: error: alignment value 3 is not a power of 2
test/compile_errors/stage1/obj/global_variable_initializer_must_be_constant_expression.zig created+7
...@@ -0,0 +1,7 @@
1extern fn foo() i32;
2const x = foo();
3export fn entry() i32 { return x; }
4
5// global variable initializer must be constant expression
6//
7// tmp.zig:2:11: error: unable to evaluate constant expression
test/compile_errors/stage1/obj/hasDecl_with_non-container.zig created+7
...@@ -0,0 +1,7 @@
1export fn entry() void {
2 _ = @hasDecl(i32, "hi");
3}
4
5// @hasDecl with non-container
6//
7// tmp.zig:2:18: error: expected struct, enum, or union; found 'i32'
test/compile_errors/stage1/obj/if_condition_is_bool_not_int.zig created+7
...@@ -0,0 +1,7 @@
1export fn f() void {
2 if (0) {}
3}
4
5// if condition is bool, not int
6//
7// tmp.zig:2:9: error: expected type 'bool', found 'comptime_int'
test/compile_errors/stage1/obj/ignored_assert-err-ok_return_value.zig created+8
...@@ -0,0 +1,8 @@
1export fn foo() void {
2 bar() catch unreachable;
3}
4fn bar() anyerror!i32 { return 0; }
5
6// ignored assert-err-ok return value
7//
8// tmp.zig:2:11: error: expression value is ignored
test/compile_errors/stage1/obj/ignored_comptime_statement_value.zig created+7
...@@ -0,0 +1,7 @@
1export fn foo() void {
2 comptime {1;}
3}
4
5// ignored comptime statement value
6//
7// tmp.zig:2:15: error: expression value is ignored
test/compile_errors/stage1/obj/ignored_comptime_value.zig created+7
...@@ -0,0 +1,7 @@
1export fn foo() void {
2 comptime 1;
3}
4
5// ignored comptime value
6//
7// tmp.zig:2:5: error: expression value is ignored
test/compile_errors/stage1/obj/ignored_deferred_function_call.zig created+8
...@@ -0,0 +1,8 @@
1export fn foo() void {
2 defer bar();
3}
4fn bar() anyerror!i32 { return 0; }
5
6// ignored deferred function call
7//
8// tmp.zig:2:14: error: error is ignored. consider using `try`, `catch`, or `if`
test/compile_errors/stage1/obj/ignored_deferred_statement_value.zig created+7
...@@ -0,0 +1,7 @@
1export fn foo() void {
2 defer {1;}
3}
4
5// ignored deferred statement value
6//
7// tmp.zig:2:12: error: expression value is ignored
test/compile_errors/stage1/obj/ignored_expression_in_while_continuation.zig created+20
...@@ -0,0 +1,20 @@
1export fn a() void {
2 while (true) : (bad()) {}
3}
4export fn b() void {
5 var x: anyerror!i32 = 1234;
6 while (x) |_| : (bad()) {} else |_| {}
7}
8export fn c() void {
9 var x: ?i32 = 1234;
10 while (x) |_| : (bad()) {}
11}
12fn bad() anyerror!void {
13 return error.Bad;
14}
15
16// ignored expression in while continuation
17//
18// tmp.zig:2:24: error: error is ignored. consider using `try`, `catch`, or `if`
19// tmp.zig:6:25: error: error is ignored. consider using `try`, `catch`, or `if`
20// tmp.zig:10:25: error: error is ignored. consider using `try`, `catch`, or `if`
test/compile_errors/stage1/obj/ignored_return_value.zig created+8
...@@ -0,0 +1,8 @@
1export fn foo() void {
2 bar();
3}
4fn bar() i32 { return 0; }
5
6// ignored return value
7//
8// tmp.zig:2:8: error: expression value is ignored
test/compile_errors/stage1/obj/ignored_statement_value.zig created+7
...@@ -0,0 +1,7 @@
1export fn foo() void {
2 1;
3}
4
5// ignored statement value
6//
7// tmp.zig:2:5: error: expression value is ignored
test/compile_errors/stage1/obj/illegal_comparison_of_types.zig created+18
...@@ -0,0 +1,18 @@
1fn bad_eql_1(a: []u8, b: []u8) bool {
2 return a == b;
3}
4const EnumWithData = union(enum) {
5 One: void,
6 Two: i32,
7};
8fn bad_eql_2(a: *const EnumWithData, b: *const EnumWithData) bool {
9 return a.* == b.*;
10}
11
12export fn entry1() usize { return @sizeOf(@TypeOf(bad_eql_1)); }
13export fn entry2() usize { return @sizeOf(@TypeOf(bad_eql_2)); }
14
15// illegal comparison of types
16//
17// tmp.zig:2:14: error: operator not allowed for type '[]u8'
18// tmp.zig:9:16: error: operator not allowed for type 'EnumWithData'
test/compile_errors/stage1/obj/implicit_cast_between_C_pointer_and_Zig_pointer-bad_const-align-child.zig created+40
...@@ -0,0 +1,40 @@
1export fn a() void {
2 var x: [*c]u8 = undefined;
3 var y: *align(4) u8 = x;
4 _ = y;
5}
6export fn b() void {
7 var x: [*c]const u8 = undefined;
8 var y: *u8 = x;
9 _ = y;
10}
11export fn c() void {
12 var x: [*c]u8 = undefined;
13 var y: *u32 = x;
14 _ = y;
15}
16export fn d() void {
17 var y: *align(1) u32 = undefined;
18 var x: [*c]u32 = y;
19 _ = x;
20}
21export fn e() void {
22 var y: *const u8 = undefined;
23 var x: [*c]u8 = y;
24 _ = x;
25}
26export fn f() void {
27 var y: *u8 = undefined;
28 var x: [*c]u32 = y;
29 _ = x;
30}
31
32// implicit cast between C pointer and Zig pointer - bad const/align/child
33//
34// tmp.zig:3:27: error: cast increases pointer alignment
35// tmp.zig:8:18: error: cast discards const qualifier
36// tmp.zig:13:19: error: expected type '*u32', found '[*c]u8'
37// tmp.zig:13:19: note: pointer type child 'u8' cannot cast into pointer type child 'u32'
38// tmp.zig:18:22: error: cast increases pointer alignment
39// tmp.zig:23:21: error: cast discards const qualifier
40// tmp.zig:28:22: error: expected type '[*c]u32', found '*u8'
test/compile_errors/stage1/obj/implicit_cast_const_array_to_mutable_slice.zig created+10
...@@ -0,0 +1,10 @@
1export fn entry() void {
2 const buffer: [1]u8 = [_]u8{8};
3 const sliceA: []u8 = &buffer;
4 _ = sliceA;
5}
6
7// implicit cast const array to mutable slice
8//
9// tmp.zig:3:27: error: cannot cast pointer to array literal to slice type '[]u8'
10// tmp.zig:3:27: note: cast discards const qualifier
test/compile_errors/stage1/obj/implicit_cast_from_array_to_mutable_slice.zig created+9
...@@ -0,0 +1,9 @@
1var global_array: [10]i32 = undefined;
2fn foo(param: []i32) void {_ = param;}
3export fn entry() void {
4 foo(global_array);
5}
6
7// implicit cast from array to mutable slice
8//
9// tmp.zig:4:9: error: expected type '[]i32', found '[10]i32'
test/compile_errors/stage1/obj/implicit_cast_from_f64_to_f32.zig created+8
...@@ -0,0 +1,8 @@
1var x: f64 = 1.0;
2var y: f32 = x;
3
4export fn entry() usize { return @sizeOf(@TypeOf(y)); }
5
6// implicit cast from f64 to f32
7//
8// tmp.zig:2:14: error: expected type 'f32', found 'f64'
test/compile_errors/stage1/obj/implicit_cast_of_error_set_not_a_subset.zig created+14
...@@ -0,0 +1,14 @@
1const Set1 = error{A, B};
2const Set2 = error{A, C};
3export fn entry() void {
4 foo(Set1.B);
5}
6fn foo(set1: Set1) void {
7 var x: Set2 = set1;
8 _ = x;
9}
10
11// implicit cast of error set not a subset
12//
13// tmp.zig:7:19: error: expected type 'Set2', found 'Set1'
14// tmp.zig:1:23: note: 'error.B' not a member of destination error set
test/compile_errors/stage1/obj/implicit_casting_C_pointers_which_would_mess_up_null_semantics.zig created+24
...@@ -0,0 +1,24 @@
1export fn entry() void {
2 var slice: []const u8 = "aoeu";
3 const opt_many_ptr: [*]const u8 = slice.ptr;
4 var ptr_opt_many_ptr = &opt_many_ptr;
5 var c_ptr: [*c]const [*c]const u8 = ptr_opt_many_ptr;
6 ptr_opt_many_ptr = c_ptr;
7}
8export fn entry2() void {
9 var buf: [4]u8 = "aoeu".*;
10 var slice: []u8 = &buf;
11 var opt_many_ptr: [*]u8 = slice.ptr;
12 var ptr_opt_many_ptr = &opt_many_ptr;
13 var c_ptr: [*c][*c]const u8 = ptr_opt_many_ptr;
14 _ = c_ptr;
15}
16
17// implicit casting C pointers which would mess up null semantics
18//
19// tmp.zig:6:24: error: expected type '*const [*]const u8', found '[*c]const [*c]const u8'
20// tmp.zig:6:24: note: pointer type child '[*c]const u8' cannot cast into pointer type child '[*]const u8'
21// tmp.zig:6:24: note: '[*c]const u8' could have null values which are illegal in type '[*]const u8'
22// tmp.zig:13:35: error: expected type '[*c][*c]const u8', found '*[*]u8'
23// tmp.zig:13:35: note: pointer type child '[*]u8' cannot cast into pointer type child '[*c]const u8'
24// tmp.zig:13:35: note: mutable '[*c]const u8' allows illegal null values stored to type '[*]u8'
test/compile_errors/stage1/obj/implicit_casting_null_c_pointer_to_zig_pointer.zig created+9
...@@ -0,0 +1,9 @@
1comptime {
2 var c_ptr: [*c]u8 = 0;
3 var zig_ptr: *u8 = c_ptr;
4 _ = zig_ptr;
5}
6
7// implicit casting null c pointer to zig pointer
8//
9// tmp.zig:3:24: error: null pointer casted to type '*u8'
test/compile_errors/stage1/obj/implicit_casting_too_big_integers_to_C_pointers.zig created+14
...@@ -0,0 +1,14 @@
1export fn a() void {
2 var ptr: [*c]u8 = (1 << 64) + 1;
3 _ = ptr;
4}
5export fn b() void {
6 var x: u65 = 0x1234;
7 var ptr: [*c]u8 = x;
8 _ = ptr;
9}
10
11// implicit casting too big integers to C pointers
12//
13// tmp.zig:2:33: error: integer value 18446744073709551617 cannot be coerced to type 'usize'
14// tmp.zig:7:23: error: integer type 'u65' too big for implicit @intToPtr to type '[*c]u8'
test/compile_errors/stage1/obj/implicit_casting_undefined_c_pointer_to_zig_pointer.zig created+9
...@@ -0,0 +1,9 @@
1comptime {
2 var c_ptr: [*c]u8 = undefined;
3 var zig_ptr: *u8 = c_ptr;
4 _ = zig_ptr;
5}
6
7// implicit casting undefined c pointer to zig pointer
8//
9// tmp.zig:3:24: error: use of undefined value here causes undefined behavior
test/compile_errors/stage1/obj/implicit_semicolon-block_expr.zig created+10
...@@ -0,0 +1,10 @@
1export fn entry() void {
2 _ = {};
3 var good = {};
4 _ = {}
5 var bad = {};
6}
7
8// implicit semicolon - block expr
9//
10// tmp.zig:4:11: error: expected ';' after statement
test/compile_errors/stage1/obj/implicit_semicolon-block_statement.zig created+10
...@@ -0,0 +1,10 @@
1export fn entry() void {
2 {}
3 var good = {};
4 ({})
5 var bad = {};
6}
7
8// implicit semicolon - block statement
9//
10// tmp.zig:4:9: error: expected ';' after statement
test/compile_errors/stage1/obj/implicit_semicolon-comptime_expression.zig created+10
...@@ -0,0 +1,10 @@
1export fn entry() void {
2 _ = comptime {};
3 var good = {};
4 _ = comptime {}
5 var bad = {};
6}
7
8// implicit semicolon - comptime expression
9//
10// tmp.zig:4:20: error: expected ';' after statement
test/compile_errors/stage1/obj/implicit_semicolon-comptime_statement.zig created+10
...@@ -0,0 +1,10 @@
1export fn entry() void {
2 comptime {}
3 var good = {};
4 comptime ({})
5 var bad = {};
6}
7
8// implicit semicolon - comptime statement
9//
10// tmp.zig:4:18: error: expected ';' after statement
test/compile_errors/stage1/obj/implicit_semicolon-defer.zig created+10
...@@ -0,0 +1,10 @@
1export fn entry() void {
2 defer {}
3 var good = {};
4 defer ({})
5 var bad = {};
6}
7
8// implicit semicolon - defer
9//
10// tmp.zig:4:15: error: expected ';' after statement
test/compile_errors/stage1/obj/implicit_semicolon-for_expression.zig created+10
...@@ -0,0 +1,10 @@
1export fn entry() void {
2 _ = for(foo()) |_| {};
3 var good = {};
4 _ = for(foo()) |_| {}
5 var bad = {};
6}
7
8// implicit semicolon - for expression
9//
10// tmp.zig:4:26: error: expected ';' after statement
test/compile_errors/stage1/obj/implicit_semicolon-for_statement.zig created+10
...@@ -0,0 +1,10 @@
1export fn entry() void {
2 for(foo()) |_| {}
3 var good = {};
4 for(foo()) |_| ({})
5 var bad = {};
6}
7
8// implicit semicolon - for statement
9//
10// tmp.zig:4:24: error: expected ';' or 'else' after statement
test/compile_errors/stage1/obj/implicit_semicolon-if-else-if-else_expression.zig created+10
...@@ -0,0 +1,10 @@
1export fn entry() void {
2 _ = if(true) {} else if(true) {} else {};
3 var good = {};
4 _ = if(true) {} else if(true) {} else {}
5 var bad = {};
6}
7
8// implicit semicolon - if-else-if-else expression
9//
10// tmp.zig:4:45: error: expected ';' after statement
test/compile_errors/stage1/obj/implicit_semicolon-if-else-if-else_statement.zig created+10
...@@ -0,0 +1,10 @@
1export fn entry() void {
2 if(true) {} else if(true) {} else {}
3 var good = {};
4 if(true) ({}) else if(true) ({}) else ({})
5 var bad = {};
6}
7
8// implicit semicolon - if-else-if-else statement
9//
10// tmp.zig:4:47: error: expected ';' after statement
test/compile_errors/stage1/obj/implicit_semicolon-if-else-if_expression.zig created+10
...@@ -0,0 +1,10 @@
1export fn entry() void {
2 _ = if(true) {} else if(true) {};
3 var good = {};
4 _ = if(true) {} else if(true) {}
5 var bad = {};
6}
7
8// implicit semicolon - if-else-if expression
9//
10// tmp.zig:4:37: error: expected ';' after statement
test/compile_errors/stage1/obj/implicit_semicolon-if-else-if_statement.zig created+10
...@@ -0,0 +1,10 @@
1export fn entry() void {
2 if(true) {} else if(true) {}
3 var good = {};
4 if(true) ({}) else if(true) ({})
5 var bad = {};
6}
7
8// implicit semicolon - if-else-if statement
9//
10// tmp.zig:4:37: error: expected ';' or 'else' after statement
test/compile_errors/stage1/obj/implicit_semicolon-if-else_expression.zig created+10
...@@ -0,0 +1,10 @@
1export fn entry() void {
2 _ = if(true) {} else {};
3 var good = {};
4 _ = if(true) {} else {}
5 var bad = {};
6}
7
8// implicit semicolon - if-else expression
9//
10// tmp.zig:4:28: error: expected ';' after statement
test/compile_errors/stage1/obj/implicit_semicolon-if-else_statement.zig created+10
...@@ -0,0 +1,10 @@
1export fn entry() void {
2 if(true) {} else {}
3 var good = {};
4 if(true) ({}) else ({})
5 var bad = {};
6}
7
8// implicit semicolon - if-else statement
9//
10// tmp.zig:4:28: error: expected ';' after statement
test/compile_errors/stage1/obj/implicit_semicolon-if_expression.zig created+10
...@@ -0,0 +1,10 @@
1export fn entry() void {
2 _ = if(true) {};
3 var good = {};
4 _ = if(true) {}
5 var bad = {};
6}
7
8// implicit semicolon - if expression
9//
10// tmp.zig:4:20: error: expected ';' after statement
test/compile_errors/stage1/obj/implicit_semicolon-if_statement.zig created+10
...@@ -0,0 +1,10 @@
1export fn entry() void {
2 if(true) {}
3 var good = {};
4 if(true) ({})
5 var bad = {};
6}
7
8// implicit semicolon - if statement
9//
10// tmp.zig:4:18: error: expected ';' or 'else' after statement
test/compile_errors/stage1/obj/implicit_semicolon-test_expression.zig created+10
...@@ -0,0 +1,10 @@
1export fn entry() void {
2 _ = if (foo()) |_| {};
3 var good = {};
4 _ = if (foo()) |_| {}
5 var bad = {};
6}
7
8// implicit semicolon - test expression
9//
10// tmp.zig:4:26: error: expected ';' after statement
test/compile_errors/stage1/obj/implicit_semicolon-test_statement.zig created+10
...@@ -0,0 +1,10 @@
1export fn entry() void {
2 if (foo()) |_| {}
3 var good = {};
4 if (foo()) |_| ({})
5 var bad = {};
6}
7
8// implicit semicolon - test statement
9//
10// tmp.zig:4:24: error: expected ';' or 'else' after statement
test/compile_errors/stage1/obj/implicit_semicolon-while-continue_expression.zig created+10
...@@ -0,0 +1,10 @@
1export fn entry() void {
2 _ = while(true):({}) {};
3 var good = {};
4 _ = while(true):({}) {}
5 var bad = {};
6}
7
8// implicit semicolon - while-continue expression
9//
10// tmp.zig:4:28: error: expected ';' after statement
test/compile_errors/stage1/obj/implicit_semicolon-while-continue_statement.zig created+10
...@@ -0,0 +1,10 @@
1export fn entry() void {
2 while(true):({}) {}
3 var good = {};
4 while(true):({}) ({})
5 var bad = {};
6}
7
8// implicit semicolon - while-continue statement
9//
10// tmp.zig:4:26: error: expected ';' or 'else' after statement
test/compile_errors/stage1/obj/implicit_semicolon-while_expression.zig created+10
...@@ -0,0 +1,10 @@
1export fn entry() void {
2 _ = while(true) {};
3 var good = {};
4 _ = while(true) {}
5 var bad = {};
6}
7
8// implicit semicolon - while expression
9//
10// tmp.zig:4:23: error: expected ';' after statement
test/compile_errors/stage1/obj/implicit_semicolon-while_statement.zig created+10
...@@ -0,0 +1,10 @@
1export fn entry() void {
2 while(true) {}
3 var good = {};
4 while(true) 1
5 var bad = {};
6}
7
8// implicit semicolon - while statement
9//
10// tmp.zig:4:18: error: expected ';' or 'else' after statement
test/compile_errors/stage1/obj/implicitly_casting_enum_to_tag_type.zig created+15
...@@ -0,0 +1,15 @@
1const Small = enum(u2) {
2 One,
3 Two,
4 Three,
5 Four,
6};
7
8export fn entry() void {
9 var x: u2 = Small.Two;
10 _ = x;
11}
12
13// implicitly casting enum to tag type
14//
15// tmp.zig:9:22: error: expected type 'u2', found 'Small'
test/compile_errors/stage1/obj/implicitly_increasing_pointer_alignment.zig created+17
...@@ -0,0 +1,17 @@
1const Foo = packed struct {
2 a: u8,
3 b: u32,
4};
5
6export fn entry() void {
7 var foo = Foo { .a = 1, .b = 10 };
8 bar(&foo.b);
9}
10
11fn bar(x: *u32) void {
12 x.* += 1;
13}
14
15// implicitly increasing pointer alignment
16//
17// tmp.zig:8:13: error: expected type '*u32', found '*align(1) u32'
test/compile_errors/stage1/obj/implicitly_increasing_slice_alignment.zig created+20
...@@ -0,0 +1,20 @@
1const Foo = packed struct {
2 a: u8,
3 b: u32,
4};
5
6export fn entry() void {
7 var foo = Foo { .a = 1, .b = 10 };
8 foo.b += 1;
9 bar(@as(*[1]u32, &foo.b)[0..]);
10}
11
12fn bar(x: []u32) void {
13 x[0] += 1;
14}
15
16// implicitly increasing slice alignment
17//
18// tmp.zig:9:26: error: cast increases pointer alignment
19// tmp.zig:9:26: note: '*align(1) u32' has alignment 1
20// tmp.zig:9:26: note: '*[1]u32' has alignment 4
test/compile_errors/stage1/obj/import_outside_package_path.zig created+7
...@@ -0,0 +1,7 @@
1comptime{
2 _ = @import("../a.zig");
3}
4
5// import outside package path
6//
7// tmp.zig:2:9: error: import of file outside package path: '../a.zig'
test/compile_errors/stage1/obj/incorrect_return_type.zig created+19
...@@ -0,0 +1,19 @@
1 pub export fn entry() void{
2 _ = foo();
3 }
4 const A = struct {
5 a: u32,
6 };
7 fn foo() A {
8 return bar();
9 }
10 const B = struct {
11 a: u32,
12 };
13 fn bar() B {
14 unreachable;
15 }
16
17// incorrect return type
18//
19// tmp.zig:8:16: error: expected type 'A', found 'B'
test/compile_errors/stage1/obj/increase_pointer_alignment_in_ptrCast.zig created+11
...@@ -0,0 +1,11 @@
1export fn entry() u32 {
2 var bytes: [4]u8 = [_]u8{0x01, 0x02, 0x03, 0x04};
3 const ptr = @ptrCast(*u32, &bytes[0]);
4 return ptr.*;
5}
6
7// increase pointer alignment in @ptrCast
8//
9// tmp.zig:3:17: error: cast increases pointer alignment
10// tmp.zig:3:38: note: '*u8' has alignment 1
11// tmp.zig:3:26: note: '*u32' has alignment 4
test/compile_errors/stage1/obj/indexing_a_undefined_slice_at_comptime.zig created+8
...@@ -0,0 +1,8 @@
1comptime {
2 var slice: []u8 = undefined;
3 slice[0] = 2;
4}
5
6// indexing a undefined slice at comptime
7//
8// tmp.zig:3:10: error: index 0 outside slice of size 0
test/compile_errors/stage1/obj/indexing_an_array_of_size_zero.zig created+9
...@@ -0,0 +1,9 @@
1const array = [_]u8{};
2export fn foo() void {
3 const pointer = &array[0];
4 _ = pointer;
5}
6
7// indexing an array of size zero
8//
9// tmp.zig:3:27: error: accessing a zero length array is not allowed
test/compile_errors/stage1/obj/indexing_an_array_of_size_zero_with_runtime_index.zig created+10
...@@ -0,0 +1,10 @@
1const array = [_]u8{};
2export fn foo() void {
3 var index: usize = 0;
4 const pointer = &array[index];
5 _ = pointer;
6}
7
8// indexing an array of size zero with runtime index
9//
10// tmp.zig:4:27: error: accessing a zero length array is not allowed
test/compile_errors/stage1/obj/indexing_single-item_pointer.zig created+7
...@@ -0,0 +1,7 @@
1export fn entry(ptr: *i32) i32 {
2 return ptr[1];
3}
4
5// indexing single-item pointer
6//
7// tmp.zig:2:15: error: index of single-item pointer
test/compile_errors/stage1/obj/indirect_recursion_of_async_functions_detected.zig created+34
...@@ -0,0 +1,34 @@
1var frame: ?anyframe = null;
2
3export fn a() void {
4 _ = async rangeSum(10);
5 while (frame) |f| resume f;
6}
7
8fn rangeSum(x: i32) i32 {
9 suspend {
10 frame = @frame();
11 }
12 frame = null;
13
14 if (x == 0) return 0;
15 var child = rangeSumIndirect(x - 1);
16 return child + 1;
17}
18
19fn rangeSumIndirect(x: i32) i32 {
20 suspend {
21 frame = @frame();
22 }
23 frame = null;
24
25 if (x == 0) return 0;
26 var child = rangeSum(x - 1);
27 return child + 1;
28}
29
30// indirect recursion of async functions detected
31//
32// tmp.zig:8:1: error: '@Frame(rangeSum)' depends on itself
33// tmp.zig:15:33: note: when analyzing type '@Frame(rangeSum)' here
34// tmp.zig:26:25: note: when analyzing type '@Frame(rangeSumIndirect)' here
test/compile_errors/stage1/obj/indirect_struct_loop.zig created+8
...@@ -0,0 +1,8 @@
1const A = struct { b : B, };
2const B = struct { c : C, };
3const C = struct { a : A, };
4export fn entry() usize { return @sizeOf(A); }
5
6// indirect struct loop
7//
8// tmp.zig:1:11: error: struct 'A' depends on itself
test/compile_errors/stage1/obj/inferred_array_size_invalid_here.zig created+14
...@@ -0,0 +1,14 @@
1export fn entry() void {
2 const x = [_]u8;
3 _ = x;
4}
5export fn entry2() void {
6 const S = struct { a: *const [_]u8 };
7 var a = .{ S{} };
8 _ = a;
9}
10
11// inferred array size invalid here
12//
13// tmp.zig:2:16: error: unable to infer array size
14// tmp.zig:6:35: error: unable to infer array size
test/compile_errors/stage1/obj/inferring_error_set_of_function_pointer.zig created+7
...@@ -0,0 +1,7 @@
1comptime {
2 const z: ?fn()!void = null;
3}
4
5// inferring error set of function pointer
6//
7// tmp.zig:2:19: error: function prototype may not have inferred error set
test/compile_errors/stage1/obj/initializing_array_with_struct_syntax.zig created+8
...@@ -0,0 +1,8 @@
1export fn entry() void {
2 const x = [_]u8{ .y = 2 };
3 _ = x;
4}
5
6// initializing array with struct syntax
7//
8// tmp.zig:2:15: error: initializing array with struct syntax
test/compile_errors/stage1/obj/instantiating_an_undefined_value_for_an_invalid_struct_that_contains_itself.zig created+13
...@@ -0,0 +1,13 @@
1const Foo = struct {
2 x: Foo,
3};
4
5var foo: Foo = undefined;
6
7export fn entry() usize {
8 return @sizeOf(@TypeOf(foo.x));
9}
10
11// instantiating an undefined value for an invalid struct that contains itself
12//
13// tmp.zig:1:13: error: struct 'Foo' depends on itself
test/compile_errors/stage1/obj/intToPtr_with_misaligned_address.zig created+8
...@@ -0,0 +1,8 @@
1pub fn main() void {
2 var y = @intToPtr([*]align(4) u8, 5);
3 _ = y;
4}
5
6// intToPtr with misaligned address
7//
8// tmp.zig:2:13: error: pointer type '[*]align(4) u8' requires aligned address
test/compile_errors/stage1/obj/int_to_err_global_invalid_number.zig created+13
...@@ -0,0 +1,13 @@
1const Set1 = error{
2 A,
3 B,
4};
5comptime {
6 var x: u16 = 3;
7 var y = @intToError(x);
8 _ = y;
9}
10
11// int to err global invalid number
12//
13// tmp.zig:7:13: error: integer value 3 represents no error
test/compile_errors/stage1/obj/int_to_err_non_global_invalid_number.zig created+17
...@@ -0,0 +1,17 @@
1const Set1 = error{
2 A,
3 B,
4};
5const Set2 = error{
6 A,
7 C,
8};
9comptime {
10 var x = @errorToInt(Set1.B);
11 var y = @errSetCast(Set2, @intToError(x));
12 _ = y;
13}
14
15// int to err non global invalid number
16//
17// tmp.zig:11:13: error: error.B not a member of error set 'Set2'
test/compile_errors/stage1/obj/int_to_ptr_of_0_bits.zig created+9
...@@ -0,0 +1,9 @@
1export fn foo() void {
2 var x: usize = 0x1000;
3 var y: *void = @intToPtr(*void, x);
4 _ = y;
5}
6
7// int to ptr of 0 bits
8//
9// tmp.zig:3:30: error: type '*void' has 0 bits and cannot store information
test/compile_errors/stage1/obj/integer_cast_truncates_bits.zig created+29
...@@ -0,0 +1,29 @@
1export fn entry1() void {
2 const spartan_count: u16 = 300;
3 const byte = @intCast(u8, spartan_count);
4 _ = byte;
5}
6export fn entry2() void {
7 const spartan_count: u16 = 300;
8 const byte: u8 = spartan_count;
9 _ = byte;
10}
11export fn entry3() void {
12 var spartan_count: u16 = 300;
13 var byte: u8 = spartan_count;
14 _ = byte;
15}
16export fn entry4() void {
17 var signed: i8 = -1;
18 var unsigned: u64 = signed;
19 _ = unsigned;
20}
21
22// integer cast truncates bits
23//
24// tmp.zig:3:18: error: cast from 'u16' to 'u8' truncates bits
25// tmp.zig:8:22: error: integer value 300 cannot be coerced to type 'u8'
26// tmp.zig:13:20: error: expected type 'u8', found 'u16'
27// tmp.zig:13:20: note: unsigned 8-bit int cannot represent all possible unsigned 16-bit values
28// tmp.zig:18:25: error: expected type 'u64', found 'i8'
29// tmp.zig:18:25: note: unsigned 64-bit int cannot represent all possible signed 8-bit values
test/compile_errors/stage1/obj/integer_overflow_error.zig created+6
...@@ -0,0 +1,6 @@
1const x : u8 = 300;
2export fn entry() usize { return @sizeOf(@TypeOf(x)); }
3
4// integer overflow error
5//
6// tmp.zig:1:16: error: integer value 300 cannot be coerced to type 'u8'
test/compile_errors/stage1/obj/integer_underflow_error.zig created+7
...@@ -0,0 +1,7 @@
1export fn entry() void {
2 _ = @intToPtr(*anyopaque, ~@as(usize, @import("std").math.maxInt(usize)) - 1);
3}
4
5// integer underflow error
6//
7// :2:78: error: operation caused overflow
test/compile_errors/stage1/obj/invalid_break_expression.zig created+7
...@@ -0,0 +1,7 @@
1export fn f() void {
2 break;
3}
4
5// invalid break expression
6//
7// tmp.zig:2:5: error: break expression outside loop
test/compile_errors/stage1/obj/invalid_builtin_fn.zig created+7
...@@ -0,0 +1,7 @@
1fn f() @bogus(foo) {
2}
3export fn entry() void { _ = f(); }
4
5// invalid builtin fn
6//
7// tmp.zig:1:8: error: invalid builtin function: '@bogus'
test/compile_errors/stage1/obj/invalid_cast_from_integral_type_to_enum.zig created+15
...@@ -0,0 +1,15 @@
1const E = enum(usize) { One, Two };
2
3export fn entry() void {
4 foo(1);
5}
6
7fn foo(x: usize) void {
8 switch (x) {
9 E.One => {},
10 }
11}
12
13// invalid cast from integral type to enum
14//
15// tmp.zig:9:10: error: expected type 'usize', found 'E'
test/compile_errors/stage1/obj/invalid_comparison_for_function_pointers.zig created+8
...@@ -0,0 +1,8 @@
1fn foo() void {}
2const invalid = foo > foo;
3
4export fn entry() usize { return @sizeOf(@TypeOf(invalid)); }
5
6// invalid comparison for function pointers
7//
8// tmp.zig:2:21: error: operator not allowed for type 'fn() void'
test/compile_errors/stage1/obj/invalid_continue_expression.zig created+7
...@@ -0,0 +1,7 @@
1export fn f() void {
2 continue;
3}
4
5// invalid continue expression
6//
7// tmp.zig:2:5: error: continue expression outside loop
test/compile_errors/stage1/obj/invalid_deref_on_switch_target.zig created+15
...@@ -0,0 +1,15 @@
1comptime {
2 var tile = Tile.Empty;
3 switch (tile.*) {
4 Tile.Empty => {},
5 Tile.Filled => {},
6 }
7}
8const Tile = enum {
9 Empty,
10 Filled,
11};
12
13// invalid deref on switch target
14//
15// tmp.zig:3:17: error: attempt to dereference non-pointer type 'Tile'
test/compile_errors/stage1/obj/invalid_empty_unicode_escape.zig created+7
...@@ -0,0 +1,7 @@
1export fn entry() void {
2 const a = '\u{}';
3}
4
5// invalid empty unicode escape
6//
7// tmp.zig:2:19: error: empty unicode escape sequence
test/compile_errors/stage1/obj/invalid_exponent_in_float_literal-1.zig created+9
...@@ -0,0 +1,9 @@
1fn main() void {
2 var bad: f128 = 0x1.0p1ab1;
3 _ = bad;
4}
5
6// invalid exponent in float literal - 1
7//
8// tmp.zig:2:21: error: expected expression, found 'invalid bytes'
9// tmp.zig:2:28: note: invalid byte: 'a'
test/compile_errors/stage1/obj/invalid_exponent_in_float_literal-2.zig created+9
...@@ -0,0 +1,9 @@
1fn main() void {
2 var bad: f128 = 0x1.0p50F;
3 _ = bad;
4}
5
6// invalid exponent in float literal - 2
7//
8// tmp.zig:2:21: error: expected expression, found 'invalid bytes'
9// tmp.zig:2:29: note: invalid byte: 'F'
test/compile_errors/stage1/obj/invalid_field_access_in_comptime.zig created+5
...@@ -0,0 +1,5 @@
1comptime { var x = doesnt_exist.whatever; _ = x; }
2
3// invalid field access in comptime
4//
5// tmp.zig:1:20: error: use of undeclared identifier 'doesnt_exist'
test/compile_errors/stage1/obj/invalid_field_in_struct_value_expression.zig created+17
...@@ -0,0 +1,17 @@
1const A = struct {
2 x : i32,
3 y : i32,
4 z : i32,
5};
6export fn f() void {
7 const a = A {
8 .z = 4,
9 .y = 2,
10 .foo = 42,
11 };
12 _ = a;
13}
14
15// invalid field in struct value expression
16//
17// tmp.zig:10:9: error: no member named 'foo' in struct 'A'
test/compile_errors/stage1/obj/invalid_float_literal.zig created+11
...@@ -0,0 +1,11 @@
1const std = @import("std");
2
3pub fn main() void {
4 var bad_float :f32 = 0.0;
5 bad_float = bad_float + .20;
6 std.debug.assert(bad_float < 1.0);
7}
8
9// invalid float literal
10//
11// tmp.zig:5:29: error: expected expression, found '.'
test/compile_errors/stage1/obj/invalid_legacy_unicode_escape.zig created+8
...@@ -0,0 +1,8 @@
1export fn entry() void {
2 const a = '\U1234';
3}
4
5// invalid legacy unicode escape
6//
7// tmp.zig:2:15: error: expected expression, found 'invalid bytes'
8// tmp.zig:2:18: note: invalid byte: '1'
test/compile_errors/stage1/obj/invalid_maybe_type.zig created+7
...@@ -0,0 +1,7 @@
1export fn f() void {
2 if (true) |x| { _ = x; }
3}
4
5// invalid maybe type
6//
7// tmp.zig:2:9: error: expected optional type, found 'bool'
test/compile_errors/stage1/obj/invalid_member_of_builtin_enum.zig created+9
...@@ -0,0 +1,9 @@
1const builtin = @import("std").builtin;
2export fn entry() void {
3 const foo = builtin.Mode.x86;
4 _ = foo;
5}
6
7// invalid member of builtin enum
8//
9// tmp.zig:3:29: error: container 'std.builtin.Mode' has no member called 'x86'
test/compile_errors/stage1/obj/invalid_multiple_dereferences.zig created+17
...@@ -0,0 +1,17 @@
1export fn a() void {
2 var box = Box{ .field = 0 };
3 box.*.field = 1;
4}
5export fn b() void {
6 var box = Box{ .field = 0 };
7 var boxPtr = &box;
8 boxPtr.*.*.field = 1;
9}
10pub const Box = struct {
11 field: i32,
12};
13
14// invalid multiple dereferences
15//
16// tmp.zig:3:8: error: attempt to dereference non-pointer type 'Box'
17// tmp.zig:8:13: error: attempt to dereference non-pointer type 'Box'
test/compile_errors/stage1/obj/invalid_optional_type_in_extern_struct.zig created+8
...@@ -0,0 +1,8 @@
1const stroo = extern struct {
2 moo: ?[*c]u8,
3};
4export fn testf(fluff: *stroo) void { _ = fluff; }
5
6// invalid optional type in extern struct
7//
8// tmp.zig:2:5: error: extern structs cannot contain fields of type '?[*c]u8'
test/compile_errors/stage1/obj/invalid_pointer_for_var_type.zig created+11
...@@ -0,0 +1,11 @@
1extern fn ext() usize;
2var bytes: [ext()]u8 = undefined;
3export fn f() void {
4 for (bytes) |*b, i| {
5 b.* = @as(u8, i);
6 }
7}
8
9// invalid pointer for var type
10//
11// tmp.zig:2:13: error: unable to evaluate constant expression
test/compile_errors/stage1/obj/invalid_pointer_syntax.zig created+7
...@@ -0,0 +1,7 @@
1export fn foo() void {
2 var guid: *:0 const u8 = undefined;
3}
4
5// invalid pointer syntax
6//
7// tmp.zig:2:16: error: expected type expression, found ':'
test/compile_errors/stage1/obj/invalid_shift_amount_error.zig created+9
...@@ -0,0 +1,9 @@
1const x : u8 = 2;
2fn f() u16 {
3 return x << 8;
4}
5export fn entry() u16 { return f(); }
6
7// invalid shift amount error
8//
9// tmp.zig:3:17: error: integer value 8 cannot be coerced to type 'u3'
test/compile_errors/stage1/obj/invalid_struct_field.zig created+17
...@@ -0,0 +1,17 @@
1const A = struct { x : i32, };
2export fn f() void {
3 var a : A = undefined;
4 a.foo = 1;
5 const y = a.bar;
6 _ = y;
7}
8export fn g() void {
9 var a : A = undefined;
10 const y = a.bar;
11 _ = y;
12}
13
14// invalid struct field
15//
16// tmp.zig:4:6: error: no member named 'foo' in struct 'A'
17// tmp.zig:10:16: error: no member named 'bar' in struct 'A'
test/compile_errors/stage1/obj/invalid_suspend_in_exported_function.zig created+13
...@@ -0,0 +1,13 @@
1export fn entry() void {
2 var frame = async func();
3 var result = await frame;
4 _ = result;
5}
6fn func() void {
7 suspend {}
8}
9
10// invalid suspend in exported function
11//
12// tmp.zig:1:1: error: function with calling convention 'C' cannot be async
13// tmp.zig:3:18: note: await here is a suspend point
test/compile_errors/stage1/obj/invalid_type.zig created+6
...@@ -0,0 +1,6 @@
1fn a() bogus {}
2export fn entry() void { _ = a(); }
3
4// invalid type
5//
6// tmp.zig:1:8: error: use of undeclared identifier 'bogus'
test/compile_errors/stage1/obj/invalid_type_used_in_array_type.zig created+12
...@@ -0,0 +1,12 @@
1const Item = struct {
2 field: SomeNonexistentType,
3};
4var items: [100]Item = undefined;
5export fn entry() void {
6 const a = items[0];
7 _ = a;
8}
9
10// invalid type used in array type
11//
12// tmp.zig:2:12: error: use of undeclared identifier 'SomeNonexistentType'
test/compile_errors/stage1/obj/invalid_underscore_placement_in_float_literal-1.zig created+9
...@@ -0,0 +1,9 @@
1fn main() void {
2 var bad: f128 = 0._0;
3 _ = bad;
4}
5
6// invalid underscore placement in float literal - 1
7//
8// tmp.zig:2:21: error: expected expression, found 'invalid bytes'
9// tmp.zig:2:23: note: invalid byte: '_'
test/compile_errors/stage1/obj/invalid_underscore_placement_in_float_literal-10.zig created+9
...@@ -0,0 +1,9 @@
1fn main() void {
2 var bad: f128 = 1.0__0e-1;
3 _ = bad;
4}
5
6// invalid underscore placement in float literal - 10
7//
8// tmp.zig:2:21: error: expected expression, found 'invalid bytes'
9// tmp.zig:2:25: note: invalid byte: '_'
test/compile_errors/stage1/obj/invalid_underscore_placement_in_float_literal-11.zig created+9
...@@ -0,0 +1,9 @@
1fn main() void {
2 var bad: f128 = 1.0e-1__0;
3 _ = bad;
4}
5
6// invalid underscore placement in float literal - 11
7//
8// tmp.zig:2:21: error: expected expression, found 'invalid bytes'
9// tmp.zig:2:28: note: invalid byte: '_'
test/compile_errors/stage1/obj/invalid_underscore_placement_in_float_literal-12.zig created+9
...@@ -0,0 +1,9 @@
1fn main() void {
2 var bad: f128 = 0_x0.0;
3 _ = bad;
4}
5
6// invalid underscore placement in float literal - 12
7//
8// tmp.zig:2:21: error: expected expression, found 'invalid bytes'
9// tmp.zig:2:23: note: invalid byte: 'x'
test/compile_errors/stage1/obj/invalid_underscore_placement_in_float_literal-13.zig created+9
...@@ -0,0 +1,9 @@
1fn main() void {
2 var bad: f128 = 0x_0.0;
3 _ = bad;
4}
5
6// invalid underscore placement in float literal - 13
7//
8// tmp.zig:2:21: error: expected expression, found 'invalid bytes'
9// tmp.zig:2:23: note: invalid byte: '_'
test/compile_errors/stage1/obj/invalid_underscore_placement_in_float_literal-14.zig created+9
...@@ -0,0 +1,9 @@
1fn main() void {
2 var bad: f128 = 0x0.0_p1;
3 _ = bad;
4}
5
6// invalid underscore placement in float literal - 14
7//
8// tmp.zig:2:21: error: expected expression, found 'invalid bytes'
9// tmp.zig:2:27: note: invalid byte: 'p'
test/compile_errors/stage1/obj/invalid_underscore_placement_in_float_literal-2.zig created+9
...@@ -0,0 +1,9 @@
1fn main() void {
2 var bad: f128 = 0_.0;
3 _ = bad;
4}
5
6// invalid underscore placement in float literal - 2
7//
8// tmp.zig:2:21: error: expected expression, found 'invalid bytes'
9// tmp.zig:2:23: note: invalid byte: '.'
test/compile_errors/stage1/obj/invalid_underscore_placement_in_float_literal-3.zig created+9
...@@ -0,0 +1,9 @@
1fn main() void {
2 var bad: f128 = 0.0_;
3 _ = bad;
4}
5
6// invalid underscore placement in float literal - 3
7//
8// tmp.zig:2:21: error: expected expression, found 'invalid bytes'
9// tmp.zig:2:25: note: invalid byte: ';'
test/compile_errors/stage1/obj/invalid_underscore_placement_in_float_literal-4.zig created+9
...@@ -0,0 +1,9 @@
1fn main() void {
2 var bad: f128 = 1.0e_1;
3 _ = bad;
4}
5
6// invalid underscore placement in float literal - 4
7//
8// tmp.zig:2:21: error: expected expression, found 'invalid bytes'
9// tmp.zig:2:25: note: invalid byte: '_'
test/compile_errors/stage1/obj/invalid_underscore_placement_in_float_literal-5.zig created+9
...@@ -0,0 +1,9 @@
1fn main() void {
2 var bad: f128 = 1.0e+_1;
3 _ = bad;
4}
5
6// invalid underscore placement in float literal - 5
7//
8// tmp.zig:2:21: error: expected expression, found 'invalid bytes'
9// tmp.zig:2:26: note: invalid byte: '_'
test/compile_errors/stage1/obj/invalid_underscore_placement_in_float_literal-6.zig created+9
...@@ -0,0 +1,9 @@
1fn main() void {
2 var bad: f128 = 1.0e-_1;
3 _ = bad;
4}
5
6// invalid underscore placement in float literal - 6
7//
8// tmp.zig:2:21: error: expected expression, found 'invalid bytes'
9// tmp.zig:2:26: note: invalid byte: '_'
test/compile_errors/stage1/obj/invalid_underscore_placement_in_float_literal-7.zig created+9
...@@ -0,0 +1,9 @@
1fn main() void {
2 var bad: f128 = 1.0e-1_;
3 _ = bad;
4}
5
6// invalid underscore placement in float literal - 7
7//
8// tmp.zig:2:21: error: expected expression, found 'invalid bytes'
9// tmp.zig:2:28: note: invalid byte: ';'
test/compile_errors/stage1/obj/invalid_underscore_placement_in_float_literal-9.zig created+9
...@@ -0,0 +1,9 @@
1fn main() void {
2 var bad: f128 = 1__0.0e-1;
3 _ = bad;
4}
5
6// invalid underscore placement in float literal - 9
7//
8// tmp.zig:2:21: error: expected expression, found 'invalid bytes'
9// tmp.zig:2:23: note: invalid byte: '_'
test/compile_errors/stage1/obj/invalid_underscore_placement_in_int_literal-1.zig created+9
...@@ -0,0 +1,9 @@
1fn main() void {
2 var bad: u128 = 0010_;
3 _ = bad;
4}
5
6// invalid underscore placement in int literal - 1
7//
8// tmp.zig:2:21: error: expected expression, found 'invalid bytes'
9// tmp.zig:2:26: note: invalid byte: ';'
test/compile_errors/stage1/obj/invalid_underscore_placement_in_int_literal-2.zig created+9
...@@ -0,0 +1,9 @@
1fn main() void {
2 var bad: u128 = 0b0010_;
3 _ = bad;
4}
5
6// invalid underscore placement in int literal - 2
7//
8// tmp.zig:2:21: error: expected expression, found 'invalid bytes'
9// tmp.zig:2:28: note: invalid byte: ';'
test/compile_errors/stage1/obj/invalid_underscore_placement_in_int_literal-3.zig created+9
...@@ -0,0 +1,9 @@
1fn main() void {
2 var bad: u128 = 0o0010_;
3 _ = bad;
4}
5
6// invalid underscore placement in int literal - 3
7//
8// tmp.zig:2:21: error: expected expression, found 'invalid bytes'
9// tmp.zig:2:28: note: invalid byte: ';'
test/compile_errors/stage1/obj/invalid_underscore_placement_in_int_literal-4.zig created+9
...@@ -0,0 +1,9 @@
1fn main() void {
2 var bad: u128 = 0x0010_;
3 _ = bad;
4}
5
6// invalid underscore placement in int literal - 4
7//
8// tmp.zig:2:21: error: expected expression, found 'invalid bytes'
9// tmp.zig:2:28: note: invalid byte: ';'
test/compile_errors/stage1/obj/invalid_union_field_access_in_comptime.zig created+13
...@@ -0,0 +1,13 @@
1const Foo = union {
2 Bar: u8,
3 Baz: void,
4};
5comptime {
6 var foo = Foo {.Baz = {}};
7 const bar_val = foo.Bar;
8 _ = bar_val;
9}
10
11// invalid union field access in comptime
12//
13// tmp.zig:7:24: error: accessing union field 'Bar' while field 'Baz' is set
test/compile_errors/stage1/obj/issue_2032_compile_diagnostic_string_for_top_level_decl_type.zig created+8
...@@ -0,0 +1,8 @@
1export fn entry() void {
2 var foo: u32 = @This(){};
3 _ = foo;
4}
5
6// compile diagnostic string for top level decl type (issue 2032)
7//
8// tmp.zig:2:27: error: type 'u32' does not support array initialization
test/compile_errors/stage1/obj/issue_2687_coerce_from_undefined_array_pointer_to_slice.zig created+25
...@@ -0,0 +1,25 @@
1export fn foo1() void {
2 const a: *[1]u8 = undefined;
3 var b: []u8 = a;
4 _ = b;
5}
6export fn foo2() void {
7 comptime {
8 var a: *[1]u8 = undefined;
9 var b: []u8 = a;
10 _ = b;
11 }
12}
13export fn foo3() void {
14 comptime {
15 const a: *[1]u8 = undefined;
16 var b: []u8 = a;
17 _ = b;
18 }
19}
20
21// issue #2687: coerce from undefined array pointer to slice
22//
23// tmp.zig:3:19: error: use of undefined value here causes undefined behavior
24// tmp.zig:9:23: error: use of undefined value here causes undefined behavior
25// tmp.zig:16:23: error: use of undefined value here causes undefined behavior
test/compile_errors/stage1/obj/issue_3818_bitcast_from_parray-slice_to_u16.zig created+15
...@@ -0,0 +1,15 @@
1export fn foo1() void {
2 var bytes = [_]u8{1, 2};
3 const word: u16 = @bitCast(u16, bytes[0..]);
4 _ = word;
5}
6export fn foo2() void {
7 var bytes: []const u8 = &[_]u8{1, 2};
8 const word: u16 = @bitCast(u16, bytes);
9 _ = word;
10}
11
12// issue #3818: bitcast from parray/slice to u16
13//
14// tmp.zig:3:42: error: unable to @bitCast from pointer type '*[2]u8'
15// tmp.zig:8:32: error: destination type 'u16' has size 2 but source type '[]const u8' has size 16
test/compile_errors/stage1/obj/issue_4207_coerce_from_non-terminated-slice_to_terminated-pointer.zig created+9
...@@ -0,0 +1,9 @@
1export fn foo() [*:0]const u8 {
2 var buffer: [64]u8 = undefined;
3 return buffer[0..];
4}
5
6// issue #4207: coerce from non-terminated-slice to terminated-pointer
7//
8// :3:18: error: expected type '[*:0]const u8', found '*[64]u8'
9// :3:18: note: destination pointer requires a terminating '0' sentinel
test/compile_errors/stage1/obj/issue_5221_invalid_struct_init_type_referenced_by_typeInfo_and_passed_into_function.zig created+14
...@@ -0,0 +1,14 @@
1fn ignore(comptime param: anytype) void {_ = param;}
2
3export fn foo() void {
4 const MyStruct = struct {
5 wrong_type: []u8 = "foo",
6 };
7
8 comptime ignore(@typeInfo(MyStruct).Struct.fields[0]);
9}
10
11// issue #5221: invalid struct init type referenced by @typeInfo and passed into function
12//
13// :5:28: error: cannot cast pointer to array literal to slice type '[]u8'
14// :5:28: note: cast discards const qualifier
test/compile_errors/stage1/obj/issue_5618_coercion_of_optional_anyopaque_to_anyopaque_must_fail.zig created+9
...@@ -0,0 +1,9 @@
1export fn foo() void {
2 var u: ?*anyopaque = null;
3 var v: *anyopaque = undefined;
4 v = u;
5}
6
7// Issue #5618: coercion of ?*anyopaque to *anyopaque must fail.
8//
9// tmp.zig:4:9: error: cannot convert optional to payload type. consider using `.?`, `orelse`, or `if`. expected type '*anyopaque', found '?*anyopaque'
test/compile_errors/stage1/obj/issue_7810-comptime_slice-len_increment_beyond_bounds.zig created+12
...@@ -0,0 +1,12 @@
1export fn foo_slice_len_increment_beyond_bounds() void {
2 comptime {
3 var buf_storage: [8]u8 = undefined;
4 var buf: []const u8 = buf_storage[0..];
5 buf.len += 1;
6 buf[8] = 42;
7 }
8}
9
10// comptime slice-len increment beyond bounds
11//
12// :6:12: error: out of bounds slice
test/compile_errors/stage1/obj/issue_9346_return_outside_of_function_scope.zig created+5
...@@ -0,0 +1,5 @@
1pub const empty = return 1;
2
3// issue #9346: return outside of function scope
4//
5// tmp.zig:1:19: error: 'return' outside function scope
test/compile_errors/stage1/obj/labeled_break_not_found.zig created+11
...@@ -0,0 +1,11 @@
1export fn entry() void {
2 blah: while (true) {
3 while (true) {
4 break :outer;
5 }
6 }
7}
8
9// labeled break not found
10//
11// tmp.zig:4:20: error: label not found: 'outer'
test/compile_errors/stage1/obj/labeled_continue_not_found.zig created+12
...@@ -0,0 +1,12 @@
1export fn entry() void {
2 var i: usize = 0;
3 blah: while (i < 10) : (i += 1) {
4 while (true) {
5 continue :outer;
6 }
7 }
8}
9
10// labeled continue not found
11//
12// tmp.zig:5:23: error: label not found: 'outer'
test/compile_errors/stage1/obj/lazy_pointer_with_undefined_element_type.zig created+10
...@@ -0,0 +1,10 @@
1export fn foo() void {
2 comptime var T: type = undefined;
3 const S = struct { x: *T };
4 const I = @typeInfo(S);
5 _ = I;
6}
7
8// lazy pointer with undefined element type
9//
10// :3:28: error: use of undefined value here causes undefined behavior
test/compile_errors/stage1/obj/load_too_many_bytes_from_comptime_reinterpreted_pointer.zig created+11
...@@ -0,0 +1,11 @@
1export fn entry() void {
2 const float: f32 = 5.99999999999994648725e-01;
3 const float_ptr = &float;
4 const int_ptr = @ptrCast(*const i64, float_ptr);
5 const int_val = int_ptr.*;
6 _ = int_val;
7}
8
9// load too many bytes from comptime reinterpreted pointer
10//
11// tmp.zig:5:28: error: attempt to read 8 bytes from pointer to f32 which is 4 bytes
test/compile_errors/stage1/obj/load_vector_pointer_with_unknown_runtime_index.zig created+15
...@@ -0,0 +1,15 @@
1export fn entry() void {
2 var v: @import("std").meta.Vector(4, i32) = [_]i32{ 1, 5, 3, undefined };
3
4 var i: u32 = 0;
5 var x = loadv(&v[i]);
6 _ = x;
7}
8
9fn loadv(ptr: anytype) i32 {
10 return ptr.*;
11}
12
13// load vector pointer with unknown runtime index
14//
15// tmp.zig:10:12: error: unable to determine vector element index of type '*align(16:0:4:?) i32
test/compile_errors/stage1/obj/local_shadows_global_that_occurs_later.zig created+10
...@@ -0,0 +1,10 @@
1pub fn main() void {
2 var foo = true;
3 _ = foo;
4}
5fn foo() void {}
6
7// local shadows global that occurs later
8//
9// tmp.zig:2:9: error: local shadows declaration of 'foo'
10// tmp.zig:5:1: note: declared here
test/compile_errors/stage1/obj/local_variable_redeclaration.zig created+9
...@@ -0,0 +1,9 @@
1export fn f() void {
2 const a : i32 = 0;
3 var a = 0;
4}
5
6// local variable redeclaration
7//
8// tmp.zig:3:9: error: redeclaration of local constant 'a'
9// tmp.zig:2:11: note: previous declaration here
test/compile_errors/stage1/obj/local_variable_redeclares_parameter.zig created+9
...@@ -0,0 +1,9 @@
1fn f(a : i32) void {
2 const a = 0;
3}
4export fn entry() void { f(1); }
5
6// local variable redeclares parameter
7//
8// tmp.zig:2:11: error: redeclaration of function parameter 'a'
9// tmp.zig:1:6: note: previous declaration here
test/compile_errors/stage1/obj/local_variable_shadowing_global.zig created+12
...@@ -0,0 +1,12 @@
1const Foo = struct {};
2const Bar = struct {};
3
4export fn entry() void {
5 var Bar : i32 = undefined;
6 _ = Bar;
7}
8
9// local variable shadowing global
10//
11// tmp.zig:5:9: error: local shadows declaration of 'Bar'
12// tmp.zig:2:1: note: declared here
test/compile_errors/stage1/obj/locally_shadowing_a_primitive_type.zig created+10
...@@ -0,0 +1,10 @@
1export fn foo() void {
2 const u8 = u16;
3 const a: u8 = 300;
4 _ = a;
5}
6
7// locally shadowing a primitive type
8//
9// tmp.zig:2:11: error: name shadows primitive 'u8'
10// tmp.zig:2:11: note: consider using @"u8" to disambiguate
test/compile_errors/stage1/obj/main_function_with_bogus_args_type.zig created+5
...@@ -0,0 +1,5 @@
1pub fn main(args: [][]bogus) !void {_ = args;}
2
3// main function with bogus args type
4//
5// tmp.zig:1:23: error: use of undeclared identifier 'bogus'
test/compile_errors/stage1/obj/method_call_with_first_arg_type_primitive.zig created+19
...@@ -0,0 +1,19 @@
1const Foo = struct {
2 x: i32,
3
4 fn init(x: i32) Foo {
5 return Foo {
6 .x = x,
7 };
8 }
9};
10
11export fn f() void {
12 const derp = Foo.init(3);
13
14 derp.init();
15}
16
17// method call with first arg type primitive
18//
19// tmp.zig:14:5: error: expected type 'i32', found 'Foo'
test/compile_errors/stage1/obj/method_call_with_first_arg_type_wrong_container.zig created+28
...@@ -0,0 +1,28 @@
1pub const List = struct {
2 len: usize,
3 allocator: *Allocator,
4
5 pub fn init(allocator: *Allocator) List {
6 return List {
7 .len = 0,
8 .allocator = allocator,
9 };
10 }
11};
12
13pub var global_allocator = Allocator {
14 .field = 1234,
15};
16
17pub const Allocator = struct {
18 field: i32,
19};
20
21export fn foo() void {
22 var x = List.init(&global_allocator);
23 x.init();
24}
25
26// method call with first arg type wrong container
27//
28// tmp.zig:23:5: error: expected type '*Allocator', found '*List'
test/compile_errors/stage1/obj/missing_boolean_switch_value.zig created+17
...@@ -0,0 +1,17 @@
1comptime {
2 const x = switch (true) {
3 true => false,
4 };
5 _ = x;
6}
7comptime {
8 const x = switch (true) {
9 false => true,
10 };
11 _ = x;
12}
13
14// missing boolean switch value
15//
16// tmp.zig:2:15: error: switch must handle all possibilities
17// tmp.zig:8:15: error: switch must handle all possibilities
test/compile_errors/stage1/obj/missing_const_in_slice_with_nested_array_type.zig created+16
...@@ -0,0 +1,16 @@
1const Geo3DTex2D = struct { vertices: [][2]f32 };
2pub fn getGeo3DTex2D() Geo3DTex2D {
3 return Geo3DTex2D{
4 .vertices = [_][2]f32{
5 [_]f32{ -0.5, -0.5},
6 },
7 };
8}
9export fn entry() void {
10 var geo_data = getGeo3DTex2D();
11 _ = geo_data;
12}
13
14// missing const in slice with nested array type
15//
16// tmp.zig:4:30: error: array literal requires address-of operator (&) to coerce to slice type '[][2]f32'
test/compile_errors/stage1/obj/missing_else_clause.zig created+14
...@@ -0,0 +1,14 @@
1fn f(b: bool) void {
2 const x : i32 = if (b) h: { break :h 1; };
3 _ = x;
4}
5fn g(b: bool) void {
6 const y = if (b) h: { break :h @as(i32, 1); };
7 _ = y;
8}
9export fn entry() void { f(true); g(true); }
10
11// missing else clause
12//
13// tmp.zig:2:21: error: expected type 'i32', found 'void'
14// tmp.zig:6:15: error: incompatible types: 'i32' and 'void'
test/compile_errors/stage1/obj/missing_field_in_struct_value_expression.zig created+18
...@@ -0,0 +1,18 @@
1const A = struct {
2 x : i32,
3 y : i32,
4 z : i32,
5};
6export fn f() void {
7 // we want the error on the '{' not the 'A' because
8 // the A could be a complicated expression
9 const a = A {
10 .z = 4,
11 .y = 2,
12 };
13 _ = a;
14}
15
16// missing field in struct value expression
17//
18// tmp.zig:9:17: error: missing field: 'x'
test/compile_errors/stage1/obj/missing_function_call_param.zig created+29
...@@ -0,0 +1,29 @@
1const Foo = struct {
2 a: i32,
3 b: i32,
4
5 fn member_a(foo: *const Foo) i32 {
6 return foo.a;
7 }
8 fn member_b(foo: *const Foo) i32 {
9 return foo.b;
10 }
11};
12
13const member_fn_type = @TypeOf(Foo.member_a);
14const members = [_]member_fn_type {
15 Foo.member_a,
16 Foo.member_b,
17};
18
19fn f(foo: *const Foo, index: usize) void {
20 const result = members[index]();
21 _ = foo;
22 _ = result;
23}
24
25export fn entry() usize { return @sizeOf(@TypeOf(f)); }
26
27// missing function call param
28//
29// tmp.zig:20:34: error: expected 1 argument(s), found 0
test/compile_errors/stage1/obj/missing_function_name.zig created+6
...@@ -0,0 +1,6 @@
1fn () void {}
2export fn entry() usize { return @sizeOf(@TypeOf(f)); }
3
4// missing function name
5//
6// tmp.zig:1:1: error: missing function name
test/compile_errors/stage1/obj/missing_param_name.zig created+6
...@@ -0,0 +1,6 @@
1fn f(i32) void {}
2export fn entry() usize { return @sizeOf(@TypeOf(f)); }
3
4// missing param name
5//
6// tmp.zig:1:6: error: missing parameter name
test/compile_errors/stage1/obj/missing_parameter_name_of_generic_function.zig created+9
...@@ -0,0 +1,9 @@
1fn dump(anytype) void {}
2export fn entry() void {
3 var a: u8 = 9;
4 dump(a);
5}
6
7// missing parameter name of generic function
8//
9// tmp.zig:1:9: error: missing parameter name
test/compile_errors/stage1/obj/missing_result_type_for_phi_node.zig created+10
...@@ -0,0 +1,10 @@
1fn foo() !void {
2 return anyerror.Foo;
3}
4export fn entry() void {
5 foo() catch 0;
6}
7
8// missing result type for phi node
9//
10// tmp.zig:5:17: error: integer value 0 cannot be coerced to type 'void'
test/compile_errors/stage1/obj/misspelled_type_with_pointer_only_reference.zig created+35
...@@ -0,0 +1,35 @@
1const JasonHM = u8;
2const JasonList = *JsonNode;
3
4const JsonOA = union(enum) {
5 JSONArray: JsonList,
6 JSONObject: JasonHM,
7};
8
9const JsonType = union(enum) {
10 JSONNull: void,
11 JSONInteger: isize,
12 JSONDouble: f64,
13 JSONBool: bool,
14 JSONString: []u8,
15 JSONArray: void,
16 JSONObject: void,
17};
18
19pub const JsonNode = struct {
20 kind: JsonType,
21 jobject: ?JsonOA,
22};
23
24fn foo() void {
25 var jll: JasonList = undefined;
26 jll.init(1234);
27 var jd = JsonNode {.kind = JsonType.JSONArray , .jobject = JsonOA.JSONArray {jll} };
28 _ = jd;
29}
30
31export fn entry() usize { return @sizeOf(@TypeOf(foo)); }
32
33// misspelled type with pointer only reference
34//
35// tmp.zig:5:16: error: use of undeclared identifier 'JsonList'
test/compile_errors/stage1/obj/mod_assign_on_undefined_value.zig created+8
...@@ -0,0 +1,8 @@
1comptime {
2 var a: i64 = undefined;
3 a %= a;
4}
5
6// mod assign on undefined value
7//
8// tmp.zig:3:5: error: use of undefined value here causes undefined behavior
test/compile_errors/stage1/obj/mod_on_undefined_value.zig created+8
...@@ -0,0 +1,8 @@
1comptime {
2 var a: i64 = undefined;
3 _ = a % a;
4}
5
6// mod on undefined value
7//
8// tmp.zig:3:9: error: use of undefined value here causes undefined behavior
test/compile_errors/stage1/obj/mul_overflow_in_function_evaluation.zig created+10
...@@ -0,0 +1,10 @@
1const y = mul(300, 6000);
2fn mul(a: u16, b: u16) u16 {
3 return a * b;
4}
5
6export fn entry() usize { return @sizeOf(@TypeOf(y)); }
7
8// mul overflow in function evaluation
9//
10// tmp.zig:3:14: error: operation caused overflow
test/compile_errors/stage1/obj/mult_assign_on_undefined_value.zig created+8
...@@ -0,0 +1,8 @@
1comptime {
2 var a: i64 = undefined;
3 a *= a;
4}
5
6// mult assign on undefined value
7//
8// tmp.zig:3:5: error: use of undefined value here causes undefined behavior
test/compile_errors/stage1/obj/mult_on_undefined_value.zig created+8
...@@ -0,0 +1,8 @@
1comptime {
2 var a: i64 = undefined;
3 _ = a * a;
4}
5
6// mult on undefined value
7//
8// tmp.zig:3:9: error: use of undefined value here causes undefined behavior
test/compile_errors/stage1/obj/mult_wrap_assign_on_undefined_value.zig created+8
...@@ -0,0 +1,8 @@
1comptime {
2 var a: i64 = undefined;
3 a *%= a;
4}
5
6// mult wrap assign on undefined value
7//
8// tmp.zig:3:5: error: use of undefined value here causes undefined behavior
test/compile_errors/stage1/obj/mult_wrap_on_undefined_value.zig created+8
...@@ -0,0 +1,8 @@
1comptime {
2 var a: i64 = undefined;
3 _ = a *% a;
4}
5
6// mult wrap on undefined value
7//
8// tmp.zig:3:9: error: use of undefined value here causes undefined behavior
test/compile_errors/stage1/obj/multiple_function_definitions.zig created+8
...@@ -0,0 +1,8 @@
1fn a() void {}
2fn a() void {}
3export fn entry() void { a(); }
4
5// multiple function definitions
6//
7// tmp.zig:2:1: error: redeclaration of 'a'
8// tmp.zig:1:1: note: other declaration here
test/compile_errors/stage1/obj/negate_on_undefined_value.zig created+8
...@@ -0,0 +1,8 @@
1comptime {
2 var a: i64 = undefined;
3 _ = -a;
4}
5
6// negate on undefined value
7//
8// tmp.zig:3:10: error: use of undefined value here causes undefined behavior
test/compile_errors/stage1/obj/negate_wrap_on_undefined_value.zig created+8
...@@ -0,0 +1,8 @@
1comptime {
2 var a: i64 = undefined;
3 _ = -%a;
4}
5
6// negate wrap on undefined value
7//
8// tmp.zig:3:11: error: use of undefined value here causes undefined behavior
test/compile_errors/stage1/obj/negation_overflow_in_function_evaluation.zig created+10
...@@ -0,0 +1,10 @@
1const y = neg(-128);
2fn neg(x: i8) i8 {
3 return -x;
4}
5
6export fn entry() usize { return @sizeOf(@TypeOf(y)); }
7
8// negation overflow in function evaluation
9//
10// tmp.zig:3:12: error: negation caused overflow
test/compile_errors/stage1/obj/nested_error_set_mismatch.zig created+18
...@@ -0,0 +1,18 @@
1const NextError = error{NextError};
2const OtherError = error{OutOfMemory};
3
4export fn entry() void {
5 const a: ?NextError!i32 = foo();
6 _ = a;
7}
8
9fn foo() ?OtherError!i32 {
10 return null;
11}
12
13// nested error set mismatch
14//
15// tmp.zig:5:34: error: expected type '?NextError!i32', found '?OtherError!i32'
16// tmp.zig:5:34: note: optional type child 'OtherError!i32' cannot cast into optional type child 'NextError!i32'
17// tmp.zig:5:34: note: error set 'OtherError' cannot cast into error set 'NextError'
18// tmp.zig:2:26: note: 'error.OutOfMemory' not a member of destination error set
test/compile_errors/stage1/obj/no_else_prong_on_switch_on_global_error_set.zig created+12
...@@ -0,0 +1,12 @@
1export fn entry() void {
2 foo(error.A);
3}
4fn foo(a: anyerror) void {
5 switch (a) {
6 error.A => {},
7 }
8}
9
10// no else prong on switch on global error set
11//
12// tmp.zig:5:5: error: else prong required when switching on type 'anyerror'
test/compile_errors/stage1/obj/noalias_on_non_pointer_param.zig created+6
...@@ -0,0 +1,6 @@
1fn f(noalias x: i32) void { _ = x; }
2export fn entry() void { f(1234); }
3
4// noalias on non pointer param
5//
6// tmp.zig:1:6: error: noalias on non-pointer parameter
test/compile_errors/stage1/obj/non-async_function_pointer_eventually_is_inferred_to_become_async.zig created+13
...@@ -0,0 +1,13 @@
1export fn a() void {
2 var non_async_fn: fn () void = undefined;
3 non_async_fn = func;
4}
5fn func() void {
6 suspend {}
7}
8
9// non-async function pointer eventually is inferred to become async
10//
11// tmp.zig:5:1: error: 'func' cannot be async
12// tmp.zig:3:20: note: required to be non-async here
13// tmp.zig:6:5: note: suspends here
test/compile_errors/stage1/obj/non-const_expression_function_call_with_struct_return_value_outside_function.zig created+15
...@@ -0,0 +1,15 @@
1const Foo = struct {
2 x: i32,
3};
4const a = get_it();
5fn get_it() Foo {
6 global_side_effect = true;
7 return Foo {.x = 13};
8}
9var global_side_effect = false;
10
11export fn entry() usize { return @sizeOf(@TypeOf(a)); }
12
13// non-const expression function call with struct return value outside function
14//
15// tmp.zig:6:26: error: unable to evaluate constant expression
test/compile_errors/stage1/obj/non-const_expression_in_struct_literal_outside_function.zig created+11
...@@ -0,0 +1,11 @@
1const Foo = struct {
2 x: i32,
3};
4const a = Foo {.x = get_it()};
5extern fn get_it() i32;
6
7export fn entry() usize { return @sizeOf(@TypeOf(a)); }
8
9// non-const expression in struct literal outside function
10//
11// tmp.zig:4:21: error: unable to evaluate constant expression
test/compile_errors/stage1/obj/non-const_switch_number_literal.zig created+15
...@@ -0,0 +1,15 @@
1export fn foo() void {
2 const x = switch (bar()) {
3 1, 2 => 1,
4 3, 4 => 2,
5 else => 3,
6 };
7 _ = x;
8}
9fn bar() i32 {
10 return 2;
11}
12
13// non-const switch number literal
14//
15// tmp.zig:5:17: error: cannot store runtime value in type 'comptime_int'
test/compile_errors/stage1/obj/non-const_variables_of_things_that_require_const_variables.zig created+49
...@@ -0,0 +1,49 @@
1export fn entry1() void {
2 var m2 = &2;
3 _ = m2;
4}
5export fn entry2() void {
6 var a = undefined;
7 _ = a;
8}
9export fn entry3() void {
10 var b = 1;
11 _ = b;
12}
13export fn entry4() void {
14 var c = 1.0;
15 _ = c;
16}
17export fn entry5() void {
18 var d = null;
19 _ = d;
20}
21export fn entry6(opaque_: *Opaque) void {
22 var e = opaque_.*;
23 _ = e;
24}
25export fn entry7() void {
26 var f = i32;
27 _ = f;
28}
29export fn entry8() void {
30 var h = (Foo {}).bar;
31 _ = h;
32}
33const Opaque = opaque {};
34const Foo = struct {
35 fn bar(self: *const Foo) void {_ = self;}
36};
37
38// non-const variables of things that require const variables
39//
40// tmp.zig:2:4: error: variable of type '*const comptime_int' must be const or comptime
41// tmp.zig:6:4: error: variable of type '@Type(.Undefined)' must be const or comptime
42// tmp.zig:10:4: error: variable of type 'comptime_int' must be const or comptime
43// tmp.zig:10:4: note: to modify this variable at runtime, it must be given an explicit fixed-size number type
44// tmp.zig:14:4: error: variable of type 'comptime_float' must be const or comptime
45// tmp.zig:14:4: note: to modify this variable at runtime, it must be given an explicit fixed-size number type
46// tmp.zig:18:4: error: variable of type '@Type(.Null)' must be const or comptime
47// tmp.zig:22:4: error: variable of type 'Opaque' not allowed
48// tmp.zig:26:4: error: variable of type 'type' must be const or comptime
49// tmp.zig:30:4: error: variable of type '(bound fn(*const Foo) void)' must be const or comptime
test/compile_errors/stage1/obj/non-enum_tag_type_passed_to_union.zig created+11
...@@ -0,0 +1,11 @@
1const Foo = union(u32) {
2 A: i32,
3};
4export fn entry() void {
5 const x = @typeInfo(Foo).Union.tag_type.?;
6 _ = x;
7}
8
9// non-enum tag type passed to union
10//
11// tmp.zig:1:19: error: expected enum tag type, found 'u32'
test/compile_errors/stage1/obj/non-extern_function_with_var_args.zig created+8
...@@ -0,0 +1,8 @@
1fn foo(args: ...) void {}
2export fn entry() void {
3 foo();
4}
5
6// non-extern function with var args
7//
8// tmp.zig:1:14: error: expected type expression, found '...'
test/compile_errors/stage1/obj/non-inline_for_loop_on_a_type_that_requires_comptime.zig created+12
...@@ -0,0 +1,12 @@
1const Foo = struct {
2 name: []const u8,
3 T: type,
4};
5export fn entry() void {
6 const xx: [2]Foo = undefined;
7 for (xx) |f| { _ = f;}
8}
9
10// non-inline for loop on a type that requires comptime
11//
12// tmp.zig:7:5: error: values of type 'Foo' must be comptime known, but index value is runtime known
test/compile_errors/stage1/obj/non-integer_tag_type_to_automatic_union_enum.zig created+11
...@@ -0,0 +1,11 @@
1const Foo = union(enum(f32)) {
2 A: i32,
3};
4export fn entry() void {
5 const x = @typeInfo(Foo).Union.tag_type.?;
6 _ = x;
7}
8
9// non-integer tag type to automatic union enum
10//
11// tmp.zig:1:24: error: expected integer tag type, found 'f32'
test/compile_errors/stage1/obj/non-pure_function_returns_type.zig created+22
...@@ -0,0 +1,22 @@
1var a: u32 = 0;
2pub fn List(comptime T: type) type {
3 a += 1;
4 return SmallList(T, 8);
5}
6
7pub fn SmallList(comptime T: type, comptime STATIC_SIZE: usize) type {
8 return struct {
9 items: []T,
10 length: usize,
11 prealloc_items: [STATIC_SIZE]T,
12 };
13}
14
15export fn function_with_return_type_type() void {
16 var list: List(i32) = undefined;
17 list.length = 10;
18}
19
20// non-pure function returns type
21//
22// tmp.zig:3:7: error: unable to evaluate constant expression
test/compile_errors/stage1/obj/non_async_function_pointer_passed_to_asyncCall.zig created+10
...@@ -0,0 +1,10 @@
1export fn entry() void {
2 var ptr = afunc;
3 var bytes: [100]u8 align(16) = undefined;
4 _ = @asyncCall(&bytes, {}, ptr, .{});
5}
6fn afunc() void { }
7
8// non async function pointer passed to @asyncCall
9//
10// tmp.zig:4:32: error: expected async function, found 'fn() void'
test/compile_errors/stage1/obj/non_compile_time_array_concatenation.zig created+9
...@@ -0,0 +1,9 @@
1fn f() []u8 {
2 return s ++ "foo";
3}
4var s: [10]u8 = undefined;
5export fn entry() usize { return @sizeOf(@TypeOf(f)); }
6
7// non compile time array concatenation
8//
9// tmp.zig:2:12: error: unable to evaluate constant expression
test/compile_errors/stage1/obj/non_constant_expression_in_array_size.zig created+12
...@@ -0,0 +1,12 @@
1const Foo = struct {
2 y: [get()]u8,
3};
4var global_var: usize = 1;
5fn get() usize { return global_var; }
6
7export fn entry() usize { return @sizeOf(@TypeOf(Foo)); }
8
9// non constant expression in array size
10//
11// tmp.zig:5:25: error: cannot store runtime value in compile time variable
12// tmp.zig:2:12: note: called from here
test/compile_errors/stage1/obj/non_error_sets_used_in_merge_error_sets_operator.zig created+15
...@@ -0,0 +1,15 @@
1export fn foo() void {
2 const Errors = u8 || u16;
3 _ = Errors;
4}
5export fn bar() void {
6 const Errors = error{} || u16;
7 _ = Errors;
8}
9
10// non error sets used in merge error sets operator
11//
12// tmp.zig:2:20: error: expected error set type, found type 'u8'
13// tmp.zig:2:23: note: `||` merges error sets; `or` performs boolean OR
14// tmp.zig:6:31: error: expected error set type, found type 'u16'
15// tmp.zig:6:28: note: `||` merges error sets; `or` performs boolean OR
test/compile_errors/stage1/obj/non_float_passed_to_floatToInt.zig created+8
...@@ -0,0 +1,8 @@
1export fn entry() void {
2 const x = @floatToInt(i32, @as(i32, 54));
3 _ = x;
4}
5
6// non float passed to @floatToInt
7//
8// tmp.zig:2:32: error: expected float type, found 'i32'
test/compile_errors/stage1/obj/non_int_passed_to_intToFloat.zig created+8
...@@ -0,0 +1,8 @@
1export fn entry() void {
2 const x = @intToFloat(f32, 1.1);
3 _ = x;
4}
5
6// non int passed to @intToFloat
7//
8// tmp.zig:2:32: error: expected int type, found 'comptime_float'
test/compile_errors/stage1/obj/non_pointer_given_to_ptrToInt.zig created+7
...@@ -0,0 +1,7 @@
1export fn entry(x: i32) usize {
2 return @ptrToInt(x);
3}
4
5// non pointer given to @ptrToInt
6//
7// tmp.zig:2:22: error: expected pointer, found 'i32'
test/compile_errors/stage1/obj/normal_string_with_newline.zig created+7
...@@ -0,0 +1,7 @@
1const foo = "a
2b";
3
4// normal string with newline
5//
6// tmp.zig:1:13: error: expected expression, found 'invalid bytes'
7// tmp.zig:1:15: note: invalid byte: '\n'
test/compile_errors/stage1/obj/offsetOf-bad_field_name.zig created+10
...@@ -0,0 +1,10 @@
1const Foo = struct {
2 derp: i32,
3};
4export fn foo() usize {
5 return @offsetOf(Foo, "a",);
6}
7
8// @offsetOf - bad field name
9//
10// tmp.zig:5:27: error: struct 'Foo' has no field 'a'
test/compile_errors/stage1/obj/offsetOf-non_struct.zig created+8
...@@ -0,0 +1,8 @@
1const Foo = i32;
2export fn foo() usize {
3 return @offsetOf(Foo, "a",);
4}
5
6// @offsetOf - non struct
7//
8// tmp.zig:3:22: error: expected struct type, found 'i32'
test/compile_errors/stage1/obj/only_equality_binary_operator_allowed_for_error_sets.zig created+8
...@@ -0,0 +1,8 @@
1comptime {
2 const z = error.A > error.B;
3 _ = z;
4}
5
6// only equality binary operator allowed for error sets
7//
8// tmp.zig:2:23: error: operator not allowed for errors
test/compile_errors/stage1/obj/opaque_type_with_field.zig created+9
...@@ -0,0 +1,9 @@
1const Opaque = opaque { foo: i32 };
2export fn entry() void {
3 const foo: ?*Opaque = null;
4 _ = foo;
5}
6
7// opaque type with field
8//
9// tmp.zig:1:25: error: opaque types cannot have fields
test/compile_errors/stage1/obj/optional_pointer_to_void_in_extern_struct.zig created+12
...@@ -0,0 +1,12 @@
1const Foo = extern struct {
2 x: ?*const void,
3};
4const Bar = extern struct {
5 foo: Foo,
6 y: i32,
7};
8export fn entry(bar: *Bar) void {_ = bar;}
9
10// optional pointer to void in extern struct
11//
12// tmp.zig:2:5: error: extern structs cannot contain fields of type '?*const void'
test/compile_errors/stage1/obj/or_on_undefined_value.zig created+8
...@@ -0,0 +1,8 @@
1comptime {
2 var a: bool = undefined;
3 _ = a or a;
4}
5
6// or on undefined value
7//
8// tmp.zig:3:9: error: use of undefined value here causes undefined behavior
test/compile_errors/stage1/obj/orelse_on_undefined_value.zig created+8
...@@ -0,0 +1,8 @@
1comptime {
2 var a: ?bool = undefined;
3 _ = a orelse false;
4}
5
6// orelse on undefined value
7//
8// tmp.zig:3:11: error: use of undefined value here causes undefined behavior
test/compile_errors/stage1/obj/out_of_range_comptime_int_passed_to_floatToInt.zig created+8
...@@ -0,0 +1,8 @@
1export fn entry() void {
2 const x = @floatToInt(i8, 200);
3 _ = x;
4}
5
6// out of range comptime_int passed to @floatToInt
7//
8// tmp.zig:2:31: error: integer value 200 cannot be coerced to type 'i8'
test/compile_errors/stage1/obj/overflow_in_enum_value_allocation.zig created+12
...@@ -0,0 +1,12 @@
1const Moo = enum(u8) {
2 Last = 255,
3 Over,
4};
5pub fn main() void {
6 var y = Moo.Last;
7 _ = y;
8}
9
10// overflow in enum value allocation
11//
12// tmp.zig:3:5: error: enumeration value 256 too large for type 'u8'
test/compile_errors/stage1/obj/packed_union_given_enum_tag_type.zig created+18
...@@ -0,0 +1,18 @@
1const Letter = enum {
2 A,
3 B,
4 C,
5};
6const Payload = packed union(Letter) {
7 A: i32,
8 B: f64,
9 C: bool,
10};
11export fn entry() void {
12 var a = Payload { .A = 1234 };
13 _ = a;
14}
15
16// packed union given enum tag type
17//
18// tmp.zig:6:30: error: packed union does not support enum tag type
test/compile_errors/stage1/obj/packed_union_with_automatic_layout_field.zig created+16
...@@ -0,0 +1,16 @@
1const Foo = struct {
2 a: u32,
3 b: f32,
4};
5const Payload = packed union {
6 A: Foo,
7 B: bool,
8};
9export fn entry() void {
10 var a = Payload { .B = true };
11 _ = a;
12}
13
14// packed union with automatic layout field
15//
16// tmp.zig:6:5: error: non-packed, non-extern struct 'Foo' not allowed in packed union; no guaranteed in-memory representation
test/compile_errors/stage1/obj/panic_called_at_compile_time.zig created+9
...@@ -0,0 +1,9 @@
1export fn entry() void {
2 comptime {
3 @panic("aoeu",);
4 }
5}
6
7// @panic called at compile time
8//
9// tmp.zig:3:9: error: encountered @panic at compile-time
test/compile_errors/stage1/obj/parameter_redeclaration.zig created+8
...@@ -0,0 +1,8 @@
1fn f(a : i32, a : i32) void {
2}
3export fn entry() void { f(1, 2); }
4
5// parameter redeclaration
6//
7// tmp.zig:1:15: error: redeclaration of function parameter 'a'
8// tmp.zig:1:6: note: previous declaration here
test/compile_errors/stage1/obj/parameter_shadowing_global.zig created+10
...@@ -0,0 +1,10 @@
1const Foo = struct {};
2fn f(Foo: i32) void {}
3export fn entry() void {
4 f(1234);
5}
6
7// parameter shadowing global
8//
9// tmp.zig:2:6: error: local shadows declaration of 'Foo'
10// tmp.zig:1:1: note: declared here
test/compile_errors/stage1/obj/pass_const_ptr_to_mutable_ptr_fn.zig created+15
...@@ -0,0 +1,15 @@
1fn foo() bool {
2 const a = @as([]const u8, "a",);
3 const b = &a;
4 return ptrEql(b, b);
5}
6fn ptrEql(a: *[]const u8, b: *[]const u8) bool {
7 _ = a; _ = b;
8 return true;
9}
10
11export fn entry() usize { return @sizeOf(@TypeOf(foo)); }
12
13// pass const ptr to mutable ptr fn
14//
15// tmp.zig:4:19: error: expected type '*[]const u8', found '*const []const u8'
test/compile_errors/stage1/obj/passing_a_not-aligned-enough_pointer_to_cmpxchg.zig created+10
...@@ -0,0 +1,10 @@
1const AtomicOrder = @import("std").builtin.AtomicOrder;
2export fn entry() bool {
3 var x: i32 align(1) = 1234;
4 while (!@cmpxchgWeak(i32, &x, 1234, 5678, AtomicOrder.SeqCst, AtomicOrder.SeqCst)) {}
5 return x == 5678;
6}
7
8// passing a not-aligned-enough pointer to cmpxchg
9//
10// tmp.zig:4:32: error: expected type '*i32', found '*align(1) i32'
test/compile_errors/stage1/obj/passing_an_under-aligned_function_pointer.zig created+11
...@@ -0,0 +1,11 @@
1export fn entry() void {
2 testImplicitlyDecreaseFnAlign(alignedSmall, 1234);
3}
4fn testImplicitlyDecreaseFnAlign(ptr: fn () align(8) i32, answer: i32) void {
5 if (ptr() != answer) unreachable;
6}
7fn alignedSmall() align(4) i32 { return 1234; }
8
9// passing an under-aligned function pointer
10//
11// tmp.zig:2:35: error: expected type 'fn() align(8) i32', found 'fn() align(4) i32'
test/compile_errors/stage1/obj/peer_cast_then_implicit_cast_const_pointer_to_mutable_C_pointer.zig created+9
...@@ -0,0 +1,9 @@
1export fn func() void {
2 var strValue: [*c]u8 = undefined;
3 strValue = strValue orelse "";
4}
5
6// peer cast then implicit cast const pointer to mutable C pointer
7//
8// tmp.zig:3:32: error: expected type '[*c]u8', found '*const [0:0]u8'
9// tmp.zig:3:32: note: cast discards const qualifier
test/compile_errors/stage1/obj/pointer_arithmetic_on_pointer-to-array.zig created+10
...@@ -0,0 +1,10 @@
1export fn foo() void {
2 var x: [10]u8 = undefined;
3 var y = &x;
4 var z = y + 1;
5 _ = z;
6}
7
8// pointer arithmetic on pointer-to-array
9//
10// tmp.zig:4:17: error: integer value 1 cannot be coerced to type '*[10]u8'
test/compile_errors/stage1/obj/pointer_attributes_checked_when_coercing_pointer_to_anon_literal.zig created+22
...@@ -0,0 +1,22 @@
1comptime {
2 const c: [][]const u8 = &.{"hello", "world" };
3 _ = c;
4}
5comptime {
6 const c: *[2][]const u8 = &.{"hello", "world" };
7 _ = c;
8}
9const S = struct {a: u8 = 1, b: u32 = 2};
10comptime {
11 const c: *S = &.{};
12 _ = c;
13}
14
15// pointer attributes checked when coercing pointer to anon literal
16//
17// tmp.zig:2:31: error: cannot cast pointer to array literal to slice type '[][]const u8'
18// tmp.zig:2:31: note: cast discards const qualifier
19// tmp.zig:6:33: error: cannot cast pointer to array literal to '*[2][]const u8'
20// tmp.zig:6:33: note: cast discards const qualifier
21// tmp.zig:11:21: error: expected type '*S', found '*const struct:11:21'
22// tmp.zig:11:21: note: cast discards const qualifier
test/compile_errors/stage1/obj/pointer_to_noreturn.zig created+6
...@@ -0,0 +1,6 @@
1fn a() *noreturn {}
2export fn entry() void { _ = a(); }
3
4// pointer to noreturn
5//
6// tmp.zig:1:9: error: pointer to noreturn not allowed
test/compile_errors/stage1/obj/popCount-non-integer.zig created+7
...@@ -0,0 +1,7 @@
1export fn entry(x: f32) u32 {
2 return @popCount(f32, x);
3}
4
5// @popCount - non-integer
6//
7// tmp.zig:2:22: error: expected integer type, found 'f32'
test/compile_errors/stage1/obj/prevent_bad_implicit_casting_of_anyframe_types.zig created+22
...@@ -0,0 +1,22 @@
1export fn a() void {
2 var x: anyframe = undefined;
3 var y: anyframe->i32 = x;
4 _ = y;
5}
6export fn b() void {
7 var x: i32 = undefined;
8 var y: anyframe->i32 = x;
9 _ = y;
10}
11export fn c() void {
12 var x: @Frame(func) = undefined;
13 var y: anyframe->i32 = &x;
14 _ = y;
15}
16fn func() void {}
17
18// prevent bad implicit casting of anyframe types
19//
20// tmp.zig:3:28: error: expected type 'anyframe->i32', found 'anyframe'
21// tmp.zig:8:28: error: expected type 'anyframe->i32', found 'i32'
22// tmp.zig:13:29: error: expected type 'anyframe->i32', found '*@Frame(func)'
test/compile_errors/stage1/obj/primitives_take_precedence_over_declarations.zig created+9
...@@ -0,0 +1,9 @@
1const @"u8" = u16;
2export fn entry() void {
3 const a: u8 = 300;
4 _ = a;
5}
6
7// primitives take precedence over declarations
8//
9// tmp.zig:3:19: error: integer value 300 cannot be coerced to type 'u8'
test/compile_errors/stage1/obj/ptrCast_a_0_bit_type_to_a_non-_0_bit_type.zig created+11
...@@ -0,0 +1,11 @@
1export fn entry() bool {
2 var x: u0 = 0;
3 const p = @ptrCast(?*u0, &x);
4 return p == null;
5}
6
7// @ptrCast a 0 bit type to a non- 0 bit type
8//
9// tmp.zig:3:15: error: '*u0' and '?*u0' do not have the same in-memory representation
10// tmp.zig:3:31: note: '*u0' has no in-memory bits
11// tmp.zig:3:24: note: '?*u0' has in-memory bits
test/compile_errors/stage1/obj/ptrCast_discards_const_qualifier.zig created+9
...@@ -0,0 +1,9 @@
1export fn entry() void {
2 const x: i32 = 1234;
3 const y = @ptrCast(*i32, &x);
4 _ = y;
5}
6
7// @ptrCast discards const qualifier
8//
9// tmp.zig:3:15: error: cast discards const qualifier
test/compile_errors/stage1/obj/ptrToInt_0_to_non_optional_pointer.zig created+8
...@@ -0,0 +1,8 @@
1export fn entry() void {
2 var b = @intToPtr(*i32, 0);
3 _ = b;
4}
5
6// @ptrToInt 0 to non optional pointer
7//
8// tmp.zig:2:13: error: pointer type '*i32' does not allow address zero
test/compile_errors/stage1/obj/ptrToInt_on_void.zig created+7
...@@ -0,0 +1,7 @@
1export fn entry() bool {
2 return @ptrToInt(&{}) == @ptrToInt(&{});
3}
4
5// @ptrToInt on *void
6//
7// tmp.zig:2:23: error: pointer to size 0 type has no address
test/compile_errors/stage1/obj/ptrcast_to_non-pointer.zig created+7
...@@ -0,0 +1,7 @@
1export fn entry(a: *i32) usize {
2 return @ptrCast(usize, a);
3}
4
5// ptrcast to non-pointer
6//
7// tmp.zig:2:21: error: expected pointer, found 'usize'
test/compile_errors/stage1/obj/range_operator_in_switch_used_on_error_set.zig created+17
...@@ -0,0 +1,17 @@
1export fn entry() void {
2 try foo(452) catch |err| switch (err) {
3 error.A ... error.B => {},
4 else => {},
5 };
6}
7fn foo(x: i32) !void {
8 switch (x) {
9 0 ... 10 => return error.Foo,
10 11 ... 20 => return error.Bar,
11 else => {},
12 }
13}
14
15// range operator in switch used on error set
16//
17// tmp.zig:3:17: error: operator not allowed for errors
test/compile_errors/stage1/obj/reading_past_end_of_pointer_casted_array.zig created+11
...@@ -0,0 +1,11 @@
1comptime {
2 const array: [4]u8 = "aoeu".*;
3 const sub_array = array[1..];
4 const int_ptr = @ptrCast(*const u24, sub_array);
5 const deref = int_ptr.*;
6 _ = deref;
7}
8
9// reading past end of pointer casted array
10//
11// tmp.zig:5:26: error: attempt to read 4 bytes from [4]u8 at index 1 which is 3 bytes
test/compile_errors/stage1/obj/recursive_inferred_error_set.zig created+10
...@@ -0,0 +1,10 @@
1export fn entry() void {
2 foo() catch unreachable;
3}
4fn foo() !void {
5 try foo();
6}
7
8// recursive inferred error set
9//
10// tmp.zig:5:5: error: cannot resolve inferred error set '@typeInfo(@typeInfo(@TypeOf(foo)).Fn.return_type.?).ErrorUnion.error_set': function 'foo' not fully analyzed yet
test/compile_errors/stage1/obj/redefinition_of_enums.zig created+7
...@@ -0,0 +1,7 @@
1const A = enum {x};
2const A = enum {x};
3
4// redefinition of enums
5//
6// tmp.zig:2:1: error: redeclaration of 'A'
7// tmp.zig:1:1: note: other declaration here
test/compile_errors/stage1/obj/redefinition_of_global_variables.zig created+7
...@@ -0,0 +1,7 @@
1var a : i32 = 1;
2var a : i32 = 2;
3
4// redefinition of global variables
5//
6// tmp.zig:2:1: error: redeclaration of 'a'
7// tmp.zig:1:1: note: other declaration here
test/compile_errors/stage1/obj/redefinition_of_struct.zig created+7
...@@ -0,0 +1,7 @@
1const A = struct { x : i32, };
2const A = struct { y : i32, };
3
4// redefinition of struct
5//
6// tmp.zig:2:1: error: redeclaration of 'A'
7// tmp.zig:1:1: note: other declaration here
test/compile_errors/stage1/obj/refer_to_the_type_of_a_generic_function.zig created+9
...@@ -0,0 +1,9 @@
1export fn entry() void {
2 const Func = fn (type) void;
3 const f: Func = undefined;
4 f(i32);
5}
6
7// refer to the type of a generic function
8//
9// tmp.zig:4:5: error: use of undefined value here causes undefined behavior
test/compile_errors/stage1/obj/referring_to_a_struct_that_is_invalid.zig created+15
...@@ -0,0 +1,15 @@
1const UsbDeviceRequest = struct {
2 Type: u8,
3};
4
5export fn foo() void {
6 comptime assert(@sizeOf(UsbDeviceRequest) == 0x8);
7}
8
9fn assert(ok: bool) void {
10 if (!ok) unreachable;
11}
12
13// referring to a struct that is invalid
14//
15// tmp.zig:10:14: error: reached unreachable code
test/compile_errors/stage1/obj/regression_test_2980_base_type_u32_is_not_type_checked_properly_when_assigning_a_value_within_a_struct.zig created+19
...@@ -0,0 +1,19 @@
1const Foo = struct {
2 ptr: ?*usize,
3 uval: u32,
4};
5fn get_uval(x: u32) !u32 {
6 _ = x;
7 return error.NotFound;
8}
9export fn entry() void {
10 const afoo = Foo{
11 .ptr = null,
12 .uval = get_uval(42),
13 };
14 _ = afoo;
15}
16
17// regression test #2980: base type u32 is not type checked properly when assigning a value within a struct
18//
19// tmp.zig:12:25: error: cannot convert error union to payload type. consider using `try`, `catch`, or `if`. expected type 'u32', found '@typeInfo(@typeInfo(@TypeOf(get_uval)).Fn.return_type.?).ErrorUnion.error_set!u32'
test/compile_errors/stage1/obj/reify_type.Fn_with_is_generic_true.zig created+15
...@@ -0,0 +1,15 @@
1const Foo = @Type(.{
2 .Fn = .{
3 .calling_convention = .Unspecified,
4 .alignment = 0,
5 .is_generic = true,
6 .is_var_args = false,
7 .return_type = u0,
8 .args = &.{},
9 },
10});
11comptime { _ = Foo; }
12
13// @Type(.Fn) with is_generic = true
14//
15// tmp.zig:1:20: error: Type.Fn.is_generic must be false for @Type
test/compile_errors/stage1/obj/reify_type.Fn_with_is_var_args_true_and_non-C_callconv.zig created+15
...@@ -0,0 +1,15 @@
1const Foo = @Type(.{
2 .Fn = .{
3 .calling_convention = .Unspecified,
4 .alignment = 0,
5 .is_generic = false,
6 .is_var_args = true,
7 .return_type = u0,
8 .args = &.{},
9 },
10});
11comptime { _ = Foo; }
12
13// @Type(.Fn) with is_var_args = true and non-C callconv
14//
15// tmp.zig:1:20: error: varargs functions must have C calling convention
test/compile_errors/stage1/obj/reify_type.Fn_with_return_type_null.zig created+15
...@@ -0,0 +1,15 @@
1const Foo = @Type(.{
2 .Fn = .{
3 .calling_convention = .Unspecified,
4 .alignment = 0,
5 .is_generic = false,
6 .is_var_args = false,
7 .return_type = null,
8 .args = &.{},
9 },
10});
11comptime { _ = Foo; }
12
13// @Type(.Fn) with return_type = null
14//
15// tmp.zig:1:20: error: Type.Fn.return_type must be non-null for @Type
test/compile_errors/stage1/obj/reify_type.Pointer_with_invalid_address_space.zig created+16
...@@ -0,0 +1,16 @@
1export fn entry() void {
2 _ = @Type(.{ .Pointer = .{
3 .size = .One,
4 .is_const = false,
5 .is_volatile = false,
6 .alignment = 1,
7 .address_space = .gs,
8 .child = u8,
9 .is_allowzero = false,
10 .sentinel = null,
11 }});
12}
13
14// @Type(.Pointer) with invalid address space
15//
16// tmp.zig:2:16: error: address space 'gs' not available in stage 1 compiler, must be .generic
test/compile_errors/stage1/obj/reify_type_for_exhaustive_enum_with_non-integer_tag_type.zig created+16
...@@ -0,0 +1,16 @@
1const Tag = @Type(.{
2 .Enum = .{
3 .layout = .Auto,
4 .tag_type = bool,
5 .fields = &.{},
6 .decls = &.{},
7 .is_exhaustive = false,
8 },
9});
10export fn entry() void {
11 _ = @intToEnum(Tag, 0);
12}
13
14// @Type for exhaustive enum with non-integer tag type
15//
16// tmp.zig:1:20: error: Type.Enum.tag_type must be an integer type, not 'bool'
test/compile_errors/stage1/obj/reify_type_for_exhaustive_enum_with_undefined_tag_type.zig created+16
...@@ -0,0 +1,16 @@
1const Tag = @Type(.{
2 .Enum = .{
3 .layout = .Auto,
4 .tag_type = undefined,
5 .fields = &.{},
6 .decls = &.{},
7 .is_exhaustive = false,
8 },
9});
10export fn entry() void {
11 _ = @intToEnum(Tag, 0);
12}
13
14// @Type for exhaustive enum with undefined tag type
15//
16// tmp.zig:1:20: error: use of undefined value here causes undefined behavior
test/compile_errors/stage1/obj/reify_type_for_exhaustive_enum_with_zero_fields.zig created+16
...@@ -0,0 +1,16 @@
1const Tag = @Type(.{
2 .Enum = .{
3 .layout = .Auto,
4 .tag_type = u1,
5 .fields = &.{},
6 .decls = &.{},
7 .is_exhaustive = true,
8 },
9});
10export fn entry() void {
11 _ = @intToEnum(Tag, 0);
12}
13
14// @Type for exhaustive enum with zero fields
15//
16// tmp.zig:1:20: error: enums must have 1 or more fields
test/compile_errors/stage1/obj/reify_type_for_tagged_union_with_extra_enum_field.zig created+32
...@@ -0,0 +1,32 @@
1const Tag = @Type(.{
2 .Enum = .{
3 .layout = .Auto,
4 .tag_type = u2,
5 .fields = &.{
6 .{ .name = "signed", .value = 0 },
7 .{ .name = "unsigned", .value = 1 },
8 .{ .name = "arst", .value = 2 },
9 },
10 .decls = &.{},
11 .is_exhaustive = true,
12 },
13});
14const Tagged = @Type(.{
15 .Union = .{
16 .layout = .Auto,
17 .tag_type = Tag,
18 .fields = &.{
19 .{ .name = "signed", .field_type = i32, .alignment = @alignOf(i32) },
20 .{ .name = "unsigned", .field_type = u32, .alignment = @alignOf(u32) },
21 },
22 .decls = &.{},
23 },
24});
25export fn entry() void {
26 var tagged = Tagged{ .signed = -1 };
27 tagged = .{ .unsigned = 1 };
28}
29
30// @Type for tagged union with extra enum field
31//
32// tmp.zig:14:23: error: enum field missing: 'arst'
test/compile_errors/stage1/obj/reify_type_for_tagged_union_with_extra_union_field.zig created+33
...@@ -0,0 +1,33 @@
1const Tag = @Type(.{
2 .Enum = .{
3 .layout = .Auto,
4 .tag_type = u1,
5 .fields = &.{
6 .{ .name = "signed", .value = 0 },
7 .{ .name = "unsigned", .value = 1 },
8 },
9 .decls = &.{},
10 .is_exhaustive = true,
11 },
12});
13const Tagged = @Type(.{
14 .Union = .{
15 .layout = .Auto,
16 .tag_type = Tag,
17 .fields = &.{
18 .{ .name = "signed", .field_type = i32, .alignment = @alignOf(i32) },
19 .{ .name = "unsigned", .field_type = u32, .alignment = @alignOf(u32) },
20 .{ .name = "arst", .field_type = f32, .alignment = @alignOf(f32) },
21 },
22 .decls = &.{},
23 },
24});
25export fn entry() void {
26 var tagged = Tagged{ .signed = -1 };
27 tagged = .{ .unsigned = 1 };
28}
29
30// @Type for tagged union with extra union field
31//
32// tmp.zig:13:23: error: enum field not found: 'arst'
33// tmp.zig:1:20: note: enum declared here
test/compile_errors/stage1/obj/reify_type_for_union_with_opaque_field.zig created+17
...@@ -0,0 +1,17 @@
1const Untagged = @Type(.{
2 .Union = .{
3 .layout = .Auto,
4 .tag_type = null,
5 .fields = &.{
6 .{ .name = "foo", .field_type = opaque {}, .alignment = 1 },
7 },
8 .decls = &.{},
9 },
10});
11export fn entry() void {
12 _ = Untagged{};
13}
14
15// @Type for union with opaque field
16//
17// tmp.zig:1:25: error: opaque types have unknown size and therefore cannot be directly embedded in unions
test/compile_errors/stage1/obj/reify_type_for_union_with_zero_fields.zig created+15
...@@ -0,0 +1,15 @@
1const Untagged = @Type(.{
2 .Union = .{
3 .layout = .Auto,
4 .tag_type = null,
5 .fields = &.{},
6 .decls = &.{},
7 },
8});
9export fn entry() void {
10 _ = Untagged{};
11}
12
13// @Type for union with zero fields
14//
15// tmp.zig:1:25: error: unions must have 1 or more fields
test/compile_errors/stage1/obj/reify_type_union_payload_is_undefined.zig created+8
...@@ -0,0 +1,8 @@
1const Foo = @Type(.{
2 .Struct = undefined,
3});
4comptime { _ = Foo; }
5
6// @Type() union payload is undefined
7//
8// tmp.zig:1:20: error: use of undefined value here causes undefined behavior
test/compile_errors/stage1/obj/reify_type_with_Type.Int.zig created+11
...@@ -0,0 +1,11 @@
1const builtin = @import("std").builtin;
2export fn entry() void {
3 _ = @Type(builtin.Type.Int{
4 .signedness = .signed,
5 .bits = 8,
6 });
7}
8
9// @Type with Type.Int
10//
11// tmp.zig:3:31: error: expected type 'std.builtin.Type', found 'std.builtin.Type.Int'
test/compile_errors/stage1/obj/reify_type_with_non-constant_expression.zig created+9
...@@ -0,0 +1,9 @@
1const builtin = @import("std").builtin;
2var globalTypeInfo : builtin.Type = undefined;
3export fn entry() void {
4 _ = @Type(globalTypeInfo);
5}
6
7// @Type with non-constant expression
8//
9// tmp.zig:4:15: error: unable to evaluate constant expression
test/compile_errors/stage1/obj/reify_type_with_undefined.zig created+18
...@@ -0,0 +1,18 @@
1comptime {
2 _ = @Type(.{ .Array = .{ .len = 0, .child = u8, .sentinel = undefined } });
3}
4comptime {
5 _ = @Type(.{
6 .Struct = .{
7 .fields = undefined,
8 .decls = undefined,
9 .is_tuple = false,
10 .layout = .Auto,
11 },
12 });
13}
14
15// @Type with undefined
16//
17// tmp.zig:2:16: error: use of undefined value here causes undefined behavior
18// tmp.zig:5:16: error: use of undefined value here causes undefined behavior
test/compile_errors/stage1/obj/result_location_incompatibility_mismatching_handle_is_ptr.zig created+16
...@@ -0,0 +1,16 @@
1export fn entry() void {
2 var damn = Container{
3 .not_optional = getOptional(),
4 };
5 _ = damn;
6}
7pub fn getOptional() ?i32 {
8 return 0;
9}
10pub const Container = struct {
11 not_optional: i32,
12};
13
14// result location incompatibility mismatching handle_is_ptr
15//
16// tmp.zig:3:36: error: cannot convert optional to payload type. consider using `.?`, `orelse`, or `if`. expected type 'i32', found '?i32'
test/compile_errors/stage1/obj/result_location_incompatibility_mismatching_handle_is_ptr_generic_call.zig created+16
...@@ -0,0 +1,16 @@
1export fn entry() void {
2 var damn = Container{
3 .not_optional = getOptional(i32),
4 };
5 _ = damn;
6}
7pub fn getOptional(comptime T: type) ?T {
8 return 0;
9}
10pub const Container = struct {
11 not_optional: i32,
12};
13
14// result location incompatibility mismatching handle_is_ptr (generic call)
15//
16// tmp.zig:3:36: error: cannot convert optional to payload type. consider using `.?`, `orelse`, or `if`. expected type 'i32', found '?i32'
test/compile_errors/stage1/obj/return_from_defer_expression.zig created+19
...@@ -0,0 +1,19 @@
1pub fn testTrickyDefer() !void {
2 defer canFail() catch {};
3
4 defer try canFail();
5
6 const a = maybeInt() orelse return;
7}
8
9fn canFail() anyerror!void { }
10
11pub fn maybeInt() ?i32 {
12 return 0;
13}
14
15export fn entry() usize { return @sizeOf(@TypeOf(testTrickyDefer)); }
16
17// return from defer expression
18//
19// tmp.zig:4:11: error: 'try' not allowed inside defer expression
test/compile_errors/stage1/obj/returning_error_from_void_async_function.zig created+10
...@@ -0,0 +1,10 @@
1export fn entry() void {
2 _ = async amain();
3}
4fn amain() callconv(.Async) void {
5 return error.ShouldBeCompileError;
6}
7
8// returning error from void async function
9//
10// tmp.zig:5:17: error: expected type 'void', found 'error{ShouldBeCompileError}'
test/compile_errors/stage1/obj/runtime-known_async_function_called.zig created+12
...@@ -0,0 +1,12 @@
1export fn entry() void {
2 _ = async amain();
3}
4fn amain() void {
5 var ptr = afunc;
6 _ = ptr();
7}
8fn afunc() callconv(.Async) void {}
9
10// runtime-known async function called
11//
12// tmp.zig:6:12: error: function is not comptime-known; @asyncCall required
test/compile_errors/stage1/obj/runtime-known_function_called_with_async_keyword.zig created+10
...@@ -0,0 +1,10 @@
1export fn entry() void {
2 var ptr = afunc;
3 _ = async ptr();
4}
5
6fn afunc() callconv(.Async) void { }
7
8// runtime-known function called with async keyword
9//
10// tmp.zig:3:15: error: function is not comptime-known; @asyncCall required
test/compile_errors/stage1/obj/runtime_assignment_to_comptime_struct_type.zig created+13
...@@ -0,0 +1,13 @@
1const Foo = struct {
2 Bar: u8,
3 Baz: type,
4};
5export fn f() void {
6 var x: u8 = 0;
7 const foo = Foo { .Bar = x, .Baz = u8 };
8 _ = foo;
9}
10
11// runtime assignment to comptime struct type
12//
13// tmp.zig:7:23: error: unable to evaluate constant expression
test/compile_errors/stage1/obj/runtime_assignment_to_comptime_union_type.zig created+13
...@@ -0,0 +1,13 @@
1const Foo = union {
2 Bar: u8,
3 Baz: type,
4};
5export fn f() void {
6 var x: u8 = 0;
7 const foo = Foo { .Bar = x };
8 _ = foo;
9}
10
11// runtime assignment to comptime union type
12//
13// tmp.zig:7:23: error: unable to evaluate constant expression
test/compile_errors/stage1/obj/runtime_cast_to_union_which_has_non-void_fields.zig created+18
...@@ -0,0 +1,18 @@
1const Letter = enum { A, B, C };
2const Value = union(Letter) {
3 A: i32,
4 B,
5 C,
6};
7export fn entry() void {
8 foo(Letter.A);
9}
10fn foo(l: Letter) void {
11 var x: Value = l;
12 _ = x;
13}
14
15// runtime cast to union which has non-void fields
16//
17// tmp.zig:11:20: error: runtime cast to union 'Value' which has non-void fields
18// tmp.zig:3:5: note: field 'A' has type 'i32'
test/compile_errors/stage1/obj/runtime_index_into_comptime_type_slice.zig created+15
...@@ -0,0 +1,15 @@
1const Struct = struct {
2 a: u32,
3};
4fn getIndex() usize {
5 return 2;
6}
7export fn entry() void {
8 const index = getIndex();
9 const field = @typeInfo(Struct).Struct.fields[index];
10 _ = field;
11}
12
13// runtime index into comptime type slice
14//
15// tmp.zig:9:51: error: values of type 'std.builtin.Type.StructField' must be comptime known, but index value is runtime known
test/compile_errors/stage1/obj/saturating_arithmetic_does_not_allow_floats.zig created+7
...@@ -0,0 +1,7 @@
1export fn a() void {
2 _ = @as(f32, 1.0) +| @as(f32, 1.0);
3}
4
5// saturating arithmetic does not allow floats
6//
7// error: invalid operands to binary expression: 'f32' and 'f32'
test/compile_errors/stage1/obj/saturating_shl_assign_does_not_allow_negative_rhs_at_comptime.zig created+10
...@@ -0,0 +1,10 @@
1export fn a() void {
2 comptime {
3 var x = @as(i32, 1);
4 x <<|= @as(i32, -2);
5 }
6}
7
8// saturating shl assign does not allow negative rhs at comptime
9//
10// error: shift by negative value -2
test/compile_errors/stage1/obj/saturating_shl_does_not_allow_negative_rhs_at_comptime.zig created+7
...@@ -0,0 +1,7 @@
1export fn a() void {
2 _ = @as(i32, 1) <<| @as(i32, -2);
3}
4
5// saturating shl does not allow negative rhs at comptime
6//
7// error: shift by negative value -2
test/compile_errors/stage1/obj/setAlignStack_in_inline_function.zig created+10
...@@ -0,0 +1,10 @@
1export fn entry() void {
2 foo();
3}
4fn foo() callconv(.Inline) void {
5 @setAlignStack(16);
6}
7
8// @setAlignStack in inline function
9//
10// tmp.zig:5:5: error: @setAlignStack in inline function
test/compile_errors/stage1/obj/setAlignStack_in_naked_function.zig created+7
...@@ -0,0 +1,7 @@
1export fn entry() callconv(.Naked) void {
2 @setAlignStack(16);
3}
4
5// @setAlignStack in naked function
6//
7// tmp.zig:2:5: error: @setAlignStack in naked function
test/compile_errors/stage1/obj/setAlignStack_outside_function.zig created+7
...@@ -0,0 +1,7 @@
1comptime {
2 @setAlignStack(16);
3}
4
5// @setAlignStack outside function
6//
7// tmp.zig:2:5: error: @setAlignStack outside function
test/compile_errors/stage1/obj/setAlignStack_set_twice.zig created+9
...@@ -0,0 +1,9 @@
1export fn entry() void {
2 @setAlignStack(16);
3 @setAlignStack(16);
4}
5
6// @setAlignStack set twice
7//
8// tmp.zig:3:5: error: alignstack set twice
9// tmp.zig:2:5: note: first set here
test/compile_errors/stage1/obj/setAlignStack_too_big.zig created+7
...@@ -0,0 +1,7 @@
1export fn entry() void {
2 @setAlignStack(511 + 1);
3}
4
5// @setAlignStack too big
6//
7// tmp.zig:2:5: error: attempt to @setAlignStack(512); maximum is 256
test/compile_errors/stage1/obj/setFloatMode_twice_for_same_scope.zig created+9
...@@ -0,0 +1,9 @@
1export fn foo() void {
2 @setFloatMode(@import("std").builtin.FloatMode.Optimized);
3 @setFloatMode(@import("std").builtin.FloatMode.Optimized);
4}
5
6// @setFloatMode twice for same scope
7//
8// tmp.zig:3:5: error: float mode set twice for same scope
9// tmp.zig:2:5: note: first set here
test/compile_errors/stage1/obj/setRuntimeSafety_twice_for_same_scope.zig created+9
...@@ -0,0 +1,9 @@
1export fn foo() void {
2 @setRuntimeSafety(false);
3 @setRuntimeSafety(false);
4}
5
6// @setRuntimeSafety twice for same scope
7//
8// tmp.zig:3:5: error: runtime safety set twice for same scope
9// tmp.zig:2:5: note: first set here
test/compile_errors/stage1/obj/setting_a_section_on_a_local_variable.zig created+8
...@@ -0,0 +1,8 @@
1export fn entry() i32 {
2 var foo: i32 linksection(".text2") = 1234;
3 return foo;
4}
5
6// setting a section on a local variable
7//
8// tmp.zig:2:30: error: cannot set section of local variable 'foo'
test/compile_errors/stage1/obj/shift_amount_has_to_be_an_integer_type.zig created+8
...@@ -0,0 +1,8 @@
1export fn entry() void {
2 const x = 1 << &@as(u8, 10);
3 _ = x;
4}
5
6// shift amount has to be an integer type
7//
8// tmp.zig:2:21: error: shift amount has to be an integer type, but found '*const u8'
test/compile_errors/stage1/obj/shift_by_negative_comptime_integer.zig created+8
...@@ -0,0 +1,8 @@
1comptime {
2 var a = 1 >> -1;
3 _ = a;
4}
5
6// shift by negative comptime integer
7//
8// tmp.zig:2:18: error: shift by negative value -1
test/compile_errors/stage1/obj/shift_left_assign_on_undefined_value.zig created+8
...@@ -0,0 +1,8 @@
1comptime {
2 var a: i64 = undefined;
3 a >>= 2;
4}
5
6// shift left assign on undefined value
7//
8// tmp.zig:3:5: error: use of undefined value here causes undefined behavior
test/compile_errors/stage1/obj/shift_left_on_undefined_value.zig created+8
...@@ -0,0 +1,8 @@
1comptime {
2 var a: i64 = undefined;
3 _ = a << 2;
4}
5
6// shift left on undefined value
7//
8// tmp.zig:3:9: error: use of undefined value here causes undefined behavior
test/compile_errors/stage1/obj/shift_right_assign_on_undefined_value.zig created+8
...@@ -0,0 +1,8 @@
1comptime {
2 var a: i64 = undefined;
3 a >>= 2;
4}
5
6// shift right assign on undefined value
7//
8// tmp.zig:3:5: error: use of undefined value here causes undefined behavior
test/compile_errors/stage1/obj/shift_right_on_undefined_value.zig created+8
...@@ -0,0 +1,8 @@
1comptime {
2 var a: i64 = undefined;
3 _ = a >> 2;
4}
5
6// shift right on undefined value
7//
8// tmp.zig:3:9: error: use of undefined value here causes undefined behavior
test/compile_errors/stage1/obj/shifting_RHS_is_log2_of_LHS_int_bit_width.zig created+7
...@@ -0,0 +1,7 @@
1export fn entry(x: u8, y: u8) u8 {
2 return x << y;
3}
4
5// shifting RHS is log2 of LHS int bit width
6//
7// tmp.zig:2:17: error: expected type 'u3', found 'u8'
test/compile_errors/stage1/obj/shifting_without_int_type_or_comptime_known.zig created+7
...@@ -0,0 +1,7 @@
1export fn entry(x: u8) u8 {
2 return 0x11 << x;
3}
4
5// shifting without int type or comptime known
6//
7// tmp.zig:2:17: error: LHS of shift must be a fixed-width integer type, or RHS must be compile-time known
test/compile_errors/stage1/obj/shlExact_shifts_out_1_bits.zig created+8
...@@ -0,0 +1,8 @@
1comptime {
2 const x = @shlExact(@as(u8, 0b01010101), 2);
3 _ = x;
4}
5
6// @shlExact shifts out 1 bits
7//
8// tmp.zig:2:15: error: operation caused overflow
test/compile_errors/stage1/obj/shrExact_shifts_out_1_bits.zig created+8
...@@ -0,0 +1,8 @@
1comptime {
2 const x = @shrExact(@as(u8, 0b10101010), 2);
3 _ = x;
4}
5
6// @shrExact shifts out 1 bits
7//
8// tmp.zig:2:15: error: exact shift shifted out 1 bits
test/compile_errors/stage1/obj/signed_integer_division.zig created+7
...@@ -0,0 +1,7 @@
1export fn foo(a: i32, b: i32) i32 {
2 return a / b;
3}
4
5// signed integer division
6//
7// tmp.zig:2:14: error: division with 'i32' and 'i32': signed integers must use @divTrunc, @divFloor, or @divExact
test/compile_errors/stage1/obj/signed_integer_remainder_division.zig created+7
...@@ -0,0 +1,7 @@
1export fn foo(a: i32, b: i32) i32 {
2 return a % b;
3}
4
5// signed integer remainder division
6//
7// tmp.zig:2:14: error: remainder division with 'i32' and 'i32': signed integers and floats must use @rem or @mod
test/compile_errors/stage1/obj/sizeOf_bad_type.zig created+7
...@@ -0,0 +1,7 @@
1export fn entry() usize {
2 return @sizeOf(@TypeOf(null));
3}
4
5// @sizeOf bad type
6//
7// tmp.zig:2:20: error: no size available for type '@Type(.Null)'
test/compile_errors/stage1/obj/slice_cannot_have_its_bytes_reinterpreted.zig created+9
...@@ -0,0 +1,9 @@
1export fn foo() void {
2 const bytes = [1]u8{ 0xfa } ** 16;
3 var value = @ptrCast(*const []const u8, &bytes).*;
4 _ = value;
5}
6
7// slice cannot have its bytes reinterpreted
8//
9// :3:52: error: slice '[]const u8' cannot have its bytes reinterpreted
test/compile_errors/stage1/obj/slice_passed_as_array_init_type.zig created+8
...@@ -0,0 +1,8 @@
1export fn entry() void {
2 const x = []u8{};
3 _ = x;
4}
5
6// slice passed as array init type
7//
8// tmp.zig:2:15: error: array literal requires address-of operator (&) to coerce to slice type '[]u8'
test/compile_errors/stage1/obj/slice_passed_as_array_init_type_with_elems.zig created+8
...@@ -0,0 +1,8 @@
1export fn entry() void {
2 const x = []u8{1, 2};
3 _ = x;
4}
5
6// slice passed as array init type with elems
7//
8// tmp.zig:2:15: error: array literal requires address-of operator (&) to coerce to slice type '[]u8'
test/compile_errors/stage1/obj/slice_sentinel_mismatch-1.zig created+8
...@@ -0,0 +1,8 @@
1export fn entry() void {
2 const y: [:1]const u8 = &[_:2]u8{ 1, 2 };
3 _ = y;
4}
5
6// slice sentinel mismatch - 1
7//
8// tmp.zig:2:37: error: expected type '[:1]const u8', found '*const [2:2]u8'
test/compile_errors/stage1/obj/slice_sentinel_mismatch-2.zig created+10
...@@ -0,0 +1,10 @@
1fn foo() [:0]u8 {
2 var x: []u8 = undefined;
3 return x;
4}
5comptime { _ = foo; }
6
7// slice sentinel mismatch - 2
8//
9// tmp.zig:3:12: error: expected type '[:0]u8', found '[]u8'
10// tmp.zig:3:12: note: destination pointer requires a terminating '0' sentinel
test/compile_errors/stage1/obj/slicing_of_global_undefined_pointer.zig created+8
...@@ -0,0 +1,8 @@
1var buf: *[1]u8 = undefined;
2export fn entry() void {
3 _ = buf[0..1];
4}
5
6// slicing of global undefined pointer
7//
8// tmp.zig:3:12: error: non-zero length slice of undefined pointer
test/compile_errors/stage1/obj/slicing_single-item_pointer.zig created+8
...@@ -0,0 +1,8 @@
1export fn entry(ptr: *i32) void {
2 const slice = ptr[0..2];
3 _ = slice;
4}
5
6// slicing single-item pointer
7//
8// tmp.zig:2:22: error: slice of single-item pointer
test/compile_errors/stage1/obj/specify_enum_tag_type_that_is_too_small.zig created+16
...@@ -0,0 +1,16 @@
1const Small = enum (u2) {
2 One,
3 Two,
4 Three,
5 Four,
6 Five,
7};
8
9export fn entry() void {
10 var x = Small.One;
11 _ = x;
12}
13
14// specify enum tag type that is too small
15//
16// tmp.zig:6:5: error: enumeration value 4 too large for type 'u2'
test/compile_errors/stage1/obj/specify_non-integer_enum_tag_type.zig created+14
...@@ -0,0 +1,14 @@
1const Small = enum (f32) {
2 One,
3 Two,
4 Three,
5};
6
7export fn entry() void {
8 var x = Small.One;
9 _ = x;
10}
11
12// specify non-integer enum tag type
13//
14// tmp.zig:1:21: error: expected integer, found 'f32'
test/compile_errors/stage1/obj/src_outside_function.zig created+7
...@@ -0,0 +1,7 @@
1comptime {
2 @src();
3}
4
5// @src outside function
6//
7// tmp.zig:2:5: error: @src outside function
test/compile_errors/stage1/obj/store_vector_pointer_with_unknown_runtime_index.zig created+14
...@@ -0,0 +1,14 @@
1export fn entry() void {
2 var v: @import("std").meta.Vector(4, i32) = [_]i32{ 1, 5, 3, undefined };
3
4 var i: u32 = 0;
5 storev(&v[i], 42);
6}
7
8fn storev(ptr: anytype, val: i32) void {
9 ptr.* = val;
10}
11
12// store vector pointer with unknown runtime index
13//
14// tmp.zig:9:8: error: unable to determine vector element index of type '*align(16:0:4:?) i32
test/compile_errors/stage1/obj/storing_runtime_value_in_compile_time_variable_then_using_it.zig created+47
...@@ -0,0 +1,47 @@
1const Mode = @import("std").builtin.Mode;
2
3fn Free(comptime filename: []const u8) TestCase {
4 return TestCase {
5 .filename = filename,
6 .problem_type = ProblemType.Free,
7 };
8}
9
10fn LibC(comptime filename: []const u8) TestCase {
11 return TestCase {
12 .filename = filename,
13 .problem_type = ProblemType.LinkLibC,
14 };
15}
16
17const TestCase = struct {
18 filename: []const u8,
19 problem_type: ProblemType,
20};
21
22const ProblemType = enum {
23 Free,
24 LinkLibC,
25};
26
27export fn entry() void {
28 const tests = [_]TestCase {
29 Free("001"),
30 Free("002"),
31 LibC("078"),
32 Free("116"),
33 Free("117"),
34 };
35
36 for ([_]Mode { Mode.Debug, Mode.ReleaseSafe, Mode.ReleaseFast }) |mode| {
37 _ = mode;
38 inline for (tests) |test_case| {
39 const foo = test_case.filename ++ ".zig";
40 _ = foo;
41 }
42 }
43}
44
45// storing runtime value in compile time variable then using it
46//
47// tmp.zig:38:29: error: cannot store runtime value in compile time variable
test/compile_errors/stage1/obj/struct_depends_on_itself_via_optional_field.zig created+17
...@@ -0,0 +1,17 @@
1const LhsExpr = struct {
2 rhsExpr: ?AstObject,
3};
4const AstObject = union {
5 lhsExpr: LhsExpr,
6};
7export fn entry() void {
8 const lhsExpr = LhsExpr{ .rhsExpr = null };
9 const obj = AstObject{ .lhsExpr = lhsExpr };
10 _ = obj;
11}
12
13// struct depends on itself via optional field
14//
15// tmp.zig:1:17: error: struct 'LhsExpr' depends on itself
16// tmp.zig:5:5: note: while checking this field
17// tmp.zig:2:5: note: while checking this field
test/compile_errors/stage1/obj/struct_field_missing_type.zig created+11
...@@ -0,0 +1,11 @@
1const Letter = struct {
2 A,
3};
4export fn entry() void {
5 var a = Letter { .A = {} };
6 _ = a;
7}
8
9// struct field missing type
10//
11// tmp.zig:2:5: error: struct field missing type
test/compile_errors/stage1/obj/struct_init_syntax_for_array.zig created+8
...@@ -0,0 +1,8 @@
1const foo = [3]u16{ .x = 1024 };
2comptime {
3 _ = foo;
4}
5
6// struct init syntax for array
7//
8// tmp.zig:1:13: error: initializing array with struct syntax
test/compile_errors/stage1/obj/struct_with_declarations_unavailable_for_reify_type.zig created+7
...@@ -0,0 +1,7 @@
1export fn entry() void {
2 _ = @Type(@typeInfo(struct { const foo = 1; }));
3}
4
5// struct with declarations unavailable for @Type
6//
7// tmp.zig:2:15: error: Type.Struct.decls must be empty for @Type
test/compile_errors/stage1/obj/struct_with_invalid_field.zig created+28
...@@ -0,0 +1,28 @@
1const std = @import("std",);
2const Allocator = std.mem.Allocator;
3const ArrayList = std.ArrayList;
4
5const HeaderWeight = enum {
6 H1, H2, H3, H4, H5, H6,
7};
8
9const MdText = ArrayList(u8);
10
11const MdNode = union(enum) {
12 Header: struct {
13 text: MdText,
14 weight: HeaderValue,
15 },
16};
17
18export fn entry() void {
19 const a = MdNode.Header {
20 .text = MdText.init(std.testing.allocator),
21 .weight = HeaderWeight.H1,
22 };
23 _ = a;
24}
25
26// struct with invalid field
27//
28// tmp.zig:14:17: error: use of undeclared identifier 'HeaderValue'
test/compile_errors/stage1/obj/sub_assign_on_undefined_value.zig created+8
...@@ -0,0 +1,8 @@
1comptime {
2 var a: i64 = undefined;
3 a -= a;
4}
5
6// sub assign on undefined value
7//
8// tmp.zig:3:5: error: use of undefined value here causes undefined behavior
test/compile_errors/stage1/obj/sub_on_undefined_value.zig created+8
...@@ -0,0 +1,8 @@
1comptime {
2 var a: i64 = undefined;
3 _ = a - a;
4}
5
6// sub on undefined value
7//
8// tmp.zig:3:9: error: use of undefined value here causes undefined behavior
test/compile_errors/stage1/obj/sub_overflow_in_function_evaluation.zig created+10
...@@ -0,0 +1,10 @@
1const y = sub(10, 20);
2fn sub(a: u16, b: u16) u16 {
3 return a - b;
4}
5
6export fn entry() usize { return @sizeOf(@TypeOf(y)); }
7
8// sub overflow in function evaluation
9//
10// tmp.zig:3:14: error: operation caused overflow
test/compile_errors/stage1/obj/sub_wrap_assign_on_undefined_value.zig created+8
...@@ -0,0 +1,8 @@
1comptime {
2 var a: i64 = undefined;
3 a -%= a;
4}
5
6// sub wrap assign on undefined value
7//
8// tmp.zig:3:5: error: use of undefined value here causes undefined behavior
test/compile_errors/stage1/obj/sub_wrap_on_undefined_value.zig created+8
...@@ -0,0 +1,8 @@
1comptime {
2 var a: i64 = undefined;
3 _ = a -% a;
4}
5
6// sub wrap on undefined value
7//
8// tmp.zig:3:9: error: use of undefined value here causes undefined behavior
test/compile_errors/stage1/obj/suspend_inside_suspend_block.zig created+14
...@@ -0,0 +1,14 @@
1export fn entry() void {
2 _ = async foo();
3}
4fn foo() void {
5 suspend {
6 suspend {
7 }
8 }
9}
10
11// suspend inside suspend block
12//
13// tmp.zig:6:9: error: cannot suspend inside suspend block
14// tmp.zig:5:5: note: other suspend block here
test/compile_errors/stage1/obj/switch_expression-duplicate_enumeration_prong.zig created+22
...@@ -0,0 +1,22 @@
1const Number = enum {
2 One,
3 Two,
4 Three,
5 Four,
6};
7fn f(n: Number) i32 {
8 switch (n) {
9 Number.One => 1,
10 Number.Two => 2,
11 Number.Three => @as(i32, 3),
12 Number.Four => 4,
13 Number.Two => 2,
14 }
15}
16
17export fn entry() usize { return @sizeOf(@TypeOf(f)); }
18
19// switch expression - duplicate enumeration prong
20//
21// tmp.zig:13:15: error: duplicate switch value
22// tmp.zig:10:15: note: other value here
test/compile_errors/stage1/obj/switch_expression-duplicate_enumeration_prong_when_else_present.zig created+23
...@@ -0,0 +1,23 @@
1const Number = enum {
2 One,
3 Two,
4 Three,
5 Four,
6};
7fn f(n: Number) i32 {
8 switch (n) {
9 Number.One => 1,
10 Number.Two => 2,
11 Number.Three => @as(i32, 3),
12 Number.Four => 4,
13 Number.Two => 2,
14 else => 10,
15 }
16}
17
18export fn entry() usize { return @sizeOf(@TypeOf(f)); }
19
20// switch expression - duplicate enumeration prong when else present
21//
22// tmp.zig:13:15: error: duplicate switch value
23// tmp.zig:10:15: note: other value here
test/compile_errors/stage1/obj/switch_expression-duplicate_or_overlapping_integer_value.zig created+14
...@@ -0,0 +1,14 @@
1fn foo(x: u8) u8 {
2 return switch (x) {
3 0 ... 100 => @as(u8, 0),
4 101 ... 200 => 1,
5 201, 203 ... 207 => 2,
6 206 ... 255 => 3,
7 };
8}
9export fn entry() usize { return @sizeOf(@TypeOf(foo)); }
10
11// switch expression - duplicate or overlapping integer value
12//
13// tmp.zig:6:9: error: duplicate switch value
14// tmp.zig:5:14: note: previous value here
test/compile_errors/stage1/obj/switch_expression-duplicate_type.zig created+15
...@@ -0,0 +1,15 @@
1fn foo(comptime T: type, x: T) u8 {
2 _ = x;
3 return switch (T) {
4 u32 => 0,
5 u64 => 1,
6 u32 => 2,
7 else => 3,
8 };
9}
10export fn entry() usize { return @sizeOf(@TypeOf(foo(u32, 0))); }
11
12// switch expression - duplicate type
13//
14// tmp.zig:6:9: error: duplicate switch value
15// tmp.zig:4:9: note: previous value here
test/compile_errors/stage1/obj/switch_expression-duplicate_type_struct_alias.zig created+19
...@@ -0,0 +1,19 @@
1const Test = struct {
2 bar: i32,
3};
4const Test2 = Test;
5fn foo(comptime T: type, x: T) u8 {
6 _ = x;
7 return switch (T) {
8 Test => 0,
9 u64 => 1,
10 Test2 => 2,
11 else => 3,
12 };
13}
14export fn entry() usize { return @sizeOf(@TypeOf(foo(u32, 0))); }
15
16// switch expression - duplicate type (struct alias)
17//
18// tmp.zig:10:9: error: duplicate switch value
19// tmp.zig:8:9: note: previous value here
test/compile_errors/stage1/obj/switch_expression-missing_enumeration_prong.zig created+19
...@@ -0,0 +1,19 @@
1const Number = enum {
2 One,
3 Two,
4 Three,
5 Four,
6};
7fn f(n: Number) i32 {
8 switch (n) {
9 Number.One => 1,
10 Number.Two => 2,
11 Number.Three => @as(i32, 3),
12 }
13}
14
15export fn entry() usize { return @sizeOf(@TypeOf(f)); }
16
17// switch expression - missing enumeration prong
18//
19// tmp.zig:8:5: error: enumeration value 'Number.Four' not handled in switch
test/compile_errors/stage1/obj/switch_expression-multiple_else_prongs.zig created+14
...@@ -0,0 +1,14 @@
1fn f(x: u32) void {
2 const value: bool = switch (x) {
3 1234 => false,
4 else => true,
5 else => true,
6 };
7}
8export fn entry() void {
9 f(1234);
10}
11
12// switch expression - multiple else prongs
13//
14// tmp.zig:5:9: error: multiple else prongs in switch expression
test/compile_errors/stage1/obj/switch_expression-non_exhaustive_integer_prongs.zig created+10
...@@ -0,0 +1,10 @@
1fn foo(x: u8) void {
2 switch (x) {
3 0 => {},
4 }
5}
6export fn entry() usize { return @sizeOf(@TypeOf(foo)); }
7
8// switch expression - non exhaustive integer prongs
9//
10// tmp.zig:2:5: error: switch must handle all possibilities
test/compile_errors/stage1/obj/switch_expression-switch_on_pointer_type_with_no_else.zig created+11
...@@ -0,0 +1,11 @@
1fn foo(x: *u8) void {
2 switch (x) {
3 &y => {},
4 }
5}
6const y: u8 = 100;
7export fn entry() usize { return @sizeOf(@TypeOf(foo)); }
8
9// switch expression - switch on pointer type with no else
10//
11// tmp.zig:2:5: error: else prong required when switching on type '*u8'
test/compile_errors/stage1/obj/switch_expression-unreachable_else_prong_bool.zig created+12
...@@ -0,0 +1,12 @@
1fn foo(x: bool) void {
2 switch (x) {
3 true => {},
4 false => {},
5 else => {},
6 }
7}
8export fn entry() usize { return @sizeOf(@TypeOf(foo)); }
9
10// switch expression - unreachable else prong (bool)
11//
12// tmp.zig:5:9: error: unreachable else prong, all cases already handled
test/compile_errors/stage1/obj/switch_expression-unreachable_else_prong_enum.zig created+22
...@@ -0,0 +1,22 @@
1const TestEnum = enum{ T1, T2 };
2
3fn err(x: u8) TestEnum {
4 switch (x) {
5 0 => return TestEnum.T1,
6 else => return TestEnum.T2,
7 }
8}
9
10fn foo(x: u8) void {
11 switch (err(x)) {
12 TestEnum.T1 => {},
13 TestEnum.T2 => {},
14 else => {},
15 }
16}
17
18export fn entry() usize { return @sizeOf(@TypeOf(foo)); }
19
20// switch expression - unreachable else prong (enum)
21//
22// tmp.zig:14:9: error: unreachable else prong, all cases already handled
test/compile_errors/stage1/obj/switch_expression-unreachable_else_prong_range_i8.zig created+15
...@@ -0,0 +1,15 @@
1fn foo(x: i8) void {
2 switch (x) {
3 -128...0 => {},
4 1 => {},
5 2 => {},
6 3 => {},
7 4...127 => {},
8 else => {},
9 }
10}
11export fn entry() usize { return @sizeOf(@TypeOf(foo)); }
12
13// switch expression - unreachable else prong (range i8)
14//
15// tmp.zig:8:9: error: unreachable else prong, all cases already handled
test/compile_errors/stage1/obj/switch_expression-unreachable_else_prong_range_u8.zig created+15
...@@ -0,0 +1,15 @@
1fn foo(x: u8) void {
2 switch (x) {
3 0 => {},
4 1 => {},
5 2 => {},
6 3 => {},
7 4...255 => {},
8 else => {},
9 }
10}
11export fn entry() usize { return @sizeOf(@TypeOf(foo)); }
12
13// switch expression - unreachable else prong (range u8)
14//
15// tmp.zig:8:9: error: unreachable else prong, all cases already handled
test/compile_errors/stage1/obj/switch_expression-unreachable_else_prong_u1.zig created+12
...@@ -0,0 +1,12 @@
1fn foo(x: u1) void {
2 switch (x) {
3 0 => {},
4 1 => {},
5 else => {},
6 }
7}
8export fn entry() usize { return @sizeOf(@TypeOf(foo)); }
9
10// switch expression - unreachable else prong (u1)
11//
12// tmp.zig:5:9: error: unreachable else prong, all cases already handled
test/compile_errors/stage1/obj/switch_expression-unreachable_else_prong_u2.zig created+14
...@@ -0,0 +1,14 @@
1fn foo(x: u2) void {
2 switch (x) {
3 0 => {},
4 1 => {},
5 2 => {},
6 3 => {},
7 else => {},
8 }
9}
10export fn entry() usize { return @sizeOf(@TypeOf(foo)); }
11
12// switch expression - unreachable else prong (u2)
13//
14// tmp.zig:7:9: error: unreachable else prong, all cases already handled
test/compile_errors/stage1/obj/switch_on_enum_with_1_field_with_no_prongs.zig created+10
...@@ -0,0 +1,10 @@
1const Foo = enum { M };
2
3export fn entry() void {
4 var f = Foo.M;
5 switch (f) {}
6}
7
8// switch on enum with 1 field with no prongs
9//
10// tmp.zig:5:5: error: enumeration value 'Foo.M' not handled in switch
test/compile_errors/stage1/obj/switch_on_union_with_no_attached_enum.zig created+20
...@@ -0,0 +1,20 @@
1const Payload = union {
2 A: i32,
3 B: f64,
4 C: bool,
5};
6export fn entry() void {
7 const a = Payload { .A = 1234 };
8 foo(a);
9}
10fn foo(a: *const Payload) void {
11 switch (a.*) {
12 Payload.A => {},
13 else => unreachable,
14 }
15}
16
17// switch on union with no attached enum
18//
19// tmp.zig:11:14: error: switch on union which has no attached enum
20// tmp.zig:1:17: note: consider 'union(enum)' here
test/compile_errors/stage1/obj/switch_with_invalid_expression_parameter.zig created+15
...@@ -0,0 +1,15 @@
1export fn entry() void {
2 Test(i32);
3}
4fn Test(comptime T: type) void {
5 const x = switch (T) {
6 []u8 => |x| x,
7 i32 => |x| x,
8 else => unreachable,
9 };
10 _ = x;
11}
12
13// switch with invalid expression parameter
14//
15// tmp.zig:7:17: error: switch on type 'type' provides no expression parameter
test/compile_errors/stage1/obj/switch_with_overlapping_case_ranges.zig created+11
...@@ -0,0 +1,11 @@
1export fn entry() void {
2 var q: u8 = 0;
3 switch (q) {
4 1...2 => {},
5 0...255 => {},
6 }
7}
8
9// switch with overlapping case ranges
10//
11// tmp.zig:5:9: error: duplicate switch value
test/compile_errors/stage1/obj/tagName_used_on_union_with_no_associated_enum_tag.zig created+14
...@@ -0,0 +1,14 @@
1const FloatInt = extern union {
2 Float: f32,
3 Int: i32,
4};
5export fn entry() void {
6 var fi = FloatInt{.Float = 123.45};
7 var tagName = @tagName(fi);
8 _ = tagName;
9}
10
11// @tagName used on union with no associated enum tag
12//
13// tmp.zig:7:19: error: union has no associated enum
14// tmp.zig:1:18: note: declared here
test/compile_errors/stage1/obj/take_slice_of_invalid_dereference.zig created+8
...@@ -0,0 +1,8 @@
1export fn entry() void {
2 const x = 'a'.*[0..];
3 _ = x;
4}
5
6// take slice of invalid dereference
7//
8// tmp.zig:2:18: error: attempt to dereference non-pointer type 'comptime_int'
test/compile_errors/stage1/obj/taking_bit_offset_of_void_field_in_struct.zig created+11
...@@ -0,0 +1,11 @@
1const Empty = struct {
2 val: void,
3};
4export fn foo() void {
5 const fieldOffset = @bitOffsetOf(Empty, "val",);
6 _ = fieldOffset;
7}
8
9// taking bit offset of void field in struct
10//
11// tmp.zig:5:45: error: zero-bit field 'val' in struct 'Empty' has no offset
test/compile_errors/stage1/obj/taking_byte_offset_of_void_field_in_struct.zig created+11
...@@ -0,0 +1,11 @@
1const Empty = struct {
2 val: void,
3};
4export fn foo() void {
5 const fieldOffset = @offsetOf(Empty, "val",);
6 _ = fieldOffset;
7}
8
9// taking byte offset of void field in struct
10//
11// tmp.zig:5:42: error: zero-bit field 'val' in struct 'Empty' has no offset
test/compile_errors/stage1/obj/threadlocal_qualifier_on_const.zig created+8
...@@ -0,0 +1,8 @@
1threadlocal const x: i32 = 1234;
2export fn entry() i32 {
3 return x;
4}
5
6// threadlocal qualifier on const
7//
8// tmp.zig:1:1: error: threadlocal variable cannot be constant
test/compile_errors/stage1/obj/top_level_decl_dependency_loop.zig created+10
...@@ -0,0 +1,10 @@
1const a : @TypeOf(b) = 0;
2const b : @TypeOf(a) = 0;
3export fn entry() void {
4 const c = a + b;
5 _ = c;
6}
7
8// top level decl dependency loop
9//
10// tmp.zig:2:19: error: dependency loop detected
test/compile_errors/stage1/obj/truncate_sign_mismatch.zig created+23
...@@ -0,0 +1,23 @@
1export fn entry1() i8 {
2 var x: u32 = 10;
3 return @truncate(i8, x);
4}
5export fn entry2() u8 {
6 var x: i32 = -10;
7 return @truncate(u8, x);
8}
9export fn entry3() i8 {
10 comptime var x: u32 = 10;
11 return @truncate(i8, x);
12}
13export fn entry4() u8 {
14 comptime var x: i32 = -10;
15 return @truncate(u8, x);
16}
17
18// truncate sign mismatch
19//
20// tmp.zig:3:26: error: expected signed integer type, found 'u32'
21// tmp.zig:7:26: error: expected unsigned integer type, found 'i32'
22// tmp.zig:11:26: error: expected signed integer type, found 'u32'
23// tmp.zig:15:26: error: expected unsigned integer type, found 'i32'
test/compile_errors/stage1/obj/truncate_undefined_value.zig created+8
...@@ -0,0 +1,8 @@
1export fn entry() void {
2 var z = @truncate(u8, @as(u16, undefined));
3 _ = z;
4}
5
6// @truncate undefined value
7//
8// tmp.zig:2:27: error: use of undefined value here causes undefined behavior
test/compile_errors/stage1/obj/try_in_function_with_non_error_return_type.zig created+8
...@@ -0,0 +1,8 @@
1export fn f() void {
2 try something();
3}
4fn something() anyerror!void { }
5
6// try in function with non error return type
7//
8// tmp.zig:2:5: error: expected type 'void', found 'anyerror'
test/compile_errors/stage1/obj/type_checking_function_pointers.zig created+11
...@@ -0,0 +1,11 @@
1fn a(b: fn (*const u8) void) void {
2 b('a');
3}
4fn c(d: u8) void {_ = d;}
5export fn entry() void {
6 a(c);
7}
8
9// type checking function pointers
10//
11// tmp.zig:6:7: error: expected type 'fn(*const u8) void', found 'fn(u8) void'
test/compile_errors/stage1/obj/type_variables_must_be_constant.zig created+8
...@@ -0,0 +1,8 @@
1var foo = u8;
2export fn entry() foo {
3 return 1;
4}
5
6// type variables must be constant
7//
8// tmp.zig:1:1: error: variable of type 'type' must be constant
test/compile_errors/stage1/obj/undeclared_identifier.zig created+9
...@@ -0,0 +1,9 @@
1export fn a() void {
2 return
3 b +
4 c;
5}
6
7// undeclared identifier
8//
9// tmp.zig:3:5: error: use of undeclared identifier 'b'
test/compile_errors/stage1/obj/undeclared_identifier_error_should_mark_fn_as_impure.zig created+10
...@@ -0,0 +1,10 @@
1export fn foo() void {
2 test_a_thing();
3}
4fn test_a_thing() void {
5 bad_fn_call();
6}
7
8// undeclared identifier error should mark fn as impure
9//
10// tmp.zig:5:5: error: use of undeclared identifier 'bad_fn_call'
test/compile_errors/stage1/obj/undeclared_identifier_in_unanalyzed_branch.zig created+9
...@@ -0,0 +1,9 @@
1export fn a() void {
2 if (false) {
3 lol_this_doesnt_exist = nonsense;
4 }
5}
6
7// undeclared identifier in unanalyzed branch
8//
9// tmp.zig:3:9: error: use of undeclared identifier 'lol_this_doesnt_exist'
test/compile_errors/stage1/obj/undefined_as_field_type_is_rejected.zig created+11
...@@ -0,0 +1,11 @@
1const Foo = struct {
2 a: undefined,
3};
4export fn entry1() void {
5 const foo: Foo = undefined;
6 _ = foo;
7}
8
9// undefined as field type is rejected
10//
11// tmp.zig:2:8: error: use of undefined value here causes undefined behavior
test/compile_errors/stage1/obj/undefined_function_call.zig created+7
...@@ -0,0 +1,7 @@
1export fn a() void {
2 b();
3}
4
5// undefined function call
6//
7// tmp.zig:2:5: error: use of undeclared identifier 'b'
test/compile_errors/stage1/obj/underscore_is_not_a_declarable_symbol.zig created+8
...@@ -0,0 +1,8 @@
1export fn f1() usize {
2 var _: usize = 2;
3 return _;
4}
5
6// `_` is not a declarable symbol
7//
8// tmp.zig:2:9: error: '_' used as an identifier without @"_" syntax
test/compile_errors/stage1/obj/underscore_should_not_be_usable_inside_for.zig created+11
...@@ -0,0 +1,11 @@
1export fn returns() void {
2 for ([_]void{}) |_, i| {
3 for ([_]void{}) |_, j| {
4 return _;
5 }
6 }
7}
8
9// `_` should not be usable inside for
10//
11// tmp.zig:4:20: error: '_' used as an identifier without @"_" syntax
test/compile_errors/stage1/obj/underscore_should_not_be_usable_inside_while.zig created+14
...@@ -0,0 +1,14 @@
1export fn returns() void {
2 while (optionalReturn()) |_| {
3 while (optionalReturn()) |_| {
4 return _;
5 }
6 }
7}
8fn optionalReturn() ?u32 {
9 return 1;
10}
11
12// `_` should not be usable inside while
13//
14// tmp.zig:4:20: error: '_' used as an identifier without @"_" syntax
test/compile_errors/stage1/obj/underscore_should_not_be_usable_inside_while_else.zig created+16
...@@ -0,0 +1,16 @@
1export fn returns() void {
2 while (optionalReturnError()) |_| {
3 while (optionalReturnError()) |_| {
4 return;
5 } else |_| {
6 if (_ == error.optionalReturnError) return;
7 }
8 }
9}
10fn optionalReturnError() !?u32 {
11 return error.optionalReturnError;
12}
13
14// `_` should not be usable inside while else
15//
16// tmp.zig:6:17: error: '_' used as an identifier without @"_" syntax
test/compile_errors/stage1/obj/union_auto-enum_value_already_taken.zig created+16
...@@ -0,0 +1,16 @@
1const MultipleChoice = union(enum(u32)) {
2 A = 20,
3 B = 40,
4 C = 60,
5 D = 1000,
6 E = 60,
7};
8export fn entry() void {
9 var x = MultipleChoice { .C = {} };
10 _ = x;
11}
12
13// union auto-enum value already taken
14//
15// tmp.zig:6:9: error: enum tag value 60 already taken
16// tmp.zig:4:9: note: other occurrence here
test/compile_errors/stage1/obj/union_enum_field_does_not_match_enum.zig created+20
...@@ -0,0 +1,20 @@
1const Letter = enum {
2 A,
3 B,
4 C,
5};
6const Payload = union(Letter) {
7 A: i32,
8 B: f64,
9 C: bool,
10 D: bool,
11};
12export fn entry() void {
13 var a = Payload {.A = 1234};
14 _ = a;
15}
16
17// union enum field does not match enum
18//
19// tmp.zig:10:5: error: enum field not found: 'D'
20// tmp.zig:1:16: note: enum declared here
test/compile_errors/stage1/obj/union_fields_with_value_assignments.zig created+12
...@@ -0,0 +1,12 @@
1const MultipleChoice = union {
2 A: i32 = 20,
3};
4export fn entry() void {
5 var x: MultipleChoice = undefined;
6 _ = x;
7}
8
9// union fields with value assignments
10//
11// tmp.zig:1:24: error: explicitly valued tagged union missing integer tag type
12// tmp.zig:2:14: note: tag value specified here
test/compile_errors/stage1/obj/union_with_0_fields.zig created+5
...@@ -0,0 +1,5 @@
1const Foo = union {};
2
3// union with 0 fields
4//
5// tmp.zig:1:13: error: union declarations must have at least one tag
test/compile_errors/stage1/obj/union_with_specified_enum_omits_field.zig created+17
...@@ -0,0 +1,17 @@
1const Letter = enum {
2 A,
3 B,
4 C,
5};
6const Payload = union(Letter) {
7 A: i32,
8 B: f64,
9};
10export fn entry() usize {
11 return @sizeOf(Payload);
12}
13
14// union with specified enum omits field
15//
16// tmp.zig:6:17: error: enum field missing: 'C'
17// tmp.zig:4:5: note: declared here
test/compile_errors/stage1/obj/union_with_too_small_explicit_signed_tag_type.zig created+14
...@@ -0,0 +1,14 @@
1const U = union(enum(i2)) {
2 A: u8,
3 B: u8,
4 C: u8,
5 D: u8,
6};
7export fn entry() void {
8 _ = U{ .D = 1 };
9}
10
11// union with too small explicit signed tag type
12//
13// tmp.zig:1:22: error: specified integer tag type cannot represent every field
14// tmp.zig:1:22: note: type i2 cannot fit values in range 0...3
test/compile_errors/stage1/obj/union_with_too_small_explicit_unsigned_tag_type.zig created+15
...@@ -0,0 +1,15 @@
1const U = union(enum(u2)) {
2 A: u8,
3 B: u8,
4 C: u8,
5 D: u8,
6 E: u8,
7};
8export fn entry() void {
9 _ = U{ .E = 1 };
10}
11
12// union with too small explicit unsigned tag type
13//
14// tmp.zig:1:22: error: specified integer tag type cannot represent every field
15// tmp.zig:1:22: note: type u2 cannot fit values in range 0...4
test/compile_errors/stage1/obj/unknown_length_pointer_to_opaque.zig created+5
...@@ -0,0 +1,5 @@
1export const T = [*]opaque {};
2
3// unknown length pointer to opaque
4//
5// tmp.zig:1:21: error: unknown-length pointer to opaque
test/compile_errors/stage1/obj/unreachable_code-double_break.zig created+10
...@@ -0,0 +1,10 @@
1export fn a() void {
2 const b = blk: {
3 break :blk break :blk @as(u32, 1);
4 };
5}
6
7// unreachable code - double break
8//
9// tmp.zig:3:9: error: unreachable code
10// tmp.zig:3:20: note: control flow is diverted here
test/compile_errors/stage1/obj/unreachable_code-nested_returns.zig created+8
...@@ -0,0 +1,8 @@
1export fn a() i32 {
2 return return 1;
3}
4
5// unreachable code - nested returns
6//
7// tmp.zig:2:5: error: unreachable code
8// tmp.zig:2:12: note: control flow is diverted here
test/compile_errors/stage1/obj/unreachable_code.zig created+11
...@@ -0,0 +1,11 @@
1export fn a() void {
2 return;
3 b();
4}
5
6fn b() void {}
7
8// unreachable code
9//
10// tmp.zig:3:6: error: unreachable code
11// tmp.zig:2:5: note: control flow is diverted here
test/compile_errors/stage1/obj/unreachable_executed_at_comptime.zig created+14
...@@ -0,0 +1,14 @@
1fn foo(comptime x: i32) i32 {
2 comptime {
3 if (x >= 0) return -x;
4 unreachable;
5 }
6}
7export fn entry() void {
8 _ = foo(-42);
9}
10
11// unreachable executed at comptime
12//
13// tmp.zig:4:9: error: reached unreachable code
14// tmp.zig:8:12: note: called from here
test/compile_errors/stage1/obj/unreachable_parameter.zig created+6
...@@ -0,0 +1,6 @@
1fn f(a: noreturn) void { _ = a; }
2export fn entry() void { f(); }
3
4// unreachable parameter
5//
6// tmp.zig:1:9: error: parameter of type 'noreturn' not allowed
test/compile_errors/stage1/obj/unreachable_variable.zig created+8
...@@ -0,0 +1,8 @@
1export fn f() void {
2 const a: noreturn = {};
3 _ = a;
4}
5
6// unreachable variable
7//
8// tmp.zig:2:25: error: expected type 'noreturn', found 'void'
test/compile_errors/stage1/obj/unreachable_with_return.zig created+6
...@@ -0,0 +1,6 @@
1fn a() noreturn {return;}
2export fn entry() void { a(); }
3
4// unreachable with return
5//
6// tmp.zig:1:18: error: expected type 'noreturn', found 'void'
test/compile_errors/stage1/obj/unsupported_modifier_at_start_of_asm_output_constraint.zig created+8
...@@ -0,0 +1,8 @@
1export fn foo() void {
2 var bar: u32 = 3;
3 asm volatile ("" : [baz]"+r"(bar) : : "");
4}
5
6// unsupported modifier at start of asm output constraint
7//
8// tmp.zig:3:5: error: invalid modifier starting output constraint for 'baz': '+', only '=' is supported. Compiler TODO: see https://github.com/ziglang/zig/issues/215
test/compile_errors/stage1/obj/use_anyopaque_as_return_type_of_fn_ptr.zig created+8
...@@ -0,0 +1,8 @@
1export fn entry() void {
2 const a: fn () anyopaque = undefined;
3 _ = a;
4}
5
6// use anyopaque as return type of fn ptr
7//
8// tmp.zig:2:20: error: return type cannot be opaque
test/compile_errors/stage1/obj/use_implicit_casts_to_assign_null_to_non-nullable_pointer.zig created+12
...@@ -0,0 +1,12 @@
1export fn entry() void {
2 var x: i32 = 1234;
3 var p: *i32 = &x;
4 var pp: *?*i32 = &p;
5 pp.* = null;
6 var y = p.*;
7 _ = y;
8}
9
10// use implicit casts to assign null to non-nullable pointer
11//
12// tmp.zig:4:23: error: expected type '*?*i32', found '**i32'
test/compile_errors/stage1/obj/use_invalid_number_literal_as_array_index.zig created+9
...@@ -0,0 +1,9 @@
1var v = 25;
2export fn entry() void {
3 var arr: [v]u8 = undefined;
4 _ = arr;
5}
6
7// use invalid number literal as array index
8//
9// tmp.zig:1:1: error: unable to infer variable type
test/compile_errors/stage1/obj/use_of_comptime-known_undefined_function_value.zig created+11
...@@ -0,0 +1,11 @@
1const Cmd = struct {
2 exec: fn () void,
3};
4export fn entry() void {
5 const command = Cmd{ .exec = undefined };
6 command.exec();
7}
8
9// use of comptime-known undefined function value
10//
11// tmp.zig:6:12: error: use of undefined value here causes undefined behavior
test/compile_errors/stage1/obj/use_of_undeclared_identifier.zig created+7
...@@ -0,0 +1,7 @@
1export fn f() void {
2 b = 3;
3}
4
5// use of undeclared identifier
6//
7// tmp.zig:2:5: error: use of undeclared identifier 'b'
test/compile_errors/stage1/obj/using_an_unknown_len_ptr_type_instead_of_array.zig created+11
...@@ -0,0 +1,11 @@
1const resolutions = [*][*]const u8{
2 "[320 240 ]",
3 null,
4};
5comptime {
6 _ = resolutions;
7}
8
9// using an unknown len ptr type instead of array
10//
11// tmp.zig:1:21: error: expected array type or [_], found '[*][*]const u8'
test/compile_errors/stage1/obj/using_invalid_types_in_function_call_raises_an_error.zig created+9
...@@ -0,0 +1,9 @@
1const MenuEffect = enum {};
2fn func(effect: MenuEffect) void { _ = effect; }
3export fn entry() void {
4 func(MenuEffect.ThisDoesNotExist);
5}
6
7// using invalid types in function call raises an error
8//
9// tmp.zig:1:20: error: enum declarations must have at least one tag
test/compile_errors/stage1/obj/usingnamespace_with_wrong_type.zig created+5
...@@ -0,0 +1,5 @@
1usingnamespace void;
2
3// usingnamespace with wrong type
4//
5// tmp.zig:1:1: error: expected struct, enum, or union; found 'void'
test/compile_errors/stage1/obj/variable_has_wrong_type.zig created+8
...@@ -0,0 +1,8 @@
1export fn f() i32 {
2 const a = "a";
3 return a;
4}
5
6// variable has wrong type
7//
8// tmp.zig:3:12: error: expected type 'i32', found '*const [1:0]u8'
test/compile_errors/stage1/obj/variable_initialization_compile_error_then_referenced.zig created+17
...@@ -0,0 +1,17 @@
1fn Undeclared() type {
2 return T;
3}
4fn Gen() type {
5 const X = Undeclared();
6 return struct {
7 x: X,
8 };
9}
10export fn entry() void {
11 const S = Gen();
12 _ = S;
13}
14
15// variable initialization compile error then referenced
16//
17// tmp.zig:2:12: error: use of undeclared identifier 'T'
test/compile_errors/stage1/obj/variable_with_type_noreturn.zig created+8
...@@ -0,0 +1,8 @@
1export fn entry9() void {
2 var z: noreturn = return;
3}
4
5// variable with type 'noreturn'
6//
7// tmp.zig:2:5: error: unreachable code
8// tmp.zig:2:23: note: control flow is diverted here
test/compile_errors/stage1/obj/vector_index_out_of_bounds.zig created+8
...@@ -0,0 +1,8 @@
1export fn entry() void {
2 const x = @import("std").meta.Vector(3, f32){ 25, 75, 5, 0 };
3 _ = x;
4}
5
6// vector index out of bounds
7//
8// tmp.zig:2:62: error: index 3 outside vector of size 3
test/compile_errors/stage1/obj/volatile_on_global_assembly.zig created+7
...@@ -0,0 +1,7 @@
1comptime {
2 asm volatile ("");
3}
4
5// volatile on global assembly
6//
7// tmp.zig:2:9: error: volatile is meaningless on global assembly
test/compile_errors/stage1/obj/wasmMemoryGrow_is_a_compile_error_in_non-Wasm_targets.zig created+8
...@@ -0,0 +1,8 @@
1export fn foo() void {
2 _ = @wasmMemoryGrow(0, 1);
3 return;
4}
5
6// wasmMemoryGrow is a compile error in non-Wasm targets
7//
8// tmp.zig:2:9: error: @wasmMemoryGrow is a wasm32 feature only
test/compile_errors/stage1/obj/wasmMemorySize_is_a_compile_error_in_non-Wasm_targets.zig created+8
...@@ -0,0 +1,8 @@
1export fn foo() void {
2 _ = @wasmMemorySize(0);
3 return;
4}
5
6// wasmMemorySize is a compile error in non-Wasm targets
7//
8// tmp.zig:2:9: error: @wasmMemorySize is a wasm32 feature only
test/compile_errors/stage1/obj/while_expected_bool_got_error_union.zig created+8
...@@ -0,0 +1,8 @@
1export fn foo() void {
2 while (bar()) {}
3}
4fn bar() anyerror!i32 { return 1; }
5
6// while expected bool, got error union
7//
8// tmp.zig:2:15: error: expected type 'bool', found 'anyerror!i32'
test/compile_errors/stage1/obj/while_expected_bool_got_optional.zig created+8
...@@ -0,0 +1,8 @@
1export fn foo() void {
2 while (bar()) {}
3}
4fn bar() ?i32 { return 1; }
5
6// while expected bool, got optional
7//
8// tmp.zig:2:15: error: expected type 'bool', found '?i32'
test/compile_errors/stage1/obj/while_expected_error_union_got_bool.zig created+8
...@@ -0,0 +1,8 @@
1export fn foo() void {
2 while (bar()) |x| {_ = x;} else |err| {_ = err;}
3}
4fn bar() bool { return true; }
5
6// while expected error union, got bool
7//
8// tmp.zig:2:15: error: expected error union type, found 'bool'
test/compile_errors/stage1/obj/while_expected_error_union_got_optional.zig created+8
...@@ -0,0 +1,8 @@
1export fn foo() void {
2 while (bar()) |x| {_ = x;} else |err| {_ = err;}
3}
4fn bar() ?i32 { return 1; }
5
6// while expected error union, got optional
7//
8// tmp.zig:2:15: error: expected error union type, found '?i32'
test/compile_errors/stage1/obj/while_expected_optional_got_bool.zig created+8
...@@ -0,0 +1,8 @@
1export fn foo() void {
2 while (bar()) |x| {_ = x;}
3}
4fn bar() bool { return true; }
5
6// while expected optional, got bool
7//
8// tmp.zig:2:15: error: expected optional type, found 'bool'
test/compile_errors/stage1/obj/while_expected_optional_got_error_union.zig created+8
...@@ -0,0 +1,8 @@
1export fn foo() void {
2 while (bar()) |x| {_ = x;}
3}
4fn bar() anyerror!i32 { return 1; }
5
6// while expected optional, got error union
7//
8// tmp.zig:2:15: error: expected optional type, found 'anyerror!i32'
test/compile_errors/stage1/obj/while_loop_body_expression_ignored.zig created+20
...@@ -0,0 +1,20 @@
1fn returns() usize {
2 return 2;
3}
4export fn f1() void {
5 while (true) returns();
6}
7export fn f2() void {
8 var x: ?i32 = null;
9 while (x) |_| returns();
10}
11export fn f3() void {
12 var x: anyerror!i32 = error.Bad;
13 while (x) |_| returns() else |_| unreachable;
14}
15
16// while loop body expression ignored
17//
18// tmp.zig:5:25: error: expression value is ignored
19// tmp.zig:9:26: error: expression value is ignored
20// tmp.zig:13:26: error: expression value is ignored
test/compile_errors/stage1/obj/write_to_const_global_variable.zig created+9
...@@ -0,0 +1,9 @@
1const x : i32 = 99;
2fn f() void {
3 x = 1;
4}
5export fn entry() void { f(); }
6
7// write to const global variable
8//
9// tmp.zig:3:9: error: cannot assign to constant
test/compile_errors/stage1/obj/wrong_frame_type_used_for_async_call.zig created+14
...@@ -0,0 +1,14 @@
1export fn entry() void {
2 var frame: @Frame(foo) = undefined;
3 frame = async bar();
4}
5fn foo() void {
6 suspend {}
7}
8fn bar() void {
9 suspend {}
10}
11
12// wrong frame type used for async call
13//
14// tmp.zig:3:13: error: expected type '*@Frame(bar)', found '*@Frame(foo)'
test/compile_errors/stage1/obj/wrong_function_type.zig created+9
...@@ -0,0 +1,9 @@
1const fns = [_]fn() void { a, b, c };
2fn a() i32 {return 0;}
3fn b() i32 {return 1;}
4fn c() i32 {return 2;}
5export fn entry() usize { return @sizeOf(@TypeOf(fns)); }
6
7// wrong function type
8//
9// tmp.zig:1:28: error: expected type 'fn() void', found 'fn() i32'
test/compile_errors/stage1/obj/wrong_initializer_for_union_payload_of_type_type.zig created+14
...@@ -0,0 +1,14 @@
1const U = union(enum) {
2 A: type,
3};
4const S = struct {
5 u: U,
6};
7export fn entry() void {
8 comptime var v: S = undefined;
9 v.u.A = U{ .A = i32 };
10}
11
12// wrong initializer for union payload of type 'type'
13//
14// tmp.zig:9:8: error: use of undefined value here causes undefined behavior
test/compile_errors/stage1/obj/wrong_number_of_arguments.zig created+8
...@@ -0,0 +1,8 @@
1export fn a() void {
2 c(1);
3}
4fn c(d: i32, e: i32, f: i32) void { _ = d; _ = e; _ = f; }
5
6// wrong number of arguments
7//
8// tmp.zig:2:6: error: expected 3 argument(s), found 1
test/compile_errors/stage1/obj/wrong_number_of_arguments_for_method_fn_call.zig created+12
...@@ -0,0 +1,12 @@
1const Foo = struct {
2 fn method(self: *const Foo, a: i32) void {_ = self; _ = a;}
3};
4fn f(foo: *const Foo) void {
5
6 foo.method(1, 2);
7}
8export fn entry() usize { return @sizeOf(@TypeOf(f)); }
9
10// wrong number of arguments for method fn call
11//
12// tmp.zig:6:15: error: expected 2 argument(s), found 3
test/compile_errors/stage1/obj/wrong_panic_signature_generic_function.zig created+10
...@@ -0,0 +1,10 @@
1pub fn panic(comptime msg: []const u8, error_return_trace: ?*builtin.StackTrace) noreturn {
2 _ = msg; _ = error_return_trace;
3 while (true) {}
4}
5const builtin = @import("std").builtin;
6
7// wrong panic signature, generic function
8//
9// error: expected type 'fn([]const u8, ?*std.builtin.StackTrace) noreturn', found 'fn([]const u8,anytype) anytype'
10// note: only one of the functions is generic
test/compile_errors/stage1/obj/wrong_panic_signature_runtime_function.zig created+8
...@@ -0,0 +1,8 @@
1test "" {}
2
3pub fn panic() void {}
4
5
6// wrong panic signature, runtime function
7//
8// error: expected type 'fn([]const u8, ?*std.builtin.StackTrace) noreturn', found 'fn() void'
test/compile_errors/stage1/obj/wrong_pointer_coerced_to_pointer_to_opaque_{}.zig created+10
...@@ -0,0 +1,10 @@
1const Derp = opaque {};
2extern fn bar(d: *Derp) void;
3export fn foo() void {
4 var x = @as(u8, 1);
5 bar(@ptrCast(*anyopaque, &x));
6}
7
8// wrong pointer coerced to pointer to opaque {}
9//
10// tmp.zig:5:9: error: expected type '*Derp', found '*anyopaque'
test/compile_errors/stage1/obj/wrong_return_type_for_main.zig created+5
...@@ -0,0 +1,5 @@
1pub fn main() f32 { }
2
3// wrong return type for main
4//
5// error: expected return type of main to be 'void', '!void', 'noreturn', 'u8', or '!u8'
test/compile_errors/stage1/obj/wrong_size_to_an_array_literal.zig created+8
...@@ -0,0 +1,8 @@
1comptime {
2 const array = [2]u8{1, 2, 3};
3 _ = array;
4}
5
6// wrong size to an array literal
7//
8// tmp.zig:2:31: error: index 2 outside array of size 2
test/compile_errors/stage1/obj/wrong_type_for_argument_tuple_to_asyncCall.zig created+12
...@@ -0,0 +1,12 @@
1export fn entry1() void {
2 var frame: @Frame(foo) = undefined;
3 @asyncCall(&frame, {}, foo, {});
4}
5
6fn foo() i32 {
7 return 0;
8}
9
10// wrong type for argument tuple to @asyncCall
11//
12// tmp.zig:3:33: error: expected tuple or struct, found 'void'
test/compile_errors/stage1/obj/wrong_type_for_reify_type.zig created+7
...@@ -0,0 +1,7 @@
1export fn entry() void {
2 _ = @Type(0);
3}
4
5// wrong type for @Type
6//
7// tmp.zig:2:15: error: expected type 'std.builtin.Type', found 'comptime_int'
test/compile_errors/stage1/obj/wrong_type_for_result_ptr_to_asyncCall.zig created+14
...@@ -0,0 +1,14 @@
1export fn entry() void {
2 _ = async amain();
3}
4fn amain() i32 {
5 var frame: @Frame(foo) = undefined;
6 return await @asyncCall(&frame, false, foo, .{});
7}
8fn foo() i32 {
9 return 1234;
10}
11
12// wrong type for result ptr to @asyncCall
13//
14// tmp.zig:6:37: error: expected type '*i32', found 'bool'
test/compile_errors/stage1/obj/wrong_type_passed_to_panic.zig created+8
...@@ -0,0 +1,8 @@
1export fn entry() void {
2 var e = error.Foo;
3 @panic(e);
4}
5
6// wrong type passed to @panic
7//
8// tmp.zig:3:12: error: expected type '[]const u8', found 'error{Foo}'
test/compile_errors/stage1/obj/wrong_type_to_hasField.zig created+7
...@@ -0,0 +1,7 @@
1export fn entry() bool {
2 return @hasField(i32, "hi");
3}
4
5// wrong type to @hasField
6//
7// tmp.zig:2:22: error: type 'i32' does not support @hasField
test/compile_errors/stage1/obj/wrong_types_given_to_atomic_order_args_in_cmpxchg.zig created+8
...@@ -0,0 +1,8 @@
1export fn entry() void {
2 var x: i32 = 1234;
3 while (!@cmpxchgWeak(i32, &x, 1234, 5678, @as(u32, 1234), @as(u32, 1234))) {}
4}
5
6// wrong types given to atomic order args in cmpxchg
7//
8// tmp.zig:3:47: error: expected type 'std.builtin.AtomicOrder', found 'u32'
test/compile_errors/stage1/obj/wrong_types_given_to_export.zig created+8
...@@ -0,0 +1,8 @@
1fn entry() callconv(.C) void { }
2comptime {
3 @export(entry, .{.name = "entry", .linkage = @as(u32, 1234) });
4}
5
6// wrong types given to @export
7//
8// tmp.zig:3:59: error: expected type 'std.builtin.GlobalLinkage', found 'comptime_int'
test/compile_errors/stage1/test/access_invalid_typeInfo_decl.zig created+8
...@@ -0,0 +1,8 @@
1const A = B;
2test "Crash" {
3 _ = @typeInfo(@This()).Struct.decls[0];
4}
5
6// access invalid @typeInfo decl
7//
8// tmp.zig:1:11: error: use of undeclared identifier 'B'
test/compile_errors/stage1/test/alignCast_of_zero_sized_types.zig created+25
...@@ -0,0 +1,25 @@
1export fn foo() void {
2 const a: *void = undefined;
3 _ = @alignCast(2, a);
4}
5export fn bar() void {
6 const a: ?*void = undefined;
7 _ = @alignCast(2, a);
8}
9export fn baz() void {
10 const a: []void = undefined;
11 _ = @alignCast(2, a);
12}
13export fn qux() void {
14 const a = struct {
15 fn a(comptime b: u32) void { _ = b; }
16 }.a;
17 _ = @alignCast(2, a);
18}
19
20// @alignCast of zero sized types
21//
22// tmp.zig:3:23: error: cannot adjust alignment of zero sized type '*void'
23// tmp.zig:7:23: error: cannot adjust alignment of zero sized type '?*void'
24// tmp.zig:11:23: error: cannot adjust alignment of zero sized type '[]void'
25// tmp.zig:17:23: error: cannot adjust alignment of zero sized type 'fn(u32) anytype'
test/compile_errors/stage1/test/bad_splat_type.zig created+9
...@@ -0,0 +1,9 @@
1export fn entry() void {
2 const c = 4;
3 var v = @splat(4, c);
4 _ = v;
5}
6
7// bad @splat type
8//
9// tmp.zig:3:23: error: vector element type must be integer, float, bool, or pointer; 'comptime_int' is invalid
test/compile_errors/stage1/test/binary_OR_operator_on_error_sets.zig created+10
...@@ -0,0 +1,10 @@
1pub const A = error.A;
2pub const AB = A | error.B;
3export fn entry() void {
4 var x: AB = undefined;
5 _ = x;
6}
7
8// binary OR operator on error sets
9//
10// tmp.zig:2:18: error: invalid operands to binary expression: 'error{A}' and 'error{B}'
test/compile_errors/stage1/test/call_rejects_non_comptime-known_fn-always_inline.zig created+8
...@@ -0,0 +1,8 @@
1pub export fn entry() void {
2 var call_me: fn () void = undefined;
3 @call(.{ .modifier = .always_inline }, call_me, .{});
4}
5
6// @call rejects non comptime-known fn - always_inline
7//
8// tmp.zig:3:5: error: the specified modifier requires a comptime-known function
test/compile_errors/stage1/test/call_rejects_non_comptime-known_fn-compile_time.zig created+8
...@@ -0,0 +1,8 @@
1pub export fn entry() void {
2 var call_me: fn () void = undefined;
3 @call(.{ .modifier = .compile_time }, call_me, .{});
4}
5
6// @call rejects non comptime-known fn - compile_time
7//
8// tmp.zig:3:5: error: the specified modifier requires a comptime-known function
test/compile_errors/stage1/test/cast_between_optional_T_where_T_is_not_a_pointer.zig created+12
...@@ -0,0 +1,12 @@
1pub const fnty1 = ?fn (i8) void;
2pub const fnty2 = ?fn (u64) void;
3export fn entry() void {
4 var a: fnty1 = undefined;
5 var b: fnty2 = undefined;
6 a = b;
7}
8
9// cast between ?T where T is not a pointer
10//
11// tmp.zig:6:9: error: expected type '?fn(i8) void', found '?fn(u64) void'
12// tmp.zig:6:9: note: optional type child 'fn(u64) void' cannot cast into optional type child 'fn(i8) void'
test/compile_errors/stage1/test/combination_of_nosuspend_and_async.zig created+13
...@@ -0,0 +1,13 @@
1export fn entry() void {
2 nosuspend {
3 const bar = async foo();
4 suspend {}
5 resume bar;
6 }
7}
8fn foo() void {}
9
10// combination of nosuspend and async
11//
12// tmp.zig:4:9: error: suspend inside nosuspend block
13// tmp.zig:2:5: note: nosuspend block here
test/compile_errors/stage1/test/comparison_of_non-tagged_union_and_enum_literal.zig created+11
...@@ -0,0 +1,11 @@
1export fn entry() void {
2 const U = union { A: u32, B: u64 };
3 var u = U{ .A = 42 };
4 var ok = u == .A;
5 _ = ok;
6}
7
8// comparison of non-tagged union and enum literal
9//
10// tmp.zig:4:16: error: comparison of union and enum literal is only valid for tagged union types
11// tmp.zig:2:15: note: type U is not a tagged union
test/compile_errors/stage1/test/comptime_vector_overflow_shows_the_index.zig created+11
...@@ -0,0 +1,11 @@
1comptime {
2 var a: @import("std").meta.Vector(4, u8) = [_]u8{ 1, 2, 255, 4 };
3 var b: @import("std").meta.Vector(4, u8) = [_]u8{ 5, 6, 1, 8 };
4 var x = a + b;
5 _ = x;
6}
7
8// comptime vector overflow shows the index
9//
10// tmp.zig:4:15: error: operation caused overflow
11// tmp.zig:4:15: note: when computing vector element at index 2
test/compile_errors/stage1/test/duplicate-unused_labels.zig created+30
...@@ -0,0 +1,30 @@
1comptime {
2 blk: { blk: while (false) {} }
3}
4comptime {
5 blk: while (false) { blk: for (@as([0]void, undefined)) |_| {} }
6}
7comptime {
8 blk: for (@as([0]void, undefined)) |_| { blk: {} }
9}
10comptime {
11 blk: {}
12}
13comptime {
14 blk: while(false) {}
15}
16comptime {
17 blk: for(@as([0]void, undefined)) |_| {}
18}
19
20// duplicate/unused labels
21//
22// tmp.zig:2:12: error: redefinition of label 'blk'
23// tmp.zig:2:5: note: previous definition here
24// tmp.zig:5:26: error: redefinition of label 'blk'
25// tmp.zig:5:5: note: previous definition here
26// tmp.zig:8:46: error: redefinition of label 'blk'
27// tmp.zig:8:5: note: previous definition here
28// tmp.zig:11:5: error: unused block label
29// tmp.zig:14:5: error: unused while loop label
30// tmp.zig:17:5: error: unused for loop label
test/compile_errors/stage1/test/duplicate_field_in_anonymous_struct_literal.zig created+16
...@@ -0,0 +1,16 @@
1export fn entry() void {
2 const anon = .{
3 .inner = .{
4 .a = .{
5 .something = "text",
6 },
7 .a = .{},
8 },
9 };
10 _ = anon;
11}
12
13// duplicate field in anonymous struct literal
14//
15// tmp.zig:7:13: error: duplicate field
16// tmp.zig:4:13: note: other field here
test/compile_errors/stage1/test/error_in_struct_initializer_doesnt_crash_the_compiler.zig created+12
...@@ -0,0 +1,12 @@
1pub export fn entry() void {
2 const bitfield = struct {
3 e: u8,
4 e: u8,
5 };
6 var a = .{@sizeOf(bitfield)};
7 _ = a;
8}
9
10// error in struct initializer doesn't crash the compiler
11//
12// tmp.zig:4:9: error: duplicate struct field: 'e'
test/compile_errors/stage1/test/errors_in_for_loop_bodies_are_propagated.zig created+8
...@@ -0,0 +1,8 @@
1pub export fn entry() void {
2 var arr: [100]u8 = undefined;
3 for (arr) |bits| _ = @popCount(bits);
4}
5
6// errors in for loop bodies are propagated
7//
8// tmp.zig:3:26: error: expected 2 arguments, found 1
test/compile_errors/stage1/test/export_with_empty_name_string.zig created+8
...@@ -0,0 +1,8 @@
1pub export fn entry() void { }
2comptime {
3 @export(entry, .{ .name = "" });
4}
5
6// @export with empty name string
7//
8// tmp.zig:3:5: error: exported symbol name cannot be empty
test/compile_errors/stage1/test/helpful_return_type_error_message.zig created+27
...@@ -0,0 +1,27 @@
1export fn foo() u32 {
2 return error.Ohno;
3}
4fn bar() !u32 {
5 return error.Ohno;
6}
7export fn baz() void {
8 try bar();
9}
10export fn qux() u32 {
11 return bar();
12}
13export fn quux() u32 {
14 var buf: u32 = 0;
15 buf = bar();
16}
17
18// helpful return type error message
19//
20// tmp.zig:2:17: error: expected type 'u32', found 'error{Ohno}'
21// tmp.zig:1:17: note: function cannot return an error
22// tmp.zig:8:5: error: expected type 'void', found '@typeInfo(@typeInfo(@TypeOf(bar)).Fn.return_type.?).ErrorUnion.error_set'
23// tmp.zig:7:17: note: function cannot return an error
24// tmp.zig:11:15: error: cannot convert error union to payload type. consider using `try`, `catch`, or `if`. expected type 'u32', found '@typeInfo(@typeInfo(@TypeOf(bar)).Fn.return_type.?).ErrorUnion.error_set!u32'
25// tmp.zig:10:17: note: function cannot return an error
26// tmp.zig:15:14: error: cannot convert error union to payload type. consider using `try`, `catch`, or `if`. expected type 'u32', found '@typeInfo(@typeInfo(@TypeOf(bar)).Fn.return_type.?).ErrorUnion.error_set!u32'
27// tmp.zig:14:5: note: cannot store an error in type 'u32'
test/compile_errors/stage1/test/int-float_conversion_to_comptime_int-float.zig created+13
...@@ -0,0 +1,13 @@
1export fn foo() void {
2 var a: f32 = 2;
3 _ = @floatToInt(comptime_int, a);
4}
5export fn bar() void {
6 var a: u32 = 2;
7 _ = @intToFloat(comptime_float, a);
8}
9
10// int/float conversion to comptime_int/float
11//
12// tmp.zig:3:35: error: unable to evaluate constant expression
13// tmp.zig:7:37: error: unable to evaluate constant expression
test/compile_errors/stage1/test/invalid_assignments.zig created+17
...@@ -0,0 +1,17 @@
1export fn entry1() void {
2 var a: []const u8 = "foo";
3 a[0..2] = "bar";
4}
5export fn entry2() void {
6 var a: u8 = 2;
7 a + 2 = 3;
8}
9export fn entry4() void {
10 2 + 2 = 3;
11}
12
13// invalid assignments
14//
15// tmp.zig:3:6: error: invalid left-hand side to assignment
16// tmp.zig:7:7: error: invalid left-hand side to assignment
17// tmp.zig:10:7: error: invalid left-hand side to assignment
test/compile_errors/stage1/test/invalid_float_casts.zig created+23
...@@ -0,0 +1,23 @@
1export fn foo() void {
2 var a: f32 = 2;
3 _ = @floatCast(comptime_float, a);
4}
5export fn bar() void {
6 var a: f32 = 2;
7 _ = @floatToInt(f32, a);
8}
9export fn baz() void {
10 var a: f32 = 2;
11 _ = @intToFloat(f32, a);
12}
13export fn qux() void {
14 var a: u32 = 2;
15 _ = @floatCast(f32, a);
16}
17
18// invalid float casts
19//
20// tmp.zig:3:36: error: unable to evaluate constant expression
21// tmp.zig:7:21: error: expected integer type, found 'f32'
22// tmp.zig:11:26: error: expected int type, found 'f32'
23// tmp.zig:15:25: error: expected float type, found 'u32'
test/compile_errors/stage1/test/invalid_int_casts.zig created+23
...@@ -0,0 +1,23 @@
1export fn foo() void {
2 var a: u32 = 2;
3 _ = @intCast(comptime_int, a);
4}
5export fn bar() void {
6 var a: u32 = 2;
7 _ = @intToFloat(u32, a);
8}
9export fn baz() void {
10 var a: u32 = 2;
11 _ = @floatToInt(u32, a);
12}
13export fn qux() void {
14 var a: f32 = 2;
15 _ = @intCast(u32, a);
16}
17
18// invalid int casts
19//
20// tmp.zig:3:32: error: unable to evaluate constant expression
21// tmp.zig:7:21: error: expected float type, found 'u32'
22// tmp.zig:11:26: error: expected float type, found 'u32'
23// tmp.zig:15:23: error: expected integer type, found 'f32'
test/compile_errors/stage1/test/invalid_non-exhaustive_enum_to_union.zig created+24
...@@ -0,0 +1,24 @@
1const E = enum(u8) {
2 a,
3 b,
4 _,
5};
6const U = union(E) {
7 a,
8 b,
9};
10export fn foo() void {
11 var e = @intToEnum(E, 15);
12 var u: U = e;
13 _ = u;
14}
15export fn bar() void {
16 const e = @intToEnum(E, 15);
17 var u: U = e;
18 _ = u;
19}
20
21// invalid non-exhaustive enum to union
22//
23// tmp.zig:12:16: error: runtime cast to union 'U' from non-exhaustive enum
24// tmp.zig:17:16: error: no tag by value 15
test/compile_errors/stage1/test/invalid_pointer_with_reify_type.zig created+16
...@@ -0,0 +1,16 @@
1export fn entry() void {
2 _ = @Type(.{ .Pointer = .{
3 .size = .One,
4 .is_const = false,
5 .is_volatile = false,
6 .alignment = 1,
7 .address_space = .generic,
8 .child = u8,
9 .is_allowzero = false,
10 .sentinel = &@as(u8, 0),
11 }});
12}
13
14// invalid pointer with @Type
15//
16// tmp.zig:2:16: error: sentinels are only allowed on slices and unknown-length pointers
test/compile_errors/stage1/test/nested_vectors.zig created+10
...@@ -0,0 +1,10 @@
1export fn entry() void {
2 const V1 = @import("std").meta.Vector(4, u8);
3 const V2 = @Type(.{ .Vector = .{ .len = 4, .child = V1 } });
4 var v: V2 = undefined;
5 _ = v;
6}
7
8// nested vectors
9//
10// tmp.zig:3:23: error: vector element type must be integer, float, bool, or pointer; '@Vector(4, u8)' is invalid
test/compile_errors/stage1/test/non-exhaustive_enum_marker_assigned_a_value.zig created+17
...@@ -0,0 +1,17 @@
1const A = enum {
2 a,
3 b,
4 _ = 1,
5};
6const B = enum {
7 a,
8 b,
9 _,
10};
11comptime { _ = A; _ = B; }
12
13// non-exhaustive enum marker assigned a value
14//
15// tmp.zig:4:9: error: '_' is used to mark an enum as non-exhaustive and cannot be assigned a value
16// tmp.zig:6:11: error: non-exhaustive enum missing integer tag type
17// tmp.zig:9:5: note: marked non-exhaustive here
test/compile_errors/stage1/test/non-exhaustive_enums.zig created+19
...@@ -0,0 +1,19 @@
1const B = enum(u1) {
2 a,
3 _,
4 b,
5};
6const C = enum(u1) {
7 a,
8 b,
9 _,
10};
11pub export fn entry() void {
12 _ = B;
13 _ = C;
14}
15
16// non-exhaustive enums
17//
18// tmp.zig:3:5: error: '_' field of non-exhaustive enum must be last
19// tmp.zig:6:11: error: non-exhaustive enum specifies every value
test/compile_errors/stage1/test/not_an_enum_type.zig created+17
...@@ -0,0 +1,17 @@
1export fn entry() void {
2 var self: Error = undefined;
3 switch (self) {
4 InvalidToken => |x| return x.token,
5 ExpectedVarDeclOrFn => |x| return x.token,
6 }
7}
8const Error = union(enum) {
9 A: InvalidToken,
10 B: ExpectedVarDeclOrFn,
11};
12const InvalidToken = struct {};
13const ExpectedVarDeclOrFn = struct {};
14
15// not an enum type
16//
17// tmp.zig:4:9: error: expected type '@typeInfo(Error).Union.tag_type.?', found 'type'
test/compile_errors/stage1/test/packed_struct_with_fields_of_not_allowed_types.zig created+71
...@@ -0,0 +1,71 @@
1const A = packed struct {
2 x: anyerror,
3};
4const B = packed struct {
5 x: [2]u24,
6};
7const C = packed struct {
8 x: [1]anyerror,
9};
10const D = packed struct {
11 x: [1]S,
12};
13const E = packed struct {
14 x: [1]U,
15};
16const F = packed struct {
17 x: ?anyerror,
18};
19const G = packed struct {
20 x: Enum,
21};
22export fn entry1() void {
23 var a: A = undefined;
24 _ = a;
25}
26export fn entry2() void {
27 var b: B = undefined;
28 _ = b;
29}
30export fn entry3() void {
31 var r: C = undefined;
32 _ = r;
33}
34export fn entry4() void {
35 var d: D = undefined;
36 _ = d;
37}
38export fn entry5() void {
39 var e: E = undefined;
40 _ = e;
41}
42export fn entry6() void {
43 var f: F = undefined;
44 _ = f;
45}
46export fn entry7() void {
47 var g: G = undefined;
48 _ = g;
49}
50const S = struct {
51 x: i32,
52};
53const U = struct {
54 A: i32,
55 B: u32,
56};
57const Enum = enum {
58 A,
59 B,
60};
61
62// packed struct with fields of not allowed types
63//
64// tmp.zig:2:5: error: type 'anyerror' not allowed in packed struct; no guaranteed in-memory representation
65// tmp.zig:5:5: error: array of 'u24' not allowed in packed struct due to padding bits (must be padded from 48 to 64 bits)
66// tmp.zig:8:5: error: type 'anyerror' not allowed in packed struct; no guaranteed in-memory representation
67// tmp.zig:11:5: error: non-packed, non-extern struct 'S' not allowed in packed struct; no guaranteed in-memory representation
68// tmp.zig:14:5: error: non-packed, non-extern struct 'U' not allowed in packed struct; no guaranteed in-memory representation
69// tmp.zig:17:5: error: type '?anyerror' not allowed in packed struct; no guaranteed in-memory representation
70// tmp.zig:20:5: error: type 'Enum' not allowed in packed struct; no guaranteed in-memory representation
71// tmp.zig:57:14: note: enum declaration does not specify an integer tag type
test/compile_errors/stage1/test/ptrToInt_with_pointer_to_zero-sized_type.zig created+9
...@@ -0,0 +1,9 @@
1export fn entry() void {
2 var pointer: ?*u0 = null;
3 var x = @ptrToInt(pointer);
4 _ = x;
5}
6
7// @ptrToInt with pointer to zero-sized type
8//
9// tmp.zig:3:23: error: pointer to size 0 type has no address
test/compile_errors/stage1/test/reassign_to_array_parameter.zig created+10
...@@ -0,0 +1,10 @@
1fn reassign(a: [3]f32) void {
2 a = [3]f32{4, 5, 6};
3}
4export fn entry() void {
5 reassign(.{1, 2, 3});
6}
7
8// reassign to array parameter
9//
10// tmp.zig:2:15: error: cannot assign to constant
test/compile_errors/stage1/test/reassign_to_slice_parameter.zig created+10
...@@ -0,0 +1,10 @@
1pub fn reassign(s: []const u8) void {
2 s = s[0..];
3}
4export fn entry() void {
5 reassign("foo");
6}
7
8// reassign to slice parameter
9//
10// tmp.zig:2:10: error: cannot assign to constant
test/compile_errors/stage1/test/reassign_to_struct_parameter.zig created+13
...@@ -0,0 +1,13 @@
1const S = struct {
2 x: u32,
3};
4fn reassign(s: S) void {
5 s = S{.x = 2};
6}
7export fn entry() void {
8 reassign(S{.x = 3});
9}
10
11// reassign to struct parameter
12//
13// tmp.zig:5:10: error: cannot assign to constant
test/compile_errors/stage1/test/reference_to_const_data.zig created+27
...@@ -0,0 +1,27 @@
1export fn foo() void {
2 var ptr = &[_]u8{0,0,0,0};
3 ptr[1] = 2;
4}
5export fn bar() void {
6 var ptr = &@as(u32, 2);
7 ptr.* = 2;
8}
9export fn baz() void {
10 var ptr = &true;
11 ptr.* = false;
12}
13export fn qux() void {
14 const S = struct{
15 x: usize,
16 y: usize,
17 };
18 var ptr = &S{.x=1,.y=2};
19 ptr.x = 2;
20}
21
22// reference to const data
23//
24// tmp.zig:3:14: error: cannot assign to constant
25// tmp.zig:7:13: error: cannot assign to constant
26// tmp.zig:11:13: error: cannot assign to constant
27// tmp.zig:19:13: error: cannot assign to constant
test/compile_errors/stage1/test/reify_typeOf_with_incompatible_arguments.zig created+9
...@@ -0,0 +1,9 @@
1export fn entry() void {
2 var var_1: f32 = undefined;
3 var var_2: u32 = undefined;
4 _ = @TypeOf(var_1, var_2);
5}
6
7// @TypeOf with incompatible arguments
8//
9// tmp.zig:4:9: error: incompatible types: 'f32' and 'u32'
test/compile_errors/stage1/test/reify_typeOf_with_no_arguments.zig created+7
...@@ -0,0 +1,7 @@
1export fn entry() void {
2 _ = @TypeOf();
3}
4
5// @TypeOf with no arguments
6//
7// tmp.zig:2:9: error: expected at least 1 argument, found 0
test/compile_errors/stage1/test/reject_extern_function_definitions_with_body.zig created+7
...@@ -0,0 +1,7 @@
1extern "c" fn definitelyNotInLibC(a: i32, b: i32) i32 {
2 return a + b;
3}
4
5// reject extern function definitions with body
6//
7// tmp.zig:1:1: error: extern functions have no body
test/compile_errors/stage1/test/reject_extern_variables_with_initializers.zig created+5
...@@ -0,0 +1,5 @@
1extern var foo: int = 2;
2
3// reject extern variables with initializers
4//
5// tmp.zig:1:23: error: extern variables have no initializers
test/compile_errors/stage1/test/repeated_invalid_field_access_to_generic_function_returning_type_crashes_compiler_2655.zig created+11
...@@ -0,0 +1,11 @@
1pub fn A() type {
2 return Q;
3}
4test "1" {
5 _ = A().a;
6 _ = A().a;
7}
8
9// repeated invalid field access to generic function returning type crashes compiler. #2655
10//
11// tmp.zig:2:12: error: use of undeclared identifier 'Q'
test/compile_errors/stage1/test/return_invalid_type_from_test.zig created+5
...@@ -0,0 +1,5 @@
1test "example" { return 1; }
2
3// return invalid type from test
4//
5// tmp.zig:1:25: error: expected type 'void', found 'comptime_int'
test/compile_errors/stage1/test/shift_on_type_with_non-power-of-two_size.zig created+31
...@@ -0,0 +1,31 @@
1export fn entry() void {
2 const S = struct {
3 fn a() void {
4 var x: u24 = 42;
5 _ = x >> 24;
6 }
7 fn b() void {
8 var x: u24 = 42;
9 _ = x << 24;
10 }
11 fn c() void {
12 var x: u24 = 42;
13 _ = @shlExact(x, 24);
14 }
15 fn d() void {
16 var x: u24 = 42;
17 _ = @shrExact(x, 24);
18 }
19 };
20 S.a();
21 S.b();
22 S.c();
23 S.d();
24}
25
26// shift on type with non-power-of-two size
27//
28// tmp.zig:5:19: error: RHS of shift is too large for LHS type
29// tmp.zig:9:19: error: RHS of shift is too large for LHS type
30// tmp.zig:13:17: error: RHS of shift is too large for LHS type
31// tmp.zig:17:17: error: RHS of shift is too large for LHS type
test/compile_errors/stage1/test/shuffle_with_selected_index_past_first_vector_length.zig created+12
...@@ -0,0 +1,12 @@
1export fn entry() void {
2 const v: @import("std").meta.Vector(4, u32) = [4]u32{ 10, 11, 12, 13 };
3 const x: @import("std").meta.Vector(4, u32) = [4]u32{ 14, 15, 16, 17 };
4 var z = @shuffle(u32, v, x, [8]i32{ 0, 1, 2, 3, 7, 6, 5, 4 });
5 _ = z;
6}
7
8// @shuffle with selected index past first vector length
9//
10// tmp.zig:4:39: error: mask index '4' has out-of-bounds selection
11// tmp.zig:4:27: note: selected index '7' out of bounds of @Vector(4, u32)
12// tmp.zig:4:30: note: selections from the second vector are specified with negative numbers
test/compile_errors/stage1/test/switch_ranges_endpoints_are_validated.zig created+13
...@@ -0,0 +1,13 @@
1pub export fn entry() void {
2 var x: i32 = 0;
3 switch (x) {
4 6...1 => {},
5 -1...-5 => {},
6 else => unreachable,
7 }
8}
9
10// switch ranges endpoints are validated
11//
12// tmp.zig:4:9: error: range start value is greater than the end value
13// tmp.zig:5:9: error: range start value is greater than the end value
test/compile_errors/stage1/test/switching_with_exhaustive_enum_has___prong_.zig created+16
...@@ -0,0 +1,16 @@
1const E = enum{
2 a,
3 b,
4};
5pub export fn entry() void {
6 var e: E = .b;
7 switch (e) {
8 .a => {},
9 .b => {},
10 _ => {},
11 }
12}
13
14// switching with exhaustive enum has '_' prong
15//
16// tmp.zig:7:5: error: switch on exhaustive enum has `_` prong
test/compile_errors/stage1/test/switching_with_non-exhaustive_enums.zig created+32
...@@ -0,0 +1,32 @@
1const E = enum(u8) {
2 a,
3 b,
4 _,
5};
6const U = union(E) {
7 a: i32,
8 b: u32,
9};
10pub export fn entry() void {
11 var e: E = .b;
12 switch (e) { // error: switch not handling the tag `b`
13 .a => {},
14 _ => {},
15 }
16 switch (e) { // error: switch on non-exhaustive enum must include `else` or `_` prong
17 .a => {},
18 .b => {},
19 }
20 var u = U{.a = 2};
21 switch (u) { // error: `_` prong not allowed when switching on tagged union
22 .a => {},
23 .b => {},
24 _ => {},
25 }
26}
27
28// switching with non-exhaustive enums
29//
30// tmp.zig:12:5: error: enumeration value 'E.b' not handled in switch
31// tmp.zig:16:5: error: switch on non-exhaustive enum must include `else` or `_` prong
32// tmp.zig:21:5: error: `_` prong not allowed when switching on tagged union
test/compile_errors/stage1/test/tagName_on_invalid_value_of_non-exhaustive_enum.zig created+8
...@@ -0,0 +1,8 @@
1test "enum" {
2 const E = enum(u8) {A, B, _};
3 _ = @tagName(@intToEnum(E, 5));
4}
5
6// @tagName on invalid value of non-exhaustive enum
7//
8// tmp.zig:3:18: error: no tag by value 5
test/compile_errors/stage1/test/type_mismatch_in_C_prototype_with_varargs.zig created+11
...@@ -0,0 +1,11 @@
1const fn_ty = ?fn ([*c]u8, ...) callconv(.C) void;
2extern fn fn_decl(fmt: [*:0]u8, ...) void;
3
4export fn main() void {
5 const x: fn_ty = fn_decl;
6 _ = x;
7}
8
9// type mismatch in C prototype with varargs
10//
11// tmp.zig:5:22: error: expected type 'fn([*c]u8, ...) callconv(.C) void', found 'fn([*:0]u8, ...) callconv(.C) void'
test/compile_errors/stage1/test/type_mismatch_with_tuple_concatenation.zig created+8
...@@ -0,0 +1,8 @@
1export fn entry() void {
2 var x = .{};
3 x = x ++ .{ 1, 2, 3 };
4}
5
6// type mismatch with tuple concatenation
7//
8// tmp.zig:3:11: error: expected type 'struct:2:14', found 'struct:3:11'
test/compile_errors/stage1/test/unused_variable_error_on_errdefer.zig created+11
...@@ -0,0 +1,11 @@
1fn foo() !void {
2 errdefer |a| unreachable;
3 return error.A;
4}
5export fn entry() void {
6 foo() catch unreachable;
7}
8
9// unused variable error on errdefer
10//
11// tmp.zig:2:15: error: unused variable: 'a'
test/compile_errors/stage2/embed_outside_package.zig created+7
...@@ -0,0 +1,7 @@
1export fn a() usize {
2 return @embedFile("/root/foo").len;
3}
4
5// embed outside package
6//
7//:2:23: error: embed of file outside package path: '/root/foo'
test/compile_errors/stage2/import_outside_package.zig created+7
...@@ -0,0 +1,7 @@
1export fn a() usize {
2 return @import("../../above.zig").len;
3}
4
5// import outside package
6//
7// :2:20: error: import of file outside package path: '../../above.zig'
test/compile_errors/stage2/out_of_bounds_index.zig created+28
...@@ -0,0 +1,28 @@
1comptime {
2 var array = [_:0]u8{ 1, 2, 3, 4 };
3 var src_slice: [:0]u8 = &array;
4 var slice = src_slice[2..6];
5 _ = slice;
6}
7comptime {
8 var array = [_:0]u8{ 1, 2, 3, 4 };
9 var slice = array[2..6];
10 _ = slice;
11}
12comptime {
13 var array = [_]u8{ 1, 2, 3, 4 };
14 var slice = array[2..5];
15 _ = slice;
16}
17comptime {
18 var array = [_:0]u8{ 1, 2, 3, 4 };
19 var slice = array[3..2];
20 _ = slice;
21}
22
23// out of bounds indexing
24//
25// :4:26: error: end index 6 out of bounds for slice of length 4 +1 (sentinel)
26// :9:22: error: end index 6 out of bounds for array of length 4 +1 (sentinel)
27// :14:22: error: end index 5 out of bounds for array of length 4
28// :19:22: error: start index 3 is larger than end index 2