| ... | ... | @@ -1,53 +1,50 @@ |
| 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", |
| 6 | | \\pub fn main() !void { |
| 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 | | \\} |
| 9 | | , &.{ |
| 10 | | \\error: 10 unused arguments in "{d} {d} {d} {d} {d}" |
| 11 | | }); |
| 12 | | |
| 13 | | cases.add("lazy pointer with undefined element type", |
| 4 | pub fn addCases(ctx: *TestContext) !void { |
| 5 | ctx.objErrStage1("lazy pointer with undefined element type", |
| 14 | 6 | \\export fn foo() void { |
| 15 | 7 | \\ comptime var T: type = undefined; |
| 16 | 8 | \\ const S = struct { x: *T }; |
| 17 | 9 | \\ const I = @typeInfo(S); |
| 10 | \\ _ = I; |
| 18 | 11 | \\} |
| 19 | 12 | , &[_][]const u8{ |
| 20 | | "tmp.zig:3:28: error: use of undefined value here causes undefined behavior", |
| 13 | ":3:28: error: use of undefined value here causes undefined behavior", |
| 21 | 14 | }); |
| 22 | 15 | |
| 23 | | cases.add("pointer arithmetic on pointer-to-array", |
| 16 | ctx.objErrStage1("pointer arithmetic on pointer-to-array", |
| 24 | 17 | \\export fn foo() void { |
| 25 | 18 | \\ var x: [10]u8 = undefined; |
| 26 | 19 | \\ var y = &x; |
| 27 | 20 | \\ var z = y + 1; |
| 21 | \\ _ = z; |
| 28 | 22 | \\} |
| 29 | 23 | , &[_][]const u8{ |
| 30 | 24 | "tmp.zig:4:17: error: integer value 1 cannot be coerced to type '*[10]u8'", |
| 31 | 25 | }); |
| 32 | 26 | |
| 33 | | cases.add("pointer attributes checked when coercing pointer to anon literal", |
| 27 | ctx.objErrStage1("pointer attributes checked when coercing pointer to anon literal", |
| 34 | 28 | \\comptime { |
| 35 | 29 | \\ const c: [][]const u8 = &.{"hello", "world" }; |
| 30 | \\ _ = c; |
| 36 | 31 | \\} |
| 37 | 32 | \\comptime { |
| 38 | 33 | \\ const c: *[2][]const u8 = &.{"hello", "world" }; |
| 34 | \\ _ = c; |
| 39 | 35 | \\} |
| 40 | 36 | \\const S = struct {a: u8 = 1, b: u32 = 2}; |
| 41 | 37 | \\comptime { |
| 42 | 38 | \\ const c: *S = &.{}; |
| 39 | \\ _ = c; |
| 43 | 40 | \\} |
| 44 | 41 | , &[_][]const u8{ |
| 45 | 42 | "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'", |
| 43 | "tmp.zig:6:33: error: expected type '*[2][]const u8', found '*const struct:6:33'", |
| 44 | "tmp.zig:11:21: error: expected type '*S', found '*const struct:11:21'", |
| 48 | 45 | }); |
| 49 | 46 | |
| 50 | | cases.add("@Type() union payload is undefined", |
| 47 | ctx.objErrStage1("@Type() union payload is undefined", |
| 51 | 48 | \\const Foo = @Type(@import("std").builtin.TypeInfo{ |
| 52 | 49 | \\ .Struct = undefined, |
| 53 | 50 | \\}); |
| ... | ... | @@ -56,7 +53,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 56 | 53 | "tmp.zig:1:50: error: use of undefined value here causes undefined behavior", |
| 57 | 54 | }); |
| 58 | 55 | |
| 59 | | cases.add("wrong initializer for union payload of type 'type'", |
| 56 | ctx.objErrStage1("wrong initializer for union payload of type 'type'", |
| 60 | 57 | \\const U = union(enum) { |
| 61 | 58 | \\ A: type, |
| 62 | 59 | \\}; |
| ... | ... | @@ -71,7 +68,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 71 | 68 | "tmp.zig:9:8: error: use of undefined value here causes undefined behavior", |
| 72 | 69 | }); |
| 73 | 70 | |
| 74 | | cases.add("union with too small explicit signed tag type", |
| 71 | ctx.objErrStage1("union with too small explicit signed tag type", |
| 75 | 72 | \\const U = union(enum(i2)) { |
| 76 | 73 | \\ A: u8, |
| 77 | 74 | \\ B: u8, |
| ... | ... | @@ -86,7 +83,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 86 | 83 | "tmp.zig:1:22: note: type i2 cannot fit values in range 0...3", |
| 87 | 84 | }); |
| 88 | 85 | |
| 89 | | cases.add("union with too small explicit unsigned tag type", |
| 86 | ctx.objErrStage1("union with too small explicit unsigned tag type", |
| 90 | 87 | \\const U = union(enum(u2)) { |
| 91 | 88 | \\ A: u8, |
| 92 | 89 | \\ B: u8, |
| ... | ... | @@ -102,56 +99,60 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 102 | 99 | "tmp.zig:1:22: note: type u2 cannot fit values in range 0...4", |
| 103 | 100 | }); |
| 104 | 101 | |
| 105 | | cases.addCase(x: { |
| 106 | | var tc = cases.create("callconv(.Interrupt) on unsupported platform", |
| 102 | { |
| 103 | const case = ctx.obj("callconv(.Interrupt) on unsupported platform", .{ |
| 104 | .cpu_arch = .aarch64, |
| 105 | .os_tag = .linux, |
| 106 | .abi = .none, |
| 107 | }); |
| 108 | case.backend = .stage1; |
| 109 | case.addError( |
| 107 | 110 | \\export fn entry() callconv(.Interrupt) void {} |
| 108 | 111 | , &[_][]const u8{ |
| 109 | 112 | "tmp.zig:1:28: error: callconv 'Interrupt' is only available on x86, x86_64, AVR, and MSP430, not aarch64", |
| 110 | 113 | }); |
| 111 | | tc.target = std.zig.CrossTarget{ |
| 112 | | .cpu_arch = .aarch64, |
| 114 | } |
| 115 | { |
| 116 | var case = ctx.obj("callconv(.Signal) on unsupported platform", .{ |
| 117 | .cpu_arch = .x86_64, |
| 113 | 118 | .os_tag = .linux, |
| 114 | 119 | .abi = .none, |
| 115 | | }; |
| 116 | | break :x tc; |
| 117 | | }); |
| 118 | | |
| 119 | | cases.addCase(x: { |
| 120 | | var tc = cases.create("callconv(.Signal) on unsupported platform", |
| 120 | }); |
| 121 | case.backend = .stage1; |
| 122 | case.addError( |
| 121 | 123 | \\export fn entry() callconv(.Signal) void {} |
| 122 | 124 | , &[_][]const u8{ |
| 123 | 125 | "tmp.zig:1:28: error: callconv 'Signal' is only available on AVR, not x86_64", |
| 124 | 126 | }); |
| 125 | | tc.target = std.zig.CrossTarget{ |
| 127 | } |
| 128 | { |
| 129 | const case = ctx.obj("callconv(.Stdcall, .Fastcall, .Thiscall) on unsupported platform", .{ |
| 126 | 130 | .cpu_arch = .x86_64, |
| 127 | 131 | .os_tag = .linux, |
| 128 | 132 | .abi = .none, |
| 129 | | }; |
| 130 | | break :x tc; |
| 131 | | }); |
| 132 | | cases.addCase(x: { |
| 133 | | var tc = cases.create("callconv(.Stdcall, .Fastcall, .Thiscall) on unsupported platform", |
| 133 | }); |
| 134 | case.backend = .stage1; |
| 135 | case.addError( |
| 134 | 136 | \\const F1 = fn () callconv(.Stdcall) void; |
| 135 | 137 | \\const F2 = fn () callconv(.Fastcall) void; |
| 136 | 138 | \\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; } |
| 139 | \\export fn entry1() void { var a: F1 = undefined; _ = a; } |
| 140 | \\export fn entry2() void { var a: F2 = undefined; _ = a; } |
| 141 | \\export fn entry3() void { var a: F3 = undefined; _ = a; } |
| 140 | 142 | , &[_][]const u8{ |
| 141 | 143 | "tmp.zig:1:27: error: callconv 'Stdcall' is only available on x86, not x86_64", |
| 142 | 144 | "tmp.zig:2:27: error: callconv 'Fastcall' is only available on x86, not x86_64", |
| 143 | 145 | "tmp.zig:3:27: error: callconv 'Thiscall' is only available on x86, not x86_64", |
| 144 | 146 | }); |
| 145 | | tc.target = std.zig.CrossTarget{ |
| 147 | } |
| 148 | { |
| 149 | const case = ctx.obj("callconv(.Stdcall, .Fastcall, .Thiscall) on unsupported platform", .{ |
| 146 | 150 | .cpu_arch = .x86_64, |
| 147 | 151 | .os_tag = .linux, |
| 148 | 152 | .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", |
| 153 | }); |
| 154 | case.backend = .stage1; |
| 155 | case.addError( |
| 155 | 156 | \\export fn entry1() callconv(.Stdcall) void {} |
| 156 | 157 | \\export fn entry2() callconv(.Fastcall) void {} |
| 157 | 158 | \\export fn entry3() callconv(.Thiscall) void {} |
| ... | ... | @@ -160,30 +161,28 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 160 | 161 | "tmp.zig:2:29: error: callconv 'Fastcall' is only available on x86, not x86_64", |
| 161 | 162 | "tmp.zig:3:29: error: callconv 'Thiscall' is only available on x86, not x86_64", |
| 162 | 163 | }); |
| 163 | | tc.target = std.zig.CrossTarget{ |
| 164 | } |
| 165 | { |
| 166 | const case = ctx.obj("callconv(.Vectorcall) on unsupported platform", .{ |
| 164 | 167 | .cpu_arch = .x86_64, |
| 165 | 168 | .os_tag = .linux, |
| 166 | 169 | .abi = .none, |
| 167 | | }; |
| 168 | | break :x tc; |
| 169 | | }); |
| 170 | | |
| 171 | | cases.addCase(x: { |
| 172 | | var tc = cases.create("callconv(.Vectorcall) on unsupported platform", |
| 170 | }); |
| 171 | case.backend = .stage1; |
| 172 | case.addError( |
| 173 | 173 | \\export fn entry() callconv(.Vectorcall) void {} |
| 174 | 174 | , &[_][]const u8{ |
| 175 | 175 | "tmp.zig:1:28: error: callconv 'Vectorcall' is only available on x86 and AArch64, not x86_64", |
| 176 | 176 | }); |
| 177 | | tc.target = std.zig.CrossTarget{ |
| 177 | } |
| 178 | { |
| 179 | const case = ctx.obj("callconv(.APCS, .AAPCS, .AAPCSVFP) on unsupported platform", .{ |
| 178 | 180 | .cpu_arch = .x86_64, |
| 179 | 181 | .os_tag = .linux, |
| 180 | 182 | .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", |
| 183 | }); |
| 184 | case.backend = .stage1; |
| 185 | case.addError( |
| 187 | 186 | \\export fn entry1() callconv(.APCS) void {} |
| 188 | 187 | \\export fn entry2() callconv(.AAPCS) void {} |
| 189 | 188 | \\export fn entry3() callconv(.AAPCSVFP) void {} |
| ... | ... | @@ -192,15 +191,9 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 192 | 191 | "tmp.zig:2:29: error: callconv 'AAPCS' is only available on ARM, not x86_64", |
| 193 | 192 | "tmp.zig:3:29: error: callconv 'AAPCSVFP' is only available on ARM, not x86_64", |
| 194 | 193 | }); |
| 195 | | tc.target = std.zig.CrossTarget{ |
| 196 | | .cpu_arch = .x86_64, |
| 197 | | .os_tag = .linux, |
| 198 | | .abi = .none, |
| 199 | | }; |
| 200 | | break :x tc; |
| 201 | | }); |
| 194 | } |
| 202 | 195 | |
| 203 | | cases.add("unreachable executed at comptime", |
| 196 | ctx.objErrStage1("unreachable executed at comptime", |
| 204 | 197 | \\fn foo(comptime x: i32) i32 { |
| 205 | 198 | \\ comptime { |
| 206 | 199 | \\ if (x >= 0) return -x; |
| ... | ... | @@ -215,7 +208,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 215 | 208 | "tmp.zig:8:12: note: called from here", |
| 216 | 209 | }); |
| 217 | 210 | |
| 218 | | cases.add("@Type with TypeInfo.Int", |
| 211 | ctx.objErrStage1("@Type with TypeInfo.Int", |
| 219 | 212 | \\const builtin = @import("std").builtin; |
| 220 | 213 | \\export fn entry() void { |
| 221 | 214 | \\ _ = @Type(builtin.TypeInfo.Int { |
| ... | ... | @@ -227,7 +220,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 227 | 220 | "tmp.zig:3:36: error: expected type 'std.builtin.TypeInfo', found 'std.builtin.Int'", |
| 228 | 221 | }); |
| 229 | 222 | |
| 230 | | cases.add("indexing a undefined slice at comptime", |
| 223 | ctx.objErrStage1("indexing a undefined slice at comptime", |
| 231 | 224 | \\comptime { |
| 232 | 225 | \\ var slice: []u8 = undefined; |
| 233 | 226 | \\ slice[0] = 2; |
| ... | ... | @@ -236,7 +229,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 236 | 229 | "tmp.zig:3:10: error: index 0 outside slice of size 0", |
| 237 | 230 | }); |
| 238 | 231 | |
| 239 | | cases.add("array in c exported function", |
| 232 | ctx.objErrStage1("array in c exported function", |
| 240 | 233 | \\export fn zig_array(x: [10]u8) void { |
| 241 | 234 | \\try expect(std.mem.eql(u8, &x, "1234567890")); |
| 242 | 235 | \\} |
| ... | ... | @@ -249,7 +242,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 249 | 242 | "tmp.zig:5:30: error: return type '[10]u8' not allowed in function with calling convention 'C'", |
| 250 | 243 | }); |
| 251 | 244 | |
| 252 | | cases.add("@Type for exhaustive enum with undefined tag type", |
| 245 | ctx.objErrStage1("@Type for exhaustive enum with undefined tag type", |
| 253 | 246 | \\const TypeInfo = @import("std").builtin.TypeInfo; |
| 254 | 247 | \\const Tag = @Type(.{ |
| 255 | 248 | \\ .Enum = .{ |
| ... | ... | @@ -267,19 +260,20 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 267 | 260 | "tmp.zig:2:20: error: use of undefined value here causes undefined behavior", |
| 268 | 261 | }); |
| 269 | 262 | |
| 270 | | cases.add("extern struct with non-extern-compatible integer tag type", |
| 263 | ctx.objErrStage1("extern struct with non-extern-compatible integer tag type", |
| 271 | 264 | \\pub const E = enum(u31) { A, B, C }; |
| 272 | 265 | \\pub const S = extern struct { |
| 273 | 266 | \\ e: E, |
| 274 | 267 | \\}; |
| 275 | 268 | \\export fn entry() void { |
| 276 | 269 | \\ const s: S = undefined; |
| 270 | \\ _ = s; |
| 277 | 271 | \\} |
| 278 | 272 | , &[_][]const u8{ |
| 279 | 273 | "tmp.zig:3:5: error: extern structs cannot contain fields of type 'E'", |
| 280 | 274 | }); |
| 281 | 275 | |
| 282 | | cases.add("@Type for exhaustive enum with non-integer tag type", |
| 276 | ctx.objErrStage1("@Type for exhaustive enum with non-integer tag type", |
| 283 | 277 | \\const TypeInfo = @import("std").builtin.TypeInfo; |
| 284 | 278 | \\const Tag = @Type(.{ |
| 285 | 279 | \\ .Enum = .{ |
| ... | ... | @@ -297,7 +291,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 297 | 291 | "tmp.zig:2:20: error: TypeInfo.Enum.tag_type must be an integer type, not 'bool'", |
| 298 | 292 | }); |
| 299 | 293 | |
| 300 | | cases.add("extern struct with extern-compatible but inferred integer tag type", |
| 294 | ctx.objErrStage1("extern struct with extern-compatible but inferred integer tag type", |
| 301 | 295 | \\pub const E = enum { |
| 302 | 296 | \\@"0",@"1",@"2",@"3",@"4",@"5",@"6",@"7",@"8",@"9",@"10",@"11",@"12", |
| 303 | 297 | \\@"13",@"14",@"15",@"16",@"17",@"18",@"19",@"20",@"21",@"22",@"23", |
| ... | ... | @@ -333,12 +327,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 333 | 327 | \\export fn entry() void { |
| 334 | 328 | \\ if (@typeInfo(E).Enum.tag_type != u8) @compileError("did not infer u8 tag type"); |
| 335 | 329 | \\ const s: S = undefined; |
| 330 | \\ _ = s; |
| 336 | 331 | \\} |
| 337 | 332 | , &[_][]const u8{ |
| 338 | 333 | "tmp.zig:31:5: error: extern structs cannot contain fields of type 'E'", |
| 339 | 334 | }); |
| 340 | 335 | |
| 341 | | cases.add("@Type for tagged union with extra enum field", |
| 336 | ctx.objErrStage1("@Type for tagged union with extra enum field", |
| 342 | 337 | \\const TypeInfo = @import("std").builtin.TypeInfo; |
| 343 | 338 | \\const Tag = @Type(.{ |
| 344 | 339 | \\ .Enum = .{ |
| ... | ... | @@ -373,7 +368,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 373 | 368 | "tmp.zig:27:24: note: referenced here", |
| 374 | 369 | }); |
| 375 | 370 | |
| 376 | | cases.add("field access of opaque type", |
| 371 | ctx.objErrStage1("field access of opaque type", |
| 377 | 372 | \\const MyType = opaque {}; |
| 378 | 373 | \\ |
| 379 | 374 | \\export fn entry() bool { |
| ... | ... | @@ -388,16 +383,17 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 388 | 383 | "tmp.zig:9:13: error: no member named 'blah' in opaque type 'MyType'", |
| 389 | 384 | }); |
| 390 | 385 | |
| 391 | | cases.add("opaque type with field", |
| 386 | ctx.objErrStage1("opaque type with field", |
| 392 | 387 | \\const Opaque = opaque { foo: i32 }; |
| 393 | 388 | \\export fn entry() void { |
| 394 | 389 | \\ const foo: ?*Opaque = null; |
| 390 | \\ _ = foo; |
| 395 | 391 | \\} |
| 396 | 392 | , &[_][]const u8{ |
| 397 | 393 | "tmp.zig:1:25: error: opaque types cannot have fields", |
| 398 | 394 | }); |
| 399 | 395 | |
| 400 | | cases.add("@Type(.Fn) with is_generic = true", |
| 396 | ctx.objErrStage1("@Type(.Fn) with is_generic = true", |
| 401 | 397 | \\const Foo = @Type(.{ |
| 402 | 398 | \\ .Fn = .{ |
| 403 | 399 | \\ .calling_convention = .Unspecified, |
| ... | ... | @@ -413,7 +409,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 413 | 409 | "tmp.zig:1:20: error: TypeInfo.Fn.is_generic must be false for @Type", |
| 414 | 410 | }); |
| 415 | 411 | |
| 416 | | cases.add("@Type(.Fn) with is_var_args = true and non-C callconv", |
| 412 | ctx.objErrStage1("@Type(.Fn) with is_var_args = true and non-C callconv", |
| 417 | 413 | \\const Foo = @Type(.{ |
| 418 | 414 | \\ .Fn = .{ |
| 419 | 415 | \\ .calling_convention = .Unspecified, |
| ... | ... | @@ -429,7 +425,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 429 | 425 | "tmp.zig:1:20: error: varargs functions must have C calling convention", |
| 430 | 426 | }); |
| 431 | 427 | |
| 432 | | cases.add("@Type(.Fn) with return_type = null", |
| 428 | ctx.objErrStage1("@Type(.Fn) with return_type = null", |
| 433 | 429 | \\const Foo = @Type(.{ |
| 434 | 430 | \\ .Fn = .{ |
| 435 | 431 | \\ .calling_convention = .Unspecified, |
| ... | ... | @@ -445,7 +441,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 445 | 441 | "tmp.zig:1:20: error: TypeInfo.Fn.return_type must be non-null for @Type", |
| 446 | 442 | }); |
| 447 | 443 | |
| 448 | | cases.add("@Type for union with opaque field", |
| 444 | ctx.objErrStage1("@Type for union with opaque field", |
| 449 | 445 | \\const TypeInfo = @import("std").builtin.TypeInfo; |
| 450 | 446 | \\const Untagged = @Type(.{ |
| 451 | 447 | \\ .Union = .{ |
| ... | ... | @@ -465,23 +461,25 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 465 | 461 | "tmp.zig:13:17: note: referenced here", |
| 466 | 462 | }); |
| 467 | 463 | |
| 468 | | cases.add("slice sentinel mismatch", |
| 464 | ctx.objErrStage1("slice sentinel mismatch", |
| 469 | 465 | \\export fn entry() void { |
| 470 | 466 | \\ const x = @import("std").meta.Vector(3, f32){ 25, 75, 5, 0 }; |
| 467 | \\ _ = x; |
| 471 | 468 | \\} |
| 472 | 469 | , &[_][]const u8{ |
| 473 | 470 | "tmp.zig:2:62: error: index 3 outside vector of size 3", |
| 474 | 471 | }); |
| 475 | 472 | |
| 476 | | cases.add("slice sentinel mismatch", |
| 473 | ctx.objErrStage1("slice sentinel mismatch", |
| 477 | 474 | \\export fn entry() void { |
| 478 | 475 | \\ const y: [:1]const u8 = &[_:2]u8{ 1, 2 }; |
| 476 | \\ _ = y; |
| 479 | 477 | \\} |
| 480 | 478 | , &[_][]const u8{ |
| 481 | 479 | "tmp.zig:2:37: error: expected type '[:1]const u8', found '*const [2:2]u8'", |
| 482 | 480 | }); |
| 483 | 481 | |
| 484 | | cases.add("@Type for union with zero fields", |
| 482 | ctx.objErrStage1("@Type for union with zero fields", |
| 485 | 483 | \\const TypeInfo = @import("std").builtin.TypeInfo; |
| 486 | 484 | \\const Untagged = @Type(.{ |
| 487 | 485 | \\ .Union = .{ |
| ... | ... | @@ -499,7 +497,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 499 | 497 | "tmp.zig:11:17: note: referenced here", |
| 500 | 498 | }); |
| 501 | 499 | |
| 502 | | cases.add("@Type for exhaustive enum with zero fields", |
| 500 | ctx.objErrStage1("@Type for exhaustive enum with zero fields", |
| 503 | 501 | \\const TypeInfo = @import("std").builtin.TypeInfo; |
| 504 | 502 | \\const Tag = @Type(.{ |
| 505 | 503 | \\ .Enum = .{ |
| ... | ... | @@ -518,7 +516,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 518 | 516 | "tmp.zig:12:9: note: referenced here", |
| 519 | 517 | }); |
| 520 | 518 | |
| 521 | | cases.add("@Type for tagged union with extra union field", |
| 519 | ctx.objErrStage1("@Type for tagged union with extra union field", |
| 522 | 520 | \\const TypeInfo = @import("std").builtin.TypeInfo; |
| 523 | 521 | \\const Tag = @Type(.{ |
| 524 | 522 | \\ .Enum = .{ |
| ... | ... | @@ -554,7 +552,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 554 | 552 | "tmp.zig:27:24: note: referenced here", |
| 555 | 553 | }); |
| 556 | 554 | |
| 557 | | cases.add("@Type with undefined", |
| 555 | ctx.objErrStage1("@Type with undefined", |
| 558 | 556 | \\comptime { |
| 559 | 557 | \\ _ = @Type(.{ .Array = .{ .len = 0, .child = u8, .sentinel = undefined } }); |
| 560 | 558 | \\} |
| ... | ... | @@ -573,7 +571,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 573 | 571 | "tmp.zig:5:16: error: use of undefined value here causes undefined behavior", |
| 574 | 572 | }); |
| 575 | 573 | |
| 576 | | cases.add("struct with declarations unavailable for @Type", |
| 574 | ctx.objErrStage1("struct with declarations unavailable for @Type", |
| 577 | 575 | \\export fn entry() void { |
| 578 | 576 | \\ _ = @Type(@typeInfo(struct { const foo = 1; })); |
| 579 | 577 | \\} |
| ... | ... | @@ -581,7 +579,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 581 | 579 | "tmp.zig:2:15: error: TypeInfo.Struct.decls must be empty for @Type", |
| 582 | 580 | }); |
| 583 | 581 | |
| 584 | | cases.add("enum with declarations unavailable for @Type", |
| 582 | ctx.objErrStage1("enum with declarations unavailable for @Type", |
| 585 | 583 | \\export fn entry() void { |
| 586 | 584 | \\ _ = @Type(@typeInfo(enum { foo, const bar = 1; })); |
| 587 | 585 | \\} |
| ... | ... | @@ -589,36 +587,44 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 589 | 587 | "tmp.zig:2:15: error: TypeInfo.Enum.decls must be empty for @Type", |
| 590 | 588 | }); |
| 591 | 589 | |
| 592 | | cases.addTest("reject extern variables with initializers", |
| 590 | ctx.testErrStage1("reject extern variables with initializers", |
| 593 | 591 | \\extern var foo: int = 2; |
| 594 | 592 | , &[_][]const u8{ |
| 595 | | "tmp.zig:1:1: error: extern variables have no initializers", |
| 593 | "tmp.zig:1:23: error: extern variables have no initializers", |
| 596 | 594 | }); |
| 597 | 595 | |
| 598 | | cases.addTest("duplicate/unused labels", |
| 596 | ctx.testErrStage1("duplicate/unused labels", |
| 599 | 597 | \\comptime { |
| 600 | 598 | \\ blk: { blk: while (false) {} } |
| 599 | \\} |
| 600 | \\comptime { |
| 601 | 601 | \\ blk: while (false) { blk: for (@as([0]void, undefined)) |_| {} } |
| 602 | \\} |
| 603 | \\comptime { |
| 602 | 604 | \\ blk: for (@as([0]void, undefined)) |_| { blk: {} } |
| 603 | 605 | \\} |
| 604 | 606 | \\comptime { |
| 605 | 607 | \\ blk: {} |
| 608 | \\} |
| 609 | \\comptime { |
| 606 | 610 | \\ blk: while(false) {} |
| 611 | \\} |
| 612 | \\comptime { |
| 607 | 613 | \\ blk: for(@as([0]void, undefined)) |_| {} |
| 608 | 614 | \\} |
| 609 | 615 | , &[_][]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", |
| 616 | "tmp.zig:2:12: error: redefinition of label 'blk'", |
| 617 | "tmp.zig:2:5: note: previous definition is here", |
| 618 | "tmp.zig:5:26: error: redefinition of label 'blk'", |
| 619 | "tmp.zig:5:5: note: previous definition is here", |
| 620 | "tmp.zig:8:46: error: redefinition of label 'blk'", |
| 621 | "tmp.zig:8:5: note: previous definition is here", |
| 622 | "tmp.zig:11:5: error: unused block label", |
| 623 | "tmp.zig:14:5: error: unused while loop label", |
| 624 | "tmp.zig:17:5: error: unused for loop label", |
| 619 | 625 | }); |
| 620 | 626 | |
| 621 | | cases.addTest("@alignCast of zero sized types", |
| 627 | ctx.testErrStage1("@alignCast of zero sized types", |
| 622 | 628 | \\export fn foo() void { |
| 623 | 629 | \\ const a: *void = undefined; |
| 624 | 630 | \\ _ = @alignCast(2, a); |
| ... | ... | @@ -633,7 +639,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 633 | 639 | \\} |
| 634 | 640 | \\export fn qux() void { |
| 635 | 641 | \\ const a = struct { |
| 636 | | \\ fn a(comptime b: u32) void {} |
| 642 | \\ fn a(comptime b: u32) void { _ = b; } |
| 637 | 643 | \\ }.a; |
| 638 | 644 | \\ _ = @alignCast(2, a); |
| 639 | 645 | \\} |
| ... | ... | @@ -644,7 +650,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 644 | 650 | "tmp.zig:17:23: error: cannot adjust alignment of zero sized type 'fn(u32) anytype'", |
| 645 | 651 | }); |
| 646 | 652 | |
| 647 | | cases.addTest("invalid non-exhaustive enum to union", |
| 653 | ctx.testErrStage1("invalid non-exhaustive enum to union", |
| 648 | 654 | \\const E = enum(u8) { |
| 649 | 655 | \\ a, |
| 650 | 656 | \\ b, |
| ... | ... | @@ -657,17 +663,19 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 657 | 663 | \\export fn foo() void { |
| 658 | 664 | \\ var e = @intToEnum(E, 15); |
| 659 | 665 | \\ var u: U = e; |
| 666 | \\ _ = u; |
| 660 | 667 | \\} |
| 661 | 668 | \\export fn bar() void { |
| 662 | 669 | \\ const e = @intToEnum(E, 15); |
| 663 | 670 | \\ var u: U = e; |
| 671 | \\ _ = u; |
| 664 | 672 | \\} |
| 665 | 673 | , &[_][]const u8{ |
| 666 | 674 | "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", |
| 675 | "tmp.zig:17:16: error: no tag by value 15", |
| 668 | 676 | }); |
| 669 | 677 | |
| 670 | | cases.addTest("switching with exhaustive enum has '_' prong ", |
| 678 | ctx.testErrStage1("switching with exhaustive enum has '_' prong ", |
| 671 | 679 | \\const E = enum{ |
| 672 | 680 | \\ a, |
| 673 | 681 | \\ b, |
| ... | ... | @@ -684,7 +692,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 684 | 692 | "tmp.zig:7:5: error: switch on exhaustive enum has `_` prong", |
| 685 | 693 | }); |
| 686 | 694 | |
| 687 | | cases.addTest("invalid pointer with @Type", |
| 695 | ctx.testErrStage1("invalid pointer with @Type", |
| 688 | 696 | \\export fn entry() void { |
| 689 | 697 | \\ _ = @Type(.{ .Pointer = .{ |
| 690 | 698 | \\ .size = .One, |
| ... | ... | @@ -700,7 +708,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 700 | 708 | "tmp.zig:2:16: error: sentinels are only allowed on slices and unknown-length pointers", |
| 701 | 709 | }); |
| 702 | 710 | |
| 703 | | cases.addTest("helpful return type error message", |
| 711 | ctx.testErrStage1("helpful return type error message", |
| 704 | 712 | \\export fn foo() u32 { |
| 705 | 713 | \\ return error.Ohno; |
| 706 | 714 | \\} |
| ... | ... | @@ -728,7 +736,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 728 | 736 | "tmp.zig:14:5: note: cannot store an error in type 'u32'", |
| 729 | 737 | }); |
| 730 | 738 | |
| 731 | | cases.addTest("int/float conversion to comptime_int/float", |
| 739 | ctx.testErrStage1("int/float conversion to comptime_int/float", |
| 732 | 740 | \\export fn foo() void { |
| 733 | 741 | \\ var a: f32 = 2; |
| 734 | 742 | \\ _ = @floatToInt(comptime_int, a); |
| ... | ... | @@ -744,16 +752,16 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 744 | 752 | "tmp.zig:7:9: note: referenced here", |
| 745 | 753 | }); |
| 746 | 754 | |
| 747 | | cases.add("extern variable has no type", |
| 755 | ctx.objErrStage1("extern variable has no type", |
| 748 | 756 | \\extern var foo; |
| 749 | 757 | \\pub export fn entry() void { |
| 750 | 758 | \\ foo; |
| 751 | 759 | \\} |
| 752 | 760 | , &[_][]const u8{ |
| 753 | | "tmp.zig:1:1: error: unable to infer variable type", |
| 761 | "tmp.zig:1:8: error: unable to infer variable type", |
| 754 | 762 | }); |
| 755 | 763 | |
| 756 | | cases.add("@src outside function", |
| 764 | ctx.objErrStage1("@src outside function", |
| 757 | 765 | \\comptime { |
| 758 | 766 | \\ @src(); |
| 759 | 767 | \\} |
| ... | ... | @@ -761,7 +769,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 761 | 769 | "tmp.zig:2:5: error: @src outside function", |
| 762 | 770 | }); |
| 763 | 771 | |
| 764 | | cases.add("call assigned to constant", |
| 772 | ctx.objErrStage1("call assigned to constant", |
| 765 | 773 | \\const Foo = struct { |
| 766 | 774 | \\ x: i32, |
| 767 | 775 | \\}; |
| ... | ... | @@ -784,15 +792,15 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 784 | 792 | "tmp.zig:16:14: error: cannot assign to constant", |
| 785 | 793 | }); |
| 786 | 794 | |
| 787 | | cases.add("invalid pointer syntax", |
| 795 | ctx.objErrStage1("invalid pointer syntax", |
| 788 | 796 | \\export fn foo() void { |
| 789 | 797 | \\ var guid: *:0 const u8 = undefined; |
| 790 | 798 | \\} |
| 791 | 799 | , &[_][]const u8{ |
| 792 | | "tmp.zig:2:15: error: sentinels are only allowed on unknown-length pointers", |
| 800 | "tmp.zig:2:16: error: expected type expression, found ':'", |
| 793 | 801 | }); |
| 794 | 802 | |
| 795 | | cases.add("declaration between fields", |
| 803 | ctx.objErrStage1("declaration between fields", |
| 796 | 804 | \\const S = struct { |
| 797 | 805 | \\ const foo = 2; |
| 798 | 806 | \\ const bar = 2; |
| ... | ... | @@ -810,16 +818,16 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 810 | 818 | "tmp.zig:6:5: error: declarations are not allowed between container fields", |
| 811 | 819 | }); |
| 812 | 820 | |
| 813 | | cases.add("non-extern function with var args", |
| 821 | ctx.objErrStage1("non-extern function with var args", |
| 814 | 822 | \\fn foo(args: ...) void {} |
| 815 | 823 | \\export fn entry() void { |
| 816 | 824 | \\ foo(); |
| 817 | 825 | \\} |
| 818 | 826 | , &[_][]const u8{ |
| 819 | | "tmp.zig:1:1: error: non-extern function is variadic", |
| 827 | "tmp.zig:1:14: error: expected type expression, found '...'", |
| 820 | 828 | }); |
| 821 | 829 | |
| 822 | | cases.addTest("invalid int casts", |
| 830 | ctx.testErrStage1("invalid int casts", |
| 823 | 831 | \\export fn foo() void { |
| 824 | 832 | \\ var a: u32 = 2; |
| 825 | 833 | \\ _ = @intCast(comptime_int, a); |
| ... | ... | @@ -847,7 +855,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 847 | 855 | "tmp.zig:15:9: note: referenced here", |
| 848 | 856 | }); |
| 849 | 857 | |
| 850 | | cases.addTest("invalid float casts", |
| 858 | ctx.testErrStage1("invalid float casts", |
| 851 | 859 | \\export fn foo() void { |
| 852 | 860 | \\ var a: f32 = 2; |
| 853 | 861 | \\ _ = @floatCast(comptime_float, a); |
| ... | ... | @@ -875,7 +883,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 875 | 883 | "tmp.zig:15:9: note: referenced here", |
| 876 | 884 | }); |
| 877 | 885 | |
| 878 | | cases.addTest("invalid assignments", |
| 886 | ctx.testErrStage1("invalid assignments", |
| 879 | 887 | \\export fn entry1() void { |
| 880 | 888 | \\ var a: []const u8 = "foo"; |
| 881 | 889 | \\ a[0..2] = "bar"; |
| ... | ... | @@ -893,7 +901,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 893 | 901 | "tmp.zig:10:7: error: invalid left-hand side to assignment", |
| 894 | 902 | }); |
| 895 | 903 | |
| 896 | | cases.addTest("reassign to array parameter", |
| 904 | ctx.testErrStage1("reassign to array parameter", |
| 897 | 905 | \\fn reassign(a: [3]f32) void { |
| 898 | 906 | \\ a = [3]f32{4, 5, 6}; |
| 899 | 907 | \\} |
| ... | ... | @@ -904,7 +912,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 904 | 912 | "tmp.zig:2:15: error: cannot assign to constant", |
| 905 | 913 | }); |
| 906 | 914 | |
| 907 | | cases.addTest("reassign to slice parameter", |
| 915 | ctx.testErrStage1("reassign to slice parameter", |
| 908 | 916 | \\pub fn reassign(s: []const u8) void { |
| 909 | 917 | \\ s = s[0..]; |
| 910 | 918 | \\} |
| ... | ... | @@ -915,7 +923,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 915 | 923 | "tmp.zig:2:10: error: cannot assign to constant", |
| 916 | 924 | }); |
| 917 | 925 | |
| 918 | | cases.addTest("reassign to struct parameter", |
| 926 | ctx.testErrStage1("reassign to struct parameter", |
| 919 | 927 | \\const S = struct { |
| 920 | 928 | \\ x: u32, |
| 921 | 929 | \\}; |
| ... | ... | @@ -929,7 +937,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 929 | 937 | "tmp.zig:5:10: error: cannot assign to constant", |
| 930 | 938 | }); |
| 931 | 939 | |
| 932 | | cases.addTest("reference to const data", |
| 940 | ctx.testErrStage1("reference to const data", |
| 933 | 941 | \\export fn foo() void { |
| 934 | 942 | \\ var ptr = &[_]u8{0,0,0,0}; |
| 935 | 943 | \\ ptr[1] = 2; |
| ... | ... | @@ -957,7 +965,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 957 | 965 | "tmp.zig:19:13: error: cannot assign to constant", |
| 958 | 966 | }); |
| 959 | 967 | |
| 960 | | cases.addTest("cast between ?T where T is not a pointer", |
| 968 | ctx.testErrStage1("cast between ?T where T is not a pointer", |
| 961 | 969 | \\pub const fnty1 = ?fn (i8) void; |
| 962 | 970 | \\pub const fnty2 = ?fn (u64) void; |
| 963 | 971 | \\export fn entry() void { |
| ... | ... | @@ -970,7 +978,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 970 | 978 | "tmp.zig:6:9: note: optional type child 'fn(u64) void' cannot cast into optional type child 'fn(i8) void'", |
| 971 | 979 | }); |
| 972 | 980 | |
| 973 | | cases.addTest("unused variable error on errdefer", |
| 981 | ctx.testErrStage1("unused variable error on errdefer", |
| 974 | 982 | \\fn foo() !void { |
| 975 | 983 | \\ errdefer |a| unreachable; |
| 976 | 984 | \\ return error.A; |
| ... | ... | @@ -982,18 +990,19 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 982 | 990 | "tmp.zig:2:15: error: unused variable: 'a'", |
| 983 | 991 | }); |
| 984 | 992 | |
| 985 | | cases.addTest("comparison of non-tagged union and enum literal", |
| 993 | ctx.testErrStage1("comparison of non-tagged union and enum literal", |
| 986 | 994 | \\export fn entry() void { |
| 987 | 995 | \\ const U = union { A: u32, B: u64 }; |
| 988 | 996 | \\ var u = U{ .A = 42 }; |
| 989 | 997 | \\ var ok = u == .A; |
| 998 | \\ _ = ok; |
| 990 | 999 | \\} |
| 991 | 1000 | , &[_][]const u8{ |
| 992 | 1001 | "tmp.zig:4:16: error: comparison of union and enum literal is only valid for tagged union types", |
| 993 | 1002 | "tmp.zig:2:15: note: type U is not a tagged union", |
| 994 | 1003 | }); |
| 995 | 1004 | |
| 996 | | cases.addTest("shift on type with non-power-of-two size", |
| 1005 | ctx.testErrStage1("shift on type with non-power-of-two size", |
| 997 | 1006 | \\export fn entry() void { |
| 998 | 1007 | \\ const S = struct { |
| 999 | 1008 | \\ fn a() void { |
| ... | ... | @@ -1025,7 +1034,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1025 | 1034 | "tmp.zig:17:17: error: RHS of shift is too large for LHS type", |
| 1026 | 1035 | }); |
| 1027 | 1036 | |
| 1028 | | cases.addTest("combination of nosuspend and async", |
| 1037 | ctx.testErrStage1("combination of nosuspend and async", |
| 1029 | 1038 | \\export fn entry() void { |
| 1030 | 1039 | \\ nosuspend { |
| 1031 | 1040 | \\ const bar = async foo(); |
| ... | ... | @@ -1035,10 +1044,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1035 | 1044 | \\} |
| 1036 | 1045 | \\fn foo() void {} |
| 1037 | 1046 | , &[_][]const u8{ |
| 1038 | | "tmp.zig:4:9: error: suspend in nosuspend scope", |
| 1047 | "tmp.zig:4:9: error: suspend inside nosuspend block", |
| 1048 | "tmp.zig:2:5: note: nosuspend block here", |
| 1039 | 1049 | }); |
| 1040 | 1050 | |
| 1041 | | cases.add("atomicrmw with bool op not .Xchg", |
| 1051 | ctx.objErrStage1("atomicrmw with bool op not .Xchg", |
| 1042 | 1052 | \\export fn entry() void { |
| 1043 | 1053 | \\ var x = false; |
| 1044 | 1054 | \\ _ = @atomicRmw(bool, &x, .Add, true, .SeqCst); |
| ... | ... | @@ -1047,7 +1057,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1047 | 1057 | "tmp.zig:3:30: error: @atomicRmw with bool only allowed with .Xchg", |
| 1048 | 1058 | }); |
| 1049 | 1059 | |
| 1050 | | cases.addTest("@TypeOf with no arguments", |
| 1060 | ctx.testErrStage1("@TypeOf with no arguments", |
| 1051 | 1061 | \\export fn entry() void { |
| 1052 | 1062 | \\ _ = @TypeOf(); |
| 1053 | 1063 | \\} |
| ... | ... | @@ -1055,7 +1065,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1055 | 1065 | "tmp.zig:2:9: error: expected at least 1 argument, found 0", |
| 1056 | 1066 | }); |
| 1057 | 1067 | |
| 1058 | | cases.addTest("@TypeOf with incompatible arguments", |
| 1068 | ctx.testErrStage1("@TypeOf with incompatible arguments", |
| 1059 | 1069 | \\export fn entry() void { |
| 1060 | 1070 | \\ var var_1: f32 = undefined; |
| 1061 | 1071 | \\ var var_2: u32 = undefined; |
| ... | ... | @@ -1065,7 +1075,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1065 | 1075 | "tmp.zig:4:9: error: incompatible types: 'f32' and 'u32'", |
| 1066 | 1076 | }); |
| 1067 | 1077 | |
| 1068 | | cases.addTest("type mismatch with tuple concatenation", |
| 1078 | ctx.testErrStage1("type mismatch with tuple concatenation", |
| 1069 | 1079 | \\export fn entry() void { |
| 1070 | 1080 | \\ var x = .{}; |
| 1071 | 1081 | \\ x = x ++ .{ 1, 2, 3 }; |
| ... | ... | @@ -1074,7 +1084,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1074 | 1084 | "tmp.zig:3:11: error: expected type 'struct:2:14', found 'struct:3:11'", |
| 1075 | 1085 | }); |
| 1076 | 1086 | |
| 1077 | | cases.addTest("@tagName on invalid value of non-exhaustive enum", |
| 1087 | ctx.testErrStage1("@tagName on invalid value of non-exhaustive enum", |
| 1078 | 1088 | \\test "enum" { |
| 1079 | 1089 | \\ const E = enum(u8) {A, B, _}; |
| 1080 | 1090 | \\ _ = @tagName(@intToEnum(E, 5)); |
| ... | ... | @@ -1083,16 +1093,17 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1083 | 1093 | "tmp.zig:3:18: error: no tag by value 5", |
| 1084 | 1094 | }); |
| 1085 | 1095 | |
| 1086 | | cases.addTest("@ptrToInt with pointer to zero-sized type", |
| 1096 | ctx.testErrStage1("@ptrToInt with pointer to zero-sized type", |
| 1087 | 1097 | \\export fn entry() void { |
| 1088 | 1098 | \\ var pointer: ?*u0 = null; |
| 1089 | 1099 | \\ var x = @ptrToInt(pointer); |
| 1100 | \\ _ = x; |
| 1090 | 1101 | \\} |
| 1091 | 1102 | , &[_][]const u8{ |
| 1092 | 1103 | "tmp.zig:3:23: error: pointer to size 0 type has no address", |
| 1093 | 1104 | }); |
| 1094 | 1105 | |
| 1095 | | cases.addTest("access invalid @typeInfo decl", |
| 1106 | ctx.testErrStage1("access invalid @typeInfo decl", |
| 1096 | 1107 | \\const A = B; |
| 1097 | 1108 | \\test "Crash" { |
| 1098 | 1109 | \\ _ = @typeInfo(@This()).Struct.decls[0]; |
| ... | ... | @@ -1101,7 +1112,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1101 | 1112 | "tmp.zig:1:11: error: use of undeclared identifier 'B'", |
| 1102 | 1113 | }); |
| 1103 | 1114 | |
| 1104 | | cases.addTest("reject extern function definitions with body", |
| 1115 | ctx.testErrStage1("reject extern function definitions with body", |
| 1105 | 1116 | \\extern "c" fn definitelyNotInLibC(a: i32, b: i32) i32 { |
| 1106 | 1117 | \\ return a + b; |
| 1107 | 1118 | \\} |
| ... | ... | @@ -1109,7 +1120,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1109 | 1120 | "tmp.zig:1:1: error: extern functions have no body", |
| 1110 | 1121 | }); |
| 1111 | 1122 | |
| 1112 | | cases.addTest("duplicate field in anonymous struct literal", |
| 1123 | ctx.testErrStage1("duplicate field in anonymous struct literal", |
| 1113 | 1124 | \\export fn entry() void { |
| 1114 | 1125 | \\ const anon = .{ |
| 1115 | 1126 | \\ .inner = .{ |
| ... | ... | @@ -1119,31 +1130,33 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1119 | 1130 | \\ .a = .{}, |
| 1120 | 1131 | \\ }, |
| 1121 | 1132 | \\ }; |
| 1133 | \\ _ = anon; |
| 1122 | 1134 | \\} |
| 1123 | 1135 | , &[_][]const u8{ |
| 1124 | 1136 | "tmp.zig:7:13: error: duplicate field", |
| 1125 | 1137 | "tmp.zig:4:13: note: other field here", |
| 1126 | 1138 | }); |
| 1127 | 1139 | |
| 1128 | | cases.addTest("type mismatch in C prototype with varargs", |
| 1140 | ctx.testErrStage1("type mismatch in C prototype with varargs", |
| 1129 | 1141 | \\const fn_ty = ?fn ([*c]u8, ...) callconv(.C) void; |
| 1130 | 1142 | \\extern fn fn_decl(fmt: [*:0]u8, ...) void; |
| 1131 | 1143 | \\ |
| 1132 | 1144 | \\export fn main() void { |
| 1133 | 1145 | \\ const x: fn_ty = fn_decl; |
| 1146 | \\ _ = x; |
| 1134 | 1147 | \\} |
| 1135 | 1148 | , &[_][]const u8{ |
| 1136 | 1149 | "tmp.zig:5:22: error: expected type 'fn([*c]u8, ...) callconv(.C) void', found 'fn([*:0]u8, ...) callconv(.C) void'", |
| 1137 | 1150 | }); |
| 1138 | 1151 | |
| 1139 | | cases.addTest("dependency loop in top-level decl with @TypeInfo when accessing the decls", |
| 1152 | ctx.testErrStage1("dependency loop in top-level decl with @TypeInfo when accessing the decls", |
| 1140 | 1153 | \\export const foo = @typeInfo(@This()).Struct.decls; |
| 1141 | 1154 | , &[_][]const u8{ |
| 1142 | 1155 | "tmp.zig:1:20: error: dependency loop detected", |
| 1143 | 1156 | "tmp.zig:1:45: note: referenced here", |
| 1144 | 1157 | }); |
| 1145 | 1158 | |
| 1146 | | cases.add("function call assigned to incorrect type", |
| 1159 | ctx.objErrStage1("function call assigned to incorrect type", |
| 1147 | 1160 | \\export fn entry() void { |
| 1148 | 1161 | \\ var arr: [4]f32 = undefined; |
| 1149 | 1162 | \\ arr = concat(); |
| ... | ... | @@ -1155,7 +1168,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1155 | 1168 | "tmp.zig:3:17: error: expected type '[4]f32', found '[16]f32'", |
| 1156 | 1169 | }); |
| 1157 | 1170 | |
| 1158 | | cases.add("generic function call assigned to incorrect type", |
| 1171 | ctx.objErrStage1("generic function call assigned to incorrect type", |
| 1159 | 1172 | \\pub export fn entry() void { |
| 1160 | 1173 | \\ var res: []i32 = undefined; |
| 1161 | 1174 | \\ res = myAlloc(i32); |
| ... | ... | @@ -1167,12 +1180,25 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1167 | 1180 | "tmp.zig:3:18: error: expected type '[]i32', found 'anyerror!i32", |
| 1168 | 1181 | }); |
| 1169 | 1182 | |
| 1170 | | cases.addTest("non-exhaustive enums", |
| 1183 | ctx.testErrStage1("non-exhaustive enum marker assigned a value", |
| 1171 | 1184 | \\const A = enum { |
| 1172 | 1185 | \\ a, |
| 1173 | 1186 | \\ b, |
| 1174 | 1187 | \\ _ = 1, |
| 1175 | 1188 | \\}; |
| 1189 | \\const B = enum { |
| 1190 | \\ a, |
| 1191 | \\ b, |
| 1192 | \\ _, |
| 1193 | \\}; |
| 1194 | \\comptime { _ = A; _ = B; } |
| 1195 | , &[_][]const u8{ |
| 1196 | "tmp.zig:4:9: error: '_' is used to mark an enum as non-exhaustive and cannot be assigned a value", |
| 1197 | "tmp.zig:6:11: error: non-exhaustive enum missing integer tag type", |
| 1198 | "tmp.zig:9:5: note: marked non-exhaustive here", |
| 1199 | }); |
| 1200 | |
| 1201 | ctx.testErrStage1("non-exhaustive enums", |
| 1176 | 1202 | \\const B = enum(u1) { |
| 1177 | 1203 | \\ a, |
| 1178 | 1204 | \\ _, |
| ... | ... | @@ -1184,18 +1210,15 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1184 | 1210 | \\ _, |
| 1185 | 1211 | \\}; |
| 1186 | 1212 | \\pub export fn entry() void { |
| 1187 | | \\ _ = A; |
| 1188 | 1213 | \\ _ = B; |
| 1189 | 1214 | \\ _ = C; |
| 1190 | 1215 | \\} |
| 1191 | 1216 | , &[_][]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", |
| 1217 | "tmp.zig:3:5: error: '_' field of non-exhaustive enum must be last", |
| 1218 | "tmp.zig:6:11: error: non-exhaustive enum specifies every value", |
| 1196 | 1219 | }); |
| 1197 | 1220 | |
| 1198 | | cases.addTest("switching with non-exhaustive enums", |
| 1221 | ctx.testErrStage1("switching with non-exhaustive enums", |
| 1199 | 1222 | \\const E = enum(u8) { |
| 1200 | 1223 | \\ a, |
| 1201 | 1224 | \\ b, |
| ... | ... | @@ -1228,7 +1251,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1228 | 1251 | "tmp.zig:21:5: error: `_` prong not allowed when switching on tagged union", |
| 1229 | 1252 | }); |
| 1230 | 1253 | |
| 1231 | | cases.add("switch expression - unreachable else prong (bool)", |
| 1254 | ctx.objErrStage1("switch expression - unreachable else prong (bool)", |
| 1232 | 1255 | \\fn foo(x: bool) void { |
| 1233 | 1256 | \\ switch (x) { |
| 1234 | 1257 | \\ true => {}, |
| ... | ... | @@ -1241,7 +1264,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1241 | 1264 | "tmp.zig:5:9: error: unreachable else prong, all cases already handled", |
| 1242 | 1265 | }); |
| 1243 | 1266 | |
| 1244 | | cases.add("switch expression - unreachable else prong (u1)", |
| 1267 | ctx.objErrStage1("switch expression - unreachable else prong (u1)", |
| 1245 | 1268 | \\fn foo(x: u1) void { |
| 1246 | 1269 | \\ switch (x) { |
| 1247 | 1270 | \\ 0 => {}, |
| ... | ... | @@ -1254,7 +1277,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1254 | 1277 | "tmp.zig:5:9: error: unreachable else prong, all cases already handled", |
| 1255 | 1278 | }); |
| 1256 | 1279 | |
| 1257 | | cases.add("switch expression - unreachable else prong (u2)", |
| 1280 | ctx.objErrStage1("switch expression - unreachable else prong (u2)", |
| 1258 | 1281 | \\fn foo(x: u2) void { |
| 1259 | 1282 | \\ switch (x) { |
| 1260 | 1283 | \\ 0 => {}, |
| ... | ... | @@ -1269,7 +1292,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1269 | 1292 | "tmp.zig:7:9: error: unreachable else prong, all cases already handled", |
| 1270 | 1293 | }); |
| 1271 | 1294 | |
| 1272 | | cases.add("switch expression - unreachable else prong (range u8)", |
| 1295 | ctx.objErrStage1("switch expression - unreachable else prong (range u8)", |
| 1273 | 1296 | \\fn foo(x: u8) void { |
| 1274 | 1297 | \\ switch (x) { |
| 1275 | 1298 | \\ 0 => {}, |
| ... | ... | @@ -1285,7 +1308,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1285 | 1308 | "tmp.zig:8:9: error: unreachable else prong, all cases already handled", |
| 1286 | 1309 | }); |
| 1287 | 1310 | |
| 1288 | | cases.add("switch expression - unreachable else prong (range i8)", |
| 1311 | ctx.objErrStage1("switch expression - unreachable else prong (range i8)", |
| 1289 | 1312 | \\fn foo(x: i8) void { |
| 1290 | 1313 | \\ switch (x) { |
| 1291 | 1314 | \\ -128...0 => {}, |
| ... | ... | @@ -1301,7 +1324,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1301 | 1324 | "tmp.zig:8:9: error: unreachable else prong, all cases already handled", |
| 1302 | 1325 | }); |
| 1303 | 1326 | |
| 1304 | | cases.add("switch expression - unreachable else prong (enum)", |
| 1327 | ctx.objErrStage1("switch expression - unreachable else prong (enum)", |
| 1305 | 1328 | \\const TestEnum = enum{ T1, T2 }; |
| 1306 | 1329 | \\ |
| 1307 | 1330 | \\fn err(x: u8) TestEnum { |
| ... | ... | @@ -1324,7 +1347,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1324 | 1347 | "tmp.zig:14:9: error: unreachable else prong, all cases already handled", |
| 1325 | 1348 | }); |
| 1326 | 1349 | |
| 1327 | | cases.addTest("@export with empty name string", |
| 1350 | ctx.testErrStage1("@export with empty name string", |
| 1328 | 1351 | \\pub export fn entry() void { } |
| 1329 | 1352 | \\comptime { |
| 1330 | 1353 | \\ @export(entry, .{ .name = "" }); |
| ... | ... | @@ -1333,7 +1356,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1333 | 1356 | "tmp.zig:3:5: error: exported symbol name cannot be empty", |
| 1334 | 1357 | }); |
| 1335 | 1358 | |
| 1336 | | cases.addTest("switch ranges endpoints are validated", |
| 1359 | ctx.testErrStage1("switch ranges endpoints are validated", |
| 1337 | 1360 | \\pub export fn entry() void { |
| 1338 | 1361 | \\ var x: i32 = 0; |
| 1339 | 1362 | \\ switch (x) { |
| ... | ... | @@ -1347,16 +1370,16 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1347 | 1370 | "tmp.zig:5:9: error: range start value is greater than the end value", |
| 1348 | 1371 | }); |
| 1349 | 1372 | |
| 1350 | | cases.addTest("errors in for loop bodies are propagated", |
| 1373 | ctx.testErrStage1("errors in for loop bodies are propagated", |
| 1351 | 1374 | \\pub export fn entry() void { |
| 1352 | 1375 | \\ var arr: [100]u8 = undefined; |
| 1353 | 1376 | \\ for (arr) |bits| _ = @popCount(bits); |
| 1354 | 1377 | \\} |
| 1355 | 1378 | , &[_][]const u8{ |
| 1356 | | "tmp.zig:3:26: error: expected 2 argument(s), found 1", |
| 1379 | "tmp.zig:3:26: error: expected 2 arguments, found 1", |
| 1357 | 1380 | }); |
| 1358 | 1381 | |
| 1359 | | cases.addTest("@call rejects non comptime-known fn - always_inline", |
| 1382 | ctx.testErrStage1("@call rejects non comptime-known fn - always_inline", |
| 1360 | 1383 | \\pub export fn entry() void { |
| 1361 | 1384 | \\ var call_me: fn () void = undefined; |
| 1362 | 1385 | \\ @call(.{ .modifier = .always_inline }, call_me, .{}); |
| ... | ... | @@ -1365,7 +1388,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1365 | 1388 | "tmp.zig:3:5: error: the specified modifier requires a comptime-known function", |
| 1366 | 1389 | }); |
| 1367 | 1390 | |
| 1368 | | cases.addTest("@call rejects non comptime-known fn - compile_time", |
| 1391 | ctx.testErrStage1("@call rejects non comptime-known fn - compile_time", |
| 1369 | 1392 | \\pub export fn entry() void { |
| 1370 | 1393 | \\ var call_me: fn () void = undefined; |
| 1371 | 1394 | \\ @call(.{ .modifier = .compile_time }, call_me, .{}); |
| ... | ... | @@ -1374,19 +1397,20 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1374 | 1397 | "tmp.zig:3:5: error: the specified modifier requires a comptime-known function", |
| 1375 | 1398 | }); |
| 1376 | 1399 | |
| 1377 | | cases.addTest("error in struct initializer doesn't crash the compiler", |
| 1400 | ctx.testErrStage1("error in struct initializer doesn't crash the compiler", |
| 1378 | 1401 | \\pub export fn entry() void { |
| 1379 | 1402 | \\ const bitfield = struct { |
| 1380 | 1403 | \\ e: u8, |
| 1381 | 1404 | \\ e: u8, |
| 1382 | 1405 | \\ }; |
| 1383 | 1406 | \\ var a = .{@sizeOf(bitfield)}; |
| 1407 | \\ _ = a; |
| 1384 | 1408 | \\} |
| 1385 | 1409 | , &[_][]const u8{ |
| 1386 | 1410 | "tmp.zig:4:9: error: duplicate struct field: 'e'", |
| 1387 | 1411 | }); |
| 1388 | 1412 | |
| 1389 | | cases.addTest("repeated invalid field access to generic function returning type crashes compiler. #2655", |
| 1413 | ctx.testErrStage1("repeated invalid field access to generic function returning type crashes compiler. #2655", |
| 1390 | 1414 | \\pub fn A() type { |
| 1391 | 1415 | \\ return Q; |
| 1392 | 1416 | \\} |
| ... | ... | @@ -1398,15 +1422,16 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1398 | 1422 | "tmp.zig:2:12: error: use of undeclared identifier 'Q'", |
| 1399 | 1423 | }); |
| 1400 | 1424 | |
| 1401 | | cases.add("bitCast to enum type", |
| 1425 | ctx.objErrStage1("bitCast to enum type", |
| 1402 | 1426 | \\export fn entry() void { |
| 1403 | 1427 | \\ const y = @bitCast(enum(u32) { a, b }, @as(u32, 3)); |
| 1428 | \\ _ = y; |
| 1404 | 1429 | \\} |
| 1405 | 1430 | , &[_][]const u8{ |
| 1406 | 1431 | "tmp.zig:2:24: error: cannot cast a value of type 'y'", |
| 1407 | 1432 | }); |
| 1408 | 1433 | |
| 1409 | | cases.add("comparing against undefined produces undefined value", |
| 1434 | ctx.objErrStage1("comparing against undefined produces undefined value", |
| 1410 | 1435 | \\export fn entry() void { |
| 1411 | 1436 | \\ if (2 == undefined) {} |
| 1412 | 1437 | \\} |
| ... | ... | @@ -1414,17 +1439,18 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1414 | 1439 | "tmp.zig:2:11: error: use of undefined value here causes undefined behavior", |
| 1415 | 1440 | }); |
| 1416 | 1441 | |
| 1417 | | cases.add("comptime ptrcast of zero-sized type", |
| 1442 | ctx.objErrStage1("comptime ptrcast of zero-sized type", |
| 1418 | 1443 | \\fn foo() void { |
| 1419 | 1444 | \\ const node: struct {} = undefined; |
| 1420 | 1445 | \\ const vla_ptr = @ptrCast([*]const u8, &node); |
| 1446 | \\ _ = vla_ptr; |
| 1421 | 1447 | \\} |
| 1422 | 1448 | \\comptime { foo(); } |
| 1423 | 1449 | , &[_][]const u8{ |
| 1424 | 1450 | "tmp.zig:3:21: error: '*const struct:2:17' and '[*]const u8' do not have the same in-memory representation", |
| 1425 | 1451 | }); |
| 1426 | 1452 | |
| 1427 | | cases.add("slice sentinel mismatch", |
| 1453 | ctx.objErrStage1("slice sentinel mismatch", |
| 1428 | 1454 | \\fn foo() [:0]u8 { |
| 1429 | 1455 | \\ var x: []u8 = undefined; |
| 1430 | 1456 | \\ return x; |
| ... | ... | @@ -1435,7 +1461,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1435 | 1461 | "tmp.zig:3:12: note: destination pointer requires a terminating '0' sentinel", |
| 1436 | 1462 | }); |
| 1437 | 1463 | |
| 1438 | | cases.add("cmpxchg with float", |
| 1464 | ctx.objErrStage1("cmpxchg with float", |
| 1439 | 1465 | \\export fn entry() void { |
| 1440 | 1466 | \\ var x: f32 = 0; |
| 1441 | 1467 | \\ _ = @cmpxchgWeak(f32, &x, 1, 2, .SeqCst, .SeqCst); |
| ... | ... | @@ -1444,7 +1470,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1444 | 1470 | "tmp.zig:3:22: error: expected bool, integer, enum or pointer type, found 'f32'", |
| 1445 | 1471 | }); |
| 1446 | 1472 | |
| 1447 | | cases.add("atomicrmw with float op not .Xchg, .Add or .Sub", |
| 1473 | ctx.objErrStage1("atomicrmw with float op not .Xchg, .Add or .Sub", |
| 1448 | 1474 | \\export fn entry() void { |
| 1449 | 1475 | \\ var x: f32 = 0; |
| 1450 | 1476 | \\ _ = @atomicRmw(f32, &x, .And, 2, .SeqCst); |
| ... | ... | @@ -1453,15 +1479,16 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1453 | 1479 | "tmp.zig:3:29: error: @atomicRmw with float only allowed with .Xchg, .Add and .Sub", |
| 1454 | 1480 | }); |
| 1455 | 1481 | |
| 1456 | | cases.add("intToPtr with misaligned address", |
| 1482 | ctx.objErrStage1("intToPtr with misaligned address", |
| 1457 | 1483 | \\pub fn main() void { |
| 1458 | 1484 | \\ var y = @intToPtr([*]align(4) u8, 5); |
| 1485 | \\ _ = y; |
| 1459 | 1486 | \\} |
| 1460 | 1487 | , &[_][]const u8{ |
| 1461 | 1488 | "tmp.zig:2:13: error: pointer type '[*]align(4) u8' requires aligned address", |
| 1462 | 1489 | }); |
| 1463 | 1490 | |
| 1464 | | cases.add("invalid float literal", |
| 1491 | ctx.objErrStage1("invalid float literal", |
| 1465 | 1492 | \\const std = @import("std"); |
| 1466 | 1493 | \\ |
| 1467 | 1494 | \\pub fn main() void { |
| ... | ... | @@ -1473,170 +1500,190 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1473 | 1500 | "tmp.zig:5:29: error: invalid token: '.'", |
| 1474 | 1501 | }); |
| 1475 | 1502 | |
| 1476 | | cases.add("invalid exponent in float literal - 1", |
| 1503 | ctx.objErrStage1("invalid exponent in float literal - 1", |
| 1477 | 1504 | \\fn main() void { |
| 1478 | 1505 | \\ var bad: f128 = 0x1.0p1ab1; |
| 1506 | \\ _ = bad; |
| 1479 | 1507 | \\} |
| 1480 | 1508 | , &[_][]const u8{ |
| 1481 | 1509 | "tmp.zig:2:28: error: invalid character: 'a'", |
| 1482 | 1510 | }); |
| 1483 | 1511 | |
| 1484 | | cases.add("invalid exponent in float literal - 2", |
| 1512 | ctx.objErrStage1("invalid exponent in float literal - 2", |
| 1485 | 1513 | \\fn main() void { |
| 1486 | 1514 | \\ var bad: f128 = 0x1.0p50F; |
| 1515 | \\ _ = bad; |
| 1487 | 1516 | \\} |
| 1488 | 1517 | , &[_][]const u8{ |
| 1489 | 1518 | "tmp.zig:2:29: error: invalid character: 'F'", |
| 1490 | 1519 | }); |
| 1491 | 1520 | |
| 1492 | | cases.add("invalid underscore placement in float literal - 1", |
| 1521 | ctx.objErrStage1("invalid underscore placement in float literal - 1", |
| 1493 | 1522 | \\fn main() void { |
| 1494 | 1523 | \\ var bad: f128 = 0._0; |
| 1524 | \\ _ = bad; |
| 1495 | 1525 | \\} |
| 1496 | 1526 | , &[_][]const u8{ |
| 1497 | 1527 | "tmp.zig:2:23: error: invalid character: '_'", |
| 1498 | 1528 | }); |
| 1499 | 1529 | |
| 1500 | | cases.add("invalid underscore placement in float literal - 2", |
| 1530 | ctx.objErrStage1("invalid underscore placement in float literal - 2", |
| 1501 | 1531 | \\fn main() void { |
| 1502 | 1532 | \\ var bad: f128 = 0_.0; |
| 1533 | \\ _ = bad; |
| 1503 | 1534 | \\} |
| 1504 | 1535 | , &[_][]const u8{ |
| 1505 | 1536 | "tmp.zig:2:23: error: invalid character: '.'", |
| 1506 | 1537 | }); |
| 1507 | 1538 | |
| 1508 | | cases.add("invalid underscore placement in float literal - 3", |
| 1539 | ctx.objErrStage1("invalid underscore placement in float literal - 3", |
| 1509 | 1540 | \\fn main() void { |
| 1510 | 1541 | \\ var bad: f128 = 0.0_; |
| 1542 | \\ _ = bad; |
| 1511 | 1543 | \\} |
| 1512 | 1544 | , &[_][]const u8{ |
| 1513 | 1545 | "tmp.zig:2:25: error: invalid character: ';'", |
| 1514 | 1546 | }); |
| 1515 | 1547 | |
| 1516 | | cases.add("invalid underscore placement in float literal - 4", |
| 1548 | ctx.objErrStage1("invalid underscore placement in float literal - 4", |
| 1517 | 1549 | \\fn main() void { |
| 1518 | 1550 | \\ var bad: f128 = 1.0e_1; |
| 1551 | \\ _ = bad; |
| 1519 | 1552 | \\} |
| 1520 | 1553 | , &[_][]const u8{ |
| 1521 | 1554 | "tmp.zig:2:25: error: invalid character: '_'", |
| 1522 | 1555 | }); |
| 1523 | 1556 | |
| 1524 | | cases.add("invalid underscore placement in float literal - 5", |
| 1557 | ctx.objErrStage1("invalid underscore placement in float literal - 5", |
| 1525 | 1558 | \\fn main() void { |
| 1526 | 1559 | \\ var bad: f128 = 1.0e+_1; |
| 1560 | \\ _ = bad; |
| 1527 | 1561 | \\} |
| 1528 | 1562 | , &[_][]const u8{ |
| 1529 | 1563 | "tmp.zig:2:26: error: invalid character: '_'", |
| 1530 | 1564 | }); |
| 1531 | 1565 | |
| 1532 | | cases.add("invalid underscore placement in float literal - 6", |
| 1566 | ctx.objErrStage1("invalid underscore placement in float literal - 6", |
| 1533 | 1567 | \\fn main() void { |
| 1534 | 1568 | \\ var bad: f128 = 1.0e-_1; |
| 1569 | \\ _ = bad; |
| 1535 | 1570 | \\} |
| 1536 | 1571 | , &[_][]const u8{ |
| 1537 | 1572 | "tmp.zig:2:26: error: invalid character: '_'", |
| 1538 | 1573 | }); |
| 1539 | 1574 | |
| 1540 | | cases.add("invalid underscore placement in float literal - 7", |
| 1575 | ctx.objErrStage1("invalid underscore placement in float literal - 7", |
| 1541 | 1576 | \\fn main() void { |
| 1542 | 1577 | \\ var bad: f128 = 1.0e-1_; |
| 1578 | \\ _ = bad; |
| 1543 | 1579 | \\} |
| 1544 | 1580 | , &[_][]const u8{ |
| 1545 | 1581 | "tmp.zig:2:28: error: invalid character: ';'", |
| 1546 | 1582 | }); |
| 1547 | 1583 | |
| 1548 | | cases.add("invalid underscore placement in float literal - 9", |
| 1584 | ctx.objErrStage1("invalid underscore placement in float literal - 9", |
| 1549 | 1585 | \\fn main() void { |
| 1550 | 1586 | \\ var bad: f128 = 1__0.0e-1; |
| 1587 | \\ _ = bad; |
| 1551 | 1588 | \\} |
| 1552 | 1589 | , &[_][]const u8{ |
| 1553 | 1590 | "tmp.zig:2:23: error: invalid character: '_'", |
| 1554 | 1591 | }); |
| 1555 | 1592 | |
| 1556 | | cases.add("invalid underscore placement in float literal - 10", |
| 1593 | ctx.objErrStage1("invalid underscore placement in float literal - 10", |
| 1557 | 1594 | \\fn main() void { |
| 1558 | 1595 | \\ var bad: f128 = 1.0__0e-1; |
| 1596 | \\ _ = bad; |
| 1559 | 1597 | \\} |
| 1560 | 1598 | , &[_][]const u8{ |
| 1561 | 1599 | "tmp.zig:2:25: error: invalid character: '_'", |
| 1562 | 1600 | }); |
| 1563 | 1601 | |
| 1564 | | cases.add("invalid underscore placement in float literal - 11", |
| 1602 | ctx.objErrStage1("invalid underscore placement in float literal - 11", |
| 1565 | 1603 | \\fn main() void { |
| 1566 | 1604 | \\ var bad: f128 = 1.0e-1__0; |
| 1605 | \\ _ = bad; |
| 1567 | 1606 | \\} |
| 1568 | 1607 | , &[_][]const u8{ |
| 1569 | 1608 | "tmp.zig:2:28: error: invalid character: '_'", |
| 1570 | 1609 | }); |
| 1571 | 1610 | |
| 1572 | | cases.add("invalid underscore placement in float literal - 12", |
| 1611 | ctx.objErrStage1("invalid underscore placement in float literal - 12", |
| 1573 | 1612 | \\fn main() void { |
| 1574 | 1613 | \\ var bad: f128 = 0_x0.0; |
| 1614 | \\ _ = bad; |
| 1575 | 1615 | \\} |
| 1576 | 1616 | , &[_][]const u8{ |
| 1577 | 1617 | "tmp.zig:2:23: error: invalid character: 'x'", |
| 1578 | 1618 | }); |
| 1579 | 1619 | |
| 1580 | | cases.add("invalid underscore placement in float literal - 13", |
| 1620 | ctx.objErrStage1("invalid underscore placement in float literal - 13", |
| 1581 | 1621 | \\fn main() void { |
| 1582 | 1622 | \\ var bad: f128 = 0x_0.0; |
| 1623 | \\ _ = bad; |
| 1583 | 1624 | \\} |
| 1584 | 1625 | , &[_][]const u8{ |
| 1585 | 1626 | "tmp.zig:2:23: error: invalid character: '_'", |
| 1586 | 1627 | }); |
| 1587 | 1628 | |
| 1588 | | cases.add("invalid underscore placement in float literal - 14", |
| 1629 | ctx.objErrStage1("invalid underscore placement in float literal - 14", |
| 1589 | 1630 | \\fn main() void { |
| 1590 | 1631 | \\ var bad: f128 = 0x0.0_p1; |
| 1632 | \\ _ = bad; |
| 1591 | 1633 | \\} |
| 1592 | 1634 | , &[_][]const u8{ |
| 1593 | 1635 | "tmp.zig:2:27: error: invalid character: 'p'", |
| 1594 | 1636 | }); |
| 1595 | 1637 | |
| 1596 | | cases.add("invalid underscore placement in int literal - 1", |
| 1638 | ctx.objErrStage1("invalid underscore placement in int literal - 1", |
| 1597 | 1639 | \\fn main() void { |
| 1598 | 1640 | \\ var bad: u128 = 0010_; |
| 1641 | \\ _ = bad; |
| 1599 | 1642 | \\} |
| 1600 | 1643 | , &[_][]const u8{ |
| 1601 | 1644 | "tmp.zig:2:26: error: invalid character: ';'", |
| 1602 | 1645 | }); |
| 1603 | 1646 | |
| 1604 | | cases.add("invalid underscore placement in int literal - 2", |
| 1647 | ctx.objErrStage1("invalid underscore placement in int literal - 2", |
| 1605 | 1648 | \\fn main() void { |
| 1606 | 1649 | \\ var bad: u128 = 0b0010_; |
| 1650 | \\ _ = bad; |
| 1607 | 1651 | \\} |
| 1608 | 1652 | , &[_][]const u8{ |
| 1609 | 1653 | "tmp.zig:2:28: error: invalid character: ';'", |
| 1610 | 1654 | }); |
| 1611 | 1655 | |
| 1612 | | cases.add("invalid underscore placement in int literal - 3", |
| 1656 | ctx.objErrStage1("invalid underscore placement in int literal - 3", |
| 1613 | 1657 | \\fn main() void { |
| 1614 | 1658 | \\ var bad: u128 = 0o0010_; |
| 1659 | \\ _ = bad; |
| 1615 | 1660 | \\} |
| 1616 | 1661 | , &[_][]const u8{ |
| 1617 | 1662 | "tmp.zig:2:28: error: invalid character: ';'", |
| 1618 | 1663 | }); |
| 1619 | 1664 | |
| 1620 | | cases.add("invalid underscore placement in int literal - 4", |
| 1665 | ctx.objErrStage1("invalid underscore placement in int literal - 4", |
| 1621 | 1666 | \\fn main() void { |
| 1622 | 1667 | \\ var bad: u128 = 0x0010_; |
| 1668 | \\ _ = bad; |
| 1623 | 1669 | \\} |
| 1624 | 1670 | , &[_][]const u8{ |
| 1625 | 1671 | "tmp.zig:2:28: error: invalid character: ';'", |
| 1626 | 1672 | }); |
| 1627 | 1673 | |
| 1628 | | cases.add("comptime struct field, no init value", |
| 1674 | ctx.objErrStage1("comptime struct field, no init value", |
| 1629 | 1675 | \\const Foo = struct { |
| 1630 | 1676 | \\ comptime b: i32, |
| 1631 | 1677 | \\}; |
| 1632 | 1678 | \\export fn entry() void { |
| 1633 | 1679 | \\ var f: Foo = undefined; |
| 1680 | \\ _ = f; |
| 1634 | 1681 | \\} |
| 1635 | 1682 | , &[_][]const u8{ |
| 1636 | | "tmp.zig:2:5: error: comptime struct field missing initialization value", |
| 1683 | "tmp.zig:2:5: error: comptime field without default initialization value", |
| 1637 | 1684 | }); |
| 1638 | 1685 | |
| 1639 | | cases.add("bad usage of @call", |
| 1686 | ctx.objErrStage1("bad usage of @call", |
| 1640 | 1687 | \\export fn entry1() void { |
| 1641 | 1688 | \\ @call(.{}, foo, {}); |
| 1642 | 1689 | \\} |
| ... | ... | @@ -1665,20 +1712,26 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1665 | 1712 | "tmp.zig:15:5: error: the specified modifier requires a comptime-known function", |
| 1666 | 1713 | }); |
| 1667 | 1714 | |
| 1668 | | cases.add("exported async function", |
| 1715 | ctx.objErrStage1("exported async function", |
| 1669 | 1716 | \\export fn foo() callconv(.Async) void {} |
| 1670 | 1717 | , &[_][]const u8{ |
| 1671 | 1718 | "tmp.zig:1:1: error: exported function cannot be async", |
| 1672 | 1719 | }); |
| 1673 | 1720 | |
| 1674 | | cases.addExe("main missing name", |
| 1721 | ctx.exeErrStage1("main missing name", |
| 1675 | 1722 | \\pub fn (main) void {} |
| 1676 | 1723 | , &[_][]const u8{ |
| 1677 | 1724 | "tmp.zig:1:5: error: missing function name", |
| 1678 | 1725 | }); |
| 1679 | 1726 | |
| 1680 | | cases.addCase(x: { |
| 1681 | | var tc = cases.create("call with new stack on unsupported target", |
| 1727 | { |
| 1728 | const case = ctx.obj("call with new stack on unsupported target", .{ |
| 1729 | .cpu_arch = .wasm32, |
| 1730 | .os_tag = .wasi, |
| 1731 | .abi = .none, |
| 1732 | }); |
| 1733 | case.backend = .stage1; |
| 1734 | case.addError( |
| 1682 | 1735 | \\var buf: [10]u8 align(16) = undefined; |
| 1683 | 1736 | \\export fn entry() void { |
| 1684 | 1737 | \\ @call(.{.stack = &buf}, foo, .{}); |
| ... | ... | @@ -1687,17 +1740,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1687 | 1740 | , &[_][]const u8{ |
| 1688 | 1741 | "tmp.zig:3:5: error: target arch 'wasm32' does not support calling with a new stack", |
| 1689 | 1742 | }); |
| 1690 | | tc.target = std.zig.CrossTarget{ |
| 1691 | | .cpu_arch = .wasm32, |
| 1692 | | .os_tag = .wasi, |
| 1693 | | .abi = .none, |
| 1694 | | }; |
| 1695 | | break :x tc; |
| 1696 | | }); |
| 1743 | } |
| 1697 | 1744 | |
| 1698 | 1745 | // Note: One of the error messages here is backwards. It would be nice to fix, but that's not |
| 1699 | 1746 | // going to stop me from merging this branch which fixes a bunch of other stuff. |
| 1700 | | cases.add("incompatible sentinels", |
| 1747 | ctx.objErrStage1("incompatible sentinels", |
| 1701 | 1748 | \\export fn entry1(ptr: [*:255]u8) [*:0]u8 { |
| 1702 | 1749 | \\ return ptr; |
| 1703 | 1750 | \\} |
| ... | ... | @@ -1706,9 +1753,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1706 | 1753 | \\} |
| 1707 | 1754 | \\export fn entry3() void { |
| 1708 | 1755 | \\ var array: [2:0]u8 = [_:255]u8{1, 2}; |
| 1756 | \\ _ = array; |
| 1709 | 1757 | \\} |
| 1710 | 1758 | \\export fn entry4() void { |
| 1711 | 1759 | \\ var array: [2:0]u8 = [_]u8{1, 2}; |
| 1760 | \\ _ = array; |
| 1712 | 1761 | \\} |
| 1713 | 1762 | , &[_][]const u8{ |
| 1714 | 1763 | "tmp.zig:2:12: error: expected type '[*:0]u8', found '[*:255]u8'", |
| ... | ... | @@ -1718,11 +1767,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1718 | 1767 | |
| 1719 | 1768 | "tmp.zig:8:35: error: expected type '[2:255]u8', found '[2:0]u8'", |
| 1720 | 1769 | "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", |
| 1770 | "tmp.zig:12:31: error: expected type '[2:0]u8', found '[2]u8'", |
| 1771 | "tmp.zig:12:31: note: destination array requires a terminating '0' sentinel", |
| 1723 | 1772 | }); |
| 1724 | 1773 | |
| 1725 | | cases.add("empty switch on an integer", |
| 1774 | ctx.objErrStage1("empty switch on an integer", |
| 1726 | 1775 | \\export fn entry() void { |
| 1727 | 1776 | \\ var x: u32 = 0; |
| 1728 | 1777 | \\ switch(x) {} |
| ... | ... | @@ -1731,7 +1780,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1731 | 1780 | "tmp.zig:3:5: error: switch must handle all possibilities", |
| 1732 | 1781 | }); |
| 1733 | 1782 | |
| 1734 | | cases.add("incorrect return type", |
| 1783 | ctx.objErrStage1("incorrect return type", |
| 1735 | 1784 | \\ pub export fn entry() void{ |
| 1736 | 1785 | \\ _ = foo(); |
| 1737 | 1786 | \\ } |
| ... | ... | @@ -1751,12 +1800,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1751 | 1800 | "tmp.zig:8:16: error: expected type 'A', found 'B'", |
| 1752 | 1801 | }); |
| 1753 | 1802 | |
| 1754 | | cases.add("regression test #2980: base type u32 is not type checked properly when assigning a value within a struct", |
| 1803 | ctx.objErrStage1("regression test #2980: base type u32 is not type checked properly when assigning a value within a struct", |
| 1755 | 1804 | \\const Foo = struct { |
| 1756 | 1805 | \\ ptr: ?*usize, |
| 1757 | 1806 | \\ uval: u32, |
| 1758 | 1807 | \\}; |
| 1759 | 1808 | \\fn get_uval(x: u32) !u32 { |
| 1809 | \\ _ = x; |
| 1760 | 1810 | \\ return error.NotFound; |
| 1761 | 1811 | \\} |
| 1762 | 1812 | \\export fn entry() void { |
| ... | ... | @@ -1764,12 +1814,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1764 | 1814 | \\ .ptr = null, |
| 1765 | 1815 | \\ .uval = get_uval(42), |
| 1766 | 1816 | \\ }; |
| 1817 | \\ _ = afoo; |
| 1767 | 1818 | \\} |
| 1768 | 1819 | , &[_][]const u8{ |
| 1769 | | "tmp.zig:11:25: error: expected type 'u32', found '@typeInfo(@typeInfo(@TypeOf(get_uval)).Fn.return_type.?).ErrorUnion.error_set!u32'", |
| 1820 | "tmp.zig:12:25: error: expected type 'u32', found '@typeInfo(@typeInfo(@TypeOf(get_uval)).Fn.return_type.?).ErrorUnion.error_set!u32'", |
| 1770 | 1821 | }); |
| 1771 | 1822 | |
| 1772 | | cases.add("assigning to struct or union fields that are not optionals with a function that returns an optional", |
| 1823 | ctx.objErrStage1("assigning to struct or union fields that are not optionals with a function that returns an optional", |
| 1773 | 1824 | \\fn maybe(is: bool) ?u8 { |
| 1774 | 1825 | \\ if (is) return @as(u8, 10) else return null; |
| 1775 | 1826 | \\} |
| ... | ... | @@ -1782,12 +1833,14 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1782 | 1833 | \\export fn entry() void { |
| 1783 | 1834 | \\ var u = U{ .Ye = maybe(false) }; |
| 1784 | 1835 | \\ var s = S{ .num = maybe(false) }; |
| 1836 | \\ _ = u; |
| 1837 | \\ _ = s; |
| 1785 | 1838 | \\} |
| 1786 | 1839 | , &[_][]const u8{ |
| 1787 | 1840 | "tmp.zig:11:27: error: expected type 'u8', found '?u8'", |
| 1788 | 1841 | }); |
| 1789 | 1842 | |
| 1790 | | cases.add("missing result type for phi node", |
| 1843 | ctx.objErrStage1("missing result type for phi node", |
| 1791 | 1844 | \\fn foo() !void { |
| 1792 | 1845 | \\ return anyerror.Foo; |
| 1793 | 1846 | \\} |
| ... | ... | @@ -1798,7 +1851,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1798 | 1851 | "tmp.zig:5:17: error: integer value 0 cannot be coerced to type 'void'", |
| 1799 | 1852 | }); |
| 1800 | 1853 | |
| 1801 | | cases.add("atomicrmw with enum op not .Xchg", |
| 1854 | ctx.objErrStage1("atomicrmw with enum op not .Xchg", |
| 1802 | 1855 | \\export fn entry() void { |
| 1803 | 1856 | \\ const E = enum(u8) { |
| 1804 | 1857 | \\ a, |
| ... | ... | @@ -1813,7 +1866,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1813 | 1866 | "tmp.zig:9:27: error: @atomicRmw with enum only allowed with .Xchg", |
| 1814 | 1867 | }); |
| 1815 | 1868 | |
| 1816 | | cases.add("disallow coercion from non-null-terminated pointer to null-terminated pointer", |
| 1869 | ctx.objErrStage1("disallow coercion from non-null-terminated pointer to null-terminated pointer", |
| 1817 | 1870 | \\extern fn puts(s: [*:0]const u8) c_int; |
| 1818 | 1871 | \\pub fn main() void { |
| 1819 | 1872 | \\ const no_zero_array = [_]u8{'h', 'e', 'l', 'l', 'o'}; |
| ... | ... | @@ -1824,7 +1877,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1824 | 1877 | "tmp.zig:5:14: error: expected type '[*:0]const u8', found '[*]const u8'", |
| 1825 | 1878 | }); |
| 1826 | 1879 | |
| 1827 | | cases.add("atomic orderings of atomicStore Acquire or AcqRel", |
| 1880 | ctx.objErrStage1("atomic orderings of atomicStore Acquire or AcqRel", |
| 1828 | 1881 | \\export fn entry() void { |
| 1829 | 1882 | \\ var x: u32 = 0; |
| 1830 | 1883 | \\ @atomicStore(u32, &x, 1, .Acquire); |
| ... | ... | @@ -1833,7 +1886,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1833 | 1886 | "tmp.zig:3:30: error: @atomicStore atomic ordering must not be Acquire or AcqRel", |
| 1834 | 1887 | }); |
| 1835 | 1888 | |
| 1836 | | cases.add("missing const in slice with nested array type", |
| 1889 | ctx.objErrStage1("missing const in slice with nested array type", |
| 1837 | 1890 | \\const Geo3DTex2D = struct { vertices: [][2]f32 }; |
| 1838 | 1891 | \\pub fn getGeo3DTex2D() Geo3DTex2D { |
| 1839 | 1892 | \\ return Geo3DTex2D{ |
| ... | ... | @@ -1844,12 +1897,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1844 | 1897 | \\} |
| 1845 | 1898 | \\export fn entry() void { |
| 1846 | 1899 | \\ var geo_data = getGeo3DTex2D(); |
| 1900 | \\ _ = geo_data; |
| 1847 | 1901 | \\} |
| 1848 | 1902 | , &[_][]const u8{ |
| 1849 | 1903 | "tmp.zig:4:30: error: array literal requires address-of operator to coerce to slice type '[][2]f32'", |
| 1850 | 1904 | }); |
| 1851 | 1905 | |
| 1852 | | cases.add("slicing of global undefined pointer", |
| 1906 | ctx.objErrStage1("slicing of global undefined pointer", |
| 1853 | 1907 | \\var buf: *[1]u8 = undefined; |
| 1854 | 1908 | \\export fn entry() void { |
| 1855 | 1909 | \\ _ = buf[0..1]; |
| ... | ... | @@ -1858,18 +1912,17 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1858 | 1912 | "tmp.zig:3:12: error: non-zero length slice of undefined pointer", |
| 1859 | 1913 | }); |
| 1860 | 1914 | |
| 1861 | | cases.add("using invalid types in function call raises an error", |
| 1915 | ctx.objErrStage1("using invalid types in function call raises an error", |
| 1862 | 1916 | \\const MenuEffect = enum {}; |
| 1863 | | \\fn func(effect: MenuEffect) void {} |
| 1917 | \\fn func(effect: MenuEffect) void { _ = effect; } |
| 1864 | 1918 | \\export fn entry() void { |
| 1865 | 1919 | \\ func(MenuEffect.ThisDoesNotExist); |
| 1866 | 1920 | \\} |
| 1867 | 1921 | , &[_][]const u8{ |
| 1868 | | "tmp.zig:1:20: error: enums must have 1 or more fields", |
| 1869 | | "tmp.zig:4:20: note: referenced here", |
| 1922 | "tmp.zig:1:20: error: enum declarations must have at least one tag", |
| 1870 | 1923 | }); |
| 1871 | 1924 | |
| 1872 | | cases.add("store vector pointer with unknown runtime index", |
| 1925 | ctx.objErrStage1("store vector pointer with unknown runtime index", |
| 1873 | 1926 | \\export fn entry() void { |
| 1874 | 1927 | \\ var v: @import("std").meta.Vector(4, i32) = [_]i32{ 1, 5, 3, undefined }; |
| 1875 | 1928 | \\ |
| ... | ... | @@ -1884,22 +1937,23 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1884 | 1937 | "tmp.zig:9:8: error: unable to determine vector element index of type '*align(16:0:4:?) i32", |
| 1885 | 1938 | }); |
| 1886 | 1939 | |
| 1887 | | cases.add("load vector pointer with unknown runtime index", |
| 1940 | ctx.objErrStage1("load vector pointer with unknown runtime index", |
| 1888 | 1941 | \\export fn entry() void { |
| 1889 | 1942 | \\ var v: @import("std").meta.Vector(4, i32) = [_]i32{ 1, 5, 3, undefined }; |
| 1890 | 1943 | \\ |
| 1891 | 1944 | \\ var i: u32 = 0; |
| 1892 | 1945 | \\ var x = loadv(&v[i]); |
| 1946 | \\ _ = x; |
| 1893 | 1947 | \\} |
| 1894 | 1948 | \\ |
| 1895 | 1949 | \\fn loadv(ptr: anytype) i32 { |
| 1896 | 1950 | \\ return ptr.*; |
| 1897 | 1951 | \\} |
| 1898 | 1952 | , &[_][]const u8{ |
| 1899 | | "tmp.zig:9:12: error: unable to determine vector element index of type '*align(16:0:4:?) i32", |
| 1953 | "tmp.zig:10:12: error: unable to determine vector element index of type '*align(16:0:4:?) i32", |
| 1900 | 1954 | }); |
| 1901 | 1955 | |
| 1902 | | cases.add("using an unknown len ptr type instead of array", |
| 1956 | ctx.objErrStage1("using an unknown len ptr type instead of array", |
| 1903 | 1957 | \\const resolutions = [*][*]const u8{ |
| 1904 | 1958 | \\ "[320 240 ]", |
| 1905 | 1959 | \\ null, |
| ... | ... | @@ -1911,7 +1965,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1911 | 1965 | "tmp.zig:1:21: error: expected array type or [_], found '[*][*]const u8'", |
| 1912 | 1966 | }); |
| 1913 | 1967 | |
| 1914 | | cases.add("comparison with error union and error value", |
| 1968 | ctx.objErrStage1("comparison with error union and error value", |
| 1915 | 1969 | \\export fn entry() void { |
| 1916 | 1970 | \\ var number_or_error: anyerror!i32 = error.SomethingAwful; |
| 1917 | 1971 | \\ _ = number_or_error == error.SomethingAwful; |
| ... | ... | @@ -1920,7 +1974,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1920 | 1974 | "tmp.zig:3:25: error: operator not allowed for type 'anyerror!i32'", |
| 1921 | 1975 | }); |
| 1922 | 1976 | |
| 1923 | | cases.add("switch with overlapping case ranges", |
| 1977 | ctx.objErrStage1("switch with overlapping case ranges", |
| 1924 | 1978 | \\export fn entry() void { |
| 1925 | 1979 | \\ var q: u8 = 0; |
| 1926 | 1980 | \\ switch (q) { |
| ... | ... | @@ -1932,28 +1986,29 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1932 | 1986 | "tmp.zig:5:9: error: duplicate switch value", |
| 1933 | 1987 | }); |
| 1934 | 1988 | |
| 1935 | | cases.add("invalid optional type in extern struct", |
| 1989 | ctx.objErrStage1("invalid optional type in extern struct", |
| 1936 | 1990 | \\const stroo = extern struct { |
| 1937 | 1991 | \\ moo: ?[*c]u8, |
| 1938 | 1992 | \\}; |
| 1939 | | \\export fn testf(fluff: *stroo) void {} |
| 1993 | \\export fn testf(fluff: *stroo) void { _ = fluff; } |
| 1940 | 1994 | , &[_][]const u8{ |
| 1941 | 1995 | "tmp.zig:2:5: error: extern structs cannot contain fields of type '?[*c]u8'", |
| 1942 | 1996 | }); |
| 1943 | 1997 | |
| 1944 | | cases.add("attempt to negate a non-integer, non-float or non-vector type", |
| 1998 | ctx.objErrStage1("attempt to negate a non-integer, non-float or non-vector type", |
| 1945 | 1999 | \\fn foo() anyerror!u32 { |
| 1946 | 2000 | \\ return 1; |
| 1947 | 2001 | \\} |
| 1948 | 2002 | \\ |
| 1949 | 2003 | \\export fn entry() void { |
| 1950 | 2004 | \\ const x = -foo(); |
| 2005 | \\ _ = x; |
| 1951 | 2006 | \\} |
| 1952 | 2007 | , &[_][]const u8{ |
| 1953 | 2008 | "tmp.zig:6:15: error: negation of type 'anyerror!u32'", |
| 1954 | 2009 | }); |
| 1955 | 2010 | |
| 1956 | | cases.add("attempt to create 17 bit float type", |
| 2011 | ctx.objErrStage1("attempt to create 17 bit float type", |
| 1957 | 2012 | \\const builtin = @import("std").builtin; |
| 1958 | 2013 | \\comptime { |
| 1959 | 2014 | \\ _ = @Type(builtin.TypeInfo { .Float = builtin.TypeInfo.Float { .bits = 17 } }); |
| ... | ... | @@ -1962,7 +2017,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1962 | 2017 | "tmp.zig:3:32: error: 17-bit float unsupported", |
| 1963 | 2018 | }); |
| 1964 | 2019 | |
| 1965 | | cases.add("wrong type for @Type", |
| 2020 | ctx.objErrStage1("wrong type for @Type", |
| 1966 | 2021 | \\export fn entry() void { |
| 1967 | 2022 | \\ _ = @Type(0); |
| 1968 | 2023 | \\} |
| ... | ... | @@ -1970,7 +2025,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1970 | 2025 | "tmp.zig:2:15: error: expected type 'std.builtin.TypeInfo', found 'comptime_int'", |
| 1971 | 2026 | }); |
| 1972 | 2027 | |
| 1973 | | cases.add("@Type with non-constant expression", |
| 2028 | ctx.objErrStage1("@Type with non-constant expression", |
| 1974 | 2029 | \\const builtin = @import("std").builtin; |
| 1975 | 2030 | \\var globalTypeInfo : builtin.TypeInfo = undefined; |
| 1976 | 2031 | \\export fn entry() void { |
| ... | ... | @@ -1980,7 +2035,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1980 | 2035 | "tmp.zig:4:15: error: unable to evaluate constant expression", |
| 1981 | 2036 | }); |
| 1982 | 2037 | |
| 1983 | | cases.add("wrong type for argument tuple to @asyncCall", |
| 2038 | ctx.objErrStage1("wrong type for argument tuple to @asyncCall", |
| 1984 | 2039 | \\export fn entry1() void { |
| 1985 | 2040 | \\ var frame: @Frame(foo) = undefined; |
| 1986 | 2041 | \\ @asyncCall(&frame, {}, foo, {}); |
| ... | ... | @@ -1993,7 +2048,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1993 | 2048 | "tmp.zig:3:33: error: expected tuple or struct, found 'void'", |
| 1994 | 2049 | }); |
| 1995 | 2050 | |
| 1996 | | cases.add("wrong type for result ptr to @asyncCall", |
| 2051 | ctx.objErrStage1("wrong type for result ptr to @asyncCall", |
| 1997 | 2052 | \\export fn entry() void { |
| 1998 | 2053 | \\ _ = async amain(); |
| 1999 | 2054 | \\} |
| ... | ... | @@ -2008,25 +2063,27 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2008 | 2063 | "tmp.zig:6:37: error: expected type '*i32', found 'bool'", |
| 2009 | 2064 | }); |
| 2010 | 2065 | |
| 2011 | | cases.add("shift amount has to be an integer type", |
| 2066 | ctx.objErrStage1("shift amount has to be an integer type", |
| 2012 | 2067 | \\export fn entry() void { |
| 2013 | 2068 | \\ const x = 1 << &@as(u8, 10); |
| 2069 | \\ _ = x; |
| 2014 | 2070 | \\} |
| 2015 | 2071 | , &[_][]const u8{ |
| 2016 | 2072 | "tmp.zig:2:21: error: shift amount has to be an integer type, but found '*const u8'", |
| 2017 | 2073 | "tmp.zig:2:17: note: referenced here", |
| 2018 | 2074 | }); |
| 2019 | 2075 | |
| 2020 | | cases.add("bit shifting only works on integer types", |
| 2076 | ctx.objErrStage1("bit shifting only works on integer types", |
| 2021 | 2077 | \\export fn entry() void { |
| 2022 | 2078 | \\ const x = &@as(u8, 1) << 10; |
| 2079 | \\ _ = x; |
| 2023 | 2080 | \\} |
| 2024 | 2081 | , &[_][]const u8{ |
| 2025 | 2082 | "tmp.zig:2:16: error: bit shifting operation expected integer type, found '*const u8'", |
| 2026 | 2083 | "tmp.zig:2:27: note: referenced here", |
| 2027 | 2084 | }); |
| 2028 | 2085 | |
| 2029 | | cases.add("struct depends on itself via optional field", |
| 2086 | ctx.objErrStage1("struct depends on itself via optional field", |
| 2030 | 2087 | \\const LhsExpr = struct { |
| 2031 | 2088 | \\ rhsExpr: ?AstObject, |
| 2032 | 2089 | \\}; |
| ... | ... | @@ -2036,6 +2093,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2036 | 2093 | \\export fn entry() void { |
| 2037 | 2094 | \\ const lhsExpr = LhsExpr{ .rhsExpr = null }; |
| 2038 | 2095 | \\ const obj = AstObject{ .lhsExpr = lhsExpr }; |
| 2096 | \\ _ = obj; |
| 2039 | 2097 | \\} |
| 2040 | 2098 | , &[_][]const u8{ |
| 2041 | 2099 | "tmp.zig:1:17: error: struct 'LhsExpr' depends on itself", |
| ... | ... | @@ -2043,51 +2101,55 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2043 | 2101 | "tmp.zig:2:5: note: while checking this field", |
| 2044 | 2102 | }); |
| 2045 | 2103 | |
| 2046 | | cases.add("alignment of enum field specified", |
| 2104 | ctx.objErrStage1("alignment of enum field specified", |
| 2047 | 2105 | \\const Number = enum { |
| 2048 | 2106 | \\ a, |
| 2049 | 2107 | \\ b align(i32), |
| 2050 | 2108 | \\}; |
| 2051 | 2109 | \\export fn entry1() void { |
| 2052 | 2110 | \\ var x: Number = undefined; |
| 2111 | \\ _ = x; |
| 2053 | 2112 | \\} |
| 2054 | 2113 | , &[_][]const u8{ |
| 2055 | 2114 | "tmp.zig:3:13: error: structs and unions, not enums, support field alignment", |
| 2056 | 2115 | "tmp.zig:1:16: note: consider 'union(enum)' here", |
| 2057 | 2116 | }); |
| 2058 | 2117 | |
| 2059 | | cases.add("bad alignment type", |
| 2118 | ctx.objErrStage1("bad alignment type", |
| 2060 | 2119 | \\export fn entry1() void { |
| 2061 | 2120 | \\ var x: []align(true) i32 = undefined; |
| 2121 | \\ _ = x; |
| 2062 | 2122 | \\} |
| 2063 | 2123 | \\export fn entry2() void { |
| 2064 | 2124 | \\ var x: *align(@as(f64, 12.34)) i32 = undefined; |
| 2125 | \\ _ = x; |
| 2065 | 2126 | \\} |
| 2066 | 2127 | , &[_][]const u8{ |
| 2067 | 2128 | "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'", |
| 2129 | "tmp.zig:6:19: error: fractional component prevents float value 12.340000 from being casted to type 'u29'", |
| 2069 | 2130 | }); |
| 2070 | 2131 | |
| 2071 | | cases.addCase(x: { |
| 2072 | | var tc = cases.create("variable in inline assembly template cannot be found", |
| 2132 | { |
| 2133 | const case = ctx.obj("variable in inline assembly template cannot be found", .{ |
| 2134 | .cpu_arch = .x86_64, |
| 2135 | .os_tag = .linux, |
| 2136 | .abi = .gnu, |
| 2137 | }); |
| 2138 | case.backend = .stage1; |
| 2139 | case.addError( |
| 2073 | 2140 | \\export fn entry() void { |
| 2074 | 2141 | \\ var sp = asm volatile ( |
| 2075 | 2142 | \\ "mov %[foo], sp" |
| 2076 | 2143 | \\ : [bar] "=r" (-> usize) |
| 2077 | 2144 | \\ ); |
| 2145 | \\ _ = sp; |
| 2078 | 2146 | \\} |
| 2079 | 2147 | , &[_][]const u8{ |
| 2080 | 2148 | "tmp.zig:2:14: error: could not find 'foo' in the inputs or outputs", |
| 2081 | 2149 | }); |
| 2082 | | tc.target = std.zig.CrossTarget{ |
| 2083 | | .cpu_arch = .x86_64, |
| 2084 | | .os_tag = .linux, |
| 2085 | | .abi = .gnu, |
| 2086 | | }; |
| 2087 | | break :x tc; |
| 2088 | | }); |
| 2150 | } |
| 2089 | 2151 | |
| 2090 | | cases.add("indirect recursion of async functions detected", |
| 2152 | ctx.objErrStage1("indirect recursion of async functions detected", |
| 2091 | 2153 | \\var frame: ?anyframe = null; |
| 2092 | 2154 | \\ |
| 2093 | 2155 | \\export fn a() void { |
| ... | ... | @@ -2122,7 +2184,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2122 | 2184 | "tmp.zig:26:25: note: when analyzing type '@Frame(rangeSumIndirect)' here", |
| 2123 | 2185 | }); |
| 2124 | 2186 | |
| 2125 | | cases.add("non-async function pointer eventually is inferred to become async", |
| 2187 | ctx.objErrStage1("non-async function pointer eventually is inferred to become async", |
| 2126 | 2188 | \\export fn a() void { |
| 2127 | 2189 | \\ var non_async_fn: fn () void = undefined; |
| 2128 | 2190 | \\ non_async_fn = func; |
| ... | ... | @@ -2136,20 +2198,26 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2136 | 2198 | "tmp.zig:6:5: note: suspends here", |
| 2137 | 2199 | }); |
| 2138 | 2200 | |
| 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 | | }); |
| 2201 | { |
| 2202 | const case = ctx.obj("bad alignment in @asyncCall", .{ |
| 2203 | .cpu_arch = .aarch64, |
| 2204 | .os_tag = .linux, |
| 2205 | .abi = .none, |
| 2206 | }); |
| 2207 | case.backend = .stage1; |
| 2208 | case.addError( |
| 2209 | \\export fn entry() void { |
| 2210 | \\ var ptr: fn () callconv(.Async) void = func; |
| 2211 | \\ var bytes: [64]u8 = undefined; |
| 2212 | \\ _ = @asyncCall(&bytes, {}, ptr, .{}); |
| 2213 | \\} |
| 2214 | \\fn func() callconv(.Async) void {} |
| 2215 | , &[_][]const u8{ |
| 2216 | "tmp.zig:4:21: error: expected type '[]align(8) u8', found '*[64]u8'", |
| 2217 | }); |
| 2218 | } |
| 2151 | 2219 | |
| 2152 | | cases.add("atomic orderings of fence Acquire or stricter", |
| 2220 | ctx.objErrStage1("atomic orderings of fence Acquire or stricter", |
| 2153 | 2221 | \\export fn entry() void { |
| 2154 | 2222 | \\ @fence(.Monotonic); |
| 2155 | 2223 | \\} |
| ... | ... | @@ -2157,20 +2225,22 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2157 | 2225 | "tmp.zig:2:12: error: atomic ordering must be Acquire or stricter", |
| 2158 | 2226 | }); |
| 2159 | 2227 | |
| 2160 | | cases.add("bad alignment in implicit cast from array pointer to slice", |
| 2228 | ctx.objErrStage1("bad alignment in implicit cast from array pointer to slice", |
| 2161 | 2229 | \\export fn a() void { |
| 2162 | 2230 | \\ var x: [10]u8 = undefined; |
| 2163 | 2231 | \\ var y: []align(16) u8 = &x; |
| 2232 | \\ _ = y; |
| 2164 | 2233 | \\} |
| 2165 | 2234 | , &[_][]const u8{ |
| 2166 | 2235 | "tmp.zig:3:30: error: expected type '[]align(16) u8', found '*[10]u8'", |
| 2167 | 2236 | }); |
| 2168 | 2237 | |
| 2169 | | cases.add("result location incompatibility mismatching handle_is_ptr (generic call)", |
| 2238 | ctx.objErrStage1("result location incompatibility mismatching handle_is_ptr (generic call)", |
| 2170 | 2239 | \\export fn entry() void { |
| 2171 | 2240 | \\ var damn = Container{ |
| 2172 | 2241 | \\ .not_optional = getOptional(i32), |
| 2173 | 2242 | \\ }; |
| 2243 | \\ _ = damn; |
| 2174 | 2244 | \\} |
| 2175 | 2245 | \\pub fn getOptional(comptime T: type) ?T { |
| 2176 | 2246 | \\ return 0; |
| ... | ... | @@ -2182,11 +2252,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2182 | 2252 | "tmp.zig:3:36: error: expected type 'i32', found '?i32'", |
| 2183 | 2253 | }); |
| 2184 | 2254 | |
| 2185 | | cases.add("result location incompatibility mismatching handle_is_ptr", |
| 2255 | ctx.objErrStage1("result location incompatibility mismatching handle_is_ptr", |
| 2186 | 2256 | \\export fn entry() void { |
| 2187 | 2257 | \\ var damn = Container{ |
| 2188 | 2258 | \\ .not_optional = getOptional(), |
| 2189 | 2259 | \\ }; |
| 2260 | \\ _ = damn; |
| 2190 | 2261 | \\} |
| 2191 | 2262 | \\pub fn getOptional() ?i32 { |
| 2192 | 2263 | \\ return 0; |
| ... | ... | @@ -2198,7 +2269,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2198 | 2269 | "tmp.zig:3:36: error: expected type 'i32', found '?i32'", |
| 2199 | 2270 | }); |
| 2200 | 2271 | |
| 2201 | | cases.add("const frame cast to anyframe", |
| 2272 | ctx.objErrStage1("const frame cast to anyframe", |
| 2202 | 2273 | \\export fn a() void { |
| 2203 | 2274 | \\ const f = async func(); |
| 2204 | 2275 | \\ resume f; |
| ... | ... | @@ -2206,6 +2277,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2206 | 2277 | \\export fn b() void { |
| 2207 | 2278 | \\ const f = async func(); |
| 2208 | 2279 | \\ var x: anyframe = &f; |
| 2280 | \\ _ = x; |
| 2209 | 2281 | \\} |
| 2210 | 2282 | \\fn func() void { |
| 2211 | 2283 | \\ suspend {} |
| ... | ... | @@ -2215,27 +2287,30 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2215 | 2287 | "tmp.zig:7:24: error: expected type 'anyframe', found '*const @Frame(func)'", |
| 2216 | 2288 | }); |
| 2217 | 2289 | |
| 2218 | | cases.add("prevent bad implicit casting of anyframe types", |
| 2290 | ctx.objErrStage1("prevent bad implicit casting of anyframe types", |
| 2219 | 2291 | \\export fn a() void { |
| 2220 | 2292 | \\ var x: anyframe = undefined; |
| 2221 | 2293 | \\ var y: anyframe->i32 = x; |
| 2294 | \\ _ = y; |
| 2222 | 2295 | \\} |
| 2223 | 2296 | \\export fn b() void { |
| 2224 | 2297 | \\ var x: i32 = undefined; |
| 2225 | 2298 | \\ var y: anyframe->i32 = x; |
| 2299 | \\ _ = y; |
| 2226 | 2300 | \\} |
| 2227 | 2301 | \\export fn c() void { |
| 2228 | 2302 | \\ var x: @Frame(func) = undefined; |
| 2229 | 2303 | \\ var y: anyframe->i32 = &x; |
| 2304 | \\ _ = y; |
| 2230 | 2305 | \\} |
| 2231 | 2306 | \\fn func() void {} |
| 2232 | 2307 | , &[_][]const u8{ |
| 2233 | 2308 | "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)'", |
| 2309 | "tmp.zig:8:28: error: expected type 'anyframe->i32', found 'i32'", |
| 2310 | "tmp.zig:13:29: error: expected type 'anyframe->i32', found '*@Frame(func)'", |
| 2236 | 2311 | }); |
| 2237 | 2312 | |
| 2238 | | cases.add("wrong frame type used for async call", |
| 2313 | ctx.objErrStage1("wrong frame type used for async call", |
| 2239 | 2314 | \\export fn entry() void { |
| 2240 | 2315 | \\ var frame: @Frame(foo) = undefined; |
| 2241 | 2316 | \\ frame = async bar(); |
| ... | ... | @@ -2250,18 +2325,20 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2250 | 2325 | "tmp.zig:3:13: error: expected type '*@Frame(bar)', found '*@Frame(foo)'", |
| 2251 | 2326 | }); |
| 2252 | 2327 | |
| 2253 | | cases.add("@Frame() of generic function", |
| 2328 | ctx.objErrStage1("@Frame() of generic function", |
| 2254 | 2329 | \\export fn entry() void { |
| 2255 | 2330 | \\ var frame: @Frame(func) = undefined; |
| 2331 | \\ _ = frame; |
| 2256 | 2332 | \\} |
| 2257 | 2333 | \\fn func(comptime T: type) void { |
| 2258 | 2334 | \\ var x: T = undefined; |
| 2335 | \\ _ = x; |
| 2259 | 2336 | \\} |
| 2260 | 2337 | , &[_][]const u8{ |
| 2261 | 2338 | "tmp.zig:2:16: error: @Frame() of generic function", |
| 2262 | 2339 | }); |
| 2263 | 2340 | |
| 2264 | | cases.add("@frame() causes function to be async", |
| 2341 | ctx.objErrStage1("@frame() causes function to be async", |
| 2265 | 2342 | \\export fn entry() void { |
| 2266 | 2343 | \\ func(); |
| 2267 | 2344 | \\} |
| ... | ... | @@ -2273,10 +2350,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2273 | 2350 | "tmp.zig:5:9: note: @frame() causes function to be async", |
| 2274 | 2351 | }); |
| 2275 | 2352 | |
| 2276 | | cases.add("invalid suspend in exported function", |
| 2353 | ctx.objErrStage1("invalid suspend in exported function", |
| 2277 | 2354 | \\export fn entry() void { |
| 2278 | 2355 | \\ var frame = async func(); |
| 2279 | 2356 | \\ var result = await frame; |
| 2357 | \\ _ = result; |
| 2280 | 2358 | \\} |
| 2281 | 2359 | \\fn func() void { |
| 2282 | 2360 | \\ suspend {} |
| ... | ... | @@ -2286,7 +2364,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2286 | 2364 | "tmp.zig:3:18: note: await here is a suspend point", |
| 2287 | 2365 | }); |
| 2288 | 2366 | |
| 2289 | | cases.add("async function indirectly depends on its own frame", |
| 2367 | ctx.objErrStage1("async function indirectly depends on its own frame", |
| 2290 | 2368 | \\export fn entry() void { |
| 2291 | 2369 | \\ _ = async amain(); |
| 2292 | 2370 | \\} |
| ... | ... | @@ -2295,6 +2373,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2295 | 2373 | \\} |
| 2296 | 2374 | \\fn other() void { |
| 2297 | 2375 | \\ var x: [@sizeOf(@Frame(amain))]u8 = undefined; |
| 2376 | \\ _ = x; |
| 2298 | 2377 | \\} |
| 2299 | 2378 | , &[_][]const u8{ |
| 2300 | 2379 | "tmp.zig:4:1: error: unable to determine async function frame of 'amain'", |
| ... | ... | @@ -2302,19 +2381,20 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2302 | 2381 | "tmp.zig:8:13: note: referenced here", |
| 2303 | 2382 | }); |
| 2304 | 2383 | |
| 2305 | | cases.add("async function depends on its own frame", |
| 2384 | ctx.objErrStage1("async function depends on its own frame", |
| 2306 | 2385 | \\export fn entry() void { |
| 2307 | 2386 | \\ _ = async amain(); |
| 2308 | 2387 | \\} |
| 2309 | 2388 | \\fn amain() callconv(.Async) void { |
| 2310 | 2389 | \\ var x: [@sizeOf(@Frame(amain))]u8 = undefined; |
| 2390 | \\ _ = x; |
| 2311 | 2391 | \\} |
| 2312 | 2392 | , &[_][]const u8{ |
| 2313 | 2393 | "tmp.zig:4:1: error: cannot resolve '@Frame(amain)': function not fully analyzed yet", |
| 2314 | 2394 | "tmp.zig:5:13: note: referenced here", |
| 2315 | 2395 | }); |
| 2316 | 2396 | |
| 2317 | | cases.add("non async function pointer passed to @asyncCall", |
| 2397 | ctx.objErrStage1("non async function pointer passed to @asyncCall", |
| 2318 | 2398 | \\export fn entry() void { |
| 2319 | 2399 | \\ var ptr = afunc; |
| 2320 | 2400 | \\ var bytes: [100]u8 align(16) = undefined; |
| ... | ... | @@ -2325,7 +2405,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2325 | 2405 | "tmp.zig:4:32: error: expected async function, found 'fn() void'", |
| 2326 | 2406 | }); |
| 2327 | 2407 | |
| 2328 | | cases.add("runtime-known async function called", |
| 2408 | ctx.objErrStage1("runtime-known async function called", |
| 2329 | 2409 | \\export fn entry() void { |
| 2330 | 2410 | \\ _ = async amain(); |
| 2331 | 2411 | \\} |
| ... | ... | @@ -2338,7 +2418,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2338 | 2418 | "tmp.zig:6:12: error: function is not comptime-known; @asyncCall required", |
| 2339 | 2419 | }); |
| 2340 | 2420 | |
| 2341 | | cases.add("runtime-known function called with async keyword", |
| 2421 | ctx.objErrStage1("runtime-known function called with async keyword", |
| 2342 | 2422 | \\export fn entry() void { |
| 2343 | 2423 | \\ var ptr = afunc; |
| 2344 | 2424 | \\ _ = async ptr(); |
| ... | ... | @@ -2349,7 +2429,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2349 | 2429 | "tmp.zig:3:15: error: function is not comptime-known; @asyncCall required", |
| 2350 | 2430 | }); |
| 2351 | 2431 | |
| 2352 | | cases.add("function with ccc indirectly calling async function", |
| 2432 | ctx.objErrStage1("function with ccc indirectly calling async function", |
| 2353 | 2433 | \\export fn entry() void { |
| 2354 | 2434 | \\ foo(); |
| 2355 | 2435 | \\} |
| ... | ... | @@ -2366,7 +2446,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2366 | 2446 | "tmp.zig:8:5: note: suspends here", |
| 2367 | 2447 | }); |
| 2368 | 2448 | |
| 2369 | | cases.add("capture group on switch prong with incompatible payload types", |
| 2449 | ctx.objErrStage1("capture group on switch prong with incompatible payload types", |
| 2370 | 2450 | \\const Union = union(enum) { |
| 2371 | 2451 | \\ A: usize, |
| 2372 | 2452 | \\ B: isize, |
| ... | ... | @@ -2374,7 +2454,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2374 | 2454 | \\comptime { |
| 2375 | 2455 | \\ var u = Union{ .A = 8 }; |
| 2376 | 2456 | \\ switch (u) { |
| 2377 | | \\ .A, .B => |e| unreachable, |
| 2457 | \\ .A, .B => |e| { |
| 2458 | \\ _ = e; |
| 2459 | \\ unreachable; |
| 2460 | \\ }, |
| 2378 | 2461 | \\ } |
| 2379 | 2462 | \\} |
| 2380 | 2463 | , &[_][]const u8{ |
| ... | ... | @@ -2383,7 +2466,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2383 | 2466 | "tmp.zig:8:13: note: type 'isize' here", |
| 2384 | 2467 | }); |
| 2385 | 2468 | |
| 2386 | | cases.add("wrong type to @hasField", |
| 2469 | ctx.objErrStage1("wrong type to @hasField", |
| 2387 | 2470 | \\export fn entry() bool { |
| 2388 | 2471 | \\ return @hasField(i32, "hi"); |
| 2389 | 2472 | \\} |
| ... | ... | @@ -2391,44 +2474,49 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2391 | 2474 | "tmp.zig:2:22: error: type 'i32' does not support @hasField", |
| 2392 | 2475 | }); |
| 2393 | 2476 | |
| 2394 | | cases.add("slice passed as array init type with elems", |
| 2477 | ctx.objErrStage1("slice passed as array init type with elems", |
| 2395 | 2478 | \\export fn entry() void { |
| 2396 | 2479 | \\ const x = []u8{1, 2}; |
| 2480 | \\ _ = x; |
| 2397 | 2481 | \\} |
| 2398 | 2482 | , &[_][]const u8{ |
| 2399 | 2483 | "tmp.zig:2:15: error: array literal requires address-of operator to coerce to slice type '[]u8'", |
| 2400 | 2484 | }); |
| 2401 | 2485 | |
| 2402 | | cases.add("slice passed as array init type", |
| 2486 | ctx.objErrStage1("slice passed as array init type", |
| 2403 | 2487 | \\export fn entry() void { |
| 2404 | 2488 | \\ const x = []u8{}; |
| 2489 | \\ _ = x; |
| 2405 | 2490 | \\} |
| 2406 | 2491 | , &[_][]const u8{ |
| 2407 | 2492 | "tmp.zig:2:15: error: array literal requires address-of operator to coerce to slice type '[]u8'", |
| 2408 | 2493 | }); |
| 2409 | 2494 | |
| 2410 | | cases.add("inferred array size invalid here", |
| 2495 | ctx.objErrStage1("inferred array size invalid here", |
| 2411 | 2496 | \\export fn entry() void { |
| 2412 | 2497 | \\ const x = [_]u8; |
| 2498 | \\ _ = x; |
| 2413 | 2499 | \\} |
| 2414 | 2500 | \\export fn entry2() void { |
| 2415 | 2501 | \\ const S = struct { a: *const [_]u8 }; |
| 2416 | 2502 | \\ var a = .{ S{} }; |
| 2503 | \\ _ = a; |
| 2417 | 2504 | \\} |
| 2418 | 2505 | , &[_][]const u8{ |
| 2419 | | "tmp.zig:2:15: error: inferred array size invalid here", |
| 2420 | | "tmp.zig:5:34: error: inferred array size invalid here", |
| 2506 | "tmp.zig:2:16: error: unable to infer array size", |
| 2507 | "tmp.zig:6:35: error: unable to infer array size", |
| 2421 | 2508 | }); |
| 2422 | 2509 | |
| 2423 | | cases.add("initializing array with struct syntax", |
| 2510 | ctx.objErrStage1("initializing array with struct syntax", |
| 2424 | 2511 | \\export fn entry() void { |
| 2425 | 2512 | \\ const x = [_]u8{ .y = 2 }; |
| 2513 | \\ _ = x; |
| 2426 | 2514 | \\} |
| 2427 | 2515 | , &[_][]const u8{ |
| 2428 | 2516 | "tmp.zig:2:15: error: initializing array with struct syntax", |
| 2429 | 2517 | }); |
| 2430 | 2518 | |
| 2431 | | cases.add("compile error in struct init expression", |
| 2519 | ctx.objErrStage1("compile error in struct init expression", |
| 2432 | 2520 | \\const Foo = struct { |
| 2433 | 2521 | \\ a: i32 = crap, |
| 2434 | 2522 | \\ b: i32, |
| ... | ... | @@ -2437,23 +2525,25 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2437 | 2525 | \\ var x = Foo{ |
| 2438 | 2526 | \\ .b = 5, |
| 2439 | 2527 | \\ }; |
| 2528 | \\ _ = x; |
| 2440 | 2529 | \\} |
| 2441 | 2530 | , &[_][]const u8{ |
| 2442 | 2531 | "tmp.zig:2:14: error: use of undeclared identifier 'crap'", |
| 2443 | 2532 | }); |
| 2444 | 2533 | |
| 2445 | | cases.add("undefined as field type is rejected", |
| 2534 | ctx.objErrStage1("undefined as field type is rejected", |
| 2446 | 2535 | \\const Foo = struct { |
| 2447 | 2536 | \\ a: undefined, |
| 2448 | 2537 | \\}; |
| 2449 | 2538 | \\export fn entry1() void { |
| 2450 | 2539 | \\ const foo: Foo = undefined; |
| 2540 | \\ _ = foo; |
| 2451 | 2541 | \\} |
| 2452 | 2542 | , &[_][]const u8{ |
| 2453 | 2543 | "tmp.zig:2:8: error: use of undefined value here causes undefined behavior", |
| 2454 | 2544 | }); |
| 2455 | 2545 | |
| 2456 | | cases.add("@hasDecl with non-container", |
| 2546 | ctx.objErrStage1("@hasDecl with non-container", |
| 2457 | 2547 | \\export fn entry() void { |
| 2458 | 2548 | \\ _ = @hasDecl(i32, "hi"); |
| 2459 | 2549 | \\} |
| ... | ... | @@ -2461,16 +2551,17 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2461 | 2551 | "tmp.zig:2:18: error: expected struct, enum, or union; found 'i32'", |
| 2462 | 2552 | }); |
| 2463 | 2553 | |
| 2464 | | cases.add("field access of slices", |
| 2554 | ctx.objErrStage1("field access of slices", |
| 2465 | 2555 | \\export fn entry() void { |
| 2466 | 2556 | \\ var slice: []i32 = undefined; |
| 2467 | 2557 | \\ const info = @TypeOf(slice).unknown; |
| 2558 | \\ _ = info; |
| 2468 | 2559 | \\} |
| 2469 | 2560 | , &[_][]const u8{ |
| 2470 | 2561 | "tmp.zig:3:32: error: type 'type' does not support field access", |
| 2471 | 2562 | }); |
| 2472 | 2563 | |
| 2473 | | cases.add("peer cast then implicit cast const pointer to mutable C pointer", |
| 2564 | ctx.objErrStage1("peer cast then implicit cast const pointer to mutable C pointer", |
| 2474 | 2565 | \\export fn func() void { |
| 2475 | 2566 | \\ var strValue: [*c]u8 = undefined; |
| 2476 | 2567 | \\ strValue = strValue orelse ""; |
| ... | ... | @@ -2480,19 +2571,20 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2480 | 2571 | "tmp.zig:3:32: note: cast discards const qualifier", |
| 2481 | 2572 | }); |
| 2482 | 2573 | |
| 2483 | | cases.add("overflow in enum value allocation", |
| 2574 | ctx.objErrStage1("overflow in enum value allocation", |
| 2484 | 2575 | \\const Moo = enum(u8) { |
| 2485 | 2576 | \\ Last = 255, |
| 2486 | 2577 | \\ Over, |
| 2487 | 2578 | \\}; |
| 2488 | 2579 | \\pub fn main() void { |
| 2489 | 2580 | \\ var y = Moo.Last; |
| 2581 | \\ _ = y; |
| 2490 | 2582 | \\} |
| 2491 | 2583 | , &[_][]const u8{ |
| 2492 | 2584 | "tmp.zig:3:5: error: enumeration value 256 too large for type 'u8'", |
| 2493 | 2585 | }); |
| 2494 | 2586 | |
| 2495 | | cases.add("attempt to cast enum literal to error", |
| 2587 | ctx.objErrStage1("attempt to cast enum literal to error", |
| 2496 | 2588 | \\export fn entry() void { |
| 2497 | 2589 | \\ switch (error.Hi) { |
| 2498 | 2590 | \\ .Hi => {}, |
| ... | ... | @@ -2502,7 +2594,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2502 | 2594 | "tmp.zig:3:9: error: expected type 'error{Hi}', found '(enum literal)'", |
| 2503 | 2595 | }); |
| 2504 | 2596 | |
| 2505 | | cases.add("@sizeOf bad type", |
| 2597 | ctx.objErrStage1("@sizeOf bad type", |
| 2506 | 2598 | \\export fn entry() usize { |
| 2507 | 2599 | \\ return @sizeOf(@TypeOf(null)); |
| 2508 | 2600 | \\} |
| ... | ... | @@ -2510,7 +2602,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2510 | 2602 | "tmp.zig:2:20: error: no size available for type '(null)'", |
| 2511 | 2603 | }); |
| 2512 | 2604 | |
| 2513 | | cases.add("generic function where return type is self-referenced", |
| 2605 | ctx.objErrStage1("generic function where return type is self-referenced", |
| 2514 | 2606 | \\fn Foo(comptime T: type) Foo(T) { |
| 2515 | 2607 | \\ return struct{ x: T }; |
| 2516 | 2608 | \\} |
| ... | ... | @@ -2518,34 +2610,37 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2518 | 2610 | \\ const t = Foo(u32) { |
| 2519 | 2611 | \\ .x = 1 |
| 2520 | 2612 | \\ }; |
| 2613 | \\ _ = t; |
| 2521 | 2614 | \\} |
| 2522 | 2615 | , &[_][]const u8{ |
| 2523 | 2616 | "tmp.zig:1:29: error: evaluation exceeded 1000 backwards branches", |
| 2524 | 2617 | "tmp.zig:5:18: note: referenced here", |
| 2525 | 2618 | }); |
| 2526 | 2619 | |
| 2527 | | cases.add("@ptrToInt 0 to non optional pointer", |
| 2620 | ctx.objErrStage1("@ptrToInt 0 to non optional pointer", |
| 2528 | 2621 | \\export fn entry() void { |
| 2529 | 2622 | \\ var b = @intToPtr(*i32, 0); |
| 2623 | \\ _ = b; |
| 2530 | 2624 | \\} |
| 2531 | 2625 | , &[_][]const u8{ |
| 2532 | 2626 | "tmp.zig:2:13: error: pointer type '*i32' does not allow address zero", |
| 2533 | 2627 | }); |
| 2534 | 2628 | |
| 2535 | | cases.add("cast enum literal to enum but it doesn't match", |
| 2629 | ctx.objErrStage1("cast enum literal to enum but it doesn't match", |
| 2536 | 2630 | \\const Foo = enum { |
| 2537 | 2631 | \\ a, |
| 2538 | 2632 | \\ b, |
| 2539 | 2633 | \\}; |
| 2540 | 2634 | \\export fn entry() void { |
| 2541 | 2635 | \\ const x: Foo = .c; |
| 2636 | \\ _ = x; |
| 2542 | 2637 | \\} |
| 2543 | 2638 | , &[_][]const u8{ |
| 2544 | 2639 | "tmp.zig:6:20: error: enum 'Foo' has no field named 'c'", |
| 2545 | 2640 | "tmp.zig:1:13: note: 'Foo' declared here", |
| 2546 | 2641 | }); |
| 2547 | 2642 | |
| 2548 | | cases.add("discarding error value", |
| 2643 | ctx.objErrStage1("discarding error value", |
| 2549 | 2644 | \\export fn entry() void { |
| 2550 | 2645 | \\ _ = foo(); |
| 2551 | 2646 | \\} |
| ... | ... | @@ -2556,7 +2651,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2556 | 2651 | "tmp.zig:2:12: error: error is discarded. consider using `try`, `catch`, or `if`", |
| 2557 | 2652 | }); |
| 2558 | 2653 | |
| 2559 | | cases.add("volatile on global assembly", |
| 2654 | ctx.objErrStage1("volatile on global assembly", |
| 2560 | 2655 | \\comptime { |
| 2561 | 2656 | \\ asm volatile (""); |
| 2562 | 2657 | \\} |
| ... | ... | @@ -2564,7 +2659,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2564 | 2659 | "tmp.zig:2:9: error: volatile is meaningless on global assembly", |
| 2565 | 2660 | }); |
| 2566 | 2661 | |
| 2567 | | cases.add("invalid multiple dereferences", |
| 2662 | ctx.objErrStage1("invalid multiple dereferences", |
| 2568 | 2663 | \\export fn a() void { |
| 2569 | 2664 | \\ var box = Box{ .field = 0 }; |
| 2570 | 2665 | \\ box.*.field = 1; |
| ... | ... | @@ -2582,13 +2677,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2582 | 2677 | "tmp.zig:8:13: error: attempt to dereference non-pointer type 'Box'", |
| 2583 | 2678 | }); |
| 2584 | 2679 | |
| 2585 | | cases.add("usingnamespace with wrong type", |
| 2680 | ctx.objErrStage1("usingnamespace with wrong type", |
| 2586 | 2681 | \\usingnamespace void; |
| 2587 | 2682 | , &[_][]const u8{ |
| 2588 | 2683 | "tmp.zig:1:1: error: expected struct, enum, or union; found 'void'", |
| 2589 | 2684 | }); |
| 2590 | 2685 | |
| 2591 | | cases.add("ignored expression in while continuation", |
| 2686 | ctx.objErrStage1("ignored expression in while continuation", |
| 2592 | 2687 | \\export fn a() void { |
| 2593 | 2688 | \\ while (true) : (bad()) {} |
| 2594 | 2689 | \\} |
| ... | ... | @@ -2609,31 +2704,31 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2609 | 2704 | "tmp.zig:10:25: error: error is ignored. consider using `try`, `catch`, or `if`", |
| 2610 | 2705 | }); |
| 2611 | 2706 | |
| 2612 | | cases.add("empty while loop body", |
| 2707 | ctx.objErrStage1("empty while loop body", |
| 2613 | 2708 | \\export fn a() void { |
| 2614 | 2709 | \\ while(true); |
| 2615 | 2710 | \\} |
| 2616 | 2711 | , &[_][]const u8{ |
| 2617 | | "tmp.zig:2:16: error: expected loop body, found ';'", |
| 2712 | "tmp.zig:2:16: error: expected block or assignment, found ';'", |
| 2618 | 2713 | }); |
| 2619 | 2714 | |
| 2620 | | cases.add("empty for loop body", |
| 2715 | ctx.objErrStage1("empty for loop body", |
| 2621 | 2716 | \\export fn a() void { |
| 2622 | 2717 | \\ for(undefined) |x|; |
| 2623 | 2718 | \\} |
| 2624 | 2719 | , &[_][]const u8{ |
| 2625 | | "tmp.zig:2:23: error: expected loop body, found ';'", |
| 2720 | "tmp.zig:2:23: error: expected block or assignment, found ';'", |
| 2626 | 2721 | }); |
| 2627 | 2722 | |
| 2628 | | cases.add("empty if body", |
| 2723 | ctx.objErrStage1("empty if body", |
| 2629 | 2724 | \\export fn a() void { |
| 2630 | 2725 | \\ if(true); |
| 2631 | 2726 | \\} |
| 2632 | 2727 | , &[_][]const u8{ |
| 2633 | | "tmp.zig:2:13: error: expected if body, found ';'", |
| 2728 | "tmp.zig:2:13: error: expected block or assignment, found ';'", |
| 2634 | 2729 | }); |
| 2635 | 2730 | |
| 2636 | | cases.add("import outside package path", |
| 2731 | ctx.objErrStage1("import outside package path", |
| 2637 | 2732 | \\comptime{ |
| 2638 | 2733 | \\ _ = @import("../a.zig"); |
| 2639 | 2734 | \\} |
| ... | ... | @@ -2641,14 +2736,14 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2641 | 2736 | "tmp.zig:2:9: error: import of file outside package path: '../a.zig'", |
| 2642 | 2737 | }); |
| 2643 | 2738 | |
| 2644 | | cases.add("bogus compile var", |
| 2739 | ctx.objErrStage1("bogus compile var", |
| 2645 | 2740 | \\const x = @import("builtin").bogus; |
| 2646 | 2741 | \\export fn entry() usize { return @sizeOf(@TypeOf(x)); } |
| 2647 | 2742 | , &[_][]const u8{ |
| 2648 | 2743 | "tmp.zig:1:29: error: container 'builtin' has no member called 'bogus'", |
| 2649 | 2744 | }); |
| 2650 | 2745 | |
| 2651 | | cases.add("wrong panic signature, runtime function", |
| 2746 | ctx.objErrStage1("wrong panic signature, runtime function", |
| 2652 | 2747 | \\test "" {} |
| 2653 | 2748 | \\ |
| 2654 | 2749 | \\pub fn panic() void {} |
| ... | ... | @@ -2657,8 +2752,9 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2657 | 2752 | "error: expected type 'fn([]const u8, ?*std.builtin.StackTrace) noreturn', found 'fn() void'", |
| 2658 | 2753 | }); |
| 2659 | 2754 | |
| 2660 | | cases.add("wrong panic signature, generic function", |
| 2755 | ctx.objErrStage1("wrong panic signature, generic function", |
| 2661 | 2756 | \\pub fn panic(comptime msg: []const u8, error_return_trace: ?*builtin.StackTrace) noreturn { |
| 2757 | \\ _ = msg; _ = error_return_trace; |
| 2662 | 2758 | \\ while (true) {} |
| 2663 | 2759 | \\} |
| 2664 | 2760 | , &[_][]const u8{ |
| ... | ... | @@ -2666,14 +2762,14 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2666 | 2762 | "note: only one of the functions is generic", |
| 2667 | 2763 | }); |
| 2668 | 2764 | |
| 2669 | | cases.add("direct struct loop", |
| 2765 | ctx.objErrStage1("direct struct loop", |
| 2670 | 2766 | \\const A = struct { a : A, }; |
| 2671 | 2767 | \\export fn entry() usize { return @sizeOf(A); } |
| 2672 | 2768 | , &[_][]const u8{ |
| 2673 | 2769 | "tmp.zig:1:11: error: struct 'A' depends on itself", |
| 2674 | 2770 | }); |
| 2675 | 2771 | |
| 2676 | | cases.add("indirect struct loop", |
| 2772 | ctx.objErrStage1("indirect struct loop", |
| 2677 | 2773 | \\const A = struct { b : B, }; |
| 2678 | 2774 | \\const B = struct { c : C, }; |
| 2679 | 2775 | \\const C = struct { a : A, }; |
| ... | ... | @@ -2682,7 +2778,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2682 | 2778 | "tmp.zig:1:11: error: struct 'A' depends on itself", |
| 2683 | 2779 | }); |
| 2684 | 2780 | |
| 2685 | | cases.add("instantiating an undefined value for an invalid struct that contains itself", |
| 2781 | ctx.objErrStage1("instantiating an undefined value for an invalid struct that contains itself", |
| 2686 | 2782 | \\const Foo = struct { |
| 2687 | 2783 | \\ x: Foo, |
| 2688 | 2784 | \\}; |
| ... | ... | @@ -2697,23 +2793,25 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2697 | 2793 | "tmp.zig:8:28: note: referenced here", |
| 2698 | 2794 | }); |
| 2699 | 2795 | |
| 2700 | | cases.add("enum field value references enum", |
| 2701 | | \\pub const Foo = extern enum { |
| 2796 | ctx.objErrStage1("enum field value references enum", |
| 2797 | \\pub const Foo = enum(c_int) { |
| 2702 | 2798 | \\ A = Foo.B, |
| 2703 | 2799 | \\ C = D, |
| 2704 | 2800 | \\}; |
| 2705 | 2801 | \\export fn entry() void { |
| 2706 | 2802 | \\ var s: Foo = Foo.E; |
| 2803 | \\ _ = s; |
| 2707 | 2804 | \\} |
| 2708 | 2805 | , &[_][]const u8{ |
| 2709 | 2806 | "tmp.zig:1:17: error: enum 'Foo' depends on itself", |
| 2710 | 2807 | }); |
| 2711 | 2808 | |
| 2712 | | cases.add("top level decl dependency loop", |
| 2809 | ctx.objErrStage1("top level decl dependency loop", |
| 2713 | 2810 | \\const a : @TypeOf(b) = 0; |
| 2714 | 2811 | \\const b : @TypeOf(a) = 0; |
| 2715 | 2812 | \\export fn entry() void { |
| 2716 | 2813 | \\ const c = a + b; |
| 2814 | \\ _ = c; |
| 2717 | 2815 | \\} |
| 2718 | 2816 | , &[_][]const u8{ |
| 2719 | 2817 | "tmp.zig:2:19: error: dependency loop detected", |
| ... | ... | @@ -2721,7 +2819,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2721 | 2819 | "tmp.zig:4:15: note: referenced here", |
| 2722 | 2820 | }); |
| 2723 | 2821 | |
| 2724 | | cases.addTest("not an enum type", |
| 2822 | ctx.testErrStage1("not an enum type", |
| 2725 | 2823 | \\export fn entry() void { |
| 2726 | 2824 | \\ var self: Error = undefined; |
| 2727 | 2825 | \\ switch (self) { |
| ... | ... | @@ -2739,18 +2837,19 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2739 | 2837 | "tmp.zig:4:9: error: expected type '@typeInfo(Error).Union.tag_type.?', found 'type'", |
| 2740 | 2838 | }); |
| 2741 | 2839 | |
| 2742 | | cases.addTest("binary OR operator on error sets", |
| 2840 | ctx.testErrStage1("binary OR operator on error sets", |
| 2743 | 2841 | \\pub const A = error.A; |
| 2744 | 2842 | \\pub const AB = A | error.B; |
| 2745 | 2843 | \\export fn entry() void { |
| 2746 | 2844 | \\ var x: AB = undefined; |
| 2845 | \\ _ = x; |
| 2747 | 2846 | \\} |
| 2748 | 2847 | , &[_][]const u8{ |
| 2749 | 2848 | "tmp.zig:2:18: error: invalid operands to binary expression: 'error{A}' and 'error{B}'", |
| 2750 | 2849 | }); |
| 2751 | 2850 | |
| 2752 | 2851 | if (std.Target.current.os.tag == .linux) { |
| 2753 | | cases.addTest("implicit dependency on libc", |
| 2852 | ctx.testErrStage1("implicit dependency on libc", |
| 2754 | 2853 | \\extern "c" fn exit(u8) void; |
| 2755 | 2854 | \\export fn entry() void { |
| 2756 | 2855 | \\ exit(0); |
| ... | ... | @@ -2759,7 +2858,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2759 | 2858 | "tmp.zig:3:5: error: dependency on libc must be explicitly specified in the build command", |
| 2760 | 2859 | }); |
| 2761 | 2860 | |
| 2762 | | cases.addTest("libc headers note", |
| 2861 | ctx.testErrStage1("libc headers note", |
| 2763 | 2862 | \\const c = @cImport(@cInclude("stdio.h")); |
| 2764 | 2863 | \\export fn entry() void { |
| 2765 | 2864 | \\ _ = c.printf("hello, world!\n"); |
| ... | ... | @@ -2770,18 +2869,19 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2770 | 2869 | }); |
| 2771 | 2870 | } |
| 2772 | 2871 | |
| 2773 | | cases.addTest("comptime vector overflow shows the index", |
| 2872 | ctx.testErrStage1("comptime vector overflow shows the index", |
| 2774 | 2873 | \\comptime { |
| 2775 | 2874 | \\ var a: @import("std").meta.Vector(4, u8) = [_]u8{ 1, 2, 255, 4 }; |
| 2776 | 2875 | \\ var b: @import("std").meta.Vector(4, u8) = [_]u8{ 5, 6, 1, 8 }; |
| 2777 | 2876 | \\ var x = a + b; |
| 2877 | \\ _ = x; |
| 2778 | 2878 | \\} |
| 2779 | 2879 | , &[_][]const u8{ |
| 2780 | 2880 | "tmp.zig:4:15: error: operation caused overflow", |
| 2781 | 2881 | "tmp.zig:4:15: note: when computing vector element at index 2", |
| 2782 | 2882 | }); |
| 2783 | 2883 | |
| 2784 | | cases.addTest("packed struct with fields of not allowed types", |
| 2884 | ctx.testErrStage1("packed struct with fields of not allowed types", |
| 2785 | 2885 | \\const A = packed struct { |
| 2786 | 2886 | \\ x: anyerror, |
| 2787 | 2887 | \\}; |
| ... | ... | @@ -2805,24 +2905,31 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2805 | 2905 | \\}; |
| 2806 | 2906 | \\export fn entry1() void { |
| 2807 | 2907 | \\ var a: A = undefined; |
| 2908 | \\ _ = a; |
| 2808 | 2909 | \\} |
| 2809 | 2910 | \\export fn entry2() void { |
| 2810 | 2911 | \\ var b: B = undefined; |
| 2912 | \\ _ = b; |
| 2811 | 2913 | \\} |
| 2812 | 2914 | \\export fn entry3() void { |
| 2813 | 2915 | \\ var r: C = undefined; |
| 2916 | \\ _ = r; |
| 2814 | 2917 | \\} |
| 2815 | 2918 | \\export fn entry4() void { |
| 2816 | 2919 | \\ var d: D = undefined; |
| 2920 | \\ _ = d; |
| 2817 | 2921 | \\} |
| 2818 | 2922 | \\export fn entry5() void { |
| 2819 | 2923 | \\ var e: E = undefined; |
| 2924 | \\ _ = e; |
| 2820 | 2925 | \\} |
| 2821 | 2926 | \\export fn entry6() void { |
| 2822 | 2927 | \\ var f: F = undefined; |
| 2928 | \\ _ = f; |
| 2823 | 2929 | \\} |
| 2824 | 2930 | \\export fn entry7() void { |
| 2825 | 2931 | \\ var g: G = undefined; |
| 2932 | \\ _ = g; |
| 2826 | 2933 | \\} |
| 2827 | 2934 | \\const S = struct { |
| 2828 | 2935 | \\ x: i32, |
| ... | ... | @@ -2843,42 +2950,40 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2843 | 2950 | "tmp.zig:14:5: error: non-packed, non-extern struct 'U' not allowed in packed struct; no guaranteed in-memory representation", |
| 2844 | 2951 | "tmp.zig:17:5: error: type '?anyerror' not allowed in packed struct; no guaranteed in-memory representation", |
| 2845 | 2952 | "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", |
| 2953 | "tmp.zig:57:14: note: enum declaration does not specify an integer tag type", |
| 2847 | 2954 | }); |
| 2848 | 2955 | |
| 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; |
| 2956 | ctx.objErrStage1("deduplicate undeclared identifier", |
| 2957 | \\export fn a() void { |
| 2958 | \\ x += 1; |
| 2959 | \\} |
| 2960 | \\export fn b() void { |
| 2961 | \\ x += 1; |
| 2962 | \\} |
| 2963 | , &[_][]const u8{ |
| 2964 | "tmp.zig:2:5: error: use of undeclared identifier 'x'", |
| 2862 | 2965 | }); |
| 2863 | 2966 | |
| 2864 | | cases.add("export generic function", |
| 2967 | ctx.objErrStage1("export generic function", |
| 2865 | 2968 | \\export fn foo(num: anytype) i32 { |
| 2969 | \\ _ = num; |
| 2866 | 2970 | \\ return 0; |
| 2867 | 2971 | \\} |
| 2868 | 2972 | , &[_][]const u8{ |
| 2869 | 2973 | "tmp.zig:1:15: error: parameter of type 'anytype' not allowed in function with calling convention 'C'", |
| 2870 | 2974 | }); |
| 2871 | 2975 | |
| 2872 | | cases.add("C pointer to c_void", |
| 2976 | ctx.objErrStage1("C pointer to c_void", |
| 2873 | 2977 | \\export fn a() void { |
| 2874 | 2978 | \\ var x: *c_void = undefined; |
| 2875 | 2979 | \\ var y: [*c]c_void = x; |
| 2980 | \\ _ = y; |
| 2876 | 2981 | \\} |
| 2877 | 2982 | , &[_][]const u8{ |
| 2878 | 2983 | "tmp.zig:3:16: error: C pointers cannot point to opaque types", |
| 2879 | 2984 | }); |
| 2880 | 2985 | |
| 2881 | | cases.add("directly embedding opaque type in struct and union", |
| 2986 | ctx.objErrStage1("directly embedding opaque type in struct and union", |
| 2882 | 2987 | \\const O = opaque {}; |
| 2883 | 2988 | \\const Foo = struct { |
| 2884 | 2989 | \\ o: O, |
| ... | ... | @@ -2889,74 +2994,85 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2889 | 2994 | \\}; |
| 2890 | 2995 | \\export fn a() void { |
| 2891 | 2996 | \\ var foo: Foo = undefined; |
| 2997 | \\ _ = foo; |
| 2892 | 2998 | \\} |
| 2893 | 2999 | \\export fn b() void { |
| 2894 | 3000 | \\ var bar: Bar = undefined; |
| 3001 | \\ _ = bar; |
| 2895 | 3002 | \\} |
| 2896 | 3003 | \\export fn c() void { |
| 2897 | 3004 | \\ var baz: *opaque {} = undefined; |
| 2898 | 3005 | \\ const qux = .{baz.*}; |
| 3006 | \\ _ = qux; |
| 2899 | 3007 | \\} |
| 2900 | 3008 | , &[_][]const u8{ |
| 2901 | 3009 | "tmp.zig:3:5: error: opaque types have unknown size and therefore cannot be directly embedded in structs", |
| 2902 | 3010 | "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", |
| 3011 | "tmp.zig:19:22: error: opaque types have unknown size and therefore cannot be directly embedded in structs", |
| 2904 | 3012 | }); |
| 2905 | 3013 | |
| 2906 | | cases.add("implicit cast between C pointer and Zig pointer - bad const/align/child", |
| 3014 | ctx.objErrStage1("implicit cast between C pointer and Zig pointer - bad const/align/child", |
| 2907 | 3015 | \\export fn a() void { |
| 2908 | 3016 | \\ var x: [*c]u8 = undefined; |
| 2909 | 3017 | \\ var y: *align(4) u8 = x; |
| 3018 | \\ _ = y; |
| 2910 | 3019 | \\} |
| 2911 | 3020 | \\export fn b() void { |
| 2912 | 3021 | \\ var x: [*c]const u8 = undefined; |
| 2913 | 3022 | \\ var y: *u8 = x; |
| 3023 | \\ _ = y; |
| 2914 | 3024 | \\} |
| 2915 | 3025 | \\export fn c() void { |
| 2916 | 3026 | \\ var x: [*c]u8 = undefined; |
| 2917 | 3027 | \\ var y: *u32 = x; |
| 3028 | \\ _ = y; |
| 2918 | 3029 | \\} |
| 2919 | 3030 | \\export fn d() void { |
| 2920 | 3031 | \\ var y: *align(1) u32 = undefined; |
| 2921 | 3032 | \\ var x: [*c]u32 = y; |
| 3033 | \\ _ = x; |
| 2922 | 3034 | \\} |
| 2923 | 3035 | \\export fn e() void { |
| 2924 | 3036 | \\ var y: *const u8 = undefined; |
| 2925 | 3037 | \\ var x: [*c]u8 = y; |
| 3038 | \\ _ = x; |
| 2926 | 3039 | \\} |
| 2927 | 3040 | \\export fn f() void { |
| 2928 | 3041 | \\ var y: *u8 = undefined; |
| 2929 | 3042 | \\ var x: [*c]u32 = y; |
| 3043 | \\ _ = x; |
| 2930 | 3044 | \\} |
| 2931 | 3045 | , &[_][]const u8{ |
| 2932 | 3046 | "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'", |
| 3047 | "tmp.zig:8:18: error: cast discards const qualifier", |
| 3048 | "tmp.zig:13:19: error: expected type '*u32', found '[*c]u8'", |
| 3049 | "tmp.zig:13:19: note: pointer type child 'u8' cannot cast into pointer type child 'u32'", |
| 3050 | "tmp.zig:18:22: error: cast increases pointer alignment", |
| 3051 | "tmp.zig:23:21: error: cast discards const qualifier", |
| 3052 | "tmp.zig:28:22: error: expected type '[*c]u32', found '*u8'", |
| 2939 | 3053 | }); |
| 2940 | 3054 | |
| 2941 | | cases.add("implicit casting null c pointer to zig pointer", |
| 3055 | ctx.objErrStage1("implicit casting null c pointer to zig pointer", |
| 2942 | 3056 | \\comptime { |
| 2943 | 3057 | \\ var c_ptr: [*c]u8 = 0; |
| 2944 | 3058 | \\ var zig_ptr: *u8 = c_ptr; |
| 3059 | \\ _ = zig_ptr; |
| 2945 | 3060 | \\} |
| 2946 | 3061 | , &[_][]const u8{ |
| 2947 | 3062 | "tmp.zig:3:24: error: null pointer casted to type '*u8'", |
| 2948 | 3063 | }); |
| 2949 | 3064 | |
| 2950 | | cases.add("implicit casting undefined c pointer to zig pointer", |
| 3065 | ctx.objErrStage1("implicit casting undefined c pointer to zig pointer", |
| 2951 | 3066 | \\comptime { |
| 2952 | 3067 | \\ var c_ptr: [*c]u8 = undefined; |
| 2953 | 3068 | \\ var zig_ptr: *u8 = c_ptr; |
| 3069 | \\ _ = zig_ptr; |
| 2954 | 3070 | \\} |
| 2955 | 3071 | , &[_][]const u8{ |
| 2956 | 3072 | "tmp.zig:3:24: error: use of undefined value here causes undefined behavior", |
| 2957 | 3073 | }); |
| 2958 | 3074 | |
| 2959 | | cases.add("implicit casting C pointers which would mess up null semantics", |
| 3075 | ctx.objErrStage1("implicit casting C pointers which would mess up null semantics", |
| 2960 | 3076 | \\export fn entry() void { |
| 2961 | 3077 | \\ var slice: []const u8 = "aoeu"; |
| 2962 | 3078 | \\ const opt_many_ptr: [*]const u8 = slice.ptr; |
| ... | ... | @@ -2970,6 +3086,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2970 | 3086 | \\ var opt_many_ptr: [*]u8 = slice.ptr; |
| 2971 | 3087 | \\ var ptr_opt_many_ptr = &opt_many_ptr; |
| 2972 | 3088 | \\ var c_ptr: [*c][*c]const u8 = ptr_opt_many_ptr; |
| 3089 | \\ _ = c_ptr; |
| 2973 | 3090 | \\} |
| 2974 | 3091 | , &[_][]const u8{ |
| 2975 | 3092 | "tmp.zig:6:24: error: expected type '*const [*]const u8', found '[*c]const [*c]const u8'", |
| ... | ... | @@ -2980,47 +3097,46 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2980 | 3097 | "tmp.zig:13:35: note: mutable '[*c]const u8' allows illegal null values stored to type '[*]u8'", |
| 2981 | 3098 | }); |
| 2982 | 3099 | |
| 2983 | | cases.add("implicit casting too big integers to C pointers", |
| 3100 | ctx.objErrStage1("implicit casting too big integers to C pointers", |
| 2984 | 3101 | \\export fn a() void { |
| 2985 | 3102 | \\ var ptr: [*c]u8 = (1 << 64) + 1; |
| 3103 | \\ _ = ptr; |
| 2986 | 3104 | \\} |
| 2987 | 3105 | \\export fn b() void { |
| 2988 | 3106 | \\ var x: u65 = 0x1234; |
| 2989 | 3107 | \\ var ptr: [*c]u8 = x; |
| 3108 | \\ _ = ptr; |
| 2990 | 3109 | \\} |
| 2991 | 3110 | , &[_][]const u8{ |
| 2992 | 3111 | "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'", |
| 3112 | "tmp.zig:7:23: error: integer type 'u65' too big for implicit @intToPtr to type '[*c]u8'", |
| 2994 | 3113 | }); |
| 2995 | 3114 | |
| 2996 | | cases.add("C pointer pointing to non C ABI compatible type or has align attr", |
| 3115 | ctx.objErrStage1("C pointer pointing to non C ABI compatible type or has align attr", |
| 2997 | 3116 | \\const Foo = struct {}; |
| 2998 | 3117 | \\export fn a() void { |
| 2999 | 3118 | \\ const T = [*c]Foo; |
| 3000 | 3119 | \\ var t: T = undefined; |
| 3120 | \\ _ = t; |
| 3001 | 3121 | \\} |
| 3002 | 3122 | , &[_][]const u8{ |
| 3003 | 3123 | "tmp.zig:3:19: error: C pointers cannot point to non-C-ABI-compatible type 'Foo'", |
| 3004 | 3124 | }); |
| 3005 | 3125 | |
| 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; |
| 3126 | ctx.objErrStage1("compile log statement warning deduplication in generic fn", |
| 3127 | \\export fn entry() void { |
| 3128 | \\ inner(1); |
| 3129 | \\ inner(2); |
| 3130 | \\} |
| 3131 | \\fn inner(comptime n: usize) void { |
| 3132 | \\ comptime var i = 0; |
| 3133 | \\ inline while (i < n) : (i += 1) { @compileLog("!@#$"); } |
| 3134 | \\} |
| 3135 | , &[_][]const u8{ |
| 3136 | "tmp.zig:7:39: error: found compile log statement", |
| 3021 | 3137 | }); |
| 3022 | 3138 | |
| 3023 | | cases.add("assign to invalid dereference", |
| 3139 | ctx.objErrStage1("assign to invalid dereference", |
| 3024 | 3140 | \\export fn entry() void { |
| 3025 | 3141 | \\ 'a'.* = 1; |
| 3026 | 3142 | \\} |
| ... | ... | @@ -3028,54 +3144,58 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3028 | 3144 | "tmp.zig:2:8: error: attempt to dereference non-pointer type 'comptime_int'", |
| 3029 | 3145 | }); |
| 3030 | 3146 | |
| 3031 | | cases.add("take slice of invalid dereference", |
| 3147 | ctx.objErrStage1("take slice of invalid dereference", |
| 3032 | 3148 | \\export fn entry() void { |
| 3033 | 3149 | \\ const x = 'a'.*[0..]; |
| 3150 | \\ _ = x; |
| 3034 | 3151 | \\} |
| 3035 | 3152 | , &[_][]const u8{ |
| 3036 | 3153 | "tmp.zig:2:18: error: attempt to dereference non-pointer type 'comptime_int'", |
| 3037 | 3154 | }); |
| 3038 | 3155 | |
| 3039 | | cases.add("@truncate undefined value", |
| 3156 | ctx.objErrStage1("@truncate undefined value", |
| 3040 | 3157 | \\export fn entry() void { |
| 3041 | 3158 | \\ var z = @truncate(u8, @as(u16, undefined)); |
| 3159 | \\ _ = z; |
| 3042 | 3160 | \\} |
| 3043 | 3161 | , &[_][]const u8{ |
| 3044 | 3162 | "tmp.zig:2:27: error: use of undefined value here causes undefined behavior", |
| 3045 | 3163 | }); |
| 3046 | 3164 | |
| 3047 | | cases.addTest("return invalid type from test", |
| 3165 | ctx.testErrStage1("return invalid type from test", |
| 3048 | 3166 | \\test "example" { return 1; } |
| 3049 | 3167 | , &[_][]const u8{ |
| 3050 | 3168 | "tmp.zig:1:25: error: expected type 'void', found 'comptime_int'", |
| 3051 | 3169 | }); |
| 3052 | 3170 | |
| 3053 | | cases.add("threadlocal qualifier on const", |
| 3171 | ctx.objErrStage1("threadlocal qualifier on const", |
| 3054 | 3172 | \\threadlocal const x: i32 = 1234; |
| 3055 | 3173 | \\export fn entry() i32 { |
| 3056 | 3174 | \\ return x; |
| 3057 | 3175 | \\} |
| 3058 | 3176 | , &[_][]const u8{ |
| 3059 | | "tmp.zig:1:13: error: threadlocal variable cannot be constant", |
| 3177 | "tmp.zig:1:1: error: threadlocal variable cannot be constant", |
| 3060 | 3178 | }); |
| 3061 | 3179 | |
| 3062 | | cases.add("@bitCast same size but bit count mismatch", |
| 3180 | ctx.objErrStage1("@bitCast same size but bit count mismatch", |
| 3063 | 3181 | \\export fn entry(byte: u8) void { |
| 3064 | 3182 | \\ var oops = @bitCast(u7, byte); |
| 3183 | \\ _ = oops; |
| 3065 | 3184 | \\} |
| 3066 | 3185 | , &[_][]const u8{ |
| 3067 | 3186 | "tmp.zig:2:25: error: destination type 'u7' has 7 bits but source type 'u8' has 8 bits", |
| 3068 | 3187 | }); |
| 3069 | 3188 | |
| 3070 | | cases.add("@bitCast with different sizes inside an expression", |
| 3189 | ctx.objErrStage1("@bitCast with different sizes inside an expression", |
| 3071 | 3190 | \\export fn entry() void { |
| 3072 | 3191 | \\ var foo = (@bitCast(u8, @as(f32, 1.0)) == 0xf); |
| 3192 | \\ _ = foo; |
| 3073 | 3193 | \\} |
| 3074 | 3194 | , &[_][]const u8{ |
| 3075 | 3195 | "tmp.zig:2:25: error: destination type 'u8' has size 1 but source type 'f32' has size 4", |
| 3076 | 3196 | }); |
| 3077 | 3197 | |
| 3078 | | cases.add("attempted `&&`", |
| 3198 | ctx.objErrStage1("attempted `&&`", |
| 3079 | 3199 | \\export fn entry(a: bool, b: bool) i32 { |
| 3080 | 3200 | \\ if (a && b) { |
| 3081 | 3201 | \\ return 1234; |
| ... | ... | @@ -3083,10 +3203,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3083 | 3203 | \\ return 5678; |
| 3084 | 3204 | \\} |
| 3085 | 3205 | , &[_][]const u8{ |
| 3086 | | "tmp.zig:2:12: error: `&&` is invalid. Note that `and` is boolean AND", |
| 3206 | "tmp.zig:2:11: error: `&&` is invalid; note that `and` is boolean AND", |
| 3087 | 3207 | }); |
| 3088 | 3208 | |
| 3089 | | cases.add("attempted `||` on boolean values", |
| 3209 | ctx.objErrStage1("attempted `||` on boolean values", |
| 3090 | 3210 | \\export fn entry(a: bool, b: bool) i32 { |
| 3091 | 3211 | \\ if (a || b) { |
| 3092 | 3212 | \\ return 1234; |
| ... | ... | @@ -3098,7 +3218,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3098 | 3218 | "tmp.zig:2:11: note: `||` merges error sets; `or` performs boolean OR", |
| 3099 | 3219 | }); |
| 3100 | 3220 | |
| 3101 | | cases.add("compile log a pointer to an opaque value", |
| 3221 | ctx.objErrStage1("compile log a pointer to an opaque value", |
| 3102 | 3222 | \\export fn entry() void { |
| 3103 | 3223 | \\ @compileLog(@ptrCast(*const c_void, &entry)); |
| 3104 | 3224 | \\} |
| ... | ... | @@ -3106,13 +3226,14 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3106 | 3226 | "tmp.zig:2:5: error: found compile log statement", |
| 3107 | 3227 | }); |
| 3108 | 3228 | |
| 3109 | | cases.add("duplicate boolean switch value", |
| 3229 | ctx.objErrStage1("duplicate boolean switch value", |
| 3110 | 3230 | \\comptime { |
| 3111 | 3231 | \\ const x = switch (true) { |
| 3112 | 3232 | \\ true => false, |
| 3113 | 3233 | \\ false => true, |
| 3114 | 3234 | \\ true => false, |
| 3115 | 3235 | \\ }; |
| 3236 | \\ _ = x; |
| 3116 | 3237 | \\} |
| 3117 | 3238 | \\comptime { |
| 3118 | 3239 | \\ const x = switch (true) { |
| ... | ... | @@ -3120,42 +3241,46 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3120 | 3241 | \\ true => false, |
| 3121 | 3242 | \\ false => true, |
| 3122 | 3243 | \\ }; |
| 3244 | \\ _ = x; |
| 3123 | 3245 | \\} |
| 3124 | 3246 | , &[_][]const u8{ |
| 3125 | 3247 | "tmp.zig:5:9: error: duplicate switch value", |
| 3126 | | "tmp.zig:12:9: error: duplicate switch value", |
| 3248 | "tmp.zig:13:9: error: duplicate switch value", |
| 3127 | 3249 | }); |
| 3128 | 3250 | |
| 3129 | | cases.add("missing boolean switch value", |
| 3251 | ctx.objErrStage1("missing boolean switch value", |
| 3130 | 3252 | \\comptime { |
| 3131 | 3253 | \\ const x = switch (true) { |
| 3132 | 3254 | \\ true => false, |
| 3133 | 3255 | \\ }; |
| 3256 | \\ _ = x; |
| 3134 | 3257 | \\} |
| 3135 | 3258 | \\comptime { |
| 3136 | 3259 | \\ const x = switch (true) { |
| 3137 | 3260 | \\ false => true, |
| 3138 | 3261 | \\ }; |
| 3262 | \\ _ = x; |
| 3139 | 3263 | \\} |
| 3140 | 3264 | , &[_][]const u8{ |
| 3141 | 3265 | "tmp.zig:2:15: error: switch must handle all possibilities", |
| 3142 | | "tmp.zig:7:15: error: switch must handle all possibilities", |
| 3266 | "tmp.zig:8:15: error: switch must handle all possibilities", |
| 3143 | 3267 | }); |
| 3144 | 3268 | |
| 3145 | | cases.add("reading past end of pointer casted array", |
| 3269 | ctx.objErrStage1("reading past end of pointer casted array", |
| 3146 | 3270 | \\comptime { |
| 3147 | 3271 | \\ const array: [4]u8 = "aoeu".*; |
| 3148 | 3272 | \\ const sub_array = array[1..]; |
| 3149 | 3273 | \\ const int_ptr = @ptrCast(*const u24, sub_array); |
| 3150 | 3274 | \\ const deref = int_ptr.*; |
| 3275 | \\ _ = deref; |
| 3151 | 3276 | \\} |
| 3152 | 3277 | , &[_][]const u8{ |
| 3153 | 3278 | "tmp.zig:5:26: error: attempt to read 4 bytes from [4]u8 at index 1 which is 3 bytes", |
| 3154 | 3279 | }); |
| 3155 | 3280 | |
| 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 {} |
| 3281 | ctx.objErrStage1("error note for function parameter incompatibility", |
| 3282 | \\fn do_the_thing(func: fn (arg: i32) void) void { _ = func; } |
| 3283 | \\fn bar(arg: bool) void { _ = arg; } |
| 3159 | 3284 | \\export fn entry() void { |
| 3160 | 3285 | \\ do_the_thing(bar); |
| 3161 | 3286 | \\} |
| ... | ... | @@ -3163,56 +3288,63 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3163 | 3288 | "tmp.zig:4:18: error: expected type 'fn(i32) void', found 'fn(bool) void", |
| 3164 | 3289 | "tmp.zig:4:18: note: parameter 0: 'bool' cannot cast into 'i32'", |
| 3165 | 3290 | }); |
| 3166 | | cases.add("cast negative value to unsigned integer", |
| 3291 | ctx.objErrStage1("cast negative value to unsigned integer", |
| 3167 | 3292 | \\comptime { |
| 3168 | 3293 | \\ const value: i32 = -1; |
| 3169 | 3294 | \\ const unsigned = @intCast(u32, value); |
| 3295 | \\ _ = unsigned; |
| 3170 | 3296 | \\} |
| 3171 | 3297 | \\export fn entry1() void { |
| 3172 | 3298 | \\ const value: i32 = -1; |
| 3173 | 3299 | \\ const unsigned: u32 = value; |
| 3300 | \\ _ = unsigned; |
| 3174 | 3301 | \\} |
| 3175 | 3302 | , &[_][]const u8{ |
| 3176 | 3303 | "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'", |
| 3304 | "tmp.zig:8:27: error: cannot cast negative value -1 to unsigned integer type 'u32'", |
| 3178 | 3305 | }); |
| 3179 | 3306 | |
| 3180 | | cases.add("integer cast truncates bits", |
| 3307 | ctx.objErrStage1("integer cast truncates bits", |
| 3181 | 3308 | \\export fn entry1() void { |
| 3182 | 3309 | \\ const spartan_count: u16 = 300; |
| 3183 | 3310 | \\ const byte = @intCast(u8, spartan_count); |
| 3311 | \\ _ = byte; |
| 3184 | 3312 | \\} |
| 3185 | 3313 | \\export fn entry2() void { |
| 3186 | 3314 | \\ const spartan_count: u16 = 300; |
| 3187 | 3315 | \\ const byte: u8 = spartan_count; |
| 3316 | \\ _ = byte; |
| 3188 | 3317 | \\} |
| 3189 | 3318 | \\export fn entry3() void { |
| 3190 | 3319 | \\ var spartan_count: u16 = 300; |
| 3191 | 3320 | \\ var byte: u8 = spartan_count; |
| 3321 | \\ _ = byte; |
| 3192 | 3322 | \\} |
| 3193 | 3323 | \\export fn entry4() void { |
| 3194 | 3324 | \\ var signed: i8 = -1; |
| 3195 | 3325 | \\ var unsigned: u64 = signed; |
| 3326 | \\ _ = unsigned; |
| 3196 | 3327 | \\} |
| 3197 | 3328 | , &[_][]const u8{ |
| 3198 | 3329 | "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", |
| 3330 | "tmp.zig:8:22: error: integer value 300 cannot be coerced to type 'u8'", |
| 3331 | "tmp.zig:13:20: error: expected type 'u8', found 'u16'", |
| 3332 | "tmp.zig:13:20: note: unsigned 8-bit int cannot represent all possible unsigned 16-bit values", |
| 3333 | "tmp.zig:18:25: error: expected type 'u64', found 'i8'", |
| 3334 | "tmp.zig:18:25: note: unsigned 64-bit int cannot represent all possible signed 8-bit values", |
| 3204 | 3335 | }); |
| 3205 | 3336 | |
| 3206 | | cases.add("comptime implicit cast f64 to f32", |
| 3337 | ctx.objErrStage1("comptime implicit cast f64 to f32", |
| 3207 | 3338 | \\export fn entry() void { |
| 3208 | 3339 | \\ const x: f64 = 16777217; |
| 3209 | 3340 | \\ const y: f32 = x; |
| 3341 | \\ _ = y; |
| 3210 | 3342 | \\} |
| 3211 | 3343 | , &[_][]const u8{ |
| 3212 | 3344 | "tmp.zig:3:20: error: cast of value 16777217.000000 to type 'f32' loses information", |
| 3213 | 3345 | }); |
| 3214 | 3346 | |
| 3215 | | cases.add("implicit cast from f64 to f32", |
| 3347 | ctx.objErrStage1("implicit cast from f64 to f32", |
| 3216 | 3348 | \\var x: f64 = 1.0; |
| 3217 | 3349 | \\var y: f32 = x; |
| 3218 | 3350 | \\ |
| ... | ... | @@ -3221,41 +3353,46 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3221 | 3353 | "tmp.zig:2:14: error: expected type 'f32', found 'f64'", |
| 3222 | 3354 | }); |
| 3223 | 3355 | |
| 3224 | | cases.add("exceeded maximum bit width of integer", |
| 3356 | ctx.objErrStage1("exceeded maximum bit width of integer", |
| 3225 | 3357 | \\export fn entry1() void { |
| 3226 | 3358 | \\ const T = u65536; |
| 3359 | \\ _ = T; |
| 3227 | 3360 | \\} |
| 3228 | 3361 | \\export fn entry2() void { |
| 3229 | 3362 | \\ var x: i65536 = 1; |
| 3363 | \\ _ = x; |
| 3230 | 3364 | \\} |
| 3231 | 3365 | , &[_][]const u8{ |
| 3232 | | "tmp.zig:5:12: error: primitive integer type 'i65536' exceeds maximum bit width of 65535", |
| 3366 | "tmp.zig:2:15: error: primitive integer type 'u65536' exceeds maximum bit width of 65535", |
| 3367 | "tmp.zig:6:12: error: primitive integer type 'i65536' exceeds maximum bit width of 65535", |
| 3233 | 3368 | }); |
| 3234 | 3369 | |
| 3235 | | cases.add("compile error when evaluating return type of inferred error set", |
| 3370 | ctx.objErrStage1("compile error when evaluating return type of inferred error set", |
| 3236 | 3371 | \\const Car = struct { |
| 3237 | 3372 | \\ foo: *SymbolThatDoesNotExist, |
| 3238 | 3373 | \\ pub fn init() !Car {} |
| 3239 | 3374 | \\}; |
| 3240 | 3375 | \\export fn entry() void { |
| 3241 | 3376 | \\ const car = Car.init(); |
| 3377 | \\ _ = car; |
| 3242 | 3378 | \\} |
| 3243 | 3379 | , &[_][]const u8{ |
| 3244 | 3380 | "tmp.zig:2:11: error: use of undeclared identifier 'SymbolThatDoesNotExist'", |
| 3245 | 3381 | }); |
| 3246 | 3382 | |
| 3247 | | cases.add("don't implicit cast double pointer to *c_void", |
| 3383 | ctx.objErrStage1("don't implicit cast double pointer to *c_void", |
| 3248 | 3384 | \\export fn entry() void { |
| 3249 | 3385 | \\ var a: u32 = 1; |
| 3250 | 3386 | \\ var ptr: *align(@alignOf(u32)) c_void = &a; |
| 3251 | 3387 | \\ var b: *u32 = @ptrCast(*u32, ptr); |
| 3252 | 3388 | \\ var ptr2: *c_void = &b; |
| 3389 | \\ _ = ptr2; |
| 3253 | 3390 | \\} |
| 3254 | 3391 | , &[_][]const u8{ |
| 3255 | 3392 | "tmp.zig:5:26: error: expected type '*c_void', found '**u32'", |
| 3256 | 3393 | }); |
| 3257 | 3394 | |
| 3258 | | cases.add("runtime index into comptime type slice", |
| 3395 | ctx.objErrStage1("runtime index into comptime type slice", |
| 3259 | 3396 | \\const Struct = struct { |
| 3260 | 3397 | \\ a: u32, |
| 3261 | 3398 | \\}; |
| ... | ... | @@ -3265,12 +3402,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3265 | 3402 | \\export fn entry() void { |
| 3266 | 3403 | \\ const index = getIndex(); |
| 3267 | 3404 | \\ const field = @typeInfo(Struct).Struct.fields[index]; |
| 3405 | \\ _ = field; |
| 3268 | 3406 | \\} |
| 3269 | 3407 | , &[_][]const u8{ |
| 3270 | 3408 | "tmp.zig:9:51: error: values of type 'std.builtin.StructField' must be comptime known, but index value is runtime known", |
| 3271 | 3409 | }); |
| 3272 | 3410 | |
| 3273 | | cases.add("compile log statement inside function which must be comptime evaluated", |
| 3411 | ctx.objErrStage1("compile log statement inside function which must be comptime evaluated", |
| 3274 | 3412 | \\fn Foo(comptime T: type) type { |
| 3275 | 3413 | \\ @compileLog(@typeName(T)); |
| 3276 | 3414 | \\ return T; |
| ... | ... | @@ -3283,25 +3421,27 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3283 | 3421 | "tmp.zig:2:5: error: found compile log statement", |
| 3284 | 3422 | }); |
| 3285 | 3423 | |
| 3286 | | cases.add("comptime slice of an undefined slice", |
| 3424 | ctx.objErrStage1("comptime slice of an undefined slice", |
| 3287 | 3425 | \\comptime { |
| 3288 | 3426 | \\ var a: []u8 = undefined; |
| 3289 | 3427 | \\ var b = a[0..10]; |
| 3428 | \\ _ = b; |
| 3290 | 3429 | \\} |
| 3291 | 3430 | , &[_][]const u8{ |
| 3292 | 3431 | "tmp.zig:3:14: error: slice of undefined", |
| 3293 | 3432 | }); |
| 3294 | 3433 | |
| 3295 | | cases.add("implicit cast const array to mutable slice", |
| 3434 | ctx.objErrStage1("implicit cast const array to mutable slice", |
| 3296 | 3435 | \\export fn entry() void { |
| 3297 | 3436 | \\ const buffer: [1]u8 = [_]u8{8}; |
| 3298 | 3437 | \\ const sliceA: []u8 = &buffer; |
| 3438 | \\ _ = sliceA; |
| 3299 | 3439 | \\} |
| 3300 | 3440 | , &[_][]const u8{ |
| 3301 | 3441 | "tmp.zig:3:27: error: expected type '[]u8', found '*const [1]u8'", |
| 3302 | 3442 | }); |
| 3303 | 3443 | |
| 3304 | | cases.add("deref slice and get len field", |
| 3444 | ctx.objErrStage1("deref slice and get len field", |
| 3305 | 3445 | \\export fn entry() void { |
| 3306 | 3446 | \\ var a: []u8 = undefined; |
| 3307 | 3447 | \\ _ = a.*.len; |
| ... | ... | @@ -3310,7 +3450,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3310 | 3450 | "tmp.zig:3:10: error: attempt to dereference non-pointer type '[]u8'", |
| 3311 | 3451 | }); |
| 3312 | 3452 | |
| 3313 | | cases.add("@ptrCast a 0 bit type to a non- 0 bit type", |
| 3453 | ctx.objErrStage1("@ptrCast a 0 bit type to a non- 0 bit type", |
| 3314 | 3454 | \\export fn entry() bool { |
| 3315 | 3455 | \\ var x: u0 = 0; |
| 3316 | 3456 | \\ const p = @ptrCast(?*u0, &x); |
| ... | ... | @@ -3322,7 +3462,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3322 | 3462 | "tmp.zig:3:24: note: '?*u0' has in-memory bits", |
| 3323 | 3463 | }); |
| 3324 | 3464 | |
| 3325 | | cases.add("comparing a non-optional pointer against null", |
| 3465 | ctx.objErrStage1("comparing a non-optional pointer against null", |
| 3326 | 3466 | \\export fn entry() void { |
| 3327 | 3467 | \\ var x: i32 = 1; |
| 3328 | 3468 | \\ _ = &x == null; |
| ... | ... | @@ -3331,21 +3471,23 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3331 | 3471 | "tmp.zig:3:12: error: comparison of '*i32' with null", |
| 3332 | 3472 | }); |
| 3333 | 3473 | |
| 3334 | | cases.add("non error sets used in merge error sets operator", |
| 3474 | ctx.objErrStage1("non error sets used in merge error sets operator", |
| 3335 | 3475 | \\export fn foo() void { |
| 3336 | 3476 | \\ const Errors = u8 || u16; |
| 3477 | \\ _ = Errors; |
| 3337 | 3478 | \\} |
| 3338 | 3479 | \\export fn bar() void { |
| 3339 | 3480 | \\ const Errors = error{} || u16; |
| 3481 | \\ _ = Errors; |
| 3340 | 3482 | \\} |
| 3341 | 3483 | , &[_][]const u8{ |
| 3342 | 3484 | "tmp.zig:2:20: error: expected error set type, found type 'u8'", |
| 3343 | 3485 | "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", |
| 3486 | "tmp.zig:6:31: error: expected error set type, found type 'u16'", |
| 3487 | "tmp.zig:6:28: note: `||` merges error sets; `or` performs boolean OR", |
| 3346 | 3488 | }); |
| 3347 | 3489 | |
| 3348 | | cases.add("variable initialization compile error then referenced", |
| 3490 | ctx.objErrStage1("variable initialization compile error then referenced", |
| 3349 | 3491 | \\fn Undeclared() type { |
| 3350 | 3492 | \\ return T; |
| 3351 | 3493 | \\} |
| ... | ... | @@ -3357,12 +3499,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3357 | 3499 | \\} |
| 3358 | 3500 | \\export fn entry() void { |
| 3359 | 3501 | \\ const S = Gen(); |
| 3502 | \\ _ = S; |
| 3360 | 3503 | \\} |
| 3361 | 3504 | , &[_][]const u8{ |
| 3362 | 3505 | "tmp.zig:2:12: error: use of undeclared identifier 'T'", |
| 3363 | 3506 | }); |
| 3364 | 3507 | |
| 3365 | | cases.add("refer to the type of a generic function", |
| 3508 | ctx.objErrStage1("refer to the type of a generic function", |
| 3366 | 3509 | \\export fn entry() void { |
| 3367 | 3510 | \\ const Func = fn (type) void; |
| 3368 | 3511 | \\ const f: Func = undefined; |
| ... | ... | @@ -3372,7 +3515,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3372 | 3515 | "tmp.zig:4:5: error: use of undefined value here causes undefined behavior", |
| 3373 | 3516 | }); |
| 3374 | 3517 | |
| 3375 | | cases.add("accessing runtime parameter from outer function", |
| 3518 | ctx.objErrStage1("accessing runtime parameter from outer function", |
| 3376 | 3519 | \\fn outer(y: u32) fn (u32) u32 { |
| 3377 | 3520 | \\ const st = struct { |
| 3378 | 3521 | \\ fn get(z: u32) u32 { |
| ... | ... | @@ -3384,6 +3527,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3384 | 3527 | \\export fn entry() void { |
| 3385 | 3528 | \\ var func = outer(10); |
| 3386 | 3529 | \\ var x = func(3); |
| 3530 | \\ _ = x; |
| 3387 | 3531 | \\} |
| 3388 | 3532 | , &[_][]const u8{ |
| 3389 | 3533 | "tmp.zig:4:24: error: 'y' not accessible from inner function", |
| ... | ... | @@ -3391,69 +3535,74 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3391 | 3535 | "tmp.zig:1:10: note: declared here", |
| 3392 | 3536 | }); |
| 3393 | 3537 | |
| 3394 | | cases.add("non int passed to @intToFloat", |
| 3538 | ctx.objErrStage1("non int passed to @intToFloat", |
| 3395 | 3539 | \\export fn entry() void { |
| 3396 | 3540 | \\ const x = @intToFloat(f32, 1.1); |
| 3541 | \\ _ = x; |
| 3397 | 3542 | \\} |
| 3398 | 3543 | , &[_][]const u8{ |
| 3399 | 3544 | "tmp.zig:2:32: error: expected int type, found 'comptime_float'", |
| 3400 | 3545 | }); |
| 3401 | 3546 | |
| 3402 | | cases.add("non float passed to @floatToInt", |
| 3547 | ctx.objErrStage1("non float passed to @floatToInt", |
| 3403 | 3548 | \\export fn entry() void { |
| 3404 | 3549 | \\ const x = @floatToInt(i32, @as(i32, 54)); |
| 3550 | \\ _ = x; |
| 3405 | 3551 | \\} |
| 3406 | 3552 | , &[_][]const u8{ |
| 3407 | 3553 | "tmp.zig:2:32: error: expected float type, found 'i32'", |
| 3408 | 3554 | }); |
| 3409 | 3555 | |
| 3410 | | cases.add("out of range comptime_int passed to @floatToInt", |
| 3556 | ctx.objErrStage1("out of range comptime_int passed to @floatToInt", |
| 3411 | 3557 | \\export fn entry() void { |
| 3412 | 3558 | \\ const x = @floatToInt(i8, 200); |
| 3559 | \\ _ = x; |
| 3413 | 3560 | \\} |
| 3414 | 3561 | , &[_][]const u8{ |
| 3415 | 3562 | "tmp.zig:2:31: error: integer value 200 cannot be coerced to type 'i8'", |
| 3416 | 3563 | }); |
| 3417 | 3564 | |
| 3418 | | cases.add("load too many bytes from comptime reinterpreted pointer", |
| 3565 | ctx.objErrStage1("load too many bytes from comptime reinterpreted pointer", |
| 3419 | 3566 | \\export fn entry() void { |
| 3420 | 3567 | \\ const float: f32 = 5.99999999999994648725e-01; |
| 3421 | 3568 | \\ const float_ptr = &float; |
| 3422 | 3569 | \\ const int_ptr = @ptrCast(*const i64, float_ptr); |
| 3423 | 3570 | \\ const int_val = int_ptr.*; |
| 3571 | \\ _ = int_val; |
| 3424 | 3572 | \\} |
| 3425 | 3573 | , &[_][]const u8{ |
| 3426 | 3574 | "tmp.zig:5:28: error: attempt to read 8 bytes from pointer to f32 which is 4 bytes", |
| 3427 | 3575 | }); |
| 3428 | 3576 | |
| 3429 | | cases.add("invalid type used in array type", |
| 3577 | ctx.objErrStage1("invalid type used in array type", |
| 3430 | 3578 | \\const Item = struct { |
| 3431 | 3579 | \\ field: SomeNonexistentType, |
| 3432 | 3580 | \\}; |
| 3433 | 3581 | \\var items: [100]Item = undefined; |
| 3434 | 3582 | \\export fn entry() void { |
| 3435 | 3583 | \\ const a = items[0]; |
| 3584 | \\ _ = a; |
| 3436 | 3585 | \\} |
| 3437 | 3586 | , &[_][]const u8{ |
| 3438 | 3587 | "tmp.zig:2:12: error: use of undeclared identifier 'SomeNonexistentType'", |
| 3439 | 3588 | }); |
| 3440 | 3589 | |
| 3441 | | cases.add("comptime continue inside runtime catch", |
| 3442 | | \\export fn entry(c: bool) void { |
| 3590 | ctx.objErrStage1("comptime continue inside runtime catch", |
| 3591 | \\export fn entry() void { |
| 3443 | 3592 | \\ const ints = [_]u8{ 1, 2 }; |
| 3444 | 3593 | \\ inline for (ints) |_| { |
| 3445 | | \\ bad() catch |_| continue; |
| 3594 | \\ bad() catch continue; |
| 3446 | 3595 | \\ } |
| 3447 | 3596 | \\} |
| 3448 | 3597 | \\fn bad() !void { |
| 3449 | 3598 | \\ return error.Bad; |
| 3450 | 3599 | \\} |
| 3451 | 3600 | , &[_][]const u8{ |
| 3452 | | "tmp.zig:4:25: error: comptime control flow inside runtime block", |
| 3601 | "tmp.zig:4:21: error: comptime control flow inside runtime block", |
| 3453 | 3602 | "tmp.zig:4:15: note: runtime block created here", |
| 3454 | 3603 | }); |
| 3455 | 3604 | |
| 3456 | | cases.add("comptime continue inside runtime switch", |
| 3605 | ctx.objErrStage1("comptime continue inside runtime switch", |
| 3457 | 3606 | \\export fn entry() void { |
| 3458 | 3607 | \\ var p: i32 = undefined; |
| 3459 | 3608 | \\ comptime var q = true; |
| ... | ... | @@ -3470,7 +3619,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3470 | 3619 | "tmp.zig:5:9: note: runtime block created here", |
| 3471 | 3620 | }); |
| 3472 | 3621 | |
| 3473 | | cases.add("comptime continue inside runtime while error", |
| 3622 | ctx.objErrStage1("comptime continue inside runtime while error", |
| 3474 | 3623 | \\export fn entry() void { |
| 3475 | 3624 | \\ var p: anyerror!usize = undefined; |
| 3476 | 3625 | \\ comptime var q = true; |
| ... | ... | @@ -3486,7 +3635,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3486 | 3635 | "tmp.zig:5:9: note: runtime block created here", |
| 3487 | 3636 | }); |
| 3488 | 3637 | |
| 3489 | | cases.add("comptime continue inside runtime while optional", |
| 3638 | ctx.objErrStage1("comptime continue inside runtime while optional", |
| 3490 | 3639 | \\export fn entry() void { |
| 3491 | 3640 | \\ var p: ?usize = undefined; |
| 3492 | 3641 | \\ comptime var q = true; |
| ... | ... | @@ -3500,7 +3649,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3500 | 3649 | "tmp.zig:5:9: note: runtime block created here", |
| 3501 | 3650 | }); |
| 3502 | 3651 | |
| 3503 | | cases.add("comptime continue inside runtime while bool", |
| 3652 | ctx.objErrStage1("comptime continue inside runtime while bool", |
| 3504 | 3653 | \\export fn entry() void { |
| 3505 | 3654 | \\ var p: usize = undefined; |
| 3506 | 3655 | \\ comptime var q = true; |
| ... | ... | @@ -3514,7 +3663,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3514 | 3663 | "tmp.zig:5:9: note: runtime block created here", |
| 3515 | 3664 | }); |
| 3516 | 3665 | |
| 3517 | | cases.add("comptime continue inside runtime if error", |
| 3666 | ctx.objErrStage1("comptime continue inside runtime if error", |
| 3518 | 3667 | \\export fn entry() void { |
| 3519 | 3668 | \\ var p: anyerror!i32 = undefined; |
| 3520 | 3669 | \\ comptime var q = true; |
| ... | ... | @@ -3528,7 +3677,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3528 | 3677 | "tmp.zig:5:9: note: runtime block created here", |
| 3529 | 3678 | }); |
| 3530 | 3679 | |
| 3531 | | cases.add("comptime continue inside runtime if optional", |
| 3680 | ctx.objErrStage1("comptime continue inside runtime if optional", |
| 3532 | 3681 | \\export fn entry() void { |
| 3533 | 3682 | \\ var p: ?i32 = undefined; |
| 3534 | 3683 | \\ comptime var q = true; |
| ... | ... | @@ -3542,7 +3691,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3542 | 3691 | "tmp.zig:5:9: note: runtime block created here", |
| 3543 | 3692 | }); |
| 3544 | 3693 | |
| 3545 | | cases.add("comptime continue inside runtime if bool", |
| 3694 | ctx.objErrStage1("comptime continue inside runtime if bool", |
| 3546 | 3695 | \\export fn entry() void { |
| 3547 | 3696 | \\ var p: usize = undefined; |
| 3548 | 3697 | \\ comptime var q = true; |
| ... | ... | @@ -3556,22 +3705,23 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3556 | 3705 | "tmp.zig:5:9: note: runtime block created here", |
| 3557 | 3706 | }); |
| 3558 | 3707 | |
| 3559 | | cases.add("switch with invalid expression parameter", |
| 3708 | ctx.objErrStage1("switch with invalid expression parameter", |
| 3560 | 3709 | \\export fn entry() void { |
| 3561 | 3710 | \\ Test(i32); |
| 3562 | 3711 | \\} |
| 3563 | 3712 | \\fn Test(comptime T: type) void { |
| 3564 | 3713 | \\ const x = switch (T) { |
| 3565 | | \\ []u8 => |x| 123, |
| 3566 | | \\ i32 => |x| 456, |
| 3714 | \\ []u8 => |x| x, |
| 3715 | \\ i32 => |x| x, |
| 3567 | 3716 | \\ else => unreachable, |
| 3568 | 3717 | \\ }; |
| 3718 | \\ _ = x; |
| 3569 | 3719 | \\} |
| 3570 | 3720 | , &[_][]const u8{ |
| 3571 | 3721 | "tmp.zig:7:17: error: switch on type 'type' provides no expression parameter", |
| 3572 | 3722 | }); |
| 3573 | 3723 | |
| 3574 | | cases.add("function prototype with no body", |
| 3724 | ctx.objErrStage1("function prototype with no body", |
| 3575 | 3725 | \\fn foo() void; |
| 3576 | 3726 | \\export fn entry() void { |
| 3577 | 3727 | \\ foo(); |
| ... | ... | @@ -3580,7 +3730,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3580 | 3730 | "tmp.zig:1:1: error: non-extern function has no body", |
| 3581 | 3731 | }); |
| 3582 | 3732 | |
| 3583 | | cases.add("@frame() called outside of function definition", |
| 3733 | ctx.objErrStage1("@frame() called outside of function definition", |
| 3584 | 3734 | \\var handle_undef: anyframe = undefined; |
| 3585 | 3735 | \\var handle_dummy: anyframe = @frame(); |
| 3586 | 3736 | \\export fn entry() bool { |
| ... | ... | @@ -3590,16 +3740,17 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3590 | 3740 | "tmp.zig:2:30: error: @frame() called outside of function definition", |
| 3591 | 3741 | }); |
| 3592 | 3742 | |
| 3593 | | cases.add("`_` is not a declarable symbol", |
| 3743 | ctx.objErrStage1("`_` is not a declarable symbol", |
| 3594 | 3744 | \\export fn f1() usize { |
| 3595 | 3745 | \\ var _: usize = 2; |
| 3596 | 3746 | \\ return _; |
| 3597 | 3747 | \\} |
| 3598 | 3748 | , &[_][]const u8{ |
| 3599 | | "tmp.zig:2:5: error: `_` is not a declarable symbol", |
| 3749 | "tmp.zig:2:5: error: '_' used as an identifier without @\"_\" syntax", |
| 3750 | "tmp.zig:3:12: error: '_' used as an identifier without @\"_\" syntax", |
| 3600 | 3751 | }); |
| 3601 | 3752 | |
| 3602 | | cases.add("`_` should not be usable inside for", |
| 3753 | ctx.objErrStage1("`_` should not be usable inside for", |
| 3603 | 3754 | \\export fn returns() void { |
| 3604 | 3755 | \\ for ([_]void{}) |_, i| { |
| 3605 | 3756 | \\ for ([_]void{}) |_, j| { |
| ... | ... | @@ -3608,10 +3759,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3608 | 3759 | \\ } |
| 3609 | 3760 | \\} |
| 3610 | 3761 | , &[_][]const u8{ |
| 3611 | | "tmp.zig:4:20: error: `_` may only be used to assign things to", |
| 3762 | "tmp.zig:4:20: error: '_' used as an identifier without @\"_\" syntax", |
| 3612 | 3763 | }); |
| 3613 | 3764 | |
| 3614 | | cases.add("`_` should not be usable inside while", |
| 3765 | ctx.objErrStage1("`_` should not be usable inside while", |
| 3615 | 3766 | \\export fn returns() void { |
| 3616 | 3767 | \\ while (optionalReturn()) |_| { |
| 3617 | 3768 | \\ while (optionalReturn()) |_| { |
| ... | ... | @@ -3623,10 +3774,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3623 | 3774 | \\ return 1; |
| 3624 | 3775 | \\} |
| 3625 | 3776 | , &[_][]const u8{ |
| 3626 | | "tmp.zig:4:20: error: `_` may only be used to assign things to", |
| 3777 | "tmp.zig:4:20: error: '_' used as an identifier without @\"_\" syntax", |
| 3627 | 3778 | }); |
| 3628 | 3779 | |
| 3629 | | cases.add("`_` should not be usable inside while else", |
| 3780 | ctx.objErrStage1("`_` should not be usable inside while else", |
| 3630 | 3781 | \\export fn returns() void { |
| 3631 | 3782 | \\ while (optionalReturnError()) |_| { |
| 3632 | 3783 | \\ while (optionalReturnError()) |_| { |
| ... | ... | @@ -3640,10 +3791,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3640 | 3791 | \\ return error.optionalReturnError; |
| 3641 | 3792 | \\} |
| 3642 | 3793 | , &[_][]const u8{ |
| 3643 | | "tmp.zig:6:17: error: `_` may only be used to assign things to", |
| 3794 | "tmp.zig:6:17: error: '_' used as an identifier without @\"_\" syntax", |
| 3644 | 3795 | }); |
| 3645 | 3796 | |
| 3646 | | cases.add("while loop body expression ignored", |
| 3797 | ctx.objErrStage1("while loop body expression ignored", |
| 3647 | 3798 | \\fn returns() usize { |
| 3648 | 3799 | \\ return 2; |
| 3649 | 3800 | \\} |
| ... | ... | @@ -3664,7 +3815,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3664 | 3815 | "tmp.zig:13:26: error: expression value is ignored", |
| 3665 | 3816 | }); |
| 3666 | 3817 | |
| 3667 | | cases.add("missing parameter name of generic function", |
| 3818 | ctx.objErrStage1("missing parameter name of generic function", |
| 3668 | 3819 | \\fn dump(anytype) void {} |
| 3669 | 3820 | \\export fn entry() void { |
| 3670 | 3821 | \\ var a: u8 = 9; |
| ... | ... | @@ -3674,20 +3825,20 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3674 | 3825 | "tmp.zig:1:9: error: missing parameter name", |
| 3675 | 3826 | }); |
| 3676 | 3827 | |
| 3677 | | cases.add("non-inline for loop on a type that requires comptime", |
| 3828 | ctx.objErrStage1("non-inline for loop on a type that requires comptime", |
| 3678 | 3829 | \\const Foo = struct { |
| 3679 | 3830 | \\ name: []const u8, |
| 3680 | 3831 | \\ T: type, |
| 3681 | 3832 | \\}; |
| 3682 | 3833 | \\export fn entry() void { |
| 3683 | 3834 | \\ const xx: [2]Foo = undefined; |
| 3684 | | \\ for (xx) |f| {} |
| 3835 | \\ for (xx) |f| { _ = f;} |
| 3685 | 3836 | \\} |
| 3686 | 3837 | , &[_][]const u8{ |
| 3687 | 3838 | "tmp.zig:7:5: error: values of type 'Foo' must be comptime known, but index value is runtime known", |
| 3688 | 3839 | }); |
| 3689 | 3840 | |
| 3690 | | cases.add("generic fn as parameter without comptime keyword", |
| 3841 | ctx.objErrStage1("generic fn as parameter without comptime keyword", |
| 3691 | 3842 | \\fn f(_: fn (anytype) void) void {} |
| 3692 | 3843 | \\fn g(_: anytype) void {} |
| 3693 | 3844 | \\export fn entry() void { |
| ... | ... | @@ -3697,7 +3848,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3697 | 3848 | "tmp.zig:1:9: error: parameter of type 'fn(anytype) anytype' must be declared comptime", |
| 3698 | 3849 | }); |
| 3699 | 3850 | |
| 3700 | | cases.add("optional pointer to void in extern struct", |
| 3851 | ctx.objErrStage1("optional pointer to void in extern struct", |
| 3701 | 3852 | \\const Foo = extern struct { |
| 3702 | 3853 | \\ x: ?*const void, |
| 3703 | 3854 | \\}; |
| ... | ... | @@ -3705,12 +3856,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3705 | 3856 | \\ foo: Foo, |
| 3706 | 3857 | \\ y: i32, |
| 3707 | 3858 | \\}; |
| 3708 | | \\export fn entry(bar: *Bar) void {} |
| 3859 | \\export fn entry(bar: *Bar) void {_ = bar;} |
| 3709 | 3860 | , &[_][]const u8{ |
| 3710 | 3861 | "tmp.zig:2:5: error: extern structs cannot contain fields of type '?*const void'", |
| 3711 | 3862 | }); |
| 3712 | 3863 | |
| 3713 | | cases.add("use of comptime-known undefined function value", |
| 3864 | ctx.objErrStage1("use of comptime-known undefined function value", |
| 3714 | 3865 | \\const Cmd = struct { |
| 3715 | 3866 | \\ exec: fn () void, |
| 3716 | 3867 | \\}; |
| ... | ... | @@ -3722,7 +3873,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3722 | 3873 | "tmp.zig:6:12: error: use of undefined value here causes undefined behavior", |
| 3723 | 3874 | }); |
| 3724 | 3875 | |
| 3725 | | cases.add("use of comptime-known undefined function value", |
| 3876 | ctx.objErrStage1("use of comptime-known undefined function value", |
| 3726 | 3877 | \\const Cmd = struct { |
| 3727 | 3878 | \\ exec: fn () void, |
| 3728 | 3879 | \\}; |
| ... | ... | @@ -3734,16 +3885,17 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3734 | 3885 | "tmp.zig:6:12: error: use of undefined value here causes undefined behavior", |
| 3735 | 3886 | }); |
| 3736 | 3887 | |
| 3737 | | cases.add("bad @alignCast at comptime", |
| 3888 | ctx.objErrStage1("bad @alignCast at comptime", |
| 3738 | 3889 | \\comptime { |
| 3739 | 3890 | \\ const ptr = @intToPtr(*align(1) i32, 0x1); |
| 3740 | 3891 | \\ const aligned = @alignCast(4, ptr); |
| 3892 | \\ _ = aligned; |
| 3741 | 3893 | \\} |
| 3742 | 3894 | , &[_][]const u8{ |
| 3743 | 3895 | "tmp.zig:3:35: error: pointer address 0x1 is not aligned to 4 bytes", |
| 3744 | 3896 | }); |
| 3745 | 3897 | |
| 3746 | | cases.add("@ptrToInt on *void", |
| 3898 | ctx.objErrStage1("@ptrToInt on *void", |
| 3747 | 3899 | \\export fn entry() bool { |
| 3748 | 3900 | \\ return @ptrToInt(&{}) == @ptrToInt(&{}); |
| 3749 | 3901 | \\} |
| ... | ... | @@ -3751,7 +3903,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3751 | 3903 | "tmp.zig:2:23: error: pointer to size 0 type has no address", |
| 3752 | 3904 | }); |
| 3753 | 3905 | |
| 3754 | | cases.add("@popCount - non-integer", |
| 3906 | ctx.objErrStage1("@popCount - non-integer", |
| 3755 | 3907 | \\export fn entry(x: f32) u32 { |
| 3756 | 3908 | \\ return @popCount(f32, x); |
| 3757 | 3909 | \\} |
| ... | ... | @@ -3759,8 +3911,23 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3759 | 3911 | "tmp.zig:2:22: error: expected integer type, found 'f32'", |
| 3760 | 3912 | }); |
| 3761 | 3913 | |
| 3762 | | cases.addCase(x: { |
| 3763 | | const tc = cases.create("wrong same named struct", |
| 3914 | { |
| 3915 | const case = ctx.obj("wrong same named struct", .{}); |
| 3916 | case.backend = .stage1; |
| 3917 | |
| 3918 | case.addSourceFile("a.zig", |
| 3919 | \\pub const Foo = struct { |
| 3920 | \\ x: i32, |
| 3921 | \\}; |
| 3922 | ); |
| 3923 | |
| 3924 | case.addSourceFile("b.zig", |
| 3925 | \\pub const Foo = struct { |
| 3926 | \\ z: f64, |
| 3927 | \\}; |
| 3928 | ); |
| 3929 | |
| 3930 | case.addError( |
| 3764 | 3931 | \\const a = @import("a.zig"); |
| 3765 | 3932 | \\const b = @import("b.zig"); |
| 3766 | 3933 | \\ |
| ... | ... | @@ -3769,30 +3936,16 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3769 | 3936 | \\ bar(&a1); |
| 3770 | 3937 | \\} |
| 3771 | 3938 | \\ |
| 3772 | | \\fn bar(x: *b.Foo) void {} |
| 3939 | \\fn bar(x: *b.Foo) void {_ = x;} |
| 3773 | 3940 | , &[_][]const u8{ |
| 3774 | 3941 | "tmp.zig:6:10: error: expected type '*b.Foo', found '*a.Foo'", |
| 3775 | 3942 | "tmp.zig:6:10: note: pointer type child 'a.Foo' cannot cast into pointer type child 'b.Foo'", |
| 3776 | 3943 | "a.zig:1:17: note: a.Foo declared here", |
| 3777 | 3944 | "b.zig:1:17: note: b.Foo declared here", |
| 3778 | 3945 | }); |
| 3946 | } |
| 3779 | 3947 | |
| 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", |
| 3948 | ctx.objErrStage1("@floatToInt comptime safety", |
| 3796 | 3949 | \\comptime { |
| 3797 | 3950 | \\ _ = @floatToInt(i8, @as(f32, -129.1)); |
| 3798 | 3951 | \\} |
| ... | ... | @@ -3808,35 +3961,38 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3808 | 3961 | "tmp.zig:8:9: error: integer value '256' cannot be stored in type 'u8'", |
| 3809 | 3962 | }); |
| 3810 | 3963 | |
| 3811 | | cases.add("use c_void as return type of fn ptr", |
| 3964 | ctx.objErrStage1("use c_void as return type of fn ptr", |
| 3812 | 3965 | \\export fn entry() void { |
| 3813 | 3966 | \\ const a: fn () c_void = undefined; |
| 3967 | \\ _ = a; |
| 3814 | 3968 | \\} |
| 3815 | 3969 | , &[_][]const u8{ |
| 3816 | 3970 | "tmp.zig:2:20: error: return type cannot be opaque", |
| 3817 | 3971 | }); |
| 3818 | 3972 | |
| 3819 | | cases.add("use implicit casts to assign null to non-nullable pointer", |
| 3973 | ctx.objErrStage1("use implicit casts to assign null to non-nullable pointer", |
| 3820 | 3974 | \\export fn entry() void { |
| 3821 | 3975 | \\ var x: i32 = 1234; |
| 3822 | 3976 | \\ var p: *i32 = &x; |
| 3823 | 3977 | \\ var pp: *?*i32 = &p; |
| 3824 | 3978 | \\ pp.* = null; |
| 3825 | 3979 | \\ var y = p.*; |
| 3980 | \\ _ = y; |
| 3826 | 3981 | \\} |
| 3827 | 3982 | , &[_][]const u8{ |
| 3828 | 3983 | "tmp.zig:4:23: error: expected type '*?*i32', found '**i32'", |
| 3829 | 3984 | }); |
| 3830 | 3985 | |
| 3831 | | cases.add("attempted implicit cast from T to [*]const T", |
| 3986 | ctx.objErrStage1("attempted implicit cast from T to [*]const T", |
| 3832 | 3987 | \\export fn entry() void { |
| 3833 | 3988 | \\ const x: [*]const bool = true; |
| 3989 | \\ _ = x; |
| 3834 | 3990 | \\} |
| 3835 | 3991 | , &[_][]const u8{ |
| 3836 | 3992 | "tmp.zig:2:30: error: expected type '[*]const bool', found 'bool'", |
| 3837 | 3993 | }); |
| 3838 | 3994 | |
| 3839 | | cases.add("dereference unknown length pointer", |
| 3995 | ctx.objErrStage1("dereference unknown length pointer", |
| 3840 | 3996 | \\export fn entry(x: [*]i32) i32 { |
| 3841 | 3997 | \\ return x.*; |
| 3842 | 3998 | \\} |
| ... | ... | @@ -3844,7 +4000,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3844 | 4000 | "tmp.zig:2:13: error: index syntax required for unknown-length pointer type '[*]i32'", |
| 3845 | 4001 | }); |
| 3846 | 4002 | |
| 3847 | | cases.add("field access of unknown length pointer", |
| 4003 | ctx.objErrStage1("field access of unknown length pointer", |
| 3848 | 4004 | \\const Foo = extern struct { |
| 3849 | 4005 | \\ a: i32, |
| 3850 | 4006 | \\}; |
| ... | ... | @@ -3856,13 +4012,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3856 | 4012 | "tmp.zig:6:8: error: type '[*]Foo' does not support field access", |
| 3857 | 4013 | }); |
| 3858 | 4014 | |
| 3859 | | cases.add("unknown length pointer to opaque", |
| 4015 | ctx.objErrStage1("unknown length pointer to opaque", |
| 3860 | 4016 | \\export const T = [*]opaque {}; |
| 3861 | 4017 | , &[_][]const u8{ |
| 3862 | 4018 | "tmp.zig:1:21: error: unknown-length pointer to opaque", |
| 3863 | 4019 | }); |
| 3864 | 4020 | |
| 3865 | | cases.add("error when evaluating return type", |
| 4021 | ctx.objErrStage1("error when evaluating return type", |
| 3866 | 4022 | \\const Foo = struct { |
| 3867 | 4023 | \\ map: @as(i32, i32), |
| 3868 | 4024 | \\ |
| ... | ... | @@ -3872,20 +4028,22 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3872 | 4028 | \\}; |
| 3873 | 4029 | \\export fn entry() void { |
| 3874 | 4030 | \\ var rule_set = try Foo.init(); |
| 4031 | \\ _ = rule_set; |
| 3875 | 4032 | \\} |
| 3876 | 4033 | , &[_][]const u8{ |
| 3877 | 4034 | "tmp.zig:2:19: error: expected type 'i32', found 'type'", |
| 3878 | 4035 | }); |
| 3879 | 4036 | |
| 3880 | | cases.add("slicing single-item pointer", |
| 4037 | ctx.objErrStage1("slicing single-item pointer", |
| 3881 | 4038 | \\export fn entry(ptr: *i32) void { |
| 3882 | 4039 | \\ const slice = ptr[0..2]; |
| 4040 | \\ _ = slice; |
| 3883 | 4041 | \\} |
| 3884 | 4042 | , &[_][]const u8{ |
| 3885 | 4043 | "tmp.zig:2:22: error: slice of single-item pointer", |
| 3886 | 4044 | }); |
| 3887 | 4045 | |
| 3888 | | cases.add("indexing single-item pointer", |
| 4046 | ctx.objErrStage1("indexing single-item pointer", |
| 3889 | 4047 | \\export fn entry(ptr: *i32) i32 { |
| 3890 | 4048 | \\ return ptr[1]; |
| 3891 | 4049 | \\} |
| ... | ... | @@ -3893,12 +4051,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3893 | 4051 | "tmp.zig:2:15: error: index of single-item pointer", |
| 3894 | 4052 | }); |
| 3895 | 4053 | |
| 3896 | | cases.add("nested error set mismatch", |
| 4054 | ctx.objErrStage1("nested error set mismatch", |
| 3897 | 4055 | \\const NextError = error{NextError}; |
| 3898 | 4056 | \\const OtherError = error{OutOfMemory}; |
| 3899 | 4057 | \\ |
| 3900 | 4058 | \\export fn entry() void { |
| 3901 | 4059 | \\ const a: ?NextError!i32 = foo(); |
| 4060 | \\ _ = a; |
| 3902 | 4061 | \\} |
| 3903 | 4062 | \\ |
| 3904 | 4063 | \\fn foo() ?OtherError!i32 { |
| ... | ... | @@ -3911,7 +4070,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3911 | 4070 | "tmp.zig:2:26: note: 'error.OutOfMemory' not a member of destination error set", |
| 3912 | 4071 | }); |
| 3913 | 4072 | |
| 3914 | | cases.add("invalid deref on switch target", |
| 4073 | ctx.objErrStage1("invalid deref on switch target", |
| 3915 | 4074 | \\comptime { |
| 3916 | 4075 | \\ var tile = Tile.Empty; |
| 3917 | 4076 | \\ switch (tile.*) { |
| ... | ... | @@ -3927,13 +4086,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3927 | 4086 | "tmp.zig:3:17: error: attempt to dereference non-pointer type 'Tile'", |
| 3928 | 4087 | }); |
| 3929 | 4088 | |
| 3930 | | cases.add("invalid field access in comptime", |
| 3931 | | \\comptime { var x = doesnt_exist.whatever; } |
| 4089 | ctx.objErrStage1("invalid field access in comptime", |
| 4090 | \\comptime { var x = doesnt_exist.whatever; _ = x; } |
| 3932 | 4091 | , &[_][]const u8{ |
| 3933 | 4092 | "tmp.zig:1:20: error: use of undeclared identifier 'doesnt_exist'", |
| 3934 | 4093 | }); |
| 3935 | 4094 | |
| 3936 | | cases.add("suspend inside suspend block", |
| 4095 | ctx.objErrStage1("suspend inside suspend block", |
| 3937 | 4096 | \\export fn entry() void { |
| 3938 | 4097 | \\ _ = async foo(); |
| 3939 | 4098 | \\} |
| ... | ... | @@ -3948,17 +4107,18 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3948 | 4107 | "tmp.zig:5:5: note: other suspend block here", |
| 3949 | 4108 | }); |
| 3950 | 4109 | |
| 3951 | | cases.add("assign inline fn to non-comptime var", |
| 4110 | ctx.objErrStage1("assign inline fn to non-comptime var", |
| 3952 | 4111 | \\export fn entry() void { |
| 3953 | 4112 | \\ var a = b; |
| 4113 | \\ _ = a; |
| 3954 | 4114 | \\} |
| 3955 | 4115 | \\fn b() callconv(.Inline) void { } |
| 3956 | 4116 | , &[_][]const u8{ |
| 3957 | 4117 | "tmp.zig:2:5: error: functions marked inline must be stored in const or comptime var", |
| 3958 | | "tmp.zig:4:1: note: declared here", |
| 4118 | "tmp.zig:5:1: note: declared here", |
| 3959 | 4119 | }); |
| 3960 | 4120 | |
| 3961 | | cases.add("wrong type passed to @panic", |
| 4121 | ctx.objErrStage1("wrong type passed to @panic", |
| 3962 | 4122 | \\export fn entry() void { |
| 3963 | 4123 | \\ var e = error.Foo; |
| 3964 | 4124 | \\ @panic(e); |
| ... | ... | @@ -3967,7 +4127,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3967 | 4127 | "tmp.zig:3:12: error: expected type '[]const u8', found 'error{Foo}'", |
| 3968 | 4128 | }); |
| 3969 | 4129 | |
| 3970 | | cases.add("@tagName used on union with no associated enum tag", |
| 4130 | ctx.objErrStage1("@tagName used on union with no associated enum tag", |
| 3971 | 4131 | \\const FloatInt = extern union { |
| 3972 | 4132 | \\ Float: f32, |
| 3973 | 4133 | \\ Int: i32, |
| ... | ... | @@ -3975,13 +4135,14 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3975 | 4135 | \\export fn entry() void { |
| 3976 | 4136 | \\ var fi = FloatInt{.Float = 123.45}; |
| 3977 | 4137 | \\ var tagName = @tagName(fi); |
| 4138 | \\ _ = tagName; |
| 3978 | 4139 | \\} |
| 3979 | 4140 | , &[_][]const u8{ |
| 3980 | 4141 | "tmp.zig:7:19: error: union has no associated enum", |
| 3981 | 4142 | "tmp.zig:1:18: note: declared here", |
| 3982 | 4143 | }); |
| 3983 | 4144 | |
| 3984 | | cases.add("returning error from void async function", |
| 4145 | ctx.objErrStage1("returning error from void async function", |
| 3985 | 4146 | \\export fn entry() void { |
| 3986 | 4147 | \\ _ = async amain(); |
| 3987 | 4148 | \\} |
| ... | ... | @@ -3992,37 +4153,40 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3992 | 4153 | "tmp.zig:5:17: error: expected type 'void', found 'error{ShouldBeCompileError}'", |
| 3993 | 4154 | }); |
| 3994 | 4155 | |
| 3995 | | cases.add("var makes structs required to be comptime known", |
| 4156 | ctx.objErrStage1("var makes structs required to be comptime known", |
| 3996 | 4157 | \\export fn entry() void { |
| 3997 | 4158 | \\ const S = struct{v: anytype}; |
| 3998 | 4159 | \\ var s = S{.v=@as(i32, 10)}; |
| 4160 | \\ _ = s; |
| 3999 | 4161 | \\} |
| 4000 | 4162 | , &[_][]const u8{ |
| 4001 | 4163 | "tmp.zig:3:4: error: variable of type 'S' must be const or comptime", |
| 4002 | 4164 | }); |
| 4003 | 4165 | |
| 4004 | | cases.add("@ptrCast discards const qualifier", |
| 4166 | ctx.objErrStage1("@ptrCast discards const qualifier", |
| 4005 | 4167 | \\export fn entry() void { |
| 4006 | 4168 | \\ const x: i32 = 1234; |
| 4007 | 4169 | \\ const y = @ptrCast(*i32, &x); |
| 4170 | \\ _ = y; |
| 4008 | 4171 | \\} |
| 4009 | 4172 | , &[_][]const u8{ |
| 4010 | 4173 | "tmp.zig:3:15: error: cast discards const qualifier", |
| 4011 | 4174 | }); |
| 4012 | 4175 | |
| 4013 | | cases.add("comptime slice of undefined pointer non-zero len", |
| 4176 | ctx.objErrStage1("comptime slice of undefined pointer non-zero len", |
| 4014 | 4177 | \\export fn entry() void { |
| 4015 | 4178 | \\ const slice = @as([*]i32, undefined)[0..1]; |
| 4179 | \\ _ = slice; |
| 4016 | 4180 | \\} |
| 4017 | 4181 | , &[_][]const u8{ |
| 4018 | 4182 | "tmp.zig:2:41: error: non-zero length slice of undefined pointer", |
| 4019 | 4183 | }); |
| 4020 | 4184 | |
| 4021 | | cases.add("type checking function pointers", |
| 4185 | ctx.objErrStage1("type checking function pointers", |
| 4022 | 4186 | \\fn a(b: fn (*const u8) void) void { |
| 4023 | 4187 | \\ b('a'); |
| 4024 | 4188 | \\} |
| 4025 | | \\fn c(d: u8) void {} |
| 4189 | \\fn c(d: u8) void {_ = d;} |
| 4026 | 4190 | \\export fn entry() void { |
| 4027 | 4191 | \\ a(c); |
| 4028 | 4192 | \\} |
| ... | ... | @@ -4030,7 +4194,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4030 | 4194 | "tmp.zig:6:7: error: expected type 'fn(*const u8) void', found 'fn(u8) void'", |
| 4031 | 4195 | }); |
| 4032 | 4196 | |
| 4033 | | cases.add("no else prong on switch on global error set", |
| 4197 | ctx.objErrStage1("no else prong on switch on global error set", |
| 4034 | 4198 | \\export fn entry() void { |
| 4035 | 4199 | \\ foo(error.A); |
| 4036 | 4200 | \\} |
| ... | ... | @@ -4043,7 +4207,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4043 | 4207 | "tmp.zig:5:5: error: else prong required when switching on type 'anyerror'", |
| 4044 | 4208 | }); |
| 4045 | 4209 | |
| 4046 | | cases.add("error not handled in switch", |
| 4210 | ctx.objErrStage1("error not handled in switch", |
| 4047 | 4211 | \\export fn entry() void { |
| 4048 | 4212 | \\ foo(452) catch |err| switch (err) { |
| 4049 | 4213 | \\ error.Foo => {}, |
| ... | ... | @@ -4062,7 +4226,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4062 | 4226 | "tmp.zig:2:26: error: error.Bar not handled in switch", |
| 4063 | 4227 | }); |
| 4064 | 4228 | |
| 4065 | | cases.add("duplicate error in switch", |
| 4229 | ctx.objErrStage1("duplicate error in switch", |
| 4066 | 4230 | \\export fn entry() void { |
| 4067 | 4231 | \\ foo(452) catch |err| switch (err) { |
| 4068 | 4232 | \\ error.Foo => {}, |
| ... | ... | @@ -4083,7 +4247,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4083 | 4247 | "tmp.zig:3:14: note: other value is here", |
| 4084 | 4248 | }); |
| 4085 | 4249 | |
| 4086 | | cases.add("invalid cast from integral type to enum", |
| 4250 | ctx.objErrStage1("invalid cast from integral type to enum", |
| 4087 | 4251 | \\const E = enum(usize) { One, Two }; |
| 4088 | 4252 | \\ |
| 4089 | 4253 | \\export fn entry() void { |
| ... | ... | @@ -4099,7 +4263,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4099 | 4263 | "tmp.zig:9:10: error: expected type 'usize', found 'E'", |
| 4100 | 4264 | }); |
| 4101 | 4265 | |
| 4102 | | cases.add("range operator in switch used on error set", |
| 4266 | ctx.objErrStage1("range operator in switch used on error set", |
| 4103 | 4267 | \\export fn entry() void { |
| 4104 | 4268 | \\ try foo(452) catch |err| switch (err) { |
| 4105 | 4269 | \\ error.A ... error.B => {}, |
| ... | ... | @@ -4117,33 +4281,35 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4117 | 4281 | "tmp.zig:3:17: error: operator not allowed for errors", |
| 4118 | 4282 | }); |
| 4119 | 4283 | |
| 4120 | | cases.add("inferring error set of function pointer", |
| 4284 | ctx.objErrStage1("inferring error set of function pointer", |
| 4121 | 4285 | \\comptime { |
| 4122 | 4286 | \\ const z: ?fn()!void = null; |
| 4123 | 4287 | \\} |
| 4124 | 4288 | , &[_][]const u8{ |
| 4125 | | "tmp.zig:2:15: error: inferring error set of return type valid only for function definitions", |
| 4289 | "tmp.zig:2:19: error: function prototype may not have inferred error set", |
| 4126 | 4290 | }); |
| 4127 | 4291 | |
| 4128 | | cases.add("access non-existent member of error set", |
| 4292 | ctx.objErrStage1("access non-existent member of error set", |
| 4129 | 4293 | \\const Foo = error{A}; |
| 4130 | 4294 | \\comptime { |
| 4131 | 4295 | \\ const z = Foo.Bar; |
| 4296 | \\ _ = z; |
| 4132 | 4297 | \\} |
| 4133 | 4298 | , &[_][]const u8{ |
| 4134 | 4299 | "tmp.zig:3:18: error: no error named 'Bar' in 'Foo'", |
| 4135 | 4300 | }); |
| 4136 | 4301 | |
| 4137 | | cases.add("error union operator with non error set LHS", |
| 4302 | ctx.objErrStage1("error union operator with non error set LHS", |
| 4138 | 4303 | \\comptime { |
| 4139 | 4304 | \\ const z = i32!i32; |
| 4140 | 4305 | \\ var x: z = undefined; |
| 4306 | \\ _ = x; |
| 4141 | 4307 | \\} |
| 4142 | 4308 | , &[_][]const u8{ |
| 4143 | 4309 | "tmp.zig:2:15: error: expected error set type, found type 'i32'", |
| 4144 | 4310 | }); |
| 4145 | 4311 | |
| 4146 | | cases.add("error equality but sets have no common members", |
| 4312 | ctx.objErrStage1("error equality but sets have no common members", |
| 4147 | 4313 | \\const Set1 = error{A, C}; |
| 4148 | 4314 | \\const Set2 = error{B, D}; |
| 4149 | 4315 | \\export fn entry() void { |
| ... | ... | @@ -4158,29 +4324,32 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4158 | 4324 | "tmp.zig:7:11: error: error sets 'Set1' and 'Set2' have no common errors", |
| 4159 | 4325 | }); |
| 4160 | 4326 | |
| 4161 | | cases.add("only equality binary operator allowed for error sets", |
| 4327 | ctx.objErrStage1("only equality binary operator allowed for error sets", |
| 4162 | 4328 | \\comptime { |
| 4163 | 4329 | \\ const z = error.A > error.B; |
| 4330 | \\ _ = z; |
| 4164 | 4331 | \\} |
| 4165 | 4332 | , &[_][]const u8{ |
| 4166 | 4333 | "tmp.zig:2:23: error: operator not allowed for errors", |
| 4167 | 4334 | }); |
| 4168 | 4335 | |
| 4169 | | cases.add("explicit error set cast known at comptime violates error sets", |
| 4336 | ctx.objErrStage1("explicit error set cast known at comptime violates error sets", |
| 4170 | 4337 | \\const Set1 = error {A, B}; |
| 4171 | 4338 | \\const Set2 = error {A, C}; |
| 4172 | 4339 | \\comptime { |
| 4173 | 4340 | \\ var x = Set1.B; |
| 4174 | 4341 | \\ var y = @errSetCast(Set2, x); |
| 4342 | \\ _ = y; |
| 4175 | 4343 | \\} |
| 4176 | 4344 | , &[_][]const u8{ |
| 4177 | 4345 | "tmp.zig:5:13: error: error.B not a member of error set 'Set2'", |
| 4178 | 4346 | }); |
| 4179 | 4347 | |
| 4180 | | cases.add("cast error union of global error set to error union of smaller error set", |
| 4348 | ctx.objErrStage1("cast error union of global error set to error union of smaller error set", |
| 4181 | 4349 | \\const SmallErrorSet = error{A}; |
| 4182 | 4350 | \\export fn entry() void { |
| 4183 | 4351 | \\ var x: SmallErrorSet!i32 = foo(); |
| 4352 | \\ _ = x; |
| 4184 | 4353 | \\} |
| 4185 | 4354 | \\fn foo() anyerror!i32 { |
| 4186 | 4355 | \\ return error.B; |
| ... | ... | @@ -4191,10 +4360,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4191 | 4360 | "tmp.zig:3:35: note: cannot cast global error set into smaller set", |
| 4192 | 4361 | }); |
| 4193 | 4362 | |
| 4194 | | cases.add("cast global error set to error set", |
| 4363 | ctx.objErrStage1("cast global error set to error set", |
| 4195 | 4364 | \\const SmallErrorSet = error{A}; |
| 4196 | 4365 | \\export fn entry() void { |
| 4197 | 4366 | \\ var x: SmallErrorSet = foo(); |
| 4367 | \\ _ = x; |
| 4198 | 4368 | \\} |
| 4199 | 4369 | \\fn foo() anyerror { |
| 4200 | 4370 | \\ return error.B; |
| ... | ... | @@ -4203,7 +4373,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4203 | 4373 | "tmp.zig:3:31: error: expected type 'SmallErrorSet', found 'anyerror'", |
| 4204 | 4374 | "tmp.zig:3:31: note: cannot cast global error set into smaller set", |
| 4205 | 4375 | }); |
| 4206 | | cases.add("recursive inferred error set", |
| 4376 | ctx.objErrStage1("recursive inferred error set", |
| 4207 | 4377 | \\export fn entry() void { |
| 4208 | 4378 | \\ foo() catch unreachable; |
| 4209 | 4379 | \\} |
| ... | ... | @@ -4214,7 +4384,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4214 | 4384 | "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 | 4385 | }); |
| 4216 | 4386 | |
| 4217 | | cases.add("implicit cast of error set not a subset", |
| 4387 | ctx.objErrStage1("implicit cast of error set not a subset", |
| 4218 | 4388 | \\const Set1 = error{A, B}; |
| 4219 | 4389 | \\const Set2 = error{A, C}; |
| 4220 | 4390 | \\export fn entry() void { |
| ... | ... | @@ -4222,13 +4392,14 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4222 | 4392 | \\} |
| 4223 | 4393 | \\fn foo(set1: Set1) void { |
| 4224 | 4394 | \\ var x: Set2 = set1; |
| 4395 | \\ _ = x; |
| 4225 | 4396 | \\} |
| 4226 | 4397 | , &[_][]const u8{ |
| 4227 | 4398 | "tmp.zig:7:19: error: expected type 'Set2', found 'Set1'", |
| 4228 | 4399 | "tmp.zig:1:23: note: 'error.B' not a member of destination error set", |
| 4229 | 4400 | }); |
| 4230 | 4401 | |
| 4231 | | cases.add("int to err global invalid number", |
| 4402 | ctx.objErrStage1("int to err global invalid number", |
| 4232 | 4403 | \\const Set1 = error{ |
| 4233 | 4404 | \\ A, |
| 4234 | 4405 | \\ B, |
| ... | ... | @@ -4236,12 +4407,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4236 | 4407 | \\comptime { |
| 4237 | 4408 | \\ var x: u16 = 3; |
| 4238 | 4409 | \\ var y = @intToError(x); |
| 4410 | \\ _ = y; |
| 4239 | 4411 | \\} |
| 4240 | 4412 | , &[_][]const u8{ |
| 4241 | 4413 | "tmp.zig:7:13: error: integer value 3 represents no error", |
| 4242 | 4414 | }); |
| 4243 | 4415 | |
| 4244 | | cases.add("int to err non global invalid number", |
| 4416 | ctx.objErrStage1("int to err non global invalid number", |
| 4245 | 4417 | \\const Set1 = error{ |
| 4246 | 4418 | \\ A, |
| 4247 | 4419 | \\ B, |
| ... | ... | @@ -4253,68 +4425,74 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4253 | 4425 | \\comptime { |
| 4254 | 4426 | \\ var x = @errorToInt(Set1.B); |
| 4255 | 4427 | \\ var y = @errSetCast(Set2, @intToError(x)); |
| 4428 | \\ _ = y; |
| 4256 | 4429 | \\} |
| 4257 | 4430 | , &[_][]const u8{ |
| 4258 | 4431 | "tmp.zig:11:13: error: error.B not a member of error set 'Set2'", |
| 4259 | 4432 | }); |
| 4260 | 4433 | |
| 4261 | | cases.add("duplicate error value in error set", |
| 4434 | ctx.objErrStage1("duplicate error value in error set", |
| 4262 | 4435 | \\const Foo = error { |
| 4263 | 4436 | \\ Bar, |
| 4264 | 4437 | \\ Bar, |
| 4265 | 4438 | \\}; |
| 4266 | 4439 | \\export fn entry() void { |
| 4267 | 4440 | \\ const a: Foo = undefined; |
| 4441 | \\ _ = a; |
| 4268 | 4442 | \\} |
| 4269 | 4443 | , &[_][]const u8{ |
| 4270 | 4444 | "tmp.zig:3:5: error: duplicate error: 'Bar'", |
| 4271 | 4445 | "tmp.zig:2:5: note: other error here", |
| 4272 | 4446 | }); |
| 4273 | 4447 | |
| 4274 | | cases.add("cast negative integer literal to usize", |
| 4448 | ctx.objErrStage1("cast negative integer literal to usize", |
| 4275 | 4449 | \\export fn entry() void { |
| 4276 | 4450 | \\ const x = @as(usize, -10); |
| 4451 | \\ _ = x; |
| 4277 | 4452 | \\} |
| 4278 | 4453 | , &[_][]const u8{ |
| 4279 | 4454 | "tmp.zig:2:26: error: cannot cast negative value -10 to unsigned integer type 'usize'", |
| 4280 | 4455 | }); |
| 4281 | 4456 | |
| 4282 | | cases.add("use invalid number literal as array index", |
| 4457 | ctx.objErrStage1("use invalid number literal as array index", |
| 4283 | 4458 | \\var v = 25; |
| 4284 | 4459 | \\export fn entry() void { |
| 4285 | 4460 | \\ var arr: [v]u8 = undefined; |
| 4461 | \\ _ = arr; |
| 4286 | 4462 | \\} |
| 4287 | 4463 | , &[_][]const u8{ |
| 4288 | 4464 | "tmp.zig:1:1: error: unable to infer variable type", |
| 4289 | 4465 | }); |
| 4290 | 4466 | |
| 4291 | | cases.add("duplicate struct field", |
| 4467 | ctx.objErrStage1("duplicate struct field", |
| 4292 | 4468 | \\const Foo = struct { |
| 4293 | 4469 | \\ Bar: i32, |
| 4294 | 4470 | \\ Bar: usize, |
| 4295 | 4471 | \\}; |
| 4296 | 4472 | \\export fn entry() void { |
| 4297 | 4473 | \\ const a: Foo = undefined; |
| 4474 | \\ _ = a; |
| 4298 | 4475 | \\} |
| 4299 | 4476 | , &[_][]const u8{ |
| 4300 | 4477 | "tmp.zig:3:5: error: duplicate struct field: 'Bar'", |
| 4301 | 4478 | "tmp.zig:2:5: note: other field here", |
| 4302 | 4479 | }); |
| 4303 | 4480 | |
| 4304 | | cases.add("duplicate union field", |
| 4481 | ctx.objErrStage1("duplicate union field", |
| 4305 | 4482 | \\const Foo = union { |
| 4306 | 4483 | \\ Bar: i32, |
| 4307 | 4484 | \\ Bar: usize, |
| 4308 | 4485 | \\}; |
| 4309 | 4486 | \\export fn entry() void { |
| 4310 | 4487 | \\ const a: Foo = undefined; |
| 4488 | \\ _ = a; |
| 4311 | 4489 | \\} |
| 4312 | 4490 | , &[_][]const u8{ |
| 4313 | 4491 | "tmp.zig:3:5: error: duplicate union field: 'Bar'", |
| 4314 | 4492 | "tmp.zig:2:5: note: other field here", |
| 4315 | 4493 | }); |
| 4316 | 4494 | |
| 4317 | | cases.add("duplicate enum field", |
| 4495 | ctx.objErrStage1("duplicate enum field", |
| 4318 | 4496 | \\const Foo = enum { |
| 4319 | 4497 | \\ Bar, |
| 4320 | 4498 | \\ Bar, |
| ... | ... | @@ -4322,13 +4500,14 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4322 | 4500 | \\ |
| 4323 | 4501 | \\export fn entry() void { |
| 4324 | 4502 | \\ const a: Foo = undefined; |
| 4503 | \\ _ = a; |
| 4325 | 4504 | \\} |
| 4326 | 4505 | , &[_][]const u8{ |
| 4327 | 4506 | "tmp.zig:3:5: error: duplicate enum field: 'Bar'", |
| 4328 | 4507 | "tmp.zig:2:5: note: other field here", |
| 4329 | 4508 | }); |
| 4330 | 4509 | |
| 4331 | | cases.add("calling function with naked calling convention", |
| 4510 | ctx.objErrStage1("calling function with naked calling convention", |
| 4332 | 4511 | \\export fn entry() void { |
| 4333 | 4512 | \\ foo(); |
| 4334 | 4513 | \\} |
| ... | ... | @@ -4338,42 +4517,42 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4338 | 4517 | "tmp.zig:4:1: note: declared here", |
| 4339 | 4518 | }); |
| 4340 | 4519 | |
| 4341 | | cases.add("function with invalid return type", |
| 4520 | ctx.objErrStage1("function with invalid return type", |
| 4342 | 4521 | \\export fn foo() boid {} |
| 4343 | 4522 | , &[_][]const u8{ |
| 4344 | 4523 | "tmp.zig:1:17: error: use of undeclared identifier 'boid'", |
| 4345 | 4524 | }); |
| 4346 | 4525 | |
| 4347 | | cases.add("function with non-extern non-packed enum parameter", |
| 4526 | ctx.objErrStage1("function with non-extern non-packed enum parameter", |
| 4348 | 4527 | \\const Foo = enum { A, B, C }; |
| 4349 | | \\export fn entry(foo: Foo) void { } |
| 4528 | \\export fn entry(foo: Foo) void { _ = foo; } |
| 4350 | 4529 | , &[_][]const u8{ |
| 4351 | 4530 | "tmp.zig:2:22: error: parameter of type 'Foo' not allowed in function with calling convention 'C'", |
| 4352 | 4531 | }); |
| 4353 | 4532 | |
| 4354 | | cases.add("function with non-extern non-packed struct parameter", |
| 4533 | ctx.objErrStage1("function with non-extern non-packed struct parameter", |
| 4355 | 4534 | \\const Foo = struct { |
| 4356 | 4535 | \\ A: i32, |
| 4357 | 4536 | \\ B: f32, |
| 4358 | 4537 | \\ C: bool, |
| 4359 | 4538 | \\}; |
| 4360 | | \\export fn entry(foo: Foo) void { } |
| 4539 | \\export fn entry(foo: Foo) void { _ = foo; } |
| 4361 | 4540 | , &[_][]const u8{ |
| 4362 | 4541 | "tmp.zig:6:22: error: parameter of type 'Foo' not allowed in function with calling convention 'C'", |
| 4363 | 4542 | }); |
| 4364 | 4543 | |
| 4365 | | cases.add("function with non-extern non-packed union parameter", |
| 4544 | ctx.objErrStage1("function with non-extern non-packed union parameter", |
| 4366 | 4545 | \\const Foo = union { |
| 4367 | 4546 | \\ A: i32, |
| 4368 | 4547 | \\ B: f32, |
| 4369 | 4548 | \\ C: bool, |
| 4370 | 4549 | \\}; |
| 4371 | | \\export fn entry(foo: Foo) void { } |
| 4550 | \\export fn entry(foo: Foo) void { _ = foo; } |
| 4372 | 4551 | , &[_][]const u8{ |
| 4373 | 4552 | "tmp.zig:6:22: error: parameter of type 'Foo' not allowed in function with calling convention 'C'", |
| 4374 | 4553 | }); |
| 4375 | 4554 | |
| 4376 | | cases.add("switch on enum with 1 field with no prongs", |
| 4555 | ctx.objErrStage1("switch on enum with 1 field with no prongs", |
| 4377 | 4556 | \\const Foo = enum { M }; |
| 4378 | 4557 | \\ |
| 4379 | 4558 | \\export fn entry() void { |
| ... | ... | @@ -4384,15 +4563,16 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4384 | 4563 | "tmp.zig:5:5: error: enumeration value 'Foo.M' not handled in switch", |
| 4385 | 4564 | }); |
| 4386 | 4565 | |
| 4387 | | cases.add("shift by negative comptime integer", |
| 4566 | ctx.objErrStage1("shift by negative comptime integer", |
| 4388 | 4567 | \\comptime { |
| 4389 | 4568 | \\ var a = 1 >> -1; |
| 4569 | \\ _ = a; |
| 4390 | 4570 | \\} |
| 4391 | 4571 | , &[_][]const u8{ |
| 4392 | 4572 | "tmp.zig:2:18: error: shift by negative value -1", |
| 4393 | 4573 | }); |
| 4394 | 4574 | |
| 4395 | | cases.add("@panic called at compile time", |
| 4575 | ctx.objErrStage1("@panic called at compile time", |
| 4396 | 4576 | \\export fn entry() void { |
| 4397 | 4577 | \\ comptime { |
| 4398 | 4578 | \\ @panic("aoeu",); |
| ... | ... | @@ -4402,20 +4582,20 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4402 | 4582 | "tmp.zig:3:9: error: encountered @panic at compile-time", |
| 4403 | 4583 | }); |
| 4404 | 4584 | |
| 4405 | | cases.add("wrong return type for main", |
| 4585 | ctx.objErrStage1("wrong return type for main", |
| 4406 | 4586 | \\pub fn main() f32 { } |
| 4407 | 4587 | , &[_][]const u8{ |
| 4408 | 4588 | "error: expected return type of main to be 'void', '!void', 'noreturn', 'u8', or '!u8'", |
| 4409 | 4589 | }); |
| 4410 | 4590 | |
| 4411 | | cases.add("double ?? on main return value", |
| 4591 | ctx.objErrStage1("double ?? on main return value", |
| 4412 | 4592 | \\pub fn main() ??void { |
| 4413 | 4593 | \\} |
| 4414 | 4594 | , &[_][]const u8{ |
| 4415 | 4595 | "error: expected return type of main to be 'void', '!void', 'noreturn', 'u8', or '!u8'", |
| 4416 | 4596 | }); |
| 4417 | 4597 | |
| 4418 | | cases.add("bad identifier in function with struct defined inside function which references local const", |
| 4598 | ctx.objErrStage1("bad identifier in function with struct defined inside function which references local const", |
| 4419 | 4599 | \\export fn entry() void { |
| 4420 | 4600 | \\ const BlockKind = u32; |
| 4421 | 4601 | \\ |
| ... | ... | @@ -4424,12 +4604,14 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4424 | 4604 | \\ }; |
| 4425 | 4605 | \\ |
| 4426 | 4606 | \\ bogus; |
| 4607 | \\ |
| 4608 | \\ _ = Block; |
| 4427 | 4609 | \\} |
| 4428 | 4610 | , &[_][]const u8{ |
| 4429 | 4611 | "tmp.zig:8:5: error: use of undeclared identifier 'bogus'", |
| 4430 | 4612 | }); |
| 4431 | 4613 | |
| 4432 | | cases.add("labeled break not found", |
| 4614 | ctx.objErrStage1("labeled break not found", |
| 4433 | 4615 | \\export fn entry() void { |
| 4434 | 4616 | \\ blah: while (true) { |
| 4435 | 4617 | \\ while (true) { |
| ... | ... | @@ -4438,10 +4620,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4438 | 4620 | \\ } |
| 4439 | 4621 | \\} |
| 4440 | 4622 | , &[_][]const u8{ |
| 4441 | | "tmp.zig:4:13: error: label not found: 'outer'", |
| 4623 | "tmp.zig:4:20: error: label not found: 'outer'", |
| 4442 | 4624 | }); |
| 4443 | 4625 | |
| 4444 | | cases.add("labeled continue not found", |
| 4626 | ctx.objErrStage1("labeled continue not found", |
| 4445 | 4627 | \\export fn entry() void { |
| 4446 | 4628 | \\ var i: usize = 0; |
| 4447 | 4629 | \\ blah: while (i < 10) : (i += 1) { |
| ... | ... | @@ -4451,17 +4633,17 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4451 | 4633 | \\ } |
| 4452 | 4634 | \\} |
| 4453 | 4635 | , &[_][]const u8{ |
| 4454 | | "tmp.zig:5:13: error: labeled loop not found: 'outer'", |
| 4636 | "tmp.zig:5:23: error: label not found: 'outer'", |
| 4455 | 4637 | }); |
| 4456 | 4638 | |
| 4457 | | cases.add("attempt to use 0 bit type in extern fn", |
| 4639 | ctx.objErrStage1("attempt to use 0 bit type in extern fn", |
| 4458 | 4640 | \\extern fn foo(ptr: fn(*void) callconv(.C) void) void; |
| 4459 | 4641 | \\ |
| 4460 | 4642 | \\export fn entry() void { |
| 4461 | 4643 | \\ foo(bar); |
| 4462 | 4644 | \\} |
| 4463 | 4645 | \\ |
| 4464 | | \\fn bar(x: *void) callconv(.C) void { } |
| 4646 | \\fn bar(x: *void) callconv(.C) void { _ = x; } |
| 4465 | 4647 | \\export fn entry2() void { |
| 4466 | 4648 | \\ bar(&{}); |
| 4467 | 4649 | \\} |
| ... | ... | @@ -4470,7 +4652,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4470 | 4652 | "tmp.zig:7:11: error: parameter of type '*void' has 0 bits; not allowed in function with calling convention 'C'", |
| 4471 | 4653 | }); |
| 4472 | 4654 | |
| 4473 | | cases.add("implicit semicolon - block statement", |
| 4655 | ctx.objErrStage1("implicit semicolon - block statement", |
| 4474 | 4656 | \\export fn entry() void { |
| 4475 | 4657 | \\ {} |
| 4476 | 4658 | \\ var good = {}; |
| ... | ... | @@ -4478,10 +4660,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4478 | 4660 | \\ var bad = {}; |
| 4479 | 4661 | \\} |
| 4480 | 4662 | , &[_][]const u8{ |
| 4481 | | "tmp.zig:5:5: error: expected token ';', found 'var'", |
| 4663 | "tmp.zig:5:5: error: expected ';', found 'var'", |
| 4482 | 4664 | }); |
| 4483 | 4665 | |
| 4484 | | cases.add("implicit semicolon - block expr", |
| 4666 | ctx.objErrStage1("implicit semicolon - block expr", |
| 4485 | 4667 | \\export fn entry() void { |
| 4486 | 4668 | \\ _ = {}; |
| 4487 | 4669 | \\ var good = {}; |
| ... | ... | @@ -4489,10 +4671,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4489 | 4671 | \\ var bad = {}; |
| 4490 | 4672 | \\} |
| 4491 | 4673 | , &[_][]const u8{ |
| 4492 | | "tmp.zig:5:5: error: expected token ';', found 'var'", |
| 4674 | "tmp.zig:5:5: error: expected ';', found 'var'", |
| 4493 | 4675 | }); |
| 4494 | 4676 | |
| 4495 | | cases.add("implicit semicolon - comptime statement", |
| 4677 | ctx.objErrStage1("implicit semicolon - comptime statement", |
| 4496 | 4678 | \\export fn entry() void { |
| 4497 | 4679 | \\ comptime {} |
| 4498 | 4680 | \\ var good = {}; |
| ... | ... | @@ -4500,10 +4682,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4500 | 4682 | \\ var bad = {}; |
| 4501 | 4683 | \\} |
| 4502 | 4684 | , &[_][]const u8{ |
| 4503 | | "tmp.zig:5:5: error: expected token ';', found 'var'", |
| 4685 | "tmp.zig:5:5: error: expected ';', found 'var'", |
| 4504 | 4686 | }); |
| 4505 | 4687 | |
| 4506 | | cases.add("implicit semicolon - comptime expression", |
| 4688 | ctx.objErrStage1("implicit semicolon - comptime expression", |
| 4507 | 4689 | \\export fn entry() void { |
| 4508 | 4690 | \\ _ = comptime {}; |
| 4509 | 4691 | \\ var good = {}; |
| ... | ... | @@ -4511,10 +4693,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4511 | 4693 | \\ var bad = {}; |
| 4512 | 4694 | \\} |
| 4513 | 4695 | , &[_][]const u8{ |
| 4514 | | "tmp.zig:5:5: error: expected token ';', found 'var'", |
| 4696 | "tmp.zig:5:5: error: expected ';', found 'var'", |
| 4515 | 4697 | }); |
| 4516 | 4698 | |
| 4517 | | cases.add("implicit semicolon - defer", |
| 4699 | ctx.objErrStage1("implicit semicolon - defer", |
| 4518 | 4700 | \\export fn entry() void { |
| 4519 | 4701 | \\ defer {} |
| 4520 | 4702 | \\ var good = {}; |
| ... | ... | @@ -4522,10 +4704,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4522 | 4704 | \\ var bad = {}; |
| 4523 | 4705 | \\} |
| 4524 | 4706 | , &[_][]const u8{ |
| 4525 | | "tmp.zig:5:5: error: expected token ';', found 'var'", |
| 4707 | "tmp.zig:5:5: error: expected ';', found 'var'", |
| 4526 | 4708 | }); |
| 4527 | 4709 | |
| 4528 | | cases.add("implicit semicolon - if statement", |
| 4710 | ctx.objErrStage1("implicit semicolon - if statement", |
| 4529 | 4711 | \\export fn entry() void { |
| 4530 | 4712 | \\ if(true) {} |
| 4531 | 4713 | \\ var good = {}; |
| ... | ... | @@ -4533,10 +4715,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4533 | 4715 | \\ var bad = {}; |
| 4534 | 4716 | \\} |
| 4535 | 4717 | , &[_][]const u8{ |
| 4536 | | "tmp.zig:5:5: error: expected token ';', found 'var'", |
| 4718 | "tmp.zig:5:5: error: expected ';' or 'else', found 'var'", |
| 4537 | 4719 | }); |
| 4538 | 4720 | |
| 4539 | | cases.add("implicit semicolon - if expression", |
| 4721 | ctx.objErrStage1("implicit semicolon - if expression", |
| 4540 | 4722 | \\export fn entry() void { |
| 4541 | 4723 | \\ _ = if(true) {}; |
| 4542 | 4724 | \\ var good = {}; |
| ... | ... | @@ -4544,10 +4726,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4544 | 4726 | \\ var bad = {}; |
| 4545 | 4727 | \\} |
| 4546 | 4728 | , &[_][]const u8{ |
| 4547 | | "tmp.zig:5:5: error: expected token ';', found 'var'", |
| 4729 | "tmp.zig:5:5: error: expected ';', found 'var'", |
| 4548 | 4730 | }); |
| 4549 | 4731 | |
| 4550 | | cases.add("implicit semicolon - if-else statement", |
| 4732 | ctx.objErrStage1("implicit semicolon - if-else statement", |
| 4551 | 4733 | \\export fn entry() void { |
| 4552 | 4734 | \\ if(true) {} else {} |
| 4553 | 4735 | \\ var good = {}; |
| ... | ... | @@ -4555,10 +4737,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4555 | 4737 | \\ var bad = {}; |
| 4556 | 4738 | \\} |
| 4557 | 4739 | , &[_][]const u8{ |
| 4558 | | "tmp.zig:5:5: error: expected token ';', found 'var'", |
| 4740 | "tmp.zig:5:5: error: expected ';', found 'var'", |
| 4559 | 4741 | }); |
| 4560 | 4742 | |
| 4561 | | cases.add("implicit semicolon - if-else expression", |
| 4743 | ctx.objErrStage1("implicit semicolon - if-else expression", |
| 4562 | 4744 | \\export fn entry() void { |
| 4563 | 4745 | \\ _ = if(true) {} else {}; |
| 4564 | 4746 | \\ var good = {}; |
| ... | ... | @@ -4566,10 +4748,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4566 | 4748 | \\ var bad = {}; |
| 4567 | 4749 | \\} |
| 4568 | 4750 | , &[_][]const u8{ |
| 4569 | | "tmp.zig:5:5: error: expected token ';', found 'var'", |
| 4751 | "tmp.zig:5:5: error: expected ';', found 'var'", |
| 4570 | 4752 | }); |
| 4571 | 4753 | |
| 4572 | | cases.add("implicit semicolon - if-else-if statement", |
| 4754 | ctx.objErrStage1("implicit semicolon - if-else-if statement", |
| 4573 | 4755 | \\export fn entry() void { |
| 4574 | 4756 | \\ if(true) {} else if(true) {} |
| 4575 | 4757 | \\ var good = {}; |
| ... | ... | @@ -4577,10 +4759,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4577 | 4759 | \\ var bad = {}; |
| 4578 | 4760 | \\} |
| 4579 | 4761 | , &[_][]const u8{ |
| 4580 | | "tmp.zig:5:5: error: expected token ';', found 'var'", |
| 4762 | "tmp.zig:5:5: error: expected ';' or 'else', found 'var'", |
| 4581 | 4763 | }); |
| 4582 | 4764 | |
| 4583 | | cases.add("implicit semicolon - if-else-if expression", |
| 4765 | ctx.objErrStage1("implicit semicolon - if-else-if expression", |
| 4584 | 4766 | \\export fn entry() void { |
| 4585 | 4767 | \\ _ = if(true) {} else if(true) {}; |
| 4586 | 4768 | \\ var good = {}; |
| ... | ... | @@ -4588,10 +4770,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4588 | 4770 | \\ var bad = {}; |
| 4589 | 4771 | \\} |
| 4590 | 4772 | , &[_][]const u8{ |
| 4591 | | "tmp.zig:5:5: error: expected token ';', found 'var'", |
| 4773 | "tmp.zig:5:5: error: expected ';', found 'var'", |
| 4592 | 4774 | }); |
| 4593 | 4775 | |
| 4594 | | cases.add("implicit semicolon - if-else-if-else statement", |
| 4776 | ctx.objErrStage1("implicit semicolon - if-else-if-else statement", |
| 4595 | 4777 | \\export fn entry() void { |
| 4596 | 4778 | \\ if(true) {} else if(true) {} else {} |
| 4597 | 4779 | \\ var good = {}; |
| ... | ... | @@ -4599,10 +4781,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4599 | 4781 | \\ var bad = {}; |
| 4600 | 4782 | \\} |
| 4601 | 4783 | , &[_][]const u8{ |
| 4602 | | "tmp.zig:5:5: error: expected token ';', found 'var'", |
| 4784 | "tmp.zig:5:5: error: expected ';', found 'var'", |
| 4603 | 4785 | }); |
| 4604 | 4786 | |
| 4605 | | cases.add("implicit semicolon - if-else-if-else expression", |
| 4787 | ctx.objErrStage1("implicit semicolon - if-else-if-else expression", |
| 4606 | 4788 | \\export fn entry() void { |
| 4607 | 4789 | \\ _ = if(true) {} else if(true) {} else {}; |
| 4608 | 4790 | \\ var good = {}; |
| ... | ... | @@ -4610,10 +4792,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4610 | 4792 | \\ var bad = {}; |
| 4611 | 4793 | \\} |
| 4612 | 4794 | , &[_][]const u8{ |
| 4613 | | "tmp.zig:5:5: error: expected token ';', found 'var'", |
| 4795 | "tmp.zig:5:5: error: expected ';', found 'var'", |
| 4614 | 4796 | }); |
| 4615 | 4797 | |
| 4616 | | cases.add("implicit semicolon - test statement", |
| 4798 | ctx.objErrStage1("implicit semicolon - test statement", |
| 4617 | 4799 | \\export fn entry() void { |
| 4618 | 4800 | \\ if (foo()) |_| {} |
| 4619 | 4801 | \\ var good = {}; |
| ... | ... | @@ -4621,10 +4803,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4621 | 4803 | \\ var bad = {}; |
| 4622 | 4804 | \\} |
| 4623 | 4805 | , &[_][]const u8{ |
| 4624 | | "tmp.zig:5:5: error: expected token ';', found 'var'", |
| 4806 | "tmp.zig:5:5: error: expected ';' or 'else', found 'var'", |
| 4625 | 4807 | }); |
| 4626 | 4808 | |
| 4627 | | cases.add("implicit semicolon - test expression", |
| 4809 | ctx.objErrStage1("implicit semicolon - test expression", |
| 4628 | 4810 | \\export fn entry() void { |
| 4629 | 4811 | \\ _ = if (foo()) |_| {}; |
| 4630 | 4812 | \\ var good = {}; |
| ... | ... | @@ -4632,10 +4814,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4632 | 4814 | \\ var bad = {}; |
| 4633 | 4815 | \\} |
| 4634 | 4816 | , &[_][]const u8{ |
| 4635 | | "tmp.zig:5:5: error: expected token ';', found 'var'", |
| 4817 | "tmp.zig:5:5: error: expected ';', found 'var'", |
| 4636 | 4818 | }); |
| 4637 | 4819 | |
| 4638 | | cases.add("implicit semicolon - while statement", |
| 4820 | ctx.objErrStage1("implicit semicolon - while statement", |
| 4639 | 4821 | \\export fn entry() void { |
| 4640 | 4822 | \\ while(true) {} |
| 4641 | 4823 | \\ var good = {}; |
| ... | ... | @@ -4643,10 +4825,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4643 | 4825 | \\ var bad = {}; |
| 4644 | 4826 | \\} |
| 4645 | 4827 | , &[_][]const u8{ |
| 4646 | | "tmp.zig:5:5: error: expected token ';', found 'var'", |
| 4828 | "tmp.zig:5:5: error: expected ';' or 'else', found 'var'", |
| 4647 | 4829 | }); |
| 4648 | 4830 | |
| 4649 | | cases.add("implicit semicolon - while expression", |
| 4831 | ctx.objErrStage1("implicit semicolon - while expression", |
| 4650 | 4832 | \\export fn entry() void { |
| 4651 | 4833 | \\ _ = while(true) {}; |
| 4652 | 4834 | \\ var good = {}; |
| ... | ... | @@ -4654,10 +4836,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4654 | 4836 | \\ var bad = {}; |
| 4655 | 4837 | \\} |
| 4656 | 4838 | , &[_][]const u8{ |
| 4657 | | "tmp.zig:5:5: error: expected token ';', found 'var'", |
| 4839 | "tmp.zig:5:5: error: expected ';', found 'var'", |
| 4658 | 4840 | }); |
| 4659 | 4841 | |
| 4660 | | cases.add("implicit semicolon - while-continue statement", |
| 4842 | ctx.objErrStage1("implicit semicolon - while-continue statement", |
| 4661 | 4843 | \\export fn entry() void { |
| 4662 | 4844 | \\ while(true):({}) {} |
| 4663 | 4845 | \\ var good = {}; |
| ... | ... | @@ -4665,10 +4847,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4665 | 4847 | \\ var bad = {}; |
| 4666 | 4848 | \\} |
| 4667 | 4849 | , &[_][]const u8{ |
| 4668 | | "tmp.zig:5:5: error: expected token ';', found 'var'", |
| 4850 | "tmp.zig:5:5: error: expected ';' or 'else', found 'var'", |
| 4669 | 4851 | }); |
| 4670 | 4852 | |
| 4671 | | cases.add("implicit semicolon - while-continue expression", |
| 4853 | ctx.objErrStage1("implicit semicolon - while-continue expression", |
| 4672 | 4854 | \\export fn entry() void { |
| 4673 | 4855 | \\ _ = while(true):({}) {}; |
| 4674 | 4856 | \\ var good = {}; |
| ... | ... | @@ -4676,10 +4858,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4676 | 4858 | \\ var bad = {}; |
| 4677 | 4859 | \\} |
| 4678 | 4860 | , &[_][]const u8{ |
| 4679 | | "tmp.zig:5:5: error: expected token ';', found 'var'", |
| 4861 | "tmp.zig:5:5: error: expected ';', found 'var'", |
| 4680 | 4862 | }); |
| 4681 | 4863 | |
| 4682 | | cases.add("implicit semicolon - for statement", |
| 4864 | ctx.objErrStage1("implicit semicolon - for statement", |
| 4683 | 4865 | \\export fn entry() void { |
| 4684 | 4866 | \\ for(foo()) |_| {} |
| 4685 | 4867 | \\ var good = {}; |
| ... | ... | @@ -4687,10 +4869,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4687 | 4869 | \\ var bad = {}; |
| 4688 | 4870 | \\} |
| 4689 | 4871 | , &[_][]const u8{ |
| 4690 | | "tmp.zig:5:5: error: expected token ';', found 'var'", |
| 4872 | "tmp.zig:5:5: error: expected ';' or 'else', found 'var'", |
| 4691 | 4873 | }); |
| 4692 | 4874 | |
| 4693 | | cases.add("implicit semicolon - for expression", |
| 4875 | ctx.objErrStage1("implicit semicolon - for expression", |
| 4694 | 4876 | \\export fn entry() void { |
| 4695 | 4877 | \\ _ = for(foo()) |_| {}; |
| 4696 | 4878 | \\ var good = {}; |
| ... | ... | @@ -4698,32 +4880,33 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4698 | 4880 | \\ var bad = {}; |
| 4699 | 4881 | \\} |
| 4700 | 4882 | , &[_][]const u8{ |
| 4701 | | "tmp.zig:5:5: error: expected token ';', found 'var'", |
| 4883 | "tmp.zig:5:5: error: expected ';', found 'var'", |
| 4702 | 4884 | }); |
| 4703 | 4885 | |
| 4704 | | cases.add("multiple function definitions", |
| 4886 | ctx.objErrStage1("multiple function definitions", |
| 4705 | 4887 | \\fn a() void {} |
| 4706 | 4888 | \\fn a() void {} |
| 4707 | 4889 | \\export fn entry() void { a(); } |
| 4708 | 4890 | , &[_][]const u8{ |
| 4709 | | "tmp.zig:2:1: error: redefinition of 'a'", |
| 4891 | "tmp.zig:2:1: error: redeclaration of 'a'", |
| 4892 | "tmp.zig:1:1: error: other declaration here", |
| 4710 | 4893 | }); |
| 4711 | 4894 | |
| 4712 | | cases.add("unreachable with return", |
| 4895 | ctx.objErrStage1("unreachable with return", |
| 4713 | 4896 | \\fn a() noreturn {return;} |
| 4714 | 4897 | \\export fn entry() void { a(); } |
| 4715 | 4898 | , &[_][]const u8{ |
| 4716 | 4899 | "tmp.zig:1:18: error: expected type 'noreturn', found 'void'", |
| 4717 | 4900 | }); |
| 4718 | 4901 | |
| 4719 | | cases.add("control reaches end of non-void function", |
| 4902 | ctx.objErrStage1("control reaches end of non-void function", |
| 4720 | 4903 | \\fn a() i32 {} |
| 4721 | 4904 | \\export fn entry() void { _ = a(); } |
| 4722 | 4905 | , &[_][]const u8{ |
| 4723 | 4906 | "tmp.zig:1:12: error: expected type 'i32', found 'void'", |
| 4724 | 4907 | }); |
| 4725 | 4908 | |
| 4726 | | cases.add("undefined function call", |
| 4909 | ctx.objErrStage1("undefined function call", |
| 4727 | 4910 | \\export fn a() void { |
| 4728 | 4911 | \\ b(); |
| 4729 | 4912 | \\} |
| ... | ... | @@ -4731,30 +4914,30 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4731 | 4914 | "tmp.zig:2:5: error: use of undeclared identifier 'b'", |
| 4732 | 4915 | }); |
| 4733 | 4916 | |
| 4734 | | cases.add("wrong number of arguments", |
| 4917 | ctx.objErrStage1("wrong number of arguments", |
| 4735 | 4918 | \\export fn a() void { |
| 4736 | 4919 | \\ b(1); |
| 4737 | 4920 | \\} |
| 4738 | | \\fn b(a: i32, b: i32, c: i32) void { } |
| 4921 | \\fn b(a: i32, b: i32, c: i32) void { _ = a; _ = b; _ = c; } |
| 4739 | 4922 | , &[_][]const u8{ |
| 4740 | 4923 | "tmp.zig:2:6: error: expected 3 argument(s), found 1", |
| 4741 | 4924 | }); |
| 4742 | 4925 | |
| 4743 | | cases.add("invalid type", |
| 4926 | ctx.objErrStage1("invalid type", |
| 4744 | 4927 | \\fn a() bogus {} |
| 4745 | 4928 | \\export fn entry() void { _ = a(); } |
| 4746 | 4929 | , &[_][]const u8{ |
| 4747 | 4930 | "tmp.zig:1:8: error: use of undeclared identifier 'bogus'", |
| 4748 | 4931 | }); |
| 4749 | 4932 | |
| 4750 | | cases.add("pointer to noreturn", |
| 4933 | ctx.objErrStage1("pointer to noreturn", |
| 4751 | 4934 | \\fn a() *noreturn {} |
| 4752 | 4935 | \\export fn entry() void { _ = a(); } |
| 4753 | 4936 | , &[_][]const u8{ |
| 4754 | 4937 | "tmp.zig:1:9: error: pointer to noreturn not allowed", |
| 4755 | 4938 | }); |
| 4756 | 4939 | |
| 4757 | | cases.add("unreachable code", |
| 4940 | ctx.objErrStage1("unreachable code", |
| 4758 | 4941 | \\export fn a() void { |
| 4759 | 4942 | \\ return; |
| 4760 | 4943 | \\ b(); |
| ... | ... | @@ -4766,14 +4949,14 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4766 | 4949 | "tmp.zig:2:5: note: control flow is diverted here", |
| 4767 | 4950 | }); |
| 4768 | 4951 | |
| 4769 | | cases.add("bad import", |
| 4952 | ctx.objErrStage1("bad import", |
| 4770 | 4953 | \\const bogus = @import("bogus-does-not-exist.zig",); |
| 4771 | 4954 | \\export fn entry() void { bogus.bogo(); } |
| 4772 | 4955 | , &[_][]const u8{ |
| 4773 | 4956 | "tmp.zig:1:15: error: unable to find 'bogus-does-not-exist.zig'", |
| 4774 | 4957 | }); |
| 4775 | 4958 | |
| 4776 | | cases.add("undeclared identifier", |
| 4959 | ctx.objErrStage1("undeclared identifier", |
| 4777 | 4960 | \\export fn a() void { |
| 4778 | 4961 | \\ return |
| 4779 | 4962 | \\ b + |
| ... | ... | @@ -4783,33 +4966,36 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4783 | 4966 | "tmp.zig:3:5: error: use of undeclared identifier 'b'", |
| 4784 | 4967 | }); |
| 4785 | 4968 | |
| 4786 | | cases.add("parameter redeclaration", |
| 4969 | ctx.objErrStage1("parameter redeclaration", |
| 4787 | 4970 | \\fn f(a : i32, a : i32) void { |
| 4788 | 4971 | \\} |
| 4789 | 4972 | \\export fn entry() void { f(1, 2); } |
| 4790 | 4973 | , &[_][]const u8{ |
| 4791 | | "tmp.zig:1:15: error: redeclaration of variable 'a'", |
| 4974 | "tmp.zig:1:15: error: redeclaration of parameter 'a'", |
| 4975 | "tmp.zig:1:6: note: previous declaration here", |
| 4792 | 4976 | }); |
| 4793 | 4977 | |
| 4794 | | cases.add("local variable redeclaration", |
| 4978 | ctx.objErrStage1("local variable redeclaration", |
| 4795 | 4979 | \\export fn f() void { |
| 4796 | 4980 | \\ const a : i32 = 0; |
| 4797 | | \\ const a = 0; |
| 4981 | \\ var a = 0; |
| 4798 | 4982 | \\} |
| 4799 | 4983 | , &[_][]const u8{ |
| 4800 | | "tmp.zig:3:5: error: redeclaration of variable 'a'", |
| 4984 | "tmp.zig:3:9: error: redeclaration of local const 'a'", |
| 4985 | "tmp.zig:2:11: note: previous declaration here", |
| 4801 | 4986 | }); |
| 4802 | 4987 | |
| 4803 | | cases.add("local variable redeclares parameter", |
| 4988 | ctx.objErrStage1("local variable redeclares parameter", |
| 4804 | 4989 | \\fn f(a : i32) void { |
| 4805 | 4990 | \\ const a = 0; |
| 4806 | 4991 | \\} |
| 4807 | 4992 | \\export fn entry() void { f(1); } |
| 4808 | 4993 | , &[_][]const u8{ |
| 4809 | | "tmp.zig:2:5: error: redeclaration of variable 'a'", |
| 4994 | "tmp.zig:2:11: error: redeclaration of parameter 'a'", |
| 4995 | "tmp.zig:1:6: note: previous declaration here", |
| 4810 | 4996 | }); |
| 4811 | 4997 | |
| 4812 | | cases.add("variable has wrong type", |
| 4998 | ctx.objErrStage1("variable has wrong type", |
| 4813 | 4999 | \\export fn f() i32 { |
| 4814 | 5000 | \\ const a = "a"; |
| 4815 | 5001 | \\ return a; |
| ... | ... | @@ -4818,7 +5004,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4818 | 5004 | "tmp.zig:3:12: error: expected type 'i32', found '*const [1:0]u8'", |
| 4819 | 5005 | }); |
| 4820 | 5006 | |
| 4821 | | cases.add("if condition is bool, not int", |
| 5007 | ctx.objErrStage1("if condition is bool, not int", |
| 4822 | 5008 | \\export fn f() void { |
| 4823 | 5009 | \\ if (0) {} |
| 4824 | 5010 | \\} |
| ... | ... | @@ -4826,7 +5012,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4826 | 5012 | "tmp.zig:2:9: error: expected type 'bool', found 'comptime_int'", |
| 4827 | 5013 | }); |
| 4828 | 5014 | |
| 4829 | | cases.add("assign unreachable", |
| 5015 | ctx.objErrStage1("assign unreachable", |
| 4830 | 5016 | \\export fn f() void { |
| 4831 | 5017 | \\ const a = return; |
| 4832 | 5018 | \\} |
| ... | ... | @@ -4835,22 +5021,23 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4835 | 5021 | "tmp.zig:2:15: note: control flow is diverted here", |
| 4836 | 5022 | }); |
| 4837 | 5023 | |
| 4838 | | cases.add("unreachable variable", |
| 5024 | ctx.objErrStage1("unreachable variable", |
| 4839 | 5025 | \\export fn f() void { |
| 4840 | 5026 | \\ const a: noreturn = {}; |
| 5027 | \\ _ = a; |
| 4841 | 5028 | \\} |
| 4842 | 5029 | , &[_][]const u8{ |
| 4843 | 5030 | "tmp.zig:2:25: error: expected type 'noreturn', found 'void'", |
| 4844 | 5031 | }); |
| 4845 | 5032 | |
| 4846 | | cases.add("unreachable parameter", |
| 4847 | | \\fn f(a: noreturn) void {} |
| 5033 | ctx.objErrStage1("unreachable parameter", |
| 5034 | \\fn f(a: noreturn) void { _ = a; } |
| 4848 | 5035 | \\export fn entry() void { f(); } |
| 4849 | 5036 | , &[_][]const u8{ |
| 4850 | 5037 | "tmp.zig:1:9: error: parameter of type 'noreturn' not allowed", |
| 4851 | 5038 | }); |
| 4852 | 5039 | |
| 4853 | | cases.add("assign to constant variable", |
| 5040 | ctx.objErrStage1("assign to constant variable", |
| 4854 | 5041 | \\export fn f() void { |
| 4855 | 5042 | \\ const a = 3; |
| 4856 | 5043 | \\ a = 4; |
| ... | ... | @@ -4859,7 +5046,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4859 | 5046 | "tmp.zig:3:9: error: cannot assign to constant", |
| 4860 | 5047 | }); |
| 4861 | 5048 | |
| 4862 | | cases.add("use of undeclared identifier", |
| 5049 | ctx.objErrStage1("use of undeclared identifier", |
| 4863 | 5050 | \\export fn f() void { |
| 4864 | 5051 | \\ b = 3; |
| 4865 | 5052 | \\} |
| ... | ... | @@ -4867,15 +5054,15 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4867 | 5054 | "tmp.zig:2:5: error: use of undeclared identifier 'b'", |
| 4868 | 5055 | }); |
| 4869 | 5056 | |
| 4870 | | cases.add("const is a statement, not an expression", |
| 5057 | ctx.objErrStage1("const is a statement, not an expression", |
| 4871 | 5058 | \\export fn f() void { |
| 4872 | 5059 | \\ (const a = 0); |
| 4873 | 5060 | \\} |
| 4874 | 5061 | , &[_][]const u8{ |
| 4875 | | "tmp.zig:2:6: error: invalid token: 'const'", |
| 5062 | "tmp.zig:2:6: error: expected expression, found 'const'", |
| 4876 | 5063 | }); |
| 4877 | 5064 | |
| 4878 | | cases.add("array access of undeclared identifier", |
| 5065 | ctx.objErrStage1("array access of undeclared identifier", |
| 4879 | 5066 | \\export fn f() void { |
| 4880 | 5067 | \\ i[i] = i[i]; |
| 4881 | 5068 | \\} |
| ... | ... | @@ -4883,7 +5070,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4883 | 5070 | "tmp.zig:2:5: error: use of undeclared identifier 'i'", |
| 4884 | 5071 | }); |
| 4885 | 5072 | |
| 4886 | | cases.add("array access of non array", |
| 5073 | ctx.objErrStage1("array access of non array", |
| 4887 | 5074 | \\export fn f() void { |
| 4888 | 5075 | \\ var bad : bool = undefined; |
| 4889 | 5076 | \\ bad[0] = bad[0]; |
| ... | ... | @@ -4897,7 +5084,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4897 | 5084 | "tmp.zig:7:12: error: array access of non-array type 'bool'", |
| 4898 | 5085 | }); |
| 4899 | 5086 | |
| 4900 | | cases.add("array access with non integer index", |
| 5087 | ctx.objErrStage1("array access with non integer index", |
| 4901 | 5088 | \\export fn f() void { |
| 4902 | 5089 | \\ var array = "aoeu"; |
| 4903 | 5090 | \\ var bad = false; |
| ... | ... | @@ -4913,7 +5100,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4913 | 5100 | "tmp.zig:9:15: error: expected type 'usize', found 'bool'", |
| 4914 | 5101 | }); |
| 4915 | 5102 | |
| 4916 | | cases.add("write to const global variable", |
| 5103 | ctx.objErrStage1("write to const global variable", |
| 4917 | 5104 | \\const x : i32 = 99; |
| 4918 | 5105 | \\fn f() void { |
| 4919 | 5106 | \\ x = 1; |
| ... | ... | @@ -4923,58 +5110,64 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4923 | 5110 | "tmp.zig:3:9: error: cannot assign to constant", |
| 4924 | 5111 | }); |
| 4925 | 5112 | |
| 4926 | | cases.add("missing else clause", |
| 5113 | ctx.objErrStage1("missing else clause", |
| 4927 | 5114 | \\fn f(b: bool) void { |
| 4928 | 5115 | \\ const x : i32 = if (b) h: { break :h 1; }; |
| 5116 | \\ _ = x; |
| 4929 | 5117 | \\} |
| 4930 | 5118 | \\fn g(b: bool) void { |
| 4931 | 5119 | \\ const y = if (b) h: { break :h @as(i32, 1); }; |
| 5120 | \\ _ = y; |
| 4932 | 5121 | \\} |
| 4933 | 5122 | \\export fn entry() void { f(true); g(true); } |
| 4934 | 5123 | , &[_][]const u8{ |
| 4935 | 5124 | "tmp.zig:2:21: error: expected type 'i32', found 'void'", |
| 4936 | | "tmp.zig:5:15: error: incompatible types: 'i32' and 'void'", |
| 5125 | "tmp.zig:6:15: error: incompatible types: 'i32' and 'void'", |
| 4937 | 5126 | }); |
| 4938 | 5127 | |
| 4939 | | cases.add("invalid struct field", |
| 5128 | ctx.objErrStage1("invalid struct field", |
| 4940 | 5129 | \\const A = struct { x : i32, }; |
| 4941 | 5130 | \\export fn f() void { |
| 4942 | 5131 | \\ var a : A = undefined; |
| 4943 | 5132 | \\ a.foo = 1; |
| 4944 | 5133 | \\ const y = a.bar; |
| 5134 | \\ _ = y; |
| 4945 | 5135 | \\} |
| 4946 | 5136 | \\export fn g() void { |
| 4947 | 5137 | \\ var a : A = undefined; |
| 4948 | 5138 | \\ const y = a.bar; |
| 5139 | \\ _ = y; |
| 4949 | 5140 | \\} |
| 4950 | 5141 | , &[_][]const u8{ |
| 4951 | 5142 | "tmp.zig:4:6: error: no member named 'foo' in struct 'A'", |
| 4952 | | "tmp.zig:9:16: error: no member named 'bar' in struct 'A'", |
| 5143 | "tmp.zig:10:16: error: no member named 'bar' in struct 'A'", |
| 4953 | 5144 | }); |
| 4954 | 5145 | |
| 4955 | | cases.add("redefinition of struct", |
| 5146 | ctx.objErrStage1("redefinition of struct", |
| 4956 | 5147 | \\const A = struct { x : i32, }; |
| 4957 | 5148 | \\const A = struct { y : i32, }; |
| 4958 | 5149 | , &[_][]const u8{ |
| 4959 | | "tmp.zig:2:1: error: redefinition of 'A'", |
| 5150 | "tmp.zig:2:1: error: redeclaration of 'A'", |
| 5151 | "tmp.zig:1:1: note: other declaration here", |
| 4960 | 5152 | }); |
| 4961 | 5153 | |
| 4962 | | cases.add("redefinition of enums", |
| 4963 | | \\const A = enum {}; |
| 4964 | | \\const A = enum {}; |
| 5154 | ctx.objErrStage1("redefinition of enums", |
| 5155 | \\const A = enum {x}; |
| 5156 | \\const A = enum {x}; |
| 4965 | 5157 | , &[_][]const u8{ |
| 4966 | | "tmp.zig:2:1: error: redefinition of 'A'", |
| 5158 | "tmp.zig:2:1: error: redeclaration of 'A'", |
| 5159 | "tmp.zig:1:1: note: other declaration here", |
| 4967 | 5160 | }); |
| 4968 | 5161 | |
| 4969 | | cases.add("redefinition of global variables", |
| 5162 | ctx.objErrStage1("redefinition of global variables", |
| 4970 | 5163 | \\var a : i32 = 1; |
| 4971 | 5164 | \\var a : i32 = 2; |
| 4972 | 5165 | , &[_][]const u8{ |
| 4973 | | "tmp.zig:2:1: error: redefinition of 'a'", |
| 4974 | | "tmp.zig:1:1: note: previous definition is here", |
| 5166 | "tmp.zig:2:1: error: redeclaration of 'a'", |
| 5167 | "tmp.zig:1:1: note: other declaration here", |
| 4975 | 5168 | }); |
| 4976 | 5169 | |
| 4977 | | cases.add("duplicate field in struct value expression", |
| 5170 | ctx.objErrStage1("duplicate field in struct value expression", |
| 4978 | 5171 | \\const A = struct { |
| 4979 | 5172 | \\ x : i32, |
| 4980 | 5173 | \\ y : i32, |
| ... | ... | @@ -4987,12 +5180,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4987 | 5180 | \\ .x = 3, |
| 4988 | 5181 | \\ .z = 4, |
| 4989 | 5182 | \\ }; |
| 5183 | \\ _ = a; |
| 4990 | 5184 | \\} |
| 4991 | 5185 | , &[_][]const u8{ |
| 4992 | 5186 | "tmp.zig:11:9: error: duplicate field", |
| 4993 | 5187 | }); |
| 4994 | 5188 | |
| 4995 | | cases.add("missing field in struct value expression", |
| 5189 | ctx.objErrStage1("missing field in struct value expression", |
| 4996 | 5190 | \\const A = struct { |
| 4997 | 5191 | \\ x : i32, |
| 4998 | 5192 | \\ y : i32, |
| ... | ... | @@ -5010,7 +5204,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5010 | 5204 | "tmp.zig:9:17: error: missing field: 'x'", |
| 5011 | 5205 | }); |
| 5012 | 5206 | |
| 5013 | | cases.add("invalid field in struct value expression", |
| 5207 | ctx.objErrStage1("invalid field in struct value expression", |
| 5014 | 5208 | \\const A = struct { |
| 5015 | 5209 | \\ x : i32, |
| 5016 | 5210 | \\ y : i32, |
| ... | ... | @@ -5022,12 +5216,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5022 | 5216 | \\ .y = 2, |
| 5023 | 5217 | \\ .foo = 42, |
| 5024 | 5218 | \\ }; |
| 5219 | \\ _ = a; |
| 5025 | 5220 | \\} |
| 5026 | 5221 | , &[_][]const u8{ |
| 5027 | 5222 | "tmp.zig:10:9: error: no member named 'foo' in struct 'A'", |
| 5028 | 5223 | }); |
| 5029 | 5224 | |
| 5030 | | cases.add("invalid break expression", |
| 5225 | ctx.objErrStage1("invalid break expression", |
| 5031 | 5226 | \\export fn f() void { |
| 5032 | 5227 | \\ break; |
| 5033 | 5228 | \\} |
| ... | ... | @@ -5035,7 +5230,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5035 | 5230 | "tmp.zig:2:5: error: break expression outside loop", |
| 5036 | 5231 | }); |
| 5037 | 5232 | |
| 5038 | | cases.add("invalid continue expression", |
| 5233 | ctx.objErrStage1("invalid continue expression", |
| 5039 | 5234 | \\export fn f() void { |
| 5040 | 5235 | \\ continue; |
| 5041 | 5236 | \\} |
| ... | ... | @@ -5043,15 +5238,15 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5043 | 5238 | "tmp.zig:2:5: error: continue expression outside loop", |
| 5044 | 5239 | }); |
| 5045 | 5240 | |
| 5046 | | cases.add("invalid maybe type", |
| 5241 | ctx.objErrStage1("invalid maybe type", |
| 5047 | 5242 | \\export fn f() void { |
| 5048 | | \\ if (true) |x| { } |
| 5243 | \\ if (true) |x| { _ = x; } |
| 5049 | 5244 | \\} |
| 5050 | 5245 | , &[_][]const u8{ |
| 5051 | 5246 | "tmp.zig:2:9: error: expected optional type, found 'bool'", |
| 5052 | 5247 | }); |
| 5053 | 5248 | |
| 5054 | | cases.add("cast unreachable", |
| 5249 | ctx.objErrStage1("cast unreachable", |
| 5055 | 5250 | \\fn f() i32 { |
| 5056 | 5251 | \\ return @as(i32, return 1); |
| 5057 | 5252 | \\} |
| ... | ... | @@ -5061,22 +5256,22 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5061 | 5256 | "tmp.zig:2:21: note: control flow is diverted here", |
| 5062 | 5257 | }); |
| 5063 | 5258 | |
| 5064 | | cases.add("invalid builtin fn", |
| 5259 | ctx.objErrStage1("invalid builtin fn", |
| 5065 | 5260 | \\fn f() @bogus(foo) { |
| 5066 | 5261 | \\} |
| 5067 | 5262 | \\export fn entry() void { _ = f(); } |
| 5068 | 5263 | , &[_][]const u8{ |
| 5069 | | "tmp.zig:1:8: error: invalid builtin function: 'bogus'", |
| 5264 | "tmp.zig:1:8: error: invalid builtin function: '@bogus'", |
| 5070 | 5265 | }); |
| 5071 | 5266 | |
| 5072 | | cases.add("noalias on non pointer param", |
| 5073 | | \\fn f(noalias x: i32) void {} |
| 5267 | ctx.objErrStage1("noalias on non pointer param", |
| 5268 | \\fn f(noalias x: i32) void { _ = x; } |
| 5074 | 5269 | \\export fn entry() void { f(1234); } |
| 5075 | 5270 | , &[_][]const u8{ |
| 5076 | 5271 | "tmp.zig:1:6: error: noalias on non-pointer parameter", |
| 5077 | 5272 | }); |
| 5078 | 5273 | |
| 5079 | | cases.add("struct init syntax for array", |
| 5274 | ctx.objErrStage1("struct init syntax for array", |
| 5080 | 5275 | \\const foo = [3]u16{ .x = 1024 }; |
| 5081 | 5276 | \\comptime { |
| 5082 | 5277 | \\ _ = foo; |
| ... | ... | @@ -5085,7 +5280,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5085 | 5280 | "tmp.zig:1:21: error: type '[3]u16' does not support struct initialization syntax", |
| 5086 | 5281 | }); |
| 5087 | 5282 | |
| 5088 | | cases.add("type variables must be constant", |
| 5283 | ctx.objErrStage1("type variables must be constant", |
| 5089 | 5284 | \\var foo = u8; |
| 5090 | 5285 | \\export fn entry() foo { |
| 5091 | 5286 | \\ return 1; |
| ... | ... | @@ -5094,12 +5289,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5094 | 5289 | "tmp.zig:1:1: error: variable of type 'type' must be constant", |
| 5095 | 5290 | }); |
| 5096 | 5291 | |
| 5097 | | cases.add("variables shadowing types", |
| 5292 | ctx.objErrStage1("variables shadowing types", |
| 5098 | 5293 | \\const Foo = struct {}; |
| 5099 | 5294 | \\const Bar = struct {}; |
| 5100 | 5295 | \\ |
| 5101 | 5296 | \\fn f(Foo: i32) void { |
| 5102 | 5297 | \\ var Bar : i32 = undefined; |
| 5298 | \\ _ = Bar; |
| 5103 | 5299 | \\} |
| 5104 | 5300 | \\ |
| 5105 | 5301 | \\export fn entry() void { |
| ... | ... | @@ -5112,7 +5308,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5112 | 5308 | "tmp.zig:2:1: note: previous definition is here", |
| 5113 | 5309 | }); |
| 5114 | 5310 | |
| 5115 | | cases.add("switch expression - missing enumeration prong", |
| 5311 | ctx.objErrStage1("switch expression - missing enumeration prong", |
| 5116 | 5312 | \\const Number = enum { |
| 5117 | 5313 | \\ One, |
| 5118 | 5314 | \\ Two, |
| ... | ... | @@ -5132,7 +5328,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5132 | 5328 | "tmp.zig:8:5: error: enumeration value 'Number.Four' not handled in switch", |
| 5133 | 5329 | }); |
| 5134 | 5330 | |
| 5135 | | cases.add("switch expression - duplicate enumeration prong", |
| 5331 | ctx.objErrStage1("switch expression - duplicate enumeration prong", |
| 5136 | 5332 | \\const Number = enum { |
| 5137 | 5333 | \\ One, |
| 5138 | 5334 | \\ Two, |
| ... | ... | @@ -5155,7 +5351,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5155 | 5351 | "tmp.zig:10:15: note: other value is here", |
| 5156 | 5352 | }); |
| 5157 | 5353 | |
| 5158 | | cases.add("switch expression - duplicate enumeration prong when else present", |
| 5354 | ctx.objErrStage1("switch expression - duplicate enumeration prong when else present", |
| 5159 | 5355 | \\const Number = enum { |
| 5160 | 5356 | \\ One, |
| 5161 | 5357 | \\ Two, |
| ... | ... | @@ -5179,7 +5375,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5179 | 5375 | "tmp.zig:10:15: note: other value is here", |
| 5180 | 5376 | }); |
| 5181 | 5377 | |
| 5182 | | cases.add("switch expression - multiple else prongs", |
| 5378 | ctx.objErrStage1("switch expression - multiple else prongs", |
| 5183 | 5379 | \\fn f(x: u32) void { |
| 5184 | 5380 | \\ const value: bool = switch (x) { |
| 5185 | 5381 | \\ 1234 => false, |
| ... | ... | @@ -5194,7 +5390,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5194 | 5390 | "tmp.zig:5:9: error: multiple else prongs in switch expression", |
| 5195 | 5391 | }); |
| 5196 | 5392 | |
| 5197 | | cases.add("switch expression - non exhaustive integer prongs", |
| 5393 | ctx.objErrStage1("switch expression - non exhaustive integer prongs", |
| 5198 | 5394 | \\fn foo(x: u8) void { |
| 5199 | 5395 | \\ switch (x) { |
| 5200 | 5396 | \\ 0 => {}, |
| ... | ... | @@ -5205,7 +5401,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5205 | 5401 | "tmp.zig:2:5: error: switch must handle all possibilities", |
| 5206 | 5402 | }); |
| 5207 | 5403 | |
| 5208 | | cases.add("switch expression - duplicate or overlapping integer value", |
| 5404 | ctx.objErrStage1("switch expression - duplicate or overlapping integer value", |
| 5209 | 5405 | \\fn foo(x: u8) u8 { |
| 5210 | 5406 | \\ return switch (x) { |
| 5211 | 5407 | \\ 0 ... 100 => @as(u8, 0), |
| ... | ... | @@ -5220,8 +5416,9 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5220 | 5416 | "tmp.zig:5:14: note: previous value is here", |
| 5221 | 5417 | }); |
| 5222 | 5418 | |
| 5223 | | cases.add("switch expression - duplicate type", |
| 5419 | ctx.objErrStage1("switch expression - duplicate type", |
| 5224 | 5420 | \\fn foo(comptime T: type, x: T) u8 { |
| 5421 | \\ _ = x; |
| 5225 | 5422 | \\ return switch (T) { |
| 5226 | 5423 | \\ u32 => 0, |
| 5227 | 5424 | \\ u64 => 1, |
| ... | ... | @@ -5231,16 +5428,17 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5231 | 5428 | \\} |
| 5232 | 5429 | \\export fn entry() usize { return @sizeOf(@TypeOf(foo(u32, 0))); } |
| 5233 | 5430 | , &[_][]const u8{ |
| 5234 | | "tmp.zig:5:9: error: duplicate switch value", |
| 5235 | | "tmp.zig:3:9: note: previous value is here", |
| 5431 | "tmp.zig:6:9: error: duplicate switch value", |
| 5432 | "tmp.zig:4:9: note: previous value is here", |
| 5236 | 5433 | }); |
| 5237 | 5434 | |
| 5238 | | cases.add("switch expression - duplicate type (struct alias)", |
| 5435 | ctx.objErrStage1("switch expression - duplicate type (struct alias)", |
| 5239 | 5436 | \\const Test = struct { |
| 5240 | 5437 | \\ bar: i32, |
| 5241 | 5438 | \\}; |
| 5242 | 5439 | \\const Test2 = Test; |
| 5243 | 5440 | \\fn foo(comptime T: type, x: T) u8 { |
| 5441 | \\ _ = x; |
| 5244 | 5442 | \\ return switch (T) { |
| 5245 | 5443 | \\ Test => 0, |
| 5246 | 5444 | \\ u64 => 1, |
| ... | ... | @@ -5250,11 +5448,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5250 | 5448 | \\} |
| 5251 | 5449 | \\export fn entry() usize { return @sizeOf(@TypeOf(foo(u32, 0))); } |
| 5252 | 5450 | , &[_][]const u8{ |
| 5253 | | "tmp.zig:9:9: error: duplicate switch value", |
| 5254 | | "tmp.zig:7:9: note: previous value is here", |
| 5451 | "tmp.zig:10:9: error: duplicate switch value", |
| 5452 | "tmp.zig:8:9: note: previous value is here", |
| 5255 | 5453 | }); |
| 5256 | 5454 | |
| 5257 | | cases.add("switch expression - switch on pointer type with no else", |
| 5455 | ctx.objErrStage1("switch expression - switch on pointer type with no else", |
| 5258 | 5456 | \\fn foo(x: *u8) void { |
| 5259 | 5457 | \\ switch (x) { |
| 5260 | 5458 | \\ &y => {}, |
| ... | ... | @@ -5266,7 +5464,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5266 | 5464 | "tmp.zig:2:5: error: else prong required when switching on type '*u8'", |
| 5267 | 5465 | }); |
| 5268 | 5466 | |
| 5269 | | cases.add("global variable initializer must be constant expression", |
| 5467 | ctx.objErrStage1("global variable initializer must be constant expression", |
| 5270 | 5468 | \\extern fn foo() i32; |
| 5271 | 5469 | \\const x = foo(); |
| 5272 | 5470 | \\export fn entry() i32 { return x; } |
| ... | ... | @@ -5274,7 +5472,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5274 | 5472 | "tmp.zig:2:11: error: unable to evaluate constant expression", |
| 5275 | 5473 | }); |
| 5276 | 5474 | |
| 5277 | | cases.add("array concatenation with wrong type", |
| 5475 | ctx.objErrStage1("array concatenation with wrong type", |
| 5278 | 5476 | \\const src = "aoeu"; |
| 5279 | 5477 | \\const derp: usize = 1234; |
| 5280 | 5478 | \\const a = derp ++ "foo"; |
| ... | ... | @@ -5284,7 +5482,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5284 | 5482 | "tmp.zig:3:11: error: expected array, found 'usize'", |
| 5285 | 5483 | }); |
| 5286 | 5484 | |
| 5287 | | cases.add("non compile time array concatenation", |
| 5485 | ctx.objErrStage1("non compile time array concatenation", |
| 5288 | 5486 | \\fn f() []u8 { |
| 5289 | 5487 | \\ return s ++ "foo"; |
| 5290 | 5488 | \\} |
| ... | ... | @@ -5294,7 +5492,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5294 | 5492 | "tmp.zig:2:12: error: unable to evaluate constant expression", |
| 5295 | 5493 | }); |
| 5296 | 5494 | |
| 5297 | | cases.add("@cImport with bogus include", |
| 5495 | ctx.objErrStage1("@cImport with bogus include", |
| 5298 | 5496 | \\const c = @cImport(@cInclude("bogus.h")); |
| 5299 | 5497 | \\export fn entry() usize { return @sizeOf(@TypeOf(c.bogo)); } |
| 5300 | 5498 | , &[_][]const u8{ |
| ... | ... | @@ -5302,7 +5500,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5302 | 5500 | ".h:1:10: note: 'bogus.h' file not found", |
| 5303 | 5501 | }); |
| 5304 | 5502 | |
| 5305 | | cases.add("address of number literal", |
| 5503 | ctx.objErrStage1("address of number literal", |
| 5306 | 5504 | \\const x = 3; |
| 5307 | 5505 | \\const y = &x; |
| 5308 | 5506 | \\fn foo() *const i32 { return y; } |
| ... | ... | @@ -5311,14 +5509,14 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5311 | 5509 | "tmp.zig:3:30: error: expected type '*const i32', found '*const comptime_int'", |
| 5312 | 5510 | }); |
| 5313 | 5511 | |
| 5314 | | cases.add("integer overflow error", |
| 5512 | ctx.objErrStage1("integer overflow error", |
| 5315 | 5513 | \\const x : u8 = 300; |
| 5316 | 5514 | \\export fn entry() usize { return @sizeOf(@TypeOf(x)); } |
| 5317 | 5515 | , &[_][]const u8{ |
| 5318 | 5516 | "tmp.zig:1:16: error: integer value 300 cannot be coerced to type 'u8'", |
| 5319 | 5517 | }); |
| 5320 | 5518 | |
| 5321 | | cases.add("invalid shift amount error", |
| 5519 | ctx.objErrStage1("invalid shift amount error", |
| 5322 | 5520 | \\const x : u8 = 2; |
| 5323 | 5521 | \\fn f() u16 { |
| 5324 | 5522 | \\ return x << 8; |
| ... | ... | @@ -5328,7 +5526,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5328 | 5526 | "tmp.zig:3:17: error: integer value 8 cannot be coerced to type 'u3'", |
| 5329 | 5527 | }); |
| 5330 | 5528 | |
| 5331 | | cases.add("missing function call param", |
| 5529 | ctx.objErrStage1("missing function call param", |
| 5332 | 5530 | \\const Foo = struct { |
| 5333 | 5531 | \\ a: i32, |
| 5334 | 5532 | \\ b: i32, |
| ... | ... | @@ -5349,6 +5547,8 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5349 | 5547 | \\ |
| 5350 | 5548 | \\fn f(foo: *const Foo, index: usize) void { |
| 5351 | 5549 | \\ const result = members[index](); |
| 5550 | \\ _ = foo; |
| 5551 | \\ _ = result; |
| 5352 | 5552 | \\} |
| 5353 | 5553 | \\ |
| 5354 | 5554 | \\export fn entry() usize { return @sizeOf(@TypeOf(f)); } |
| ... | ... | @@ -5356,21 +5556,21 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5356 | 5556 | "tmp.zig:20:34: error: expected 1 argument(s), found 0", |
| 5357 | 5557 | }); |
| 5358 | 5558 | |
| 5359 | | cases.add("missing function name", |
| 5559 | ctx.objErrStage1("missing function name", |
| 5360 | 5560 | \\fn () void {} |
| 5361 | 5561 | \\export fn entry() usize { return @sizeOf(@TypeOf(f)); } |
| 5362 | 5562 | , &[_][]const u8{ |
| 5363 | 5563 | "tmp.zig:1:1: error: missing function name", |
| 5364 | 5564 | }); |
| 5365 | 5565 | |
| 5366 | | cases.add("missing param name", |
| 5566 | ctx.objErrStage1("missing param name", |
| 5367 | 5567 | \\fn f(i32) void {} |
| 5368 | 5568 | \\export fn entry() usize { return @sizeOf(@TypeOf(f)); } |
| 5369 | 5569 | , &[_][]const u8{ |
| 5370 | 5570 | "tmp.zig:1:6: error: missing parameter name", |
| 5371 | 5571 | }); |
| 5372 | 5572 | |
| 5373 | | cases.add("wrong function type", |
| 5573 | ctx.objErrStage1("wrong function type", |
| 5374 | 5574 | \\const fns = [_]fn() void { a, b, c }; |
| 5375 | 5575 | \\fn a() i32 {return 0;} |
| 5376 | 5576 | \\fn b() i32 {return 1;} |
| ... | ... | @@ -5380,7 +5580,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5380 | 5580 | "tmp.zig:1:28: error: expected type 'fn() void', found 'fn() i32'", |
| 5381 | 5581 | }); |
| 5382 | 5582 | |
| 5383 | | cases.add("extern function pointer mismatch", |
| 5583 | ctx.objErrStage1("extern function pointer mismatch", |
| 5384 | 5584 | \\const fns = [_](fn(i32)i32) { a, b, c }; |
| 5385 | 5585 | \\pub fn a(x: i32) i32 {return x + 0;} |
| 5386 | 5586 | \\pub fn b(x: i32) i32 {return x + 1;} |
| ... | ... | @@ -5391,15 +5591,16 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5391 | 5591 | "tmp.zig:1:37: error: expected type 'fn(i32) i32', found 'fn(i32) callconv(.C) i32'", |
| 5392 | 5592 | }); |
| 5393 | 5593 | |
| 5394 | | cases.add("colliding invalid top level functions", |
| 5594 | ctx.objErrStage1("colliding invalid top level functions", |
| 5395 | 5595 | \\fn func() bogus {} |
| 5396 | 5596 | \\fn func() bogus {} |
| 5397 | 5597 | \\export fn entry() usize { return @sizeOf(@TypeOf(func)); } |
| 5398 | 5598 | , &[_][]const u8{ |
| 5399 | | "tmp.zig:2:1: error: redefinition of 'func'", |
| 5599 | "tmp.zig:2:1: error: redeclaration of 'func'", |
| 5600 | "tmp.zig:1:1: note: other declaration here", |
| 5400 | 5601 | }); |
| 5401 | 5602 | |
| 5402 | | cases.add("non constant expression in array size", |
| 5603 | ctx.objErrStage1("non constant expression in array size", |
| 5403 | 5604 | \\const Foo = struct { |
| 5404 | 5605 | \\ y: [get()]u8, |
| 5405 | 5606 | \\}; |
| ... | ... | @@ -5412,7 +5613,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5412 | 5613 | "tmp.zig:2:12: note: called from here", |
| 5413 | 5614 | }); |
| 5414 | 5615 | |
| 5415 | | cases.add("addition with non numbers", |
| 5616 | ctx.objErrStage1("addition with non numbers", |
| 5416 | 5617 | \\const Foo = struct { |
| 5417 | 5618 | \\ field: i32, |
| 5418 | 5619 | \\}; |
| ... | ... | @@ -5423,7 +5624,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5423 | 5624 | "tmp.zig:4:28: error: invalid operands to binary expression: 'Foo' and 'Foo'", |
| 5424 | 5625 | }); |
| 5425 | 5626 | |
| 5426 | | cases.add("division by zero", |
| 5627 | ctx.objErrStage1("division by zero", |
| 5427 | 5628 | \\const lit_int_x = 1 / 0; |
| 5428 | 5629 | \\const lit_float_x = 1.0 / 0.0; |
| 5429 | 5630 | \\const int_x = @as(u32, 1) / @as(u32, 0); |
| ... | ... | @@ -5440,7 +5641,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5440 | 5641 | "tmp.zig:4:31: error: division by zero", |
| 5441 | 5642 | }); |
| 5442 | 5643 | |
| 5443 | | cases.add("normal string with newline", |
| 5644 | ctx.objErrStage1("normal string with newline", |
| 5444 | 5645 | \\const foo = "a |
| 5445 | 5646 | \\b"; |
| 5446 | 5647 | \\ |
| ... | ... | @@ -5449,7 +5650,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5449 | 5650 | "tmp.zig:1:15: error: newline not allowed in string literal", |
| 5450 | 5651 | }); |
| 5451 | 5652 | |
| 5452 | | cases.add("invalid comparison for function pointers", |
| 5653 | ctx.objErrStage1("invalid comparison for function pointers", |
| 5453 | 5654 | \\fn foo() void {} |
| 5454 | 5655 | \\const invalid = foo > foo; |
| 5455 | 5656 | \\ |
| ... | ... | @@ -5458,7 +5659,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5458 | 5659 | "tmp.zig:2:21: error: operator not allowed for type 'fn() void'", |
| 5459 | 5660 | }); |
| 5460 | 5661 | |
| 5461 | | cases.add("generic function instance with non-constant expression", |
| 5662 | ctx.objErrStage1("generic function instance with non-constant expression", |
| 5462 | 5663 | \\fn foo(comptime x: i32, y: i32) i32 { return x + y; } |
| 5463 | 5664 | \\fn test1(a: i32, b: i32) i32 { |
| 5464 | 5665 | \\ return foo(a, b); |
| ... | ... | @@ -5469,7 +5670,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5469 | 5670 | "tmp.zig:3:16: error: runtime value cannot be passed to comptime arg", |
| 5470 | 5671 | }); |
| 5471 | 5672 | |
| 5472 | | cases.add("assign null to non-optional pointer", |
| 5673 | ctx.objErrStage1("assign null to non-optional pointer", |
| 5473 | 5674 | \\const a: *u8 = null; |
| 5474 | 5675 | \\ |
| 5475 | 5676 | \\export fn entry() usize { return @sizeOf(@TypeOf(a)); } |
| ... | ... | @@ -5477,26 +5678,28 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5477 | 5678 | "tmp.zig:1:16: error: expected type '*u8', found '(null)'", |
| 5478 | 5679 | }); |
| 5479 | 5680 | |
| 5480 | | cases.add("indexing an array of size zero", |
| 5681 | ctx.objErrStage1("indexing an array of size zero", |
| 5481 | 5682 | \\const array = [_]u8{}; |
| 5482 | 5683 | \\export fn foo() void { |
| 5483 | 5684 | \\ const pointer = &array[0]; |
| 5685 | \\ _ = pointer; |
| 5484 | 5686 | \\} |
| 5485 | 5687 | , &[_][]const u8{ |
| 5486 | 5688 | "tmp.zig:3:27: error: accessing a zero length array is not allowed", |
| 5487 | 5689 | }); |
| 5488 | 5690 | |
| 5489 | | cases.add("indexing an array of size zero with runtime index", |
| 5691 | ctx.objErrStage1("indexing an array of size zero with runtime index", |
| 5490 | 5692 | \\const array = [_]u8{}; |
| 5491 | 5693 | \\export fn foo() void { |
| 5492 | 5694 | \\ var index: usize = 0; |
| 5493 | 5695 | \\ const pointer = &array[index]; |
| 5696 | \\ _ = pointer; |
| 5494 | 5697 | \\} |
| 5495 | 5698 | , &[_][]const u8{ |
| 5496 | 5699 | "tmp.zig:4:27: error: accessing a zero length array is not allowed", |
| 5497 | 5700 | }); |
| 5498 | 5701 | |
| 5499 | | cases.add("compile time division by zero", |
| 5702 | ctx.objErrStage1("compile time division by zero", |
| 5500 | 5703 | \\const y = foo(0); |
| 5501 | 5704 | \\fn foo(x: u32) u32 { |
| 5502 | 5705 | \\ return 1 / x; |
| ... | ... | @@ -5508,7 +5711,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5508 | 5711 | "tmp.zig:1:14: note: referenced here", |
| 5509 | 5712 | }); |
| 5510 | 5713 | |
| 5511 | | cases.add("branch on undefined value", |
| 5714 | ctx.objErrStage1("branch on undefined value", |
| 5512 | 5715 | \\const x = if (undefined) true else false; |
| 5513 | 5716 | \\ |
| 5514 | 5717 | \\export fn entry() usize { return @sizeOf(@TypeOf(x)); } |
| ... | ... | @@ -5516,7 +5719,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5516 | 5719 | "tmp.zig:1:15: error: use of undefined value here causes undefined behavior", |
| 5517 | 5720 | }); |
| 5518 | 5721 | |
| 5519 | | cases.add("div on undefined value", |
| 5722 | ctx.objErrStage1("div on undefined value", |
| 5520 | 5723 | \\comptime { |
| 5521 | 5724 | \\ var a: i64 = undefined; |
| 5522 | 5725 | \\ _ = a / a; |
| ... | ... | @@ -5525,7 +5728,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5525 | 5728 | "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", |
| 5526 | 5729 | }); |
| 5527 | 5730 | |
| 5528 | | cases.add("div assign on undefined value", |
| 5731 | ctx.objErrStage1("div assign on undefined value", |
| 5529 | 5732 | \\comptime { |
| 5530 | 5733 | \\ var a: i64 = undefined; |
| 5531 | 5734 | \\ a /= a; |
| ... | ... | @@ -5534,7 +5737,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5534 | 5737 | "tmp.zig:3:5: error: use of undefined value here causes undefined behavior", |
| 5535 | 5738 | }); |
| 5536 | 5739 | |
| 5537 | | cases.add("mod on undefined value", |
| 5740 | ctx.objErrStage1("mod on undefined value", |
| 5538 | 5741 | \\comptime { |
| 5539 | 5742 | \\ var a: i64 = undefined; |
| 5540 | 5743 | \\ _ = a % a; |
| ... | ... | @@ -5543,7 +5746,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5543 | 5746 | "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", |
| 5544 | 5747 | }); |
| 5545 | 5748 | |
| 5546 | | cases.add("mod assign on undefined value", |
| 5749 | ctx.objErrStage1("mod assign on undefined value", |
| 5547 | 5750 | \\comptime { |
| 5548 | 5751 | \\ var a: i64 = undefined; |
| 5549 | 5752 | \\ a %= a; |
| ... | ... | @@ -5552,7 +5755,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5552 | 5755 | "tmp.zig:3:5: error: use of undefined value here causes undefined behavior", |
| 5553 | 5756 | }); |
| 5554 | 5757 | |
| 5555 | | cases.add("add on undefined value", |
| 5758 | ctx.objErrStage1("add on undefined value", |
| 5556 | 5759 | \\comptime { |
| 5557 | 5760 | \\ var a: i64 = undefined; |
| 5558 | 5761 | \\ _ = a + a; |
| ... | ... | @@ -5561,7 +5764,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5561 | 5764 | "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", |
| 5562 | 5765 | }); |
| 5563 | 5766 | |
| 5564 | | cases.add("add assign on undefined value", |
| 5767 | ctx.objErrStage1("add assign on undefined value", |
| 5565 | 5768 | \\comptime { |
| 5566 | 5769 | \\ var a: i64 = undefined; |
| 5567 | 5770 | \\ a += a; |
| ... | ... | @@ -5570,7 +5773,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5570 | 5773 | "tmp.zig:3:5: error: use of undefined value here causes undefined behavior", |
| 5571 | 5774 | }); |
| 5572 | 5775 | |
| 5573 | | cases.add("add wrap on undefined value", |
| 5776 | ctx.objErrStage1("add wrap on undefined value", |
| 5574 | 5777 | \\comptime { |
| 5575 | 5778 | \\ var a: i64 = undefined; |
| 5576 | 5779 | \\ _ = a +% a; |
| ... | ... | @@ -5579,7 +5782,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5579 | 5782 | "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", |
| 5580 | 5783 | }); |
| 5581 | 5784 | |
| 5582 | | cases.add("add wrap assign on undefined value", |
| 5785 | ctx.objErrStage1("add wrap assign on undefined value", |
| 5583 | 5786 | \\comptime { |
| 5584 | 5787 | \\ var a: i64 = undefined; |
| 5585 | 5788 | \\ a +%= a; |
| ... | ... | @@ -5588,7 +5791,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5588 | 5791 | "tmp.zig:3:5: error: use of undefined value here causes undefined behavior", |
| 5589 | 5792 | }); |
| 5590 | 5793 | |
| 5591 | | cases.add("sub on undefined value", |
| 5794 | ctx.objErrStage1("sub on undefined value", |
| 5592 | 5795 | \\comptime { |
| 5593 | 5796 | \\ var a: i64 = undefined; |
| 5594 | 5797 | \\ _ = a - a; |
| ... | ... | @@ -5597,7 +5800,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5597 | 5800 | "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", |
| 5598 | 5801 | }); |
| 5599 | 5802 | |
| 5600 | | cases.add("sub assign on undefined value", |
| 5803 | ctx.objErrStage1("sub assign on undefined value", |
| 5601 | 5804 | \\comptime { |
| 5602 | 5805 | \\ var a: i64 = undefined; |
| 5603 | 5806 | \\ a -= a; |
| ... | ... | @@ -5606,7 +5809,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5606 | 5809 | "tmp.zig:3:5: error: use of undefined value here causes undefined behavior", |
| 5607 | 5810 | }); |
| 5608 | 5811 | |
| 5609 | | cases.add("sub wrap on undefined value", |
| 5812 | ctx.objErrStage1("sub wrap on undefined value", |
| 5610 | 5813 | \\comptime { |
| 5611 | 5814 | \\ var a: i64 = undefined; |
| 5612 | 5815 | \\ _ = a -% a; |
| ... | ... | @@ -5615,7 +5818,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5615 | 5818 | "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", |
| 5616 | 5819 | }); |
| 5617 | 5820 | |
| 5618 | | cases.add("sub wrap assign on undefined value", |
| 5821 | ctx.objErrStage1("sub wrap assign on undefined value", |
| 5619 | 5822 | \\comptime { |
| 5620 | 5823 | \\ var a: i64 = undefined; |
| 5621 | 5824 | \\ a -%= a; |
| ... | ... | @@ -5624,7 +5827,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5624 | 5827 | "tmp.zig:3:5: error: use of undefined value here causes undefined behavior", |
| 5625 | 5828 | }); |
| 5626 | 5829 | |
| 5627 | | cases.add("mult on undefined value", |
| 5830 | ctx.objErrStage1("mult on undefined value", |
| 5628 | 5831 | \\comptime { |
| 5629 | 5832 | \\ var a: i64 = undefined; |
| 5630 | 5833 | \\ _ = a * a; |
| ... | ... | @@ -5633,7 +5836,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5633 | 5836 | "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", |
| 5634 | 5837 | }); |
| 5635 | 5838 | |
| 5636 | | cases.add("mult assign on undefined value", |
| 5839 | ctx.objErrStage1("mult assign on undefined value", |
| 5637 | 5840 | \\comptime { |
| 5638 | 5841 | \\ var a: i64 = undefined; |
| 5639 | 5842 | \\ a *= a; |
| ... | ... | @@ -5642,7 +5845,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5642 | 5845 | "tmp.zig:3:5: error: use of undefined value here causes undefined behavior", |
| 5643 | 5846 | }); |
| 5644 | 5847 | |
| 5645 | | cases.add("mult wrap on undefined value", |
| 5848 | ctx.objErrStage1("mult wrap on undefined value", |
| 5646 | 5849 | \\comptime { |
| 5647 | 5850 | \\ var a: i64 = undefined; |
| 5648 | 5851 | \\ _ = a *% a; |
| ... | ... | @@ -5651,7 +5854,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5651 | 5854 | "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", |
| 5652 | 5855 | }); |
| 5653 | 5856 | |
| 5654 | | cases.add("mult wrap assign on undefined value", |
| 5857 | ctx.objErrStage1("mult wrap assign on undefined value", |
| 5655 | 5858 | \\comptime { |
| 5656 | 5859 | \\ var a: i64 = undefined; |
| 5657 | 5860 | \\ a *%= a; |
| ... | ... | @@ -5660,7 +5863,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5660 | 5863 | "tmp.zig:3:5: error: use of undefined value here causes undefined behavior", |
| 5661 | 5864 | }); |
| 5662 | 5865 | |
| 5663 | | cases.add("shift left on undefined value", |
| 5866 | ctx.objErrStage1("shift left on undefined value", |
| 5664 | 5867 | \\comptime { |
| 5665 | 5868 | \\ var a: i64 = undefined; |
| 5666 | 5869 | \\ _ = a << 2; |
| ... | ... | @@ -5669,7 +5872,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5669 | 5872 | "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", |
| 5670 | 5873 | }); |
| 5671 | 5874 | |
| 5672 | | cases.add("shift left assign on undefined value", |
| 5875 | ctx.objErrStage1("shift left assign on undefined value", |
| 5673 | 5876 | \\comptime { |
| 5674 | 5877 | \\ var a: i64 = undefined; |
| 5675 | 5878 | \\ a <<= 2; |
| ... | ... | @@ -5678,7 +5881,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5678 | 5881 | "tmp.zig:3:5: error: use of undefined value here causes undefined behavior", |
| 5679 | 5882 | }); |
| 5680 | 5883 | |
| 5681 | | cases.add("shift right on undefined value", |
| 5884 | ctx.objErrStage1("shift right on undefined value", |
| 5682 | 5885 | \\comptime { |
| 5683 | 5886 | \\ var a: i64 = undefined; |
| 5684 | 5887 | \\ _ = a >> 2; |
| ... | ... | @@ -5687,7 +5890,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5687 | 5890 | "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", |
| 5688 | 5891 | }); |
| 5689 | 5892 | |
| 5690 | | cases.add("shift left assign on undefined value", |
| 5893 | ctx.objErrStage1("shift left assign on undefined value", |
| 5691 | 5894 | \\comptime { |
| 5692 | 5895 | \\ var a: i64 = undefined; |
| 5693 | 5896 | \\ a >>= 2; |
| ... | ... | @@ -5696,7 +5899,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5696 | 5899 | "tmp.zig:3:5: error: use of undefined value here causes undefined behavior", |
| 5697 | 5900 | }); |
| 5698 | 5901 | |
| 5699 | | cases.add("bin and on undefined value", |
| 5902 | ctx.objErrStage1("bin and on undefined value", |
| 5700 | 5903 | \\comptime { |
| 5701 | 5904 | \\ var a: i64 = undefined; |
| 5702 | 5905 | \\ _ = a & a; |
| ... | ... | @@ -5705,7 +5908,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5705 | 5908 | "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", |
| 5706 | 5909 | }); |
| 5707 | 5910 | |
| 5708 | | cases.add("bin and assign on undefined value", |
| 5911 | ctx.objErrStage1("bin and assign on undefined value", |
| 5709 | 5912 | \\comptime { |
| 5710 | 5913 | \\ var a: i64 = undefined; |
| 5711 | 5914 | \\ a &= a; |
| ... | ... | @@ -5714,7 +5917,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5714 | 5917 | "tmp.zig:3:5: error: use of undefined value here causes undefined behavior", |
| 5715 | 5918 | }); |
| 5716 | 5919 | |
| 5717 | | cases.add("bin or on undefined value", |
| 5920 | ctx.objErrStage1("bin or on undefined value", |
| 5718 | 5921 | \\comptime { |
| 5719 | 5922 | \\ var a: i64 = undefined; |
| 5720 | 5923 | \\ _ = a | a; |
| ... | ... | @@ -5723,7 +5926,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5723 | 5926 | "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", |
| 5724 | 5927 | }); |
| 5725 | 5928 | |
| 5726 | | cases.add("bin or assign on undefined value", |
| 5929 | ctx.objErrStage1("bin or assign on undefined value", |
| 5727 | 5930 | \\comptime { |
| 5728 | 5931 | \\ var a: i64 = undefined; |
| 5729 | 5932 | \\ a |= a; |
| ... | ... | @@ -5732,7 +5935,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5732 | 5935 | "tmp.zig:3:5: error: use of undefined value here causes undefined behavior", |
| 5733 | 5936 | }); |
| 5734 | 5937 | |
| 5735 | | cases.add("bin xor on undefined value", |
| 5938 | ctx.objErrStage1("bin xor on undefined value", |
| 5736 | 5939 | \\comptime { |
| 5737 | 5940 | \\ var a: i64 = undefined; |
| 5738 | 5941 | \\ _ = a ^ a; |
| ... | ... | @@ -5741,7 +5944,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5741 | 5944 | "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", |
| 5742 | 5945 | }); |
| 5743 | 5946 | |
| 5744 | | cases.add("bin xor assign on undefined value", |
| 5947 | ctx.objErrStage1("bin xor assign on undefined value", |
| 5745 | 5948 | \\comptime { |
| 5746 | 5949 | \\ var a: i64 = undefined; |
| 5747 | 5950 | \\ a ^= a; |
| ... | ... | @@ -5750,7 +5953,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5750 | 5953 | "tmp.zig:3:5: error: use of undefined value here causes undefined behavior", |
| 5751 | 5954 | }); |
| 5752 | 5955 | |
| 5753 | | cases.add("comparison operators with undefined value", |
| 5956 | ctx.objErrStage1("comparison operators with undefined value", |
| 5754 | 5957 | \\// operator == |
| 5755 | 5958 | \\comptime { |
| 5756 | 5959 | \\ var a: i64 = undefined; |
| ... | ... | @@ -5796,7 +5999,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5796 | 5999 | "tmp.zig:35:11: error: use of undefined value here causes undefined behavior", |
| 5797 | 6000 | }); |
| 5798 | 6001 | |
| 5799 | | cases.add("and on undefined value", |
| 6002 | ctx.objErrStage1("and on undefined value", |
| 5800 | 6003 | \\comptime { |
| 5801 | 6004 | \\ var a: bool = undefined; |
| 5802 | 6005 | \\ _ = a and a; |
| ... | ... | @@ -5805,7 +6008,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5805 | 6008 | "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", |
| 5806 | 6009 | }); |
| 5807 | 6010 | |
| 5808 | | cases.add("or on undefined value", |
| 6011 | ctx.objErrStage1("or on undefined value", |
| 5809 | 6012 | \\comptime { |
| 5810 | 6013 | \\ var a: bool = undefined; |
| 5811 | 6014 | \\ _ = a or a; |
| ... | ... | @@ -5814,7 +6017,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5814 | 6017 | "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", |
| 5815 | 6018 | }); |
| 5816 | 6019 | |
| 5817 | | cases.add("negate on undefined value", |
| 6020 | ctx.objErrStage1("negate on undefined value", |
| 5818 | 6021 | \\comptime { |
| 5819 | 6022 | \\ var a: i64 = undefined; |
| 5820 | 6023 | \\ _ = -a; |
| ... | ... | @@ -5823,7 +6026,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5823 | 6026 | "tmp.zig:3:10: error: use of undefined value here causes undefined behavior", |
| 5824 | 6027 | }); |
| 5825 | 6028 | |
| 5826 | | cases.add("negate wrap on undefined value", |
| 6029 | ctx.objErrStage1("negate wrap on undefined value", |
| 5827 | 6030 | \\comptime { |
| 5828 | 6031 | \\ var a: i64 = undefined; |
| 5829 | 6032 | \\ _ = -%a; |
| ... | ... | @@ -5832,7 +6035,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5832 | 6035 | "tmp.zig:3:11: error: use of undefined value here causes undefined behavior", |
| 5833 | 6036 | }); |
| 5834 | 6037 | |
| 5835 | | cases.add("bin not on undefined value", |
| 6038 | ctx.objErrStage1("bin not on undefined value", |
| 5836 | 6039 | \\comptime { |
| 5837 | 6040 | \\ var a: i64 = undefined; |
| 5838 | 6041 | \\ _ = ~a; |
| ... | ... | @@ -5841,7 +6044,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5841 | 6044 | "tmp.zig:3:10: error: use of undefined value here causes undefined behavior", |
| 5842 | 6045 | }); |
| 5843 | 6046 | |
| 5844 | | cases.add("bool not on undefined value", |
| 6047 | ctx.objErrStage1("bool not on undefined value", |
| 5845 | 6048 | \\comptime { |
| 5846 | 6049 | \\ var a: bool = undefined; |
| 5847 | 6050 | \\ _ = !a; |
| ... | ... | @@ -5850,7 +6053,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5850 | 6053 | "tmp.zig:3:10: error: use of undefined value here causes undefined behavior", |
| 5851 | 6054 | }); |
| 5852 | 6055 | |
| 5853 | | cases.add("orelse on undefined value", |
| 6056 | ctx.objErrStage1("orelse on undefined value", |
| 5854 | 6057 | \\comptime { |
| 5855 | 6058 | \\ var a: ?bool = undefined; |
| 5856 | 6059 | \\ _ = a orelse false; |
| ... | ... | @@ -5859,16 +6062,16 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5859 | 6062 | "tmp.zig:3:11: error: use of undefined value here causes undefined behavior", |
| 5860 | 6063 | }); |
| 5861 | 6064 | |
| 5862 | | cases.add("catch on undefined value", |
| 6065 | ctx.objErrStage1("catch on undefined value", |
| 5863 | 6066 | \\comptime { |
| 5864 | 6067 | \\ var a: anyerror!bool = undefined; |
| 5865 | | \\ _ = a catch |err| false; |
| 6068 | \\ _ = a catch false; |
| 5866 | 6069 | \\} |
| 5867 | 6070 | , &[_][]const u8{ |
| 5868 | 6071 | "tmp.zig:3:11: error: use of undefined value here causes undefined behavior", |
| 5869 | 6072 | }); |
| 5870 | 6073 | |
| 5871 | | cases.add("deref on undefined value", |
| 6074 | ctx.objErrStage1("deref on undefined value", |
| 5872 | 6075 | \\comptime { |
| 5873 | 6076 | \\ var a: *u8 = undefined; |
| 5874 | 6077 | \\ _ = a.*; |
| ... | ... | @@ -5877,7 +6080,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5877 | 6080 | "tmp.zig:3:9: error: attempt to dereference undefined value", |
| 5878 | 6081 | }); |
| 5879 | 6082 | |
| 5880 | | cases.add("endless loop in function evaluation", |
| 6083 | ctx.objErrStage1("endless loop in function evaluation", |
| 5881 | 6084 | \\const seventh_fib_number = fibbonaci(7); |
| 5882 | 6085 | \\fn fibbonaci(x: i32) i32 { |
| 5883 | 6086 | \\ return fibbonaci(x - 1) + fibbonaci(x - 2); |
| ... | ... | @@ -5890,16 +6093,15 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5890 | 6093 | "tmp.zig:6:50: note: referenced here", |
| 5891 | 6094 | }); |
| 5892 | 6095 | |
| 5893 | | cases.add("@embedFile with bogus file", |
| 6096 | ctx.objErrStage1("@embedFile with bogus file", |
| 5894 | 6097 | \\const resource = @embedFile("bogus.txt",); |
| 5895 | 6098 | \\ |
| 5896 | 6099 | \\export fn entry() usize { return @sizeOf(@TypeOf(resource)); } |
| 5897 | 6100 | , &[_][]const u8{ |
| 5898 | | "tmp.zig:1:29: error: unable to find '", |
| 5899 | | "bogus.txt'", |
| 6101 | "tmp.zig:1:29: error: unable to find 'bogus.txt'", |
| 5900 | 6102 | }); |
| 5901 | 6103 | |
| 5902 | | cases.add("non-const expression in struct literal outside function", |
| 6104 | ctx.objErrStage1("non-const expression in struct literal outside function", |
| 5903 | 6105 | \\const Foo = struct { |
| 5904 | 6106 | \\ x: i32, |
| 5905 | 6107 | \\}; |
| ... | ... | @@ -5911,7 +6113,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5911 | 6113 | "tmp.zig:4:21: error: unable to evaluate constant expression", |
| 5912 | 6114 | }); |
| 5913 | 6115 | |
| 5914 | | cases.add("non-const expression function call with struct return value outside function", |
| 6116 | ctx.objErrStage1("non-const expression function call with struct return value outside function", |
| 5915 | 6117 | \\const Foo = struct { |
| 5916 | 6118 | \\ x: i32, |
| 5917 | 6119 | \\}; |
| ... | ... | @@ -5928,7 +6130,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5928 | 6130 | "tmp.zig:4:17: note: referenced here", |
| 5929 | 6131 | }); |
| 5930 | 6132 | |
| 5931 | | cases.add("undeclared identifier error should mark fn as impure", |
| 6133 | ctx.objErrStage1("undeclared identifier error should mark fn as impure", |
| 5932 | 6134 | \\export fn foo() void { |
| 5933 | 6135 | \\ test_a_thing(); |
| 5934 | 6136 | \\} |
| ... | ... | @@ -5939,7 +6141,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5939 | 6141 | "tmp.zig:5:5: error: use of undeclared identifier 'bad_fn_call'", |
| 5940 | 6142 | }); |
| 5941 | 6143 | |
| 5942 | | cases.add("illegal comparison of types", |
| 6144 | ctx.objErrStage1("illegal comparison of types", |
| 5943 | 6145 | \\fn bad_eql_1(a: []u8, b: []u8) bool { |
| 5944 | 6146 | \\ return a == b; |
| 5945 | 6147 | \\} |
| ... | ... | @@ -5958,13 +6160,14 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5958 | 6160 | "tmp.zig:9:16: error: operator not allowed for type 'EnumWithData'", |
| 5959 | 6161 | }); |
| 5960 | 6162 | |
| 5961 | | cases.add("non-const switch number literal", |
| 6163 | ctx.objErrStage1("non-const switch number literal", |
| 5962 | 6164 | \\export fn foo() void { |
| 5963 | 6165 | \\ const x = switch (bar()) { |
| 5964 | 6166 | \\ 1, 2 => 1, |
| 5965 | 6167 | \\ 3, 4 => 2, |
| 5966 | 6168 | \\ else => 3, |
| 5967 | 6169 | \\ }; |
| 6170 | \\ _ = x; |
| 5968 | 6171 | \\} |
| 5969 | 6172 | \\fn bar() i32 { |
| 5970 | 6173 | \\ return 2; |
| ... | ... | @@ -5973,7 +6176,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5973 | 6176 | "tmp.zig:5:17: error: cannot store runtime value in type 'comptime_int'", |
| 5974 | 6177 | }); |
| 5975 | 6178 | |
| 5976 | | cases.add("atomic orderings of cmpxchg - failure stricter than success", |
| 6179 | ctx.objErrStage1("atomic orderings of cmpxchg - failure stricter than success", |
| 5977 | 6180 | \\const AtomicOrder = @import("std").builtin.AtomicOrder; |
| 5978 | 6181 | \\export fn f() void { |
| 5979 | 6182 | \\ var x: i32 = 1234; |
| ... | ... | @@ -5983,7 +6186,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5983 | 6186 | "tmp.zig:4:81: error: failure atomic ordering must be no stricter than success", |
| 5984 | 6187 | }); |
| 5985 | 6188 | |
| 5986 | | cases.add("atomic orderings of cmpxchg - success Monotonic or stricter", |
| 6189 | ctx.objErrStage1("atomic orderings of cmpxchg - success Monotonic or stricter", |
| 5987 | 6190 | \\const AtomicOrder = @import("std").builtin.AtomicOrder; |
| 5988 | 6191 | \\export fn f() void { |
| 5989 | 6192 | \\ var x: i32 = 1234; |
| ... | ... | @@ -5993,7 +6196,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5993 | 6196 | "tmp.zig:4:58: error: success atomic ordering must be Monotonic or stricter", |
| 5994 | 6197 | }); |
| 5995 | 6198 | |
| 5996 | | cases.add("negation overflow in function evaluation", |
| 6199 | ctx.objErrStage1("negation overflow in function evaluation", |
| 5997 | 6200 | \\const y = neg(-128); |
| 5998 | 6201 | \\fn neg(x: i8) i8 { |
| 5999 | 6202 | \\ return -x; |
| ... | ... | @@ -6005,7 +6208,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6005 | 6208 | "tmp.zig:1:14: note: referenced here", |
| 6006 | 6209 | }); |
| 6007 | 6210 | |
| 6008 | | cases.add("add overflow in function evaluation", |
| 6211 | ctx.objErrStage1("add overflow in function evaluation", |
| 6009 | 6212 | \\const y = add(65530, 10); |
| 6010 | 6213 | \\fn add(a: u16, b: u16) u16 { |
| 6011 | 6214 | \\ return a + b; |
| ... | ... | @@ -6017,7 +6220,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6017 | 6220 | "tmp.zig:1:14: note: referenced here", |
| 6018 | 6221 | }); |
| 6019 | 6222 | |
| 6020 | | cases.add("sub overflow in function evaluation", |
| 6223 | ctx.objErrStage1("sub overflow in function evaluation", |
| 6021 | 6224 | \\const y = sub(10, 20); |
| 6022 | 6225 | \\fn sub(a: u16, b: u16) u16 { |
| 6023 | 6226 | \\ return a - b; |
| ... | ... | @@ -6029,7 +6232,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6029 | 6232 | "tmp.zig:1:14: note: referenced here", |
| 6030 | 6233 | }); |
| 6031 | 6234 | |
| 6032 | | cases.add("mul overflow in function evaluation", |
| 6235 | ctx.objErrStage1("mul overflow in function evaluation", |
| 6033 | 6236 | \\const y = mul(300, 6000); |
| 6034 | 6237 | \\fn mul(a: u16, b: u16) u16 { |
| 6035 | 6238 | \\ return a * b; |
| ... | ... | @@ -6041,7 +6244,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6041 | 6244 | "tmp.zig:1:14: note: referenced here", |
| 6042 | 6245 | }); |
| 6043 | 6246 | |
| 6044 | | cases.add("truncate sign mismatch", |
| 6247 | ctx.objErrStage1("truncate sign mismatch", |
| 6045 | 6248 | \\export fn entry1() i8 { |
| 6046 | 6249 | \\ var x: u32 = 10; |
| 6047 | 6250 | \\ return @truncate(i8, x); |
| ... | ... | @@ -6065,7 +6268,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6065 | 6268 | "tmp.zig:15:26: error: expected unsigned integer type, found 'i32'", |
| 6066 | 6269 | }); |
| 6067 | 6270 | |
| 6068 | | cases.add("try in function with non error return type", |
| 6271 | ctx.objErrStage1("try in function with non error return type", |
| 6069 | 6272 | \\export fn f() void { |
| 6070 | 6273 | \\ try something(); |
| 6071 | 6274 | \\} |
| ... | ... | @@ -6074,7 +6277,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6074 | 6277 | "tmp.zig:2:5: error: expected type 'void', found 'anyerror'", |
| 6075 | 6278 | }); |
| 6076 | 6279 | |
| 6077 | | cases.add("invalid pointer for var type", |
| 6280 | ctx.objErrStage1("invalid pointer for var type", |
| 6078 | 6281 | \\extern fn ext() usize; |
| 6079 | 6282 | \\var bytes: [ext()]u8 = undefined; |
| 6080 | 6283 | \\export fn f() void { |
| ... | ... | @@ -6086,7 +6289,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6086 | 6289 | "tmp.zig:2:13: error: unable to evaluate constant expression", |
| 6087 | 6290 | }); |
| 6088 | 6291 | |
| 6089 | | cases.add("export function with comptime parameter", |
| 6292 | ctx.objErrStage1("export function with comptime parameter", |
| 6090 | 6293 | \\export fn foo(comptime x: i32, y: i32) i32{ |
| 6091 | 6294 | \\ return x + y; |
| 6092 | 6295 | \\} |
| ... | ... | @@ -6094,7 +6297,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6094 | 6297 | "tmp.zig:1:15: error: comptime parameter not allowed in function with calling convention 'C'", |
| 6095 | 6298 | }); |
| 6096 | 6299 | |
| 6097 | | cases.add("extern function with comptime parameter", |
| 6300 | ctx.objErrStage1("extern function with comptime parameter", |
| 6098 | 6301 | \\extern fn foo(comptime x: i32, y: i32) i32; |
| 6099 | 6302 | \\fn f() i32 { |
| 6100 | 6303 | \\ return foo(1, 2); |
| ... | ... | @@ -6104,7 +6307,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6104 | 6307 | "tmp.zig:1:15: error: comptime parameter not allowed in function with calling convention 'C'", |
| 6105 | 6308 | }); |
| 6106 | 6309 | |
| 6107 | | cases.add("non-pure function returns type", |
| 6310 | ctx.objErrStage1("non-pure function returns type", |
| 6108 | 6311 | \\var a: u32 = 0; |
| 6109 | 6312 | \\pub fn List(comptime T: type) type { |
| 6110 | 6313 | \\ a += 1; |
| ... | ... | @@ -6128,7 +6331,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6128 | 6331 | "tmp.zig:16:19: note: referenced here", |
| 6129 | 6332 | }); |
| 6130 | 6333 | |
| 6131 | | cases.add("bogus method call on slice", |
| 6334 | ctx.objErrStage1("bogus method call on slice", |
| 6132 | 6335 | \\var self = "aoeu"; |
| 6133 | 6336 | \\fn f(m: []const u8) void { |
| 6134 | 6337 | \\ m.copy(u8, self[0..], m); |
| ... | ... | @@ -6138,9 +6341,9 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6138 | 6341 | "tmp.zig:3:6: error: no member named 'copy' in '[]const u8'", |
| 6139 | 6342 | }); |
| 6140 | 6343 | |
| 6141 | | cases.add("wrong number of arguments for method fn call", |
| 6344 | ctx.objErrStage1("wrong number of arguments for method fn call", |
| 6142 | 6345 | \\const Foo = struct { |
| 6143 | | \\ fn method(self: *const Foo, a: i32) void {} |
| 6346 | \\ fn method(self: *const Foo, a: i32) void {_ = self; _ = a;} |
| 6144 | 6347 | \\}; |
| 6145 | 6348 | \\fn f(foo: *const Foo) void { |
| 6146 | 6349 | \\ |
| ... | ... | @@ -6151,7 +6354,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6151 | 6354 | "tmp.zig:6:15: error: expected 2 argument(s), found 3", |
| 6152 | 6355 | }); |
| 6153 | 6356 | |
| 6154 | | cases.add("assign through constant pointer", |
| 6357 | ctx.objErrStage1("assign through constant pointer", |
| 6155 | 6358 | \\export fn f() void { |
| 6156 | 6359 | \\ var cstr = "Hat"; |
| 6157 | 6360 | \\ cstr[0] = 'W'; |
| ... | ... | @@ -6160,7 +6363,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6160 | 6363 | "tmp.zig:3:13: error: cannot assign to constant", |
| 6161 | 6364 | }); |
| 6162 | 6365 | |
| 6163 | | cases.add("assign through constant slice", |
| 6366 | ctx.objErrStage1("assign through constant slice", |
| 6164 | 6367 | \\export fn f() void { |
| 6165 | 6368 | \\ var cstr: []const u8 = "Hat"; |
| 6166 | 6369 | \\ cstr[0] = 'W'; |
| ... | ... | @@ -6169,13 +6372,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6169 | 6372 | "tmp.zig:3:13: error: cannot assign to constant", |
| 6170 | 6373 | }); |
| 6171 | 6374 | |
| 6172 | | cases.add("main function with bogus args type", |
| 6173 | | \\pub fn main(args: [][]bogus) !void {} |
| 6375 | ctx.objErrStage1("main function with bogus args type", |
| 6376 | \\pub fn main(args: [][]bogus) !void {_ = args;} |
| 6174 | 6377 | , &[_][]const u8{ |
| 6175 | 6378 | "tmp.zig:1:23: error: use of undeclared identifier 'bogus'", |
| 6176 | 6379 | }); |
| 6177 | 6380 | |
| 6178 | | cases.add("misspelled type with pointer only reference", |
| 6381 | ctx.objErrStage1("misspelled type with pointer only reference", |
| 6179 | 6382 | \\const JasonHM = u8; |
| 6180 | 6383 | \\const JasonList = *JsonNode; |
| 6181 | 6384 | \\ |
| ... | ... | @@ -6203,6 +6406,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6203 | 6406 | \\ var jll: JasonList = undefined; |
| 6204 | 6407 | \\ jll.init(1234); |
| 6205 | 6408 | \\ var jd = JsonNode {.kind = JsonType.JSONArray , .jobject = JsonOA.JSONArray {jll} }; |
| 6409 | \\ _ = jd; |
| 6206 | 6410 | \\} |
| 6207 | 6411 | \\ |
| 6208 | 6412 | \\export fn entry() usize { return @sizeOf(@TypeOf(foo)); } |
| ... | ... | @@ -6210,7 +6414,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6210 | 6414 | "tmp.zig:5:16: error: use of undeclared identifier 'JsonList'", |
| 6211 | 6415 | }); |
| 6212 | 6416 | |
| 6213 | | cases.add("method call with first arg type primitive", |
| 6417 | ctx.objErrStage1("method call with first arg type primitive", |
| 6214 | 6418 | \\const Foo = struct { |
| 6215 | 6419 | \\ x: i32, |
| 6216 | 6420 | \\ |
| ... | ... | @@ -6230,7 +6434,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6230 | 6434 | "tmp.zig:14:5: error: expected type 'i32', found 'Foo'", |
| 6231 | 6435 | }); |
| 6232 | 6436 | |
| 6233 | | cases.add("method call with first arg type wrong container", |
| 6437 | ctx.objErrStage1("method call with first arg type wrong container", |
| 6234 | 6438 | \\pub const List = struct { |
| 6235 | 6439 | \\ len: usize, |
| 6236 | 6440 | \\ allocator: *Allocator, |
| ... | ... | @@ -6259,7 +6463,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6259 | 6463 | "tmp.zig:23:5: error: expected type '*Allocator', found '*List'", |
| 6260 | 6464 | }); |
| 6261 | 6465 | |
| 6262 | | cases.add("binary not on number literal", |
| 6466 | ctx.objErrStage1("binary not on number literal", |
| 6263 | 6467 | \\const TINY_QUANTUM_SHIFT = 4; |
| 6264 | 6468 | \\const TINY_QUANTUM_SIZE = 1 << TINY_QUANTUM_SHIFT; |
| 6265 | 6469 | \\var block_aligned_stuff: usize = (4 + TINY_QUANTUM_SIZE) & ~(TINY_QUANTUM_SIZE - 1); |
| ... | ... | @@ -6269,8 +6473,15 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6269 | 6473 | "tmp.zig:3:60: error: unable to perform binary not operation on type 'comptime_int'", |
| 6270 | 6474 | }); |
| 6271 | 6475 | |
| 6272 | | cases.addCase(x: { |
| 6273 | | const tc = cases.create("multiple files with private function error", |
| 6476 | { |
| 6477 | const case = ctx.obj("multiple files with private function error", .{}); |
| 6478 | case.backend = .stage1; |
| 6479 | |
| 6480 | case.addSourceFile("foo.zig", |
| 6481 | \\fn privateFunction() void { } |
| 6482 | ); |
| 6483 | |
| 6484 | case.addError( |
| 6274 | 6485 | \\const foo = @import("foo.zig",); |
| 6275 | 6486 | \\ |
| 6276 | 6487 | \\export fn callPrivFunction() void { |
| ... | ... | @@ -6280,16 +6491,19 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6280 | 6491 | "tmp.zig:4:8: error: 'privateFunction' is private", |
| 6281 | 6492 | "foo.zig:1:1: note: declared here", |
| 6282 | 6493 | }); |
| 6494 | } |
| 6283 | 6495 | |
| 6284 | | tc.addSourceFile("foo.zig", |
| 6285 | | \\fn privateFunction() void { } |
| 6286 | | ); |
| 6496 | { |
| 6497 | const case = ctx.obj("multiple files with private member instance function (canonical invocation) error", .{}); |
| 6498 | case.backend = .stage1; |
| 6287 | 6499 | |
| 6288 | | break :x tc; |
| 6289 | | }); |
| 6500 | case.addSourceFile("foo.zig", |
| 6501 | \\pub const Foo = struct { |
| 6502 | \\ fn privateFunction(self: *Foo) void { _ = self; } |
| 6503 | \\}; |
| 6504 | ); |
| 6290 | 6505 | |
| 6291 | | cases.addCase(x: { |
| 6292 | | const tc = cases.create("multiple files with private member instance function (canonical invocation) error", |
| 6506 | case.addError( |
| 6293 | 6507 | \\const Foo = @import("foo.zig",).Foo; |
| 6294 | 6508 | \\ |
| 6295 | 6509 | \\export fn callPrivFunction() void { |
| ... | ... | @@ -6300,18 +6514,19 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6300 | 6514 | "tmp.zig:5:8: error: 'privateFunction' is private", |
| 6301 | 6515 | "foo.zig:2:5: note: declared here", |
| 6302 | 6516 | }); |
| 6517 | } |
| 6303 | 6518 | |
| 6304 | | tc.addSourceFile("foo.zig", |
| 6519 | { |
| 6520 | const case = ctx.obj("multiple files with private member instance function error", .{}); |
| 6521 | case.backend = .stage1; |
| 6522 | |
| 6523 | case.addSourceFile("foo.zig", |
| 6305 | 6524 | \\pub const Foo = struct { |
| 6306 | | \\ fn privateFunction(self: *Foo) void { } |
| 6525 | \\ fn privateFunction(self: *Foo) void { _ = self; } |
| 6307 | 6526 | \\}; |
| 6308 | 6527 | ); |
| 6309 | 6528 | |
| 6310 | | break :x tc; |
| 6311 | | }); |
| 6312 | | |
| 6313 | | cases.addCase(x: { |
| 6314 | | const tc = cases.create("multiple files with private member instance function error", |
| 6529 | case.addError( |
| 6315 | 6530 | \\const Foo = @import("foo.zig",).Foo; |
| 6316 | 6531 | \\ |
| 6317 | 6532 | \\export fn callPrivFunction() void { |
| ... | ... | @@ -6322,17 +6537,9 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6322 | 6537 | "tmp.zig:5:8: error: 'privateFunction' is private", |
| 6323 | 6538 | "foo.zig:2:5: note: declared here", |
| 6324 | 6539 | }); |
| 6540 | } |
| 6325 | 6541 | |
| 6326 | | tc.addSourceFile("foo.zig", |
| 6327 | | \\pub const Foo = struct { |
| 6328 | | \\ fn privateFunction(self: *Foo) void { } |
| 6329 | | \\}; |
| 6330 | | ); |
| 6331 | | |
| 6332 | | break :x tc; |
| 6333 | | }); |
| 6334 | | |
| 6335 | | cases.add("container init with non-type", |
| 6542 | ctx.objErrStage1("container init with non-type", |
| 6336 | 6543 | \\const zero: i32 = 0; |
| 6337 | 6544 | \\const a = zero{1}; |
| 6338 | 6545 | \\ |
| ... | ... | @@ -6341,7 +6548,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6341 | 6548 | "tmp.zig:2:11: error: expected type 'type', found 'i32'", |
| 6342 | 6549 | }); |
| 6343 | 6550 | |
| 6344 | | cases.add("assign to constant field", |
| 6551 | ctx.objErrStage1("assign to constant field", |
| 6345 | 6552 | \\const Foo = struct { |
| 6346 | 6553 | \\ field: i32, |
| 6347 | 6554 | \\}; |
| ... | ... | @@ -6353,7 +6560,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6353 | 6560 | "tmp.zig:6:15: error: cannot assign to constant", |
| 6354 | 6561 | }); |
| 6355 | 6562 | |
| 6356 | | cases.add("return from defer expression", |
| 6563 | ctx.objErrStage1("return from defer expression", |
| 6357 | 6564 | \\pub fn testTrickyDefer() !void { |
| 6358 | 6565 | \\ defer canFail() catch {}; |
| 6359 | 6566 | \\ |
| ... | ... | @@ -6370,32 +6577,33 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6370 | 6577 | \\ |
| 6371 | 6578 | \\export fn entry() usize { return @sizeOf(@TypeOf(testTrickyDefer)); } |
| 6372 | 6579 | , &[_][]const u8{ |
| 6373 | | "tmp.zig:4:11: error: cannot return from defer expression", |
| 6580 | "tmp.zig:4:11: error: 'try' is not allowed inside defer expression", |
| 6374 | 6581 | }); |
| 6375 | 6582 | |
| 6376 | | cases.add("assign too big number to u16", |
| 6583 | ctx.objErrStage1("assign too big number to u16", |
| 6377 | 6584 | \\export fn foo() void { |
| 6378 | 6585 | \\ var vga_mem: u16 = 0xB8000; |
| 6586 | \\ _ = vga_mem; |
| 6379 | 6587 | \\} |
| 6380 | 6588 | , &[_][]const u8{ |
| 6381 | 6589 | "tmp.zig:2:24: error: integer value 753664 cannot be coerced to type 'u16'", |
| 6382 | 6590 | }); |
| 6383 | 6591 | |
| 6384 | | cases.add("global variable alignment non power of 2", |
| 6592 | ctx.objErrStage1("global variable alignment non power of 2", |
| 6385 | 6593 | \\const some_data: [100]u8 align(3) = undefined; |
| 6386 | 6594 | \\export fn entry() usize { return @sizeOf(@TypeOf(some_data)); } |
| 6387 | 6595 | , &[_][]const u8{ |
| 6388 | 6596 | "tmp.zig:1:32: error: alignment value 3 is not a power of 2", |
| 6389 | 6597 | }); |
| 6390 | 6598 | |
| 6391 | | cases.add("function alignment non power of 2", |
| 6599 | ctx.objErrStage1("function alignment non power of 2", |
| 6392 | 6600 | \\extern fn foo() align(3) void; |
| 6393 | 6601 | \\export fn entry() void { return foo(); } |
| 6394 | 6602 | , &[_][]const u8{ |
| 6395 | 6603 | "tmp.zig:1:23: error: alignment value 3 is not a power of 2", |
| 6396 | 6604 | }); |
| 6397 | 6605 | |
| 6398 | | cases.add("compile log", |
| 6606 | ctx.objErrStage1("compile log", |
| 6399 | 6607 | \\export fn foo() void { |
| 6400 | 6608 | \\ comptime bar(12, "hi",); |
| 6401 | 6609 | \\} |
| ... | ... | @@ -6410,7 +6618,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6410 | 6618 | "tmp.zig:7:5: error: found compile log statement", |
| 6411 | 6619 | }); |
| 6412 | 6620 | |
| 6413 | | cases.add("casting bit offset pointer to regular pointer", |
| 6621 | ctx.objErrStage1("casting bit offset pointer to regular pointer", |
| 6414 | 6622 | \\const BitField = packed struct { |
| 6415 | 6623 | \\ a: u3, |
| 6416 | 6624 | \\ b: u3, |
| ... | ... | @@ -6430,7 +6638,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6430 | 6638 | "tmp.zig:8:26: error: expected type '*const u3', found '*align(:3:1) const u3'", |
| 6431 | 6639 | }); |
| 6432 | 6640 | |
| 6433 | | cases.add("referring to a struct that is invalid", |
| 6641 | ctx.objErrStage1("referring to a struct that is invalid", |
| 6434 | 6642 | \\const UsbDeviceRequest = struct { |
| 6435 | 6643 | \\ Type: u8, |
| 6436 | 6644 | \\}; |
| ... | ... | @@ -6447,7 +6655,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6447 | 6655 | "tmp.zig:6:20: note: referenced here", |
| 6448 | 6656 | }); |
| 6449 | 6657 | |
| 6450 | | cases.add("control flow uses comptime var at runtime", |
| 6658 | ctx.objErrStage1("control flow uses comptime var at runtime", |
| 6451 | 6659 | \\export fn foo() void { |
| 6452 | 6660 | \\ comptime var i = 0; |
| 6453 | 6661 | \\ while (i < 5) : (i += 1) { |
| ... | ... | @@ -6461,7 +6669,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6461 | 6669 | "tmp.zig:3:24: note: compile-time variable assigned here", |
| 6462 | 6670 | }); |
| 6463 | 6671 | |
| 6464 | | cases.add("ignored return value", |
| 6672 | ctx.objErrStage1("ignored return value", |
| 6465 | 6673 | \\export fn foo() void { |
| 6466 | 6674 | \\ bar(); |
| 6467 | 6675 | \\} |
| ... | ... | @@ -6470,7 +6678,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6470 | 6678 | "tmp.zig:2:8: error: expression value is ignored", |
| 6471 | 6679 | }); |
| 6472 | 6680 | |
| 6473 | | cases.add("ignored assert-err-ok return value", |
| 6681 | ctx.objErrStage1("ignored assert-err-ok return value", |
| 6474 | 6682 | \\export fn foo() void { |
| 6475 | 6683 | \\ bar() catch unreachable; |
| 6476 | 6684 | \\} |
| ... | ... | @@ -6479,7 +6687,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6479 | 6687 | "tmp.zig:2:11: error: expression value is ignored", |
| 6480 | 6688 | }); |
| 6481 | 6689 | |
| 6482 | | cases.add("ignored statement value", |
| 6690 | ctx.objErrStage1("ignored statement value", |
| 6483 | 6691 | \\export fn foo() void { |
| 6484 | 6692 | \\ 1; |
| 6485 | 6693 | \\} |
| ... | ... | @@ -6487,7 +6695,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6487 | 6695 | "tmp.zig:2:5: error: expression value is ignored", |
| 6488 | 6696 | }); |
| 6489 | 6697 | |
| 6490 | | cases.add("ignored comptime statement value", |
| 6698 | ctx.objErrStage1("ignored comptime statement value", |
| 6491 | 6699 | \\export fn foo() void { |
| 6492 | 6700 | \\ comptime {1;} |
| 6493 | 6701 | \\} |
| ... | ... | @@ -6495,7 +6703,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6495 | 6703 | "tmp.zig:2:15: error: expression value is ignored", |
| 6496 | 6704 | }); |
| 6497 | 6705 | |
| 6498 | | cases.add("ignored comptime value", |
| 6706 | ctx.objErrStage1("ignored comptime value", |
| 6499 | 6707 | \\export fn foo() void { |
| 6500 | 6708 | \\ comptime 1; |
| 6501 | 6709 | \\} |
| ... | ... | @@ -6503,7 +6711,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6503 | 6711 | "tmp.zig:2:5: error: expression value is ignored", |
| 6504 | 6712 | }); |
| 6505 | 6713 | |
| 6506 | | cases.add("ignored defered statement value", |
| 6714 | ctx.objErrStage1("ignored defered statement value", |
| 6507 | 6715 | \\export fn foo() void { |
| 6508 | 6716 | \\ defer {1;} |
| 6509 | 6717 | \\} |
| ... | ... | @@ -6511,7 +6719,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6511 | 6719 | "tmp.zig:2:12: error: expression value is ignored", |
| 6512 | 6720 | }); |
| 6513 | 6721 | |
| 6514 | | cases.add("ignored defered function call", |
| 6722 | ctx.objErrStage1("ignored defered function call", |
| 6515 | 6723 | \\export fn foo() void { |
| 6516 | 6724 | \\ defer bar(); |
| 6517 | 6725 | \\} |
| ... | ... | @@ -6520,7 +6728,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6520 | 6728 | "tmp.zig:2:14: error: error is ignored. consider using `try`, `catch`, or `if`", |
| 6521 | 6729 | }); |
| 6522 | 6730 | |
| 6523 | | cases.add("dereference an array", |
| 6731 | ctx.objErrStage1("dereference an array", |
| 6524 | 6732 | \\var s_buffer: [10]u8 = undefined; |
| 6525 | 6733 | \\pub fn pass(in: []u8) []u8 { |
| 6526 | 6734 | \\ var out = &s_buffer; |
| ... | ... | @@ -6533,13 +6741,14 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6533 | 6741 | "tmp.zig:4:10: error: attempt to dereference non-pointer type '[10]u8'", |
| 6534 | 6742 | }); |
| 6535 | 6743 | |
| 6536 | | cases.add("pass const ptr to mutable ptr fn", |
| 6744 | ctx.objErrStage1("pass const ptr to mutable ptr fn", |
| 6537 | 6745 | \\fn foo() bool { |
| 6538 | 6746 | \\ const a = @as([]const u8, "a",); |
| 6539 | 6747 | \\ const b = &a; |
| 6540 | 6748 | \\ return ptrEql(b, b); |
| 6541 | 6749 | \\} |
| 6542 | 6750 | \\fn ptrEql(a: *[]const u8, b: *[]const u8) bool { |
| 6751 | \\ _ = a; _ = b; |
| 6543 | 6752 | \\ return true; |
| 6544 | 6753 | \\} |
| 6545 | 6754 | \\ |
| ... | ... | @@ -6548,8 +6757,16 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6548 | 6757 | "tmp.zig:4:19: error: expected type '*[]const u8', found '*const []const u8'", |
| 6549 | 6758 | }); |
| 6550 | 6759 | |
| 6551 | | cases.addCase(x: { |
| 6552 | | const tc = cases.create("export collision", |
| 6760 | { |
| 6761 | const case = ctx.obj("export collision", .{}); |
| 6762 | case.backend = .stage1; |
| 6763 | |
| 6764 | case.addSourceFile("foo.zig", |
| 6765 | \\export fn bar() void {} |
| 6766 | \\pub const baz = 1234; |
| 6767 | ); |
| 6768 | |
| 6769 | case.addError( |
| 6553 | 6770 | \\const foo = @import("foo.zig",); |
| 6554 | 6771 | \\ |
| 6555 | 6772 | \\export fn bar() usize { |
| ... | ... | @@ -6559,18 +6776,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6559 | 6776 | "foo.zig:1:1: error: exported symbol collision: 'bar'", |
| 6560 | 6777 | "tmp.zig:3:1: note: other symbol here", |
| 6561 | 6778 | }); |
| 6779 | } |
| 6562 | 6780 | |
| 6563 | | tc.addSourceFile("foo.zig", |
| 6564 | | \\export fn bar() void {} |
| 6565 | | \\pub const baz = 1234; |
| 6566 | | ); |
| 6567 | | |
| 6568 | | break :x tc; |
| 6569 | | }); |
| 6570 | | |
| 6571 | | cases.add("implicit cast from array to mutable slice", |
| 6781 | ctx.objErrStage1("implicit cast from array to mutable slice", |
| 6572 | 6782 | \\var global_array: [10]i32 = undefined; |
| 6573 | | \\fn foo(param: []i32) void {} |
| 6783 | \\fn foo(param: []i32) void {_ = param;} |
| 6574 | 6784 | \\export fn entry() void { |
| 6575 | 6785 | \\ foo(global_array); |
| 6576 | 6786 | \\} |
| ... | ... | @@ -6578,7 +6788,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6578 | 6788 | "tmp.zig:4:9: error: expected type '[]i32', found '[10]i32'", |
| 6579 | 6789 | }); |
| 6580 | 6790 | |
| 6581 | | cases.add("ptrcast to non-pointer", |
| 6791 | ctx.objErrStage1("ptrcast to non-pointer", |
| 6582 | 6792 | \\export fn entry(a: *i32) usize { |
| 6583 | 6793 | \\ return @ptrCast(usize, a); |
| 6584 | 6794 | \\} |
| ... | ... | @@ -6586,7 +6796,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6586 | 6796 | "tmp.zig:2:21: error: expected pointer, found 'usize'", |
| 6587 | 6797 | }); |
| 6588 | 6798 | |
| 6589 | | cases.add("asm at compile time", |
| 6799 | ctx.objErrStage1("asm at compile time", |
| 6590 | 6800 | \\comptime { |
| 6591 | 6801 | \\ doSomeAsm(); |
| 6592 | 6802 | \\} |
| ... | ... | @@ -6602,25 +6812,27 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6602 | 6812 | "tmp.zig:6:5: error: unable to evaluate constant expression", |
| 6603 | 6813 | }); |
| 6604 | 6814 | |
| 6605 | | cases.add("invalid member of builtin enum", |
| 6815 | ctx.objErrStage1("invalid member of builtin enum", |
| 6606 | 6816 | \\const builtin = @import("std").builtin; |
| 6607 | 6817 | \\export fn entry() void { |
| 6608 | 6818 | \\ const foo = builtin.Mode.x86; |
| 6819 | \\ _ = foo; |
| 6609 | 6820 | \\} |
| 6610 | 6821 | , &[_][]const u8{ |
| 6611 | 6822 | "tmp.zig:3:29: error: container 'std.builtin.Mode' has no member called 'x86'", |
| 6612 | 6823 | }); |
| 6613 | 6824 | |
| 6614 | | cases.add("int to ptr of 0 bits", |
| 6825 | ctx.objErrStage1("int to ptr of 0 bits", |
| 6615 | 6826 | \\export fn foo() void { |
| 6616 | 6827 | \\ var x: usize = 0x1000; |
| 6617 | 6828 | \\ var y: *void = @intToPtr(*void, x); |
| 6829 | \\ _ = y; |
| 6618 | 6830 | \\} |
| 6619 | 6831 | , &[_][]const u8{ |
| 6620 | 6832 | "tmp.zig:3:30: error: type '*void' has 0 bits and cannot store information", |
| 6621 | 6833 | }); |
| 6622 | 6834 | |
| 6623 | | cases.add("@fieldParentPtr - non struct", |
| 6835 | ctx.objErrStage1("@fieldParentPtr - non struct", |
| 6624 | 6836 | \\const Foo = i32; |
| 6625 | 6837 | \\export fn foo(a: *i32) *Foo { |
| 6626 | 6838 | \\ return @fieldParentPtr(Foo, "a", a); |
| ... | ... | @@ -6629,7 +6841,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6629 | 6841 | "tmp.zig:3:28: error: expected struct type, found 'i32'", |
| 6630 | 6842 | }); |
| 6631 | 6843 | |
| 6632 | | cases.add("@fieldParentPtr - bad field name", |
| 6844 | ctx.objErrStage1("@fieldParentPtr - bad field name", |
| 6633 | 6845 | \\const Foo = extern struct { |
| 6634 | 6846 | \\ derp: i32, |
| 6635 | 6847 | \\}; |
| ... | ... | @@ -6640,7 +6852,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6640 | 6852 | "tmp.zig:5:33: error: struct 'Foo' has no field 'a'", |
| 6641 | 6853 | }); |
| 6642 | 6854 | |
| 6643 | | cases.add("@fieldParentPtr - field pointer is not pointer", |
| 6855 | ctx.objErrStage1("@fieldParentPtr - field pointer is not pointer", |
| 6644 | 6856 | \\const Foo = extern struct { |
| 6645 | 6857 | \\ a: i32, |
| 6646 | 6858 | \\}; |
| ... | ... | @@ -6651,7 +6863,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6651 | 6863 | "tmp.zig:5:38: error: expected pointer, found 'i32'", |
| 6652 | 6864 | }); |
| 6653 | 6865 | |
| 6654 | | cases.add("@fieldParentPtr - comptime field ptr not based on struct", |
| 6866 | ctx.objErrStage1("@fieldParentPtr - comptime field ptr not based on struct", |
| 6655 | 6867 | \\const Foo = struct { |
| 6656 | 6868 | \\ a: i32, |
| 6657 | 6869 | \\ b: i32, |
| ... | ... | @@ -6661,12 +6873,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6661 | 6873 | \\comptime { |
| 6662 | 6874 | \\ const field_ptr = @intToPtr(*i32, 0x1234); |
| 6663 | 6875 | \\ const another_foo_ptr = @fieldParentPtr(Foo, "b", field_ptr); |
| 6876 | \\ _ = another_foo_ptr; |
| 6664 | 6877 | \\} |
| 6665 | 6878 | , &[_][]const u8{ |
| 6666 | 6879 | "tmp.zig:9:55: error: pointer value not based on parent struct", |
| 6667 | 6880 | }); |
| 6668 | 6881 | |
| 6669 | | cases.add("@fieldParentPtr - comptime wrong field index", |
| 6882 | ctx.objErrStage1("@fieldParentPtr - comptime wrong field index", |
| 6670 | 6883 | \\const Foo = struct { |
| 6671 | 6884 | \\ a: i32, |
| 6672 | 6885 | \\ b: i32, |
| ... | ... | @@ -6675,12 +6888,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6675 | 6888 | \\ |
| 6676 | 6889 | \\comptime { |
| 6677 | 6890 | \\ const another_foo_ptr = @fieldParentPtr(Foo, "b", &foo.a); |
| 6891 | \\ _ = another_foo_ptr; |
| 6678 | 6892 | \\} |
| 6679 | 6893 | , &[_][]const u8{ |
| 6680 | 6894 | "tmp.zig:8:29: error: field 'b' has index 1 but pointer value is index 0 of struct 'Foo'", |
| 6681 | 6895 | }); |
| 6682 | 6896 | |
| 6683 | | cases.add("@offsetOf - non struct", |
| 6897 | ctx.objErrStage1("@offsetOf - non struct", |
| 6684 | 6898 | \\const Foo = i32; |
| 6685 | 6899 | \\export fn foo() usize { |
| 6686 | 6900 | \\ return @offsetOf(Foo, "a",); |
| ... | ... | @@ -6689,7 +6903,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6689 | 6903 | "tmp.zig:3:22: error: expected struct type, found 'i32'", |
| 6690 | 6904 | }); |
| 6691 | 6905 | |
| 6692 | | cases.add("@offsetOf - bad field name", |
| 6906 | ctx.objErrStage1("@offsetOf - bad field name", |
| 6693 | 6907 | \\const Foo = struct { |
| 6694 | 6908 | \\ derp: i32, |
| 6695 | 6909 | \\}; |
| ... | ... | @@ -6700,20 +6914,20 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6700 | 6914 | "tmp.zig:5:27: error: struct 'Foo' has no field 'a'", |
| 6701 | 6915 | }); |
| 6702 | 6916 | |
| 6703 | | cases.addExe("missing main fn in executable", |
| 6917 | ctx.exeErrStage1("missing main fn in executable", |
| 6704 | 6918 | \\ |
| 6705 | 6919 | , &[_][]const u8{ |
| 6706 | 6920 | "error: root source file has no member called 'main'", |
| 6707 | 6921 | }); |
| 6708 | 6922 | |
| 6709 | | cases.addExe("private main fn", |
| 6923 | ctx.exeErrStage1("private main fn", |
| 6710 | 6924 | \\fn main() void {} |
| 6711 | 6925 | , &[_][]const u8{ |
| 6712 | 6926 | "error: 'main' is private", |
| 6713 | 6927 | "tmp.zig:1:1: note: declared here", |
| 6714 | 6928 | }); |
| 6715 | 6929 | |
| 6716 | | cases.add("setting a section on a local variable", |
| 6930 | ctx.objErrStage1("setting a section on a local variable", |
| 6717 | 6931 | \\export fn entry() i32 { |
| 6718 | 6932 | \\ var foo: i32 linksection(".text2") = 1234; |
| 6719 | 6933 | \\ return foo; |
| ... | ... | @@ -6722,7 +6936,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6722 | 6936 | "tmp.zig:2:30: error: cannot set section of local variable 'foo'", |
| 6723 | 6937 | }); |
| 6724 | 6938 | |
| 6725 | | cases.add("inner struct member shadowing outer struct member", |
| 6939 | ctx.objErrStage1("inner struct member shadowing outer struct member", |
| 6726 | 6940 | \\fn A() type { |
| 6727 | 6941 | \\ return struct { |
| 6728 | 6942 | \\ b: B(), |
| ... | ... | @@ -6747,7 +6961,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6747 | 6961 | "tmp.zig:5:9: note: previous definition is here", |
| 6748 | 6962 | }); |
| 6749 | 6963 | |
| 6750 | | cases.add("while expected bool, got optional", |
| 6964 | ctx.objErrStage1("while expected bool, got optional", |
| 6751 | 6965 | \\export fn foo() void { |
| 6752 | 6966 | \\ while (bar()) {} |
| 6753 | 6967 | \\} |
| ... | ... | @@ -6756,7 +6970,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6756 | 6970 | "tmp.zig:2:15: error: expected type 'bool', found '?i32'", |
| 6757 | 6971 | }); |
| 6758 | 6972 | |
| 6759 | | cases.add("while expected bool, got error union", |
| 6973 | ctx.objErrStage1("while expected bool, got error union", |
| 6760 | 6974 | \\export fn foo() void { |
| 6761 | 6975 | \\ while (bar()) {} |
| 6762 | 6976 | \\} |
| ... | ... | @@ -6765,36 +6979,36 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6765 | 6979 | "tmp.zig:2:15: error: expected type 'bool', found 'anyerror!i32'", |
| 6766 | 6980 | }); |
| 6767 | 6981 | |
| 6768 | | cases.add("while expected optional, got bool", |
| 6982 | ctx.objErrStage1("while expected optional, got bool", |
| 6769 | 6983 | \\export fn foo() void { |
| 6770 | | \\ while (bar()) |x| {} |
| 6984 | \\ while (bar()) |x| {_ = x;} |
| 6771 | 6985 | \\} |
| 6772 | 6986 | \\fn bar() bool { return true; } |
| 6773 | 6987 | , &[_][]const u8{ |
| 6774 | 6988 | "tmp.zig:2:15: error: expected optional type, found 'bool'", |
| 6775 | 6989 | }); |
| 6776 | 6990 | |
| 6777 | | cases.add("while expected optional, got error union", |
| 6991 | ctx.objErrStage1("while expected optional, got error union", |
| 6778 | 6992 | \\export fn foo() void { |
| 6779 | | \\ while (bar()) |x| {} |
| 6993 | \\ while (bar()) |x| {_ = x;} |
| 6780 | 6994 | \\} |
| 6781 | 6995 | \\fn bar() anyerror!i32 { return 1; } |
| 6782 | 6996 | , &[_][]const u8{ |
| 6783 | 6997 | "tmp.zig:2:15: error: expected optional type, found 'anyerror!i32'", |
| 6784 | 6998 | }); |
| 6785 | 6999 | |
| 6786 | | cases.add("while expected error union, got bool", |
| 7000 | ctx.objErrStage1("while expected error union, got bool", |
| 6787 | 7001 | \\export fn foo() void { |
| 6788 | | \\ while (bar()) |x| {} else |err| {} |
| 7002 | \\ while (bar()) |x| {_ = x;} else |err| {_ = err;} |
| 6789 | 7003 | \\} |
| 6790 | 7004 | \\fn bar() bool { return true; } |
| 6791 | 7005 | , &[_][]const u8{ |
| 6792 | 7006 | "tmp.zig:2:15: error: expected error union type, found 'bool'", |
| 6793 | 7007 | }); |
| 6794 | 7008 | |
| 6795 | | cases.add("while expected error union, got optional", |
| 7009 | ctx.objErrStage1("while expected error union, got optional", |
| 6796 | 7010 | \\export fn foo() void { |
| 6797 | | \\ while (bar()) |x| {} else |err| {} |
| 7011 | \\ while (bar()) |x| {_ = x;} else |err| {_ = err;} |
| 6798 | 7012 | \\} |
| 6799 | 7013 | \\fn bar() ?i32 { return 1; } |
| 6800 | 7014 | , &[_][]const u8{ |
| ... | ... | @@ -6802,7 +7016,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6802 | 7016 | }); |
| 6803 | 7017 | |
| 6804 | 7018 | // TODO test this in stage2, but we won't even try in stage1 |
| 6805 | | //cases.add("inline fn calls itself indirectly", |
| 7019 | //ctx.objErrStage1("inline fn calls itself indirectly", |
| 6806 | 7020 | // \\export fn foo() void { |
| 6807 | 7021 | // \\ bar(); |
| 6808 | 7022 | // \\} |
| ... | ... | @@ -6819,7 +7033,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6819 | 7033 | // "tmp.zig:4:1: error: unable to inline function", |
| 6820 | 7034 | //}); |
| 6821 | 7035 | |
| 6822 | | //cases.add("save reference to inline function", |
| 7036 | //ctx.objErrStage1("save reference to inline function", |
| 6823 | 7037 | // \\export fn foo() void { |
| 6824 | 7038 | // \\ quux(@ptrToInt(bar)); |
| 6825 | 7039 | // \\} |
| ... | ... | @@ -6829,7 +7043,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6829 | 7043 | // "tmp.zig:4:1: error: unable to inline function", |
| 6830 | 7044 | //}); |
| 6831 | 7045 | |
| 6832 | | cases.add("signed integer division", |
| 7046 | ctx.objErrStage1("signed integer division", |
| 6833 | 7047 | \\export fn foo(a: i32, b: i32) i32 { |
| 6834 | 7048 | \\ return a / b; |
| 6835 | 7049 | \\} |
| ... | ... | @@ -6837,7 +7051,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6837 | 7051 | "tmp.zig:2:14: error: division with 'i32' and 'i32': signed integers must use @divTrunc, @divFloor, or @divExact", |
| 6838 | 7052 | }); |
| 6839 | 7053 | |
| 6840 | | cases.add("signed integer remainder division", |
| 7054 | ctx.objErrStage1("signed integer remainder division", |
| 6841 | 7055 | \\export fn foo(a: i32, b: i32) i32 { |
| 6842 | 7056 | \\ return a % b; |
| 6843 | 7057 | \\} |
| ... | ... | @@ -6845,27 +7059,29 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6845 | 7059 | "tmp.zig:2:14: error: remainder division with 'i32' and 'i32': signed integers and floats must use @rem or @mod", |
| 6846 | 7060 | }); |
| 6847 | 7061 | |
| 6848 | | cases.add("compile-time division by zero", |
| 7062 | ctx.objErrStage1("compile-time division by zero", |
| 6849 | 7063 | \\comptime { |
| 6850 | 7064 | \\ const a: i32 = 1; |
| 6851 | 7065 | \\ const b: i32 = 0; |
| 6852 | 7066 | \\ const c = a / b; |
| 7067 | \\ _ = c; |
| 6853 | 7068 | \\} |
| 6854 | 7069 | , &[_][]const u8{ |
| 6855 | 7070 | "tmp.zig:4:17: error: division by zero", |
| 6856 | 7071 | }); |
| 6857 | 7072 | |
| 6858 | | cases.add("compile-time remainder division by zero", |
| 7073 | ctx.objErrStage1("compile-time remainder division by zero", |
| 6859 | 7074 | \\comptime { |
| 6860 | 7075 | \\ const a: i32 = 1; |
| 6861 | 7076 | \\ const b: i32 = 0; |
| 6862 | 7077 | \\ const c = a % b; |
| 7078 | \\ _ = c; |
| 6863 | 7079 | \\} |
| 6864 | 7080 | , &[_][]const u8{ |
| 6865 | 7081 | "tmp.zig:4:17: error: division by zero", |
| 6866 | 7082 | }); |
| 6867 | 7083 | |
| 6868 | | cases.add("@setRuntimeSafety twice for same scope", |
| 7084 | ctx.objErrStage1("@setRuntimeSafety twice for same scope", |
| 6869 | 7085 | \\export fn foo() void { |
| 6870 | 7086 | \\ @setRuntimeSafety(false); |
| 6871 | 7087 | \\ @setRuntimeSafety(false); |
| ... | ... | @@ -6875,7 +7091,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6875 | 7091 | "tmp.zig:2:5: note: first set here", |
| 6876 | 7092 | }); |
| 6877 | 7093 | |
| 6878 | | cases.add("@setFloatMode twice for same scope", |
| 7094 | ctx.objErrStage1("@setFloatMode twice for same scope", |
| 6879 | 7095 | \\export fn foo() void { |
| 6880 | 7096 | \\ @setFloatMode(@import("std").builtin.FloatMode.Optimized); |
| 6881 | 7097 | \\ @setFloatMode(@import("std").builtin.FloatMode.Optimized); |
| ... | ... | @@ -6885,15 +7101,16 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6885 | 7101 | "tmp.zig:2:5: note: first set here", |
| 6886 | 7102 | }); |
| 6887 | 7103 | |
| 6888 | | cases.add("array access of type", |
| 7104 | ctx.objErrStage1("array access of type", |
| 6889 | 7105 | \\export fn foo() void { |
| 6890 | 7106 | \\ var b: u8[40] = undefined; |
| 7107 | \\ _ = b; |
| 6891 | 7108 | \\} |
| 6892 | 7109 | , &[_][]const u8{ |
| 6893 | 7110 | "tmp.zig:2:14: error: array access of non-array type 'type'", |
| 6894 | 7111 | }); |
| 6895 | 7112 | |
| 6896 | | cases.add("cannot break out of defer expression", |
| 7113 | ctx.objErrStage1("cannot break out of defer expression", |
| 6897 | 7114 | \\export fn foo() void { |
| 6898 | 7115 | \\ while (true) { |
| 6899 | 7116 | \\ defer { |
| ... | ... | @@ -6905,7 +7122,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6905 | 7122 | "tmp.zig:4:13: error: cannot break out of defer expression", |
| 6906 | 7123 | }); |
| 6907 | 7124 | |
| 6908 | | cases.add("cannot continue out of defer expression", |
| 7125 | ctx.objErrStage1("cannot continue out of defer expression", |
| 6909 | 7126 | \\export fn foo() void { |
| 6910 | 7127 | \\ while (true) { |
| 6911 | 7128 | \\ defer { |
| ... | ... | @@ -6917,11 +7134,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6917 | 7134 | "tmp.zig:4:13: error: cannot continue out of defer expression", |
| 6918 | 7135 | }); |
| 6919 | 7136 | |
| 6920 | | cases.add("calling a generic function only known at runtime", |
| 7137 | ctx.objErrStage1("calling a generic function only known at runtime", |
| 6921 | 7138 | \\var foos = [_]fn(anytype) void { foo1, foo2 }; |
| 6922 | 7139 | \\ |
| 6923 | | \\fn foo1(arg: anytype) void {} |
| 6924 | | \\fn foo2(arg: anytype) void {} |
| 7140 | \\fn foo1(arg: anytype) void {_ = arg;} |
| 7141 | \\fn foo2(arg: anytype) void {_ = arg;} |
| 6925 | 7142 | \\ |
| 6926 | 7143 | \\pub fn main() !void { |
| 6927 | 7144 | \\ foos[0](true); |
| ... | ... | @@ -6930,7 +7147,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6930 | 7147 | "tmp.zig:7:9: error: calling a generic function requires compile-time known function value", |
| 6931 | 7148 | }); |
| 6932 | 7149 | |
| 6933 | | cases.add("@compileError shows traceback of references that caused it", |
| 7150 | ctx.objErrStage1("@compileError shows traceback of references that caused it", |
| 6934 | 7151 | \\const foo = @compileError("aoeu",); |
| 6935 | 7152 | \\ |
| 6936 | 7153 | \\const bar = baz + foo; |
| ... | ... | @@ -6945,23 +7162,25 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6945 | 7162 | "tmp.zig:7:12: note: referenced here", |
| 6946 | 7163 | }); |
| 6947 | 7164 | |
| 6948 | | cases.add("float literal too large error", |
| 7165 | ctx.objErrStage1("float literal too large error", |
| 6949 | 7166 | \\comptime { |
| 6950 | 7167 | \\ const a = 0x1.0p18495; |
| 7168 | \\ _ = a; |
| 6951 | 7169 | \\} |
| 6952 | 7170 | , &[_][]const u8{ |
| 6953 | 7171 | "tmp.zig:2:15: error: float literal out of range of any type", |
| 6954 | 7172 | }); |
| 6955 | 7173 | |
| 6956 | | cases.add("float literal too small error (denormal)", |
| 7174 | ctx.objErrStage1("float literal too small error (denormal)", |
| 6957 | 7175 | \\comptime { |
| 6958 | 7176 | \\ const a = 0x1.0p-19000; |
| 7177 | \\ _ = a; |
| 6959 | 7178 | \\} |
| 6960 | 7179 | , &[_][]const u8{ |
| 6961 | 7180 | "tmp.zig:2:15: error: float literal out of range of any type", |
| 6962 | 7181 | }); |
| 6963 | 7182 | |
| 6964 | | cases.add("explicit cast float literal to integer when there is a fraction component", |
| 7183 | ctx.objErrStage1("explicit cast float literal to integer when there is a fraction component", |
| 6965 | 7184 | \\export fn entry() i32 { |
| 6966 | 7185 | \\ return @as(i32, 12.34); |
| 6967 | 7186 | \\} |
| ... | ... | @@ -6969,7 +7188,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6969 | 7188 | "tmp.zig:2:21: error: fractional component prevents float value 12.340000 from being casted to type 'i32'", |
| 6970 | 7189 | }); |
| 6971 | 7190 | |
| 6972 | | cases.add("non pointer given to @ptrToInt", |
| 7191 | ctx.objErrStage1("non pointer given to @ptrToInt", |
| 6973 | 7192 | \\export fn entry(x: i32) usize { |
| 6974 | 7193 | \\ return @ptrToInt(x); |
| 6975 | 7194 | \\} |
| ... | ... | @@ -6977,23 +7196,25 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6977 | 7196 | "tmp.zig:2:22: error: expected pointer, found 'i32'", |
| 6978 | 7197 | }); |
| 6979 | 7198 | |
| 6980 | | cases.add("@shlExact shifts out 1 bits", |
| 7199 | ctx.objErrStage1("@shlExact shifts out 1 bits", |
| 6981 | 7200 | \\comptime { |
| 6982 | 7201 | \\ const x = @shlExact(@as(u8, 0b01010101), 2); |
| 7202 | \\ _ = x; |
| 6983 | 7203 | \\} |
| 6984 | 7204 | , &[_][]const u8{ |
| 6985 | 7205 | "tmp.zig:2:15: error: operation caused overflow", |
| 6986 | 7206 | }); |
| 6987 | 7207 | |
| 6988 | | cases.add("@shrExact shifts out 1 bits", |
| 7208 | ctx.objErrStage1("@shrExact shifts out 1 bits", |
| 6989 | 7209 | \\comptime { |
| 6990 | 7210 | \\ const x = @shrExact(@as(u8, 0b10101010), 2); |
| 7211 | \\ _ = x; |
| 6991 | 7212 | \\} |
| 6992 | 7213 | , &[_][]const u8{ |
| 6993 | 7214 | "tmp.zig:2:15: error: exact shift shifted out 1 bits", |
| 6994 | 7215 | }); |
| 6995 | 7216 | |
| 6996 | | cases.add("shifting without int type or comptime known", |
| 7217 | ctx.objErrStage1("shifting without int type or comptime known", |
| 6997 | 7218 | \\export fn entry(x: u8) u8 { |
| 6998 | 7219 | \\ return 0x11 << x; |
| 6999 | 7220 | \\} |
| ... | ... | @@ -7001,7 +7222,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7001 | 7222 | "tmp.zig:2:17: error: LHS of shift must be a fixed-width integer type, or RHS must be compile-time known", |
| 7002 | 7223 | }); |
| 7003 | 7224 | |
| 7004 | | cases.add("shifting RHS is log2 of LHS int bit width", |
| 7225 | ctx.objErrStage1("shifting RHS is log2 of LHS int bit width", |
| 7005 | 7226 | \\export fn entry(x: u8, y: u8) u8 { |
| 7006 | 7227 | \\ return x << y; |
| 7007 | 7228 | \\} |
| ... | ... | @@ -7009,16 +7230,17 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7009 | 7230 | "tmp.zig:2:17: error: expected type 'u3', found 'u8'", |
| 7010 | 7231 | }); |
| 7011 | 7232 | |
| 7012 | | cases.add("globally shadowing a primitive type", |
| 7233 | ctx.objErrStage1("globally shadowing a primitive type", |
| 7013 | 7234 | \\const u16 = u8; |
| 7014 | 7235 | \\export fn entry() void { |
| 7015 | 7236 | \\ const a: u16 = 300; |
| 7237 | \\ _ = a; |
| 7016 | 7238 | \\} |
| 7017 | 7239 | , &[_][]const u8{ |
| 7018 | 7240 | "tmp.zig:1:1: error: declaration shadows primitive type 'u16'", |
| 7019 | 7241 | }); |
| 7020 | 7242 | |
| 7021 | | cases.add("implicitly increasing pointer alignment", |
| 7243 | ctx.objErrStage1("implicitly increasing pointer alignment", |
| 7022 | 7244 | \\const Foo = packed struct { |
| 7023 | 7245 | \\ a: u8, |
| 7024 | 7246 | \\ b: u32, |
| ... | ... | @@ -7036,7 +7258,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7036 | 7258 | "tmp.zig:8:13: error: expected type '*u32', found '*align(1) u32'", |
| 7037 | 7259 | }); |
| 7038 | 7260 | |
| 7039 | | cases.add("implicitly increasing slice alignment", |
| 7261 | ctx.objErrStage1("implicitly increasing slice alignment", |
| 7040 | 7262 | \\const Foo = packed struct { |
| 7041 | 7263 | \\ a: u8, |
| 7042 | 7264 | \\ b: u32, |
| ... | ... | @@ -7057,7 +7279,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7057 | 7279 | "tmp.zig:9:26: note: '*[1]u32' has alignment 4", |
| 7058 | 7280 | }); |
| 7059 | 7281 | |
| 7060 | | cases.add("increase pointer alignment in @ptrCast", |
| 7282 | ctx.objErrStage1("increase pointer alignment in @ptrCast", |
| 7061 | 7283 | \\export fn entry() u32 { |
| 7062 | 7284 | \\ var bytes: [4]u8 = [_]u8{0x01, 0x02, 0x03, 0x04}; |
| 7063 | 7285 | \\ const ptr = @ptrCast(*u32, &bytes[0]); |
| ... | ... | @@ -7069,7 +7291,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7069 | 7291 | "tmp.zig:3:26: note: '*u32' has alignment 4", |
| 7070 | 7292 | }); |
| 7071 | 7293 | |
| 7072 | | cases.add("@alignCast expects pointer or slice", |
| 7294 | ctx.objErrStage1("@alignCast expects pointer or slice", |
| 7073 | 7295 | \\export fn entry() void { |
| 7074 | 7296 | \\ @alignCast(4, @as(u32, 3)); |
| 7075 | 7297 | \\} |
| ... | ... | @@ -7077,7 +7299,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7077 | 7299 | "tmp.zig:2:19: error: expected pointer or slice, found 'u32'", |
| 7078 | 7300 | }); |
| 7079 | 7301 | |
| 7080 | | cases.add("passing an under-aligned function pointer", |
| 7302 | ctx.objErrStage1("passing an under-aligned function pointer", |
| 7081 | 7303 | \\export fn entry() void { |
| 7082 | 7304 | \\ testImplicitlyDecreaseFnAlign(alignedSmall, 1234); |
| 7083 | 7305 | \\} |
| ... | ... | @@ -7089,7 +7311,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7089 | 7311 | "tmp.zig:2:35: error: expected type 'fn() align(8) i32', found 'fn() align(4) i32'", |
| 7090 | 7312 | }); |
| 7091 | 7313 | |
| 7092 | | cases.add("passing a not-aligned-enough pointer to cmpxchg", |
| 7314 | ctx.objErrStage1("passing a not-aligned-enough pointer to cmpxchg", |
| 7093 | 7315 | \\const AtomicOrder = @import("std").builtin.AtomicOrder; |
| 7094 | 7316 | \\export fn entry() bool { |
| 7095 | 7317 | \\ var x: i32 align(1) = 1234; |
| ... | ... | @@ -7100,15 +7322,16 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7100 | 7322 | "tmp.zig:4:32: error: expected type '*i32', found '*align(1) i32'", |
| 7101 | 7323 | }); |
| 7102 | 7324 | |
| 7103 | | cases.add("wrong size to an array literal", |
| 7325 | ctx.objErrStage1("wrong size to an array literal", |
| 7104 | 7326 | \\comptime { |
| 7105 | 7327 | \\ const array = [2]u8{1, 2, 3}; |
| 7328 | \\ _ = array; |
| 7106 | 7329 | \\} |
| 7107 | 7330 | , &[_][]const u8{ |
| 7108 | 7331 | "tmp.zig:2:31: error: index 2 outside array of size 2", |
| 7109 | 7332 | }); |
| 7110 | 7333 | |
| 7111 | | cases.add("wrong pointer coerced to pointer to opaque {}", |
| 7334 | ctx.objErrStage1("wrong pointer coerced to pointer to opaque {}", |
| 7112 | 7335 | \\const Derp = opaque {}; |
| 7113 | 7336 | \\extern fn bar(d: *Derp) void; |
| 7114 | 7337 | \\export fn foo() void { |
| ... | ... | @@ -7119,49 +7342,57 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7119 | 7342 | "tmp.zig:5:9: error: expected type '*Derp', found '*c_void'", |
| 7120 | 7343 | }); |
| 7121 | 7344 | |
| 7122 | | cases.add("non-const variables of things that require const variables", |
| 7345 | ctx.objErrStage1("non-const variables of things that require const variables", |
| 7123 | 7346 | \\export fn entry1() void { |
| 7124 | 7347 | \\ var m2 = &2; |
| 7348 | \\ _ = m2; |
| 7125 | 7349 | \\} |
| 7126 | 7350 | \\export fn entry2() void { |
| 7127 | 7351 | \\ var a = undefined; |
| 7352 | \\ _ = a; |
| 7128 | 7353 | \\} |
| 7129 | 7354 | \\export fn entry3() void { |
| 7130 | 7355 | \\ var b = 1; |
| 7356 | \\ _ = b; |
| 7131 | 7357 | \\} |
| 7132 | 7358 | \\export fn entry4() void { |
| 7133 | 7359 | \\ var c = 1.0; |
| 7360 | \\ _ = c; |
| 7134 | 7361 | \\} |
| 7135 | 7362 | \\export fn entry5() void { |
| 7136 | 7363 | \\ var d = null; |
| 7364 | \\ _ = d; |
| 7137 | 7365 | \\} |
| 7138 | 7366 | \\export fn entry6(opaque_: *Opaque) void { |
| 7139 | 7367 | \\ var e = opaque_.*; |
| 7368 | \\ _ = e; |
| 7140 | 7369 | \\} |
| 7141 | 7370 | \\export fn entry7() void { |
| 7142 | 7371 | \\ var f = i32; |
| 7372 | \\ _ = f; |
| 7143 | 7373 | \\} |
| 7144 | 7374 | \\export fn entry8() void { |
| 7145 | 7375 | \\ var h = (Foo {}).bar; |
| 7376 | \\ _ = h; |
| 7146 | 7377 | \\} |
| 7147 | 7378 | \\const Opaque = opaque {}; |
| 7148 | 7379 | \\const Foo = struct { |
| 7149 | | \\ fn bar(self: *const Foo) void {} |
| 7380 | \\ fn bar(self: *const Foo) void {_ = self;} |
| 7150 | 7381 | \\}; |
| 7151 | 7382 | , &[_][]const u8{ |
| 7152 | 7383 | "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 | | }); |
| 7163 | | |
| 7164 | | cases.add("variable with type 'noreturn'", |
| 7384 | "tmp.zig:6:4: error: variable of type '(undefined)' must be const or comptime", |
| 7385 | "tmp.zig:10:4: error: variable of type 'comptime_int' must be const or comptime", |
| 7386 | "tmp.zig:10:4: note: to modify this variable at runtime, it must be given an explicit fixed-size number type", |
| 7387 | "tmp.zig:14:4: error: variable of type 'comptime_float' must be const or comptime", |
| 7388 | "tmp.zig:14:4: note: to modify this variable at runtime, it must be given an explicit fixed-size number type", |
| 7389 | "tmp.zig:18:4: error: variable of type '(null)' must be const or comptime", |
| 7390 | "tmp.zig:22:4: error: variable of type 'Opaque' not allowed", |
| 7391 | "tmp.zig:26:4: error: variable of type 'type' must be const or comptime", |
| 7392 | "tmp.zig:30:4: error: variable of type '(bound fn(*const Foo) void)' must be const or comptime", |
| 7393 | }); |
| 7394 | |
| 7395 | ctx.objErrStage1("variable with type 'noreturn'", |
| 7165 | 7396 | \\export fn entry9() void { |
| 7166 | 7397 | \\ var z: noreturn = return; |
| 7167 | 7398 | \\} |
| ... | ... | @@ -7170,7 +7401,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7170 | 7401 | "tmp.zig:2:23: note: control flow is diverted here", |
| 7171 | 7402 | }); |
| 7172 | 7403 | |
| 7173 | | cases.add("wrong types given to atomic order args in cmpxchg", |
| 7404 | ctx.objErrStage1("wrong types given to atomic order args in cmpxchg", |
| 7174 | 7405 | \\export fn entry() void { |
| 7175 | 7406 | \\ var x: i32 = 1234; |
| 7176 | 7407 | \\ while (!@cmpxchgWeak(i32, &x, 1234, 5678, @as(u32, 1234), @as(u32, 1234))) {} |
| ... | ... | @@ -7179,7 +7410,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7179 | 7410 | "tmp.zig:3:47: error: expected type 'std.builtin.AtomicOrder', found 'u32'", |
| 7180 | 7411 | }); |
| 7181 | 7412 | |
| 7182 | | cases.add("wrong types given to @export", |
| 7413 | ctx.objErrStage1("wrong types given to @export", |
| 7183 | 7414 | \\fn entry() callconv(.C) void { } |
| 7184 | 7415 | \\comptime { |
| 7185 | 7416 | \\ @export(entry, .{.name = "entry", .linkage = @as(u32, 1234) }); |
| ... | ... | @@ -7188,7 +7419,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7188 | 7419 | "tmp.zig:3:59: error: expected type 'std.builtin.GlobalLinkage', found 'comptime_int'", |
| 7189 | 7420 | }); |
| 7190 | 7421 | |
| 7191 | | cases.add("struct with invalid field", |
| 7422 | ctx.objErrStage1("struct with invalid field", |
| 7192 | 7423 | \\const std = @import("std",); |
| 7193 | 7424 | \\const Allocator = std.mem.Allocator; |
| 7194 | 7425 | \\const ArrayList = std.ArrayList; |
| ... | ... | @@ -7211,12 +7442,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7211 | 7442 | \\ .text = MdText.init(&std.testing.allocator), |
| 7212 | 7443 | \\ .weight = HeaderWeight.H1, |
| 7213 | 7444 | \\ }; |
| 7445 | \\ _ = a; |
| 7214 | 7446 | \\} |
| 7215 | 7447 | , &[_][]const u8{ |
| 7216 | 7448 | "tmp.zig:14:17: error: use of undeclared identifier 'HeaderValue'", |
| 7217 | 7449 | }); |
| 7218 | 7450 | |
| 7219 | | cases.add("@setAlignStack outside function", |
| 7451 | ctx.objErrStage1("@setAlignStack outside function", |
| 7220 | 7452 | \\comptime { |
| 7221 | 7453 | \\ @setAlignStack(16); |
| 7222 | 7454 | \\} |
| ... | ... | @@ -7224,7 +7456,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7224 | 7456 | "tmp.zig:2:5: error: @setAlignStack outside function", |
| 7225 | 7457 | }); |
| 7226 | 7458 | |
| 7227 | | cases.add("@setAlignStack in naked function", |
| 7459 | ctx.objErrStage1("@setAlignStack in naked function", |
| 7228 | 7460 | \\export fn entry() callconv(.Naked) void { |
| 7229 | 7461 | \\ @setAlignStack(16); |
| 7230 | 7462 | \\} |
| ... | ... | @@ -7232,7 +7464,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7232 | 7464 | "tmp.zig:2:5: error: @setAlignStack in naked function", |
| 7233 | 7465 | }); |
| 7234 | 7466 | |
| 7235 | | cases.add("@setAlignStack in inline function", |
| 7467 | ctx.objErrStage1("@setAlignStack in inline function", |
| 7236 | 7468 | \\export fn entry() void { |
| 7237 | 7469 | \\ foo(); |
| 7238 | 7470 | \\} |
| ... | ... | @@ -7243,7 +7475,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7243 | 7475 | "tmp.zig:5:5: error: @setAlignStack in inline function", |
| 7244 | 7476 | }); |
| 7245 | 7477 | |
| 7246 | | cases.add("@setAlignStack set twice", |
| 7478 | ctx.objErrStage1("@setAlignStack set twice", |
| 7247 | 7479 | \\export fn entry() void { |
| 7248 | 7480 | \\ @setAlignStack(16); |
| 7249 | 7481 | \\ @setAlignStack(16); |
| ... | ... | @@ -7253,7 +7485,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7253 | 7485 | "tmp.zig:2:5: note: first set here", |
| 7254 | 7486 | }); |
| 7255 | 7487 | |
| 7256 | | cases.add("@setAlignStack too big", |
| 7488 | ctx.objErrStage1("@setAlignStack too big", |
| 7257 | 7489 | \\export fn entry() void { |
| 7258 | 7490 | \\ @setAlignStack(511 + 1); |
| 7259 | 7491 | \\} |
| ... | ... | @@ -7261,7 +7493,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7261 | 7493 | "tmp.zig:2:5: error: attempt to @setAlignStack(512); maximum is 256", |
| 7262 | 7494 | }); |
| 7263 | 7495 | |
| 7264 | | cases.add("storing runtime value in compile time variable then using it", |
| 7496 | ctx.objErrStage1("storing runtime value in compile time variable then using it", |
| 7265 | 7497 | \\const Mode = @import("std").builtin.Mode; |
| 7266 | 7498 | \\ |
| 7267 | 7499 | \\fn Free(comptime filename: []const u8) TestCase { |
| ... | ... | @@ -7307,7 +7539,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7307 | 7539 | "tmp.zig:37:29: error: cannot store runtime value in compile time variable", |
| 7308 | 7540 | }); |
| 7309 | 7541 | |
| 7310 | | cases.add("invalid legacy unicode escape", |
| 7542 | ctx.objErrStage1("invalid legacy unicode escape", |
| 7311 | 7543 | \\export fn entry() void { |
| 7312 | 7544 | \\ const a = '\U1234'; |
| 7313 | 7545 | \\} |
| ... | ... | @@ -7315,7 +7547,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7315 | 7547 | "tmp.zig:2:17: error: invalid character: 'U'", |
| 7316 | 7548 | }); |
| 7317 | 7549 | |
| 7318 | | cases.add("invalid empty unicode escape", |
| 7550 | ctx.objErrStage1("invalid empty unicode escape", |
| 7319 | 7551 | \\export fn entry() void { |
| 7320 | 7552 | \\ const a = '\u{}'; |
| 7321 | 7553 | \\} |
| ... | ... | @@ -7323,21 +7555,20 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7323 | 7555 | "tmp.zig:2:19: error: empty unicode escape sequence", |
| 7324 | 7556 | }); |
| 7325 | 7557 | |
| 7326 | | cases.add("non-printable invalid character", "\xff\xfe" ++ |
| 7327 | | \\fn test() bool {\r |
| 7328 | | \\ true\r |
| 7329 | | \\} |
| 7330 | | , &[_][]const u8{ |
| 7558 | ctx.objErrStage1("non-printable invalid character", "\xff\xfe" ++ |
| 7559 | "fn foo() bool {\r\n" ++ |
| 7560 | " return true;\r\n" ++ |
| 7561 | "}\r\n", &[_][]const u8{ |
| 7331 | 7562 | "tmp.zig:1:1: error: invalid character: '\\xff'", |
| 7332 | 7563 | }); |
| 7333 | 7564 | |
| 7334 | | cases.add("non-printable invalid character with escape alternative", "fn test() bool {\n" ++ |
| 7335 | | "\ttrue\n" ++ |
| 7565 | ctx.objErrStage1("non-printable invalid character with escape alternative", "fn foo() bool {\n" ++ |
| 7566 | "\treturn true;\n" ++ |
| 7336 | 7567 | "}\n", &[_][]const u8{ |
| 7337 | 7568 | "tmp.zig:2:1: error: invalid character: '\\t'", |
| 7338 | 7569 | }); |
| 7339 | 7570 | |
| 7340 | | cases.add("calling var args extern function, passing array instead of pointer", |
| 7571 | ctx.objErrStage1("calling var args extern function, passing array instead of pointer", |
| 7341 | 7572 | \\export fn entry() void { |
| 7342 | 7573 | \\ foo("hello".*,); |
| 7343 | 7574 | \\} |
| ... | ... | @@ -7346,7 +7577,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7346 | 7577 | "tmp.zig:2:16: error: expected type '*const u8', found '[5:0]u8'", |
| 7347 | 7578 | }); |
| 7348 | 7579 | |
| 7349 | | cases.add("constant inside comptime function has compile error", |
| 7580 | ctx.objErrStage1("constant inside comptime function has compile error", |
| 7350 | 7581 | \\const ContextAllocator = MemoryPool(usize); |
| 7351 | 7582 | \\ |
| 7352 | 7583 | \\pub fn MemoryPool(comptime T: type) type { |
| ... | ... | @@ -7361,12 +7592,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7361 | 7592 | \\ var allocator: ContextAllocator = undefined; |
| 7362 | 7593 | \\} |
| 7363 | 7594 | , &[_][]const u8{ |
| 7364 | | "tmp.zig:4:25: error: aoeu", |
| 7365 | | "tmp.zig:1:36: note: referenced here", |
| 7366 | | "tmp.zig:12:20: note: referenced here", |
| 7595 | "tmp.zig:4:5: error: unreachable code", |
| 7596 | "tmp.zig:4:25: note: control flow is diverted here", |
| 7597 | "tmp.zig:12:9: error: unused local variable", |
| 7367 | 7598 | }); |
| 7368 | 7599 | |
| 7369 | | cases.add("specify enum tag type that is too small", |
| 7600 | ctx.objErrStage1("specify enum tag type that is too small", |
| 7370 | 7601 | \\const Small = enum (u2) { |
| 7371 | 7602 | \\ One, |
| 7372 | 7603 | \\ Two, |
| ... | ... | @@ -7377,12 +7608,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7377 | 7608 | \\ |
| 7378 | 7609 | \\export fn entry() void { |
| 7379 | 7610 | \\ var x = Small.One; |
| 7611 | \\ _ = x; |
| 7380 | 7612 | \\} |
| 7381 | 7613 | , &[_][]const u8{ |
| 7382 | 7614 | "tmp.zig:6:5: error: enumeration value 4 too large for type 'u2'", |
| 7383 | 7615 | }); |
| 7384 | 7616 | |
| 7385 | | cases.add("specify non-integer enum tag type", |
| 7617 | ctx.objErrStage1("specify non-integer enum tag type", |
| 7386 | 7618 | \\const Small = enum (f32) { |
| 7387 | 7619 | \\ One, |
| 7388 | 7620 | \\ Two, |
| ... | ... | @@ -7391,12 +7623,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7391 | 7623 | \\ |
| 7392 | 7624 | \\export fn entry() void { |
| 7393 | 7625 | \\ var x = Small.One; |
| 7626 | \\ _ = x; |
| 7394 | 7627 | \\} |
| 7395 | 7628 | , &[_][]const u8{ |
| 7396 | 7629 | "tmp.zig:1:21: error: expected integer, found 'f32'", |
| 7397 | 7630 | }); |
| 7398 | 7631 | |
| 7399 | | cases.add("implicitly casting enum to tag type", |
| 7632 | ctx.objErrStage1("implicitly casting enum to tag type", |
| 7400 | 7633 | \\const Small = enum(u2) { |
| 7401 | 7634 | \\ One, |
| 7402 | 7635 | \\ Two, |
| ... | ... | @@ -7406,12 +7639,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7406 | 7639 | \\ |
| 7407 | 7640 | \\export fn entry() void { |
| 7408 | 7641 | \\ var x: u2 = Small.Two; |
| 7642 | \\ _ = x; |
| 7409 | 7643 | \\} |
| 7410 | 7644 | , &[_][]const u8{ |
| 7411 | 7645 | "tmp.zig:9:22: error: expected type 'u2', found 'Small'", |
| 7412 | 7646 | }); |
| 7413 | 7647 | |
| 7414 | | cases.add("explicitly casting non tag type to enum", |
| 7648 | ctx.objErrStage1("explicitly casting non tag type to enum", |
| 7415 | 7649 | \\const Small = enum(u2) { |
| 7416 | 7650 | \\ One, |
| 7417 | 7651 | \\ Two, |
| ... | ... | @@ -7422,24 +7656,26 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7422 | 7656 | \\export fn entry() void { |
| 7423 | 7657 | \\ var y = @as(u3, 3); |
| 7424 | 7658 | \\ var x = @intToEnum(Small, y); |
| 7659 | \\ _ = x; |
| 7425 | 7660 | \\} |
| 7426 | 7661 | , &[_][]const u8{ |
| 7427 | 7662 | "tmp.zig:10:31: error: expected type 'u2', found 'u3'", |
| 7428 | 7663 | }); |
| 7429 | 7664 | |
| 7430 | | cases.add("union fields with value assignments", |
| 7665 | ctx.objErrStage1("union fields with value assignments", |
| 7431 | 7666 | \\const MultipleChoice = union { |
| 7432 | 7667 | \\ A: i32 = 20, |
| 7433 | 7668 | \\}; |
| 7434 | 7669 | \\export fn entry() void { |
| 7435 | 7670 | \\ var x: MultipleChoice = undefined; |
| 7671 | \\ _ = x; |
| 7436 | 7672 | \\} |
| 7437 | 7673 | , &[_][]const u8{ |
| 7438 | 7674 | "tmp.zig:2:14: error: untagged union field assignment", |
| 7439 | 7675 | "tmp.zig:1:24: note: consider 'union(enum)' here", |
| 7440 | 7676 | }); |
| 7441 | 7677 | |
| 7442 | | cases.add("enum with 0 fields", |
| 7678 | ctx.objErrStage1("enum with 0 fields", |
| 7443 | 7679 | \\const Foo = enum {}; |
| 7444 | 7680 | \\export fn entry() usize { |
| 7445 | 7681 | \\ return @sizeOf(Foo); |
| ... | ... | @@ -7448,16 +7684,16 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7448 | 7684 | "tmp.zig:1:13: error: enums must have 1 or more fields", |
| 7449 | 7685 | }); |
| 7450 | 7686 | |
| 7451 | | cases.add("union with 0 fields", |
| 7687 | ctx.objErrStage1("union with 0 fields", |
| 7452 | 7688 | \\const Foo = union {}; |
| 7453 | 7689 | \\export fn entry() usize { |
| 7454 | 7690 | \\ return @sizeOf(Foo); |
| 7455 | 7691 | \\} |
| 7456 | 7692 | , &[_][]const u8{ |
| 7457 | | "tmp.zig:1:13: error: unions must have 1 or more fields", |
| 7693 | "tmp.zig:1:13: error: union declarations must have at least one tag", |
| 7458 | 7694 | }); |
| 7459 | 7695 | |
| 7460 | | cases.add("enum value already taken", |
| 7696 | ctx.objErrStage1("enum value already taken", |
| 7461 | 7697 | \\const MultipleChoice = enum(u32) { |
| 7462 | 7698 | \\ A = 20, |
| 7463 | 7699 | \\ B = 40, |
| ... | ... | @@ -7467,13 +7703,14 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7467 | 7703 | \\}; |
| 7468 | 7704 | \\export fn entry() void { |
| 7469 | 7705 | \\ var x = MultipleChoice.C; |
| 7706 | \\ _ = x; |
| 7470 | 7707 | \\} |
| 7471 | 7708 | , &[_][]const u8{ |
| 7472 | 7709 | "tmp.zig:6:5: error: enum tag value 60 already taken", |
| 7473 | 7710 | "tmp.zig:4:5: note: other occurrence here", |
| 7474 | 7711 | }); |
| 7475 | 7712 | |
| 7476 | | cases.add("union with specified enum omits field", |
| 7713 | ctx.objErrStage1("union with specified enum omits field", |
| 7477 | 7714 | \\const Letter = enum { |
| 7478 | 7715 | \\ A, |
| 7479 | 7716 | \\ B, |
| ... | ... | @@ -7491,29 +7728,31 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7491 | 7728 | "tmp.zig:4:5: note: declared here", |
| 7492 | 7729 | }); |
| 7493 | 7730 | |
| 7494 | | cases.add("non-integer tag type to automatic union enum", |
| 7731 | ctx.objErrStage1("non-integer tag type to automatic union enum", |
| 7495 | 7732 | \\const Foo = union(enum(f32)) { |
| 7496 | 7733 | \\ A: i32, |
| 7497 | 7734 | \\}; |
| 7498 | 7735 | \\export fn entry() void { |
| 7499 | 7736 | \\ const x = @typeInfo(Foo).Union.tag_type.?; |
| 7737 | \\ _ = x; |
| 7500 | 7738 | \\} |
| 7501 | 7739 | , &[_][]const u8{ |
| 7502 | 7740 | "tmp.zig:1:24: error: expected integer tag type, found 'f32'", |
| 7503 | 7741 | }); |
| 7504 | 7742 | |
| 7505 | | cases.add("non-enum tag type passed to union", |
| 7743 | ctx.objErrStage1("non-enum tag type passed to union", |
| 7506 | 7744 | \\const Foo = union(u32) { |
| 7507 | 7745 | \\ A: i32, |
| 7508 | 7746 | \\}; |
| 7509 | 7747 | \\export fn entry() void { |
| 7510 | 7748 | \\ const x = @typeInfo(Foo).Union.tag_type.?; |
| 7749 | \\ _ = x; |
| 7511 | 7750 | \\} |
| 7512 | 7751 | , &[_][]const u8{ |
| 7513 | 7752 | "tmp.zig:1:19: error: expected enum tag type, found 'u32'", |
| 7514 | 7753 | }); |
| 7515 | 7754 | |
| 7516 | | cases.add("union auto-enum value already taken", |
| 7755 | ctx.objErrStage1("union auto-enum value already taken", |
| 7517 | 7756 | \\const MultipleChoice = union(enum(u32)) { |
| 7518 | 7757 | \\ A = 20, |
| 7519 | 7758 | \\ B = 40, |
| ... | ... | @@ -7523,13 +7762,14 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7523 | 7762 | \\}; |
| 7524 | 7763 | \\export fn entry() void { |
| 7525 | 7764 | \\ var x = MultipleChoice { .C = {} }; |
| 7765 | \\ _ = x; |
| 7526 | 7766 | \\} |
| 7527 | 7767 | , &[_][]const u8{ |
| 7528 | 7768 | "tmp.zig:6:9: error: enum tag value 60 already taken", |
| 7529 | 7769 | "tmp.zig:4:9: note: other occurrence here", |
| 7530 | 7770 | }); |
| 7531 | 7771 | |
| 7532 | | cases.add("union enum field does not match enum", |
| 7772 | ctx.objErrStage1("union enum field does not match enum", |
| 7533 | 7773 | \\const Letter = enum { |
| 7534 | 7774 | \\ A, |
| 7535 | 7775 | \\ B, |
| ... | ... | @@ -7543,13 +7783,14 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7543 | 7783 | \\}; |
| 7544 | 7784 | \\export fn entry() void { |
| 7545 | 7785 | \\ var a = Payload {.A = 1234}; |
| 7786 | \\ _ = a; |
| 7546 | 7787 | \\} |
| 7547 | 7788 | , &[_][]const u8{ |
| 7548 | 7789 | "tmp.zig:10:5: error: enum field not found: 'D'", |
| 7549 | 7790 | "tmp.zig:1:16: note: enum declared here", |
| 7550 | 7791 | }); |
| 7551 | 7792 | |
| 7552 | | cases.add("field type supplied in an enum", |
| 7793 | ctx.objErrStage1("field type supplied in an enum", |
| 7553 | 7794 | \\const Letter = enum { |
| 7554 | 7795 | \\ A: void, |
| 7555 | 7796 | \\ B, |
| ... | ... | @@ -7557,35 +7798,38 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7557 | 7798 | \\}; |
| 7558 | 7799 | \\export fn entry() void { |
| 7559 | 7800 | \\ var b = Letter.B; |
| 7801 | \\ _ = b; |
| 7560 | 7802 | \\} |
| 7561 | 7803 | , &[_][]const u8{ |
| 7562 | 7804 | "tmp.zig:2:8: error: structs and unions, not enums, support field types", |
| 7563 | 7805 | "tmp.zig:1:16: note: consider 'union(enum)' here", |
| 7564 | 7806 | }); |
| 7565 | 7807 | |
| 7566 | | cases.add("struct field missing type", |
| 7808 | ctx.objErrStage1("struct field missing type", |
| 7567 | 7809 | \\const Letter = struct { |
| 7568 | 7810 | \\ A, |
| 7569 | 7811 | \\}; |
| 7570 | 7812 | \\export fn entry() void { |
| 7571 | 7813 | \\ var a = Letter { .A = {} }; |
| 7814 | \\ _ = a; |
| 7572 | 7815 | \\} |
| 7573 | 7816 | , &[_][]const u8{ |
| 7574 | 7817 | "tmp.zig:2:5: error: struct field missing type", |
| 7575 | 7818 | }); |
| 7576 | 7819 | |
| 7577 | | cases.add("extern union field missing type", |
| 7820 | ctx.objErrStage1("extern union field missing type", |
| 7578 | 7821 | \\const Letter = extern union { |
| 7579 | 7822 | \\ A, |
| 7580 | 7823 | \\}; |
| 7581 | 7824 | \\export fn entry() void { |
| 7582 | 7825 | \\ var a = Letter { .A = {} }; |
| 7826 | \\ _ = a; |
| 7583 | 7827 | \\} |
| 7584 | 7828 | , &[_][]const u8{ |
| 7585 | 7829 | "tmp.zig:2:5: error: union field missing type", |
| 7586 | 7830 | }); |
| 7587 | 7831 | |
| 7588 | | cases.add("extern union given enum tag type", |
| 7832 | ctx.objErrStage1("extern union given enum tag type", |
| 7589 | 7833 | \\const Letter = enum { |
| 7590 | 7834 | \\ A, |
| 7591 | 7835 | \\ B, |
| ... | ... | @@ -7598,12 +7842,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7598 | 7842 | \\}; |
| 7599 | 7843 | \\export fn entry() void { |
| 7600 | 7844 | \\ var a = Payload { .A = 1234 }; |
| 7845 | \\ _ = a; |
| 7601 | 7846 | \\} |
| 7602 | 7847 | , &[_][]const u8{ |
| 7603 | 7848 | "tmp.zig:6:30: error: extern union does not support enum tag type", |
| 7604 | 7849 | }); |
| 7605 | 7850 | |
| 7606 | | cases.add("packed union given enum tag type", |
| 7851 | ctx.objErrStage1("packed union given enum tag type", |
| 7607 | 7852 | \\const Letter = enum { |
| 7608 | 7853 | \\ A, |
| 7609 | 7854 | \\ B, |
| ... | ... | @@ -7616,12 +7861,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7616 | 7861 | \\}; |
| 7617 | 7862 | \\export fn entry() void { |
| 7618 | 7863 | \\ var a = Payload { .A = 1234 }; |
| 7864 | \\ _ = a; |
| 7619 | 7865 | \\} |
| 7620 | 7866 | , &[_][]const u8{ |
| 7621 | 7867 | "tmp.zig:6:30: error: packed union does not support enum tag type", |
| 7622 | 7868 | }); |
| 7623 | 7869 | |
| 7624 | | cases.add("packed union with automatic layout field", |
| 7870 | ctx.objErrStage1("packed union with automatic layout field", |
| 7625 | 7871 | \\const Foo = struct { |
| 7626 | 7872 | \\ a: u32, |
| 7627 | 7873 | \\ b: f32, |
| ... | ... | @@ -7632,12 +7878,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7632 | 7878 | \\}; |
| 7633 | 7879 | \\export fn entry() void { |
| 7634 | 7880 | \\ var a = Payload { .B = true }; |
| 7881 | \\ _ = a; |
| 7635 | 7882 | \\} |
| 7636 | 7883 | , &[_][]const u8{ |
| 7637 | 7884 | "tmp.zig:6:5: error: non-packed, non-extern struct 'Foo' not allowed in packed union; no guaranteed in-memory representation", |
| 7638 | 7885 | }); |
| 7639 | 7886 | |
| 7640 | | cases.add("switch on union with no attached enum", |
| 7887 | ctx.objErrStage1("switch on union with no attached enum", |
| 7641 | 7888 | \\const Payload = union { |
| 7642 | 7889 | \\ A: i32, |
| 7643 | 7890 | \\ B: f64, |
| ... | ... | @@ -7658,20 +7905,21 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7658 | 7905 | "tmp.zig:1:17: note: consider 'union(enum)' here", |
| 7659 | 7906 | }); |
| 7660 | 7907 | |
| 7661 | | cases.add("enum in field count range but not matching tag", |
| 7908 | ctx.objErrStage1("enum in field count range but not matching tag", |
| 7662 | 7909 | \\const Foo = enum(u32) { |
| 7663 | 7910 | \\ A = 10, |
| 7664 | 7911 | \\ B = 11, |
| 7665 | 7912 | \\}; |
| 7666 | 7913 | \\export fn entry() void { |
| 7667 | 7914 | \\ var x = @intToEnum(Foo, 0); |
| 7915 | \\ _ = x; |
| 7668 | 7916 | \\} |
| 7669 | 7917 | , &[_][]const u8{ |
| 7670 | 7918 | "tmp.zig:6:13: error: enum 'Foo' has no tag matching integer value 0", |
| 7671 | 7919 | "tmp.zig:1:13: note: 'Foo' declared here", |
| 7672 | 7920 | }); |
| 7673 | 7921 | |
| 7674 | | cases.add("comptime cast enum to union but field has payload", |
| 7922 | ctx.objErrStage1("comptime cast enum to union but field has payload", |
| 7675 | 7923 | \\const Letter = enum { A, B, C }; |
| 7676 | 7924 | \\const Value = union(Letter) { |
| 7677 | 7925 | \\ A: i32, |
| ... | ... | @@ -7680,13 +7928,14 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7680 | 7928 | \\}; |
| 7681 | 7929 | \\export fn entry() void { |
| 7682 | 7930 | \\ var x: Value = Letter.A; |
| 7931 | \\ _ = x; |
| 7683 | 7932 | \\} |
| 7684 | 7933 | , &[_][]const u8{ |
| 7685 | 7934 | "tmp.zig:8:26: error: cast to union 'Value' must initialize 'i32' field 'A'", |
| 7686 | 7935 | "tmp.zig:3:5: note: field 'A' declared here", |
| 7687 | 7936 | }); |
| 7688 | 7937 | |
| 7689 | | cases.add("runtime cast to union which has non-void fields", |
| 7938 | ctx.objErrStage1("runtime cast to union which has non-void fields", |
| 7690 | 7939 | \\const Letter = enum { A, B, C }; |
| 7691 | 7940 | \\const Value = union(Letter) { |
| 7692 | 7941 | \\ A: i32, |
| ... | ... | @@ -7698,13 +7947,14 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7698 | 7947 | \\} |
| 7699 | 7948 | \\fn foo(l: Letter) void { |
| 7700 | 7949 | \\ var x: Value = l; |
| 7950 | \\ _ = x; |
| 7701 | 7951 | \\} |
| 7702 | 7952 | , &[_][]const u8{ |
| 7703 | 7953 | "tmp.zig:11:20: error: runtime cast to union 'Value' which has non-void fields", |
| 7704 | 7954 | "tmp.zig:3:5: note: field 'A' has type 'i32'", |
| 7705 | 7955 | }); |
| 7706 | 7956 | |
| 7707 | | cases.add("taking byte offset of void field in struct", |
| 7957 | ctx.objErrStage1("taking byte offset of void field in struct", |
| 7708 | 7958 | \\const Empty = struct { |
| 7709 | 7959 | \\ val: void, |
| 7710 | 7960 | \\}; |
| ... | ... | @@ -7715,7 +7965,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7715 | 7965 | "tmp.zig:5:42: error: zero-bit field 'val' in struct 'Empty' has no offset", |
| 7716 | 7966 | }); |
| 7717 | 7967 | |
| 7718 | | cases.add("taking bit offset of void field in struct", |
| 7968 | ctx.objErrStage1("taking bit offset of void field in struct", |
| 7719 | 7969 | \\const Empty = struct { |
| 7720 | 7970 | \\ val: void, |
| 7721 | 7971 | \\}; |
| ... | ... | @@ -7726,7 +7976,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7726 | 7976 | "tmp.zig:5:45: error: zero-bit field 'val' in struct 'Empty' has no offset", |
| 7727 | 7977 | }); |
| 7728 | 7978 | |
| 7729 | | cases.add("invalid union field access in comptime", |
| 7979 | ctx.objErrStage1("invalid union field access in comptime", |
| 7730 | 7980 | \\const Foo = union { |
| 7731 | 7981 | \\ Bar: u8, |
| 7732 | 7982 | \\ Baz: void, |
| ... | ... | @@ -7739,7 +7989,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7739 | 7989 | "tmp.zig:7:24: error: accessing union field 'Bar' while field 'Baz' is set", |
| 7740 | 7990 | }); |
| 7741 | 7991 | |
| 7742 | | cases.add("unsupported modifier at start of asm output constraint", |
| 7992 | ctx.objErrStage1("unsupported modifier at start of asm output constraint", |
| 7743 | 7993 | \\export fn foo() void { |
| 7744 | 7994 | \\ var bar: u32 = 3; |
| 7745 | 7995 | \\ asm volatile ("" : [baz]"+r"(bar) : : ""); |
| ... | ... | @@ -7748,7 +7998,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7748 | 7998 | "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", |
| 7749 | 7999 | }); |
| 7750 | 8000 | |
| 7751 | | cases.add("comptime_int in asm input", |
| 8001 | ctx.objErrStage1("comptime_int in asm input", |
| 7752 | 8002 | \\export fn foo() void { |
| 7753 | 8003 | \\ asm volatile ("" : : [bar]"r"(3) : ""); |
| 7754 | 8004 | \\} |
| ... | ... | @@ -7756,7 +8006,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7756 | 8006 | "tmp.zig:2:35: error: expected sized integer or sized float, found comptime_int", |
| 7757 | 8007 | }); |
| 7758 | 8008 | |
| 7759 | | cases.add("comptime_float in asm input", |
| 8009 | ctx.objErrStage1("comptime_float in asm input", |
| 7760 | 8010 | \\export fn foo() void { |
| 7761 | 8011 | \\ asm volatile ("" : : [bar]"r"(3.17) : ""); |
| 7762 | 8012 | \\} |
| ... | ... | @@ -7764,7 +8014,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7764 | 8014 | "tmp.zig:2:35: error: expected sized integer or sized float, found comptime_float", |
| 7765 | 8015 | }); |
| 7766 | 8016 | |
| 7767 | | cases.add("runtime assignment to comptime struct type", |
| 8017 | ctx.objErrStage1("runtime assignment to comptime struct type", |
| 7768 | 8018 | \\const Foo = struct { |
| 7769 | 8019 | \\ Bar: u8, |
| 7770 | 8020 | \\ Baz: type, |
| ... | ... | @@ -7772,12 +8022,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7772 | 8022 | \\export fn f() void { |
| 7773 | 8023 | \\ var x: u8 = 0; |
| 7774 | 8024 | \\ const foo = Foo { .Bar = x, .Baz = u8 }; |
| 8025 | \\ _ = foo; |
| 7775 | 8026 | \\} |
| 7776 | 8027 | , &[_][]const u8{ |
| 7777 | 8028 | "tmp.zig:7:23: error: unable to evaluate constant expression", |
| 7778 | 8029 | }); |
| 7779 | 8030 | |
| 7780 | | cases.add("runtime assignment to comptime union type", |
| 8031 | ctx.objErrStage1("runtime assignment to comptime union type", |
| 7781 | 8032 | \\const Foo = union { |
| 7782 | 8033 | \\ Bar: u8, |
| 7783 | 8034 | \\ Baz: type, |
| ... | ... | @@ -7785,16 +8036,18 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7785 | 8036 | \\export fn f() void { |
| 7786 | 8037 | \\ var x: u8 = 0; |
| 7787 | 8038 | \\ const foo = Foo { .Bar = x }; |
| 8039 | \\ _ = foo; |
| 7788 | 8040 | \\} |
| 7789 | 8041 | , &[_][]const u8{ |
| 7790 | 8042 | "tmp.zig:7:23: error: unable to evaluate constant expression", |
| 7791 | 8043 | }); |
| 7792 | 8044 | |
| 7793 | | cases.addTest("@shuffle with selected index past first vector length", |
| 8045 | ctx.testErrStage1("@shuffle with selected index past first vector length", |
| 7794 | 8046 | \\export fn entry() void { |
| 7795 | 8047 | \\ const v: @import("std").meta.Vector(4, u32) = [4]u32{ 10, 11, 12, 13 }; |
| 7796 | 8048 | \\ const x: @import("std").meta.Vector(4, u32) = [4]u32{ 14, 15, 16, 17 }; |
| 7797 | 8049 | \\ var z = @shuffle(u32, v, x, [8]i32{ 0, 1, 2, 3, 7, 6, 5, 4 }); |
| 8050 | \\ _ = z; |
| 7798 | 8051 | \\} |
| 7799 | 8052 | , &[_][]const u8{ |
| 7800 | 8053 | "tmp.zig:4:39: error: mask index '4' has out-of-bounds selection", |
| ... | ... | @@ -7802,27 +8055,29 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7802 | 8055 | "tmp.zig:4:30: note: selections from the second vector are specified with negative numbers", |
| 7803 | 8056 | }); |
| 7804 | 8057 | |
| 7805 | | cases.addTest("nested vectors", |
| 8058 | ctx.testErrStage1("nested vectors", |
| 7806 | 8059 | \\export fn entry() void { |
| 7807 | 8060 | \\ const V1 = @import("std").meta.Vector(4, u8); |
| 7808 | 8061 | \\ const V2 = @Type(@import("std").builtin.TypeInfo{ .Vector = .{ .len = 4, .child = V1 } }); |
| 7809 | 8062 | \\ var v: V2 = undefined; |
| 8063 | \\ _ = v; |
| 7810 | 8064 | \\} |
| 7811 | 8065 | , &[_][]const u8{ |
| 7812 | 8066 | "tmp.zig:3:53: error: vector element type must be integer, float, bool, or pointer; '@Vector(4, u8)' is invalid", |
| 7813 | 8067 | "tmp.zig:3:16: note: referenced here", |
| 7814 | 8068 | }); |
| 7815 | 8069 | |
| 7816 | | cases.addTest("bad @splat type", |
| 8070 | ctx.testErrStage1("bad @splat type", |
| 7817 | 8071 | \\export fn entry() void { |
| 7818 | 8072 | \\ const c = 4; |
| 7819 | 8073 | \\ var v = @splat(4, c); |
| 8074 | \\ _ = v; |
| 7820 | 8075 | \\} |
| 7821 | 8076 | , &[_][]const u8{ |
| 7822 | 8077 | "tmp.zig:3:23: error: vector element type must be integer, float, bool, or pointer; 'comptime_int' is invalid", |
| 7823 | 8078 | }); |
| 7824 | 8079 | |
| 7825 | | cases.add("compileLog of tagged enum doesn't crash the compiler", |
| 8080 | ctx.objErrStage1("compileLog of tagged enum doesn't crash the compiler", |
| 7826 | 8081 | \\const Bar = union(enum(u32)) { |
| 7827 | 8082 | \\ X: i32 = 1 |
| 7828 | 8083 | \\}; |
| ... | ... | @@ -7838,7 +8093,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7838 | 8093 | "tmp.zig:6:5: error: found compile log statement", |
| 7839 | 8094 | }); |
| 7840 | 8095 | |
| 7841 | | cases.add("attempted implicit cast from *const T to *[1]T", |
| 8096 | ctx.objErrStage1("attempted implicit cast from *const T to *[1]T", |
| 7842 | 8097 | \\export fn entry(byte: u8) void { |
| 7843 | 8098 | \\ const w: i32 = 1234; |
| 7844 | 8099 | \\ var x: *const i32 = &w; |
| ... | ... | @@ -7850,16 +8105,17 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7850 | 8105 | "tmp.zig:4:22: note: cast discards const qualifier", |
| 7851 | 8106 | }); |
| 7852 | 8107 | |
| 7853 | | cases.add("attempted implicit cast from *const T to []T", |
| 8108 | ctx.objErrStage1("attempted implicit cast from *const T to []T", |
| 7854 | 8109 | \\export fn entry() void { |
| 7855 | 8110 | \\ const u: u32 = 42; |
| 7856 | 8111 | \\ const x: []u32 = &u; |
| 8112 | \\ _ = x; |
| 7857 | 8113 | \\} |
| 7858 | 8114 | , &[_][]const u8{ |
| 7859 | 8115 | "tmp.zig:3:23: error: expected type '[]u32', found '*const u32'", |
| 7860 | 8116 | }); |
| 7861 | 8117 | |
| 7862 | | cases.add("for loop body expression ignored", |
| 8118 | ctx.objErrStage1("for loop body expression ignored", |
| 7863 | 8119 | \\fn returns() usize { |
| 7864 | 8120 | \\ return 2; |
| 7865 | 8121 | \\} |
| ... | ... | @@ -7875,7 +8131,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7875 | 8131 | "tmp.zig:9:30: error: expression value is ignored", |
| 7876 | 8132 | }); |
| 7877 | 8133 | |
| 7878 | | cases.add("aligned variable of zero-bit type", |
| 8134 | ctx.objErrStage1("aligned variable of zero-bit type", |
| 7879 | 8135 | \\export fn f() void { |
| 7880 | 8136 | \\ var s: struct {} align(4) = undefined; |
| 7881 | 8137 | \\} |
| ... | ... | @@ -7883,7 +8139,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7883 | 8139 | "tmp.zig:2:5: error: variable 's' of zero-bit type 'struct:2:12' has no in-memory representation, it cannot be aligned", |
| 7884 | 8140 | }); |
| 7885 | 8141 | |
| 7886 | | cases.add("function returning opaque type", |
| 8142 | ctx.objErrStage1("function returning opaque type", |
| 7887 | 8143 | \\const FooType = opaque {}; |
| 7888 | 8144 | \\export fn bar() !FooType { |
| 7889 | 8145 | \\ return error.InvalidValue; |
| ... | ... | @@ -7901,7 +8157,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7901 | 8157 | "tmp.zig:8:18: error: Undefined return type '(undefined)' not allowed", |
| 7902 | 8158 | }); |
| 7903 | 8159 | |
| 7904 | | cases.add("generic function returning opaque type", |
| 8160 | ctx.objErrStage1("generic function returning opaque type", |
| 7905 | 8161 | \\const FooType = opaque {}; |
| 7906 | 8162 | \\fn generic(comptime T: type) !T { |
| 7907 | 8163 | \\ return undefined; |
| ... | ... | @@ -7925,22 +8181,24 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7925 | 8181 | "tmp.zig:2:1: note: function declared here", |
| 7926 | 8182 | }); |
| 7927 | 8183 | |
| 7928 | | cases.add("function parameter is opaque", |
| 8184 | ctx.objErrStage1("function parameter is opaque", |
| 7929 | 8185 | \\const FooType = opaque {}; |
| 7930 | 8186 | \\export fn entry1() void { |
| 7931 | 8187 | \\ const someFuncPtr: fn (FooType) void = undefined; |
| 8188 | \\ _ = someFuncPtr; |
| 7932 | 8189 | \\} |
| 7933 | 8190 | \\ |
| 7934 | 8191 | \\export fn entry2() void { |
| 7935 | 8192 | \\ const someFuncPtr: fn (@TypeOf(null)) void = undefined; |
| 8193 | \\ _ = someFuncPtr; |
| 7936 | 8194 | \\} |
| 7937 | 8195 | \\ |
| 7938 | | \\fn foo(p: FooType) void {} |
| 8196 | \\fn foo(p: FooType) void {_ = p;} |
| 7939 | 8197 | \\export fn entry3() void { |
| 7940 | 8198 | \\ _ = foo; |
| 7941 | 8199 | \\} |
| 7942 | 8200 | \\ |
| 7943 | | \\fn bar(p: @TypeOf(null)) void {} |
| 8201 | \\fn bar(p: @TypeOf(null)) void {_ = p;} |
| 7944 | 8202 | \\export fn entry4() void { |
| 7945 | 8203 | \\ _ = bar; |
| 7946 | 8204 | \\} |
| ... | ... | @@ -7951,30 +8209,34 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7951 | 8209 | "tmp.zig:15:11: error: parameter of type '(null)' not allowed", |
| 7952 | 8210 | }); |
| 7953 | 8211 | |
| 7954 | | cases.add( // fixed bug #2032 |
| 8212 | ctx.objErrStage1( // fixed bug #2032 |
| 7955 | 8213 | "compile diagnostic string for top level decl type", |
| 7956 | 8214 | \\export fn entry() void { |
| 7957 | 8215 | \\ var foo: u32 = @This(){}; |
| 8216 | \\ _ = foo; |
| 7958 | 8217 | \\} |
| 7959 | 8218 | , &[_][]const u8{ |
| 7960 | 8219 | "tmp.zig:2:27: error: type 'u32' does not support array initialization", |
| 7961 | 8220 | }); |
| 7962 | 8221 | |
| 7963 | | cases.add("issue #2687: coerce from undefined array pointer to slice", |
| 8222 | ctx.objErrStage1("issue #2687: coerce from undefined array pointer to slice", |
| 7964 | 8223 | \\export fn foo1() void { |
| 7965 | 8224 | \\ const a: *[1]u8 = undefined; |
| 7966 | 8225 | \\ var b: []u8 = a; |
| 8226 | \\ _ = b; |
| 7967 | 8227 | \\} |
| 7968 | 8228 | \\export fn foo2() void { |
| 7969 | 8229 | \\ comptime { |
| 7970 | 8230 | \\ var a: *[1]u8 = undefined; |
| 7971 | 8231 | \\ var b: []u8 = a; |
| 8232 | \\ _ = b; |
| 7972 | 8233 | \\ } |
| 7973 | 8234 | \\} |
| 7974 | 8235 | \\export fn foo3() void { |
| 7975 | 8236 | \\ comptime { |
| 7976 | 8237 | \\ const a: *[1]u8 = undefined; |
| 7977 | 8238 | \\ var b: []u8 = a; |
| 8239 | \\ _ = b; |
| 7978 | 8240 | \\ } |
| 7979 | 8241 | \\} |
| 7980 | 8242 | , &[_][]const u8{ |
| ... | ... | @@ -7983,14 +8245,16 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7983 | 8245 | "tmp.zig:14:23: error: use of undefined value here causes undefined behavior", |
| 7984 | 8246 | }); |
| 7985 | 8247 | |
| 7986 | | cases.add("issue #3818: bitcast from parray/slice to u16", |
| 8248 | ctx.objErrStage1("issue #3818: bitcast from parray/slice to u16", |
| 7987 | 8249 | \\export fn foo1() void { |
| 7988 | 8250 | \\ var bytes = [_]u8{1, 2}; |
| 7989 | 8251 | \\ const word: u16 = @bitCast(u16, bytes[0..]); |
| 8252 | \\ _ = word; |
| 7990 | 8253 | \\} |
| 7991 | 8254 | \\export fn foo2() void { |
| 7992 | 8255 | \\ var bytes: []const u8 = &[_]u8{1, 2}; |
| 7993 | 8256 | \\ const word: u16 = @bitCast(u16, bytes); |
| 8257 | \\ _ = word; |
| 7994 | 8258 | \\} |
| 7995 | 8259 | , &[_][]const u8{ |
| 7996 | 8260 | "tmp.zig:3:42: error: unable to @bitCast from pointer type '*[2]u8'", |
| ... | ... | @@ -7999,7 +8263,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7999 | 8263 | }); |
| 8000 | 8264 | |
| 8001 | 8265 | // issue #7810 |
| 8002 | | cases.add("comptime slice-len increment beyond bounds", |
| 8266 | ctx.objErrStage1("comptime slice-len increment beyond bounds", |
| 8003 | 8267 | \\export fn foo_slice_len_increment_beyond_bounds() void { |
| 8004 | 8268 | \\ comptime { |
| 8005 | 8269 | \\ var buf_storage: [8]u8 = undefined; |
| ... | ... | @@ -8012,11 +8276,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 8012 | 8276 | ":6:12: error: out of bounds slice", |
| 8013 | 8277 | }); |
| 8014 | 8278 | |
| 8015 | | cases.add("comptime slice-sentinel is out of bounds (unterminated)", |
| 8279 | ctx.objErrStage1("comptime slice-sentinel is out of bounds (unterminated)", |
| 8016 | 8280 | \\export fn foo_array() void { |
| 8017 | 8281 | \\ comptime { |
| 8018 | 8282 | \\ var target = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; |
| 8019 | 8283 | \\ const slice = target[0..14 :0]; |
| 8284 | \\ _ = slice; |
| 8020 | 8285 | \\ } |
| 8021 | 8286 | \\} |
| 8022 | 8287 | \\export fn foo_ptr_array() void { |
| ... | ... | @@ -8024,6 +8289,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 8024 | 8289 | \\ var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; |
| 8025 | 8290 | \\ var target = &buf; |
| 8026 | 8291 | \\ const slice = target[0..14 :0]; |
| 8292 | \\ _ = slice; |
| 8027 | 8293 | \\ } |
| 8028 | 8294 | \\} |
| 8029 | 8295 | \\export fn foo_vector_ConstPtrSpecialBaseArray() void { |
| ... | ... | @@ -8031,6 +8297,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 8031 | 8297 | \\ var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; |
| 8032 | 8298 | \\ var target: [*]u8 = &buf; |
| 8033 | 8299 | \\ const slice = target[0..14 :0]; |
| 8300 | \\ _ = slice; |
| 8034 | 8301 | \\ } |
| 8035 | 8302 | \\} |
| 8036 | 8303 | \\export fn foo_vector_ConstPtrSpecialRef() void { |
| ... | ... | @@ -8038,6 +8305,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 8038 | 8305 | \\ var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; |
| 8039 | 8306 | \\ var target: [*]u8 = @ptrCast([*]u8, &buf); |
| 8040 | 8307 | \\ const slice = target[0..14 :0]; |
| 8308 | \\ _ = slice; |
| 8041 | 8309 | \\ } |
| 8042 | 8310 | \\} |
| 8043 | 8311 | \\export fn foo_cvector_ConstPtrSpecialBaseArray() void { |
| ... | ... | @@ -8045,6 +8313,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 8045 | 8313 | \\ var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; |
| 8046 | 8314 | \\ var target: [*c]u8 = &buf; |
| 8047 | 8315 | \\ const slice = target[0..14 :0]; |
| 8316 | \\ _ = slice; |
| 8048 | 8317 | \\ } |
| 8049 | 8318 | \\} |
| 8050 | 8319 | \\export fn foo_cvector_ConstPtrSpecialRef() void { |
| ... | ... | @@ -8052,6 +8321,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 8052 | 8321 | \\ var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; |
| 8053 | 8322 | \\ var target: [*c]u8 = @ptrCast([*c]u8, &buf); |
| 8054 | 8323 | \\ const slice = target[0..14 :0]; |
| 8324 | \\ _ = slice; |
| 8055 | 8325 | \\ } |
| 8056 | 8326 | \\} |
| 8057 | 8327 | \\export fn foo_slice() void { |
| ... | ... | @@ -8059,6 +8329,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 8059 | 8329 | \\ var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; |
| 8060 | 8330 | \\ var target: []u8 = &buf; |
| 8061 | 8331 | \\ const slice = target[0..14 :0]; |
| 8332 | \\ _ = slice; |
| 8062 | 8333 | \\ } |
| 8063 | 8334 | \\} |
| 8064 | 8335 | , &[_][]const u8{ |
| ... | ... | @@ -8071,11 +8342,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 8071 | 8342 | ":46:29: error: slice-sentinel is out of bounds", |
| 8072 | 8343 | }); |
| 8073 | 8344 | |
| 8074 | | cases.add("comptime slice-sentinel is out of bounds (terminated)", |
| 8345 | ctx.objErrStage1("comptime slice-sentinel is out of bounds (terminated)", |
| 8075 | 8346 | \\export fn foo_array() void { |
| 8076 | 8347 | \\ comptime { |
| 8077 | 8348 | \\ var target = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; |
| 8078 | 8349 | \\ const slice = target[0..15 :1]; |
| 8350 | \\ _ = slice; |
| 8079 | 8351 | \\ } |
| 8080 | 8352 | \\} |
| 8081 | 8353 | \\export fn foo_ptr_array() void { |
| ... | ... | @@ -8083,6 +8355,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 8083 | 8355 | \\ var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; |
| 8084 | 8356 | \\ var target = &buf; |
| 8085 | 8357 | \\ const slice = target[0..15 :0]; |
| 8358 | \\ _ = slice; |
| 8086 | 8359 | \\ } |
| 8087 | 8360 | \\} |
| 8088 | 8361 | \\export fn foo_vector_ConstPtrSpecialBaseArray() void { |
| ... | ... | @@ -8090,6 +8363,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 8090 | 8363 | \\ var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; |
| 8091 | 8364 | \\ var target: [*]u8 = &buf; |
| 8092 | 8365 | \\ const slice = target[0..15 :0]; |
| 8366 | \\ _ = slice; |
| 8093 | 8367 | \\ } |
| 8094 | 8368 | \\} |
| 8095 | 8369 | \\export fn foo_vector_ConstPtrSpecialRef() void { |
| ... | ... | @@ -8097,6 +8371,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 8097 | 8371 | \\ var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; |
| 8098 | 8372 | \\ var target: [*]u8 = @ptrCast([*]u8, &buf); |
| 8099 | 8373 | \\ const slice = target[0..15 :0]; |
| 8374 | \\ _ = slice; |
| 8100 | 8375 | \\ } |
| 8101 | 8376 | \\} |
| 8102 | 8377 | \\export fn foo_cvector_ConstPtrSpecialBaseArray() void { |
| ... | ... | @@ -8104,6 +8379,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 8104 | 8379 | \\ var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; |
| 8105 | 8380 | \\ var target: [*c]u8 = &buf; |
| 8106 | 8381 | \\ const slice = target[0..15 :0]; |
| 8382 | \\ _ = slice; |
| 8107 | 8383 | \\ } |
| 8108 | 8384 | \\} |
| 8109 | 8385 | \\export fn foo_cvector_ConstPtrSpecialRef() void { |
| ... | ... | @@ -8111,6 +8387,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 8111 | 8387 | \\ var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; |
| 8112 | 8388 | \\ var target: [*c]u8 = @ptrCast([*c]u8, &buf); |
| 8113 | 8389 | \\ const slice = target[0..15 :0]; |
| 8390 | \\ _ = slice; |
| 8114 | 8391 | \\ } |
| 8115 | 8392 | \\} |
| 8116 | 8393 | \\export fn foo_slice() void { |
| ... | ... | @@ -8118,6 +8395,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 8118 | 8395 | \\ var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; |
| 8119 | 8396 | \\ var target: []u8 = &buf; |
| 8120 | 8397 | \\ const slice = target[0..15 :0]; |
| 8398 | \\ _ = slice; |
| 8121 | 8399 | \\ } |
| 8122 | 8400 | \\} |
| 8123 | 8401 | , &[_][]const u8{ |
| ... | ... | @@ -8130,11 +8408,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 8130 | 8408 | ":46:29: error: out of bounds slice", |
| 8131 | 8409 | }); |
| 8132 | 8410 | |
| 8133 | | cases.add("comptime slice-sentinel does not match memory at target index (unterminated)", |
| 8411 | ctx.objErrStage1("comptime slice-sentinel does not match memory at target index (unterminated)", |
| 8134 | 8412 | \\export fn foo_array() void { |
| 8135 | 8413 | \\ comptime { |
| 8136 | 8414 | \\ var target = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; |
| 8137 | 8415 | \\ const slice = target[0..3 :0]; |
| 8416 | \\ _ = slice; |
| 8138 | 8417 | \\ } |
| 8139 | 8418 | \\} |
| 8140 | 8419 | \\export fn foo_ptr_array() void { |
| ... | ... | @@ -8142,6 +8421,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 8142 | 8421 | \\ var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; |
| 8143 | 8422 | \\ var target = &buf; |
| 8144 | 8423 | \\ const slice = target[0..3 :0]; |
| 8424 | \\ _ = slice; |
| 8145 | 8425 | \\ } |
| 8146 | 8426 | \\} |
| 8147 | 8427 | \\export fn foo_vector_ConstPtrSpecialBaseArray() void { |
| ... | ... | @@ -8149,6 +8429,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 8149 | 8429 | \\ var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; |
| 8150 | 8430 | \\ var target: [*]u8 = &buf; |
| 8151 | 8431 | \\ const slice = target[0..3 :0]; |
| 8432 | \\ _ = slice; |
| 8152 | 8433 | \\ } |
| 8153 | 8434 | \\} |
| 8154 | 8435 | \\export fn foo_vector_ConstPtrSpecialRef() void { |
| ... | ... | @@ -8156,6 +8437,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 8156 | 8437 | \\ var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; |
| 8157 | 8438 | \\ var target: [*]u8 = @ptrCast([*]u8, &buf); |
| 8158 | 8439 | \\ const slice = target[0..3 :0]; |
| 8440 | \\ _ = slice; |
| 8159 | 8441 | \\ } |
| 8160 | 8442 | \\} |
| 8161 | 8443 | \\export fn foo_cvector_ConstPtrSpecialBaseArray() void { |
| ... | ... | @@ -8163,6 +8445,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 8163 | 8445 | \\ var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; |
| 8164 | 8446 | \\ var target: [*c]u8 = &buf; |
| 8165 | 8447 | \\ const slice = target[0..3 :0]; |
| 8448 | \\ _ = slice; |
| 8166 | 8449 | \\ } |
| 8167 | 8450 | \\} |
| 8168 | 8451 | \\export fn foo_cvector_ConstPtrSpecialRef() void { |
| ... | ... | @@ -8170,6 +8453,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 8170 | 8453 | \\ var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; |
| 8171 | 8454 | \\ var target: [*c]u8 = @ptrCast([*c]u8, &buf); |
| 8172 | 8455 | \\ const slice = target[0..3 :0]; |
| 8456 | \\ _ = slice; |
| 8173 | 8457 | \\ } |
| 8174 | 8458 | \\} |
| 8175 | 8459 | \\export fn foo_slice() void { |
| ... | ... | @@ -8177,6 +8461,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 8177 | 8461 | \\ var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; |
| 8178 | 8462 | \\ var target: []u8 = &buf; |
| 8179 | 8463 | \\ const slice = target[0..3 :0]; |
| 8464 | \\ _ = slice; |
| 8180 | 8465 | \\ } |
| 8181 | 8466 | \\} |
| 8182 | 8467 | , &[_][]const u8{ |
| ... | ... | @@ -8189,11 +8474,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 8189 | 8474 | ":46:29: error: slice-sentinel does not match memory at target index", |
| 8190 | 8475 | }); |
| 8191 | 8476 | |
| 8192 | | cases.add("comptime slice-sentinel does not match memory at target index (terminated)", |
| 8477 | ctx.objErrStage1("comptime slice-sentinel does not match memory at target index (terminated)", |
| 8193 | 8478 | \\export fn foo_array() void { |
| 8194 | 8479 | \\ comptime { |
| 8195 | 8480 | \\ var target = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; |
| 8196 | 8481 | \\ const slice = target[0..3 :0]; |
| 8482 | \\ _ = slice; |
| 8197 | 8483 | \\ } |
| 8198 | 8484 | \\} |
| 8199 | 8485 | \\export fn foo_ptr_array() void { |
| ... | ... | @@ -8201,6 +8487,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 8201 | 8487 | \\ var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; |
| 8202 | 8488 | \\ var target = &buf; |
| 8203 | 8489 | \\ const slice = target[0..3 :0]; |
| 8490 | \\ _ = slice; |
| 8204 | 8491 | \\ } |
| 8205 | 8492 | \\} |
| 8206 | 8493 | \\export fn foo_vector_ConstPtrSpecialBaseArray() void { |
| ... | ... | @@ -8208,6 +8495,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 8208 | 8495 | \\ var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; |
| 8209 | 8496 | \\ var target: [*]u8 = &buf; |
| 8210 | 8497 | \\ const slice = target[0..3 :0]; |
| 8498 | \\ _ = slice; |
| 8211 | 8499 | \\ } |
| 8212 | 8500 | \\} |
| 8213 | 8501 | \\export fn foo_vector_ConstPtrSpecialRef() void { |
| ... | ... | @@ -8215,6 +8503,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 8215 | 8503 | \\ var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; |
| 8216 | 8504 | \\ var target: [*]u8 = @ptrCast([*]u8, &buf); |
| 8217 | 8505 | \\ const slice = target[0..3 :0]; |
| 8506 | \\ _ = slice; |
| 8218 | 8507 | \\ } |
| 8219 | 8508 | \\} |
| 8220 | 8509 | \\export fn foo_cvector_ConstPtrSpecialBaseArray() void { |
| ... | ... | @@ -8222,6 +8511,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 8222 | 8511 | \\ var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; |
| 8223 | 8512 | \\ var target: [*c]u8 = &buf; |
| 8224 | 8513 | \\ const slice = target[0..3 :0]; |
| 8514 | \\ _ = slice; |
| 8225 | 8515 | \\ } |
| 8226 | 8516 | \\} |
| 8227 | 8517 | \\export fn foo_cvector_ConstPtrSpecialRef() void { |
| ... | ... | @@ -8229,6 +8519,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 8229 | 8519 | \\ var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; |
| 8230 | 8520 | \\ var target: [*c]u8 = @ptrCast([*c]u8, &buf); |
| 8231 | 8521 | \\ const slice = target[0..3 :0]; |
| 8522 | \\ _ = slice; |
| 8232 | 8523 | \\ } |
| 8233 | 8524 | \\} |
| 8234 | 8525 | \\export fn foo_slice() void { |
| ... | ... | @@ -8236,6 +8527,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 8236 | 8527 | \\ var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; |
| 8237 | 8528 | \\ var target: []u8 = &buf; |
| 8238 | 8529 | \\ const slice = target[0..3 :0]; |
| 8530 | \\ _ = slice; |
| 8239 | 8531 | \\ } |
| 8240 | 8532 | \\} |
| 8241 | 8533 | , &[_][]const u8{ |
| ... | ... | @@ -8248,11 +8540,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 8248 | 8540 | ":46:29: error: slice-sentinel does not match memory at target index", |
| 8249 | 8541 | }); |
| 8250 | 8542 | |
| 8251 | | cases.add("comptime slice-sentinel does not match target-sentinel", |
| 8543 | ctx.objErrStage1("comptime slice-sentinel does not match target-sentinel", |
| 8252 | 8544 | \\export fn foo_array() void { |
| 8253 | 8545 | \\ comptime { |
| 8254 | 8546 | \\ var target = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; |
| 8255 | 8547 | \\ const slice = target[0..14 :255]; |
| 8548 | \\ _ = slice; |
| 8256 | 8549 | \\ } |
| 8257 | 8550 | \\} |
| 8258 | 8551 | \\export fn foo_ptr_array() void { |
| ... | ... | @@ -8260,6 +8553,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 8260 | 8553 | \\ var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; |
| 8261 | 8554 | \\ var target = &buf; |
| 8262 | 8555 | \\ const slice = target[0..14 :255]; |
| 8556 | \\ _ = slice; |
| 8263 | 8557 | \\ } |
| 8264 | 8558 | \\} |
| 8265 | 8559 | \\export fn foo_vector_ConstPtrSpecialBaseArray() void { |
| ... | ... | @@ -8267,6 +8561,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 8267 | 8561 | \\ var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; |
| 8268 | 8562 | \\ var target: [*]u8 = &buf; |
| 8269 | 8563 | \\ const slice = target[0..14 :255]; |
| 8564 | \\ _ = slice; |
| 8270 | 8565 | \\ } |
| 8271 | 8566 | \\} |
| 8272 | 8567 | \\export fn foo_vector_ConstPtrSpecialRef() void { |
| ... | ... | @@ -8274,6 +8569,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 8274 | 8569 | \\ var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; |
| 8275 | 8570 | \\ var target: [*]u8 = @ptrCast([*]u8, &buf); |
| 8276 | 8571 | \\ const slice = target[0..14 :255]; |
| 8572 | \\ _ = slice; |
| 8277 | 8573 | \\ } |
| 8278 | 8574 | \\} |
| 8279 | 8575 | \\export fn foo_cvector_ConstPtrSpecialBaseArray() void { |
| ... | ... | @@ -8281,6 +8577,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 8281 | 8577 | \\ var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; |
| 8282 | 8578 | \\ var target: [*c]u8 = &buf; |
| 8283 | 8579 | \\ const slice = target[0..14 :255]; |
| 8580 | \\ _ = slice; |
| 8284 | 8581 | \\ } |
| 8285 | 8582 | \\} |
| 8286 | 8583 | \\export fn foo_cvector_ConstPtrSpecialRef() void { |
| ... | ... | @@ -8288,6 +8585,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 8288 | 8585 | \\ var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; |
| 8289 | 8586 | \\ var target: [*c]u8 = @ptrCast([*c]u8, &buf); |
| 8290 | 8587 | \\ const slice = target[0..14 :255]; |
| 8588 | \\ _ = slice; |
| 8291 | 8589 | \\ } |
| 8292 | 8590 | \\} |
| 8293 | 8591 | \\export fn foo_slice() void { |
| ... | ... | @@ -8295,6 +8593,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 8295 | 8593 | \\ var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; |
| 8296 | 8594 | \\ var target: []u8 = &buf; |
| 8297 | 8595 | \\ const slice = target[0..14 :255]; |
| 8596 | \\ _ = slice; |
| 8298 | 8597 | \\ } |
| 8299 | 8598 | \\} |
| 8300 | 8599 | , &[_][]const u8{ |
| ... | ... | @@ -8307,7 +8606,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 8307 | 8606 | ":46:29: error: slice-sentinel does not match target-sentinel", |
| 8308 | 8607 | }); |
| 8309 | 8608 | |
| 8310 | | cases.add("issue #4207: coerce from non-terminated-slice to terminated-pointer", |
| 8609 | ctx.objErrStage1("issue #4207: coerce from non-terminated-slice to terminated-pointer", |
| 8311 | 8610 | \\export fn foo() [*:0]const u8 { |
| 8312 | 8611 | \\ var buffer: [64]u8 = undefined; |
| 8313 | 8612 | \\ return buffer[0..]; |
| ... | ... | @@ -8317,7 +8616,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 8317 | 8616 | ":3:18: note: destination pointer requires a terminating '0' sentinel", |
| 8318 | 8617 | }); |
| 8319 | 8618 | |
| 8320 | | cases.add("issue #5221: invalid struct init type referenced by @typeInfo and passed into function", |
| 8619 | ctx.objErrStage1("issue #5221: invalid struct init type referenced by @typeInfo and passed into function", |
| 8321 | 8620 | \\fn ignore(comptime param: anytype) void {} |
| 8322 | 8621 | \\ |
| 8323 | 8622 | \\export fn foo() void { |
| ... | ... | @@ -8331,7 +8630,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 8331 | 8630 | ":5:28: error: expected type '[]u8', found '*const [3:0]u8'", |
| 8332 | 8631 | }); |
| 8333 | 8632 | |
| 8334 | | cases.add("integer underflow error", |
| 8633 | ctx.objErrStage1("integer underflow error", |
| 8335 | 8634 | \\export fn entry() void { |
| 8336 | 8635 | \\ _ = @intToPtr(*c_void, ~@as(usize, @import("std").math.maxInt(usize)) - 1); |
| 8337 | 8636 | \\} |
| ... | ... | @@ -8339,23 +8638,24 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 8339 | 8638 | ":2:75: error: operation caused overflow", |
| 8340 | 8639 | }); |
| 8341 | 8640 | |
| 8342 | | cases.addCase(x: { |
| 8343 | | var tc = cases.create("align(N) expr function pointers is a compile error", |
| 8641 | { |
| 8642 | const case = ctx.obj("align(N) expr function pointers is a compile error", .{ |
| 8643 | .cpu_arch = .wasm32, |
| 8644 | .os_tag = .freestanding, |
| 8645 | .abi = .none, |
| 8646 | }); |
| 8647 | case.backend = .stage1; |
| 8648 | |
| 8649 | case.addError( |
| 8344 | 8650 | \\export fn foo() align(1) void { |
| 8345 | 8651 | \\ return; |
| 8346 | 8652 | \\} |
| 8347 | 8653 | , &[_][]const u8{ |
| 8348 | 8654 | "tmp.zig:1:23: error: align(N) expr is not allowed on function prototypes in wasm32/wasm64", |
| 8349 | 8655 | }); |
| 8350 | | tc.target = std.zig.CrossTarget{ |
| 8351 | | .cpu_arch = .wasm32, |
| 8352 | | .os_tag = .freestanding, |
| 8353 | | .abi = .none, |
| 8354 | | }; |
| 8355 | | break :x tc; |
| 8356 | | }); |
| 8656 | } |
| 8357 | 8657 | |
| 8358 | | cases.add("compare optional to non-optional with invalid types", |
| 8658 | ctx.objErrStage1("compare optional to non-optional with invalid types", |
| 8359 | 8659 | \\export fn inconsistentChildType() void { |
| 8360 | 8660 | \\ var x: ?i32 = undefined; |
| 8361 | 8661 | \\ const y: comptime_int = 10; |
| ... | ... | @@ -8389,16 +8689,17 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 8389 | 8689 | ":22:12: note: operator not supported for type '[3]i32'", |
| 8390 | 8690 | }); |
| 8391 | 8691 | |
| 8392 | | cases.add("slice cannot have its bytes reinterpreted", |
| 8692 | ctx.objErrStage1("slice cannot have its bytes reinterpreted", |
| 8393 | 8693 | \\export fn foo() void { |
| 8394 | 8694 | \\ const bytes = [1]u8{ 0xfa } ** 16; |
| 8395 | 8695 | \\ var value = @ptrCast(*const []const u8, &bytes).*; |
| 8696 | \\ _ = value; |
| 8396 | 8697 | \\} |
| 8397 | 8698 | , &[_][]const u8{ |
| 8398 | 8699 | ":3:52: error: slice '[]const u8' cannot have its bytes reinterpreted", |
| 8399 | 8700 | }); |
| 8400 | 8701 | |
| 8401 | | cases.add("wasmMemorySize is a compile error in non-Wasm targets", |
| 8702 | ctx.objErrStage1("wasmMemorySize is a compile error in non-Wasm targets", |
| 8402 | 8703 | \\export fn foo() void { |
| 8403 | 8704 | \\ _ = @wasmMemorySize(0); |
| 8404 | 8705 | \\ return; |
| ... | ... | @@ -8407,7 +8708,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 8407 | 8708 | "tmp.zig:2:9: error: @wasmMemorySize is a wasm32 feature only", |
| 8408 | 8709 | }); |
| 8409 | 8710 | |
| 8410 | | cases.add("wasmMemoryGrow is a compile error in non-Wasm targets", |
| 8711 | ctx.objErrStage1("wasmMemoryGrow is a compile error in non-Wasm targets", |
| 8411 | 8712 | \\export fn foo() void { |
| 8412 | 8713 | \\ _ = @wasmMemoryGrow(0, 1); |
| 8413 | 8714 | \\ return; |
| ... | ... | @@ -8415,7 +8716,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 8415 | 8716 | , &[_][]const u8{ |
| 8416 | 8717 | "tmp.zig:2:9: error: @wasmMemoryGrow is a wasm32 feature only", |
| 8417 | 8718 | }); |
| 8418 | | cases.add("Issue #5586: Make unary minus for unsigned types a compile error", |
| 8719 | ctx.objErrStage1("Issue #5586: Make unary minus for unsigned types a compile error", |
| 8419 | 8720 | \\export fn f1(x: u32) u32 { |
| 8420 | 8721 | \\ const y = -%x; |
| 8421 | 8722 | \\ return -y; |
| ... | ... | @@ -8430,7 +8731,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 8430 | 8731 | "tmp.zig:8:12: error: negation of type 'u32'", |
| 8431 | 8732 | }); |
| 8432 | 8733 | |
| 8433 | | cases.add("Issue #5618: coercion of ?*c_void to *c_void must fail.", |
| 8734 | ctx.objErrStage1("Issue #5618: coercion of ?*c_void to *c_void must fail.", |
| 8434 | 8735 | \\export fn foo() void { |
| 8435 | 8736 | \\ var u: ?*c_void = null; |
| 8436 | 8737 | \\ var v: *c_void = undefined; |
| ... | ... | @@ -8440,15 +8741,16 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 8440 | 8741 | "tmp.zig:4:9: error: expected type '*c_void', found '?*c_void'", |
| 8441 | 8742 | }); |
| 8442 | 8743 | |
| 8443 | | cases.add("Issue #6823: don't allow .* to be followed by **", |
| 8744 | ctx.objErrStage1("Issue #6823: don't allow .* to be followed by **", |
| 8444 | 8745 | \\fn foo() void { |
| 8445 | 8746 | \\ var sequence = "repeat".*** 10; |
| 8747 | \\ _ = sequence; |
| 8446 | 8748 | \\} |
| 8447 | 8749 | , &[_][]const u8{ |
| 8448 | 8750 | "tmp.zig:2:30: error: `.*` cannot be followed by `*`. Are you missing a space?", |
| 8449 | 8751 | }); |
| 8450 | 8752 | |
| 8451 | | cases.add("Issue #9165: windows tcp server compilation error", |
| 8753 | ctx.objErrStage1("Issue #9165: windows tcp server compilation error", |
| 8452 | 8754 | \\const std = @import("std"); |
| 8453 | 8755 | \\pub const io_mode = .evented; |
| 8454 | 8756 | \\pub fn main() !void { |