| ... | ... | @@ -3,180 +3,42 @@ const builtin = @import("builtin"); |
| 3 | 3 | const TestContext = @import("../src/test.zig").TestContext; |
| 4 | 4 | |
| 5 | 5 | pub fn addCases(ctx: *TestContext) !void { |
| 6 | | { |
| 7 | | var case = ctx.obj("stage2 compile errors", .{}); |
| 6 | var parent_dir = try std.fs.cwd().openDir(std.fs.path.dirname(@src().file).?, .{ .no_follow = true }); |
| 7 | defer parent_dir.close(); |
| 8 | 8 | |
| 9 | | case.addError( |
| 10 | | \\export fn a() usize { |
| 11 | | \\ return @embedFile("/root/foo").len; |
| 12 | | \\} |
| 13 | | , &[_][]const u8{ |
| 14 | | ":2:23: error: embed of file outside package path: '/root/foo'", |
| 15 | | }); |
| 9 | var compile_errors_dir = try parent_dir.openDir("compile_errors", .{ .no_follow = true }); |
| 10 | defer compile_errors_dir.close(); |
| 16 | 11 | |
| 17 | | case.addError( |
| 18 | | \\export fn a() usize { |
| 19 | | \\ return @import("../../above.zig").len; |
| 20 | | \\} |
| 21 | | , &[_][]const u8{ |
| 22 | | ":2:20: error: import of file outside package path: '../../above.zig'", |
| 23 | | }); |
| 12 | { |
| 13 | var stage2_dir = try compile_errors_dir.openDir("stage2", .{ .iterate = true, .no_follow = true }); |
| 14 | defer stage2_dir.close(); |
| 24 | 15 | |
| 25 | | case.addError( |
| 26 | | \\comptime { |
| 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 | | }); |
| 16 | const one_test_case_per_file = false; |
| 17 | try ctx.addErrorCasesFromDir("stage2 compile errors", stage2_dir, .stage2, .Obj, false, one_test_case_per_file); |
| 53 | 18 | } |
| 54 | 19 | |
| 55 | | ctx.objErrStage1("exported enum without explicit integer tag type", |
| 56 | | \\const E = enum { one, two }; |
| 57 | | \\comptime { |
| 58 | | \\ @export(E, .{ .name = "E" }); |
| 59 | | \\} |
| 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 | | }); |
| 20 | { |
| 21 | var stage1_dir = try compile_errors_dir.openDir("stage1", .{ .no_follow = true }); |
| 22 | defer stage1_dir.close(); |
| 23 | { |
| 24 | const one_test_case_per_file = true; |
| 91 | 25 | |
| 92 | | ctx.objErrStage1("pointer arithmetic on pointer-to-array", |
| 93 | | \\export fn foo() void { |
| 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 | | }); |
| 26 | var obj_dir = try stage1_dir.openDir("obj", .{ .iterate = true, .no_follow = true }); |
| 27 | defer obj_dir.close(); |
| 102 | 28 | |
| 103 | | ctx.objErrStage1("pointer attributes checked when coercing pointer to anon literal", |
| 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 | | }); |
| 29 | try ctx.addErrorCasesFromDir("stage1", obj_dir, .stage1, .Obj, false, one_test_case_per_file); |
| 125 | 30 | |
| 126 | | ctx.objErrStage1("@Type() union payload is undefined", |
| 127 | | \\const Foo = @Type(.{ |
| 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 | | }); |
| 31 | var exe_dir = try stage1_dir.openDir("exe", .{ .iterate = true, .no_follow = true }); |
| 32 | defer exe_dir.close(); |
| 134 | 33 | |
| 135 | | ctx.objErrStage1("wrong initializer for union payload of type 'type'", |
| 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 | | }); |
| 34 | try ctx.addErrorCasesFromDir("stage1", exe_dir, .stage1, .Exe, false, one_test_case_per_file); |
| 149 | 35 | |
| 150 | | ctx.objErrStage1("union with too small explicit signed tag type", |
| 151 | | \\const U = union(enum(i2)) { |
| 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 | | }); |
| 36 | var test_dir = try stage1_dir.openDir("test", .{ .iterate = true, .no_follow = true }); |
| 37 | defer test_dir.close(); |
| 164 | 38 | |
| 165 | | ctx.objErrStage1("union with too small explicit unsigned tag type", |
| 166 | | \\const U = union(enum(u2)) { |
| 167 | | \\ A: u8, |
| 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 | | }); |
| 39 | try ctx.addErrorCasesFromDir("stage1", test_dir, .stage1, .Exe, true, one_test_case_per_file); |
| 40 | } |
| 41 | } |
| 180 | 42 | |
| 181 | 43 | { |
| 182 | 44 | const case = ctx.obj("callconv(.Interrupt) on unsupported platform", .{ |
| ... | ... | @@ -272,8493 +134,275 @@ pub fn addCases(ctx: *TestContext) !void { |
| 272 | 134 | }); |
| 273 | 135 | } |
| 274 | 136 | |
| 275 | | ctx.objErrStage1("unreachable executed at comptime", |
| 276 | | \\fn foo(comptime x: i32) i32 { |
| 277 | | \\ comptime { |
| 278 | | \\ if (x >= 0) return -x; |
| 279 | | \\ unreachable; |
| 280 | | \\ } |
| 281 | | \\} |
| 282 | | \\export fn entry() void { |
| 283 | | \\ _ = foo(-42); |
| 284 | | \\} |
| 285 | | , &[_][]const u8{ |
| 286 | | "tmp.zig:4:9: error: reached unreachable code", |
| 287 | | "tmp.zig:8:12: note: called from here", |
| 288 | | }); |
| 289 | | |
| 290 | | ctx.objErrStage1("@Type with Type.Int", |
| 291 | | \\const builtin = @import("std").builtin; |
| 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 | | }); |
| 137 | { |
| 138 | const case = ctx.obj("call with new stack on unsupported target", .{ |
| 139 | .cpu_arch = .wasm32, |
| 140 | .os_tag = .wasi, |
| 141 | .abi = .none, |
| 142 | }); |
| 143 | case.backend = .stage1; |
| 144 | case.addError( |
| 145 | \\var buf: [10]u8 align(16) = undefined; |
| 146 | \\export fn entry() void { |
| 147 | \\ @call(.{.stack = &buf}, foo, .{}); |
| 148 | \\} |
| 149 | \\fn foo() void {} |
| 150 | , &[_][]const u8{ |
| 151 | "tmp.zig:3:5: error: target arch 'wasm32' does not support calling with a new stack", |
| 152 | }); |
| 153 | } |
| 310 | 154 | |
| 311 | | ctx.objErrStage1("array in c exported function", |
| 312 | | \\export fn zig_array(x: [10]u8) void { |
| 313 | | \\ try std.testing.expect(std.mem.eql(u8, &x, "1234567890")); |
| 155 | // Note: One of the error messages here is backwards. It would be nice to fix, but that's not |
| 156 | // going to stop me from merging this branch which fixes a bunch of other stuff. |
| 157 | ctx.objErrStage1("incompatible sentinels", |
| 158 | \\export fn entry1(ptr: [*:255]u8) [*:0]u8 { |
| 159 | \\ return ptr; |
| 314 | 160 | \\} |
| 315 | | \\const std = @import("std"); |
| 316 | | \\export fn zig_return_array() [10]u8 { |
| 317 | | \\ return "1234567890".*; |
| 161 | \\export fn entry2(ptr: [*]u8) [*:0]u8 { |
| 162 | \\ return ptr; |
| 318 | 163 | \\} |
| 319 | | , &[_][]const u8{ |
| 320 | | "tmp.zig:1:24: error: parameter of type '[10]u8' not allowed in function with calling convention 'C'", |
| 321 | | "tmp.zig:5:30: error: return type '[10]u8' not allowed in function with calling convention 'C'", |
| 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); |
| 164 | \\export fn entry3() void { |
| 165 | \\ var array: [2:0]u8 = [_:255]u8{1, 2}; |
| 166 | \\ _ = array; |
| 336 | 167 | \\} |
| 337 | | , &[_][]const u8{ |
| 338 | | "tmp.zig:1:20: error: use of undefined value here causes undefined behavior", |
| 339 | | }); |
| 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; |
| 168 | \\export fn entry4() void { |
| 169 | \\ var array: [2:0]u8 = [_]u8{1, 2}; |
| 170 | \\ _ = array; |
| 349 | 171 | \\} |
| 350 | 172 | , &[_][]const u8{ |
| 351 | | "tmp.zig:3:5: error: extern structs cannot contain fields of type 'E'", |
| 352 | | }); |
| 173 | "tmp.zig:2:12: error: expected type '[*:0]u8', found '[*:255]u8'", |
| 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", |
| 353 | 177 | |
| 354 | | ctx.objErrStage1("@Type for exhaustive enum with non-integer tag type", |
| 355 | | \\const Tag = @Type(.{ |
| 356 | | \\ .Enum = .{ |
| 357 | | \\ .layout = .Auto, |
| 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'", |
| 178 | "tmp.zig:8:35: error: expected type '[2:255]u8', found '[2:0]u8'", |
| 179 | "tmp.zig:8:35: note: destination array requires a terminating '255' sentinel, but source array has a terminating '0' sentinel", |
| 180 | "tmp.zig:12:31: error: expected type '[2:0]u8', found '[2]u8'", |
| 181 | "tmp.zig:12:31: note: destination array requires a terminating '0' sentinel", |
| 369 | 182 | }); |
| 370 | 183 | |
| 371 | | ctx.objErrStage1("extern struct with extern-compatible but inferred integer tag type", |
| 372 | | \\pub const E = enum { |
| 373 | | \\@"0",@"1",@"2",@"3",@"4",@"5",@"6",@"7",@"8",@"9",@"10",@"11",@"12", |
| 374 | | \\@"13",@"14",@"15",@"16",@"17",@"18",@"19",@"20",@"21",@"22",@"23", |
| 375 | | \\@"24",@"25",@"26",@"27",@"28",@"29",@"30",@"31",@"32",@"33",@"34", |
| 376 | | \\@"35",@"36",@"37",@"38",@"39",@"40",@"41",@"42",@"43",@"44",@"45", |
| 377 | | \\@"46",@"47",@"48",@"49",@"50",@"51",@"52",@"53",@"54",@"55",@"56", |
| 378 | | \\@"57",@"58",@"59",@"60",@"61",@"62",@"63",@"64",@"65",@"66",@"67", |
| 379 | | \\@"68",@"69",@"70",@"71",@"72",@"73",@"74",@"75",@"76",@"77",@"78", |
| 380 | | \\@"79",@"80",@"81",@"82",@"83",@"84",@"85",@"86",@"87",@"88",@"89", |
| 381 | | \\@"90",@"91",@"92",@"93",@"94",@"95",@"96",@"97",@"98",@"99",@"100", |
| 382 | | \\@"101",@"102",@"103",@"104",@"105",@"106",@"107",@"108",@"109", |
| 383 | | \\@"110",@"111",@"112",@"113",@"114",@"115",@"116",@"117",@"118", |
| 384 | | \\@"119",@"120",@"121",@"122",@"123",@"124",@"125",@"126",@"127", |
| 385 | | \\@"128",@"129",@"130",@"131",@"132",@"133",@"134",@"135",@"136", |
| 386 | | \\@"137",@"138",@"139",@"140",@"141",@"142",@"143",@"144",@"145", |
| 387 | | \\@"146",@"147",@"148",@"149",@"150",@"151",@"152",@"153",@"154", |
| 388 | | \\@"155",@"156",@"157",@"158",@"159",@"160",@"161",@"162",@"163", |
| 389 | | \\@"164",@"165",@"166",@"167",@"168",@"169",@"170",@"171",@"172", |
| 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 | | }); |
| 184 | { |
| 185 | const case = ctx.obj("variable in inline assembly template cannot be found", .{ |
| 186 | .cpu_arch = .x86_64, |
| 187 | .os_tag = .linux, |
| 188 | .abi = .gnu, |
| 189 | }); |
| 190 | case.backend = .stage1; |
| 191 | case.addError( |
| 192 | \\export fn entry() void { |
| 193 | \\ var sp = asm volatile ( |
| 194 | \\ "mov %[foo], sp" |
| 195 | \\ : [bar] "=r" (-> usize) |
| 196 | \\ ); |
| 197 | \\ _ = sp; |
| 198 | \\} |
| 199 | , &[_][]const u8{ |
| 200 | "tmp.zig:2:14: error: could not find 'foo' in the inputs or outputs", |
| 201 | }); |
| 202 | } |
| 412 | 203 | |
| 413 | | ctx.objErrStage1("@Type for tagged union with extra enum field", |
| 414 | | \\const Tag = @Type(.{ |
| 415 | | \\ .Enum = .{ |
| 416 | | \\ .layout = .Auto, |
| 417 | | \\ .tag_type = u2, |
| 418 | | \\ .fields = &.{ |
| 419 | | \\ .{ .name = "signed", .value = 0 }, |
| 420 | | \\ .{ .name = "unsigned", .value = 1 }, |
| 421 | | \\ .{ .name = "arst", .value = 2 }, |
| 422 | | \\ }, |
| 423 | | \\ .decls = &.{}, |
| 424 | | \\ .is_exhaustive = true, |
| 425 | | \\ }, |
| 426 | | \\}); |
| 427 | | \\const Tagged = @Type(.{ |
| 428 | | \\ .Union = .{ |
| 429 | | \\ .layout = .Auto, |
| 430 | | \\ .tag_type = Tag, |
| 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 | | }); |
| 204 | { |
| 205 | const case = ctx.obj("bad alignment in @asyncCall", .{ |
| 206 | .cpu_arch = .aarch64, |
| 207 | .os_tag = .linux, |
| 208 | .abi = .none, |
| 209 | }); |
| 210 | case.backend = .stage1; |
| 211 | case.addError( |
| 212 | \\export fn entry() void { |
| 213 | \\ var ptr: fn () callconv(.Async) void = func; |
| 214 | \\ var bytes: [64]u8 = undefined; |
| 215 | \\ _ = @asyncCall(&bytes, {}, ptr, .{}); |
| 216 | \\} |
| 217 | \\fn func() callconv(.Async) void {} |
| 218 | , &[_][]const u8{ |
| 219 | "tmp.zig:4:21: error: expected type '[]align(8) u8', found '*[64]u8'", |
| 220 | }); |
| 221 | } |
| 445 | 222 | |
| 446 | | ctx.objErrStage1("field access of opaque type", |
| 447 | | \\const MyType = opaque {}; |
| 448 | | \\ |
| 449 | | \\export fn entry() bool { |
| 450 | | \\ var x: i32 = 1; |
| 451 | | \\ return bar(@ptrCast(*MyType, &x)); |
| 452 | | \\} |
| 453 | | \\ |
| 454 | | \\fn bar(x: *MyType) bool { |
| 455 | | \\ return x.blah; |
| 456 | | \\} |
| 457 | | , &[_][]const u8{ |
| 458 | | "tmp.zig:9:13: error: no member named 'blah' in opaque type 'MyType'", |
| 459 | | }); |
| 223 | if (builtin.os.tag == .linux) { |
| 224 | ctx.testErrStage1("implicit dependency on libc", |
| 225 | \\extern "c" fn exit(u8) void; |
| 226 | \\export fn entry() void { |
| 227 | \\ exit(0); |
| 228 | \\} |
| 229 | , &[_][]const u8{ |
| 230 | "tmp.zig:3:5: error: dependency on libc must be explicitly specified in the build command", |
| 231 | }); |
| 460 | 232 | |
| 461 | | ctx.objErrStage1("opaque type with field", |
| 462 | | \\const Opaque = opaque { foo: i32 }; |
| 463 | | \\export fn entry() void { |
| 464 | | \\ const foo: ?*Opaque = null; |
| 465 | | \\ _ = foo; |
| 466 | | \\} |
| 467 | | , &[_][]const u8{ |
| 468 | | "tmp.zig:1:25: error: opaque types cannot have fields", |
| 469 | | }); |
| 233 | ctx.testErrStage1("libc headers note", |
| 234 | \\const c = @cImport(@cInclude("stdio.h")); |
| 235 | \\export fn entry() void { |
| 236 | \\ _ = c.printf("hello, world!\n"); |
| 237 | \\} |
| 238 | , &[_][]const u8{ |
| 239 | "tmp.zig:1:11: error: C import failed", |
| 240 | "tmp.zig:1:11: note: libc headers not available; compilation does not link against libc", |
| 241 | }); |
| 242 | } |
| 470 | 243 | |
| 471 | | ctx.objErrStage1("@Type(.Fn) with is_generic = true", |
| 472 | | \\const Foo = @Type(.{ |
| 473 | | \\ .Fn = .{ |
| 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 | | }); |
| 244 | { |
| 245 | const case = ctx.obj("wrong same named struct", .{}); |
| 246 | case.backend = .stage1; |
| 486 | 247 | |
| 487 | | ctx.objErrStage1("@Type(.Fn) with is_var_args = true and non-C callconv", |
| 488 | | \\const Foo = @Type(.{ |
| 489 | | \\ .Fn = .{ |
| 490 | | \\ .calling_convention = .Unspecified, |
| 491 | | \\ .alignment = 0, |
| 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 | | }); |
| 248 | case.addSourceFile("a.zig", |
| 249 | \\pub const Foo = struct { |
| 250 | \\ x: i32, |
| 251 | \\}; |
| 252 | ); |
| 502 | 253 | |
| 503 | | ctx.objErrStage1("@Type(.Fn) with return_type = null", |
| 504 | | \\const Foo = @Type(.{ |
| 505 | | \\ .Fn = .{ |
| 506 | | \\ .calling_convention = .Unspecified, |
| 507 | | \\ .alignment = 0, |
| 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 | | }); |
| 254 | case.addSourceFile("b.zig", |
| 255 | \\pub const Foo = struct { |
| 256 | \\ z: f64, |
| 257 | \\}; |
| 258 | ); |
| 518 | 259 | |
| 519 | | ctx.objErrStage1("@Type for union with opaque field", |
| 520 | | \\const Untagged = @Type(.{ |
| 521 | | \\ .Union = .{ |
| 522 | | \\ .layout = .Auto, |
| 523 | | \\ .tag_type = null, |
| 524 | | \\ .fields = &.{ |
| 525 | | \\ .{ .name = "foo", .field_type = opaque {}, .alignment = 1 }, |
| 526 | | \\ }, |
| 527 | | \\ .decls = &.{}, |
| 528 | | \\ }, |
| 529 | | \\}); |
| 530 | | \\export fn entry() void { |
| 531 | | \\ _ = Untagged{}; |
| 532 | | \\} |
| 533 | | , &[_][]const u8{ |
| 534 | | "tmp.zig:1:25: error: opaque types have unknown size and therefore cannot be directly embedded in unions", |
| 535 | | }); |
| 260 | case.addError( |
| 261 | \\const a = @import("a.zig"); |
| 262 | \\const b = @import("b.zig"); |
| 263 | \\ |
| 264 | \\export fn entry() void { |
| 265 | \\ var a1: a.Foo = undefined; |
| 266 | \\ bar(&a1); |
| 267 | \\} |
| 268 | \\ |
| 269 | \\fn bar(x: *b.Foo) void {_ = x;} |
| 270 | , &[_][]const u8{ |
| 271 | "tmp.zig:6:10: error: expected type '*b.Foo', found '*a.Foo'", |
| 272 | "tmp.zig:6:10: note: pointer type child 'a.Foo' cannot cast into pointer type child 'b.Foo'", |
| 273 | "a.zig:1:17: note: a.Foo declared here", |
| 274 | "b.zig:1:17: note: b.Foo declared here", |
| 275 | }); |
| 276 | } |
| 536 | 277 | |
| 537 | | ctx.objErrStage1("slice sentinel mismatch", |
| 538 | | \\export fn entry() void { |
| 539 | | \\ const x = @import("std").meta.Vector(3, f32){ 25, 75, 5, 0 }; |
| 540 | | \\ _ = x; |
| 541 | | \\} |
| 542 | | , &[_][]const u8{ |
| 543 | | "tmp.zig:2:62: error: index 3 outside vector of size 3", |
| 544 | | }); |
| 278 | { |
| 279 | const case = ctx.obj("multiple files with private function error", .{}); |
| 280 | case.backend = .stage1; |
| 545 | 281 | |
| 546 | | ctx.objErrStage1("slice sentinel mismatch", |
| 547 | | \\export fn entry() void { |
| 548 | | \\ const y: [:1]const u8 = &[_:2]u8{ 1, 2 }; |
| 549 | | \\ _ = y; |
| 550 | | \\} |
| 551 | | , &[_][]const u8{ |
| 552 | | "tmp.zig:2:37: error: expected type '[:1]const u8', found '*const [2:2]u8'", |
| 553 | | }); |
| 282 | case.addSourceFile("foo.zig", |
| 283 | \\fn privateFunction() void { } |
| 284 | ); |
| 554 | 285 | |
| 555 | | ctx.objErrStage1("@Type for union with zero fields", |
| 556 | | \\const Untagged = @Type(.{ |
| 557 | | \\ .Union = .{ |
| 558 | | \\ .layout = .Auto, |
| 559 | | \\ .tag_type = null, |
| 560 | | \\ .fields = &.{}, |
| 561 | | \\ .decls = &.{}, |
| 562 | | \\ }, |
| 563 | | \\}); |
| 564 | | \\export fn entry() void { |
| 565 | | \\ _ = Untagged{}; |
| 566 | | \\} |
| 567 | | , &[_][]const u8{ |
| 568 | | "tmp.zig:1:25: error: unions must have 1 or more fields", |
| 569 | | }); |
| 286 | case.addError( |
| 287 | \\const foo = @import("foo.zig",); |
| 288 | \\ |
| 289 | \\export fn callPrivFunction() void { |
| 290 | \\ foo.privateFunction(); |
| 291 | \\} |
| 292 | , &[_][]const u8{ |
| 293 | "tmp.zig:4:8: error: 'privateFunction' is private", |
| 294 | "foo.zig:1:1: note: declared here", |
| 295 | }); |
| 296 | } |
| 570 | 297 | |
| 571 | | ctx.objErrStage1("@Type for exhaustive enum with zero fields", |
| 572 | | \\const Tag = @Type(.{ |
| 573 | | \\ .Enum = .{ |
| 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 | | }); |
| 298 | { |
| 299 | const case = ctx.obj("multiple files with private member instance function (canonical invocation) error", .{}); |
| 300 | case.backend = .stage1; |
| 587 | 301 | |
| 588 | | ctx.objErrStage1("@Type for tagged union with extra union field", |
| 589 | | \\const Tag = @Type(.{ |
| 590 | | \\ .Enum = .{ |
| 591 | | \\ .layout = .Auto, |
| 592 | | \\ .tag_type = u1, |
| 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 | | }); |
| 302 | case.addSourceFile("foo.zig", |
| 303 | \\pub const Foo = struct { |
| 304 | \\ fn privateFunction(self: *Foo) void { _ = self; } |
| 305 | \\}; |
| 306 | ); |
| 621 | 307 | |
| 622 | | ctx.objErrStage1("@Type with undefined", |
| 623 | | \\comptime { |
| 624 | | \\ _ = @Type(.{ .Array = .{ .len = 0, .child = u8, .sentinel = undefined } }); |
| 625 | | \\} |
| 626 | | \\comptime { |
| 627 | | \\ _ = @Type(.{ |
| 628 | | \\ .Struct = .{ |
| 629 | | \\ .fields = undefined, |
| 630 | | \\ .decls = undefined, |
| 631 | | \\ .is_tuple = false, |
| 632 | | \\ .layout = .Auto, |
| 633 | | \\ }, |
| 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 | | }); |
| 308 | case.addError( |
| 309 | \\const Foo = @import("foo.zig",).Foo; |
| 310 | \\ |
| 311 | \\export fn callPrivFunction() void { |
| 312 | \\ var foo = Foo{}; |
| 313 | \\ Foo.privateFunction(foo); |
| 314 | \\} |
| 315 | , &[_][]const u8{ |
| 316 | "tmp.zig:5:8: error: 'privateFunction' is private", |
| 317 | "foo.zig:2:5: note: declared here", |
| 318 | }); |
| 319 | } |
| 8369 | 320 | |
| 8370 | | ctx.objErrStage1("issue #3818: bitcast from parray/slice to u16", |
| 8371 | | \\export fn foo1() void { |
| 8372 | | \\ var bytes = [_]u8{1, 2}; |
| 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 | | }); |
| 321 | { |
| 322 | const case = ctx.obj("multiple files with private member instance function error", .{}); |
| 323 | case.backend = .stage1; |
| 8385 | 324 | |
| 8386 | | // issue #7810 |
| 8387 | | ctx.objErrStage1("comptime slice-len increment beyond bounds", |
| 8388 | | \\export fn foo_slice_len_increment_beyond_bounds() void { |
| 8389 | | \\ comptime { |
| 8390 | | \\ var buf_storage: [8]u8 = undefined; |
| 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 | | }); |
| 325 | case.addSourceFile("foo.zig", |
| 326 | \\pub const Foo = struct { |
| 327 | \\ fn privateFunction(self: *Foo) void { _ = self; } |
| 328 | \\}; |
| 329 | ); |
| 8399 | 330 | |
| 8400 | | ctx.objErrStage1("comptime slice-sentinel is out of bounds (unterminated)", |
| 8401 | | \\export fn foo_array() void { |
| 8402 | | \\ comptime { |
| 8403 | | \\ var target = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; |
| 8404 | | \\ const slice = target[0..14 :0]; |
| 8405 | | \\ _ = slice; |
| 8406 | | \\ } |
| 8407 | | \\} |
| 8408 | | \\export fn foo_ptr_array() void { |
| 8409 | | \\ comptime { |
| 8410 | | \\ var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; |
| 8411 | | \\ var target = &buf; |
| 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 | | }); |
| 331 | case.addError( |
| 332 | \\const Foo = @import("foo.zig",).Foo; |
| 333 | \\ |
| 334 | \\export fn callPrivFunction() void { |
| 335 | \\ var foo = Foo{}; |
| 336 | \\ foo.privateFunction(); |
| 337 | \\} |
| 338 | , &[_][]const u8{ |
| 339 | "tmp.zig:5:8: error: 'privateFunction' is private", |
| 340 | "foo.zig:2:5: note: declared here", |
| 341 | }); |
| 342 | } |
| 8465 | 343 | |
| 8466 | | ctx.objErrStage1("comptime slice-sentinel is out of bounds (terminated)", |
| 8467 | | \\export fn foo_array() void { |
| 8468 | | \\ comptime { |
| 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 | | }); |
| 344 | { |
| 345 | const case = ctx.obj("export collision", .{}); |
| 346 | case.backend = .stage1; |
| 8531 | 347 | |
| 8532 | | ctx.objErrStage1("comptime slice-sentinel does not match memory at target index (unterminated)", |
| 8533 | | \\export fn foo_array() void { |
| 8534 | | \\ comptime { |
| 8535 | | \\ var target = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; |
| 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 | | }); |
| 348 | case.addSourceFile("foo.zig", |
| 349 | \\export fn bar() void {} |
| 350 | \\pub const baz = 1234; |
| 351 | ); |
| 8597 | 352 | |
| 8598 | | ctx.objErrStage1("comptime slice-sentinel does not match memory at target index (terminated)", |
| 8599 | | \\export fn foo_array() void { |
| 8600 | | \\ comptime { |
| 8601 | | \\ var target = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; |
| 8602 | | \\ const slice = target[0..3 :0]; |
| 8603 | | \\ _ = slice; |
| 8604 | | \\ } |
| 8605 | | \\} |
| 8606 | | \\export fn foo_ptr_array() void { |
| 8607 | | \\ comptime { |
| 8608 | | \\ var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; |
| 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 | | }); |
| 353 | case.addError( |
| 354 | \\const foo = @import("foo.zig",); |
| 355 | \\ |
| 356 | \\export fn bar() usize { |
| 357 | \\ return foo.baz; |
| 358 | \\} |
| 359 | , &[_][]const u8{ |
| 360 | "foo.zig:1:1: error: exported symbol collision: 'bar'", |
| 361 | "tmp.zig:3:1: note: other symbol here", |
| 362 | }); |
| 363 | } |
| 8663 | 364 | |
| 8664 | | ctx.objErrStage1("comptime slice-sentinel does not match target-sentinel", |
| 8665 | | \\export fn foo_array() void { |
| 8666 | | \\ comptime { |
| 8667 | | \\ var target = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; |
| 8668 | | \\ const slice = target[0..14 :255]; |
| 8669 | | \\ _ = slice; |
| 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", |
| 365 | ctx.objErrStage1("non-printable invalid character", "\xff\xfe" ++ |
| 366 | "fn foo() bool {\r\n" ++ |
| 367 | " return true;\r\n" ++ |
| 368 | "}\r\n", &[_][]const u8{ |
| 369 | "tmp.zig:1:1: error: expected test, comptime, var decl, or container field, found 'invalid bytes'", |
| 370 | "tmp.zig:1:1: note: invalid byte: '\\xff'", |
| 8728 | 371 | }); |
| 8729 | 372 | |
| 8730 | | ctx.objErrStage1("issue #4207: coerce from non-terminated-slice to terminated-pointer", |
| 8731 | | \\export fn foo() [*:0]const u8 { |
| 8732 | | \\ var buffer: [64]u8 = undefined; |
| 8733 | | \\ return buffer[0..]; |
| 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", |
| 373 | ctx.objErrStage1("non-printable invalid character with escape alternative", "fn foo() bool {\n" ++ |
| 374 | "\treturn true;\n" ++ |
| 375 | "}\n", &[_][]const u8{ |
| 376 | "tmp.zig:2:1: error: invalid character: '\\t'", |
| 8738 | 377 | }); |
| 8739 | 378 | |
| 8740 | | ctx.objErrStage1("issue #5221: invalid struct init type referenced by @typeInfo and passed into function", |
| 8741 | | \\fn ignore(comptime param: anytype) void {_ = param;} |
| 8742 | | \\ |
| 8743 | | \\export fn foo() void { |
| 8744 | | \\ const MyStruct = struct { |
| 8745 | | \\ wrong_type: []u8 = "foo", |
| 8746 | | \\ }; |
| 8747 | | \\ |
| 8748 | | \\ comptime ignore(@typeInfo(MyStruct).Struct.fields[0]); |
| 8749 | | \\} |
| 8750 | | , &[_][]const u8{ |
| 8751 | | ":5:28: error: cannot cast pointer to array literal to slice type '[]u8'", |
| 8752 | | ":5:28: note: cast discards const qualifier", |
| 8753 | | }); |
| 379 | // TODO test this in stage2, but we won't even try in stage1 |
| 380 | //ctx.objErrStage1("inline fn calls itself indirectly", |
| 381 | // \\export fn foo() void { |
| 382 | // \\ bar(); |
| 383 | // \\} |
| 384 | // \\fn bar() callconv(.Inline) void { |
| 385 | // \\ baz(); |
| 386 | // \\ quux(); |
| 387 | // \\} |
| 388 | // \\fn baz() callconv(.Inline) void { |
| 389 | // \\ bar(); |
| 390 | // \\ quux(); |
| 391 | // \\} |
| 392 | // \\extern fn quux() void; |
| 393 | //, &[_][]const u8{ |
| 394 | // "tmp.zig:4:1: error: unable to inline function", |
| 395 | //}); |
| 8754 | 396 | |
| 8755 | | ctx.objErrStage1("integer underflow error", |
| 8756 | | \\export fn entry() void { |
| 8757 | | \\ _ = @intToPtr(*anyopaque, ~@as(usize, @import("std").math.maxInt(usize)) - 1); |
| 8758 | | \\} |
| 8759 | | , &[_][]const u8{ |
| 8760 | | ":2:78: error: operation caused overflow", |
| 8761 | | }); |
| 397 | //ctx.objErrStage1("save reference to inline function", |
| 398 | // \\export fn foo() void { |
| 399 | // \\ quux(@ptrToInt(bar)); |
| 400 | // \\} |
| 401 | // \\fn bar() callconv(.Inline) void { } |
| 402 | // \\extern fn quux(usize) void; |
| 403 | //, &[_][]const u8{ |
| 404 | // "tmp.zig:4:1: error: unable to inline function", |
| 405 | //}); |
| 8762 | 406 | |
| 8763 | 407 | { |
| 8764 | 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 | 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 | } |