| ... | ... | @@ -1,53 +1,58 @@ |
| 1 | | const tests = @import("tests.zig"); |
| 2 | 1 | const std = @import("std"); |
| 2 | const TestContext = @import("../src/test.zig").TestContext; |
| 3 | 3 | |
| 4 | | pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5 | | cases.add("std.fmt error for unused arguments", |
| 4 | pub fn addCases(ctx: *TestContext) !void { |
| 5 | ctx.exeErrStage1("std.fmt error for unused arguments", |
| 6 | 6 | \\pub fn main() !void { |
| 7 | 7 | \\ @import("std").debug.print("{d} {d} {d} {d} {d}", .{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15}); |
| 8 | 8 | \\} |
| 9 | 9 | , &.{ |
| 10 | | \\error: 10 unused arguments in "{d} {d} {d} {d} {d}" |
| 10 | "?:?:?: error: 10 unused arguments in '{d} {d} {d} {d} {d}'", |
| 11 | 11 | }); |
| 12 | 12 | |
| 13 | | cases.add("lazy pointer with undefined element type", |
| 13 | ctx.objErrStage1("lazy pointer with undefined element type", |
| 14 | 14 | \\export fn foo() void { |
| 15 | 15 | \\ comptime var T: type = undefined; |
| 16 | 16 | \\ const S = struct { x: *T }; |
| 17 | 17 | \\ const I = @typeInfo(S); |
| 18 | \\ _ = I; |
| 18 | 19 | \\} |
| 19 | 20 | , &[_][]const u8{ |
| 20 | | "tmp.zig:3:28: error: use of undefined value here causes undefined behavior", |
| 21 | ":3:28: error: use of undefined value here causes undefined behavior", |
| 21 | 22 | }); |
| 22 | 23 | |
| 23 | | cases.add("pointer arithmetic on pointer-to-array", |
| 24 | ctx.objErrStage1("pointer arithmetic on pointer-to-array", |
| 24 | 25 | \\export fn foo() void { |
| 25 | 26 | \\ var x: [10]u8 = undefined; |
| 26 | 27 | \\ var y = &x; |
| 27 | 28 | \\ var z = y + 1; |
| 29 | \\ _ = z; |
| 28 | 30 | \\} |
| 29 | 31 | , &[_][]const u8{ |
| 30 | 32 | "tmp.zig:4:17: error: integer value 1 cannot be coerced to type '*[10]u8'", |
| 31 | 33 | }); |
| 32 | 34 | |
| 33 | | cases.add("pointer attributes checked when coercing pointer to anon literal", |
| 35 | ctx.objErrStage1("pointer attributes checked when coercing pointer to anon literal", |
| 34 | 36 | \\comptime { |
| 35 | 37 | \\ const c: [][]const u8 = &.{"hello", "world" }; |
| 38 | \\ _ = c; |
| 36 | 39 | \\} |
| 37 | 40 | \\comptime { |
| 38 | 41 | \\ const c: *[2][]const u8 = &.{"hello", "world" }; |
| 42 | \\ _ = c; |
| 39 | 43 | \\} |
| 40 | 44 | \\const S = struct {a: u8 = 1, b: u32 = 2}; |
| 41 | 45 | \\comptime { |
| 42 | 46 | \\ const c: *S = &.{}; |
| 47 | \\ _ = c; |
| 43 | 48 | \\} |
| 44 | 49 | , &[_][]const u8{ |
| 45 | 50 | "tmp.zig:2:31: error: expected type '[][]const u8', found '*const struct:2:31'", |
| 46 | | "tmp.zig:5:33: error: expected type '*[2][]const u8', found '*const struct:5:33'", |
| 47 | | "tmp.zig:9:21: error: expected type '*S', found '*const struct:9:21'", |
| 51 | "tmp.zig:6:33: error: expected type '*[2][]const u8', found '*const struct:6:33'", |
| 52 | "tmp.zig:11:21: error: expected type '*S', found '*const struct:11:21'", |
| 48 | 53 | }); |
| 49 | 54 | |
| 50 | | cases.add("@Type() union payload is undefined", |
| 55 | ctx.objErrStage1("@Type() union payload is undefined", |
| 51 | 56 | \\const Foo = @Type(@import("std").builtin.TypeInfo{ |
| 52 | 57 | \\ .Struct = undefined, |
| 53 | 58 | \\}); |
| ... | ... | @@ -56,7 +61,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 56 | 61 | "tmp.zig:1:50: error: use of undefined value here causes undefined behavior", |
| 57 | 62 | }); |
| 58 | 63 | |
| 59 | | cases.add("wrong initializer for union payload of type 'type'", |
| 64 | ctx.objErrStage1("wrong initializer for union payload of type 'type'", |
| 60 | 65 | \\const U = union(enum) { |
| 61 | 66 | \\ A: type, |
| 62 | 67 | \\}; |
| ... | ... | @@ -71,7 +76,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 71 | 76 | "tmp.zig:9:8: error: use of undefined value here causes undefined behavior", |
| 72 | 77 | }); |
| 73 | 78 | |
| 74 | | cases.add("union with too small explicit signed tag type", |
| 79 | ctx.objErrStage1("union with too small explicit signed tag type", |
| 75 | 80 | \\const U = union(enum(i2)) { |
| 76 | 81 | \\ A: u8, |
| 77 | 82 | \\ B: u8, |
| ... | ... | @@ -86,7 +91,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 86 | 91 | "tmp.zig:1:22: note: type i2 cannot fit values in range 0...3", |
| 87 | 92 | }); |
| 88 | 93 | |
| 89 | | cases.add("union with too small explicit unsigned tag type", |
| 94 | ctx.objErrStage1("union with too small explicit unsigned tag type", |
| 90 | 95 | \\const U = union(enum(u2)) { |
| 91 | 96 | \\ A: u8, |
| 92 | 97 | \\ B: u8, |
| ... | ... | @@ -102,56 +107,60 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 102 | 107 | "tmp.zig:1:22: note: type u2 cannot fit values in range 0...4", |
| 103 | 108 | }); |
| 104 | 109 | |
| 105 | | cases.addCase(x: { |
| 106 | | var tc = cases.create("callconv(.Interrupt) on unsupported platform", |
| 110 | { |
| 111 | const case = ctx.obj("callconv(.Interrupt) on unsupported platform", .{ |
| 112 | .cpu_arch = .aarch64, |
| 113 | .os_tag = .linux, |
| 114 | .abi = .none, |
| 115 | }); |
| 116 | case.backend = .stage1; |
| 117 | case.addError( |
| 107 | 118 | \\export fn entry() callconv(.Interrupt) void {} |
| 108 | 119 | , &[_][]const u8{ |
| 109 | 120 | "tmp.zig:1:28: error: callconv 'Interrupt' is only available on x86, x86_64, AVR, and MSP430, not aarch64", |
| 110 | 121 | }); |
| 111 | | tc.target = std.zig.CrossTarget{ |
| 112 | | .cpu_arch = .aarch64, |
| 122 | } |
| 123 | { |
| 124 | var case = ctx.obj("callconv(.Signal) on unsupported platform", .{ |
| 125 | .cpu_arch = .x86_64, |
| 113 | 126 | .os_tag = .linux, |
| 114 | 127 | .abi = .none, |
| 115 | | }; |
| 116 | | break :x tc; |
| 117 | | }); |
| 118 | | |
| 119 | | cases.addCase(x: { |
| 120 | | var tc = cases.create("callconv(.Signal) on unsupported platform", |
| 128 | }); |
| 129 | case.backend = .stage1; |
| 130 | case.addError( |
| 121 | 131 | \\export fn entry() callconv(.Signal) void {} |
| 122 | 132 | , &[_][]const u8{ |
| 123 | 133 | "tmp.zig:1:28: error: callconv 'Signal' is only available on AVR, not x86_64", |
| 124 | 134 | }); |
| 125 | | tc.target = std.zig.CrossTarget{ |
| 135 | } |
| 136 | { |
| 137 | const case = ctx.obj("callconv(.Stdcall, .Fastcall, .Thiscall) on unsupported platform", .{ |
| 126 | 138 | .cpu_arch = .x86_64, |
| 127 | 139 | .os_tag = .linux, |
| 128 | 140 | .abi = .none, |
| 129 | | }; |
| 130 | | break :x tc; |
| 131 | | }); |
| 132 | | cases.addCase(x: { |
| 133 | | var tc = cases.create("callconv(.Stdcall, .Fastcall, .Thiscall) on unsupported platform", |
| 141 | }); |
| 142 | case.backend = .stage1; |
| 143 | case.addError( |
| 134 | 144 | \\const F1 = fn () callconv(.Stdcall) void; |
| 135 | 145 | \\const F2 = fn () callconv(.Fastcall) void; |
| 136 | 146 | \\const F3 = fn () callconv(.Thiscall) void; |
| 137 | | \\export fn entry1() void { var a: F1 = undefined; } |
| 138 | | \\export fn entry2() void { var a: F2 = undefined; } |
| 139 | | \\export fn entry3() void { var a: F3 = undefined; } |
| 147 | \\export fn entry1() void { var a: F1 = undefined; _ = a; } |
| 148 | \\export fn entry2() void { var a: F2 = undefined; _ = a; } |
| 149 | \\export fn entry3() void { var a: F3 = undefined; _ = a; } |
| 140 | 150 | , &[_][]const u8{ |
| 141 | 151 | "tmp.zig:1:27: error: callconv 'Stdcall' is only available on x86, not x86_64", |
| 142 | 152 | "tmp.zig:2:27: error: callconv 'Fastcall' is only available on x86, not x86_64", |
| 143 | 153 | "tmp.zig:3:27: error: callconv 'Thiscall' is only available on x86, not x86_64", |
| 144 | 154 | }); |
| 145 | | tc.target = std.zig.CrossTarget{ |
| 155 | } |
| 156 | { |
| 157 | const case = ctx.obj("callconv(.Stdcall, .Fastcall, .Thiscall) on unsupported platform", .{ |
| 146 | 158 | .cpu_arch = .x86_64, |
| 147 | 159 | .os_tag = .linux, |
| 148 | 160 | .abi = .none, |
| 149 | | }; |
| 150 | | break :x tc; |
| 151 | | }); |
| 152 | | |
| 153 | | cases.addCase(x: { |
| 154 | | var tc = cases.create("callconv(.Stdcall, .Fastcall, .Thiscall) on unsupported platform", |
| 161 | }); |
| 162 | case.backend = .stage1; |
| 163 | case.addError( |
| 155 | 164 | \\export fn entry1() callconv(.Stdcall) void {} |
| 156 | 165 | \\export fn entry2() callconv(.Fastcall) void {} |
| 157 | 166 | \\export fn entry3() callconv(.Thiscall) void {} |
| ... | ... | @@ -160,30 +169,28 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 160 | 169 | "tmp.zig:2:29: error: callconv 'Fastcall' is only available on x86, not x86_64", |
| 161 | 170 | "tmp.zig:3:29: error: callconv 'Thiscall' is only available on x86, not x86_64", |
| 162 | 171 | }); |
| 163 | | tc.target = std.zig.CrossTarget{ |
| 172 | } |
| 173 | { |
| 174 | const case = ctx.obj("callconv(.Vectorcall) on unsupported platform", .{ |
| 164 | 175 | .cpu_arch = .x86_64, |
| 165 | 176 | .os_tag = .linux, |
| 166 | 177 | .abi = .none, |
| 167 | | }; |
| 168 | | break :x tc; |
| 169 | | }); |
| 170 | | |
| 171 | | cases.addCase(x: { |
| 172 | | var tc = cases.create("callconv(.Vectorcall) on unsupported platform", |
| 178 | }); |
| 179 | case.backend = .stage1; |
| 180 | case.addError( |
| 173 | 181 | \\export fn entry() callconv(.Vectorcall) void {} |
| 174 | 182 | , &[_][]const u8{ |
| 175 | 183 | "tmp.zig:1:28: error: callconv 'Vectorcall' is only available on x86 and AArch64, not x86_64", |
| 176 | 184 | }); |
| 177 | | tc.target = std.zig.CrossTarget{ |
| 185 | } |
| 186 | { |
| 187 | const case = ctx.obj("callconv(.APCS, .AAPCS, .AAPCSVFP) on unsupported platform", .{ |
| 178 | 188 | .cpu_arch = .x86_64, |
| 179 | 189 | .os_tag = .linux, |
| 180 | 190 | .abi = .none, |
| 181 | | }; |
| 182 | | break :x tc; |
| 183 | | }); |
| 184 | | |
| 185 | | cases.addCase(x: { |
| 186 | | var tc = cases.create("callconv(.APCS, .AAPCS, .AAPCSVFP) on unsupported platform", |
| 191 | }); |
| 192 | case.backend = .stage1; |
| 193 | case.addError( |
| 187 | 194 | \\export fn entry1() callconv(.APCS) void {} |
| 188 | 195 | \\export fn entry2() callconv(.AAPCS) void {} |
| 189 | 196 | \\export fn entry3() callconv(.AAPCSVFP) void {} |
| ... | ... | @@ -192,15 +199,9 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 192 | 199 | "tmp.zig:2:29: error: callconv 'AAPCS' is only available on ARM, not x86_64", |
| 193 | 200 | "tmp.zig:3:29: error: callconv 'AAPCSVFP' is only available on ARM, not x86_64", |
| 194 | 201 | }); |
| 195 | | tc.target = std.zig.CrossTarget{ |
| 196 | | .cpu_arch = .x86_64, |
| 197 | | .os_tag = .linux, |
| 198 | | .abi = .none, |
| 199 | | }; |
| 200 | | break :x tc; |
| 201 | | }); |
| 202 | } |
| 202 | 203 | |
| 203 | | cases.add("unreachable executed at comptime", |
| 204 | ctx.objErrStage1("unreachable executed at comptime", |
| 204 | 205 | \\fn foo(comptime x: i32) i32 { |
| 205 | 206 | \\ comptime { |
| 206 | 207 | \\ if (x >= 0) return -x; |
| ... | ... | @@ -215,7 +216,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 215 | 216 | "tmp.zig:8:12: note: called from here", |
| 216 | 217 | }); |
| 217 | 218 | |
| 218 | | cases.add("@Type with TypeInfo.Int", |
| 219 | ctx.objErrStage1("@Type with TypeInfo.Int", |
| 219 | 220 | \\const builtin = @import("std").builtin; |
| 220 | 221 | \\export fn entry() void { |
| 221 | 222 | \\ _ = @Type(builtin.TypeInfo.Int { |
| ... | ... | @@ -227,7 +228,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 227 | 228 | "tmp.zig:3:36: error: expected type 'std.builtin.TypeInfo', found 'std.builtin.Int'", |
| 228 | 229 | }); |
| 229 | 230 | |
| 230 | | cases.add("indexing a undefined slice at comptime", |
| 231 | ctx.objErrStage1("indexing a undefined slice at comptime", |
| 231 | 232 | \\comptime { |
| 232 | 233 | \\ var slice: []u8 = undefined; |
| 233 | 234 | \\ slice[0] = 2; |
| ... | ... | @@ -236,7 +237,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 236 | 237 | "tmp.zig:3:10: error: index 0 outside slice of size 0", |
| 237 | 238 | }); |
| 238 | 239 | |
| 239 | | cases.add("array in c exported function", |
| 240 | ctx.objErrStage1("array in c exported function", |
| 240 | 241 | \\export fn zig_array(x: [10]u8) void { |
| 241 | 242 | \\try expect(std.mem.eql(u8, &x, "1234567890")); |
| 242 | 243 | \\} |
| ... | ... | @@ -249,7 +250,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 249 | 250 | "tmp.zig:5:30: error: return type '[10]u8' not allowed in function with calling convention 'C'", |
| 250 | 251 | }); |
| 251 | 252 | |
| 252 | | cases.add("@Type for exhaustive enum with undefined tag type", |
| 253 | ctx.objErrStage1("@Type for exhaustive enum with undefined tag type", |
| 253 | 254 | \\const TypeInfo = @import("std").builtin.TypeInfo; |
| 254 | 255 | \\const Tag = @Type(.{ |
| 255 | 256 | \\ .Enum = .{ |
| ... | ... | @@ -267,19 +268,20 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 267 | 268 | "tmp.zig:2:20: error: use of undefined value here causes undefined behavior", |
| 268 | 269 | }); |
| 269 | 270 | |
| 270 | | cases.add("extern struct with non-extern-compatible integer tag type", |
| 271 | ctx.objErrStage1("extern struct with non-extern-compatible integer tag type", |
| 271 | 272 | \\pub const E = enum(u31) { A, B, C }; |
| 272 | 273 | \\pub const S = extern struct { |
| 273 | 274 | \\ e: E, |
| 274 | 275 | \\}; |
| 275 | 276 | \\export fn entry() void { |
| 276 | 277 | \\ const s: S = undefined; |
| 278 | \\ _ = s; |
| 277 | 279 | \\} |
| 278 | 280 | , &[_][]const u8{ |
| 279 | 281 | "tmp.zig:3:5: error: extern structs cannot contain fields of type 'E'", |
| 280 | 282 | }); |
| 281 | 283 | |
| 282 | | cases.add("@Type for exhaustive enum with non-integer tag type", |
| 284 | ctx.objErrStage1("@Type for exhaustive enum with non-integer tag type", |
| 283 | 285 | \\const TypeInfo = @import("std").builtin.TypeInfo; |
| 284 | 286 | \\const Tag = @Type(.{ |
| 285 | 287 | \\ .Enum = .{ |
| ... | ... | @@ -297,7 +299,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 297 | 299 | "tmp.zig:2:20: error: TypeInfo.Enum.tag_type must be an integer type, not 'bool'", |
| 298 | 300 | }); |
| 299 | 301 | |
| 300 | | cases.add("extern struct with extern-compatible but inferred integer tag type", |
| 302 | ctx.objErrStage1("extern struct with extern-compatible but inferred integer tag type", |
| 301 | 303 | \\pub const E = enum { |
| 302 | 304 | \\@"0",@"1",@"2",@"3",@"4",@"5",@"6",@"7",@"8",@"9",@"10",@"11",@"12", |
| 303 | 305 | \\@"13",@"14",@"15",@"16",@"17",@"18",@"19",@"20",@"21",@"22",@"23", |
| ... | ... | @@ -333,12 +335,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 333 | 335 | \\export fn entry() void { |
| 334 | 336 | \\ if (@typeInfo(E).Enum.tag_type != u8) @compileError("did not infer u8 tag type"); |
| 335 | 337 | \\ const s: S = undefined; |
| 338 | \\ _ = s; |
| 336 | 339 | \\} |
| 337 | 340 | , &[_][]const u8{ |
| 338 | 341 | "tmp.zig:31:5: error: extern structs cannot contain fields of type 'E'", |
| 339 | 342 | }); |
| 340 | 343 | |
| 341 | | cases.add("@Type for tagged union with extra enum field", |
| 344 | ctx.objErrStage1("@Type for tagged union with extra enum field", |
| 342 | 345 | \\const TypeInfo = @import("std").builtin.TypeInfo; |
| 343 | 346 | \\const Tag = @Type(.{ |
| 344 | 347 | \\ .Enum = .{ |
| ... | ... | @@ -373,7 +376,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 373 | 376 | "tmp.zig:27:24: note: referenced here", |
| 374 | 377 | }); |
| 375 | 378 | |
| 376 | | cases.add("field access of opaque type", |
| 379 | ctx.objErrStage1("field access of opaque type", |
| 377 | 380 | \\const MyType = opaque {}; |
| 378 | 381 | \\ |
| 379 | 382 | \\export fn entry() bool { |
| ... | ... | @@ -388,16 +391,17 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 388 | 391 | "tmp.zig:9:13: error: no member named 'blah' in opaque type 'MyType'", |
| 389 | 392 | }); |
| 390 | 393 | |
| 391 | | cases.add("opaque type with field", |
| 394 | ctx.objErrStage1("opaque type with field", |
| 392 | 395 | \\const Opaque = opaque { foo: i32 }; |
| 393 | 396 | \\export fn entry() void { |
| 394 | 397 | \\ const foo: ?*Opaque = null; |
| 398 | \\ _ = foo; |
| 395 | 399 | \\} |
| 396 | 400 | , &[_][]const u8{ |
| 397 | 401 | "tmp.zig:1:25: error: opaque types cannot have fields", |
| 398 | 402 | }); |
| 399 | 403 | |
| 400 | | cases.add("@Type(.Fn) with is_generic = true", |
| 404 | ctx.objErrStage1("@Type(.Fn) with is_generic = true", |
| 401 | 405 | \\const Foo = @Type(.{ |
| 402 | 406 | \\ .Fn = .{ |
| 403 | 407 | \\ .calling_convention = .Unspecified, |
| ... | ... | @@ -413,7 +417,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 413 | 417 | "tmp.zig:1:20: error: TypeInfo.Fn.is_generic must be false for @Type", |
| 414 | 418 | }); |
| 415 | 419 | |
| 416 | | cases.add("@Type(.Fn) with is_var_args = true and non-C callconv", |
| 420 | ctx.objErrStage1("@Type(.Fn) with is_var_args = true and non-C callconv", |
| 417 | 421 | \\const Foo = @Type(.{ |
| 418 | 422 | \\ .Fn = .{ |
| 419 | 423 | \\ .calling_convention = .Unspecified, |
| ... | ... | @@ -429,7 +433,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 429 | 433 | "tmp.zig:1:20: error: varargs functions must have C calling convention", |
| 430 | 434 | }); |
| 431 | 435 | |
| 432 | | cases.add("@Type(.Fn) with return_type = null", |
| 436 | ctx.objErrStage1("@Type(.Fn) with return_type = null", |
| 433 | 437 | \\const Foo = @Type(.{ |
| 434 | 438 | \\ .Fn = .{ |
| 435 | 439 | \\ .calling_convention = .Unspecified, |
| ... | ... | @@ -445,7 +449,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 445 | 449 | "tmp.zig:1:20: error: TypeInfo.Fn.return_type must be non-null for @Type", |
| 446 | 450 | }); |
| 447 | 451 | |
| 448 | | cases.add("@Type for union with opaque field", |
| 452 | ctx.objErrStage1("@Type for union with opaque field", |
| 449 | 453 | \\const TypeInfo = @import("std").builtin.TypeInfo; |
| 450 | 454 | \\const Untagged = @Type(.{ |
| 451 | 455 | \\ .Union = .{ |
| ... | ... | @@ -465,23 +469,25 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 465 | 469 | "tmp.zig:13:17: note: referenced here", |
| 466 | 470 | }); |
| 467 | 471 | |
| 468 | | cases.add("slice sentinel mismatch", |
| 472 | ctx.objErrStage1("slice sentinel mismatch", |
| 469 | 473 | \\export fn entry() void { |
| 470 | 474 | \\ const x = @import("std").meta.Vector(3, f32){ 25, 75, 5, 0 }; |
| 475 | \\ _ = x; |
| 471 | 476 | \\} |
| 472 | 477 | , &[_][]const u8{ |
| 473 | 478 | "tmp.zig:2:62: error: index 3 outside vector of size 3", |
| 474 | 479 | }); |
| 475 | 480 | |
| 476 | | cases.add("slice sentinel mismatch", |
| 481 | ctx.objErrStage1("slice sentinel mismatch", |
| 477 | 482 | \\export fn entry() void { |
| 478 | 483 | \\ const y: [:1]const u8 = &[_:2]u8{ 1, 2 }; |
| 484 | \\ _ = y; |
| 479 | 485 | \\} |
| 480 | 486 | , &[_][]const u8{ |
| 481 | 487 | "tmp.zig:2:37: error: expected type '[:1]const u8', found '*const [2:2]u8'", |
| 482 | 488 | }); |
| 483 | 489 | |
| 484 | | cases.add("@Type for union with zero fields", |
| 490 | ctx.objErrStage1("@Type for union with zero fields", |
| 485 | 491 | \\const TypeInfo = @import("std").builtin.TypeInfo; |
| 486 | 492 | \\const Untagged = @Type(.{ |
| 487 | 493 | \\ .Union = .{ |
| ... | ... | @@ -499,7 +505,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 499 | 505 | "tmp.zig:11:17: note: referenced here", |
| 500 | 506 | }); |
| 501 | 507 | |
| 502 | | cases.add("@Type for exhaustive enum with zero fields", |
| 508 | ctx.objErrStage1("@Type for exhaustive enum with zero fields", |
| 503 | 509 | \\const TypeInfo = @import("std").builtin.TypeInfo; |
| 504 | 510 | \\const Tag = @Type(.{ |
| 505 | 511 | \\ .Enum = .{ |
| ... | ... | @@ -518,7 +524,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 518 | 524 | "tmp.zig:12:9: note: referenced here", |
| 519 | 525 | }); |
| 520 | 526 | |
| 521 | | cases.add("@Type for tagged union with extra union field", |
| 527 | ctx.objErrStage1("@Type for tagged union with extra union field", |
| 522 | 528 | \\const TypeInfo = @import("std").builtin.TypeInfo; |
| 523 | 529 | \\const Tag = @Type(.{ |
| 524 | 530 | \\ .Enum = .{ |
| ... | ... | @@ -554,7 +560,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 554 | 560 | "tmp.zig:27:24: note: referenced here", |
| 555 | 561 | }); |
| 556 | 562 | |
| 557 | | cases.add("@Type with undefined", |
| 563 | ctx.objErrStage1("@Type with undefined", |
| 558 | 564 | \\comptime { |
| 559 | 565 | \\ _ = @Type(.{ .Array = .{ .len = 0, .child = u8, .sentinel = undefined } }); |
| 560 | 566 | \\} |
| ... | ... | @@ -573,7 +579,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 573 | 579 | "tmp.zig:5:16: error: use of undefined value here causes undefined behavior", |
| 574 | 580 | }); |
| 575 | 581 | |
| 576 | | cases.add("struct with declarations unavailable for @Type", |
| 582 | ctx.objErrStage1("struct with declarations unavailable for @Type", |
| 577 | 583 | \\export fn entry() void { |
| 578 | 584 | \\ _ = @Type(@typeInfo(struct { const foo = 1; })); |
| 579 | 585 | \\} |
| ... | ... | @@ -581,7 +587,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 581 | 587 | "tmp.zig:2:15: error: TypeInfo.Struct.decls must be empty for @Type", |
| 582 | 588 | }); |
| 583 | 589 | |
| 584 | | cases.add("enum with declarations unavailable for @Type", |
| 590 | ctx.objErrStage1("enum with declarations unavailable for @Type", |
| 585 | 591 | \\export fn entry() void { |
| 586 | 592 | \\ _ = @Type(@typeInfo(enum { foo, const bar = 1; })); |
| 587 | 593 | \\} |
| ... | ... | @@ -589,36 +595,44 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 589 | 595 | "tmp.zig:2:15: error: TypeInfo.Enum.decls must be empty for @Type", |
| 590 | 596 | }); |
| 591 | 597 | |
| 592 | | cases.addTest("reject extern variables with initializers", |
| 598 | ctx.testErrStage1("reject extern variables with initializers", |
| 593 | 599 | \\extern var foo: int = 2; |
| 594 | 600 | , &[_][]const u8{ |
| 595 | | "tmp.zig:1:1: error: extern variables have no initializers", |
| 601 | "tmp.zig:1:23: error: extern variables have no initializers", |
| 596 | 602 | }); |
| 597 | 603 | |
| 598 | | cases.addTest("duplicate/unused labels", |
| 604 | ctx.testErrStage1("duplicate/unused labels", |
| 599 | 605 | \\comptime { |
| 600 | 606 | \\ blk: { blk: while (false) {} } |
| 607 | \\} |
| 608 | \\comptime { |
| 601 | 609 | \\ blk: while (false) { blk: for (@as([0]void, undefined)) |_| {} } |
| 610 | \\} |
| 611 | \\comptime { |
| 602 | 612 | \\ blk: for (@as([0]void, undefined)) |_| { blk: {} } |
| 603 | 613 | \\} |
| 604 | 614 | \\comptime { |
| 605 | 615 | \\ blk: {} |
| 616 | \\} |
| 617 | \\comptime { |
| 606 | 618 | \\ blk: while(false) {} |
| 619 | \\} |
| 620 | \\comptime { |
| 607 | 621 | \\ blk: for(@as([0]void, undefined)) |_| {} |
| 608 | 622 | \\} |
| 609 | 623 | , &[_][]const u8{ |
| 610 | | "tmp.zig:2:17: error: redeclaration of label 'blk'", |
| 611 | | "tmp.zig:2:10: note: previous declaration is here", |
| 612 | | "tmp.zig:3:31: error: redeclaration of label 'blk'", |
| 613 | | "tmp.zig:3:10: note: previous declaration is here", |
| 614 | | "tmp.zig:4:51: error: redeclaration of label 'blk'", |
| 615 | | "tmp.zig:4:10: note: previous declaration is here", |
| 616 | | "tmp.zig:7:10: error: unused block label", |
| 617 | | "tmp.zig:8:10: error: unused while label", |
| 618 | | "tmp.zig:9:10: error: unused for label", |
| 624 | "tmp.zig:2:12: error: redefinition of label 'blk'", |
| 625 | "tmp.zig:2:5: note: previous definition here", |
| 626 | "tmp.zig:5:26: error: redefinition of label 'blk'", |
| 627 | "tmp.zig:5:5: note: previous definition here", |
| 628 | "tmp.zig:8:46: error: redefinition of label 'blk'", |
| 629 | "tmp.zig:8:5: note: previous definition here", |
| 630 | "tmp.zig:11:5: error: unused block label", |
| 631 | "tmp.zig:14:5: error: unused while loop label", |
| 632 | "tmp.zig:17:5: error: unused for loop label", |
| 619 | 633 | }); |
| 620 | 634 | |
| 621 | | cases.addTest("@alignCast of zero sized types", |
| 635 | ctx.testErrStage1("@alignCast of zero sized types", |
| 622 | 636 | \\export fn foo() void { |
| 623 | 637 | \\ const a: *void = undefined; |
| 624 | 638 | \\ _ = @alignCast(2, a); |
| ... | ... | @@ -633,7 +647,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 633 | 647 | \\} |
| 634 | 648 | \\export fn qux() void { |
| 635 | 649 | \\ const a = struct { |
| 636 | | \\ fn a(comptime b: u32) void {} |
| 650 | \\ fn a(comptime b: u32) void { _ = b; } |
| 637 | 651 | \\ }.a; |
| 638 | 652 | \\ _ = @alignCast(2, a); |
| 639 | 653 | \\} |
| ... | ... | @@ -644,7 +658,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 644 | 658 | "tmp.zig:17:23: error: cannot adjust alignment of zero sized type 'fn(u32) anytype'", |
| 645 | 659 | }); |
| 646 | 660 | |
| 647 | | cases.addTest("invalid non-exhaustive enum to union", |
| 661 | ctx.testErrStage1("invalid non-exhaustive enum to union", |
| 648 | 662 | \\const E = enum(u8) { |
| 649 | 663 | \\ a, |
| 650 | 664 | \\ b, |
| ... | ... | @@ -657,17 +671,19 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 657 | 671 | \\export fn foo() void { |
| 658 | 672 | \\ var e = @intToEnum(E, 15); |
| 659 | 673 | \\ var u: U = e; |
| 674 | \\ _ = u; |
| 660 | 675 | \\} |
| 661 | 676 | \\export fn bar() void { |
| 662 | 677 | \\ const e = @intToEnum(E, 15); |
| 663 | 678 | \\ var u: U = e; |
| 679 | \\ _ = u; |
| 664 | 680 | \\} |
| 665 | 681 | , &[_][]const u8{ |
| 666 | 682 | "tmp.zig:12:16: error: runtime cast to union 'U' from non-exhustive enum", |
| 667 | | "tmp.zig:16:16: error: no tag by value 15", |
| 683 | "tmp.zig:17:16: error: no tag by value 15", |
| 668 | 684 | }); |
| 669 | 685 | |
| 670 | | cases.addTest("switching with exhaustive enum has '_' prong ", |
| 686 | ctx.testErrStage1("switching with exhaustive enum has '_' prong ", |
| 671 | 687 | \\const E = enum{ |
| 672 | 688 | \\ a, |
| 673 | 689 | \\ b, |
| ... | ... | @@ -684,7 +700,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 684 | 700 | "tmp.zig:7:5: error: switch on exhaustive enum has `_` prong", |
| 685 | 701 | }); |
| 686 | 702 | |
| 687 | | cases.addTest("invalid pointer with @Type", |
| 703 | ctx.testErrStage1("invalid pointer with @Type", |
| 688 | 704 | \\export fn entry() void { |
| 689 | 705 | \\ _ = @Type(.{ .Pointer = .{ |
| 690 | 706 | \\ .size = .One, |
| ... | ... | @@ -700,7 +716,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 700 | 716 | "tmp.zig:2:16: error: sentinels are only allowed on slices and unknown-length pointers", |
| 701 | 717 | }); |
| 702 | 718 | |
| 703 | | cases.addTest("helpful return type error message", |
| 719 | ctx.testErrStage1("helpful return type error message", |
| 704 | 720 | \\export fn foo() u32 { |
| 705 | 721 | \\ return error.Ohno; |
| 706 | 722 | \\} |
| ... | ... | @@ -728,7 +744,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 728 | 744 | "tmp.zig:14:5: note: cannot store an error in type 'u32'", |
| 729 | 745 | }); |
| 730 | 746 | |
| 731 | | cases.addTest("int/float conversion to comptime_int/float", |
| 747 | ctx.testErrStage1("int/float conversion to comptime_int/float", |
| 732 | 748 | \\export fn foo() void { |
| 733 | 749 | \\ var a: f32 = 2; |
| 734 | 750 | \\ _ = @floatToInt(comptime_int, a); |
| ... | ... | @@ -744,16 +760,16 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 744 | 760 | "tmp.zig:7:9: note: referenced here", |
| 745 | 761 | }); |
| 746 | 762 | |
| 747 | | cases.add("extern variable has no type", |
| 763 | ctx.objErrStage1("extern variable has no type", |
| 748 | 764 | \\extern var foo; |
| 749 | 765 | \\pub export fn entry() void { |
| 750 | 766 | \\ foo; |
| 751 | 767 | \\} |
| 752 | 768 | , &[_][]const u8{ |
| 753 | | "tmp.zig:1:1: error: unable to infer variable type", |
| 769 | "tmp.zig:1:8: error: unable to infer variable type", |
| 754 | 770 | }); |
| 755 | 771 | |
| 756 | | cases.add("@src outside function", |
| 772 | ctx.objErrStage1("@src outside function", |
| 757 | 773 | \\comptime { |
| 758 | 774 | \\ @src(); |
| 759 | 775 | \\} |
| ... | ... | @@ -761,7 +777,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 761 | 777 | "tmp.zig:2:5: error: @src outside function", |
| 762 | 778 | }); |
| 763 | 779 | |
| 764 | | cases.add("call assigned to constant", |
| 780 | ctx.objErrStage1("call assigned to constant", |
| 765 | 781 | \\const Foo = struct { |
| 766 | 782 | \\ x: i32, |
| 767 | 783 | \\}; |
| ... | ... | @@ -784,15 +800,15 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 784 | 800 | "tmp.zig:16:14: error: cannot assign to constant", |
| 785 | 801 | }); |
| 786 | 802 | |
| 787 | | cases.add("invalid pointer syntax", |
| 803 | ctx.objErrStage1("invalid pointer syntax", |
| 788 | 804 | \\export fn foo() void { |
| 789 | 805 | \\ var guid: *:0 const u8 = undefined; |
| 790 | 806 | \\} |
| 791 | 807 | , &[_][]const u8{ |
| 792 | | "tmp.zig:2:15: error: sentinels are only allowed on unknown-length pointers", |
| 808 | "tmp.zig:2:16: error: expected type expression, found ':'", |
| 793 | 809 | }); |
| 794 | 810 | |
| 795 | | cases.add("declaration between fields", |
| 811 | ctx.objErrStage1("declaration between fields", |
| 796 | 812 | \\const S = struct { |
| 797 | 813 | \\ const foo = 2; |
| 798 | 814 | \\ const bar = 2; |
| ... | ... | @@ -810,16 +826,16 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 810 | 826 | "tmp.zig:6:5: error: declarations are not allowed between container fields", |
| 811 | 827 | }); |
| 812 | 828 | |
| 813 | | cases.add("non-extern function with var args", |
| 829 | ctx.objErrStage1("non-extern function with var args", |
| 814 | 830 | \\fn foo(args: ...) void {} |
| 815 | 831 | \\export fn entry() void { |
| 816 | 832 | \\ foo(); |
| 817 | 833 | \\} |
| 818 | 834 | , &[_][]const u8{ |
| 819 | | "tmp.zig:1:1: error: non-extern function is variadic", |
| 835 | "tmp.zig:1:14: error: expected type expression, found '...'", |
| 820 | 836 | }); |
| 821 | 837 | |
| 822 | | cases.addTest("invalid int casts", |
| 838 | ctx.testErrStage1("invalid int casts", |
| 823 | 839 | \\export fn foo() void { |
| 824 | 840 | \\ var a: u32 = 2; |
| 825 | 841 | \\ _ = @intCast(comptime_int, a); |
| ... | ... | @@ -847,7 +863,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 847 | 863 | "tmp.zig:15:9: note: referenced here", |
| 848 | 864 | }); |
| 849 | 865 | |
| 850 | | cases.addTest("invalid float casts", |
| 866 | ctx.testErrStage1("invalid float casts", |
| 851 | 867 | \\export fn foo() void { |
| 852 | 868 | \\ var a: f32 = 2; |
| 853 | 869 | \\ _ = @floatCast(comptime_float, a); |
| ... | ... | @@ -875,7 +891,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 875 | 891 | "tmp.zig:15:9: note: referenced here", |
| 876 | 892 | }); |
| 877 | 893 | |
| 878 | | cases.addTest("invalid assignments", |
| 894 | ctx.testErrStage1("invalid assignments", |
| 879 | 895 | \\export fn entry1() void { |
| 880 | 896 | \\ var a: []const u8 = "foo"; |
| 881 | 897 | \\ a[0..2] = "bar"; |
| ... | ... | @@ -893,7 +909,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 893 | 909 | "tmp.zig:10:7: error: invalid left-hand side to assignment", |
| 894 | 910 | }); |
| 895 | 911 | |
| 896 | | cases.addTest("reassign to array parameter", |
| 912 | ctx.testErrStage1("reassign to array parameter", |
| 897 | 913 | \\fn reassign(a: [3]f32) void { |
| 898 | 914 | \\ a = [3]f32{4, 5, 6}; |
| 899 | 915 | \\} |
| ... | ... | @@ -904,7 +920,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 904 | 920 | "tmp.zig:2:15: error: cannot assign to constant", |
| 905 | 921 | }); |
| 906 | 922 | |
| 907 | | cases.addTest("reassign to slice parameter", |
| 923 | ctx.testErrStage1("reassign to slice parameter", |
| 908 | 924 | \\pub fn reassign(s: []const u8) void { |
| 909 | 925 | \\ s = s[0..]; |
| 910 | 926 | \\} |
| ... | ... | @@ -915,7 +931,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 915 | 931 | "tmp.zig:2:10: error: cannot assign to constant", |
| 916 | 932 | }); |
| 917 | 933 | |
| 918 | | cases.addTest("reassign to struct parameter", |
| 934 | ctx.testErrStage1("reassign to struct parameter", |
| 919 | 935 | \\const S = struct { |
| 920 | 936 | \\ x: u32, |
| 921 | 937 | \\}; |
| ... | ... | @@ -929,7 +945,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 929 | 945 | "tmp.zig:5:10: error: cannot assign to constant", |
| 930 | 946 | }); |
| 931 | 947 | |
| 932 | | cases.addTest("reference to const data", |
| 948 | ctx.testErrStage1("reference to const data", |
| 933 | 949 | \\export fn foo() void { |
| 934 | 950 | \\ var ptr = &[_]u8{0,0,0,0}; |
| 935 | 951 | \\ ptr[1] = 2; |
| ... | ... | @@ -957,7 +973,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 957 | 973 | "tmp.zig:19:13: error: cannot assign to constant", |
| 958 | 974 | }); |
| 959 | 975 | |
| 960 | | cases.addTest("cast between ?T where T is not a pointer", |
| 976 | ctx.testErrStage1("cast between ?T where T is not a pointer", |
| 961 | 977 | \\pub const fnty1 = ?fn (i8) void; |
| 962 | 978 | \\pub const fnty2 = ?fn (u64) void; |
| 963 | 979 | \\export fn entry() void { |
| ... | ... | @@ -970,7 +986,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 970 | 986 | "tmp.zig:6:9: note: optional type child 'fn(u64) void' cannot cast into optional type child 'fn(i8) void'", |
| 971 | 987 | }); |
| 972 | 988 | |
| 973 | | cases.addTest("unused variable error on errdefer", |
| 989 | ctx.testErrStage1("unused variable error on errdefer", |
| 974 | 990 | \\fn foo() !void { |
| 975 | 991 | \\ errdefer |a| unreachable; |
| 976 | 992 | \\ return error.A; |
| ... | ... | @@ -982,18 +998,19 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 982 | 998 | "tmp.zig:2:15: error: unused variable: 'a'", |
| 983 | 999 | }); |
| 984 | 1000 | |
| 985 | | cases.addTest("comparison of non-tagged union and enum literal", |
| 1001 | ctx.testErrStage1("comparison of non-tagged union and enum literal", |
| 986 | 1002 | \\export fn entry() void { |
| 987 | 1003 | \\ const U = union { A: u32, B: u64 }; |
| 988 | 1004 | \\ var u = U{ .A = 42 }; |
| 989 | 1005 | \\ var ok = u == .A; |
| 1006 | \\ _ = ok; |
| 990 | 1007 | \\} |
| 991 | 1008 | , &[_][]const u8{ |
| 992 | 1009 | "tmp.zig:4:16: error: comparison of union and enum literal is only valid for tagged union types", |
| 993 | 1010 | "tmp.zig:2:15: note: type U is not a tagged union", |
| 994 | 1011 | }); |
| 995 | 1012 | |
| 996 | | cases.addTest("shift on type with non-power-of-two size", |
| 1013 | ctx.testErrStage1("shift on type with non-power-of-two size", |
| 997 | 1014 | \\export fn entry() void { |
| 998 | 1015 | \\ const S = struct { |
| 999 | 1016 | \\ fn a() void { |
| ... | ... | @@ -1025,7 +1042,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1025 | 1042 | "tmp.zig:17:17: error: RHS of shift is too large for LHS type", |
| 1026 | 1043 | }); |
| 1027 | 1044 | |
| 1028 | | cases.addTest("combination of nosuspend and async", |
| 1045 | ctx.testErrStage1("combination of nosuspend and async", |
| 1029 | 1046 | \\export fn entry() void { |
| 1030 | 1047 | \\ nosuspend { |
| 1031 | 1048 | \\ const bar = async foo(); |
| ... | ... | @@ -1035,10 +1052,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1035 | 1052 | \\} |
| 1036 | 1053 | \\fn foo() void {} |
| 1037 | 1054 | , &[_][]const u8{ |
| 1038 | | "tmp.zig:4:9: error: suspend in nosuspend scope", |
| 1055 | "tmp.zig:4:9: error: suspend inside nosuspend block", |
| 1056 | "tmp.zig:2:5: note: nosuspend block here", |
| 1039 | 1057 | }); |
| 1040 | 1058 | |
| 1041 | | cases.add("atomicrmw with bool op not .Xchg", |
| 1059 | ctx.objErrStage1("atomicrmw with bool op not .Xchg", |
| 1042 | 1060 | \\export fn entry() void { |
| 1043 | 1061 | \\ var x = false; |
| 1044 | 1062 | \\ _ = @atomicRmw(bool, &x, .Add, true, .SeqCst); |
| ... | ... | @@ -1047,7 +1065,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1047 | 1065 | "tmp.zig:3:30: error: @atomicRmw with bool only allowed with .Xchg", |
| 1048 | 1066 | }); |
| 1049 | 1067 | |
| 1050 | | cases.addTest("@TypeOf with no arguments", |
| 1068 | ctx.testErrStage1("@TypeOf with no arguments", |
| 1051 | 1069 | \\export fn entry() void { |
| 1052 | 1070 | \\ _ = @TypeOf(); |
| 1053 | 1071 | \\} |
| ... | ... | @@ -1055,7 +1073,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1055 | 1073 | "tmp.zig:2:9: error: expected at least 1 argument, found 0", |
| 1056 | 1074 | }); |
| 1057 | 1075 | |
| 1058 | | cases.addTest("@TypeOf with incompatible arguments", |
| 1076 | ctx.testErrStage1("@TypeOf with incompatible arguments", |
| 1059 | 1077 | \\export fn entry() void { |
| 1060 | 1078 | \\ var var_1: f32 = undefined; |
| 1061 | 1079 | \\ var var_2: u32 = undefined; |
| ... | ... | @@ -1065,7 +1083,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1065 | 1083 | "tmp.zig:4:9: error: incompatible types: 'f32' and 'u32'", |
| 1066 | 1084 | }); |
| 1067 | 1085 | |
| 1068 | | cases.addTest("type mismatch with tuple concatenation", |
| 1086 | ctx.testErrStage1("type mismatch with tuple concatenation", |
| 1069 | 1087 | \\export fn entry() void { |
| 1070 | 1088 | \\ var x = .{}; |
| 1071 | 1089 | \\ x = x ++ .{ 1, 2, 3 }; |
| ... | ... | @@ -1074,7 +1092,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1074 | 1092 | "tmp.zig:3:11: error: expected type 'struct:2:14', found 'struct:3:11'", |
| 1075 | 1093 | }); |
| 1076 | 1094 | |
| 1077 | | cases.addTest("@tagName on invalid value of non-exhaustive enum", |
| 1095 | ctx.testErrStage1("@tagName on invalid value of non-exhaustive enum", |
| 1078 | 1096 | \\test "enum" { |
| 1079 | 1097 | \\ const E = enum(u8) {A, B, _}; |
| 1080 | 1098 | \\ _ = @tagName(@intToEnum(E, 5)); |
| ... | ... | @@ -1083,16 +1101,17 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1083 | 1101 | "tmp.zig:3:18: error: no tag by value 5", |
| 1084 | 1102 | }); |
| 1085 | 1103 | |
| 1086 | | cases.addTest("@ptrToInt with pointer to zero-sized type", |
| 1104 | ctx.testErrStage1("@ptrToInt with pointer to zero-sized type", |
| 1087 | 1105 | \\export fn entry() void { |
| 1088 | 1106 | \\ var pointer: ?*u0 = null; |
| 1089 | 1107 | \\ var x = @ptrToInt(pointer); |
| 1108 | \\ _ = x; |
| 1090 | 1109 | \\} |
| 1091 | 1110 | , &[_][]const u8{ |
| 1092 | 1111 | "tmp.zig:3:23: error: pointer to size 0 type has no address", |
| 1093 | 1112 | }); |
| 1094 | 1113 | |
| 1095 | | cases.addTest("access invalid @typeInfo decl", |
| 1114 | ctx.testErrStage1("access invalid @typeInfo decl", |
| 1096 | 1115 | \\const A = B; |
| 1097 | 1116 | \\test "Crash" { |
| 1098 | 1117 | \\ _ = @typeInfo(@This()).Struct.decls[0]; |
| ... | ... | @@ -1101,7 +1120,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1101 | 1120 | "tmp.zig:1:11: error: use of undeclared identifier 'B'", |
| 1102 | 1121 | }); |
| 1103 | 1122 | |
| 1104 | | cases.addTest("reject extern function definitions with body", |
| 1123 | ctx.testErrStage1("reject extern function definitions with body", |
| 1105 | 1124 | \\extern "c" fn definitelyNotInLibC(a: i32, b: i32) i32 { |
| 1106 | 1125 | \\ return a + b; |
| 1107 | 1126 | \\} |
| ... | ... | @@ -1109,7 +1128,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1109 | 1128 | "tmp.zig:1:1: error: extern functions have no body", |
| 1110 | 1129 | }); |
| 1111 | 1130 | |
| 1112 | | cases.addTest("duplicate field in anonymous struct literal", |
| 1131 | ctx.testErrStage1("duplicate field in anonymous struct literal", |
| 1113 | 1132 | \\export fn entry() void { |
| 1114 | 1133 | \\ const anon = .{ |
| 1115 | 1134 | \\ .inner = .{ |
| ... | ... | @@ -1119,31 +1138,33 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1119 | 1138 | \\ .a = .{}, |
| 1120 | 1139 | \\ }, |
| 1121 | 1140 | \\ }; |
| 1141 | \\ _ = anon; |
| 1122 | 1142 | \\} |
| 1123 | 1143 | , &[_][]const u8{ |
| 1124 | 1144 | "tmp.zig:7:13: error: duplicate field", |
| 1125 | 1145 | "tmp.zig:4:13: note: other field here", |
| 1126 | 1146 | }); |
| 1127 | 1147 | |
| 1128 | | cases.addTest("type mismatch in C prototype with varargs", |
| 1148 | ctx.testErrStage1("type mismatch in C prototype with varargs", |
| 1129 | 1149 | \\const fn_ty = ?fn ([*c]u8, ...) callconv(.C) void; |
| 1130 | 1150 | \\extern fn fn_decl(fmt: [*:0]u8, ...) void; |
| 1131 | 1151 | \\ |
| 1132 | 1152 | \\export fn main() void { |
| 1133 | 1153 | \\ const x: fn_ty = fn_decl; |
| 1154 | \\ _ = x; |
| 1134 | 1155 | \\} |
| 1135 | 1156 | , &[_][]const u8{ |
| 1136 | 1157 | "tmp.zig:5:22: error: expected type 'fn([*c]u8, ...) callconv(.C) void', found 'fn([*:0]u8, ...) callconv(.C) void'", |
| 1137 | 1158 | }); |
| 1138 | 1159 | |
| 1139 | | cases.addTest("dependency loop in top-level decl with @TypeInfo when accessing the decls", |
| 1160 | ctx.testErrStage1("dependency loop in top-level decl with @TypeInfo when accessing the decls", |
| 1140 | 1161 | \\export const foo = @typeInfo(@This()).Struct.decls; |
| 1141 | 1162 | , &[_][]const u8{ |
| 1142 | 1163 | "tmp.zig:1:20: error: dependency loop detected", |
| 1143 | 1164 | "tmp.zig:1:45: note: referenced here", |
| 1144 | 1165 | }); |
| 1145 | 1166 | |
| 1146 | | cases.add("function call assigned to incorrect type", |
| 1167 | ctx.objErrStage1("function call assigned to incorrect type", |
| 1147 | 1168 | \\export fn entry() void { |
| 1148 | 1169 | \\ var arr: [4]f32 = undefined; |
| 1149 | 1170 | \\ arr = concat(); |
| ... | ... | @@ -1155,7 +1176,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1155 | 1176 | "tmp.zig:3:17: error: expected type '[4]f32', found '[16]f32'", |
| 1156 | 1177 | }); |
| 1157 | 1178 | |
| 1158 | | cases.add("generic function call assigned to incorrect type", |
| 1179 | ctx.objErrStage1("generic function call assigned to incorrect type", |
| 1159 | 1180 | \\pub export fn entry() void { |
| 1160 | 1181 | \\ var res: []i32 = undefined; |
| 1161 | 1182 | \\ res = myAlloc(i32); |
| ... | ... | @@ -1167,12 +1188,25 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1167 | 1188 | "tmp.zig:3:18: error: expected type '[]i32', found 'anyerror!i32", |
| 1168 | 1189 | }); |
| 1169 | 1190 | |
| 1170 | | cases.addTest("non-exhaustive enums", |
| 1191 | ctx.testErrStage1("non-exhaustive enum marker assigned a value", |
| 1171 | 1192 | \\const A = enum { |
| 1172 | 1193 | \\ a, |
| 1173 | 1194 | \\ b, |
| 1174 | 1195 | \\ _ = 1, |
| 1175 | 1196 | \\}; |
| 1197 | \\const B = enum { |
| 1198 | \\ a, |
| 1199 | \\ b, |
| 1200 | \\ _, |
| 1201 | \\}; |
| 1202 | \\comptime { _ = A; _ = B; } |
| 1203 | , &[_][]const u8{ |
| 1204 | "tmp.zig:4:9: error: '_' is used to mark an enum as non-exhaustive and cannot be assigned a value", |
| 1205 | "tmp.zig:6:11: error: non-exhaustive enum missing integer tag type", |
| 1206 | "tmp.zig:9:5: note: marked non-exhaustive here", |
| 1207 | }); |
| 1208 | |
| 1209 | ctx.testErrStage1("non-exhaustive enums", |
| 1176 | 1210 | \\const B = enum(u1) { |
| 1177 | 1211 | \\ a, |
| 1178 | 1212 | \\ _, |
| ... | ... | @@ -1184,18 +1218,15 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1184 | 1218 | \\ _, |
| 1185 | 1219 | \\}; |
| 1186 | 1220 | \\pub export fn entry() void { |
| 1187 | | \\ _ = A; |
| 1188 | 1221 | \\ _ = B; |
| 1189 | 1222 | \\ _ = C; |
| 1190 | 1223 | \\} |
| 1191 | 1224 | , &[_][]const u8{ |
| 1192 | | "tmp.zig:4:5: error: value assigned to '_' field of non-exhaustive enum", |
| 1193 | | "error: non-exhaustive enum must specify size", |
| 1194 | | "error: non-exhaustive enum specifies every value", |
| 1195 | | "error: '_' field of non-exhaustive enum must be last", |
| 1225 | "tmp.zig:3:5: error: '_' field of non-exhaustive enum must be last", |
| 1226 | "tmp.zig:6:11: error: non-exhaustive enum specifies every value", |
| 1196 | 1227 | }); |
| 1197 | 1228 | |
| 1198 | | cases.addTest("switching with non-exhaustive enums", |
| 1229 | ctx.testErrStage1("switching with non-exhaustive enums", |
| 1199 | 1230 | \\const E = enum(u8) { |
| 1200 | 1231 | \\ a, |
| 1201 | 1232 | \\ b, |
| ... | ... | @@ -1228,7 +1259,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1228 | 1259 | "tmp.zig:21:5: error: `_` prong not allowed when switching on tagged union", |
| 1229 | 1260 | }); |
| 1230 | 1261 | |
| 1231 | | cases.add("switch expression - unreachable else prong (bool)", |
| 1262 | ctx.objErrStage1("switch expression - unreachable else prong (bool)", |
| 1232 | 1263 | \\fn foo(x: bool) void { |
| 1233 | 1264 | \\ switch (x) { |
| 1234 | 1265 | \\ true => {}, |
| ... | ... | @@ -1241,7 +1272,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1241 | 1272 | "tmp.zig:5:9: error: unreachable else prong, all cases already handled", |
| 1242 | 1273 | }); |
| 1243 | 1274 | |
| 1244 | | cases.add("switch expression - unreachable else prong (u1)", |
| 1275 | ctx.objErrStage1("switch expression - unreachable else prong (u1)", |
| 1245 | 1276 | \\fn foo(x: u1) void { |
| 1246 | 1277 | \\ switch (x) { |
| 1247 | 1278 | \\ 0 => {}, |
| ... | ... | @@ -1254,7 +1285,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1254 | 1285 | "tmp.zig:5:9: error: unreachable else prong, all cases already handled", |
| 1255 | 1286 | }); |
| 1256 | 1287 | |
| 1257 | | cases.add("switch expression - unreachable else prong (u2)", |
| 1288 | ctx.objErrStage1("switch expression - unreachable else prong (u2)", |
| 1258 | 1289 | \\fn foo(x: u2) void { |
| 1259 | 1290 | \\ switch (x) { |
| 1260 | 1291 | \\ 0 => {}, |
| ... | ... | @@ -1269,7 +1300,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1269 | 1300 | "tmp.zig:7:9: error: unreachable else prong, all cases already handled", |
| 1270 | 1301 | }); |
| 1271 | 1302 | |
| 1272 | | cases.add("switch expression - unreachable else prong (range u8)", |
| 1303 | ctx.objErrStage1("switch expression - unreachable else prong (range u8)", |
| 1273 | 1304 | \\fn foo(x: u8) void { |
| 1274 | 1305 | \\ switch (x) { |
| 1275 | 1306 | \\ 0 => {}, |
| ... | ... | @@ -1285,7 +1316,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1285 | 1316 | "tmp.zig:8:9: error: unreachable else prong, all cases already handled", |
| 1286 | 1317 | }); |
| 1287 | 1318 | |
| 1288 | | cases.add("switch expression - unreachable else prong (range i8)", |
| 1319 | ctx.objErrStage1("switch expression - unreachable else prong (range i8)", |
| 1289 | 1320 | \\fn foo(x: i8) void { |
| 1290 | 1321 | \\ switch (x) { |
| 1291 | 1322 | \\ -128...0 => {}, |
| ... | ... | @@ -1301,7 +1332,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1301 | 1332 | "tmp.zig:8:9: error: unreachable else prong, all cases already handled", |
| 1302 | 1333 | }); |
| 1303 | 1334 | |
| 1304 | | cases.add("switch expression - unreachable else prong (enum)", |
| 1335 | ctx.objErrStage1("switch expression - unreachable else prong (enum)", |
| 1305 | 1336 | \\const TestEnum = enum{ T1, T2 }; |
| 1306 | 1337 | \\ |
| 1307 | 1338 | \\fn err(x: u8) TestEnum { |
| ... | ... | @@ -1324,7 +1355,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1324 | 1355 | "tmp.zig:14:9: error: unreachable else prong, all cases already handled", |
| 1325 | 1356 | }); |
| 1326 | 1357 | |
| 1327 | | cases.addTest("@export with empty name string", |
| 1358 | ctx.testErrStage1("@export with empty name string", |
| 1328 | 1359 | \\pub export fn entry() void { } |
| 1329 | 1360 | \\comptime { |
| 1330 | 1361 | \\ @export(entry, .{ .name = "" }); |
| ... | ... | @@ -1333,7 +1364,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1333 | 1364 | "tmp.zig:3:5: error: exported symbol name cannot be empty", |
| 1334 | 1365 | }); |
| 1335 | 1366 | |
| 1336 | | cases.addTest("switch ranges endpoints are validated", |
| 1367 | ctx.testErrStage1("switch ranges endpoints are validated", |
| 1337 | 1368 | \\pub export fn entry() void { |
| 1338 | 1369 | \\ var x: i32 = 0; |
| 1339 | 1370 | \\ switch (x) { |
| ... | ... | @@ -1347,16 +1378,16 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1347 | 1378 | "tmp.zig:5:9: error: range start value is greater than the end value", |
| 1348 | 1379 | }); |
| 1349 | 1380 | |
| 1350 | | cases.addTest("errors in for loop bodies are propagated", |
| 1381 | ctx.testErrStage1("errors in for loop bodies are propagated", |
| 1351 | 1382 | \\pub export fn entry() void { |
| 1352 | 1383 | \\ var arr: [100]u8 = undefined; |
| 1353 | 1384 | \\ for (arr) |bits| _ = @popCount(bits); |
| 1354 | 1385 | \\} |
| 1355 | 1386 | , &[_][]const u8{ |
| 1356 | | "tmp.zig:3:26: error: expected 2 argument(s), found 1", |
| 1387 | "tmp.zig:3:26: error: expected 2 arguments, found 1", |
| 1357 | 1388 | }); |
| 1358 | 1389 | |
| 1359 | | cases.addTest("@call rejects non comptime-known fn - always_inline", |
| 1390 | ctx.testErrStage1("@call rejects non comptime-known fn - always_inline", |
| 1360 | 1391 | \\pub export fn entry() void { |
| 1361 | 1392 | \\ var call_me: fn () void = undefined; |
| 1362 | 1393 | \\ @call(.{ .modifier = .always_inline }, call_me, .{}); |
| ... | ... | @@ -1365,7 +1396,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1365 | 1396 | "tmp.zig:3:5: error: the specified modifier requires a comptime-known function", |
| 1366 | 1397 | }); |
| 1367 | 1398 | |
| 1368 | | cases.addTest("@call rejects non comptime-known fn - compile_time", |
| 1399 | ctx.testErrStage1("@call rejects non comptime-known fn - compile_time", |
| 1369 | 1400 | \\pub export fn entry() void { |
| 1370 | 1401 | \\ var call_me: fn () void = undefined; |
| 1371 | 1402 | \\ @call(.{ .modifier = .compile_time }, call_me, .{}); |
| ... | ... | @@ -1374,19 +1405,20 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1374 | 1405 | "tmp.zig:3:5: error: the specified modifier requires a comptime-known function", |
| 1375 | 1406 | }); |
| 1376 | 1407 | |
| 1377 | | cases.addTest("error in struct initializer doesn't crash the compiler", |
| 1408 | ctx.testErrStage1("error in struct initializer doesn't crash the compiler", |
| 1378 | 1409 | \\pub export fn entry() void { |
| 1379 | 1410 | \\ const bitfield = struct { |
| 1380 | 1411 | \\ e: u8, |
| 1381 | 1412 | \\ e: u8, |
| 1382 | 1413 | \\ }; |
| 1383 | 1414 | \\ var a = .{@sizeOf(bitfield)}; |
| 1415 | \\ _ = a; |
| 1384 | 1416 | \\} |
| 1385 | 1417 | , &[_][]const u8{ |
| 1386 | 1418 | "tmp.zig:4:9: error: duplicate struct field: 'e'", |
| 1387 | 1419 | }); |
| 1388 | 1420 | |
| 1389 | | cases.addTest("repeated invalid field access to generic function returning type crashes compiler. #2655", |
| 1421 | ctx.testErrStage1("repeated invalid field access to generic function returning type crashes compiler. #2655", |
| 1390 | 1422 | \\pub fn A() type { |
| 1391 | 1423 | \\ return Q; |
| 1392 | 1424 | \\} |
| ... | ... | @@ -1398,15 +1430,16 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1398 | 1430 | "tmp.zig:2:12: error: use of undeclared identifier 'Q'", |
| 1399 | 1431 | }); |
| 1400 | 1432 | |
| 1401 | | cases.add("bitCast to enum type", |
| 1433 | ctx.objErrStage1("bitCast to enum type", |
| 1402 | 1434 | \\export fn entry() void { |
| 1403 | 1435 | \\ const y = @bitCast(enum(u32) { a, b }, @as(u32, 3)); |
| 1436 | \\ _ = y; |
| 1404 | 1437 | \\} |
| 1405 | 1438 | , &[_][]const u8{ |
| 1406 | 1439 | "tmp.zig:2:24: error: cannot cast a value of type 'y'", |
| 1407 | 1440 | }); |
| 1408 | 1441 | |
| 1409 | | cases.add("comparing against undefined produces undefined value", |
| 1442 | ctx.objErrStage1("comparing against undefined produces undefined value", |
| 1410 | 1443 | \\export fn entry() void { |
| 1411 | 1444 | \\ if (2 == undefined) {} |
| 1412 | 1445 | \\} |
| ... | ... | @@ -1414,17 +1447,18 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1414 | 1447 | "tmp.zig:2:11: error: use of undefined value here causes undefined behavior", |
| 1415 | 1448 | }); |
| 1416 | 1449 | |
| 1417 | | cases.add("comptime ptrcast of zero-sized type", |
| 1450 | ctx.objErrStage1("comptime ptrcast of zero-sized type", |
| 1418 | 1451 | \\fn foo() void { |
| 1419 | 1452 | \\ const node: struct {} = undefined; |
| 1420 | 1453 | \\ const vla_ptr = @ptrCast([*]const u8, &node); |
| 1454 | \\ _ = vla_ptr; |
| 1421 | 1455 | \\} |
| 1422 | 1456 | \\comptime { foo(); } |
| 1423 | 1457 | , &[_][]const u8{ |
| 1424 | 1458 | "tmp.zig:3:21: error: '*const struct:2:17' and '[*]const u8' do not have the same in-memory representation", |
| 1425 | 1459 | }); |
| 1426 | 1460 | |
| 1427 | | cases.add("slice sentinel mismatch", |
| 1461 | ctx.objErrStage1("slice sentinel mismatch", |
| 1428 | 1462 | \\fn foo() [:0]u8 { |
| 1429 | 1463 | \\ var x: []u8 = undefined; |
| 1430 | 1464 | \\ return x; |
| ... | ... | @@ -1435,7 +1469,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1435 | 1469 | "tmp.zig:3:12: note: destination pointer requires a terminating '0' sentinel", |
| 1436 | 1470 | }); |
| 1437 | 1471 | |
| 1438 | | cases.add("cmpxchg with float", |
| 1472 | ctx.objErrStage1("cmpxchg with float", |
| 1439 | 1473 | \\export fn entry() void { |
| 1440 | 1474 | \\ var x: f32 = 0; |
| 1441 | 1475 | \\ _ = @cmpxchgWeak(f32, &x, 1, 2, .SeqCst, .SeqCst); |
| ... | ... | @@ -1444,7 +1478,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1444 | 1478 | "tmp.zig:3:22: error: expected bool, integer, enum or pointer type, found 'f32'", |
| 1445 | 1479 | }); |
| 1446 | 1480 | |
| 1447 | | cases.add("atomicrmw with float op not .Xchg, .Add or .Sub", |
| 1481 | ctx.objErrStage1("atomicrmw with float op not .Xchg, .Add or .Sub", |
| 1448 | 1482 | \\export fn entry() void { |
| 1449 | 1483 | \\ var x: f32 = 0; |
| 1450 | 1484 | \\ _ = @atomicRmw(f32, &x, .And, 2, .SeqCst); |
| ... | ... | @@ -1453,15 +1487,16 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1453 | 1487 | "tmp.zig:3:29: error: @atomicRmw with float only allowed with .Xchg, .Add and .Sub", |
| 1454 | 1488 | }); |
| 1455 | 1489 | |
| 1456 | | cases.add("intToPtr with misaligned address", |
| 1490 | ctx.objErrStage1("intToPtr with misaligned address", |
| 1457 | 1491 | \\pub fn main() void { |
| 1458 | 1492 | \\ var y = @intToPtr([*]align(4) u8, 5); |
| 1493 | \\ _ = y; |
| 1459 | 1494 | \\} |
| 1460 | 1495 | , &[_][]const u8{ |
| 1461 | 1496 | "tmp.zig:2:13: error: pointer type '[*]align(4) u8' requires aligned address", |
| 1462 | 1497 | }); |
| 1463 | 1498 | |
| 1464 | | cases.add("invalid float literal", |
| 1499 | ctx.objErrStage1("invalid float literal", |
| 1465 | 1500 | \\const std = @import("std"); |
| 1466 | 1501 | \\ |
| 1467 | 1502 | \\pub fn main() void { |
| ... | ... | @@ -1473,170 +1508,209 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1473 | 1508 | "tmp.zig:5:29: error: invalid token: '.'", |
| 1474 | 1509 | }); |
| 1475 | 1510 | |
| 1476 | | cases.add("invalid exponent in float literal - 1", |
| 1511 | ctx.objErrStage1("invalid exponent in float literal - 1", |
| 1477 | 1512 | \\fn main() void { |
| 1478 | 1513 | \\ var bad: f128 = 0x1.0p1ab1; |
| 1514 | \\ _ = bad; |
| 1479 | 1515 | \\} |
| 1480 | 1516 | , &[_][]const u8{ |
| 1481 | | "tmp.zig:2:28: error: invalid character: 'a'", |
| 1517 | "tmp.zig:2:21: error: expected expression, found 'invalid'", |
| 1518 | "tmp.zig:2:28: note: invalid byte: 'a'", |
| 1482 | 1519 | }); |
| 1483 | 1520 | |
| 1484 | | cases.add("invalid exponent in float literal - 2", |
| 1521 | ctx.objErrStage1("invalid exponent in float literal - 2", |
| 1485 | 1522 | \\fn main() void { |
| 1486 | 1523 | \\ var bad: f128 = 0x1.0p50F; |
| 1524 | \\ _ = bad; |
| 1487 | 1525 | \\} |
| 1488 | 1526 | , &[_][]const u8{ |
| 1489 | | "tmp.zig:2:29: error: invalid character: 'F'", |
| 1527 | "tmp.zig:2:21: error: expected expression, found 'invalid'", |
| 1528 | "tmp.zig:2:29: note: invalid byte: 'F'", |
| 1490 | 1529 | }); |
| 1491 | 1530 | |
| 1492 | | cases.add("invalid underscore placement in float literal - 1", |
| 1531 | ctx.objErrStage1("invalid underscore placement in float literal - 1", |
| 1493 | 1532 | \\fn main() void { |
| 1494 | 1533 | \\ var bad: f128 = 0._0; |
| 1534 | \\ _ = bad; |
| 1495 | 1535 | \\} |
| 1496 | 1536 | , &[_][]const u8{ |
| 1497 | | "tmp.zig:2:23: error: invalid character: '_'", |
| 1537 | "tmp.zig:2:21: error: expected expression, found 'invalid'", |
| 1538 | "tmp.zig:2:23: note: invalid byte: '_'", |
| 1498 | 1539 | }); |
| 1499 | 1540 | |
| 1500 | | cases.add("invalid underscore placement in float literal - 2", |
| 1541 | ctx.objErrStage1("invalid underscore placement in float literal - 2", |
| 1501 | 1542 | \\fn main() void { |
| 1502 | 1543 | \\ var bad: f128 = 0_.0; |
| 1544 | \\ _ = bad; |
| 1503 | 1545 | \\} |
| 1504 | 1546 | , &[_][]const u8{ |
| 1505 | | "tmp.zig:2:23: error: invalid character: '.'", |
| 1547 | "tmp.zig:2:21: error: expected expression, found 'invalid'", |
| 1548 | "tmp.zig:2:23: note: invalid byte: '.'", |
| 1506 | 1549 | }); |
| 1507 | 1550 | |
| 1508 | | cases.add("invalid underscore placement in float literal - 3", |
| 1551 | ctx.objErrStage1("invalid underscore placement in float literal - 3", |
| 1509 | 1552 | \\fn main() void { |
| 1510 | 1553 | \\ var bad: f128 = 0.0_; |
| 1554 | \\ _ = bad; |
| 1511 | 1555 | \\} |
| 1512 | 1556 | , &[_][]const u8{ |
| 1513 | | "tmp.zig:2:25: error: invalid character: ';'", |
| 1557 | "tmp.zig:2:21: error: expected expression, found 'invalid'", |
| 1558 | "tmp.zig:2:25: note: invalid byte: ';'", |
| 1514 | 1559 | }); |
| 1515 | 1560 | |
| 1516 | | cases.add("invalid underscore placement in float literal - 4", |
| 1561 | ctx.objErrStage1("invalid underscore placement in float literal - 4", |
| 1517 | 1562 | \\fn main() void { |
| 1518 | 1563 | \\ var bad: f128 = 1.0e_1; |
| 1564 | \\ _ = bad; |
| 1519 | 1565 | \\} |
| 1520 | 1566 | , &[_][]const u8{ |
| 1521 | | "tmp.zig:2:25: error: invalid character: '_'", |
| 1567 | "tmp.zig:2:21: error: expected expression, found 'invalid'", |
| 1568 | "tmp.zig:2:25: note: invalid byte: '_'", |
| 1522 | 1569 | }); |
| 1523 | 1570 | |
| 1524 | | cases.add("invalid underscore placement in float literal - 5", |
| 1571 | ctx.objErrStage1("invalid underscore placement in float literal - 5", |
| 1525 | 1572 | \\fn main() void { |
| 1526 | 1573 | \\ var bad: f128 = 1.0e+_1; |
| 1574 | \\ _ = bad; |
| 1527 | 1575 | \\} |
| 1528 | 1576 | , &[_][]const u8{ |
| 1529 | | "tmp.zig:2:26: error: invalid character: '_'", |
| 1577 | "tmp.zig:2:21: error: expected expression, found 'invalid'", |
| 1578 | "tmp.zig:2:26: note: invalid byte: '_'", |
| 1530 | 1579 | }); |
| 1531 | 1580 | |
| 1532 | | cases.add("invalid underscore placement in float literal - 6", |
| 1581 | ctx.objErrStage1("invalid underscore placement in float literal - 6", |
| 1533 | 1582 | \\fn main() void { |
| 1534 | 1583 | \\ var bad: f128 = 1.0e-_1; |
| 1584 | \\ _ = bad; |
| 1535 | 1585 | \\} |
| 1536 | 1586 | , &[_][]const u8{ |
| 1537 | | "tmp.zig:2:26: error: invalid character: '_'", |
| 1587 | "tmp.zig:2:21: error: expected expression, found 'invalid'", |
| 1588 | "tmp.zig:2:26: note: invalid byte: '_'", |
| 1538 | 1589 | }); |
| 1539 | 1590 | |
| 1540 | | cases.add("invalid underscore placement in float literal - 7", |
| 1591 | ctx.objErrStage1("invalid underscore placement in float literal - 7", |
| 1541 | 1592 | \\fn main() void { |
| 1542 | 1593 | \\ var bad: f128 = 1.0e-1_; |
| 1594 | \\ _ = bad; |
| 1543 | 1595 | \\} |
| 1544 | 1596 | , &[_][]const u8{ |
| 1545 | | "tmp.zig:2:28: error: invalid character: ';'", |
| 1597 | "tmp.zig:2:21: error: expected expression, found 'invalid'", |
| 1598 | "tmp.zig:2:28: note: invalid byte: ';'", |
| 1546 | 1599 | }); |
| 1547 | 1600 | |
| 1548 | | cases.add("invalid underscore placement in float literal - 9", |
| 1601 | ctx.objErrStage1("invalid underscore placement in float literal - 9", |
| 1549 | 1602 | \\fn main() void { |
| 1550 | 1603 | \\ var bad: f128 = 1__0.0e-1; |
| 1604 | \\ _ = bad; |
| 1551 | 1605 | \\} |
| 1552 | 1606 | , &[_][]const u8{ |
| 1553 | | "tmp.zig:2:23: error: invalid character: '_'", |
| 1607 | "tmp.zig:2:21: error: expected expression, found 'invalid'", |
| 1608 | "tmp.zig:2:23: note: invalid byte: '_'", |
| 1554 | 1609 | }); |
| 1555 | 1610 | |
| 1556 | | cases.add("invalid underscore placement in float literal - 10", |
| 1611 | ctx.objErrStage1("invalid underscore placement in float literal - 10", |
| 1557 | 1612 | \\fn main() void { |
| 1558 | 1613 | \\ var bad: f128 = 1.0__0e-1; |
| 1614 | \\ _ = bad; |
| 1559 | 1615 | \\} |
| 1560 | 1616 | , &[_][]const u8{ |
| 1561 | | "tmp.zig:2:25: error: invalid character: '_'", |
| 1617 | "tmp.zig:2:21: error: expected expression, found 'invalid'", |
| 1618 | "tmp.zig:2:25: note: invalid byte: '_'", |
| 1562 | 1619 | }); |
| 1563 | 1620 | |
| 1564 | | cases.add("invalid underscore placement in float literal - 11", |
| 1621 | ctx.objErrStage1("invalid underscore placement in float literal - 11", |
| 1565 | 1622 | \\fn main() void { |
| 1566 | 1623 | \\ var bad: f128 = 1.0e-1__0; |
| 1624 | \\ _ = bad; |
| 1567 | 1625 | \\} |
| 1568 | 1626 | , &[_][]const u8{ |
| 1569 | | "tmp.zig:2:28: error: invalid character: '_'", |
| 1627 | "tmp.zig:2:21: error: expected expression, found 'invalid'", |
| 1628 | "tmp.zig:2:28: note: invalid byte: '_'", |
| 1570 | 1629 | }); |
| 1571 | 1630 | |
| 1572 | | cases.add("invalid underscore placement in float literal - 12", |
| 1631 | ctx.objErrStage1("invalid underscore placement in float literal - 12", |
| 1573 | 1632 | \\fn main() void { |
| 1574 | 1633 | \\ var bad: f128 = 0_x0.0; |
| 1634 | \\ _ = bad; |
| 1575 | 1635 | \\} |
| 1576 | 1636 | , &[_][]const u8{ |
| 1577 | | "tmp.zig:2:23: error: invalid character: 'x'", |
| 1637 | "tmp.zig:2:21: error: expected expression, found 'invalid'", |
| 1638 | "tmp.zig:2:23: note: invalid byte: 'x'", |
| 1578 | 1639 | }); |
| 1579 | 1640 | |
| 1580 | | cases.add("invalid underscore placement in float literal - 13", |
| 1641 | ctx.objErrStage1("invalid underscore placement in float literal - 13", |
| 1581 | 1642 | \\fn main() void { |
| 1582 | 1643 | \\ var bad: f128 = 0x_0.0; |
| 1644 | \\ _ = bad; |
| 1583 | 1645 | \\} |
| 1584 | 1646 | , &[_][]const u8{ |
| 1585 | | "tmp.zig:2:23: error: invalid character: '_'", |
| 1647 | "tmp.zig:2:21: error: expected expression, found 'invalid'", |
| 1648 | "tmp.zig:2:23: note: invalid byte: '_'", |
| 1586 | 1649 | }); |
| 1587 | 1650 | |
| 1588 | | cases.add("invalid underscore placement in float literal - 14", |
| 1651 | ctx.objErrStage1("invalid underscore placement in float literal - 14", |
| 1589 | 1652 | \\fn main() void { |
| 1590 | 1653 | \\ var bad: f128 = 0x0.0_p1; |
| 1654 | \\ _ = bad; |
| 1591 | 1655 | \\} |
| 1592 | 1656 | , &[_][]const u8{ |
| 1593 | | "tmp.zig:2:27: error: invalid character: 'p'", |
| 1657 | "tmp.zig:2:21: error: expected expression, found 'invalid'", |
| 1658 | "tmp.zig:2:27: note: invalid byte: 'p'", |
| 1594 | 1659 | }); |
| 1595 | 1660 | |
| 1596 | | cases.add("invalid underscore placement in int literal - 1", |
| 1661 | ctx.objErrStage1("invalid underscore placement in int literal - 1", |
| 1597 | 1662 | \\fn main() void { |
| 1598 | 1663 | \\ var bad: u128 = 0010_; |
| 1664 | \\ _ = bad; |
| 1599 | 1665 | \\} |
| 1600 | 1666 | , &[_][]const u8{ |
| 1601 | | "tmp.zig:2:26: error: invalid character: ';'", |
| 1667 | "tmp.zig:2:21: error: expected expression, found 'invalid'", |
| 1668 | "tmp.zig:2:26: note: invalid byte: ';'", |
| 1602 | 1669 | }); |
| 1603 | 1670 | |
| 1604 | | cases.add("invalid underscore placement in int literal - 2", |
| 1671 | ctx.objErrStage1("invalid underscore placement in int literal - 2", |
| 1605 | 1672 | \\fn main() void { |
| 1606 | 1673 | \\ var bad: u128 = 0b0010_; |
| 1674 | \\ _ = bad; |
| 1607 | 1675 | \\} |
| 1608 | 1676 | , &[_][]const u8{ |
| 1609 | | "tmp.zig:2:28: error: invalid character: ';'", |
| 1677 | "tmp.zig:2:21: error: expected expression, found 'invalid'", |
| 1678 | "tmp.zig:2:28: note: invalid byte: ';'", |
| 1610 | 1679 | }); |
| 1611 | 1680 | |
| 1612 | | cases.add("invalid underscore placement in int literal - 3", |
| 1681 | ctx.objErrStage1("invalid underscore placement in int literal - 3", |
| 1613 | 1682 | \\fn main() void { |
| 1614 | 1683 | \\ var bad: u128 = 0o0010_; |
| 1684 | \\ _ = bad; |
| 1615 | 1685 | \\} |
| 1616 | 1686 | , &[_][]const u8{ |
| 1617 | | "tmp.zig:2:28: error: invalid character: ';'", |
| 1687 | "tmp.zig:2:21: error: expected expression, found 'invalid'", |
| 1688 | "tmp.zig:2:28: note: invalid byte: ';'", |
| 1618 | 1689 | }); |
| 1619 | 1690 | |
| 1620 | | cases.add("invalid underscore placement in int literal - 4", |
| 1691 | ctx.objErrStage1("invalid underscore placement in int literal - 4", |
| 1621 | 1692 | \\fn main() void { |
| 1622 | 1693 | \\ var bad: u128 = 0x0010_; |
| 1694 | \\ _ = bad; |
| 1623 | 1695 | \\} |
| 1624 | 1696 | , &[_][]const u8{ |
| 1625 | | "tmp.zig:2:28: error: invalid character: ';'", |
| 1697 | "tmp.zig:2:21: error: expected expression, found 'invalid'", |
| 1698 | "tmp.zig:2:28: note: invalid byte: ';'", |
| 1626 | 1699 | }); |
| 1627 | 1700 | |
| 1628 | | cases.add("comptime struct field, no init value", |
| 1701 | ctx.objErrStage1("comptime struct field, no init value", |
| 1629 | 1702 | \\const Foo = struct { |
| 1630 | 1703 | \\ comptime b: i32, |
| 1631 | 1704 | \\}; |
| 1632 | 1705 | \\export fn entry() void { |
| 1633 | 1706 | \\ var f: Foo = undefined; |
| 1707 | \\ _ = f; |
| 1634 | 1708 | \\} |
| 1635 | 1709 | , &[_][]const u8{ |
| 1636 | | "tmp.zig:2:5: error: comptime struct field missing initialization value", |
| 1710 | "tmp.zig:2:5: error: comptime field without default initialization value", |
| 1637 | 1711 | }); |
| 1638 | 1712 | |
| 1639 | | cases.add("bad usage of @call", |
| 1713 | ctx.objErrStage1("bad usage of @call", |
| 1640 | 1714 | \\export fn entry1() void { |
| 1641 | 1715 | \\ @call(.{}, foo, {}); |
| 1642 | 1716 | \\} |
| ... | ... | @@ -1665,20 +1739,26 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1665 | 1739 | "tmp.zig:15:5: error: the specified modifier requires a comptime-known function", |
| 1666 | 1740 | }); |
| 1667 | 1741 | |
| 1668 | | cases.add("exported async function", |
| 1742 | ctx.objErrStage1("exported async function", |
| 1669 | 1743 | \\export fn foo() callconv(.Async) void {} |
| 1670 | 1744 | , &[_][]const u8{ |
| 1671 | 1745 | "tmp.zig:1:1: error: exported function cannot be async", |
| 1672 | 1746 | }); |
| 1673 | 1747 | |
| 1674 | | cases.addExe("main missing name", |
| 1748 | ctx.exeErrStage1("main missing name", |
| 1675 | 1749 | \\pub fn (main) void {} |
| 1676 | 1750 | , &[_][]const u8{ |
| 1677 | 1751 | "tmp.zig:1:5: error: missing function name", |
| 1678 | 1752 | }); |
| 1679 | 1753 | |
| 1680 | | cases.addCase(x: { |
| 1681 | | var tc = cases.create("call with new stack on unsupported target", |
| 1754 | { |
| 1755 | const case = ctx.obj("call with new stack on unsupported target", .{ |
| 1756 | .cpu_arch = .wasm32, |
| 1757 | .os_tag = .wasi, |
| 1758 | .abi = .none, |
| 1759 | }); |
| 1760 | case.backend = .stage1; |
| 1761 | case.addError( |
| 1682 | 1762 | \\var buf: [10]u8 align(16) = undefined; |
| 1683 | 1763 | \\export fn entry() void { |
| 1684 | 1764 | \\ @call(.{.stack = &buf}, foo, .{}); |
| ... | ... | @@ -1687,17 +1767,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1687 | 1767 | , &[_][]const u8{ |
| 1688 | 1768 | "tmp.zig:3:5: error: target arch 'wasm32' does not support calling with a new stack", |
| 1689 | 1769 | }); |
| 1690 | | tc.target = std.zig.CrossTarget{ |
| 1691 | | .cpu_arch = .wasm32, |
| 1692 | | .os_tag = .wasi, |
| 1693 | | .abi = .none, |
| 1694 | | }; |
| 1695 | | break :x tc; |
| 1696 | | }); |
| 1770 | } |
| 1697 | 1771 | |
| 1698 | 1772 | // Note: One of the error messages here is backwards. It would be nice to fix, but that's not |
| 1699 | 1773 | // going to stop me from merging this branch which fixes a bunch of other stuff. |
| 1700 | | cases.add("incompatible sentinels", |
| 1774 | ctx.objErrStage1("incompatible sentinels", |
| 1701 | 1775 | \\export fn entry1(ptr: [*:255]u8) [*:0]u8 { |
| 1702 | 1776 | \\ return ptr; |
| 1703 | 1777 | \\} |
| ... | ... | @@ -1706,9 +1780,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1706 | 1780 | \\} |
| 1707 | 1781 | \\export fn entry3() void { |
| 1708 | 1782 | \\ var array: [2:0]u8 = [_:255]u8{1, 2}; |
| 1783 | \\ _ = array; |
| 1709 | 1784 | \\} |
| 1710 | 1785 | \\export fn entry4() void { |
| 1711 | 1786 | \\ var array: [2:0]u8 = [_]u8{1, 2}; |
| 1787 | \\ _ = array; |
| 1712 | 1788 | \\} |
| 1713 | 1789 | , &[_][]const u8{ |
| 1714 | 1790 | "tmp.zig:2:12: error: expected type '[*:0]u8', found '[*:255]u8'", |
| ... | ... | @@ -1718,11 +1794,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1718 | 1794 | |
| 1719 | 1795 | "tmp.zig:8:35: error: expected type '[2:255]u8', found '[2:0]u8'", |
| 1720 | 1796 | "tmp.zig:8:35: note: destination array requires a terminating '255' sentinel, but source array has a terminating '0' sentinel", |
| 1721 | | "tmp.zig:11:31: error: expected type '[2:0]u8', found '[2]u8'", |
| 1722 | | "tmp.zig:11:31: note: destination array requires a terminating '0' sentinel", |
| 1797 | "tmp.zig:12:31: error: expected type '[2:0]u8', found '[2]u8'", |
| 1798 | "tmp.zig:12:31: note: destination array requires a terminating '0' sentinel", |
| 1723 | 1799 | }); |
| 1724 | 1800 | |
| 1725 | | cases.add("empty switch on an integer", |
| 1801 | ctx.objErrStage1("empty switch on an integer", |
| 1726 | 1802 | \\export fn entry() void { |
| 1727 | 1803 | \\ var x: u32 = 0; |
| 1728 | 1804 | \\ switch(x) {} |
| ... | ... | @@ -1731,7 +1807,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1731 | 1807 | "tmp.zig:3:5: error: switch must handle all possibilities", |
| 1732 | 1808 | }); |
| 1733 | 1809 | |
| 1734 | | cases.add("incorrect return type", |
| 1810 | ctx.objErrStage1("incorrect return type", |
| 1735 | 1811 | \\ pub export fn entry() void{ |
| 1736 | 1812 | \\ _ = foo(); |
| 1737 | 1813 | \\ } |
| ... | ... | @@ -1751,12 +1827,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1751 | 1827 | "tmp.zig:8:16: error: expected type 'A', found 'B'", |
| 1752 | 1828 | }); |
| 1753 | 1829 | |
| 1754 | | cases.add("regression test #2980: base type u32 is not type checked properly when assigning a value within a struct", |
| 1830 | ctx.objErrStage1("regression test #2980: base type u32 is not type checked properly when assigning a value within a struct", |
| 1755 | 1831 | \\const Foo = struct { |
| 1756 | 1832 | \\ ptr: ?*usize, |
| 1757 | 1833 | \\ uval: u32, |
| 1758 | 1834 | \\}; |
| 1759 | 1835 | \\fn get_uval(x: u32) !u32 { |
| 1836 | \\ _ = x; |
| 1760 | 1837 | \\ return error.NotFound; |
| 1761 | 1838 | \\} |
| 1762 | 1839 | \\export fn entry() void { |
| ... | ... | @@ -1764,12 +1841,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1764 | 1841 | \\ .ptr = null, |
| 1765 | 1842 | \\ .uval = get_uval(42), |
| 1766 | 1843 | \\ }; |
| 1844 | \\ _ = afoo; |
| 1767 | 1845 | \\} |
| 1768 | 1846 | , &[_][]const u8{ |
| 1769 | | "tmp.zig:11:25: error: expected type 'u32', found '@typeInfo(@typeInfo(@TypeOf(get_uval)).Fn.return_type.?).ErrorUnion.error_set!u32'", |
| 1847 | "tmp.zig:12:25: error: expected type 'u32', found '@typeInfo(@typeInfo(@TypeOf(get_uval)).Fn.return_type.?).ErrorUnion.error_set!u32'", |
| 1770 | 1848 | }); |
| 1771 | 1849 | |
| 1772 | | cases.add("assigning to struct or union fields that are not optionals with a function that returns an optional", |
| 1850 | ctx.objErrStage1("assigning to struct or union fields that are not optionals with a function that returns an optional", |
| 1773 | 1851 | \\fn maybe(is: bool) ?u8 { |
| 1774 | 1852 | \\ if (is) return @as(u8, 10) else return null; |
| 1775 | 1853 | \\} |
| ... | ... | @@ -1782,12 +1860,14 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1782 | 1860 | \\export fn entry() void { |
| 1783 | 1861 | \\ var u = U{ .Ye = maybe(false) }; |
| 1784 | 1862 | \\ var s = S{ .num = maybe(false) }; |
| 1863 | \\ _ = u; |
| 1864 | \\ _ = s; |
| 1785 | 1865 | \\} |
| 1786 | 1866 | , &[_][]const u8{ |
| 1787 | 1867 | "tmp.zig:11:27: error: expected type 'u8', found '?u8'", |
| 1788 | 1868 | }); |
| 1789 | 1869 | |
| 1790 | | cases.add("missing result type for phi node", |
| 1870 | ctx.objErrStage1("missing result type for phi node", |
| 1791 | 1871 | \\fn foo() !void { |
| 1792 | 1872 | \\ return anyerror.Foo; |
| 1793 | 1873 | \\} |
| ... | ... | @@ -1798,7 +1878,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1798 | 1878 | "tmp.zig:5:17: error: integer value 0 cannot be coerced to type 'void'", |
| 1799 | 1879 | }); |
| 1800 | 1880 | |
| 1801 | | cases.add("atomicrmw with enum op not .Xchg", |
| 1881 | ctx.objErrStage1("atomicrmw with enum op not .Xchg", |
| 1802 | 1882 | \\export fn entry() void { |
| 1803 | 1883 | \\ const E = enum(u8) { |
| 1804 | 1884 | \\ a, |
| ... | ... | @@ -1813,7 +1893,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1813 | 1893 | "tmp.zig:9:27: error: @atomicRmw with enum only allowed with .Xchg", |
| 1814 | 1894 | }); |
| 1815 | 1895 | |
| 1816 | | cases.add("disallow coercion from non-null-terminated pointer to null-terminated pointer", |
| 1896 | ctx.objErrStage1("disallow coercion from non-null-terminated pointer to null-terminated pointer", |
| 1817 | 1897 | \\extern fn puts(s: [*:0]const u8) c_int; |
| 1818 | 1898 | \\pub fn main() void { |
| 1819 | 1899 | \\ const no_zero_array = [_]u8{'h', 'e', 'l', 'l', 'o'}; |
| ... | ... | @@ -1824,7 +1904,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1824 | 1904 | "tmp.zig:5:14: error: expected type '[*:0]const u8', found '[*]const u8'", |
| 1825 | 1905 | }); |
| 1826 | 1906 | |
| 1827 | | cases.add("atomic orderings of atomicStore Acquire or AcqRel", |
| 1907 | ctx.objErrStage1("atomic orderings of atomicStore Acquire or AcqRel", |
| 1828 | 1908 | \\export fn entry() void { |
| 1829 | 1909 | \\ var x: u32 = 0; |
| 1830 | 1910 | \\ @atomicStore(u32, &x, 1, .Acquire); |
| ... | ... | @@ -1833,7 +1913,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1833 | 1913 | "tmp.zig:3:30: error: @atomicStore atomic ordering must not be Acquire or AcqRel", |
| 1834 | 1914 | }); |
| 1835 | 1915 | |
| 1836 | | cases.add("missing const in slice with nested array type", |
| 1916 | ctx.objErrStage1("missing const in slice with nested array type", |
| 1837 | 1917 | \\const Geo3DTex2D = struct { vertices: [][2]f32 }; |
| 1838 | 1918 | \\pub fn getGeo3DTex2D() Geo3DTex2D { |
| 1839 | 1919 | \\ return Geo3DTex2D{ |
| ... | ... | @@ -1844,12 +1924,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1844 | 1924 | \\} |
| 1845 | 1925 | \\export fn entry() void { |
| 1846 | 1926 | \\ var geo_data = getGeo3DTex2D(); |
| 1927 | \\ _ = geo_data; |
| 1847 | 1928 | \\} |
| 1848 | 1929 | , &[_][]const u8{ |
| 1849 | 1930 | "tmp.zig:4:30: error: array literal requires address-of operator to coerce to slice type '[][2]f32'", |
| 1850 | 1931 | }); |
| 1851 | 1932 | |
| 1852 | | cases.add("slicing of global undefined pointer", |
| 1933 | ctx.objErrStage1("slicing of global undefined pointer", |
| 1853 | 1934 | \\var buf: *[1]u8 = undefined; |
| 1854 | 1935 | \\export fn entry() void { |
| 1855 | 1936 | \\ _ = buf[0..1]; |
| ... | ... | @@ -1858,18 +1939,17 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1858 | 1939 | "tmp.zig:3:12: error: non-zero length slice of undefined pointer", |
| 1859 | 1940 | }); |
| 1860 | 1941 | |
| 1861 | | cases.add("using invalid types in function call raises an error", |
| 1942 | ctx.objErrStage1("using invalid types in function call raises an error", |
| 1862 | 1943 | \\const MenuEffect = enum {}; |
| 1863 | | \\fn func(effect: MenuEffect) void {} |
| 1944 | \\fn func(effect: MenuEffect) void { _ = effect; } |
| 1864 | 1945 | \\export fn entry() void { |
| 1865 | 1946 | \\ func(MenuEffect.ThisDoesNotExist); |
| 1866 | 1947 | \\} |
| 1867 | 1948 | , &[_][]const u8{ |
| 1868 | | "tmp.zig:1:20: error: enums must have 1 or more fields", |
| 1869 | | "tmp.zig:4:20: note: referenced here", |
| 1949 | "tmp.zig:1:20: error: enum declarations must have at least one tag", |
| 1870 | 1950 | }); |
| 1871 | 1951 | |
| 1872 | | cases.add("store vector pointer with unknown runtime index", |
| 1952 | ctx.objErrStage1("store vector pointer with unknown runtime index", |
| 1873 | 1953 | \\export fn entry() void { |
| 1874 | 1954 | \\ var v: @import("std").meta.Vector(4, i32) = [_]i32{ 1, 5, 3, undefined }; |
| 1875 | 1955 | \\ |
| ... | ... | @@ -1884,22 +1964,23 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1884 | 1964 | "tmp.zig:9:8: error: unable to determine vector element index of type '*align(16:0:4:?) i32", |
| 1885 | 1965 | }); |
| 1886 | 1966 | |
| 1887 | | cases.add("load vector pointer with unknown runtime index", |
| 1967 | ctx.objErrStage1("load vector pointer with unknown runtime index", |
| 1888 | 1968 | \\export fn entry() void { |
| 1889 | 1969 | \\ var v: @import("std").meta.Vector(4, i32) = [_]i32{ 1, 5, 3, undefined }; |
| 1890 | 1970 | \\ |
| 1891 | 1971 | \\ var i: u32 = 0; |
| 1892 | 1972 | \\ var x = loadv(&v[i]); |
| 1973 | \\ _ = x; |
| 1893 | 1974 | \\} |
| 1894 | 1975 | \\ |
| 1895 | 1976 | \\fn loadv(ptr: anytype) i32 { |
| 1896 | 1977 | \\ return ptr.*; |
| 1897 | 1978 | \\} |
| 1898 | 1979 | , &[_][]const u8{ |
| 1899 | | "tmp.zig:9:12: error: unable to determine vector element index of type '*align(16:0:4:?) i32", |
| 1980 | "tmp.zig:10:12: error: unable to determine vector element index of type '*align(16:0:4:?) i32", |
| 1900 | 1981 | }); |
| 1901 | 1982 | |
| 1902 | | cases.add("using an unknown len ptr type instead of array", |
| 1983 | ctx.objErrStage1("using an unknown len ptr type instead of array", |
| 1903 | 1984 | \\const resolutions = [*][*]const u8{ |
| 1904 | 1985 | \\ "[320 240 ]", |
| 1905 | 1986 | \\ null, |
| ... | ... | @@ -1911,7 +1992,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1911 | 1992 | "tmp.zig:1:21: error: expected array type or [_], found '[*][*]const u8'", |
| 1912 | 1993 | }); |
| 1913 | 1994 | |
| 1914 | | cases.add("comparison with error union and error value", |
| 1995 | ctx.objErrStage1("comparison with error union and error value", |
| 1915 | 1996 | \\export fn entry() void { |
| 1916 | 1997 | \\ var number_or_error: anyerror!i32 = error.SomethingAwful; |
| 1917 | 1998 | \\ _ = number_or_error == error.SomethingAwful; |
| ... | ... | @@ -1920,7 +2001,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1920 | 2001 | "tmp.zig:3:25: error: operator not allowed for type 'anyerror!i32'", |
| 1921 | 2002 | }); |
| 1922 | 2003 | |
| 1923 | | cases.add("switch with overlapping case ranges", |
| 2004 | ctx.objErrStage1("switch with overlapping case ranges", |
| 1924 | 2005 | \\export fn entry() void { |
| 1925 | 2006 | \\ var q: u8 = 0; |
| 1926 | 2007 | \\ switch (q) { |
| ... | ... | @@ -1932,28 +2013,29 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1932 | 2013 | "tmp.zig:5:9: error: duplicate switch value", |
| 1933 | 2014 | }); |
| 1934 | 2015 | |
| 1935 | | cases.add("invalid optional type in extern struct", |
| 2016 | ctx.objErrStage1("invalid optional type in extern struct", |
| 1936 | 2017 | \\const stroo = extern struct { |
| 1937 | 2018 | \\ moo: ?[*c]u8, |
| 1938 | 2019 | \\}; |
| 1939 | | \\export fn testf(fluff: *stroo) void {} |
| 2020 | \\export fn testf(fluff: *stroo) void { _ = fluff; } |
| 1940 | 2021 | , &[_][]const u8{ |
| 1941 | 2022 | "tmp.zig:2:5: error: extern structs cannot contain fields of type '?[*c]u8'", |
| 1942 | 2023 | }); |
| 1943 | 2024 | |
| 1944 | | cases.add("attempt to negate a non-integer, non-float or non-vector type", |
| 2025 | ctx.objErrStage1("attempt to negate a non-integer, non-float or non-vector type", |
| 1945 | 2026 | \\fn foo() anyerror!u32 { |
| 1946 | 2027 | \\ return 1; |
| 1947 | 2028 | \\} |
| 1948 | 2029 | \\ |
| 1949 | 2030 | \\export fn entry() void { |
| 1950 | 2031 | \\ const x = -foo(); |
| 2032 | \\ _ = x; |
| 1951 | 2033 | \\} |
| 1952 | 2034 | , &[_][]const u8{ |
| 1953 | 2035 | "tmp.zig:6:15: error: negation of type 'anyerror!u32'", |
| 1954 | 2036 | }); |
| 1955 | 2037 | |
| 1956 | | cases.add("attempt to create 17 bit float type", |
| 2038 | ctx.objErrStage1("attempt to create 17 bit float type", |
| 1957 | 2039 | \\const builtin = @import("std").builtin; |
| 1958 | 2040 | \\comptime { |
| 1959 | 2041 | \\ _ = @Type(builtin.TypeInfo { .Float = builtin.TypeInfo.Float { .bits = 17 } }); |
| ... | ... | @@ -1962,7 +2044,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1962 | 2044 | "tmp.zig:3:32: error: 17-bit float unsupported", |
| 1963 | 2045 | }); |
| 1964 | 2046 | |
| 1965 | | cases.add("wrong type for @Type", |
| 2047 | ctx.objErrStage1("wrong type for @Type", |
| 1966 | 2048 | \\export fn entry() void { |
| 1967 | 2049 | \\ _ = @Type(0); |
| 1968 | 2050 | \\} |
| ... | ... | @@ -1970,7 +2052,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1970 | 2052 | "tmp.zig:2:15: error: expected type 'std.builtin.TypeInfo', found 'comptime_int'", |
| 1971 | 2053 | }); |
| 1972 | 2054 | |
| 1973 | | cases.add("@Type with non-constant expression", |
| 2055 | ctx.objErrStage1("@Type with non-constant expression", |
| 1974 | 2056 | \\const builtin = @import("std").builtin; |
| 1975 | 2057 | \\var globalTypeInfo : builtin.TypeInfo = undefined; |
| 1976 | 2058 | \\export fn entry() void { |
| ... | ... | @@ -1980,7 +2062,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1980 | 2062 | "tmp.zig:4:15: error: unable to evaluate constant expression", |
| 1981 | 2063 | }); |
| 1982 | 2064 | |
| 1983 | | cases.add("wrong type for argument tuple to @asyncCall", |
| 2065 | ctx.objErrStage1("wrong type for argument tuple to @asyncCall", |
| 1984 | 2066 | \\export fn entry1() void { |
| 1985 | 2067 | \\ var frame: @Frame(foo) = undefined; |
| 1986 | 2068 | \\ @asyncCall(&frame, {}, foo, {}); |
| ... | ... | @@ -1993,7 +2075,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1993 | 2075 | "tmp.zig:3:33: error: expected tuple or struct, found 'void'", |
| 1994 | 2076 | }); |
| 1995 | 2077 | |
| 1996 | | cases.add("wrong type for result ptr to @asyncCall", |
| 2078 | ctx.objErrStage1("wrong type for result ptr to @asyncCall", |
| 1997 | 2079 | \\export fn entry() void { |
| 1998 | 2080 | \\ _ = async amain(); |
| 1999 | 2081 | \\} |
| ... | ... | @@ -2008,25 +2090,27 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2008 | 2090 | "tmp.zig:6:37: error: expected type '*i32', found 'bool'", |
| 2009 | 2091 | }); |
| 2010 | 2092 | |
| 2011 | | cases.add("shift amount has to be an integer type", |
| 2093 | ctx.objErrStage1("shift amount has to be an integer type", |
| 2012 | 2094 | \\export fn entry() void { |
| 2013 | 2095 | \\ const x = 1 << &@as(u8, 10); |
| 2096 | \\ _ = x; |
| 2014 | 2097 | \\} |
| 2015 | 2098 | , &[_][]const u8{ |
| 2016 | 2099 | "tmp.zig:2:21: error: shift amount has to be an integer type, but found '*const u8'", |
| 2017 | 2100 | "tmp.zig:2:17: note: referenced here", |
| 2018 | 2101 | }); |
| 2019 | 2102 | |
| 2020 | | cases.add("bit shifting only works on integer types", |
| 2103 | ctx.objErrStage1("bit shifting only works on integer types", |
| 2021 | 2104 | \\export fn entry() void { |
| 2022 | 2105 | \\ const x = &@as(u8, 1) << 10; |
| 2106 | \\ _ = x; |
| 2023 | 2107 | \\} |
| 2024 | 2108 | , &[_][]const u8{ |
| 2025 | 2109 | "tmp.zig:2:16: error: bit shifting operation expected integer type, found '*const u8'", |
| 2026 | 2110 | "tmp.zig:2:27: note: referenced here", |
| 2027 | 2111 | }); |
| 2028 | 2112 | |
| 2029 | | cases.add("struct depends on itself via optional field", |
| 2113 | ctx.objErrStage1("struct depends on itself via optional field", |
| 2030 | 2114 | \\const LhsExpr = struct { |
| 2031 | 2115 | \\ rhsExpr: ?AstObject, |
| 2032 | 2116 | \\}; |
| ... | ... | @@ -2036,6 +2120,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2036 | 2120 | \\export fn entry() void { |
| 2037 | 2121 | \\ const lhsExpr = LhsExpr{ .rhsExpr = null }; |
| 2038 | 2122 | \\ const obj = AstObject{ .lhsExpr = lhsExpr }; |
| 2123 | \\ _ = obj; |
| 2039 | 2124 | \\} |
| 2040 | 2125 | , &[_][]const u8{ |
| 2041 | 2126 | "tmp.zig:1:17: error: struct 'LhsExpr' depends on itself", |
| ... | ... | @@ -2043,51 +2128,54 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2043 | 2128 | "tmp.zig:2:5: note: while checking this field", |
| 2044 | 2129 | }); |
| 2045 | 2130 | |
| 2046 | | cases.add("alignment of enum field specified", |
| 2131 | ctx.objErrStage1("alignment of enum field specified", |
| 2047 | 2132 | \\const Number = enum { |
| 2048 | 2133 | \\ a, |
| 2049 | 2134 | \\ b align(i32), |
| 2050 | 2135 | \\}; |
| 2051 | 2136 | \\export fn entry1() void { |
| 2052 | 2137 | \\ var x: Number = undefined; |
| 2138 | \\ _ = x; |
| 2053 | 2139 | \\} |
| 2054 | 2140 | , &[_][]const u8{ |
| 2055 | | "tmp.zig:3:13: error: structs and unions, not enums, support field alignment", |
| 2056 | | "tmp.zig:1:16: note: consider 'union(enum)' here", |
| 2141 | "tmp.zig:3:7: error: expected ',', found 'align'", |
| 2057 | 2142 | }); |
| 2058 | 2143 | |
| 2059 | | cases.add("bad alignment type", |
| 2144 | ctx.objErrStage1("bad alignment type", |
| 2060 | 2145 | \\export fn entry1() void { |
| 2061 | 2146 | \\ var x: []align(true) i32 = undefined; |
| 2147 | \\ _ = x; |
| 2062 | 2148 | \\} |
| 2063 | 2149 | \\export fn entry2() void { |
| 2064 | 2150 | \\ var x: *align(@as(f64, 12.34)) i32 = undefined; |
| 2151 | \\ _ = x; |
| 2065 | 2152 | \\} |
| 2066 | 2153 | , &[_][]const u8{ |
| 2067 | 2154 | "tmp.zig:2:20: error: expected type 'u29', found 'bool'", |
| 2068 | | "tmp.zig:5:19: error: fractional component prevents float value 12.340000 from being casted to type 'u29'", |
| 2155 | "tmp.zig:6:19: error: fractional component prevents float value 12.340000 from being casted to type 'u29'", |
| 2069 | 2156 | }); |
| 2070 | 2157 | |
| 2071 | | cases.addCase(x: { |
| 2072 | | var tc = cases.create("variable in inline assembly template cannot be found", |
| 2158 | { |
| 2159 | const case = ctx.obj("variable in inline assembly template cannot be found", .{ |
| 2160 | .cpu_arch = .x86_64, |
| 2161 | .os_tag = .linux, |
| 2162 | .abi = .gnu, |
| 2163 | }); |
| 2164 | case.backend = .stage1; |
| 2165 | case.addError( |
| 2073 | 2166 | \\export fn entry() void { |
| 2074 | 2167 | \\ var sp = asm volatile ( |
| 2075 | 2168 | \\ "mov %[foo], sp" |
| 2076 | 2169 | \\ : [bar] "=r" (-> usize) |
| 2077 | 2170 | \\ ); |
| 2171 | \\ _ = sp; |
| 2078 | 2172 | \\} |
| 2079 | 2173 | , &[_][]const u8{ |
| 2080 | 2174 | "tmp.zig:2:14: error: could not find 'foo' in the inputs or outputs", |
| 2081 | 2175 | }); |
| 2082 | | tc.target = std.zig.CrossTarget{ |
| 2083 | | .cpu_arch = .x86_64, |
| 2084 | | .os_tag = .linux, |
| 2085 | | .abi = .gnu, |
| 2086 | | }; |
| 2087 | | break :x tc; |
| 2088 | | }); |
| 2176 | } |
| 2089 | 2177 | |
| 2090 | | cases.add("indirect recursion of async functions detected", |
| 2178 | ctx.objErrStage1("indirect recursion of async functions detected", |
| 2091 | 2179 | \\var frame: ?anyframe = null; |
| 2092 | 2180 | \\ |
| 2093 | 2181 | \\export fn a() void { |
| ... | ... | @@ -2122,7 +2210,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2122 | 2210 | "tmp.zig:26:25: note: when analyzing type '@Frame(rangeSumIndirect)' here", |
| 2123 | 2211 | }); |
| 2124 | 2212 | |
| 2125 | | cases.add("non-async function pointer eventually is inferred to become async", |
| 2213 | ctx.objErrStage1("non-async function pointer eventually is inferred to become async", |
| 2126 | 2214 | \\export fn a() void { |
| 2127 | 2215 | \\ var non_async_fn: fn () void = undefined; |
| 2128 | 2216 | \\ non_async_fn = func; |
| ... | ... | @@ -2136,20 +2224,26 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2136 | 2224 | "tmp.zig:6:5: note: suspends here", |
| 2137 | 2225 | }); |
| 2138 | 2226 | |
| 2139 | | cases.add("bad alignment in @asyncCall", |
| 2140 | | \\export fn entry() void { |
| 2141 | | \\ var ptr: fn () callconv(.Async) void = func; |
| 2142 | | \\ var bytes: [64]u8 = undefined; |
| 2143 | | \\ _ = @asyncCall(&bytes, {}, ptr, .{}); |
| 2144 | | \\} |
| 2145 | | \\fn func() callconv(.Async) void {} |
| 2146 | | , &[_][]const u8{ |
| 2147 | | // Split the check in two as the alignment value is target dependent. |
| 2148 | | "tmp.zig:4:21: error: expected type '[]align(", |
| 2149 | | ") u8', found '*[64]u8'", |
| 2150 | | }); |
| 2227 | { |
| 2228 | const case = ctx.obj("bad alignment in @asyncCall", .{ |
| 2229 | .cpu_arch = .aarch64, |
| 2230 | .os_tag = .linux, |
| 2231 | .abi = .none, |
| 2232 | }); |
| 2233 | case.backend = .stage1; |
| 2234 | case.addError( |
| 2235 | \\export fn entry() void { |
| 2236 | \\ var ptr: fn () callconv(.Async) void = func; |
| 2237 | \\ var bytes: [64]u8 = undefined; |
| 2238 | \\ _ = @asyncCall(&bytes, {}, ptr, .{}); |
| 2239 | \\} |
| 2240 | \\fn func() callconv(.Async) void {} |
| 2241 | , &[_][]const u8{ |
| 2242 | "tmp.zig:4:21: error: expected type '[]align(8) u8', found '*[64]u8'", |
| 2243 | }); |
| 2244 | } |
| 2151 | 2245 | |
| 2152 | | cases.add("atomic orderings of fence Acquire or stricter", |
| 2246 | ctx.objErrStage1("atomic orderings of fence Acquire or stricter", |
| 2153 | 2247 | \\export fn entry() void { |
| 2154 | 2248 | \\ @fence(.Monotonic); |
| 2155 | 2249 | \\} |
| ... | ... | @@ -2157,20 +2251,22 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2157 | 2251 | "tmp.zig:2:12: error: atomic ordering must be Acquire or stricter", |
| 2158 | 2252 | }); |
| 2159 | 2253 | |
| 2160 | | cases.add("bad alignment in implicit cast from array pointer to slice", |
| 2254 | ctx.objErrStage1("bad alignment in implicit cast from array pointer to slice", |
| 2161 | 2255 | \\export fn a() void { |
| 2162 | 2256 | \\ var x: [10]u8 = undefined; |
| 2163 | 2257 | \\ var y: []align(16) u8 = &x; |
| 2258 | \\ _ = y; |
| 2164 | 2259 | \\} |
| 2165 | 2260 | , &[_][]const u8{ |
| 2166 | 2261 | "tmp.zig:3:30: error: expected type '[]align(16) u8', found '*[10]u8'", |
| 2167 | 2262 | }); |
| 2168 | 2263 | |
| 2169 | | cases.add("result location incompatibility mismatching handle_is_ptr (generic call)", |
| 2264 | ctx.objErrStage1("result location incompatibility mismatching handle_is_ptr (generic call)", |
| 2170 | 2265 | \\export fn entry() void { |
| 2171 | 2266 | \\ var damn = Container{ |
| 2172 | 2267 | \\ .not_optional = getOptional(i32), |
| 2173 | 2268 | \\ }; |
| 2269 | \\ _ = damn; |
| 2174 | 2270 | \\} |
| 2175 | 2271 | \\pub fn getOptional(comptime T: type) ?T { |
| 2176 | 2272 | \\ return 0; |
| ... | ... | @@ -2182,11 +2278,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2182 | 2278 | "tmp.zig:3:36: error: expected type 'i32', found '?i32'", |
| 2183 | 2279 | }); |
| 2184 | 2280 | |
| 2185 | | cases.add("result location incompatibility mismatching handle_is_ptr", |
| 2281 | ctx.objErrStage1("result location incompatibility mismatching handle_is_ptr", |
| 2186 | 2282 | \\export fn entry() void { |
| 2187 | 2283 | \\ var damn = Container{ |
| 2188 | 2284 | \\ .not_optional = getOptional(), |
| 2189 | 2285 | \\ }; |
| 2286 | \\ _ = damn; |
| 2190 | 2287 | \\} |
| 2191 | 2288 | \\pub fn getOptional() ?i32 { |
| 2192 | 2289 | \\ return 0; |
| ... | ... | @@ -2198,7 +2295,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2198 | 2295 | "tmp.zig:3:36: error: expected type 'i32', found '?i32'", |
| 2199 | 2296 | }); |
| 2200 | 2297 | |
| 2201 | | cases.add("const frame cast to anyframe", |
| 2298 | ctx.objErrStage1("const frame cast to anyframe", |
| 2202 | 2299 | \\export fn a() void { |
| 2203 | 2300 | \\ const f = async func(); |
| 2204 | 2301 | \\ resume f; |
| ... | ... | @@ -2206,6 +2303,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2206 | 2303 | \\export fn b() void { |
| 2207 | 2304 | \\ const f = async func(); |
| 2208 | 2305 | \\ var x: anyframe = &f; |
| 2306 | \\ _ = x; |
| 2209 | 2307 | \\} |
| 2210 | 2308 | \\fn func() void { |
| 2211 | 2309 | \\ suspend {} |
| ... | ... | @@ -2215,27 +2313,30 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2215 | 2313 | "tmp.zig:7:24: error: expected type 'anyframe', found '*const @Frame(func)'", |
| 2216 | 2314 | }); |
| 2217 | 2315 | |
| 2218 | | cases.add("prevent bad implicit casting of anyframe types", |
| 2316 | ctx.objErrStage1("prevent bad implicit casting of anyframe types", |
| 2219 | 2317 | \\export fn a() void { |
| 2220 | 2318 | \\ var x: anyframe = undefined; |
| 2221 | 2319 | \\ var y: anyframe->i32 = x; |
| 2320 | \\ _ = y; |
| 2222 | 2321 | \\} |
| 2223 | 2322 | \\export fn b() void { |
| 2224 | 2323 | \\ var x: i32 = undefined; |
| 2225 | 2324 | \\ var y: anyframe->i32 = x; |
| 2325 | \\ _ = y; |
| 2226 | 2326 | \\} |
| 2227 | 2327 | \\export fn c() void { |
| 2228 | 2328 | \\ var x: @Frame(func) = undefined; |
| 2229 | 2329 | \\ var y: anyframe->i32 = &x; |
| 2330 | \\ _ = y; |
| 2230 | 2331 | \\} |
| 2231 | 2332 | \\fn func() void {} |
| 2232 | 2333 | , &[_][]const u8{ |
| 2233 | 2334 | "tmp.zig:3:28: error: expected type 'anyframe->i32', found 'anyframe'", |
| 2234 | | "tmp.zig:7:28: error: expected type 'anyframe->i32', found 'i32'", |
| 2235 | | "tmp.zig:11:29: error: expected type 'anyframe->i32', found '*@Frame(func)'", |
| 2335 | "tmp.zig:8:28: error: expected type 'anyframe->i32', found 'i32'", |
| 2336 | "tmp.zig:13:29: error: expected type 'anyframe->i32', found '*@Frame(func)'", |
| 2236 | 2337 | }); |
| 2237 | 2338 | |
| 2238 | | cases.add("wrong frame type used for async call", |
| 2339 | ctx.objErrStage1("wrong frame type used for async call", |
| 2239 | 2340 | \\export fn entry() void { |
| 2240 | 2341 | \\ var frame: @Frame(foo) = undefined; |
| 2241 | 2342 | \\ frame = async bar(); |
| ... | ... | @@ -2250,18 +2351,20 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2250 | 2351 | "tmp.zig:3:13: error: expected type '*@Frame(bar)', found '*@Frame(foo)'", |
| 2251 | 2352 | }); |
| 2252 | 2353 | |
| 2253 | | cases.add("@Frame() of generic function", |
| 2354 | ctx.objErrStage1("@Frame() of generic function", |
| 2254 | 2355 | \\export fn entry() void { |
| 2255 | 2356 | \\ var frame: @Frame(func) = undefined; |
| 2357 | \\ _ = frame; |
| 2256 | 2358 | \\} |
| 2257 | 2359 | \\fn func(comptime T: type) void { |
| 2258 | 2360 | \\ var x: T = undefined; |
| 2361 | \\ _ = x; |
| 2259 | 2362 | \\} |
| 2260 | 2363 | , &[_][]const u8{ |
| 2261 | 2364 | "tmp.zig:2:16: error: @Frame() of generic function", |
| 2262 | 2365 | }); |
| 2263 | 2366 | |
| 2264 | | cases.add("@frame() causes function to be async", |
| 2367 | ctx.objErrStage1("@frame() causes function to be async", |
| 2265 | 2368 | \\export fn entry() void { |
| 2266 | 2369 | \\ func(); |
| 2267 | 2370 | \\} |
| ... | ... | @@ -2273,10 +2376,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2273 | 2376 | "tmp.zig:5:9: note: @frame() causes function to be async", |
| 2274 | 2377 | }); |
| 2275 | 2378 | |
| 2276 | | cases.add("invalid suspend in exported function", |
| 2379 | ctx.objErrStage1("invalid suspend in exported function", |
| 2277 | 2380 | \\export fn entry() void { |
| 2278 | 2381 | \\ var frame = async func(); |
| 2279 | 2382 | \\ var result = await frame; |
| 2383 | \\ _ = result; |
| 2280 | 2384 | \\} |
| 2281 | 2385 | \\fn func() void { |
| 2282 | 2386 | \\ suspend {} |
| ... | ... | @@ -2286,7 +2390,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2286 | 2390 | "tmp.zig:3:18: note: await here is a suspend point", |
| 2287 | 2391 | }); |
| 2288 | 2392 | |
| 2289 | | cases.add("async function indirectly depends on its own frame", |
| 2393 | ctx.objErrStage1("async function indirectly depends on its own frame", |
| 2290 | 2394 | \\export fn entry() void { |
| 2291 | 2395 | \\ _ = async amain(); |
| 2292 | 2396 | \\} |
| ... | ... | @@ -2295,6 +2399,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2295 | 2399 | \\} |
| 2296 | 2400 | \\fn other() void { |
| 2297 | 2401 | \\ var x: [@sizeOf(@Frame(amain))]u8 = undefined; |
| 2402 | \\ _ = x; |
| 2298 | 2403 | \\} |
| 2299 | 2404 | , &[_][]const u8{ |
| 2300 | 2405 | "tmp.zig:4:1: error: unable to determine async function frame of 'amain'", |
| ... | ... | @@ -2302,19 +2407,20 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2302 | 2407 | "tmp.zig:8:13: note: referenced here", |
| 2303 | 2408 | }); |
| 2304 | 2409 | |
| 2305 | | cases.add("async function depends on its own frame", |
| 2410 | ctx.objErrStage1("async function depends on its own frame", |
| 2306 | 2411 | \\export fn entry() void { |
| 2307 | 2412 | \\ _ = async amain(); |
| 2308 | 2413 | \\} |
| 2309 | 2414 | \\fn amain() callconv(.Async) void { |
| 2310 | 2415 | \\ var x: [@sizeOf(@Frame(amain))]u8 = undefined; |
| 2416 | \\ _ = x; |
| 2311 | 2417 | \\} |
| 2312 | 2418 | , &[_][]const u8{ |
| 2313 | 2419 | "tmp.zig:4:1: error: cannot resolve '@Frame(amain)': function not fully analyzed yet", |
| 2314 | 2420 | "tmp.zig:5:13: note: referenced here", |
| 2315 | 2421 | }); |
| 2316 | 2422 | |
| 2317 | | cases.add("non async function pointer passed to @asyncCall", |
| 2423 | ctx.objErrStage1("non async function pointer passed to @asyncCall", |
| 2318 | 2424 | \\export fn entry() void { |
| 2319 | 2425 | \\ var ptr = afunc; |
| 2320 | 2426 | \\ var bytes: [100]u8 align(16) = undefined; |
| ... | ... | @@ -2325,7 +2431,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2325 | 2431 | "tmp.zig:4:32: error: expected async function, found 'fn() void'", |
| 2326 | 2432 | }); |
| 2327 | 2433 | |
| 2328 | | cases.add("runtime-known async function called", |
| 2434 | ctx.objErrStage1("runtime-known async function called", |
| 2329 | 2435 | \\export fn entry() void { |
| 2330 | 2436 | \\ _ = async amain(); |
| 2331 | 2437 | \\} |
| ... | ... | @@ -2338,7 +2444,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2338 | 2444 | "tmp.zig:6:12: error: function is not comptime-known; @asyncCall required", |
| 2339 | 2445 | }); |
| 2340 | 2446 | |
| 2341 | | cases.add("runtime-known function called with async keyword", |
| 2447 | ctx.objErrStage1("runtime-known function called with async keyword", |
| 2342 | 2448 | \\export fn entry() void { |
| 2343 | 2449 | \\ var ptr = afunc; |
| 2344 | 2450 | \\ _ = async ptr(); |
| ... | ... | @@ -2349,7 +2455,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2349 | 2455 | "tmp.zig:3:15: error: function is not comptime-known; @asyncCall required", |
| 2350 | 2456 | }); |
| 2351 | 2457 | |
| 2352 | | cases.add("function with ccc indirectly calling async function", |
| 2458 | ctx.objErrStage1("function with ccc indirectly calling async function", |
| 2353 | 2459 | \\export fn entry() void { |
| 2354 | 2460 | \\ foo(); |
| 2355 | 2461 | \\} |
| ... | ... | @@ -2366,7 +2472,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2366 | 2472 | "tmp.zig:8:5: note: suspends here", |
| 2367 | 2473 | }); |
| 2368 | 2474 | |
| 2369 | | cases.add("capture group on switch prong with incompatible payload types", |
| 2475 | ctx.objErrStage1("capture group on switch prong with incompatible payload types", |
| 2370 | 2476 | \\const Union = union(enum) { |
| 2371 | 2477 | \\ A: usize, |
| 2372 | 2478 | \\ B: isize, |
| ... | ... | @@ -2374,7 +2480,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2374 | 2480 | \\comptime { |
| 2375 | 2481 | \\ var u = Union{ .A = 8 }; |
| 2376 | 2482 | \\ switch (u) { |
| 2377 | | \\ .A, .B => |e| unreachable, |
| 2483 | \\ .A, .B => |e| { |
| 2484 | \\ _ = e; |
| 2485 | \\ unreachable; |
| 2486 | \\ }, |
| 2378 | 2487 | \\ } |
| 2379 | 2488 | \\} |
| 2380 | 2489 | , &[_][]const u8{ |
| ... | ... | @@ -2383,7 +2492,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2383 | 2492 | "tmp.zig:8:13: note: type 'isize' here", |
| 2384 | 2493 | }); |
| 2385 | 2494 | |
| 2386 | | cases.add("wrong type to @hasField", |
| 2495 | ctx.objErrStage1("wrong type to @hasField", |
| 2387 | 2496 | \\export fn entry() bool { |
| 2388 | 2497 | \\ return @hasField(i32, "hi"); |
| 2389 | 2498 | \\} |
| ... | ... | @@ -2391,44 +2500,49 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2391 | 2500 | "tmp.zig:2:22: error: type 'i32' does not support @hasField", |
| 2392 | 2501 | }); |
| 2393 | 2502 | |
| 2394 | | cases.add("slice passed as array init type with elems", |
| 2503 | ctx.objErrStage1("slice passed as array init type with elems", |
| 2395 | 2504 | \\export fn entry() void { |
| 2396 | 2505 | \\ const x = []u8{1, 2}; |
| 2506 | \\ _ = x; |
| 2397 | 2507 | \\} |
| 2398 | 2508 | , &[_][]const u8{ |
| 2399 | 2509 | "tmp.zig:2:15: error: array literal requires address-of operator to coerce to slice type '[]u8'", |
| 2400 | 2510 | }); |
| 2401 | 2511 | |
| 2402 | | cases.add("slice passed as array init type", |
| 2512 | ctx.objErrStage1("slice passed as array init type", |
| 2403 | 2513 | \\export fn entry() void { |
| 2404 | 2514 | \\ const x = []u8{}; |
| 2515 | \\ _ = x; |
| 2405 | 2516 | \\} |
| 2406 | 2517 | , &[_][]const u8{ |
| 2407 | 2518 | "tmp.zig:2:15: error: array literal requires address-of operator to coerce to slice type '[]u8'", |
| 2408 | 2519 | }); |
| 2409 | 2520 | |
| 2410 | | cases.add("inferred array size invalid here", |
| 2521 | ctx.objErrStage1("inferred array size invalid here", |
| 2411 | 2522 | \\export fn entry() void { |
| 2412 | 2523 | \\ const x = [_]u8; |
| 2524 | \\ _ = x; |
| 2413 | 2525 | \\} |
| 2414 | 2526 | \\export fn entry2() void { |
| 2415 | 2527 | \\ const S = struct { a: *const [_]u8 }; |
| 2416 | 2528 | \\ var a = .{ S{} }; |
| 2529 | \\ _ = a; |
| 2417 | 2530 | \\} |
| 2418 | 2531 | , &[_][]const u8{ |
| 2419 | | "tmp.zig:2:15: error: inferred array size invalid here", |
| 2420 | | "tmp.zig:5:34: error: inferred array size invalid here", |
| 2532 | "tmp.zig:2:16: error: unable to infer array size", |
| 2533 | "tmp.zig:6:35: error: unable to infer array size", |
| 2421 | 2534 | }); |
| 2422 | 2535 | |
| 2423 | | cases.add("initializing array with struct syntax", |
| 2536 | ctx.objErrStage1("initializing array with struct syntax", |
| 2424 | 2537 | \\export fn entry() void { |
| 2425 | 2538 | \\ const x = [_]u8{ .y = 2 }; |
| 2539 | \\ _ = x; |
| 2426 | 2540 | \\} |
| 2427 | 2541 | , &[_][]const u8{ |
| 2428 | 2542 | "tmp.zig:2:15: error: initializing array with struct syntax", |
| 2429 | 2543 | }); |
| 2430 | 2544 | |
| 2431 | | cases.add("compile error in struct init expression", |
| 2545 | ctx.objErrStage1("compile error in struct init expression", |
| 2432 | 2546 | \\const Foo = struct { |
| 2433 | 2547 | \\ a: i32 = crap, |
| 2434 | 2548 | \\ b: i32, |
| ... | ... | @@ -2437,23 +2551,25 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2437 | 2551 | \\ var x = Foo{ |
| 2438 | 2552 | \\ .b = 5, |
| 2439 | 2553 | \\ }; |
| 2554 | \\ _ = x; |
| 2440 | 2555 | \\} |
| 2441 | 2556 | , &[_][]const u8{ |
| 2442 | 2557 | "tmp.zig:2:14: error: use of undeclared identifier 'crap'", |
| 2443 | 2558 | }); |
| 2444 | 2559 | |
| 2445 | | cases.add("undefined as field type is rejected", |
| 2560 | ctx.objErrStage1("undefined as field type is rejected", |
| 2446 | 2561 | \\const Foo = struct { |
| 2447 | 2562 | \\ a: undefined, |
| 2448 | 2563 | \\}; |
| 2449 | 2564 | \\export fn entry1() void { |
| 2450 | 2565 | \\ const foo: Foo = undefined; |
| 2566 | \\ _ = foo; |
| 2451 | 2567 | \\} |
| 2452 | 2568 | , &[_][]const u8{ |
| 2453 | 2569 | "tmp.zig:2:8: error: use of undefined value here causes undefined behavior", |
| 2454 | 2570 | }); |
| 2455 | 2571 | |
| 2456 | | cases.add("@hasDecl with non-container", |
| 2572 | ctx.objErrStage1("@hasDecl with non-container", |
| 2457 | 2573 | \\export fn entry() void { |
| 2458 | 2574 | \\ _ = @hasDecl(i32, "hi"); |
| 2459 | 2575 | \\} |
| ... | ... | @@ -2461,16 +2577,17 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2461 | 2577 | "tmp.zig:2:18: error: expected struct, enum, or union; found 'i32'", |
| 2462 | 2578 | }); |
| 2463 | 2579 | |
| 2464 | | cases.add("field access of slices", |
| 2580 | ctx.objErrStage1("field access of slices", |
| 2465 | 2581 | \\export fn entry() void { |
| 2466 | 2582 | \\ var slice: []i32 = undefined; |
| 2467 | 2583 | \\ const info = @TypeOf(slice).unknown; |
| 2584 | \\ _ = info; |
| 2468 | 2585 | \\} |
| 2469 | 2586 | , &[_][]const u8{ |
| 2470 | 2587 | "tmp.zig:3:32: error: type 'type' does not support field access", |
| 2471 | 2588 | }); |
| 2472 | 2589 | |
| 2473 | | cases.add("peer cast then implicit cast const pointer to mutable C pointer", |
| 2590 | ctx.objErrStage1("peer cast then implicit cast const pointer to mutable C pointer", |
| 2474 | 2591 | \\export fn func() void { |
| 2475 | 2592 | \\ var strValue: [*c]u8 = undefined; |
| 2476 | 2593 | \\ strValue = strValue orelse ""; |
| ... | ... | @@ -2480,19 +2597,20 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2480 | 2597 | "tmp.zig:3:32: note: cast discards const qualifier", |
| 2481 | 2598 | }); |
| 2482 | 2599 | |
| 2483 | | cases.add("overflow in enum value allocation", |
| 2600 | ctx.objErrStage1("overflow in enum value allocation", |
| 2484 | 2601 | \\const Moo = enum(u8) { |
| 2485 | 2602 | \\ Last = 255, |
| 2486 | 2603 | \\ Over, |
| 2487 | 2604 | \\}; |
| 2488 | 2605 | \\pub fn main() void { |
| 2489 | 2606 | \\ var y = Moo.Last; |
| 2607 | \\ _ = y; |
| 2490 | 2608 | \\} |
| 2491 | 2609 | , &[_][]const u8{ |
| 2492 | 2610 | "tmp.zig:3:5: error: enumeration value 256 too large for type 'u8'", |
| 2493 | 2611 | }); |
| 2494 | 2612 | |
| 2495 | | cases.add("attempt to cast enum literal to error", |
| 2613 | ctx.objErrStage1("attempt to cast enum literal to error", |
| 2496 | 2614 | \\export fn entry() void { |
| 2497 | 2615 | \\ switch (error.Hi) { |
| 2498 | 2616 | \\ .Hi => {}, |
| ... | ... | @@ -2502,7 +2620,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2502 | 2620 | "tmp.zig:3:9: error: expected type 'error{Hi}', found '(enum literal)'", |
| 2503 | 2621 | }); |
| 2504 | 2622 | |
| 2505 | | cases.add("@sizeOf bad type", |
| 2623 | ctx.objErrStage1("@sizeOf bad type", |
| 2506 | 2624 | \\export fn entry() usize { |
| 2507 | 2625 | \\ return @sizeOf(@TypeOf(null)); |
| 2508 | 2626 | \\} |
| ... | ... | @@ -2510,7 +2628,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2510 | 2628 | "tmp.zig:2:20: error: no size available for type '(null)'", |
| 2511 | 2629 | }); |
| 2512 | 2630 | |
| 2513 | | cases.add("generic function where return type is self-referenced", |
| 2631 | ctx.objErrStage1("generic function where return type is self-referenced", |
| 2514 | 2632 | \\fn Foo(comptime T: type) Foo(T) { |
| 2515 | 2633 | \\ return struct{ x: T }; |
| 2516 | 2634 | \\} |
| ... | ... | @@ -2518,34 +2636,37 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2518 | 2636 | \\ const t = Foo(u32) { |
| 2519 | 2637 | \\ .x = 1 |
| 2520 | 2638 | \\ }; |
| 2639 | \\ _ = t; |
| 2521 | 2640 | \\} |
| 2522 | 2641 | , &[_][]const u8{ |
| 2523 | 2642 | "tmp.zig:1:29: error: evaluation exceeded 1000 backwards branches", |
| 2524 | 2643 | "tmp.zig:5:18: note: referenced here", |
| 2525 | 2644 | }); |
| 2526 | 2645 | |
| 2527 | | cases.add("@ptrToInt 0 to non optional pointer", |
| 2646 | ctx.objErrStage1("@ptrToInt 0 to non optional pointer", |
| 2528 | 2647 | \\export fn entry() void { |
| 2529 | 2648 | \\ var b = @intToPtr(*i32, 0); |
| 2649 | \\ _ = b; |
| 2530 | 2650 | \\} |
| 2531 | 2651 | , &[_][]const u8{ |
| 2532 | 2652 | "tmp.zig:2:13: error: pointer type '*i32' does not allow address zero", |
| 2533 | 2653 | }); |
| 2534 | 2654 | |
| 2535 | | cases.add("cast enum literal to enum but it doesn't match", |
| 2655 | ctx.objErrStage1("cast enum literal to enum but it doesn't match", |
| 2536 | 2656 | \\const Foo = enum { |
| 2537 | 2657 | \\ a, |
| 2538 | 2658 | \\ b, |
| 2539 | 2659 | \\}; |
| 2540 | 2660 | \\export fn entry() void { |
| 2541 | 2661 | \\ const x: Foo = .c; |
| 2662 | \\ _ = x; |
| 2542 | 2663 | \\} |
| 2543 | 2664 | , &[_][]const u8{ |
| 2544 | 2665 | "tmp.zig:6:20: error: enum 'Foo' has no field named 'c'", |
| 2545 | 2666 | "tmp.zig:1:13: note: 'Foo' declared here", |
| 2546 | 2667 | }); |
| 2547 | 2668 | |
| 2548 | | cases.add("discarding error value", |
| 2669 | ctx.objErrStage1("discarding error value", |
| 2549 | 2670 | \\export fn entry() void { |
| 2550 | 2671 | \\ _ = foo(); |
| 2551 | 2672 | \\} |
| ... | ... | @@ -2556,7 +2677,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2556 | 2677 | "tmp.zig:2:12: error: error is discarded. consider using `try`, `catch`, or `if`", |
| 2557 | 2678 | }); |
| 2558 | 2679 | |
| 2559 | | cases.add("volatile on global assembly", |
| 2680 | ctx.objErrStage1("volatile on global assembly", |
| 2560 | 2681 | \\comptime { |
| 2561 | 2682 | \\ asm volatile (""); |
| 2562 | 2683 | \\} |
| ... | ... | @@ -2564,7 +2685,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2564 | 2685 | "tmp.zig:2:9: error: volatile is meaningless on global assembly", |
| 2565 | 2686 | }); |
| 2566 | 2687 | |
| 2567 | | cases.add("invalid multiple dereferences", |
| 2688 | ctx.objErrStage1("invalid multiple dereferences", |
| 2568 | 2689 | \\export fn a() void { |
| 2569 | 2690 | \\ var box = Box{ .field = 0 }; |
| 2570 | 2691 | \\ box.*.field = 1; |
| ... | ... | @@ -2582,13 +2703,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2582 | 2703 | "tmp.zig:8:13: error: attempt to dereference non-pointer type 'Box'", |
| 2583 | 2704 | }); |
| 2584 | 2705 | |
| 2585 | | cases.add("usingnamespace with wrong type", |
| 2706 | ctx.objErrStage1("usingnamespace with wrong type", |
| 2586 | 2707 | \\usingnamespace void; |
| 2587 | 2708 | , &[_][]const u8{ |
| 2588 | 2709 | "tmp.zig:1:1: error: expected struct, enum, or union; found 'void'", |
| 2589 | 2710 | }); |
| 2590 | 2711 | |
| 2591 | | cases.add("ignored expression in while continuation", |
| 2712 | ctx.objErrStage1("ignored expression in while continuation", |
| 2592 | 2713 | \\export fn a() void { |
| 2593 | 2714 | \\ while (true) : (bad()) {} |
| 2594 | 2715 | \\} |
| ... | ... | @@ -2609,31 +2730,31 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2609 | 2730 | "tmp.zig:10:25: error: error is ignored. consider using `try`, `catch`, or `if`", |
| 2610 | 2731 | }); |
| 2611 | 2732 | |
| 2612 | | cases.add("empty while loop body", |
| 2733 | ctx.objErrStage1("empty while loop body", |
| 2613 | 2734 | \\export fn a() void { |
| 2614 | 2735 | \\ while(true); |
| 2615 | 2736 | \\} |
| 2616 | 2737 | , &[_][]const u8{ |
| 2617 | | "tmp.zig:2:16: error: expected loop body, found ';'", |
| 2738 | "tmp.zig:2:16: error: expected block or assignment, found ';'", |
| 2618 | 2739 | }); |
| 2619 | 2740 | |
| 2620 | | cases.add("empty for loop body", |
| 2741 | ctx.objErrStage1("empty for loop body", |
| 2621 | 2742 | \\export fn a() void { |
| 2622 | 2743 | \\ for(undefined) |x|; |
| 2623 | 2744 | \\} |
| 2624 | 2745 | , &[_][]const u8{ |
| 2625 | | "tmp.zig:2:23: error: expected loop body, found ';'", |
| 2746 | "tmp.zig:2:23: error: expected block or assignment, found ';'", |
| 2626 | 2747 | }); |
| 2627 | 2748 | |
| 2628 | | cases.add("empty if body", |
| 2749 | ctx.objErrStage1("empty if body", |
| 2629 | 2750 | \\export fn a() void { |
| 2630 | 2751 | \\ if(true); |
| 2631 | 2752 | \\} |
| 2632 | 2753 | , &[_][]const u8{ |
| 2633 | | "tmp.zig:2:13: error: expected if body, found ';'", |
| 2754 | "tmp.zig:2:13: error: expected block or assignment, found ';'", |
| 2634 | 2755 | }); |
| 2635 | 2756 | |
| 2636 | | cases.add("import outside package path", |
| 2757 | ctx.objErrStage1("import outside package path", |
| 2637 | 2758 | \\comptime{ |
| 2638 | 2759 | \\ _ = @import("../a.zig"); |
| 2639 | 2760 | \\} |
| ... | ... | @@ -2641,14 +2762,14 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2641 | 2762 | "tmp.zig:2:9: error: import of file outside package path: '../a.zig'", |
| 2642 | 2763 | }); |
| 2643 | 2764 | |
| 2644 | | cases.add("bogus compile var", |
| 2765 | ctx.objErrStage1("bogus compile var", |
| 2645 | 2766 | \\const x = @import("builtin").bogus; |
| 2646 | 2767 | \\export fn entry() usize { return @sizeOf(@TypeOf(x)); } |
| 2647 | 2768 | , &[_][]const u8{ |
| 2648 | 2769 | "tmp.zig:1:29: error: container 'builtin' has no member called 'bogus'", |
| 2649 | 2770 | }); |
| 2650 | 2771 | |
| 2651 | | cases.add("wrong panic signature, runtime function", |
| 2772 | ctx.objErrStage1("wrong panic signature, runtime function", |
| 2652 | 2773 | \\test "" {} |
| 2653 | 2774 | \\ |
| 2654 | 2775 | \\pub fn panic() void {} |
| ... | ... | @@ -2657,8 +2778,9 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2657 | 2778 | "error: expected type 'fn([]const u8, ?*std.builtin.StackTrace) noreturn', found 'fn() void'", |
| 2658 | 2779 | }); |
| 2659 | 2780 | |
| 2660 | | cases.add("wrong panic signature, generic function", |
| 2781 | ctx.objErrStage1("wrong panic signature, generic function", |
| 2661 | 2782 | \\pub fn panic(comptime msg: []const u8, error_return_trace: ?*builtin.StackTrace) noreturn { |
| 2783 | \\ _ = msg; _ = error_return_trace; |
| 2662 | 2784 | \\ while (true) {} |
| 2663 | 2785 | \\} |
| 2664 | 2786 | , &[_][]const u8{ |
| ... | ... | @@ -2666,14 +2788,14 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2666 | 2788 | "note: only one of the functions is generic", |
| 2667 | 2789 | }); |
| 2668 | 2790 | |
| 2669 | | cases.add("direct struct loop", |
| 2791 | ctx.objErrStage1("direct struct loop", |
| 2670 | 2792 | \\const A = struct { a : A, }; |
| 2671 | 2793 | \\export fn entry() usize { return @sizeOf(A); } |
| 2672 | 2794 | , &[_][]const u8{ |
| 2673 | 2795 | "tmp.zig:1:11: error: struct 'A' depends on itself", |
| 2674 | 2796 | }); |
| 2675 | 2797 | |
| 2676 | | cases.add("indirect struct loop", |
| 2798 | ctx.objErrStage1("indirect struct loop", |
| 2677 | 2799 | \\const A = struct { b : B, }; |
| 2678 | 2800 | \\const B = struct { c : C, }; |
| 2679 | 2801 | \\const C = struct { a : A, }; |
| ... | ... | @@ -2682,7 +2804,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2682 | 2804 | "tmp.zig:1:11: error: struct 'A' depends on itself", |
| 2683 | 2805 | }); |
| 2684 | 2806 | |
| 2685 | | cases.add("instantiating an undefined value for an invalid struct that contains itself", |
| 2807 | ctx.objErrStage1("instantiating an undefined value for an invalid struct that contains itself", |
| 2686 | 2808 | \\const Foo = struct { |
| 2687 | 2809 | \\ x: Foo, |
| 2688 | 2810 | \\}; |
| ... | ... | @@ -2697,23 +2819,25 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2697 | 2819 | "tmp.zig:8:28: note: referenced here", |
| 2698 | 2820 | }); |
| 2699 | 2821 | |
| 2700 | | cases.add("enum field value references enum", |
| 2701 | | \\pub const Foo = extern enum { |
| 2822 | ctx.objErrStage1("enum field value references enum", |
| 2823 | \\pub const Foo = enum(c_int) { |
| 2702 | 2824 | \\ A = Foo.B, |
| 2703 | 2825 | \\ C = D, |
| 2704 | 2826 | \\}; |
| 2705 | 2827 | \\export fn entry() void { |
| 2706 | 2828 | \\ var s: Foo = Foo.E; |
| 2829 | \\ _ = s; |
| 2707 | 2830 | \\} |
| 2708 | 2831 | , &[_][]const u8{ |
| 2709 | 2832 | "tmp.zig:1:17: error: enum 'Foo' depends on itself", |
| 2710 | 2833 | }); |
| 2711 | 2834 | |
| 2712 | | cases.add("top level decl dependency loop", |
| 2835 | ctx.objErrStage1("top level decl dependency loop", |
| 2713 | 2836 | \\const a : @TypeOf(b) = 0; |
| 2714 | 2837 | \\const b : @TypeOf(a) = 0; |
| 2715 | 2838 | \\export fn entry() void { |
| 2716 | 2839 | \\ const c = a + b; |
| 2840 | \\ _ = c; |
| 2717 | 2841 | \\} |
| 2718 | 2842 | , &[_][]const u8{ |
| 2719 | 2843 | "tmp.zig:2:19: error: dependency loop detected", |
| ... | ... | @@ -2721,7 +2845,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2721 | 2845 | "tmp.zig:4:15: note: referenced here", |
| 2722 | 2846 | }); |
| 2723 | 2847 | |
| 2724 | | cases.addTest("not an enum type", |
| 2848 | ctx.testErrStage1("not an enum type", |
| 2725 | 2849 | \\export fn entry() void { |
| 2726 | 2850 | \\ var self: Error = undefined; |
| 2727 | 2851 | \\ switch (self) { |
| ... | ... | @@ -2739,18 +2863,19 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2739 | 2863 | "tmp.zig:4:9: error: expected type '@typeInfo(Error).Union.tag_type.?', found 'type'", |
| 2740 | 2864 | }); |
| 2741 | 2865 | |
| 2742 | | cases.addTest("binary OR operator on error sets", |
| 2866 | ctx.testErrStage1("binary OR operator on error sets", |
| 2743 | 2867 | \\pub const A = error.A; |
| 2744 | 2868 | \\pub const AB = A | error.B; |
| 2745 | 2869 | \\export fn entry() void { |
| 2746 | 2870 | \\ var x: AB = undefined; |
| 2871 | \\ _ = x; |
| 2747 | 2872 | \\} |
| 2748 | 2873 | , &[_][]const u8{ |
| 2749 | 2874 | "tmp.zig:2:18: error: invalid operands to binary expression: 'error{A}' and 'error{B}'", |
| 2750 | 2875 | }); |
| 2751 | 2876 | |
| 2752 | 2877 | if (std.Target.current.os.tag == .linux) { |
| 2753 | | cases.addTest("implicit dependency on libc", |
| 2878 | ctx.testErrStage1("implicit dependency on libc", |
| 2754 | 2879 | \\extern "c" fn exit(u8) void; |
| 2755 | 2880 | \\export fn entry() void { |
| 2756 | 2881 | \\ exit(0); |
| ... | ... | @@ -2759,7 +2884,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2759 | 2884 | "tmp.zig:3:5: error: dependency on libc must be explicitly specified in the build command", |
| 2760 | 2885 | }); |
| 2761 | 2886 | |
| 2762 | | cases.addTest("libc headers note", |
| 2887 | ctx.testErrStage1("libc headers note", |
| 2763 | 2888 | \\const c = @cImport(@cInclude("stdio.h")); |
| 2764 | 2889 | \\export fn entry() void { |
| 2765 | 2890 | \\ _ = c.printf("hello, world!\n"); |
| ... | ... | @@ -2770,18 +2895,19 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2770 | 2895 | }); |
| 2771 | 2896 | } |
| 2772 | 2897 | |
| 2773 | | cases.addTest("comptime vector overflow shows the index", |
| 2898 | ctx.testErrStage1("comptime vector overflow shows the index", |
| 2774 | 2899 | \\comptime { |
| 2775 | 2900 | \\ var a: @import("std").meta.Vector(4, u8) = [_]u8{ 1, 2, 255, 4 }; |
| 2776 | 2901 | \\ var b: @import("std").meta.Vector(4, u8) = [_]u8{ 5, 6, 1, 8 }; |
| 2777 | 2902 | \\ var x = a + b; |
| 2903 | \\ _ = x; |
| 2778 | 2904 | \\} |
| 2779 | 2905 | , &[_][]const u8{ |
| 2780 | 2906 | "tmp.zig:4:15: error: operation caused overflow", |
| 2781 | 2907 | "tmp.zig:4:15: note: when computing vector element at index 2", |
| 2782 | 2908 | }); |
| 2783 | 2909 | |
| 2784 | | cases.addTest("packed struct with fields of not allowed types", |
| 2910 | ctx.testErrStage1("packed struct with fields of not allowed types", |
| 2785 | 2911 | \\const A = packed struct { |
| 2786 | 2912 | \\ x: anyerror, |
| 2787 | 2913 | \\}; |
| ... | ... | @@ -2805,24 +2931,31 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2805 | 2931 | \\}; |
| 2806 | 2932 | \\export fn entry1() void { |
| 2807 | 2933 | \\ var a: A = undefined; |
| 2934 | \\ _ = a; |
| 2808 | 2935 | \\} |
| 2809 | 2936 | \\export fn entry2() void { |
| 2810 | 2937 | \\ var b: B = undefined; |
| 2938 | \\ _ = b; |
| 2811 | 2939 | \\} |
| 2812 | 2940 | \\export fn entry3() void { |
| 2813 | 2941 | \\ var r: C = undefined; |
| 2942 | \\ _ = r; |
| 2814 | 2943 | \\} |
| 2815 | 2944 | \\export fn entry4() void { |
| 2816 | 2945 | \\ var d: D = undefined; |
| 2946 | \\ _ = d; |
| 2817 | 2947 | \\} |
| 2818 | 2948 | \\export fn entry5() void { |
| 2819 | 2949 | \\ var e: E = undefined; |
| 2950 | \\ _ = e; |
| 2820 | 2951 | \\} |
| 2821 | 2952 | \\export fn entry6() void { |
| 2822 | 2953 | \\ var f: F = undefined; |
| 2954 | \\ _ = f; |
| 2823 | 2955 | \\} |
| 2824 | 2956 | \\export fn entry7() void { |
| 2825 | 2957 | \\ var g: G = undefined; |
| 2958 | \\ _ = g; |
| 2826 | 2959 | \\} |
| 2827 | 2960 | \\const S = struct { |
| 2828 | 2961 | \\ x: i32, |
| ... | ... | @@ -2843,42 +2976,40 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2843 | 2976 | "tmp.zig:14:5: error: non-packed, non-extern struct 'U' not allowed in packed struct; no guaranteed in-memory representation", |
| 2844 | 2977 | "tmp.zig:17:5: error: type '?anyerror' not allowed in packed struct; no guaranteed in-memory representation", |
| 2845 | 2978 | "tmp.zig:20:5: error: type 'Enum' not allowed in packed struct; no guaranteed in-memory representation", |
| 2846 | | "tmp.zig:50:14: note: enum declaration does not specify an integer tag type", |
| 2979 | "tmp.zig:57:14: note: enum declaration does not specify an integer tag type", |
| 2847 | 2980 | }); |
| 2848 | 2981 | |
| 2849 | | cases.addCase(x: { |
| 2850 | | var tc = cases.create("deduplicate undeclared identifier", |
| 2851 | | \\export fn a() void { |
| 2852 | | \\ x += 1; |
| 2853 | | \\} |
| 2854 | | \\export fn b() void { |
| 2855 | | \\ x += 1; |
| 2856 | | \\} |
| 2857 | | , &[_][]const u8{ |
| 2858 | | "tmp.zig:2:5: error: use of undeclared identifier 'x'", |
| 2859 | | }); |
| 2860 | | tc.expect_exact = true; |
| 2861 | | break :x tc; |
| 2982 | ctx.objErrStage1("deduplicate undeclared identifier", |
| 2983 | \\export fn a() void { |
| 2984 | \\ x += 1; |
| 2985 | \\} |
| 2986 | \\export fn b() void { |
| 2987 | \\ x += 1; |
| 2988 | \\} |
| 2989 | , &[_][]const u8{ |
| 2990 | "tmp.zig:2:5: error: use of undeclared identifier 'x'", |
| 2862 | 2991 | }); |
| 2863 | 2992 | |
| 2864 | | cases.add("export generic function", |
| 2993 | ctx.objErrStage1("export generic function", |
| 2865 | 2994 | \\export fn foo(num: anytype) i32 { |
| 2995 | \\ _ = num; |
| 2866 | 2996 | \\ return 0; |
| 2867 | 2997 | \\} |
| 2868 | 2998 | , &[_][]const u8{ |
| 2869 | 2999 | "tmp.zig:1:15: error: parameter of type 'anytype' not allowed in function with calling convention 'C'", |
| 2870 | 3000 | }); |
| 2871 | 3001 | |
| 2872 | | cases.add("C pointer to c_void", |
| 3002 | ctx.objErrStage1("C pointer to c_void", |
| 2873 | 3003 | \\export fn a() void { |
| 2874 | 3004 | \\ var x: *c_void = undefined; |
| 2875 | 3005 | \\ var y: [*c]c_void = x; |
| 3006 | \\ _ = y; |
| 2876 | 3007 | \\} |
| 2877 | 3008 | , &[_][]const u8{ |
| 2878 | 3009 | "tmp.zig:3:16: error: C pointers cannot point to opaque types", |
| 2879 | 3010 | }); |
| 2880 | 3011 | |
| 2881 | | cases.add("directly embedding opaque type in struct and union", |
| 3012 | ctx.objErrStage1("directly embedding opaque type in struct and union", |
| 2882 | 3013 | \\const O = opaque {}; |
| 2883 | 3014 | \\const Foo = struct { |
| 2884 | 3015 | \\ o: O, |
| ... | ... | @@ -2889,74 +3020,85 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2889 | 3020 | \\}; |
| 2890 | 3021 | \\export fn a() void { |
| 2891 | 3022 | \\ var foo: Foo = undefined; |
| 3023 | \\ _ = foo; |
| 2892 | 3024 | \\} |
| 2893 | 3025 | \\export fn b() void { |
| 2894 | 3026 | \\ var bar: Bar = undefined; |
| 3027 | \\ _ = bar; |
| 2895 | 3028 | \\} |
| 2896 | 3029 | \\export fn c() void { |
| 2897 | 3030 | \\ var baz: *opaque {} = undefined; |
| 2898 | 3031 | \\ const qux = .{baz.*}; |
| 3032 | \\ _ = qux; |
| 2899 | 3033 | \\} |
| 2900 | 3034 | , &[_][]const u8{ |
| 2901 | 3035 | "tmp.zig:3:5: error: opaque types have unknown size and therefore cannot be directly embedded in structs", |
| 2902 | 3036 | "tmp.zig:7:5: error: opaque types have unknown size and therefore cannot be directly embedded in unions", |
| 2903 | | "tmp.zig:17:22: error: opaque types have unknown size and therefore cannot be directly embedded in structs", |
| 3037 | "tmp.zig:19:22: error: opaque types have unknown size and therefore cannot be directly embedded in structs", |
| 2904 | 3038 | }); |
| 2905 | 3039 | |
| 2906 | | cases.add("implicit cast between C pointer and Zig pointer - bad const/align/child", |
| 3040 | ctx.objErrStage1("implicit cast between C pointer and Zig pointer - bad const/align/child", |
| 2907 | 3041 | \\export fn a() void { |
| 2908 | 3042 | \\ var x: [*c]u8 = undefined; |
| 2909 | 3043 | \\ var y: *align(4) u8 = x; |
| 3044 | \\ _ = y; |
| 2910 | 3045 | \\} |
| 2911 | 3046 | \\export fn b() void { |
| 2912 | 3047 | \\ var x: [*c]const u8 = undefined; |
| 2913 | 3048 | \\ var y: *u8 = x; |
| 3049 | \\ _ = y; |
| 2914 | 3050 | \\} |
| 2915 | 3051 | \\export fn c() void { |
| 2916 | 3052 | \\ var x: [*c]u8 = undefined; |
| 2917 | 3053 | \\ var y: *u32 = x; |
| 3054 | \\ _ = y; |
| 2918 | 3055 | \\} |
| 2919 | 3056 | \\export fn d() void { |
| 2920 | 3057 | \\ var y: *align(1) u32 = undefined; |
| 2921 | 3058 | \\ var x: [*c]u32 = y; |
| 3059 | \\ _ = x; |
| 2922 | 3060 | \\} |
| 2923 | 3061 | \\export fn e() void { |
| 2924 | 3062 | \\ var y: *const u8 = undefined; |
| 2925 | 3063 | \\ var x: [*c]u8 = y; |
| 3064 | \\ _ = x; |
| 2926 | 3065 | \\} |
| 2927 | 3066 | \\export fn f() void { |
| 2928 | 3067 | \\ var y: *u8 = undefined; |
| 2929 | 3068 | \\ var x: [*c]u32 = y; |
| 3069 | \\ _ = x; |
| 2930 | 3070 | \\} |
| 2931 | 3071 | , &[_][]const u8{ |
| 2932 | 3072 | "tmp.zig:3:27: error: cast increases pointer alignment", |
| 2933 | | "tmp.zig:7:18: error: cast discards const qualifier", |
| 2934 | | "tmp.zig:11:19: error: expected type '*u32', found '[*c]u8'", |
| 2935 | | "tmp.zig:11:19: note: pointer type child 'u8' cannot cast into pointer type child 'u32'", |
| 2936 | | "tmp.zig:15:22: error: cast increases pointer alignment", |
| 2937 | | "tmp.zig:19:21: error: cast discards const qualifier", |
| 2938 | | "tmp.zig:23:22: error: expected type '[*c]u32', found '*u8'", |
| 3073 | "tmp.zig:8:18: error: cast discards const qualifier", |
| 3074 | "tmp.zig:13:19: error: expected type '*u32', found '[*c]u8'", |
| 3075 | "tmp.zig:13:19: note: pointer type child 'u8' cannot cast into pointer type child 'u32'", |
| 3076 | "tmp.zig:18:22: error: cast increases pointer alignment", |
| 3077 | "tmp.zig:23:21: error: cast discards const qualifier", |
| 3078 | "tmp.zig:28:22: error: expected type '[*c]u32', found '*u8'", |
| 2939 | 3079 | }); |
| 2940 | 3080 | |
| 2941 | | cases.add("implicit casting null c pointer to zig pointer", |
| 3081 | ctx.objErrStage1("implicit casting null c pointer to zig pointer", |
| 2942 | 3082 | \\comptime { |
| 2943 | 3083 | \\ var c_ptr: [*c]u8 = 0; |
| 2944 | 3084 | \\ var zig_ptr: *u8 = c_ptr; |
| 3085 | \\ _ = zig_ptr; |
| 2945 | 3086 | \\} |
| 2946 | 3087 | , &[_][]const u8{ |
| 2947 | 3088 | "tmp.zig:3:24: error: null pointer casted to type '*u8'", |
| 2948 | 3089 | }); |
| 2949 | 3090 | |
| 2950 | | cases.add("implicit casting undefined c pointer to zig pointer", |
| 3091 | ctx.objErrStage1("implicit casting undefined c pointer to zig pointer", |
| 2951 | 3092 | \\comptime { |
| 2952 | 3093 | \\ var c_ptr: [*c]u8 = undefined; |
| 2953 | 3094 | \\ var zig_ptr: *u8 = c_ptr; |
| 3095 | \\ _ = zig_ptr; |
| 2954 | 3096 | \\} |
| 2955 | 3097 | , &[_][]const u8{ |
| 2956 | 3098 | "tmp.zig:3:24: error: use of undefined value here causes undefined behavior", |
| 2957 | 3099 | }); |
| 2958 | 3100 | |
| 2959 | | cases.add("implicit casting C pointers which would mess up null semantics", |
| 3101 | ctx.objErrStage1("implicit casting C pointers which would mess up null semantics", |
| 2960 | 3102 | \\export fn entry() void { |
| 2961 | 3103 | \\ var slice: []const u8 = "aoeu"; |
| 2962 | 3104 | \\ const opt_many_ptr: [*]const u8 = slice.ptr; |
| ... | ... | @@ -2970,6 +3112,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2970 | 3112 | \\ var opt_many_ptr: [*]u8 = slice.ptr; |
| 2971 | 3113 | \\ var ptr_opt_many_ptr = &opt_many_ptr; |
| 2972 | 3114 | \\ var c_ptr: [*c][*c]const u8 = ptr_opt_many_ptr; |
| 3115 | \\ _ = c_ptr; |
| 2973 | 3116 | \\} |
| 2974 | 3117 | , &[_][]const u8{ |
| 2975 | 3118 | "tmp.zig:6:24: error: expected type '*const [*]const u8', found '[*c]const [*c]const u8'", |
| ... | ... | @@ -2980,47 +3123,46 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2980 | 3123 | "tmp.zig:13:35: note: mutable '[*c]const u8' allows illegal null values stored to type '[*]u8'", |
| 2981 | 3124 | }); |
| 2982 | 3125 | |
| 2983 | | cases.add("implicit casting too big integers to C pointers", |
| 3126 | ctx.objErrStage1("implicit casting too big integers to C pointers", |
| 2984 | 3127 | \\export fn a() void { |
| 2985 | 3128 | \\ var ptr: [*c]u8 = (1 << 64) + 1; |
| 3129 | \\ _ = ptr; |
| 2986 | 3130 | \\} |
| 2987 | 3131 | \\export fn b() void { |
| 2988 | 3132 | \\ var x: u65 = 0x1234; |
| 2989 | 3133 | \\ var ptr: [*c]u8 = x; |
| 3134 | \\ _ = ptr; |
| 2990 | 3135 | \\} |
| 2991 | 3136 | , &[_][]const u8{ |
| 2992 | 3137 | "tmp.zig:2:33: error: integer value 18446744073709551617 cannot be coerced to type 'usize'", |
| 2993 | | "tmp.zig:6:23: error: integer type 'u65' too big for implicit @intToPtr to type '[*c]u8'", |
| 3138 | "tmp.zig:7:23: error: integer type 'u65' too big for implicit @intToPtr to type '[*c]u8'", |
| 2994 | 3139 | }); |
| 2995 | 3140 | |
| 2996 | | cases.add("C pointer pointing to non C ABI compatible type or has align attr", |
| 3141 | ctx.objErrStage1("C pointer pointing to non C ABI compatible type or has align attr", |
| 2997 | 3142 | \\const Foo = struct {}; |
| 2998 | 3143 | \\export fn a() void { |
| 2999 | 3144 | \\ const T = [*c]Foo; |
| 3000 | 3145 | \\ var t: T = undefined; |
| 3146 | \\ _ = t; |
| 3001 | 3147 | \\} |
| 3002 | 3148 | , &[_][]const u8{ |
| 3003 | 3149 | "tmp.zig:3:19: error: C pointers cannot point to non-C-ABI-compatible type 'Foo'", |
| 3004 | 3150 | }); |
| 3005 | 3151 | |
| 3006 | | cases.addCase(x: { |
| 3007 | | var tc = cases.create("compile log statement warning deduplication in generic fn", |
| 3008 | | \\export fn entry() void { |
| 3009 | | \\ inner(1); |
| 3010 | | \\ inner(2); |
| 3011 | | \\} |
| 3012 | | \\fn inner(comptime n: usize) void { |
| 3013 | | \\ comptime var i = 0; |
| 3014 | | \\ inline while (i < n) : (i += 1) { @compileLog("!@#$"); } |
| 3015 | | \\} |
| 3016 | | , &[_][]const u8{ |
| 3017 | | "tmp.zig:7:39: error: found compile log statement", |
| 3018 | | }); |
| 3019 | | tc.expect_exact = true; |
| 3020 | | break :x tc; |
| 3152 | ctx.objErrStage1("compile log statement warning deduplication in generic fn", |
| 3153 | \\export fn entry() void { |
| 3154 | \\ inner(1); |
| 3155 | \\ inner(2); |
| 3156 | \\} |
| 3157 | \\fn inner(comptime n: usize) void { |
| 3158 | \\ comptime var i = 0; |
| 3159 | \\ inline while (i < n) : (i += 1) { @compileLog("!@#$"); } |
| 3160 | \\} |
| 3161 | , &[_][]const u8{ |
| 3162 | "tmp.zig:7:39: error: found compile log statement", |
| 3021 | 3163 | }); |
| 3022 | 3164 | |
| 3023 | | cases.add("assign to invalid dereference", |
| 3165 | ctx.objErrStage1("assign to invalid dereference", |
| 3024 | 3166 | \\export fn entry() void { |
| 3025 | 3167 | \\ 'a'.* = 1; |
| 3026 | 3168 | \\} |
| ... | ... | @@ -3028,54 +3170,58 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3028 | 3170 | "tmp.zig:2:8: error: attempt to dereference non-pointer type 'comptime_int'", |
| 3029 | 3171 | }); |
| 3030 | 3172 | |
| 3031 | | cases.add("take slice of invalid dereference", |
| 3173 | ctx.objErrStage1("take slice of invalid dereference", |
| 3032 | 3174 | \\export fn entry() void { |
| 3033 | 3175 | \\ const x = 'a'.*[0..]; |
| 3176 | \\ _ = x; |
| 3034 | 3177 | \\} |
| 3035 | 3178 | , &[_][]const u8{ |
| 3036 | 3179 | "tmp.zig:2:18: error: attempt to dereference non-pointer type 'comptime_int'", |
| 3037 | 3180 | }); |
| 3038 | 3181 | |
| 3039 | | cases.add("@truncate undefined value", |
| 3182 | ctx.objErrStage1("@truncate undefined value", |
| 3040 | 3183 | \\export fn entry() void { |
| 3041 | 3184 | \\ var z = @truncate(u8, @as(u16, undefined)); |
| 3185 | \\ _ = z; |
| 3042 | 3186 | \\} |
| 3043 | 3187 | , &[_][]const u8{ |
| 3044 | 3188 | "tmp.zig:2:27: error: use of undefined value here causes undefined behavior", |
| 3045 | 3189 | }); |
| 3046 | 3190 | |
| 3047 | | cases.addTest("return invalid type from test", |
| 3191 | ctx.testErrStage1("return invalid type from test", |
| 3048 | 3192 | \\test "example" { return 1; } |
| 3049 | 3193 | , &[_][]const u8{ |
| 3050 | 3194 | "tmp.zig:1:25: error: expected type 'void', found 'comptime_int'", |
| 3051 | 3195 | }); |
| 3052 | 3196 | |
| 3053 | | cases.add("threadlocal qualifier on const", |
| 3197 | ctx.objErrStage1("threadlocal qualifier on const", |
| 3054 | 3198 | \\threadlocal const x: i32 = 1234; |
| 3055 | 3199 | \\export fn entry() i32 { |
| 3056 | 3200 | \\ return x; |
| 3057 | 3201 | \\} |
| 3058 | 3202 | , &[_][]const u8{ |
| 3059 | | "tmp.zig:1:13: error: threadlocal variable cannot be constant", |
| 3203 | "tmp.zig:1:1: error: threadlocal variable cannot be constant", |
| 3060 | 3204 | }); |
| 3061 | 3205 | |
| 3062 | | cases.add("@bitCast same size but bit count mismatch", |
| 3206 | ctx.objErrStage1("@bitCast same size but bit count mismatch", |
| 3063 | 3207 | \\export fn entry(byte: u8) void { |
| 3064 | 3208 | \\ var oops = @bitCast(u7, byte); |
| 3209 | \\ _ = oops; |
| 3065 | 3210 | \\} |
| 3066 | 3211 | , &[_][]const u8{ |
| 3067 | 3212 | "tmp.zig:2:25: error: destination type 'u7' has 7 bits but source type 'u8' has 8 bits", |
| 3068 | 3213 | }); |
| 3069 | 3214 | |
| 3070 | | cases.add("@bitCast with different sizes inside an expression", |
| 3215 | ctx.objErrStage1("@bitCast with different sizes inside an expression", |
| 3071 | 3216 | \\export fn entry() void { |
| 3072 | 3217 | \\ var foo = (@bitCast(u8, @as(f32, 1.0)) == 0xf); |
| 3218 | \\ _ = foo; |
| 3073 | 3219 | \\} |
| 3074 | 3220 | , &[_][]const u8{ |
| 3075 | 3221 | "tmp.zig:2:25: error: destination type 'u8' has size 1 but source type 'f32' has size 4", |
| 3076 | 3222 | }); |
| 3077 | 3223 | |
| 3078 | | cases.add("attempted `&&`", |
| 3224 | ctx.objErrStage1("attempted `&&`", |
| 3079 | 3225 | \\export fn entry(a: bool, b: bool) i32 { |
| 3080 | 3226 | \\ if (a && b) { |
| 3081 | 3227 | \\ return 1234; |
| ... | ... | @@ -3083,10 +3229,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3083 | 3229 | \\ return 5678; |
| 3084 | 3230 | \\} |
| 3085 | 3231 | , &[_][]const u8{ |
| 3086 | | "tmp.zig:2:12: error: `&&` is invalid. Note that `and` is boolean AND", |
| 3232 | "tmp.zig:2:11: error: `&&` is invalid; note that `and` is boolean AND", |
| 3087 | 3233 | }); |
| 3088 | 3234 | |
| 3089 | | cases.add("attempted `||` on boolean values", |
| 3235 | ctx.objErrStage1("attempted `||` on boolean values", |
| 3090 | 3236 | \\export fn entry(a: bool, b: bool) i32 { |
| 3091 | 3237 | \\ if (a || b) { |
| 3092 | 3238 | \\ return 1234; |
| ... | ... | @@ -3098,7 +3244,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3098 | 3244 | "tmp.zig:2:11: note: `||` merges error sets; `or` performs boolean OR", |
| 3099 | 3245 | }); |
| 3100 | 3246 | |
| 3101 | | cases.add("compile log a pointer to an opaque value", |
| 3247 | ctx.objErrStage1("compile log a pointer to an opaque value", |
| 3102 | 3248 | \\export fn entry() void { |
| 3103 | 3249 | \\ @compileLog(@ptrCast(*const c_void, &entry)); |
| 3104 | 3250 | \\} |
| ... | ... | @@ -3106,13 +3252,14 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3106 | 3252 | "tmp.zig:2:5: error: found compile log statement", |
| 3107 | 3253 | }); |
| 3108 | 3254 | |
| 3109 | | cases.add("duplicate boolean switch value", |
| 3255 | ctx.objErrStage1("duplicate boolean switch value", |
| 3110 | 3256 | \\comptime { |
| 3111 | 3257 | \\ const x = switch (true) { |
| 3112 | 3258 | \\ true => false, |
| 3113 | 3259 | \\ false => true, |
| 3114 | 3260 | \\ true => false, |
| 3115 | 3261 | \\ }; |
| 3262 | \\ _ = x; |
| 3116 | 3263 | \\} |
| 3117 | 3264 | \\comptime { |
| 3118 | 3265 | \\ const x = switch (true) { |
| ... | ... | @@ -3120,42 +3267,46 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3120 | 3267 | \\ true => false, |
| 3121 | 3268 | \\ false => true, |
| 3122 | 3269 | \\ }; |
| 3270 | \\ _ = x; |
| 3123 | 3271 | \\} |
| 3124 | 3272 | , &[_][]const u8{ |
| 3125 | 3273 | "tmp.zig:5:9: error: duplicate switch value", |
| 3126 | | "tmp.zig:12:9: error: duplicate switch value", |
| 3274 | "tmp.zig:13:9: error: duplicate switch value", |
| 3127 | 3275 | }); |
| 3128 | 3276 | |
| 3129 | | cases.add("missing boolean switch value", |
| 3277 | ctx.objErrStage1("missing boolean switch value", |
| 3130 | 3278 | \\comptime { |
| 3131 | 3279 | \\ const x = switch (true) { |
| 3132 | 3280 | \\ true => false, |
| 3133 | 3281 | \\ }; |
| 3282 | \\ _ = x; |
| 3134 | 3283 | \\} |
| 3135 | 3284 | \\comptime { |
| 3136 | 3285 | \\ const x = switch (true) { |
| 3137 | 3286 | \\ false => true, |
| 3138 | 3287 | \\ }; |
| 3288 | \\ _ = x; |
| 3139 | 3289 | \\} |
| 3140 | 3290 | , &[_][]const u8{ |
| 3141 | 3291 | "tmp.zig:2:15: error: switch must handle all possibilities", |
| 3142 | | "tmp.zig:7:15: error: switch must handle all possibilities", |
| 3292 | "tmp.zig:8:15: error: switch must handle all possibilities", |
| 3143 | 3293 | }); |
| 3144 | 3294 | |
| 3145 | | cases.add("reading past end of pointer casted array", |
| 3295 | ctx.objErrStage1("reading past end of pointer casted array", |
| 3146 | 3296 | \\comptime { |
| 3147 | 3297 | \\ const array: [4]u8 = "aoeu".*; |
| 3148 | 3298 | \\ const sub_array = array[1..]; |
| 3149 | 3299 | \\ const int_ptr = @ptrCast(*const u24, sub_array); |
| 3150 | 3300 | \\ const deref = int_ptr.*; |
| 3301 | \\ _ = deref; |
| 3151 | 3302 | \\} |
| 3152 | 3303 | , &[_][]const u8{ |
| 3153 | 3304 | "tmp.zig:5:26: error: attempt to read 4 bytes from [4]u8 at index 1 which is 3 bytes", |
| 3154 | 3305 | }); |
| 3155 | 3306 | |
| 3156 | | cases.add("error note for function parameter incompatibility", |
| 3157 | | \\fn do_the_thing(func: fn (arg: i32) void) void {} |
| 3158 | | \\fn bar(arg: bool) void {} |
| 3307 | ctx.objErrStage1("error note for function parameter incompatibility", |
| 3308 | \\fn do_the_thing(func: fn (arg: i32) void) void { _ = func; } |
| 3309 | \\fn bar(arg: bool) void { _ = arg; } |
| 3159 | 3310 | \\export fn entry() void { |
| 3160 | 3311 | \\ do_the_thing(bar); |
| 3161 | 3312 | \\} |
| ... | ... | @@ -3163,56 +3314,63 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3163 | 3314 | "tmp.zig:4:18: error: expected type 'fn(i32) void', found 'fn(bool) void", |
| 3164 | 3315 | "tmp.zig:4:18: note: parameter 0: 'bool' cannot cast into 'i32'", |
| 3165 | 3316 | }); |
| 3166 | | cases.add("cast negative value to unsigned integer", |
| 3317 | ctx.objErrStage1("cast negative value to unsigned integer", |
| 3167 | 3318 | \\comptime { |
| 3168 | 3319 | \\ const value: i32 = -1; |
| 3169 | 3320 | \\ const unsigned = @intCast(u32, value); |
| 3321 | \\ _ = unsigned; |
| 3170 | 3322 | \\} |
| 3171 | 3323 | \\export fn entry1() void { |
| 3172 | 3324 | \\ const value: i32 = -1; |
| 3173 | 3325 | \\ const unsigned: u32 = value; |
| 3326 | \\ _ = unsigned; |
| 3174 | 3327 | \\} |
| 3175 | 3328 | , &[_][]const u8{ |
| 3176 | 3329 | "tmp.zig:3:22: error: attempt to cast negative value to unsigned integer", |
| 3177 | | "tmp.zig:7:27: error: cannot cast negative value -1 to unsigned integer type 'u32'", |
| 3330 | "tmp.zig:8:27: error: cannot cast negative value -1 to unsigned integer type 'u32'", |
| 3178 | 3331 | }); |
| 3179 | 3332 | |
| 3180 | | cases.add("integer cast truncates bits", |
| 3333 | ctx.objErrStage1("integer cast truncates bits", |
| 3181 | 3334 | \\export fn entry1() void { |
| 3182 | 3335 | \\ const spartan_count: u16 = 300; |
| 3183 | 3336 | \\ const byte = @intCast(u8, spartan_count); |
| 3337 | \\ _ = byte; |
| 3184 | 3338 | \\} |
| 3185 | 3339 | \\export fn entry2() void { |
| 3186 | 3340 | \\ const spartan_count: u16 = 300; |
| 3187 | 3341 | \\ const byte: u8 = spartan_count; |
| 3342 | \\ _ = byte; |
| 3188 | 3343 | \\} |
| 3189 | 3344 | \\export fn entry3() void { |
| 3190 | 3345 | \\ var spartan_count: u16 = 300; |
| 3191 | 3346 | \\ var byte: u8 = spartan_count; |
| 3347 | \\ _ = byte; |
| 3192 | 3348 | \\} |
| 3193 | 3349 | \\export fn entry4() void { |
| 3194 | 3350 | \\ var signed: i8 = -1; |
| 3195 | 3351 | \\ var unsigned: u64 = signed; |
| 3352 | \\ _ = unsigned; |
| 3196 | 3353 | \\} |
| 3197 | 3354 | , &[_][]const u8{ |
| 3198 | 3355 | "tmp.zig:3:18: error: cast from 'u16' to 'u8' truncates bits", |
| 3199 | | "tmp.zig:7:22: error: integer value 300 cannot be coerced to type 'u8'", |
| 3200 | | "tmp.zig:11:20: error: expected type 'u8', found 'u16'", |
| 3201 | | "tmp.zig:11:20: note: unsigned 8-bit int cannot represent all possible unsigned 16-bit values", |
| 3202 | | "tmp.zig:15:25: error: expected type 'u64', found 'i8'", |
| 3203 | | "tmp.zig:15:25: note: unsigned 64-bit int cannot represent all possible signed 8-bit values", |
| 3356 | "tmp.zig:8:22: error: integer value 300 cannot be coerced to type 'u8'", |
| 3357 | "tmp.zig:13:20: error: expected type 'u8', found 'u16'", |
| 3358 | "tmp.zig:13:20: note: unsigned 8-bit int cannot represent all possible unsigned 16-bit values", |
| 3359 | "tmp.zig:18:25: error: expected type 'u64', found 'i8'", |
| 3360 | "tmp.zig:18:25: note: unsigned 64-bit int cannot represent all possible signed 8-bit values", |
| 3204 | 3361 | }); |
| 3205 | 3362 | |
| 3206 | | cases.add("comptime implicit cast f64 to f32", |
| 3363 | ctx.objErrStage1("comptime implicit cast f64 to f32", |
| 3207 | 3364 | \\export fn entry() void { |
| 3208 | 3365 | \\ const x: f64 = 16777217; |
| 3209 | 3366 | \\ const y: f32 = x; |
| 3367 | \\ _ = y; |
| 3210 | 3368 | \\} |
| 3211 | 3369 | , &[_][]const u8{ |
| 3212 | 3370 | "tmp.zig:3:20: error: cast of value 16777217.000000 to type 'f32' loses information", |
| 3213 | 3371 | }); |
| 3214 | 3372 | |
| 3215 | | cases.add("implicit cast from f64 to f32", |
| 3373 | ctx.objErrStage1("implicit cast from f64 to f32", |
| 3216 | 3374 | \\var x: f64 = 1.0; |
| 3217 | 3375 | \\var y: f32 = x; |
| 3218 | 3376 | \\ |
| ... | ... | @@ -3221,41 +3379,46 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3221 | 3379 | "tmp.zig:2:14: error: expected type 'f32', found 'f64'", |
| 3222 | 3380 | }); |
| 3223 | 3381 | |
| 3224 | | cases.add("exceeded maximum bit width of integer", |
| 3382 | ctx.objErrStage1("exceeded maximum bit width of integer", |
| 3225 | 3383 | \\export fn entry1() void { |
| 3226 | 3384 | \\ const T = u65536; |
| 3385 | \\ _ = T; |
| 3227 | 3386 | \\} |
| 3228 | 3387 | \\export fn entry2() void { |
| 3229 | 3388 | \\ var x: i65536 = 1; |
| 3389 | \\ _ = x; |
| 3230 | 3390 | \\} |
| 3231 | 3391 | , &[_][]const u8{ |
| 3232 | | "tmp.zig:5:12: error: primitive integer type 'i65536' exceeds maximum bit width of 65535", |
| 3392 | "tmp.zig:2:15: error: primitive integer type 'u65536' exceeds maximum bit width of 65535", |
| 3393 | "tmp.zig:6:12: error: primitive integer type 'i65536' exceeds maximum bit width of 65535", |
| 3233 | 3394 | }); |
| 3234 | 3395 | |
| 3235 | | cases.add("compile error when evaluating return type of inferred error set", |
| 3396 | ctx.objErrStage1("compile error when evaluating return type of inferred error set", |
| 3236 | 3397 | \\const Car = struct { |
| 3237 | 3398 | \\ foo: *SymbolThatDoesNotExist, |
| 3238 | 3399 | \\ pub fn init() !Car {} |
| 3239 | 3400 | \\}; |
| 3240 | 3401 | \\export fn entry() void { |
| 3241 | 3402 | \\ const car = Car.init(); |
| 3403 | \\ _ = car; |
| 3242 | 3404 | \\} |
| 3243 | 3405 | , &[_][]const u8{ |
| 3244 | 3406 | "tmp.zig:2:11: error: use of undeclared identifier 'SymbolThatDoesNotExist'", |
| 3245 | 3407 | }); |
| 3246 | 3408 | |
| 3247 | | cases.add("don't implicit cast double pointer to *c_void", |
| 3409 | ctx.objErrStage1("don't implicit cast double pointer to *c_void", |
| 3248 | 3410 | \\export fn entry() void { |
| 3249 | 3411 | \\ var a: u32 = 1; |
| 3250 | 3412 | \\ var ptr: *align(@alignOf(u32)) c_void = &a; |
| 3251 | 3413 | \\ var b: *u32 = @ptrCast(*u32, ptr); |
| 3252 | 3414 | \\ var ptr2: *c_void = &b; |
| 3415 | \\ _ = ptr2; |
| 3253 | 3416 | \\} |
| 3254 | 3417 | , &[_][]const u8{ |
| 3255 | 3418 | "tmp.zig:5:26: error: expected type '*c_void', found '**u32'", |
| 3256 | 3419 | }); |
| 3257 | 3420 | |
| 3258 | | cases.add("runtime index into comptime type slice", |
| 3421 | ctx.objErrStage1("runtime index into comptime type slice", |
| 3259 | 3422 | \\const Struct = struct { |
| 3260 | 3423 | \\ a: u32, |
| 3261 | 3424 | \\}; |
| ... | ... | @@ -3265,12 +3428,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3265 | 3428 | \\export fn entry() void { |
| 3266 | 3429 | \\ const index = getIndex(); |
| 3267 | 3430 | \\ const field = @typeInfo(Struct).Struct.fields[index]; |
| 3431 | \\ _ = field; |
| 3268 | 3432 | \\} |
| 3269 | 3433 | , &[_][]const u8{ |
| 3270 | 3434 | "tmp.zig:9:51: error: values of type 'std.builtin.StructField' must be comptime known, but index value is runtime known", |
| 3271 | 3435 | }); |
| 3272 | 3436 | |
| 3273 | | cases.add("compile log statement inside function which must be comptime evaluated", |
| 3437 | ctx.objErrStage1("compile log statement inside function which must be comptime evaluated", |
| 3274 | 3438 | \\fn Foo(comptime T: type) type { |
| 3275 | 3439 | \\ @compileLog(@typeName(T)); |
| 3276 | 3440 | \\ return T; |
| ... | ... | @@ -3283,25 +3447,27 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3283 | 3447 | "tmp.zig:2:5: error: found compile log statement", |
| 3284 | 3448 | }); |
| 3285 | 3449 | |
| 3286 | | cases.add("comptime slice of an undefined slice", |
| 3450 | ctx.objErrStage1("comptime slice of an undefined slice", |
| 3287 | 3451 | \\comptime { |
| 3288 | 3452 | \\ var a: []u8 = undefined; |
| 3289 | 3453 | \\ var b = a[0..10]; |
| 3454 | \\ _ = b; |
| 3290 | 3455 | \\} |
| 3291 | 3456 | , &[_][]const u8{ |
| 3292 | 3457 | "tmp.zig:3:14: error: slice of undefined", |
| 3293 | 3458 | }); |
| 3294 | 3459 | |
| 3295 | | cases.add("implicit cast const array to mutable slice", |
| 3460 | ctx.objErrStage1("implicit cast const array to mutable slice", |
| 3296 | 3461 | \\export fn entry() void { |
| 3297 | 3462 | \\ const buffer: [1]u8 = [_]u8{8}; |
| 3298 | 3463 | \\ const sliceA: []u8 = &buffer; |
| 3464 | \\ _ = sliceA; |
| 3299 | 3465 | \\} |
| 3300 | 3466 | , &[_][]const u8{ |
| 3301 | 3467 | "tmp.zig:3:27: error: expected type '[]u8', found '*const [1]u8'", |
| 3302 | 3468 | }); |
| 3303 | 3469 | |
| 3304 | | cases.add("deref slice and get len field", |
| 3470 | ctx.objErrStage1("deref slice and get len field", |
| 3305 | 3471 | \\export fn entry() void { |
| 3306 | 3472 | \\ var a: []u8 = undefined; |
| 3307 | 3473 | \\ _ = a.*.len; |
| ... | ... | @@ -3310,7 +3476,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3310 | 3476 | "tmp.zig:3:10: error: attempt to dereference non-pointer type '[]u8'", |
| 3311 | 3477 | }); |
| 3312 | 3478 | |
| 3313 | | cases.add("@ptrCast a 0 bit type to a non- 0 bit type", |
| 3479 | ctx.objErrStage1("@ptrCast a 0 bit type to a non- 0 bit type", |
| 3314 | 3480 | \\export fn entry() bool { |
| 3315 | 3481 | \\ var x: u0 = 0; |
| 3316 | 3482 | \\ const p = @ptrCast(?*u0, &x); |
| ... | ... | @@ -3322,7 +3488,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3322 | 3488 | "tmp.zig:3:24: note: '?*u0' has in-memory bits", |
| 3323 | 3489 | }); |
| 3324 | 3490 | |
| 3325 | | cases.add("comparing a non-optional pointer against null", |
| 3491 | ctx.objErrStage1("comparing a non-optional pointer against null", |
| 3326 | 3492 | \\export fn entry() void { |
| 3327 | 3493 | \\ var x: i32 = 1; |
| 3328 | 3494 | \\ _ = &x == null; |
| ... | ... | @@ -3331,21 +3497,23 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3331 | 3497 | "tmp.zig:3:12: error: comparison of '*i32' with null", |
| 3332 | 3498 | }); |
| 3333 | 3499 | |
| 3334 | | cases.add("non error sets used in merge error sets operator", |
| 3500 | ctx.objErrStage1("non error sets used in merge error sets operator", |
| 3335 | 3501 | \\export fn foo() void { |
| 3336 | 3502 | \\ const Errors = u8 || u16; |
| 3503 | \\ _ = Errors; |
| 3337 | 3504 | \\} |
| 3338 | 3505 | \\export fn bar() void { |
| 3339 | 3506 | \\ const Errors = error{} || u16; |
| 3507 | \\ _ = Errors; |
| 3340 | 3508 | \\} |
| 3341 | 3509 | , &[_][]const u8{ |
| 3342 | 3510 | "tmp.zig:2:20: error: expected error set type, found type 'u8'", |
| 3343 | 3511 | "tmp.zig:2:23: note: `||` merges error sets; `or` performs boolean OR", |
| 3344 | | "tmp.zig:5:31: error: expected error set type, found type 'u16'", |
| 3345 | | "tmp.zig:5:28: note: `||` merges error sets; `or` performs boolean OR", |
| 3512 | "tmp.zig:6:31: error: expected error set type, found type 'u16'", |
| 3513 | "tmp.zig:6:28: note: `||` merges error sets; `or` performs boolean OR", |
| 3346 | 3514 | }); |
| 3347 | 3515 | |
| 3348 | | cases.add("variable initialization compile error then referenced", |
| 3516 | ctx.objErrStage1("variable initialization compile error then referenced", |
| 3349 | 3517 | \\fn Undeclared() type { |
| 3350 | 3518 | \\ return T; |
| 3351 | 3519 | \\} |
| ... | ... | @@ -3357,12 +3525,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3357 | 3525 | \\} |
| 3358 | 3526 | \\export fn entry() void { |
| 3359 | 3527 | \\ const S = Gen(); |
| 3528 | \\ _ = S; |
| 3360 | 3529 | \\} |
| 3361 | 3530 | , &[_][]const u8{ |
| 3362 | 3531 | "tmp.zig:2:12: error: use of undeclared identifier 'T'", |
| 3363 | 3532 | }); |
| 3364 | 3533 | |
| 3365 | | cases.add("refer to the type of a generic function", |
| 3534 | ctx.objErrStage1("refer to the type of a generic function", |
| 3366 | 3535 | \\export fn entry() void { |
| 3367 | 3536 | \\ const Func = fn (type) void; |
| 3368 | 3537 | \\ const f: Func = undefined; |
| ... | ... | @@ -3372,7 +3541,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3372 | 3541 | "tmp.zig:4:5: error: use of undefined value here causes undefined behavior", |
| 3373 | 3542 | }); |
| 3374 | 3543 | |
| 3375 | | cases.add("accessing runtime parameter from outer function", |
| 3544 | ctx.objErrStage1("accessing runtime parameter from outer function", |
| 3376 | 3545 | \\fn outer(y: u32) fn (u32) u32 { |
| 3377 | 3546 | \\ const st = struct { |
| 3378 | 3547 | \\ fn get(z: u32) u32 { |
| ... | ... | @@ -3384,6 +3553,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3384 | 3553 | \\export fn entry() void { |
| 3385 | 3554 | \\ var func = outer(10); |
| 3386 | 3555 | \\ var x = func(3); |
| 3556 | \\ _ = x; |
| 3387 | 3557 | \\} |
| 3388 | 3558 | , &[_][]const u8{ |
| 3389 | 3559 | "tmp.zig:4:24: error: 'y' not accessible from inner function", |
| ... | ... | @@ -3391,69 +3561,74 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3391 | 3561 | "tmp.zig:1:10: note: declared here", |
| 3392 | 3562 | }); |
| 3393 | 3563 | |
| 3394 | | cases.add("non int passed to @intToFloat", |
| 3564 | ctx.objErrStage1("non int passed to @intToFloat", |
| 3395 | 3565 | \\export fn entry() void { |
| 3396 | 3566 | \\ const x = @intToFloat(f32, 1.1); |
| 3567 | \\ _ = x; |
| 3397 | 3568 | \\} |
| 3398 | 3569 | , &[_][]const u8{ |
| 3399 | 3570 | "tmp.zig:2:32: error: expected int type, found 'comptime_float'", |
| 3400 | 3571 | }); |
| 3401 | 3572 | |
| 3402 | | cases.add("non float passed to @floatToInt", |
| 3573 | ctx.objErrStage1("non float passed to @floatToInt", |
| 3403 | 3574 | \\export fn entry() void { |
| 3404 | 3575 | \\ const x = @floatToInt(i32, @as(i32, 54)); |
| 3576 | \\ _ = x; |
| 3405 | 3577 | \\} |
| 3406 | 3578 | , &[_][]const u8{ |
| 3407 | 3579 | "tmp.zig:2:32: error: expected float type, found 'i32'", |
| 3408 | 3580 | }); |
| 3409 | 3581 | |
| 3410 | | cases.add("out of range comptime_int passed to @floatToInt", |
| 3582 | ctx.objErrStage1("out of range comptime_int passed to @floatToInt", |
| 3411 | 3583 | \\export fn entry() void { |
| 3412 | 3584 | \\ const x = @floatToInt(i8, 200); |
| 3585 | \\ _ = x; |
| 3413 | 3586 | \\} |
| 3414 | 3587 | , &[_][]const u8{ |
| 3415 | 3588 | "tmp.zig:2:31: error: integer value 200 cannot be coerced to type 'i8'", |
| 3416 | 3589 | }); |
| 3417 | 3590 | |
| 3418 | | cases.add("load too many bytes from comptime reinterpreted pointer", |
| 3591 | ctx.objErrStage1("load too many bytes from comptime reinterpreted pointer", |
| 3419 | 3592 | \\export fn entry() void { |
| 3420 | 3593 | \\ const float: f32 = 5.99999999999994648725e-01; |
| 3421 | 3594 | \\ const float_ptr = &float; |
| 3422 | 3595 | \\ const int_ptr = @ptrCast(*const i64, float_ptr); |
| 3423 | 3596 | \\ const int_val = int_ptr.*; |
| 3597 | \\ _ = int_val; |
| 3424 | 3598 | \\} |
| 3425 | 3599 | , &[_][]const u8{ |
| 3426 | 3600 | "tmp.zig:5:28: error: attempt to read 8 bytes from pointer to f32 which is 4 bytes", |
| 3427 | 3601 | }); |
| 3428 | 3602 | |
| 3429 | | cases.add("invalid type used in array type", |
| 3603 | ctx.objErrStage1("invalid type used in array type", |
| 3430 | 3604 | \\const Item = struct { |
| 3431 | 3605 | \\ field: SomeNonexistentType, |
| 3432 | 3606 | \\}; |
| 3433 | 3607 | \\var items: [100]Item = undefined; |
| 3434 | 3608 | \\export fn entry() void { |
| 3435 | 3609 | \\ const a = items[0]; |
| 3610 | \\ _ = a; |
| 3436 | 3611 | \\} |
| 3437 | 3612 | , &[_][]const u8{ |
| 3438 | 3613 | "tmp.zig:2:12: error: use of undeclared identifier 'SomeNonexistentType'", |
| 3439 | 3614 | }); |
| 3440 | 3615 | |
| 3441 | | cases.add("comptime continue inside runtime catch", |
| 3442 | | \\export fn entry(c: bool) void { |
| 3616 | ctx.objErrStage1("comptime continue inside runtime catch", |
| 3617 | \\export fn entry() void { |
| 3443 | 3618 | \\ const ints = [_]u8{ 1, 2 }; |
| 3444 | 3619 | \\ inline for (ints) |_| { |
| 3445 | | \\ bad() catch |_| continue; |
| 3620 | \\ bad() catch continue; |
| 3446 | 3621 | \\ } |
| 3447 | 3622 | \\} |
| 3448 | 3623 | \\fn bad() !void { |
| 3449 | 3624 | \\ return error.Bad; |
| 3450 | 3625 | \\} |
| 3451 | 3626 | , &[_][]const u8{ |
| 3452 | | "tmp.zig:4:25: error: comptime control flow inside runtime block", |
| 3627 | "tmp.zig:4:21: error: comptime control flow inside runtime block", |
| 3453 | 3628 | "tmp.zig:4:15: note: runtime block created here", |
| 3454 | 3629 | }); |
| 3455 | 3630 | |
| 3456 | | cases.add("comptime continue inside runtime switch", |
| 3631 | ctx.objErrStage1("comptime continue inside runtime switch", |
| 3457 | 3632 | \\export fn entry() void { |
| 3458 | 3633 | \\ var p: i32 = undefined; |
| 3459 | 3634 | \\ comptime var q = true; |
| ... | ... | @@ -3470,7 +3645,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3470 | 3645 | "tmp.zig:5:9: note: runtime block created here", |
| 3471 | 3646 | }); |
| 3472 | 3647 | |
| 3473 | | cases.add("comptime continue inside runtime while error", |
| 3648 | ctx.objErrStage1("comptime continue inside runtime while error", |
| 3474 | 3649 | \\export fn entry() void { |
| 3475 | 3650 | \\ var p: anyerror!usize = undefined; |
| 3476 | 3651 | \\ comptime var q = true; |
| ... | ... | @@ -3486,7 +3661,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3486 | 3661 | "tmp.zig:5:9: note: runtime block created here", |
| 3487 | 3662 | }); |
| 3488 | 3663 | |
| 3489 | | cases.add("comptime continue inside runtime while optional", |
| 3664 | ctx.objErrStage1("comptime continue inside runtime while optional", |
| 3490 | 3665 | \\export fn entry() void { |
| 3491 | 3666 | \\ var p: ?usize = undefined; |
| 3492 | 3667 | \\ comptime var q = true; |
| ... | ... | @@ -3500,7 +3675,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3500 | 3675 | "tmp.zig:5:9: note: runtime block created here", |
| 3501 | 3676 | }); |
| 3502 | 3677 | |
| 3503 | | cases.add("comptime continue inside runtime while bool", |
| 3678 | ctx.objErrStage1("comptime continue inside runtime while bool", |
| 3504 | 3679 | \\export fn entry() void { |
| 3505 | 3680 | \\ var p: usize = undefined; |
| 3506 | 3681 | \\ comptime var q = true; |
| ... | ... | @@ -3514,7 +3689,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3514 | 3689 | "tmp.zig:5:9: note: runtime block created here", |
| 3515 | 3690 | }); |
| 3516 | 3691 | |
| 3517 | | cases.add("comptime continue inside runtime if error", |
| 3692 | ctx.objErrStage1("comptime continue inside runtime if error", |
| 3518 | 3693 | \\export fn entry() void { |
| 3519 | 3694 | \\ var p: anyerror!i32 = undefined; |
| 3520 | 3695 | \\ comptime var q = true; |
| ... | ... | @@ -3528,7 +3703,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3528 | 3703 | "tmp.zig:5:9: note: runtime block created here", |
| 3529 | 3704 | }); |
| 3530 | 3705 | |
| 3531 | | cases.add("comptime continue inside runtime if optional", |
| 3706 | ctx.objErrStage1("comptime continue inside runtime if optional", |
| 3532 | 3707 | \\export fn entry() void { |
| 3533 | 3708 | \\ var p: ?i32 = undefined; |
| 3534 | 3709 | \\ comptime var q = true; |
| ... | ... | @@ -3542,7 +3717,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3542 | 3717 | "tmp.zig:5:9: note: runtime block created here", |
| 3543 | 3718 | }); |
| 3544 | 3719 | |
| 3545 | | cases.add("comptime continue inside runtime if bool", |
| 3720 | ctx.objErrStage1("comptime continue inside runtime if bool", |
| 3546 | 3721 | \\export fn entry() void { |
| 3547 | 3722 | \\ var p: usize = undefined; |
| 3548 | 3723 | \\ comptime var q = true; |
| ... | ... | @@ -3556,22 +3731,23 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3556 | 3731 | "tmp.zig:5:9: note: runtime block created here", |
| 3557 | 3732 | }); |
| 3558 | 3733 | |
| 3559 | | cases.add("switch with invalid expression parameter", |
| 3734 | ctx.objErrStage1("switch with invalid expression parameter", |
| 3560 | 3735 | \\export fn entry() void { |
| 3561 | 3736 | \\ Test(i32); |
| 3562 | 3737 | \\} |
| 3563 | 3738 | \\fn Test(comptime T: type) void { |
| 3564 | 3739 | \\ const x = switch (T) { |
| 3565 | | \\ []u8 => |x| 123, |
| 3566 | | \\ i32 => |x| 456, |
| 3740 | \\ []u8 => |x| x, |
| 3741 | \\ i32 => |x| x, |
| 3567 | 3742 | \\ else => unreachable, |
| 3568 | 3743 | \\ }; |
| 3744 | \\ _ = x; |
| 3569 | 3745 | \\} |
| 3570 | 3746 | , &[_][]const u8{ |
| 3571 | 3747 | "tmp.zig:7:17: error: switch on type 'type' provides no expression parameter", |
| 3572 | 3748 | }); |
| 3573 | 3749 | |
| 3574 | | cases.add("function prototype with no body", |
| 3750 | ctx.objErrStage1("function prototype with no body", |
| 3575 | 3751 | \\fn foo() void; |
| 3576 | 3752 | \\export fn entry() void { |
| 3577 | 3753 | \\ foo(); |
| ... | ... | @@ -3580,7 +3756,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3580 | 3756 | "tmp.zig:1:1: error: non-extern function has no body", |
| 3581 | 3757 | }); |
| 3582 | 3758 | |
| 3583 | | cases.add("@frame() called outside of function definition", |
| 3759 | ctx.objErrStage1("@frame() called outside of function definition", |
| 3584 | 3760 | \\var handle_undef: anyframe = undefined; |
| 3585 | 3761 | \\var handle_dummy: anyframe = @frame(); |
| 3586 | 3762 | \\export fn entry() bool { |
| ... | ... | @@ -3590,16 +3766,16 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3590 | 3766 | "tmp.zig:2:30: error: @frame() called outside of function definition", |
| 3591 | 3767 | }); |
| 3592 | 3768 | |
| 3593 | | cases.add("`_` is not a declarable symbol", |
| 3769 | ctx.objErrStage1("`_` is not a declarable symbol", |
| 3594 | 3770 | \\export fn f1() usize { |
| 3595 | 3771 | \\ var _: usize = 2; |
| 3596 | 3772 | \\ return _; |
| 3597 | 3773 | \\} |
| 3598 | 3774 | , &[_][]const u8{ |
| 3599 | | "tmp.zig:2:5: error: `_` is not a declarable symbol", |
| 3775 | "tmp.zig:2:9: error: '_' used as an identifier without @\"_\" syntax", |
| 3600 | 3776 | }); |
| 3601 | 3777 | |
| 3602 | | cases.add("`_` should not be usable inside for", |
| 3778 | ctx.objErrStage1("`_` should not be usable inside for", |
| 3603 | 3779 | \\export fn returns() void { |
| 3604 | 3780 | \\ for ([_]void{}) |_, i| { |
| 3605 | 3781 | \\ for ([_]void{}) |_, j| { |
| ... | ... | @@ -3608,10 +3784,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3608 | 3784 | \\ } |
| 3609 | 3785 | \\} |
| 3610 | 3786 | , &[_][]const u8{ |
| 3611 | | "tmp.zig:4:20: error: `_` may only be used to assign things to", |
| 3787 | "tmp.zig:4:20: error: '_' used as an identifier without @\"_\" syntax", |
| 3612 | 3788 | }); |
| 3613 | 3789 | |
| 3614 | | cases.add("`_` should not be usable inside while", |
| 3790 | ctx.objErrStage1("`_` should not be usable inside while", |
| 3615 | 3791 | \\export fn returns() void { |
| 3616 | 3792 | \\ while (optionalReturn()) |_| { |
| 3617 | 3793 | \\ while (optionalReturn()) |_| { |
| ... | ... | @@ -3623,10 +3799,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3623 | 3799 | \\ return 1; |
| 3624 | 3800 | \\} |
| 3625 | 3801 | , &[_][]const u8{ |
| 3626 | | "tmp.zig:4:20: error: `_` may only be used to assign things to", |
| 3802 | "tmp.zig:4:20: error: '_' used as an identifier without @\"_\" syntax", |
| 3627 | 3803 | }); |
| 3628 | 3804 | |
| 3629 | | cases.add("`_` should not be usable inside while else", |
| 3805 | ctx.objErrStage1("`_` should not be usable inside while else", |
| 3630 | 3806 | \\export fn returns() void { |
| 3631 | 3807 | \\ while (optionalReturnError()) |_| { |
| 3632 | 3808 | \\ while (optionalReturnError()) |_| { |
| ... | ... | @@ -3640,10 +3816,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3640 | 3816 | \\ return error.optionalReturnError; |
| 3641 | 3817 | \\} |
| 3642 | 3818 | , &[_][]const u8{ |
| 3643 | | "tmp.zig:6:17: error: `_` may only be used to assign things to", |
| 3819 | "tmp.zig:6:17: error: '_' used as an identifier without @\"_\" syntax", |
| 3644 | 3820 | }); |
| 3645 | 3821 | |
| 3646 | | cases.add("while loop body expression ignored", |
| 3822 | ctx.objErrStage1("while loop body expression ignored", |
| 3647 | 3823 | \\fn returns() usize { |
| 3648 | 3824 | \\ return 2; |
| 3649 | 3825 | \\} |
| ... | ... | @@ -3664,7 +3840,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3664 | 3840 | "tmp.zig:13:26: error: expression value is ignored", |
| 3665 | 3841 | }); |
| 3666 | 3842 | |
| 3667 | | cases.add("missing parameter name of generic function", |
| 3843 | ctx.objErrStage1("missing parameter name of generic function", |
| 3668 | 3844 | \\fn dump(anytype) void {} |
| 3669 | 3845 | \\export fn entry() void { |
| 3670 | 3846 | \\ var a: u8 = 9; |
| ... | ... | @@ -3674,20 +3850,20 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3674 | 3850 | "tmp.zig:1:9: error: missing parameter name", |
| 3675 | 3851 | }); |
| 3676 | 3852 | |
| 3677 | | cases.add("non-inline for loop on a type that requires comptime", |
| 3853 | ctx.objErrStage1("non-inline for loop on a type that requires comptime", |
| 3678 | 3854 | \\const Foo = struct { |
| 3679 | 3855 | \\ name: []const u8, |
| 3680 | 3856 | \\ T: type, |
| 3681 | 3857 | \\}; |
| 3682 | 3858 | \\export fn entry() void { |
| 3683 | 3859 | \\ const xx: [2]Foo = undefined; |
| 3684 | | \\ for (xx) |f| {} |
| 3860 | \\ for (xx) |f| { _ = f;} |
| 3685 | 3861 | \\} |
| 3686 | 3862 | , &[_][]const u8{ |
| 3687 | 3863 | "tmp.zig:7:5: error: values of type 'Foo' must be comptime known, but index value is runtime known", |
| 3688 | 3864 | }); |
| 3689 | 3865 | |
| 3690 | | cases.add("generic fn as parameter without comptime keyword", |
| 3866 | ctx.objErrStage1("generic fn as parameter without comptime keyword", |
| 3691 | 3867 | \\fn f(_: fn (anytype) void) void {} |
| 3692 | 3868 | \\fn g(_: anytype) void {} |
| 3693 | 3869 | \\export fn entry() void { |
| ... | ... | @@ -3697,7 +3873,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3697 | 3873 | "tmp.zig:1:9: error: parameter of type 'fn(anytype) anytype' must be declared comptime", |
| 3698 | 3874 | }); |
| 3699 | 3875 | |
| 3700 | | cases.add("optional pointer to void in extern struct", |
| 3876 | ctx.objErrStage1("optional pointer to void in extern struct", |
| 3701 | 3877 | \\const Foo = extern struct { |
| 3702 | 3878 | \\ x: ?*const void, |
| 3703 | 3879 | \\}; |
| ... | ... | @@ -3705,12 +3881,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3705 | 3881 | \\ foo: Foo, |
| 3706 | 3882 | \\ y: i32, |
| 3707 | 3883 | \\}; |
| 3708 | | \\export fn entry(bar: *Bar) void {} |
| 3884 | \\export fn entry(bar: *Bar) void {_ = bar;} |
| 3709 | 3885 | , &[_][]const u8{ |
| 3710 | 3886 | "tmp.zig:2:5: error: extern structs cannot contain fields of type '?*const void'", |
| 3711 | 3887 | }); |
| 3712 | 3888 | |
| 3713 | | cases.add("use of comptime-known undefined function value", |
| 3889 | ctx.objErrStage1("use of comptime-known undefined function value", |
| 3714 | 3890 | \\const Cmd = struct { |
| 3715 | 3891 | \\ exec: fn () void, |
| 3716 | 3892 | \\}; |
| ... | ... | @@ -3722,7 +3898,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3722 | 3898 | "tmp.zig:6:12: error: use of undefined value here causes undefined behavior", |
| 3723 | 3899 | }); |
| 3724 | 3900 | |
| 3725 | | cases.add("use of comptime-known undefined function value", |
| 3901 | ctx.objErrStage1("use of comptime-known undefined function value", |
| 3726 | 3902 | \\const Cmd = struct { |
| 3727 | 3903 | \\ exec: fn () void, |
| 3728 | 3904 | \\}; |
| ... | ... | @@ -3734,16 +3910,17 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3734 | 3910 | "tmp.zig:6:12: error: use of undefined value here causes undefined behavior", |
| 3735 | 3911 | }); |
| 3736 | 3912 | |
| 3737 | | cases.add("bad @alignCast at comptime", |
| 3913 | ctx.objErrStage1("bad @alignCast at comptime", |
| 3738 | 3914 | \\comptime { |
| 3739 | 3915 | \\ const ptr = @intToPtr(*align(1) i32, 0x1); |
| 3740 | 3916 | \\ const aligned = @alignCast(4, ptr); |
| 3917 | \\ _ = aligned; |
| 3741 | 3918 | \\} |
| 3742 | 3919 | , &[_][]const u8{ |
| 3743 | 3920 | "tmp.zig:3:35: error: pointer address 0x1 is not aligned to 4 bytes", |
| 3744 | 3921 | }); |
| 3745 | 3922 | |
| 3746 | | cases.add("@ptrToInt on *void", |
| 3923 | ctx.objErrStage1("@ptrToInt on *void", |
| 3747 | 3924 | \\export fn entry() bool { |
| 3748 | 3925 | \\ return @ptrToInt(&{}) == @ptrToInt(&{}); |
| 3749 | 3926 | \\} |
| ... | ... | @@ -3751,7 +3928,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3751 | 3928 | "tmp.zig:2:23: error: pointer to size 0 type has no address", |
| 3752 | 3929 | }); |
| 3753 | 3930 | |
| 3754 | | cases.add("@popCount - non-integer", |
| 3931 | ctx.objErrStage1("@popCount - non-integer", |
| 3755 | 3932 | \\export fn entry(x: f32) u32 { |
| 3756 | 3933 | \\ return @popCount(f32, x); |
| 3757 | 3934 | \\} |
| ... | ... | @@ -3759,8 +3936,23 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3759 | 3936 | "tmp.zig:2:22: error: expected integer type, found 'f32'", |
| 3760 | 3937 | }); |
| 3761 | 3938 | |
| 3762 | | cases.addCase(x: { |
| 3763 | | const tc = cases.create("wrong same named struct", |
| 3939 | { |
| 3940 | const case = ctx.obj("wrong same named struct", .{}); |
| 3941 | case.backend = .stage1; |
| 3942 | |
| 3943 | case.addSourceFile("a.zig", |
| 3944 | \\pub const Foo = struct { |
| 3945 | \\ x: i32, |
| 3946 | \\}; |
| 3947 | ); |
| 3948 | |
| 3949 | case.addSourceFile("b.zig", |
| 3950 | \\pub const Foo = struct { |
| 3951 | \\ z: f64, |
| 3952 | \\}; |
| 3953 | ); |
| 3954 | |
| 3955 | case.addError( |
| 3764 | 3956 | \\const a = @import("a.zig"); |
| 3765 | 3957 | \\const b = @import("b.zig"); |
| 3766 | 3958 | \\ |
| ... | ... | @@ -3769,30 +3961,16 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3769 | 3961 | \\ bar(&a1); |
| 3770 | 3962 | \\} |
| 3771 | 3963 | \\ |
| 3772 | | \\fn bar(x: *b.Foo) void {} |
| 3964 | \\fn bar(x: *b.Foo) void {_ = x;} |
| 3773 | 3965 | , &[_][]const u8{ |
| 3774 | 3966 | "tmp.zig:6:10: error: expected type '*b.Foo', found '*a.Foo'", |
| 3775 | 3967 | "tmp.zig:6:10: note: pointer type child 'a.Foo' cannot cast into pointer type child 'b.Foo'", |
| 3776 | 3968 | "a.zig:1:17: note: a.Foo declared here", |
| 3777 | 3969 | "b.zig:1:17: note: b.Foo declared here", |
| 3778 | 3970 | }); |
| 3971 | } |
| 3779 | 3972 | |
| 3780 | | tc.addSourceFile("a.zig", |
| 3781 | | \\pub const Foo = struct { |
| 3782 | | \\ x: i32, |
| 3783 | | \\}; |
| 3784 | | ); |
| 3785 | | |
| 3786 | | tc.addSourceFile("b.zig", |
| 3787 | | \\pub const Foo = struct { |
| 3788 | | \\ z: f64, |
| 3789 | | \\}; |
| 3790 | | ); |
| 3791 | | |
| 3792 | | break :x tc; |
| 3793 | | }); |
| 3794 | | |
| 3795 | | cases.add("@floatToInt comptime safety", |
| 3973 | ctx.objErrStage1("@floatToInt comptime safety", |
| 3796 | 3974 | \\comptime { |
| 3797 | 3975 | \\ _ = @floatToInt(i8, @as(f32, -129.1)); |
| 3798 | 3976 | \\} |
| ... | ... | @@ -3808,35 +3986,38 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3808 | 3986 | "tmp.zig:8:9: error: integer value '256' cannot be stored in type 'u8'", |
| 3809 | 3987 | }); |
| 3810 | 3988 | |
| 3811 | | cases.add("use c_void as return type of fn ptr", |
| 3989 | ctx.objErrStage1("use c_void as return type of fn ptr", |
| 3812 | 3990 | \\export fn entry() void { |
| 3813 | 3991 | \\ const a: fn () c_void = undefined; |
| 3992 | \\ _ = a; |
| 3814 | 3993 | \\} |
| 3815 | 3994 | , &[_][]const u8{ |
| 3816 | 3995 | "tmp.zig:2:20: error: return type cannot be opaque", |
| 3817 | 3996 | }); |
| 3818 | 3997 | |
| 3819 | | cases.add("use implicit casts to assign null to non-nullable pointer", |
| 3998 | ctx.objErrStage1("use implicit casts to assign null to non-nullable pointer", |
| 3820 | 3999 | \\export fn entry() void { |
| 3821 | 4000 | \\ var x: i32 = 1234; |
| 3822 | 4001 | \\ var p: *i32 = &x; |
| 3823 | 4002 | \\ var pp: *?*i32 = &p; |
| 3824 | 4003 | \\ pp.* = null; |
| 3825 | 4004 | \\ var y = p.*; |
| 4005 | \\ _ = y; |
| 3826 | 4006 | \\} |
| 3827 | 4007 | , &[_][]const u8{ |
| 3828 | 4008 | "tmp.zig:4:23: error: expected type '*?*i32', found '**i32'", |
| 3829 | 4009 | }); |
| 3830 | 4010 | |
| 3831 | | cases.add("attempted implicit cast from T to [*]const T", |
| 4011 | ctx.objErrStage1("attempted implicit cast from T to [*]const T", |
| 3832 | 4012 | \\export fn entry() void { |
| 3833 | 4013 | \\ const x: [*]const bool = true; |
| 4014 | \\ _ = x; |
| 3834 | 4015 | \\} |
| 3835 | 4016 | , &[_][]const u8{ |
| 3836 | 4017 | "tmp.zig:2:30: error: expected type '[*]const bool', found 'bool'", |
| 3837 | 4018 | }); |
| 3838 | 4019 | |
| 3839 | | cases.add("dereference unknown length pointer", |
| 4020 | ctx.objErrStage1("dereference unknown length pointer", |
| 3840 | 4021 | \\export fn entry(x: [*]i32) i32 { |
| 3841 | 4022 | \\ return x.*; |
| 3842 | 4023 | \\} |
| ... | ... | @@ -3844,7 +4025,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3844 | 4025 | "tmp.zig:2:13: error: index syntax required for unknown-length pointer type '[*]i32'", |
| 3845 | 4026 | }); |
| 3846 | 4027 | |
| 3847 | | cases.add("field access of unknown length pointer", |
| 4028 | ctx.objErrStage1("field access of unknown length pointer", |
| 3848 | 4029 | \\const Foo = extern struct { |
| 3849 | 4030 | \\ a: i32, |
| 3850 | 4031 | \\}; |
| ... | ... | @@ -3856,13 +4037,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3856 | 4037 | "tmp.zig:6:8: error: type '[*]Foo' does not support field access", |
| 3857 | 4038 | }); |
| 3858 | 4039 | |
| 3859 | | cases.add("unknown length pointer to opaque", |
| 4040 | ctx.objErrStage1("unknown length pointer to opaque", |
| 3860 | 4041 | \\export const T = [*]opaque {}; |
| 3861 | 4042 | , &[_][]const u8{ |
| 3862 | 4043 | "tmp.zig:1:21: error: unknown-length pointer to opaque", |
| 3863 | 4044 | }); |
| 3864 | 4045 | |
| 3865 | | cases.add("error when evaluating return type", |
| 4046 | ctx.objErrStage1("error when evaluating return type", |
| 3866 | 4047 | \\const Foo = struct { |
| 3867 | 4048 | \\ map: @as(i32, i32), |
| 3868 | 4049 | \\ |
| ... | ... | @@ -3872,20 +4053,22 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3872 | 4053 | \\}; |
| 3873 | 4054 | \\export fn entry() void { |
| 3874 | 4055 | \\ var rule_set = try Foo.init(); |
| 4056 | \\ _ = rule_set; |
| 3875 | 4057 | \\} |
| 3876 | 4058 | , &[_][]const u8{ |
| 3877 | 4059 | "tmp.zig:2:19: error: expected type 'i32', found 'type'", |
| 3878 | 4060 | }); |
| 3879 | 4061 | |
| 3880 | | cases.add("slicing single-item pointer", |
| 4062 | ctx.objErrStage1("slicing single-item pointer", |
| 3881 | 4063 | \\export fn entry(ptr: *i32) void { |
| 3882 | 4064 | \\ const slice = ptr[0..2]; |
| 4065 | \\ _ = slice; |
| 3883 | 4066 | \\} |
| 3884 | 4067 | , &[_][]const u8{ |
| 3885 | 4068 | "tmp.zig:2:22: error: slice of single-item pointer", |
| 3886 | 4069 | }); |
| 3887 | 4070 | |
| 3888 | | cases.add("indexing single-item pointer", |
| 4071 | ctx.objErrStage1("indexing single-item pointer", |
| 3889 | 4072 | \\export fn entry(ptr: *i32) i32 { |
| 3890 | 4073 | \\ return ptr[1]; |
| 3891 | 4074 | \\} |
| ... | ... | @@ -3893,12 +4076,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3893 | 4076 | "tmp.zig:2:15: error: index of single-item pointer", |
| 3894 | 4077 | }); |
| 3895 | 4078 | |
| 3896 | | cases.add("nested error set mismatch", |
| 4079 | ctx.objErrStage1("nested error set mismatch", |
| 3897 | 4080 | \\const NextError = error{NextError}; |
| 3898 | 4081 | \\const OtherError = error{OutOfMemory}; |
| 3899 | 4082 | \\ |
| 3900 | 4083 | \\export fn entry() void { |
| 3901 | 4084 | \\ const a: ?NextError!i32 = foo(); |
| 4085 | \\ _ = a; |
| 3902 | 4086 | \\} |
| 3903 | 4087 | \\ |
| 3904 | 4088 | \\fn foo() ?OtherError!i32 { |
| ... | ... | @@ -3911,7 +4095,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3911 | 4095 | "tmp.zig:2:26: note: 'error.OutOfMemory' not a member of destination error set", |
| 3912 | 4096 | }); |
| 3913 | 4097 | |
| 3914 | | cases.add("invalid deref on switch target", |
| 4098 | ctx.objErrStage1("invalid deref on switch target", |
| 3915 | 4099 | \\comptime { |
| 3916 | 4100 | \\ var tile = Tile.Empty; |
| 3917 | 4101 | \\ switch (tile.*) { |
| ... | ... | @@ -3927,13 +4111,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3927 | 4111 | "tmp.zig:3:17: error: attempt to dereference non-pointer type 'Tile'", |
| 3928 | 4112 | }); |
| 3929 | 4113 | |
| 3930 | | cases.add("invalid field access in comptime", |
| 3931 | | \\comptime { var x = doesnt_exist.whatever; } |
| 4114 | ctx.objErrStage1("invalid field access in comptime", |
| 4115 | \\comptime { var x = doesnt_exist.whatever; _ = x; } |
| 3932 | 4116 | , &[_][]const u8{ |
| 3933 | 4117 | "tmp.zig:1:20: error: use of undeclared identifier 'doesnt_exist'", |
| 3934 | 4118 | }); |
| 3935 | 4119 | |
| 3936 | | cases.add("suspend inside suspend block", |
| 4120 | ctx.objErrStage1("suspend inside suspend block", |
| 3937 | 4121 | \\export fn entry() void { |
| 3938 | 4122 | \\ _ = async foo(); |
| 3939 | 4123 | \\} |
| ... | ... | @@ -3948,17 +4132,18 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3948 | 4132 | "tmp.zig:5:5: note: other suspend block here", |
| 3949 | 4133 | }); |
| 3950 | 4134 | |
| 3951 | | cases.add("assign inline fn to non-comptime var", |
| 4135 | ctx.objErrStage1("assign inline fn to non-comptime var", |
| 3952 | 4136 | \\export fn entry() void { |
| 3953 | 4137 | \\ var a = b; |
| 4138 | \\ _ = a; |
| 3954 | 4139 | \\} |
| 3955 | 4140 | \\fn b() callconv(.Inline) void { } |
| 3956 | 4141 | , &[_][]const u8{ |
| 3957 | 4142 | "tmp.zig:2:5: error: functions marked inline must be stored in const or comptime var", |
| 3958 | | "tmp.zig:4:1: note: declared here", |
| 4143 | "tmp.zig:5:1: note: declared here", |
| 3959 | 4144 | }); |
| 3960 | 4145 | |
| 3961 | | cases.add("wrong type passed to @panic", |
| 4146 | ctx.objErrStage1("wrong type passed to @panic", |
| 3962 | 4147 | \\export fn entry() void { |
| 3963 | 4148 | \\ var e = error.Foo; |
| 3964 | 4149 | \\ @panic(e); |
| ... | ... | @@ -3967,7 +4152,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3967 | 4152 | "tmp.zig:3:12: error: expected type '[]const u8', found 'error{Foo}'", |
| 3968 | 4153 | }); |
| 3969 | 4154 | |
| 3970 | | cases.add("@tagName used on union with no associated enum tag", |
| 4155 | ctx.objErrStage1("@tagName used on union with no associated enum tag", |
| 3971 | 4156 | \\const FloatInt = extern union { |
| 3972 | 4157 | \\ Float: f32, |
| 3973 | 4158 | \\ Int: i32, |
| ... | ... | @@ -3975,13 +4160,14 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3975 | 4160 | \\export fn entry() void { |
| 3976 | 4161 | \\ var fi = FloatInt{.Float = 123.45}; |
| 3977 | 4162 | \\ var tagName = @tagName(fi); |
| 4163 | \\ _ = tagName; |
| 3978 | 4164 | \\} |
| 3979 | 4165 | , &[_][]const u8{ |
| 3980 | 4166 | "tmp.zig:7:19: error: union has no associated enum", |
| 3981 | 4167 | "tmp.zig:1:18: note: declared here", |
| 3982 | 4168 | }); |
| 3983 | 4169 | |
| 3984 | | cases.add("returning error from void async function", |
| 4170 | ctx.objErrStage1("returning error from void async function", |
| 3985 | 4171 | \\export fn entry() void { |
| 3986 | 4172 | \\ _ = async amain(); |
| 3987 | 4173 | \\} |
| ... | ... | @@ -3992,37 +4178,40 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3992 | 4178 | "tmp.zig:5:17: error: expected type 'void', found 'error{ShouldBeCompileError}'", |
| 3993 | 4179 | }); |
| 3994 | 4180 | |
| 3995 | | cases.add("var makes structs required to be comptime known", |
| 4181 | ctx.objErrStage1("var makes structs required to be comptime known", |
| 3996 | 4182 | \\export fn entry() void { |
| 3997 | 4183 | \\ const S = struct{v: anytype}; |
| 3998 | 4184 | \\ var s = S{.v=@as(i32, 10)}; |
| 4185 | \\ _ = s; |
| 3999 | 4186 | \\} |
| 4000 | 4187 | , &[_][]const u8{ |
| 4001 | 4188 | "tmp.zig:3:4: error: variable of type 'S' must be const or comptime", |
| 4002 | 4189 | }); |
| 4003 | 4190 | |
| 4004 | | cases.add("@ptrCast discards const qualifier", |
| 4191 | ctx.objErrStage1("@ptrCast discards const qualifier", |
| 4005 | 4192 | \\export fn entry() void { |
| 4006 | 4193 | \\ const x: i32 = 1234; |
| 4007 | 4194 | \\ const y = @ptrCast(*i32, &x); |
| 4195 | \\ _ = y; |
| 4008 | 4196 | \\} |
| 4009 | 4197 | , &[_][]const u8{ |
| 4010 | 4198 | "tmp.zig:3:15: error: cast discards const qualifier", |
| 4011 | 4199 | }); |
| 4012 | 4200 | |
| 4013 | | cases.add("comptime slice of undefined pointer non-zero len", |
| 4201 | ctx.objErrStage1("comptime slice of undefined pointer non-zero len", |
| 4014 | 4202 | \\export fn entry() void { |
| 4015 | 4203 | \\ const slice = @as([*]i32, undefined)[0..1]; |
| 4204 | \\ _ = slice; |
| 4016 | 4205 | \\} |
| 4017 | 4206 | , &[_][]const u8{ |
| 4018 | 4207 | "tmp.zig:2:41: error: non-zero length slice of undefined pointer", |
| 4019 | 4208 | }); |
| 4020 | 4209 | |
| 4021 | | cases.add("type checking function pointers", |
| 4210 | ctx.objErrStage1("type checking function pointers", |
| 4022 | 4211 | \\fn a(b: fn (*const u8) void) void { |
| 4023 | 4212 | \\ b('a'); |
| 4024 | 4213 | \\} |
| 4025 | | \\fn c(d: u8) void {} |
| 4214 | \\fn c(d: u8) void {_ = d;} |
| 4026 | 4215 | \\export fn entry() void { |
| 4027 | 4216 | \\ a(c); |
| 4028 | 4217 | \\} |
| ... | ... | @@ -4030,7 +4219,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4030 | 4219 | "tmp.zig:6:7: error: expected type 'fn(*const u8) void', found 'fn(u8) void'", |
| 4031 | 4220 | }); |
| 4032 | 4221 | |
| 4033 | | cases.add("no else prong on switch on global error set", |
| 4222 | ctx.objErrStage1("no else prong on switch on global error set", |
| 4034 | 4223 | \\export fn entry() void { |
| 4035 | 4224 | \\ foo(error.A); |
| 4036 | 4225 | \\} |
| ... | ... | @@ -4043,7 +4232,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4043 | 4232 | "tmp.zig:5:5: error: else prong required when switching on type 'anyerror'", |
| 4044 | 4233 | }); |
| 4045 | 4234 | |
| 4046 | | cases.add("error not handled in switch", |
| 4235 | ctx.objErrStage1("error not handled in switch", |
| 4047 | 4236 | \\export fn entry() void { |
| 4048 | 4237 | \\ foo(452) catch |err| switch (err) { |
| 4049 | 4238 | \\ error.Foo => {}, |
| ... | ... | @@ -4062,7 +4251,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4062 | 4251 | "tmp.zig:2:26: error: error.Bar not handled in switch", |
| 4063 | 4252 | }); |
| 4064 | 4253 | |
| 4065 | | cases.add("duplicate error in switch", |
| 4254 | ctx.objErrStage1("duplicate error in switch", |
| 4066 | 4255 | \\export fn entry() void { |
| 4067 | 4256 | \\ foo(452) catch |err| switch (err) { |
| 4068 | 4257 | \\ error.Foo => {}, |
| ... | ... | @@ -4080,10 +4269,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4080 | 4269 | \\} |
| 4081 | 4270 | , &[_][]const u8{ |
| 4082 | 4271 | "tmp.zig:5:14: error: duplicate switch value: '@typeInfo(@typeInfo(@TypeOf(foo)).Fn.return_type.?).ErrorUnion.error_set.Foo'", |
| 4083 | | "tmp.zig:3:14: note: other value is here", |
| 4272 | "tmp.zig:3:14: note: other value here", |
| 4084 | 4273 | }); |
| 4085 | 4274 | |
| 4086 | | cases.add("invalid cast from integral type to enum", |
| 4275 | ctx.objErrStage1("invalid cast from integral type to enum", |
| 4087 | 4276 | \\const E = enum(usize) { One, Two }; |
| 4088 | 4277 | \\ |
| 4089 | 4278 | \\export fn entry() void { |
| ... | ... | @@ -4099,7 +4288,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4099 | 4288 | "tmp.zig:9:10: error: expected type 'usize', found 'E'", |
| 4100 | 4289 | }); |
| 4101 | 4290 | |
| 4102 | | cases.add("range operator in switch used on error set", |
| 4291 | ctx.objErrStage1("range operator in switch used on error set", |
| 4103 | 4292 | \\export fn entry() void { |
| 4104 | 4293 | \\ try foo(452) catch |err| switch (err) { |
| 4105 | 4294 | \\ error.A ... error.B => {}, |
| ... | ... | @@ -4117,33 +4306,35 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4117 | 4306 | "tmp.zig:3:17: error: operator not allowed for errors", |
| 4118 | 4307 | }); |
| 4119 | 4308 | |
| 4120 | | cases.add("inferring error set of function pointer", |
| 4309 | ctx.objErrStage1("inferring error set of function pointer", |
| 4121 | 4310 | \\comptime { |
| 4122 | 4311 | \\ const z: ?fn()!void = null; |
| 4123 | 4312 | \\} |
| 4124 | 4313 | , &[_][]const u8{ |
| 4125 | | "tmp.zig:2:15: error: inferring error set of return type valid only for function definitions", |
| 4314 | "tmp.zig:2:19: error: function prototype may not have inferred error set", |
| 4126 | 4315 | }); |
| 4127 | 4316 | |
| 4128 | | cases.add("access non-existent member of error set", |
| 4317 | ctx.objErrStage1("access non-existent member of error set", |
| 4129 | 4318 | \\const Foo = error{A}; |
| 4130 | 4319 | \\comptime { |
| 4131 | 4320 | \\ const z = Foo.Bar; |
| 4321 | \\ _ = z; |
| 4132 | 4322 | \\} |
| 4133 | 4323 | , &[_][]const u8{ |
| 4134 | 4324 | "tmp.zig:3:18: error: no error named 'Bar' in 'Foo'", |
| 4135 | 4325 | }); |
| 4136 | 4326 | |
| 4137 | | cases.add("error union operator with non error set LHS", |
| 4327 | ctx.objErrStage1("error union operator with non error set LHS", |
| 4138 | 4328 | \\comptime { |
| 4139 | 4329 | \\ const z = i32!i32; |
| 4140 | 4330 | \\ var x: z = undefined; |
| 4331 | \\ _ = x; |
| 4141 | 4332 | \\} |
| 4142 | 4333 | , &[_][]const u8{ |
| 4143 | 4334 | "tmp.zig:2:15: error: expected error set type, found type 'i32'", |
| 4144 | 4335 | }); |
| 4145 | 4336 | |
| 4146 | | cases.add("error equality but sets have no common members", |
| 4337 | ctx.objErrStage1("error equality but sets have no common members", |
| 4147 | 4338 | \\const Set1 = error{A, C}; |
| 4148 | 4339 | \\const Set2 = error{B, D}; |
| 4149 | 4340 | \\export fn entry() void { |
| ... | ... | @@ -4158,29 +4349,32 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4158 | 4349 | "tmp.zig:7:11: error: error sets 'Set1' and 'Set2' have no common errors", |
| 4159 | 4350 | }); |
| 4160 | 4351 | |
| 4161 | | cases.add("only equality binary operator allowed for error sets", |
| 4352 | ctx.objErrStage1("only equality binary operator allowed for error sets", |
| 4162 | 4353 | \\comptime { |
| 4163 | 4354 | \\ const z = error.A > error.B; |
| 4355 | \\ _ = z; |
| 4164 | 4356 | \\} |
| 4165 | 4357 | , &[_][]const u8{ |
| 4166 | 4358 | "tmp.zig:2:23: error: operator not allowed for errors", |
| 4167 | 4359 | }); |
| 4168 | 4360 | |
| 4169 | | cases.add("explicit error set cast known at comptime violates error sets", |
| 4361 | ctx.objErrStage1("explicit error set cast known at comptime violates error sets", |
| 4170 | 4362 | \\const Set1 = error {A, B}; |
| 4171 | 4363 | \\const Set2 = error {A, C}; |
| 4172 | 4364 | \\comptime { |
| 4173 | 4365 | \\ var x = Set1.B; |
| 4174 | 4366 | \\ var y = @errSetCast(Set2, x); |
| 4367 | \\ _ = y; |
| 4175 | 4368 | \\} |
| 4176 | 4369 | , &[_][]const u8{ |
| 4177 | 4370 | "tmp.zig:5:13: error: error.B not a member of error set 'Set2'", |
| 4178 | 4371 | }); |
| 4179 | 4372 | |
| 4180 | | cases.add("cast error union of global error set to error union of smaller error set", |
| 4373 | ctx.objErrStage1("cast error union of global error set to error union of smaller error set", |
| 4181 | 4374 | \\const SmallErrorSet = error{A}; |
| 4182 | 4375 | \\export fn entry() void { |
| 4183 | 4376 | \\ var x: SmallErrorSet!i32 = foo(); |
| 4377 | \\ _ = x; |
| 4184 | 4378 | \\} |
| 4185 | 4379 | \\fn foo() anyerror!i32 { |
| 4186 | 4380 | \\ return error.B; |
| ... | ... | @@ -4191,10 +4385,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4191 | 4385 | "tmp.zig:3:35: note: cannot cast global error set into smaller set", |
| 4192 | 4386 | }); |
| 4193 | 4387 | |
| 4194 | | cases.add("cast global error set to error set", |
| 4388 | ctx.objErrStage1("cast global error set to error set", |
| 4195 | 4389 | \\const SmallErrorSet = error{A}; |
| 4196 | 4390 | \\export fn entry() void { |
| 4197 | 4391 | \\ var x: SmallErrorSet = foo(); |
| 4392 | \\ _ = x; |
| 4198 | 4393 | \\} |
| 4199 | 4394 | \\fn foo() anyerror { |
| 4200 | 4395 | \\ return error.B; |
| ... | ... | @@ -4203,7 +4398,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4203 | 4398 | "tmp.zig:3:31: error: expected type 'SmallErrorSet', found 'anyerror'", |
| 4204 | 4399 | "tmp.zig:3:31: note: cannot cast global error set into smaller set", |
| 4205 | 4400 | }); |
| 4206 | | cases.add("recursive inferred error set", |
| 4401 | ctx.objErrStage1("recursive inferred error set", |
| 4207 | 4402 | \\export fn entry() void { |
| 4208 | 4403 | \\ foo() catch unreachable; |
| 4209 | 4404 | \\} |
| ... | ... | @@ -4214,7 +4409,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4214 | 4409 | "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", |
| 4215 | 4410 | }); |
| 4216 | 4411 | |
| 4217 | | cases.add("implicit cast of error set not a subset", |
| 4412 | ctx.objErrStage1("implicit cast of error set not a subset", |
| 4218 | 4413 | \\const Set1 = error{A, B}; |
| 4219 | 4414 | \\const Set2 = error{A, C}; |
| 4220 | 4415 | \\export fn entry() void { |
| ... | ... | @@ -4222,13 +4417,14 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4222 | 4417 | \\} |
| 4223 | 4418 | \\fn foo(set1: Set1) void { |
| 4224 | 4419 | \\ var x: Set2 = set1; |
| 4420 | \\ _ = x; |
| 4225 | 4421 | \\} |
| 4226 | 4422 | , &[_][]const u8{ |
| 4227 | 4423 | "tmp.zig:7:19: error: expected type 'Set2', found 'Set1'", |
| 4228 | 4424 | "tmp.zig:1:23: note: 'error.B' not a member of destination error set", |
| 4229 | 4425 | }); |
| 4230 | 4426 | |
| 4231 | | cases.add("int to err global invalid number", |
| 4427 | ctx.objErrStage1("int to err global invalid number", |
| 4232 | 4428 | \\const Set1 = error{ |
| 4233 | 4429 | \\ A, |
| 4234 | 4430 | \\ B, |
| ... | ... | @@ -4236,12 +4432,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4236 | 4432 | \\comptime { |
| 4237 | 4433 | \\ var x: u16 = 3; |
| 4238 | 4434 | \\ var y = @intToError(x); |
| 4435 | \\ _ = y; |
| 4239 | 4436 | \\} |
| 4240 | 4437 | , &[_][]const u8{ |
| 4241 | 4438 | "tmp.zig:7:13: error: integer value 3 represents no error", |
| 4242 | 4439 | }); |
| 4243 | 4440 | |
| 4244 | | cases.add("int to err non global invalid number", |
| 4441 | ctx.objErrStage1("int to err non global invalid number", |
| 4245 | 4442 | \\const Set1 = error{ |
| 4246 | 4443 | \\ A, |
| 4247 | 4444 | \\ B, |
| ... | ... | @@ -4253,68 +4450,74 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4253 | 4450 | \\comptime { |
| 4254 | 4451 | \\ var x = @errorToInt(Set1.B); |
| 4255 | 4452 | \\ var y = @errSetCast(Set2, @intToError(x)); |
| 4453 | \\ _ = y; |
| 4256 | 4454 | \\} |
| 4257 | 4455 | , &[_][]const u8{ |
| 4258 | 4456 | "tmp.zig:11:13: error: error.B not a member of error set 'Set2'", |
| 4259 | 4457 | }); |
| 4260 | 4458 | |
| 4261 | | cases.add("duplicate error value in error set", |
| 4459 | ctx.objErrStage1("duplicate error value in error set", |
| 4262 | 4460 | \\const Foo = error { |
| 4263 | 4461 | \\ Bar, |
| 4264 | 4462 | \\ Bar, |
| 4265 | 4463 | \\}; |
| 4266 | 4464 | \\export fn entry() void { |
| 4267 | 4465 | \\ const a: Foo = undefined; |
| 4466 | \\ _ = a; |
| 4268 | 4467 | \\} |
| 4269 | 4468 | , &[_][]const u8{ |
| 4270 | 4469 | "tmp.zig:3:5: error: duplicate error: 'Bar'", |
| 4271 | 4470 | "tmp.zig:2:5: note: other error here", |
| 4272 | 4471 | }); |
| 4273 | 4472 | |
| 4274 | | cases.add("cast negative integer literal to usize", |
| 4473 | ctx.objErrStage1("cast negative integer literal to usize", |
| 4275 | 4474 | \\export fn entry() void { |
| 4276 | 4475 | \\ const x = @as(usize, -10); |
| 4476 | \\ _ = x; |
| 4277 | 4477 | \\} |
| 4278 | 4478 | , &[_][]const u8{ |
| 4279 | 4479 | "tmp.zig:2:26: error: cannot cast negative value -10 to unsigned integer type 'usize'", |
| 4280 | 4480 | }); |
| 4281 | 4481 | |
| 4282 | | cases.add("use invalid number literal as array index", |
| 4482 | ctx.objErrStage1("use invalid number literal as array index", |
| 4283 | 4483 | \\var v = 25; |
| 4284 | 4484 | \\export fn entry() void { |
| 4285 | 4485 | \\ var arr: [v]u8 = undefined; |
| 4486 | \\ _ = arr; |
| 4286 | 4487 | \\} |
| 4287 | 4488 | , &[_][]const u8{ |
| 4288 | 4489 | "tmp.zig:1:1: error: unable to infer variable type", |
| 4289 | 4490 | }); |
| 4290 | 4491 | |
| 4291 | | cases.add("duplicate struct field", |
| 4492 | ctx.objErrStage1("duplicate struct field", |
| 4292 | 4493 | \\const Foo = struct { |
| 4293 | 4494 | \\ Bar: i32, |
| 4294 | 4495 | \\ Bar: usize, |
| 4295 | 4496 | \\}; |
| 4296 | 4497 | \\export fn entry() void { |
| 4297 | 4498 | \\ const a: Foo = undefined; |
| 4499 | \\ _ = a; |
| 4298 | 4500 | \\} |
| 4299 | 4501 | , &[_][]const u8{ |
| 4300 | 4502 | "tmp.zig:3:5: error: duplicate struct field: 'Bar'", |
| 4301 | 4503 | "tmp.zig:2:5: note: other field here", |
| 4302 | 4504 | }); |
| 4303 | 4505 | |
| 4304 | | cases.add("duplicate union field", |
| 4506 | ctx.objErrStage1("duplicate union field", |
| 4305 | 4507 | \\const Foo = union { |
| 4306 | 4508 | \\ Bar: i32, |
| 4307 | 4509 | \\ Bar: usize, |
| 4308 | 4510 | \\}; |
| 4309 | 4511 | \\export fn entry() void { |
| 4310 | 4512 | \\ const a: Foo = undefined; |
| 4513 | \\ _ = a; |
| 4311 | 4514 | \\} |
| 4312 | 4515 | , &[_][]const u8{ |
| 4313 | 4516 | "tmp.zig:3:5: error: duplicate union field: 'Bar'", |
| 4314 | 4517 | "tmp.zig:2:5: note: other field here", |
| 4315 | 4518 | }); |
| 4316 | 4519 | |
| 4317 | | cases.add("duplicate enum field", |
| 4520 | ctx.objErrStage1("duplicate enum field", |
| 4318 | 4521 | \\const Foo = enum { |
| 4319 | 4522 | \\ Bar, |
| 4320 | 4523 | \\ Bar, |
| ... | ... | @@ -4322,13 +4525,14 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4322 | 4525 | \\ |
| 4323 | 4526 | \\export fn entry() void { |
| 4324 | 4527 | \\ const a: Foo = undefined; |
| 4528 | \\ _ = a; |
| 4325 | 4529 | \\} |
| 4326 | 4530 | , &[_][]const u8{ |
| 4327 | 4531 | "tmp.zig:3:5: error: duplicate enum field: 'Bar'", |
| 4328 | 4532 | "tmp.zig:2:5: note: other field here", |
| 4329 | 4533 | }); |
| 4330 | 4534 | |
| 4331 | | cases.add("calling function with naked calling convention", |
| 4535 | ctx.objErrStage1("calling function with naked calling convention", |
| 4332 | 4536 | \\export fn entry() void { |
| 4333 | 4537 | \\ foo(); |
| 4334 | 4538 | \\} |
| ... | ... | @@ -4338,42 +4542,42 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4338 | 4542 | "tmp.zig:4:1: note: declared here", |
| 4339 | 4543 | }); |
| 4340 | 4544 | |
| 4341 | | cases.add("function with invalid return type", |
| 4545 | ctx.objErrStage1("function with invalid return type", |
| 4342 | 4546 | \\export fn foo() boid {} |
| 4343 | 4547 | , &[_][]const u8{ |
| 4344 | 4548 | "tmp.zig:1:17: error: use of undeclared identifier 'boid'", |
| 4345 | 4549 | }); |
| 4346 | 4550 | |
| 4347 | | cases.add("function with non-extern non-packed enum parameter", |
| 4551 | ctx.objErrStage1("function with non-extern non-packed enum parameter", |
| 4348 | 4552 | \\const Foo = enum { A, B, C }; |
| 4349 | | \\export fn entry(foo: Foo) void { } |
| 4553 | \\export fn entry(foo: Foo) void { _ = foo; } |
| 4350 | 4554 | , &[_][]const u8{ |
| 4351 | 4555 | "tmp.zig:2:22: error: parameter of type 'Foo' not allowed in function with calling convention 'C'", |
| 4352 | 4556 | }); |
| 4353 | 4557 | |
| 4354 | | cases.add("function with non-extern non-packed struct parameter", |
| 4558 | ctx.objErrStage1("function with non-extern non-packed struct parameter", |
| 4355 | 4559 | \\const Foo = struct { |
| 4356 | 4560 | \\ A: i32, |
| 4357 | 4561 | \\ B: f32, |
| 4358 | 4562 | \\ C: bool, |
| 4359 | 4563 | \\}; |
| 4360 | | \\export fn entry(foo: Foo) void { } |
| 4564 | \\export fn entry(foo: Foo) void { _ = foo; } |
| 4361 | 4565 | , &[_][]const u8{ |
| 4362 | 4566 | "tmp.zig:6:22: error: parameter of type 'Foo' not allowed in function with calling convention 'C'", |
| 4363 | 4567 | }); |
| 4364 | 4568 | |
| 4365 | | cases.add("function with non-extern non-packed union parameter", |
| 4569 | ctx.objErrStage1("function with non-extern non-packed union parameter", |
| 4366 | 4570 | \\const Foo = union { |
| 4367 | 4571 | \\ A: i32, |
| 4368 | 4572 | \\ B: f32, |
| 4369 | 4573 | \\ C: bool, |
| 4370 | 4574 | \\}; |
| 4371 | | \\export fn entry(foo: Foo) void { } |
| 4575 | \\export fn entry(foo: Foo) void { _ = foo; } |
| 4372 | 4576 | , &[_][]const u8{ |
| 4373 | 4577 | "tmp.zig:6:22: error: parameter of type 'Foo' not allowed in function with calling convention 'C'", |
| 4374 | 4578 | }); |
| 4375 | 4579 | |
| 4376 | | cases.add("switch on enum with 1 field with no prongs", |
| 4580 | ctx.objErrStage1("switch on enum with 1 field with no prongs", |
| 4377 | 4581 | \\const Foo = enum { M }; |
| 4378 | 4582 | \\ |
| 4379 | 4583 | \\export fn entry() void { |
| ... | ... | @@ -4384,15 +4588,16 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4384 | 4588 | "tmp.zig:5:5: error: enumeration value 'Foo.M' not handled in switch", |
| 4385 | 4589 | }); |
| 4386 | 4590 | |
| 4387 | | cases.add("shift by negative comptime integer", |
| 4591 | ctx.objErrStage1("shift by negative comptime integer", |
| 4388 | 4592 | \\comptime { |
| 4389 | 4593 | \\ var a = 1 >> -1; |
| 4594 | \\ _ = a; |
| 4390 | 4595 | \\} |
| 4391 | 4596 | , &[_][]const u8{ |
| 4392 | 4597 | "tmp.zig:2:18: error: shift by negative value -1", |
| 4393 | 4598 | }); |
| 4394 | 4599 | |
| 4395 | | cases.add("@panic called at compile time", |
| 4600 | ctx.objErrStage1("@panic called at compile time", |
| 4396 | 4601 | \\export fn entry() void { |
| 4397 | 4602 | \\ comptime { |
| 4398 | 4603 | \\ @panic("aoeu",); |
| ... | ... | @@ -4402,20 +4607,20 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4402 | 4607 | "tmp.zig:3:9: error: encountered @panic at compile-time", |
| 4403 | 4608 | }); |
| 4404 | 4609 | |
| 4405 | | cases.add("wrong return type for main", |
| 4610 | ctx.objErrStage1("wrong return type for main", |
| 4406 | 4611 | \\pub fn main() f32 { } |
| 4407 | 4612 | , &[_][]const u8{ |
| 4408 | 4613 | "error: expected return type of main to be 'void', '!void', 'noreturn', 'u8', or '!u8'", |
| 4409 | 4614 | }); |
| 4410 | 4615 | |
| 4411 | | cases.add("double ?? on main return value", |
| 4616 | ctx.objErrStage1("double ?? on main return value", |
| 4412 | 4617 | \\pub fn main() ??void { |
| 4413 | 4618 | \\} |
| 4414 | 4619 | , &[_][]const u8{ |
| 4415 | 4620 | "error: expected return type of main to be 'void', '!void', 'noreturn', 'u8', or '!u8'", |
| 4416 | 4621 | }); |
| 4417 | 4622 | |
| 4418 | | cases.add("bad identifier in function with struct defined inside function which references local const", |
| 4623 | ctx.objErrStage1("bad identifier in function with struct defined inside function which references local const", |
| 4419 | 4624 | \\export fn entry() void { |
| 4420 | 4625 | \\ const BlockKind = u32; |
| 4421 | 4626 | \\ |
| ... | ... | @@ -4424,12 +4629,14 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4424 | 4629 | \\ }; |
| 4425 | 4630 | \\ |
| 4426 | 4631 | \\ bogus; |
| 4632 | \\ |
| 4633 | \\ _ = Block; |
| 4427 | 4634 | \\} |
| 4428 | 4635 | , &[_][]const u8{ |
| 4429 | 4636 | "tmp.zig:8:5: error: use of undeclared identifier 'bogus'", |
| 4430 | 4637 | }); |
| 4431 | 4638 | |
| 4432 | | cases.add("labeled break not found", |
| 4639 | ctx.objErrStage1("labeled break not found", |
| 4433 | 4640 | \\export fn entry() void { |
| 4434 | 4641 | \\ blah: while (true) { |
| 4435 | 4642 | \\ while (true) { |
| ... | ... | @@ -4438,10 +4645,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4438 | 4645 | \\ } |
| 4439 | 4646 | \\} |
| 4440 | 4647 | , &[_][]const u8{ |
| 4441 | | "tmp.zig:4:13: error: label not found: 'outer'", |
| 4648 | "tmp.zig:4:20: error: label not found: 'outer'", |
| 4442 | 4649 | }); |
| 4443 | 4650 | |
| 4444 | | cases.add("labeled continue not found", |
| 4651 | ctx.objErrStage1("labeled continue not found", |
| 4445 | 4652 | \\export fn entry() void { |
| 4446 | 4653 | \\ var i: usize = 0; |
| 4447 | 4654 | \\ blah: while (i < 10) : (i += 1) { |
| ... | ... | @@ -4451,17 +4658,17 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4451 | 4658 | \\ } |
| 4452 | 4659 | \\} |
| 4453 | 4660 | , &[_][]const u8{ |
| 4454 | | "tmp.zig:5:13: error: labeled loop not found: 'outer'", |
| 4661 | "tmp.zig:5:23: error: label not found: 'outer'", |
| 4455 | 4662 | }); |
| 4456 | 4663 | |
| 4457 | | cases.add("attempt to use 0 bit type in extern fn", |
| 4664 | ctx.objErrStage1("attempt to use 0 bit type in extern fn", |
| 4458 | 4665 | \\extern fn foo(ptr: fn(*void) callconv(.C) void) void; |
| 4459 | 4666 | \\ |
| 4460 | 4667 | \\export fn entry() void { |
| 4461 | 4668 | \\ foo(bar); |
| 4462 | 4669 | \\} |
| 4463 | 4670 | \\ |
| 4464 | | \\fn bar(x: *void) callconv(.C) void { } |
| 4671 | \\fn bar(x: *void) callconv(.C) void { _ = x; } |
| 4465 | 4672 | \\export fn entry2() void { |
| 4466 | 4673 | \\ bar(&{}); |
| 4467 | 4674 | \\} |
| ... | ... | @@ -4470,7 +4677,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4470 | 4677 | "tmp.zig:7:11: error: parameter of type '*void' has 0 bits; not allowed in function with calling convention 'C'", |
| 4471 | 4678 | }); |
| 4472 | 4679 | |
| 4473 | | cases.add("implicit semicolon - block statement", |
| 4680 | ctx.objErrStage1("implicit semicolon - block statement", |
| 4474 | 4681 | \\export fn entry() void { |
| 4475 | 4682 | \\ {} |
| 4476 | 4683 | \\ var good = {}; |
| ... | ... | @@ -4478,10 +4685,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4478 | 4685 | \\ var bad = {}; |
| 4479 | 4686 | \\} |
| 4480 | 4687 | , &[_][]const u8{ |
| 4481 | | "tmp.zig:5:5: error: expected token ';', found 'var'", |
| 4688 | "tmp.zig:5:5: error: expected ';', found 'var'", |
| 4482 | 4689 | }); |
| 4483 | 4690 | |
| 4484 | | cases.add("implicit semicolon - block expr", |
| 4691 | ctx.objErrStage1("implicit semicolon - block expr", |
| 4485 | 4692 | \\export fn entry() void { |
| 4486 | 4693 | \\ _ = {}; |
| 4487 | 4694 | \\ var good = {}; |
| ... | ... | @@ -4489,10 +4696,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4489 | 4696 | \\ var bad = {}; |
| 4490 | 4697 | \\} |
| 4491 | 4698 | , &[_][]const u8{ |
| 4492 | | "tmp.zig:5:5: error: expected token ';', found 'var'", |
| 4699 | "tmp.zig:5:5: error: expected ';', found 'var'", |
| 4493 | 4700 | }); |
| 4494 | 4701 | |
| 4495 | | cases.add("implicit semicolon - comptime statement", |
| 4702 | ctx.objErrStage1("implicit semicolon - comptime statement", |
| 4496 | 4703 | \\export fn entry() void { |
| 4497 | 4704 | \\ comptime {} |
| 4498 | 4705 | \\ var good = {}; |
| ... | ... | @@ -4500,10 +4707,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4500 | 4707 | \\ var bad = {}; |
| 4501 | 4708 | \\} |
| 4502 | 4709 | , &[_][]const u8{ |
| 4503 | | "tmp.zig:5:5: error: expected token ';', found 'var'", |
| 4710 | "tmp.zig:5:5: error: expected ';', found 'var'", |
| 4504 | 4711 | }); |
| 4505 | 4712 | |
| 4506 | | cases.add("implicit semicolon - comptime expression", |
| 4713 | ctx.objErrStage1("implicit semicolon - comptime expression", |
| 4507 | 4714 | \\export fn entry() void { |
| 4508 | 4715 | \\ _ = comptime {}; |
| 4509 | 4716 | \\ var good = {}; |
| ... | ... | @@ -4511,10 +4718,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4511 | 4718 | \\ var bad = {}; |
| 4512 | 4719 | \\} |
| 4513 | 4720 | , &[_][]const u8{ |
| 4514 | | "tmp.zig:5:5: error: expected token ';', found 'var'", |
| 4721 | "tmp.zig:5:5: error: expected ';', found 'var'", |
| 4515 | 4722 | }); |
| 4516 | 4723 | |
| 4517 | | cases.add("implicit semicolon - defer", |
| 4724 | ctx.objErrStage1("implicit semicolon - defer", |
| 4518 | 4725 | \\export fn entry() void { |
| 4519 | 4726 | \\ defer {} |
| 4520 | 4727 | \\ var good = {}; |
| ... | ... | @@ -4522,10 +4729,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4522 | 4729 | \\ var bad = {}; |
| 4523 | 4730 | \\} |
| 4524 | 4731 | , &[_][]const u8{ |
| 4525 | | "tmp.zig:5:5: error: expected token ';', found 'var'", |
| 4732 | "tmp.zig:5:5: error: expected ';', found 'var'", |
| 4526 | 4733 | }); |
| 4527 | 4734 | |
| 4528 | | cases.add("implicit semicolon - if statement", |
| 4735 | ctx.objErrStage1("implicit semicolon - if statement", |
| 4529 | 4736 | \\export fn entry() void { |
| 4530 | 4737 | \\ if(true) {} |
| 4531 | 4738 | \\ var good = {}; |
| ... | ... | @@ -4533,10 +4740,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4533 | 4740 | \\ var bad = {}; |
| 4534 | 4741 | \\} |
| 4535 | 4742 | , &[_][]const u8{ |
| 4536 | | "tmp.zig:5:5: error: expected token ';', found 'var'", |
| 4743 | "tmp.zig:5:5: error: expected ';' or 'else', found 'var'", |
| 4537 | 4744 | }); |
| 4538 | 4745 | |
| 4539 | | cases.add("implicit semicolon - if expression", |
| 4746 | ctx.objErrStage1("implicit semicolon - if expression", |
| 4540 | 4747 | \\export fn entry() void { |
| 4541 | 4748 | \\ _ = if(true) {}; |
| 4542 | 4749 | \\ var good = {}; |
| ... | ... | @@ -4544,10 +4751,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4544 | 4751 | \\ var bad = {}; |
| 4545 | 4752 | \\} |
| 4546 | 4753 | , &[_][]const u8{ |
| 4547 | | "tmp.zig:5:5: error: expected token ';', found 'var'", |
| 4754 | "tmp.zig:5:5: error: expected ';', found 'var'", |
| 4548 | 4755 | }); |
| 4549 | 4756 | |
| 4550 | | cases.add("implicit semicolon - if-else statement", |
| 4757 | ctx.objErrStage1("implicit semicolon - if-else statement", |
| 4551 | 4758 | \\export fn entry() void { |
| 4552 | 4759 | \\ if(true) {} else {} |
| 4553 | 4760 | \\ var good = {}; |
| ... | ... | @@ -4555,10 +4762,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4555 | 4762 | \\ var bad = {}; |
| 4556 | 4763 | \\} |
| 4557 | 4764 | , &[_][]const u8{ |
| 4558 | | "tmp.zig:5:5: error: expected token ';', found 'var'", |
| 4765 | "tmp.zig:5:5: error: expected ';', found 'var'", |
| 4559 | 4766 | }); |
| 4560 | 4767 | |
| 4561 | | cases.add("implicit semicolon - if-else expression", |
| 4768 | ctx.objErrStage1("implicit semicolon - if-else expression", |
| 4562 | 4769 | \\export fn entry() void { |
| 4563 | 4770 | \\ _ = if(true) {} else {}; |
| 4564 | 4771 | \\ var good = {}; |
| ... | ... | @@ -4566,10 +4773,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4566 | 4773 | \\ var bad = {}; |
| 4567 | 4774 | \\} |
| 4568 | 4775 | , &[_][]const u8{ |
| 4569 | | "tmp.zig:5:5: error: expected token ';', found 'var'", |
| 4776 | "tmp.zig:5:5: error: expected ';', found 'var'", |
| 4570 | 4777 | }); |
| 4571 | 4778 | |
| 4572 | | cases.add("implicit semicolon - if-else-if statement", |
| 4779 | ctx.objErrStage1("implicit semicolon - if-else-if statement", |
| 4573 | 4780 | \\export fn entry() void { |
| 4574 | 4781 | \\ if(true) {} else if(true) {} |
| 4575 | 4782 | \\ var good = {}; |
| ... | ... | @@ -4577,10 +4784,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4577 | 4784 | \\ var bad = {}; |
| 4578 | 4785 | \\} |
| 4579 | 4786 | , &[_][]const u8{ |
| 4580 | | "tmp.zig:5:5: error: expected token ';', found 'var'", |
| 4787 | "tmp.zig:5:5: error: expected ';' or 'else', found 'var'", |
| 4581 | 4788 | }); |
| 4582 | 4789 | |
| 4583 | | cases.add("implicit semicolon - if-else-if expression", |
| 4790 | ctx.objErrStage1("implicit semicolon - if-else-if expression", |
| 4584 | 4791 | \\export fn entry() void { |
| 4585 | 4792 | \\ _ = if(true) {} else if(true) {}; |
| 4586 | 4793 | \\ var good = {}; |
| ... | ... | @@ -4588,10 +4795,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4588 | 4795 | \\ var bad = {}; |
| 4589 | 4796 | \\} |
| 4590 | 4797 | , &[_][]const u8{ |
| 4591 | | "tmp.zig:5:5: error: expected token ';', found 'var'", |
| 4798 | "tmp.zig:5:5: error: expected ';', found 'var'", |
| 4592 | 4799 | }); |
| 4593 | 4800 | |
| 4594 | | cases.add("implicit semicolon - if-else-if-else statement", |
| 4801 | ctx.objErrStage1("implicit semicolon - if-else-if-else statement", |
| 4595 | 4802 | \\export fn entry() void { |
| 4596 | 4803 | \\ if(true) {} else if(true) {} else {} |
| 4597 | 4804 | \\ var good = {}; |
| ... | ... | @@ -4599,10 +4806,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4599 | 4806 | \\ var bad = {}; |
| 4600 | 4807 | \\} |
| 4601 | 4808 | , &[_][]const u8{ |
| 4602 | | "tmp.zig:5:5: error: expected token ';', found 'var'", |
| 4809 | "tmp.zig:5:5: error: expected ';', found 'var'", |
| 4603 | 4810 | }); |
| 4604 | 4811 | |
| 4605 | | cases.add("implicit semicolon - if-else-if-else expression", |
| 4812 | ctx.objErrStage1("implicit semicolon - if-else-if-else expression", |
| 4606 | 4813 | \\export fn entry() void { |
| 4607 | 4814 | \\ _ = if(true) {} else if(true) {} else {}; |
| 4608 | 4815 | \\ var good = {}; |
| ... | ... | @@ -4610,10 +4817,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4610 | 4817 | \\ var bad = {}; |
| 4611 | 4818 | \\} |
| 4612 | 4819 | , &[_][]const u8{ |
| 4613 | | "tmp.zig:5:5: error: expected token ';', found 'var'", |
| 4820 | "tmp.zig:5:5: error: expected ';', found 'var'", |
| 4614 | 4821 | }); |
| 4615 | 4822 | |
| 4616 | | cases.add("implicit semicolon - test statement", |
| 4823 | ctx.objErrStage1("implicit semicolon - test statement", |
| 4617 | 4824 | \\export fn entry() void { |
| 4618 | 4825 | \\ if (foo()) |_| {} |
| 4619 | 4826 | \\ var good = {}; |
| ... | ... | @@ -4621,10 +4828,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4621 | 4828 | \\ var bad = {}; |
| 4622 | 4829 | \\} |
| 4623 | 4830 | , &[_][]const u8{ |
| 4624 | | "tmp.zig:5:5: error: expected token ';', found 'var'", |
| 4831 | "tmp.zig:5:5: error: expected ';' or 'else', found 'var'", |
| 4625 | 4832 | }); |
| 4626 | 4833 | |
| 4627 | | cases.add("implicit semicolon - test expression", |
| 4834 | ctx.objErrStage1("implicit semicolon - test expression", |
| 4628 | 4835 | \\export fn entry() void { |
| 4629 | 4836 | \\ _ = if (foo()) |_| {}; |
| 4630 | 4837 | \\ var good = {}; |
| ... | ... | @@ -4632,10 +4839,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4632 | 4839 | \\ var bad = {}; |
| 4633 | 4840 | \\} |
| 4634 | 4841 | , &[_][]const u8{ |
| 4635 | | "tmp.zig:5:5: error: expected token ';', found 'var'", |
| 4842 | "tmp.zig:5:5: error: expected ';', found 'var'", |
| 4636 | 4843 | }); |
| 4637 | 4844 | |
| 4638 | | cases.add("implicit semicolon - while statement", |
| 4845 | ctx.objErrStage1("implicit semicolon - while statement", |
| 4639 | 4846 | \\export fn entry() void { |
| 4640 | 4847 | \\ while(true) {} |
| 4641 | 4848 | \\ var good = {}; |
| ... | ... | @@ -4643,10 +4850,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4643 | 4850 | \\ var bad = {}; |
| 4644 | 4851 | \\} |
| 4645 | 4852 | , &[_][]const u8{ |
| 4646 | | "tmp.zig:5:5: error: expected token ';', found 'var'", |
| 4853 | "tmp.zig:5:5: error: expected ';' or 'else', found 'var'", |
| 4647 | 4854 | }); |
| 4648 | 4855 | |
| 4649 | | cases.add("implicit semicolon - while expression", |
| 4856 | ctx.objErrStage1("implicit semicolon - while expression", |
| 4650 | 4857 | \\export fn entry() void { |
| 4651 | 4858 | \\ _ = while(true) {}; |
| 4652 | 4859 | \\ var good = {}; |
| ... | ... | @@ -4654,10 +4861,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4654 | 4861 | \\ var bad = {}; |
| 4655 | 4862 | \\} |
| 4656 | 4863 | , &[_][]const u8{ |
| 4657 | | "tmp.zig:5:5: error: expected token ';', found 'var'", |
| 4864 | "tmp.zig:5:5: error: expected ';', found 'var'", |
| 4658 | 4865 | }); |
| 4659 | 4866 | |
| 4660 | | cases.add("implicit semicolon - while-continue statement", |
| 4867 | ctx.objErrStage1("implicit semicolon - while-continue statement", |
| 4661 | 4868 | \\export fn entry() void { |
| 4662 | 4869 | \\ while(true):({}) {} |
| 4663 | 4870 | \\ var good = {}; |
| ... | ... | @@ -4665,10 +4872,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4665 | 4872 | \\ var bad = {}; |
| 4666 | 4873 | \\} |
| 4667 | 4874 | , &[_][]const u8{ |
| 4668 | | "tmp.zig:5:5: error: expected token ';', found 'var'", |
| 4875 | "tmp.zig:5:5: error: expected ';' or 'else', found 'var'", |
| 4669 | 4876 | }); |
| 4670 | 4877 | |
| 4671 | | cases.add("implicit semicolon - while-continue expression", |
| 4878 | ctx.objErrStage1("implicit semicolon - while-continue expression", |
| 4672 | 4879 | \\export fn entry() void { |
| 4673 | 4880 | \\ _ = while(true):({}) {}; |
| 4674 | 4881 | \\ var good = {}; |
| ... | ... | @@ -4676,10 +4883,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4676 | 4883 | \\ var bad = {}; |
| 4677 | 4884 | \\} |
| 4678 | 4885 | , &[_][]const u8{ |
| 4679 | | "tmp.zig:5:5: error: expected token ';', found 'var'", |
| 4886 | "tmp.zig:5:5: error: expected ';', found 'var'", |
| 4680 | 4887 | }); |
| 4681 | 4888 | |
| 4682 | | cases.add("implicit semicolon - for statement", |
| 4889 | ctx.objErrStage1("implicit semicolon - for statement", |
| 4683 | 4890 | \\export fn entry() void { |
| 4684 | 4891 | \\ for(foo()) |_| {} |
| 4685 | 4892 | \\ var good = {}; |
| ... | ... | @@ -4687,10 +4894,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4687 | 4894 | \\ var bad = {}; |
| 4688 | 4895 | \\} |
| 4689 | 4896 | , &[_][]const u8{ |
| 4690 | | "tmp.zig:5:5: error: expected token ';', found 'var'", |
| 4897 | "tmp.zig:5:5: error: expected ';' or 'else', found 'var'", |
| 4691 | 4898 | }); |
| 4692 | 4899 | |
| 4693 | | cases.add("implicit semicolon - for expression", |
| 4900 | ctx.objErrStage1("implicit semicolon - for expression", |
| 4694 | 4901 | \\export fn entry() void { |
| 4695 | 4902 | \\ _ = for(foo()) |_| {}; |
| 4696 | 4903 | \\ var good = {}; |
| ... | ... | @@ -4698,32 +4905,33 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4698 | 4905 | \\ var bad = {}; |
| 4699 | 4906 | \\} |
| 4700 | 4907 | , &[_][]const u8{ |
| 4701 | | "tmp.zig:5:5: error: expected token ';', found 'var'", |
| 4908 | "tmp.zig:5:5: error: expected ';', found 'var'", |
| 4702 | 4909 | }); |
| 4703 | 4910 | |
| 4704 | | cases.add("multiple function definitions", |
| 4911 | ctx.objErrStage1("multiple function definitions", |
| 4705 | 4912 | \\fn a() void {} |
| 4706 | 4913 | \\fn a() void {} |
| 4707 | 4914 | \\export fn entry() void { a(); } |
| 4708 | 4915 | , &[_][]const u8{ |
| 4709 | | "tmp.zig:2:1: error: redefinition of 'a'", |
| 4916 | "tmp.zig:2:1: error: redeclaration of 'a'", |
| 4917 | "tmp.zig:1:1: note: other declaration here", |
| 4710 | 4918 | }); |
| 4711 | 4919 | |
| 4712 | | cases.add("unreachable with return", |
| 4920 | ctx.objErrStage1("unreachable with return", |
| 4713 | 4921 | \\fn a() noreturn {return;} |
| 4714 | 4922 | \\export fn entry() void { a(); } |
| 4715 | 4923 | , &[_][]const u8{ |
| 4716 | 4924 | "tmp.zig:1:18: error: expected type 'noreturn', found 'void'", |
| 4717 | 4925 | }); |
| 4718 | 4926 | |
| 4719 | | cases.add("control reaches end of non-void function", |
| 4927 | ctx.objErrStage1("control reaches end of non-void function", |
| 4720 | 4928 | \\fn a() i32 {} |
| 4721 | 4929 | \\export fn entry() void { _ = a(); } |
| 4722 | 4930 | , &[_][]const u8{ |
| 4723 | 4931 | "tmp.zig:1:12: error: expected type 'i32', found 'void'", |
| 4724 | 4932 | }); |
| 4725 | 4933 | |
| 4726 | | cases.add("undefined function call", |
| 4934 | ctx.objErrStage1("undefined function call", |
| 4727 | 4935 | \\export fn a() void { |
| 4728 | 4936 | \\ b(); |
| 4729 | 4937 | \\} |
| ... | ... | @@ -4731,30 +4939,30 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4731 | 4939 | "tmp.zig:2:5: error: use of undeclared identifier 'b'", |
| 4732 | 4940 | }); |
| 4733 | 4941 | |
| 4734 | | cases.add("wrong number of arguments", |
| 4942 | ctx.objErrStage1("wrong number of arguments", |
| 4735 | 4943 | \\export fn a() void { |
| 4736 | | \\ b(1); |
| 4944 | \\ c(1); |
| 4737 | 4945 | \\} |
| 4738 | | \\fn b(a: i32, b: i32, c: i32) void { } |
| 4946 | \\fn c(d: i32, e: i32, f: i32) void { _ = d; _ = e; _ = f; } |
| 4739 | 4947 | , &[_][]const u8{ |
| 4740 | 4948 | "tmp.zig:2:6: error: expected 3 argument(s), found 1", |
| 4741 | 4949 | }); |
| 4742 | 4950 | |
| 4743 | | cases.add("invalid type", |
| 4951 | ctx.objErrStage1("invalid type", |
| 4744 | 4952 | \\fn a() bogus {} |
| 4745 | 4953 | \\export fn entry() void { _ = a(); } |
| 4746 | 4954 | , &[_][]const u8{ |
| 4747 | 4955 | "tmp.zig:1:8: error: use of undeclared identifier 'bogus'", |
| 4748 | 4956 | }); |
| 4749 | 4957 | |
| 4750 | | cases.add("pointer to noreturn", |
| 4958 | ctx.objErrStage1("pointer to noreturn", |
| 4751 | 4959 | \\fn a() *noreturn {} |
| 4752 | 4960 | \\export fn entry() void { _ = a(); } |
| 4753 | 4961 | , &[_][]const u8{ |
| 4754 | 4962 | "tmp.zig:1:9: error: pointer to noreturn not allowed", |
| 4755 | 4963 | }); |
| 4756 | 4964 | |
| 4757 | | cases.add("unreachable code", |
| 4965 | ctx.objErrStage1("unreachable code", |
| 4758 | 4966 | \\export fn a() void { |
| 4759 | 4967 | \\ return; |
| 4760 | 4968 | \\ b(); |
| ... | ... | @@ -4762,17 +4970,17 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4762 | 4970 | \\ |
| 4763 | 4971 | \\fn b() void {} |
| 4764 | 4972 | , &[_][]const u8{ |
| 4765 | | "tmp.zig:3:5: error: unreachable code", |
| 4973 | "tmp.zig:3:6: error: unreachable code", |
| 4974 | "tmp.zig:2:5: note: control flow is diverted here", |
| 4766 | 4975 | }); |
| 4767 | 4976 | |
| 4768 | | cases.add("bad import", |
| 4977 | ctx.objErrStage1("bad import", |
| 4769 | 4978 | \\const bogus = @import("bogus-does-not-exist.zig",); |
| 4770 | | \\export fn entry() void { bogus.bogo(); } |
| 4771 | 4979 | , &[_][]const u8{ |
| 4772 | | "tmp.zig:1:15: error: unable to find 'bogus-does-not-exist.zig'", |
| 4980 | "tmp.zig:1:23: error: unable to load '${DIR}bogus-does-not-exist.zig': FileNotFound", |
| 4773 | 4981 | }); |
| 4774 | 4982 | |
| 4775 | | cases.add("undeclared identifier", |
| 4983 | ctx.objErrStage1("undeclared identifier", |
| 4776 | 4984 | \\export fn a() void { |
| 4777 | 4985 | \\ return |
| 4778 | 4986 | \\ b + |
| ... | ... | @@ -4782,33 +4990,36 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4782 | 4990 | "tmp.zig:3:5: error: use of undeclared identifier 'b'", |
| 4783 | 4991 | }); |
| 4784 | 4992 | |
| 4785 | | cases.add("parameter redeclaration", |
| 4993 | ctx.objErrStage1("parameter redeclaration", |
| 4786 | 4994 | \\fn f(a : i32, a : i32) void { |
| 4787 | 4995 | \\} |
| 4788 | 4996 | \\export fn entry() void { f(1, 2); } |
| 4789 | 4997 | , &[_][]const u8{ |
| 4790 | | "tmp.zig:1:15: error: redeclaration of variable 'a'", |
| 4998 | "tmp.zig:1:15: error: redeclaration of function parameter 'a'", |
| 4999 | "tmp.zig:1:6: note: previous declaration here", |
| 4791 | 5000 | }); |
| 4792 | 5001 | |
| 4793 | | cases.add("local variable redeclaration", |
| 5002 | ctx.objErrStage1("local variable redeclaration", |
| 4794 | 5003 | \\export fn f() void { |
| 4795 | 5004 | \\ const a : i32 = 0; |
| 4796 | | \\ const a = 0; |
| 5005 | \\ var a = 0; |
| 4797 | 5006 | \\} |
| 4798 | 5007 | , &[_][]const u8{ |
| 4799 | | "tmp.zig:3:5: error: redeclaration of variable 'a'", |
| 5008 | "tmp.zig:3:9: error: redeclaration of local constant 'a'", |
| 5009 | "tmp.zig:2:11: note: previous declaration here", |
| 4800 | 5010 | }); |
| 4801 | 5011 | |
| 4802 | | cases.add("local variable redeclares parameter", |
| 5012 | ctx.objErrStage1("local variable redeclares parameter", |
| 4803 | 5013 | \\fn f(a : i32) void { |
| 4804 | 5014 | \\ const a = 0; |
| 4805 | 5015 | \\} |
| 4806 | 5016 | \\export fn entry() void { f(1); } |
| 4807 | 5017 | , &[_][]const u8{ |
| 4808 | | "tmp.zig:2:5: error: redeclaration of variable 'a'", |
| 5018 | "tmp.zig:2:11: error: redeclaration of function parameter 'a'", |
| 5019 | "tmp.zig:1:6: note: previous declaration here", |
| 4809 | 5020 | }); |
| 4810 | 5021 | |
| 4811 | | cases.add("variable has wrong type", |
| 5022 | ctx.objErrStage1("variable has wrong type", |
| 4812 | 5023 | \\export fn f() i32 { |
| 4813 | 5024 | \\ const a = "a"; |
| 4814 | 5025 | \\ return a; |
| ... | ... | @@ -4817,7 +5028,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4817 | 5028 | "tmp.zig:3:12: error: expected type 'i32', found '*const [1:0]u8'", |
| 4818 | 5029 | }); |
| 4819 | 5030 | |
| 4820 | | cases.add("if condition is bool, not int", |
| 5031 | ctx.objErrStage1("if condition is bool, not int", |
| 4821 | 5032 | \\export fn f() void { |
| 4822 | 5033 | \\ if (0) {} |
| 4823 | 5034 | \\} |
| ... | ... | @@ -4825,30 +5036,32 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4825 | 5036 | "tmp.zig:2:9: error: expected type 'bool', found 'comptime_int'", |
| 4826 | 5037 | }); |
| 4827 | 5038 | |
| 4828 | | cases.add("assign unreachable", |
| 5039 | ctx.objErrStage1("assign unreachable", |
| 4829 | 5040 | \\export fn f() void { |
| 4830 | 5041 | \\ const a = return; |
| 4831 | 5042 | \\} |
| 4832 | 5043 | , &[_][]const u8{ |
| 4833 | 5044 | "tmp.zig:2:5: error: unreachable code", |
| 5045 | "tmp.zig:2:15: note: control flow is diverted here", |
| 4834 | 5046 | }); |
| 4835 | 5047 | |
| 4836 | | cases.add("unreachable variable", |
| 5048 | ctx.objErrStage1("unreachable variable", |
| 4837 | 5049 | \\export fn f() void { |
| 4838 | 5050 | \\ const a: noreturn = {}; |
| 5051 | \\ _ = a; |
| 4839 | 5052 | \\} |
| 4840 | 5053 | , &[_][]const u8{ |
| 4841 | 5054 | "tmp.zig:2:25: error: expected type 'noreturn', found 'void'", |
| 4842 | 5055 | }); |
| 4843 | 5056 | |
| 4844 | | cases.add("unreachable parameter", |
| 4845 | | \\fn f(a: noreturn) void {} |
| 5057 | ctx.objErrStage1("unreachable parameter", |
| 5058 | \\fn f(a: noreturn) void { _ = a; } |
| 4846 | 5059 | \\export fn entry() void { f(); } |
| 4847 | 5060 | , &[_][]const u8{ |
| 4848 | 5061 | "tmp.zig:1:9: error: parameter of type 'noreturn' not allowed", |
| 4849 | 5062 | }); |
| 4850 | 5063 | |
| 4851 | | cases.add("assign to constant variable", |
| 5064 | ctx.objErrStage1("assign to constant variable", |
| 4852 | 5065 | \\export fn f() void { |
| 4853 | 5066 | \\ const a = 3; |
| 4854 | 5067 | \\ a = 4; |
| ... | ... | @@ -4857,7 +5070,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4857 | 5070 | "tmp.zig:3:9: error: cannot assign to constant", |
| 4858 | 5071 | }); |
| 4859 | 5072 | |
| 4860 | | cases.add("use of undeclared identifier", |
| 5073 | ctx.objErrStage1("use of undeclared identifier", |
| 4861 | 5074 | \\export fn f() void { |
| 4862 | 5075 | \\ b = 3; |
| 4863 | 5076 | \\} |
| ... | ... | @@ -4865,15 +5078,15 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4865 | 5078 | "tmp.zig:2:5: error: use of undeclared identifier 'b'", |
| 4866 | 5079 | }); |
| 4867 | 5080 | |
| 4868 | | cases.add("const is a statement, not an expression", |
| 5081 | ctx.objErrStage1("const is a statement, not an expression", |
| 4869 | 5082 | \\export fn f() void { |
| 4870 | 5083 | \\ (const a = 0); |
| 4871 | 5084 | \\} |
| 4872 | 5085 | , &[_][]const u8{ |
| 4873 | | "tmp.zig:2:6: error: invalid token: 'const'", |
| 5086 | "tmp.zig:2:6: error: expected expression, found 'const'", |
| 4874 | 5087 | }); |
| 4875 | 5088 | |
| 4876 | | cases.add("array access of undeclared identifier", |
| 5089 | ctx.objErrStage1("array access of undeclared identifier", |
| 4877 | 5090 | \\export fn f() void { |
| 4878 | 5091 | \\ i[i] = i[i]; |
| 4879 | 5092 | \\} |
| ... | ... | @@ -4881,7 +5094,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4881 | 5094 | "tmp.zig:2:5: error: use of undeclared identifier 'i'", |
| 4882 | 5095 | }); |
| 4883 | 5096 | |
| 4884 | | cases.add("array access of non array", |
| 5097 | ctx.objErrStage1("array access of non array", |
| 4885 | 5098 | \\export fn f() void { |
| 4886 | 5099 | \\ var bad : bool = undefined; |
| 4887 | 5100 | \\ bad[0] = bad[0]; |
| ... | ... | @@ -4895,7 +5108,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4895 | 5108 | "tmp.zig:7:12: error: array access of non-array type 'bool'", |
| 4896 | 5109 | }); |
| 4897 | 5110 | |
| 4898 | | cases.add("array access with non integer index", |
| 5111 | ctx.objErrStage1("array access with non integer index", |
| 4899 | 5112 | \\export fn f() void { |
| 4900 | 5113 | \\ var array = "aoeu"; |
| 4901 | 5114 | \\ var bad = false; |
| ... | ... | @@ -4911,7 +5124,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4911 | 5124 | "tmp.zig:9:15: error: expected type 'usize', found 'bool'", |
| 4912 | 5125 | }); |
| 4913 | 5126 | |
| 4914 | | cases.add("write to const global variable", |
| 5127 | ctx.objErrStage1("write to const global variable", |
| 4915 | 5128 | \\const x : i32 = 99; |
| 4916 | 5129 | \\fn f() void { |
| 4917 | 5130 | \\ x = 1; |
| ... | ... | @@ -4921,58 +5134,64 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4921 | 5134 | "tmp.zig:3:9: error: cannot assign to constant", |
| 4922 | 5135 | }); |
| 4923 | 5136 | |
| 4924 | | cases.add("missing else clause", |
| 5137 | ctx.objErrStage1("missing else clause", |
| 4925 | 5138 | \\fn f(b: bool) void { |
| 4926 | 5139 | \\ const x : i32 = if (b) h: { break :h 1; }; |
| 5140 | \\ _ = x; |
| 4927 | 5141 | \\} |
| 4928 | 5142 | \\fn g(b: bool) void { |
| 4929 | 5143 | \\ const y = if (b) h: { break :h @as(i32, 1); }; |
| 5144 | \\ _ = y; |
| 4930 | 5145 | \\} |
| 4931 | 5146 | \\export fn entry() void { f(true); g(true); } |
| 4932 | 5147 | , &[_][]const u8{ |
| 4933 | 5148 | "tmp.zig:2:21: error: expected type 'i32', found 'void'", |
| 4934 | | "tmp.zig:5:15: error: incompatible types: 'i32' and 'void'", |
| 5149 | "tmp.zig:6:15: error: incompatible types: 'i32' and 'void'", |
| 4935 | 5150 | }); |
| 4936 | 5151 | |
| 4937 | | cases.add("invalid struct field", |
| 5152 | ctx.objErrStage1("invalid struct field", |
| 4938 | 5153 | \\const A = struct { x : i32, }; |
| 4939 | 5154 | \\export fn f() void { |
| 4940 | 5155 | \\ var a : A = undefined; |
| 4941 | 5156 | \\ a.foo = 1; |
| 4942 | 5157 | \\ const y = a.bar; |
| 5158 | \\ _ = y; |
| 4943 | 5159 | \\} |
| 4944 | 5160 | \\export fn g() void { |
| 4945 | 5161 | \\ var a : A = undefined; |
| 4946 | 5162 | \\ const y = a.bar; |
| 5163 | \\ _ = y; |
| 4947 | 5164 | \\} |
| 4948 | 5165 | , &[_][]const u8{ |
| 4949 | 5166 | "tmp.zig:4:6: error: no member named 'foo' in struct 'A'", |
| 4950 | | "tmp.zig:9:16: error: no member named 'bar' in struct 'A'", |
| 5167 | "tmp.zig:10:16: error: no member named 'bar' in struct 'A'", |
| 4951 | 5168 | }); |
| 4952 | 5169 | |
| 4953 | | cases.add("redefinition of struct", |
| 5170 | ctx.objErrStage1("redefinition of struct", |
| 4954 | 5171 | \\const A = struct { x : i32, }; |
| 4955 | 5172 | \\const A = struct { y : i32, }; |
| 4956 | 5173 | , &[_][]const u8{ |
| 4957 | | "tmp.zig:2:1: error: redefinition of 'A'", |
| 5174 | "tmp.zig:2:1: error: redeclaration of 'A'", |
| 5175 | "tmp.zig:1:1: note: other declaration here", |
| 4958 | 5176 | }); |
| 4959 | 5177 | |
| 4960 | | cases.add("redefinition of enums", |
| 4961 | | \\const A = enum {}; |
| 4962 | | \\const A = enum {}; |
| 5178 | ctx.objErrStage1("redefinition of enums", |
| 5179 | \\const A = enum {x}; |
| 5180 | \\const A = enum {x}; |
| 4963 | 5181 | , &[_][]const u8{ |
| 4964 | | "tmp.zig:2:1: error: redefinition of 'A'", |
| 5182 | "tmp.zig:2:1: error: redeclaration of 'A'", |
| 5183 | "tmp.zig:1:1: note: other declaration here", |
| 4965 | 5184 | }); |
| 4966 | 5185 | |
| 4967 | | cases.add("redefinition of global variables", |
| 5186 | ctx.objErrStage1("redefinition of global variables", |
| 4968 | 5187 | \\var a : i32 = 1; |
| 4969 | 5188 | \\var a : i32 = 2; |
| 4970 | 5189 | , &[_][]const u8{ |
| 4971 | | "tmp.zig:2:1: error: redefinition of 'a'", |
| 4972 | | "tmp.zig:1:1: note: previous definition is here", |
| 5190 | "tmp.zig:2:1: error: redeclaration of 'a'", |
| 5191 | "tmp.zig:1:1: note: other declaration here", |
| 4973 | 5192 | }); |
| 4974 | 5193 | |
| 4975 | | cases.add("duplicate field in struct value expression", |
| 5194 | ctx.objErrStage1("duplicate field in struct value expression", |
| 4976 | 5195 | \\const A = struct { |
| 4977 | 5196 | \\ x : i32, |
| 4978 | 5197 | \\ y : i32, |
| ... | ... | @@ -4985,12 +5204,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4985 | 5204 | \\ .x = 3, |
| 4986 | 5205 | \\ .z = 4, |
| 4987 | 5206 | \\ }; |
| 5207 | \\ _ = a; |
| 4988 | 5208 | \\} |
| 4989 | 5209 | , &[_][]const u8{ |
| 4990 | 5210 | "tmp.zig:11:9: error: duplicate field", |
| 4991 | 5211 | }); |
| 4992 | 5212 | |
| 4993 | | cases.add("missing field in struct value expression", |
| 5213 | ctx.objErrStage1("missing field in struct value expression", |
| 4994 | 5214 | \\const A = struct { |
| 4995 | 5215 | \\ x : i32, |
| 4996 | 5216 | \\ y : i32, |
| ... | ... | @@ -5003,12 +5223,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5003 | 5223 | \\ .z = 4, |
| 5004 | 5224 | \\ .y = 2, |
| 5005 | 5225 | \\ }; |
| 5226 | \\ _ = a; |
| 5006 | 5227 | \\} |
| 5007 | 5228 | , &[_][]const u8{ |
| 5008 | 5229 | "tmp.zig:9:17: error: missing field: 'x'", |
| 5009 | 5230 | }); |
| 5010 | 5231 | |
| 5011 | | cases.add("invalid field in struct value expression", |
| 5232 | ctx.objErrStage1("invalid field in struct value expression", |
| 5012 | 5233 | \\const A = struct { |
| 5013 | 5234 | \\ x : i32, |
| 5014 | 5235 | \\ y : i32, |
| ... | ... | @@ -5020,12 +5241,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5020 | 5241 | \\ .y = 2, |
| 5021 | 5242 | \\ .foo = 42, |
| 5022 | 5243 | \\ }; |
| 5244 | \\ _ = a; |
| 5023 | 5245 | \\} |
| 5024 | 5246 | , &[_][]const u8{ |
| 5025 | 5247 | "tmp.zig:10:9: error: no member named 'foo' in struct 'A'", |
| 5026 | 5248 | }); |
| 5027 | 5249 | |
| 5028 | | cases.add("invalid break expression", |
| 5250 | ctx.objErrStage1("invalid break expression", |
| 5029 | 5251 | \\export fn f() void { |
| 5030 | 5252 | \\ break; |
| 5031 | 5253 | \\} |
| ... | ... | @@ -5033,7 +5255,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5033 | 5255 | "tmp.zig:2:5: error: break expression outside loop", |
| 5034 | 5256 | }); |
| 5035 | 5257 | |
| 5036 | | cases.add("invalid continue expression", |
| 5258 | ctx.objErrStage1("invalid continue expression", |
| 5037 | 5259 | \\export fn f() void { |
| 5038 | 5260 | \\ continue; |
| 5039 | 5261 | \\} |
| ... | ... | @@ -5041,48 +5263,49 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5041 | 5263 | "tmp.zig:2:5: error: continue expression outside loop", |
| 5042 | 5264 | }); |
| 5043 | 5265 | |
| 5044 | | cases.add("invalid maybe type", |
| 5266 | ctx.objErrStage1("invalid maybe type", |
| 5045 | 5267 | \\export fn f() void { |
| 5046 | | \\ if (true) |x| { } |
| 5268 | \\ if (true) |x| { _ = x; } |
| 5047 | 5269 | \\} |
| 5048 | 5270 | , &[_][]const u8{ |
| 5049 | 5271 | "tmp.zig:2:9: error: expected optional type, found 'bool'", |
| 5050 | 5272 | }); |
| 5051 | 5273 | |
| 5052 | | cases.add("cast unreachable", |
| 5274 | ctx.objErrStage1("cast unreachable", |
| 5053 | 5275 | \\fn f() i32 { |
| 5054 | 5276 | \\ return @as(i32, return 1); |
| 5055 | 5277 | \\} |
| 5056 | 5278 | \\export fn entry() void { _ = f(); } |
| 5057 | 5279 | , &[_][]const u8{ |
| 5058 | 5280 | "tmp.zig:2:12: error: unreachable code", |
| 5281 | "tmp.zig:2:21: note: control flow is diverted here", |
| 5059 | 5282 | }); |
| 5060 | 5283 | |
| 5061 | | cases.add("invalid builtin fn", |
| 5284 | ctx.objErrStage1("invalid builtin fn", |
| 5062 | 5285 | \\fn f() @bogus(foo) { |
| 5063 | 5286 | \\} |
| 5064 | 5287 | \\export fn entry() void { _ = f(); } |
| 5065 | 5288 | , &[_][]const u8{ |
| 5066 | | "tmp.zig:1:8: error: invalid builtin function: 'bogus'", |
| 5289 | "tmp.zig:1:8: error: invalid builtin function: '@bogus'", |
| 5067 | 5290 | }); |
| 5068 | 5291 | |
| 5069 | | cases.add("noalias on non pointer param", |
| 5070 | | \\fn f(noalias x: i32) void {} |
| 5292 | ctx.objErrStage1("noalias on non pointer param", |
| 5293 | \\fn f(noalias x: i32) void { _ = x; } |
| 5071 | 5294 | \\export fn entry() void { f(1234); } |
| 5072 | 5295 | , &[_][]const u8{ |
| 5073 | 5296 | "tmp.zig:1:6: error: noalias on non-pointer parameter", |
| 5074 | 5297 | }); |
| 5075 | 5298 | |
| 5076 | | cases.add("struct init syntax for array", |
| 5299 | ctx.objErrStage1("struct init syntax for array", |
| 5077 | 5300 | \\const foo = [3]u16{ .x = 1024 }; |
| 5078 | 5301 | \\comptime { |
| 5079 | 5302 | \\ _ = foo; |
| 5080 | 5303 | \\} |
| 5081 | 5304 | , &[_][]const u8{ |
| 5082 | | "tmp.zig:1:21: error: type '[3]u16' does not support struct initialization syntax", |
| 5305 | "tmp.zig:1:13: error: initializing array with struct syntax", |
| 5083 | 5306 | }); |
| 5084 | 5307 | |
| 5085 | | cases.add("type variables must be constant", |
| 5308 | ctx.objErrStage1("type variables must be constant", |
| 5086 | 5309 | \\var foo = u8; |
| 5087 | 5310 | \\export fn entry() foo { |
| 5088 | 5311 | \\ return 1; |
| ... | ... | @@ -5091,25 +5314,31 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5091 | 5314 | "tmp.zig:1:1: error: variable of type 'type' must be constant", |
| 5092 | 5315 | }); |
| 5093 | 5316 | |
| 5094 | | cases.add("variables shadowing types", |
| 5317 | ctx.objErrStage1("parameter shadowing global", |
| 5095 | 5318 | \\const Foo = struct {}; |
| 5096 | | \\const Bar = struct {}; |
| 5097 | | \\ |
| 5098 | | \\fn f(Foo: i32) void { |
| 5099 | | \\ var Bar : i32 = undefined; |
| 5319 | \\fn f(Foo: i32) void {} |
| 5320 | \\export fn entry() void { |
| 5321 | \\ f(1234); |
| 5100 | 5322 | \\} |
| 5323 | , &[_][]const u8{ |
| 5324 | "tmp.zig:2:6: error: local shadows declaration of 'Foo'", |
| 5325 | "tmp.zig:1:1: note: declared here", |
| 5326 | }); |
| 5327 | |
| 5328 | ctx.objErrStage1("local variable shadowing global", |
| 5329 | \\const Foo = struct {}; |
| 5330 | \\const Bar = struct {}; |
| 5101 | 5331 | \\ |
| 5102 | 5332 | \\export fn entry() void { |
| 5103 | | \\ f(1234); |
| 5333 | \\ var Bar : i32 = undefined; |
| 5334 | \\ _ = Bar; |
| 5104 | 5335 | \\} |
| 5105 | 5336 | , &[_][]const u8{ |
| 5106 | | "tmp.zig:4:6: error: redefinition of 'Foo'", |
| 5107 | | "tmp.zig:1:1: note: previous definition is here", |
| 5108 | | "tmp.zig:5:5: error: redefinition of 'Bar'", |
| 5109 | | "tmp.zig:2:1: note: previous definition is here", |
| 5337 | "tmp.zig:5:9: error: local shadows declaration of 'Bar'", |
| 5338 | "tmp.zig:2:1: note: declared here", |
| 5110 | 5339 | }); |
| 5111 | 5340 | |
| 5112 | | cases.add("switch expression - missing enumeration prong", |
| 5341 | ctx.objErrStage1("switch expression - missing enumeration prong", |
| 5113 | 5342 | \\const Number = enum { |
| 5114 | 5343 | \\ One, |
| 5115 | 5344 | \\ Two, |
| ... | ... | @@ -5129,7 +5358,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5129 | 5358 | "tmp.zig:8:5: error: enumeration value 'Number.Four' not handled in switch", |
| 5130 | 5359 | }); |
| 5131 | 5360 | |
| 5132 | | cases.add("switch expression - duplicate enumeration prong", |
| 5361 | ctx.objErrStage1("switch expression - duplicate enumeration prong", |
| 5133 | 5362 | \\const Number = enum { |
| 5134 | 5363 | \\ One, |
| 5135 | 5364 | \\ Two, |
| ... | ... | @@ -5149,10 +5378,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5149 | 5378 | \\export fn entry() usize { return @sizeOf(@TypeOf(f)); } |
| 5150 | 5379 | , &[_][]const u8{ |
| 5151 | 5380 | "tmp.zig:13:15: error: duplicate switch value", |
| 5152 | | "tmp.zig:10:15: note: other value is here", |
| 5381 | "tmp.zig:10:15: note: other value here", |
| 5153 | 5382 | }); |
| 5154 | 5383 | |
| 5155 | | cases.add("switch expression - duplicate enumeration prong when else present", |
| 5384 | ctx.objErrStage1("switch expression - duplicate enumeration prong when else present", |
| 5156 | 5385 | \\const Number = enum { |
| 5157 | 5386 | \\ One, |
| 5158 | 5387 | \\ Two, |
| ... | ... | @@ -5173,10 +5402,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5173 | 5402 | \\export fn entry() usize { return @sizeOf(@TypeOf(f)); } |
| 5174 | 5403 | , &[_][]const u8{ |
| 5175 | 5404 | "tmp.zig:13:15: error: duplicate switch value", |
| 5176 | | "tmp.zig:10:15: note: other value is here", |
| 5405 | "tmp.zig:10:15: note: other value here", |
| 5177 | 5406 | }); |
| 5178 | 5407 | |
| 5179 | | cases.add("switch expression - multiple else prongs", |
| 5408 | ctx.objErrStage1("switch expression - multiple else prongs", |
| 5180 | 5409 | \\fn f(x: u32) void { |
| 5181 | 5410 | \\ const value: bool = switch (x) { |
| 5182 | 5411 | \\ 1234 => false, |
| ... | ... | @@ -5191,7 +5420,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5191 | 5420 | "tmp.zig:5:9: error: multiple else prongs in switch expression", |
| 5192 | 5421 | }); |
| 5193 | 5422 | |
| 5194 | | cases.add("switch expression - non exhaustive integer prongs", |
| 5423 | ctx.objErrStage1("switch expression - non exhaustive integer prongs", |
| 5195 | 5424 | \\fn foo(x: u8) void { |
| 5196 | 5425 | \\ switch (x) { |
| 5197 | 5426 | \\ 0 => {}, |
| ... | ... | @@ -5202,7 +5431,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5202 | 5431 | "tmp.zig:2:5: error: switch must handle all possibilities", |
| 5203 | 5432 | }); |
| 5204 | 5433 | |
| 5205 | | cases.add("switch expression - duplicate or overlapping integer value", |
| 5434 | ctx.objErrStage1("switch expression - duplicate or overlapping integer value", |
| 5206 | 5435 | \\fn foo(x: u8) u8 { |
| 5207 | 5436 | \\ return switch (x) { |
| 5208 | 5437 | \\ 0 ... 100 => @as(u8, 0), |
| ... | ... | @@ -5214,11 +5443,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5214 | 5443 | \\export fn entry() usize { return @sizeOf(@TypeOf(foo)); } |
| 5215 | 5444 | , &[_][]const u8{ |
| 5216 | 5445 | "tmp.zig:6:9: error: duplicate switch value", |
| 5217 | | "tmp.zig:5:14: note: previous value is here", |
| 5446 | "tmp.zig:5:14: note: previous value here", |
| 5218 | 5447 | }); |
| 5219 | 5448 | |
| 5220 | | cases.add("switch expression - duplicate type", |
| 5449 | ctx.objErrStage1("switch expression - duplicate type", |
| 5221 | 5450 | \\fn foo(comptime T: type, x: T) u8 { |
| 5451 | \\ _ = x; |
| 5222 | 5452 | \\ return switch (T) { |
| 5223 | 5453 | \\ u32 => 0, |
| 5224 | 5454 | \\ u64 => 1, |
| ... | ... | @@ -5228,16 +5458,17 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5228 | 5458 | \\} |
| 5229 | 5459 | \\export fn entry() usize { return @sizeOf(@TypeOf(foo(u32, 0))); } |
| 5230 | 5460 | , &[_][]const u8{ |
| 5231 | | "tmp.zig:5:9: error: duplicate switch value", |
| 5232 | | "tmp.zig:3:9: note: previous value is here", |
| 5461 | "tmp.zig:6:9: error: duplicate switch value", |
| 5462 | "tmp.zig:4:9: note: previous value here", |
| 5233 | 5463 | }); |
| 5234 | 5464 | |
| 5235 | | cases.add("switch expression - duplicate type (struct alias)", |
| 5465 | ctx.objErrStage1("switch expression - duplicate type (struct alias)", |
| 5236 | 5466 | \\const Test = struct { |
| 5237 | 5467 | \\ bar: i32, |
| 5238 | 5468 | \\}; |
| 5239 | 5469 | \\const Test2 = Test; |
| 5240 | 5470 | \\fn foo(comptime T: type, x: T) u8 { |
| 5471 | \\ _ = x; |
| 5241 | 5472 | \\ return switch (T) { |
| 5242 | 5473 | \\ Test => 0, |
| 5243 | 5474 | \\ u64 => 1, |
| ... | ... | @@ -5247,11 +5478,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5247 | 5478 | \\} |
| 5248 | 5479 | \\export fn entry() usize { return @sizeOf(@TypeOf(foo(u32, 0))); } |
| 5249 | 5480 | , &[_][]const u8{ |
| 5250 | | "tmp.zig:9:9: error: duplicate switch value", |
| 5251 | | "tmp.zig:7:9: note: previous value is here", |
| 5481 | "tmp.zig:10:9: error: duplicate switch value", |
| 5482 | "tmp.zig:8:9: note: previous value here", |
| 5252 | 5483 | }); |
| 5253 | 5484 | |
| 5254 | | cases.add("switch expression - switch on pointer type with no else", |
| 5485 | ctx.objErrStage1("switch expression - switch on pointer type with no else", |
| 5255 | 5486 | \\fn foo(x: *u8) void { |
| 5256 | 5487 | \\ switch (x) { |
| 5257 | 5488 | \\ &y => {}, |
| ... | ... | @@ -5263,7 +5494,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5263 | 5494 | "tmp.zig:2:5: error: else prong required when switching on type '*u8'", |
| 5264 | 5495 | }); |
| 5265 | 5496 | |
| 5266 | | cases.add("global variable initializer must be constant expression", |
| 5497 | ctx.objErrStage1("global variable initializer must be constant expression", |
| 5267 | 5498 | \\extern fn foo() i32; |
| 5268 | 5499 | \\const x = foo(); |
| 5269 | 5500 | \\export fn entry() i32 { return x; } |
| ... | ... | @@ -5271,7 +5502,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5271 | 5502 | "tmp.zig:2:11: error: unable to evaluate constant expression", |
| 5272 | 5503 | }); |
| 5273 | 5504 | |
| 5274 | | cases.add("array concatenation with wrong type", |
| 5505 | ctx.objErrStage1("array concatenation with wrong type", |
| 5275 | 5506 | \\const src = "aoeu"; |
| 5276 | 5507 | \\const derp: usize = 1234; |
| 5277 | 5508 | \\const a = derp ++ "foo"; |
| ... | ... | @@ -5281,7 +5512,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5281 | 5512 | "tmp.zig:3:11: error: expected array, found 'usize'", |
| 5282 | 5513 | }); |
| 5283 | 5514 | |
| 5284 | | cases.add("non compile time array concatenation", |
| 5515 | ctx.objErrStage1("non compile time array concatenation", |
| 5285 | 5516 | \\fn f() []u8 { |
| 5286 | 5517 | \\ return s ++ "foo"; |
| 5287 | 5518 | \\} |
| ... | ... | @@ -5291,7 +5522,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5291 | 5522 | "tmp.zig:2:12: error: unable to evaluate constant expression", |
| 5292 | 5523 | }); |
| 5293 | 5524 | |
| 5294 | | cases.add("@cImport with bogus include", |
| 5525 | ctx.objErrStage1("@cImport with bogus include", |
| 5295 | 5526 | \\const c = @cImport(@cInclude("bogus.h")); |
| 5296 | 5527 | \\export fn entry() usize { return @sizeOf(@TypeOf(c.bogo)); } |
| 5297 | 5528 | , &[_][]const u8{ |
| ... | ... | @@ -5299,7 +5530,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5299 | 5530 | ".h:1:10: note: 'bogus.h' file not found", |
| 5300 | 5531 | }); |
| 5301 | 5532 | |
| 5302 | | cases.add("address of number literal", |
| 5533 | ctx.objErrStage1("address of number literal", |
| 5303 | 5534 | \\const x = 3; |
| 5304 | 5535 | \\const y = &x; |
| 5305 | 5536 | \\fn foo() *const i32 { return y; } |
| ... | ... | @@ -5308,14 +5539,14 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5308 | 5539 | "tmp.zig:3:30: error: expected type '*const i32', found '*const comptime_int'", |
| 5309 | 5540 | }); |
| 5310 | 5541 | |
| 5311 | | cases.add("integer overflow error", |
| 5542 | ctx.objErrStage1("integer overflow error", |
| 5312 | 5543 | \\const x : u8 = 300; |
| 5313 | 5544 | \\export fn entry() usize { return @sizeOf(@TypeOf(x)); } |
| 5314 | 5545 | , &[_][]const u8{ |
| 5315 | 5546 | "tmp.zig:1:16: error: integer value 300 cannot be coerced to type 'u8'", |
| 5316 | 5547 | }); |
| 5317 | 5548 | |
| 5318 | | cases.add("invalid shift amount error", |
| 5549 | ctx.objErrStage1("invalid shift amount error", |
| 5319 | 5550 | \\const x : u8 = 2; |
| 5320 | 5551 | \\fn f() u16 { |
| 5321 | 5552 | \\ return x << 8; |
| ... | ... | @@ -5325,7 +5556,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5325 | 5556 | "tmp.zig:3:17: error: integer value 8 cannot be coerced to type 'u3'", |
| 5326 | 5557 | }); |
| 5327 | 5558 | |
| 5328 | | cases.add("missing function call param", |
| 5559 | ctx.objErrStage1("missing function call param", |
| 5329 | 5560 | \\const Foo = struct { |
| 5330 | 5561 | \\ a: i32, |
| 5331 | 5562 | \\ b: i32, |
| ... | ... | @@ -5346,6 +5577,8 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5346 | 5577 | \\ |
| 5347 | 5578 | \\fn f(foo: *const Foo, index: usize) void { |
| 5348 | 5579 | \\ const result = members[index](); |
| 5580 | \\ _ = foo; |
| 5581 | \\ _ = result; |
| 5349 | 5582 | \\} |
| 5350 | 5583 | \\ |
| 5351 | 5584 | \\export fn entry() usize { return @sizeOf(@TypeOf(f)); } |
| ... | ... | @@ -5353,21 +5586,21 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5353 | 5586 | "tmp.zig:20:34: error: expected 1 argument(s), found 0", |
| 5354 | 5587 | }); |
| 5355 | 5588 | |
| 5356 | | cases.add("missing function name", |
| 5589 | ctx.objErrStage1("missing function name", |
| 5357 | 5590 | \\fn () void {} |
| 5358 | 5591 | \\export fn entry() usize { return @sizeOf(@TypeOf(f)); } |
| 5359 | 5592 | , &[_][]const u8{ |
| 5360 | 5593 | "tmp.zig:1:1: error: missing function name", |
| 5361 | 5594 | }); |
| 5362 | 5595 | |
| 5363 | | cases.add("missing param name", |
| 5596 | ctx.objErrStage1("missing param name", |
| 5364 | 5597 | \\fn f(i32) void {} |
| 5365 | 5598 | \\export fn entry() usize { return @sizeOf(@TypeOf(f)); } |
| 5366 | 5599 | , &[_][]const u8{ |
| 5367 | 5600 | "tmp.zig:1:6: error: missing parameter name", |
| 5368 | 5601 | }); |
| 5369 | 5602 | |
| 5370 | | cases.add("wrong function type", |
| 5603 | ctx.objErrStage1("wrong function type", |
| 5371 | 5604 | \\const fns = [_]fn() void { a, b, c }; |
| 5372 | 5605 | \\fn a() i32 {return 0;} |
| 5373 | 5606 | \\fn b() i32 {return 1;} |
| ... | ... | @@ -5377,7 +5610,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5377 | 5610 | "tmp.zig:1:28: error: expected type 'fn() void', found 'fn() i32'", |
| 5378 | 5611 | }); |
| 5379 | 5612 | |
| 5380 | | cases.add("extern function pointer mismatch", |
| 5613 | ctx.objErrStage1("extern function pointer mismatch", |
| 5381 | 5614 | \\const fns = [_](fn(i32)i32) { a, b, c }; |
| 5382 | 5615 | \\pub fn a(x: i32) i32 {return x + 0;} |
| 5383 | 5616 | \\pub fn b(x: i32) i32 {return x + 1;} |
| ... | ... | @@ -5388,15 +5621,16 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5388 | 5621 | "tmp.zig:1:37: error: expected type 'fn(i32) i32', found 'fn(i32) callconv(.C) i32'", |
| 5389 | 5622 | }); |
| 5390 | 5623 | |
| 5391 | | cases.add("colliding invalid top level functions", |
| 5624 | ctx.objErrStage1("colliding invalid top level functions", |
| 5392 | 5625 | \\fn func() bogus {} |
| 5393 | 5626 | \\fn func() bogus {} |
| 5394 | 5627 | \\export fn entry() usize { return @sizeOf(@TypeOf(func)); } |
| 5395 | 5628 | , &[_][]const u8{ |
| 5396 | | "tmp.zig:2:1: error: redefinition of 'func'", |
| 5629 | "tmp.zig:2:1: error: redeclaration of 'func'", |
| 5630 | "tmp.zig:1:1: note: other declaration here", |
| 5397 | 5631 | }); |
| 5398 | 5632 | |
| 5399 | | cases.add("non constant expression in array size", |
| 5633 | ctx.objErrStage1("non constant expression in array size", |
| 5400 | 5634 | \\const Foo = struct { |
| 5401 | 5635 | \\ y: [get()]u8, |
| 5402 | 5636 | \\}; |
| ... | ... | @@ -5409,7 +5643,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5409 | 5643 | "tmp.zig:2:12: note: called from here", |
| 5410 | 5644 | }); |
| 5411 | 5645 | |
| 5412 | | cases.add("addition with non numbers", |
| 5646 | ctx.objErrStage1("addition with non numbers", |
| 5413 | 5647 | \\const Foo = struct { |
| 5414 | 5648 | \\ field: i32, |
| 5415 | 5649 | \\}; |
| ... | ... | @@ -5420,7 +5654,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5420 | 5654 | "tmp.zig:4:28: error: invalid operands to binary expression: 'Foo' and 'Foo'", |
| 5421 | 5655 | }); |
| 5422 | 5656 | |
| 5423 | | cases.add("division by zero", |
| 5657 | ctx.objErrStage1("division by zero", |
| 5424 | 5658 | \\const lit_int_x = 1 / 0; |
| 5425 | 5659 | \\const lit_float_x = 1.0 / 0.0; |
| 5426 | 5660 | \\const int_x = @as(u32, 1) / @as(u32, 0); |
| ... | ... | @@ -5437,16 +5671,15 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5437 | 5671 | "tmp.zig:4:31: error: division by zero", |
| 5438 | 5672 | }); |
| 5439 | 5673 | |
| 5440 | | cases.add("normal string with newline", |
| 5674 | ctx.objErrStage1("normal string with newline", |
| 5441 | 5675 | \\const foo = "a |
| 5442 | 5676 | \\b"; |
| 5443 | | \\ |
| 5444 | | \\export fn entry() usize { return @sizeOf(@TypeOf(foo)); } |
| 5445 | 5677 | , &[_][]const u8{ |
| 5446 | | "tmp.zig:1:15: error: newline not allowed in string literal", |
| 5678 | "tmp.zig:1:13: error: expected expression, found 'invalid'", |
| 5679 | "tmp.zig:1:15: note: invalid byte: '\\n'", |
| 5447 | 5680 | }); |
| 5448 | 5681 | |
| 5449 | | cases.add("invalid comparison for function pointers", |
| 5682 | ctx.objErrStage1("invalid comparison for function pointers", |
| 5450 | 5683 | \\fn foo() void {} |
| 5451 | 5684 | \\const invalid = foo > foo; |
| 5452 | 5685 | \\ |
| ... | ... | @@ -5455,7 +5688,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5455 | 5688 | "tmp.zig:2:21: error: operator not allowed for type 'fn() void'", |
| 5456 | 5689 | }); |
| 5457 | 5690 | |
| 5458 | | cases.add("generic function instance with non-constant expression", |
| 5691 | ctx.objErrStage1("generic function instance with non-constant expression", |
| 5459 | 5692 | \\fn foo(comptime x: i32, y: i32) i32 { return x + y; } |
| 5460 | 5693 | \\fn test1(a: i32, b: i32) i32 { |
| 5461 | 5694 | \\ return foo(a, b); |
| ... | ... | @@ -5466,7 +5699,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5466 | 5699 | "tmp.zig:3:16: error: runtime value cannot be passed to comptime arg", |
| 5467 | 5700 | }); |
| 5468 | 5701 | |
| 5469 | | cases.add("assign null to non-optional pointer", |
| 5702 | ctx.objErrStage1("assign null to non-optional pointer", |
| 5470 | 5703 | \\const a: *u8 = null; |
| 5471 | 5704 | \\ |
| 5472 | 5705 | \\export fn entry() usize { return @sizeOf(@TypeOf(a)); } |
| ... | ... | @@ -5474,26 +5707,28 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5474 | 5707 | "tmp.zig:1:16: error: expected type '*u8', found '(null)'", |
| 5475 | 5708 | }); |
| 5476 | 5709 | |
| 5477 | | cases.add("indexing an array of size zero", |
| 5710 | ctx.objErrStage1("indexing an array of size zero", |
| 5478 | 5711 | \\const array = [_]u8{}; |
| 5479 | 5712 | \\export fn foo() void { |
| 5480 | 5713 | \\ const pointer = &array[0]; |
| 5714 | \\ _ = pointer; |
| 5481 | 5715 | \\} |
| 5482 | 5716 | , &[_][]const u8{ |
| 5483 | 5717 | "tmp.zig:3:27: error: accessing a zero length array is not allowed", |
| 5484 | 5718 | }); |
| 5485 | 5719 | |
| 5486 | | cases.add("indexing an array of size zero with runtime index", |
| 5720 | ctx.objErrStage1("indexing an array of size zero with runtime index", |
| 5487 | 5721 | \\const array = [_]u8{}; |
| 5488 | 5722 | \\export fn foo() void { |
| 5489 | 5723 | \\ var index: usize = 0; |
| 5490 | 5724 | \\ const pointer = &array[index]; |
| 5725 | \\ _ = pointer; |
| 5491 | 5726 | \\} |
| 5492 | 5727 | , &[_][]const u8{ |
| 5493 | 5728 | "tmp.zig:4:27: error: accessing a zero length array is not allowed", |
| 5494 | 5729 | }); |
| 5495 | 5730 | |
| 5496 | | cases.add("compile time division by zero", |
| 5731 | ctx.objErrStage1("compile time division by zero", |
| 5497 | 5732 | \\const y = foo(0); |
| 5498 | 5733 | \\fn foo(x: u32) u32 { |
| 5499 | 5734 | \\ return 1 / x; |
| ... | ... | @@ -5505,7 +5740,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5505 | 5740 | "tmp.zig:1:14: note: referenced here", |
| 5506 | 5741 | }); |
| 5507 | 5742 | |
| 5508 | | cases.add("branch on undefined value", |
| 5743 | ctx.objErrStage1("branch on undefined value", |
| 5509 | 5744 | \\const x = if (undefined) true else false; |
| 5510 | 5745 | \\ |
| 5511 | 5746 | \\export fn entry() usize { return @sizeOf(@TypeOf(x)); } |
| ... | ... | @@ -5513,7 +5748,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5513 | 5748 | "tmp.zig:1:15: error: use of undefined value here causes undefined behavior", |
| 5514 | 5749 | }); |
| 5515 | 5750 | |
| 5516 | | cases.add("div on undefined value", |
| 5751 | ctx.objErrStage1("div on undefined value", |
| 5517 | 5752 | \\comptime { |
| 5518 | 5753 | \\ var a: i64 = undefined; |
| 5519 | 5754 | \\ _ = a / a; |
| ... | ... | @@ -5522,7 +5757,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5522 | 5757 | "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", |
| 5523 | 5758 | }); |
| 5524 | 5759 | |
| 5525 | | cases.add("div assign on undefined value", |
| 5760 | ctx.objErrStage1("div assign on undefined value", |
| 5526 | 5761 | \\comptime { |
| 5527 | 5762 | \\ var a: i64 = undefined; |
| 5528 | 5763 | \\ a /= a; |
| ... | ... | @@ -5531,7 +5766,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5531 | 5766 | "tmp.zig:3:5: error: use of undefined value here causes undefined behavior", |
| 5532 | 5767 | }); |
| 5533 | 5768 | |
| 5534 | | cases.add("mod on undefined value", |
| 5769 | ctx.objErrStage1("mod on undefined value", |
| 5535 | 5770 | \\comptime { |
| 5536 | 5771 | \\ var a: i64 = undefined; |
| 5537 | 5772 | \\ _ = a % a; |
| ... | ... | @@ -5540,7 +5775,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5540 | 5775 | "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", |
| 5541 | 5776 | }); |
| 5542 | 5777 | |
| 5543 | | cases.add("mod assign on undefined value", |
| 5778 | ctx.objErrStage1("mod assign on undefined value", |
| 5544 | 5779 | \\comptime { |
| 5545 | 5780 | \\ var a: i64 = undefined; |
| 5546 | 5781 | \\ a %= a; |
| ... | ... | @@ -5549,7 +5784,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5549 | 5784 | "tmp.zig:3:5: error: use of undefined value here causes undefined behavior", |
| 5550 | 5785 | }); |
| 5551 | 5786 | |
| 5552 | | cases.add("add on undefined value", |
| 5787 | ctx.objErrStage1("add on undefined value", |
| 5553 | 5788 | \\comptime { |
| 5554 | 5789 | \\ var a: i64 = undefined; |
| 5555 | 5790 | \\ _ = a + a; |
| ... | ... | @@ -5558,7 +5793,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5558 | 5793 | "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", |
| 5559 | 5794 | }); |
| 5560 | 5795 | |
| 5561 | | cases.add("add assign on undefined value", |
| 5796 | ctx.objErrStage1("add assign on undefined value", |
| 5562 | 5797 | \\comptime { |
| 5563 | 5798 | \\ var a: i64 = undefined; |
| 5564 | 5799 | \\ a += a; |
| ... | ... | @@ -5567,7 +5802,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5567 | 5802 | "tmp.zig:3:5: error: use of undefined value here causes undefined behavior", |
| 5568 | 5803 | }); |
| 5569 | 5804 | |
| 5570 | | cases.add("add wrap on undefined value", |
| 5805 | ctx.objErrStage1("add wrap on undefined value", |
| 5571 | 5806 | \\comptime { |
| 5572 | 5807 | \\ var a: i64 = undefined; |
| 5573 | 5808 | \\ _ = a +% a; |
| ... | ... | @@ -5576,7 +5811,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5576 | 5811 | "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", |
| 5577 | 5812 | }); |
| 5578 | 5813 | |
| 5579 | | cases.add("add wrap assign on undefined value", |
| 5814 | ctx.objErrStage1("add wrap assign on undefined value", |
| 5580 | 5815 | \\comptime { |
| 5581 | 5816 | \\ var a: i64 = undefined; |
| 5582 | 5817 | \\ a +%= a; |
| ... | ... | @@ -5585,7 +5820,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5585 | 5820 | "tmp.zig:3:5: error: use of undefined value here causes undefined behavior", |
| 5586 | 5821 | }); |
| 5587 | 5822 | |
| 5588 | | cases.add("sub on undefined value", |
| 5823 | ctx.objErrStage1("sub on undefined value", |
| 5589 | 5824 | \\comptime { |
| 5590 | 5825 | \\ var a: i64 = undefined; |
| 5591 | 5826 | \\ _ = a - a; |
| ... | ... | @@ -5594,7 +5829,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5594 | 5829 | "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", |
| 5595 | 5830 | }); |
| 5596 | 5831 | |
| 5597 | | cases.add("sub assign on undefined value", |
| 5832 | ctx.objErrStage1("sub assign on undefined value", |
| 5598 | 5833 | \\comptime { |
| 5599 | 5834 | \\ var a: i64 = undefined; |
| 5600 | 5835 | \\ a -= a; |
| ... | ... | @@ -5603,7 +5838,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5603 | 5838 | "tmp.zig:3:5: error: use of undefined value here causes undefined behavior", |
| 5604 | 5839 | }); |
| 5605 | 5840 | |
| 5606 | | cases.add("sub wrap on undefined value", |
| 5841 | ctx.objErrStage1("sub wrap on undefined value", |
| 5607 | 5842 | \\comptime { |
| 5608 | 5843 | \\ var a: i64 = undefined; |
| 5609 | 5844 | \\ _ = a -% a; |
| ... | ... | @@ -5612,7 +5847,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5612 | 5847 | "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", |
| 5613 | 5848 | }); |
| 5614 | 5849 | |
| 5615 | | cases.add("sub wrap assign on undefined value", |
| 5850 | ctx.objErrStage1("sub wrap assign on undefined value", |
| 5616 | 5851 | \\comptime { |
| 5617 | 5852 | \\ var a: i64 = undefined; |
| 5618 | 5853 | \\ a -%= a; |
| ... | ... | @@ -5621,7 +5856,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5621 | 5856 | "tmp.zig:3:5: error: use of undefined value here causes undefined behavior", |
| 5622 | 5857 | }); |
| 5623 | 5858 | |
| 5624 | | cases.add("mult on undefined value", |
| 5859 | ctx.objErrStage1("mult on undefined value", |
| 5625 | 5860 | \\comptime { |
| 5626 | 5861 | \\ var a: i64 = undefined; |
| 5627 | 5862 | \\ _ = a * a; |
| ... | ... | @@ -5630,7 +5865,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5630 | 5865 | "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", |
| 5631 | 5866 | }); |
| 5632 | 5867 | |
| 5633 | | cases.add("mult assign on undefined value", |
| 5868 | ctx.objErrStage1("mult assign on undefined value", |
| 5634 | 5869 | \\comptime { |
| 5635 | 5870 | \\ var a: i64 = undefined; |
| 5636 | 5871 | \\ a *= a; |
| ... | ... | @@ -5639,7 +5874,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5639 | 5874 | "tmp.zig:3:5: error: use of undefined value here causes undefined behavior", |
| 5640 | 5875 | }); |
| 5641 | 5876 | |
| 5642 | | cases.add("mult wrap on undefined value", |
| 5877 | ctx.objErrStage1("mult wrap on undefined value", |
| 5643 | 5878 | \\comptime { |
| 5644 | 5879 | \\ var a: i64 = undefined; |
| 5645 | 5880 | \\ _ = a *% a; |
| ... | ... | @@ -5648,7 +5883,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5648 | 5883 | "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", |
| 5649 | 5884 | }); |
| 5650 | 5885 | |
| 5651 | | cases.add("mult wrap assign on undefined value", |
| 5886 | ctx.objErrStage1("mult wrap assign on undefined value", |
| 5652 | 5887 | \\comptime { |
| 5653 | 5888 | \\ var a: i64 = undefined; |
| 5654 | 5889 | \\ a *%= a; |
| ... | ... | @@ -5657,7 +5892,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5657 | 5892 | "tmp.zig:3:5: error: use of undefined value here causes undefined behavior", |
| 5658 | 5893 | }); |
| 5659 | 5894 | |
| 5660 | | cases.add("shift left on undefined value", |
| 5895 | ctx.objErrStage1("shift left on undefined value", |
| 5661 | 5896 | \\comptime { |
| 5662 | 5897 | \\ var a: i64 = undefined; |
| 5663 | 5898 | \\ _ = a << 2; |
| ... | ... | @@ -5666,7 +5901,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5666 | 5901 | "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", |
| 5667 | 5902 | }); |
| 5668 | 5903 | |
| 5669 | | cases.add("shift left assign on undefined value", |
| 5904 | ctx.objErrStage1("shift left assign on undefined value", |
| 5670 | 5905 | \\comptime { |
| 5671 | 5906 | \\ var a: i64 = undefined; |
| 5672 | 5907 | \\ a <<= 2; |
| ... | ... | @@ -5675,7 +5910,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5675 | 5910 | "tmp.zig:3:5: error: use of undefined value here causes undefined behavior", |
| 5676 | 5911 | }); |
| 5677 | 5912 | |
| 5678 | | cases.add("shift right on undefined value", |
| 5913 | ctx.objErrStage1("shift right on undefined value", |
| 5679 | 5914 | \\comptime { |
| 5680 | 5915 | \\ var a: i64 = undefined; |
| 5681 | 5916 | \\ _ = a >> 2; |
| ... | ... | @@ -5684,7 +5919,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5684 | 5919 | "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", |
| 5685 | 5920 | }); |
| 5686 | 5921 | |
| 5687 | | cases.add("shift left assign on undefined value", |
| 5922 | ctx.objErrStage1("shift left assign on undefined value", |
| 5688 | 5923 | \\comptime { |
| 5689 | 5924 | \\ var a: i64 = undefined; |
| 5690 | 5925 | \\ a >>= 2; |
| ... | ... | @@ -5693,7 +5928,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5693 | 5928 | "tmp.zig:3:5: error: use of undefined value here causes undefined behavior", |
| 5694 | 5929 | }); |
| 5695 | 5930 | |
| 5696 | | cases.add("bin and on undefined value", |
| 5931 | ctx.objErrStage1("bin and on undefined value", |
| 5697 | 5932 | \\comptime { |
| 5698 | 5933 | \\ var a: i64 = undefined; |
| 5699 | 5934 | \\ _ = a & a; |
| ... | ... | @@ -5702,7 +5937,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5702 | 5937 | "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", |
| 5703 | 5938 | }); |
| 5704 | 5939 | |
| 5705 | | cases.add("bin and assign on undefined value", |
| 5940 | ctx.objErrStage1("bin and assign on undefined value", |
| 5706 | 5941 | \\comptime { |
| 5707 | 5942 | \\ var a: i64 = undefined; |
| 5708 | 5943 | \\ a &= a; |
| ... | ... | @@ -5711,7 +5946,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5711 | 5946 | "tmp.zig:3:5: error: use of undefined value here causes undefined behavior", |
| 5712 | 5947 | }); |
| 5713 | 5948 | |
| 5714 | | cases.add("bin or on undefined value", |
| 5949 | ctx.objErrStage1("bin or on undefined value", |
| 5715 | 5950 | \\comptime { |
| 5716 | 5951 | \\ var a: i64 = undefined; |
| 5717 | 5952 | \\ _ = a | a; |
| ... | ... | @@ -5720,7 +5955,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5720 | 5955 | "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", |
| 5721 | 5956 | }); |
| 5722 | 5957 | |
| 5723 | | cases.add("bin or assign on undefined value", |
| 5958 | ctx.objErrStage1("bin or assign on undefined value", |
| 5724 | 5959 | \\comptime { |
| 5725 | 5960 | \\ var a: i64 = undefined; |
| 5726 | 5961 | \\ a |= a; |
| ... | ... | @@ -5729,7 +5964,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5729 | 5964 | "tmp.zig:3:5: error: use of undefined value here causes undefined behavior", |
| 5730 | 5965 | }); |
| 5731 | 5966 | |
| 5732 | | cases.add("bin xor on undefined value", |
| 5967 | ctx.objErrStage1("bin xor on undefined value", |
| 5733 | 5968 | \\comptime { |
| 5734 | 5969 | \\ var a: i64 = undefined; |
| 5735 | 5970 | \\ _ = a ^ a; |
| ... | ... | @@ -5738,7 +5973,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5738 | 5973 | "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", |
| 5739 | 5974 | }); |
| 5740 | 5975 | |
| 5741 | | cases.add("bin xor assign on undefined value", |
| 5976 | ctx.objErrStage1("bin xor assign on undefined value", |
| 5742 | 5977 | \\comptime { |
| 5743 | 5978 | \\ var a: i64 = undefined; |
| 5744 | 5979 | \\ a ^= a; |
| ... | ... | @@ -5747,7 +5982,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5747 | 5982 | "tmp.zig:3:5: error: use of undefined value here causes undefined behavior", |
| 5748 | 5983 | }); |
| 5749 | 5984 | |
| 5750 | | cases.add("comparison operators with undefined value", |
| 5985 | ctx.objErrStage1("comparison operators with undefined value", |
| 5751 | 5986 | \\// operator == |
| 5752 | 5987 | \\comptime { |
| 5753 | 5988 | \\ var a: i64 = undefined; |
| ... | ... | @@ -5793,7 +6028,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5793 | 6028 | "tmp.zig:35:11: error: use of undefined value here causes undefined behavior", |
| 5794 | 6029 | }); |
| 5795 | 6030 | |
| 5796 | | cases.add("and on undefined value", |
| 6031 | ctx.objErrStage1("and on undefined value", |
| 5797 | 6032 | \\comptime { |
| 5798 | 6033 | \\ var a: bool = undefined; |
| 5799 | 6034 | \\ _ = a and a; |
| ... | ... | @@ -5802,7 +6037,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5802 | 6037 | "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", |
| 5803 | 6038 | }); |
| 5804 | 6039 | |
| 5805 | | cases.add("or on undefined value", |
| 6040 | ctx.objErrStage1("or on undefined value", |
| 5806 | 6041 | \\comptime { |
| 5807 | 6042 | \\ var a: bool = undefined; |
| 5808 | 6043 | \\ _ = a or a; |
| ... | ... | @@ -5811,7 +6046,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5811 | 6046 | "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", |
| 5812 | 6047 | }); |
| 5813 | 6048 | |
| 5814 | | cases.add("negate on undefined value", |
| 6049 | ctx.objErrStage1("negate on undefined value", |
| 5815 | 6050 | \\comptime { |
| 5816 | 6051 | \\ var a: i64 = undefined; |
| 5817 | 6052 | \\ _ = -a; |
| ... | ... | @@ -5820,7 +6055,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5820 | 6055 | "tmp.zig:3:10: error: use of undefined value here causes undefined behavior", |
| 5821 | 6056 | }); |
| 5822 | 6057 | |
| 5823 | | cases.add("negate wrap on undefined value", |
| 6058 | ctx.objErrStage1("negate wrap on undefined value", |
| 5824 | 6059 | \\comptime { |
| 5825 | 6060 | \\ var a: i64 = undefined; |
| 5826 | 6061 | \\ _ = -%a; |
| ... | ... | @@ -5829,7 +6064,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5829 | 6064 | "tmp.zig:3:11: error: use of undefined value here causes undefined behavior", |
| 5830 | 6065 | }); |
| 5831 | 6066 | |
| 5832 | | cases.add("bin not on undefined value", |
| 6067 | ctx.objErrStage1("bin not on undefined value", |
| 5833 | 6068 | \\comptime { |
| 5834 | 6069 | \\ var a: i64 = undefined; |
| 5835 | 6070 | \\ _ = ~a; |
| ... | ... | @@ -5838,7 +6073,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5838 | 6073 | "tmp.zig:3:10: error: use of undefined value here causes undefined behavior", |
| 5839 | 6074 | }); |
| 5840 | 6075 | |
| 5841 | | cases.add("bool not on undefined value", |
| 6076 | ctx.objErrStage1("bool not on undefined value", |
| 5842 | 6077 | \\comptime { |
| 5843 | 6078 | \\ var a: bool = undefined; |
| 5844 | 6079 | \\ _ = !a; |
| ... | ... | @@ -5847,7 +6082,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5847 | 6082 | "tmp.zig:3:10: error: use of undefined value here causes undefined behavior", |
| 5848 | 6083 | }); |
| 5849 | 6084 | |
| 5850 | | cases.add("orelse on undefined value", |
| 6085 | ctx.objErrStage1("orelse on undefined value", |
| 5851 | 6086 | \\comptime { |
| 5852 | 6087 | \\ var a: ?bool = undefined; |
| 5853 | 6088 | \\ _ = a orelse false; |
| ... | ... | @@ -5856,16 +6091,16 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5856 | 6091 | "tmp.zig:3:11: error: use of undefined value here causes undefined behavior", |
| 5857 | 6092 | }); |
| 5858 | 6093 | |
| 5859 | | cases.add("catch on undefined value", |
| 6094 | ctx.objErrStage1("catch on undefined value", |
| 5860 | 6095 | \\comptime { |
| 5861 | 6096 | \\ var a: anyerror!bool = undefined; |
| 5862 | | \\ _ = a catch |err| false; |
| 6097 | \\ _ = a catch false; |
| 5863 | 6098 | \\} |
| 5864 | 6099 | , &[_][]const u8{ |
| 5865 | 6100 | "tmp.zig:3:11: error: use of undefined value here causes undefined behavior", |
| 5866 | 6101 | }); |
| 5867 | 6102 | |
| 5868 | | cases.add("deref on undefined value", |
| 6103 | ctx.objErrStage1("deref on undefined value", |
| 5869 | 6104 | \\comptime { |
| 5870 | 6105 | \\ var a: *u8 = undefined; |
| 5871 | 6106 | \\ _ = a.*; |
| ... | ... | @@ -5874,7 +6109,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5874 | 6109 | "tmp.zig:3:9: error: attempt to dereference undefined value", |
| 5875 | 6110 | }); |
| 5876 | 6111 | |
| 5877 | | cases.add("endless loop in function evaluation", |
| 6112 | ctx.objErrStage1("endless loop in function evaluation", |
| 5878 | 6113 | \\const seventh_fib_number = fibbonaci(7); |
| 5879 | 6114 | \\fn fibbonaci(x: i32) i32 { |
| 5880 | 6115 | \\ return fibbonaci(x - 1) + fibbonaci(x - 2); |
| ... | ... | @@ -5887,16 +6122,15 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5887 | 6122 | "tmp.zig:6:50: note: referenced here", |
| 5888 | 6123 | }); |
| 5889 | 6124 | |
| 5890 | | cases.add("@embedFile with bogus file", |
| 6125 | ctx.objErrStage1("@embedFile with bogus file", |
| 5891 | 6126 | \\const resource = @embedFile("bogus.txt",); |
| 5892 | 6127 | \\ |
| 5893 | 6128 | \\export fn entry() usize { return @sizeOf(@TypeOf(resource)); } |
| 5894 | 6129 | , &[_][]const u8{ |
| 5895 | 6130 | "tmp.zig:1:29: error: unable to find '", |
| 5896 | | "bogus.txt'", |
| 5897 | 6131 | }); |
| 5898 | 6132 | |
| 5899 | | cases.add("non-const expression in struct literal outside function", |
| 6133 | ctx.objErrStage1("non-const expression in struct literal outside function", |
| 5900 | 6134 | \\const Foo = struct { |
| 5901 | 6135 | \\ x: i32, |
| 5902 | 6136 | \\}; |
| ... | ... | @@ -5908,7 +6142,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5908 | 6142 | "tmp.zig:4:21: error: unable to evaluate constant expression", |
| 5909 | 6143 | }); |
| 5910 | 6144 | |
| 5911 | | cases.add("non-const expression function call with struct return value outside function", |
| 6145 | ctx.objErrStage1("non-const expression function call with struct return value outside function", |
| 5912 | 6146 | \\const Foo = struct { |
| 5913 | 6147 | \\ x: i32, |
| 5914 | 6148 | \\}; |
| ... | ... | @@ -5925,7 +6159,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5925 | 6159 | "tmp.zig:4:17: note: referenced here", |
| 5926 | 6160 | }); |
| 5927 | 6161 | |
| 5928 | | cases.add("undeclared identifier error should mark fn as impure", |
| 6162 | ctx.objErrStage1("undeclared identifier error should mark fn as impure", |
| 5929 | 6163 | \\export fn foo() void { |
| 5930 | 6164 | \\ test_a_thing(); |
| 5931 | 6165 | \\} |
| ... | ... | @@ -5936,7 +6170,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5936 | 6170 | "tmp.zig:5:5: error: use of undeclared identifier 'bad_fn_call'", |
| 5937 | 6171 | }); |
| 5938 | 6172 | |
| 5939 | | cases.add("illegal comparison of types", |
| 6173 | ctx.objErrStage1("illegal comparison of types", |
| 5940 | 6174 | \\fn bad_eql_1(a: []u8, b: []u8) bool { |
| 5941 | 6175 | \\ return a == b; |
| 5942 | 6176 | \\} |
| ... | ... | @@ -5955,13 +6189,14 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5955 | 6189 | "tmp.zig:9:16: error: operator not allowed for type 'EnumWithData'", |
| 5956 | 6190 | }); |
| 5957 | 6191 | |
| 5958 | | cases.add("non-const switch number literal", |
| 6192 | ctx.objErrStage1("non-const switch number literal", |
| 5959 | 6193 | \\export fn foo() void { |
| 5960 | 6194 | \\ const x = switch (bar()) { |
| 5961 | 6195 | \\ 1, 2 => 1, |
| 5962 | 6196 | \\ 3, 4 => 2, |
| 5963 | 6197 | \\ else => 3, |
| 5964 | 6198 | \\ }; |
| 6199 | \\ _ = x; |
| 5965 | 6200 | \\} |
| 5966 | 6201 | \\fn bar() i32 { |
| 5967 | 6202 | \\ return 2; |
| ... | ... | @@ -5970,7 +6205,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5970 | 6205 | "tmp.zig:5:17: error: cannot store runtime value in type 'comptime_int'", |
| 5971 | 6206 | }); |
| 5972 | 6207 | |
| 5973 | | cases.add("atomic orderings of cmpxchg - failure stricter than success", |
| 6208 | ctx.objErrStage1("atomic orderings of cmpxchg - failure stricter than success", |
| 5974 | 6209 | \\const AtomicOrder = @import("std").builtin.AtomicOrder; |
| 5975 | 6210 | \\export fn f() void { |
| 5976 | 6211 | \\ var x: i32 = 1234; |
| ... | ... | @@ -5980,7 +6215,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5980 | 6215 | "tmp.zig:4:81: error: failure atomic ordering must be no stricter than success", |
| 5981 | 6216 | }); |
| 5982 | 6217 | |
| 5983 | | cases.add("atomic orderings of cmpxchg - success Monotonic or stricter", |
| 6218 | ctx.objErrStage1("atomic orderings of cmpxchg - success Monotonic or stricter", |
| 5984 | 6219 | \\const AtomicOrder = @import("std").builtin.AtomicOrder; |
| 5985 | 6220 | \\export fn f() void { |
| 5986 | 6221 | \\ var x: i32 = 1234; |
| ... | ... | @@ -5990,7 +6225,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5990 | 6225 | "tmp.zig:4:58: error: success atomic ordering must be Monotonic or stricter", |
| 5991 | 6226 | }); |
| 5992 | 6227 | |
| 5993 | | cases.add("negation overflow in function evaluation", |
| 6228 | ctx.objErrStage1("negation overflow in function evaluation", |
| 5994 | 6229 | \\const y = neg(-128); |
| 5995 | 6230 | \\fn neg(x: i8) i8 { |
| 5996 | 6231 | \\ return -x; |
| ... | ... | @@ -6002,7 +6237,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6002 | 6237 | "tmp.zig:1:14: note: referenced here", |
| 6003 | 6238 | }); |
| 6004 | 6239 | |
| 6005 | | cases.add("add overflow in function evaluation", |
| 6240 | ctx.objErrStage1("add overflow in function evaluation", |
| 6006 | 6241 | \\const y = add(65530, 10); |
| 6007 | 6242 | \\fn add(a: u16, b: u16) u16 { |
| 6008 | 6243 | \\ return a + b; |
| ... | ... | @@ -6014,7 +6249,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6014 | 6249 | "tmp.zig:1:14: note: referenced here", |
| 6015 | 6250 | }); |
| 6016 | 6251 | |
| 6017 | | cases.add("sub overflow in function evaluation", |
| 6252 | ctx.objErrStage1("sub overflow in function evaluation", |
| 6018 | 6253 | \\const y = sub(10, 20); |
| 6019 | 6254 | \\fn sub(a: u16, b: u16) u16 { |
| 6020 | 6255 | \\ return a - b; |
| ... | ... | @@ -6026,7 +6261,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6026 | 6261 | "tmp.zig:1:14: note: referenced here", |
| 6027 | 6262 | }); |
| 6028 | 6263 | |
| 6029 | | cases.add("mul overflow in function evaluation", |
| 6264 | ctx.objErrStage1("mul overflow in function evaluation", |
| 6030 | 6265 | \\const y = mul(300, 6000); |
| 6031 | 6266 | \\fn mul(a: u16, b: u16) u16 { |
| 6032 | 6267 | \\ return a * b; |
| ... | ... | @@ -6038,7 +6273,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6038 | 6273 | "tmp.zig:1:14: note: referenced here", |
| 6039 | 6274 | }); |
| 6040 | 6275 | |
| 6041 | | cases.add("truncate sign mismatch", |
| 6276 | ctx.objErrStage1("truncate sign mismatch", |
| 6042 | 6277 | \\export fn entry1() i8 { |
| 6043 | 6278 | \\ var x: u32 = 10; |
| 6044 | 6279 | \\ return @truncate(i8, x); |
| ... | ... | @@ -6062,7 +6297,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6062 | 6297 | "tmp.zig:15:26: error: expected unsigned integer type, found 'i32'", |
| 6063 | 6298 | }); |
| 6064 | 6299 | |
| 6065 | | cases.add("try in function with non error return type", |
| 6300 | ctx.objErrStage1("try in function with non error return type", |
| 6066 | 6301 | \\export fn f() void { |
| 6067 | 6302 | \\ try something(); |
| 6068 | 6303 | \\} |
| ... | ... | @@ -6071,7 +6306,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6071 | 6306 | "tmp.zig:2:5: error: expected type 'void', found 'anyerror'", |
| 6072 | 6307 | }); |
| 6073 | 6308 | |
| 6074 | | cases.add("invalid pointer for var type", |
| 6309 | ctx.objErrStage1("invalid pointer for var type", |
| 6075 | 6310 | \\extern fn ext() usize; |
| 6076 | 6311 | \\var bytes: [ext()]u8 = undefined; |
| 6077 | 6312 | \\export fn f() void { |
| ... | ... | @@ -6083,7 +6318,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6083 | 6318 | "tmp.zig:2:13: error: unable to evaluate constant expression", |
| 6084 | 6319 | }); |
| 6085 | 6320 | |
| 6086 | | cases.add("export function with comptime parameter", |
| 6321 | ctx.objErrStage1("export function with comptime parameter", |
| 6087 | 6322 | \\export fn foo(comptime x: i32, y: i32) i32{ |
| 6088 | 6323 | \\ return x + y; |
| 6089 | 6324 | \\} |
| ... | ... | @@ -6091,7 +6326,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6091 | 6326 | "tmp.zig:1:15: error: comptime parameter not allowed in function with calling convention 'C'", |
| 6092 | 6327 | }); |
| 6093 | 6328 | |
| 6094 | | cases.add("extern function with comptime parameter", |
| 6329 | ctx.objErrStage1("extern function with comptime parameter", |
| 6095 | 6330 | \\extern fn foo(comptime x: i32, y: i32) i32; |
| 6096 | 6331 | \\fn f() i32 { |
| 6097 | 6332 | \\ return foo(1, 2); |
| ... | ... | @@ -6101,7 +6336,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6101 | 6336 | "tmp.zig:1:15: error: comptime parameter not allowed in function with calling convention 'C'", |
| 6102 | 6337 | }); |
| 6103 | 6338 | |
| 6104 | | cases.add("non-pure function returns type", |
| 6339 | ctx.objErrStage1("non-pure function returns type", |
| 6105 | 6340 | \\var a: u32 = 0; |
| 6106 | 6341 | \\pub fn List(comptime T: type) type { |
| 6107 | 6342 | \\ a += 1; |
| ... | ... | @@ -6125,7 +6360,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6125 | 6360 | "tmp.zig:16:19: note: referenced here", |
| 6126 | 6361 | }); |
| 6127 | 6362 | |
| 6128 | | cases.add("bogus method call on slice", |
| 6363 | ctx.objErrStage1("bogus method call on slice", |
| 6129 | 6364 | \\var self = "aoeu"; |
| 6130 | 6365 | \\fn f(m: []const u8) void { |
| 6131 | 6366 | \\ m.copy(u8, self[0..], m); |
| ... | ... | @@ -6135,9 +6370,9 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6135 | 6370 | "tmp.zig:3:6: error: no member named 'copy' in '[]const u8'", |
| 6136 | 6371 | }); |
| 6137 | 6372 | |
| 6138 | | cases.add("wrong number of arguments for method fn call", |
| 6373 | ctx.objErrStage1("wrong number of arguments for method fn call", |
| 6139 | 6374 | \\const Foo = struct { |
| 6140 | | \\ fn method(self: *const Foo, a: i32) void {} |
| 6375 | \\ fn method(self: *const Foo, a: i32) void {_ = self; _ = a;} |
| 6141 | 6376 | \\}; |
| 6142 | 6377 | \\fn f(foo: *const Foo) void { |
| 6143 | 6378 | \\ |
| ... | ... | @@ -6148,7 +6383,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6148 | 6383 | "tmp.zig:6:15: error: expected 2 argument(s), found 3", |
| 6149 | 6384 | }); |
| 6150 | 6385 | |
| 6151 | | cases.add("assign through constant pointer", |
| 6386 | ctx.objErrStage1("assign through constant pointer", |
| 6152 | 6387 | \\export fn f() void { |
| 6153 | 6388 | \\ var cstr = "Hat"; |
| 6154 | 6389 | \\ cstr[0] = 'W'; |
| ... | ... | @@ -6157,7 +6392,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6157 | 6392 | "tmp.zig:3:13: error: cannot assign to constant", |
| 6158 | 6393 | }); |
| 6159 | 6394 | |
| 6160 | | cases.add("assign through constant slice", |
| 6395 | ctx.objErrStage1("assign through constant slice", |
| 6161 | 6396 | \\export fn f() void { |
| 6162 | 6397 | \\ var cstr: []const u8 = "Hat"; |
| 6163 | 6398 | \\ cstr[0] = 'W'; |
| ... | ... | @@ -6166,13 +6401,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6166 | 6401 | "tmp.zig:3:13: error: cannot assign to constant", |
| 6167 | 6402 | }); |
| 6168 | 6403 | |
| 6169 | | cases.add("main function with bogus args type", |
| 6170 | | \\pub fn main(args: [][]bogus) !void {} |
| 6404 | ctx.objErrStage1("main function with bogus args type", |
| 6405 | \\pub fn main(args: [][]bogus) !void {_ = args;} |
| 6171 | 6406 | , &[_][]const u8{ |
| 6172 | 6407 | "tmp.zig:1:23: error: use of undeclared identifier 'bogus'", |
| 6173 | 6408 | }); |
| 6174 | 6409 | |
| 6175 | | cases.add("misspelled type with pointer only reference", |
| 6410 | ctx.objErrStage1("misspelled type with pointer only reference", |
| 6176 | 6411 | \\const JasonHM = u8; |
| 6177 | 6412 | \\const JasonList = *JsonNode; |
| 6178 | 6413 | \\ |
| ... | ... | @@ -6200,6 +6435,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6200 | 6435 | \\ var jll: JasonList = undefined; |
| 6201 | 6436 | \\ jll.init(1234); |
| 6202 | 6437 | \\ var jd = JsonNode {.kind = JsonType.JSONArray , .jobject = JsonOA.JSONArray {jll} }; |
| 6438 | \\ _ = jd; |
| 6203 | 6439 | \\} |
| 6204 | 6440 | \\ |
| 6205 | 6441 | \\export fn entry() usize { return @sizeOf(@TypeOf(foo)); } |
| ... | ... | @@ -6207,7 +6443,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6207 | 6443 | "tmp.zig:5:16: error: use of undeclared identifier 'JsonList'", |
| 6208 | 6444 | }); |
| 6209 | 6445 | |
| 6210 | | cases.add("method call with first arg type primitive", |
| 6446 | ctx.objErrStage1("method call with first arg type primitive", |
| 6211 | 6447 | \\const Foo = struct { |
| 6212 | 6448 | \\ x: i32, |
| 6213 | 6449 | \\ |
| ... | ... | @@ -6227,7 +6463,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6227 | 6463 | "tmp.zig:14:5: error: expected type 'i32', found 'Foo'", |
| 6228 | 6464 | }); |
| 6229 | 6465 | |
| 6230 | | cases.add("method call with first arg type wrong container", |
| 6466 | ctx.objErrStage1("method call with first arg type wrong container", |
| 6231 | 6467 | \\pub const List = struct { |
| 6232 | 6468 | \\ len: usize, |
| 6233 | 6469 | \\ allocator: *Allocator, |
| ... | ... | @@ -6256,7 +6492,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6256 | 6492 | "tmp.zig:23:5: error: expected type '*Allocator', found '*List'", |
| 6257 | 6493 | }); |
| 6258 | 6494 | |
| 6259 | | cases.add("binary not on number literal", |
| 6495 | ctx.objErrStage1("binary not on number literal", |
| 6260 | 6496 | \\const TINY_QUANTUM_SHIFT = 4; |
| 6261 | 6497 | \\const TINY_QUANTUM_SIZE = 1 << TINY_QUANTUM_SHIFT; |
| 6262 | 6498 | \\var block_aligned_stuff: usize = (4 + TINY_QUANTUM_SIZE) & ~(TINY_QUANTUM_SIZE - 1); |
| ... | ... | @@ -6266,8 +6502,15 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6266 | 6502 | "tmp.zig:3:60: error: unable to perform binary not operation on type 'comptime_int'", |
| 6267 | 6503 | }); |
| 6268 | 6504 | |
| 6269 | | cases.addCase(x: { |
| 6270 | | const tc = cases.create("multiple files with private function error", |
| 6505 | { |
| 6506 | const case = ctx.obj("multiple files with private function error", .{}); |
| 6507 | case.backend = .stage1; |
| 6508 | |
| 6509 | case.addSourceFile("foo.zig", |
| 6510 | \\fn privateFunction() void { } |
| 6511 | ); |
| 6512 | |
| 6513 | case.addError( |
| 6271 | 6514 | \\const foo = @import("foo.zig",); |
| 6272 | 6515 | \\ |
| 6273 | 6516 | \\export fn callPrivFunction() void { |
| ... | ... | @@ -6277,16 +6520,19 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6277 | 6520 | "tmp.zig:4:8: error: 'privateFunction' is private", |
| 6278 | 6521 | "foo.zig:1:1: note: declared here", |
| 6279 | 6522 | }); |
| 6523 | } |
| 6280 | 6524 | |
| 6281 | | tc.addSourceFile("foo.zig", |
| 6282 | | \\fn privateFunction() void { } |
| 6283 | | ); |
| 6525 | { |
| 6526 | const case = ctx.obj("multiple files with private member instance function (canonical invocation) error", .{}); |
| 6527 | case.backend = .stage1; |
| 6284 | 6528 | |
| 6285 | | break :x tc; |
| 6286 | | }); |
| 6529 | case.addSourceFile("foo.zig", |
| 6530 | \\pub const Foo = struct { |
| 6531 | \\ fn privateFunction(self: *Foo) void { _ = self; } |
| 6532 | \\}; |
| 6533 | ); |
| 6287 | 6534 | |
| 6288 | | cases.addCase(x: { |
| 6289 | | const tc = cases.create("multiple files with private member instance function (canonical invocation) error", |
| 6535 | case.addError( |
| 6290 | 6536 | \\const Foo = @import("foo.zig",).Foo; |
| 6291 | 6537 | \\ |
| 6292 | 6538 | \\export fn callPrivFunction() void { |
| ... | ... | @@ -6297,18 +6543,19 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6297 | 6543 | "tmp.zig:5:8: error: 'privateFunction' is private", |
| 6298 | 6544 | "foo.zig:2:5: note: declared here", |
| 6299 | 6545 | }); |
| 6546 | } |
| 6547 | |
| 6548 | { |
| 6549 | const case = ctx.obj("multiple files with private member instance function error", .{}); |
| 6550 | case.backend = .stage1; |
| 6300 | 6551 | |
| 6301 | | tc.addSourceFile("foo.zig", |
| 6552 | case.addSourceFile("foo.zig", |
| 6302 | 6553 | \\pub const Foo = struct { |
| 6303 | | \\ fn privateFunction(self: *Foo) void { } |
| 6554 | \\ fn privateFunction(self: *Foo) void { _ = self; } |
| 6304 | 6555 | \\}; |
| 6305 | 6556 | ); |
| 6306 | 6557 | |
| 6307 | | break :x tc; |
| 6308 | | }); |
| 6309 | | |
| 6310 | | cases.addCase(x: { |
| 6311 | | const tc = cases.create("multiple files with private member instance function error", |
| 6558 | case.addError( |
| 6312 | 6559 | \\const Foo = @import("foo.zig",).Foo; |
| 6313 | 6560 | \\ |
| 6314 | 6561 | \\export fn callPrivFunction() void { |
| ... | ... | @@ -6319,17 +6566,9 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6319 | 6566 | "tmp.zig:5:8: error: 'privateFunction' is private", |
| 6320 | 6567 | "foo.zig:2:5: note: declared here", |
| 6321 | 6568 | }); |
| 6569 | } |
| 6322 | 6570 | |
| 6323 | | tc.addSourceFile("foo.zig", |
| 6324 | | \\pub const Foo = struct { |
| 6325 | | \\ fn privateFunction(self: *Foo) void { } |
| 6326 | | \\}; |
| 6327 | | ); |
| 6328 | | |
| 6329 | | break :x tc; |
| 6330 | | }); |
| 6331 | | |
| 6332 | | cases.add("container init with non-type", |
| 6571 | ctx.objErrStage1("container init with non-type", |
| 6333 | 6572 | \\const zero: i32 = 0; |
| 6334 | 6573 | \\const a = zero{1}; |
| 6335 | 6574 | \\ |
| ... | ... | @@ -6338,7 +6577,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6338 | 6577 | "tmp.zig:2:11: error: expected type 'type', found 'i32'", |
| 6339 | 6578 | }); |
| 6340 | 6579 | |
| 6341 | | cases.add("assign to constant field", |
| 6580 | ctx.objErrStage1("assign to constant field", |
| 6342 | 6581 | \\const Foo = struct { |
| 6343 | 6582 | \\ field: i32, |
| 6344 | 6583 | \\}; |
| ... | ... | @@ -6350,7 +6589,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6350 | 6589 | "tmp.zig:6:15: error: cannot assign to constant", |
| 6351 | 6590 | }); |
| 6352 | 6591 | |
| 6353 | | cases.add("return from defer expression", |
| 6592 | ctx.objErrStage1("return from defer expression", |
| 6354 | 6593 | \\pub fn testTrickyDefer() !void { |
| 6355 | 6594 | \\ defer canFail() catch {}; |
| 6356 | 6595 | \\ |
| ... | ... | @@ -6367,32 +6606,33 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6367 | 6606 | \\ |
| 6368 | 6607 | \\export fn entry() usize { return @sizeOf(@TypeOf(testTrickyDefer)); } |
| 6369 | 6608 | , &[_][]const u8{ |
| 6370 | | "tmp.zig:4:11: error: cannot return from defer expression", |
| 6609 | "tmp.zig:4:11: error: 'try' not allowed inside defer expression", |
| 6371 | 6610 | }); |
| 6372 | 6611 | |
| 6373 | | cases.add("assign too big number to u16", |
| 6612 | ctx.objErrStage1("assign too big number to u16", |
| 6374 | 6613 | \\export fn foo() void { |
| 6375 | 6614 | \\ var vga_mem: u16 = 0xB8000; |
| 6615 | \\ _ = vga_mem; |
| 6376 | 6616 | \\} |
| 6377 | 6617 | , &[_][]const u8{ |
| 6378 | 6618 | "tmp.zig:2:24: error: integer value 753664 cannot be coerced to type 'u16'", |
| 6379 | 6619 | }); |
| 6380 | 6620 | |
| 6381 | | cases.add("global variable alignment non power of 2", |
| 6621 | ctx.objErrStage1("global variable alignment non power of 2", |
| 6382 | 6622 | \\const some_data: [100]u8 align(3) = undefined; |
| 6383 | 6623 | \\export fn entry() usize { return @sizeOf(@TypeOf(some_data)); } |
| 6384 | 6624 | , &[_][]const u8{ |
| 6385 | 6625 | "tmp.zig:1:32: error: alignment value 3 is not a power of 2", |
| 6386 | 6626 | }); |
| 6387 | 6627 | |
| 6388 | | cases.add("function alignment non power of 2", |
| 6628 | ctx.objErrStage1("function alignment non power of 2", |
| 6389 | 6629 | \\extern fn foo() align(3) void; |
| 6390 | 6630 | \\export fn entry() void { return foo(); } |
| 6391 | 6631 | , &[_][]const u8{ |
| 6392 | 6632 | "tmp.zig:1:23: error: alignment value 3 is not a power of 2", |
| 6393 | 6633 | }); |
| 6394 | 6634 | |
| 6395 | | cases.add("compile log", |
| 6635 | ctx.objErrStage1("compile log", |
| 6396 | 6636 | \\export fn foo() void { |
| 6397 | 6637 | \\ comptime bar(12, "hi",); |
| 6398 | 6638 | \\} |
| ... | ... | @@ -6407,7 +6647,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6407 | 6647 | "tmp.zig:7:5: error: found compile log statement", |
| 6408 | 6648 | }); |
| 6409 | 6649 | |
| 6410 | | cases.add("casting bit offset pointer to regular pointer", |
| 6650 | ctx.objErrStage1("casting bit offset pointer to regular pointer", |
| 6411 | 6651 | \\const BitField = packed struct { |
| 6412 | 6652 | \\ a: u3, |
| 6413 | 6653 | \\ b: u3, |
| ... | ... | @@ -6427,7 +6667,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6427 | 6667 | "tmp.zig:8:26: error: expected type '*const u3', found '*align(:3:1) const u3'", |
| 6428 | 6668 | }); |
| 6429 | 6669 | |
| 6430 | | cases.add("referring to a struct that is invalid", |
| 6670 | ctx.objErrStage1("referring to a struct that is invalid", |
| 6431 | 6671 | \\const UsbDeviceRequest = struct { |
| 6432 | 6672 | \\ Type: u8, |
| 6433 | 6673 | \\}; |
| ... | ... | @@ -6444,7 +6684,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6444 | 6684 | "tmp.zig:6:20: note: referenced here", |
| 6445 | 6685 | }); |
| 6446 | 6686 | |
| 6447 | | cases.add("control flow uses comptime var at runtime", |
| 6687 | ctx.objErrStage1("control flow uses comptime var at runtime", |
| 6448 | 6688 | \\export fn foo() void { |
| 6449 | 6689 | \\ comptime var i = 0; |
| 6450 | 6690 | \\ while (i < 5) : (i += 1) { |
| ... | ... | @@ -6458,7 +6698,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6458 | 6698 | "tmp.zig:3:24: note: compile-time variable assigned here", |
| 6459 | 6699 | }); |
| 6460 | 6700 | |
| 6461 | | cases.add("ignored return value", |
| 6701 | ctx.objErrStage1("ignored return value", |
| 6462 | 6702 | \\export fn foo() void { |
| 6463 | 6703 | \\ bar(); |
| 6464 | 6704 | \\} |
| ... | ... | @@ -6467,7 +6707,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6467 | 6707 | "tmp.zig:2:8: error: expression value is ignored", |
| 6468 | 6708 | }); |
| 6469 | 6709 | |
| 6470 | | cases.add("ignored assert-err-ok return value", |
| 6710 | ctx.objErrStage1("ignored assert-err-ok return value", |
| 6471 | 6711 | \\export fn foo() void { |
| 6472 | 6712 | \\ bar() catch unreachable; |
| 6473 | 6713 | \\} |
| ... | ... | @@ -6476,7 +6716,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6476 | 6716 | "tmp.zig:2:11: error: expression value is ignored", |
| 6477 | 6717 | }); |
| 6478 | 6718 | |
| 6479 | | cases.add("ignored statement value", |
| 6719 | ctx.objErrStage1("ignored statement value", |
| 6480 | 6720 | \\export fn foo() void { |
| 6481 | 6721 | \\ 1; |
| 6482 | 6722 | \\} |
| ... | ... | @@ -6484,7 +6724,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6484 | 6724 | "tmp.zig:2:5: error: expression value is ignored", |
| 6485 | 6725 | }); |
| 6486 | 6726 | |
| 6487 | | cases.add("ignored comptime statement value", |
| 6727 | ctx.objErrStage1("ignored comptime statement value", |
| 6488 | 6728 | \\export fn foo() void { |
| 6489 | 6729 | \\ comptime {1;} |
| 6490 | 6730 | \\} |
| ... | ... | @@ -6492,7 +6732,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6492 | 6732 | "tmp.zig:2:15: error: expression value is ignored", |
| 6493 | 6733 | }); |
| 6494 | 6734 | |
| 6495 | | cases.add("ignored comptime value", |
| 6735 | ctx.objErrStage1("ignored comptime value", |
| 6496 | 6736 | \\export fn foo() void { |
| 6497 | 6737 | \\ comptime 1; |
| 6498 | 6738 | \\} |
| ... | ... | @@ -6500,7 +6740,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6500 | 6740 | "tmp.zig:2:5: error: expression value is ignored", |
| 6501 | 6741 | }); |
| 6502 | 6742 | |
| 6503 | | cases.add("ignored defered statement value", |
| 6743 | ctx.objErrStage1("ignored defered statement value", |
| 6504 | 6744 | \\export fn foo() void { |
| 6505 | 6745 | \\ defer {1;} |
| 6506 | 6746 | \\} |
| ... | ... | @@ -6508,7 +6748,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6508 | 6748 | "tmp.zig:2:12: error: expression value is ignored", |
| 6509 | 6749 | }); |
| 6510 | 6750 | |
| 6511 | | cases.add("ignored defered function call", |
| 6751 | ctx.objErrStage1("ignored defered function call", |
| 6512 | 6752 | \\export fn foo() void { |
| 6513 | 6753 | \\ defer bar(); |
| 6514 | 6754 | \\} |
| ... | ... | @@ -6517,7 +6757,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6517 | 6757 | "tmp.zig:2:14: error: error is ignored. consider using `try`, `catch`, or `if`", |
| 6518 | 6758 | }); |
| 6519 | 6759 | |
| 6520 | | cases.add("dereference an array", |
| 6760 | ctx.objErrStage1("dereference an array", |
| 6521 | 6761 | \\var s_buffer: [10]u8 = undefined; |
| 6522 | 6762 | \\pub fn pass(in: []u8) []u8 { |
| 6523 | 6763 | \\ var out = &s_buffer; |
| ... | ... | @@ -6530,13 +6770,14 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6530 | 6770 | "tmp.zig:4:10: error: attempt to dereference non-pointer type '[10]u8'", |
| 6531 | 6771 | }); |
| 6532 | 6772 | |
| 6533 | | cases.add("pass const ptr to mutable ptr fn", |
| 6773 | ctx.objErrStage1("pass const ptr to mutable ptr fn", |
| 6534 | 6774 | \\fn foo() bool { |
| 6535 | 6775 | \\ const a = @as([]const u8, "a",); |
| 6536 | 6776 | \\ const b = &a; |
| 6537 | 6777 | \\ return ptrEql(b, b); |
| 6538 | 6778 | \\} |
| 6539 | 6779 | \\fn ptrEql(a: *[]const u8, b: *[]const u8) bool { |
| 6780 | \\ _ = a; _ = b; |
| 6540 | 6781 | \\ return true; |
| 6541 | 6782 | \\} |
| 6542 | 6783 | \\ |
| ... | ... | @@ -6545,8 +6786,16 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6545 | 6786 | "tmp.zig:4:19: error: expected type '*[]const u8', found '*const []const u8'", |
| 6546 | 6787 | }); |
| 6547 | 6788 | |
| 6548 | | cases.addCase(x: { |
| 6549 | | const tc = cases.create("export collision", |
| 6789 | { |
| 6790 | const case = ctx.obj("export collision", .{}); |
| 6791 | case.backend = .stage1; |
| 6792 | |
| 6793 | case.addSourceFile("foo.zig", |
| 6794 | \\export fn bar() void {} |
| 6795 | \\pub const baz = 1234; |
| 6796 | ); |
| 6797 | |
| 6798 | case.addError( |
| 6550 | 6799 | \\const foo = @import("foo.zig",); |
| 6551 | 6800 | \\ |
| 6552 | 6801 | \\export fn bar() usize { |
| ... | ... | @@ -6556,18 +6805,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6556 | 6805 | "foo.zig:1:1: error: exported symbol collision: 'bar'", |
| 6557 | 6806 | "tmp.zig:3:1: note: other symbol here", |
| 6558 | 6807 | }); |
| 6808 | } |
| 6559 | 6809 | |
| 6560 | | tc.addSourceFile("foo.zig", |
| 6561 | | \\export fn bar() void {} |
| 6562 | | \\pub const baz = 1234; |
| 6563 | | ); |
| 6564 | | |
| 6565 | | break :x tc; |
| 6566 | | }); |
| 6567 | | |
| 6568 | | cases.add("implicit cast from array to mutable slice", |
| 6810 | ctx.objErrStage1("implicit cast from array to mutable slice", |
| 6569 | 6811 | \\var global_array: [10]i32 = undefined; |
| 6570 | | \\fn foo(param: []i32) void {} |
| 6812 | \\fn foo(param: []i32) void {_ = param;} |
| 6571 | 6813 | \\export fn entry() void { |
| 6572 | 6814 | \\ foo(global_array); |
| 6573 | 6815 | \\} |
| ... | ... | @@ -6575,7 +6817,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6575 | 6817 | "tmp.zig:4:9: error: expected type '[]i32', found '[10]i32'", |
| 6576 | 6818 | }); |
| 6577 | 6819 | |
| 6578 | | cases.add("ptrcast to non-pointer", |
| 6820 | ctx.objErrStage1("ptrcast to non-pointer", |
| 6579 | 6821 | \\export fn entry(a: *i32) usize { |
| 6580 | 6822 | \\ return @ptrCast(usize, a); |
| 6581 | 6823 | \\} |
| ... | ... | @@ -6583,7 +6825,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6583 | 6825 | "tmp.zig:2:21: error: expected pointer, found 'usize'", |
| 6584 | 6826 | }); |
| 6585 | 6827 | |
| 6586 | | cases.add("asm at compile time", |
| 6828 | ctx.objErrStage1("asm at compile time", |
| 6587 | 6829 | \\comptime { |
| 6588 | 6830 | \\ doSomeAsm(); |
| 6589 | 6831 | \\} |
| ... | ... | @@ -6599,25 +6841,27 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6599 | 6841 | "tmp.zig:6:5: error: unable to evaluate constant expression", |
| 6600 | 6842 | }); |
| 6601 | 6843 | |
| 6602 | | cases.add("invalid member of builtin enum", |
| 6844 | ctx.objErrStage1("invalid member of builtin enum", |
| 6603 | 6845 | \\const builtin = @import("std").builtin; |
| 6604 | 6846 | \\export fn entry() void { |
| 6605 | 6847 | \\ const foo = builtin.Mode.x86; |
| 6848 | \\ _ = foo; |
| 6606 | 6849 | \\} |
| 6607 | 6850 | , &[_][]const u8{ |
| 6608 | 6851 | "tmp.zig:3:29: error: container 'std.builtin.Mode' has no member called 'x86'", |
| 6609 | 6852 | }); |
| 6610 | 6853 | |
| 6611 | | cases.add("int to ptr of 0 bits", |
| 6854 | ctx.objErrStage1("int to ptr of 0 bits", |
| 6612 | 6855 | \\export fn foo() void { |
| 6613 | 6856 | \\ var x: usize = 0x1000; |
| 6614 | 6857 | \\ var y: *void = @intToPtr(*void, x); |
| 6858 | \\ _ = y; |
| 6615 | 6859 | \\} |
| 6616 | 6860 | , &[_][]const u8{ |
| 6617 | 6861 | "tmp.zig:3:30: error: type '*void' has 0 bits and cannot store information", |
| 6618 | 6862 | }); |
| 6619 | 6863 | |
| 6620 | | cases.add("@fieldParentPtr - non struct", |
| 6864 | ctx.objErrStage1("@fieldParentPtr - non struct", |
| 6621 | 6865 | \\const Foo = i32; |
| 6622 | 6866 | \\export fn foo(a: *i32) *Foo { |
| 6623 | 6867 | \\ return @fieldParentPtr(Foo, "a", a); |
| ... | ... | @@ -6626,7 +6870,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6626 | 6870 | "tmp.zig:3:28: error: expected struct type, found 'i32'", |
| 6627 | 6871 | }); |
| 6628 | 6872 | |
| 6629 | | cases.add("@fieldParentPtr - bad field name", |
| 6873 | ctx.objErrStage1("@fieldParentPtr - bad field name", |
| 6630 | 6874 | \\const Foo = extern struct { |
| 6631 | 6875 | \\ derp: i32, |
| 6632 | 6876 | \\}; |
| ... | ... | @@ -6637,7 +6881,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6637 | 6881 | "tmp.zig:5:33: error: struct 'Foo' has no field 'a'", |
| 6638 | 6882 | }); |
| 6639 | 6883 | |
| 6640 | | cases.add("@fieldParentPtr - field pointer is not pointer", |
| 6884 | ctx.objErrStage1("@fieldParentPtr - field pointer is not pointer", |
| 6641 | 6885 | \\const Foo = extern struct { |
| 6642 | 6886 | \\ a: i32, |
| 6643 | 6887 | \\}; |
| ... | ... | @@ -6648,7 +6892,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6648 | 6892 | "tmp.zig:5:38: error: expected pointer, found 'i32'", |
| 6649 | 6893 | }); |
| 6650 | 6894 | |
| 6651 | | cases.add("@fieldParentPtr - comptime field ptr not based on struct", |
| 6895 | ctx.objErrStage1("@fieldParentPtr - comptime field ptr not based on struct", |
| 6652 | 6896 | \\const Foo = struct { |
| 6653 | 6897 | \\ a: i32, |
| 6654 | 6898 | \\ b: i32, |
| ... | ... | @@ -6658,12 +6902,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6658 | 6902 | \\comptime { |
| 6659 | 6903 | \\ const field_ptr = @intToPtr(*i32, 0x1234); |
| 6660 | 6904 | \\ const another_foo_ptr = @fieldParentPtr(Foo, "b", field_ptr); |
| 6905 | \\ _ = another_foo_ptr; |
| 6661 | 6906 | \\} |
| 6662 | 6907 | , &[_][]const u8{ |
| 6663 | 6908 | "tmp.zig:9:55: error: pointer value not based on parent struct", |
| 6664 | 6909 | }); |
| 6665 | 6910 | |
| 6666 | | cases.add("@fieldParentPtr - comptime wrong field index", |
| 6911 | ctx.objErrStage1("@fieldParentPtr - comptime wrong field index", |
| 6667 | 6912 | \\const Foo = struct { |
| 6668 | 6913 | \\ a: i32, |
| 6669 | 6914 | \\ b: i32, |
| ... | ... | @@ -6672,12 +6917,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6672 | 6917 | \\ |
| 6673 | 6918 | \\comptime { |
| 6674 | 6919 | \\ const another_foo_ptr = @fieldParentPtr(Foo, "b", &foo.a); |
| 6920 | \\ _ = another_foo_ptr; |
| 6675 | 6921 | \\} |
| 6676 | 6922 | , &[_][]const u8{ |
| 6677 | 6923 | "tmp.zig:8:29: error: field 'b' has index 1 but pointer value is index 0 of struct 'Foo'", |
| 6678 | 6924 | }); |
| 6679 | 6925 | |
| 6680 | | cases.add("@offsetOf - non struct", |
| 6926 | ctx.objErrStage1("@offsetOf - non struct", |
| 6681 | 6927 | \\const Foo = i32; |
| 6682 | 6928 | \\export fn foo() usize { |
| 6683 | 6929 | \\ return @offsetOf(Foo, "a",); |
| ... | ... | @@ -6686,7 +6932,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6686 | 6932 | "tmp.zig:3:22: error: expected struct type, found 'i32'", |
| 6687 | 6933 | }); |
| 6688 | 6934 | |
| 6689 | | cases.add("@offsetOf - bad field name", |
| 6935 | ctx.objErrStage1("@offsetOf - bad field name", |
| 6690 | 6936 | \\const Foo = struct { |
| 6691 | 6937 | \\ derp: i32, |
| 6692 | 6938 | \\}; |
| ... | ... | @@ -6697,20 +6943,20 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6697 | 6943 | "tmp.zig:5:27: error: struct 'Foo' has no field 'a'", |
| 6698 | 6944 | }); |
| 6699 | 6945 | |
| 6700 | | cases.addExe("missing main fn in executable", |
| 6946 | ctx.exeErrStage1("missing main fn in executable", |
| 6701 | 6947 | \\ |
| 6702 | 6948 | , &[_][]const u8{ |
| 6703 | 6949 | "error: root source file has no member called 'main'", |
| 6704 | 6950 | }); |
| 6705 | 6951 | |
| 6706 | | cases.addExe("private main fn", |
| 6952 | ctx.exeErrStage1("private main fn", |
| 6707 | 6953 | \\fn main() void {} |
| 6708 | 6954 | , &[_][]const u8{ |
| 6709 | 6955 | "error: 'main' is private", |
| 6710 | 6956 | "tmp.zig:1:1: note: declared here", |
| 6711 | 6957 | }); |
| 6712 | 6958 | |
| 6713 | | cases.add("setting a section on a local variable", |
| 6959 | ctx.objErrStage1("setting a section on a local variable", |
| 6714 | 6960 | \\export fn entry() i32 { |
| 6715 | 6961 | \\ var foo: i32 linksection(".text2") = 1234; |
| 6716 | 6962 | \\ return foo; |
| ... | ... | @@ -6719,7 +6965,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6719 | 6965 | "tmp.zig:2:30: error: cannot set section of local variable 'foo'", |
| 6720 | 6966 | }); |
| 6721 | 6967 | |
| 6722 | | cases.add("inner struct member shadowing outer struct member", |
| 6968 | ctx.objErrStage1("inner struct member shadowing outer struct member", |
| 6723 | 6969 | \\fn A() type { |
| 6724 | 6970 | \\ return struct { |
| 6725 | 6971 | \\ b: B(), |
| ... | ... | @@ -6741,10 +6987,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6741 | 6987 | \\} |
| 6742 | 6988 | , &[_][]const u8{ |
| 6743 | 6989 | "tmp.zig:9:17: error: redefinition of 'Self'", |
| 6744 | | "tmp.zig:5:9: note: previous definition is here", |
| 6990 | "tmp.zig:5:9: note: previous definition here", |
| 6745 | 6991 | }); |
| 6746 | 6992 | |
| 6747 | | cases.add("while expected bool, got optional", |
| 6993 | ctx.objErrStage1("while expected bool, got optional", |
| 6748 | 6994 | \\export fn foo() void { |
| 6749 | 6995 | \\ while (bar()) {} |
| 6750 | 6996 | \\} |
| ... | ... | @@ -6753,7 +6999,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6753 | 6999 | "tmp.zig:2:15: error: expected type 'bool', found '?i32'", |
| 6754 | 7000 | }); |
| 6755 | 7001 | |
| 6756 | | cases.add("while expected bool, got error union", |
| 7002 | ctx.objErrStage1("while expected bool, got error union", |
| 6757 | 7003 | \\export fn foo() void { |
| 6758 | 7004 | \\ while (bar()) {} |
| 6759 | 7005 | \\} |
| ... | ... | @@ -6762,36 +7008,36 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6762 | 7008 | "tmp.zig:2:15: error: expected type 'bool', found 'anyerror!i32'", |
| 6763 | 7009 | }); |
| 6764 | 7010 | |
| 6765 | | cases.add("while expected optional, got bool", |
| 7011 | ctx.objErrStage1("while expected optional, got bool", |
| 6766 | 7012 | \\export fn foo() void { |
| 6767 | | \\ while (bar()) |x| {} |
| 7013 | \\ while (bar()) |x| {_ = x;} |
| 6768 | 7014 | \\} |
| 6769 | 7015 | \\fn bar() bool { return true; } |
| 6770 | 7016 | , &[_][]const u8{ |
| 6771 | 7017 | "tmp.zig:2:15: error: expected optional type, found 'bool'", |
| 6772 | 7018 | }); |
| 6773 | 7019 | |
| 6774 | | cases.add("while expected optional, got error union", |
| 7020 | ctx.objErrStage1("while expected optional, got error union", |
| 6775 | 7021 | \\export fn foo() void { |
| 6776 | | \\ while (bar()) |x| {} |
| 7022 | \\ while (bar()) |x| {_ = x;} |
| 6777 | 7023 | \\} |
| 6778 | 7024 | \\fn bar() anyerror!i32 { return 1; } |
| 6779 | 7025 | , &[_][]const u8{ |
| 6780 | 7026 | "tmp.zig:2:15: error: expected optional type, found 'anyerror!i32'", |
| 6781 | 7027 | }); |
| 6782 | 7028 | |
| 6783 | | cases.add("while expected error union, got bool", |
| 7029 | ctx.objErrStage1("while expected error union, got bool", |
| 6784 | 7030 | \\export fn foo() void { |
| 6785 | | \\ while (bar()) |x| {} else |err| {} |
| 7031 | \\ while (bar()) |x| {_ = x;} else |err| {_ = err;} |
| 6786 | 7032 | \\} |
| 6787 | 7033 | \\fn bar() bool { return true; } |
| 6788 | 7034 | , &[_][]const u8{ |
| 6789 | 7035 | "tmp.zig:2:15: error: expected error union type, found 'bool'", |
| 6790 | 7036 | }); |
| 6791 | 7037 | |
| 6792 | | cases.add("while expected error union, got optional", |
| 7038 | ctx.objErrStage1("while expected error union, got optional", |
| 6793 | 7039 | \\export fn foo() void { |
| 6794 | | \\ while (bar()) |x| {} else |err| {} |
| 7040 | \\ while (bar()) |x| {_ = x;} else |err| {_ = err;} |
| 6795 | 7041 | \\} |
| 6796 | 7042 | \\fn bar() ?i32 { return 1; } |
| 6797 | 7043 | , &[_][]const u8{ |
| ... | ... | @@ -6799,7 +7045,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6799 | 7045 | }); |
| 6800 | 7046 | |
| 6801 | 7047 | // TODO test this in stage2, but we won't even try in stage1 |
| 6802 | | //cases.add("inline fn calls itself indirectly", |
| 7048 | //ctx.objErrStage1("inline fn calls itself indirectly", |
| 6803 | 7049 | // \\export fn foo() void { |
| 6804 | 7050 | // \\ bar(); |
| 6805 | 7051 | // \\} |
| ... | ... | @@ -6816,7 +7062,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6816 | 7062 | // "tmp.zig:4:1: error: unable to inline function", |
| 6817 | 7063 | //}); |
| 6818 | 7064 | |
| 6819 | | //cases.add("save reference to inline function", |
| 7065 | //ctx.objErrStage1("save reference to inline function", |
| 6820 | 7066 | // \\export fn foo() void { |
| 6821 | 7067 | // \\ quux(@ptrToInt(bar)); |
| 6822 | 7068 | // \\} |
| ... | ... | @@ -6826,7 +7072,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6826 | 7072 | // "tmp.zig:4:1: error: unable to inline function", |
| 6827 | 7073 | //}); |
| 6828 | 7074 | |
| 6829 | | cases.add("signed integer division", |
| 7075 | ctx.objErrStage1("signed integer division", |
| 6830 | 7076 | \\export fn foo(a: i32, b: i32) i32 { |
| 6831 | 7077 | \\ return a / b; |
| 6832 | 7078 | \\} |
| ... | ... | @@ -6834,7 +7080,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6834 | 7080 | "tmp.zig:2:14: error: division with 'i32' and 'i32': signed integers must use @divTrunc, @divFloor, or @divExact", |
| 6835 | 7081 | }); |
| 6836 | 7082 | |
| 6837 | | cases.add("signed integer remainder division", |
| 7083 | ctx.objErrStage1("signed integer remainder division", |
| 6838 | 7084 | \\export fn foo(a: i32, b: i32) i32 { |
| 6839 | 7085 | \\ return a % b; |
| 6840 | 7086 | \\} |
| ... | ... | @@ -6842,27 +7088,29 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6842 | 7088 | "tmp.zig:2:14: error: remainder division with 'i32' and 'i32': signed integers and floats must use @rem or @mod", |
| 6843 | 7089 | }); |
| 6844 | 7090 | |
| 6845 | | cases.add("compile-time division by zero", |
| 7091 | ctx.objErrStage1("compile-time division by zero", |
| 6846 | 7092 | \\comptime { |
| 6847 | 7093 | \\ const a: i32 = 1; |
| 6848 | 7094 | \\ const b: i32 = 0; |
| 6849 | 7095 | \\ const c = a / b; |
| 7096 | \\ _ = c; |
| 6850 | 7097 | \\} |
| 6851 | 7098 | , &[_][]const u8{ |
| 6852 | 7099 | "tmp.zig:4:17: error: division by zero", |
| 6853 | 7100 | }); |
| 6854 | 7101 | |
| 6855 | | cases.add("compile-time remainder division by zero", |
| 7102 | ctx.objErrStage1("compile-time remainder division by zero", |
| 6856 | 7103 | \\comptime { |
| 6857 | 7104 | \\ const a: i32 = 1; |
| 6858 | 7105 | \\ const b: i32 = 0; |
| 6859 | 7106 | \\ const c = a % b; |
| 7107 | \\ _ = c; |
| 6860 | 7108 | \\} |
| 6861 | 7109 | , &[_][]const u8{ |
| 6862 | 7110 | "tmp.zig:4:17: error: division by zero", |
| 6863 | 7111 | }); |
| 6864 | 7112 | |
| 6865 | | cases.add("@setRuntimeSafety twice for same scope", |
| 7113 | ctx.objErrStage1("@setRuntimeSafety twice for same scope", |
| 6866 | 7114 | \\export fn foo() void { |
| 6867 | 7115 | \\ @setRuntimeSafety(false); |
| 6868 | 7116 | \\ @setRuntimeSafety(false); |
| ... | ... | @@ -6872,7 +7120,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6872 | 7120 | "tmp.zig:2:5: note: first set here", |
| 6873 | 7121 | }); |
| 6874 | 7122 | |
| 6875 | | cases.add("@setFloatMode twice for same scope", |
| 7123 | ctx.objErrStage1("@setFloatMode twice for same scope", |
| 6876 | 7124 | \\export fn foo() void { |
| 6877 | 7125 | \\ @setFloatMode(@import("std").builtin.FloatMode.Optimized); |
| 6878 | 7126 | \\ @setFloatMode(@import("std").builtin.FloatMode.Optimized); |
| ... | ... | @@ -6882,15 +7130,16 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6882 | 7130 | "tmp.zig:2:5: note: first set here", |
| 6883 | 7131 | }); |
| 6884 | 7132 | |
| 6885 | | cases.add("array access of type", |
| 7133 | ctx.objErrStage1("array access of type", |
| 6886 | 7134 | \\export fn foo() void { |
| 6887 | 7135 | \\ var b: u8[40] = undefined; |
| 7136 | \\ _ = b; |
| 6888 | 7137 | \\} |
| 6889 | 7138 | , &[_][]const u8{ |
| 6890 | 7139 | "tmp.zig:2:14: error: array access of non-array type 'type'", |
| 6891 | 7140 | }); |
| 6892 | 7141 | |
| 6893 | | cases.add("cannot break out of defer expression", |
| 7142 | ctx.objErrStage1("cannot break out of defer expression", |
| 6894 | 7143 | \\export fn foo() void { |
| 6895 | 7144 | \\ while (true) { |
| 6896 | 7145 | \\ defer { |
| ... | ... | @@ -6902,7 +7151,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6902 | 7151 | "tmp.zig:4:13: error: cannot break out of defer expression", |
| 6903 | 7152 | }); |
| 6904 | 7153 | |
| 6905 | | cases.add("cannot continue out of defer expression", |
| 7154 | ctx.objErrStage1("cannot continue out of defer expression", |
| 6906 | 7155 | \\export fn foo() void { |
| 6907 | 7156 | \\ while (true) { |
| 6908 | 7157 | \\ defer { |
| ... | ... | @@ -6914,11 +7163,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6914 | 7163 | "tmp.zig:4:13: error: cannot continue out of defer expression", |
| 6915 | 7164 | }); |
| 6916 | 7165 | |
| 6917 | | cases.add("calling a generic function only known at runtime", |
| 7166 | ctx.objErrStage1("calling a generic function only known at runtime", |
| 6918 | 7167 | \\var foos = [_]fn(anytype) void { foo1, foo2 }; |
| 6919 | 7168 | \\ |
| 6920 | | \\fn foo1(arg: anytype) void {} |
| 6921 | | \\fn foo2(arg: anytype) void {} |
| 7169 | \\fn foo1(arg: anytype) void {_ = arg;} |
| 7170 | \\fn foo2(arg: anytype) void {_ = arg;} |
| 6922 | 7171 | \\ |
| 6923 | 7172 | \\pub fn main() !void { |
| 6924 | 7173 | \\ foos[0](true); |
| ... | ... | @@ -6927,7 +7176,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6927 | 7176 | "tmp.zig:7:9: error: calling a generic function requires compile-time known function value", |
| 6928 | 7177 | }); |
| 6929 | 7178 | |
| 6930 | | cases.add("@compileError shows traceback of references that caused it", |
| 7179 | ctx.objErrStage1("@compileError shows traceback of references that caused it", |
| 6931 | 7180 | \\const foo = @compileError("aoeu",); |
| 6932 | 7181 | \\ |
| 6933 | 7182 | \\const bar = baz + foo; |
| ... | ... | @@ -6942,23 +7191,25 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6942 | 7191 | "tmp.zig:7:12: note: referenced here", |
| 6943 | 7192 | }); |
| 6944 | 7193 | |
| 6945 | | cases.add("float literal too large error", |
| 7194 | ctx.objErrStage1("float literal too large error", |
| 6946 | 7195 | \\comptime { |
| 6947 | 7196 | \\ const a = 0x1.0p18495; |
| 7197 | \\ _ = a; |
| 6948 | 7198 | \\} |
| 6949 | 7199 | , &[_][]const u8{ |
| 6950 | 7200 | "tmp.zig:2:15: error: float literal out of range of any type", |
| 6951 | 7201 | }); |
| 6952 | 7202 | |
| 6953 | | cases.add("float literal too small error (denormal)", |
| 7203 | ctx.objErrStage1("float literal too small error (denormal)", |
| 6954 | 7204 | \\comptime { |
| 6955 | 7205 | \\ const a = 0x1.0p-19000; |
| 7206 | \\ _ = a; |
| 6956 | 7207 | \\} |
| 6957 | 7208 | , &[_][]const u8{ |
| 6958 | 7209 | "tmp.zig:2:15: error: float literal out of range of any type", |
| 6959 | 7210 | }); |
| 6960 | 7211 | |
| 6961 | | cases.add("explicit cast float literal to integer when there is a fraction component", |
| 7212 | ctx.objErrStage1("explicit cast float literal to integer when there is a fraction component", |
| 6962 | 7213 | \\export fn entry() i32 { |
| 6963 | 7214 | \\ return @as(i32, 12.34); |
| 6964 | 7215 | \\} |
| ... | ... | @@ -6966,7 +7217,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6966 | 7217 | "tmp.zig:2:21: error: fractional component prevents float value 12.340000 from being casted to type 'i32'", |
| 6967 | 7218 | }); |
| 6968 | 7219 | |
| 6969 | | cases.add("non pointer given to @ptrToInt", |
| 7220 | ctx.objErrStage1("non pointer given to @ptrToInt", |
| 6970 | 7221 | \\export fn entry(x: i32) usize { |
| 6971 | 7222 | \\ return @ptrToInt(x); |
| 6972 | 7223 | \\} |
| ... | ... | @@ -6974,23 +7225,25 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6974 | 7225 | "tmp.zig:2:22: error: expected pointer, found 'i32'", |
| 6975 | 7226 | }); |
| 6976 | 7227 | |
| 6977 | | cases.add("@shlExact shifts out 1 bits", |
| 7228 | ctx.objErrStage1("@shlExact shifts out 1 bits", |
| 6978 | 7229 | \\comptime { |
| 6979 | 7230 | \\ const x = @shlExact(@as(u8, 0b01010101), 2); |
| 7231 | \\ _ = x; |
| 6980 | 7232 | \\} |
| 6981 | 7233 | , &[_][]const u8{ |
| 6982 | 7234 | "tmp.zig:2:15: error: operation caused overflow", |
| 6983 | 7235 | }); |
| 6984 | 7236 | |
| 6985 | | cases.add("@shrExact shifts out 1 bits", |
| 7237 | ctx.objErrStage1("@shrExact shifts out 1 bits", |
| 6986 | 7238 | \\comptime { |
| 6987 | 7239 | \\ const x = @shrExact(@as(u8, 0b10101010), 2); |
| 7240 | \\ _ = x; |
| 6988 | 7241 | \\} |
| 6989 | 7242 | , &[_][]const u8{ |
| 6990 | 7243 | "tmp.zig:2:15: error: exact shift shifted out 1 bits", |
| 6991 | 7244 | }); |
| 6992 | 7245 | |
| 6993 | | cases.add("shifting without int type or comptime known", |
| 7246 | ctx.objErrStage1("shifting without int type or comptime known", |
| 6994 | 7247 | \\export fn entry(x: u8) u8 { |
| 6995 | 7248 | \\ return 0x11 << x; |
| 6996 | 7249 | \\} |
| ... | ... | @@ -6998,7 +7251,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6998 | 7251 | "tmp.zig:2:17: error: LHS of shift must be a fixed-width integer type, or RHS must be compile-time known", |
| 6999 | 7252 | }); |
| 7000 | 7253 | |
| 7001 | | cases.add("shifting RHS is log2 of LHS int bit width", |
| 7254 | ctx.objErrStage1("shifting RHS is log2 of LHS int bit width", |
| 7002 | 7255 | \\export fn entry(x: u8, y: u8) u8 { |
| 7003 | 7256 | \\ return x << y; |
| 7004 | 7257 | \\} |
| ... | ... | @@ -7006,16 +7259,17 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7006 | 7259 | "tmp.zig:2:17: error: expected type 'u3', found 'u8'", |
| 7007 | 7260 | }); |
| 7008 | 7261 | |
| 7009 | | cases.add("globally shadowing a primitive type", |
| 7262 | ctx.objErrStage1("globally shadowing a primitive type", |
| 7010 | 7263 | \\const u16 = u8; |
| 7011 | 7264 | \\export fn entry() void { |
| 7012 | 7265 | \\ const a: u16 = 300; |
| 7266 | \\ _ = a; |
| 7013 | 7267 | \\} |
| 7014 | 7268 | , &[_][]const u8{ |
| 7015 | 7269 | "tmp.zig:1:1: error: declaration shadows primitive type 'u16'", |
| 7016 | 7270 | }); |
| 7017 | 7271 | |
| 7018 | | cases.add("implicitly increasing pointer alignment", |
| 7272 | ctx.objErrStage1("implicitly increasing pointer alignment", |
| 7019 | 7273 | \\const Foo = packed struct { |
| 7020 | 7274 | \\ a: u8, |
| 7021 | 7275 | \\ b: u32, |
| ... | ... | @@ -7033,7 +7287,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7033 | 7287 | "tmp.zig:8:13: error: expected type '*u32', found '*align(1) u32'", |
| 7034 | 7288 | }); |
| 7035 | 7289 | |
| 7036 | | cases.add("implicitly increasing slice alignment", |
| 7290 | ctx.objErrStage1("implicitly increasing slice alignment", |
| 7037 | 7291 | \\const Foo = packed struct { |
| 7038 | 7292 | \\ a: u8, |
| 7039 | 7293 | \\ b: u32, |
| ... | ... | @@ -7054,7 +7308,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7054 | 7308 | "tmp.zig:9:26: note: '*[1]u32' has alignment 4", |
| 7055 | 7309 | }); |
| 7056 | 7310 | |
| 7057 | | cases.add("increase pointer alignment in @ptrCast", |
| 7311 | ctx.objErrStage1("increase pointer alignment in @ptrCast", |
| 7058 | 7312 | \\export fn entry() u32 { |
| 7059 | 7313 | \\ var bytes: [4]u8 = [_]u8{0x01, 0x02, 0x03, 0x04}; |
| 7060 | 7314 | \\ const ptr = @ptrCast(*u32, &bytes[0]); |
| ... | ... | @@ -7066,7 +7320,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7066 | 7320 | "tmp.zig:3:26: note: '*u32' has alignment 4", |
| 7067 | 7321 | }); |
| 7068 | 7322 | |
| 7069 | | cases.add("@alignCast expects pointer or slice", |
| 7323 | ctx.objErrStage1("@alignCast expects pointer or slice", |
| 7070 | 7324 | \\export fn entry() void { |
| 7071 | 7325 | \\ @alignCast(4, @as(u32, 3)); |
| 7072 | 7326 | \\} |
| ... | ... | @@ -7074,7 +7328,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7074 | 7328 | "tmp.zig:2:19: error: expected pointer or slice, found 'u32'", |
| 7075 | 7329 | }); |
| 7076 | 7330 | |
| 7077 | | cases.add("passing an under-aligned function pointer", |
| 7331 | ctx.objErrStage1("passing an under-aligned function pointer", |
| 7078 | 7332 | \\export fn entry() void { |
| 7079 | 7333 | \\ testImplicitlyDecreaseFnAlign(alignedSmall, 1234); |
| 7080 | 7334 | \\} |
| ... | ... | @@ -7086,7 +7340,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7086 | 7340 | "tmp.zig:2:35: error: expected type 'fn() align(8) i32', found 'fn() align(4) i32'", |
| 7087 | 7341 | }); |
| 7088 | 7342 | |
| 7089 | | cases.add("passing a not-aligned-enough pointer to cmpxchg", |
| 7343 | ctx.objErrStage1("passing a not-aligned-enough pointer to cmpxchg", |
| 7090 | 7344 | \\const AtomicOrder = @import("std").builtin.AtomicOrder; |
| 7091 | 7345 | \\export fn entry() bool { |
| 7092 | 7346 | \\ var x: i32 align(1) = 1234; |
| ... | ... | @@ -7097,15 +7351,16 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7097 | 7351 | "tmp.zig:4:32: error: expected type '*i32', found '*align(1) i32'", |
| 7098 | 7352 | }); |
| 7099 | 7353 | |
| 7100 | | cases.add("wrong size to an array literal", |
| 7354 | ctx.objErrStage1("wrong size to an array literal", |
| 7101 | 7355 | \\comptime { |
| 7102 | 7356 | \\ const array = [2]u8{1, 2, 3}; |
| 7357 | \\ _ = array; |
| 7103 | 7358 | \\} |
| 7104 | 7359 | , &[_][]const u8{ |
| 7105 | 7360 | "tmp.zig:2:31: error: index 2 outside array of size 2", |
| 7106 | 7361 | }); |
| 7107 | 7362 | |
| 7108 | | cases.add("wrong pointer coerced to pointer to opaque {}", |
| 7363 | ctx.objErrStage1("wrong pointer coerced to pointer to opaque {}", |
| 7109 | 7364 | \\const Derp = opaque {}; |
| 7110 | 7365 | \\extern fn bar(d: *Derp) void; |
| 7111 | 7366 | \\export fn foo() void { |
| ... | ... | @@ -7116,53 +7371,66 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7116 | 7371 | "tmp.zig:5:9: error: expected type '*Derp', found '*c_void'", |
| 7117 | 7372 | }); |
| 7118 | 7373 | |
| 7119 | | cases.add("non-const variables of things that require const variables", |
| 7374 | ctx.objErrStage1("non-const variables of things that require const variables", |
| 7120 | 7375 | \\export fn entry1() void { |
| 7121 | 7376 | \\ var m2 = &2; |
| 7377 | \\ _ = m2; |
| 7122 | 7378 | \\} |
| 7123 | 7379 | \\export fn entry2() void { |
| 7124 | 7380 | \\ var a = undefined; |
| 7381 | \\ _ = a; |
| 7125 | 7382 | \\} |
| 7126 | 7383 | \\export fn entry3() void { |
| 7127 | 7384 | \\ var b = 1; |
| 7385 | \\ _ = b; |
| 7128 | 7386 | \\} |
| 7129 | 7387 | \\export fn entry4() void { |
| 7130 | 7388 | \\ var c = 1.0; |
| 7389 | \\ _ = c; |
| 7131 | 7390 | \\} |
| 7132 | 7391 | \\export fn entry5() void { |
| 7133 | 7392 | \\ var d = null; |
| 7393 | \\ _ = d; |
| 7134 | 7394 | \\} |
| 7135 | 7395 | \\export fn entry6(opaque_: *Opaque) void { |
| 7136 | 7396 | \\ var e = opaque_.*; |
| 7397 | \\ _ = e; |
| 7137 | 7398 | \\} |
| 7138 | 7399 | \\export fn entry7() void { |
| 7139 | 7400 | \\ var f = i32; |
| 7401 | \\ _ = f; |
| 7140 | 7402 | \\} |
| 7141 | 7403 | \\export fn entry8() void { |
| 7142 | 7404 | \\ var h = (Foo {}).bar; |
| 7143 | | \\} |
| 7144 | | \\export fn entry9() void { |
| 7145 | | \\ var z: noreturn = return; |
| 7405 | \\ _ = h; |
| 7146 | 7406 | \\} |
| 7147 | 7407 | \\const Opaque = opaque {}; |
| 7148 | 7408 | \\const Foo = struct { |
| 7149 | | \\ fn bar(self: *const Foo) void {} |
| 7409 | \\ fn bar(self: *const Foo) void {_ = self;} |
| 7150 | 7410 | \\}; |
| 7151 | 7411 | , &[_][]const u8{ |
| 7152 | 7412 | "tmp.zig:2:4: error: variable of type '*const comptime_int' must be const or comptime", |
| 7153 | | "tmp.zig:5:4: error: variable of type '(undefined)' must be const or comptime", |
| 7154 | | "tmp.zig:8:4: error: variable of type 'comptime_int' must be const or comptime", |
| 7155 | | "tmp.zig:8:4: note: to modify this variable at runtime, it must be given an explicit fixed-size number type", |
| 7156 | | "tmp.zig:11:4: error: variable of type 'comptime_float' must be const or comptime", |
| 7157 | | "tmp.zig:11:4: note: to modify this variable at runtime, it must be given an explicit fixed-size number type", |
| 7158 | | "tmp.zig:14:4: error: variable of type '(null)' must be const or comptime", |
| 7159 | | "tmp.zig:17:4: error: variable of type 'Opaque' not allowed", |
| 7160 | | "tmp.zig:20:4: error: variable of type 'type' must be const or comptime", |
| 7161 | | "tmp.zig:23:4: error: variable of type '(bound fn(*const Foo) void)' must be const or comptime", |
| 7162 | | "tmp.zig:26:22: error: unreachable code", |
| 7413 | "tmp.zig:6:4: error: variable of type '(undefined)' must be const or comptime", |
| 7414 | "tmp.zig:10:4: error: variable of type 'comptime_int' must be const or comptime", |
| 7415 | "tmp.zig:10:4: note: to modify this variable at runtime, it must be given an explicit fixed-size number type", |
| 7416 | "tmp.zig:14:4: error: variable of type 'comptime_float' must be const or comptime", |
| 7417 | "tmp.zig:14:4: note: to modify this variable at runtime, it must be given an explicit fixed-size number type", |
| 7418 | "tmp.zig:18:4: error: variable of type '(null)' must be const or comptime", |
| 7419 | "tmp.zig:22:4: error: variable of type 'Opaque' not allowed", |
| 7420 | "tmp.zig:26:4: error: variable of type 'type' must be const or comptime", |
| 7421 | "tmp.zig:30:4: error: variable of type '(bound fn(*const Foo) void)' must be const or comptime", |
| 7422 | }); |
| 7423 | |
| 7424 | ctx.objErrStage1("variable with type 'noreturn'", |
| 7425 | \\export fn entry9() void { |
| 7426 | \\ var z: noreturn = return; |
| 7427 | \\} |
| 7428 | , &[_][]const u8{ |
| 7429 | "tmp.zig:2:5: error: unreachable code", |
| 7430 | "tmp.zig:2:23: note: control flow is diverted here", |
| 7163 | 7431 | }); |
| 7164 | 7432 | |
| 7165 | | cases.add("wrong types given to atomic order args in cmpxchg", |
| 7433 | ctx.objErrStage1("wrong types given to atomic order args in cmpxchg", |
| 7166 | 7434 | \\export fn entry() void { |
| 7167 | 7435 | \\ var x: i32 = 1234; |
| 7168 | 7436 | \\ while (!@cmpxchgWeak(i32, &x, 1234, 5678, @as(u32, 1234), @as(u32, 1234))) {} |
| ... | ... | @@ -7171,7 +7439,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7171 | 7439 | "tmp.zig:3:47: error: expected type 'std.builtin.AtomicOrder', found 'u32'", |
| 7172 | 7440 | }); |
| 7173 | 7441 | |
| 7174 | | cases.add("wrong types given to @export", |
| 7442 | ctx.objErrStage1("wrong types given to @export", |
| 7175 | 7443 | \\fn entry() callconv(.C) void { } |
| 7176 | 7444 | \\comptime { |
| 7177 | 7445 | \\ @export(entry, .{.name = "entry", .linkage = @as(u32, 1234) }); |
| ... | ... | @@ -7180,7 +7448,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7180 | 7448 | "tmp.zig:3:59: error: expected type 'std.builtin.GlobalLinkage', found 'comptime_int'", |
| 7181 | 7449 | }); |
| 7182 | 7450 | |
| 7183 | | cases.add("struct with invalid field", |
| 7451 | ctx.objErrStage1("struct with invalid field", |
| 7184 | 7452 | \\const std = @import("std",); |
| 7185 | 7453 | \\const Allocator = std.mem.Allocator; |
| 7186 | 7454 | \\const ArrayList = std.ArrayList; |
| ... | ... | @@ -7203,12 +7471,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7203 | 7471 | \\ .text = MdText.init(&std.testing.allocator), |
| 7204 | 7472 | \\ .weight = HeaderWeight.H1, |
| 7205 | 7473 | \\ }; |
| 7474 | \\ _ = a; |
| 7206 | 7475 | \\} |
| 7207 | 7476 | , &[_][]const u8{ |
| 7208 | 7477 | "tmp.zig:14:17: error: use of undeclared identifier 'HeaderValue'", |
| 7209 | 7478 | }); |
| 7210 | 7479 | |
| 7211 | | cases.add("@setAlignStack outside function", |
| 7480 | ctx.objErrStage1("@setAlignStack outside function", |
| 7212 | 7481 | \\comptime { |
| 7213 | 7482 | \\ @setAlignStack(16); |
| 7214 | 7483 | \\} |
| ... | ... | @@ -7216,7 +7485,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7216 | 7485 | "tmp.zig:2:5: error: @setAlignStack outside function", |
| 7217 | 7486 | }); |
| 7218 | 7487 | |
| 7219 | | cases.add("@setAlignStack in naked function", |
| 7488 | ctx.objErrStage1("@setAlignStack in naked function", |
| 7220 | 7489 | \\export fn entry() callconv(.Naked) void { |
| 7221 | 7490 | \\ @setAlignStack(16); |
| 7222 | 7491 | \\} |
| ... | ... | @@ -7224,7 +7493,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7224 | 7493 | "tmp.zig:2:5: error: @setAlignStack in naked function", |
| 7225 | 7494 | }); |
| 7226 | 7495 | |
| 7227 | | cases.add("@setAlignStack in inline function", |
| 7496 | ctx.objErrStage1("@setAlignStack in inline function", |
| 7228 | 7497 | \\export fn entry() void { |
| 7229 | 7498 | \\ foo(); |
| 7230 | 7499 | \\} |
| ... | ... | @@ -7235,7 +7504,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7235 | 7504 | "tmp.zig:5:5: error: @setAlignStack in inline function", |
| 7236 | 7505 | }); |
| 7237 | 7506 | |
| 7238 | | cases.add("@setAlignStack set twice", |
| 7507 | ctx.objErrStage1("@setAlignStack set twice", |
| 7239 | 7508 | \\export fn entry() void { |
| 7240 | 7509 | \\ @setAlignStack(16); |
| 7241 | 7510 | \\ @setAlignStack(16); |
| ... | ... | @@ -7245,7 +7514,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7245 | 7514 | "tmp.zig:2:5: note: first set here", |
| 7246 | 7515 | }); |
| 7247 | 7516 | |
| 7248 | | cases.add("@setAlignStack too big", |
| 7517 | ctx.objErrStage1("@setAlignStack too big", |
| 7249 | 7518 | \\export fn entry() void { |
| 7250 | 7519 | \\ @setAlignStack(511 + 1); |
| 7251 | 7520 | \\} |
| ... | ... | @@ -7253,7 +7522,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7253 | 7522 | "tmp.zig:2:5: error: attempt to @setAlignStack(512); maximum is 256", |
| 7254 | 7523 | }); |
| 7255 | 7524 | |
| 7256 | | cases.add("storing runtime value in compile time variable then using it", |
| 7525 | ctx.objErrStage1("storing runtime value in compile time variable then using it", |
| 7257 | 7526 | \\const Mode = @import("std").builtin.Mode; |
| 7258 | 7527 | \\ |
| 7259 | 7528 | \\fn Free(comptime filename: []const u8) TestCase { |
| ... | ... | @@ -7290,24 +7559,27 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7290 | 7559 | \\ }; |
| 7291 | 7560 | \\ |
| 7292 | 7561 | \\ for ([_]Mode { Mode.Debug, Mode.ReleaseSafe, Mode.ReleaseFast }) |mode| { |
| 7562 | \\ _ = mode; |
| 7293 | 7563 | \\ inline for (tests) |test_case| { |
| 7294 | 7564 | \\ const foo = test_case.filename ++ ".zig"; |
| 7565 | \\ _ = foo; |
| 7295 | 7566 | \\ } |
| 7296 | 7567 | \\ } |
| 7297 | 7568 | \\} |
| 7298 | 7569 | , &[_][]const u8{ |
| 7299 | | "tmp.zig:37:29: error: cannot store runtime value in compile time variable", |
| 7570 | "tmp.zig:38:29: error: cannot store runtime value in compile time variable", |
| 7300 | 7571 | }); |
| 7301 | 7572 | |
| 7302 | | cases.add("invalid legacy unicode escape", |
| 7573 | ctx.objErrStage1("invalid legacy unicode escape", |
| 7303 | 7574 | \\export fn entry() void { |
| 7304 | 7575 | \\ const a = '\U1234'; |
| 7305 | 7576 | \\} |
| 7306 | 7577 | , &[_][]const u8{ |
| 7307 | | "tmp.zig:2:17: error: invalid character: 'U'", |
| 7578 | "tmp.zig:2:15: error: expected expression, found 'invalid'", |
| 7579 | "tmp.zig:2:18: note: invalid byte: '1'", |
| 7308 | 7580 | }); |
| 7309 | 7581 | |
| 7310 | | cases.add("invalid empty unicode escape", |
| 7582 | ctx.objErrStage1("invalid empty unicode escape", |
| 7311 | 7583 | \\export fn entry() void { |
| 7312 | 7584 | \\ const a = '\u{}'; |
| 7313 | 7585 | \\} |
| ... | ... | @@ -7315,21 +7587,21 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7315 | 7587 | "tmp.zig:2:19: error: empty unicode escape sequence", |
| 7316 | 7588 | }); |
| 7317 | 7589 | |
| 7318 | | cases.add("non-printable invalid character", "\xff\xfe" ++ |
| 7319 | | \\fn test() bool {\r |
| 7320 | | \\ true\r |
| 7321 | | \\} |
| 7322 | | , &[_][]const u8{ |
| 7323 | | "tmp.zig:1:1: error: invalid character: '\\xff'", |
| 7590 | ctx.objErrStage1("non-printable invalid character", "\xff\xfe" ++ |
| 7591 | "fn foo() bool {\r\n" ++ |
| 7592 | " return true;\r\n" ++ |
| 7593 | "}\r\n", &[_][]const u8{ |
| 7594 | "tmp.zig:1:1: error: expected test, comptime, var decl, or container field, found 'invalid'", |
| 7595 | "tmp.zig:1:1: note: invalid byte: '\\xff'", |
| 7324 | 7596 | }); |
| 7325 | 7597 | |
| 7326 | | cases.add("non-printable invalid character with escape alternative", "fn test() bool {\n" ++ |
| 7327 | | "\ttrue\n" ++ |
| 7598 | ctx.objErrStage1("non-printable invalid character with escape alternative", "fn foo() bool {\n" ++ |
| 7599 | "\treturn true;\n" ++ |
| 7328 | 7600 | "}\n", &[_][]const u8{ |
| 7329 | 7601 | "tmp.zig:2:1: error: invalid character: '\\t'", |
| 7330 | 7602 | }); |
| 7331 | 7603 | |
| 7332 | | cases.add("calling var args extern function, passing array instead of pointer", |
| 7604 | ctx.objErrStage1("calling var args extern function, passing array instead of pointer", |
| 7333 | 7605 | \\export fn entry() void { |
| 7334 | 7606 | \\ foo("hello".*,); |
| 7335 | 7607 | \\} |
| ... | ... | @@ -7338,7 +7610,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7338 | 7610 | "tmp.zig:2:16: error: expected type '*const u8', found '[5:0]u8'", |
| 7339 | 7611 | }); |
| 7340 | 7612 | |
| 7341 | | cases.add("constant inside comptime function has compile error", |
| 7613 | ctx.objErrStage1("constant inside comptime function has compile error", |
| 7342 | 7614 | \\const ContextAllocator = MemoryPool(usize); |
| 7343 | 7615 | \\ |
| 7344 | 7616 | \\pub fn MemoryPool(comptime T: type) type { |
| ... | ... | @@ -7353,12 +7625,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7353 | 7625 | \\ var allocator: ContextAllocator = undefined; |
| 7354 | 7626 | \\} |
| 7355 | 7627 | , &[_][]const u8{ |
| 7356 | | "tmp.zig:4:25: error: aoeu", |
| 7357 | | "tmp.zig:1:36: note: referenced here", |
| 7358 | | "tmp.zig:12:20: note: referenced here", |
| 7628 | "tmp.zig:4:5: error: unreachable code", |
| 7629 | "tmp.zig:4:25: note: control flow is diverted here", |
| 7630 | "tmp.zig:12:9: error: unused local variable", |
| 7359 | 7631 | }); |
| 7360 | 7632 | |
| 7361 | | cases.add("specify enum tag type that is too small", |
| 7633 | ctx.objErrStage1("specify enum tag type that is too small", |
| 7362 | 7634 | \\const Small = enum (u2) { |
| 7363 | 7635 | \\ One, |
| 7364 | 7636 | \\ Two, |
| ... | ... | @@ -7369,12 +7641,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7369 | 7641 | \\ |
| 7370 | 7642 | \\export fn entry() void { |
| 7371 | 7643 | \\ var x = Small.One; |
| 7644 | \\ _ = x; |
| 7372 | 7645 | \\} |
| 7373 | 7646 | , &[_][]const u8{ |
| 7374 | 7647 | "tmp.zig:6:5: error: enumeration value 4 too large for type 'u2'", |
| 7375 | 7648 | }); |
| 7376 | 7649 | |
| 7377 | | cases.add("specify non-integer enum tag type", |
| 7650 | ctx.objErrStage1("specify non-integer enum tag type", |
| 7378 | 7651 | \\const Small = enum (f32) { |
| 7379 | 7652 | \\ One, |
| 7380 | 7653 | \\ Two, |
| ... | ... | @@ -7383,12 +7656,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7383 | 7656 | \\ |
| 7384 | 7657 | \\export fn entry() void { |
| 7385 | 7658 | \\ var x = Small.One; |
| 7659 | \\ _ = x; |
| 7386 | 7660 | \\} |
| 7387 | 7661 | , &[_][]const u8{ |
| 7388 | 7662 | "tmp.zig:1:21: error: expected integer, found 'f32'", |
| 7389 | 7663 | }); |
| 7390 | 7664 | |
| 7391 | | cases.add("implicitly casting enum to tag type", |
| 7665 | ctx.objErrStage1("implicitly casting enum to tag type", |
| 7392 | 7666 | \\const Small = enum(u2) { |
| 7393 | 7667 | \\ One, |
| 7394 | 7668 | \\ Two, |
| ... | ... | @@ -7398,12 +7672,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7398 | 7672 | \\ |
| 7399 | 7673 | \\export fn entry() void { |
| 7400 | 7674 | \\ var x: u2 = Small.Two; |
| 7675 | \\ _ = x; |
| 7401 | 7676 | \\} |
| 7402 | 7677 | , &[_][]const u8{ |
| 7403 | 7678 | "tmp.zig:9:22: error: expected type 'u2', found 'Small'", |
| 7404 | 7679 | }); |
| 7405 | 7680 | |
| 7406 | | cases.add("explicitly casting non tag type to enum", |
| 7681 | ctx.objErrStage1("explicitly casting non tag type to enum", |
| 7407 | 7682 | \\const Small = enum(u2) { |
| 7408 | 7683 | \\ One, |
| 7409 | 7684 | \\ Two, |
| ... | ... | @@ -7414,42 +7689,38 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7414 | 7689 | \\export fn entry() void { |
| 7415 | 7690 | \\ var y = @as(u3, 3); |
| 7416 | 7691 | \\ var x = @intToEnum(Small, y); |
| 7692 | \\ _ = x; |
| 7417 | 7693 | \\} |
| 7418 | 7694 | , &[_][]const u8{ |
| 7419 | 7695 | "tmp.zig:10:31: error: expected type 'u2', found 'u3'", |
| 7420 | 7696 | }); |
| 7421 | 7697 | |
| 7422 | | cases.add("union fields with value assignments", |
| 7698 | ctx.objErrStage1("union fields with value assignments", |
| 7423 | 7699 | \\const MultipleChoice = union { |
| 7424 | 7700 | \\ A: i32 = 20, |
| 7425 | 7701 | \\}; |
| 7426 | 7702 | \\export fn entry() void { |
| 7427 | 7703 | \\ var x: MultipleChoice = undefined; |
| 7704 | \\ _ = x; |
| 7428 | 7705 | \\} |
| 7429 | 7706 | , &[_][]const u8{ |
| 7430 | | "tmp.zig:2:14: error: untagged union field assignment", |
| 7431 | | "tmp.zig:1:24: note: consider 'union(enum)' here", |
| 7707 | "tmp.zig:1:24: error: explicitly valued tagged union missing integer tag type", |
| 7708 | "tmp.zig:2:14: note: tag value specified here", |
| 7432 | 7709 | }); |
| 7433 | 7710 | |
| 7434 | | cases.add("enum with 0 fields", |
| 7711 | ctx.objErrStage1("enum with 0 fields", |
| 7435 | 7712 | \\const Foo = enum {}; |
| 7436 | | \\export fn entry() usize { |
| 7437 | | \\ return @sizeOf(Foo); |
| 7438 | | \\} |
| 7439 | 7713 | , &[_][]const u8{ |
| 7440 | | "tmp.zig:1:13: error: enums must have 1 or more fields", |
| 7714 | "tmp.zig:1:13: error: enum declarations must have at least one tag", |
| 7441 | 7715 | }); |
| 7442 | 7716 | |
| 7443 | | cases.add("union with 0 fields", |
| 7717 | ctx.objErrStage1("union with 0 fields", |
| 7444 | 7718 | \\const Foo = union {}; |
| 7445 | | \\export fn entry() usize { |
| 7446 | | \\ return @sizeOf(Foo); |
| 7447 | | \\} |
| 7448 | 7719 | , &[_][]const u8{ |
| 7449 | | "tmp.zig:1:13: error: unions must have 1 or more fields", |
| 7720 | "tmp.zig:1:13: error: union declarations must have at least one tag", |
| 7450 | 7721 | }); |
| 7451 | 7722 | |
| 7452 | | cases.add("enum value already taken", |
| 7723 | ctx.objErrStage1("enum value already taken", |
| 7453 | 7724 | \\const MultipleChoice = enum(u32) { |
| 7454 | 7725 | \\ A = 20, |
| 7455 | 7726 | \\ B = 40, |
| ... | ... | @@ -7459,13 +7730,14 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7459 | 7730 | \\}; |
| 7460 | 7731 | \\export fn entry() void { |
| 7461 | 7732 | \\ var x = MultipleChoice.C; |
| 7733 | \\ _ = x; |
| 7462 | 7734 | \\} |
| 7463 | 7735 | , &[_][]const u8{ |
| 7464 | 7736 | "tmp.zig:6:5: error: enum tag value 60 already taken", |
| 7465 | 7737 | "tmp.zig:4:5: note: other occurrence here", |
| 7466 | 7738 | }); |
| 7467 | 7739 | |
| 7468 | | cases.add("union with specified enum omits field", |
| 7740 | ctx.objErrStage1("union with specified enum omits field", |
| 7469 | 7741 | \\const Letter = enum { |
| 7470 | 7742 | \\ A, |
| 7471 | 7743 | \\ B, |
| ... | ... | @@ -7483,29 +7755,31 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7483 | 7755 | "tmp.zig:4:5: note: declared here", |
| 7484 | 7756 | }); |
| 7485 | 7757 | |
| 7486 | | cases.add("non-integer tag type to automatic union enum", |
| 7758 | ctx.objErrStage1("non-integer tag type to automatic union enum", |
| 7487 | 7759 | \\const Foo = union(enum(f32)) { |
| 7488 | 7760 | \\ A: i32, |
| 7489 | 7761 | \\}; |
| 7490 | 7762 | \\export fn entry() void { |
| 7491 | 7763 | \\ const x = @typeInfo(Foo).Union.tag_type.?; |
| 7764 | \\ _ = x; |
| 7492 | 7765 | \\} |
| 7493 | 7766 | , &[_][]const u8{ |
| 7494 | 7767 | "tmp.zig:1:24: error: expected integer tag type, found 'f32'", |
| 7495 | 7768 | }); |
| 7496 | 7769 | |
| 7497 | | cases.add("non-enum tag type passed to union", |
| 7770 | ctx.objErrStage1("non-enum tag type passed to union", |
| 7498 | 7771 | \\const Foo = union(u32) { |
| 7499 | 7772 | \\ A: i32, |
| 7500 | 7773 | \\}; |
| 7501 | 7774 | \\export fn entry() void { |
| 7502 | 7775 | \\ const x = @typeInfo(Foo).Union.tag_type.?; |
| 7776 | \\ _ = x; |
| 7503 | 7777 | \\} |
| 7504 | 7778 | , &[_][]const u8{ |
| 7505 | 7779 | "tmp.zig:1:19: error: expected enum tag type, found 'u32'", |
| 7506 | 7780 | }); |
| 7507 | 7781 | |
| 7508 | | cases.add("union auto-enum value already taken", |
| 7782 | ctx.objErrStage1("union auto-enum value already taken", |
| 7509 | 7783 | \\const MultipleChoice = union(enum(u32)) { |
| 7510 | 7784 | \\ A = 20, |
| 7511 | 7785 | \\ B = 40, |
| ... | ... | @@ -7515,13 +7789,14 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7515 | 7789 | \\}; |
| 7516 | 7790 | \\export fn entry() void { |
| 7517 | 7791 | \\ var x = MultipleChoice { .C = {} }; |
| 7792 | \\ _ = x; |
| 7518 | 7793 | \\} |
| 7519 | 7794 | , &[_][]const u8{ |
| 7520 | 7795 | "tmp.zig:6:9: error: enum tag value 60 already taken", |
| 7521 | 7796 | "tmp.zig:4:9: note: other occurrence here", |
| 7522 | 7797 | }); |
| 7523 | 7798 | |
| 7524 | | cases.add("union enum field does not match enum", |
| 7799 | ctx.objErrStage1("union enum field does not match enum", |
| 7525 | 7800 | \\const Letter = enum { |
| 7526 | 7801 | \\ A, |
| 7527 | 7802 | \\ B, |
| ... | ... | @@ -7535,49 +7810,49 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7535 | 7810 | \\}; |
| 7536 | 7811 | \\export fn entry() void { |
| 7537 | 7812 | \\ var a = Payload {.A = 1234}; |
| 7813 | \\ _ = a; |
| 7538 | 7814 | \\} |
| 7539 | 7815 | , &[_][]const u8{ |
| 7540 | 7816 | "tmp.zig:10:5: error: enum field not found: 'D'", |
| 7541 | 7817 | "tmp.zig:1:16: note: enum declared here", |
| 7542 | 7818 | }); |
| 7543 | 7819 | |
| 7544 | | cases.add("field type supplied in an enum", |
| 7820 | ctx.objErrStage1("field type supplied in an enum", |
| 7545 | 7821 | \\const Letter = enum { |
| 7546 | 7822 | \\ A: void, |
| 7547 | 7823 | \\ B, |
| 7548 | 7824 | \\ C, |
| 7549 | 7825 | \\}; |
| 7550 | | \\export fn entry() void { |
| 7551 | | \\ var b = Letter.B; |
| 7552 | | \\} |
| 7553 | 7826 | , &[_][]const u8{ |
| 7554 | | "tmp.zig:2:8: error: structs and unions, not enums, support field types", |
| 7555 | | "tmp.zig:1:16: note: consider 'union(enum)' here", |
| 7827 | "tmp.zig:2:8: error: enum fields do not have types", |
| 7828 | "tmp.zig:1:16: note: consider 'union(enum)' here to make it a tagged union", |
| 7556 | 7829 | }); |
| 7557 | 7830 | |
| 7558 | | cases.add("struct field missing type", |
| 7831 | ctx.objErrStage1("struct field missing type", |
| 7559 | 7832 | \\const Letter = struct { |
| 7560 | 7833 | \\ A, |
| 7561 | 7834 | \\}; |
| 7562 | 7835 | \\export fn entry() void { |
| 7563 | 7836 | \\ var a = Letter { .A = {} }; |
| 7837 | \\ _ = a; |
| 7564 | 7838 | \\} |
| 7565 | 7839 | , &[_][]const u8{ |
| 7566 | 7840 | "tmp.zig:2:5: error: struct field missing type", |
| 7567 | 7841 | }); |
| 7568 | 7842 | |
| 7569 | | cases.add("extern union field missing type", |
| 7843 | ctx.objErrStage1("extern union field missing type", |
| 7570 | 7844 | \\const Letter = extern union { |
| 7571 | 7845 | \\ A, |
| 7572 | 7846 | \\}; |
| 7573 | 7847 | \\export fn entry() void { |
| 7574 | 7848 | \\ var a = Letter { .A = {} }; |
| 7849 | \\ _ = a; |
| 7575 | 7850 | \\} |
| 7576 | 7851 | , &[_][]const u8{ |
| 7577 | 7852 | "tmp.zig:2:5: error: union field missing type", |
| 7578 | 7853 | }); |
| 7579 | 7854 | |
| 7580 | | cases.add("extern union given enum tag type", |
| 7855 | ctx.objErrStage1("extern union given enum tag type", |
| 7581 | 7856 | \\const Letter = enum { |
| 7582 | 7857 | \\ A, |
| 7583 | 7858 | \\ B, |
| ... | ... | @@ -7590,12 +7865,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7590 | 7865 | \\}; |
| 7591 | 7866 | \\export fn entry() void { |
| 7592 | 7867 | \\ var a = Payload { .A = 1234 }; |
| 7868 | \\ _ = a; |
| 7593 | 7869 | \\} |
| 7594 | 7870 | , &[_][]const u8{ |
| 7595 | 7871 | "tmp.zig:6:30: error: extern union does not support enum tag type", |
| 7596 | 7872 | }); |
| 7597 | 7873 | |
| 7598 | | cases.add("packed union given enum tag type", |
| 7874 | ctx.objErrStage1("packed union given enum tag type", |
| 7599 | 7875 | \\const Letter = enum { |
| 7600 | 7876 | \\ A, |
| 7601 | 7877 | \\ B, |
| ... | ... | @@ -7608,12 +7884,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7608 | 7884 | \\}; |
| 7609 | 7885 | \\export fn entry() void { |
| 7610 | 7886 | \\ var a = Payload { .A = 1234 }; |
| 7887 | \\ _ = a; |
| 7611 | 7888 | \\} |
| 7612 | 7889 | , &[_][]const u8{ |
| 7613 | 7890 | "tmp.zig:6:30: error: packed union does not support enum tag type", |
| 7614 | 7891 | }); |
| 7615 | 7892 | |
| 7616 | | cases.add("packed union with automatic layout field", |
| 7893 | ctx.objErrStage1("packed union with automatic layout field", |
| 7617 | 7894 | \\const Foo = struct { |
| 7618 | 7895 | \\ a: u32, |
| 7619 | 7896 | \\ b: f32, |
| ... | ... | @@ -7624,12 +7901,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7624 | 7901 | \\}; |
| 7625 | 7902 | \\export fn entry() void { |
| 7626 | 7903 | \\ var a = Payload { .B = true }; |
| 7904 | \\ _ = a; |
| 7627 | 7905 | \\} |
| 7628 | 7906 | , &[_][]const u8{ |
| 7629 | 7907 | "tmp.zig:6:5: error: non-packed, non-extern struct 'Foo' not allowed in packed union; no guaranteed in-memory representation", |
| 7630 | 7908 | }); |
| 7631 | 7909 | |
| 7632 | | cases.add("switch on union with no attached enum", |
| 7910 | ctx.objErrStage1("switch on union with no attached enum", |
| 7633 | 7911 | \\const Payload = union { |
| 7634 | 7912 | \\ A: i32, |
| 7635 | 7913 | \\ B: f64, |
| ... | ... | @@ -7650,20 +7928,21 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7650 | 7928 | "tmp.zig:1:17: note: consider 'union(enum)' here", |
| 7651 | 7929 | }); |
| 7652 | 7930 | |
| 7653 | | cases.add("enum in field count range but not matching tag", |
| 7931 | ctx.objErrStage1("enum in field count range but not matching tag", |
| 7654 | 7932 | \\const Foo = enum(u32) { |
| 7655 | 7933 | \\ A = 10, |
| 7656 | 7934 | \\ B = 11, |
| 7657 | 7935 | \\}; |
| 7658 | 7936 | \\export fn entry() void { |
| 7659 | 7937 | \\ var x = @intToEnum(Foo, 0); |
| 7938 | \\ _ = x; |
| 7660 | 7939 | \\} |
| 7661 | 7940 | , &[_][]const u8{ |
| 7662 | 7941 | "tmp.zig:6:13: error: enum 'Foo' has no tag matching integer value 0", |
| 7663 | 7942 | "tmp.zig:1:13: note: 'Foo' declared here", |
| 7664 | 7943 | }); |
| 7665 | 7944 | |
| 7666 | | cases.add("comptime cast enum to union but field has payload", |
| 7945 | ctx.objErrStage1("comptime cast enum to union but field has payload", |
| 7667 | 7946 | \\const Letter = enum { A, B, C }; |
| 7668 | 7947 | \\const Value = union(Letter) { |
| 7669 | 7948 | \\ A: i32, |
| ... | ... | @@ -7672,13 +7951,14 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7672 | 7951 | \\}; |
| 7673 | 7952 | \\export fn entry() void { |
| 7674 | 7953 | \\ var x: Value = Letter.A; |
| 7954 | \\ _ = x; |
| 7675 | 7955 | \\} |
| 7676 | 7956 | , &[_][]const u8{ |
| 7677 | 7957 | "tmp.zig:8:26: error: cast to union 'Value' must initialize 'i32' field 'A'", |
| 7678 | 7958 | "tmp.zig:3:5: note: field 'A' declared here", |
| 7679 | 7959 | }); |
| 7680 | 7960 | |
| 7681 | | cases.add("runtime cast to union which has non-void fields", |
| 7961 | ctx.objErrStage1("runtime cast to union which has non-void fields", |
| 7682 | 7962 | \\const Letter = enum { A, B, C }; |
| 7683 | 7963 | \\const Value = union(Letter) { |
| 7684 | 7964 | \\ A: i32, |
| ... | ... | @@ -7690,35 +7970,38 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7690 | 7970 | \\} |
| 7691 | 7971 | \\fn foo(l: Letter) void { |
| 7692 | 7972 | \\ var x: Value = l; |
| 7973 | \\ _ = x; |
| 7693 | 7974 | \\} |
| 7694 | 7975 | , &[_][]const u8{ |
| 7695 | 7976 | "tmp.zig:11:20: error: runtime cast to union 'Value' which has non-void fields", |
| 7696 | 7977 | "tmp.zig:3:5: note: field 'A' has type 'i32'", |
| 7697 | 7978 | }); |
| 7698 | 7979 | |
| 7699 | | cases.add("taking byte offset of void field in struct", |
| 7980 | ctx.objErrStage1("taking byte offset of void field in struct", |
| 7700 | 7981 | \\const Empty = struct { |
| 7701 | 7982 | \\ val: void, |
| 7702 | 7983 | \\}; |
| 7703 | 7984 | \\export fn foo() void { |
| 7704 | 7985 | \\ const fieldOffset = @offsetOf(Empty, "val",); |
| 7986 | \\ _ = fieldOffset; |
| 7705 | 7987 | \\} |
| 7706 | 7988 | , &[_][]const u8{ |
| 7707 | 7989 | "tmp.zig:5:42: error: zero-bit field 'val' in struct 'Empty' has no offset", |
| 7708 | 7990 | }); |
| 7709 | 7991 | |
| 7710 | | cases.add("taking bit offset of void field in struct", |
| 7992 | ctx.objErrStage1("taking bit offset of void field in struct", |
| 7711 | 7993 | \\const Empty = struct { |
| 7712 | 7994 | \\ val: void, |
| 7713 | 7995 | \\}; |
| 7714 | 7996 | \\export fn foo() void { |
| 7715 | 7997 | \\ const fieldOffset = @bitOffsetOf(Empty, "val",); |
| 7998 | \\ _ = fieldOffset; |
| 7716 | 7999 | \\} |
| 7717 | 8000 | , &[_][]const u8{ |
| 7718 | 8001 | "tmp.zig:5:45: error: zero-bit field 'val' in struct 'Empty' has no offset", |
| 7719 | 8002 | }); |
| 7720 | 8003 | |
| 7721 | | cases.add("invalid union field access in comptime", |
| 8004 | ctx.objErrStage1("invalid union field access in comptime", |
| 7722 | 8005 | \\const Foo = union { |
| 7723 | 8006 | \\ Bar: u8, |
| 7724 | 8007 | \\ Baz: void, |
| ... | ... | @@ -7726,12 +8009,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7726 | 8009 | \\comptime { |
| 7727 | 8010 | \\ var foo = Foo {.Baz = {}}; |
| 7728 | 8011 | \\ const bar_val = foo.Bar; |
| 8012 | \\ _ = bar_val; |
| 7729 | 8013 | \\} |
| 7730 | 8014 | , &[_][]const u8{ |
| 7731 | 8015 | "tmp.zig:7:24: error: accessing union field 'Bar' while field 'Baz' is set", |
| 7732 | 8016 | }); |
| 7733 | 8017 | |
| 7734 | | cases.add("unsupported modifier at start of asm output constraint", |
| 8018 | ctx.objErrStage1("unsupported modifier at start of asm output constraint", |
| 7735 | 8019 | \\export fn foo() void { |
| 7736 | 8020 | \\ var bar: u32 = 3; |
| 7737 | 8021 | \\ asm volatile ("" : [baz]"+r"(bar) : : ""); |
| ... | ... | @@ -7740,7 +8024,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7740 | 8024 | "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", |
| 7741 | 8025 | }); |
| 7742 | 8026 | |
| 7743 | | cases.add("comptime_int in asm input", |
| 8027 | ctx.objErrStage1("comptime_int in asm input", |
| 7744 | 8028 | \\export fn foo() void { |
| 7745 | 8029 | \\ asm volatile ("" : : [bar]"r"(3) : ""); |
| 7746 | 8030 | \\} |
| ... | ... | @@ -7748,7 +8032,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7748 | 8032 | "tmp.zig:2:35: error: expected sized integer or sized float, found comptime_int", |
| 7749 | 8033 | }); |
| 7750 | 8034 | |
| 7751 | | cases.add("comptime_float in asm input", |
| 8035 | ctx.objErrStage1("comptime_float in asm input", |
| 7752 | 8036 | \\export fn foo() void { |
| 7753 | 8037 | \\ asm volatile ("" : : [bar]"r"(3.17) : ""); |
| 7754 | 8038 | \\} |
| ... | ... | @@ -7756,7 +8040,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7756 | 8040 | "tmp.zig:2:35: error: expected sized integer or sized float, found comptime_float", |
| 7757 | 8041 | }); |
| 7758 | 8042 | |
| 7759 | | cases.add("runtime assignment to comptime struct type", |
| 8043 | ctx.objErrStage1("runtime assignment to comptime struct type", |
| 7760 | 8044 | \\const Foo = struct { |
| 7761 | 8045 | \\ Bar: u8, |
| 7762 | 8046 | \\ Baz: type, |
| ... | ... | @@ -7764,12 +8048,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7764 | 8048 | \\export fn f() void { |
| 7765 | 8049 | \\ var x: u8 = 0; |
| 7766 | 8050 | \\ const foo = Foo { .Bar = x, .Baz = u8 }; |
| 8051 | \\ _ = foo; |
| 7767 | 8052 | \\} |
| 7768 | 8053 | , &[_][]const u8{ |
| 7769 | 8054 | "tmp.zig:7:23: error: unable to evaluate constant expression", |
| 7770 | 8055 | }); |
| 7771 | 8056 | |
| 7772 | | cases.add("runtime assignment to comptime union type", |
| 8057 | ctx.objErrStage1("runtime assignment to comptime union type", |
| 7773 | 8058 | \\const Foo = union { |
| 7774 | 8059 | \\ Bar: u8, |
| 7775 | 8060 | \\ Baz: type, |
| ... | ... | @@ -7777,16 +8062,18 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7777 | 8062 | \\export fn f() void { |
| 7778 | 8063 | \\ var x: u8 = 0; |
| 7779 | 8064 | \\ const foo = Foo { .Bar = x }; |
| 8065 | \\ _ = foo; |
| 7780 | 8066 | \\} |
| 7781 | 8067 | , &[_][]const u8{ |
| 7782 | 8068 | "tmp.zig:7:23: error: unable to evaluate constant expression", |
| 7783 | 8069 | }); |
| 7784 | 8070 | |
| 7785 | | cases.addTest("@shuffle with selected index past first vector length", |
| 8071 | ctx.testErrStage1("@shuffle with selected index past first vector length", |
| 7786 | 8072 | \\export fn entry() void { |
| 7787 | 8073 | \\ const v: @import("std").meta.Vector(4, u32) = [4]u32{ 10, 11, 12, 13 }; |
| 7788 | 8074 | \\ const x: @import("std").meta.Vector(4, u32) = [4]u32{ 14, 15, 16, 17 }; |
| 7789 | 8075 | \\ var z = @shuffle(u32, v, x, [8]i32{ 0, 1, 2, 3, 7, 6, 5, 4 }); |
| 8076 | \\ _ = z; |
| 7790 | 8077 | \\} |
| 7791 | 8078 | , &[_][]const u8{ |
| 7792 | 8079 | "tmp.zig:4:39: error: mask index '4' has out-of-bounds selection", |
| ... | ... | @@ -7794,27 +8081,29 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7794 | 8081 | "tmp.zig:4:30: note: selections from the second vector are specified with negative numbers", |
| 7795 | 8082 | }); |
| 7796 | 8083 | |
| 7797 | | cases.addTest("nested vectors", |
| 8084 | ctx.testErrStage1("nested vectors", |
| 7798 | 8085 | \\export fn entry() void { |
| 7799 | 8086 | \\ const V1 = @import("std").meta.Vector(4, u8); |
| 7800 | 8087 | \\ const V2 = @Type(@import("std").builtin.TypeInfo{ .Vector = .{ .len = 4, .child = V1 } }); |
| 7801 | 8088 | \\ var v: V2 = undefined; |
| 8089 | \\ _ = v; |
| 7802 | 8090 | \\} |
| 7803 | 8091 | , &[_][]const u8{ |
| 7804 | 8092 | "tmp.zig:3:53: error: vector element type must be integer, float, bool, or pointer; '@Vector(4, u8)' is invalid", |
| 7805 | 8093 | "tmp.zig:3:16: note: referenced here", |
| 7806 | 8094 | }); |
| 7807 | 8095 | |
| 7808 | | cases.addTest("bad @splat type", |
| 8096 | ctx.testErrStage1("bad @splat type", |
| 7809 | 8097 | \\export fn entry() void { |
| 7810 | 8098 | \\ const c = 4; |
| 7811 | 8099 | \\ var v = @splat(4, c); |
| 8100 | \\ _ = v; |
| 7812 | 8101 | \\} |
| 7813 | 8102 | , &[_][]const u8{ |
| 7814 | 8103 | "tmp.zig:3:23: error: vector element type must be integer, float, bool, or pointer; 'comptime_int' is invalid", |
| 7815 | 8104 | }); |
| 7816 | 8105 | |
| 7817 | | cases.add("compileLog of tagged enum doesn't crash the compiler", |
| 8106 | ctx.objErrStage1("compileLog of tagged enum doesn't crash the compiler", |
| 7818 | 8107 | \\const Bar = union(enum(u32)) { |
| 7819 | 8108 | \\ X: i32 = 1 |
| 7820 | 8109 | \\}; |
| ... | ... | @@ -7830,28 +8119,30 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7830 | 8119 | "tmp.zig:6:5: error: found compile log statement", |
| 7831 | 8120 | }); |
| 7832 | 8121 | |
| 7833 | | cases.add("attempted implicit cast from *const T to *[1]T", |
| 8122 | ctx.objErrStage1("attempted implicit cast from *const T to *[1]T", |
| 7834 | 8123 | \\export fn entry(byte: u8) void { |
| 7835 | 8124 | \\ const w: i32 = 1234; |
| 7836 | 8125 | \\ var x: *const i32 = &w; |
| 7837 | 8126 | \\ var y: *[1]i32 = x; |
| 7838 | 8127 | \\ y[0] += 1; |
| 8128 | \\ _ = byte; |
| 7839 | 8129 | \\} |
| 7840 | 8130 | , &[_][]const u8{ |
| 7841 | 8131 | "tmp.zig:4:22: error: expected type '*[1]i32', found '*const i32'", |
| 7842 | 8132 | "tmp.zig:4:22: note: cast discards const qualifier", |
| 7843 | 8133 | }); |
| 7844 | 8134 | |
| 7845 | | cases.add("attempted implicit cast from *const T to []T", |
| 8135 | ctx.objErrStage1("attempted implicit cast from *const T to []T", |
| 7846 | 8136 | \\export fn entry() void { |
| 7847 | 8137 | \\ const u: u32 = 42; |
| 7848 | 8138 | \\ const x: []u32 = &u; |
| 8139 | \\ _ = x; |
| 7849 | 8140 | \\} |
| 7850 | 8141 | , &[_][]const u8{ |
| 7851 | 8142 | "tmp.zig:3:23: error: expected type '[]u32', found '*const u32'", |
| 7852 | 8143 | }); |
| 7853 | 8144 | |
| 7854 | | cases.add("for loop body expression ignored", |
| 8145 | ctx.objErrStage1("for loop body expression ignored", |
| 7855 | 8146 | \\fn returns() usize { |
| 7856 | 8147 | \\ return 2; |
| 7857 | 8148 | \\} |
| ... | ... | @@ -7861,21 +8152,23 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7861 | 8152 | \\export fn f2() void { |
| 7862 | 8153 | \\ var x: anyerror!i32 = error.Bad; |
| 7863 | 8154 | \\ for ("hello") |_| returns() else unreachable; |
| 8155 | \\ _ = x; |
| 7864 | 8156 | \\} |
| 7865 | 8157 | , &[_][]const u8{ |
| 7866 | 8158 | "tmp.zig:5:30: error: expression value is ignored", |
| 7867 | 8159 | "tmp.zig:9:30: error: expression value is ignored", |
| 7868 | 8160 | }); |
| 7869 | 8161 | |
| 7870 | | cases.add("aligned variable of zero-bit type", |
| 8162 | ctx.objErrStage1("aligned variable of zero-bit type", |
| 7871 | 8163 | \\export fn f() void { |
| 7872 | 8164 | \\ var s: struct {} align(4) = undefined; |
| 8165 | \\ _ = s; |
| 7873 | 8166 | \\} |
| 7874 | 8167 | , &[_][]const u8{ |
| 7875 | 8168 | "tmp.zig:2:5: error: variable 's' of zero-bit type 'struct:2:12' has no in-memory representation, it cannot be aligned", |
| 7876 | 8169 | }); |
| 7877 | 8170 | |
| 7878 | | cases.add("function returning opaque type", |
| 8171 | ctx.objErrStage1("function returning opaque type", |
| 7879 | 8172 | \\const FooType = opaque {}; |
| 7880 | 8173 | \\export fn bar() !FooType { |
| 7881 | 8174 | \\ return error.InvalidValue; |
| ... | ... | @@ -7893,7 +8186,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7893 | 8186 | "tmp.zig:8:18: error: Undefined return type '(undefined)' not allowed", |
| 7894 | 8187 | }); |
| 7895 | 8188 | |
| 7896 | | cases.add("generic function returning opaque type", |
| 8189 | ctx.objErrStage1("generic function returning opaque type", |
| 7897 | 8190 | \\const FooType = opaque {}; |
| 7898 | 8191 | \\fn generic(comptime T: type) !T { |
| 7899 | 8192 | \\ return undefined; |
| ... | ... | @@ -7917,81 +8210,89 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7917 | 8210 | "tmp.zig:2:1: note: function declared here", |
| 7918 | 8211 | }); |
| 7919 | 8212 | |
| 7920 | | cases.add("function parameter is opaque", |
| 8213 | ctx.objErrStage1("function parameter is opaque", |
| 7921 | 8214 | \\const FooType = opaque {}; |
| 7922 | 8215 | \\export fn entry1() void { |
| 7923 | 8216 | \\ const someFuncPtr: fn (FooType) void = undefined; |
| 8217 | \\ _ = someFuncPtr; |
| 7924 | 8218 | \\} |
| 7925 | 8219 | \\ |
| 7926 | 8220 | \\export fn entry2() void { |
| 7927 | 8221 | \\ const someFuncPtr: fn (@TypeOf(null)) void = undefined; |
| 8222 | \\ _ = someFuncPtr; |
| 7928 | 8223 | \\} |
| 7929 | 8224 | \\ |
| 7930 | | \\fn foo(p: FooType) void {} |
| 8225 | \\fn foo(p: FooType) void {_ = p;} |
| 7931 | 8226 | \\export fn entry3() void { |
| 7932 | 8227 | \\ _ = foo; |
| 7933 | 8228 | \\} |
| 7934 | 8229 | \\ |
| 7935 | | \\fn bar(p: @TypeOf(null)) void {} |
| 8230 | \\fn bar(p: @TypeOf(null)) void {_ = p;} |
| 7936 | 8231 | \\export fn entry4() void { |
| 7937 | 8232 | \\ _ = bar; |
| 7938 | 8233 | \\} |
| 7939 | 8234 | , &[_][]const u8{ |
| 7940 | 8235 | "tmp.zig:3:28: error: parameter of opaque type 'FooType' not allowed", |
| 7941 | | "tmp.zig:7:28: error: parameter of type '(null)' not allowed", |
| 7942 | | "tmp.zig:10:11: error: parameter of opaque type 'FooType' not allowed", |
| 7943 | | "tmp.zig:15:11: error: parameter of type '(null)' not allowed", |
| 8236 | "tmp.zig:8:28: error: parameter of type '(null)' not allowed", |
| 8237 | "tmp.zig:12:11: error: parameter of opaque type 'FooType' not allowed", |
| 8238 | "tmp.zig:17:11: error: parameter of type '(null)' not allowed", |
| 7944 | 8239 | }); |
| 7945 | 8240 | |
| 7946 | | cases.add( // fixed bug #2032 |
| 8241 | ctx.objErrStage1( // fixed bug #2032 |
| 7947 | 8242 | "compile diagnostic string for top level decl type", |
| 7948 | 8243 | \\export fn entry() void { |
| 7949 | 8244 | \\ var foo: u32 = @This(){}; |
| 8245 | \\ _ = foo; |
| 7950 | 8246 | \\} |
| 7951 | 8247 | , &[_][]const u8{ |
| 7952 | 8248 | "tmp.zig:2:27: error: type 'u32' does not support array initialization", |
| 7953 | 8249 | }); |
| 7954 | 8250 | |
| 7955 | | cases.add("issue #2687: coerce from undefined array pointer to slice", |
| 8251 | ctx.objErrStage1("issue #2687: coerce from undefined array pointer to slice", |
| 7956 | 8252 | \\export fn foo1() void { |
| 7957 | 8253 | \\ const a: *[1]u8 = undefined; |
| 7958 | 8254 | \\ var b: []u8 = a; |
| 8255 | \\ _ = b; |
| 7959 | 8256 | \\} |
| 7960 | 8257 | \\export fn foo2() void { |
| 7961 | 8258 | \\ comptime { |
| 7962 | 8259 | \\ var a: *[1]u8 = undefined; |
| 7963 | 8260 | \\ var b: []u8 = a; |
| 8261 | \\ _ = b; |
| 7964 | 8262 | \\ } |
| 7965 | 8263 | \\} |
| 7966 | 8264 | \\export fn foo3() void { |
| 7967 | 8265 | \\ comptime { |
| 7968 | 8266 | \\ const a: *[1]u8 = undefined; |
| 7969 | 8267 | \\ var b: []u8 = a; |
| 8268 | \\ _ = b; |
| 7970 | 8269 | \\ } |
| 7971 | 8270 | \\} |
| 7972 | 8271 | , &[_][]const u8{ |
| 7973 | 8272 | "tmp.zig:3:19: error: use of undefined value here causes undefined behavior", |
| 7974 | | "tmp.zig:8:23: error: use of undefined value here causes undefined behavior", |
| 7975 | | "tmp.zig:14:23: error: use of undefined value here causes undefined behavior", |
| 8273 | "tmp.zig:9:23: error: use of undefined value here causes undefined behavior", |
| 8274 | "tmp.zig:16:23: error: use of undefined value here causes undefined behavior", |
| 7976 | 8275 | }); |
| 7977 | 8276 | |
| 7978 | | cases.add("issue #3818: bitcast from parray/slice to u16", |
| 8277 | ctx.objErrStage1("issue #3818: bitcast from parray/slice to u16", |
| 7979 | 8278 | \\export fn foo1() void { |
| 7980 | 8279 | \\ var bytes = [_]u8{1, 2}; |
| 7981 | 8280 | \\ const word: u16 = @bitCast(u16, bytes[0..]); |
| 8281 | \\ _ = word; |
| 7982 | 8282 | \\} |
| 7983 | 8283 | \\export fn foo2() void { |
| 7984 | 8284 | \\ var bytes: []const u8 = &[_]u8{1, 2}; |
| 7985 | 8285 | \\ const word: u16 = @bitCast(u16, bytes); |
| 8286 | \\ _ = word; |
| 7986 | 8287 | \\} |
| 7987 | 8288 | , &[_][]const u8{ |
| 7988 | 8289 | "tmp.zig:3:42: error: unable to @bitCast from pointer type '*[2]u8'", |
| 7989 | | "tmp.zig:7:32: error: destination type 'u16' has size 2 but source type '[]const u8' has size 16", |
| 7990 | | "tmp.zig:7:37: note: referenced here", |
| 8290 | "tmp.zig:8:32: error: destination type 'u16' has size 2 but source type '[]const u8' has size 16", |
| 8291 | "tmp.zig:8:37: note: referenced here", |
| 7991 | 8292 | }); |
| 7992 | 8293 | |
| 7993 | 8294 | // issue #7810 |
| 7994 | | cases.add("comptime slice-len increment beyond bounds", |
| 8295 | ctx.objErrStage1("comptime slice-len increment beyond bounds", |
| 7995 | 8296 | \\export fn foo_slice_len_increment_beyond_bounds() void { |
| 7996 | 8297 | \\ comptime { |
| 7997 | 8298 | \\ var buf_storage: [8]u8 = undefined; |
| ... | ... | @@ -8004,11 +8305,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 8004 | 8305 | ":6:12: error: out of bounds slice", |
| 8005 | 8306 | }); |
| 8006 | 8307 | |
| 8007 | | cases.add("comptime slice-sentinel is out of bounds (unterminated)", |
| 8308 | ctx.objErrStage1("comptime slice-sentinel is out of bounds (unterminated)", |
| 8008 | 8309 | \\export fn foo_array() void { |
| 8009 | 8310 | \\ comptime { |
| 8010 | 8311 | \\ var target = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; |
| 8011 | 8312 | \\ const slice = target[0..14 :0]; |
| 8313 | \\ _ = slice; |
| 8012 | 8314 | \\ } |
| 8013 | 8315 | \\} |
| 8014 | 8316 | \\export fn foo_ptr_array() void { |
| ... | ... | @@ -8016,6 +8318,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 8016 | 8318 | \\ var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; |
| 8017 | 8319 | \\ var target = &buf; |
| 8018 | 8320 | \\ const slice = target[0..14 :0]; |
| 8321 | \\ _ = slice; |
| 8019 | 8322 | \\ } |
| 8020 | 8323 | \\} |
| 8021 | 8324 | \\export fn foo_vector_ConstPtrSpecialBaseArray() void { |
| ... | ... | @@ -8023,6 +8326,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 8023 | 8326 | \\ var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; |
| 8024 | 8327 | \\ var target: [*]u8 = &buf; |
| 8025 | 8328 | \\ const slice = target[0..14 :0]; |
| 8329 | \\ _ = slice; |
| 8026 | 8330 | \\ } |
| 8027 | 8331 | \\} |
| 8028 | 8332 | \\export fn foo_vector_ConstPtrSpecialRef() void { |
| ... | ... | @@ -8030,6 +8334,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 8030 | 8334 | \\ var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; |
| 8031 | 8335 | \\ var target: [*]u8 = @ptrCast([*]u8, &buf); |
| 8032 | 8336 | \\ const slice = target[0..14 :0]; |
| 8337 | \\ _ = slice; |
| 8033 | 8338 | \\ } |
| 8034 | 8339 | \\} |
| 8035 | 8340 | \\export fn foo_cvector_ConstPtrSpecialBaseArray() void { |
| ... | ... | @@ -8037,6 +8342,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 8037 | 8342 | \\ var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; |
| 8038 | 8343 | \\ var target: [*c]u8 = &buf; |
| 8039 | 8344 | \\ const slice = target[0..14 :0]; |
| 8345 | \\ _ = slice; |
| 8040 | 8346 | \\ } |
| 8041 | 8347 | \\} |
| 8042 | 8348 | \\export fn foo_cvector_ConstPtrSpecialRef() void { |
| ... | ... | @@ -8044,6 +8350,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 8044 | 8350 | \\ var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; |
| 8045 | 8351 | \\ var target: [*c]u8 = @ptrCast([*c]u8, &buf); |
| 8046 | 8352 | \\ const slice = target[0..14 :0]; |
| 8353 | \\ _ = slice; |
| 8047 | 8354 | \\ } |
| 8048 | 8355 | \\} |
| 8049 | 8356 | \\export fn foo_slice() void { |
| ... | ... | @@ -8051,23 +8358,25 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 8051 | 8358 | \\ var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; |
| 8052 | 8359 | \\ var target: []u8 = &buf; |
| 8053 | 8360 | \\ const slice = target[0..14 :0]; |
| 8361 | \\ _ = slice; |
| 8054 | 8362 | \\ } |
| 8055 | 8363 | \\} |
| 8056 | 8364 | , &[_][]const u8{ |
| 8057 | 8365 | ":4:29: error: slice-sentinel is out of bounds", |
| 8058 | | ":11:29: error: slice-sentinel is out of bounds", |
| 8059 | | ":18:29: error: slice-sentinel is out of bounds", |
| 8060 | | ":25:29: error: slice-sentinel is out of bounds", |
| 8061 | | ":32:29: error: slice-sentinel is out of bounds", |
| 8062 | | ":39:29: error: slice-sentinel is out of bounds", |
| 8063 | | ":46:29: error: slice-sentinel is out of bounds", |
| 8366 | ":12:29: error: slice-sentinel is out of bounds", |
| 8367 | ":20:29: error: slice-sentinel is out of bounds", |
| 8368 | ":28:29: error: slice-sentinel is out of bounds", |
| 8369 | ":36:29: error: slice-sentinel is out of bounds", |
| 8370 | ":44:29: error: slice-sentinel is out of bounds", |
| 8371 | ":52:29: error: slice-sentinel is out of bounds", |
| 8064 | 8372 | }); |
| 8065 | 8373 | |
| 8066 | | cases.add("comptime slice-sentinel is out of bounds (terminated)", |
| 8374 | ctx.objErrStage1("comptime slice-sentinel is out of bounds (terminated)", |
| 8067 | 8375 | \\export fn foo_array() void { |
| 8068 | 8376 | \\ comptime { |
| 8069 | 8377 | \\ var target = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; |
| 8070 | 8378 | \\ const slice = target[0..15 :1]; |
| 8379 | \\ _ = slice; |
| 8071 | 8380 | \\ } |
| 8072 | 8381 | \\} |
| 8073 | 8382 | \\export fn foo_ptr_array() void { |
| ... | ... | @@ -8075,6 +8384,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 8075 | 8384 | \\ var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; |
| 8076 | 8385 | \\ var target = &buf; |
| 8077 | 8386 | \\ const slice = target[0..15 :0]; |
| 8387 | \\ _ = slice; |
| 8078 | 8388 | \\ } |
| 8079 | 8389 | \\} |
| 8080 | 8390 | \\export fn foo_vector_ConstPtrSpecialBaseArray() void { |
| ... | ... | @@ -8082,6 +8392,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 8082 | 8392 | \\ var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; |
| 8083 | 8393 | \\ var target: [*]u8 = &buf; |
| 8084 | 8394 | \\ const slice = target[0..15 :0]; |
| 8395 | \\ _ = slice; |
| 8085 | 8396 | \\ } |
| 8086 | 8397 | \\} |
| 8087 | 8398 | \\export fn foo_vector_ConstPtrSpecialRef() void { |
| ... | ... | @@ -8089,6 +8400,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 8089 | 8400 | \\ var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; |
| 8090 | 8401 | \\ var target: [*]u8 = @ptrCast([*]u8, &buf); |
| 8091 | 8402 | \\ const slice = target[0..15 :0]; |
| 8403 | \\ _ = slice; |
| 8092 | 8404 | \\ } |
| 8093 | 8405 | \\} |
| 8094 | 8406 | \\export fn foo_cvector_ConstPtrSpecialBaseArray() void { |
| ... | ... | @@ -8096,6 +8408,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 8096 | 8408 | \\ var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; |
| 8097 | 8409 | \\ var target: [*c]u8 = &buf; |
| 8098 | 8410 | \\ const slice = target[0..15 :0]; |
| 8411 | \\ _ = slice; |
| 8099 | 8412 | \\ } |
| 8100 | 8413 | \\} |
| 8101 | 8414 | \\export fn foo_cvector_ConstPtrSpecialRef() void { |
| ... | ... | @@ -8103,6 +8416,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 8103 | 8416 | \\ var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; |
| 8104 | 8417 | \\ var target: [*c]u8 = @ptrCast([*c]u8, &buf); |
| 8105 | 8418 | \\ const slice = target[0..15 :0]; |
| 8419 | \\ _ = slice; |
| 8106 | 8420 | \\ } |
| 8107 | 8421 | \\} |
| 8108 | 8422 | \\export fn foo_slice() void { |
| ... | ... | @@ -8110,23 +8424,25 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 8110 | 8424 | \\ var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; |
| 8111 | 8425 | \\ var target: []u8 = &buf; |
| 8112 | 8426 | \\ const slice = target[0..15 :0]; |
| 8427 | \\ _ = slice; |
| 8113 | 8428 | \\ } |
| 8114 | 8429 | \\} |
| 8115 | 8430 | , &[_][]const u8{ |
| 8116 | 8431 | ":4:29: error: out of bounds slice", |
| 8117 | | ":11:29: error: out of bounds slice", |
| 8118 | | ":18:29: error: out of bounds slice", |
| 8119 | | ":25:29: error: out of bounds slice", |
| 8120 | | ":32:29: error: out of bounds slice", |
| 8121 | | ":39:29: error: out of bounds slice", |
| 8122 | | ":46:29: error: out of bounds slice", |
| 8432 | ":12:29: error: out of bounds slice", |
| 8433 | ":20:29: error: out of bounds slice", |
| 8434 | ":28:29: error: out of bounds slice", |
| 8435 | ":36:29: error: out of bounds slice", |
| 8436 | ":44:29: error: out of bounds slice", |
| 8437 | ":52:29: error: out of bounds slice", |
| 8123 | 8438 | }); |
| 8124 | 8439 | |
| 8125 | | cases.add("comptime slice-sentinel does not match memory at target index (unterminated)", |
| 8440 | ctx.objErrStage1("comptime slice-sentinel does not match memory at target index (unterminated)", |
| 8126 | 8441 | \\export fn foo_array() void { |
| 8127 | 8442 | \\ comptime { |
| 8128 | 8443 | \\ var target = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; |
| 8129 | 8444 | \\ const slice = target[0..3 :0]; |
| 8445 | \\ _ = slice; |
| 8130 | 8446 | \\ } |
| 8131 | 8447 | \\} |
| 8132 | 8448 | \\export fn foo_ptr_array() void { |
| ... | ... | @@ -8134,6 +8450,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 8134 | 8450 | \\ var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; |
| 8135 | 8451 | \\ var target = &buf; |
| 8136 | 8452 | \\ const slice = target[0..3 :0]; |
| 8453 | \\ _ = slice; |
| 8137 | 8454 | \\ } |
| 8138 | 8455 | \\} |
| 8139 | 8456 | \\export fn foo_vector_ConstPtrSpecialBaseArray() void { |
| ... | ... | @@ -8141,6 +8458,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 8141 | 8458 | \\ var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; |
| 8142 | 8459 | \\ var target: [*]u8 = &buf; |
| 8143 | 8460 | \\ const slice = target[0..3 :0]; |
| 8461 | \\ _ = slice; |
| 8144 | 8462 | \\ } |
| 8145 | 8463 | \\} |
| 8146 | 8464 | \\export fn foo_vector_ConstPtrSpecialRef() void { |
| ... | ... | @@ -8148,6 +8466,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 8148 | 8466 | \\ var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; |
| 8149 | 8467 | \\ var target: [*]u8 = @ptrCast([*]u8, &buf); |
| 8150 | 8468 | \\ const slice = target[0..3 :0]; |
| 8469 | \\ _ = slice; |
| 8151 | 8470 | \\ } |
| 8152 | 8471 | \\} |
| 8153 | 8472 | \\export fn foo_cvector_ConstPtrSpecialBaseArray() void { |
| ... | ... | @@ -8155,6 +8474,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 8155 | 8474 | \\ var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; |
| 8156 | 8475 | \\ var target: [*c]u8 = &buf; |
| 8157 | 8476 | \\ const slice = target[0..3 :0]; |
| 8477 | \\ _ = slice; |
| 8158 | 8478 | \\ } |
| 8159 | 8479 | \\} |
| 8160 | 8480 | \\export fn foo_cvector_ConstPtrSpecialRef() void { |
| ... | ... | @@ -8162,6 +8482,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 8162 | 8482 | \\ var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; |
| 8163 | 8483 | \\ var target: [*c]u8 = @ptrCast([*c]u8, &buf); |
| 8164 | 8484 | \\ const slice = target[0..3 :0]; |
| 8485 | \\ _ = slice; |
| 8165 | 8486 | \\ } |
| 8166 | 8487 | \\} |
| 8167 | 8488 | \\export fn foo_slice() void { |
| ... | ... | @@ -8169,23 +8490,25 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 8169 | 8490 | \\ var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; |
| 8170 | 8491 | \\ var target: []u8 = &buf; |
| 8171 | 8492 | \\ const slice = target[0..3 :0]; |
| 8493 | \\ _ = slice; |
| 8172 | 8494 | \\ } |
| 8173 | 8495 | \\} |
| 8174 | 8496 | , &[_][]const u8{ |
| 8175 | 8497 | ":4:29: error: slice-sentinel does not match memory at target index", |
| 8176 | | ":11:29: error: slice-sentinel does not match memory at target index", |
| 8177 | | ":18:29: error: slice-sentinel does not match memory at target index", |
| 8178 | | ":25:29: error: slice-sentinel does not match memory at target index", |
| 8179 | | ":32:29: error: slice-sentinel does not match memory at target index", |
| 8180 | | ":39:29: error: slice-sentinel does not match memory at target index", |
| 8181 | | ":46:29: error: slice-sentinel does not match memory at target index", |
| 8498 | ":12:29: error: slice-sentinel does not match memory at target index", |
| 8499 | ":20:29: error: slice-sentinel does not match memory at target index", |
| 8500 | ":28:29: error: slice-sentinel does not match memory at target index", |
| 8501 | ":36:29: error: slice-sentinel does not match memory at target index", |
| 8502 | ":44:29: error: slice-sentinel does not match memory at target index", |
| 8503 | ":52:29: error: slice-sentinel does not match memory at target index", |
| 8182 | 8504 | }); |
| 8183 | 8505 | |
| 8184 | | cases.add("comptime slice-sentinel does not match memory at target index (terminated)", |
| 8506 | ctx.objErrStage1("comptime slice-sentinel does not match memory at target index (terminated)", |
| 8185 | 8507 | \\export fn foo_array() void { |
| 8186 | 8508 | \\ comptime { |
| 8187 | 8509 | \\ var target = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; |
| 8188 | 8510 | \\ const slice = target[0..3 :0]; |
| 8511 | \\ _ = slice; |
| 8189 | 8512 | \\ } |
| 8190 | 8513 | \\} |
| 8191 | 8514 | \\export fn foo_ptr_array() void { |
| ... | ... | @@ -8193,6 +8516,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 8193 | 8516 | \\ var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; |
| 8194 | 8517 | \\ var target = &buf; |
| 8195 | 8518 | \\ const slice = target[0..3 :0]; |
| 8519 | \\ _ = slice; |
| 8196 | 8520 | \\ } |
| 8197 | 8521 | \\} |
| 8198 | 8522 | \\export fn foo_vector_ConstPtrSpecialBaseArray() void { |
| ... | ... | @@ -8200,6 +8524,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 8200 | 8524 | \\ var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; |
| 8201 | 8525 | \\ var target: [*]u8 = &buf; |
| 8202 | 8526 | \\ const slice = target[0..3 :0]; |
| 8527 | \\ _ = slice; |
| 8203 | 8528 | \\ } |
| 8204 | 8529 | \\} |
| 8205 | 8530 | \\export fn foo_vector_ConstPtrSpecialRef() void { |
| ... | ... | @@ -8207,6 +8532,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 8207 | 8532 | \\ var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; |
| 8208 | 8533 | \\ var target: [*]u8 = @ptrCast([*]u8, &buf); |
| 8209 | 8534 | \\ const slice = target[0..3 :0]; |
| 8535 | \\ _ = slice; |
| 8210 | 8536 | \\ } |
| 8211 | 8537 | \\} |
| 8212 | 8538 | \\export fn foo_cvector_ConstPtrSpecialBaseArray() void { |
| ... | ... | @@ -8214,6 +8540,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 8214 | 8540 | \\ var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; |
| 8215 | 8541 | \\ var target: [*c]u8 = &buf; |
| 8216 | 8542 | \\ const slice = target[0..3 :0]; |
| 8543 | \\ _ = slice; |
| 8217 | 8544 | \\ } |
| 8218 | 8545 | \\} |
| 8219 | 8546 | \\export fn foo_cvector_ConstPtrSpecialRef() void { |
| ... | ... | @@ -8221,6 +8548,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 8221 | 8548 | \\ var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; |
| 8222 | 8549 | \\ var target: [*c]u8 = @ptrCast([*c]u8, &buf); |
| 8223 | 8550 | \\ const slice = target[0..3 :0]; |
| 8551 | \\ _ = slice; |
| 8224 | 8552 | \\ } |
| 8225 | 8553 | \\} |
| 8226 | 8554 | \\export fn foo_slice() void { |
| ... | ... | @@ -8228,23 +8556,25 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 8228 | 8556 | \\ var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; |
| 8229 | 8557 | \\ var target: []u8 = &buf; |
| 8230 | 8558 | \\ const slice = target[0..3 :0]; |
| 8559 | \\ _ = slice; |
| 8231 | 8560 | \\ } |
| 8232 | 8561 | \\} |
| 8233 | 8562 | , &[_][]const u8{ |
| 8234 | 8563 | ":4:29: error: slice-sentinel does not match memory at target index", |
| 8235 | | ":11:29: error: slice-sentinel does not match memory at target index", |
| 8236 | | ":18:29: error: slice-sentinel does not match memory at target index", |
| 8237 | | ":25:29: error: slice-sentinel does not match memory at target index", |
| 8238 | | ":32:29: error: slice-sentinel does not match memory at target index", |
| 8239 | | ":39:29: error: slice-sentinel does not match memory at target index", |
| 8240 | | ":46:29: error: slice-sentinel does not match memory at target index", |
| 8564 | ":12:29: error: slice-sentinel does not match memory at target index", |
| 8565 | ":20:29: error: slice-sentinel does not match memory at target index", |
| 8566 | ":28:29: error: slice-sentinel does not match memory at target index", |
| 8567 | ":36:29: error: slice-sentinel does not match memory at target index", |
| 8568 | ":44:29: error: slice-sentinel does not match memory at target index", |
| 8569 | ":52:29: error: slice-sentinel does not match memory at target index", |
| 8241 | 8570 | }); |
| 8242 | 8571 | |
| 8243 | | cases.add("comptime slice-sentinel does not match target-sentinel", |
| 8572 | ctx.objErrStage1("comptime slice-sentinel does not match target-sentinel", |
| 8244 | 8573 | \\export fn foo_array() void { |
| 8245 | 8574 | \\ comptime { |
| 8246 | 8575 | \\ var target = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; |
| 8247 | 8576 | \\ const slice = target[0..14 :255]; |
| 8577 | \\ _ = slice; |
| 8248 | 8578 | \\ } |
| 8249 | 8579 | \\} |
| 8250 | 8580 | \\export fn foo_ptr_array() void { |
| ... | ... | @@ -8252,6 +8582,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 8252 | 8582 | \\ var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; |
| 8253 | 8583 | \\ var target = &buf; |
| 8254 | 8584 | \\ const slice = target[0..14 :255]; |
| 8585 | \\ _ = slice; |
| 8255 | 8586 | \\ } |
| 8256 | 8587 | \\} |
| 8257 | 8588 | \\export fn foo_vector_ConstPtrSpecialBaseArray() void { |
| ... | ... | @@ -8259,6 +8590,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 8259 | 8590 | \\ var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; |
| 8260 | 8591 | \\ var target: [*]u8 = &buf; |
| 8261 | 8592 | \\ const slice = target[0..14 :255]; |
| 8593 | \\ _ = slice; |
| 8262 | 8594 | \\ } |
| 8263 | 8595 | \\} |
| 8264 | 8596 | \\export fn foo_vector_ConstPtrSpecialRef() void { |
| ... | ... | @@ -8266,6 +8598,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 8266 | 8598 | \\ var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; |
| 8267 | 8599 | \\ var target: [*]u8 = @ptrCast([*]u8, &buf); |
| 8268 | 8600 | \\ const slice = target[0..14 :255]; |
| 8601 | \\ _ = slice; |
| 8269 | 8602 | \\ } |
| 8270 | 8603 | \\} |
| 8271 | 8604 | \\export fn foo_cvector_ConstPtrSpecialBaseArray() void { |
| ... | ... | @@ -8273,6 +8606,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 8273 | 8606 | \\ var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; |
| 8274 | 8607 | \\ var target: [*c]u8 = &buf; |
| 8275 | 8608 | \\ const slice = target[0..14 :255]; |
| 8609 | \\ _ = slice; |
| 8276 | 8610 | \\ } |
| 8277 | 8611 | \\} |
| 8278 | 8612 | \\export fn foo_cvector_ConstPtrSpecialRef() void { |
| ... | ... | @@ -8280,6 +8614,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 8280 | 8614 | \\ var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; |
| 8281 | 8615 | \\ var target: [*c]u8 = @ptrCast([*c]u8, &buf); |
| 8282 | 8616 | \\ const slice = target[0..14 :255]; |
| 8617 | \\ _ = slice; |
| 8283 | 8618 | \\ } |
| 8284 | 8619 | \\} |
| 8285 | 8620 | \\export fn foo_slice() void { |
| ... | ... | @@ -8287,19 +8622,20 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 8287 | 8622 | \\ var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; |
| 8288 | 8623 | \\ var target: []u8 = &buf; |
| 8289 | 8624 | \\ const slice = target[0..14 :255]; |
| 8625 | \\ _ = slice; |
| 8290 | 8626 | \\ } |
| 8291 | 8627 | \\} |
| 8292 | 8628 | , &[_][]const u8{ |
| 8293 | 8629 | ":4:29: error: slice-sentinel does not match target-sentinel", |
| 8294 | | ":11:29: error: slice-sentinel does not match target-sentinel", |
| 8295 | | ":18:29: error: slice-sentinel does not match target-sentinel", |
| 8296 | | ":25:29: error: slice-sentinel does not match target-sentinel", |
| 8297 | | ":32:29: error: slice-sentinel does not match target-sentinel", |
| 8298 | | ":39:29: error: slice-sentinel does not match target-sentinel", |
| 8299 | | ":46:29: error: slice-sentinel does not match target-sentinel", |
| 8630 | ":12:29: error: slice-sentinel does not match target-sentinel", |
| 8631 | ":20:29: error: slice-sentinel does not match target-sentinel", |
| 8632 | ":28:29: error: slice-sentinel does not match target-sentinel", |
| 8633 | ":36:29: error: slice-sentinel does not match target-sentinel", |
| 8634 | ":44:29: error: slice-sentinel does not match target-sentinel", |
| 8635 | ":52:29: error: slice-sentinel does not match target-sentinel", |
| 8300 | 8636 | }); |
| 8301 | 8637 | |
| 8302 | | cases.add("issue #4207: coerce from non-terminated-slice to terminated-pointer", |
| 8638 | ctx.objErrStage1("issue #4207: coerce from non-terminated-slice to terminated-pointer", |
| 8303 | 8639 | \\export fn foo() [*:0]const u8 { |
| 8304 | 8640 | \\ var buffer: [64]u8 = undefined; |
| 8305 | 8641 | \\ return buffer[0..]; |
| ... | ... | @@ -8309,8 +8645,8 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 8309 | 8645 | ":3:18: note: destination pointer requires a terminating '0' sentinel", |
| 8310 | 8646 | }); |
| 8311 | 8647 | |
| 8312 | | cases.add("issue #5221: invalid struct init type referenced by @typeInfo and passed into function", |
| 8313 | | \\fn ignore(comptime param: anytype) void {} |
| 8648 | ctx.objErrStage1("issue #5221: invalid struct init type referenced by @typeInfo and passed into function", |
| 8649 | \\fn ignore(comptime param: anytype) void {_ = param;} |
| 8314 | 8650 | \\ |
| 8315 | 8651 | \\export fn foo() void { |
| 8316 | 8652 | \\ const MyStruct = struct { |
| ... | ... | @@ -8323,7 +8659,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 8323 | 8659 | ":5:28: error: expected type '[]u8', found '*const [3:0]u8'", |
| 8324 | 8660 | }); |
| 8325 | 8661 | |
| 8326 | | cases.add("integer underflow error", |
| 8662 | ctx.objErrStage1("integer underflow error", |
| 8327 | 8663 | \\export fn entry() void { |
| 8328 | 8664 | \\ _ = @intToPtr(*c_void, ~@as(usize, @import("std").math.maxInt(usize)) - 1); |
| 8329 | 8665 | \\} |
| ... | ... | @@ -8331,23 +8667,24 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 8331 | 8667 | ":2:75: error: operation caused overflow", |
| 8332 | 8668 | }); |
| 8333 | 8669 | |
| 8334 | | cases.addCase(x: { |
| 8335 | | var tc = cases.create("align(N) expr function pointers is a compile error", |
| 8670 | { |
| 8671 | const case = ctx.obj("align(N) expr function pointers is a compile error", .{ |
| 8672 | .cpu_arch = .wasm32, |
| 8673 | .os_tag = .freestanding, |
| 8674 | .abi = .none, |
| 8675 | }); |
| 8676 | case.backend = .stage1; |
| 8677 | |
| 8678 | case.addError( |
| 8336 | 8679 | \\export fn foo() align(1) void { |
| 8337 | 8680 | \\ return; |
| 8338 | 8681 | \\} |
| 8339 | 8682 | , &[_][]const u8{ |
| 8340 | 8683 | "tmp.zig:1:23: error: align(N) expr is not allowed on function prototypes in wasm32/wasm64", |
| 8341 | 8684 | }); |
| 8342 | | tc.target = std.zig.CrossTarget{ |
| 8343 | | .cpu_arch = .wasm32, |
| 8344 | | .os_tag = .freestanding, |
| 8345 | | .abi = .none, |
| 8346 | | }; |
| 8347 | | break :x tc; |
| 8348 | | }); |
| 8685 | } |
| 8349 | 8686 | |
| 8350 | | cases.add("compare optional to non-optional with invalid types", |
| 8687 | ctx.objErrStage1("compare optional to non-optional with invalid types", |
| 8351 | 8688 | \\export fn inconsistentChildType() void { |
| 8352 | 8689 | \\ var x: ?i32 = undefined; |
| 8353 | 8690 | \\ const y: comptime_int = 10; |
| ... | ... | @@ -8381,16 +8718,17 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 8381 | 8718 | ":22:12: note: operator not supported for type '[3]i32'", |
| 8382 | 8719 | }); |
| 8383 | 8720 | |
| 8384 | | cases.add("slice cannot have its bytes reinterpreted", |
| 8721 | ctx.objErrStage1("slice cannot have its bytes reinterpreted", |
| 8385 | 8722 | \\export fn foo() void { |
| 8386 | 8723 | \\ const bytes = [1]u8{ 0xfa } ** 16; |
| 8387 | 8724 | \\ var value = @ptrCast(*const []const u8, &bytes).*; |
| 8725 | \\ _ = value; |
| 8388 | 8726 | \\} |
| 8389 | 8727 | , &[_][]const u8{ |
| 8390 | 8728 | ":3:52: error: slice '[]const u8' cannot have its bytes reinterpreted", |
| 8391 | 8729 | }); |
| 8392 | 8730 | |
| 8393 | | cases.add("wasmMemorySize is a compile error in non-Wasm targets", |
| 8731 | ctx.objErrStage1("wasmMemorySize is a compile error in non-Wasm targets", |
| 8394 | 8732 | \\export fn foo() void { |
| 8395 | 8733 | \\ _ = @wasmMemorySize(0); |
| 8396 | 8734 | \\ return; |
| ... | ... | @@ -8399,7 +8737,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 8399 | 8737 | "tmp.zig:2:9: error: @wasmMemorySize is a wasm32 feature only", |
| 8400 | 8738 | }); |
| 8401 | 8739 | |
| 8402 | | cases.add("wasmMemoryGrow is a compile error in non-Wasm targets", |
| 8740 | ctx.objErrStage1("wasmMemoryGrow is a compile error in non-Wasm targets", |
| 8403 | 8741 | \\export fn foo() void { |
| 8404 | 8742 | \\ _ = @wasmMemoryGrow(0, 1); |
| 8405 | 8743 | \\ return; |
| ... | ... | @@ -8407,7 +8745,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 8407 | 8745 | , &[_][]const u8{ |
| 8408 | 8746 | "tmp.zig:2:9: error: @wasmMemoryGrow is a wasm32 feature only", |
| 8409 | 8747 | }); |
| 8410 | | cases.add("Issue #5586: Make unary minus for unsigned types a compile error", |
| 8748 | ctx.objErrStage1("Issue #5586: Make unary minus for unsigned types a compile error", |
| 8411 | 8749 | \\export fn f1(x: u32) u32 { |
| 8412 | 8750 | \\ const y = -%x; |
| 8413 | 8751 | \\ return -y; |
| ... | ... | @@ -8422,7 +8760,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 8422 | 8760 | "tmp.zig:8:12: error: negation of type 'u32'", |
| 8423 | 8761 | }); |
| 8424 | 8762 | |
| 8425 | | cases.add("Issue #5618: coercion of ?*c_void to *c_void must fail.", |
| 8763 | ctx.objErrStage1("Issue #5618: coercion of ?*c_void to *c_void must fail.", |
| 8426 | 8764 | \\export fn foo() void { |
| 8427 | 8765 | \\ var u: ?*c_void = null; |
| 8428 | 8766 | \\ var v: *c_void = undefined; |
| ... | ... | @@ -8432,15 +8770,17 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 8432 | 8770 | "tmp.zig:4:9: error: expected type '*c_void', found '?*c_void'", |
| 8433 | 8771 | }); |
| 8434 | 8772 | |
| 8435 | | cases.add("Issue #6823: don't allow .* to be followed by **", |
| 8773 | ctx.objErrStage1("Issue #6823: don't allow .* to be followed by **", |
| 8436 | 8774 | \\fn foo() void { |
| 8437 | 8775 | \\ var sequence = "repeat".*** 10; |
| 8776 | \\ _ = sequence; |
| 8438 | 8777 | \\} |
| 8439 | 8778 | , &[_][]const u8{ |
| 8440 | | "tmp.zig:2:30: error: `.*` cannot be followed by `*`. Are you missing a space?", |
| 8779 | // Ideally this would be column 30 but it's not very important. |
| 8780 | "tmp.zig:2:28: error: '.*' cannot be followed by '*'. Are you missing a space?", |
| 8441 | 8781 | }); |
| 8442 | 8782 | |
| 8443 | | cases.add("Issue #9165: windows tcp server compilation error", |
| 8783 | ctx.objErrStage1("Issue #9165: windows tcp server compilation error", |
| 8444 | 8784 | \\const std = @import("std"); |
| 8445 | 8785 | \\pub const io_mode = .evented; |
| 8446 | 8786 | \\pub fn main() !void { |