authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-03-26 00:45:38-04:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2022-03-26 00:45:38-04:00
log6ef761307ce286f4c6955ce2e7627e9a0d6ec442
tree0248fdbf3aa19fa879698578082e13119eda24aa
parent88e98a0611b9fb41c1da026febac2467548bb129
parent0568b4577947f7af2e04cb9e9c95011b0fca88c8
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

Merge pull request #11284 from topolarity/compile-errors-indep-files

Add primitive file support for compile error tests

658 files changed, 8266 insertions(+), 8778 deletions(-)

ci/zinc/linux_test.sh+1-1
...@@ -45,7 +45,7 @@ cd $WORKSPACE...@@ -45,7 +45,7 @@ cd $WORKSPACE
4545
46# Look for non-conforming code formatting.46# Look for non-conforming code formatting.
47# Formatting errors can be fixed by running `zig fmt` on the files printed here.47# Formatting errors can be fixed by running `zig fmt` on the files printed here.
48$ZIG fmt --check .48$ZIG fmt --check . --exclude test/compile_errors/
4949
50# Build stage2 standalone so that we can test stage2 against stage2 compiler-rt.50# Build stage2 standalone so that we can test stage2 against stage2 compiler-rt.
51$ZIG build -p stage2 -Denable-llvm -Duse-zig-libcxx51$ZIG build -p stage2 -Denable-llvm -Duse-zig-libcxx
src/main.zig+20
...@@ -3792,6 +3792,7 @@ pub const usage_fmt =...@@ -3792,6 +3792,7 @@ pub const usage_fmt =
3792 \\ --check List non-conforming files and exit with an error3792 \\ --check List non-conforming files and exit with an error
3793 \\ if the list is non-empty3793 \\ if the list is non-empty
3794 \\ --ast-check Run zig ast-check on every file3794 \\ --ast-check Run zig ast-check on every file
3795 \\ --exclude [file] Exclude file or directory from formatting
3795 \\3796 \\
3796 \\3797 \\
3797;3798;
...@@ -3815,6 +3816,8 @@ pub fn cmdFmt(gpa: Allocator, arena: Allocator, args: []const []const u8) !void...@@ -3815,6 +3816,8 @@ pub fn cmdFmt(gpa: Allocator, arena: Allocator, args: []const []const u8) !void
3815 var check_ast_flag: bool = false;3816 var check_ast_flag: bool = false;
3816 var input_files = ArrayList([]const u8).init(gpa);3817 var input_files = ArrayList([]const u8).init(gpa);
3817 defer input_files.deinit();3818 defer input_files.deinit();
3819 var excluded_files = ArrayList([]const u8).init(gpa);
3820 defer excluded_files.deinit();
38183821
3819 {3822 {
3820 var i: usize = 0;3823 var i: usize = 0;
...@@ -3840,6 +3843,13 @@ pub fn cmdFmt(gpa: Allocator, arena: Allocator, args: []const []const u8) !void...@@ -3840,6 +3843,13 @@ pub fn cmdFmt(gpa: Allocator, arena: Allocator, args: []const []const u8) !void
3840 check_flag = true;3843 check_flag = true;
3841 } else if (mem.eql(u8, arg, "--ast-check")) {3844 } else if (mem.eql(u8, arg, "--ast-check")) {
3842 check_ast_flag = true;3845 check_ast_flag = true;
3846 } else if (mem.eql(u8, arg, "--exclude")) {
3847 if (i + 1 >= args.len) {
3848 fatal("expected parameter after --exclude", .{});
3849 }
3850 i += 1;
3851 const next_arg = args[i];
3852 try excluded_files.append(next_arg);
3843 } else {3853 } else {
3844 fatal("unrecognized parameter: '{s}'", .{arg});3854 fatal("unrecognized parameter: '{s}'", .{arg});
3845 }3855 }
...@@ -3940,6 +3950,16 @@ pub fn cmdFmt(gpa: Allocator, arena: Allocator, args: []const []const u8) !void...@@ -3940,6 +3950,16 @@ pub fn cmdFmt(gpa: Allocator, arena: Allocator, args: []const []const u8) !void
3940 defer fmt.seen.deinit();3950 defer fmt.seen.deinit();
3941 defer fmt.out_buffer.deinit();3951 defer fmt.out_buffer.deinit();
39423952
3953 // Mark any excluded files/directories as already seen,
3954 // so that they are skipped later during actual processing
3955 for (excluded_files.items) |file_path| {
3956 var dir = try fs.cwd().openDir(file_path, .{});
3957 defer dir.close();
3958
3959 const stat = try dir.stat();
3960 try fmt.seen.put(stat.inode, {});
3961 }
3962
3943 for (input_files.items) |file_path| {3963 for (input_files.items) |file_path| {
3944 try fmtPath(&fmt, file_path, check_flag, fs.cwd(), file_path);3964 try fmtPath(&fmt, file_path, check_flag, fs.cwd(), file_path);
3945 }3965 }
src/test.zig+99
...@@ -20,6 +20,7 @@ const assert = std.debug.assert;...@@ -20,6 +20,7 @@ const assert = std.debug.assert;
2020
21const zig_h = link.File.C.zig_h;21const zig_h = link.File.C.zig_h;
2222
23var general_purpose_allocator = std.heap.GeneralPurposeAllocator(.{}){};
23const hr = "=" ** 80;24const hr = "=" ** 80;
2425
25test {26test {
...@@ -594,6 +595,104 @@ pub const TestContext = struct {...@@ -594,6 +595,104 @@ pub const TestContext = struct {
594 case.compiles(fixed_src);595 case.compiles(fixed_src);
595 }596 }
596597
598 /// Adds a compile-error test for each file in the provided directory, using the
599 /// selected backend and output mode. If `one_test_case_per_file` is true, a new
600 /// test case is created for each file. Otherwise, a single test case is used for
601 /// all tests.
602 ///
603 /// Each file should include a test manifest as a contiguous block of comments at
604 /// the end of the file. The first line should be the test case name, followed by
605 /// a blank line, then one expected errors on each line in the form
606 /// `:line:column: error: message`
607 pub fn addErrorCasesFromDir(
608 ctx: *TestContext,
609 name: []const u8,
610 dir: std.fs.Dir,
611 backend: Backend,
612 output_mode: std.builtin.OutputMode,
613 is_test: bool,
614 one_test_case_per_file: bool,
615 ) !void {
616 if (skip_compile_errors) return;
617
618 const gpa = general_purpose_allocator.allocator();
619 var case: ?*Case = null;
620
621 var it = dir.iterate();
622 while (try it.next()) |entry| {
623 if (entry.kind != .File) continue;
624
625 var contents = try dir.readFileAlloc(gpa, entry.name, std.math.maxInt(u32));
626 defer gpa.free(contents);
627
628 // The manifest is the last contiguous block of comments in the file
629 // We scan for the beginning by searching backward for the first non-empty line that does not start with "//"
630 var manifest_start: ?usize = null;
631 var manifest_end: usize = contents.len;
632 if (contents.len > 0) {
633 var cursor: usize = contents.len - 1;
634 while (true) {
635 // Move to beginning of line
636 while (cursor > 0 and contents[cursor - 1] != '\n') cursor -= 1;
637
638 // Check if line is non-empty and does not start with "//"
639 if (cursor + 1 < contents.len and contents[cursor + 1] != '\n' and contents[cursor + 1] != '\r') {
640 if (std.mem.startsWith(u8, contents[cursor..], "//")) {
641 manifest_start = cursor;
642 } else {
643 break;
644 }
645 } else manifest_end = cursor;
646
647 // Move to previous line
648 if (cursor != 0) cursor -= 1 else break;
649 }
650 }
651
652 var errors = std.ArrayList([]const u8).init(gpa);
653 defer errors.deinit();
654
655 if (manifest_start) |start| {
656 // Due to the above processing, we know that this is a contiguous block of comments
657 var manifest_it = std.mem.tokenize(u8, contents[start..manifest_end], "\r\n");
658
659 // First line is the test case name
660 const first_line = manifest_it.next() orelse return error.InvalidFile;
661 const case_name = try std.mem.concat(gpa, u8, &.{ name, ": ", std.mem.trim(u8, first_line[2..], " \t") });
662
663 // If the second line is present, it should be blank
664 if (manifest_it.next()) |second_line| {
665 if (std.mem.trim(u8, second_line[2..], " \t").len != 0) return error.InvalidFile;
666 }
667
668 // All following lines are expected error messages
669 while (manifest_it.next()) |line| try errors.append(try gpa.dupe(u8, std.mem.trim(u8, line[2..], " \t")));
670
671 // The entire file contents is the source, including the manifest
672 const src = try gpa.dupeZ(u8, contents);
673
674 // Create a new test case, if necessary
675 case = if (one_test_case_per_file or case == null) blk: {
676 ctx.cases.append(TestContext.Case{
677 .name = if (one_test_case_per_file) case_name else name,
678 .target = .{},
679 .backend = backend,
680 .updates = std.ArrayList(TestContext.Update).init(ctx.cases.allocator),
681 .is_test = is_test,
682 .output_mode = output_mode,
683 .files = std.ArrayList(TestContext.File).init(ctx.cases.allocator),
684 }) catch @panic("out of memory");
685 break :blk &ctx.cases.items[ctx.cases.items.len - 1];
686 } else case.?;
687
688 // Add our update + expected errors
689 case.?.addError(src, errors.items);
690 } else {
691 return error.InvalidFile; // Manifests are currently mandatory
692 }
693 }
694 }
695
597 fn init() TestContext {696 fn init() TestContext {
598 const allocator = std.heap.page_allocator;697 const allocator = std.heap.page_allocator;
599 return .{ .cases = std.ArrayList(Case).init(allocator) };698 return .{ .cases = std.ArrayList(Case).init(allocator) };
test/compile_errors.zig+260-8777
...@@ -3,180 +3,42 @@ const builtin = @import("builtin");...@@ -3,180 +3,42 @@ const builtin = @import("builtin");
3const TestContext = @import("../src/test.zig").TestContext;3const TestContext = @import("../src/test.zig").TestContext;
44
5pub fn addCases(ctx: *TestContext) !void {5pub fn addCases(ctx: *TestContext) !void {
6 {6 var parent_dir = try std.fs.cwd().openDir(std.fs.path.dirname(@src().file).?, .{ .no_follow = true });
7 var case = ctx.obj("stage2 compile errors", .{});7 defer parent_dir.close();
88
9 case.addError(9 var compile_errors_dir = try parent_dir.openDir("compile_errors", .{ .no_follow = true });
10 \\export fn a() usize {10 defer compile_errors_dir.close();
11 \\ return @embedFile("/root/foo").len;
12 \\}
13 , &[_][]const u8{
14 ":2:23: error: embed of file outside package path: '/root/foo'",
15 });
1611
17 case.addError(12 {
18 \\export fn a() usize {13 var stage2_dir = try compile_errors_dir.openDir("stage2", .{ .iterate = true, .no_follow = true });
19 \\ return @import("../../above.zig").len;14 defer stage2_dir.close();
20 \\}
21 , &[_][]const u8{
22 ":2:20: error: import of file outside package path: '../../above.zig'",
23 });
2415
25 case.addError(16 const one_test_case_per_file = false;
26 \\comptime {17 try ctx.addErrorCasesFromDir("stage2 compile errors", stage2_dir, .stage2, .Obj, false, one_test_case_per_file);
27 \\ var array = [_:0]u8{ 1, 2, 3, 4 };
28 \\ var src_slice: [:0]u8 = &array;
29 \\ var slice = src_slice[2..6];
30 \\ _ = slice;
31 \\}
32 \\comptime {
33 \\ var array = [_:0]u8{ 1, 2, 3, 4 };
34 \\ var slice = array[2..6];
35 \\ _ = slice;
36 \\}
37 \\comptime {
38 \\ var array = [_]u8{ 1, 2, 3, 4 };
39 \\ var slice = array[2..5];
40 \\ _ = slice;
41 \\}
42 \\comptime {
43 \\ var array = [_:0]u8{ 1, 2, 3, 4 };
44 \\ var slice = array[3..2];
45 \\ _ = slice;
46 \\}
47 , &[_][]const u8{
48 ":4:26: error: end index 6 out of bounds for slice of length 4 +1 (sentinel)",
49 ":9:22: error: end index 6 out of bounds for array of length 4 +1 (sentinel)",
50 ":14:22: error: end index 5 out of bounds for array of length 4",
51 ":19:22: error: start index 3 is larger than end index 2",
52 });
53 }18 }
5419
55 ctx.objErrStage1("exported enum without explicit integer tag type",20 {
56 \\const E = enum { one, two };21 var stage1_dir = try compile_errors_dir.openDir("stage1", .{ .no_follow = true });
57 \\comptime {22 defer stage1_dir.close();
58 \\ @export(E, .{ .name = "E" });23 {
59 \\}24 const one_test_case_per_file = true;
60 \\const e: E = .two;
61 \\comptime {
62 \\ @export(e, .{ .name = "e" });
63 \\}
64 , &.{
65 "tmp.zig:3:13: error: exported enum without explicit integer tag type",
66 "tmp.zig:7:13: error: exported enum value without explicit integer tag type",
67 });
68
69 ctx.objErrStage1("issue #9346: return outside of function scope",
70 \\pub const empty = return 1;
71 , &.{"tmp.zig:1:19: error: 'return' outside function scope"});
72
73 ctx.exeErrStage1("std.fmt error for unused arguments",
74 \\pub fn main() !void {
75 \\ @import("std").debug.print("{d} {d} {d} {d} {d}", .{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15});
76 \\}
77 , &.{
78 "?:?:?: error: 10 unused arguments in '{d} {d} {d} {d} {d}'",
79 });
80
81 ctx.objErrStage1("lazy pointer with undefined element type",
82 \\export fn foo() void {
83 \\ comptime var T: type = undefined;
84 \\ const S = struct { x: *T };
85 \\ const I = @typeInfo(S);
86 \\ _ = I;
87 \\}
88 , &[_][]const u8{
89 ":3:28: error: use of undefined value here causes undefined behavior",
90 });
9125
92 ctx.objErrStage1("pointer arithmetic on pointer-to-array",26 var obj_dir = try stage1_dir.openDir("obj", .{ .iterate = true, .no_follow = true });
93 \\export fn foo() void {27 defer obj_dir.close();
94 \\ var x: [10]u8 = undefined;
95 \\ var y = &x;
96 \\ var z = y + 1;
97 \\ _ = z;
98 \\}
99 , &[_][]const u8{
100 "tmp.zig:4:17: error: integer value 1 cannot be coerced to type '*[10]u8'",
101 });
10228
103 ctx.objErrStage1("pointer attributes checked when coercing pointer to anon literal",29 try ctx.addErrorCasesFromDir("stage1", obj_dir, .stage1, .Obj, false, one_test_case_per_file);
104 \\comptime {
105 \\ const c: [][]const u8 = &.{"hello", "world" };
106 \\ _ = c;
107 \\}
108 \\comptime {
109 \\ const c: *[2][]const u8 = &.{"hello", "world" };
110 \\ _ = c;
111 \\}
112 \\const S = struct {a: u8 = 1, b: u32 = 2};
113 \\comptime {
114 \\ const c: *S = &.{};
115 \\ _ = c;
116 \\}
117 , &[_][]const u8{
118 "tmp.zig:2:31: error: cannot cast pointer to array literal to slice type '[][]const u8'",
119 "tmp.zig:2:31: note: cast discards const qualifier",
120 "tmp.zig:6:33: error: cannot cast pointer to array literal to '*[2][]const u8'",
121 "tmp.zig:6:33: note: cast discards const qualifier",
122 "tmp.zig:11:21: error: expected type '*S', found '*const struct:11:21'",
123 "tmp.zig:11:21: note: cast discards const qualifier",
124 });
12530
126 ctx.objErrStage1("@Type() union payload is undefined",31 var exe_dir = try stage1_dir.openDir("exe", .{ .iterate = true, .no_follow = true });
127 \\const Foo = @Type(.{32 defer exe_dir.close();
128 \\ .Struct = undefined,
129 \\});
130 \\comptime { _ = Foo; }
131 , &[_][]const u8{
132 "tmp.zig:1:20: error: use of undefined value here causes undefined behavior",
133 });
13433
135 ctx.objErrStage1("wrong initializer for union payload of type 'type'",34 try ctx.addErrorCasesFromDir("stage1", exe_dir, .stage1, .Exe, false, one_test_case_per_file);
136 \\const U = union(enum) {
137 \\ A: type,
138 \\};
139 \\const S = struct {
140 \\ u: U,
141 \\};
142 \\export fn entry() void {
143 \\ comptime var v: S = undefined;
144 \\ v.u.A = U{ .A = i32 };
145 \\}
146 , &[_][]const u8{
147 "tmp.zig:9:8: error: use of undefined value here causes undefined behavior",
148 });
14935
150 ctx.objErrStage1("union with too small explicit signed tag type",36 var test_dir = try stage1_dir.openDir("test", .{ .iterate = true, .no_follow = true });
151 \\const U = union(enum(i2)) {37 defer test_dir.close();
152 \\ A: u8,
153 \\ B: u8,
154 \\ C: u8,
155 \\ D: u8,
156 \\};
157 \\export fn entry() void {
158 \\ _ = U{ .D = 1 };
159 \\}
160 , &[_][]const u8{
161 "tmp.zig:1:22: error: specified integer tag type cannot represent every field",
162 "tmp.zig:1:22: note: type i2 cannot fit values in range 0...3",
163 });
16438
165 ctx.objErrStage1("union with too small explicit unsigned tag type",39 try ctx.addErrorCasesFromDir("stage1", test_dir, .stage1, .Exe, true, one_test_case_per_file);
166 \\const U = union(enum(u2)) {40 }
167 \\ A: u8,41 }
168 \\ B: u8,
169 \\ C: u8,
170 \\ D: u8,
171 \\ E: u8,
172 \\};
173 \\export fn entry() void {
174 \\ _ = U{ .E = 1 };
175 \\}
176 , &[_][]const u8{
177 "tmp.zig:1:22: error: specified integer tag type cannot represent every field",
178 "tmp.zig:1:22: note: type u2 cannot fit values in range 0...4",
179 });
18042
181 {43 {
182 const case = ctx.obj("callconv(.Interrupt) on unsupported platform", .{44 const case = ctx.obj("callconv(.Interrupt) on unsupported platform", .{
...@@ -272,8493 +134,275 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -272,8493 +134,275 @@ pub fn addCases(ctx: *TestContext) !void {
272 });134 });
273 }135 }
274136
275 ctx.objErrStage1("unreachable executed at comptime",137 {
276 \\fn foo(comptime x: i32) i32 {138 const case = ctx.obj("call with new stack on unsupported target", .{
277 \\ comptime {139 .cpu_arch = .wasm32,
278 \\ if (x >= 0) return -x;140 .os_tag = .wasi,
279 \\ unreachable;141 .abi = .none,
280 \\ }142 });
281 \\}143 case.backend = .stage1;
282 \\export fn entry() void {144 case.addError(
283 \\ _ = foo(-42);145 \\var buf: [10]u8 align(16) = undefined;
284 \\}146 \\export fn entry() void {
285 , &[_][]const u8{147 \\ @call(.{.stack = &buf}, foo, .{});
286 "tmp.zig:4:9: error: reached unreachable code",148 \\}
287 "tmp.zig:8:12: note: called from here",149 \\fn foo() void {}
288 });150 , &[_][]const u8{
289151 "tmp.zig:3:5: error: target arch 'wasm32' does not support calling with a new stack",
290 ctx.objErrStage1("@Type with Type.Int",152 });
291 \\const builtin = @import("std").builtin;153 }
292 \\export fn entry() void {
293 \\ _ = @Type(builtin.Type.Int{
294 \\ .signedness = .signed,
295 \\ .bits = 8,
296 \\ });
297 \\}
298 , &[_][]const u8{
299 "tmp.zig:3:31: error: expected type 'std.builtin.Type', found 'std.builtin.Type.Int'",
300 });
301
302 ctx.objErrStage1("indexing a undefined slice at comptime",
303 \\comptime {
304 \\ var slice: []u8 = undefined;
305 \\ slice[0] = 2;
306 \\}
307 , &[_][]const u8{
308 "tmp.zig:3:10: error: index 0 outside slice of size 0",
309 });
310154
311 ctx.objErrStage1("array in c exported function",155 // Note: One of the error messages here is backwards. It would be nice to fix, but that's not
312 \\export fn zig_array(x: [10]u8) void {156 // going to stop me from merging this branch which fixes a bunch of other stuff.
313 \\ try std.testing.expect(std.mem.eql(u8, &x, "1234567890"));157 ctx.objErrStage1("incompatible sentinels",
158 \\export fn entry1(ptr: [*:255]u8) [*:0]u8 {
159 \\ return ptr;
314 \\}160 \\}
315 \\const std = @import("std");161 \\export fn entry2(ptr: [*]u8) [*:0]u8 {
316 \\export fn zig_return_array() [10]u8 {162 \\ return ptr;
317 \\ return "1234567890".*;
318 \\}163 \\}
319 , &[_][]const u8{164 \\export fn entry3() void {
320 "tmp.zig:1:24: error: parameter of type '[10]u8' not allowed in function with calling convention 'C'",165 \\ var array: [2:0]u8 = [_:255]u8{1, 2};
321 "tmp.zig:5:30: error: return type '[10]u8' not allowed in function with calling convention 'C'",166 \\ _ = array;
322 });
323
324 ctx.objErrStage1("@Type for exhaustive enum with undefined tag type",
325 \\const Tag = @Type(.{
326 \\ .Enum = .{
327 \\ .layout = .Auto,
328 \\ .tag_type = undefined,
329 \\ .fields = &.{},
330 \\ .decls = &.{},
331 \\ .is_exhaustive = false,
332 \\ },
333 \\});
334 \\export fn entry() void {
335 \\ _ = @intToEnum(Tag, 0);
336 \\}167 \\}
337 , &[_][]const u8{168 \\export fn entry4() void {
338 "tmp.zig:1:20: error: use of undefined value here causes undefined behavior",169 \\ var array: [2:0]u8 = [_]u8{1, 2};
339 });170 \\ _ = array;
340
341 ctx.objErrStage1("extern struct with non-extern-compatible integer tag type",
342 \\pub const E = enum(u31) { A, B, C };
343 \\pub const S = extern struct {
344 \\ e: E,
345 \\};
346 \\export fn entry() void {
347 \\ const s: S = undefined;
348 \\ _ = s;
349 \\}171 \\}
350 , &[_][]const u8{172 , &[_][]const u8{
351 "tmp.zig:3:5: error: extern structs cannot contain fields of type 'E'",173 "tmp.zig:2:12: error: expected type '[*:0]u8', found '[*:255]u8'",
352 });174 "tmp.zig:2:12: note: destination pointer requires a terminating '0' sentinel, but source pointer has a terminating '255' sentinel",
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",
353177
354 ctx.objErrStage1("@Type for exhaustive enum with non-integer tag type",178 "tmp.zig:8:35: error: expected type '[2:255]u8', found '[2:0]u8'",
355 \\const Tag = @Type(.{179 "tmp.zig:8:35: note: destination array requires a terminating '255' sentinel, but source array has a terminating '0' sentinel",
356 \\ .Enum = .{180 "tmp.zig:12:31: error: expected type '[2:0]u8', found '[2]u8'",
357 \\ .layout = .Auto,181 "tmp.zig:12:31: note: destination array requires a terminating '0' sentinel",
358 \\ .tag_type = bool,
359 \\ .fields = &.{},
360 \\ .decls = &.{},
361 \\ .is_exhaustive = false,
362 \\ },
363 \\});
364 \\export fn entry() void {
365 \\ _ = @intToEnum(Tag, 0);
366 \\}
367 , &[_][]const u8{
368 "tmp.zig:1:20: error: Type.Enum.tag_type must be an integer type, not 'bool'",
369 });182 });
370183
371 ctx.objErrStage1("extern struct with extern-compatible but inferred integer tag type",184 {
372 \\pub const E = enum {185 const case = ctx.obj("variable in inline assembly template cannot be found", .{
373 \\@"0",@"1",@"2",@"3",@"4",@"5",@"6",@"7",@"8",@"9",@"10",@"11",@"12",186 .cpu_arch = .x86_64,
374 \\@"13",@"14",@"15",@"16",@"17",@"18",@"19",@"20",@"21",@"22",@"23",187 .os_tag = .linux,
375 \\@"24",@"25",@"26",@"27",@"28",@"29",@"30",@"31",@"32",@"33",@"34",188 .abi = .gnu,
376 \\@"35",@"36",@"37",@"38",@"39",@"40",@"41",@"42",@"43",@"44",@"45",189 });
377 \\@"46",@"47",@"48",@"49",@"50",@"51",@"52",@"53",@"54",@"55",@"56",190 case.backend = .stage1;
378 \\@"57",@"58",@"59",@"60",@"61",@"62",@"63",@"64",@"65",@"66",@"67",191 case.addError(
379 \\@"68",@"69",@"70",@"71",@"72",@"73",@"74",@"75",@"76",@"77",@"78",192 \\export fn entry() void {
380 \\@"79",@"80",@"81",@"82",@"83",@"84",@"85",@"86",@"87",@"88",@"89",193 \\ var sp = asm volatile (
381 \\@"90",@"91",@"92",@"93",@"94",@"95",@"96",@"97",@"98",@"99",@"100",194 \\ "mov %[foo], sp"
382 \\@"101",@"102",@"103",@"104",@"105",@"106",@"107",@"108",@"109",195 \\ : [bar] "=r" (-> usize)
383 \\@"110",@"111",@"112",@"113",@"114",@"115",@"116",@"117",@"118",196 \\ );
384 \\@"119",@"120",@"121",@"122",@"123",@"124",@"125",@"126",@"127",197 \\ _ = sp;
385 \\@"128",@"129",@"130",@"131",@"132",@"133",@"134",@"135",@"136",198 \\}
386 \\@"137",@"138",@"139",@"140",@"141",@"142",@"143",@"144",@"145",199 , &[_][]const u8{
387 \\@"146",@"147",@"148",@"149",@"150",@"151",@"152",@"153",@"154",200 "tmp.zig:2:14: error: could not find 'foo' in the inputs or outputs",
388 \\@"155",@"156",@"157",@"158",@"159",@"160",@"161",@"162",@"163",201 });
389 \\@"164",@"165",@"166",@"167",@"168",@"169",@"170",@"171",@"172",202 }
390 \\@"173",@"174",@"175",@"176",@"177",@"178",@"179",@"180",@"181",
391 \\@"182",@"183",@"184",@"185",@"186",@"187",@"188",@"189",@"190",
392 \\@"191",@"192",@"193",@"194",@"195",@"196",@"197",@"198",@"199",
393 \\@"200",@"201",@"202",@"203",@"204",@"205",@"206",@"207",@"208",
394 \\@"209",@"210",@"211",@"212",@"213",@"214",@"215",@"216",@"217",
395 \\@"218",@"219",@"220",@"221",@"222",@"223",@"224",@"225",@"226",
396 \\@"227",@"228",@"229",@"230",@"231",@"232",@"233",@"234",@"235",
397 \\@"236",@"237",@"238",@"239",@"240",@"241",@"242",@"243",@"244",
398 \\@"245",@"246",@"247",@"248",@"249",@"250",@"251",@"252",@"253",
399 \\@"254",@"255"
400 \\};
401 \\pub const S = extern struct {
402 \\ e: E,
403 \\};
404 \\export fn entry() void {
405 \\ if (@typeInfo(E).Enum.tag_type != u8) @compileError("did not infer u8 tag type");
406 \\ const s: S = undefined;
407 \\ _ = s;
408 \\}
409 , &[_][]const u8{
410 "tmp.zig:31:5: error: extern structs cannot contain fields of type 'E'",
411 });
412203
413 ctx.objErrStage1("@Type for tagged union with extra enum field",204 {
414 \\const Tag = @Type(.{205 const case = ctx.obj("bad alignment in @asyncCall", .{
415 \\ .Enum = .{206 .cpu_arch = .aarch64,
416 \\ .layout = .Auto,207 .os_tag = .linux,
417 \\ .tag_type = u2,208 .abi = .none,
418 \\ .fields = &.{209 });
419 \\ .{ .name = "signed", .value = 0 },210 case.backend = .stage1;
420 \\ .{ .name = "unsigned", .value = 1 },211 case.addError(
421 \\ .{ .name = "arst", .value = 2 },212 \\export fn entry() void {
422 \\ },213 \\ var ptr: fn () callconv(.Async) void = func;
423 \\ .decls = &.{},214 \\ var bytes: [64]u8 = undefined;
424 \\ .is_exhaustive = true,215 \\ _ = @asyncCall(&bytes, {}, ptr, .{});
425 \\ },216 \\}
426 \\});217 \\fn func() callconv(.Async) void {}
427 \\const Tagged = @Type(.{218 , &[_][]const u8{
428 \\ .Union = .{219 "tmp.zig:4:21: error: expected type '[]align(8) u8', found '*[64]u8'",
429 \\ .layout = .Auto,220 });
430 \\ .tag_type = Tag,221 }
431 \\ .fields = &.{
432 \\ .{ .name = "signed", .field_type = i32, .alignment = @alignOf(i32) },
433 \\ .{ .name = "unsigned", .field_type = u32, .alignment = @alignOf(u32) },
434 \\ },
435 \\ .decls = &.{},
436 \\ },
437 \\});
438 \\export fn entry() void {
439 \\ var tagged = Tagged{ .signed = -1 };
440 \\ tagged = .{ .unsigned = 1 };
441 \\}
442 , &[_][]const u8{
443 "tmp.zig:14:23: error: enum field missing: 'arst'",
444 });
445222
446 ctx.objErrStage1("field access of opaque type",223 if (builtin.os.tag == .linux) {
447 \\const MyType = opaque {};224 ctx.testErrStage1("implicit dependency on libc",
448 \\225 \\extern "c" fn exit(u8) void;
449 \\export fn entry() bool {226 \\export fn entry() void {
450 \\ var x: i32 = 1;227 \\ exit(0);
451 \\ return bar(@ptrCast(*MyType, &x));228 \\}
452 \\}229 , &[_][]const u8{
453 \\230 "tmp.zig:3:5: error: dependency on libc must be explicitly specified in the build command",
454 \\fn bar(x: *MyType) bool {231 });
455 \\ return x.blah;
456 \\}
457 , &[_][]const u8{
458 "tmp.zig:9:13: error: no member named 'blah' in opaque type 'MyType'",
459 });
460232
461 ctx.objErrStage1("opaque type with field",233 ctx.testErrStage1("libc headers note",
462 \\const Opaque = opaque { foo: i32 };234 \\const c = @cImport(@cInclude("stdio.h"));
463 \\export fn entry() void {235 \\export fn entry() void {
464 \\ const foo: ?*Opaque = null;236 \\ _ = c.printf("hello, world!\n");
465 \\ _ = foo;237 \\}
466 \\}238 , &[_][]const u8{
467 , &[_][]const u8{239 "tmp.zig:1:11: error: C import failed",
468 "tmp.zig:1:25: error: opaque types cannot have fields",240 "tmp.zig:1:11: note: libc headers not available; compilation does not link against libc",
469 });241 });
242 }
470243
471 ctx.objErrStage1("@Type(.Fn) with is_generic = true",244 {
472 \\const Foo = @Type(.{245 const case = ctx.obj("wrong same named struct", .{});
473 \\ .Fn = .{246 case.backend = .stage1;
474 \\ .calling_convention = .Unspecified,
475 \\ .alignment = 0,
476 \\ .is_generic = true,
477 \\ .is_var_args = false,
478 \\ .return_type = u0,
479 \\ .args = &.{},
480 \\ },
481 \\});
482 \\comptime { _ = Foo; }
483 , &[_][]const u8{
484 "tmp.zig:1:20: error: Type.Fn.is_generic must be false for @Type",
485 });
486247
487 ctx.objErrStage1("@Type(.Fn) with is_var_args = true and non-C callconv",248 case.addSourceFile("a.zig",
488 \\const Foo = @Type(.{249 \\pub const Foo = struct {
489 \\ .Fn = .{250 \\ x: i32,
490 \\ .calling_convention = .Unspecified,251 \\};
491 \\ .alignment = 0,252 );
492 \\ .is_generic = false,
493 \\ .is_var_args = true,
494 \\ .return_type = u0,
495 \\ .args = &.{},
496 \\ },
497 \\});
498 \\comptime { _ = Foo; }
499 , &[_][]const u8{
500 "tmp.zig:1:20: error: varargs functions must have C calling convention",
501 });
502253
503 ctx.objErrStage1("@Type(.Fn) with return_type = null",254 case.addSourceFile("b.zig",
504 \\const Foo = @Type(.{255 \\pub const Foo = struct {
505 \\ .Fn = .{256 \\ z: f64,
506 \\ .calling_convention = .Unspecified,257 \\};
507 \\ .alignment = 0,258 );
508 \\ .is_generic = false,
509 \\ .is_var_args = false,
510 \\ .return_type = null,
511 \\ .args = &.{},
512 \\ },
513 \\});
514 \\comptime { _ = Foo; }
515 , &[_][]const u8{
516 "tmp.zig:1:20: error: Type.Fn.return_type must be non-null for @Type",
517 });
518259
519 ctx.objErrStage1("@Type for union with opaque field",260 case.addError(
520 \\const Untagged = @Type(.{261 \\const a = @import("a.zig");
521 \\ .Union = .{262 \\const b = @import("b.zig");
522 \\ .layout = .Auto,263 \\
523 \\ .tag_type = null,264 \\export fn entry() void {
524 \\ .fields = &.{265 \\ var a1: a.Foo = undefined;
525 \\ .{ .name = "foo", .field_type = opaque {}, .alignment = 1 },266 \\ bar(&a1);
526 \\ },267 \\}
527 \\ .decls = &.{},268 \\
528 \\ },269 \\fn bar(x: *b.Foo) void {_ = x;}
529 \\});270 , &[_][]const u8{
530 \\export fn entry() void {271 "tmp.zig:6:10: error: expected type '*b.Foo', found '*a.Foo'",
531 \\ _ = Untagged{};272 "tmp.zig:6:10: note: pointer type child 'a.Foo' cannot cast into pointer type child 'b.Foo'",
532 \\}273 "a.zig:1:17: note: a.Foo declared here",
533 , &[_][]const u8{274 "b.zig:1:17: note: b.Foo declared here",
534 "tmp.zig:1:25: error: opaque types have unknown size and therefore cannot be directly embedded in unions",275 });
535 });276 }
536277
537 ctx.objErrStage1("slice sentinel mismatch",278 {
538 \\export fn entry() void {279 const case = ctx.obj("multiple files with private function error", .{});
539 \\ const x = @import("std").meta.Vector(3, f32){ 25, 75, 5, 0 };280 case.backend = .stage1;
540 \\ _ = x;
541 \\}
542 , &[_][]const u8{
543 "tmp.zig:2:62: error: index 3 outside vector of size 3",
544 });
545281
546 ctx.objErrStage1("slice sentinel mismatch",282 case.addSourceFile("foo.zig",
547 \\export fn entry() void {283 \\fn privateFunction() void { }
548 \\ const y: [:1]const u8 = &[_:2]u8{ 1, 2 };284 );
549 \\ _ = y;
550 \\}
551 , &[_][]const u8{
552 "tmp.zig:2:37: error: expected type '[:1]const u8', found '*const [2:2]u8'",
553 });
554285
555 ctx.objErrStage1("@Type for union with zero fields",286 case.addError(
556 \\const Untagged = @Type(.{287 \\const foo = @import("foo.zig",);
557 \\ .Union = .{288 \\
558 \\ .layout = .Auto,289 \\export fn callPrivFunction() void {
559 \\ .tag_type = null,290 \\ foo.privateFunction();
560 \\ .fields = &.{},291 \\}
561 \\ .decls = &.{},292 , &[_][]const u8{
562 \\ },293 "tmp.zig:4:8: error: 'privateFunction' is private",
563 \\});294 "foo.zig:1:1: note: declared here",
564 \\export fn entry() void {295 });
565 \\ _ = Untagged{};296 }
566 \\}
567 , &[_][]const u8{
568 "tmp.zig:1:25: error: unions must have 1 or more fields",
569 });
570297
571 ctx.objErrStage1("@Type for exhaustive enum with zero fields",298 {
572 \\const Tag = @Type(.{299 const case = ctx.obj("multiple files with private member instance function (canonical invocation) error", .{});
573 \\ .Enum = .{300 case.backend = .stage1;
574 \\ .layout = .Auto,
575 \\ .tag_type = u1,
576 \\ .fields = &.{},
577 \\ .decls = &.{},
578 \\ .is_exhaustive = true,
579 \\ },
580 \\});
581 \\export fn entry() void {
582 \\ _ = @intToEnum(Tag, 0);
583 \\}
584 , &[_][]const u8{
585 "tmp.zig:1:20: error: enums must have 1 or more fields",
586 });
587301
588 ctx.objErrStage1("@Type for tagged union with extra union field",302 case.addSourceFile("foo.zig",
589 \\const Tag = @Type(.{303 \\pub const Foo = struct {
590 \\ .Enum = .{304 \\ fn privateFunction(self: *Foo) void { _ = self; }
591 \\ .layout = .Auto,305 \\};
592 \\ .tag_type = u1,306 );
593 \\ .fields = &.{
594 \\ .{ .name = "signed", .value = 0 },
595 \\ .{ .name = "unsigned", .value = 1 },
596 \\ },
597 \\ .decls = &.{},
598 \\ .is_exhaustive = true,
599 \\ },
600 \\});
601 \\const Tagged = @Type(.{
602 \\ .Union = .{
603 \\ .layout = .Auto,
604 \\ .tag_type = Tag,
605 \\ .fields = &.{
606 \\ .{ .name = "signed", .field_type = i32, .alignment = @alignOf(i32) },
607 \\ .{ .name = "unsigned", .field_type = u32, .alignment = @alignOf(u32) },
608 \\ .{ .name = "arst", .field_type = f32, .alignment = @alignOf(f32) },
609 \\ },
610 \\ .decls = &.{},
611 \\ },
612 \\});
613 \\export fn entry() void {
614 \\ var tagged = Tagged{ .signed = -1 };
615 \\ tagged = .{ .unsigned = 1 };
616 \\}
617 , &[_][]const u8{
618 "tmp.zig:13:23: error: enum field not found: 'arst'",
619 "tmp.zig:1:20: note: enum declared here",
620 });
621307
622 ctx.objErrStage1("@Type with undefined",308 case.addError(
623 \\comptime {309 \\const Foo = @import("foo.zig",).Foo;
624 \\ _ = @Type(.{ .Array = .{ .len = 0, .child = u8, .sentinel = undefined } });310 \\
625 \\}311 \\export fn callPrivFunction() void {
626 \\comptime {312 \\ var foo = Foo{};
627 \\ _ = @Type(.{313 \\ Foo.privateFunction(foo);
628 \\ .Struct = .{314 \\}
629 \\ .fields = undefined,315 , &[_][]const u8{
630 \\ .decls = undefined,316 "tmp.zig:5:8: error: 'privateFunction' is private",
631 \\ .is_tuple = false,317 "foo.zig:2:5: note: declared here",
632 \\ .layout = .Auto,318 });
633 \\ },319 }
634 \\ });
635 \\}
636 , &[_][]const u8{
637 "tmp.zig:2:16: error: use of undefined value here causes undefined behavior",
638 "tmp.zig:5:16: error: use of undefined value here causes undefined behavior",
639 });
640
641 ctx.objErrStage1("struct with declarations unavailable for @Type",
642 \\export fn entry() void {
643 \\ _ = @Type(@typeInfo(struct { const foo = 1; }));
644 \\}
645 , &[_][]const u8{
646 "tmp.zig:2:15: error: Type.Struct.decls must be empty for @Type",
647 });
648
649 ctx.objErrStage1("enum with declarations unavailable for @Type",
650 \\export fn entry() void {
651 \\ _ = @Type(@typeInfo(enum { foo, const bar = 1; }));
652 \\}
653 , &[_][]const u8{
654 "tmp.zig:2:15: error: Type.Enum.decls must be empty for @Type",
655 });
656
657 ctx.testErrStage1("reject extern variables with initializers",
658 \\extern var foo: int = 2;
659 , &[_][]const u8{
660 "tmp.zig:1:23: error: extern variables have no initializers",
661 });
662
663 ctx.testErrStage1("duplicate/unused labels",
664 \\comptime {
665 \\ blk: { blk: while (false) {} }
666 \\}
667 \\comptime {
668 \\ blk: while (false) { blk: for (@as([0]void, undefined)) |_| {} }
669 \\}
670 \\comptime {
671 \\ blk: for (@as([0]void, undefined)) |_| { blk: {} }
672 \\}
673 \\comptime {
674 \\ blk: {}
675 \\}
676 \\comptime {
677 \\ blk: while(false) {}
678 \\}
679 \\comptime {
680 \\ blk: for(@as([0]void, undefined)) |_| {}
681 \\}
682 , &[_][]const u8{
683 "tmp.zig:2:12: error: redefinition of label 'blk'",
684 "tmp.zig:2:5: note: previous definition here",
685 "tmp.zig:5:26: error: redefinition of label 'blk'",
686 "tmp.zig:5:5: note: previous definition here",
687 "tmp.zig:8:46: error: redefinition of label 'blk'",
688 "tmp.zig:8:5: note: previous definition here",
689 "tmp.zig:11:5: error: unused block label",
690 "tmp.zig:14:5: error: unused while loop label",
691 "tmp.zig:17:5: error: unused for loop label",
692 });
693
694 ctx.testErrStage1("@alignCast of zero sized types",
695 \\export fn foo() void {
696 \\ const a: *void = undefined;
697 \\ _ = @alignCast(2, a);
698 \\}
699 \\export fn bar() void {
700 \\ const a: ?*void = undefined;
701 \\ _ = @alignCast(2, a);
702 \\}
703 \\export fn baz() void {
704 \\ const a: []void = undefined;
705 \\ _ = @alignCast(2, a);
706 \\}
707 \\export fn qux() void {
708 \\ const a = struct {
709 \\ fn a(comptime b: u32) void { _ = b; }
710 \\ }.a;
711 \\ _ = @alignCast(2, a);
712 \\}
713 , &[_][]const u8{
714 "tmp.zig:3:23: error: cannot adjust alignment of zero sized type '*void'",
715 "tmp.zig:7:23: error: cannot adjust alignment of zero sized type '?*void'",
716 "tmp.zig:11:23: error: cannot adjust alignment of zero sized type '[]void'",
717 "tmp.zig:17:23: error: cannot adjust alignment of zero sized type 'fn(u32) anytype'",
718 });
719
720 ctx.testErrStage1("invalid non-exhaustive enum to union",
721 \\const E = enum(u8) {
722 \\ a,
723 \\ b,
724 \\ _,
725 \\};
726 \\const U = union(E) {
727 \\ a,
728 \\ b,
729 \\};
730 \\export fn foo() void {
731 \\ var e = @intToEnum(E, 15);
732 \\ var u: U = e;
733 \\ _ = u;
734 \\}
735 \\export fn bar() void {
736 \\ const e = @intToEnum(E, 15);
737 \\ var u: U = e;
738 \\ _ = u;
739 \\}
740 , &[_][]const u8{
741 "tmp.zig:12:16: error: runtime cast to union 'U' from non-exhaustive enum",
742 "tmp.zig:17:16: error: no tag by value 15",
743 });
744
745 ctx.testErrStage1("switching with exhaustive enum has '_' prong ",
746 \\const E = enum{
747 \\ a,
748 \\ b,
749 \\};
750 \\pub export fn entry() void {
751 \\ var e: E = .b;
752 \\ switch (e) {
753 \\ .a => {},
754 \\ .b => {},
755 \\ _ => {},
756 \\ }
757 \\}
758 , &[_][]const u8{
759 "tmp.zig:7:5: error: switch on exhaustive enum has `_` prong",
760 });
761
762 ctx.testErrStage1("invalid pointer with @Type",
763 \\export fn entry() void {
764 \\ _ = @Type(.{ .Pointer = .{
765 \\ .size = .One,
766 \\ .is_const = false,
767 \\ .is_volatile = false,
768 \\ .alignment = 1,
769 \\ .address_space = .generic,
770 \\ .child = u8,
771 \\ .is_allowzero = false,
772 \\ .sentinel = &@as(u8, 0),
773 \\ }});
774 \\}
775 , &[_][]const u8{
776 "tmp.zig:2:16: error: sentinels are only allowed on slices and unknown-length pointers",
777 });
778
779 ctx.objErrStage1("@Type(.Pointer) with invalid address space ",
780 \\export fn entry() void {
781 \\ _ = @Type(.{ .Pointer = .{
782 \\ .size = .One,
783 \\ .is_const = false,
784 \\ .is_volatile = false,
785 \\ .alignment = 1,
786 \\ .address_space = .gs,
787 \\ .child = u8,
788 \\ .is_allowzero = false,
789 \\ .sentinel = null,
790 \\ }});
791 \\}
792 , &[_][]const u8{
793 "tmp.zig:2:16: error: address space 'gs' not available in stage 1 compiler, must be .generic",
794 });
795
796 ctx.testErrStage1("helpful return type error message",
797 \\export fn foo() u32 {
798 \\ return error.Ohno;
799 \\}
800 \\fn bar() !u32 {
801 \\ return error.Ohno;
802 \\}
803 \\export fn baz() void {
804 \\ try bar();
805 \\}
806 \\export fn qux() u32 {
807 \\ return bar();
808 \\}
809 \\export fn quux() u32 {
810 \\ var buf: u32 = 0;
811 \\ buf = bar();
812 \\}
813 , &[_][]const u8{
814 "tmp.zig:2:17: error: expected type 'u32', found 'error{Ohno}'",
815 "tmp.zig:1:17: note: function cannot return an error",
816 "tmp.zig:8:5: error: expected type 'void', found '@typeInfo(@typeInfo(@TypeOf(bar)).Fn.return_type.?).ErrorUnion.error_set'",
817 "tmp.zig:7:17: note: function cannot return an error",
818 "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'",
819 "tmp.zig:10:17: note: function cannot return an error",
820 "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'",
821 "tmp.zig:14:5: note: cannot store an error in type 'u32'",
822 });
823
824 ctx.testErrStage1("int/float conversion to comptime_int/float",
825 \\export fn foo() void {
826 \\ var a: f32 = 2;
827 \\ _ = @floatToInt(comptime_int, a);
828 \\}
829 \\export fn bar() void {
830 \\ var a: u32 = 2;
831 \\ _ = @intToFloat(comptime_float, a);
832 \\}
833 , &[_][]const u8{
834 "tmp.zig:3:35: error: unable to evaluate constant expression",
835 "tmp.zig:7:37: error: unable to evaluate constant expression",
836 });
837
838 ctx.objErrStage1("extern variable has no type",
839 \\extern var foo;
840 \\pub export fn entry() void {
841 \\ foo;
842 \\}
843 , &[_][]const u8{
844 "tmp.zig:1:8: error: unable to infer variable type",
845 });
846
847 ctx.objErrStage1("@src outside function",
848 \\comptime {
849 \\ @src();
850 \\}
851 , &[_][]const u8{
852 "tmp.zig:2:5: error: @src outside function",
853 });
854
855 ctx.objErrStage1("call assigned to constant",
856 \\const Foo = struct {
857 \\ x: i32,
858 \\};
859 \\fn foo() Foo {
860 \\ return .{ .x = 42 };
861 \\}
862 \\fn bar(val: anytype) Foo {
863 \\ return .{ .x = val };
864 \\}
865 \\export fn entry() void {
866 \\ const baz: Foo = undefined;
867 \\ baz = foo();
868 \\}
869 \\export fn entry1() void {
870 \\ const baz: Foo = undefined;
871 \\ baz = bar(42);
872 \\}
873 , &[_][]const u8{
874 "tmp.zig:12:14: error: cannot assign to constant",
875 "tmp.zig:16:14: error: cannot assign to constant",
876 });
877
878 ctx.objErrStage1("invalid pointer syntax",
879 \\export fn foo() void {
880 \\ var guid: *:0 const u8 = undefined;
881 \\}
882 , &[_][]const u8{
883 "tmp.zig:2:16: error: expected type expression, found ':'",
884 });
885
886 ctx.objErrStage1("declaration between fields",
887 \\const S = struct {
888 \\ const foo = 2;
889 \\ const bar = 2;
890 \\ const baz = 2;
891 \\ a: struct {
892 \\ a: u32,
893 \\ b: u32,
894 \\ },
895 \\ const foo1 = 2;
896 \\ const bar1 = 2;
897 \\ const baz1 = 2;
898 \\ b: usize,
899 \\};
900 \\comptime {
901 \\ _ = S;
902 \\}
903 , &[_][]const u8{
904 "tmp.zig:9:5: error: declarations are not allowed between container fields",
905 "tmp.zig:5:5: note: field before declarations here",
906 "tmp.zig:12:5: note: field after declarations here",
907 });
908
909 ctx.objErrStage1("non-extern function with var args",
910 \\fn foo(args: ...) void {}
911 \\export fn entry() void {
912 \\ foo();
913 \\}
914 , &[_][]const u8{
915 "tmp.zig:1:14: error: expected type expression, found '...'",
916 });
917
918 ctx.testErrStage1("invalid int casts",
919 \\export fn foo() void {
920 \\ var a: u32 = 2;
921 \\ _ = @intCast(comptime_int, a);
922 \\}
923 \\export fn bar() void {
924 \\ var a: u32 = 2;
925 \\ _ = @intToFloat(u32, a);
926 \\}
927 \\export fn baz() void {
928 \\ var a: u32 = 2;
929 \\ _ = @floatToInt(u32, a);
930 \\}
931 \\export fn qux() void {
932 \\ var a: f32 = 2;
933 \\ _ = @intCast(u32, a);
934 \\}
935 , &[_][]const u8{
936 "tmp.zig:3:32: error: unable to evaluate constant expression",
937 "tmp.zig:7:21: error: expected float type, found 'u32'",
938 "tmp.zig:11:26: error: expected float type, found 'u32'",
939 "tmp.zig:15:23: error: expected integer type, found 'f32'",
940 });
941
942 ctx.testErrStage1("invalid float casts",
943 \\export fn foo() void {
944 \\ var a: f32 = 2;
945 \\ _ = @floatCast(comptime_float, a);
946 \\}
947 \\export fn bar() void {
948 \\ var a: f32 = 2;
949 \\ _ = @floatToInt(f32, a);
950 \\}
951 \\export fn baz() void {
952 \\ var a: f32 = 2;
953 \\ _ = @intToFloat(f32, a);
954 \\}
955 \\export fn qux() void {
956 \\ var a: u32 = 2;
957 \\ _ = @floatCast(f32, a);
958 \\}
959 , &[_][]const u8{
960 "tmp.zig:3:36: error: unable to evaluate constant expression",
961 "tmp.zig:7:21: error: expected integer type, found 'f32'",
962 "tmp.zig:11:26: error: expected int type, found 'f32'",
963 "tmp.zig:15:25: error: expected float type, found 'u32'",
964 });
965
966 ctx.testErrStage1("invalid assignments",
967 \\export fn entry1() void {
968 \\ var a: []const u8 = "foo";
969 \\ a[0..2] = "bar";
970 \\}
971 \\export fn entry2() void {
972 \\ var a: u8 = 2;
973 \\ a + 2 = 3;
974 \\}
975 \\export fn entry4() void {
976 \\ 2 + 2 = 3;
977 \\}
978 , &[_][]const u8{
979 "tmp.zig:3:6: error: invalid left-hand side to assignment",
980 "tmp.zig:7:7: error: invalid left-hand side to assignment",
981 "tmp.zig:10:7: error: invalid left-hand side to assignment",
982 });
983
984 ctx.testErrStage1("reassign to array parameter",
985 \\fn reassign(a: [3]f32) void {
986 \\ a = [3]f32{4, 5, 6};
987 \\}
988 \\export fn entry() void {
989 \\ reassign(.{1, 2, 3});
990 \\}
991 , &[_][]const u8{
992 "tmp.zig:2:15: error: cannot assign to constant",
993 });
994
995 ctx.testErrStage1("reassign to slice parameter",
996 \\pub fn reassign(s: []const u8) void {
997 \\ s = s[0..];
998 \\}
999 \\export fn entry() void {
1000 \\ reassign("foo");
1001 \\}
1002 , &[_][]const u8{
1003 "tmp.zig:2:10: error: cannot assign to constant",
1004 });
1005
1006 ctx.testErrStage1("reassign to struct parameter",
1007 \\const S = struct {
1008 \\ x: u32,
1009 \\};
1010 \\fn reassign(s: S) void {
1011 \\ s = S{.x = 2};
1012 \\}
1013 \\export fn entry() void {
1014 \\ reassign(S{.x = 3});
1015 \\}
1016 , &[_][]const u8{
1017 "tmp.zig:5:10: error: cannot assign to constant",
1018 });
1019
1020 ctx.testErrStage1("reference to const data",
1021 \\export fn foo() void {
1022 \\ var ptr = &[_]u8{0,0,0,0};
1023 \\ ptr[1] = 2;
1024 \\}
1025 \\export fn bar() void {
1026 \\ var ptr = &@as(u32, 2);
1027 \\ ptr.* = 2;
1028 \\}
1029 \\export fn baz() void {
1030 \\ var ptr = &true;
1031 \\ ptr.* = false;
1032 \\}
1033 \\export fn qux() void {
1034 \\ const S = struct{
1035 \\ x: usize,
1036 \\ y: usize,
1037 \\ };
1038 \\ var ptr = &S{.x=1,.y=2};
1039 \\ ptr.x = 2;
1040 \\}
1041 , &[_][]const u8{
1042 "tmp.zig:3:14: error: cannot assign to constant",
1043 "tmp.zig:7:13: error: cannot assign to constant",
1044 "tmp.zig:11:13: error: cannot assign to constant",
1045 "tmp.zig:19:13: error: cannot assign to constant",
1046 });
1047
1048 ctx.testErrStage1("cast between ?T where T is not a pointer",
1049 \\pub const fnty1 = ?fn (i8) void;
1050 \\pub const fnty2 = ?fn (u64) void;
1051 \\export fn entry() void {
1052 \\ var a: fnty1 = undefined;
1053 \\ var b: fnty2 = undefined;
1054 \\ a = b;
1055 \\}
1056 , &[_][]const u8{
1057 "tmp.zig:6:9: error: expected type '?fn(i8) void', found '?fn(u64) void'",
1058 "tmp.zig:6:9: note: optional type child 'fn(u64) void' cannot cast into optional type child 'fn(i8) void'",
1059 });
1060
1061 ctx.testErrStage1("unused variable error on errdefer",
1062 \\fn foo() !void {
1063 \\ errdefer |a| unreachable;
1064 \\ return error.A;
1065 \\}
1066 \\export fn entry() void {
1067 \\ foo() catch unreachable;
1068 \\}
1069 , &[_][]const u8{
1070 "tmp.zig:2:15: error: unused variable: 'a'",
1071 });
1072
1073 ctx.testErrStage1("comparison of non-tagged union and enum literal",
1074 \\export fn entry() void {
1075 \\ const U = union { A: u32, B: u64 };
1076 \\ var u = U{ .A = 42 };
1077 \\ var ok = u == .A;
1078 \\ _ = ok;
1079 \\}
1080 , &[_][]const u8{
1081 "tmp.zig:4:16: error: comparison of union and enum literal is only valid for tagged union types",
1082 "tmp.zig:2:15: note: type U is not a tagged union",
1083 });
1084
1085 ctx.testErrStage1("shift on type with non-power-of-two size",
1086 \\export fn entry() void {
1087 \\ const S = struct {
1088 \\ fn a() void {
1089 \\ var x: u24 = 42;
1090 \\ _ = x >> 24;
1091 \\ }
1092 \\ fn b() void {
1093 \\ var x: u24 = 42;
1094 \\ _ = x << 24;
1095 \\ }
1096 \\ fn c() void {
1097 \\ var x: u24 = 42;
1098 \\ _ = @shlExact(x, 24);
1099 \\ }
1100 \\ fn d() void {
1101 \\ var x: u24 = 42;
1102 \\ _ = @shrExact(x, 24);
1103 \\ }
1104 \\ };
1105 \\ S.a();
1106 \\ S.b();
1107 \\ S.c();
1108 \\ S.d();
1109 \\}
1110 , &[_][]const u8{
1111 "tmp.zig:5:19: error: RHS of shift is too large for LHS type",
1112 "tmp.zig:9:19: error: RHS of shift is too large for LHS type",
1113 "tmp.zig:13:17: error: RHS of shift is too large for LHS type",
1114 "tmp.zig:17:17: error: RHS of shift is too large for LHS type",
1115 });
1116
1117 ctx.testErrStage1("combination of nosuspend and async",
1118 \\export fn entry() void {
1119 \\ nosuspend {
1120 \\ const bar = async foo();
1121 \\ suspend {}
1122 \\ resume bar;
1123 \\ }
1124 \\}
1125 \\fn foo() void {}
1126 , &[_][]const u8{
1127 "tmp.zig:4:9: error: suspend inside nosuspend block",
1128 "tmp.zig:2:5: note: nosuspend block here",
1129 });
1130
1131 ctx.objErrStage1("atomicrmw with bool op not .Xchg",
1132 \\export fn entry() void {
1133 \\ var x = false;
1134 \\ _ = @atomicRmw(bool, &x, .Add, true, .SeqCst);
1135 \\}
1136 , &[_][]const u8{
1137 "tmp.zig:3:30: error: @atomicRmw with bool only allowed with .Xchg",
1138 });
1139
1140 ctx.testErrStage1("@TypeOf with no arguments",
1141 \\export fn entry() void {
1142 \\ _ = @TypeOf();
1143 \\}
1144 , &[_][]const u8{
1145 "tmp.zig:2:9: error: expected at least 1 argument, found 0",
1146 });
1147
1148 ctx.testErrStage1("@TypeOf with incompatible arguments",
1149 \\export fn entry() void {
1150 \\ var var_1: f32 = undefined;
1151 \\ var var_2: u32 = undefined;
1152 \\ _ = @TypeOf(var_1, var_2);
1153 \\}
1154 , &[_][]const u8{
1155 "tmp.zig:4:9: error: incompatible types: 'f32' and 'u32'",
1156 });
1157
1158 ctx.testErrStage1("type mismatch with tuple concatenation",
1159 \\export fn entry() void {
1160 \\ var x = .{};
1161 \\ x = x ++ .{ 1, 2, 3 };
1162 \\}
1163 , &[_][]const u8{
1164 "tmp.zig:3:11: error: expected type 'struct:2:14', found 'struct:3:11'",
1165 });
1166
1167 ctx.testErrStage1("@tagName on invalid value of non-exhaustive enum",
1168 \\test "enum" {
1169 \\ const E = enum(u8) {A, B, _};
1170 \\ _ = @tagName(@intToEnum(E, 5));
1171 \\}
1172 , &[_][]const u8{
1173 "tmp.zig:3:18: error: no tag by value 5",
1174 });
1175
1176 ctx.testErrStage1("@ptrToInt with pointer to zero-sized type",
1177 \\export fn entry() void {
1178 \\ var pointer: ?*u0 = null;
1179 \\ var x = @ptrToInt(pointer);
1180 \\ _ = x;
1181 \\}
1182 , &[_][]const u8{
1183 "tmp.zig:3:23: error: pointer to size 0 type has no address",
1184 });
1185
1186 ctx.testErrStage1("access invalid @typeInfo decl",
1187 \\const A = B;
1188 \\test "Crash" {
1189 \\ _ = @typeInfo(@This()).Struct.decls[0];
1190 \\}
1191 , &[_][]const u8{
1192 "tmp.zig:1:11: error: use of undeclared identifier 'B'",
1193 });
1194
1195 ctx.testErrStage1("reject extern function definitions with body",
1196 \\extern "c" fn definitelyNotInLibC(a: i32, b: i32) i32 {
1197 \\ return a + b;
1198 \\}
1199 , &[_][]const u8{
1200 "tmp.zig:1:1: error: extern functions have no body",
1201 });
1202
1203 ctx.testErrStage1("duplicate field in anonymous struct literal",
1204 \\export fn entry() void {
1205 \\ const anon = .{
1206 \\ .inner = .{
1207 \\ .a = .{
1208 \\ .something = "text",
1209 \\ },
1210 \\ .a = .{},
1211 \\ },
1212 \\ };
1213 \\ _ = anon;
1214 \\}
1215 , &[_][]const u8{
1216 "tmp.zig:7:13: error: duplicate field",
1217 "tmp.zig:4:13: note: other field here",
1218 });
1219
1220 ctx.testErrStage1("type mismatch in C prototype with varargs",
1221 \\const fn_ty = ?fn ([*c]u8, ...) callconv(.C) void;
1222 \\extern fn fn_decl(fmt: [*:0]u8, ...) void;
1223 \\
1224 \\export fn main() void {
1225 \\ const x: fn_ty = fn_decl;
1226 \\ _ = x;
1227 \\}
1228 , &[_][]const u8{
1229 "tmp.zig:5:22: error: expected type 'fn([*c]u8, ...) callconv(.C) void', found 'fn([*:0]u8, ...) callconv(.C) void'",
1230 });
1231
1232 ctx.objErrStage1("function call assigned to incorrect type",
1233 \\export fn entry() void {
1234 \\ var arr: [4]f32 = undefined;
1235 \\ arr = concat();
1236 \\}
1237 \\fn concat() [16]f32 {
1238 \\ return [1]f32{0}**16;
1239 \\}
1240 , &[_][]const u8{
1241 "tmp.zig:3:17: error: expected type '[4]f32', found '[16]f32'",
1242 });
1243
1244 ctx.objErrStage1("generic function call assigned to incorrect type",
1245 \\pub export fn entry() void {
1246 \\ var res: []i32 = undefined;
1247 \\ res = myAlloc(i32);
1248 \\}
1249 \\fn myAlloc(comptime arg: type) anyerror!arg{
1250 \\ unreachable;
1251 \\}
1252 , &[_][]const u8{
1253 "tmp.zig:3:18: error: expected type '[]i32', found 'anyerror!i32",
1254 });
1255
1256 ctx.testErrStage1("non-exhaustive enum marker assigned a value",
1257 \\const A = enum {
1258 \\ a,
1259 \\ b,
1260 \\ _ = 1,
1261 \\};
1262 \\const B = enum {
1263 \\ a,
1264 \\ b,
1265 \\ _,
1266 \\};
1267 \\comptime { _ = A; _ = B; }
1268 , &[_][]const u8{
1269 "tmp.zig:4:9: error: '_' is used to mark an enum as non-exhaustive and cannot be assigned a value",
1270 "tmp.zig:6:11: error: non-exhaustive enum missing integer tag type",
1271 "tmp.zig:9:5: note: marked non-exhaustive here",
1272 });
1273
1274 ctx.testErrStage1("non-exhaustive enums",
1275 \\const B = enum(u1) {
1276 \\ a,
1277 \\ _,
1278 \\ b,
1279 \\};
1280 \\const C = enum(u1) {
1281 \\ a,
1282 \\ b,
1283 \\ _,
1284 \\};
1285 \\pub export fn entry() void {
1286 \\ _ = B;
1287 \\ _ = C;
1288 \\}
1289 , &[_][]const u8{
1290 "tmp.zig:3:5: error: '_' field of non-exhaustive enum must be last",
1291 "tmp.zig:6:11: error: non-exhaustive enum specifies every value",
1292 });
1293
1294 ctx.testErrStage1("switching with non-exhaustive enums",
1295 \\const E = enum(u8) {
1296 \\ a,
1297 \\ b,
1298 \\ _,
1299 \\};
1300 \\const U = union(E) {
1301 \\ a: i32,
1302 \\ b: u32,
1303 \\};
1304 \\pub export fn entry() void {
1305 \\ var e: E = .b;
1306 \\ switch (e) { // error: switch not handling the tag `b`
1307 \\ .a => {},
1308 \\ _ => {},
1309 \\ }
1310 \\ switch (e) { // error: switch on non-exhaustive enum must include `else` or `_` prong
1311 \\ .a => {},
1312 \\ .b => {},
1313 \\ }
1314 \\ var u = U{.a = 2};
1315 \\ switch (u) { // error: `_` prong not allowed when switching on tagged union
1316 \\ .a => {},
1317 \\ .b => {},
1318 \\ _ => {},
1319 \\ }
1320 \\}
1321 , &[_][]const u8{
1322 "tmp.zig:12:5: error: enumeration value 'E.b' not handled in switch",
1323 "tmp.zig:16:5: error: switch on non-exhaustive enum must include `else` or `_` prong",
1324 "tmp.zig:21:5: error: `_` prong not allowed when switching on tagged union",
1325 });
1326
1327 ctx.objErrStage1("switch expression - unreachable else prong (bool)",
1328 \\fn foo(x: bool) void {
1329 \\ switch (x) {
1330 \\ true => {},
1331 \\ false => {},
1332 \\ else => {},
1333 \\ }
1334 \\}
1335 \\export fn entry() usize { return @sizeOf(@TypeOf(foo)); }
1336 , &[_][]const u8{
1337 "tmp.zig:5:9: error: unreachable else prong, all cases already handled",
1338 });
1339
1340 ctx.objErrStage1("switch expression - unreachable else prong (u1)",
1341 \\fn foo(x: u1) void {
1342 \\ switch (x) {
1343 \\ 0 => {},
1344 \\ 1 => {},
1345 \\ else => {},
1346 \\ }
1347 \\}
1348 \\export fn entry() usize { return @sizeOf(@TypeOf(foo)); }
1349 , &[_][]const u8{
1350 "tmp.zig:5:9: error: unreachable else prong, all cases already handled",
1351 });
1352
1353 ctx.objErrStage1("switch expression - unreachable else prong (u2)",
1354 \\fn foo(x: u2) void {
1355 \\ switch (x) {
1356 \\ 0 => {},
1357 \\ 1 => {},
1358 \\ 2 => {},
1359 \\ 3 => {},
1360 \\ else => {},
1361 \\ }
1362 \\}
1363 \\export fn entry() usize { return @sizeOf(@TypeOf(foo)); }
1364 , &[_][]const u8{
1365 "tmp.zig:7:9: error: unreachable else prong, all cases already handled",
1366 });
1367
1368 ctx.objErrStage1("switch expression - unreachable else prong (range u8)",
1369 \\fn foo(x: u8) void {
1370 \\ switch (x) {
1371 \\ 0 => {},
1372 \\ 1 => {},
1373 \\ 2 => {},
1374 \\ 3 => {},
1375 \\ 4...255 => {},
1376 \\ else => {},
1377 \\ }
1378 \\}
1379 \\export fn entry() usize { return @sizeOf(@TypeOf(foo)); }
1380 , &[_][]const u8{
1381 "tmp.zig:8:9: error: unreachable else prong, all cases already handled",
1382 });
1383
1384 ctx.objErrStage1("switch expression - unreachable else prong (range i8)",
1385 \\fn foo(x: i8) void {
1386 \\ switch (x) {
1387 \\ -128...0 => {},
1388 \\ 1 => {},
1389 \\ 2 => {},
1390 \\ 3 => {},
1391 \\ 4...127 => {},
1392 \\ else => {},
1393 \\ }
1394 \\}
1395 \\export fn entry() usize { return @sizeOf(@TypeOf(foo)); }
1396 , &[_][]const u8{
1397 "tmp.zig:8:9: error: unreachable else prong, all cases already handled",
1398 });
1399
1400 ctx.objErrStage1("switch expression - unreachable else prong (enum)",
1401 \\const TestEnum = enum{ T1, T2 };
1402 \\
1403 \\fn err(x: u8) TestEnum {
1404 \\ switch (x) {
1405 \\ 0 => return TestEnum.T1,
1406 \\ else => return TestEnum.T2,
1407 \\ }
1408 \\}
1409 \\
1410 \\fn foo(x: u8) void {
1411 \\ switch (err(x)) {
1412 \\ TestEnum.T1 => {},
1413 \\ TestEnum.T2 => {},
1414 \\ else => {},
1415 \\ }
1416 \\}
1417 \\
1418 \\export fn entry() usize { return @sizeOf(@TypeOf(foo)); }
1419 , &[_][]const u8{
1420 "tmp.zig:14:9: error: unreachable else prong, all cases already handled",
1421 });
1422
1423 ctx.testErrStage1("@export with empty name string",
1424 \\pub export fn entry() void { }
1425 \\comptime {
1426 \\ @export(entry, .{ .name = "" });
1427 \\}
1428 , &[_][]const u8{
1429 "tmp.zig:3:5: error: exported symbol name cannot be empty",
1430 });
1431
1432 ctx.testErrStage1("switch ranges endpoints are validated",
1433 \\pub export fn entry() void {
1434 \\ var x: i32 = 0;
1435 \\ switch (x) {
1436 \\ 6...1 => {},
1437 \\ -1...-5 => {},
1438 \\ else => unreachable,
1439 \\ }
1440 \\}
1441 , &[_][]const u8{
1442 "tmp.zig:4:9: error: range start value is greater than the end value",
1443 "tmp.zig:5:9: error: range start value is greater than the end value",
1444 });
1445
1446 ctx.testErrStage1("errors in for loop bodies are propagated",
1447 \\pub export fn entry() void {
1448 \\ var arr: [100]u8 = undefined;
1449 \\ for (arr) |bits| _ = @popCount(bits);
1450 \\}
1451 , &[_][]const u8{
1452 "tmp.zig:3:26: error: expected 2 arguments, found 1",
1453 });
1454
1455 ctx.testErrStage1("@call rejects non comptime-known fn - always_inline",
1456 \\pub export fn entry() void {
1457 \\ var call_me: fn () void = undefined;
1458 \\ @call(.{ .modifier = .always_inline }, call_me, .{});
1459 \\}
1460 , &[_][]const u8{
1461 "tmp.zig:3:5: error: the specified modifier requires a comptime-known function",
1462 });
1463
1464 ctx.testErrStage1("@call rejects non comptime-known fn - compile_time",
1465 \\pub export fn entry() void {
1466 \\ var call_me: fn () void = undefined;
1467 \\ @call(.{ .modifier = .compile_time }, call_me, .{});
1468 \\}
1469 , &[_][]const u8{
1470 "tmp.zig:3:5: error: the specified modifier requires a comptime-known function",
1471 });
1472
1473 ctx.testErrStage1("error in struct initializer doesn't crash the compiler",
1474 \\pub export fn entry() void {
1475 \\ const bitfield = struct {
1476 \\ e: u8,
1477 \\ e: u8,
1478 \\ };
1479 \\ var a = .{@sizeOf(bitfield)};
1480 \\ _ = a;
1481 \\}
1482 , &[_][]const u8{
1483 "tmp.zig:4:9: error: duplicate struct field: 'e'",
1484 });
1485
1486 ctx.testErrStage1("repeated invalid field access to generic function returning type crashes compiler. #2655",
1487 \\pub fn A() type {
1488 \\ return Q;
1489 \\}
1490 \\test "1" {
1491 \\ _ = A().a;
1492 \\ _ = A().a;
1493 \\}
1494 , &[_][]const u8{
1495 "tmp.zig:2:12: error: use of undeclared identifier 'Q'",
1496 });
1497
1498 ctx.objErrStage1("bitCast to enum type",
1499 \\export fn entry() void {
1500 \\ const y = @bitCast(enum(u32) { a, b }, @as(u32, 3));
1501 \\ _ = y;
1502 \\}
1503 , &[_][]const u8{
1504 "tmp.zig:2:24: error: cannot cast a value of type 'y'",
1505 });
1506
1507 ctx.objErrStage1("comparing against undefined produces undefined value",
1508 \\export fn entry() void {
1509 \\ if (2 == undefined) {}
1510 \\}
1511 , &[_][]const u8{
1512 "tmp.zig:2:11: error: use of undefined value here causes undefined behavior",
1513 });
1514
1515 ctx.objErrStage1("comptime ptrcast of zero-sized type",
1516 \\fn foo() void {
1517 \\ const node: struct {} = undefined;
1518 \\ const vla_ptr = @ptrCast([*]const u8, &node);
1519 \\ _ = vla_ptr;
1520 \\}
1521 \\comptime { foo(); }
1522 , &[_][]const u8{
1523 "tmp.zig:3:21: error: '*const struct:2:17' and '[*]const u8' do not have the same in-memory representation",
1524 });
1525
1526 ctx.objErrStage1("slice sentinel mismatch",
1527 \\fn foo() [:0]u8 {
1528 \\ var x: []u8 = undefined;
1529 \\ return x;
1530 \\}
1531 \\comptime { _ = foo; }
1532 , &[_][]const u8{
1533 "tmp.zig:3:12: error: expected type '[:0]u8', found '[]u8'",
1534 "tmp.zig:3:12: note: destination pointer requires a terminating '0' sentinel",
1535 });
1536
1537 ctx.objErrStage1("cmpxchg with float",
1538 \\export fn entry() void {
1539 \\ var x: f32 = 0;
1540 \\ _ = @cmpxchgWeak(f32, &x, 1, 2, .SeqCst, .SeqCst);
1541 \\}
1542 , &[_][]const u8{
1543 "tmp.zig:3:22: error: expected bool, integer, enum or pointer type, found 'f32'",
1544 });
1545
1546 ctx.objErrStage1("atomicrmw with float op not .Xchg, .Add or .Sub",
1547 \\export fn entry() void {
1548 \\ var x: f32 = 0;
1549 \\ _ = @atomicRmw(f32, &x, .And, 2, .SeqCst);
1550 \\}
1551 , &[_][]const u8{
1552 "tmp.zig:3:29: error: @atomicRmw with float only allowed with .Xchg, .Add and .Sub",
1553 });
1554
1555 ctx.objErrStage1("intToPtr with misaligned address",
1556 \\pub fn main() void {
1557 \\ var y = @intToPtr([*]align(4) u8, 5);
1558 \\ _ = y;
1559 \\}
1560 , &[_][]const u8{
1561 "tmp.zig:2:13: error: pointer type '[*]align(4) u8' requires aligned address",
1562 });
1563
1564 ctx.objErrStage1("invalid float literal",
1565 \\const std = @import("std");
1566 \\
1567 \\pub fn main() void {
1568 \\ var bad_float :f32 = 0.0;
1569 \\ bad_float = bad_float + .20;
1570 \\ std.debug.assert(bad_float < 1.0);
1571 \\}
1572 , &[_][]const u8{
1573 "tmp.zig:5:29: error: expected expression, found '.'",
1574 });
1575
1576 ctx.objErrStage1("invalid exponent in float literal - 1",
1577 \\fn main() void {
1578 \\ var bad: f128 = 0x1.0p1ab1;
1579 \\ _ = bad;
1580 \\}
1581 , &[_][]const u8{
1582 "tmp.zig:2:21: error: expected expression, found 'invalid bytes'",
1583 "tmp.zig:2:28: note: invalid byte: 'a'",
1584 });
1585
1586 ctx.objErrStage1("invalid exponent in float literal - 2",
1587 \\fn main() void {
1588 \\ var bad: f128 = 0x1.0p50F;
1589 \\ _ = bad;
1590 \\}
1591 , &[_][]const u8{
1592 "tmp.zig:2:21: error: expected expression, found 'invalid bytes'",
1593 "tmp.zig:2:29: note: invalid byte: 'F'",
1594 });
1595
1596 ctx.objErrStage1("invalid underscore placement in float literal - 1",
1597 \\fn main() void {
1598 \\ var bad: f128 = 0._0;
1599 \\ _ = bad;
1600 \\}
1601 , &[_][]const u8{
1602 "tmp.zig:2:21: error: expected expression, found 'invalid bytes'",
1603 "tmp.zig:2:23: note: invalid byte: '_'",
1604 });
1605
1606 ctx.objErrStage1("invalid underscore placement in float literal - 2",
1607 \\fn main() void {
1608 \\ var bad: f128 = 0_.0;
1609 \\ _ = bad;
1610 \\}
1611 , &[_][]const u8{
1612 "tmp.zig:2:21: error: expected expression, found 'invalid bytes'",
1613 "tmp.zig:2:23: note: invalid byte: '.'",
1614 });
1615
1616 ctx.objErrStage1("invalid underscore placement in float literal - 3",
1617 \\fn main() void {
1618 \\ var bad: f128 = 0.0_;
1619 \\ _ = bad;
1620 \\}
1621 , &[_][]const u8{
1622 "tmp.zig:2:21: error: expected expression, found 'invalid bytes'",
1623 "tmp.zig:2:25: note: invalid byte: ';'",
1624 });
1625
1626 ctx.objErrStage1("invalid underscore placement in float literal - 4",
1627 \\fn main() void {
1628 \\ var bad: f128 = 1.0e_1;
1629 \\ _ = bad;
1630 \\}
1631 , &[_][]const u8{
1632 "tmp.zig:2:21: error: expected expression, found 'invalid bytes'",
1633 "tmp.zig:2:25: note: invalid byte: '_'",
1634 });
1635
1636 ctx.objErrStage1("invalid underscore placement in float literal - 5",
1637 \\fn main() void {
1638 \\ var bad: f128 = 1.0e+_1;
1639 \\ _ = bad;
1640 \\}
1641 , &[_][]const u8{
1642 "tmp.zig:2:21: error: expected expression, found 'invalid bytes'",
1643 "tmp.zig:2:26: note: invalid byte: '_'",
1644 });
1645
1646 ctx.objErrStage1("invalid underscore placement in float literal - 6",
1647 \\fn main() void {
1648 \\ var bad: f128 = 1.0e-_1;
1649 \\ _ = bad;
1650 \\}
1651 , &[_][]const u8{
1652 "tmp.zig:2:21: error: expected expression, found 'invalid bytes'",
1653 "tmp.zig:2:26: note: invalid byte: '_'",
1654 });
1655
1656 ctx.objErrStage1("invalid underscore placement in float literal - 7",
1657 \\fn main() void {
1658 \\ var bad: f128 = 1.0e-1_;
1659 \\ _ = bad;
1660 \\}
1661 , &[_][]const u8{
1662 "tmp.zig:2:21: error: expected expression, found 'invalid bytes'",
1663 "tmp.zig:2:28: note: invalid byte: ';'",
1664 });
1665
1666 ctx.objErrStage1("invalid underscore placement in float literal - 9",
1667 \\fn main() void {
1668 \\ var bad: f128 = 1__0.0e-1;
1669 \\ _ = bad;
1670 \\}
1671 , &[_][]const u8{
1672 "tmp.zig:2:21: error: expected expression, found 'invalid bytes'",
1673 "tmp.zig:2:23: note: invalid byte: '_'",
1674 });
1675
1676 ctx.objErrStage1("invalid underscore placement in float literal - 10",
1677 \\fn main() void {
1678 \\ var bad: f128 = 1.0__0e-1;
1679 \\ _ = bad;
1680 \\}
1681 , &[_][]const u8{
1682 "tmp.zig:2:21: error: expected expression, found 'invalid bytes'",
1683 "tmp.zig:2:25: note: invalid byte: '_'",
1684 });
1685
1686 ctx.objErrStage1("invalid underscore placement in float literal - 11",
1687 \\fn main() void {
1688 \\ var bad: f128 = 1.0e-1__0;
1689 \\ _ = bad;
1690 \\}
1691 , &[_][]const u8{
1692 "tmp.zig:2:21: error: expected expression, found 'invalid bytes'",
1693 "tmp.zig:2:28: note: invalid byte: '_'",
1694 });
1695
1696 ctx.objErrStage1("invalid underscore placement in float literal - 12",
1697 \\fn main() void {
1698 \\ var bad: f128 = 0_x0.0;
1699 \\ _ = bad;
1700 \\}
1701 , &[_][]const u8{
1702 "tmp.zig:2:21: error: expected expression, found 'invalid bytes'",
1703 "tmp.zig:2:23: note: invalid byte: 'x'",
1704 });
1705
1706 ctx.objErrStage1("invalid underscore placement in float literal - 13",
1707 \\fn main() void {
1708 \\ var bad: f128 = 0x_0.0;
1709 \\ _ = bad;
1710 \\}
1711 , &[_][]const u8{
1712 "tmp.zig:2:21: error: expected expression, found 'invalid bytes'",
1713 "tmp.zig:2:23: note: invalid byte: '_'",
1714 });
1715
1716 ctx.objErrStage1("invalid underscore placement in float literal - 14",
1717 \\fn main() void {
1718 \\ var bad: f128 = 0x0.0_p1;
1719 \\ _ = bad;
1720 \\}
1721 , &[_][]const u8{
1722 "tmp.zig:2:21: error: expected expression, found 'invalid bytes'",
1723 "tmp.zig:2:27: note: invalid byte: 'p'",
1724 });
1725
1726 ctx.objErrStage1("invalid underscore placement in int literal - 1",
1727 \\fn main() void {
1728 \\ var bad: u128 = 0010_;
1729 \\ _ = bad;
1730 \\}
1731 , &[_][]const u8{
1732 "tmp.zig:2:21: error: expected expression, found 'invalid bytes'",
1733 "tmp.zig:2:26: note: invalid byte: ';'",
1734 });
1735
1736 ctx.objErrStage1("invalid underscore placement in int literal - 2",
1737 \\fn main() void {
1738 \\ var bad: u128 = 0b0010_;
1739 \\ _ = bad;
1740 \\}
1741 , &[_][]const u8{
1742 "tmp.zig:2:21: error: expected expression, found 'invalid bytes'",
1743 "tmp.zig:2:28: note: invalid byte: ';'",
1744 });
1745
1746 ctx.objErrStage1("invalid underscore placement in int literal - 3",
1747 \\fn main() void {
1748 \\ var bad: u128 = 0o0010_;
1749 \\ _ = bad;
1750 \\}
1751 , &[_][]const u8{
1752 "tmp.zig:2:21: error: expected expression, found 'invalid bytes'",
1753 "tmp.zig:2:28: note: invalid byte: ';'",
1754 });
1755
1756 ctx.objErrStage1("invalid underscore placement in int literal - 4",
1757 \\fn main() void {
1758 \\ var bad: u128 = 0x0010_;
1759 \\ _ = bad;
1760 \\}
1761 , &[_][]const u8{
1762 "tmp.zig:2:21: error: expected expression, found 'invalid bytes'",
1763 "tmp.zig:2:28: note: invalid byte: ';'",
1764 });
1765
1766 ctx.objErrStage1("comptime struct field, no init value",
1767 \\const Foo = struct {
1768 \\ comptime b: i32,
1769 \\};
1770 \\export fn entry() void {
1771 \\ var f: Foo = undefined;
1772 \\ _ = f;
1773 \\}
1774 , &[_][]const u8{
1775 "tmp.zig:2:5: error: comptime field without default initialization value",
1776 });
1777
1778 ctx.objErrStage1("bad usage of @call",
1779 \\export fn entry1() void {
1780 \\ @call(.{}, foo, {});
1781 \\}
1782 \\export fn entry2() void {
1783 \\ comptime @call(.{ .modifier = .never_inline }, foo, .{});
1784 \\}
1785 \\export fn entry3() void {
1786 \\ comptime @call(.{ .modifier = .never_tail }, foo, .{});
1787 \\}
1788 \\export fn entry4() void {
1789 \\ @call(.{ .modifier = .never_inline }, bar, .{});
1790 \\}
1791 \\export fn entry5(c: bool) void {
1792 \\ var baz = if (c) baz1 else baz2;
1793 \\ @call(.{ .modifier = .compile_time }, baz, .{});
1794 \\}
1795 \\fn foo() void {}
1796 \\fn bar() callconv(.Inline) void {}
1797 \\fn baz1() void {}
1798 \\fn baz2() void {}
1799 , &[_][]const u8{
1800 "tmp.zig:2:21: error: expected tuple or struct, found 'void'",
1801 "tmp.zig:5:14: error: unable to perform 'never_inline' call at compile-time",
1802 "tmp.zig:8:14: error: unable to perform 'never_tail' call at compile-time",
1803 "tmp.zig:11:5: error: no-inline call of inline function",
1804 "tmp.zig:15:5: error: the specified modifier requires a comptime-known function",
1805 });
1806
1807 ctx.objErrStage1("exported async function",
1808 \\export fn foo() callconv(.Async) void {}
1809 , &[_][]const u8{
1810 "tmp.zig:1:1: error: exported function cannot be async",
1811 });
1812
1813 ctx.exeErrStage1("main missing name",
1814 \\pub fn (main) void {}
1815 , &[_][]const u8{
1816 "tmp.zig:1:5: error: missing function name",
1817 });
1818
1819 {
1820 const case = ctx.obj("call with new stack on unsupported target", .{
1821 .cpu_arch = .wasm32,
1822 .os_tag = .wasi,
1823 .abi = .none,
1824 });
1825 case.backend = .stage1;
1826 case.addError(
1827 \\var buf: [10]u8 align(16) = undefined;
1828 \\export fn entry() void {
1829 \\ @call(.{.stack = &buf}, foo, .{});
1830 \\}
1831 \\fn foo() void {}
1832 , &[_][]const u8{
1833 "tmp.zig:3:5: error: target arch 'wasm32' does not support calling with a new stack",
1834 });
1835 }
1836
1837 // Note: One of the error messages here is backwards. It would be nice to fix, but that's not
1838 // going to stop me from merging this branch which fixes a bunch of other stuff.
1839 ctx.objErrStage1("incompatible sentinels",
1840 \\export fn entry1(ptr: [*:255]u8) [*:0]u8 {
1841 \\ return ptr;
1842 \\}
1843 \\export fn entry2(ptr: [*]u8) [*:0]u8 {
1844 \\ return ptr;
1845 \\}
1846 \\export fn entry3() void {
1847 \\ var array: [2:0]u8 = [_:255]u8{1, 2};
1848 \\ _ = array;
1849 \\}
1850 \\export fn entry4() void {
1851 \\ var array: [2:0]u8 = [_]u8{1, 2};
1852 \\ _ = array;
1853 \\}
1854 , &[_][]const u8{
1855 "tmp.zig:2:12: error: expected type '[*:0]u8', found '[*:255]u8'",
1856 "tmp.zig:2:12: note: destination pointer requires a terminating '0' sentinel, but source pointer has a terminating '255' sentinel",
1857 "tmp.zig:5:12: error: expected type '[*:0]u8', found '[*]u8'",
1858 "tmp.zig:5:12: note: destination pointer requires a terminating '0' sentinel",
1859
1860 "tmp.zig:8:35: error: expected type '[2:255]u8', found '[2:0]u8'",
1861 "tmp.zig:8:35: note: destination array requires a terminating '255' sentinel, but source array has a terminating '0' sentinel",
1862 "tmp.zig:12:31: error: expected type '[2:0]u8', found '[2]u8'",
1863 "tmp.zig:12:31: note: destination array requires a terminating '0' sentinel",
1864 });
1865
1866 ctx.objErrStage1("empty switch on an integer",
1867 \\export fn entry() void {
1868 \\ var x: u32 = 0;
1869 \\ switch(x) {}
1870 \\}
1871 , &[_][]const u8{
1872 "tmp.zig:3:5: error: switch must handle all possibilities",
1873 });
1874
1875 ctx.objErrStage1("incorrect return type",
1876 \\ pub export fn entry() void{
1877 \\ _ = foo();
1878 \\ }
1879 \\ const A = struct {
1880 \\ a: u32,
1881 \\ };
1882 \\ fn foo() A {
1883 \\ return bar();
1884 \\ }
1885 \\ const B = struct {
1886 \\ a: u32,
1887 \\ };
1888 \\ fn bar() B {
1889 \\ unreachable;
1890 \\ }
1891 , &[_][]const u8{
1892 "tmp.zig:8:16: error: expected type 'A', found 'B'",
1893 });
1894
1895 ctx.objErrStage1("regression test #2980: base type u32 is not type checked properly when assigning a value within a struct",
1896 \\const Foo = struct {
1897 \\ ptr: ?*usize,
1898 \\ uval: u32,
1899 \\};
1900 \\fn get_uval(x: u32) !u32 {
1901 \\ _ = x;
1902 \\ return error.NotFound;
1903 \\}
1904 \\export fn entry() void {
1905 \\ const afoo = Foo{
1906 \\ .ptr = null,
1907 \\ .uval = get_uval(42),
1908 \\ };
1909 \\ _ = afoo;
1910 \\}
1911 , &[_][]const u8{
1912 "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'",
1913 });
1914
1915 ctx.objErrStage1("assigning to struct or union fields that are not optionals with a function that returns an optional",
1916 \\fn maybe(is: bool) ?u8 {
1917 \\ if (is) return @as(u8, 10) else return null;
1918 \\}
1919 \\const U = union {
1920 \\ Ye: u8,
1921 \\};
1922 \\const S = struct {
1923 \\ num: u8,
1924 \\};
1925 \\export fn entry() void {
1926 \\ var u = U{ .Ye = maybe(false) };
1927 \\ var s = S{ .num = maybe(false) };
1928 \\ _ = u;
1929 \\ _ = s;
1930 \\}
1931 , &[_][]const u8{
1932 "tmp.zig:11:27: error: cannot convert optional to payload type. consider using `.?`, `orelse`, or `if`. expected type 'u8', found '?u8'",
1933 });
1934
1935 ctx.objErrStage1("missing result type for phi node",
1936 \\fn foo() !void {
1937 \\ return anyerror.Foo;
1938 \\}
1939 \\export fn entry() void {
1940 \\ foo() catch 0;
1941 \\}
1942 , &[_][]const u8{
1943 "tmp.zig:5:17: error: integer value 0 cannot be coerced to type 'void'",
1944 });
1945
1946 ctx.objErrStage1("atomicrmw with enum op not .Xchg",
1947 \\export fn entry() void {
1948 \\ const E = enum(u8) {
1949 \\ a,
1950 \\ b,
1951 \\ c,
1952 \\ d,
1953 \\ };
1954 \\ var x: E = .a;
1955 \\ _ = @atomicRmw(E, &x, .Add, .b, .SeqCst);
1956 \\}
1957 , &[_][]const u8{
1958 "tmp.zig:9:27: error: @atomicRmw with enum only allowed with .Xchg",
1959 });
1960
1961 ctx.objErrStage1("disallow coercion from non-null-terminated pointer to null-terminated pointer",
1962 \\extern fn puts(s: [*:0]const u8) c_int;
1963 \\pub fn main() void {
1964 \\ const no_zero_array = [_]u8{'h', 'e', 'l', 'l', 'o'};
1965 \\ const no_zero_ptr: [*]const u8 = &no_zero_array;
1966 \\ _ = puts(no_zero_ptr);
1967 \\}
1968 , &[_][]const u8{
1969 "tmp.zig:5:14: error: expected type '[*:0]const u8', found '[*]const u8'",
1970 });
1971
1972 ctx.objErrStage1("atomic orderings of atomicStore Acquire or AcqRel",
1973 \\export fn entry() void {
1974 \\ var x: u32 = 0;
1975 \\ @atomicStore(u32, &x, 1, .Acquire);
1976 \\}
1977 , &[_][]const u8{
1978 "tmp.zig:3:30: error: @atomicStore atomic ordering must not be Acquire or AcqRel",
1979 });
1980
1981 ctx.objErrStage1("missing const in slice with nested array type",
1982 \\const Geo3DTex2D = struct { vertices: [][2]f32 };
1983 \\pub fn getGeo3DTex2D() Geo3DTex2D {
1984 \\ return Geo3DTex2D{
1985 \\ .vertices = [_][2]f32{
1986 \\ [_]f32{ -0.5, -0.5},
1987 \\ },
1988 \\ };
1989 \\}
1990 \\export fn entry() void {
1991 \\ var geo_data = getGeo3DTex2D();
1992 \\ _ = geo_data;
1993 \\}
1994 , &[_][]const u8{
1995 "tmp.zig:4:30: error: array literal requires address-of operator (&) to coerce to slice type '[][2]f32'",
1996 });
1997
1998 ctx.objErrStage1("slicing of global undefined pointer",
1999 \\var buf: *[1]u8 = undefined;
2000 \\export fn entry() void {
2001 \\ _ = buf[0..1];
2002 \\}
2003 , &[_][]const u8{
2004 "tmp.zig:3:12: error: non-zero length slice of undefined pointer",
2005 });
2006
2007 ctx.objErrStage1("using invalid types in function call raises an error",
2008 \\const MenuEffect = enum {};
2009 \\fn func(effect: MenuEffect) void { _ = effect; }
2010 \\export fn entry() void {
2011 \\ func(MenuEffect.ThisDoesNotExist);
2012 \\}
2013 , &[_][]const u8{
2014 "tmp.zig:1:20: error: enum declarations must have at least one tag",
2015 });
2016
2017 ctx.objErrStage1("store vector pointer with unknown runtime index",
2018 \\export fn entry() void {
2019 \\ var v: @import("std").meta.Vector(4, i32) = [_]i32{ 1, 5, 3, undefined };
2020 \\
2021 \\ var i: u32 = 0;
2022 \\ storev(&v[i], 42);
2023 \\}
2024 \\
2025 \\fn storev(ptr: anytype, val: i32) void {
2026 \\ ptr.* = val;
2027 \\}
2028 , &[_][]const u8{
2029 "tmp.zig:9:8: error: unable to determine vector element index of type '*align(16:0:4:?) i32",
2030 });
2031
2032 ctx.objErrStage1("load vector pointer with unknown runtime index",
2033 \\export fn entry() void {
2034 \\ var v: @import("std").meta.Vector(4, i32) = [_]i32{ 1, 5, 3, undefined };
2035 \\
2036 \\ var i: u32 = 0;
2037 \\ var x = loadv(&v[i]);
2038 \\ _ = x;
2039 \\}
2040 \\
2041 \\fn loadv(ptr: anytype) i32 {
2042 \\ return ptr.*;
2043 \\}
2044 , &[_][]const u8{
2045 "tmp.zig:10:12: error: unable to determine vector element index of type '*align(16:0:4:?) i32",
2046 });
2047
2048 ctx.objErrStage1("using an unknown len ptr type instead of array",
2049 \\const resolutions = [*][*]const u8{
2050 \\ "[320 240 ]",
2051 \\ null,
2052 \\};
2053 \\comptime {
2054 \\ _ = resolutions;
2055 \\}
2056 , &[_][]const u8{
2057 "tmp.zig:1:21: error: expected array type or [_], found '[*][*]const u8'",
2058 });
2059
2060 ctx.objErrStage1("comparison with error union and error value",
2061 \\export fn entry() void {
2062 \\ var number_or_error: anyerror!i32 = error.SomethingAwful;
2063 \\ _ = number_or_error == error.SomethingAwful;
2064 \\}
2065 , &[_][]const u8{
2066 "tmp.zig:3:25: error: operator not allowed for type 'anyerror!i32'",
2067 });
2068
2069 ctx.objErrStage1("switch with overlapping case ranges",
2070 \\export fn entry() void {
2071 \\ var q: u8 = 0;
2072 \\ switch (q) {
2073 \\ 1...2 => {},
2074 \\ 0...255 => {},
2075 \\ }
2076 \\}
2077 , &[_][]const u8{
2078 "tmp.zig:5:9: error: duplicate switch value",
2079 });
2080
2081 ctx.objErrStage1("invalid optional type in extern struct",
2082 \\const stroo = extern struct {
2083 \\ moo: ?[*c]u8,
2084 \\};
2085 \\export fn testf(fluff: *stroo) void { _ = fluff; }
2086 , &[_][]const u8{
2087 "tmp.zig:2:5: error: extern structs cannot contain fields of type '?[*c]u8'",
2088 });
2089
2090 ctx.objErrStage1("attempt to negate a non-integer, non-float or non-vector type",
2091 \\fn foo() anyerror!u32 {
2092 \\ return 1;
2093 \\}
2094 \\
2095 \\export fn entry() void {
2096 \\ const x = -foo();
2097 \\ _ = x;
2098 \\}
2099 , &[_][]const u8{
2100 "tmp.zig:6:15: error: negation of type 'anyerror!u32'",
2101 });
2102
2103 ctx.objErrStage1("attempt to create 17 bit float type",
2104 \\const builtin = @import("std").builtin;
2105 \\comptime {
2106 \\ _ = @Type(.{ .Float = .{ .bits = 17 } });
2107 \\}
2108 , &[_][]const u8{
2109 "tmp.zig:3:16: error: 17-bit float unsupported",
2110 });
2111
2112 ctx.objErrStage1("wrong type for @Type",
2113 \\export fn entry() void {
2114 \\ _ = @Type(0);
2115 \\}
2116 , &[_][]const u8{
2117 "tmp.zig:2:15: error: expected type 'std.builtin.Type', found 'comptime_int'",
2118 });
2119
2120 ctx.objErrStage1("@Type with non-constant expression",
2121 \\const builtin = @import("std").builtin;
2122 \\var globalTypeInfo : builtin.Type = undefined;
2123 \\export fn entry() void {
2124 \\ _ = @Type(globalTypeInfo);
2125 \\}
2126 , &[_][]const u8{
2127 "tmp.zig:4:15: error: unable to evaluate constant expression",
2128 });
2129
2130 ctx.objErrStage1("wrong type for argument tuple to @asyncCall",
2131 \\export fn entry1() void {
2132 \\ var frame: @Frame(foo) = undefined;
2133 \\ @asyncCall(&frame, {}, foo, {});
2134 \\}
2135 \\
2136 \\fn foo() i32 {
2137 \\ return 0;
2138 \\}
2139 , &[_][]const u8{
2140 "tmp.zig:3:33: error: expected tuple or struct, found 'void'",
2141 });
2142
2143 ctx.objErrStage1("wrong type for result ptr to @asyncCall",
2144 \\export fn entry() void {
2145 \\ _ = async amain();
2146 \\}
2147 \\fn amain() i32 {
2148 \\ var frame: @Frame(foo) = undefined;
2149 \\ return await @asyncCall(&frame, false, foo, .{});
2150 \\}
2151 \\fn foo() i32 {
2152 \\ return 1234;
2153 \\}
2154 , &[_][]const u8{
2155 "tmp.zig:6:37: error: expected type '*i32', found 'bool'",
2156 });
2157
2158 ctx.objErrStage1("shift amount has to be an integer type",
2159 \\export fn entry() void {
2160 \\ const x = 1 << &@as(u8, 10);
2161 \\ _ = x;
2162 \\}
2163 , &[_][]const u8{
2164 "tmp.zig:2:21: error: shift amount has to be an integer type, but found '*const u8'",
2165 });
2166
2167 ctx.objErrStage1("bit shifting only works on integer types",
2168 \\export fn entry() void {
2169 \\ const x = &@as(u8, 1) << 10;
2170 \\ _ = x;
2171 \\}
2172 , &[_][]const u8{
2173 "tmp.zig:2:16: error: bit shifting operation expected integer type, found '*const u8'",
2174 });
2175
2176 ctx.objErrStage1("struct depends on itself via optional field",
2177 \\const LhsExpr = struct {
2178 \\ rhsExpr: ?AstObject,
2179 \\};
2180 \\const AstObject = union {
2181 \\ lhsExpr: LhsExpr,
2182 \\};
2183 \\export fn entry() void {
2184 \\ const lhsExpr = LhsExpr{ .rhsExpr = null };
2185 \\ const obj = AstObject{ .lhsExpr = lhsExpr };
2186 \\ _ = obj;
2187 \\}
2188 , &[_][]const u8{
2189 "tmp.zig:1:17: error: struct 'LhsExpr' depends on itself",
2190 "tmp.zig:5:5: note: while checking this field",
2191 "tmp.zig:2:5: note: while checking this field",
2192 });
2193
2194 ctx.objErrStage1("alignment of enum field specified",
2195 \\const Number = enum {
2196 \\ a,
2197 \\ b align(i32),
2198 \\};
2199 \\export fn entry1() void {
2200 \\ var x: Number = undefined;
2201 \\ _ = x;
2202 \\}
2203 , &[_][]const u8{
2204 "tmp.zig:3:7: error: expected ',' after field",
2205 });
2206
2207 ctx.objErrStage1("bad alignment type",
2208 \\export fn entry1() void {
2209 \\ var x: []align(true) i32 = undefined;
2210 \\ _ = x;
2211 \\}
2212 \\export fn entry2() void {
2213 \\ var x: *align(@as(f64, 12.34)) i32 = undefined;
2214 \\ _ = x;
2215 \\}
2216 , &[_][]const u8{
2217 "tmp.zig:2:20: error: expected type 'u29', found 'bool'",
2218 "tmp.zig:6:19: error: fractional component prevents float value 12.340000 from being casted to type 'u29'",
2219 });
2220
2221 {
2222 const case = ctx.obj("variable in inline assembly template cannot be found", .{
2223 .cpu_arch = .x86_64,
2224 .os_tag = .linux,
2225 .abi = .gnu,
2226 });
2227 case.backend = .stage1;
2228 case.addError(
2229 \\export fn entry() void {
2230 \\ var sp = asm volatile (
2231 \\ "mov %[foo], sp"
2232 \\ : [bar] "=r" (-> usize)
2233 \\ );
2234 \\ _ = sp;
2235 \\}
2236 , &[_][]const u8{
2237 "tmp.zig:2:14: error: could not find 'foo' in the inputs or outputs",
2238 });
2239 }
2240
2241 ctx.objErrStage1("indirect recursion of async functions detected",
2242 \\var frame: ?anyframe = null;
2243 \\
2244 \\export fn a() void {
2245 \\ _ = async rangeSum(10);
2246 \\ while (frame) |f| resume f;
2247 \\}
2248 \\
2249 \\fn rangeSum(x: i32) i32 {
2250 \\ suspend {
2251 \\ frame = @frame();
2252 \\ }
2253 \\ frame = null;
2254 \\
2255 \\ if (x == 0) return 0;
2256 \\ var child = rangeSumIndirect(x - 1);
2257 \\ return child + 1;
2258 \\}
2259 \\
2260 \\fn rangeSumIndirect(x: i32) i32 {
2261 \\ suspend {
2262 \\ frame = @frame();
2263 \\ }
2264 \\ frame = null;
2265 \\
2266 \\ if (x == 0) return 0;
2267 \\ var child = rangeSum(x - 1);
2268 \\ return child + 1;
2269 \\}
2270 , &[_][]const u8{
2271 "tmp.zig:8:1: error: '@Frame(rangeSum)' depends on itself",
2272 "tmp.zig:15:33: note: when analyzing type '@Frame(rangeSum)' here",
2273 "tmp.zig:26:25: note: when analyzing type '@Frame(rangeSumIndirect)' here",
2274 });
2275
2276 ctx.objErrStage1("non-async function pointer eventually is inferred to become async",
2277 \\export fn a() void {
2278 \\ var non_async_fn: fn () void = undefined;
2279 \\ non_async_fn = func;
2280 \\}
2281 \\fn func() void {
2282 \\ suspend {}
2283 \\}
2284 , &[_][]const u8{
2285 "tmp.zig:5:1: error: 'func' cannot be async",
2286 "tmp.zig:3:20: note: required to be non-async here",
2287 "tmp.zig:6:5: note: suspends here",
2288 });
2289
2290 {
2291 const case = ctx.obj("bad alignment in @asyncCall", .{
2292 .cpu_arch = .aarch64,
2293 .os_tag = .linux,
2294 .abi = .none,
2295 });
2296 case.backend = .stage1;
2297 case.addError(
2298 \\export fn entry() void {
2299 \\ var ptr: fn () callconv(.Async) void = func;
2300 \\ var bytes: [64]u8 = undefined;
2301 \\ _ = @asyncCall(&bytes, {}, ptr, .{});
2302 \\}
2303 \\fn func() callconv(.Async) void {}
2304 , &[_][]const u8{
2305 "tmp.zig:4:21: error: expected type '[]align(8) u8', found '*[64]u8'",
2306 });
2307 }
2308
2309 ctx.objErrStage1("atomic orderings of fence Acquire or stricter",
2310 \\export fn entry() void {
2311 \\ @fence(.Monotonic);
2312 \\}
2313 , &[_][]const u8{
2314 "tmp.zig:2:12: error: atomic ordering must be Acquire or stricter",
2315 });
2316
2317 ctx.objErrStage1("bad alignment in implicit cast from array pointer to slice",
2318 \\export fn a() void {
2319 \\ var x: [10]u8 = undefined;
2320 \\ var y: []align(16) u8 = &x;
2321 \\ _ = y;
2322 \\}
2323 , &[_][]const u8{
2324 "tmp.zig:3:30: error: expected type '[]align(16) u8', found '*[10]u8'",
2325 });
2326
2327 ctx.objErrStage1("result location incompatibility mismatching handle_is_ptr (generic call)",
2328 \\export fn entry() void {
2329 \\ var damn = Container{
2330 \\ .not_optional = getOptional(i32),
2331 \\ };
2332 \\ _ = damn;
2333 \\}
2334 \\pub fn getOptional(comptime T: type) ?T {
2335 \\ return 0;
2336 \\}
2337 \\pub const Container = struct {
2338 \\ not_optional: i32,
2339 \\};
2340 , &[_][]const u8{
2341 "tmp.zig:3:36: error: cannot convert optional to payload type. consider using `.?`, `orelse`, or `if`. expected type 'i32', found '?i32'",
2342 });
2343
2344 ctx.objErrStage1("result location incompatibility mismatching handle_is_ptr",
2345 \\export fn entry() void {
2346 \\ var damn = Container{
2347 \\ .not_optional = getOptional(),
2348 \\ };
2349 \\ _ = damn;
2350 \\}
2351 \\pub fn getOptional() ?i32 {
2352 \\ return 0;
2353 \\}
2354 \\pub const Container = struct {
2355 \\ not_optional: i32,
2356 \\};
2357 , &[_][]const u8{
2358 "tmp.zig:3:36: error: cannot convert optional to payload type. consider using `.?`, `orelse`, or `if`. expected type 'i32', found '?i32'",
2359 });
2360
2361 ctx.objErrStage1("const frame cast to anyframe",
2362 \\export fn a() void {
2363 \\ const f = async func();
2364 \\ resume f;
2365 \\}
2366 \\export fn b() void {
2367 \\ const f = async func();
2368 \\ var x: anyframe = &f;
2369 \\ _ = x;
2370 \\}
2371 \\fn func() void {
2372 \\ suspend {}
2373 \\}
2374 , &[_][]const u8{
2375 "tmp.zig:3:12: error: expected type 'anyframe', found '*const @Frame(func)'",
2376 "tmp.zig:7:24: error: expected type 'anyframe', found '*const @Frame(func)'",
2377 });
2378
2379 ctx.objErrStage1("prevent bad implicit casting of anyframe types",
2380 \\export fn a() void {
2381 \\ var x: anyframe = undefined;
2382 \\ var y: anyframe->i32 = x;
2383 \\ _ = y;
2384 \\}
2385 \\export fn b() void {
2386 \\ var x: i32 = undefined;
2387 \\ var y: anyframe->i32 = x;
2388 \\ _ = y;
2389 \\}
2390 \\export fn c() void {
2391 \\ var x: @Frame(func) = undefined;
2392 \\ var y: anyframe->i32 = &x;
2393 \\ _ = y;
2394 \\}
2395 \\fn func() void {}
2396 , &[_][]const u8{
2397 "tmp.zig:3:28: error: expected type 'anyframe->i32', found 'anyframe'",
2398 "tmp.zig:8:28: error: expected type 'anyframe->i32', found 'i32'",
2399 "tmp.zig:13:29: error: expected type 'anyframe->i32', found '*@Frame(func)'",
2400 });
2401
2402 ctx.objErrStage1("wrong frame type used for async call",
2403 \\export fn entry() void {
2404 \\ var frame: @Frame(foo) = undefined;
2405 \\ frame = async bar();
2406 \\}
2407 \\fn foo() void {
2408 \\ suspend {}
2409 \\}
2410 \\fn bar() void {
2411 \\ suspend {}
2412 \\}
2413 , &[_][]const u8{
2414 "tmp.zig:3:13: error: expected type '*@Frame(bar)', found '*@Frame(foo)'",
2415 });
2416
2417 ctx.objErrStage1("@Frame() of generic function",
2418 \\export fn entry() void {
2419 \\ var frame: @Frame(func) = undefined;
2420 \\ _ = frame;
2421 \\}
2422 \\fn func(comptime T: type) void {
2423 \\ var x: T = undefined;
2424 \\ _ = x;
2425 \\}
2426 , &[_][]const u8{
2427 "tmp.zig:2:16: error: @Frame() of generic function",
2428 });
2429
2430 ctx.objErrStage1("@frame() causes function to be async",
2431 \\export fn entry() void {
2432 \\ func();
2433 \\}
2434 \\fn func() void {
2435 \\ _ = @frame();
2436 \\}
2437 , &[_][]const u8{
2438 "tmp.zig:1:1: error: function with calling convention 'C' cannot be async",
2439 "tmp.zig:5:9: note: @frame() causes function to be async",
2440 });
2441
2442 ctx.objErrStage1("invalid suspend in exported function",
2443 \\export fn entry() void {
2444 \\ var frame = async func();
2445 \\ var result = await frame;
2446 \\ _ = result;
2447 \\}
2448 \\fn func() void {
2449 \\ suspend {}
2450 \\}
2451 , &[_][]const u8{
2452 "tmp.zig:1:1: error: function with calling convention 'C' cannot be async",
2453 "tmp.zig:3:18: note: await here is a suspend point",
2454 });
2455
2456 ctx.objErrStage1("async function indirectly depends on its own frame",
2457 \\export fn entry() void {
2458 \\ _ = async amain();
2459 \\}
2460 \\fn amain() callconv(.Async) void {
2461 \\ other();
2462 \\}
2463 \\fn other() void {
2464 \\ var x: [@sizeOf(@Frame(amain))]u8 = undefined;
2465 \\ _ = x;
2466 \\}
2467 , &[_][]const u8{
2468 "tmp.zig:4:1: error: unable to determine async function frame of 'amain'",
2469 "tmp.zig:5:10: note: analysis of function 'other' depends on the frame",
2470 });
2471
2472 ctx.objErrStage1("async function depends on its own frame",
2473 \\export fn entry() void {
2474 \\ _ = async amain();
2475 \\}
2476 \\fn amain() callconv(.Async) void {
2477 \\ var x: [@sizeOf(@Frame(amain))]u8 = undefined;
2478 \\ _ = x;
2479 \\}
2480 , &[_][]const u8{
2481 "tmp.zig:4:1: error: cannot resolve '@Frame(amain)': function not fully analyzed yet",
2482 });
2483
2484 ctx.objErrStage1("non async function pointer passed to @asyncCall",
2485 \\export fn entry() void {
2486 \\ var ptr = afunc;
2487 \\ var bytes: [100]u8 align(16) = undefined;
2488 \\ _ = @asyncCall(&bytes, {}, ptr, .{});
2489 \\}
2490 \\fn afunc() void { }
2491 , &[_][]const u8{
2492 "tmp.zig:4:32: error: expected async function, found 'fn() void'",
2493 });
2494
2495 ctx.objErrStage1("runtime-known async function called",
2496 \\export fn entry() void {
2497 \\ _ = async amain();
2498 \\}
2499 \\fn amain() void {
2500 \\ var ptr = afunc;
2501 \\ _ = ptr();
2502 \\}
2503 \\fn afunc() callconv(.Async) void {}
2504 , &[_][]const u8{
2505 "tmp.zig:6:12: error: function is not comptime-known; @asyncCall required",
2506 });
2507
2508 ctx.objErrStage1("runtime-known function called with async keyword",
2509 \\export fn entry() void {
2510 \\ var ptr = afunc;
2511 \\ _ = async ptr();
2512 \\}
2513 \\
2514 \\fn afunc() callconv(.Async) void { }
2515 , &[_][]const u8{
2516 "tmp.zig:3:15: error: function is not comptime-known; @asyncCall required",
2517 });
2518
2519 ctx.objErrStage1("function with ccc indirectly calling async function",
2520 \\export fn entry() void {
2521 \\ foo();
2522 \\}
2523 \\fn foo() void {
2524 \\ bar();
2525 \\}
2526 \\fn bar() void {
2527 \\ suspend {}
2528 \\}
2529 , &[_][]const u8{
2530 "tmp.zig:1:1: error: function with calling convention 'C' cannot be async",
2531 "tmp.zig:2:8: note: async function call here",
2532 "tmp.zig:5:8: note: async function call here",
2533 "tmp.zig:8:5: note: suspends here",
2534 });
2535
2536 ctx.objErrStage1("capture group on switch prong with incompatible payload types",
2537 \\const Union = union(enum) {
2538 \\ A: usize,
2539 \\ B: isize,
2540 \\};
2541 \\comptime {
2542 \\ var u = Union{ .A = 8 };
2543 \\ switch (u) {
2544 \\ .A, .B => |e| {
2545 \\ _ = e;
2546 \\ unreachable;
2547 \\ },
2548 \\ }
2549 \\}
2550 , &[_][]const u8{
2551 "tmp.zig:8:20: error: capture group with incompatible types",
2552 "tmp.zig:8:9: note: type 'usize' here",
2553 "tmp.zig:8:13: note: type 'isize' here",
2554 });
2555
2556 ctx.objErrStage1("wrong type to @hasField",
2557 \\export fn entry() bool {
2558 \\ return @hasField(i32, "hi");
2559 \\}
2560 , &[_][]const u8{
2561 "tmp.zig:2:22: error: type 'i32' does not support @hasField",
2562 });
2563
2564 ctx.objErrStage1("slice passed as array init type with elems",
2565 \\export fn entry() void {
2566 \\ const x = []u8{1, 2};
2567 \\ _ = x;
2568 \\}
2569 , &[_][]const u8{
2570 "tmp.zig:2:15: error: array literal requires address-of operator (&) to coerce to slice type '[]u8'",
2571 });
2572
2573 ctx.objErrStage1("slice passed as array init type",
2574 \\export fn entry() void {
2575 \\ const x = []u8{};
2576 \\ _ = x;
2577 \\}
2578 , &[_][]const u8{
2579 "tmp.zig:2:15: error: array literal requires address-of operator (&) to coerce to slice type '[]u8'",
2580 });
2581
2582 ctx.objErrStage1("inferred array size invalid here",
2583 \\export fn entry() void {
2584 \\ const x = [_]u8;
2585 \\ _ = x;
2586 \\}
2587 \\export fn entry2() void {
2588 \\ const S = struct { a: *const [_]u8 };
2589 \\ var a = .{ S{} };
2590 \\ _ = a;
2591 \\}
2592 , &[_][]const u8{
2593 "tmp.zig:2:16: error: unable to infer array size",
2594 "tmp.zig:6:35: error: unable to infer array size",
2595 });
2596
2597 ctx.objErrStage1("initializing array with struct syntax",
2598 \\export fn entry() void {
2599 \\ const x = [_]u8{ .y = 2 };
2600 \\ _ = x;
2601 \\}
2602 , &[_][]const u8{
2603 "tmp.zig:2:15: error: initializing array with struct syntax",
2604 });
2605
2606 ctx.objErrStage1("compile error in struct init expression",
2607 \\const Foo = struct {
2608 \\ a: i32 = crap,
2609 \\ b: i32,
2610 \\};
2611 \\export fn entry() void {
2612 \\ var x = Foo{
2613 \\ .b = 5,
2614 \\ };
2615 \\ _ = x;
2616 \\}
2617 , &[_][]const u8{
2618 "tmp.zig:2:14: error: use of undeclared identifier 'crap'",
2619 });
2620
2621 ctx.objErrStage1("undefined as field type is rejected",
2622 \\const Foo = struct {
2623 \\ a: undefined,
2624 \\};
2625 \\export fn entry1() void {
2626 \\ const foo: Foo = undefined;
2627 \\ _ = foo;
2628 \\}
2629 , &[_][]const u8{
2630 "tmp.zig:2:8: error: use of undefined value here causes undefined behavior",
2631 });
2632
2633 ctx.objErrStage1("@hasDecl with non-container",
2634 \\export fn entry() void {
2635 \\ _ = @hasDecl(i32, "hi");
2636 \\}
2637 , &[_][]const u8{
2638 "tmp.zig:2:18: error: expected struct, enum, or union; found 'i32'",
2639 });
2640
2641 ctx.objErrStage1("field access of slices",
2642 \\export fn entry() void {
2643 \\ var slice: []i32 = undefined;
2644 \\ const info = @TypeOf(slice).unknown;
2645 \\ _ = info;
2646 \\}
2647 , &[_][]const u8{
2648 "tmp.zig:3:32: error: type 'type' does not support field access",
2649 });
2650
2651 ctx.objErrStage1("peer cast then implicit cast const pointer to mutable C pointer",
2652 \\export fn func() void {
2653 \\ var strValue: [*c]u8 = undefined;
2654 \\ strValue = strValue orelse "";
2655 \\}
2656 , &[_][]const u8{
2657 "tmp.zig:3:32: error: expected type '[*c]u8', found '*const [0:0]u8'",
2658 "tmp.zig:3:32: note: cast discards const qualifier",
2659 });
2660
2661 ctx.objErrStage1("overflow in enum value allocation",
2662 \\const Moo = enum(u8) {
2663 \\ Last = 255,
2664 \\ Over,
2665 \\};
2666 \\pub fn main() void {
2667 \\ var y = Moo.Last;
2668 \\ _ = y;
2669 \\}
2670 , &[_][]const u8{
2671 "tmp.zig:3:5: error: enumeration value 256 too large for type 'u8'",
2672 });
2673
2674 ctx.objErrStage1("attempt to cast enum literal to error",
2675 \\export fn entry() void {
2676 \\ switch (error.Hi) {
2677 \\ .Hi => {},
2678 \\ }
2679 \\}
2680 , &[_][]const u8{
2681 "tmp.zig:3:9: error: expected type 'error{Hi}', found '@Type(.EnumLiteral)'",
2682 });
2683
2684 ctx.objErrStage1("@sizeOf bad type",
2685 \\export fn entry() usize {
2686 \\ return @sizeOf(@TypeOf(null));
2687 \\}
2688 , &[_][]const u8{
2689 "tmp.zig:2:20: error: no size available for type '@Type(.Null)'",
2690 });
2691
2692 ctx.objErrStage1("generic function where return type is self-referenced",
2693 \\fn Foo(comptime T: type) Foo(T) {
2694 \\ return struct{ x: T };
2695 \\}
2696 \\export fn entry() void {
2697 \\ const t = Foo(u32) {
2698 \\ .x = 1
2699 \\ };
2700 \\ _ = t;
2701 \\}
2702 , &[_][]const u8{
2703 "tmp.zig:1:29: error: evaluation exceeded 1000 backwards branches",
2704 });
2705
2706 ctx.objErrStage1("@ptrToInt 0 to non optional pointer",
2707 \\export fn entry() void {
2708 \\ var b = @intToPtr(*i32, 0);
2709 \\ _ = b;
2710 \\}
2711 , &[_][]const u8{
2712 "tmp.zig:2:13: error: pointer type '*i32' does not allow address zero",
2713 });
2714
2715 ctx.objErrStage1("cast enum literal to enum but it doesn't match",
2716 \\const Foo = enum {
2717 \\ a,
2718 \\ b,
2719 \\};
2720 \\export fn entry() void {
2721 \\ const x: Foo = .c;
2722 \\ _ = x;
2723 \\}
2724 , &[_][]const u8{
2725 "tmp.zig:6:20: error: enum 'Foo' has no field named 'c'",
2726 "tmp.zig:1:13: note: 'Foo' declared here",
2727 });
2728
2729 ctx.objErrStage1("discarding error value",
2730 \\export fn entry() void {
2731 \\ _ = foo();
2732 \\}
2733 \\fn foo() !void {
2734 \\ return error.OutOfMemory;
2735 \\}
2736 , &[_][]const u8{
2737 "tmp.zig:2:12: error: error is discarded. consider using `try`, `catch`, or `if`",
2738 });
2739
2740 ctx.objErrStage1("volatile on global assembly",
2741 \\comptime {
2742 \\ asm volatile ("");
2743 \\}
2744 , &[_][]const u8{
2745 "tmp.zig:2:9: error: volatile is meaningless on global assembly",
2746 });
2747
2748 ctx.objErrStage1("invalid multiple dereferences",
2749 \\export fn a() void {
2750 \\ var box = Box{ .field = 0 };
2751 \\ box.*.field = 1;
2752 \\}
2753 \\export fn b() void {
2754 \\ var box = Box{ .field = 0 };
2755 \\ var boxPtr = &box;
2756 \\ boxPtr.*.*.field = 1;
2757 \\}
2758 \\pub const Box = struct {
2759 \\ field: i32,
2760 \\};
2761 , &[_][]const u8{
2762 "tmp.zig:3:8: error: attempt to dereference non-pointer type 'Box'",
2763 "tmp.zig:8:13: error: attempt to dereference non-pointer type 'Box'",
2764 });
2765
2766 ctx.objErrStage1("usingnamespace with wrong type",
2767 \\usingnamespace void;
2768 , &[_][]const u8{
2769 "tmp.zig:1:1: error: expected struct, enum, or union; found 'void'",
2770 });
2771
2772 ctx.objErrStage1("ignored expression in while continuation",
2773 \\export fn a() void {
2774 \\ while (true) : (bad()) {}
2775 \\}
2776 \\export fn b() void {
2777 \\ var x: anyerror!i32 = 1234;
2778 \\ while (x) |_| : (bad()) {} else |_| {}
2779 \\}
2780 \\export fn c() void {
2781 \\ var x: ?i32 = 1234;
2782 \\ while (x) |_| : (bad()) {}
2783 \\}
2784 \\fn bad() anyerror!void {
2785 \\ return error.Bad;
2786 \\}
2787 , &[_][]const u8{
2788 "tmp.zig:2:24: error: error is ignored. consider using `try`, `catch`, or `if`",
2789 "tmp.zig:6:25: error: error is ignored. consider using `try`, `catch`, or `if`",
2790 "tmp.zig:10:25: error: error is ignored. consider using `try`, `catch`, or `if`",
2791 });
2792
2793 ctx.objErrStage1("empty while loop body",
2794 \\export fn a() void {
2795 \\ while(true);
2796 \\}
2797 , &[_][]const u8{
2798 "tmp.zig:2:16: error: expected block or assignment, found ';'",
2799 });
2800
2801 ctx.objErrStage1("empty for loop body",
2802 \\export fn a() void {
2803 \\ for(undefined) |x|;
2804 \\}
2805 , &[_][]const u8{
2806 "tmp.zig:2:23: error: expected block or assignment, found ';'",
2807 });
2808
2809 ctx.objErrStage1("empty if body",
2810 \\export fn a() void {
2811 \\ if(true);
2812 \\}
2813 , &[_][]const u8{
2814 "tmp.zig:2:13: error: expected block or assignment, found ';'",
2815 });
2816
2817 ctx.objErrStage1("import outside package path",
2818 \\comptime{
2819 \\ _ = @import("../a.zig");
2820 \\}
2821 , &[_][]const u8{
2822 "tmp.zig:2:9: error: import of file outside package path: '../a.zig'",
2823 });
2824
2825 ctx.objErrStage1("bogus compile var",
2826 \\const x = @import("builtin").bogus;
2827 \\export fn entry() usize { return @sizeOf(@TypeOf(x)); }
2828 , &[_][]const u8{
2829 "tmp.zig:1:29: error: container 'builtin' has no member called 'bogus'",
2830 });
2831
2832 ctx.objErrStage1("wrong panic signature, runtime function",
2833 \\test "" {}
2834 \\
2835 \\pub fn panic() void {}
2836 \\
2837 , &[_][]const u8{
2838 "error: expected type 'fn([]const u8, ?*std.builtin.StackTrace) noreturn', found 'fn() void'",
2839 });
2840
2841 ctx.objErrStage1("wrong panic signature, generic function",
2842 \\pub fn panic(comptime msg: []const u8, error_return_trace: ?*builtin.StackTrace) noreturn {
2843 \\ _ = msg; _ = error_return_trace;
2844 \\ while (true) {}
2845 \\}
2846 \\const builtin = @import("std").builtin;
2847 , &[_][]const u8{
2848 "error: expected type 'fn([]const u8, ?*std.builtin.StackTrace) noreturn', found 'fn([]const u8,anytype) anytype'",
2849 "note: only one of the functions is generic",
2850 });
2851
2852 ctx.objErrStage1("direct struct loop",
2853 \\const A = struct { a : A, };
2854 \\export fn entry() usize { return @sizeOf(A); }
2855 , &[_][]const u8{
2856 "tmp.zig:1:11: error: struct 'A' depends on itself",
2857 });
2858
2859 ctx.objErrStage1("indirect struct loop",
2860 \\const A = struct { b : B, };
2861 \\const B = struct { c : C, };
2862 \\const C = struct { a : A, };
2863 \\export fn entry() usize { return @sizeOf(A); }
2864 , &[_][]const u8{
2865 "tmp.zig:1:11: error: struct 'A' depends on itself",
2866 });
2867
2868 ctx.objErrStage1("instantiating an undefined value for an invalid struct that contains itself",
2869 \\const Foo = struct {
2870 \\ x: Foo,
2871 \\};
2872 \\
2873 \\var foo: Foo = undefined;
2874 \\
2875 \\export fn entry() usize {
2876 \\ return @sizeOf(@TypeOf(foo.x));
2877 \\}
2878 , &[_][]const u8{
2879 "tmp.zig:1:13: error: struct 'Foo' depends on itself",
2880 });
2881
2882 ctx.objErrStage1("enum field value references enum",
2883 \\pub const Foo = enum(c_int) {
2884 \\ A = Foo.B,
2885 \\ C = D,
2886 \\};
2887 \\export fn entry() void {
2888 \\ var s: Foo = Foo.E;
2889 \\ _ = s;
2890 \\}
2891 \\const D = 1;
2892 , &[_][]const u8{
2893 "tmp.zig:1:17: error: enum 'Foo' depends on itself",
2894 });
2895
2896 ctx.objErrStage1("top level decl dependency loop",
2897 \\const a : @TypeOf(b) = 0;
2898 \\const b : @TypeOf(a) = 0;
2899 \\export fn entry() void {
2900 \\ const c = a + b;
2901 \\ _ = c;
2902 \\}
2903 , &[_][]const u8{
2904 "tmp.zig:2:19: error: dependency loop detected",
2905 });
2906
2907 ctx.testErrStage1("not an enum type",
2908 \\export fn entry() void {
2909 \\ var self: Error = undefined;
2910 \\ switch (self) {
2911 \\ InvalidToken => |x| return x.token,
2912 \\ ExpectedVarDeclOrFn => |x| return x.token,
2913 \\ }
2914 \\}
2915 \\const Error = union(enum) {
2916 \\ A: InvalidToken,
2917 \\ B: ExpectedVarDeclOrFn,
2918 \\};
2919 \\const InvalidToken = struct {};
2920 \\const ExpectedVarDeclOrFn = struct {};
2921 , &[_][]const u8{
2922 "tmp.zig:4:9: error: expected type '@typeInfo(Error).Union.tag_type.?', found 'type'",
2923 });
2924
2925 ctx.testErrStage1("binary OR operator on error sets",
2926 \\pub const A = error.A;
2927 \\pub const AB = A | error.B;
2928 \\export fn entry() void {
2929 \\ var x: AB = undefined;
2930 \\ _ = x;
2931 \\}
2932 , &[_][]const u8{
2933 "tmp.zig:2:18: error: invalid operands to binary expression: 'error{A}' and 'error{B}'",
2934 });
2935
2936 if (builtin.os.tag == .linux) {
2937 ctx.testErrStage1("implicit dependency on libc",
2938 \\extern "c" fn exit(u8) void;
2939 \\export fn entry() void {
2940 \\ exit(0);
2941 \\}
2942 , &[_][]const u8{
2943 "tmp.zig:3:5: error: dependency on libc must be explicitly specified in the build command",
2944 });
2945
2946 ctx.testErrStage1("libc headers note",
2947 \\const c = @cImport(@cInclude("stdio.h"));
2948 \\export fn entry() void {
2949 \\ _ = c.printf("hello, world!\n");
2950 \\}
2951 , &[_][]const u8{
2952 "tmp.zig:1:11: error: C import failed",
2953 "tmp.zig:1:11: note: libc headers not available; compilation does not link against libc",
2954 });
2955 }
2956
2957 ctx.testErrStage1("comptime vector overflow shows the index",
2958 \\comptime {
2959 \\ var a: @import("std").meta.Vector(4, u8) = [_]u8{ 1, 2, 255, 4 };
2960 \\ var b: @import("std").meta.Vector(4, u8) = [_]u8{ 5, 6, 1, 8 };
2961 \\ var x = a + b;
2962 \\ _ = x;
2963 \\}
2964 , &[_][]const u8{
2965 "tmp.zig:4:15: error: operation caused overflow",
2966 "tmp.zig:4:15: note: when computing vector element at index 2",
2967 });
2968
2969 ctx.testErrStage1("packed struct with fields of not allowed types",
2970 \\const A = packed struct {
2971 \\ x: anyerror,
2972 \\};
2973 \\const B = packed struct {
2974 \\ x: [2]u24,
2975 \\};
2976 \\const C = packed struct {
2977 \\ x: [1]anyerror,
2978 \\};
2979 \\const D = packed struct {
2980 \\ x: [1]S,
2981 \\};
2982 \\const E = packed struct {
2983 \\ x: [1]U,
2984 \\};
2985 \\const F = packed struct {
2986 \\ x: ?anyerror,
2987 \\};
2988 \\const G = packed struct {
2989 \\ x: Enum,
2990 \\};
2991 \\export fn entry1() void {
2992 \\ var a: A = undefined;
2993 \\ _ = a;
2994 \\}
2995 \\export fn entry2() void {
2996 \\ var b: B = undefined;
2997 \\ _ = b;
2998 \\}
2999 \\export fn entry3() void {
3000 \\ var r: C = undefined;
3001 \\ _ = r;
3002 \\}
3003 \\export fn entry4() void {
3004 \\ var d: D = undefined;
3005 \\ _ = d;
3006 \\}
3007 \\export fn entry5() void {
3008 \\ var e: E = undefined;
3009 \\ _ = e;
3010 \\}
3011 \\export fn entry6() void {
3012 \\ var f: F = undefined;
3013 \\ _ = f;
3014 \\}
3015 \\export fn entry7() void {
3016 \\ var g: G = undefined;
3017 \\ _ = g;
3018 \\}
3019 \\const S = struct {
3020 \\ x: i32,
3021 \\};
3022 \\const U = struct {
3023 \\ A: i32,
3024 \\ B: u32,
3025 \\};
3026 \\const Enum = enum {
3027 \\ A,
3028 \\ B,
3029 \\};
3030 , &[_][]const u8{
3031 "tmp.zig:2:5: error: type 'anyerror' not allowed in packed struct; no guaranteed in-memory representation",
3032 "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)",
3033 "tmp.zig:8:5: error: type 'anyerror' not allowed in packed struct; no guaranteed in-memory representation",
3034 "tmp.zig:11:5: error: non-packed, non-extern struct 'S' not allowed in packed struct; no guaranteed in-memory representation",
3035 "tmp.zig:14:5: error: non-packed, non-extern struct 'U' not allowed in packed struct; no guaranteed in-memory representation",
3036 "tmp.zig:17:5: error: type '?anyerror' not allowed in packed struct; no guaranteed in-memory representation",
3037 "tmp.zig:20:5: error: type 'Enum' not allowed in packed struct; no guaranteed in-memory representation",
3038 "tmp.zig:57:14: note: enum declaration does not specify an integer tag type",
3039 });
3040
3041 ctx.objErrStage1("deduplicate undeclared identifier",
3042 \\export fn a() void {
3043 \\ x += 1;
3044 \\}
3045 \\export fn b() void {
3046 \\ x += 1;
3047 \\}
3048 , &[_][]const u8{
3049 "tmp.zig:2:5: error: use of undeclared identifier 'x'",
3050 });
3051
3052 ctx.objErrStage1("export generic function",
3053 \\export fn foo(num: anytype) i32 {
3054 \\ _ = num;
3055 \\ return 0;
3056 \\}
3057 , &[_][]const u8{
3058 "tmp.zig:1:15: error: parameter of type 'anytype' not allowed in function with calling convention 'C'",
3059 });
3060
3061 ctx.objErrStage1("C pointer to anyopaque",
3062 \\export fn a() void {
3063 \\ var x: *anyopaque = undefined;
3064 \\ var y: [*c]anyopaque = x;
3065 \\ _ = y;
3066 \\}
3067 , &[_][]const u8{
3068 "tmp.zig:3:16: error: C pointers cannot point to opaque types",
3069 });
3070
3071 ctx.objErrStage1("directly embedding opaque type in struct and union",
3072 \\const O = opaque {};
3073 \\const Foo = struct {
3074 \\ o: O,
3075 \\};
3076 \\const Bar = union {
3077 \\ One: i32,
3078 \\ Two: O,
3079 \\};
3080 \\export fn a() void {
3081 \\ var foo: Foo = undefined;
3082 \\ _ = foo;
3083 \\}
3084 \\export fn b() void {
3085 \\ var bar: Bar = undefined;
3086 \\ _ = bar;
3087 \\}
3088 \\export fn c() void {
3089 \\ var baz: *opaque {} = undefined;
3090 \\ const qux = .{baz.*};
3091 \\ _ = qux;
3092 \\}
3093 , &[_][]const u8{
3094 "tmp.zig:3:5: error: opaque types have unknown size and therefore cannot be directly embedded in structs",
3095 "tmp.zig:7:5: error: opaque types have unknown size and therefore cannot be directly embedded in unions",
3096 "tmp.zig:19:22: error: opaque types have unknown size and therefore cannot be directly embedded in structs",
3097 });
3098
3099 ctx.objErrStage1("implicit cast between C pointer and Zig pointer - bad const/align/child",
3100 \\export fn a() void {
3101 \\ var x: [*c]u8 = undefined;
3102 \\ var y: *align(4) u8 = x;
3103 \\ _ = y;
3104 \\}
3105 \\export fn b() void {
3106 \\ var x: [*c]const u8 = undefined;
3107 \\ var y: *u8 = x;
3108 \\ _ = y;
3109 \\}
3110 \\export fn c() void {
3111 \\ var x: [*c]u8 = undefined;
3112 \\ var y: *u32 = x;
3113 \\ _ = y;
3114 \\}
3115 \\export fn d() void {
3116 \\ var y: *align(1) u32 = undefined;
3117 \\ var x: [*c]u32 = y;
3118 \\ _ = x;
3119 \\}
3120 \\export fn e() void {
3121 \\ var y: *const u8 = undefined;
3122 \\ var x: [*c]u8 = y;
3123 \\ _ = x;
3124 \\}
3125 \\export fn f() void {
3126 \\ var y: *u8 = undefined;
3127 \\ var x: [*c]u32 = y;
3128 \\ _ = x;
3129 \\}
3130 , &[_][]const u8{
3131 "tmp.zig:3:27: error: cast increases pointer alignment",
3132 "tmp.zig:8:18: error: cast discards const qualifier",
3133 "tmp.zig:13:19: error: expected type '*u32', found '[*c]u8'",
3134 "tmp.zig:13:19: note: pointer type child 'u8' cannot cast into pointer type child 'u32'",
3135 "tmp.zig:18:22: error: cast increases pointer alignment",
3136 "tmp.zig:23:21: error: cast discards const qualifier",
3137 "tmp.zig:28:22: error: expected type '[*c]u32', found '*u8'",
3138 });
3139
3140 ctx.objErrStage1("implicit casting null c pointer to zig pointer",
3141 \\comptime {
3142 \\ var c_ptr: [*c]u8 = 0;
3143 \\ var zig_ptr: *u8 = c_ptr;
3144 \\ _ = zig_ptr;
3145 \\}
3146 , &[_][]const u8{
3147 "tmp.zig:3:24: error: null pointer casted to type '*u8'",
3148 });
3149
3150 ctx.objErrStage1("implicit casting undefined c pointer to zig pointer",
3151 \\comptime {
3152 \\ var c_ptr: [*c]u8 = undefined;
3153 \\ var zig_ptr: *u8 = c_ptr;
3154 \\ _ = zig_ptr;
3155 \\}
3156 , &[_][]const u8{
3157 "tmp.zig:3:24: error: use of undefined value here causes undefined behavior",
3158 });
3159
3160 ctx.objErrStage1("implicit casting C pointers which would mess up null semantics",
3161 \\export fn entry() void {
3162 \\ var slice: []const u8 = "aoeu";
3163 \\ const opt_many_ptr: [*]const u8 = slice.ptr;
3164 \\ var ptr_opt_many_ptr = &opt_many_ptr;
3165 \\ var c_ptr: [*c]const [*c]const u8 = ptr_opt_many_ptr;
3166 \\ ptr_opt_many_ptr = c_ptr;
3167 \\}
3168 \\export fn entry2() void {
3169 \\ var buf: [4]u8 = "aoeu".*;
3170 \\ var slice: []u8 = &buf;
3171 \\ var opt_many_ptr: [*]u8 = slice.ptr;
3172 \\ var ptr_opt_many_ptr = &opt_many_ptr;
3173 \\ var c_ptr: [*c][*c]const u8 = ptr_opt_many_ptr;
3174 \\ _ = c_ptr;
3175 \\}
3176 , &[_][]const u8{
3177 "tmp.zig:6:24: error: expected type '*const [*]const u8', found '[*c]const [*c]const u8'",
3178 "tmp.zig:6:24: note: pointer type child '[*c]const u8' cannot cast into pointer type child '[*]const u8'",
3179 "tmp.zig:6:24: note: '[*c]const u8' could have null values which are illegal in type '[*]const u8'",
3180 "tmp.zig:13:35: error: expected type '[*c][*c]const u8', found '*[*]u8'",
3181 "tmp.zig:13:35: note: pointer type child '[*]u8' cannot cast into pointer type child '[*c]const u8'",
3182 "tmp.zig:13:35: note: mutable '[*c]const u8' allows illegal null values stored to type '[*]u8'",
3183 });
3184
3185 ctx.objErrStage1("implicit casting too big integers to C pointers",
3186 \\export fn a() void {
3187 \\ var ptr: [*c]u8 = (1 << 64) + 1;
3188 \\ _ = ptr;
3189 \\}
3190 \\export fn b() void {
3191 \\ var x: u65 = 0x1234;
3192 \\ var ptr: [*c]u8 = x;
3193 \\ _ = ptr;
3194 \\}
3195 , &[_][]const u8{
3196 "tmp.zig:2:33: error: integer value 18446744073709551617 cannot be coerced to type 'usize'",
3197 "tmp.zig:7:23: error: integer type 'u65' too big for implicit @intToPtr to type '[*c]u8'",
3198 });
3199
3200 ctx.objErrStage1("C pointer pointing to non C ABI compatible type or has align attr",
3201 \\const Foo = struct {};
3202 \\export fn a() void {
3203 \\ const T = [*c]Foo;
3204 \\ var t: T = undefined;
3205 \\ _ = t;
3206 \\}
3207 , &[_][]const u8{
3208 "tmp.zig:3:19: error: C pointers cannot point to non-C-ABI-compatible type 'Foo'",
3209 });
3210
3211 ctx.objErrStage1("compile log statement warning deduplication in generic fn",
3212 \\export fn entry() void {
3213 \\ inner(1);
3214 \\ inner(2);
3215 \\}
3216 \\fn inner(comptime n: usize) void {
3217 \\ comptime var i = 0;
3218 \\ inline while (i < n) : (i += 1) { @compileLog("!@#$"); }
3219 \\}
3220 , &[_][]const u8{
3221 "tmp.zig:7:39: error: found compile log statement",
3222 });
3223
3224 ctx.objErrStage1("assign to invalid dereference",
3225 \\export fn entry() void {
3226 \\ 'a'.* = 1;
3227 \\}
3228 , &[_][]const u8{
3229 "tmp.zig:2:8: error: attempt to dereference non-pointer type 'comptime_int'",
3230 });
3231
3232 ctx.objErrStage1("take slice of invalid dereference",
3233 \\export fn entry() void {
3234 \\ const x = 'a'.*[0..];
3235 \\ _ = x;
3236 \\}
3237 , &[_][]const u8{
3238 "tmp.zig:2:18: error: attempt to dereference non-pointer type 'comptime_int'",
3239 });
3240
3241 ctx.objErrStage1("@truncate undefined value",
3242 \\export fn entry() void {
3243 \\ var z = @truncate(u8, @as(u16, undefined));
3244 \\ _ = z;
3245 \\}
3246 , &[_][]const u8{
3247 "tmp.zig:2:27: error: use of undefined value here causes undefined behavior",
3248 });
3249
3250 ctx.testErrStage1("return invalid type from test",
3251 \\test "example" { return 1; }
3252 , &[_][]const u8{
3253 "tmp.zig:1:25: error: expected type 'void', found 'comptime_int'",
3254 });
3255
3256 ctx.objErrStage1("threadlocal qualifier on const",
3257 \\threadlocal const x: i32 = 1234;
3258 \\export fn entry() i32 {
3259 \\ return x;
3260 \\}
3261 , &[_][]const u8{
3262 "tmp.zig:1:1: error: threadlocal variable cannot be constant",
3263 });
3264
3265 ctx.objErrStage1("@bitCast same size but bit count mismatch",
3266 \\export fn entry(byte: u8) void {
3267 \\ var oops = @bitCast(u7, byte);
3268 \\ _ = oops;
3269 \\}
3270 , &[_][]const u8{
3271 "tmp.zig:2:25: error: destination type 'u7' has 7 bits but source type 'u8' has 8 bits",
3272 });
3273
3274 ctx.objErrStage1("@bitCast with different sizes inside an expression",
3275 \\export fn entry() void {
3276 \\ var foo = (@bitCast(u8, @as(f32, 1.0)) == 0xf);
3277 \\ _ = foo;
3278 \\}
3279 , &[_][]const u8{
3280 "tmp.zig:2:25: error: destination type 'u8' has size 1 but source type 'f32' has size 4",
3281 });
3282
3283 ctx.objErrStage1("attempted `&&`",
3284 \\export fn entry(a: bool, b: bool) i32 {
3285 \\ if (a && b) {
3286 \\ return 1234;
3287 \\ }
3288 \\ return 5678;
3289 \\}
3290 , &[_][]const u8{
3291 "tmp.zig:2:11: error: ambiguous use of '&&'; use 'and' for logical AND, or change whitespace to ' & &' for bitwise AND",
3292 });
3293
3294 ctx.objErrStage1("attempted `||` on boolean values",
3295 \\export fn entry(a: bool, b: bool) i32 {
3296 \\ if (a || b) {
3297 \\ return 1234;
3298 \\ }
3299 \\ return 5678;
3300 \\}
3301 , &[_][]const u8{
3302 "tmp.zig:2:9: error: expected error set type, found 'bool'",
3303 "tmp.zig:2:11: note: `||` merges error sets; `or` performs boolean OR",
3304 });
3305
3306 ctx.objErrStage1("compile log a pointer to an opaque value",
3307 \\export fn entry() void {
3308 \\ @compileLog(@ptrCast(*const anyopaque, &entry));
3309 \\}
3310 , &[_][]const u8{
3311 "tmp.zig:2:5: error: found compile log statement",
3312 });
3313
3314 ctx.objErrStage1("duplicate boolean switch value",
3315 \\comptime {
3316 \\ const x = switch (true) {
3317 \\ true => false,
3318 \\ false => true,
3319 \\ true => false,
3320 \\ };
3321 \\ _ = x;
3322 \\}
3323 \\comptime {
3324 \\ const x = switch (true) {
3325 \\ false => true,
3326 \\ true => false,
3327 \\ false => true,
3328 \\ };
3329 \\ _ = x;
3330 \\}
3331 , &[_][]const u8{
3332 "tmp.zig:5:9: error: duplicate switch value",
3333 "tmp.zig:13:9: error: duplicate switch value",
3334 });
3335
3336 ctx.objErrStage1("missing boolean switch value",
3337 \\comptime {
3338 \\ const x = switch (true) {
3339 \\ true => false,
3340 \\ };
3341 \\ _ = x;
3342 \\}
3343 \\comptime {
3344 \\ const x = switch (true) {
3345 \\ false => true,
3346 \\ };
3347 \\ _ = x;
3348 \\}
3349 , &[_][]const u8{
3350 "tmp.zig:2:15: error: switch must handle all possibilities",
3351 "tmp.zig:8:15: error: switch must handle all possibilities",
3352 });
3353
3354 ctx.objErrStage1("reading past end of pointer casted array",
3355 \\comptime {
3356 \\ const array: [4]u8 = "aoeu".*;
3357 \\ const sub_array = array[1..];
3358 \\ const int_ptr = @ptrCast(*const u24, sub_array);
3359 \\ const deref = int_ptr.*;
3360 \\ _ = deref;
3361 \\}
3362 , &[_][]const u8{
3363 "tmp.zig:5:26: error: attempt to read 4 bytes from [4]u8 at index 1 which is 3 bytes",
3364 });
3365
3366 ctx.objErrStage1("error note for function parameter incompatibility",
3367 \\fn do_the_thing(func: fn (arg: i32) void) void { _ = func; }
3368 \\fn bar(arg: bool) void { _ = arg; }
3369 \\export fn entry() void {
3370 \\ do_the_thing(bar);
3371 \\}
3372 , &[_][]const u8{
3373 "tmp.zig:4:18: error: expected type 'fn(i32) void', found 'fn(bool) void",
3374 "tmp.zig:4:18: note: parameter 0: 'bool' cannot cast into 'i32'",
3375 });
3376 ctx.objErrStage1("cast negative value to unsigned integer",
3377 \\comptime {
3378 \\ const value: i32 = -1;
3379 \\ const unsigned = @intCast(u32, value);
3380 \\ _ = unsigned;
3381 \\}
3382 \\export fn entry1() void {
3383 \\ const value: i32 = -1;
3384 \\ const unsigned: u32 = value;
3385 \\ _ = unsigned;
3386 \\}
3387 , &[_][]const u8{
3388 "tmp.zig:3:22: error: attempt to cast negative value to unsigned integer",
3389 "tmp.zig:8:27: error: cannot cast negative value -1 to unsigned integer type 'u32'",
3390 });
3391
3392 ctx.objErrStage1("integer cast truncates bits",
3393 \\export fn entry1() void {
3394 \\ const spartan_count: u16 = 300;
3395 \\ const byte = @intCast(u8, spartan_count);
3396 \\ _ = byte;
3397 \\}
3398 \\export fn entry2() void {
3399 \\ const spartan_count: u16 = 300;
3400 \\ const byte: u8 = spartan_count;
3401 \\ _ = byte;
3402 \\}
3403 \\export fn entry3() void {
3404 \\ var spartan_count: u16 = 300;
3405 \\ var byte: u8 = spartan_count;
3406 \\ _ = byte;
3407 \\}
3408 \\export fn entry4() void {
3409 \\ var signed: i8 = -1;
3410 \\ var unsigned: u64 = signed;
3411 \\ _ = unsigned;
3412 \\}
3413 , &[_][]const u8{
3414 "tmp.zig:3:18: error: cast from 'u16' to 'u8' truncates bits",
3415 "tmp.zig:8:22: error: integer value 300 cannot be coerced to type 'u8'",
3416 "tmp.zig:13:20: error: expected type 'u8', found 'u16'",
3417 "tmp.zig:13:20: note: unsigned 8-bit int cannot represent all possible unsigned 16-bit values",
3418 "tmp.zig:18:25: error: expected type 'u64', found 'i8'",
3419 "tmp.zig:18:25: note: unsigned 64-bit int cannot represent all possible signed 8-bit values",
3420 });
3421
3422 ctx.objErrStage1("comptime implicit cast f64 to f32",
3423 \\export fn entry() void {
3424 \\ const x: f64 = 16777217;
3425 \\ const y: f32 = x;
3426 \\ _ = y;
3427 \\}
3428 , &[_][]const u8{
3429 "tmp.zig:3:20: error: cast of value 16777217.000000 to type 'f32' loses information",
3430 });
3431
3432 ctx.objErrStage1("implicit cast from f64 to f32",
3433 \\var x: f64 = 1.0;
3434 \\var y: f32 = x;
3435 \\
3436 \\export fn entry() usize { return @sizeOf(@TypeOf(y)); }
3437 , &[_][]const u8{
3438 "tmp.zig:2:14: error: expected type 'f32', found 'f64'",
3439 });
3440
3441 ctx.objErrStage1("exceeded maximum bit width of integer",
3442 \\export fn entry1() void {
3443 \\ const T = u65536;
3444 \\ _ = T;
3445 \\}
3446 \\export fn entry2() void {
3447 \\ var x: i65536 = 1;
3448 \\ _ = x;
3449 \\}
3450 , &[_][]const u8{
3451 "tmp.zig:2:15: error: primitive integer type 'u65536' exceeds maximum bit width of 65535",
3452 "tmp.zig:6:12: error: primitive integer type 'i65536' exceeds maximum bit width of 65535",
3453 });
3454
3455 ctx.objErrStage1("compile error when evaluating return type of inferred error set",
3456 \\const Car = struct {
3457 \\ foo: *SymbolThatDoesNotExist,
3458 \\ pub fn init() !Car {}
3459 \\};
3460 \\export fn entry() void {
3461 \\ const car = Car.init();
3462 \\ _ = car;
3463 \\}
3464 , &[_][]const u8{
3465 "tmp.zig:2:11: error: use of undeclared identifier 'SymbolThatDoesNotExist'",
3466 });
3467
3468 ctx.objErrStage1("don't implicit cast double pointer to *anyopaque",
3469 \\export fn entry() void {
3470 \\ var a: u32 = 1;
3471 \\ var ptr: *align(@alignOf(u32)) anyopaque = &a;
3472 \\ var b: *u32 = @ptrCast(*u32, ptr);
3473 \\ var ptr2: *anyopaque = &b;
3474 \\ _ = ptr2;
3475 \\}
3476 , &[_][]const u8{
3477 "tmp.zig:5:29: error: expected type '*anyopaque', found '**u32'",
3478 });
3479
3480 ctx.objErrStage1("runtime index into comptime type slice",
3481 \\const Struct = struct {
3482 \\ a: u32,
3483 \\};
3484 \\fn getIndex() usize {
3485 \\ return 2;
3486 \\}
3487 \\export fn entry() void {
3488 \\ const index = getIndex();
3489 \\ const field = @typeInfo(Struct).Struct.fields[index];
3490 \\ _ = field;
3491 \\}
3492 , &[_][]const u8{
3493 "tmp.zig:9:51: error: values of type 'std.builtin.Type.StructField' must be comptime known, but index value is runtime known",
3494 });
3495
3496 ctx.objErrStage1("compile log statement inside function which must be comptime evaluated",
3497 \\fn Foo(comptime T: type) type {
3498 \\ @compileLog(@typeName(T));
3499 \\ return T;
3500 \\}
3501 \\export fn entry() void {
3502 \\ _ = Foo(i32);
3503 \\ _ = @typeName(Foo(i32));
3504 \\}
3505 , &[_][]const u8{
3506 "tmp.zig:2:5: error: found compile log statement",
3507 });
3508
3509 ctx.objErrStage1("comptime slice of an undefined slice",
3510 \\comptime {
3511 \\ var a: []u8 = undefined;
3512 \\ var b = a[0..10];
3513 \\ _ = b;
3514 \\}
3515 , &[_][]const u8{
3516 "tmp.zig:3:14: error: slice of undefined",
3517 });
3518
3519 ctx.objErrStage1("implicit cast const array to mutable slice",
3520 \\export fn entry() void {
3521 \\ const buffer: [1]u8 = [_]u8{8};
3522 \\ const sliceA: []u8 = &buffer;
3523 \\ _ = sliceA;
3524 \\}
3525 , &[_][]const u8{
3526 "tmp.zig:3:27: error: cannot cast pointer to array literal to slice type '[]u8'",
3527 "tmp.zig:3:27: note: cast discards const qualifier",
3528 });
3529
3530 ctx.objErrStage1("deref slice and get len field",
3531 \\export fn entry() void {
3532 \\ var a: []u8 = undefined;
3533 \\ _ = a.*.len;
3534 \\}
3535 , &[_][]const u8{
3536 "tmp.zig:3:10: error: attempt to dereference non-pointer type '[]u8'",
3537 });
3538
3539 ctx.objErrStage1("@ptrCast a 0 bit type to a non- 0 bit type",
3540 \\export fn entry() bool {
3541 \\ var x: u0 = 0;
3542 \\ const p = @ptrCast(?*u0, &x);
3543 \\ return p == null;
3544 \\}
3545 , &[_][]const u8{
3546 "tmp.zig:3:15: error: '*u0' and '?*u0' do not have the same in-memory representation",
3547 "tmp.zig:3:31: note: '*u0' has no in-memory bits",
3548 "tmp.zig:3:24: note: '?*u0' has in-memory bits",
3549 });
3550
3551 ctx.objErrStage1("comparing a non-optional pointer against null",
3552 \\export fn entry() void {
3553 \\ var x: i32 = 1;
3554 \\ _ = &x == null;
3555 \\}
3556 , &[_][]const u8{
3557 "tmp.zig:3:12: error: comparison of '*i32' with null",
3558 });
3559
3560 ctx.objErrStage1("non error sets used in merge error sets operator",
3561 \\export fn foo() void {
3562 \\ const Errors = u8 || u16;
3563 \\ _ = Errors;
3564 \\}
3565 \\export fn bar() void {
3566 \\ const Errors = error{} || u16;
3567 \\ _ = Errors;
3568 \\}
3569 , &[_][]const u8{
3570 "tmp.zig:2:20: error: expected error set type, found type 'u8'",
3571 "tmp.zig:2:23: note: `||` merges error sets; `or` performs boolean OR",
3572 "tmp.zig:6:31: error: expected error set type, found type 'u16'",
3573 "tmp.zig:6:28: note: `||` merges error sets; `or` performs boolean OR",
3574 });
3575
3576 ctx.objErrStage1("variable initialization compile error then referenced",
3577 \\fn Undeclared() type {
3578 \\ return T;
3579 \\}
3580 \\fn Gen() type {
3581 \\ const X = Undeclared();
3582 \\ return struct {
3583 \\ x: X,
3584 \\ };
3585 \\}
3586 \\export fn entry() void {
3587 \\ const S = Gen();
3588 \\ _ = S;
3589 \\}
3590 , &[_][]const u8{
3591 "tmp.zig:2:12: error: use of undeclared identifier 'T'",
3592 });
3593
3594 ctx.objErrStage1("refer to the type of a generic function",
3595 \\export fn entry() void {
3596 \\ const Func = fn (type) void;
3597 \\ const f: Func = undefined;
3598 \\ f(i32);
3599 \\}
3600 , &[_][]const u8{
3601 "tmp.zig:4:5: error: use of undefined value here causes undefined behavior",
3602 });
3603
3604 ctx.objErrStage1("accessing runtime parameter from outer function",
3605 \\fn outer(y: u32) fn (u32) u32 {
3606 \\ const st = struct {
3607 \\ fn get(z: u32) u32 {
3608 \\ return z + y;
3609 \\ }
3610 \\ };
3611 \\ return st.get;
3612 \\}
3613 \\export fn entry() void {
3614 \\ var func = outer(10);
3615 \\ var x = func(3);
3616 \\ _ = x;
3617 \\}
3618 , &[_][]const u8{
3619 "tmp.zig:4:24: error: 'y' not accessible from inner function",
3620 "tmp.zig:3:28: note: crossed function definition here",
3621 "tmp.zig:1:10: note: declared here",
3622 });
3623
3624 ctx.objErrStage1("non int passed to @intToFloat",
3625 \\export fn entry() void {
3626 \\ const x = @intToFloat(f32, 1.1);
3627 \\ _ = x;
3628 \\}
3629 , &[_][]const u8{
3630 "tmp.zig:2:32: error: expected int type, found 'comptime_float'",
3631 });
3632
3633 ctx.objErrStage1("non float passed to @floatToInt",
3634 \\export fn entry() void {
3635 \\ const x = @floatToInt(i32, @as(i32, 54));
3636 \\ _ = x;
3637 \\}
3638 , &[_][]const u8{
3639 "tmp.zig:2:32: error: expected float type, found 'i32'",
3640 });
3641
3642 ctx.objErrStage1("out of range comptime_int passed to @floatToInt",
3643 \\export fn entry() void {
3644 \\ const x = @floatToInt(i8, 200);
3645 \\ _ = x;
3646 \\}
3647 , &[_][]const u8{
3648 "tmp.zig:2:31: error: integer value 200 cannot be coerced to type 'i8'",
3649 });
3650
3651 ctx.objErrStage1("load too many bytes from comptime reinterpreted pointer",
3652 \\export fn entry() void {
3653 \\ const float: f32 = 5.99999999999994648725e-01;
3654 \\ const float_ptr = &float;
3655 \\ const int_ptr = @ptrCast(*const i64, float_ptr);
3656 \\ const int_val = int_ptr.*;
3657 \\ _ = int_val;
3658 \\}
3659 , &[_][]const u8{
3660 "tmp.zig:5:28: error: attempt to read 8 bytes from pointer to f32 which is 4 bytes",
3661 });
3662
3663 ctx.objErrStage1("invalid type used in array type",
3664 \\const Item = struct {
3665 \\ field: SomeNonexistentType,
3666 \\};
3667 \\var items: [100]Item = undefined;
3668 \\export fn entry() void {
3669 \\ const a = items[0];
3670 \\ _ = a;
3671 \\}
3672 , &[_][]const u8{
3673 "tmp.zig:2:12: error: use of undeclared identifier 'SomeNonexistentType'",
3674 });
3675
3676 ctx.objErrStage1("comptime continue inside runtime catch",
3677 \\export fn entry() void {
3678 \\ const ints = [_]u8{ 1, 2 };
3679 \\ inline for (ints) |_| {
3680 \\ bad() catch continue;
3681 \\ }
3682 \\}
3683 \\fn bad() !void {
3684 \\ return error.Bad;
3685 \\}
3686 , &[_][]const u8{
3687 "tmp.zig:4:21: error: comptime control flow inside runtime block",
3688 "tmp.zig:4:15: note: runtime block created here",
3689 });
3690
3691 ctx.objErrStage1("comptime continue inside runtime switch",
3692 \\export fn entry() void {
3693 \\ var p: i32 = undefined;
3694 \\ comptime var q = true;
3695 \\ inline while (q) {
3696 \\ switch (p) {
3697 \\ 11 => continue,
3698 \\ else => {},
3699 \\ }
3700 \\ q = false;
3701 \\ }
3702 \\}
3703 , &[_][]const u8{
3704 "tmp.zig:6:19: error: comptime control flow inside runtime block",
3705 "tmp.zig:5:9: note: runtime block created here",
3706 });
3707
3708 ctx.objErrStage1("comptime continue inside runtime while error",
3709 \\export fn entry() void {
3710 \\ var p: anyerror!usize = undefined;
3711 \\ comptime var q = true;
3712 \\ outer: inline while (q) {
3713 \\ while (p) |_| {
3714 \\ continue :outer;
3715 \\ } else |_| {}
3716 \\ q = false;
3717 \\ }
3718 \\}
3719 , &[_][]const u8{
3720 "tmp.zig:6:13: error: comptime control flow inside runtime block",
3721 "tmp.zig:5:9: note: runtime block created here",
3722 });
3723
3724 ctx.objErrStage1("comptime continue inside runtime while optional",
3725 \\export fn entry() void {
3726 \\ var p: ?usize = undefined;
3727 \\ comptime var q = true;
3728 \\ outer: inline while (q) {
3729 \\ while (p) |_| continue :outer;
3730 \\ q = false;
3731 \\ }
3732 \\}
3733 , &[_][]const u8{
3734 "tmp.zig:5:23: error: comptime control flow inside runtime block",
3735 "tmp.zig:5:9: note: runtime block created here",
3736 });
3737
3738 ctx.objErrStage1("comptime continue inside runtime while bool",
3739 \\export fn entry() void {
3740 \\ var p: usize = undefined;
3741 \\ comptime var q = true;
3742 \\ outer: inline while (q) {
3743 \\ while (p == 11) continue :outer;
3744 \\ q = false;
3745 \\ }
3746 \\}
3747 , &[_][]const u8{
3748 "tmp.zig:5:25: error: comptime control flow inside runtime block",
3749 "tmp.zig:5:9: note: runtime block created here",
3750 });
3751
3752 ctx.objErrStage1("comptime continue inside runtime if error",
3753 \\export fn entry() void {
3754 \\ var p: anyerror!i32 = undefined;
3755 \\ comptime var q = true;
3756 \\ inline while (q) {
3757 \\ if (p) |_| continue else |_| {}
3758 \\ q = false;
3759 \\ }
3760 \\}
3761 , &[_][]const u8{
3762 "tmp.zig:5:20: error: comptime control flow inside runtime block",
3763 "tmp.zig:5:9: note: runtime block created here",
3764 });
3765
3766 ctx.objErrStage1("comptime continue inside runtime if optional",
3767 \\export fn entry() void {
3768 \\ var p: ?i32 = undefined;
3769 \\ comptime var q = true;
3770 \\ inline while (q) {
3771 \\ if (p) |_| continue;
3772 \\ q = false;
3773 \\ }
3774 \\}
3775 , &[_][]const u8{
3776 "tmp.zig:5:20: error: comptime control flow inside runtime block",
3777 "tmp.zig:5:9: note: runtime block created here",
3778 });
3779
3780 ctx.objErrStage1("comptime continue inside runtime if bool",
3781 \\export fn entry() void {
3782 \\ var p: usize = undefined;
3783 \\ comptime var q = true;
3784 \\ inline while (q) {
3785 \\ if (p == 11) continue;
3786 \\ q = false;
3787 \\ }
3788 \\}
3789 , &[_][]const u8{
3790 "tmp.zig:5:22: error: comptime control flow inside runtime block",
3791 "tmp.zig:5:9: note: runtime block created here",
3792 });
3793
3794 ctx.objErrStage1("switch with invalid expression parameter",
3795 \\export fn entry() void {
3796 \\ Test(i32);
3797 \\}
3798 \\fn Test(comptime T: type) void {
3799 \\ const x = switch (T) {
3800 \\ []u8 => |x| x,
3801 \\ i32 => |x| x,
3802 \\ else => unreachable,
3803 \\ };
3804 \\ _ = x;
3805 \\}
3806 , &[_][]const u8{
3807 "tmp.zig:7:17: error: switch on type 'type' provides no expression parameter",
3808 });
3809
3810 ctx.objErrStage1("function prototype with no body",
3811 \\fn foo() void;
3812 \\export fn entry() void {
3813 \\ foo();
3814 \\}
3815 , &[_][]const u8{
3816 "tmp.zig:1:1: error: non-extern function has no body",
3817 });
3818
3819 ctx.objErrStage1("@frame() called outside of function definition",
3820 \\var handle_undef: anyframe = undefined;
3821 \\var handle_dummy: anyframe = @frame();
3822 \\export fn entry() bool {
3823 \\ return handle_undef == handle_dummy;
3824 \\}
3825 , &[_][]const u8{
3826 "tmp.zig:2:30: error: @frame() called outside of function definition",
3827 });
3828
3829 ctx.objErrStage1("`_` is not a declarable symbol",
3830 \\export fn f1() usize {
3831 \\ var _: usize = 2;
3832 \\ return _;
3833 \\}
3834 , &[_][]const u8{
3835 "tmp.zig:2:9: error: '_' used as an identifier without @\"_\" syntax",
3836 });
3837
3838 ctx.objErrStage1("`_` should not be usable inside for",
3839 \\export fn returns() void {
3840 \\ for ([_]void{}) |_, i| {
3841 \\ for ([_]void{}) |_, j| {
3842 \\ return _;
3843 \\ }
3844 \\ }
3845 \\}
3846 , &[_][]const u8{
3847 "tmp.zig:4:20: error: '_' used as an identifier without @\"_\" syntax",
3848 });
3849
3850 ctx.objErrStage1("`_` should not be usable inside while",
3851 \\export fn returns() void {
3852 \\ while (optionalReturn()) |_| {
3853 \\ while (optionalReturn()) |_| {
3854 \\ return _;
3855 \\ }
3856 \\ }
3857 \\}
3858 \\fn optionalReturn() ?u32 {
3859 \\ return 1;
3860 \\}
3861 , &[_][]const u8{
3862 "tmp.zig:4:20: error: '_' used as an identifier without @\"_\" syntax",
3863 });
3864
3865 ctx.objErrStage1("`_` should not be usable inside while else",
3866 \\export fn returns() void {
3867 \\ while (optionalReturnError()) |_| {
3868 \\ while (optionalReturnError()) |_| {
3869 \\ return;
3870 \\ } else |_| {
3871 \\ if (_ == error.optionalReturnError) return;
3872 \\ }
3873 \\ }
3874 \\}
3875 \\fn optionalReturnError() !?u32 {
3876 \\ return error.optionalReturnError;
3877 \\}
3878 , &[_][]const u8{
3879 "tmp.zig:6:17: error: '_' used as an identifier without @\"_\" syntax",
3880 });
3881
3882 ctx.objErrStage1("while loop body expression ignored",
3883 \\fn returns() usize {
3884 \\ return 2;
3885 \\}
3886 \\export fn f1() void {
3887 \\ while (true) returns();
3888 \\}
3889 \\export fn f2() void {
3890 \\ var x: ?i32 = null;
3891 \\ while (x) |_| returns();
3892 \\}
3893 \\export fn f3() void {
3894 \\ var x: anyerror!i32 = error.Bad;
3895 \\ while (x) |_| returns() else |_| unreachable;
3896 \\}
3897 , &[_][]const u8{
3898 "tmp.zig:5:25: error: expression value is ignored",
3899 "tmp.zig:9:26: error: expression value is ignored",
3900 "tmp.zig:13:26: error: expression value is ignored",
3901 });
3902
3903 ctx.objErrStage1("missing parameter name of generic function",
3904 \\fn dump(anytype) void {}
3905 \\export fn entry() void {
3906 \\ var a: u8 = 9;
3907 \\ dump(a);
3908 \\}
3909 , &[_][]const u8{
3910 "tmp.zig:1:9: error: missing parameter name",
3911 });
3912
3913 ctx.objErrStage1("non-inline for loop on a type that requires comptime",
3914 \\const Foo = struct {
3915 \\ name: []const u8,
3916 \\ T: type,
3917 \\};
3918 \\export fn entry() void {
3919 \\ const xx: [2]Foo = undefined;
3920 \\ for (xx) |f| { _ = f;}
3921 \\}
3922 , &[_][]const u8{
3923 "tmp.zig:7:5: error: values of type 'Foo' must be comptime known, but index value is runtime known",
3924 });
3925
3926 ctx.objErrStage1("generic fn as parameter without comptime keyword",
3927 \\fn f(_: fn (anytype) void) void {}
3928 \\fn g(_: anytype) void {}
3929 \\export fn entry() void {
3930 \\ f(g);
3931 \\}
3932 , &[_][]const u8{
3933 "tmp.zig:1:9: error: parameter of type 'fn(anytype) anytype' must be declared comptime",
3934 });
3935
3936 ctx.objErrStage1("optional pointer to void in extern struct",
3937 \\const Foo = extern struct {
3938 \\ x: ?*const void,
3939 \\};
3940 \\const Bar = extern struct {
3941 \\ foo: Foo,
3942 \\ y: i32,
3943 \\};
3944 \\export fn entry(bar: *Bar) void {_ = bar;}
3945 , &[_][]const u8{
3946 "tmp.zig:2:5: error: extern structs cannot contain fields of type '?*const void'",
3947 });
3948
3949 ctx.objErrStage1("use of comptime-known undefined function value",
3950 \\const Cmd = struct {
3951 \\ exec: fn () void,
3952 \\};
3953 \\export fn entry() void {
3954 \\ const command = Cmd{ .exec = undefined };
3955 \\ command.exec();
3956 \\}
3957 , &[_][]const u8{
3958 "tmp.zig:6:12: error: use of undefined value here causes undefined behavior",
3959 });
3960
3961 ctx.objErrStage1("use of comptime-known undefined function value",
3962 \\const Cmd = struct {
3963 \\ exec: fn () void,
3964 \\};
3965 \\export fn entry() void {
3966 \\ const command = Cmd{ .exec = undefined };
3967 \\ command.exec();
3968 \\}
3969 , &[_][]const u8{
3970 "tmp.zig:6:12: error: use of undefined value here causes undefined behavior",
3971 });
3972
3973 ctx.objErrStage1("bad @alignCast at comptime",
3974 \\comptime {
3975 \\ const ptr = @intToPtr(*align(1) i32, 0x1);
3976 \\ const aligned = @alignCast(4, ptr);
3977 \\ _ = aligned;
3978 \\}
3979 , &[_][]const u8{
3980 "tmp.zig:3:35: error: pointer address 0x1 is not aligned to 4 bytes",
3981 });
3982
3983 ctx.objErrStage1("@ptrToInt on *void",
3984 \\export fn entry() bool {
3985 \\ return @ptrToInt(&{}) == @ptrToInt(&{});
3986 \\}
3987 , &[_][]const u8{
3988 "tmp.zig:2:23: error: pointer to size 0 type has no address",
3989 });
3990
3991 ctx.objErrStage1("@popCount - non-integer",
3992 \\export fn entry(x: f32) u32 {
3993 \\ return @popCount(f32, x);
3994 \\}
3995 , &[_][]const u8{
3996 "tmp.zig:2:22: error: expected integer type, found 'f32'",
3997 });
3998
3999 {
4000 const case = ctx.obj("wrong same named struct", .{});
4001 case.backend = .stage1;
4002
4003 case.addSourceFile("a.zig",
4004 \\pub const Foo = struct {
4005 \\ x: i32,
4006 \\};
4007 );
4008
4009 case.addSourceFile("b.zig",
4010 \\pub const Foo = struct {
4011 \\ z: f64,
4012 \\};
4013 );
4014
4015 case.addError(
4016 \\const a = @import("a.zig");
4017 \\const b = @import("b.zig");
4018 \\
4019 \\export fn entry() void {
4020 \\ var a1: a.Foo = undefined;
4021 \\ bar(&a1);
4022 \\}
4023 \\
4024 \\fn bar(x: *b.Foo) void {_ = x;}
4025 , &[_][]const u8{
4026 "tmp.zig:6:10: error: expected type '*b.Foo', found '*a.Foo'",
4027 "tmp.zig:6:10: note: pointer type child 'a.Foo' cannot cast into pointer type child 'b.Foo'",
4028 "a.zig:1:17: note: a.Foo declared here",
4029 "b.zig:1:17: note: b.Foo declared here",
4030 });
4031 }
4032
4033 ctx.objErrStage1("@floatToInt comptime safety",
4034 \\comptime {
4035 \\ _ = @floatToInt(i8, @as(f32, -129.1));
4036 \\}
4037 \\comptime {
4038 \\ _ = @floatToInt(u8, @as(f32, -1.1));
4039 \\}
4040 \\comptime {
4041 \\ _ = @floatToInt(u8, @as(f32, 256.1));
4042 \\}
4043 , &[_][]const u8{
4044 "tmp.zig:2:9: error: integer value '-129' cannot be stored in type 'i8'",
4045 "tmp.zig:5:9: error: integer value '-1' cannot be stored in type 'u8'",
4046 "tmp.zig:8:9: error: integer value '256' cannot be stored in type 'u8'",
4047 });
4048
4049 ctx.objErrStage1("use anyopaque as return type of fn ptr",
4050 \\export fn entry() void {
4051 \\ const a: fn () anyopaque = undefined;
4052 \\ _ = a;
4053 \\}
4054 , &[_][]const u8{
4055 "tmp.zig:2:20: error: return type cannot be opaque",
4056 });
4057
4058 ctx.objErrStage1("use implicit casts to assign null to non-nullable pointer",
4059 \\export fn entry() void {
4060 \\ var x: i32 = 1234;
4061 \\ var p: *i32 = &x;
4062 \\ var pp: *?*i32 = &p;
4063 \\ pp.* = null;
4064 \\ var y = p.*;
4065 \\ _ = y;
4066 \\}
4067 , &[_][]const u8{
4068 "tmp.zig:4:23: error: expected type '*?*i32', found '**i32'",
4069 });
4070
4071 ctx.objErrStage1("attempted implicit cast from T to [*]const T",
4072 \\export fn entry() void {
4073 \\ const x: [*]const bool = true;
4074 \\ _ = x;
4075 \\}
4076 , &[_][]const u8{
4077 "tmp.zig:2:30: error: expected type '[*]const bool', found 'bool'",
4078 });
4079
4080 ctx.objErrStage1("dereference unknown length pointer",
4081 \\export fn entry(x: [*]i32) i32 {
4082 \\ return x.*;
4083 \\}
4084 , &[_][]const u8{
4085 "tmp.zig:2:13: error: index syntax required for unknown-length pointer type '[*]i32'",
4086 });
4087
4088 ctx.objErrStage1("field access of unknown length pointer",
4089 \\const Foo = extern struct {
4090 \\ a: i32,
4091 \\};
4092 \\
4093 \\export fn entry(foo: [*]Foo) void {
4094 \\ foo.a += 1;
4095 \\}
4096 , &[_][]const u8{
4097 "tmp.zig:6:8: error: type '[*]Foo' does not support field access",
4098 });
4099
4100 ctx.objErrStage1("unknown length pointer to opaque",
4101 \\export const T = [*]opaque {};
4102 , &[_][]const u8{
4103 "tmp.zig:1:21: error: unknown-length pointer to opaque",
4104 });
4105
4106 ctx.objErrStage1("error when evaluating return type",
4107 \\const Foo = struct {
4108 \\ map: @as(i32, i32),
4109 \\
4110 \\ fn init() Foo {
4111 \\ return undefined;
4112 \\ }
4113 \\};
4114 \\export fn entry() void {
4115 \\ var rule_set = try Foo.init();
4116 \\ _ = rule_set;
4117 \\}
4118 , &[_][]const u8{
4119 "tmp.zig:2:19: error: expected type 'i32', found 'type'",
4120 });
4121
4122 ctx.objErrStage1("slicing single-item pointer",
4123 \\export fn entry(ptr: *i32) void {
4124 \\ const slice = ptr[0..2];
4125 \\ _ = slice;
4126 \\}
4127 , &[_][]const u8{
4128 "tmp.zig:2:22: error: slice of single-item pointer",
4129 });
4130
4131 ctx.objErrStage1("indexing single-item pointer",
4132 \\export fn entry(ptr: *i32) i32 {
4133 \\ return ptr[1];
4134 \\}
4135 , &[_][]const u8{
4136 "tmp.zig:2:15: error: index of single-item pointer",
4137 });
4138
4139 ctx.objErrStage1("nested error set mismatch",
4140 \\const NextError = error{NextError};
4141 \\const OtherError = error{OutOfMemory};
4142 \\
4143 \\export fn entry() void {
4144 \\ const a: ?NextError!i32 = foo();
4145 \\ _ = a;
4146 \\}
4147 \\
4148 \\fn foo() ?OtherError!i32 {
4149 \\ return null;
4150 \\}
4151 , &[_][]const u8{
4152 "tmp.zig:5:34: error: expected type '?NextError!i32', found '?OtherError!i32'",
4153 "tmp.zig:5:34: note: optional type child 'OtherError!i32' cannot cast into optional type child 'NextError!i32'",
4154 "tmp.zig:5:34: note: error set 'OtherError' cannot cast into error set 'NextError'",
4155 "tmp.zig:2:26: note: 'error.OutOfMemory' not a member of destination error set",
4156 });
4157
4158 ctx.objErrStage1("invalid deref on switch target",
4159 \\comptime {
4160 \\ var tile = Tile.Empty;
4161 \\ switch (tile.*) {
4162 \\ Tile.Empty => {},
4163 \\ Tile.Filled => {},
4164 \\ }
4165 \\}
4166 \\const Tile = enum {
4167 \\ Empty,
4168 \\ Filled,
4169 \\};
4170 , &[_][]const u8{
4171 "tmp.zig:3:17: error: attempt to dereference non-pointer type 'Tile'",
4172 });
4173
4174 ctx.objErrStage1("invalid field access in comptime",
4175 \\comptime { var x = doesnt_exist.whatever; _ = x; }
4176 , &[_][]const u8{
4177 "tmp.zig:1:20: error: use of undeclared identifier 'doesnt_exist'",
4178 });
4179
4180 ctx.objErrStage1("suspend inside suspend block",
4181 \\export fn entry() void {
4182 \\ _ = async foo();
4183 \\}
4184 \\fn foo() void {
4185 \\ suspend {
4186 \\ suspend {
4187 \\ }
4188 \\ }
4189 \\}
4190 , &[_][]const u8{
4191 "tmp.zig:6:9: error: cannot suspend inside suspend block",
4192 "tmp.zig:5:5: note: other suspend block here",
4193 });
4194
4195 ctx.objErrStage1("assign inline fn to non-comptime var",
4196 \\export fn entry() void {
4197 \\ var a = b;
4198 \\ _ = a;
4199 \\}
4200 \\fn b() callconv(.Inline) void { }
4201 , &[_][]const u8{
4202 "tmp.zig:2:5: error: functions marked inline must be stored in const or comptime var",
4203 "tmp.zig:5:1: note: declared here",
4204 });
4205
4206 ctx.objErrStage1("wrong type passed to @panic",
4207 \\export fn entry() void {
4208 \\ var e = error.Foo;
4209 \\ @panic(e);
4210 \\}
4211 , &[_][]const u8{
4212 "tmp.zig:3:12: error: expected type '[]const u8', found 'error{Foo}'",
4213 });
4214
4215 ctx.objErrStage1("@tagName used on union with no associated enum tag",
4216 \\const FloatInt = extern union {
4217 \\ Float: f32,
4218 \\ Int: i32,
4219 \\};
4220 \\export fn entry() void {
4221 \\ var fi = FloatInt{.Float = 123.45};
4222 \\ var tagName = @tagName(fi);
4223 \\ _ = tagName;
4224 \\}
4225 , &[_][]const u8{
4226 "tmp.zig:7:19: error: union has no associated enum",
4227 "tmp.zig:1:18: note: declared here",
4228 });
4229
4230 ctx.objErrStage1("returning error from void async function",
4231 \\export fn entry() void {
4232 \\ _ = async amain();
4233 \\}
4234 \\fn amain() callconv(.Async) void {
4235 \\ return error.ShouldBeCompileError;
4236 \\}
4237 , &[_][]const u8{
4238 "tmp.zig:5:17: error: expected type 'void', found 'error{ShouldBeCompileError}'",
4239 });
4240
4241 ctx.objErrStage1("@ptrCast discards const qualifier",
4242 \\export fn entry() void {
4243 \\ const x: i32 = 1234;
4244 \\ const y = @ptrCast(*i32, &x);
4245 \\ _ = y;
4246 \\}
4247 , &[_][]const u8{
4248 "tmp.zig:3:15: error: cast discards const qualifier",
4249 });
4250
4251 ctx.objErrStage1("comptime slice of undefined pointer non-zero len",
4252 \\export fn entry() void {
4253 \\ const slice = @as([*]i32, undefined)[0..1];
4254 \\ _ = slice;
4255 \\}
4256 , &[_][]const u8{
4257 "tmp.zig:2:41: error: non-zero length slice of undefined pointer",
4258 });
4259
4260 ctx.objErrStage1("type checking function pointers",
4261 \\fn a(b: fn (*const u8) void) void {
4262 \\ b('a');
4263 \\}
4264 \\fn c(d: u8) void {_ = d;}
4265 \\export fn entry() void {
4266 \\ a(c);
4267 \\}
4268 , &[_][]const u8{
4269 "tmp.zig:6:7: error: expected type 'fn(*const u8) void', found 'fn(u8) void'",
4270 });
4271
4272 ctx.objErrStage1("no else prong on switch on global error set",
4273 \\export fn entry() void {
4274 \\ foo(error.A);
4275 \\}
4276 \\fn foo(a: anyerror) void {
4277 \\ switch (a) {
4278 \\ error.A => {},
4279 \\ }
4280 \\}
4281 , &[_][]const u8{
4282 "tmp.zig:5:5: error: else prong required when switching on type 'anyerror'",
4283 });
4284
4285 ctx.objErrStage1("error not handled in switch",
4286 \\export fn entry() void {
4287 \\ foo(452) catch |err| switch (err) {
4288 \\ error.Foo => {},
4289 \\ };
4290 \\}
4291 \\fn foo(x: i32) !void {
4292 \\ switch (x) {
4293 \\ 0 ... 10 => return error.Foo,
4294 \\ 11 ... 20 => return error.Bar,
4295 \\ 21 ... 30 => return error.Baz,
4296 \\ else => {},
4297 \\ }
4298 \\}
4299 , &[_][]const u8{
4300 "tmp.zig:2:26: error: error.Baz not handled in switch",
4301 "tmp.zig:2:26: error: error.Bar not handled in switch",
4302 });
4303
4304 ctx.objErrStage1("duplicate error in switch",
4305 \\export fn entry() void {
4306 \\ foo(452) catch |err| switch (err) {
4307 \\ error.Foo => {},
4308 \\ error.Bar => {},
4309 \\ error.Foo => {},
4310 \\ else => {},
4311 \\ };
4312 \\}
4313 \\fn foo(x: i32) !void {
4314 \\ switch (x) {
4315 \\ 0 ... 10 => return error.Foo,
4316 \\ 11 ... 20 => return error.Bar,
4317 \\ else => {},
4318 \\ }
4319 \\}
4320 , &[_][]const u8{
4321 "tmp.zig:5:14: error: duplicate switch value: '@typeInfo(@typeInfo(@TypeOf(foo)).Fn.return_type.?).ErrorUnion.error_set.Foo'",
4322 "tmp.zig:3:14: note: other value here",
4323 });
4324
4325 ctx.objErrStage1("invalid cast from integral type to enum",
4326 \\const E = enum(usize) { One, Two };
4327 \\
4328 \\export fn entry() void {
4329 \\ foo(1);
4330 \\}
4331 \\
4332 \\fn foo(x: usize) void {
4333 \\ switch (x) {
4334 \\ E.One => {},
4335 \\ }
4336 \\}
4337 , &[_][]const u8{
4338 "tmp.zig:9:10: error: expected type 'usize', found 'E'",
4339 });
4340
4341 ctx.objErrStage1("range operator in switch used on error set",
4342 \\export fn entry() void {
4343 \\ try foo(452) catch |err| switch (err) {
4344 \\ error.A ... error.B => {},
4345 \\ else => {},
4346 \\ };
4347 \\}
4348 \\fn foo(x: i32) !void {
4349 \\ switch (x) {
4350 \\ 0 ... 10 => return error.Foo,
4351 \\ 11 ... 20 => return error.Bar,
4352 \\ else => {},
4353 \\ }
4354 \\}
4355 , &[_][]const u8{
4356 "tmp.zig:3:17: error: operator not allowed for errors",
4357 });
4358
4359 ctx.objErrStage1("inferring error set of function pointer",
4360 \\comptime {
4361 \\ const z: ?fn()!void = null;
4362 \\}
4363 , &[_][]const u8{
4364 "tmp.zig:2:19: error: function prototype may not have inferred error set",
4365 });
4366
4367 ctx.objErrStage1("access non-existent member of error set",
4368 \\const Foo = error{A};
4369 \\comptime {
4370 \\ const z = Foo.Bar;
4371 \\ _ = z;
4372 \\}
4373 , &[_][]const u8{
4374 "tmp.zig:3:18: error: no error named 'Bar' in 'Foo'",
4375 });
4376
4377 ctx.objErrStage1("error union operator with non error set LHS",
4378 \\comptime {
4379 \\ const z = i32!i32;
4380 \\ var x: z = undefined;
4381 \\ _ = x;
4382 \\}
4383 , &[_][]const u8{
4384 "tmp.zig:2:15: error: expected error set type, found type 'i32'",
4385 });
4386
4387 ctx.objErrStage1("error equality but sets have no common members",
4388 \\const Set1 = error{A, C};
4389 \\const Set2 = error{B, D};
4390 \\export fn entry() void {
4391 \\ foo(Set1.A);
4392 \\}
4393 \\fn foo(x: Set1) void {
4394 \\ if (x == Set2.B) {
4395 \\
4396 \\ }
4397 \\}
4398 , &[_][]const u8{
4399 "tmp.zig:7:11: error: error sets 'Set1' and 'Set2' have no common errors",
4400 });
4401
4402 ctx.objErrStage1("only equality binary operator allowed for error sets",
4403 \\comptime {
4404 \\ const z = error.A > error.B;
4405 \\ _ = z;
4406 \\}
4407 , &[_][]const u8{
4408 "tmp.zig:2:23: error: operator not allowed for errors",
4409 });
4410
4411 ctx.objErrStage1("explicit error set cast known at comptime violates error sets",
4412 \\const Set1 = error {A, B};
4413 \\const Set2 = error {A, C};
4414 \\comptime {
4415 \\ var x = Set1.B;
4416 \\ var y = @errSetCast(Set2, x);
4417 \\ _ = y;
4418 \\}
4419 , &[_][]const u8{
4420 "tmp.zig:5:13: error: error.B not a member of error set 'Set2'",
4421 });
4422
4423 ctx.objErrStage1("cast error union of global error set to error union of smaller error set",
4424 \\const SmallErrorSet = error{A};
4425 \\export fn entry() void {
4426 \\ var x: SmallErrorSet!i32 = foo();
4427 \\ _ = x;
4428 \\}
4429 \\fn foo() anyerror!i32 {
4430 \\ return error.B;
4431 \\}
4432 , &[_][]const u8{
4433 "tmp.zig:3:35: error: expected type 'SmallErrorSet!i32', found 'anyerror!i32'",
4434 "tmp.zig:3:35: note: error set 'anyerror' cannot cast into error set 'SmallErrorSet'",
4435 "tmp.zig:3:35: note: cannot cast global error set into smaller set",
4436 });
4437
4438 ctx.objErrStage1("cast global error set to error set",
4439 \\const SmallErrorSet = error{A};
4440 \\export fn entry() void {
4441 \\ var x: SmallErrorSet = foo();
4442 \\ _ = x;
4443 \\}
4444 \\fn foo() anyerror {
4445 \\ return error.B;
4446 \\}
4447 , &[_][]const u8{
4448 "tmp.zig:3:31: error: expected type 'SmallErrorSet', found 'anyerror'",
4449 "tmp.zig:3:31: note: cannot cast global error set into smaller set",
4450 });
4451 ctx.objErrStage1("recursive inferred error set",
4452 \\export fn entry() void {
4453 \\ foo() catch unreachable;
4454 \\}
4455 \\fn foo() !void {
4456 \\ try foo();
4457 \\}
4458 , &[_][]const u8{
4459 "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",
4460 });
4461
4462 ctx.objErrStage1("implicit cast of error set not a subset",
4463 \\const Set1 = error{A, B};
4464 \\const Set2 = error{A, C};
4465 \\export fn entry() void {
4466 \\ foo(Set1.B);
4467 \\}
4468 \\fn foo(set1: Set1) void {
4469 \\ var x: Set2 = set1;
4470 \\ _ = x;
4471 \\}
4472 , &[_][]const u8{
4473 "tmp.zig:7:19: error: expected type 'Set2', found 'Set1'",
4474 "tmp.zig:1:23: note: 'error.B' not a member of destination error set",
4475 });
4476
4477 ctx.objErrStage1("int to err global invalid number",
4478 \\const Set1 = error{
4479 \\ A,
4480 \\ B,
4481 \\};
4482 \\comptime {
4483 \\ var x: u16 = 3;
4484 \\ var y = @intToError(x);
4485 \\ _ = y;
4486 \\}
4487 , &[_][]const u8{
4488 "tmp.zig:7:13: error: integer value 3 represents no error",
4489 });
4490
4491 ctx.objErrStage1("int to err non global invalid number",
4492 \\const Set1 = error{
4493 \\ A,
4494 \\ B,
4495 \\};
4496 \\const Set2 = error{
4497 \\ A,
4498 \\ C,
4499 \\};
4500 \\comptime {
4501 \\ var x = @errorToInt(Set1.B);
4502 \\ var y = @errSetCast(Set2, @intToError(x));
4503 \\ _ = y;
4504 \\}
4505 , &[_][]const u8{
4506 "tmp.zig:11:13: error: error.B not a member of error set 'Set2'",
4507 });
4508
4509 ctx.objErrStage1("duplicate error value in error set",
4510 \\const Foo = error {
4511 \\ Bar,
4512 \\ Bar,
4513 \\};
4514 \\export fn entry() void {
4515 \\ const a: Foo = undefined;
4516 \\ _ = a;
4517 \\}
4518 , &[_][]const u8{
4519 "tmp.zig:3:5: error: duplicate error set field 'Bar'",
4520 "tmp.zig:2:5: note: previous declaration here",
4521 });
4522
4523 ctx.objErrStage1("cast negative integer literal to usize",
4524 \\export fn entry() void {
4525 \\ const x = @as(usize, -10);
4526 \\ _ = x;
4527 \\}
4528 , &[_][]const u8{
4529 "tmp.zig:2:26: error: cannot cast negative value -10 to unsigned integer type 'usize'",
4530 });
4531
4532 ctx.objErrStage1("use invalid number literal as array index",
4533 \\var v = 25;
4534 \\export fn entry() void {
4535 \\ var arr: [v]u8 = undefined;
4536 \\ _ = arr;
4537 \\}
4538 , &[_][]const u8{
4539 "tmp.zig:1:1: error: unable to infer variable type",
4540 });
4541
4542 ctx.objErrStage1("duplicate struct field",
4543 \\const Foo = struct {
4544 \\ Bar: i32,
4545 \\ Bar: usize,
4546 \\};
4547 \\export fn entry() void {
4548 \\ const a: Foo = undefined;
4549 \\ _ = a;
4550 \\}
4551 , &[_][]const u8{
4552 "tmp.zig:3:5: error: duplicate struct field: 'Bar'",
4553 "tmp.zig:2:5: note: other field here",
4554 });
4555
4556 ctx.objErrStage1("duplicate union field",
4557 \\const Foo = union {
4558 \\ Bar: i32,
4559 \\ Bar: usize,
4560 \\};
4561 \\export fn entry() void {
4562 \\ const a: Foo = undefined;
4563 \\ _ = a;
4564 \\}
4565 , &[_][]const u8{
4566 "tmp.zig:3:5: error: duplicate union field: 'Bar'",
4567 "tmp.zig:2:5: note: other field here",
4568 });
4569
4570 ctx.objErrStage1("duplicate enum field",
4571 \\const Foo = enum {
4572 \\ Bar,
4573 \\ Bar,
4574 \\};
4575 \\
4576 \\export fn entry() void {
4577 \\ const a: Foo = undefined;
4578 \\ _ = a;
4579 \\}
4580 , &[_][]const u8{
4581 "tmp.zig:3:5: error: duplicate enum field: 'Bar'",
4582 "tmp.zig:2:5: note: other field here",
4583 });
4584
4585 ctx.objErrStage1("calling function with naked calling convention",
4586 \\export fn entry() void {
4587 \\ foo();
4588 \\}
4589 \\fn foo() callconv(.Naked) void { }
4590 , &[_][]const u8{
4591 "tmp.zig:2:5: error: unable to call function with naked calling convention",
4592 "tmp.zig:4:1: note: declared here",
4593 });
4594
4595 ctx.objErrStage1("function with invalid return type",
4596 \\export fn foo() boid {}
4597 , &[_][]const u8{
4598 "tmp.zig:1:17: error: use of undeclared identifier 'boid'",
4599 });
4600
4601 ctx.objErrStage1("function with non-extern non-packed enum parameter",
4602 \\const Foo = enum { A, B, C };
4603 \\export fn entry(foo: Foo) void { _ = foo; }
4604 , &[_][]const u8{
4605 "tmp.zig:2:22: error: parameter of type 'Foo' not allowed in function with calling convention 'C'",
4606 });
4607
4608 ctx.objErrStage1("function with non-extern non-packed struct parameter",
4609 \\const Foo = struct {
4610 \\ A: i32,
4611 \\ B: f32,
4612 \\ C: bool,
4613 \\};
4614 \\export fn entry(foo: Foo) void { _ = foo; }
4615 , &[_][]const u8{
4616 "tmp.zig:6:22: error: parameter of type 'Foo' not allowed in function with calling convention 'C'",
4617 });
4618
4619 ctx.objErrStage1("function with non-extern non-packed union parameter",
4620 \\const Foo = union {
4621 \\ A: i32,
4622 \\ B: f32,
4623 \\ C: bool,
4624 \\};
4625 \\export fn entry(foo: Foo) void { _ = foo; }
4626 , &[_][]const u8{
4627 "tmp.zig:6:22: error: parameter of type 'Foo' not allowed in function with calling convention 'C'",
4628 });
4629
4630 ctx.objErrStage1("switch on enum with 1 field with no prongs",
4631 \\const Foo = enum { M };
4632 \\
4633 \\export fn entry() void {
4634 \\ var f = Foo.M;
4635 \\ switch (f) {}
4636 \\}
4637 , &[_][]const u8{
4638 "tmp.zig:5:5: error: enumeration value 'Foo.M' not handled in switch",
4639 });
4640
4641 ctx.objErrStage1("shift by negative comptime integer",
4642 \\comptime {
4643 \\ var a = 1 >> -1;
4644 \\ _ = a;
4645 \\}
4646 , &[_][]const u8{
4647 "tmp.zig:2:18: error: shift by negative value -1",
4648 });
4649
4650 ctx.objErrStage1("@panic called at compile time",
4651 \\export fn entry() void {
4652 \\ comptime {
4653 \\ @panic("aoeu",);
4654 \\ }
4655 \\}
4656 , &[_][]const u8{
4657 "tmp.zig:3:9: error: encountered @panic at compile-time",
4658 });
4659
4660 ctx.objErrStage1("wrong return type for main",
4661 \\pub fn main() f32 { }
4662 , &[_][]const u8{
4663 "error: expected return type of main to be 'void', '!void', 'noreturn', 'u8', or '!u8'",
4664 });
4665
4666 ctx.objErrStage1("double ?? on main return value",
4667 \\pub fn main() ??void {
4668 \\}
4669 , &[_][]const u8{
4670 "error: expected return type of main to be 'void', '!void', 'noreturn', 'u8', or '!u8'",
4671 });
4672
4673 ctx.objErrStage1("bad identifier in function with struct defined inside function which references local const",
4674 \\export fn entry() void {
4675 \\ const BlockKind = u32;
4676 \\
4677 \\ const Block = struct {
4678 \\ kind: BlockKind,
4679 \\ };
4680 \\
4681 \\ bogus;
4682 \\
4683 \\ _ = Block;
4684 \\}
4685 , &[_][]const u8{
4686 "tmp.zig:8:5: error: use of undeclared identifier 'bogus'",
4687 });
4688
4689 ctx.objErrStage1("labeled break not found",
4690 \\export fn entry() void {
4691 \\ blah: while (true) {
4692 \\ while (true) {
4693 \\ break :outer;
4694 \\ }
4695 \\ }
4696 \\}
4697 , &[_][]const u8{
4698 "tmp.zig:4:20: error: label not found: 'outer'",
4699 });
4700
4701 ctx.objErrStage1("labeled continue not found",
4702 \\export fn entry() void {
4703 \\ var i: usize = 0;
4704 \\ blah: while (i < 10) : (i += 1) {
4705 \\ while (true) {
4706 \\ continue :outer;
4707 \\ }
4708 \\ }
4709 \\}
4710 , &[_][]const u8{
4711 "tmp.zig:5:23: error: label not found: 'outer'",
4712 });
4713
4714 ctx.objErrStage1("attempt to use 0 bit type in extern fn",
4715 \\extern fn foo(ptr: fn(*void) callconv(.C) void) void;
4716 \\
4717 \\export fn entry() void {
4718 \\ foo(bar);
4719 \\}
4720 \\
4721 \\fn bar(x: *void) callconv(.C) void { _ = x; }
4722 \\export fn entry2() void {
4723 \\ bar(&{});
4724 \\}
4725 , &[_][]const u8{
4726 "tmp.zig:1:23: error: parameter of type '*void' has 0 bits; not allowed in function with calling convention 'C'",
4727 "tmp.zig:7:11: error: parameter of type '*void' has 0 bits; not allowed in function with calling convention 'C'",
4728 });
4729
4730 ctx.objErrStage1("implicit semicolon - block statement",
4731 \\export fn entry() void {
4732 \\ {}
4733 \\ var good = {};
4734 \\ ({})
4735 \\ var bad = {};
4736 \\}
4737 , &[_][]const u8{
4738 "tmp.zig:4:9: error: expected ';' after statement",
4739 });
4740
4741 ctx.objErrStage1("implicit semicolon - block expr",
4742 \\export fn entry() void {
4743 \\ _ = {};
4744 \\ var good = {};
4745 \\ _ = {}
4746 \\ var bad = {};
4747 \\}
4748 , &[_][]const u8{
4749 "tmp.zig:4:11: error: expected ';' after statement",
4750 });
4751
4752 ctx.objErrStage1("implicit semicolon - comptime statement",
4753 \\export fn entry() void {
4754 \\ comptime {}
4755 \\ var good = {};
4756 \\ comptime ({})
4757 \\ var bad = {};
4758 \\}
4759 , &[_][]const u8{
4760 "tmp.zig:4:18: error: expected ';' after statement",
4761 });
4762
4763 ctx.objErrStage1("implicit semicolon - comptime expression",
4764 \\export fn entry() void {
4765 \\ _ = comptime {};
4766 \\ var good = {};
4767 \\ _ = comptime {}
4768 \\ var bad = {};
4769 \\}
4770 , &[_][]const u8{
4771 "tmp.zig:4:20: error: expected ';' after statement",
4772 });
4773
4774 ctx.objErrStage1("implicit semicolon - defer",
4775 \\export fn entry() void {
4776 \\ defer {}
4777 \\ var good = {};
4778 \\ defer ({})
4779 \\ var bad = {};
4780 \\}
4781 , &[_][]const u8{
4782 "tmp.zig:4:15: error: expected ';' after statement",
4783 });
4784
4785 ctx.objErrStage1("implicit semicolon - if statement",
4786 \\export fn entry() void {
4787 \\ if(true) {}
4788 \\ var good = {};
4789 \\ if(true) ({})
4790 \\ var bad = {};
4791 \\}
4792 , &[_][]const u8{
4793 "tmp.zig:4:18: error: expected ';' or 'else' after statement",
4794 });
4795
4796 ctx.objErrStage1("implicit semicolon - if expression",
4797 \\export fn entry() void {
4798 \\ _ = if(true) {};
4799 \\ var good = {};
4800 \\ _ = if(true) {}
4801 \\ var bad = {};
4802 \\}
4803 , &[_][]const u8{
4804 "tmp.zig:4:20: error: expected ';' after statement",
4805 });
4806
4807 ctx.objErrStage1("implicit semicolon - if-else statement",
4808 \\export fn entry() void {
4809 \\ if(true) {} else {}
4810 \\ var good = {};
4811 \\ if(true) ({}) else ({})
4812 \\ var bad = {};
4813 \\}
4814 , &[_][]const u8{
4815 "tmp.zig:4:28: error: expected ';' after statement",
4816 });
4817
4818 ctx.objErrStage1("implicit semicolon - if-else expression",
4819 \\export fn entry() void {
4820 \\ _ = if(true) {} else {};
4821 \\ var good = {};
4822 \\ _ = if(true) {} else {}
4823 \\ var bad = {};
4824 \\}
4825 , &[_][]const u8{
4826 "tmp.zig:4:28: error: expected ';' after statement",
4827 });
4828
4829 ctx.objErrStage1("implicit semicolon - if-else-if statement",
4830 \\export fn entry() void {
4831 \\ if(true) {} else if(true) {}
4832 \\ var good = {};
4833 \\ if(true) ({}) else if(true) ({})
4834 \\ var bad = {};
4835 \\}
4836 , &[_][]const u8{
4837 "tmp.zig:4:37: error: expected ';' or 'else' after statement",
4838 });
4839
4840 ctx.objErrStage1("implicit semicolon - if-else-if expression",
4841 \\export fn entry() void {
4842 \\ _ = if(true) {} else if(true) {};
4843 \\ var good = {};
4844 \\ _ = if(true) {} else if(true) {}
4845 \\ var bad = {};
4846 \\}
4847 , &[_][]const u8{
4848 "tmp.zig:4:37: error: expected ';' after statement",
4849 });
4850
4851 ctx.objErrStage1("implicit semicolon - if-else-if-else statement",
4852 \\export fn entry() void {
4853 \\ if(true) {} else if(true) {} else {}
4854 \\ var good = {};
4855 \\ if(true) ({}) else if(true) ({}) else ({})
4856 \\ var bad = {};
4857 \\}
4858 , &[_][]const u8{
4859 "tmp.zig:4:47: error: expected ';' after statement",
4860 });
4861
4862 ctx.objErrStage1("implicit semicolon - if-else-if-else expression",
4863 \\export fn entry() void {
4864 \\ _ = if(true) {} else if(true) {} else {};
4865 \\ var good = {};
4866 \\ _ = if(true) {} else if(true) {} else {}
4867 \\ var bad = {};
4868 \\}
4869 , &[_][]const u8{
4870 "tmp.zig:4:45: error: expected ';' after statement",
4871 });
4872
4873 ctx.objErrStage1("implicit semicolon - test statement",
4874 \\export fn entry() void {
4875 \\ if (foo()) |_| {}
4876 \\ var good = {};
4877 \\ if (foo()) |_| ({})
4878 \\ var bad = {};
4879 \\}
4880 , &[_][]const u8{
4881 "tmp.zig:4:24: error: expected ';' or 'else' after statement",
4882 });
4883
4884 ctx.objErrStage1("implicit semicolon - test expression",
4885 \\export fn entry() void {
4886 \\ _ = if (foo()) |_| {};
4887 \\ var good = {};
4888 \\ _ = if (foo()) |_| {}
4889 \\ var bad = {};
4890 \\}
4891 , &[_][]const u8{
4892 "tmp.zig:4:26: error: expected ';' after statement",
4893 });
4894
4895 ctx.objErrStage1("implicit semicolon - while statement",
4896 \\export fn entry() void {
4897 \\ while(true) {}
4898 \\ var good = {};
4899 \\ while(true) 1
4900 \\ var bad = {};
4901 \\}
4902 , &[_][]const u8{
4903 "tmp.zig:4:18: error: expected ';' or 'else' after statement",
4904 });
4905
4906 ctx.objErrStage1("implicit semicolon - while expression",
4907 \\export fn entry() void {
4908 \\ _ = while(true) {};
4909 \\ var good = {};
4910 \\ _ = while(true) {}
4911 \\ var bad = {};
4912 \\}
4913 , &[_][]const u8{
4914 "tmp.zig:4:23: error: expected ';' after statement",
4915 });
4916
4917 ctx.objErrStage1("implicit semicolon - while-continue statement",
4918 \\export fn entry() void {
4919 \\ while(true):({}) {}
4920 \\ var good = {};
4921 \\ while(true):({}) ({})
4922 \\ var bad = {};
4923 \\}
4924 , &[_][]const u8{
4925 "tmp.zig:4:26: error: expected ';' or 'else' after statement",
4926 });
4927
4928 ctx.objErrStage1("implicit semicolon - while-continue expression",
4929 \\export fn entry() void {
4930 \\ _ = while(true):({}) {};
4931 \\ var good = {};
4932 \\ _ = while(true):({}) {}
4933 \\ var bad = {};
4934 \\}
4935 , &[_][]const u8{
4936 "tmp.zig:4:28: error: expected ';' after statement",
4937 });
4938
4939 ctx.objErrStage1("implicit semicolon - for statement",
4940 \\export fn entry() void {
4941 \\ for(foo()) |_| {}
4942 \\ var good = {};
4943 \\ for(foo()) |_| ({})
4944 \\ var bad = {};
4945 \\}
4946 , &[_][]const u8{
4947 "tmp.zig:4:24: error: expected ';' or 'else' after statement",
4948 });
4949
4950 ctx.objErrStage1("implicit semicolon - for expression",
4951 \\export fn entry() void {
4952 \\ _ = for(foo()) |_| {};
4953 \\ var good = {};
4954 \\ _ = for(foo()) |_| {}
4955 \\ var bad = {};
4956 \\}
4957 , &[_][]const u8{
4958 "tmp.zig:4:26: error: expected ';' after statement",
4959 });
4960
4961 ctx.objErrStage1("multiple function definitions",
4962 \\fn a() void {}
4963 \\fn a() void {}
4964 \\export fn entry() void { a(); }
4965 , &[_][]const u8{
4966 "tmp.zig:2:1: error: redeclaration of 'a'",
4967 "tmp.zig:1:1: note: other declaration here",
4968 });
4969
4970 ctx.objErrStage1("unreachable with return",
4971 \\fn a() noreturn {return;}
4972 \\export fn entry() void { a(); }
4973 , &[_][]const u8{
4974 "tmp.zig:1:18: error: expected type 'noreturn', found 'void'",
4975 });
4976
4977 ctx.objErrStage1("control reaches end of non-void function",
4978 \\fn a() i32 {}
4979 \\export fn entry() void { _ = a(); }
4980 , &[_][]const u8{
4981 "tmp.zig:1:12: error: expected type 'i32', found 'void'",
4982 });
4983
4984 ctx.objErrStage1("undefined function call",
4985 \\export fn a() void {
4986 \\ b();
4987 \\}
4988 , &[_][]const u8{
4989 "tmp.zig:2:5: error: use of undeclared identifier 'b'",
4990 });
4991
4992 ctx.objErrStage1("wrong number of arguments",
4993 \\export fn a() void {
4994 \\ c(1);
4995 \\}
4996 \\fn c(d: i32, e: i32, f: i32) void { _ = d; _ = e; _ = f; }
4997 , &[_][]const u8{
4998 "tmp.zig:2:6: error: expected 3 argument(s), found 1",
4999 });
5000
5001 ctx.objErrStage1("invalid type",
5002 \\fn a() bogus {}
5003 \\export fn entry() void { _ = a(); }
5004 , &[_][]const u8{
5005 "tmp.zig:1:8: error: use of undeclared identifier 'bogus'",
5006 });
5007
5008 ctx.objErrStage1("pointer to noreturn",
5009 \\fn a() *noreturn {}
5010 \\export fn entry() void { _ = a(); }
5011 , &[_][]const u8{
5012 "tmp.zig:1:9: error: pointer to noreturn not allowed",
5013 });
5014
5015 ctx.objErrStage1("unreachable code",
5016 \\export fn a() void {
5017 \\ return;
5018 \\ b();
5019 \\}
5020 \\
5021 \\fn b() void {}
5022 , &[_][]const u8{
5023 "tmp.zig:3:6: error: unreachable code",
5024 "tmp.zig:2:5: note: control flow is diverted here",
5025 });
5026
5027 ctx.objErrStage1("unreachable code - nested returns",
5028 \\export fn a() i32 {
5029 \\ return return 1;
5030 \\}
5031 , &[_][]const u8{
5032 "tmp.zig:2:5: error: unreachable code",
5033 "tmp.zig:2:12: note: control flow is diverted here",
5034 });
5035
5036 ctx.objErrStage1("unreachable code - double break",
5037 \\export fn a() void {
5038 \\ const b = blk: {
5039 \\ break :blk break :blk @as(u32, 1);
5040 \\ };
5041 \\}
5042 , &[_][]const u8{
5043 "tmp.zig:3:9: error: unreachable code",
5044 "tmp.zig:3:20: note: control flow is diverted here",
5045 });
5046
5047 ctx.objErrStage1("chained comparison operators",
5048 \\export fn a(value: u32) bool {
5049 \\ return 1 < value < 1000;
5050 \\}
5051 , &[_][]const u8{
5052 "tmp.zig:2:22: error: comparison operators cannot be chained",
5053 });
5054
5055 ctx.objErrStage1("bad import",
5056 \\const bogus = @import("bogus-does-not-exist.zig",);
5057 , &[_][]const u8{
5058 "tmp.zig:1:23: error: unable to load '${DIR}bogus-does-not-exist.zig': FileNotFound",
5059 });
5060
5061 ctx.objErrStage1("undeclared identifier",
5062 \\export fn a() void {
5063 \\ return
5064 \\ b +
5065 \\ c;
5066 \\}
5067 , &[_][]const u8{
5068 "tmp.zig:3:5: error: use of undeclared identifier 'b'",
5069 });
5070
5071 ctx.objErrStage1("parameter redeclaration",
5072 \\fn f(a : i32, a : i32) void {
5073 \\}
5074 \\export fn entry() void { f(1, 2); }
5075 , &[_][]const u8{
5076 "tmp.zig:1:15: error: redeclaration of function parameter 'a'",
5077 "tmp.zig:1:6: note: previous declaration here",
5078 });
5079
5080 ctx.objErrStage1("local variable redeclaration",
5081 \\export fn f() void {
5082 \\ const a : i32 = 0;
5083 \\ var a = 0;
5084 \\}
5085 , &[_][]const u8{
5086 "tmp.zig:3:9: error: redeclaration of local constant 'a'",
5087 "tmp.zig:2:11: note: previous declaration here",
5088 });
5089
5090 ctx.objErrStage1("local variable redeclares parameter",
5091 \\fn f(a : i32) void {
5092 \\ const a = 0;
5093 \\}
5094 \\export fn entry() void { f(1); }
5095 , &[_][]const u8{
5096 "tmp.zig:2:11: error: redeclaration of function parameter 'a'",
5097 "tmp.zig:1:6: note: previous declaration here",
5098 });
5099
5100 ctx.objErrStage1("variable has wrong type",
5101 \\export fn f() i32 {
5102 \\ const a = "a";
5103 \\ return a;
5104 \\}
5105 , &[_][]const u8{
5106 "tmp.zig:3:12: error: expected type 'i32', found '*const [1:0]u8'",
5107 });
5108
5109 ctx.objErrStage1("if condition is bool, not int",
5110 \\export fn f() void {
5111 \\ if (0) {}
5112 \\}
5113 , &[_][]const u8{
5114 "tmp.zig:2:9: error: expected type 'bool', found 'comptime_int'",
5115 });
5116
5117 ctx.objErrStage1("assign unreachable",
5118 \\export fn f() void {
5119 \\ const a = return;
5120 \\}
5121 , &[_][]const u8{
5122 "tmp.zig:2:5: error: unreachable code",
5123 "tmp.zig:2:15: note: control flow is diverted here",
5124 });
5125
5126 ctx.objErrStage1("unreachable variable",
5127 \\export fn f() void {
5128 \\ const a: noreturn = {};
5129 \\ _ = a;
5130 \\}
5131 , &[_][]const u8{
5132 "tmp.zig:2:25: error: expected type 'noreturn', found 'void'",
5133 });
5134
5135 ctx.objErrStage1("unreachable parameter",
5136 \\fn f(a: noreturn) void { _ = a; }
5137 \\export fn entry() void { f(); }
5138 , &[_][]const u8{
5139 "tmp.zig:1:9: error: parameter of type 'noreturn' not allowed",
5140 });
5141
5142 ctx.objErrStage1("assign to constant variable",
5143 \\export fn f() void {
5144 \\ const a = 3;
5145 \\ a = 4;
5146 \\}
5147 , &[_][]const u8{
5148 "tmp.zig:3:9: error: cannot assign to constant",
5149 });
5150
5151 ctx.objErrStage1("use of undeclared identifier",
5152 \\export fn f() void {
5153 \\ b = 3;
5154 \\}
5155 , &[_][]const u8{
5156 "tmp.zig:2:5: error: use of undeclared identifier 'b'",
5157 });
5158
5159 ctx.objErrStage1("const is a statement, not an expression",
5160 \\export fn f() void {
5161 \\ (const a = 0);
5162 \\}
5163 , &[_][]const u8{
5164 "tmp.zig:2:6: error: expected expression, found 'const'",
5165 });
5166
5167 ctx.objErrStage1("array access of undeclared identifier",
5168 \\export fn f() void {
5169 \\ i[i] = i[i];
5170 \\}
5171 , &[_][]const u8{
5172 "tmp.zig:2:5: error: use of undeclared identifier 'i'",
5173 });
5174
5175 ctx.objErrStage1("array access of non array",
5176 \\export fn f() void {
5177 \\ var bad : bool = undefined;
5178 \\ bad[0] = bad[0];
5179 \\}
5180 \\export fn g() void {
5181 \\ var bad : bool = undefined;
5182 \\ _ = bad[0];
5183 \\}
5184 , &[_][]const u8{
5185 "tmp.zig:3:8: error: array access of non-array type 'bool'",
5186 "tmp.zig:7:12: error: array access of non-array type 'bool'",
5187 });
5188
5189 ctx.objErrStage1("array access with non integer index",
5190 \\export fn f() void {
5191 \\ var array = "aoeu";
5192 \\ var bad = false;
5193 \\ array[bad] = array[bad];
5194 \\}
5195 \\export fn g() void {
5196 \\ var array = "aoeu";
5197 \\ var bad = false;
5198 \\ _ = array[bad];
5199 \\}
5200 , &[_][]const u8{
5201 "tmp.zig:4:11: error: expected type 'usize', found 'bool'",
5202 "tmp.zig:9:15: error: expected type 'usize', found 'bool'",
5203 });
5204
5205 ctx.objErrStage1("write to const global variable",
5206 \\const x : i32 = 99;
5207 \\fn f() void {
5208 \\ x = 1;
5209 \\}
5210 \\export fn entry() void { f(); }
5211 , &[_][]const u8{
5212 "tmp.zig:3:9: error: cannot assign to constant",
5213 });
5214
5215 ctx.objErrStage1("missing else clause",
5216 \\fn f(b: bool) void {
5217 \\ const x : i32 = if (b) h: { break :h 1; };
5218 \\ _ = x;
5219 \\}
5220 \\fn g(b: bool) void {
5221 \\ const y = if (b) h: { break :h @as(i32, 1); };
5222 \\ _ = y;
5223 \\}
5224 \\export fn entry() void { f(true); g(true); }
5225 , &[_][]const u8{
5226 "tmp.zig:2:21: error: expected type 'i32', found 'void'",
5227 "tmp.zig:6:15: error: incompatible types: 'i32' and 'void'",
5228 });
5229
5230 ctx.objErrStage1("invalid struct field",
5231 \\const A = struct { x : i32, };
5232 \\export fn f() void {
5233 \\ var a : A = undefined;
5234 \\ a.foo = 1;
5235 \\ const y = a.bar;
5236 \\ _ = y;
5237 \\}
5238 \\export fn g() void {
5239 \\ var a : A = undefined;
5240 \\ const y = a.bar;
5241 \\ _ = y;
5242 \\}
5243 , &[_][]const u8{
5244 "tmp.zig:4:6: error: no member named 'foo' in struct 'A'",
5245 "tmp.zig:10:16: error: no member named 'bar' in struct 'A'",
5246 });
5247
5248 ctx.objErrStage1("redefinition of struct",
5249 \\const A = struct { x : i32, };
5250 \\const A = struct { y : i32, };
5251 , &[_][]const u8{
5252 "tmp.zig:2:1: error: redeclaration of 'A'",
5253 "tmp.zig:1:1: note: other declaration here",
5254 });
5255
5256 ctx.objErrStage1("redefinition of enums",
5257 \\const A = enum {x};
5258 \\const A = enum {x};
5259 , &[_][]const u8{
5260 "tmp.zig:2:1: error: redeclaration of 'A'",
5261 "tmp.zig:1:1: note: other declaration here",
5262 });
5263
5264 ctx.objErrStage1("redefinition of global variables",
5265 \\var a : i32 = 1;
5266 \\var a : i32 = 2;
5267 , &[_][]const u8{
5268 "tmp.zig:2:1: error: redeclaration of 'a'",
5269 "tmp.zig:1:1: note: other declaration here",
5270 });
5271
5272 ctx.objErrStage1("duplicate field in struct value expression",
5273 \\const A = struct {
5274 \\ x : i32,
5275 \\ y : i32,
5276 \\ z : i32,
5277 \\};
5278 \\export fn f() void {
5279 \\ const a = A {
5280 \\ .z = 1,
5281 \\ .y = 2,
5282 \\ .x = 3,
5283 \\ .z = 4,
5284 \\ };
5285 \\ _ = a;
5286 \\}
5287 , &[_][]const u8{
5288 "tmp.zig:11:9: error: duplicate field",
5289 });
5290
5291 ctx.objErrStage1("missing field in struct value expression",
5292 \\const A = struct {
5293 \\ x : i32,
5294 \\ y : i32,
5295 \\ z : i32,
5296 \\};
5297 \\export fn f() void {
5298 \\ // we want the error on the '{' not the 'A' because
5299 \\ // the A could be a complicated expression
5300 \\ const a = A {
5301 \\ .z = 4,
5302 \\ .y = 2,
5303 \\ };
5304 \\ _ = a;
5305 \\}
5306 , &[_][]const u8{
5307 "tmp.zig:9:17: error: missing field: 'x'",
5308 });
5309
5310 ctx.objErrStage1("invalid field in struct value expression",
5311 \\const A = struct {
5312 \\ x : i32,
5313 \\ y : i32,
5314 \\ z : i32,
5315 \\};
5316 \\export fn f() void {
5317 \\ const a = A {
5318 \\ .z = 4,
5319 \\ .y = 2,
5320 \\ .foo = 42,
5321 \\ };
5322 \\ _ = a;
5323 \\}
5324 , &[_][]const u8{
5325 "tmp.zig:10:9: error: no member named 'foo' in struct 'A'",
5326 });
5327
5328 ctx.objErrStage1("invalid break expression",
5329 \\export fn f() void {
5330 \\ break;
5331 \\}
5332 , &[_][]const u8{
5333 "tmp.zig:2:5: error: break expression outside loop",
5334 });
5335
5336 ctx.objErrStage1("invalid continue expression",
5337 \\export fn f() void {
5338 \\ continue;
5339 \\}
5340 , &[_][]const u8{
5341 "tmp.zig:2:5: error: continue expression outside loop",
5342 });
5343
5344 ctx.objErrStage1("invalid maybe type",
5345 \\export fn f() void {
5346 \\ if (true) |x| { _ = x; }
5347 \\}
5348 , &[_][]const u8{
5349 "tmp.zig:2:9: error: expected optional type, found 'bool'",
5350 });
5351
5352 ctx.objErrStage1("cast unreachable",
5353 \\fn f() i32 {
5354 \\ return @as(i32, return 1);
5355 \\}
5356 \\export fn entry() void { _ = f(); }
5357 , &[_][]const u8{
5358 "tmp.zig:2:12: error: unreachable code",
5359 "tmp.zig:2:21: note: control flow is diverted here",
5360 });
5361
5362 ctx.objErrStage1("invalid builtin fn",
5363 \\fn f() @bogus(foo) {
5364 \\}
5365 \\export fn entry() void { _ = f(); }
5366 , &[_][]const u8{
5367 "tmp.zig:1:8: error: invalid builtin function: '@bogus'",
5368 });
5369
5370 ctx.objErrStage1("noalias on non pointer param",
5371 \\fn f(noalias x: i32) void { _ = x; }
5372 \\export fn entry() void { f(1234); }
5373 , &[_][]const u8{
5374 "tmp.zig:1:6: error: noalias on non-pointer parameter",
5375 });
5376
5377 ctx.objErrStage1("struct init syntax for array",
5378 \\const foo = [3]u16{ .x = 1024 };
5379 \\comptime {
5380 \\ _ = foo;
5381 \\}
5382 , &[_][]const u8{
5383 "tmp.zig:1:13: error: initializing array with struct syntax",
5384 });
5385
5386 ctx.objErrStage1("type variables must be constant",
5387 \\var foo = u8;
5388 \\export fn entry() foo {
5389 \\ return 1;
5390 \\}
5391 , &[_][]const u8{
5392 "tmp.zig:1:1: error: variable of type 'type' must be constant",
5393 });
5394
5395 ctx.objErrStage1("parameter shadowing global",
5396 \\const Foo = struct {};
5397 \\fn f(Foo: i32) void {}
5398 \\export fn entry() void {
5399 \\ f(1234);
5400 \\}
5401 , &[_][]const u8{
5402 "tmp.zig:2:6: error: local shadows declaration of 'Foo'",
5403 "tmp.zig:1:1: note: declared here",
5404 });
5405
5406 ctx.objErrStage1("local variable shadowing global",
5407 \\const Foo = struct {};
5408 \\const Bar = struct {};
5409 \\
5410 \\export fn entry() void {
5411 \\ var Bar : i32 = undefined;
5412 \\ _ = Bar;
5413 \\}
5414 , &[_][]const u8{
5415 "tmp.zig:5:9: error: local shadows declaration of 'Bar'",
5416 "tmp.zig:2:1: note: declared here",
5417 });
5418
5419 ctx.objErrStage1("local shadows global that occurs later",
5420 \\pub fn main() void {
5421 \\ var foo = true;
5422 \\ _ = foo;
5423 \\}
5424 \\fn foo() void {}
5425 , &[_][]const u8{
5426 "tmp.zig:2:9: error: local shadows declaration of 'foo'",
5427 "tmp.zig:5:1: note: declared here",
5428 });
5429
5430 ctx.objErrStage1("switch expression - missing enumeration prong",
5431 \\const Number = enum {
5432 \\ One,
5433 \\ Two,
5434 \\ Three,
5435 \\ Four,
5436 \\};
5437 \\fn f(n: Number) i32 {
5438 \\ switch (n) {
5439 \\ Number.One => 1,
5440 \\ Number.Two => 2,
5441 \\ Number.Three => @as(i32, 3),
5442 \\ }
5443 \\}
5444 \\
5445 \\export fn entry() usize { return @sizeOf(@TypeOf(f)); }
5446 , &[_][]const u8{
5447 "tmp.zig:8:5: error: enumeration value 'Number.Four' not handled in switch",
5448 });
5449
5450 ctx.objErrStage1("switch expression - duplicate enumeration prong",
5451 \\const Number = enum {
5452 \\ One,
5453 \\ Two,
5454 \\ Three,
5455 \\ Four,
5456 \\};
5457 \\fn f(n: Number) i32 {
5458 \\ switch (n) {
5459 \\ Number.One => 1,
5460 \\ Number.Two => 2,
5461 \\ Number.Three => @as(i32, 3),
5462 \\ Number.Four => 4,
5463 \\ Number.Two => 2,
5464 \\ }
5465 \\}
5466 \\
5467 \\export fn entry() usize { return @sizeOf(@TypeOf(f)); }
5468 , &[_][]const u8{
5469 "tmp.zig:13:15: error: duplicate switch value",
5470 "tmp.zig:10:15: note: other value here",
5471 });
5472
5473 ctx.objErrStage1("switch expression - duplicate enumeration prong when else present",
5474 \\const Number = enum {
5475 \\ One,
5476 \\ Two,
5477 \\ Three,
5478 \\ Four,
5479 \\};
5480 \\fn f(n: Number) i32 {
5481 \\ switch (n) {
5482 \\ Number.One => 1,
5483 \\ Number.Two => 2,
5484 \\ Number.Three => @as(i32, 3),
5485 \\ Number.Four => 4,
5486 \\ Number.Two => 2,
5487 \\ else => 10,
5488 \\ }
5489 \\}
5490 \\
5491 \\export fn entry() usize { return @sizeOf(@TypeOf(f)); }
5492 , &[_][]const u8{
5493 "tmp.zig:13:15: error: duplicate switch value",
5494 "tmp.zig:10:15: note: other value here",
5495 });
5496
5497 ctx.objErrStage1("switch expression - multiple else prongs",
5498 \\fn f(x: u32) void {
5499 \\ const value: bool = switch (x) {
5500 \\ 1234 => false,
5501 \\ else => true,
5502 \\ else => true,
5503 \\ };
5504 \\}
5505 \\export fn entry() void {
5506 \\ f(1234);
5507 \\}
5508 , &[_][]const u8{
5509 "tmp.zig:5:9: error: multiple else prongs in switch expression",
5510 });
5511
5512 ctx.objErrStage1("switch expression - non exhaustive integer prongs",
5513 \\fn foo(x: u8) void {
5514 \\ switch (x) {
5515 \\ 0 => {},
5516 \\ }
5517 \\}
5518 \\export fn entry() usize { return @sizeOf(@TypeOf(foo)); }
5519 , &[_][]const u8{
5520 "tmp.zig:2:5: error: switch must handle all possibilities",
5521 });
5522
5523 ctx.objErrStage1("switch expression - duplicate or overlapping integer value",
5524 \\fn foo(x: u8) u8 {
5525 \\ return switch (x) {
5526 \\ 0 ... 100 => @as(u8, 0),
5527 \\ 101 ... 200 => 1,
5528 \\ 201, 203 ... 207 => 2,
5529 \\ 206 ... 255 => 3,
5530 \\ };
5531 \\}
5532 \\export fn entry() usize { return @sizeOf(@TypeOf(foo)); }
5533 , &[_][]const u8{
5534 "tmp.zig:6:9: error: duplicate switch value",
5535 "tmp.zig:5:14: note: previous value here",
5536 });
5537
5538 ctx.objErrStage1("switch expression - duplicate type",
5539 \\fn foo(comptime T: type, x: T) u8 {
5540 \\ _ = x;
5541 \\ return switch (T) {
5542 \\ u32 => 0,
5543 \\ u64 => 1,
5544 \\ u32 => 2,
5545 \\ else => 3,
5546 \\ };
5547 \\}
5548 \\export fn entry() usize { return @sizeOf(@TypeOf(foo(u32, 0))); }
5549 , &[_][]const u8{
5550 "tmp.zig:6:9: error: duplicate switch value",
5551 "tmp.zig:4:9: note: previous value here",
5552 });
5553
5554 ctx.objErrStage1("switch expression - duplicate type (struct alias)",
5555 \\const Test = struct {
5556 \\ bar: i32,
5557 \\};
5558 \\const Test2 = Test;
5559 \\fn foo(comptime T: type, x: T) u8 {
5560 \\ _ = x;
5561 \\ return switch (T) {
5562 \\ Test => 0,
5563 \\ u64 => 1,
5564 \\ Test2 => 2,
5565 \\ else => 3,
5566 \\ };
5567 \\}
5568 \\export fn entry() usize { return @sizeOf(@TypeOf(foo(u32, 0))); }
5569 , &[_][]const u8{
5570 "tmp.zig:10:9: error: duplicate switch value",
5571 "tmp.zig:8:9: note: previous value here",
5572 });
5573
5574 ctx.objErrStage1("switch expression - switch on pointer type with no else",
5575 \\fn foo(x: *u8) void {
5576 \\ switch (x) {
5577 \\ &y => {},
5578 \\ }
5579 \\}
5580 \\const y: u8 = 100;
5581 \\export fn entry() usize { return @sizeOf(@TypeOf(foo)); }
5582 , &[_][]const u8{
5583 "tmp.zig:2:5: error: else prong required when switching on type '*u8'",
5584 });
5585
5586 ctx.objErrStage1("global variable initializer must be constant expression",
5587 \\extern fn foo() i32;
5588 \\const x = foo();
5589 \\export fn entry() i32 { return x; }
5590 , &[_][]const u8{
5591 "tmp.zig:2:11: error: unable to evaluate constant expression",
5592 });
5593
5594 ctx.objErrStage1("array concatenation with wrong type",
5595 \\const src = "aoeu";
5596 \\const derp: usize = 1234;
5597 \\const a = derp ++ "foo";
5598 \\
5599 \\export fn entry() usize { return @sizeOf(@TypeOf(a)); }
5600 , &[_][]const u8{
5601 "tmp.zig:3:11: error: expected array, found 'usize'",
5602 });
5603
5604 ctx.objErrStage1("non compile time array concatenation",
5605 \\fn f() []u8 {
5606 \\ return s ++ "foo";
5607 \\}
5608 \\var s: [10]u8 = undefined;
5609 \\export fn entry() usize { return @sizeOf(@TypeOf(f)); }
5610 , &[_][]const u8{
5611 "tmp.zig:2:12: error: unable to evaluate constant expression",
5612 });
5613
5614 ctx.objErrStage1("@cImport with bogus include",
5615 \\const c = @cImport(@cInclude("bogus.h"));
5616 \\export fn entry() usize { return @sizeOf(@TypeOf(c.bogo)); }
5617 , &[_][]const u8{
5618 "tmp.zig:1:11: error: C import failed",
5619 ".h:1:10: note: 'bogus.h' file not found",
5620 });
5621
5622 ctx.objErrStage1("address of number literal",
5623 \\const x = 3;
5624 \\const y = &x;
5625 \\fn foo() *const i32 { return y; }
5626 \\export fn entry() usize { return @sizeOf(@TypeOf(foo)); }
5627 , &[_][]const u8{
5628 "tmp.zig:3:30: error: expected type '*const i32', found '*const comptime_int'",
5629 });
5630
5631 ctx.objErrStage1("integer overflow error",
5632 \\const x : u8 = 300;
5633 \\export fn entry() usize { return @sizeOf(@TypeOf(x)); }
5634 , &[_][]const u8{
5635 "tmp.zig:1:16: error: integer value 300 cannot be coerced to type 'u8'",
5636 });
5637
5638 ctx.objErrStage1("invalid shift amount error",
5639 \\const x : u8 = 2;
5640 \\fn f() u16 {
5641 \\ return x << 8;
5642 \\}
5643 \\export fn entry() u16 { return f(); }
5644 , &[_][]const u8{
5645 "tmp.zig:3:17: error: integer value 8 cannot be coerced to type 'u3'",
5646 });
5647
5648 ctx.objErrStage1("missing function call param",
5649 \\const Foo = struct {
5650 \\ a: i32,
5651 \\ b: i32,
5652 \\
5653 \\ fn member_a(foo: *const Foo) i32 {
5654 \\ return foo.a;
5655 \\ }
5656 \\ fn member_b(foo: *const Foo) i32 {
5657 \\ return foo.b;
5658 \\ }
5659 \\};
5660 \\
5661 \\const member_fn_type = @TypeOf(Foo.member_a);
5662 \\const members = [_]member_fn_type {
5663 \\ Foo.member_a,
5664 \\ Foo.member_b,
5665 \\};
5666 \\
5667 \\fn f(foo: *const Foo, index: usize) void {
5668 \\ const result = members[index]();
5669 \\ _ = foo;
5670 \\ _ = result;
5671 \\}
5672 \\
5673 \\export fn entry() usize { return @sizeOf(@TypeOf(f)); }
5674 , &[_][]const u8{
5675 "tmp.zig:20:34: error: expected 1 argument(s), found 0",
5676 });
5677
5678 ctx.objErrStage1("missing function name",
5679 \\fn () void {}
5680 \\export fn entry() usize { return @sizeOf(@TypeOf(f)); }
5681 , &[_][]const u8{
5682 "tmp.zig:1:1: error: missing function name",
5683 });
5684
5685 ctx.objErrStage1("missing param name",
5686 \\fn f(i32) void {}
5687 \\export fn entry() usize { return @sizeOf(@TypeOf(f)); }
5688 , &[_][]const u8{
5689 "tmp.zig:1:6: error: missing parameter name",
5690 });
5691
5692 ctx.objErrStage1("wrong function type",
5693 \\const fns = [_]fn() void { a, b, c };
5694 \\fn a() i32 {return 0;}
5695 \\fn b() i32 {return 1;}
5696 \\fn c() i32 {return 2;}
5697 \\export fn entry() usize { return @sizeOf(@TypeOf(fns)); }
5698 , &[_][]const u8{
5699 "tmp.zig:1:28: error: expected type 'fn() void', found 'fn() i32'",
5700 });
5701
5702 ctx.objErrStage1("extern function pointer mismatch",
5703 \\const fns = [_](fn(i32)i32) { a, b, c };
5704 \\pub fn a(x: i32) i32 {return x + 0;}
5705 \\pub fn b(x: i32) i32 {return x + 1;}
5706 \\export fn c(x: i32) i32 {return x + 2;}
5707 \\
5708 \\export fn entry() usize { return @sizeOf(@TypeOf(fns)); }
5709 , &[_][]const u8{
5710 "tmp.zig:1:37: error: expected type 'fn(i32) i32', found 'fn(i32) callconv(.C) i32'",
5711 });
5712
5713 ctx.objErrStage1("colliding invalid top level functions",
5714 \\fn func() bogus {}
5715 \\fn func() bogus {}
5716 \\export fn entry() usize { return @sizeOf(@TypeOf(func)); }
5717 , &[_][]const u8{
5718 "tmp.zig:2:1: error: redeclaration of 'func'",
5719 "tmp.zig:1:1: note: other declaration here",
5720 });
5721
5722 ctx.objErrStage1("non constant expression in array size",
5723 \\const Foo = struct {
5724 \\ y: [get()]u8,
5725 \\};
5726 \\var global_var: usize = 1;
5727 \\fn get() usize { return global_var; }
5728 \\
5729 \\export fn entry() usize { return @sizeOf(@TypeOf(Foo)); }
5730 , &[_][]const u8{
5731 "tmp.zig:5:25: error: cannot store runtime value in compile time variable",
5732 "tmp.zig:2:12: note: called from here",
5733 });
5734
5735 ctx.objErrStage1("addition with non numbers",
5736 \\const Foo = struct {
5737 \\ field: i32,
5738 \\};
5739 \\const x = Foo {.field = 1} + Foo {.field = 2};
5740 \\
5741 \\export fn entry() usize { return @sizeOf(@TypeOf(x)); }
5742 , &[_][]const u8{
5743 "tmp.zig:4:28: error: invalid operands to binary expression: 'Foo' and 'Foo'",
5744 });
5745
5746 ctx.objErrStage1("division by zero",
5747 \\const lit_int_x = 1 / 0;
5748 \\const lit_float_x = 1.0 / 0.0;
5749 \\const int_x = @as(u32, 1) / @as(u32, 0);
5750 \\const float_x = @as(f32, 1.0) / @as(f32, 0.0);
5751 \\
5752 \\export fn entry1() usize { return @sizeOf(@TypeOf(lit_int_x)); }
5753 \\export fn entry2() usize { return @sizeOf(@TypeOf(lit_float_x)); }
5754 \\export fn entry3() usize { return @sizeOf(@TypeOf(int_x)); }
5755 \\export fn entry4() usize { return @sizeOf(@TypeOf(float_x)); }
5756 , &[_][]const u8{
5757 "tmp.zig:1:21: error: division by zero",
5758 "tmp.zig:2:25: error: division by zero",
5759 "tmp.zig:3:27: error: division by zero",
5760 "tmp.zig:4:31: error: division by zero",
5761 });
5762
5763 ctx.objErrStage1("normal string with newline",
5764 \\const foo = "a
5765 \\b";
5766 , &[_][]const u8{
5767 "tmp.zig:1:13: error: expected expression, found 'invalid bytes'",
5768 "tmp.zig:1:15: note: invalid byte: '\\n'",
5769 });
5770
5771 ctx.objErrStage1("invalid comparison for function pointers",
5772 \\fn foo() void {}
5773 \\const invalid = foo > foo;
5774 \\
5775 \\export fn entry() usize { return @sizeOf(@TypeOf(invalid)); }
5776 , &[_][]const u8{
5777 "tmp.zig:2:21: error: operator not allowed for type 'fn() void'",
5778 });
5779
5780 ctx.objErrStage1("generic function instance with non-constant expression",
5781 \\fn foo(comptime x: i32, y: i32) i32 { return x + y; }
5782 \\fn test1(a: i32, b: i32) i32 {
5783 \\ return foo(a, b);
5784 \\}
5785 \\
5786 \\export fn entry() usize { return @sizeOf(@TypeOf(test1)); }
5787 , &[_][]const u8{
5788 "tmp.zig:3:16: error: runtime value cannot be passed to comptime arg",
5789 });
5790
5791 ctx.objErrStage1("assign null to non-optional pointer",
5792 \\const a: *u8 = null;
5793 \\
5794 \\export fn entry() usize { return @sizeOf(@TypeOf(a)); }
5795 , &[_][]const u8{
5796 "tmp.zig:1:16: error: expected type '*u8', found '@Type(.Null)'",
5797 });
5798
5799 ctx.objErrStage1("indexing an array of size zero",
5800 \\const array = [_]u8{};
5801 \\export fn foo() void {
5802 \\ const pointer = &array[0];
5803 \\ _ = pointer;
5804 \\}
5805 , &[_][]const u8{
5806 "tmp.zig:3:27: error: accessing a zero length array is not allowed",
5807 });
5808
5809 ctx.objErrStage1("indexing an array of size zero with runtime index",
5810 \\const array = [_]u8{};
5811 \\export fn foo() void {
5812 \\ var index: usize = 0;
5813 \\ const pointer = &array[index];
5814 \\ _ = pointer;
5815 \\}
5816 , &[_][]const u8{
5817 "tmp.zig:4:27: error: accessing a zero length array is not allowed",
5818 });
5819
5820 ctx.objErrStage1("compile time division by zero",
5821 \\const y = foo(0);
5822 \\fn foo(x: u32) u32 {
5823 \\ return 1 / x;
5824 \\}
5825 \\
5826 \\export fn entry() usize { return @sizeOf(@TypeOf(y)); }
5827 , &[_][]const u8{
5828 "tmp.zig:3:14: error: division by zero",
5829 });
5830
5831 ctx.objErrStage1("branch on undefined value",
5832 \\const x = if (undefined) true else false;
5833 \\
5834 \\export fn entry() usize { return @sizeOf(@TypeOf(x)); }
5835 , &[_][]const u8{
5836 "tmp.zig:1:15: error: use of undefined value here causes undefined behavior",
5837 });
5838
5839 ctx.objErrStage1("div on undefined value",
5840 \\comptime {
5841 \\ var a: i64 = undefined;
5842 \\ _ = a / a;
5843 \\}
5844 , &[_][]const u8{
5845 "tmp.zig:3:9: error: use of undefined value here causes undefined behavior",
5846 });
5847
5848 ctx.objErrStage1("div assign on undefined value",
5849 \\comptime {
5850 \\ var a: i64 = undefined;
5851 \\ a /= a;
5852 \\}
5853 , &[_][]const u8{
5854 "tmp.zig:3:5: error: use of undefined value here causes undefined behavior",
5855 });
5856
5857 ctx.objErrStage1("mod on undefined value",
5858 \\comptime {
5859 \\ var a: i64 = undefined;
5860 \\ _ = a % a;
5861 \\}
5862 , &[_][]const u8{
5863 "tmp.zig:3:9: error: use of undefined value here causes undefined behavior",
5864 });
5865
5866 ctx.objErrStage1("mod assign on undefined value",
5867 \\comptime {
5868 \\ var a: i64 = undefined;
5869 \\ a %= a;
5870 \\}
5871 , &[_][]const u8{
5872 "tmp.zig:3:5: error: use of undefined value here causes undefined behavior",
5873 });
5874
5875 ctx.objErrStage1("add 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("add 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("add wrap 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("add wrap 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("sub 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("sub 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("sub 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("sub 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("mult 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("mult 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("mult 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("mult 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("shift left on undefined value",
5984 \\comptime {
5985 \\ var a: i64 = undefined;
5986 \\ _ = a << 2;
5987 \\}
5988 , &[_][]const u8{
5989 "tmp.zig:3:9: error: use of undefined value here causes undefined behavior",
5990 });
5991
5992 ctx.objErrStage1("shift left assign on undefined value",
5993 \\comptime {
5994 \\ var a: i64 = undefined;
5995 \\ a <<= 2;
5996 \\}
5997 , &[_][]const u8{
5998 "tmp.zig:3:5: error: use of undefined value here causes undefined behavior",
5999 });
6000
6001 ctx.objErrStage1("shift right on undefined value",
6002 \\comptime {
6003 \\ var a: i64 = undefined;
6004 \\ _ = a >> 2;
6005 \\}
6006 , &[_][]const u8{
6007 "tmp.zig:3:9: error: use of undefined value here causes undefined behavior",
6008 });
6009
6010 ctx.objErrStage1("shift left assign on undefined value",
6011 \\comptime {
6012 \\ var a: i64 = undefined;
6013 \\ a >>= 2;
6014 \\}
6015 , &[_][]const u8{
6016 "tmp.zig:3:5: error: use of undefined value here causes undefined behavior",
6017 });
6018
6019 ctx.objErrStage1("bin and on undefined value",
6020 \\comptime {
6021 \\ var a: i64 = undefined;
6022 \\ _ = a & a;
6023 \\}
6024 , &[_][]const u8{
6025 "tmp.zig:3:9: error: use of undefined value here causes undefined behavior",
6026 });
6027
6028 ctx.objErrStage1("bin and assign on undefined value",
6029 \\comptime {
6030 \\ var a: i64 = undefined;
6031 \\ a &= a;
6032 \\}
6033 , &[_][]const u8{
6034 "tmp.zig:3:5: error: use of undefined value here causes undefined behavior",
6035 });
6036
6037 ctx.objErrStage1("bin or on undefined value",
6038 \\comptime {
6039 \\ var a: i64 = undefined;
6040 \\ _ = a | a;
6041 \\}
6042 , &[_][]const u8{
6043 "tmp.zig:3:9: error: use of undefined value here causes undefined behavior",
6044 });
6045
6046 ctx.objErrStage1("bin or assign on undefined value",
6047 \\comptime {
6048 \\ var a: i64 = undefined;
6049 \\ a |= a;
6050 \\}
6051 , &[_][]const u8{
6052 "tmp.zig:3:5: error: use of undefined value here causes undefined behavior",
6053 });
6054
6055 ctx.objErrStage1("bin xor 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 xor 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("comparison operators with undefined value",
6074 \\// operator ==
6075 \\comptime {
6076 \\ var a: i64 = undefined;
6077 \\ var x: i32 = 0;
6078 \\ if (a == a) x += 1;
6079 \\}
6080 \\// operator !=
6081 \\comptime {
6082 \\ var a: i64 = undefined;
6083 \\ var x: i32 = 0;
6084 \\ if (a != a) x += 1;
6085 \\}
6086 \\// operator >
6087 \\comptime {
6088 \\ var a: i64 = undefined;
6089 \\ var x: i32 = 0;
6090 \\ if (a > a) x += 1;
6091 \\}
6092 \\// operator <
6093 \\comptime {
6094 \\ var a: i64 = undefined;
6095 \\ var x: i32 = 0;
6096 \\ if (a < a) x += 1;
6097 \\}
6098 \\// operator >=
6099 \\comptime {
6100 \\ var a: i64 = undefined;
6101 \\ var x: i32 = 0;
6102 \\ if (a >= a) x += 1;
6103 \\}
6104 \\// operator <=
6105 \\comptime {
6106 \\ var a: i64 = undefined;
6107 \\ var x: i32 = 0;
6108 \\ if (a <= a) x += 1;
6109 \\}
6110 , &[_][]const u8{
6111 "tmp.zig:5:11: error: use of undefined value here causes undefined behavior",
6112 "tmp.zig:11:11: error: use of undefined value here causes undefined behavior",
6113 "tmp.zig:17:11: error: use of undefined value here causes undefined behavior",
6114 "tmp.zig:23:11: error: use of undefined value here causes undefined behavior",
6115 "tmp.zig:29:11: error: use of undefined value here causes undefined behavior",
6116 "tmp.zig:35:11: error: use of undefined value here causes undefined behavior",
6117 });
6118
6119 ctx.objErrStage1("and on undefined value",
6120 \\comptime {
6121 \\ var a: bool = undefined;
6122 \\ _ = a and a;
6123 \\}
6124 , &[_][]const u8{
6125 "tmp.zig:3:9: error: use of undefined value here causes undefined behavior",
6126 });
6127
6128 ctx.objErrStage1("or on undefined value",
6129 \\comptime {
6130 \\ var a: bool = undefined;
6131 \\ _ = a or a;
6132 \\}
6133 , &[_][]const u8{
6134 "tmp.zig:3:9: error: use of undefined value here causes undefined behavior",
6135 });
6136
6137 ctx.objErrStage1("negate on undefined value",
6138 \\comptime {
6139 \\ var a: i64 = undefined;
6140 \\ _ = -a;
6141 \\}
6142 , &[_][]const u8{
6143 "tmp.zig:3:10: error: use of undefined value here causes undefined behavior",
6144 });
6145
6146 ctx.objErrStage1("negate wrap on undefined value",
6147 \\comptime {
6148 \\ var a: i64 = undefined;
6149 \\ _ = -%a;
6150 \\}
6151 , &[_][]const u8{
6152 "tmp.zig:3:11: error: use of undefined value here causes undefined behavior",
6153 });
6154
6155 ctx.objErrStage1("bin not on undefined value",
6156 \\comptime {
6157 \\ var a: i64 = undefined;
6158 \\ _ = ~a;
6159 \\}
6160 , &[_][]const u8{
6161 "tmp.zig:3:10: error: use of undefined value here causes undefined behavior",
6162 });
6163
6164 ctx.objErrStage1("bool not on undefined value",
6165 \\comptime {
6166 \\ var a: bool = undefined;
6167 \\ _ = !a;
6168 \\}
6169 , &[_][]const u8{
6170 "tmp.zig:3:10: error: use of undefined value here causes undefined behavior",
6171 });
6172
6173 ctx.objErrStage1("orelse on undefined value",
6174 \\comptime {
6175 \\ var a: ?bool = undefined;
6176 \\ _ = a orelse false;
6177 \\}
6178 , &[_][]const u8{
6179 "tmp.zig:3:11: error: use of undefined value here causes undefined behavior",
6180 });
6181
6182 ctx.objErrStage1("catch on undefined value",
6183 \\comptime {
6184 \\ var a: anyerror!bool = undefined;
6185 \\ _ = a catch false;
6186 \\}
6187 , &[_][]const u8{
6188 "tmp.zig:3:11: error: use of undefined value here causes undefined behavior",
6189 });
6190
6191 ctx.objErrStage1("deref on undefined value",
6192 \\comptime {
6193 \\ var a: *u8 = undefined;
6194 \\ _ = a.*;
6195 \\}
6196 , &[_][]const u8{
6197 "tmp.zig:3:9: error: attempt to dereference undefined value",
6198 });
6199
6200 ctx.objErrStage1("endless loop in function evaluation",
6201 \\const seventh_fib_number = fibonacci(7);
6202 \\fn fibonacci(x: i32) i32 {
6203 \\ return fibonacci(x - 1) + fibonacci(x - 2);
6204 \\}
6205 \\
6206 \\export fn entry() usize { return @sizeOf(@TypeOf(seventh_fib_number)); }
6207 , &[_][]const u8{
6208 "tmp.zig:3:21: error: evaluation exceeded 1000 backwards branches",
6209 });
6210
6211 ctx.objErrStage1("@embedFile with bogus file",
6212 \\const resource = @embedFile("bogus.txt",);
6213 \\
6214 \\export fn entry() usize { return @sizeOf(@TypeOf(resource)); }
6215 , &[_][]const u8{
6216 "tmp.zig:1:29: error: unable to find '",
6217 });
6218
6219 ctx.objErrStage1("non-const expression in struct literal outside function",
6220 \\const Foo = struct {
6221 \\ x: i32,
6222 \\};
6223 \\const a = Foo {.x = get_it()};
6224 \\extern fn get_it() i32;
6225 \\
6226 \\export fn entry() usize { return @sizeOf(@TypeOf(a)); }
6227 , &[_][]const u8{
6228 "tmp.zig:4:21: error: unable to evaluate constant expression",
6229 });
6230
6231 ctx.objErrStage1("non-const expression function call with struct return value outside function",
6232 \\const Foo = struct {
6233 \\ x: i32,
6234 \\};
6235 \\const a = get_it();
6236 \\fn get_it() Foo {
6237 \\ global_side_effect = true;
6238 \\ return Foo {.x = 13};
6239 \\}
6240 \\var global_side_effect = false;
6241 \\
6242 \\export fn entry() usize { return @sizeOf(@TypeOf(a)); }
6243 , &[_][]const u8{
6244 "tmp.zig:6:26: error: unable to evaluate constant expression",
6245 });
6246
6247 ctx.objErrStage1("undeclared identifier error should mark fn as impure",
6248 \\export fn foo() void {
6249 \\ test_a_thing();
6250 \\}
6251 \\fn test_a_thing() void {
6252 \\ bad_fn_call();
6253 \\}
6254 , &[_][]const u8{
6255 "tmp.zig:5:5: error: use of undeclared identifier 'bad_fn_call'",
6256 });
6257
6258 ctx.objErrStage1("illegal comparison of types",
6259 \\fn bad_eql_1(a: []u8, b: []u8) bool {
6260 \\ return a == b;
6261 \\}
6262 \\const EnumWithData = union(enum) {
6263 \\ One: void,
6264 \\ Two: i32,
6265 \\};
6266 \\fn bad_eql_2(a: *const EnumWithData, b: *const EnumWithData) bool {
6267 \\ return a.* == b.*;
6268 \\}
6269 \\
6270 \\export fn entry1() usize { return @sizeOf(@TypeOf(bad_eql_1)); }
6271 \\export fn entry2() usize { return @sizeOf(@TypeOf(bad_eql_2)); }
6272 , &[_][]const u8{
6273 "tmp.zig:2:14: error: operator not allowed for type '[]u8'",
6274 "tmp.zig:9:16: error: operator not allowed for type 'EnumWithData'",
6275 });
6276
6277 ctx.objErrStage1("non-const switch number literal",
6278 \\export fn foo() void {
6279 \\ const x = switch (bar()) {
6280 \\ 1, 2 => 1,
6281 \\ 3, 4 => 2,
6282 \\ else => 3,
6283 \\ };
6284 \\ _ = x;
6285 \\}
6286 \\fn bar() i32 {
6287 \\ return 2;
6288 \\}
6289 , &[_][]const u8{
6290 "tmp.zig:5:17: error: cannot store runtime value in type 'comptime_int'",
6291 });
6292
6293 ctx.objErrStage1("atomic orderings of cmpxchg - failure stricter than success",
6294 \\const AtomicOrder = @import("std").builtin.AtomicOrder;
6295 \\export fn f() void {
6296 \\ var x: i32 = 1234;
6297 \\ while (!@cmpxchgWeak(i32, &x, 1234, 5678, AtomicOrder.Monotonic, AtomicOrder.SeqCst)) {}
6298 \\}
6299 , &[_][]const u8{
6300 "tmp.zig:4:81: error: failure atomic ordering must be no stricter than success",
6301 });
6302
6303 ctx.objErrStage1("atomic orderings of cmpxchg - success Monotonic or stricter",
6304 \\const AtomicOrder = @import("std").builtin.AtomicOrder;
6305 \\export fn f() void {
6306 \\ var x: i32 = 1234;
6307 \\ while (!@cmpxchgWeak(i32, &x, 1234, 5678, AtomicOrder.Unordered, AtomicOrder.Unordered)) {}
6308 \\}
6309 , &[_][]const u8{
6310 "tmp.zig:4:58: error: success atomic ordering must be Monotonic or stricter",
6311 });
6312
6313 ctx.objErrStage1("negation overflow in function evaluation",
6314 \\const y = neg(-128);
6315 \\fn neg(x: i8) i8 {
6316 \\ return -x;
6317 \\}
6318 \\
6319 \\export fn entry() usize { return @sizeOf(@TypeOf(y)); }
6320 , &[_][]const u8{
6321 "tmp.zig:3:12: error: negation caused overflow",
6322 });
6323
6324 ctx.objErrStage1("add overflow in function evaluation",
6325 \\const y = add(65530, 10);
6326 \\fn add(a: u16, b: u16) u16 {
6327 \\ return a + b;
6328 \\}
6329 \\
6330 \\export fn entry() usize { return @sizeOf(@TypeOf(y)); }
6331 , &[_][]const u8{
6332 "tmp.zig:3:14: error: operation caused overflow",
6333 });
6334
6335 ctx.objErrStage1("sub overflow in function evaluation",
6336 \\const y = sub(10, 20);
6337 \\fn sub(a: u16, b: u16) u16 {
6338 \\ return a - b;
6339 \\}
6340 \\
6341 \\export fn entry() usize { return @sizeOf(@TypeOf(y)); }
6342 , &[_][]const u8{
6343 "tmp.zig:3:14: error: operation caused overflow",
6344 });
6345
6346 ctx.objErrStage1("mul overflow in function evaluation",
6347 \\const y = mul(300, 6000);
6348 \\fn mul(a: u16, b: u16) u16 {
6349 \\ return a * b;
6350 \\}
6351 \\
6352 \\export fn entry() usize { return @sizeOf(@TypeOf(y)); }
6353 , &[_][]const u8{
6354 "tmp.zig:3:14: error: operation caused overflow",
6355 });
6356
6357 ctx.objErrStage1("truncate sign mismatch",
6358 \\export fn entry1() i8 {
6359 \\ var x: u32 = 10;
6360 \\ return @truncate(i8, x);
6361 \\}
6362 \\export fn entry2() u8 {
6363 \\ var x: i32 = -10;
6364 \\ return @truncate(u8, x);
6365 \\}
6366 \\export fn entry3() i8 {
6367 \\ comptime var x: u32 = 10;
6368 \\ return @truncate(i8, x);
6369 \\}
6370 \\export fn entry4() u8 {
6371 \\ comptime var x: i32 = -10;
6372 \\ return @truncate(u8, x);
6373 \\}
6374 , &[_][]const u8{
6375 "tmp.zig:3:26: error: expected signed integer type, found 'u32'",
6376 "tmp.zig:7:26: error: expected unsigned integer type, found 'i32'",
6377 "tmp.zig:11:26: error: expected signed integer type, found 'u32'",
6378 "tmp.zig:15:26: error: expected unsigned integer type, found 'i32'",
6379 });
6380
6381 ctx.objErrStage1("try in function with non error return type",
6382 \\export fn f() void {
6383 \\ try something();
6384 \\}
6385 \\fn something() anyerror!void { }
6386 , &[_][]const u8{
6387 "tmp.zig:2:5: error: expected type 'void', found 'anyerror'",
6388 });
6389
6390 ctx.objErrStage1("invalid pointer for var type",
6391 \\extern fn ext() usize;
6392 \\var bytes: [ext()]u8 = undefined;
6393 \\export fn f() void {
6394 \\ for (bytes) |*b, i| {
6395 \\ b.* = @as(u8, i);
6396 \\ }
6397 \\}
6398 , &[_][]const u8{
6399 "tmp.zig:2:13: error: unable to evaluate constant expression",
6400 });
6401
6402 ctx.objErrStage1("export function with comptime parameter",
6403 \\export fn foo(comptime x: i32, y: i32) i32{
6404 \\ return x + y;
6405 \\}
6406 , &[_][]const u8{
6407 "tmp.zig:1:15: error: comptime parameter not allowed in function with calling convention 'C'",
6408 });
6409
6410 ctx.objErrStage1("extern function with comptime parameter",
6411 \\extern fn foo(comptime x: i32, y: i32) i32;
6412 \\fn f() i32 {
6413 \\ return foo(1, 2);
6414 \\}
6415 \\export fn entry() usize { return @sizeOf(@TypeOf(f)); }
6416 , &[_][]const u8{
6417 "tmp.zig:1:15: error: comptime parameter not allowed in function with calling convention 'C'",
6418 });
6419
6420 ctx.objErrStage1("non-pure function returns type",
6421 \\var a: u32 = 0;
6422 \\pub fn List(comptime T: type) type {
6423 \\ a += 1;
6424 \\ return SmallList(T, 8);
6425 \\}
6426 \\
6427 \\pub fn SmallList(comptime T: type, comptime STATIC_SIZE: usize) type {
6428 \\ return struct {
6429 \\ items: []T,
6430 \\ length: usize,
6431 \\ prealloc_items: [STATIC_SIZE]T,
6432 \\ };
6433 \\}
6434 \\
6435 \\export fn function_with_return_type_type() void {
6436 \\ var list: List(i32) = undefined;
6437 \\ list.length = 10;
6438 \\}
6439 , &[_][]const u8{
6440 "tmp.zig:3:7: error: unable to evaluate constant expression",
6441 });
6442
6443 ctx.objErrStage1("bogus method call on slice",
6444 \\var self = "aoeu";
6445 \\fn f(m: []const u8) void {
6446 \\ m.copy(u8, self[0..], m);
6447 \\}
6448 \\export fn entry() usize { return @sizeOf(@TypeOf(f)); }
6449 , &[_][]const u8{
6450 "tmp.zig:3:6: error: no member named 'copy' in '[]const u8'",
6451 });
6452
6453 ctx.objErrStage1("wrong number of arguments for method fn call",
6454 \\const Foo = struct {
6455 \\ fn method(self: *const Foo, a: i32) void {_ = self; _ = a;}
6456 \\};
6457 \\fn f(foo: *const Foo) void {
6458 \\
6459 \\ foo.method(1, 2);
6460 \\}
6461 \\export fn entry() usize { return @sizeOf(@TypeOf(f)); }
6462 , &[_][]const u8{
6463 "tmp.zig:6:15: error: expected 2 argument(s), found 3",
6464 });
6465
6466 ctx.objErrStage1("assign through constant pointer",
6467 \\export fn f() void {
6468 \\ var cstr = "Hat";
6469 \\ cstr[0] = 'W';
6470 \\}
6471 , &[_][]const u8{
6472 "tmp.zig:3:13: error: cannot assign to constant",
6473 });
6474
6475 ctx.objErrStage1("assign through constant slice",
6476 \\export fn f() void {
6477 \\ var cstr: []const u8 = "Hat";
6478 \\ cstr[0] = 'W';
6479 \\}
6480 , &[_][]const u8{
6481 "tmp.zig:3:13: error: cannot assign to constant",
6482 });
6483
6484 ctx.objErrStage1("main function with bogus args type",
6485 \\pub fn main(args: [][]bogus) !void {_ = args;}
6486 , &[_][]const u8{
6487 "tmp.zig:1:23: error: use of undeclared identifier 'bogus'",
6488 });
6489
6490 ctx.objErrStage1("misspelled type with pointer only reference",
6491 \\const JasonHM = u8;
6492 \\const JasonList = *JsonNode;
6493 \\
6494 \\const JsonOA = union(enum) {
6495 \\ JSONArray: JsonList,
6496 \\ JSONObject: JasonHM,
6497 \\};
6498 \\
6499 \\const JsonType = union(enum) {
6500 \\ JSONNull: void,
6501 \\ JSONInteger: isize,
6502 \\ JSONDouble: f64,
6503 \\ JSONBool: bool,
6504 \\ JSONString: []u8,
6505 \\ JSONArray: void,
6506 \\ JSONObject: void,
6507 \\};
6508 \\
6509 \\pub const JsonNode = struct {
6510 \\ kind: JsonType,
6511 \\ jobject: ?JsonOA,
6512 \\};
6513 \\
6514 \\fn foo() void {
6515 \\ var jll: JasonList = undefined;
6516 \\ jll.init(1234);
6517 \\ var jd = JsonNode {.kind = JsonType.JSONArray , .jobject = JsonOA.JSONArray {jll} };
6518 \\ _ = jd;
6519 \\}
6520 \\
6521 \\export fn entry() usize { return @sizeOf(@TypeOf(foo)); }
6522 , &[_][]const u8{
6523 "tmp.zig:5:16: error: use of undeclared identifier 'JsonList'",
6524 });
6525
6526 ctx.objErrStage1("method call with first arg type primitive",
6527 \\const Foo = struct {
6528 \\ x: i32,
6529 \\
6530 \\ fn init(x: i32) Foo {
6531 \\ return Foo {
6532 \\ .x = x,
6533 \\ };
6534 \\ }
6535 \\};
6536 \\
6537 \\export fn f() void {
6538 \\ const derp = Foo.init(3);
6539 \\
6540 \\ derp.init();
6541 \\}
6542 , &[_][]const u8{
6543 "tmp.zig:14:5: error: expected type 'i32', found 'Foo'",
6544 });
6545
6546 ctx.objErrStage1("method call with first arg type wrong container",
6547 \\pub const List = struct {
6548 \\ len: usize,
6549 \\ allocator: *Allocator,
6550 \\
6551 \\ pub fn init(allocator: *Allocator) List {
6552 \\ return List {
6553 \\ .len = 0,
6554 \\ .allocator = allocator,
6555 \\ };
6556 \\ }
6557 \\};
6558 \\
6559 \\pub var global_allocator = Allocator {
6560 \\ .field = 1234,
6561 \\};
6562 \\
6563 \\pub const Allocator = struct {
6564 \\ field: i32,
6565 \\};
6566 \\
6567 \\export fn foo() void {
6568 \\ var x = List.init(&global_allocator);
6569 \\ x.init();
6570 \\}
6571 , &[_][]const u8{
6572 "tmp.zig:23:5: error: expected type '*Allocator', found '*List'",
6573 });
6574
6575 ctx.objErrStage1("binary not on number literal",
6576 \\const TINY_QUANTUM_SHIFT = 4;
6577 \\const TINY_QUANTUM_SIZE = 1 << TINY_QUANTUM_SHIFT;
6578 \\var block_aligned_stuff: usize = (4 + TINY_QUANTUM_SIZE) & ~(TINY_QUANTUM_SIZE - 1);
6579 \\
6580 \\export fn entry() usize { return @sizeOf(@TypeOf(block_aligned_stuff)); }
6581 , &[_][]const u8{
6582 "tmp.zig:3:60: error: unable to perform binary not operation on type 'comptime_int'",
6583 });
6584
6585 {
6586 const case = ctx.obj("multiple files with private function error", .{});
6587 case.backend = .stage1;
6588
6589 case.addSourceFile("foo.zig",
6590 \\fn privateFunction() void { }
6591 );
6592
6593 case.addError(
6594 \\const foo = @import("foo.zig",);
6595 \\
6596 \\export fn callPrivFunction() void {
6597 \\ foo.privateFunction();
6598 \\}
6599 , &[_][]const u8{
6600 "tmp.zig:4:8: error: 'privateFunction' is private",
6601 "foo.zig:1:1: note: declared here",
6602 });
6603 }
6604
6605 {
6606 const case = ctx.obj("multiple files with private member instance function (canonical invocation) error", .{});
6607 case.backend = .stage1;
6608
6609 case.addSourceFile("foo.zig",
6610 \\pub const Foo = struct {
6611 \\ fn privateFunction(self: *Foo) void { _ = self; }
6612 \\};
6613 );
6614
6615 case.addError(
6616 \\const Foo = @import("foo.zig",).Foo;
6617 \\
6618 \\export fn callPrivFunction() void {
6619 \\ var foo = Foo{};
6620 \\ Foo.privateFunction(foo);
6621 \\}
6622 , &[_][]const u8{
6623 "tmp.zig:5:8: error: 'privateFunction' is private",
6624 "foo.zig:2:5: note: declared here",
6625 });
6626 }
6627
6628 {
6629 const case = ctx.obj("multiple files with private member instance function error", .{});
6630 case.backend = .stage1;
6631
6632 case.addSourceFile("foo.zig",
6633 \\pub const Foo = struct {
6634 \\ fn privateFunction(self: *Foo) void { _ = self; }
6635 \\};
6636 );
6637
6638 case.addError(
6639 \\const Foo = @import("foo.zig",).Foo;
6640 \\
6641 \\export fn callPrivFunction() void {
6642 \\ var foo = Foo{};
6643 \\ foo.privateFunction();
6644 \\}
6645 , &[_][]const u8{
6646 "tmp.zig:5:8: error: 'privateFunction' is private",
6647 "foo.zig:2:5: note: declared here",
6648 });
6649 }
6650
6651 ctx.objErrStage1("container init with non-type",
6652 \\const zero: i32 = 0;
6653 \\const a = zero{1};
6654 \\
6655 \\export fn entry() usize { return @sizeOf(@TypeOf(a)); }
6656 , &[_][]const u8{
6657 "tmp.zig:2:11: error: expected type 'type', found 'i32'",
6658 });
6659
6660 ctx.objErrStage1("assign to constant field",
6661 \\const Foo = struct {
6662 \\ field: i32,
6663 \\};
6664 \\export fn derp() void {
6665 \\ const f = Foo {.field = 1234,};
6666 \\ f.field = 0;
6667 \\}
6668 , &[_][]const u8{
6669 "tmp.zig:6:15: error: cannot assign to constant",
6670 });
6671
6672 ctx.objErrStage1("return from defer expression",
6673 \\pub fn testTrickyDefer() !void {
6674 \\ defer canFail() catch {};
6675 \\
6676 \\ defer try canFail();
6677 \\
6678 \\ const a = maybeInt() orelse return;
6679 \\}
6680 \\
6681 \\fn canFail() anyerror!void { }
6682 \\
6683 \\pub fn maybeInt() ?i32 {
6684 \\ return 0;
6685 \\}
6686 \\
6687 \\export fn entry() usize { return @sizeOf(@TypeOf(testTrickyDefer)); }
6688 , &[_][]const u8{
6689 "tmp.zig:4:11: error: 'try' not allowed inside defer expression",
6690 });
6691
6692 ctx.objErrStage1("assign too big number to u16",
6693 \\export fn foo() void {
6694 \\ var vga_mem: u16 = 0xB8000;
6695 \\ _ = vga_mem;
6696 \\}
6697 , &[_][]const u8{
6698 "tmp.zig:2:24: error: integer value 753664 cannot be coerced to type 'u16'",
6699 });
6700
6701 ctx.objErrStage1("global variable alignment non power of 2",
6702 \\const some_data: [100]u8 align(3) = undefined;
6703 \\export fn entry() usize { return @sizeOf(@TypeOf(some_data)); }
6704 , &[_][]const u8{
6705 "tmp.zig:1:32: error: alignment value 3 is not a power of 2",
6706 });
6707
6708 ctx.objErrStage1("function alignment non power of 2",
6709 \\extern fn foo() align(3) void;
6710 \\export fn entry() void { return foo(); }
6711 , &[_][]const u8{
6712 "tmp.zig:1:23: error: alignment value 3 is not a power of 2",
6713 });
6714
6715 ctx.objErrStage1("compile log",
6716 \\export fn foo() void {
6717 \\ comptime bar(12, "hi",);
6718 \\}
6719 \\fn bar(a: i32, b: []const u8) void {
6720 \\ @compileLog("begin",);
6721 \\ @compileLog("a", a, "b", b);
6722 \\ @compileLog("end",);
6723 \\}
6724 , &[_][]const u8{
6725 "tmp.zig:5:5: error: found compile log statement",
6726 "tmp.zig:6:5: error: found compile log statement",
6727 "tmp.zig:7:5: error: found compile log statement",
6728 });
6729
6730 ctx.objErrStage1("casting bit offset pointer to regular pointer",
6731 \\const BitField = packed struct {
6732 \\ a: u3,
6733 \\ b: u3,
6734 \\ c: u2,
6735 \\};
6736 \\
6737 \\fn foo(bit_field: *const BitField) u3 {
6738 \\ return bar(&bit_field.b);
6739 \\}
6740 \\
6741 \\fn bar(x: *const u3) u3 {
6742 \\ return x.*;
6743 \\}
6744 \\
6745 \\export fn entry() usize { return @sizeOf(@TypeOf(foo)); }
6746 , &[_][]const u8{
6747 "tmp.zig:8:26: error: expected type '*const u3', found '*align(:3:1) const u3'",
6748 });
6749
6750 ctx.objErrStage1("referring to a struct that is invalid",
6751 \\const UsbDeviceRequest = struct {
6752 \\ Type: u8,
6753 \\};
6754 \\
6755 \\export fn foo() void {
6756 \\ comptime assert(@sizeOf(UsbDeviceRequest) == 0x8);
6757 \\}
6758 \\
6759 \\fn assert(ok: bool) void {
6760 \\ if (!ok) unreachable;
6761 \\}
6762 , &[_][]const u8{
6763 "tmp.zig:10:14: error: reached unreachable code",
6764 });
6765
6766 ctx.objErrStage1("control flow uses comptime var at runtime",
6767 \\export fn foo() void {
6768 \\ comptime var i = 0;
6769 \\ while (i < 5) : (i += 1) {
6770 \\ bar();
6771 \\ }
6772 \\}
6773 \\
6774 \\fn bar() void { }
6775 , &[_][]const u8{
6776 "tmp.zig:3:5: error: control flow attempts to use compile-time variable at runtime",
6777 "tmp.zig:3:24: note: compile-time variable assigned here",
6778 });
6779
6780 ctx.objErrStage1("ignored return value",
6781 \\export fn foo() void {
6782 \\ bar();
6783 \\}
6784 \\fn bar() i32 { return 0; }
6785 , &[_][]const u8{
6786 "tmp.zig:2:8: error: expression value is ignored",
6787 });
6788
6789 ctx.objErrStage1("ignored assert-err-ok return value",
6790 \\export fn foo() void {
6791 \\ bar() catch unreachable;
6792 \\}
6793 \\fn bar() anyerror!i32 { return 0; }
6794 , &[_][]const u8{
6795 "tmp.zig:2:11: error: expression value is ignored",
6796 });
6797
6798 ctx.objErrStage1("ignored statement value",
6799 \\export fn foo() void {
6800 \\ 1;
6801 \\}
6802 , &[_][]const u8{
6803 "tmp.zig:2:5: error: expression value is ignored",
6804 });
6805
6806 ctx.objErrStage1("ignored comptime statement value",
6807 \\export fn foo() void {
6808 \\ comptime {1;}
6809 \\}
6810 , &[_][]const u8{
6811 "tmp.zig:2:15: error: expression value is ignored",
6812 });
6813
6814 ctx.objErrStage1("ignored comptime value",
6815 \\export fn foo() void {
6816 \\ comptime 1;
6817 \\}
6818 , &[_][]const u8{
6819 "tmp.zig:2:5: error: expression value is ignored",
6820 });
6821
6822 ctx.objErrStage1("ignored deferred statement value",
6823 \\export fn foo() void {
6824 \\ defer {1;}
6825 \\}
6826 , &[_][]const u8{
6827 "tmp.zig:2:12: error: expression value is ignored",
6828 });
6829
6830 ctx.objErrStage1("ignored deferred function call",
6831 \\export fn foo() void {
6832 \\ defer bar();
6833 \\}
6834 \\fn bar() anyerror!i32 { return 0; }
6835 , &[_][]const u8{
6836 "tmp.zig:2:14: error: error is ignored. consider using `try`, `catch`, or `if`",
6837 });
6838
6839 ctx.objErrStage1("dereference an array",
6840 \\var s_buffer: [10]u8 = undefined;
6841 \\pub fn pass(in: []u8) []u8 {
6842 \\ var out = &s_buffer;
6843 \\ out.*.* = in[0];
6844 \\ return out.*[0..1];
6845 \\}
6846 \\
6847 \\export fn entry() usize { return @sizeOf(@TypeOf(pass)); }
6848 , &[_][]const u8{
6849 "tmp.zig:4:10: error: attempt to dereference non-pointer type '[10]u8'",
6850 });
6851
6852 ctx.objErrStage1("pass const ptr to mutable ptr fn",
6853 \\fn foo() bool {
6854 \\ const a = @as([]const u8, "a",);
6855 \\ const b = &a;
6856 \\ return ptrEql(b, b);
6857 \\}
6858 \\fn ptrEql(a: *[]const u8, b: *[]const u8) bool {
6859 \\ _ = a; _ = b;
6860 \\ return true;
6861 \\}
6862 \\
6863 \\export fn entry() usize { return @sizeOf(@TypeOf(foo)); }
6864 , &[_][]const u8{
6865 "tmp.zig:4:19: error: expected type '*[]const u8', found '*const []const u8'",
6866 });
6867
6868 {
6869 const case = ctx.obj("export collision", .{});
6870 case.backend = .stage1;
6871
6872 case.addSourceFile("foo.zig",
6873 \\export fn bar() void {}
6874 \\pub const baz = 1234;
6875 );
6876
6877 case.addError(
6878 \\const foo = @import("foo.zig",);
6879 \\
6880 \\export fn bar() usize {
6881 \\ return foo.baz;
6882 \\}
6883 , &[_][]const u8{
6884 "foo.zig:1:1: error: exported symbol collision: 'bar'",
6885 "tmp.zig:3:1: note: other symbol here",
6886 });
6887 }
6888
6889 ctx.objErrStage1("implicit cast from array to mutable slice",
6890 \\var global_array: [10]i32 = undefined;
6891 \\fn foo(param: []i32) void {_ = param;}
6892 \\export fn entry() void {
6893 \\ foo(global_array);
6894 \\}
6895 , &[_][]const u8{
6896 "tmp.zig:4:9: error: expected type '[]i32', found '[10]i32'",
6897 });
6898
6899 ctx.objErrStage1("ptrcast to non-pointer",
6900 \\export fn entry(a: *i32) usize {
6901 \\ return @ptrCast(usize, a);
6902 \\}
6903 , &[_][]const u8{
6904 "tmp.zig:2:21: error: expected pointer, found 'usize'",
6905 });
6906
6907 ctx.objErrStage1("asm at compile time",
6908 \\comptime {
6909 \\ doSomeAsm();
6910 \\}
6911 \\
6912 \\fn doSomeAsm() void {
6913 \\ asm volatile (
6914 \\ \\.globl aoeu;
6915 \\ \\.type aoeu, @function;
6916 \\ \\.set aoeu, derp;
6917 \\ );
6918 \\}
6919 , &[_][]const u8{
6920 "tmp.zig:6:5: error: unable to evaluate constant expression",
6921 });
6922
6923 ctx.objErrStage1("invalid member of builtin enum",
6924 \\const builtin = @import("std").builtin;
6925 \\export fn entry() void {
6926 \\ const foo = builtin.Mode.x86;
6927 \\ _ = foo;
6928 \\}
6929 , &[_][]const u8{
6930 "tmp.zig:3:29: error: container 'std.builtin.Mode' has no member called 'x86'",
6931 });
6932
6933 ctx.objErrStage1("int to ptr of 0 bits",
6934 \\export fn foo() void {
6935 \\ var x: usize = 0x1000;
6936 \\ var y: *void = @intToPtr(*void, x);
6937 \\ _ = y;
6938 \\}
6939 , &[_][]const u8{
6940 "tmp.zig:3:30: error: type '*void' has 0 bits and cannot store information",
6941 });
6942
6943 ctx.objErrStage1("@fieldParentPtr - non struct",
6944 \\const Foo = i32;
6945 \\export fn foo(a: *i32) *Foo {
6946 \\ return @fieldParentPtr(Foo, "a", a);
6947 \\}
6948 , &[_][]const u8{
6949 "tmp.zig:3:28: error: expected struct type, found 'i32'",
6950 });
6951
6952 ctx.objErrStage1("@fieldParentPtr - bad field name",
6953 \\const Foo = extern struct {
6954 \\ derp: i32,
6955 \\};
6956 \\export fn foo(a: *i32) *Foo {
6957 \\ return @fieldParentPtr(Foo, "a", a);
6958 \\}
6959 , &[_][]const u8{
6960 "tmp.zig:5:33: error: struct 'Foo' has no field 'a'",
6961 });
6962
6963 ctx.objErrStage1("@fieldParentPtr - field pointer is not pointer",
6964 \\const Foo = extern struct {
6965 \\ a: i32,
6966 \\};
6967 \\export fn foo(a: i32) *Foo {
6968 \\ return @fieldParentPtr(Foo, "a", a);
6969 \\}
6970 , &[_][]const u8{
6971 "tmp.zig:5:38: error: expected pointer, found 'i32'",
6972 });
6973
6974 ctx.objErrStage1("@fieldParentPtr - comptime field ptr not based on struct",
6975 \\const Foo = struct {
6976 \\ a: i32,
6977 \\ b: i32,
6978 \\};
6979 \\const foo = Foo { .a = 1, .b = 2, };
6980 \\
6981 \\comptime {
6982 \\ const field_ptr = @intToPtr(*i32, 0x1234);
6983 \\ const another_foo_ptr = @fieldParentPtr(Foo, "b", field_ptr);
6984 \\ _ = another_foo_ptr;
6985 \\}
6986 , &[_][]const u8{
6987 "tmp.zig:9:55: error: pointer value not based on parent struct",
6988 });
6989
6990 ctx.objErrStage1("@fieldParentPtr - comptime wrong field index",
6991 \\const Foo = struct {
6992 \\ a: i32,
6993 \\ b: i32,
6994 \\};
6995 \\const foo = Foo { .a = 1, .b = 2, };
6996 \\
6997 \\comptime {
6998 \\ const another_foo_ptr = @fieldParentPtr(Foo, "b", &foo.a);
6999 \\ _ = another_foo_ptr;
7000 \\}
7001 , &[_][]const u8{
7002 "tmp.zig:8:29: error: field 'b' has index 1 but pointer value is index 0 of struct 'Foo'",
7003 });
7004
7005 ctx.objErrStage1("@offsetOf - non struct",
7006 \\const Foo = i32;
7007 \\export fn foo() usize {
7008 \\ return @offsetOf(Foo, "a",);
7009 \\}
7010 , &[_][]const u8{
7011 "tmp.zig:3:22: error: expected struct type, found 'i32'",
7012 });
7013
7014 ctx.objErrStage1("@offsetOf - bad field name",
7015 \\const Foo = struct {
7016 \\ derp: i32,
7017 \\};
7018 \\export fn foo() usize {
7019 \\ return @offsetOf(Foo, "a",);
7020 \\}
7021 , &[_][]const u8{
7022 "tmp.zig:5:27: error: struct 'Foo' has no field 'a'",
7023 });
7024
7025 ctx.exeErrStage1("missing main fn in executable",
7026 \\
7027 , &[_][]const u8{
7028 "error: root source file has no member called 'main'",
7029 });
7030
7031 ctx.exeErrStage1("private main fn",
7032 \\fn main() void {}
7033 , &[_][]const u8{
7034 "error: 'main' is private",
7035 "tmp.zig:1:1: note: declared here",
7036 });
7037
7038 ctx.objErrStage1("setting a section on a local variable",
7039 \\export fn entry() i32 {
7040 \\ var foo: i32 linksection(".text2") = 1234;
7041 \\ return foo;
7042 \\}
7043 , &[_][]const u8{
7044 "tmp.zig:2:30: error: cannot set section of local variable 'foo'",
7045 });
7046
7047 ctx.objErrStage1("ambiguous decl reference",
7048 \\fn foo() void {}
7049 \\fn bar() void {
7050 \\ const S = struct {
7051 \\ fn baz() void {
7052 \\ foo();
7053 \\ }
7054 \\ fn foo() void {}
7055 \\ };
7056 \\ S.baz();
7057 \\}
7058 \\export fn entry() void {
7059 \\ bar();
7060 \\}
7061 , &[_][]const u8{
7062 "tmp.zig:5:13: error: ambiguous reference",
7063 "tmp.zig:7:9: note: declared here",
7064 "tmp.zig:1:1: note: also declared here",
7065 });
7066
7067 ctx.objErrStage1("while expected bool, got optional",
7068 \\export fn foo() void {
7069 \\ while (bar()) {}
7070 \\}
7071 \\fn bar() ?i32 { return 1; }
7072 , &[_][]const u8{
7073 "tmp.zig:2:15: error: expected type 'bool', found '?i32'",
7074 });
7075
7076 ctx.objErrStage1("while expected bool, got error union",
7077 \\export fn foo() void {
7078 \\ while (bar()) {}
7079 \\}
7080 \\fn bar() anyerror!i32 { return 1; }
7081 , &[_][]const u8{
7082 "tmp.zig:2:15: error: expected type 'bool', found 'anyerror!i32'",
7083 });
7084
7085 ctx.objErrStage1("while expected optional, got bool",
7086 \\export fn foo() void {
7087 \\ while (bar()) |x| {_ = x;}
7088 \\}
7089 \\fn bar() bool { return true; }
7090 , &[_][]const u8{
7091 "tmp.zig:2:15: error: expected optional type, found 'bool'",
7092 });
7093
7094 ctx.objErrStage1("while expected optional, got error union",
7095 \\export fn foo() void {
7096 \\ while (bar()) |x| {_ = x;}
7097 \\}
7098 \\fn bar() anyerror!i32 { return 1; }
7099 , &[_][]const u8{
7100 "tmp.zig:2:15: error: expected optional type, found 'anyerror!i32'",
7101 });
7102
7103 ctx.objErrStage1("while expected error union, got bool",
7104 \\export fn foo() void {
7105 \\ while (bar()) |x| {_ = x;} else |err| {_ = err;}
7106 \\}
7107 \\fn bar() bool { return true; }
7108 , &[_][]const u8{
7109 "tmp.zig:2:15: error: expected error union type, found 'bool'",
7110 });
7111
7112 ctx.objErrStage1("while expected error union, got optional",
7113 \\export fn foo() void {
7114 \\ while (bar()) |x| {_ = x;} else |err| {_ = err;}
7115 \\}
7116 \\fn bar() ?i32 { return 1; }
7117 , &[_][]const u8{
7118 "tmp.zig:2:15: error: expected error union type, found '?i32'",
7119 });
7120
7121 // TODO test this in stage2, but we won't even try in stage1
7122 //ctx.objErrStage1("inline fn calls itself indirectly",
7123 // \\export fn foo() void {
7124 // \\ bar();
7125 // \\}
7126 // \\fn bar() callconv(.Inline) void {
7127 // \\ baz();
7128 // \\ quux();
7129 // \\}
7130 // \\fn baz() callconv(.Inline) void {
7131 // \\ bar();
7132 // \\ quux();
7133 // \\}
7134 // \\extern fn quux() void;
7135 //, &[_][]const u8{
7136 // "tmp.zig:4:1: error: unable to inline function",
7137 //});
7138
7139 //ctx.objErrStage1("save reference to inline function",
7140 // \\export fn foo() void {
7141 // \\ quux(@ptrToInt(bar));
7142 // \\}
7143 // \\fn bar() callconv(.Inline) void { }
7144 // \\extern fn quux(usize) void;
7145 //, &[_][]const u8{
7146 // "tmp.zig:4:1: error: unable to inline function",
7147 //});
7148
7149 ctx.objErrStage1("signed integer division",
7150 \\export fn foo(a: i32, b: i32) i32 {
7151 \\ return a / b;
7152 \\}
7153 , &[_][]const u8{
7154 "tmp.zig:2:14: error: division with 'i32' and 'i32': signed integers must use @divTrunc, @divFloor, or @divExact",
7155 });
7156
7157 ctx.objErrStage1("signed integer remainder division",
7158 \\export fn foo(a: i32, b: i32) i32 {
7159 \\ return a % b;
7160 \\}
7161 , &[_][]const u8{
7162 "tmp.zig:2:14: error: remainder division with 'i32' and 'i32': signed integers and floats must use @rem or @mod",
7163 });
7164
7165 ctx.objErrStage1("compile-time division by zero",
7166 \\comptime {
7167 \\ const a: i32 = 1;
7168 \\ const b: i32 = 0;
7169 \\ const c = a / b;
7170 \\ _ = c;
7171 \\}
7172 , &[_][]const u8{
7173 "tmp.zig:4:17: error: division by zero",
7174 });
7175
7176 ctx.objErrStage1("compile-time remainder division by zero",
7177 \\comptime {
7178 \\ const a: i32 = 1;
7179 \\ const b: i32 = 0;
7180 \\ const c = a % b;
7181 \\ _ = c;
7182 \\}
7183 , &[_][]const u8{
7184 "tmp.zig:4:17: error: division by zero",
7185 });
7186
7187 ctx.objErrStage1("@setRuntimeSafety twice for same scope",
7188 \\export fn foo() void {
7189 \\ @setRuntimeSafety(false);
7190 \\ @setRuntimeSafety(false);
7191 \\}
7192 , &[_][]const u8{
7193 "tmp.zig:3:5: error: runtime safety set twice for same scope",
7194 "tmp.zig:2:5: note: first set here",
7195 });
7196
7197 ctx.objErrStage1("@setFloatMode twice for same scope",
7198 \\export fn foo() void {
7199 \\ @setFloatMode(@import("std").builtin.FloatMode.Optimized);
7200 \\ @setFloatMode(@import("std").builtin.FloatMode.Optimized);
7201 \\}
7202 , &[_][]const u8{
7203 "tmp.zig:3:5: error: float mode set twice for same scope",
7204 "tmp.zig:2:5: note: first set here",
7205 });
7206
7207 ctx.objErrStage1("array access of type",
7208 \\export fn foo() void {
7209 \\ var b: u8[40] = undefined;
7210 \\ _ = b;
7211 \\}
7212 , &[_][]const u8{
7213 "tmp.zig:2:14: error: array access of non-array type 'type'",
7214 });
7215
7216 ctx.objErrStage1("cannot break out of defer expression",
7217 \\export fn foo() void {
7218 \\ while (true) {
7219 \\ defer {
7220 \\ break;
7221 \\ }
7222 \\ }
7223 \\}
7224 , &[_][]const u8{
7225 "tmp.zig:4:13: error: cannot break out of defer expression",
7226 });
7227
7228 ctx.objErrStage1("cannot continue out of defer expression",
7229 \\export fn foo() void {
7230 \\ while (true) {
7231 \\ defer {
7232 \\ continue;
7233 \\ }
7234 \\ }
7235 \\}
7236 , &[_][]const u8{
7237 "tmp.zig:4:13: error: cannot continue out of defer expression",
7238 });
7239
7240 ctx.objErrStage1("calling a generic function only known at runtime",
7241 \\var foos = [_]fn(anytype) void { foo1, foo2 };
7242 \\
7243 \\fn foo1(arg: anytype) void {_ = arg;}
7244 \\fn foo2(arg: anytype) void {_ = arg;}
7245 \\
7246 \\pub fn main() !void {
7247 \\ foos[0](true);
7248 \\}
7249 , &[_][]const u8{
7250 "tmp.zig:7:9: error: calling a generic function requires compile-time known function value",
7251 });
7252
7253 ctx.objErrStage1("@compileError shows traceback of references that caused it",
7254 \\const foo = @compileError("aoeu",);
7255 \\
7256 \\const bar = baz + foo;
7257 \\const baz = 1;
7258 \\
7259 \\export fn entry() i32 {
7260 \\ return bar;
7261 \\}
7262 , &[_][]const u8{
7263 "tmp.zig:1:13: error: aoeu",
7264 });
7265
7266 ctx.objErrStage1("float literal too large error",
7267 \\comptime {
7268 \\ const a = 0x1.0p18495;
7269 \\ _ = a;
7270 \\}
7271 , &[_][]const u8{
7272 "tmp.zig:2:15: error: float literal out of range of any type",
7273 });
7274
7275 ctx.objErrStage1("float literal too small error (denormal)",
7276 \\comptime {
7277 \\ const a = 0x1.0p-19000;
7278 \\ _ = a;
7279 \\}
7280 , &[_][]const u8{
7281 "tmp.zig:2:15: error: float literal out of range of any type",
7282 });
7283
7284 ctx.objErrStage1("explicit cast float literal to integer when there is a fraction component",
7285 \\export fn entry() i32 {
7286 \\ return @as(i32, 12.34);
7287 \\}
7288 , &[_][]const u8{
7289 "tmp.zig:2:21: error: fractional component prevents float value 12.340000 from being casted to type 'i32'",
7290 });
7291
7292 ctx.objErrStage1("non pointer given to @ptrToInt",
7293 \\export fn entry(x: i32) usize {
7294 \\ return @ptrToInt(x);
7295 \\}
7296 , &[_][]const u8{
7297 "tmp.zig:2:22: error: expected pointer, found 'i32'",
7298 });
7299
7300 ctx.objErrStage1("@shlExact shifts out 1 bits",
7301 \\comptime {
7302 \\ const x = @shlExact(@as(u8, 0b01010101), 2);
7303 \\ _ = x;
7304 \\}
7305 , &[_][]const u8{
7306 "tmp.zig:2:15: error: operation caused overflow",
7307 });
7308
7309 ctx.objErrStage1("@shrExact shifts out 1 bits",
7310 \\comptime {
7311 \\ const x = @shrExact(@as(u8, 0b10101010), 2);
7312 \\ _ = x;
7313 \\}
7314 , &[_][]const u8{
7315 "tmp.zig:2:15: error: exact shift shifted out 1 bits",
7316 });
7317
7318 ctx.objErrStage1("shifting without int type or comptime known",
7319 \\export fn entry(x: u8) u8 {
7320 \\ return 0x11 << x;
7321 \\}
7322 , &[_][]const u8{
7323 "tmp.zig:2:17: error: LHS of shift must be a fixed-width integer type, or RHS must be compile-time known",
7324 });
7325
7326 ctx.objErrStage1("shifting RHS is log2 of LHS int bit width",
7327 \\export fn entry(x: u8, y: u8) u8 {
7328 \\ return x << y;
7329 \\}
7330 , &[_][]const u8{
7331 "tmp.zig:2:17: error: expected type 'u3', found 'u8'",
7332 });
7333
7334 ctx.objErrStage1("locally shadowing a primitive type",
7335 \\export fn foo() void {
7336 \\ const u8 = u16;
7337 \\ const a: u8 = 300;
7338 \\ _ = a;
7339 \\}
7340 , &[_][]const u8{
7341 "tmp.zig:2:11: error: name shadows primitive 'u8'",
7342 "tmp.zig:2:11: note: consider using @\"u8\" to disambiguate",
7343 });
7344
7345 ctx.objErrStage1("primitives take precedence over declarations",
7346 \\const @"u8" = u16;
7347 \\export fn entry() void {
7348 \\ const a: u8 = 300;
7349 \\ _ = a;
7350 \\}
7351 , &[_][]const u8{
7352 "tmp.zig:3:19: error: integer value 300 cannot be coerced to type 'u8'",
7353 });
7354
7355 ctx.objErrStage1("declaration with same name as primitive must use special syntax",
7356 \\const u8 = u16;
7357 \\export fn entry() void {
7358 \\ const a: u8 = 300;
7359 \\ _ = a;
7360 \\}
7361 , &[_][]const u8{
7362 "tmp.zig:1:7: error: name shadows primitive 'u8'",
7363 "tmp.zig:1:7: note: consider using @\"u8\" to disambiguate",
7364 });
7365
7366 ctx.objErrStage1("implicitly increasing pointer alignment",
7367 \\const Foo = packed struct {
7368 \\ a: u8,
7369 \\ b: u32,
7370 \\};
7371 \\
7372 \\export fn entry() void {
7373 \\ var foo = Foo { .a = 1, .b = 10 };
7374 \\ bar(&foo.b);
7375 \\}
7376 \\
7377 \\fn bar(x: *u32) void {
7378 \\ x.* += 1;
7379 \\}
7380 , &[_][]const u8{
7381 "tmp.zig:8:13: error: expected type '*u32', found '*align(1) u32'",
7382 });
7383
7384 ctx.objErrStage1("implicitly increasing slice alignment",
7385 \\const Foo = packed struct {
7386 \\ a: u8,
7387 \\ b: u32,
7388 \\};
7389 \\
7390 \\export fn entry() void {
7391 \\ var foo = Foo { .a = 1, .b = 10 };
7392 \\ foo.b += 1;
7393 \\ bar(@as(*[1]u32, &foo.b)[0..]);
7394 \\}
7395 \\
7396 \\fn bar(x: []u32) void {
7397 \\ x[0] += 1;
7398 \\}
7399 , &[_][]const u8{
7400 "tmp.zig:9:26: error: cast increases pointer alignment",
7401 "tmp.zig:9:26: note: '*align(1) u32' has alignment 1",
7402 "tmp.zig:9:26: note: '*[1]u32' has alignment 4",
7403 });
7404
7405 ctx.objErrStage1("increase pointer alignment in @ptrCast",
7406 \\export fn entry() u32 {
7407 \\ var bytes: [4]u8 = [_]u8{0x01, 0x02, 0x03, 0x04};
7408 \\ const ptr = @ptrCast(*u32, &bytes[0]);
7409 \\ return ptr.*;
7410 \\}
7411 , &[_][]const u8{
7412 "tmp.zig:3:17: error: cast increases pointer alignment",
7413 "tmp.zig:3:38: note: '*u8' has alignment 1",
7414 "tmp.zig:3:26: note: '*u32' has alignment 4",
7415 });
7416
7417 ctx.objErrStage1("@alignCast expects pointer or slice",
7418 \\export fn entry() void {
7419 \\ @alignCast(4, @as(u32, 3));
7420 \\}
7421 , &[_][]const u8{
7422 "tmp.zig:2:19: error: expected pointer or slice, found 'u32'",
7423 });
7424
7425 ctx.objErrStage1("passing an under-aligned function pointer",
7426 \\export fn entry() void {
7427 \\ testImplicitlyDecreaseFnAlign(alignedSmall, 1234);
7428 \\}
7429 \\fn testImplicitlyDecreaseFnAlign(ptr: fn () align(8) i32, answer: i32) void {
7430 \\ if (ptr() != answer) unreachable;
7431 \\}
7432 \\fn alignedSmall() align(4) i32 { return 1234; }
7433 , &[_][]const u8{
7434 "tmp.zig:2:35: error: expected type 'fn() align(8) i32', found 'fn() align(4) i32'",
7435 });
7436
7437 ctx.objErrStage1("passing a not-aligned-enough pointer to cmpxchg",
7438 \\const AtomicOrder = @import("std").builtin.AtomicOrder;
7439 \\export fn entry() bool {
7440 \\ var x: i32 align(1) = 1234;
7441 \\ while (!@cmpxchgWeak(i32, &x, 1234, 5678, AtomicOrder.SeqCst, AtomicOrder.SeqCst)) {}
7442 \\ return x == 5678;
7443 \\}
7444 , &[_][]const u8{
7445 "tmp.zig:4:32: error: expected type '*i32', found '*align(1) i32'",
7446 });
7447
7448 ctx.objErrStage1("wrong size to an array literal",
7449 \\comptime {
7450 \\ const array = [2]u8{1, 2, 3};
7451 \\ _ = array;
7452 \\}
7453 , &[_][]const u8{
7454 "tmp.zig:2:31: error: index 2 outside array of size 2",
7455 });
7456
7457 ctx.objErrStage1("wrong pointer coerced to pointer to opaque {}",
7458 \\const Derp = opaque {};
7459 \\extern fn bar(d: *Derp) void;
7460 \\export fn foo() void {
7461 \\ var x = @as(u8, 1);
7462 \\ bar(@ptrCast(*anyopaque, &x));
7463 \\}
7464 , &[_][]const u8{
7465 "tmp.zig:5:9: error: expected type '*Derp', found '*anyopaque'",
7466 });
7467
7468 ctx.objErrStage1("non-const variables of things that require const variables",
7469 \\export fn entry1() void {
7470 \\ var m2 = &2;
7471 \\ _ = m2;
7472 \\}
7473 \\export fn entry2() void {
7474 \\ var a = undefined;
7475 \\ _ = a;
7476 \\}
7477 \\export fn entry3() void {
7478 \\ var b = 1;
7479 \\ _ = b;
7480 \\}
7481 \\export fn entry4() void {
7482 \\ var c = 1.0;
7483 \\ _ = c;
7484 \\}
7485 \\export fn entry5() void {
7486 \\ var d = null;
7487 \\ _ = d;
7488 \\}
7489 \\export fn entry6(opaque_: *Opaque) void {
7490 \\ var e = opaque_.*;
7491 \\ _ = e;
7492 \\}
7493 \\export fn entry7() void {
7494 \\ var f = i32;
7495 \\ _ = f;
7496 \\}
7497 \\export fn entry8() void {
7498 \\ var h = (Foo {}).bar;
7499 \\ _ = h;
7500 \\}
7501 \\const Opaque = opaque {};
7502 \\const Foo = struct {
7503 \\ fn bar(self: *const Foo) void {_ = self;}
7504 \\};
7505 , &[_][]const u8{
7506 "tmp.zig:2:4: error: variable of type '*const comptime_int' must be const or comptime",
7507 "tmp.zig:6:4: error: variable of type '@Type(.Undefined)' must be const or comptime",
7508 "tmp.zig:10:4: error: variable of type 'comptime_int' must be const or comptime",
7509 "tmp.zig:10:4: note: to modify this variable at runtime, it must be given an explicit fixed-size number type",
7510 "tmp.zig:14:4: error: variable of type 'comptime_float' must be const or comptime",
7511 "tmp.zig:14:4: note: to modify this variable at runtime, it must be given an explicit fixed-size number type",
7512 "tmp.zig:18:4: error: variable of type '@Type(.Null)' must be const or comptime",
7513 "tmp.zig:22:4: error: variable of type 'Opaque' not allowed",
7514 "tmp.zig:26:4: error: variable of type 'type' must be const or comptime",
7515 "tmp.zig:30:4: error: variable of type '(bound fn(*const Foo) void)' must be const or comptime",
7516 });
7517
7518 ctx.objErrStage1("variable with type 'noreturn'",
7519 \\export fn entry9() void {
7520 \\ var z: noreturn = return;
7521 \\}
7522 , &[_][]const u8{
7523 "tmp.zig:2:5: error: unreachable code",
7524 "tmp.zig:2:23: note: control flow is diverted here",
7525 });
7526
7527 ctx.objErrStage1("wrong types given to atomic order args in cmpxchg",
7528 \\export fn entry() void {
7529 \\ var x: i32 = 1234;
7530 \\ while (!@cmpxchgWeak(i32, &x, 1234, 5678, @as(u32, 1234), @as(u32, 1234))) {}
7531 \\}
7532 , &[_][]const u8{
7533 "tmp.zig:3:47: error: expected type 'std.builtin.AtomicOrder', found 'u32'",
7534 });
7535
7536 ctx.objErrStage1("wrong types given to @export",
7537 \\fn entry() callconv(.C) void { }
7538 \\comptime {
7539 \\ @export(entry, .{.name = "entry", .linkage = @as(u32, 1234) });
7540 \\}
7541 , &[_][]const u8{
7542 "tmp.zig:3:59: error: expected type 'std.builtin.GlobalLinkage', found 'comptime_int'",
7543 });
7544
7545 ctx.objErrStage1("struct with invalid field",
7546 \\const std = @import("std",);
7547 \\const Allocator = std.mem.Allocator;
7548 \\const ArrayList = std.ArrayList;
7549 \\
7550 \\const HeaderWeight = enum {
7551 \\ H1, H2, H3, H4, H5, H6,
7552 \\};
7553 \\
7554 \\const MdText = ArrayList(u8);
7555 \\
7556 \\const MdNode = union(enum) {
7557 \\ Header: struct {
7558 \\ text: MdText,
7559 \\ weight: HeaderValue,
7560 \\ },
7561 \\};
7562 \\
7563 \\export fn entry() void {
7564 \\ const a = MdNode.Header {
7565 \\ .text = MdText.init(std.testing.allocator),
7566 \\ .weight = HeaderWeight.H1,
7567 \\ };
7568 \\ _ = a;
7569 \\}
7570 , &[_][]const u8{
7571 "tmp.zig:14:17: error: use of undeclared identifier 'HeaderValue'",
7572 });
7573
7574 ctx.objErrStage1("@setAlignStack outside function",
7575 \\comptime {
7576 \\ @setAlignStack(16);
7577 \\}
7578 , &[_][]const u8{
7579 "tmp.zig:2:5: error: @setAlignStack outside function",
7580 });
7581
7582 ctx.objErrStage1("@setAlignStack in naked function",
7583 \\export fn entry() callconv(.Naked) void {
7584 \\ @setAlignStack(16);
7585 \\}
7586 , &[_][]const u8{
7587 "tmp.zig:2:5: error: @setAlignStack in naked function",
7588 });
7589
7590 ctx.objErrStage1("@setAlignStack in inline function",
7591 \\export fn entry() void {
7592 \\ foo();
7593 \\}
7594 \\fn foo() callconv(.Inline) void {
7595 \\ @setAlignStack(16);
7596 \\}
7597 , &[_][]const u8{
7598 "tmp.zig:5:5: error: @setAlignStack in inline function",
7599 });
7600
7601 ctx.objErrStage1("@setAlignStack set twice",
7602 \\export fn entry() void {
7603 \\ @setAlignStack(16);
7604 \\ @setAlignStack(16);
7605 \\}
7606 , &[_][]const u8{
7607 "tmp.zig:3:5: error: alignstack set twice",
7608 "tmp.zig:2:5: note: first set here",
7609 });
7610
7611 ctx.objErrStage1("@setAlignStack too big",
7612 \\export fn entry() void {
7613 \\ @setAlignStack(511 + 1);
7614 \\}
7615 , &[_][]const u8{
7616 "tmp.zig:2:5: error: attempt to @setAlignStack(512); maximum is 256",
7617 });
7618
7619 ctx.objErrStage1("storing runtime value in compile time variable then using it",
7620 \\const Mode = @import("std").builtin.Mode;
7621 \\
7622 \\fn Free(comptime filename: []const u8) TestCase {
7623 \\ return TestCase {
7624 \\ .filename = filename,
7625 \\ .problem_type = ProblemType.Free,
7626 \\ };
7627 \\}
7628 \\
7629 \\fn LibC(comptime filename: []const u8) TestCase {
7630 \\ return TestCase {
7631 \\ .filename = filename,
7632 \\ .problem_type = ProblemType.LinkLibC,
7633 \\ };
7634 \\}
7635 \\
7636 \\const TestCase = struct {
7637 \\ filename: []const u8,
7638 \\ problem_type: ProblemType,
7639 \\};
7640 \\
7641 \\const ProblemType = enum {
7642 \\ Free,
7643 \\ LinkLibC,
7644 \\};
7645 \\
7646 \\export fn entry() void {
7647 \\ const tests = [_]TestCase {
7648 \\ Free("001"),
7649 \\ Free("002"),
7650 \\ LibC("078"),
7651 \\ Free("116"),
7652 \\ Free("117"),
7653 \\ };
7654 \\
7655 \\ for ([_]Mode { Mode.Debug, Mode.ReleaseSafe, Mode.ReleaseFast }) |mode| {
7656 \\ _ = mode;
7657 \\ inline for (tests) |test_case| {
7658 \\ const foo = test_case.filename ++ ".zig";
7659 \\ _ = foo;
7660 \\ }
7661 \\ }
7662 \\}
7663 , &[_][]const u8{
7664 "tmp.zig:38:29: error: cannot store runtime value in compile time variable",
7665 });
7666
7667 ctx.objErrStage1("invalid legacy unicode escape",
7668 \\export fn entry() void {
7669 \\ const a = '\U1234';
7670 \\}
7671 , &[_][]const u8{
7672 "tmp.zig:2:15: error: expected expression, found 'invalid bytes'",
7673 "tmp.zig:2:18: note: invalid byte: '1'",
7674 });
7675
7676 ctx.objErrStage1("invalid empty unicode escape",
7677 \\export fn entry() void {
7678 \\ const a = '\u{}';
7679 \\}
7680 , &[_][]const u8{
7681 "tmp.zig:2:19: error: empty unicode escape sequence",
7682 });
7683
7684 ctx.objErrStage1("non-printable invalid character", "\xff\xfe" ++
7685 "fn foo() bool {\r\n" ++
7686 " return true;\r\n" ++
7687 "}\r\n", &[_][]const u8{
7688 "tmp.zig:1:1: error: expected test, comptime, var decl, or container field, found 'invalid bytes'",
7689 "tmp.zig:1:1: note: invalid byte: '\\xff'",
7690 });
7691
7692 ctx.objErrStage1("non-printable invalid character with escape alternative", "fn foo() bool {\n" ++
7693 "\treturn true;\n" ++
7694 "}\n", &[_][]const u8{
7695 "tmp.zig:2:1: error: invalid character: '\\t'",
7696 });
7697
7698 ctx.objErrStage1("calling var args extern function, passing array instead of pointer",
7699 \\export fn entry() void {
7700 \\ foo("hello".*,);
7701 \\}
7702 \\pub extern fn foo(format: *const u8, ...) void;
7703 , &[_][]const u8{
7704 "tmp.zig:2:16: error: expected type '*const u8', found '[5:0]u8'",
7705 });
7706
7707 ctx.objErrStage1("constant inside comptime function has compile error",
7708 \\const ContextAllocator = MemoryPool(usize);
7709 \\
7710 \\pub fn MemoryPool(comptime T: type) type {
7711 \\ const free_list_t = @compileError("aoeu",);
7712 \\
7713 \\ return struct {
7714 \\ free_list: free_list_t,
7715 \\ };
7716 \\}
7717 \\
7718 \\export fn entry() void {
7719 \\ var allocator: ContextAllocator = undefined;
7720 \\}
7721 , &[_][]const u8{
7722 "tmp.zig:4:5: error: unreachable code",
7723 "tmp.zig:4:25: note: control flow is diverted here",
7724 "tmp.zig:12:9: error: unused local variable",
7725 });
7726
7727 ctx.objErrStage1("specify enum tag type that is too small",
7728 \\const Small = enum (u2) {
7729 \\ One,
7730 \\ Two,
7731 \\ Three,
7732 \\ Four,
7733 \\ Five,
7734 \\};
7735 \\
7736 \\export fn entry() void {
7737 \\ var x = Small.One;
7738 \\ _ = x;
7739 \\}
7740 , &[_][]const u8{
7741 "tmp.zig:6:5: error: enumeration value 4 too large for type 'u2'",
7742 });
7743
7744 ctx.objErrStage1("specify non-integer enum tag type",
7745 \\const Small = enum (f32) {
7746 \\ One,
7747 \\ Two,
7748 \\ Three,
7749 \\};
7750 \\
7751 \\export fn entry() void {
7752 \\ var x = Small.One;
7753 \\ _ = x;
7754 \\}
7755 , &[_][]const u8{
7756 "tmp.zig:1:21: error: expected integer, found 'f32'",
7757 });
7758
7759 ctx.objErrStage1("implicitly casting enum to tag type",
7760 \\const Small = enum(u2) {
7761 \\ One,
7762 \\ Two,
7763 \\ Three,
7764 \\ Four,
7765 \\};
7766 \\
7767 \\export fn entry() void {
7768 \\ var x: u2 = Small.Two;
7769 \\ _ = x;
7770 \\}
7771 , &[_][]const u8{
7772 "tmp.zig:9:22: error: expected type 'u2', found 'Small'",
7773 });
7774
7775 ctx.objErrStage1("explicitly casting non tag type to enum",
7776 \\const Small = enum(u2) {
7777 \\ One,
7778 \\ Two,
7779 \\ Three,
7780 \\ Four,
7781 \\};
7782 \\
7783 \\export fn entry() void {
7784 \\ var y = @as(f32, 3);
7785 \\ var x = @intToEnum(Small, y);
7786 \\ _ = x;
7787 \\}
7788 , &[_][]const u8{
7789 "tmp.zig:10:31: error: expected integer type, found 'f32'",
7790 });
7791
7792 ctx.objErrStage1("union fields with value assignments",
7793 \\const MultipleChoice = union {
7794 \\ A: i32 = 20,
7795 \\};
7796 \\export fn entry() void {
7797 \\ var x: MultipleChoice = undefined;
7798 \\ _ = x;
7799 \\}
7800 , &[_][]const u8{
7801 "tmp.zig:1:24: error: explicitly valued tagged union missing integer tag type",
7802 "tmp.zig:2:14: note: tag value specified here",
7803 });
7804
7805 ctx.objErrStage1("enum with 0 fields",
7806 \\const Foo = enum {};
7807 , &[_][]const u8{
7808 "tmp.zig:1:13: error: enum declarations must have at least one tag",
7809 });
7810
7811 ctx.objErrStage1("union with 0 fields",
7812 \\const Foo = union {};
7813 , &[_][]const u8{
7814 "tmp.zig:1:13: error: union declarations must have at least one tag",
7815 });
7816
7817 ctx.objErrStage1("enum value already taken",
7818 \\const MultipleChoice = enum(u32) {
7819 \\ A = 20,
7820 \\ B = 40,
7821 \\ C = 60,
7822 \\ D = 1000,
7823 \\ E = 60,
7824 \\};
7825 \\export fn entry() void {
7826 \\ var x = MultipleChoice.C;
7827 \\ _ = x;
7828 \\}
7829 , &[_][]const u8{
7830 "tmp.zig:6:5: error: enum tag value 60 already taken",
7831 "tmp.zig:4:5: note: other occurrence here",
7832 });
7833
7834 ctx.objErrStage1("union with specified enum omits field",
7835 \\const Letter = enum {
7836 \\ A,
7837 \\ B,
7838 \\ C,
7839 \\};
7840 \\const Payload = union(Letter) {
7841 \\ A: i32,
7842 \\ B: f64,
7843 \\};
7844 \\export fn entry() usize {
7845 \\ return @sizeOf(Payload);
7846 \\}
7847 , &[_][]const u8{
7848 "tmp.zig:6:17: error: enum field missing: 'C'",
7849 "tmp.zig:4:5: note: declared here",
7850 });
7851
7852 ctx.objErrStage1("non-integer tag type to automatic union enum",
7853 \\const Foo = union(enum(f32)) {
7854 \\ A: i32,
7855 \\};
7856 \\export fn entry() void {
7857 \\ const x = @typeInfo(Foo).Union.tag_type.?;
7858 \\ _ = x;
7859 \\}
7860 , &[_][]const u8{
7861 "tmp.zig:1:24: error: expected integer tag type, found 'f32'",
7862 });
7863
7864 ctx.objErrStage1("non-enum tag type passed to union",
7865 \\const Foo = union(u32) {
7866 \\ A: i32,
7867 \\};
7868 \\export fn entry() void {
7869 \\ const x = @typeInfo(Foo).Union.tag_type.?;
7870 \\ _ = x;
7871 \\}
7872 , &[_][]const u8{
7873 "tmp.zig:1:19: error: expected enum tag type, found 'u32'",
7874 });
7875
7876 ctx.objErrStage1("union auto-enum value already taken",
7877 \\const MultipleChoice = union(enum(u32)) {
7878 \\ A = 20,
7879 \\ B = 40,
7880 \\ C = 60,
7881 \\ D = 1000,
7882 \\ E = 60,
7883 \\};
7884 \\export fn entry() void {
7885 \\ var x = MultipleChoice { .C = {} };
7886 \\ _ = x;
7887 \\}
7888 , &[_][]const u8{
7889 "tmp.zig:6:9: error: enum tag value 60 already taken",
7890 "tmp.zig:4:9: note: other occurrence here",
7891 });
7892
7893 ctx.objErrStage1("union enum field does not match enum",
7894 \\const Letter = enum {
7895 \\ A,
7896 \\ B,
7897 \\ C,
7898 \\};
7899 \\const Payload = union(Letter) {
7900 \\ A: i32,
7901 \\ B: f64,
7902 \\ C: bool,
7903 \\ D: bool,
7904 \\};
7905 \\export fn entry() void {
7906 \\ var a = Payload {.A = 1234};
7907 \\ _ = a;
7908 \\}
7909 , &[_][]const u8{
7910 "tmp.zig:10:5: error: enum field not found: 'D'",
7911 "tmp.zig:1:16: note: enum declared here",
7912 });
7913
7914 ctx.objErrStage1("field type supplied in an enum",
7915 \\const Letter = enum {
7916 \\ A: void,
7917 \\ B,
7918 \\ C,
7919 \\};
7920 , &[_][]const u8{
7921 "tmp.zig:2:8: error: enum fields do not have types",
7922 "tmp.zig:1:16: note: consider 'union(enum)' here to make it a tagged union",
7923 });
7924
7925 ctx.objErrStage1("struct field missing type",
7926 \\const Letter = struct {
7927 \\ A,
7928 \\};
7929 \\export fn entry() void {
7930 \\ var a = Letter { .A = {} };
7931 \\ _ = a;
7932 \\}
7933 , &[_][]const u8{
7934 "tmp.zig:2:5: error: struct field missing type",
7935 });
7936
7937 ctx.objErrStage1("extern union field missing type",
7938 \\const Letter = extern union {
7939 \\ A,
7940 \\};
7941 \\export fn entry() void {
7942 \\ var a = Letter { .A = {} };
7943 \\ _ = a;
7944 \\}
7945 , &[_][]const u8{
7946 "tmp.zig:2:5: error: union field missing type",
7947 });
7948
7949 ctx.objErrStage1("extern union given enum tag type",
7950 \\const Letter = enum {
7951 \\ A,
7952 \\ B,
7953 \\ C,
7954 \\};
7955 \\const Payload = extern union(Letter) {
7956 \\ A: i32,
7957 \\ B: f64,
7958 \\ C: bool,
7959 \\};
7960 \\export fn entry() void {
7961 \\ var a = Payload { .A = 1234 };
7962 \\ _ = a;
7963 \\}
7964 , &[_][]const u8{
7965 "tmp.zig:6:30: error: extern union does not support enum tag type",
7966 });
7967
7968 ctx.objErrStage1("packed union given enum tag type",
7969 \\const Letter = enum {
7970 \\ A,
7971 \\ B,
7972 \\ C,
7973 \\};
7974 \\const Payload = packed union(Letter) {
7975 \\ A: i32,
7976 \\ B: f64,
7977 \\ C: bool,
7978 \\};
7979 \\export fn entry() void {
7980 \\ var a = Payload { .A = 1234 };
7981 \\ _ = a;
7982 \\}
7983 , &[_][]const u8{
7984 "tmp.zig:6:30: error: packed union does not support enum tag type",
7985 });
7986
7987 ctx.objErrStage1("packed union with automatic layout field",
7988 \\const Foo = struct {
7989 \\ a: u32,
7990 \\ b: f32,
7991 \\};
7992 \\const Payload = packed union {
7993 \\ A: Foo,
7994 \\ B: bool,
7995 \\};
7996 \\export fn entry() void {
7997 \\ var a = Payload { .B = true };
7998 \\ _ = a;
7999 \\}
8000 , &[_][]const u8{
8001 "tmp.zig:6:5: error: non-packed, non-extern struct 'Foo' not allowed in packed union; no guaranteed in-memory representation",
8002 });
8003
8004 ctx.objErrStage1("switch on union with no attached enum",
8005 \\const Payload = union {
8006 \\ A: i32,
8007 \\ B: f64,
8008 \\ C: bool,
8009 \\};
8010 \\export fn entry() void {
8011 \\ const a = Payload { .A = 1234 };
8012 \\ foo(a);
8013 \\}
8014 \\fn foo(a: *const Payload) void {
8015 \\ switch (a.*) {
8016 \\ Payload.A => {},
8017 \\ else => unreachable,
8018 \\ }
8019 \\}
8020 , &[_][]const u8{
8021 "tmp.zig:11:14: error: switch on union which has no attached enum",
8022 "tmp.zig:1:17: note: consider 'union(enum)' here",
8023 });
8024
8025 ctx.objErrStage1("enum in field count range but not matching tag",
8026 \\const Foo = enum(u32) {
8027 \\ A = 10,
8028 \\ B = 11,
8029 \\};
8030 \\export fn entry() void {
8031 \\ var x = @intToEnum(Foo, 0);
8032 \\ _ = x;
8033 \\}
8034 , &[_][]const u8{
8035 "tmp.zig:6:13: error: enum 'Foo' has no tag matching integer value 0",
8036 "tmp.zig:1:13: note: 'Foo' declared here",
8037 });
8038
8039 ctx.objErrStage1("comptime cast enum to union but field has payload",
8040 \\const Letter = enum { A, B, C };
8041 \\const Value = union(Letter) {
8042 \\ A: i32,
8043 \\ B,
8044 \\ C,
8045 \\};
8046 \\export fn entry() void {
8047 \\ var x: Value = Letter.A;
8048 \\ _ = x;
8049 \\}
8050 , &[_][]const u8{
8051 "tmp.zig:8:26: error: cast to union 'Value' must initialize 'i32' field 'A'",
8052 "tmp.zig:3:5: note: field 'A' declared here",
8053 });
8054
8055 ctx.objErrStage1("runtime cast to union which has non-void fields",
8056 \\const Letter = enum { A, B, C };
8057 \\const Value = union(Letter) {
8058 \\ A: i32,
8059 \\ B,
8060 \\ C,
8061 \\};
8062 \\export fn entry() void {
8063 \\ foo(Letter.A);
8064 \\}
8065 \\fn foo(l: Letter) void {
8066 \\ var x: Value = l;
8067 \\ _ = x;
8068 \\}
8069 , &[_][]const u8{
8070 "tmp.zig:11:20: error: runtime cast to union 'Value' which has non-void fields",
8071 "tmp.zig:3:5: note: field 'A' has type 'i32'",
8072 });
8073
8074 ctx.objErrStage1("taking byte offset of void field in struct",
8075 \\const Empty = struct {
8076 \\ val: void,
8077 \\};
8078 \\export fn foo() void {
8079 \\ const fieldOffset = @offsetOf(Empty, "val",);
8080 \\ _ = fieldOffset;
8081 \\}
8082 , &[_][]const u8{
8083 "tmp.zig:5:42: error: zero-bit field 'val' in struct 'Empty' has no offset",
8084 });
8085
8086 ctx.objErrStage1("taking bit offset of void field in struct",
8087 \\const Empty = struct {
8088 \\ val: void,
8089 \\};
8090 \\export fn foo() void {
8091 \\ const fieldOffset = @bitOffsetOf(Empty, "val",);
8092 \\ _ = fieldOffset;
8093 \\}
8094 , &[_][]const u8{
8095 "tmp.zig:5:45: error: zero-bit field 'val' in struct 'Empty' has no offset",
8096 });
8097
8098 ctx.objErrStage1("invalid union field access in comptime",
8099 \\const Foo = union {
8100 \\ Bar: u8,
8101 \\ Baz: void,
8102 \\};
8103 \\comptime {
8104 \\ var foo = Foo {.Baz = {}};
8105 \\ const bar_val = foo.Bar;
8106 \\ _ = bar_val;
8107 \\}
8108 , &[_][]const u8{
8109 "tmp.zig:7:24: error: accessing union field 'Bar' while field 'Baz' is set",
8110 });
8111
8112 ctx.objErrStage1("unsupported modifier at start of asm output constraint",
8113 \\export fn foo() void {
8114 \\ var bar: u32 = 3;
8115 \\ asm volatile ("" : [baz]"+r"(bar) : : "");
8116 \\}
8117 , &[_][]const u8{
8118 "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",
8119 });
8120
8121 ctx.objErrStage1("comptime_int in asm input",
8122 \\export fn foo() void {
8123 \\ asm volatile ("" : : [bar]"r"(3) : "");
8124 \\}
8125 , &[_][]const u8{
8126 "tmp.zig:2:35: error: expected sized integer or sized float, found comptime_int",
8127 });
8128
8129 ctx.objErrStage1("comptime_float in asm input",
8130 \\export fn foo() void {
8131 \\ asm volatile ("" : : [bar]"r"(3.17) : "");
8132 \\}
8133 , &[_][]const u8{
8134 "tmp.zig:2:35: error: expected sized integer or sized float, found comptime_float",
8135 });
8136
8137 ctx.objErrStage1("runtime assignment to comptime struct type",
8138 \\const Foo = struct {
8139 \\ Bar: u8,
8140 \\ Baz: type,
8141 \\};
8142 \\export fn f() void {
8143 \\ var x: u8 = 0;
8144 \\ const foo = Foo { .Bar = x, .Baz = u8 };
8145 \\ _ = foo;
8146 \\}
8147 , &[_][]const u8{
8148 "tmp.zig:7:23: error: unable to evaluate constant expression",
8149 });
8150
8151 ctx.objErrStage1("runtime assignment to comptime union type",
8152 \\const Foo = union {
8153 \\ Bar: u8,
8154 \\ Baz: type,
8155 \\};
8156 \\export fn f() void {
8157 \\ var x: u8 = 0;
8158 \\ const foo = Foo { .Bar = x };
8159 \\ _ = foo;
8160 \\}
8161 , &[_][]const u8{
8162 "tmp.zig:7:23: error: unable to evaluate constant expression",
8163 });
8164
8165 ctx.testErrStage1("@shuffle with selected index past first vector length",
8166 \\export fn entry() void {
8167 \\ const v: @import("std").meta.Vector(4, u32) = [4]u32{ 10, 11, 12, 13 };
8168 \\ const x: @import("std").meta.Vector(4, u32) = [4]u32{ 14, 15, 16, 17 };
8169 \\ var z = @shuffle(u32, v, x, [8]i32{ 0, 1, 2, 3, 7, 6, 5, 4 });
8170 \\ _ = z;
8171 \\}
8172 , &[_][]const u8{
8173 "tmp.zig:4:39: error: mask index '4' has out-of-bounds selection",
8174 "tmp.zig:4:27: note: selected index '7' out of bounds of @Vector(4, u32)",
8175 "tmp.zig:4:30: note: selections from the second vector are specified with negative numbers",
8176 });
8177
8178 ctx.testErrStage1("nested vectors",
8179 \\export fn entry() void {
8180 \\ const V1 = @import("std").meta.Vector(4, u8);
8181 \\ const V2 = @Type(.{ .Vector = .{ .len = 4, .child = V1 } });
8182 \\ var v: V2 = undefined;
8183 \\ _ = v;
8184 \\}
8185 , &[_][]const u8{
8186 "tmp.zig:3:23: error: vector element type must be integer, float, bool, or pointer; '@Vector(4, u8)' is invalid",
8187 });
8188
8189 ctx.testErrStage1("bad @splat type",
8190 \\export fn entry() void {
8191 \\ const c = 4;
8192 \\ var v = @splat(4, c);
8193 \\ _ = v;
8194 \\}
8195 , &[_][]const u8{
8196 "tmp.zig:3:23: error: vector element type must be integer, float, bool, or pointer; 'comptime_int' is invalid",
8197 });
8198
8199 ctx.objErrStage1("compileLog of tagged enum doesn't crash the compiler",
8200 \\const Bar = union(enum(u32)) {
8201 \\ X: i32 = 1
8202 \\};
8203 \\
8204 \\fn testCompileLog(x: Bar) void {
8205 \\ @compileLog(x);
8206 \\}
8207 \\
8208 \\pub fn main () void {
8209 \\ comptime testCompileLog(Bar{.X = 123});
8210 \\}
8211 , &[_][]const u8{
8212 "tmp.zig:6:5: error: found compile log statement",
8213 });
8214
8215 ctx.objErrStage1("attempted implicit cast from *const T to *[1]T",
8216 \\export fn entry(byte: u8) void {
8217 \\ const w: i32 = 1234;
8218 \\ var x: *const i32 = &w;
8219 \\ var y: *[1]i32 = x;
8220 \\ y[0] += 1;
8221 \\ _ = byte;
8222 \\}
8223 , &[_][]const u8{
8224 "tmp.zig:4:22: error: expected type '*[1]i32', found '*const i32'",
8225 "tmp.zig:4:22: note: cast discards const qualifier",
8226 });
8227
8228 ctx.objErrStage1("attempted implicit cast from *const T to []T",
8229 \\export fn entry() void {
8230 \\ const u: u32 = 42;
8231 \\ const x: []u32 = &u;
8232 \\ _ = x;
8233 \\}
8234 , &[_][]const u8{
8235 "tmp.zig:3:23: error: expected type '[]u32', found '*const u32'",
8236 });
8237
8238 ctx.objErrStage1("for loop body expression ignored",
8239 \\fn returns() usize {
8240 \\ return 2;
8241 \\}
8242 \\export fn f1() void {
8243 \\ for ("hello") |_| returns();
8244 \\}
8245 \\export fn f2() void {
8246 \\ var x: anyerror!i32 = error.Bad;
8247 \\ for ("hello") |_| returns() else unreachable;
8248 \\ _ = x;
8249 \\}
8250 , &[_][]const u8{
8251 "tmp.zig:5:30: error: expression value is ignored",
8252 "tmp.zig:9:30: error: expression value is ignored",
8253 });
8254
8255 ctx.objErrStage1("aligned variable of zero-bit type",
8256 \\export fn f() void {
8257 \\ var s: struct {} align(4) = undefined;
8258 \\ _ = s;
8259 \\}
8260 , &[_][]const u8{
8261 "tmp.zig:2:5: error: variable 's' of zero-bit type 'struct:2:12' has no in-memory representation, it cannot be aligned",
8262 });
8263
8264 ctx.objErrStage1("function returning opaque type",
8265 \\const FooType = opaque {};
8266 \\export fn bar() !FooType {
8267 \\ return error.InvalidValue;
8268 \\}
8269 \\export fn bav() !@TypeOf(null) {
8270 \\ return error.InvalidValue;
8271 \\}
8272 \\export fn baz() !@TypeOf(undefined) {
8273 \\ return error.InvalidValue;
8274 \\}
8275 , &[_][]const u8{
8276 "tmp.zig:2:18: error: Opaque return type 'FooType' not allowed",
8277 "tmp.zig:1:1: note: type declared here",
8278 "tmp.zig:5:18: error: Null return type '@Type(.Null)' not allowed",
8279 "tmp.zig:8:18: error: Undefined return type '@Type(.Undefined)' not allowed",
8280 });
8281
8282 ctx.objErrStage1("generic function returning opaque type",
8283 \\const FooType = opaque {};
8284 \\fn generic(comptime T: type) !T {
8285 \\ return undefined;
8286 \\}
8287 \\export fn bar() void {
8288 \\ _ = generic(FooType);
8289 \\}
8290 \\export fn bav() void {
8291 \\ _ = generic(@TypeOf(null));
8292 \\}
8293 \\export fn baz() void {
8294 \\ _ = generic(@TypeOf(undefined));
8295 \\}
8296 , &[_][]const u8{
8297 "tmp.zig:6:16: error: call to generic function with Opaque return type 'FooType' not allowed",
8298 "tmp.zig:2:1: note: function declared here",
8299 "tmp.zig:1:1: note: type declared here",
8300 "tmp.zig:9:16: error: call to generic function with Null return type '@Type(.Null)' not allowed",
8301 "tmp.zig:2:1: note: function declared here",
8302 "tmp.zig:12:16: error: call to generic function with Undefined return type '@Type(.Undefined)' not allowed",
8303 "tmp.zig:2:1: note: function declared here",
8304 });
8305
8306 ctx.objErrStage1("function parameter is opaque",
8307 \\const FooType = opaque {};
8308 \\export fn entry1() void {
8309 \\ const someFuncPtr: fn (FooType) void = undefined;
8310 \\ _ = someFuncPtr;
8311 \\}
8312 \\
8313 \\export fn entry2() void {
8314 \\ const someFuncPtr: fn (@TypeOf(null)) void = undefined;
8315 \\ _ = someFuncPtr;
8316 \\}
8317 \\
8318 \\fn foo(p: FooType) void {_ = p;}
8319 \\export fn entry3() void {
8320 \\ _ = foo;
8321 \\}
8322 \\
8323 \\fn bar(p: @TypeOf(null)) void {_ = p;}
8324 \\export fn entry4() void {
8325 \\ _ = bar;
8326 \\}
8327 , &[_][]const u8{
8328 "tmp.zig:3:28: error: parameter of opaque type 'FooType' not allowed",
8329 "tmp.zig:8:28: error: parameter of type '@Type(.Null)' not allowed",
8330 "tmp.zig:12:11: error: parameter of opaque type 'FooType' not allowed",
8331 "tmp.zig:17:11: error: parameter of type '@Type(.Null)' not allowed",
8332 });
8333
8334 ctx.objErrStage1( // fixed bug #2032
8335 "compile diagnostic string for top level decl type",
8336 \\export fn entry() void {
8337 \\ var foo: u32 = @This(){};
8338 \\ _ = foo;
8339 \\}
8340 , &[_][]const u8{
8341 "tmp.zig:2:27: error: type 'u32' does not support array initialization",
8342 });
8343
8344 ctx.objErrStage1("issue #2687: coerce from undefined array pointer to slice",
8345 \\export fn foo1() void {
8346 \\ const a: *[1]u8 = undefined;
8347 \\ var b: []u8 = a;
8348 \\ _ = b;
8349 \\}
8350 \\export fn foo2() void {
8351 \\ comptime {
8352 \\ var a: *[1]u8 = undefined;
8353 \\ var b: []u8 = a;
8354 \\ _ = b;
8355 \\ }
8356 \\}
8357 \\export fn foo3() void {
8358 \\ comptime {
8359 \\ const a: *[1]u8 = undefined;
8360 \\ var b: []u8 = a;
8361 \\ _ = b;
8362 \\ }
8363 \\}
8364 , &[_][]const u8{
8365 "tmp.zig:3:19: error: use of undefined value here causes undefined behavior",
8366 "tmp.zig:9:23: error: use of undefined value here causes undefined behavior",
8367 "tmp.zig:16:23: error: use of undefined value here causes undefined behavior",
8368 });
8369320
8370 ctx.objErrStage1("issue #3818: bitcast from parray/slice to u16",321 {
8371 \\export fn foo1() void {322 const case = ctx.obj("multiple files with private member instance function error", .{});
8372 \\ var bytes = [_]u8{1, 2};323 case.backend = .stage1;
8373 \\ const word: u16 = @bitCast(u16, bytes[0..]);
8374 \\ _ = word;
8375 \\}
8376 \\export fn foo2() void {
8377 \\ var bytes: []const u8 = &[_]u8{1, 2};
8378 \\ const word: u16 = @bitCast(u16, bytes);
8379 \\ _ = word;
8380 \\}
8381 , &[_][]const u8{
8382 "tmp.zig:3:42: error: unable to @bitCast from pointer type '*[2]u8'",
8383 "tmp.zig:8:32: error: destination type 'u16' has size 2 but source type '[]const u8' has size 16",
8384 });
8385324
8386 // issue #7810325 case.addSourceFile("foo.zig",
8387 ctx.objErrStage1("comptime slice-len increment beyond bounds",326 \\pub const Foo = struct {
8388 \\export fn foo_slice_len_increment_beyond_bounds() void {327 \\ fn privateFunction(self: *Foo) void { _ = self; }
8389 \\ comptime {328 \\};
8390 \\ var buf_storage: [8]u8 = undefined;329 );
8391 \\ var buf: []const u8 = buf_storage[0..];
8392 \\ buf.len += 1;
8393 \\ buf[8] = 42;
8394 \\ }
8395 \\}
8396 , &[_][]const u8{
8397 ":6:12: error: out of bounds slice",
8398 });
8399330
8400 ctx.objErrStage1("comptime slice-sentinel is out of bounds (unterminated)",331 case.addError(
8401 \\export fn foo_array() void {332 \\const Foo = @import("foo.zig",).Foo;
8402 \\ comptime {333 \\
8403 \\ var target = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;334 \\export fn callPrivFunction() void {
8404 \\ const slice = target[0..14 :0];335 \\ var foo = Foo{};
8405 \\ _ = slice;336 \\ foo.privateFunction();
8406 \\ }337 \\}
8407 \\}338 , &[_][]const u8{
8408 \\export fn foo_ptr_array() void {339 "tmp.zig:5:8: error: 'privateFunction' is private",
8409 \\ comptime {340 "foo.zig:2:5: note: declared here",
8410 \\ var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;341 });
8411 \\ var target = &buf;342 }
8412 \\ const slice = target[0..14 :0];
8413 \\ _ = slice;
8414 \\ }
8415 \\}
8416 \\export fn foo_vector_ConstPtrSpecialBaseArray() void {
8417 \\ comptime {
8418 \\ var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
8419 \\ var target: [*]u8 = &buf;
8420 \\ const slice = target[0..14 :0];
8421 \\ _ = slice;
8422 \\ }
8423 \\}
8424 \\export fn foo_vector_ConstPtrSpecialRef() void {
8425 \\ comptime {
8426 \\ var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
8427 \\ var target: [*]u8 = @ptrCast([*]u8, &buf);
8428 \\ const slice = target[0..14 :0];
8429 \\ _ = slice;
8430 \\ }
8431 \\}
8432 \\export fn foo_cvector_ConstPtrSpecialBaseArray() void {
8433 \\ comptime {
8434 \\ var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
8435 \\ var target: [*c]u8 = &buf;
8436 \\ const slice = target[0..14 :0];
8437 \\ _ = slice;
8438 \\ }
8439 \\}
8440 \\export fn foo_cvector_ConstPtrSpecialRef() void {
8441 \\ comptime {
8442 \\ var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
8443 \\ var target: [*c]u8 = @ptrCast([*c]u8, &buf);
8444 \\ const slice = target[0..14 :0];
8445 \\ _ = slice;
8446 \\ }
8447 \\}
8448 \\export fn foo_slice() void {
8449 \\ comptime {
8450 \\ var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
8451 \\ var target: []u8 = &buf;
8452 \\ const slice = target[0..14 :0];
8453 \\ _ = slice;
8454 \\ }
8455 \\}
8456 , &[_][]const u8{
8457 ":4:29: error: slice-sentinel is out of bounds",
8458 ":12:29: error: slice-sentinel is out of bounds",
8459 ":20:29: error: slice-sentinel is out of bounds",
8460 ":28:29: error: slice-sentinel is out of bounds",
8461 ":36:29: error: slice-sentinel is out of bounds",
8462 ":44:29: error: slice-sentinel is out of bounds",
8463 ":52:29: error: slice-sentinel is out of bounds",
8464 });
8465343
8466 ctx.objErrStage1("comptime slice-sentinel is out of bounds (terminated)",344 {
8467 \\export fn foo_array() void {345 const case = ctx.obj("export collision", .{});
8468 \\ comptime {346 case.backend = .stage1;
8469 \\ var target = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
8470 \\ const slice = target[0..15 :1];
8471 \\ _ = slice;
8472 \\ }
8473 \\}
8474 \\export fn foo_ptr_array() void {
8475 \\ comptime {
8476 \\ var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
8477 \\ var target = &buf;
8478 \\ const slice = target[0..15 :0];
8479 \\ _ = slice;
8480 \\ }
8481 \\}
8482 \\export fn foo_vector_ConstPtrSpecialBaseArray() void {
8483 \\ comptime {
8484 \\ var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
8485 \\ var target: [*]u8 = &buf;
8486 \\ const slice = target[0..15 :0];
8487 \\ _ = slice;
8488 \\ }
8489 \\}
8490 \\export fn foo_vector_ConstPtrSpecialRef() void {
8491 \\ comptime {
8492 \\ var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
8493 \\ var target: [*]u8 = @ptrCast([*]u8, &buf);
8494 \\ const slice = target[0..15 :0];
8495 \\ _ = slice;
8496 \\ }
8497 \\}
8498 \\export fn foo_cvector_ConstPtrSpecialBaseArray() void {
8499 \\ comptime {
8500 \\ var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
8501 \\ var target: [*c]u8 = &buf;
8502 \\ const slice = target[0..15 :0];
8503 \\ _ = slice;
8504 \\ }
8505 \\}
8506 \\export fn foo_cvector_ConstPtrSpecialRef() void {
8507 \\ comptime {
8508 \\ var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
8509 \\ var target: [*c]u8 = @ptrCast([*c]u8, &buf);
8510 \\ const slice = target[0..15 :0];
8511 \\ _ = slice;
8512 \\ }
8513 \\}
8514 \\export fn foo_slice() void {
8515 \\ comptime {
8516 \\ var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
8517 \\ var target: []u8 = &buf;
8518 \\ const slice = target[0..15 :0];
8519 \\ _ = slice;
8520 \\ }
8521 \\}
8522 , &[_][]const u8{
8523 ":4:29: error: out of bounds slice",
8524 ":12:29: error: out of bounds slice",
8525 ":20:29: error: out of bounds slice",
8526 ":28:29: error: out of bounds slice",
8527 ":36:29: error: out of bounds slice",
8528 ":44:29: error: out of bounds slice",
8529 ":52:29: error: out of bounds slice",
8530 });
8531347
8532 ctx.objErrStage1("comptime slice-sentinel does not match memory at target index (unterminated)",348 case.addSourceFile("foo.zig",
8533 \\export fn foo_array() void {349 \\export fn bar() void {}
8534 \\ comptime {350 \\pub const baz = 1234;
8535 \\ var target = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;351 );
8536 \\ const slice = target[0..3 :0];
8537 \\ _ = slice;
8538 \\ }
8539 \\}
8540 \\export fn foo_ptr_array() void {
8541 \\ comptime {
8542 \\ var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
8543 \\ var target = &buf;
8544 \\ const slice = target[0..3 :0];
8545 \\ _ = slice;
8546 \\ }
8547 \\}
8548 \\export fn foo_vector_ConstPtrSpecialBaseArray() void {
8549 \\ comptime {
8550 \\ var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
8551 \\ var target: [*]u8 = &buf;
8552 \\ const slice = target[0..3 :0];
8553 \\ _ = slice;
8554 \\ }
8555 \\}
8556 \\export fn foo_vector_ConstPtrSpecialRef() void {
8557 \\ comptime {
8558 \\ var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
8559 \\ var target: [*]u8 = @ptrCast([*]u8, &buf);
8560 \\ const slice = target[0..3 :0];
8561 \\ _ = slice;
8562 \\ }
8563 \\}
8564 \\export fn foo_cvector_ConstPtrSpecialBaseArray() void {
8565 \\ comptime {
8566 \\ var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
8567 \\ var target: [*c]u8 = &buf;
8568 \\ const slice = target[0..3 :0];
8569 \\ _ = slice;
8570 \\ }
8571 \\}
8572 \\export fn foo_cvector_ConstPtrSpecialRef() void {
8573 \\ comptime {
8574 \\ var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
8575 \\ var target: [*c]u8 = @ptrCast([*c]u8, &buf);
8576 \\ const slice = target[0..3 :0];
8577 \\ _ = slice;
8578 \\ }
8579 \\}
8580 \\export fn foo_slice() void {
8581 \\ comptime {
8582 \\ var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
8583 \\ var target: []u8 = &buf;
8584 \\ const slice = target[0..3 :0];
8585 \\ _ = slice;
8586 \\ }
8587 \\}
8588 , &[_][]const u8{
8589 ":4:29: error: slice-sentinel does not match memory at target index",
8590 ":12:29: error: slice-sentinel does not match memory at target index",
8591 ":20:29: error: slice-sentinel does not match memory at target index",
8592 ":28:29: error: slice-sentinel does not match memory at target index",
8593 ":36:29: error: slice-sentinel does not match memory at target index",
8594 ":44:29: error: slice-sentinel does not match memory at target index",
8595 ":52:29: error: slice-sentinel does not match memory at target index",
8596 });
8597352
8598 ctx.objErrStage1("comptime slice-sentinel does not match memory at target index (terminated)",353 case.addError(
8599 \\export fn foo_array() void {354 \\const foo = @import("foo.zig",);
8600 \\ comptime {355 \\
8601 \\ var target = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;356 \\export fn bar() usize {
8602 \\ const slice = target[0..3 :0];357 \\ return foo.baz;
8603 \\ _ = slice;358 \\}
8604 \\ }359 , &[_][]const u8{
8605 \\}360 "foo.zig:1:1: error: exported symbol collision: 'bar'",
8606 \\export fn foo_ptr_array() void {361 "tmp.zig:3:1: note: other symbol here",
8607 \\ comptime {362 });
8608 \\ var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;363 }
8609 \\ var target = &buf;
8610 \\ const slice = target[0..3 :0];
8611 \\ _ = slice;
8612 \\ }
8613 \\}
8614 \\export fn foo_vector_ConstPtrSpecialBaseArray() void {
8615 \\ comptime {
8616 \\ var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
8617 \\ var target: [*]u8 = &buf;
8618 \\ const slice = target[0..3 :0];
8619 \\ _ = slice;
8620 \\ }
8621 \\}
8622 \\export fn foo_vector_ConstPtrSpecialRef() void {
8623 \\ comptime {
8624 \\ var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
8625 \\ var target: [*]u8 = @ptrCast([*]u8, &buf);
8626 \\ const slice = target[0..3 :0];
8627 \\ _ = slice;
8628 \\ }
8629 \\}
8630 \\export fn foo_cvector_ConstPtrSpecialBaseArray() void {
8631 \\ comptime {
8632 \\ var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
8633 \\ var target: [*c]u8 = &buf;
8634 \\ const slice = target[0..3 :0];
8635 \\ _ = slice;
8636 \\ }
8637 \\}
8638 \\export fn foo_cvector_ConstPtrSpecialRef() void {
8639 \\ comptime {
8640 \\ var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
8641 \\ var target: [*c]u8 = @ptrCast([*c]u8, &buf);
8642 \\ const slice = target[0..3 :0];
8643 \\ _ = slice;
8644 \\ }
8645 \\}
8646 \\export fn foo_slice() void {
8647 \\ comptime {
8648 \\ var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
8649 \\ var target: []u8 = &buf;
8650 \\ const slice = target[0..3 :0];
8651 \\ _ = slice;
8652 \\ }
8653 \\}
8654 , &[_][]const u8{
8655 ":4:29: error: slice-sentinel does not match memory at target index",
8656 ":12:29: error: slice-sentinel does not match memory at target index",
8657 ":20:29: error: slice-sentinel does not match memory at target index",
8658 ":28:29: error: slice-sentinel does not match memory at target index",
8659 ":36:29: error: slice-sentinel does not match memory at target index",
8660 ":44:29: error: slice-sentinel does not match memory at target index",
8661 ":52:29: error: slice-sentinel does not match memory at target index",
8662 });
8663364
8664 ctx.objErrStage1("comptime slice-sentinel does not match target-sentinel",365 ctx.objErrStage1("non-printable invalid character", "\xff\xfe" ++
8665 \\export fn foo_array() void {366 "fn foo() bool {\r\n" ++
8666 \\ comptime {367 " return true;\r\n" ++
8667 \\ var target = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;368 "}\r\n", &[_][]const u8{
8668 \\ const slice = target[0..14 :255];369 "tmp.zig:1:1: error: expected test, comptime, var decl, or container field, found 'invalid bytes'",
8669 \\ _ = slice;370 "tmp.zig:1:1: note: invalid byte: '\\xff'",
8670 \\ }
8671 \\}
8672 \\export fn foo_ptr_array() void {
8673 \\ comptime {
8674 \\ var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
8675 \\ var target = &buf;
8676 \\ const slice = target[0..14 :255];
8677 \\ _ = slice;
8678 \\ }
8679 \\}
8680 \\export fn foo_vector_ConstPtrSpecialBaseArray() void {
8681 \\ comptime {
8682 \\ var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
8683 \\ var target: [*]u8 = &buf;
8684 \\ const slice = target[0..14 :255];
8685 \\ _ = slice;
8686 \\ }
8687 \\}
8688 \\export fn foo_vector_ConstPtrSpecialRef() void {
8689 \\ comptime {
8690 \\ var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
8691 \\ var target: [*]u8 = @ptrCast([*]u8, &buf);
8692 \\ const slice = target[0..14 :255];
8693 \\ _ = slice;
8694 \\ }
8695 \\}
8696 \\export fn foo_cvector_ConstPtrSpecialBaseArray() void {
8697 \\ comptime {
8698 \\ var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
8699 \\ var target: [*c]u8 = &buf;
8700 \\ const slice = target[0..14 :255];
8701 \\ _ = slice;
8702 \\ }
8703 \\}
8704 \\export fn foo_cvector_ConstPtrSpecialRef() void {
8705 \\ comptime {
8706 \\ var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
8707 \\ var target: [*c]u8 = @ptrCast([*c]u8, &buf);
8708 \\ const slice = target[0..14 :255];
8709 \\ _ = slice;
8710 \\ }
8711 \\}
8712 \\export fn foo_slice() void {
8713 \\ comptime {
8714 \\ var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
8715 \\ var target: []u8 = &buf;
8716 \\ const slice = target[0..14 :255];
8717 \\ _ = slice;
8718 \\ }
8719 \\}
8720 , &[_][]const u8{
8721 ":4:29: error: slice-sentinel does not match target-sentinel",
8722 ":12:29: error: slice-sentinel does not match target-sentinel",
8723 ":20:29: error: slice-sentinel does not match target-sentinel",
8724 ":28:29: error: slice-sentinel does not match target-sentinel",
8725 ":36:29: error: slice-sentinel does not match target-sentinel",
8726 ":44:29: error: slice-sentinel does not match target-sentinel",
8727 ":52:29: error: slice-sentinel does not match target-sentinel",
8728 });371 });
8729372
8730 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" ++
8731 \\export fn foo() [*:0]const u8 {374 "\treturn true;\n" ++
8732 \\ var buffer: [64]u8 = undefined;375 "}\n", &[_][]const u8{
8733 \\ return buffer[0..];376 "tmp.zig:2:1: error: invalid character: '\\t'",
8734 \\}
8735 , &[_][]const u8{
8736 ":3:18: error: expected type '[*:0]const u8', found '*[64]u8'",
8737 ":3:18: note: destination pointer requires a terminating '0' sentinel",
8738 });377 });
8739378
8740 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
8741 \\fn ignore(comptime param: anytype) void {_ = param;}380 //ctx.objErrStage1("inline fn calls itself indirectly",
8742 \\381 // \\export fn foo() void {
8743 \\export fn foo() void {382 // \\ bar();
8744 \\ const MyStruct = struct {383 // \\}
8745 \\ wrong_type: []u8 = "foo",384 // \\fn bar() callconv(.Inline) void {
8746 \\ };385 // \\ baz();
8747 \\386 // \\ quux();
8748 \\ comptime ignore(@typeInfo(MyStruct).Struct.fields[0]);387 // \\}
8749 \\}388 // \\fn baz() callconv(.Inline) void {
8750 , &[_][]const u8{389 // \\ bar();
8751 ":5:28: error: cannot cast pointer to array literal to slice type '[]u8'",390 // \\ quux();
8752 ":5:28: note: cast discards const qualifier",391 // \\}
8753 });392 // \\extern fn quux() void;
393 //, &[_][]const u8{
394 // "tmp.zig:4:1: error: unable to inline function",
395 //});
8754396
8755 ctx.objErrStage1("integer underflow error",397 //ctx.objErrStage1("save reference to inline function",
8756 \\export fn entry() void {398 // \\export fn foo() void {
8757 \\ _ = @intToPtr(*anyopaque, ~@as(usize, @import("std").math.maxInt(usize)) - 1);399 // \\ quux(@ptrToInt(bar));
8758 \\}400 // \\}
8759 , &[_][]const u8{401 // \\fn bar() callconv(.Inline) void { }
8760 ":2:78: error: operation caused overflow",402 // \\extern fn quux(usize) void;
8761 });403 //, &[_][]const u8{
404 // "tmp.zig:4:1: error: unable to inline function",
405 //});
8762406
8763 {407 {
8764 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", .{
...@@ -8776,165 +420,4 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -8776,165 +420,4 @@ pub fn addCases(ctx: *TestContext) !void {
8776 "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",
8777 });421 });
8778 }422 }
8779
8780 ctx.objErrStage1("compare optional to non-optional with invalid types",
8781 \\export fn inconsistentChildType() void {
8782 \\ var x: ?i32 = undefined;
8783 \\ const y: comptime_int = 10;
8784 \\ _ = (x == y);
8785 \\}
8786 \\
8787 \\export fn optionalToOptional() void {
8788 \\ var x: ?i32 = undefined;
8789 \\ var y: ?i32 = undefined;
8790 \\ _ = (x == y);
8791 \\}
8792 \\
8793 \\export fn optionalVector() void {
8794 \\ var x: ?@Vector(10, i32) = undefined;
8795 \\ var y: @Vector(10, i32) = undefined;
8796 \\ _ = (x == y);
8797 \\}
8798 \\
8799 \\export fn invalidChildType() void {
8800 \\ var x: ?[3]i32 = undefined;
8801 \\ var y: [3]i32 = undefined;
8802 \\ _ = (x == y);
8803 \\}
8804 , &[_][]const u8{
8805 ":4:12: error: cannot compare types '?i32' and 'comptime_int'",
8806 ":4:12: note: optional child type 'i32' must be the same as non-optional type 'comptime_int'",
8807 ":10:12: error: cannot compare types '?i32' and '?i32'",
8808 ":10:12: note: optional to optional comparison is only supported for optional pointer types",
8809 ":16:12: error: TODO add comparison of optional vector",
8810 ":22:12: error: cannot compare types '?[3]i32' and '[3]i32'",
8811 ":22:12: note: operator not supported for type '[3]i32'",
8812 });
8813
8814 ctx.objErrStage1("slice cannot have its bytes reinterpreted",
8815 \\export fn foo() void {
8816 \\ const bytes = [1]u8{ 0xfa } ** 16;
8817 \\ var value = @ptrCast(*const []const u8, &bytes).*;
8818 \\ _ = value;
8819 \\}
8820 , &[_][]const u8{
8821 ":3:52: error: slice '[]const u8' cannot have its bytes reinterpreted",
8822 });
8823
8824 ctx.objErrStage1("wasmMemorySize is a compile error in non-Wasm targets",
8825 \\export fn foo() void {
8826 \\ _ = @wasmMemorySize(0);
8827 \\ return;
8828 \\}
8829 , &[_][]const u8{
8830 "tmp.zig:2:9: error: @wasmMemorySize is a wasm32 feature only",
8831 });
8832
8833 ctx.objErrStage1("wasmMemoryGrow is a compile error in non-Wasm targets",
8834 \\export fn foo() void {
8835 \\ _ = @wasmMemoryGrow(0, 1);
8836 \\ return;
8837 \\}
8838 , &[_][]const u8{
8839 "tmp.zig:2:9: error: @wasmMemoryGrow is a wasm32 feature only",
8840 });
8841 ctx.objErrStage1("Issue #5586: Make unary minus for unsigned types a compile error",
8842 \\export fn f1(x: u32) u32 {
8843 \\ const y = -%x;
8844 \\ return -y;
8845 \\}
8846 \\const V = @import("std").meta.Vector;
8847 \\export fn f2(x: V(4, u32)) V(4, u32) {
8848 \\ const y = -%x;
8849 \\ return -y;
8850 \\}
8851 , &[_][]const u8{
8852 "tmp.zig:3:12: error: negation of type 'u32'",
8853 "tmp.zig:8:12: error: negation of type 'u32'",
8854 });
8855
8856 ctx.objErrStage1("Issue #5618: coercion of ?*anyopaque to *anyopaque must fail.",
8857 \\export fn foo() void {
8858 \\ var u: ?*anyopaque = null;
8859 \\ var v: *anyopaque = undefined;
8860 \\ v = u;
8861 \\}
8862 , &[_][]const u8{
8863 "tmp.zig:4:9: error: cannot convert optional to payload type. consider using `.?`, `orelse`, or `if`. expected type '*anyopaque', found '?*anyopaque'",
8864 });
8865
8866 ctx.objErrStage1("Issue #6823: don't allow .* to be followed by **",
8867 \\fn foo() void {
8868 \\ var sequence = "repeat".*** 10;
8869 \\ _ = sequence;
8870 \\}
8871 , &[_][]const u8{
8872 // Ideally this would be column 30 but it's not very important.
8873 "tmp.zig:2:28: error: '.*' cannot be followed by '*'. Are you missing a space?",
8874 });
8875
8876 ctx.objErrStage1("Issue #9165: windows tcp server compilation error",
8877 \\const std = @import("std");
8878 \\const builtin = @import("builtin");
8879 \\pub const io_mode = .evented;
8880 \\pub fn main() !void {
8881 \\ if (builtin.os.tag == .windows) {
8882 \\ _ = try (std.net.StreamServer.init(.{})).accept();
8883 \\ } else {
8884 \\ @compileError("Unsupported OS");
8885 \\ }
8886 \\}
8887 , &[_][]const u8{
8888 "error: Unsupported OS",
8889 });
8890
8891 ctx.objErrStage1("attempt to close over comptime variable from outer scope",
8892 \\fn SimpleList(comptime L: usize) type {
8893 \\ var T = u8;
8894 \\ return struct {
8895 \\ array: [L]T,
8896 \\ };
8897 \\}
8898 , &[_][]const u8{
8899 "tmp.zig:4:19: error: mutable 'T' not accessible from here",
8900 "tmp.zig:2:9: note: declared mutable here",
8901 "tmp.zig:3:12: note: crosses namespace boundary here",
8902 });
8903
8904 ctx.objErrStage1("saturating arithmetic does not allow floats",
8905 \\export fn a() void {
8906 \\ _ = @as(f32, 1.0) +| @as(f32, 1.0);
8907 \\}
8908 , &[_][]const u8{
8909 "error: invalid operands to binary expression: 'f32' and 'f32'",
8910 });
8911
8912 ctx.objErrStage1("saturating shl does not allow negative rhs at comptime",
8913 \\export fn a() void {
8914 \\ _ = @as(i32, 1) <<| @as(i32, -2);
8915 \\}
8916 , &[_][]const u8{
8917 "error: shift by negative value -2",
8918 });
8919
8920 ctx.objErrStage1("saturating shl assign does not allow negative rhs at comptime",
8921 \\export fn a() void {
8922 \\ comptime {
8923 \\ var x = @as(i32, 1);
8924 \\ x <<|= @as(i32, -2);
8925 \\ }
8926 \\}
8927 , &[_][]const u8{
8928 "error: shift by negative value -2",
8929 });
8930
8931 ctx.objErrStage1("undeclared identifier in unanalyzed branch",
8932 \\export fn a() void {
8933 \\ if (false) {
8934 \\ lol_this_doesnt_exist = nonsense;
8935 \\ }
8936 \\}
8937 , &[_][]const u8{
8938 "tmp.zig:3:9: error: use of undeclared identifier 'lol_this_doesnt_exist'",
8939 });
8940}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