| ... | @@ -1,53 +1,58 @@ | ... | @@ -1,53 +1,58 @@ |
| 1 | const tests = @import("tests.zig"); | | |
| 2 | const std = @import("std"); | 1 | const std = @import("std"); |
| | 2 | const TestContext = @import("../src/test.zig").TestContext; |
| 3 | | 3 | |
| 4 | pub fn addCases(cases: *tests.CompileErrorContext) void { | 4 | pub fn addCases(ctx: *TestContext) !void { |
| 5 | cases.add("std.fmt error for unused arguments", | 5 | ctx.exeErrStage1("std.fmt error for unused arguments", |
| 6 | \\pub fn main() !void { | 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}); | 7 | \\ @import("std").debug.print("{d} {d} {d} {d} {d}", .{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15}); |
| 8 | \\} | 8 | \\} |
| 9 | , &.{ | 9 | , &.{ |
| 10 | \\error: 10 unused arguments in "{d} {d} {d} {d} {d}" | 10 | "?:?:?: error: 10 unused arguments in '{d} {d} {d} {d} {d}'", |
| 11 | }); | 11 | }); |
| 12 | | 12 | |
| 13 | cases.add("lazy pointer with undefined element type", | 13 | ctx.objErrStage1("lazy pointer with undefined element type", |
| 14 | \\export fn foo() void { | 14 | \\export fn foo() void { |
| 15 | \\ comptime var T: type = undefined; | 15 | \\ comptime var T: type = undefined; |
| 16 | \\ const S = struct { x: *T }; | 16 | \\ const S = struct { x: *T }; |
| 17 | \\ const I = @typeInfo(S); | 17 | \\ const I = @typeInfo(S); |
| | 18 | \\ _ = I; |
| 18 | \\} | 19 | \\} |
| 19 | , &[_][]const u8{ | 20 | , &[_][]const u8{ |
| 20 | "tmp.zig:3:28: error: use of undefined value here causes undefined behavior", | 21 | ":3:28: error: use of undefined value here causes undefined behavior", |
| 21 | }); | 22 | }); |
| 22 | | 23 | |
| 23 | cases.add("pointer arithmetic on pointer-to-array", | 24 | ctx.objErrStage1("pointer arithmetic on pointer-to-array", |
| 24 | \\export fn foo() void { | 25 | \\export fn foo() void { |
| 25 | \\ var x: [10]u8 = undefined; | 26 | \\ var x: [10]u8 = undefined; |
| 26 | \\ var y = &x; | 27 | \\ var y = &x; |
| 27 | \\ var z = y + 1; | 28 | \\ var z = y + 1; |
| | 29 | \\ _ = z; |
| 28 | \\} | 30 | \\} |
| 29 | , &[_][]const u8{ | 31 | , &[_][]const u8{ |
| 30 | "tmp.zig:4:17: error: integer value 1 cannot be coerced to type '*[10]u8'", | 32 | "tmp.zig:4:17: error: integer value 1 cannot be coerced to type '*[10]u8'", |
| 31 | }); | 33 | }); |
| 32 | | 34 | |
| 33 | cases.add("pointer attributes checked when coercing pointer to anon literal", | 35 | ctx.objErrStage1("pointer attributes checked when coercing pointer to anon literal", |
| 34 | \\comptime { | 36 | \\comptime { |
| 35 | \\ const c: [][]const u8 = &.{"hello", "world" }; | 37 | \\ const c: [][]const u8 = &.{"hello", "world" }; |
| | 38 | \\ _ = c; |
| 36 | \\} | 39 | \\} |
| 37 | \\comptime { | 40 | \\comptime { |
| 38 | \\ const c: *[2][]const u8 = &.{"hello", "world" }; | 41 | \\ const c: *[2][]const u8 = &.{"hello", "world" }; |
| | 42 | \\ _ = c; |
| 39 | \\} | 43 | \\} |
| 40 | \\const S = struct {a: u8 = 1, b: u32 = 2}; | 44 | \\const S = struct {a: u8 = 1, b: u32 = 2}; |
| 41 | \\comptime { | 45 | \\comptime { |
| 42 | \\ const c: *S = &.{}; | 46 | \\ const c: *S = &.{}; |
| | 47 | \\ _ = c; |
| 43 | \\} | 48 | \\} |
| 44 | , &[_][]const u8{ | 49 | , &[_][]const u8{ |
| 45 | "tmp.zig:2:31: error: expected type '[][]const u8', found '*const struct:2:31'", | 50 | "tmp.zig:2:31: error: expected type '[][]const u8', found '*const struct:2:31'", |
| 46 | "tmp.zig:5:33: error: expected type '*[2][]const u8', found '*const struct:5:33'", | 51 | "tmp.zig:6:33: error: expected type '*[2][]const u8', found '*const struct:6:33'", |
| 47 | "tmp.zig:9:21: error: expected type '*S', found '*const struct:9:21'", | 52 | "tmp.zig:11:21: error: expected type '*S', found '*const struct:11:21'", |
| 48 | }); | 53 | }); |
| 49 | | 54 | |
| 50 | cases.add("@Type() union payload is undefined", | 55 | ctx.objErrStage1("@Type() union payload is undefined", |
| 51 | \\const Foo = @Type(@import("std").builtin.TypeInfo{ | 56 | \\const Foo = @Type(@import("std").builtin.TypeInfo{ |
| 52 | \\ .Struct = undefined, | 57 | \\ .Struct = undefined, |
| 53 | \\}); | 58 | \\}); |
| ... | @@ -56,7 +61,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -56,7 +61,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 56 | "tmp.zig:1:50: error: use of undefined value here causes undefined behavior", | 61 | "tmp.zig:1:50: error: use of undefined value here causes undefined behavior", |
| 57 | }); | 62 | }); |
| 58 | | 63 | |
| 59 | cases.add("wrong initializer for union payload of type 'type'", | 64 | ctx.objErrStage1("wrong initializer for union payload of type 'type'", |
| 60 | \\const U = union(enum) { | 65 | \\const U = union(enum) { |
| 61 | \\ A: type, | 66 | \\ A: type, |
| 62 | \\}; | 67 | \\}; |
| ... | @@ -71,7 +76,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -71,7 +76,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 71 | "tmp.zig:9:8: error: use of undefined value here causes undefined behavior", | 76 | "tmp.zig:9:8: error: use of undefined value here causes undefined behavior", |
| 72 | }); | 77 | }); |
| 73 | | 78 | |
| 74 | cases.add("union with too small explicit signed tag type", | 79 | ctx.objErrStage1("union with too small explicit signed tag type", |
| 75 | \\const U = union(enum(i2)) { | 80 | \\const U = union(enum(i2)) { |
| 76 | \\ A: u8, | 81 | \\ A: u8, |
| 77 | \\ B: u8, | 82 | \\ B: u8, |
| ... | @@ -86,7 +91,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -86,7 +91,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 86 | "tmp.zig:1:22: note: type i2 cannot fit values in range 0...3", | 91 | "tmp.zig:1:22: note: type i2 cannot fit values in range 0...3", |
| 87 | }); | 92 | }); |
| 88 | | 93 | |
| 89 | cases.add("union with too small explicit unsigned tag type", | 94 | ctx.objErrStage1("union with too small explicit unsigned tag type", |
| 90 | \\const U = union(enum(u2)) { | 95 | \\const U = union(enum(u2)) { |
| 91 | \\ A: u8, | 96 | \\ A: u8, |
| 92 | \\ B: u8, | 97 | \\ B: u8, |
| ... | @@ -102,56 +107,60 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -102,56 +107,60 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 102 | "tmp.zig:1:22: note: type u2 cannot fit values in range 0...4", | 107 | "tmp.zig:1:22: note: type u2 cannot fit values in range 0...4", |
| 103 | }); | 108 | }); |
| 104 | | 109 | |
| 105 | cases.addCase(x: { | 110 | { |
| 106 | var tc = cases.create("callconv(.Interrupt) on unsupported platform", | 111 | const case = ctx.obj("callconv(.Interrupt) on unsupported platform", .{ |
| | 112 | .cpu_arch = .aarch64, |
| | 113 | .os_tag = .linux, |
| | 114 | .abi = .none, |
| | 115 | }); |
| | 116 | case.backend = .stage1; |
| | 117 | case.addError( |
| 107 | \\export fn entry() callconv(.Interrupt) void {} | 118 | \\export fn entry() callconv(.Interrupt) void {} |
| 108 | , &[_][]const u8{ | 119 | , &[_][]const u8{ |
| 109 | "tmp.zig:1:28: error: callconv 'Interrupt' is only available on x86, x86_64, AVR, and MSP430, not aarch64", | 120 | "tmp.zig:1:28: error: callconv 'Interrupt' is only available on x86, x86_64, AVR, and MSP430, not aarch64", |
| 110 | }); | 121 | }); |
| 111 | tc.target = std.zig.CrossTarget{ | 122 | } |
| 112 | .cpu_arch = .aarch64, | 123 | { |
| | 124 | var case = ctx.obj("callconv(.Signal) on unsupported platform", .{ |
| | 125 | .cpu_arch = .x86_64, |
| 113 | .os_tag = .linux, | 126 | .os_tag = .linux, |
| 114 | .abi = .none, | 127 | .abi = .none, |
| 115 | }; | 128 | }); |
| 116 | break :x tc; | 129 | case.backend = .stage1; |
| 117 | }); | 130 | case.addError( |
| 118 | | | |
| 119 | cases.addCase(x: { | | |
| 120 | var tc = cases.create("callconv(.Signal) on unsupported platform", | | |
| 121 | \\export fn entry() callconv(.Signal) void {} | 131 | \\export fn entry() callconv(.Signal) void {} |
| 122 | , &[_][]const u8{ | 132 | , &[_][]const u8{ |
| 123 | "tmp.zig:1:28: error: callconv 'Signal' is only available on AVR, not x86_64", | 133 | "tmp.zig:1:28: error: callconv 'Signal' is only available on AVR, not x86_64", |
| 124 | }); | 134 | }); |
| 125 | tc.target = std.zig.CrossTarget{ | 135 | } |
| | 136 | { |
| | 137 | const case = ctx.obj("callconv(.Stdcall, .Fastcall, .Thiscall) on unsupported platform", .{ |
| 126 | .cpu_arch = .x86_64, | 138 | .cpu_arch = .x86_64, |
| 127 | .os_tag = .linux, | 139 | .os_tag = .linux, |
| 128 | .abi = .none, | 140 | .abi = .none, |
| 129 | }; | 141 | }); |
| 130 | break :x tc; | 142 | case.backend = .stage1; |
| 131 | }); | 143 | case.addError( |
| 132 | cases.addCase(x: { | | |
| 133 | var tc = cases.create("callconv(.Stdcall, .Fastcall, .Thiscall) on unsupported platform", | | |
| 134 | \\const F1 = fn () callconv(.Stdcall) void; | 144 | \\const F1 = fn () callconv(.Stdcall) void; |
| 135 | \\const F2 = fn () callconv(.Fastcall) void; | 145 | \\const F2 = fn () callconv(.Fastcall) void; |
| 136 | \\const F3 = fn () callconv(.Thiscall) void; | 146 | \\const F3 = fn () callconv(.Thiscall) void; |
| 137 | \\export fn entry1() void { var a: F1 = undefined; } | 147 | \\export fn entry1() void { var a: F1 = undefined; _ = a; } |
| 138 | \\export fn entry2() void { var a: F2 = undefined; } | 148 | \\export fn entry2() void { var a: F2 = undefined; _ = a; } |
| 139 | \\export fn entry3() void { var a: F3 = undefined; } | 149 | \\export fn entry3() void { var a: F3 = undefined; _ = a; } |
| 140 | , &[_][]const u8{ | 150 | , &[_][]const u8{ |
| 141 | "tmp.zig:1:27: error: callconv 'Stdcall' is only available on x86, not x86_64", | 151 | "tmp.zig:1:27: error: callconv 'Stdcall' is only available on x86, not x86_64", |
| 142 | "tmp.zig:2:27: error: callconv 'Fastcall' is only available on x86, not x86_64", | 152 | "tmp.zig:2:27: error: callconv 'Fastcall' is only available on x86, not x86_64", |
| 143 | "tmp.zig:3:27: error: callconv 'Thiscall' is only available on x86, not x86_64", | 153 | "tmp.zig:3:27: error: callconv 'Thiscall' is only available on x86, not x86_64", |
| 144 | }); | 154 | }); |
| 145 | tc.target = std.zig.CrossTarget{ | 155 | } |
| | 156 | { |
| | 157 | const case = ctx.obj("callconv(.Stdcall, .Fastcall, .Thiscall) on unsupported platform", .{ |
| 146 | .cpu_arch = .x86_64, | 158 | .cpu_arch = .x86_64, |
| 147 | .os_tag = .linux, | 159 | .os_tag = .linux, |
| 148 | .abi = .none, | 160 | .abi = .none, |
| 149 | }; | 161 | }); |
| 150 | break :x tc; | 162 | case.backend = .stage1; |
| 151 | }); | 163 | case.addError( |
| 152 | | | |
| 153 | cases.addCase(x: { | | |
| 154 | var tc = cases.create("callconv(.Stdcall, .Fastcall, .Thiscall) on unsupported platform", | | |
| 155 | \\export fn entry1() callconv(.Stdcall) void {} | 164 | \\export fn entry1() callconv(.Stdcall) void {} |
| 156 | \\export fn entry2() callconv(.Fastcall) void {} | 165 | \\export fn entry2() callconv(.Fastcall) void {} |
| 157 | \\export fn entry3() callconv(.Thiscall) void {} | 166 | \\export fn entry3() callconv(.Thiscall) void {} |
| ... | @@ -160,30 +169,28 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -160,30 +169,28 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 160 | "tmp.zig:2:29: error: callconv 'Fastcall' is only available on x86, not x86_64", | 169 | "tmp.zig:2:29: error: callconv 'Fastcall' is only available on x86, not x86_64", |
| 161 | "tmp.zig:3:29: error: callconv 'Thiscall' is only available on x86, not x86_64", | 170 | "tmp.zig:3:29: error: callconv 'Thiscall' is only available on x86, not x86_64", |
| 162 | }); | 171 | }); |
| 163 | tc.target = std.zig.CrossTarget{ | 172 | } |
| | 173 | { |
| | 174 | const case = ctx.obj("callconv(.Vectorcall) on unsupported platform", .{ |
| 164 | .cpu_arch = .x86_64, | 175 | .cpu_arch = .x86_64, |
| 165 | .os_tag = .linux, | 176 | .os_tag = .linux, |
| 166 | .abi = .none, | 177 | .abi = .none, |
| 167 | }; | 178 | }); |
| 168 | break :x tc; | 179 | case.backend = .stage1; |
| 169 | }); | 180 | case.addError( |
| 170 | | | |
| 171 | cases.addCase(x: { | | |
| 172 | var tc = cases.create("callconv(.Vectorcall) on unsupported platform", | | |
| 173 | \\export fn entry() callconv(.Vectorcall) void {} | 181 | \\export fn entry() callconv(.Vectorcall) void {} |
| 174 | , &[_][]const u8{ | 182 | , &[_][]const u8{ |
| 175 | "tmp.zig:1:28: error: callconv 'Vectorcall' is only available on x86 and AArch64, not x86_64", | 183 | "tmp.zig:1:28: error: callconv 'Vectorcall' is only available on x86 and AArch64, not x86_64", |
| 176 | }); | 184 | }); |
| 177 | tc.target = std.zig.CrossTarget{ | 185 | } |
| | 186 | { |
| | 187 | const case = ctx.obj("callconv(.APCS, .AAPCS, .AAPCSVFP) on unsupported platform", .{ |
| 178 | .cpu_arch = .x86_64, | 188 | .cpu_arch = .x86_64, |
| 179 | .os_tag = .linux, | 189 | .os_tag = .linux, |
| 180 | .abi = .none, | 190 | .abi = .none, |
| 181 | }; | 191 | }); |
| 182 | break :x tc; | 192 | case.backend = .stage1; |
| 183 | }); | 193 | case.addError( |
| 184 | | | |
| 185 | cases.addCase(x: { | | |
| 186 | var tc = cases.create("callconv(.APCS, .AAPCS, .AAPCSVFP) on unsupported platform", | | |
| 187 | \\export fn entry1() callconv(.APCS) void {} | 194 | \\export fn entry1() callconv(.APCS) void {} |
| 188 | \\export fn entry2() callconv(.AAPCS) void {} | 195 | \\export fn entry2() callconv(.AAPCS) void {} |
| 189 | \\export fn entry3() callconv(.AAPCSVFP) void {} | 196 | \\export fn entry3() callconv(.AAPCSVFP) void {} |
| ... | @@ -192,15 +199,9 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -192,15 +199,9 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 192 | "tmp.zig:2:29: error: callconv 'AAPCS' is only available on ARM, not x86_64", | 199 | "tmp.zig:2:29: error: callconv 'AAPCS' is only available on ARM, not x86_64", |
| 193 | "tmp.zig:3:29: error: callconv 'AAPCSVFP' is only available on ARM, not x86_64", | 200 | "tmp.zig:3:29: error: callconv 'AAPCSVFP' is only available on ARM, not x86_64", |
| 194 | }); | 201 | }); |
| 195 | tc.target = std.zig.CrossTarget{ | 202 | } |
| 196 | .cpu_arch = .x86_64, | | |
| 197 | .os_tag = .linux, | | |
| 198 | .abi = .none, | | |
| 199 | }; | | |
| 200 | break :x tc; | | |
| 201 | }); | | |
| 202 | | 203 | |
| 203 | cases.add("unreachable executed at comptime", | 204 | ctx.objErrStage1("unreachable executed at comptime", |
| 204 | \\fn foo(comptime x: i32) i32 { | 205 | \\fn foo(comptime x: i32) i32 { |
| 205 | \\ comptime { | 206 | \\ comptime { |
| 206 | \\ if (x >= 0) return -x; | 207 | \\ if (x >= 0) return -x; |
| ... | @@ -215,7 +216,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -215,7 +216,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 215 | "tmp.zig:8:12: note: called from here", | 216 | "tmp.zig:8:12: note: called from here", |
| 216 | }); | 217 | }); |
| 217 | | 218 | |
| 218 | cases.add("@Type with TypeInfo.Int", | 219 | ctx.objErrStage1("@Type with TypeInfo.Int", |
| 219 | \\const builtin = @import("std").builtin; | 220 | \\const builtin = @import("std").builtin; |
| 220 | \\export fn entry() void { | 221 | \\export fn entry() void { |
| 221 | \\ _ = @Type(builtin.TypeInfo.Int { | 222 | \\ _ = @Type(builtin.TypeInfo.Int { |
| ... | @@ -227,7 +228,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -227,7 +228,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 227 | "tmp.zig:3:36: error: expected type 'std.builtin.TypeInfo', found 'std.builtin.Int'", | 228 | "tmp.zig:3:36: error: expected type 'std.builtin.TypeInfo', found 'std.builtin.Int'", |
| 228 | }); | 229 | }); |
| 229 | | 230 | |
| 230 | cases.add("indexing a undefined slice at comptime", | 231 | ctx.objErrStage1("indexing a undefined slice at comptime", |
| 231 | \\comptime { | 232 | \\comptime { |
| 232 | \\ var slice: []u8 = undefined; | 233 | \\ var slice: []u8 = undefined; |
| 233 | \\ slice[0] = 2; | 234 | \\ slice[0] = 2; |
| ... | @@ -236,7 +237,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -236,7 +237,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 236 | "tmp.zig:3:10: error: index 0 outside slice of size 0", | 237 | "tmp.zig:3:10: error: index 0 outside slice of size 0", |
| 237 | }); | 238 | }); |
| 238 | | 239 | |
| 239 | cases.add("array in c exported function", | 240 | ctx.objErrStage1("array in c exported function", |
| 240 | \\export fn zig_array(x: [10]u8) void { | 241 | \\export fn zig_array(x: [10]u8) void { |
| 241 | \\try expect(std.mem.eql(u8, &x, "1234567890")); | 242 | \\try expect(std.mem.eql(u8, &x, "1234567890")); |
| 242 | \\} | 243 | \\} |
| ... | @@ -249,7 +250,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -249,7 +250,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 249 | "tmp.zig:5:30: error: return type '[10]u8' not allowed in function with calling convention 'C'", | 250 | "tmp.zig:5:30: error: return type '[10]u8' not allowed in function with calling convention 'C'", |
| 250 | }); | 251 | }); |
| 251 | | 252 | |
| 252 | cases.add("@Type for exhaustive enum with undefined tag type", | 253 | ctx.objErrStage1("@Type for exhaustive enum with undefined tag type", |
| 253 | \\const TypeInfo = @import("std").builtin.TypeInfo; | 254 | \\const TypeInfo = @import("std").builtin.TypeInfo; |
| 254 | \\const Tag = @Type(.{ | 255 | \\const Tag = @Type(.{ |
| 255 | \\ .Enum = .{ | 256 | \\ .Enum = .{ |
| ... | @@ -267,19 +268,20 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -267,19 +268,20 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 267 | "tmp.zig:2:20: error: use of undefined value here causes undefined behavior", | 268 | "tmp.zig:2:20: error: use of undefined value here causes undefined behavior", |
| 268 | }); | 269 | }); |
| 269 | | 270 | |
| 270 | cases.add("extern struct with non-extern-compatible integer tag type", | 271 | ctx.objErrStage1("extern struct with non-extern-compatible integer tag type", |
| 271 | \\pub const E = enum(u31) { A, B, C }; | 272 | \\pub const E = enum(u31) { A, B, C }; |
| 272 | \\pub const S = extern struct { | 273 | \\pub const S = extern struct { |
| 273 | \\ e: E, | 274 | \\ e: E, |
| 274 | \\}; | 275 | \\}; |
| 275 | \\export fn entry() void { | 276 | \\export fn entry() void { |
| 276 | \\ const s: S = undefined; | 277 | \\ const s: S = undefined; |
| | 278 | \\ _ = s; |
| 277 | \\} | 279 | \\} |
| 278 | , &[_][]const u8{ | 280 | , &[_][]const u8{ |
| 279 | "tmp.zig:3:5: error: extern structs cannot contain fields of type 'E'", | 281 | "tmp.zig:3:5: error: extern structs cannot contain fields of type 'E'", |
| 280 | }); | 282 | }); |
| 281 | | 283 | |
| 282 | cases.add("@Type for exhaustive enum with non-integer tag type", | 284 | ctx.objErrStage1("@Type for exhaustive enum with non-integer tag type", |
| 283 | \\const TypeInfo = @import("std").builtin.TypeInfo; | 285 | \\const TypeInfo = @import("std").builtin.TypeInfo; |
| 284 | \\const Tag = @Type(.{ | 286 | \\const Tag = @Type(.{ |
| 285 | \\ .Enum = .{ | 287 | \\ .Enum = .{ |
| ... | @@ -297,7 +299,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -297,7 +299,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 297 | "tmp.zig:2:20: error: TypeInfo.Enum.tag_type must be an integer type, not 'bool'", | 299 | "tmp.zig:2:20: error: TypeInfo.Enum.tag_type must be an integer type, not 'bool'", |
| 298 | }); | 300 | }); |
| 299 | | 301 | |
| 300 | cases.add("extern struct with extern-compatible but inferred integer tag type", | 302 | ctx.objErrStage1("extern struct with extern-compatible but inferred integer tag type", |
| 301 | \\pub const E = enum { | 303 | \\pub const E = enum { |
| 302 | \\@"0",@"1",@"2",@"3",@"4",@"5",@"6",@"7",@"8",@"9",@"10",@"11",@"12", | 304 | \\@"0",@"1",@"2",@"3",@"4",@"5",@"6",@"7",@"8",@"9",@"10",@"11",@"12", |
| 303 | \\@"13",@"14",@"15",@"16",@"17",@"18",@"19",@"20",@"21",@"22",@"23", | 305 | \\@"13",@"14",@"15",@"16",@"17",@"18",@"19",@"20",@"21",@"22",@"23", |
| ... | @@ -333,12 +335,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -333,12 +335,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 333 | \\export fn entry() void { | 335 | \\export fn entry() void { |
| 334 | \\ if (@typeInfo(E).Enum.tag_type != u8) @compileError("did not infer u8 tag type"); | 336 | \\ if (@typeInfo(E).Enum.tag_type != u8) @compileError("did not infer u8 tag type"); |
| 335 | \\ const s: S = undefined; | 337 | \\ const s: S = undefined; |
| | 338 | \\ _ = s; |
| 336 | \\} | 339 | \\} |
| 337 | , &[_][]const u8{ | 340 | , &[_][]const u8{ |
| 338 | "tmp.zig:31:5: error: extern structs cannot contain fields of type 'E'", | 341 | "tmp.zig:31:5: error: extern structs cannot contain fields of type 'E'", |
| 339 | }); | 342 | }); |
| 340 | | 343 | |
| 341 | cases.add("@Type for tagged union with extra enum field", | 344 | ctx.objErrStage1("@Type for tagged union with extra enum field", |
| 342 | \\const TypeInfo = @import("std").builtin.TypeInfo; | 345 | \\const TypeInfo = @import("std").builtin.TypeInfo; |
| 343 | \\const Tag = @Type(.{ | 346 | \\const Tag = @Type(.{ |
| 344 | \\ .Enum = .{ | 347 | \\ .Enum = .{ |
| ... | @@ -373,7 +376,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -373,7 +376,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 373 | "tmp.zig:27:24: note: referenced here", | 376 | "tmp.zig:27:24: note: referenced here", |
| 374 | }); | 377 | }); |
| 375 | | 378 | |
| 376 | cases.add("field access of opaque type", | 379 | ctx.objErrStage1("field access of opaque type", |
| 377 | \\const MyType = opaque {}; | 380 | \\const MyType = opaque {}; |
| 378 | \\ | 381 | \\ |
| 379 | \\export fn entry() bool { | 382 | \\export fn entry() bool { |
| ... | @@ -388,16 +391,17 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -388,16 +391,17 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 388 | "tmp.zig:9:13: error: no member named 'blah' in opaque type 'MyType'", | 391 | "tmp.zig:9:13: error: no member named 'blah' in opaque type 'MyType'", |
| 389 | }); | 392 | }); |
| 390 | | 393 | |
| 391 | cases.add("opaque type with field", | 394 | ctx.objErrStage1("opaque type with field", |
| 392 | \\const Opaque = opaque { foo: i32 }; | 395 | \\const Opaque = opaque { foo: i32 }; |
| 393 | \\export fn entry() void { | 396 | \\export fn entry() void { |
| 394 | \\ const foo: ?*Opaque = null; | 397 | \\ const foo: ?*Opaque = null; |
| | 398 | \\ _ = foo; |
| 395 | \\} | 399 | \\} |
| 396 | , &[_][]const u8{ | 400 | , &[_][]const u8{ |
| 397 | "tmp.zig:1:25: error: opaque types cannot have fields", | 401 | "tmp.zig:1:25: error: opaque types cannot have fields", |
| 398 | }); | 402 | }); |
| 399 | | 403 | |
| 400 | cases.add("@Type(.Fn) with is_generic = true", | 404 | ctx.objErrStage1("@Type(.Fn) with is_generic = true", |
| 401 | \\const Foo = @Type(.{ | 405 | \\const Foo = @Type(.{ |
| 402 | \\ .Fn = .{ | 406 | \\ .Fn = .{ |
| 403 | \\ .calling_convention = .Unspecified, | 407 | \\ .calling_convention = .Unspecified, |
| ... | @@ -413,7 +417,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -413,7 +417,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 413 | "tmp.zig:1:20: error: TypeInfo.Fn.is_generic must be false for @Type", | 417 | "tmp.zig:1:20: error: TypeInfo.Fn.is_generic must be false for @Type", |
| 414 | }); | 418 | }); |
| 415 | | 419 | |
| 416 | cases.add("@Type(.Fn) with is_var_args = true and non-C callconv", | 420 | ctx.objErrStage1("@Type(.Fn) with is_var_args = true and non-C callconv", |
| 417 | \\const Foo = @Type(.{ | 421 | \\const Foo = @Type(.{ |
| 418 | \\ .Fn = .{ | 422 | \\ .Fn = .{ |
| 419 | \\ .calling_convention = .Unspecified, | 423 | \\ .calling_convention = .Unspecified, |
| ... | @@ -429,7 +433,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -429,7 +433,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 429 | "tmp.zig:1:20: error: varargs functions must have C calling convention", | 433 | "tmp.zig:1:20: error: varargs functions must have C calling convention", |
| 430 | }); | 434 | }); |
| 431 | | 435 | |
| 432 | cases.add("@Type(.Fn) with return_type = null", | 436 | ctx.objErrStage1("@Type(.Fn) with return_type = null", |
| 433 | \\const Foo = @Type(.{ | 437 | \\const Foo = @Type(.{ |
| 434 | \\ .Fn = .{ | 438 | \\ .Fn = .{ |
| 435 | \\ .calling_convention = .Unspecified, | 439 | \\ .calling_convention = .Unspecified, |
| ... | @@ -445,7 +449,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -445,7 +449,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 445 | "tmp.zig:1:20: error: TypeInfo.Fn.return_type must be non-null for @Type", | 449 | "tmp.zig:1:20: error: TypeInfo.Fn.return_type must be non-null for @Type", |
| 446 | }); | 450 | }); |
| 447 | | 451 | |
| 448 | cases.add("@Type for union with opaque field", | 452 | ctx.objErrStage1("@Type for union with opaque field", |
| 449 | \\const TypeInfo = @import("std").builtin.TypeInfo; | 453 | \\const TypeInfo = @import("std").builtin.TypeInfo; |
| 450 | \\const Untagged = @Type(.{ | 454 | \\const Untagged = @Type(.{ |
| 451 | \\ .Union = .{ | 455 | \\ .Union = .{ |
| ... | @@ -465,23 +469,25 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -465,23 +469,25 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 465 | "tmp.zig:13:17: note: referenced here", | 469 | "tmp.zig:13:17: note: referenced here", |
| 466 | }); | 470 | }); |
| 467 | | 471 | |
| 468 | cases.add("slice sentinel mismatch", | 472 | ctx.objErrStage1("slice sentinel mismatch", |
| 469 | \\export fn entry() void { | 473 | \\export fn entry() void { |
| 470 | \\ const x = @import("std").meta.Vector(3, f32){ 25, 75, 5, 0 }; | 474 | \\ const x = @import("std").meta.Vector(3, f32){ 25, 75, 5, 0 }; |
| | 475 | \\ _ = x; |
| 471 | \\} | 476 | \\} |
| 472 | , &[_][]const u8{ | 477 | , &[_][]const u8{ |
| 473 | "tmp.zig:2:62: error: index 3 outside vector of size 3", | 478 | "tmp.zig:2:62: error: index 3 outside vector of size 3", |
| 474 | }); | 479 | }); |
| 475 | | 480 | |
| 476 | cases.add("slice sentinel mismatch", | 481 | ctx.objErrStage1("slice sentinel mismatch", |
| 477 | \\export fn entry() void { | 482 | \\export fn entry() void { |
| 478 | \\ const y: [:1]const u8 = &[_:2]u8{ 1, 2 }; | 483 | \\ const y: [:1]const u8 = &[_:2]u8{ 1, 2 }; |
| | 484 | \\ _ = y; |
| 479 | \\} | 485 | \\} |
| 480 | , &[_][]const u8{ | 486 | , &[_][]const u8{ |
| 481 | "tmp.zig:2:37: error: expected type '[:1]const u8', found '*const [2:2]u8'", | 487 | "tmp.zig:2:37: error: expected type '[:1]const u8', found '*const [2:2]u8'", |
| 482 | }); | 488 | }); |
| 483 | | 489 | |
| 484 | cases.add("@Type for union with zero fields", | 490 | ctx.objErrStage1("@Type for union with zero fields", |
| 485 | \\const TypeInfo = @import("std").builtin.TypeInfo; | 491 | \\const TypeInfo = @import("std").builtin.TypeInfo; |
| 486 | \\const Untagged = @Type(.{ | 492 | \\const Untagged = @Type(.{ |
| 487 | \\ .Union = .{ | 493 | \\ .Union = .{ |
| ... | @@ -499,7 +505,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -499,7 +505,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 499 | "tmp.zig:11:17: note: referenced here", | 505 | "tmp.zig:11:17: note: referenced here", |
| 500 | }); | 506 | }); |
| 501 | | 507 | |
| 502 | cases.add("@Type for exhaustive enum with zero fields", | 508 | ctx.objErrStage1("@Type for exhaustive enum with zero fields", |
| 503 | \\const TypeInfo = @import("std").builtin.TypeInfo; | 509 | \\const TypeInfo = @import("std").builtin.TypeInfo; |
| 504 | \\const Tag = @Type(.{ | 510 | \\const Tag = @Type(.{ |
| 505 | \\ .Enum = .{ | 511 | \\ .Enum = .{ |
| ... | @@ -518,7 +524,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -518,7 +524,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 518 | "tmp.zig:12:9: note: referenced here", | 524 | "tmp.zig:12:9: note: referenced here", |
| 519 | }); | 525 | }); |
| 520 | | 526 | |
| 521 | cases.add("@Type for tagged union with extra union field", | 527 | ctx.objErrStage1("@Type for tagged union with extra union field", |
| 522 | \\const TypeInfo = @import("std").builtin.TypeInfo; | 528 | \\const TypeInfo = @import("std").builtin.TypeInfo; |
| 523 | \\const Tag = @Type(.{ | 529 | \\const Tag = @Type(.{ |
| 524 | \\ .Enum = .{ | 530 | \\ .Enum = .{ |
| ... | @@ -554,7 +560,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -554,7 +560,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 554 | "tmp.zig:27:24: note: referenced here", | 560 | "tmp.zig:27:24: note: referenced here", |
| 555 | }); | 561 | }); |
| 556 | | 562 | |
| 557 | cases.add("@Type with undefined", | 563 | ctx.objErrStage1("@Type with undefined", |
| 558 | \\comptime { | 564 | \\comptime { |
| 559 | \\ _ = @Type(.{ .Array = .{ .len = 0, .child = u8, .sentinel = undefined } }); | 565 | \\ _ = @Type(.{ .Array = .{ .len = 0, .child = u8, .sentinel = undefined } }); |
| 560 | \\} | 566 | \\} |
| ... | @@ -573,7 +579,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -573,7 +579,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 573 | "tmp.zig:5:16: error: use of undefined value here causes undefined behavior", | 579 | "tmp.zig:5:16: error: use of undefined value here causes undefined behavior", |
| 574 | }); | 580 | }); |
| 575 | | 581 | |
| 576 | cases.add("struct with declarations unavailable for @Type", | 582 | ctx.objErrStage1("struct with declarations unavailable for @Type", |
| 577 | \\export fn entry() void { | 583 | \\export fn entry() void { |
| 578 | \\ _ = @Type(@typeInfo(struct { const foo = 1; })); | 584 | \\ _ = @Type(@typeInfo(struct { const foo = 1; })); |
| 579 | \\} | 585 | \\} |
| ... | @@ -581,7 +587,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -581,7 +587,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 581 | "tmp.zig:2:15: error: TypeInfo.Struct.decls must be empty for @Type", | 587 | "tmp.zig:2:15: error: TypeInfo.Struct.decls must be empty for @Type", |
| 582 | }); | 588 | }); |
| 583 | | 589 | |
| 584 | cases.add("enum with declarations unavailable for @Type", | 590 | ctx.objErrStage1("enum with declarations unavailable for @Type", |
| 585 | \\export fn entry() void { | 591 | \\export fn entry() void { |
| 586 | \\ _ = @Type(@typeInfo(enum { foo, const bar = 1; })); | 592 | \\ _ = @Type(@typeInfo(enum { foo, const bar = 1; })); |
| 587 | \\} | 593 | \\} |
| ... | @@ -589,36 +595,44 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -589,36 +595,44 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 589 | "tmp.zig:2:15: error: TypeInfo.Enum.decls must be empty for @Type", | 595 | "tmp.zig:2:15: error: TypeInfo.Enum.decls must be empty for @Type", |
| 590 | }); | 596 | }); |
| 591 | | 597 | |
| 592 | cases.addTest("reject extern variables with initializers", | 598 | ctx.testErrStage1("reject extern variables with initializers", |
| 593 | \\extern var foo: int = 2; | 599 | \\extern var foo: int = 2; |
| 594 | , &[_][]const u8{ | 600 | , &[_][]const u8{ |
| 595 | "tmp.zig:1:1: error: extern variables have no initializers", | 601 | "tmp.zig:1:23: error: extern variables have no initializers", |
| 596 | }); | 602 | }); |
| 597 | | 603 | |
| 598 | cases.addTest("duplicate/unused labels", | 604 | ctx.testErrStage1("duplicate/unused labels", |
| 599 | \\comptime { | 605 | \\comptime { |
| 600 | \\ blk: { blk: while (false) {} } | 606 | \\ blk: { blk: while (false) {} } |
| | 607 | \\} |
| | 608 | \\comptime { |
| 601 | \\ blk: while (false) { blk: for (@as([0]void, undefined)) |_| {} } | 609 | \\ blk: while (false) { blk: for (@as([0]void, undefined)) |_| {} } |
| | 610 | \\} |
| | 611 | \\comptime { |
| 602 | \\ blk: for (@as([0]void, undefined)) |_| { blk: {} } | 612 | \\ blk: for (@as([0]void, undefined)) |_| { blk: {} } |
| 603 | \\} | 613 | \\} |
| 604 | \\comptime { | 614 | \\comptime { |
| 605 | \\ blk: {} | 615 | \\ blk: {} |
| | 616 | \\} |
| | 617 | \\comptime { |
| 606 | \\ blk: while(false) {} | 618 | \\ blk: while(false) {} |
| | 619 | \\} |
| | 620 | \\comptime { |
| 607 | \\ blk: for(@as([0]void, undefined)) |_| {} | 621 | \\ blk: for(@as([0]void, undefined)) |_| {} |
| 608 | \\} | 622 | \\} |
| 609 | , &[_][]const u8{ | 623 | , &[_][]const u8{ |
| 610 | "tmp.zig:2:17: error: redeclaration of label 'blk'", | 624 | "tmp.zig:2:12: error: redefinition of label 'blk'", |
| 611 | "tmp.zig:2:10: note: previous declaration is here", | 625 | "tmp.zig:2:5: note: previous definition here", |
| 612 | "tmp.zig:3:31: error: redeclaration of label 'blk'", | 626 | "tmp.zig:5:26: error: redefinition of label 'blk'", |
| 613 | "tmp.zig:3:10: note: previous declaration is here", | 627 | "tmp.zig:5:5: note: previous definition here", |
| 614 | "tmp.zig:4:51: error: redeclaration of label 'blk'", | 628 | "tmp.zig:8:46: error: redefinition of label 'blk'", |
| 615 | "tmp.zig:4:10: note: previous declaration is here", | 629 | "tmp.zig:8:5: note: previous definition here", |
| 616 | "tmp.zig:7:10: error: unused block label", | 630 | "tmp.zig:11:5: error: unused block label", |
| 617 | "tmp.zig:8:10: error: unused while label", | 631 | "tmp.zig:14:5: error: unused while loop label", |
| 618 | "tmp.zig:9:10: error: unused for label", | 632 | "tmp.zig:17:5: error: unused for loop label", |
| 619 | }); | 633 | }); |
| 620 | | 634 | |
| 621 | cases.addTest("@alignCast of zero sized types", | 635 | ctx.testErrStage1("@alignCast of zero sized types", |
| 622 | \\export fn foo() void { | 636 | \\export fn foo() void { |
| 623 | \\ const a: *void = undefined; | 637 | \\ const a: *void = undefined; |
| 624 | \\ _ = @alignCast(2, a); | 638 | \\ _ = @alignCast(2, a); |
| ... | @@ -633,7 +647,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -633,7 +647,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 633 | \\} | 647 | \\} |
| 634 | \\export fn qux() void { | 648 | \\export fn qux() void { |
| 635 | \\ const a = struct { | 649 | \\ const a = struct { |
| 636 | \\ fn a(comptime b: u32) void {} | 650 | \\ fn a(comptime b: u32) void { _ = b; } |
| 637 | \\ }.a; | 651 | \\ }.a; |
| 638 | \\ _ = @alignCast(2, a); | 652 | \\ _ = @alignCast(2, a); |
| 639 | \\} | 653 | \\} |
| ... | @@ -644,7 +658,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -644,7 +658,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 644 | "tmp.zig:17:23: error: cannot adjust alignment of zero sized type 'fn(u32) anytype'", | 658 | "tmp.zig:17:23: error: cannot adjust alignment of zero sized type 'fn(u32) anytype'", |
| 645 | }); | 659 | }); |
| 646 | | 660 | |
| 647 | cases.addTest("invalid non-exhaustive enum to union", | 661 | ctx.testErrStage1("invalid non-exhaustive enum to union", |
| 648 | \\const E = enum(u8) { | 662 | \\const E = enum(u8) { |
| 649 | \\ a, | 663 | \\ a, |
| 650 | \\ b, | 664 | \\ b, |
| ... | @@ -657,17 +671,19 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -657,17 +671,19 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 657 | \\export fn foo() void { | 671 | \\export fn foo() void { |
| 658 | \\ var e = @intToEnum(E, 15); | 672 | \\ var e = @intToEnum(E, 15); |
| 659 | \\ var u: U = e; | 673 | \\ var u: U = e; |
| | 674 | \\ _ = u; |
| 660 | \\} | 675 | \\} |
| 661 | \\export fn bar() void { | 676 | \\export fn bar() void { |
| 662 | \\ const e = @intToEnum(E, 15); | 677 | \\ const e = @intToEnum(E, 15); |
| 663 | \\ var u: U = e; | 678 | \\ var u: U = e; |
| | 679 | \\ _ = u; |
| 664 | \\} | 680 | \\} |
| 665 | , &[_][]const u8{ | 681 | , &[_][]const u8{ |
| 666 | "tmp.zig:12:16: error: runtime cast to union 'U' from non-exhustive enum", | 682 | "tmp.zig:12:16: error: runtime cast to union 'U' from non-exhustive enum", |
| 667 | "tmp.zig:16:16: error: no tag by value 15", | 683 | "tmp.zig:17:16: error: no tag by value 15", |
| 668 | }); | 684 | }); |
| 669 | | 685 | |
| 670 | cases.addTest("switching with exhaustive enum has '_' prong ", | 686 | ctx.testErrStage1("switching with exhaustive enum has '_' prong ", |
| 671 | \\const E = enum{ | 687 | \\const E = enum{ |
| 672 | \\ a, | 688 | \\ a, |
| 673 | \\ b, | 689 | \\ b, |
| ... | @@ -684,7 +700,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -684,7 +700,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 684 | "tmp.zig:7:5: error: switch on exhaustive enum has `_` prong", | 700 | "tmp.zig:7:5: error: switch on exhaustive enum has `_` prong", |
| 685 | }); | 701 | }); |
| 686 | | 702 | |
| 687 | cases.addTest("invalid pointer with @Type", | 703 | ctx.testErrStage1("invalid pointer with @Type", |
| 688 | \\export fn entry() void { | 704 | \\export fn entry() void { |
| 689 | \\ _ = @Type(.{ .Pointer = .{ | 705 | \\ _ = @Type(.{ .Pointer = .{ |
| 690 | \\ .size = .One, | 706 | \\ .size = .One, |
| ... | @@ -700,7 +716,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -700,7 +716,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 700 | "tmp.zig:2:16: error: sentinels are only allowed on slices and unknown-length pointers", | 716 | "tmp.zig:2:16: error: sentinels are only allowed on slices and unknown-length pointers", |
| 701 | }); | 717 | }); |
| 702 | | 718 | |
| 703 | cases.addTest("helpful return type error message", | 719 | ctx.testErrStage1("helpful return type error message", |
| 704 | \\export fn foo() u32 { | 720 | \\export fn foo() u32 { |
| 705 | \\ return error.Ohno; | 721 | \\ return error.Ohno; |
| 706 | \\} | 722 | \\} |
| ... | @@ -728,7 +744,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -728,7 +744,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 728 | "tmp.zig:14:5: note: cannot store an error in type 'u32'", | 744 | "tmp.zig:14:5: note: cannot store an error in type 'u32'", |
| 729 | }); | 745 | }); |
| 730 | | 746 | |
| 731 | cases.addTest("int/float conversion to comptime_int/float", | 747 | ctx.testErrStage1("int/float conversion to comptime_int/float", |
| 732 | \\export fn foo() void { | 748 | \\export fn foo() void { |
| 733 | \\ var a: f32 = 2; | 749 | \\ var a: f32 = 2; |
| 734 | \\ _ = @floatToInt(comptime_int, a); | 750 | \\ _ = @floatToInt(comptime_int, a); |
| ... | @@ -744,16 +760,16 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -744,16 +760,16 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 744 | "tmp.zig:7:9: note: referenced here", | 760 | "tmp.zig:7:9: note: referenced here", |
| 745 | }); | 761 | }); |
| 746 | | 762 | |
| 747 | cases.add("extern variable has no type", | 763 | ctx.objErrStage1("extern variable has no type", |
| 748 | \\extern var foo; | 764 | \\extern var foo; |
| 749 | \\pub export fn entry() void { | 765 | \\pub export fn entry() void { |
| 750 | \\ foo; | 766 | \\ foo; |
| 751 | \\} | 767 | \\} |
| 752 | , &[_][]const u8{ | 768 | , &[_][]const u8{ |
| 753 | "tmp.zig:1:1: error: unable to infer variable type", | 769 | "tmp.zig:1:8: error: unable to infer variable type", |
| 754 | }); | 770 | }); |
| 755 | | 771 | |
| 756 | cases.add("@src outside function", | 772 | ctx.objErrStage1("@src outside function", |
| 757 | \\comptime { | 773 | \\comptime { |
| 758 | \\ @src(); | 774 | \\ @src(); |
| 759 | \\} | 775 | \\} |
| ... | @@ -761,7 +777,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -761,7 +777,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 761 | "tmp.zig:2:5: error: @src outside function", | 777 | "tmp.zig:2:5: error: @src outside function", |
| 762 | }); | 778 | }); |
| 763 | | 779 | |
| 764 | cases.add("call assigned to constant", | 780 | ctx.objErrStage1("call assigned to constant", |
| 765 | \\const Foo = struct { | 781 | \\const Foo = struct { |
| 766 | \\ x: i32, | 782 | \\ x: i32, |
| 767 | \\}; | 783 | \\}; |
| ... | @@ -784,15 +800,15 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -784,15 +800,15 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 784 | "tmp.zig:16:14: error: cannot assign to constant", | 800 | "tmp.zig:16:14: error: cannot assign to constant", |
| 785 | }); | 801 | }); |
| 786 | | 802 | |
| 787 | cases.add("invalid pointer syntax", | 803 | ctx.objErrStage1("invalid pointer syntax", |
| 788 | \\export fn foo() void { | 804 | \\export fn foo() void { |
| 789 | \\ var guid: *:0 const u8 = undefined; | 805 | \\ var guid: *:0 const u8 = undefined; |
| 790 | \\} | 806 | \\} |
| 791 | , &[_][]const u8{ | 807 | , &[_][]const u8{ |
| 792 | "tmp.zig:2:15: error: sentinels are only allowed on unknown-length pointers", | 808 | "tmp.zig:2:16: error: expected type expression, found ':'", |
| 793 | }); | 809 | }); |
| 794 | | 810 | |
| 795 | cases.add("declaration between fields", | 811 | ctx.objErrStage1("declaration between fields", |
| 796 | \\const S = struct { | 812 | \\const S = struct { |
| 797 | \\ const foo = 2; | 813 | \\ const foo = 2; |
| 798 | \\ const bar = 2; | 814 | \\ const bar = 2; |
| ... | @@ -810,16 +826,16 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -810,16 +826,16 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 810 | "tmp.zig:6:5: error: declarations are not allowed between container fields", | 826 | "tmp.zig:6:5: error: declarations are not allowed between container fields", |
| 811 | }); | 827 | }); |
| 812 | | 828 | |
| 813 | cases.add("non-extern function with var args", | 829 | ctx.objErrStage1("non-extern function with var args", |
| 814 | \\fn foo(args: ...) void {} | 830 | \\fn foo(args: ...) void {} |
| 815 | \\export fn entry() void { | 831 | \\export fn entry() void { |
| 816 | \\ foo(); | 832 | \\ foo(); |
| 817 | \\} | 833 | \\} |
| 818 | , &[_][]const u8{ | 834 | , &[_][]const u8{ |
| 819 | "tmp.zig:1:1: error: non-extern function is variadic", | 835 | "tmp.zig:1:14: error: expected type expression, found '...'", |
| 820 | }); | 836 | }); |
| 821 | | 837 | |
| 822 | cases.addTest("invalid int casts", | 838 | ctx.testErrStage1("invalid int casts", |
| 823 | \\export fn foo() void { | 839 | \\export fn foo() void { |
| 824 | \\ var a: u32 = 2; | 840 | \\ var a: u32 = 2; |
| 825 | \\ _ = @intCast(comptime_int, a); | 841 | \\ _ = @intCast(comptime_int, a); |
| ... | @@ -847,7 +863,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -847,7 +863,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 847 | "tmp.zig:15:9: note: referenced here", | 863 | "tmp.zig:15:9: note: referenced here", |
| 848 | }); | 864 | }); |
| 849 | | 865 | |
| 850 | cases.addTest("invalid float casts", | 866 | ctx.testErrStage1("invalid float casts", |
| 851 | \\export fn foo() void { | 867 | \\export fn foo() void { |
| 852 | \\ var a: f32 = 2; | 868 | \\ var a: f32 = 2; |
| 853 | \\ _ = @floatCast(comptime_float, a); | 869 | \\ _ = @floatCast(comptime_float, a); |
| ... | @@ -875,7 +891,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -875,7 +891,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 875 | "tmp.zig:15:9: note: referenced here", | 891 | "tmp.zig:15:9: note: referenced here", |
| 876 | }); | 892 | }); |
| 877 | | 893 | |
| 878 | cases.addTest("invalid assignments", | 894 | ctx.testErrStage1("invalid assignments", |
| 879 | \\export fn entry1() void { | 895 | \\export fn entry1() void { |
| 880 | \\ var a: []const u8 = "foo"; | 896 | \\ var a: []const u8 = "foo"; |
| 881 | \\ a[0..2] = "bar"; | 897 | \\ a[0..2] = "bar"; |
| ... | @@ -893,7 +909,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -893,7 +909,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 893 | "tmp.zig:10:7: error: invalid left-hand side to assignment", | 909 | "tmp.zig:10:7: error: invalid left-hand side to assignment", |
| 894 | }); | 910 | }); |
| 895 | | 911 | |
| 896 | cases.addTest("reassign to array parameter", | 912 | ctx.testErrStage1("reassign to array parameter", |
| 897 | \\fn reassign(a: [3]f32) void { | 913 | \\fn reassign(a: [3]f32) void { |
| 898 | \\ a = [3]f32{4, 5, 6}; | 914 | \\ a = [3]f32{4, 5, 6}; |
| 899 | \\} | 915 | \\} |
| ... | @@ -904,7 +920,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -904,7 +920,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 904 | "tmp.zig:2:15: error: cannot assign to constant", | 920 | "tmp.zig:2:15: error: cannot assign to constant", |
| 905 | }); | 921 | }); |
| 906 | | 922 | |
| 907 | cases.addTest("reassign to slice parameter", | 923 | ctx.testErrStage1("reassign to slice parameter", |
| 908 | \\pub fn reassign(s: []const u8) void { | 924 | \\pub fn reassign(s: []const u8) void { |
| 909 | \\ s = s[0..]; | 925 | \\ s = s[0..]; |
| 910 | \\} | 926 | \\} |
| ... | @@ -915,7 +931,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -915,7 +931,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 915 | "tmp.zig:2:10: error: cannot assign to constant", | 931 | "tmp.zig:2:10: error: cannot assign to constant", |
| 916 | }); | 932 | }); |
| 917 | | 933 | |
| 918 | cases.addTest("reassign to struct parameter", | 934 | ctx.testErrStage1("reassign to struct parameter", |
| 919 | \\const S = struct { | 935 | \\const S = struct { |
| 920 | \\ x: u32, | 936 | \\ x: u32, |
| 921 | \\}; | 937 | \\}; |
| ... | @@ -929,7 +945,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -929,7 +945,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 929 | "tmp.zig:5:10: error: cannot assign to constant", | 945 | "tmp.zig:5:10: error: cannot assign to constant", |
| 930 | }); | 946 | }); |
| 931 | | 947 | |
| 932 | cases.addTest("reference to const data", | 948 | ctx.testErrStage1("reference to const data", |
| 933 | \\export fn foo() void { | 949 | \\export fn foo() void { |
| 934 | \\ var ptr = &[_]u8{0,0,0,0}; | 950 | \\ var ptr = &[_]u8{0,0,0,0}; |
| 935 | \\ ptr[1] = 2; | 951 | \\ ptr[1] = 2; |
| ... | @@ -957,7 +973,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -957,7 +973,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 957 | "tmp.zig:19:13: error: cannot assign to constant", | 973 | "tmp.zig:19:13: error: cannot assign to constant", |
| 958 | }); | 974 | }); |
| 959 | | 975 | |
| 960 | cases.addTest("cast between ?T where T is not a pointer", | 976 | ctx.testErrStage1("cast between ?T where T is not a pointer", |
| 961 | \\pub const fnty1 = ?fn (i8) void; | 977 | \\pub const fnty1 = ?fn (i8) void; |
| 962 | \\pub const fnty2 = ?fn (u64) void; | 978 | \\pub const fnty2 = ?fn (u64) void; |
| 963 | \\export fn entry() void { | 979 | \\export fn entry() void { |
| ... | @@ -970,7 +986,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -970,7 +986,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 970 | "tmp.zig:6:9: note: optional type child 'fn(u64) void' cannot cast into optional type child 'fn(i8) void'", | 986 | "tmp.zig:6:9: note: optional type child 'fn(u64) void' cannot cast into optional type child 'fn(i8) void'", |
| 971 | }); | 987 | }); |
| 972 | | 988 | |
| 973 | cases.addTest("unused variable error on errdefer", | 989 | ctx.testErrStage1("unused variable error on errdefer", |
| 974 | \\fn foo() !void { | 990 | \\fn foo() !void { |
| 975 | \\ errdefer |a| unreachable; | 991 | \\ errdefer |a| unreachable; |
| 976 | \\ return error.A; | 992 | \\ return error.A; |
| ... | @@ -982,18 +998,19 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -982,18 +998,19 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 982 | "tmp.zig:2:15: error: unused variable: 'a'", | 998 | "tmp.zig:2:15: error: unused variable: 'a'", |
| 983 | }); | 999 | }); |
| 984 | | 1000 | |
| 985 | cases.addTest("comparison of non-tagged union and enum literal", | 1001 | ctx.testErrStage1("comparison of non-tagged union and enum literal", |
| 986 | \\export fn entry() void { | 1002 | \\export fn entry() void { |
| 987 | \\ const U = union { A: u32, B: u64 }; | 1003 | \\ const U = union { A: u32, B: u64 }; |
| 988 | \\ var u = U{ .A = 42 }; | 1004 | \\ var u = U{ .A = 42 }; |
| 989 | \\ var ok = u == .A; | 1005 | \\ var ok = u == .A; |
| | 1006 | \\ _ = ok; |
| 990 | \\} | 1007 | \\} |
| 991 | , &[_][]const u8{ | 1008 | , &[_][]const u8{ |
| 992 | "tmp.zig:4:16: error: comparison of union and enum literal is only valid for tagged union types", | 1009 | "tmp.zig:4:16: error: comparison of union and enum literal is only valid for tagged union types", |
| 993 | "tmp.zig:2:15: note: type U is not a tagged union", | 1010 | "tmp.zig:2:15: note: type U is not a tagged union", |
| 994 | }); | 1011 | }); |
| 995 | | 1012 | |
| 996 | cases.addTest("shift on type with non-power-of-two size", | 1013 | ctx.testErrStage1("shift on type with non-power-of-two size", |
| 997 | \\export fn entry() void { | 1014 | \\export fn entry() void { |
| 998 | \\ const S = struct { | 1015 | \\ const S = struct { |
| 999 | \\ fn a() void { | 1016 | \\ fn a() void { |
| ... | @@ -1025,7 +1042,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -1025,7 +1042,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1025 | "tmp.zig:17:17: error: RHS of shift is too large for LHS type", | 1042 | "tmp.zig:17:17: error: RHS of shift is too large for LHS type", |
| 1026 | }); | 1043 | }); |
| 1027 | | 1044 | |
| 1028 | cases.addTest("combination of nosuspend and async", | 1045 | ctx.testErrStage1("combination of nosuspend and async", |
| 1029 | \\export fn entry() void { | 1046 | \\export fn entry() void { |
| 1030 | \\ nosuspend { | 1047 | \\ nosuspend { |
| 1031 | \\ const bar = async foo(); | 1048 | \\ const bar = async foo(); |
| ... | @@ -1035,10 +1052,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -1035,10 +1052,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1035 | \\} | 1052 | \\} |
| 1036 | \\fn foo() void {} | 1053 | \\fn foo() void {} |
| 1037 | , &[_][]const u8{ | 1054 | , &[_][]const u8{ |
| 1038 | "tmp.zig:4:9: error: suspend in nosuspend scope", | 1055 | "tmp.zig:4:9: error: suspend inside nosuspend block", |
| | 1056 | "tmp.zig:2:5: note: nosuspend block here", |
| 1039 | }); | 1057 | }); |
| 1040 | | 1058 | |
| 1041 | cases.add("atomicrmw with bool op not .Xchg", | 1059 | ctx.objErrStage1("atomicrmw with bool op not .Xchg", |
| 1042 | \\export fn entry() void { | 1060 | \\export fn entry() void { |
| 1043 | \\ var x = false; | 1061 | \\ var x = false; |
| 1044 | \\ _ = @atomicRmw(bool, &x, .Add, true, .SeqCst); | 1062 | \\ _ = @atomicRmw(bool, &x, .Add, true, .SeqCst); |
| ... | @@ -1047,7 +1065,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -1047,7 +1065,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1047 | "tmp.zig:3:30: error: @atomicRmw with bool only allowed with .Xchg", | 1065 | "tmp.zig:3:30: error: @atomicRmw with bool only allowed with .Xchg", |
| 1048 | }); | 1066 | }); |
| 1049 | | 1067 | |
| 1050 | cases.addTest("@TypeOf with no arguments", | 1068 | ctx.testErrStage1("@TypeOf with no arguments", |
| 1051 | \\export fn entry() void { | 1069 | \\export fn entry() void { |
| 1052 | \\ _ = @TypeOf(); | 1070 | \\ _ = @TypeOf(); |
| 1053 | \\} | 1071 | \\} |
| ... | @@ -1055,7 +1073,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -1055,7 +1073,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1055 | "tmp.zig:2:9: error: expected at least 1 argument, found 0", | 1073 | "tmp.zig:2:9: error: expected at least 1 argument, found 0", |
| 1056 | }); | 1074 | }); |
| 1057 | | 1075 | |
| 1058 | cases.addTest("@TypeOf with incompatible arguments", | 1076 | ctx.testErrStage1("@TypeOf with incompatible arguments", |
| 1059 | \\export fn entry() void { | 1077 | \\export fn entry() void { |
| 1060 | \\ var var_1: f32 = undefined; | 1078 | \\ var var_1: f32 = undefined; |
| 1061 | \\ var var_2: u32 = undefined; | 1079 | \\ var var_2: u32 = undefined; |
| ... | @@ -1065,7 +1083,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -1065,7 +1083,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1065 | "tmp.zig:4:9: error: incompatible types: 'f32' and 'u32'", | 1083 | "tmp.zig:4:9: error: incompatible types: 'f32' and 'u32'", |
| 1066 | }); | 1084 | }); |
| 1067 | | 1085 | |
| 1068 | cases.addTest("type mismatch with tuple concatenation", | 1086 | ctx.testErrStage1("type mismatch with tuple concatenation", |
| 1069 | \\export fn entry() void { | 1087 | \\export fn entry() void { |
| 1070 | \\ var x = .{}; | 1088 | \\ var x = .{}; |
| 1071 | \\ x = x ++ .{ 1, 2, 3 }; | 1089 | \\ x = x ++ .{ 1, 2, 3 }; |
| ... | @@ -1074,7 +1092,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -1074,7 +1092,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1074 | "tmp.zig:3:11: error: expected type 'struct:2:14', found 'struct:3:11'", | 1092 | "tmp.zig:3:11: error: expected type 'struct:2:14', found 'struct:3:11'", |
| 1075 | }); | 1093 | }); |
| 1076 | | 1094 | |
| 1077 | cases.addTest("@tagName on invalid value of non-exhaustive enum", | 1095 | ctx.testErrStage1("@tagName on invalid value of non-exhaustive enum", |
| 1078 | \\test "enum" { | 1096 | \\test "enum" { |
| 1079 | \\ const E = enum(u8) {A, B, _}; | 1097 | \\ const E = enum(u8) {A, B, _}; |
| 1080 | \\ _ = @tagName(@intToEnum(E, 5)); | 1098 | \\ _ = @tagName(@intToEnum(E, 5)); |
| ... | @@ -1083,16 +1101,17 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -1083,16 +1101,17 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1083 | "tmp.zig:3:18: error: no tag by value 5", | 1101 | "tmp.zig:3:18: error: no tag by value 5", |
| 1084 | }); | 1102 | }); |
| 1085 | | 1103 | |
| 1086 | cases.addTest("@ptrToInt with pointer to zero-sized type", | 1104 | ctx.testErrStage1("@ptrToInt with pointer to zero-sized type", |
| 1087 | \\export fn entry() void { | 1105 | \\export fn entry() void { |
| 1088 | \\ var pointer: ?*u0 = null; | 1106 | \\ var pointer: ?*u0 = null; |
| 1089 | \\ var x = @ptrToInt(pointer); | 1107 | \\ var x = @ptrToInt(pointer); |
| | 1108 | \\ _ = x; |
| 1090 | \\} | 1109 | \\} |
| 1091 | , &[_][]const u8{ | 1110 | , &[_][]const u8{ |
| 1092 | "tmp.zig:3:23: error: pointer to size 0 type has no address", | 1111 | "tmp.zig:3:23: error: pointer to size 0 type has no address", |
| 1093 | }); | 1112 | }); |
| 1094 | | 1113 | |
| 1095 | cases.addTest("access invalid @typeInfo decl", | 1114 | ctx.testErrStage1("access invalid @typeInfo decl", |
| 1096 | \\const A = B; | 1115 | \\const A = B; |
| 1097 | \\test "Crash" { | 1116 | \\test "Crash" { |
| 1098 | \\ _ = @typeInfo(@This()).Struct.decls[0]; | 1117 | \\ _ = @typeInfo(@This()).Struct.decls[0]; |
| ... | @@ -1101,7 +1120,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -1101,7 +1120,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1101 | "tmp.zig:1:11: error: use of undeclared identifier 'B'", | 1120 | "tmp.zig:1:11: error: use of undeclared identifier 'B'", |
| 1102 | }); | 1121 | }); |
| 1103 | | 1122 | |
| 1104 | cases.addTest("reject extern function definitions with body", | 1123 | ctx.testErrStage1("reject extern function definitions with body", |
| 1105 | \\extern "c" fn definitelyNotInLibC(a: i32, b: i32) i32 { | 1124 | \\extern "c" fn definitelyNotInLibC(a: i32, b: i32) i32 { |
| 1106 | \\ return a + b; | 1125 | \\ return a + b; |
| 1107 | \\} | 1126 | \\} |
| ... | @@ -1109,7 +1128,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -1109,7 +1128,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1109 | "tmp.zig:1:1: error: extern functions have no body", | 1128 | "tmp.zig:1:1: error: extern functions have no body", |
| 1110 | }); | 1129 | }); |
| 1111 | | 1130 | |
| 1112 | cases.addTest("duplicate field in anonymous struct literal", | 1131 | ctx.testErrStage1("duplicate field in anonymous struct literal", |
| 1113 | \\export fn entry() void { | 1132 | \\export fn entry() void { |
| 1114 | \\ const anon = .{ | 1133 | \\ const anon = .{ |
| 1115 | \\ .inner = .{ | 1134 | \\ .inner = .{ |
| ... | @@ -1119,31 +1138,33 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -1119,31 +1138,33 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1119 | \\ .a = .{}, | 1138 | \\ .a = .{}, |
| 1120 | \\ }, | 1139 | \\ }, |
| 1121 | \\ }; | 1140 | \\ }; |
| | 1141 | \\ _ = anon; |
| 1122 | \\} | 1142 | \\} |
| 1123 | , &[_][]const u8{ | 1143 | , &[_][]const u8{ |
| 1124 | "tmp.zig:7:13: error: duplicate field", | 1144 | "tmp.zig:7:13: error: duplicate field", |
| 1125 | "tmp.zig:4:13: note: other field here", | 1145 | "tmp.zig:4:13: note: other field here", |
| 1126 | }); | 1146 | }); |
| 1127 | | 1147 | |
| 1128 | cases.addTest("type mismatch in C prototype with varargs", | 1148 | ctx.testErrStage1("type mismatch in C prototype with varargs", |
| 1129 | \\const fn_ty = ?fn ([*c]u8, ...) callconv(.C) void; | 1149 | \\const fn_ty = ?fn ([*c]u8, ...) callconv(.C) void; |
| 1130 | \\extern fn fn_decl(fmt: [*:0]u8, ...) void; | 1150 | \\extern fn fn_decl(fmt: [*:0]u8, ...) void; |
| 1131 | \\ | 1151 | \\ |
| 1132 | \\export fn main() void { | 1152 | \\export fn main() void { |
| 1133 | \\ const x: fn_ty = fn_decl; | 1153 | \\ const x: fn_ty = fn_decl; |
| | 1154 | \\ _ = x; |
| 1134 | \\} | 1155 | \\} |
| 1135 | , &[_][]const u8{ | 1156 | , &[_][]const u8{ |
| 1136 | "tmp.zig:5:22: error: expected type 'fn([*c]u8, ...) callconv(.C) void', found 'fn([*:0]u8, ...) callconv(.C) void'", | 1157 | "tmp.zig:5:22: error: expected type 'fn([*c]u8, ...) callconv(.C) void', found 'fn([*:0]u8, ...) callconv(.C) void'", |
| 1137 | }); | 1158 | }); |
| 1138 | | 1159 | |
| 1139 | cases.addTest("dependency loop in top-level decl with @TypeInfo when accessing the decls", | 1160 | ctx.testErrStage1("dependency loop in top-level decl with @TypeInfo when accessing the decls", |
| 1140 | \\export const foo = @typeInfo(@This()).Struct.decls; | 1161 | \\export const foo = @typeInfo(@This()).Struct.decls; |
| 1141 | , &[_][]const u8{ | 1162 | , &[_][]const u8{ |
| 1142 | "tmp.zig:1:20: error: dependency loop detected", | 1163 | "tmp.zig:1:20: error: dependency loop detected", |
| 1143 | "tmp.zig:1:45: note: referenced here", | 1164 | "tmp.zig:1:45: note: referenced here", |
| 1144 | }); | 1165 | }); |
| 1145 | | 1166 | |
| 1146 | cases.add("function call assigned to incorrect type", | 1167 | ctx.objErrStage1("function call assigned to incorrect type", |
| 1147 | \\export fn entry() void { | 1168 | \\export fn entry() void { |
| 1148 | \\ var arr: [4]f32 = undefined; | 1169 | \\ var arr: [4]f32 = undefined; |
| 1149 | \\ arr = concat(); | 1170 | \\ arr = concat(); |
| ... | @@ -1155,7 +1176,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -1155,7 +1176,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1155 | "tmp.zig:3:17: error: expected type '[4]f32', found '[16]f32'", | 1176 | "tmp.zig:3:17: error: expected type '[4]f32', found '[16]f32'", |
| 1156 | }); | 1177 | }); |
| 1157 | | 1178 | |
| 1158 | cases.add("generic function call assigned to incorrect type", | 1179 | ctx.objErrStage1("generic function call assigned to incorrect type", |
| 1159 | \\pub export fn entry() void { | 1180 | \\pub export fn entry() void { |
| 1160 | \\ var res: []i32 = undefined; | 1181 | \\ var res: []i32 = undefined; |
| 1161 | \\ res = myAlloc(i32); | 1182 | \\ res = myAlloc(i32); |
| ... | @@ -1167,12 +1188,25 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -1167,12 +1188,25 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1167 | "tmp.zig:3:18: error: expected type '[]i32', found 'anyerror!i32", | 1188 | "tmp.zig:3:18: error: expected type '[]i32', found 'anyerror!i32", |
| 1168 | }); | 1189 | }); |
| 1169 | | 1190 | |
| 1170 | cases.addTest("non-exhaustive enums", | 1191 | ctx.testErrStage1("non-exhaustive enum marker assigned a value", |
| 1171 | \\const A = enum { | 1192 | \\const A = enum { |
| 1172 | \\ a, | 1193 | \\ a, |
| 1173 | \\ b, | 1194 | \\ b, |
| 1174 | \\ _ = 1, | 1195 | \\ _ = 1, |
| 1175 | \\}; | 1196 | \\}; |
| | 1197 | \\const B = enum { |
| | 1198 | \\ a, |
| | 1199 | \\ b, |
| | 1200 | \\ _, |
| | 1201 | \\}; |
| | 1202 | \\comptime { _ = A; _ = B; } |
| | 1203 | , &[_][]const u8{ |
| | 1204 | "tmp.zig:4:9: error: '_' is used to mark an enum as non-exhaustive and cannot be assigned a value", |
| | 1205 | "tmp.zig:6:11: error: non-exhaustive enum missing integer tag type", |
| | 1206 | "tmp.zig:9:5: note: marked non-exhaustive here", |
| | 1207 | }); |
| | 1208 | |
| | 1209 | ctx.testErrStage1("non-exhaustive enums", |
| 1176 | \\const B = enum(u1) { | 1210 | \\const B = enum(u1) { |
| 1177 | \\ a, | 1211 | \\ a, |
| 1178 | \\ _, | 1212 | \\ _, |
| ... | @@ -1184,18 +1218,15 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -1184,18 +1218,15 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1184 | \\ _, | 1218 | \\ _, |
| 1185 | \\}; | 1219 | \\}; |
| 1186 | \\pub export fn entry() void { | 1220 | \\pub export fn entry() void { |
| 1187 | \\ _ = A; | | |
| 1188 | \\ _ = B; | 1221 | \\ _ = B; |
| 1189 | \\ _ = C; | 1222 | \\ _ = C; |
| 1190 | \\} | 1223 | \\} |
| 1191 | , &[_][]const u8{ | 1224 | , &[_][]const u8{ |
| 1192 | "tmp.zig:4:5: error: value assigned to '_' field of non-exhaustive enum", | 1225 | "tmp.zig:3:5: error: '_' field of non-exhaustive enum must be last", |
| 1193 | "error: non-exhaustive enum must specify size", | 1226 | "tmp.zig:6:11: error: non-exhaustive enum specifies every value", |
| 1194 | "error: non-exhaustive enum specifies every value", | | |
| 1195 | "error: '_' field of non-exhaustive enum must be last", | | |
| 1196 | }); | 1227 | }); |
| 1197 | | 1228 | |
| 1198 | cases.addTest("switching with non-exhaustive enums", | 1229 | ctx.testErrStage1("switching with non-exhaustive enums", |
| 1199 | \\const E = enum(u8) { | 1230 | \\const E = enum(u8) { |
| 1200 | \\ a, | 1231 | \\ a, |
| 1201 | \\ b, | 1232 | \\ b, |
| ... | @@ -1228,7 +1259,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -1228,7 +1259,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1228 | "tmp.zig:21:5: error: `_` prong not allowed when switching on tagged union", | 1259 | "tmp.zig:21:5: error: `_` prong not allowed when switching on tagged union", |
| 1229 | }); | 1260 | }); |
| 1230 | | 1261 | |
| 1231 | cases.add("switch expression - unreachable else prong (bool)", | 1262 | ctx.objErrStage1("switch expression - unreachable else prong (bool)", |
| 1232 | \\fn foo(x: bool) void { | 1263 | \\fn foo(x: bool) void { |
| 1233 | \\ switch (x) { | 1264 | \\ switch (x) { |
| 1234 | \\ true => {}, | 1265 | \\ true => {}, |
| ... | @@ -1241,7 +1272,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -1241,7 +1272,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1241 | "tmp.zig:5:9: error: unreachable else prong, all cases already handled", | 1272 | "tmp.zig:5:9: error: unreachable else prong, all cases already handled", |
| 1242 | }); | 1273 | }); |
| 1243 | | 1274 | |
| 1244 | cases.add("switch expression - unreachable else prong (u1)", | 1275 | ctx.objErrStage1("switch expression - unreachable else prong (u1)", |
| 1245 | \\fn foo(x: u1) void { | 1276 | \\fn foo(x: u1) void { |
| 1246 | \\ switch (x) { | 1277 | \\ switch (x) { |
| 1247 | \\ 0 => {}, | 1278 | \\ 0 => {}, |
| ... | @@ -1254,7 +1285,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -1254,7 +1285,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1254 | "tmp.zig:5:9: error: unreachable else prong, all cases already handled", | 1285 | "tmp.zig:5:9: error: unreachable else prong, all cases already handled", |
| 1255 | }); | 1286 | }); |
| 1256 | | 1287 | |
| 1257 | cases.add("switch expression - unreachable else prong (u2)", | 1288 | ctx.objErrStage1("switch expression - unreachable else prong (u2)", |
| 1258 | \\fn foo(x: u2) void { | 1289 | \\fn foo(x: u2) void { |
| 1259 | \\ switch (x) { | 1290 | \\ switch (x) { |
| 1260 | \\ 0 => {}, | 1291 | \\ 0 => {}, |
| ... | @@ -1269,7 +1300,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -1269,7 +1300,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1269 | "tmp.zig:7:9: error: unreachable else prong, all cases already handled", | 1300 | "tmp.zig:7:9: error: unreachable else prong, all cases already handled", |
| 1270 | }); | 1301 | }); |
| 1271 | | 1302 | |
| 1272 | cases.add("switch expression - unreachable else prong (range u8)", | 1303 | ctx.objErrStage1("switch expression - unreachable else prong (range u8)", |
| 1273 | \\fn foo(x: u8) void { | 1304 | \\fn foo(x: u8) void { |
| 1274 | \\ switch (x) { | 1305 | \\ switch (x) { |
| 1275 | \\ 0 => {}, | 1306 | \\ 0 => {}, |
| ... | @@ -1285,7 +1316,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -1285,7 +1316,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1285 | "tmp.zig:8:9: error: unreachable else prong, all cases already handled", | 1316 | "tmp.zig:8:9: error: unreachable else prong, all cases already handled", |
| 1286 | }); | 1317 | }); |
| 1287 | | 1318 | |
| 1288 | cases.add("switch expression - unreachable else prong (range i8)", | 1319 | ctx.objErrStage1("switch expression - unreachable else prong (range i8)", |
| 1289 | \\fn foo(x: i8) void { | 1320 | \\fn foo(x: i8) void { |
| 1290 | \\ switch (x) { | 1321 | \\ switch (x) { |
| 1291 | \\ -128...0 => {}, | 1322 | \\ -128...0 => {}, |
| ... | @@ -1301,7 +1332,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -1301,7 +1332,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1301 | "tmp.zig:8:9: error: unreachable else prong, all cases already handled", | 1332 | "tmp.zig:8:9: error: unreachable else prong, all cases already handled", |
| 1302 | }); | 1333 | }); |
| 1303 | | 1334 | |
| 1304 | cases.add("switch expression - unreachable else prong (enum)", | 1335 | ctx.objErrStage1("switch expression - unreachable else prong (enum)", |
| 1305 | \\const TestEnum = enum{ T1, T2 }; | 1336 | \\const TestEnum = enum{ T1, T2 }; |
| 1306 | \\ | 1337 | \\ |
| 1307 | \\fn err(x: u8) TestEnum { | 1338 | \\fn err(x: u8) TestEnum { |
| ... | @@ -1324,7 +1355,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -1324,7 +1355,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1324 | "tmp.zig:14:9: error: unreachable else prong, all cases already handled", | 1355 | "tmp.zig:14:9: error: unreachable else prong, all cases already handled", |
| 1325 | }); | 1356 | }); |
| 1326 | | 1357 | |
| 1327 | cases.addTest("@export with empty name string", | 1358 | ctx.testErrStage1("@export with empty name string", |
| 1328 | \\pub export fn entry() void { } | 1359 | \\pub export fn entry() void { } |
| 1329 | \\comptime { | 1360 | \\comptime { |
| 1330 | \\ @export(entry, .{ .name = "" }); | 1361 | \\ @export(entry, .{ .name = "" }); |
| ... | @@ -1333,7 +1364,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -1333,7 +1364,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1333 | "tmp.zig:3:5: error: exported symbol name cannot be empty", | 1364 | "tmp.zig:3:5: error: exported symbol name cannot be empty", |
| 1334 | }); | 1365 | }); |
| 1335 | | 1366 | |
| 1336 | cases.addTest("switch ranges endpoints are validated", | 1367 | ctx.testErrStage1("switch ranges endpoints are validated", |
| 1337 | \\pub export fn entry() void { | 1368 | \\pub export fn entry() void { |
| 1338 | \\ var x: i32 = 0; | 1369 | \\ var x: i32 = 0; |
| 1339 | \\ switch (x) { | 1370 | \\ switch (x) { |
| ... | @@ -1347,16 +1378,16 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -1347,16 +1378,16 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1347 | "tmp.zig:5:9: error: range start value is greater than the end value", | 1378 | "tmp.zig:5:9: error: range start value is greater than the end value", |
| 1348 | }); | 1379 | }); |
| 1349 | | 1380 | |
| 1350 | cases.addTest("errors in for loop bodies are propagated", | 1381 | ctx.testErrStage1("errors in for loop bodies are propagated", |
| 1351 | \\pub export fn entry() void { | 1382 | \\pub export fn entry() void { |
| 1352 | \\ var arr: [100]u8 = undefined; | 1383 | \\ var arr: [100]u8 = undefined; |
| 1353 | \\ for (arr) |bits| _ = @popCount(bits); | 1384 | \\ for (arr) |bits| _ = @popCount(bits); |
| 1354 | \\} | 1385 | \\} |
| 1355 | , &[_][]const u8{ | 1386 | , &[_][]const u8{ |
| 1356 | "tmp.zig:3:26: error: expected 2 argument(s), found 1", | 1387 | "tmp.zig:3:26: error: expected 2 arguments, found 1", |
| 1357 | }); | 1388 | }); |
| 1358 | | 1389 | |
| 1359 | cases.addTest("@call rejects non comptime-known fn - always_inline", | 1390 | ctx.testErrStage1("@call rejects non comptime-known fn - always_inline", |
| 1360 | \\pub export fn entry() void { | 1391 | \\pub export fn entry() void { |
| 1361 | \\ var call_me: fn () void = undefined; | 1392 | \\ var call_me: fn () void = undefined; |
| 1362 | \\ @call(.{ .modifier = .always_inline }, call_me, .{}); | 1393 | \\ @call(.{ .modifier = .always_inline }, call_me, .{}); |
| ... | @@ -1365,7 +1396,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -1365,7 +1396,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1365 | "tmp.zig:3:5: error: the specified modifier requires a comptime-known function", | 1396 | "tmp.zig:3:5: error: the specified modifier requires a comptime-known function", |
| 1366 | }); | 1397 | }); |
| 1367 | | 1398 | |
| 1368 | cases.addTest("@call rejects non comptime-known fn - compile_time", | 1399 | ctx.testErrStage1("@call rejects non comptime-known fn - compile_time", |
| 1369 | \\pub export fn entry() void { | 1400 | \\pub export fn entry() void { |
| 1370 | \\ var call_me: fn () void = undefined; | 1401 | \\ var call_me: fn () void = undefined; |
| 1371 | \\ @call(.{ .modifier = .compile_time }, call_me, .{}); | 1402 | \\ @call(.{ .modifier = .compile_time }, call_me, .{}); |
| ... | @@ -1374,19 +1405,20 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -1374,19 +1405,20 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1374 | "tmp.zig:3:5: error: the specified modifier requires a comptime-known function", | 1405 | "tmp.zig:3:5: error: the specified modifier requires a comptime-known function", |
| 1375 | }); | 1406 | }); |
| 1376 | | 1407 | |
| 1377 | cases.addTest("error in struct initializer doesn't crash the compiler", | 1408 | ctx.testErrStage1("error in struct initializer doesn't crash the compiler", |
| 1378 | \\pub export fn entry() void { | 1409 | \\pub export fn entry() void { |
| 1379 | \\ const bitfield = struct { | 1410 | \\ const bitfield = struct { |
| 1380 | \\ e: u8, | 1411 | \\ e: u8, |
| 1381 | \\ e: u8, | 1412 | \\ e: u8, |
| 1382 | \\ }; | 1413 | \\ }; |
| 1383 | \\ var a = .{@sizeOf(bitfield)}; | 1414 | \\ var a = .{@sizeOf(bitfield)}; |
| | 1415 | \\ _ = a; |
| 1384 | \\} | 1416 | \\} |
| 1385 | , &[_][]const u8{ | 1417 | , &[_][]const u8{ |
| 1386 | "tmp.zig:4:9: error: duplicate struct field: 'e'", | 1418 | "tmp.zig:4:9: error: duplicate struct field: 'e'", |
| 1387 | }); | 1419 | }); |
| 1388 | | 1420 | |
| 1389 | cases.addTest("repeated invalid field access to generic function returning type crashes compiler. #2655", | 1421 | ctx.testErrStage1("repeated invalid field access to generic function returning type crashes compiler. #2655", |
| 1390 | \\pub fn A() type { | 1422 | \\pub fn A() type { |
| 1391 | \\ return Q; | 1423 | \\ return Q; |
| 1392 | \\} | 1424 | \\} |
| ... | @@ -1398,15 +1430,16 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -1398,15 +1430,16 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1398 | "tmp.zig:2:12: error: use of undeclared identifier 'Q'", | 1430 | "tmp.zig:2:12: error: use of undeclared identifier 'Q'", |
| 1399 | }); | 1431 | }); |
| 1400 | | 1432 | |
| 1401 | cases.add("bitCast to enum type", | 1433 | ctx.objErrStage1("bitCast to enum type", |
| 1402 | \\export fn entry() void { | 1434 | \\export fn entry() void { |
| 1403 | \\ const y = @bitCast(enum(u32) { a, b }, @as(u32, 3)); | 1435 | \\ const y = @bitCast(enum(u32) { a, b }, @as(u32, 3)); |
| | 1436 | \\ _ = y; |
| 1404 | \\} | 1437 | \\} |
| 1405 | , &[_][]const u8{ | 1438 | , &[_][]const u8{ |
| 1406 | "tmp.zig:2:24: error: cannot cast a value of type 'y'", | 1439 | "tmp.zig:2:24: error: cannot cast a value of type 'y'", |
| 1407 | }); | 1440 | }); |
| 1408 | | 1441 | |
| 1409 | cases.add("comparing against undefined produces undefined value", | 1442 | ctx.objErrStage1("comparing against undefined produces undefined value", |
| 1410 | \\export fn entry() void { | 1443 | \\export fn entry() void { |
| 1411 | \\ if (2 == undefined) {} | 1444 | \\ if (2 == undefined) {} |
| 1412 | \\} | 1445 | \\} |
| ... | @@ -1414,17 +1447,18 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -1414,17 +1447,18 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1414 | "tmp.zig:2:11: error: use of undefined value here causes undefined behavior", | 1447 | "tmp.zig:2:11: error: use of undefined value here causes undefined behavior", |
| 1415 | }); | 1448 | }); |
| 1416 | | 1449 | |
| 1417 | cases.add("comptime ptrcast of zero-sized type", | 1450 | ctx.objErrStage1("comptime ptrcast of zero-sized type", |
| 1418 | \\fn foo() void { | 1451 | \\fn foo() void { |
| 1419 | \\ const node: struct {} = undefined; | 1452 | \\ const node: struct {} = undefined; |
| 1420 | \\ const vla_ptr = @ptrCast([*]const u8, &node); | 1453 | \\ const vla_ptr = @ptrCast([*]const u8, &node); |
| | 1454 | \\ _ = vla_ptr; |
| 1421 | \\} | 1455 | \\} |
| 1422 | \\comptime { foo(); } | 1456 | \\comptime { foo(); } |
| 1423 | , &[_][]const u8{ | 1457 | , &[_][]const u8{ |
| 1424 | "tmp.zig:3:21: error: '*const struct:2:17' and '[*]const u8' do not have the same in-memory representation", | 1458 | "tmp.zig:3:21: error: '*const struct:2:17' and '[*]const u8' do not have the same in-memory representation", |
| 1425 | }); | 1459 | }); |
| 1426 | | 1460 | |
| 1427 | cases.add("slice sentinel mismatch", | 1461 | ctx.objErrStage1("slice sentinel mismatch", |
| 1428 | \\fn foo() [:0]u8 { | 1462 | \\fn foo() [:0]u8 { |
| 1429 | \\ var x: []u8 = undefined; | 1463 | \\ var x: []u8 = undefined; |
| 1430 | \\ return x; | 1464 | \\ return x; |
| ... | @@ -1435,7 +1469,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -1435,7 +1469,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1435 | "tmp.zig:3:12: note: destination pointer requires a terminating '0' sentinel", | 1469 | "tmp.zig:3:12: note: destination pointer requires a terminating '0' sentinel", |
| 1436 | }); | 1470 | }); |
| 1437 | | 1471 | |
| 1438 | cases.add("cmpxchg with float", | 1472 | ctx.objErrStage1("cmpxchg with float", |
| 1439 | \\export fn entry() void { | 1473 | \\export fn entry() void { |
| 1440 | \\ var x: f32 = 0; | 1474 | \\ var x: f32 = 0; |
| 1441 | \\ _ = @cmpxchgWeak(f32, &x, 1, 2, .SeqCst, .SeqCst); | 1475 | \\ _ = @cmpxchgWeak(f32, &x, 1, 2, .SeqCst, .SeqCst); |
| ... | @@ -1444,7 +1478,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -1444,7 +1478,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1444 | "tmp.zig:3:22: error: expected bool, integer, enum or pointer type, found 'f32'", | 1478 | "tmp.zig:3:22: error: expected bool, integer, enum or pointer type, found 'f32'", |
| 1445 | }); | 1479 | }); |
| 1446 | | 1480 | |
| 1447 | cases.add("atomicrmw with float op not .Xchg, .Add or .Sub", | 1481 | ctx.objErrStage1("atomicrmw with float op not .Xchg, .Add or .Sub", |
| 1448 | \\export fn entry() void { | 1482 | \\export fn entry() void { |
| 1449 | \\ var x: f32 = 0; | 1483 | \\ var x: f32 = 0; |
| 1450 | \\ _ = @atomicRmw(f32, &x, .And, 2, .SeqCst); | 1484 | \\ _ = @atomicRmw(f32, &x, .And, 2, .SeqCst); |
| ... | @@ -1453,15 +1487,16 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -1453,15 +1487,16 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1453 | "tmp.zig:3:29: error: @atomicRmw with float only allowed with .Xchg, .Add and .Sub", | 1487 | "tmp.zig:3:29: error: @atomicRmw with float only allowed with .Xchg, .Add and .Sub", |
| 1454 | }); | 1488 | }); |
| 1455 | | 1489 | |
| 1456 | cases.add("intToPtr with misaligned address", | 1490 | ctx.objErrStage1("intToPtr with misaligned address", |
| 1457 | \\pub fn main() void { | 1491 | \\pub fn main() void { |
| 1458 | \\ var y = @intToPtr([*]align(4) u8, 5); | 1492 | \\ var y = @intToPtr([*]align(4) u8, 5); |
| | 1493 | \\ _ = y; |
| 1459 | \\} | 1494 | \\} |
| 1460 | , &[_][]const u8{ | 1495 | , &[_][]const u8{ |
| 1461 | "tmp.zig:2:13: error: pointer type '[*]align(4) u8' requires aligned address", | 1496 | "tmp.zig:2:13: error: pointer type '[*]align(4) u8' requires aligned address", |
| 1462 | }); | 1497 | }); |
| 1463 | | 1498 | |
| 1464 | cases.add("invalid float literal", | 1499 | ctx.objErrStage1("invalid float literal", |
| 1465 | \\const std = @import("std"); | 1500 | \\const std = @import("std"); |
| 1466 | \\ | 1501 | \\ |
| 1467 | \\pub fn main() void { | 1502 | \\pub fn main() void { |
| ... | @@ -1473,170 +1508,209 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -1473,170 +1508,209 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1473 | "tmp.zig:5:29: error: invalid token: '.'", | 1508 | "tmp.zig:5:29: error: invalid token: '.'", |
| 1474 | }); | 1509 | }); |
| 1475 | | 1510 | |
| 1476 | cases.add("invalid exponent in float literal - 1", | 1511 | ctx.objErrStage1("invalid exponent in float literal - 1", |
| 1477 | \\fn main() void { | 1512 | \\fn main() void { |
| 1478 | \\ var bad: f128 = 0x1.0p1ab1; | 1513 | \\ var bad: f128 = 0x1.0p1ab1; |
| | 1514 | \\ _ = bad; |
| 1479 | \\} | 1515 | \\} |
| 1480 | , &[_][]const u8{ | 1516 | , &[_][]const u8{ |
| 1481 | "tmp.zig:2:28: error: invalid character: 'a'", | 1517 | "tmp.zig:2:21: error: expected expression, found 'invalid'", |
| | 1518 | "tmp.zig:2:28: note: invalid byte: 'a'", |
| 1482 | }); | 1519 | }); |
| 1483 | | 1520 | |
| 1484 | cases.add("invalid exponent in float literal - 2", | 1521 | ctx.objErrStage1("invalid exponent in float literal - 2", |
| 1485 | \\fn main() void { | 1522 | \\fn main() void { |
| 1486 | \\ var bad: f128 = 0x1.0p50F; | 1523 | \\ var bad: f128 = 0x1.0p50F; |
| | 1524 | \\ _ = bad; |
| 1487 | \\} | 1525 | \\} |
| 1488 | , &[_][]const u8{ | 1526 | , &[_][]const u8{ |
| 1489 | "tmp.zig:2:29: error: invalid character: 'F'", | 1527 | "tmp.zig:2:21: error: expected expression, found 'invalid'", |
| | 1528 | "tmp.zig:2:29: note: invalid byte: 'F'", |
| 1490 | }); | 1529 | }); |
| 1491 | | 1530 | |
| 1492 | cases.add("invalid underscore placement in float literal - 1", | 1531 | ctx.objErrStage1("invalid underscore placement in float literal - 1", |
| 1493 | \\fn main() void { | 1532 | \\fn main() void { |
| 1494 | \\ var bad: f128 = 0._0; | 1533 | \\ var bad: f128 = 0._0; |
| | 1534 | \\ _ = bad; |
| 1495 | \\} | 1535 | \\} |
| 1496 | , &[_][]const u8{ | 1536 | , &[_][]const u8{ |
| 1497 | "tmp.zig:2:23: error: invalid character: '_'", | 1537 | "tmp.zig:2:21: error: expected expression, found 'invalid'", |
| | 1538 | "tmp.zig:2:23: note: invalid byte: '_'", |
| 1498 | }); | 1539 | }); |
| 1499 | | 1540 | |
| 1500 | cases.add("invalid underscore placement in float literal - 2", | 1541 | ctx.objErrStage1("invalid underscore placement in float literal - 2", |
| 1501 | \\fn main() void { | 1542 | \\fn main() void { |
| 1502 | \\ var bad: f128 = 0_.0; | 1543 | \\ var bad: f128 = 0_.0; |
| | 1544 | \\ _ = bad; |
| 1503 | \\} | 1545 | \\} |
| 1504 | , &[_][]const u8{ | 1546 | , &[_][]const u8{ |
| 1505 | "tmp.zig:2:23: error: invalid character: '.'", | 1547 | "tmp.zig:2:21: error: expected expression, found 'invalid'", |
| | 1548 | "tmp.zig:2:23: note: invalid byte: '.'", |
| 1506 | }); | 1549 | }); |
| 1507 | | 1550 | |
| 1508 | cases.add("invalid underscore placement in float literal - 3", | 1551 | ctx.objErrStage1("invalid underscore placement in float literal - 3", |
| 1509 | \\fn main() void { | 1552 | \\fn main() void { |
| 1510 | \\ var bad: f128 = 0.0_; | 1553 | \\ var bad: f128 = 0.0_; |
| | 1554 | \\ _ = bad; |
| 1511 | \\} | 1555 | \\} |
| 1512 | , &[_][]const u8{ | 1556 | , &[_][]const u8{ |
| 1513 | "tmp.zig:2:25: error: invalid character: ';'", | 1557 | "tmp.zig:2:21: error: expected expression, found 'invalid'", |
| | 1558 | "tmp.zig:2:25: note: invalid byte: ';'", |
| 1514 | }); | 1559 | }); |
| 1515 | | 1560 | |
| 1516 | cases.add("invalid underscore placement in float literal - 4", | 1561 | ctx.objErrStage1("invalid underscore placement in float literal - 4", |
| 1517 | \\fn main() void { | 1562 | \\fn main() void { |
| 1518 | \\ var bad: f128 = 1.0e_1; | 1563 | \\ var bad: f128 = 1.0e_1; |
| | 1564 | \\ _ = bad; |
| 1519 | \\} | 1565 | \\} |
| 1520 | , &[_][]const u8{ | 1566 | , &[_][]const u8{ |
| 1521 | "tmp.zig:2:25: error: invalid character: '_'", | 1567 | "tmp.zig:2:21: error: expected expression, found 'invalid'", |
| | 1568 | "tmp.zig:2:25: note: invalid byte: '_'", |
| 1522 | }); | 1569 | }); |
| 1523 | | 1570 | |
| 1524 | cases.add("invalid underscore placement in float literal - 5", | 1571 | ctx.objErrStage1("invalid underscore placement in float literal - 5", |
| 1525 | \\fn main() void { | 1572 | \\fn main() void { |
| 1526 | \\ var bad: f128 = 1.0e+_1; | 1573 | \\ var bad: f128 = 1.0e+_1; |
| | 1574 | \\ _ = bad; |
| 1527 | \\} | 1575 | \\} |
| 1528 | , &[_][]const u8{ | 1576 | , &[_][]const u8{ |
| 1529 | "tmp.zig:2:26: error: invalid character: '_'", | 1577 | "tmp.zig:2:21: error: expected expression, found 'invalid'", |
| | 1578 | "tmp.zig:2:26: note: invalid byte: '_'", |
| 1530 | }); | 1579 | }); |
| 1531 | | 1580 | |
| 1532 | cases.add("invalid underscore placement in float literal - 6", | 1581 | ctx.objErrStage1("invalid underscore placement in float literal - 6", |
| 1533 | \\fn main() void { | 1582 | \\fn main() void { |
| 1534 | \\ var bad: f128 = 1.0e-_1; | 1583 | \\ var bad: f128 = 1.0e-_1; |
| | 1584 | \\ _ = bad; |
| 1535 | \\} | 1585 | \\} |
| 1536 | , &[_][]const u8{ | 1586 | , &[_][]const u8{ |
| 1537 | "tmp.zig:2:26: error: invalid character: '_'", | 1587 | "tmp.zig:2:21: error: expected expression, found 'invalid'", |
| | 1588 | "tmp.zig:2:26: note: invalid byte: '_'", |
| 1538 | }); | 1589 | }); |
| 1539 | | 1590 | |
| 1540 | cases.add("invalid underscore placement in float literal - 7", | 1591 | ctx.objErrStage1("invalid underscore placement in float literal - 7", |
| 1541 | \\fn main() void { | 1592 | \\fn main() void { |
| 1542 | \\ var bad: f128 = 1.0e-1_; | 1593 | \\ var bad: f128 = 1.0e-1_; |
| | 1594 | \\ _ = bad; |
| 1543 | \\} | 1595 | \\} |
| 1544 | , &[_][]const u8{ | 1596 | , &[_][]const u8{ |
| 1545 | "tmp.zig:2:28: error: invalid character: ';'", | 1597 | "tmp.zig:2:21: error: expected expression, found 'invalid'", |
| | 1598 | "tmp.zig:2:28: note: invalid byte: ';'", |
| 1546 | }); | 1599 | }); |
| 1547 | | 1600 | |
| 1548 | cases.add("invalid underscore placement in float literal - 9", | 1601 | ctx.objErrStage1("invalid underscore placement in float literal - 9", |
| 1549 | \\fn main() void { | 1602 | \\fn main() void { |
| 1550 | \\ var bad: f128 = 1__0.0e-1; | 1603 | \\ var bad: f128 = 1__0.0e-1; |
| | 1604 | \\ _ = bad; |
| 1551 | \\} | 1605 | \\} |
| 1552 | , &[_][]const u8{ | 1606 | , &[_][]const u8{ |
| 1553 | "tmp.zig:2:23: error: invalid character: '_'", | 1607 | "tmp.zig:2:21: error: expected expression, found 'invalid'", |
| | 1608 | "tmp.zig:2:23: note: invalid byte: '_'", |
| 1554 | }); | 1609 | }); |
| 1555 | | 1610 | |
| 1556 | cases.add("invalid underscore placement in float literal - 10", | 1611 | ctx.objErrStage1("invalid underscore placement in float literal - 10", |
| 1557 | \\fn main() void { | 1612 | \\fn main() void { |
| 1558 | \\ var bad: f128 = 1.0__0e-1; | 1613 | \\ var bad: f128 = 1.0__0e-1; |
| | 1614 | \\ _ = bad; |
| 1559 | \\} | 1615 | \\} |
| 1560 | , &[_][]const u8{ | 1616 | , &[_][]const u8{ |
| 1561 | "tmp.zig:2:25: error: invalid character: '_'", | 1617 | "tmp.zig:2:21: error: expected expression, found 'invalid'", |
| | 1618 | "tmp.zig:2:25: note: invalid byte: '_'", |
| 1562 | }); | 1619 | }); |
| 1563 | | 1620 | |
| 1564 | cases.add("invalid underscore placement in float literal - 11", | 1621 | ctx.objErrStage1("invalid underscore placement in float literal - 11", |
| 1565 | \\fn main() void { | 1622 | \\fn main() void { |
| 1566 | \\ var bad: f128 = 1.0e-1__0; | 1623 | \\ var bad: f128 = 1.0e-1__0; |
| | 1624 | \\ _ = bad; |
| 1567 | \\} | 1625 | \\} |
| 1568 | , &[_][]const u8{ | 1626 | , &[_][]const u8{ |
| 1569 | "tmp.zig:2:28: error: invalid character: '_'", | 1627 | "tmp.zig:2:21: error: expected expression, found 'invalid'", |
| | 1628 | "tmp.zig:2:28: note: invalid byte: '_'", |
| 1570 | }); | 1629 | }); |
| 1571 | | 1630 | |
| 1572 | cases.add("invalid underscore placement in float literal - 12", | 1631 | ctx.objErrStage1("invalid underscore placement in float literal - 12", |
| 1573 | \\fn main() void { | 1632 | \\fn main() void { |
| 1574 | \\ var bad: f128 = 0_x0.0; | 1633 | \\ var bad: f128 = 0_x0.0; |
| | 1634 | \\ _ = bad; |
| 1575 | \\} | 1635 | \\} |
| 1576 | , &[_][]const u8{ | 1636 | , &[_][]const u8{ |
| 1577 | "tmp.zig:2:23: error: invalid character: 'x'", | 1637 | "tmp.zig:2:21: error: expected expression, found 'invalid'", |
| | 1638 | "tmp.zig:2:23: note: invalid byte: 'x'", |
| 1578 | }); | 1639 | }); |
| 1579 | | 1640 | |
| 1580 | cases.add("invalid underscore placement in float literal - 13", | 1641 | ctx.objErrStage1("invalid underscore placement in float literal - 13", |
| 1581 | \\fn main() void { | 1642 | \\fn main() void { |
| 1582 | \\ var bad: f128 = 0x_0.0; | 1643 | \\ var bad: f128 = 0x_0.0; |
| | 1644 | \\ _ = bad; |
| 1583 | \\} | 1645 | \\} |
| 1584 | , &[_][]const u8{ | 1646 | , &[_][]const u8{ |
| 1585 | "tmp.zig:2:23: error: invalid character: '_'", | 1647 | "tmp.zig:2:21: error: expected expression, found 'invalid'", |
| | 1648 | "tmp.zig:2:23: note: invalid byte: '_'", |
| 1586 | }); | 1649 | }); |
| 1587 | | 1650 | |
| 1588 | cases.add("invalid underscore placement in float literal - 14", | 1651 | ctx.objErrStage1("invalid underscore placement in float literal - 14", |
| 1589 | \\fn main() void { | 1652 | \\fn main() void { |
| 1590 | \\ var bad: f128 = 0x0.0_p1; | 1653 | \\ var bad: f128 = 0x0.0_p1; |
| | 1654 | \\ _ = bad; |
| 1591 | \\} | 1655 | \\} |
| 1592 | , &[_][]const u8{ | 1656 | , &[_][]const u8{ |
| 1593 | "tmp.zig:2:27: error: invalid character: 'p'", | 1657 | "tmp.zig:2:21: error: expected expression, found 'invalid'", |
| | 1658 | "tmp.zig:2:27: note: invalid byte: 'p'", |
| 1594 | }); | 1659 | }); |
| 1595 | | 1660 | |
| 1596 | cases.add("invalid underscore placement in int literal - 1", | 1661 | ctx.objErrStage1("invalid underscore placement in int literal - 1", |
| 1597 | \\fn main() void { | 1662 | \\fn main() void { |
| 1598 | \\ var bad: u128 = 0010_; | 1663 | \\ var bad: u128 = 0010_; |
| | 1664 | \\ _ = bad; |
| 1599 | \\} | 1665 | \\} |
| 1600 | , &[_][]const u8{ | 1666 | , &[_][]const u8{ |
| 1601 | "tmp.zig:2:26: error: invalid character: ';'", | 1667 | "tmp.zig:2:21: error: expected expression, found 'invalid'", |
| | 1668 | "tmp.zig:2:26: note: invalid byte: ';'", |
| 1602 | }); | 1669 | }); |
| 1603 | | 1670 | |
| 1604 | cases.add("invalid underscore placement in int literal - 2", | 1671 | ctx.objErrStage1("invalid underscore placement in int literal - 2", |
| 1605 | \\fn main() void { | 1672 | \\fn main() void { |
| 1606 | \\ var bad: u128 = 0b0010_; | 1673 | \\ var bad: u128 = 0b0010_; |
| | 1674 | \\ _ = bad; |
| 1607 | \\} | 1675 | \\} |
| 1608 | , &[_][]const u8{ | 1676 | , &[_][]const u8{ |
| 1609 | "tmp.zig:2:28: error: invalid character: ';'", | 1677 | "tmp.zig:2:21: error: expected expression, found 'invalid'", |
| | 1678 | "tmp.zig:2:28: note: invalid byte: ';'", |
| 1610 | }); | 1679 | }); |
| 1611 | | 1680 | |
| 1612 | cases.add("invalid underscore placement in int literal - 3", | 1681 | ctx.objErrStage1("invalid underscore placement in int literal - 3", |
| 1613 | \\fn main() void { | 1682 | \\fn main() void { |
| 1614 | \\ var bad: u128 = 0o0010_; | 1683 | \\ var bad: u128 = 0o0010_; |
| | 1684 | \\ _ = bad; |
| 1615 | \\} | 1685 | \\} |
| 1616 | , &[_][]const u8{ | 1686 | , &[_][]const u8{ |
| 1617 | "tmp.zig:2:28: error: invalid character: ';'", | 1687 | "tmp.zig:2:21: error: expected expression, found 'invalid'", |
| | 1688 | "tmp.zig:2:28: note: invalid byte: ';'", |
| 1618 | }); | 1689 | }); |
| 1619 | | 1690 | |
| 1620 | cases.add("invalid underscore placement in int literal - 4", | 1691 | ctx.objErrStage1("invalid underscore placement in int literal - 4", |
| 1621 | \\fn main() void { | 1692 | \\fn main() void { |
| 1622 | \\ var bad: u128 = 0x0010_; | 1693 | \\ var bad: u128 = 0x0010_; |
| | 1694 | \\ _ = bad; |
| 1623 | \\} | 1695 | \\} |
| 1624 | , &[_][]const u8{ | 1696 | , &[_][]const u8{ |
| 1625 | "tmp.zig:2:28: error: invalid character: ';'", | 1697 | "tmp.zig:2:21: error: expected expression, found 'invalid'", |
| | 1698 | "tmp.zig:2:28: note: invalid byte: ';'", |
| 1626 | }); | 1699 | }); |
| 1627 | | 1700 | |
| 1628 | cases.add("comptime struct field, no init value", | 1701 | ctx.objErrStage1("comptime struct field, no init value", |
| 1629 | \\const Foo = struct { | 1702 | \\const Foo = struct { |
| 1630 | \\ comptime b: i32, | 1703 | \\ comptime b: i32, |
| 1631 | \\}; | 1704 | \\}; |
| 1632 | \\export fn entry() void { | 1705 | \\export fn entry() void { |
| 1633 | \\ var f: Foo = undefined; | 1706 | \\ var f: Foo = undefined; |
| | 1707 | \\ _ = f; |
| 1634 | \\} | 1708 | \\} |
| 1635 | , &[_][]const u8{ | 1709 | , &[_][]const u8{ |
| 1636 | "tmp.zig:2:5: error: comptime struct field missing initialization value", | 1710 | "tmp.zig:2:5: error: comptime field without default initialization value", |
| 1637 | }); | 1711 | }); |
| 1638 | | 1712 | |
| 1639 | cases.add("bad usage of @call", | 1713 | ctx.objErrStage1("bad usage of @call", |
| 1640 | \\export fn entry1() void { | 1714 | \\export fn entry1() void { |
| 1641 | \\ @call(.{}, foo, {}); | 1715 | \\ @call(.{}, foo, {}); |
| 1642 | \\} | 1716 | \\} |
| ... | @@ -1665,20 +1739,26 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -1665,20 +1739,26 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1665 | "tmp.zig:15:5: error: the specified modifier requires a comptime-known function", | 1739 | "tmp.zig:15:5: error: the specified modifier requires a comptime-known function", |
| 1666 | }); | 1740 | }); |
| 1667 | | 1741 | |
| 1668 | cases.add("exported async function", | 1742 | ctx.objErrStage1("exported async function", |
| 1669 | \\export fn foo() callconv(.Async) void {} | 1743 | \\export fn foo() callconv(.Async) void {} |
| 1670 | , &[_][]const u8{ | 1744 | , &[_][]const u8{ |
| 1671 | "tmp.zig:1:1: error: exported function cannot be async", | 1745 | "tmp.zig:1:1: error: exported function cannot be async", |
| 1672 | }); | 1746 | }); |
| 1673 | | 1747 | |
| 1674 | cases.addExe("main missing name", | 1748 | ctx.exeErrStage1("main missing name", |
| 1675 | \\pub fn (main) void {} | 1749 | \\pub fn (main) void {} |
| 1676 | , &[_][]const u8{ | 1750 | , &[_][]const u8{ |
| 1677 | "tmp.zig:1:5: error: missing function name", | 1751 | "tmp.zig:1:5: error: missing function name", |
| 1678 | }); | 1752 | }); |
| 1679 | | 1753 | |
| 1680 | cases.addCase(x: { | 1754 | { |
| 1681 | var tc = cases.create("call with new stack on unsupported target", | 1755 | const case = ctx.obj("call with new stack on unsupported target", .{ |
| | 1756 | .cpu_arch = .wasm32, |
| | 1757 | .os_tag = .wasi, |
| | 1758 | .abi = .none, |
| | 1759 | }); |
| | 1760 | case.backend = .stage1; |
| | 1761 | case.addError( |
| 1682 | \\var buf: [10]u8 align(16) = undefined; | 1762 | \\var buf: [10]u8 align(16) = undefined; |
| 1683 | \\export fn entry() void { | 1763 | \\export fn entry() void { |
| 1684 | \\ @call(.{.stack = &buf}, foo, .{}); | 1764 | \\ @call(.{.stack = &buf}, foo, .{}); |
| ... | @@ -1687,17 +1767,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -1687,17 +1767,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1687 | , &[_][]const u8{ | 1767 | , &[_][]const u8{ |
| 1688 | "tmp.zig:3:5: error: target arch 'wasm32' does not support calling with a new stack", | 1768 | "tmp.zig:3:5: error: target arch 'wasm32' does not support calling with a new stack", |
| 1689 | }); | 1769 | }); |
| 1690 | tc.target = std.zig.CrossTarget{ | 1770 | } |
| 1691 | .cpu_arch = .wasm32, | | |
| 1692 | .os_tag = .wasi, | | |
| 1693 | .abi = .none, | | |
| 1694 | }; | | |
| 1695 | break :x tc; | | |
| 1696 | }); | | |
| 1697 | | 1771 | |
| 1698 | // Note: One of the error messages here is backwards. It would be nice to fix, but that's not | 1772 | // Note: One of the error messages here is backwards. It would be nice to fix, but that's not |
| 1699 | // going to stop me from merging this branch which fixes a bunch of other stuff. | 1773 | // going to stop me from merging this branch which fixes a bunch of other stuff. |
| 1700 | cases.add("incompatible sentinels", | 1774 | ctx.objErrStage1("incompatible sentinels", |
| 1701 | \\export fn entry1(ptr: [*:255]u8) [*:0]u8 { | 1775 | \\export fn entry1(ptr: [*:255]u8) [*:0]u8 { |
| 1702 | \\ return ptr; | 1776 | \\ return ptr; |
| 1703 | \\} | 1777 | \\} |
| ... | @@ -1706,9 +1780,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -1706,9 +1780,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1706 | \\} | 1780 | \\} |
| 1707 | \\export fn entry3() void { | 1781 | \\export fn entry3() void { |
| 1708 | \\ var array: [2:0]u8 = [_:255]u8{1, 2}; | 1782 | \\ var array: [2:0]u8 = [_:255]u8{1, 2}; |
| | 1783 | \\ _ = array; |
| 1709 | \\} | 1784 | \\} |
| 1710 | \\export fn entry4() void { | 1785 | \\export fn entry4() void { |
| 1711 | \\ var array: [2:0]u8 = [_]u8{1, 2}; | 1786 | \\ var array: [2:0]u8 = [_]u8{1, 2}; |
| | 1787 | \\ _ = array; |
| 1712 | \\} | 1788 | \\} |
| 1713 | , &[_][]const u8{ | 1789 | , &[_][]const u8{ |
| 1714 | "tmp.zig:2:12: error: expected type '[*:0]u8', found '[*:255]u8'", | 1790 | "tmp.zig:2:12: error: expected type '[*:0]u8', found '[*:255]u8'", |
| ... | @@ -1718,11 +1794,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -1718,11 +1794,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1718 | | 1794 | |
| 1719 | "tmp.zig:8:35: error: expected type '[2:255]u8', found '[2:0]u8'", | 1795 | "tmp.zig:8:35: error: expected type '[2:255]u8', found '[2:0]u8'", |
| 1720 | "tmp.zig:8:35: note: destination array requires a terminating '255' sentinel, but source array has a terminating '0' sentinel", | 1796 | "tmp.zig:8:35: note: destination array requires a terminating '255' sentinel, but source array has a terminating '0' sentinel", |
| 1721 | "tmp.zig:11:31: error: expected type '[2:0]u8', found '[2]u8'", | 1797 | "tmp.zig:12:31: error: expected type '[2:0]u8', found '[2]u8'", |
| 1722 | "tmp.zig:11:31: note: destination array requires a terminating '0' sentinel", | 1798 | "tmp.zig:12:31: note: destination array requires a terminating '0' sentinel", |
| 1723 | }); | 1799 | }); |
| 1724 | | 1800 | |
| 1725 | cases.add("empty switch on an integer", | 1801 | ctx.objErrStage1("empty switch on an integer", |
| 1726 | \\export fn entry() void { | 1802 | \\export fn entry() void { |
| 1727 | \\ var x: u32 = 0; | 1803 | \\ var x: u32 = 0; |
| 1728 | \\ switch(x) {} | 1804 | \\ switch(x) {} |
| ... | @@ -1731,7 +1807,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -1731,7 +1807,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1731 | "tmp.zig:3:5: error: switch must handle all possibilities", | 1807 | "tmp.zig:3:5: error: switch must handle all possibilities", |
| 1732 | }); | 1808 | }); |
| 1733 | | 1809 | |
| 1734 | cases.add("incorrect return type", | 1810 | ctx.objErrStage1("incorrect return type", |
| 1735 | \\ pub export fn entry() void{ | 1811 | \\ pub export fn entry() void{ |
| 1736 | \\ _ = foo(); | 1812 | \\ _ = foo(); |
| 1737 | \\ } | 1813 | \\ } |
| ... | @@ -1751,12 +1827,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -1751,12 +1827,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1751 | "tmp.zig:8:16: error: expected type 'A', found 'B'", | 1827 | "tmp.zig:8:16: error: expected type 'A', found 'B'", |
| 1752 | }); | 1828 | }); |
| 1753 | | 1829 | |
| 1754 | cases.add("regression test #2980: base type u32 is not type checked properly when assigning a value within a struct", | 1830 | ctx.objErrStage1("regression test #2980: base type u32 is not type checked properly when assigning a value within a struct", |
| 1755 | \\const Foo = struct { | 1831 | \\const Foo = struct { |
| 1756 | \\ ptr: ?*usize, | 1832 | \\ ptr: ?*usize, |
| 1757 | \\ uval: u32, | 1833 | \\ uval: u32, |
| 1758 | \\}; | 1834 | \\}; |
| 1759 | \\fn get_uval(x: u32) !u32 { | 1835 | \\fn get_uval(x: u32) !u32 { |
| | 1836 | \\ _ = x; |
| 1760 | \\ return error.NotFound; | 1837 | \\ return error.NotFound; |
| 1761 | \\} | 1838 | \\} |
| 1762 | \\export fn entry() void { | 1839 | \\export fn entry() void { |
| ... | @@ -1764,12 +1841,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -1764,12 +1841,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1764 | \\ .ptr = null, | 1841 | \\ .ptr = null, |
| 1765 | \\ .uval = get_uval(42), | 1842 | \\ .uval = get_uval(42), |
| 1766 | \\ }; | 1843 | \\ }; |
| | 1844 | \\ _ = afoo; |
| 1767 | \\} | 1845 | \\} |
| 1768 | , &[_][]const u8{ | 1846 | , &[_][]const u8{ |
| 1769 | "tmp.zig:11:25: error: expected type 'u32', found '@typeInfo(@typeInfo(@TypeOf(get_uval)).Fn.return_type.?).ErrorUnion.error_set!u32'", | 1847 | "tmp.zig:12:25: error: expected type 'u32', found '@typeInfo(@typeInfo(@TypeOf(get_uval)).Fn.return_type.?).ErrorUnion.error_set!u32'", |
| 1770 | }); | 1848 | }); |
| 1771 | | 1849 | |
| 1772 | cases.add("assigning to struct or union fields that are not optionals with a function that returns an optional", | 1850 | ctx.objErrStage1("assigning to struct or union fields that are not optionals with a function that returns an optional", |
| 1773 | \\fn maybe(is: bool) ?u8 { | 1851 | \\fn maybe(is: bool) ?u8 { |
| 1774 | \\ if (is) return @as(u8, 10) else return null; | 1852 | \\ if (is) return @as(u8, 10) else return null; |
| 1775 | \\} | 1853 | \\} |
| ... | @@ -1782,12 +1860,14 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -1782,12 +1860,14 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1782 | \\export fn entry() void { | 1860 | \\export fn entry() void { |
| 1783 | \\ var u = U{ .Ye = maybe(false) }; | 1861 | \\ var u = U{ .Ye = maybe(false) }; |
| 1784 | \\ var s = S{ .num = maybe(false) }; | 1862 | \\ var s = S{ .num = maybe(false) }; |
| | 1863 | \\ _ = u; |
| | 1864 | \\ _ = s; |
| 1785 | \\} | 1865 | \\} |
| 1786 | , &[_][]const u8{ | 1866 | , &[_][]const u8{ |
| 1787 | "tmp.zig:11:27: error: expected type 'u8', found '?u8'", | 1867 | "tmp.zig:11:27: error: expected type 'u8', found '?u8'", |
| 1788 | }); | 1868 | }); |
| 1789 | | 1869 | |
| 1790 | cases.add("missing result type for phi node", | 1870 | ctx.objErrStage1("missing result type for phi node", |
| 1791 | \\fn foo() !void { | 1871 | \\fn foo() !void { |
| 1792 | \\ return anyerror.Foo; | 1872 | \\ return anyerror.Foo; |
| 1793 | \\} | 1873 | \\} |
| ... | @@ -1798,7 +1878,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -1798,7 +1878,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1798 | "tmp.zig:5:17: error: integer value 0 cannot be coerced to type 'void'", | 1878 | "tmp.zig:5:17: error: integer value 0 cannot be coerced to type 'void'", |
| 1799 | }); | 1879 | }); |
| 1800 | | 1880 | |
| 1801 | cases.add("atomicrmw with enum op not .Xchg", | 1881 | ctx.objErrStage1("atomicrmw with enum op not .Xchg", |
| 1802 | \\export fn entry() void { | 1882 | \\export fn entry() void { |
| 1803 | \\ const E = enum(u8) { | 1883 | \\ const E = enum(u8) { |
| 1804 | \\ a, | 1884 | \\ a, |
| ... | @@ -1813,7 +1893,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -1813,7 +1893,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1813 | "tmp.zig:9:27: error: @atomicRmw with enum only allowed with .Xchg", | 1893 | "tmp.zig:9:27: error: @atomicRmw with enum only allowed with .Xchg", |
| 1814 | }); | 1894 | }); |
| 1815 | | 1895 | |
| 1816 | cases.add("disallow coercion from non-null-terminated pointer to null-terminated pointer", | 1896 | ctx.objErrStage1("disallow coercion from non-null-terminated pointer to null-terminated pointer", |
| 1817 | \\extern fn puts(s: [*:0]const u8) c_int; | 1897 | \\extern fn puts(s: [*:0]const u8) c_int; |
| 1818 | \\pub fn main() void { | 1898 | \\pub fn main() void { |
| 1819 | \\ const no_zero_array = [_]u8{'h', 'e', 'l', 'l', 'o'}; | 1899 | \\ const no_zero_array = [_]u8{'h', 'e', 'l', 'l', 'o'}; |
| ... | @@ -1824,7 +1904,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -1824,7 +1904,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1824 | "tmp.zig:5:14: error: expected type '[*:0]const u8', found '[*]const u8'", | 1904 | "tmp.zig:5:14: error: expected type '[*:0]const u8', found '[*]const u8'", |
| 1825 | }); | 1905 | }); |
| 1826 | | 1906 | |
| 1827 | cases.add("atomic orderings of atomicStore Acquire or AcqRel", | 1907 | ctx.objErrStage1("atomic orderings of atomicStore Acquire or AcqRel", |
| 1828 | \\export fn entry() void { | 1908 | \\export fn entry() void { |
| 1829 | \\ var x: u32 = 0; | 1909 | \\ var x: u32 = 0; |
| 1830 | \\ @atomicStore(u32, &x, 1, .Acquire); | 1910 | \\ @atomicStore(u32, &x, 1, .Acquire); |
| ... | @@ -1833,7 +1913,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -1833,7 +1913,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1833 | "tmp.zig:3:30: error: @atomicStore atomic ordering must not be Acquire or AcqRel", | 1913 | "tmp.zig:3:30: error: @atomicStore atomic ordering must not be Acquire or AcqRel", |
| 1834 | }); | 1914 | }); |
| 1835 | | 1915 | |
| 1836 | cases.add("missing const in slice with nested array type", | 1916 | ctx.objErrStage1("missing const in slice with nested array type", |
| 1837 | \\const Geo3DTex2D = struct { vertices: [][2]f32 }; | 1917 | \\const Geo3DTex2D = struct { vertices: [][2]f32 }; |
| 1838 | \\pub fn getGeo3DTex2D() Geo3DTex2D { | 1918 | \\pub fn getGeo3DTex2D() Geo3DTex2D { |
| 1839 | \\ return Geo3DTex2D{ | 1919 | \\ return Geo3DTex2D{ |
| ... | @@ -1844,12 +1924,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -1844,12 +1924,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1844 | \\} | 1924 | \\} |
| 1845 | \\export fn entry() void { | 1925 | \\export fn entry() void { |
| 1846 | \\ var geo_data = getGeo3DTex2D(); | 1926 | \\ var geo_data = getGeo3DTex2D(); |
| | 1927 | \\ _ = geo_data; |
| 1847 | \\} | 1928 | \\} |
| 1848 | , &[_][]const u8{ | 1929 | , &[_][]const u8{ |
| 1849 | "tmp.zig:4:30: error: array literal requires address-of operator to coerce to slice type '[][2]f32'", | 1930 | "tmp.zig:4:30: error: array literal requires address-of operator to coerce to slice type '[][2]f32'", |
| 1850 | }); | 1931 | }); |
| 1851 | | 1932 | |
| 1852 | cases.add("slicing of global undefined pointer", | 1933 | ctx.objErrStage1("slicing of global undefined pointer", |
| 1853 | \\var buf: *[1]u8 = undefined; | 1934 | \\var buf: *[1]u8 = undefined; |
| 1854 | \\export fn entry() void { | 1935 | \\export fn entry() void { |
| 1855 | \\ _ = buf[0..1]; | 1936 | \\ _ = buf[0..1]; |
| ... | @@ -1858,18 +1939,17 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -1858,18 +1939,17 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1858 | "tmp.zig:3:12: error: non-zero length slice of undefined pointer", | 1939 | "tmp.zig:3:12: error: non-zero length slice of undefined pointer", |
| 1859 | }); | 1940 | }); |
| 1860 | | 1941 | |
| 1861 | cases.add("using invalid types in function call raises an error", | 1942 | ctx.objErrStage1("using invalid types in function call raises an error", |
| 1862 | \\const MenuEffect = enum {}; | 1943 | \\const MenuEffect = enum {}; |
| 1863 | \\fn func(effect: MenuEffect) void {} | 1944 | \\fn func(effect: MenuEffect) void { _ = effect; } |
| 1864 | \\export fn entry() void { | 1945 | \\export fn entry() void { |
| 1865 | \\ func(MenuEffect.ThisDoesNotExist); | 1946 | \\ func(MenuEffect.ThisDoesNotExist); |
| 1866 | \\} | 1947 | \\} |
| 1867 | , &[_][]const u8{ | 1948 | , &[_][]const u8{ |
| 1868 | "tmp.zig:1:20: error: enums must have 1 or more fields", | 1949 | "tmp.zig:1:20: error: enum declarations must have at least one tag", |
| 1869 | "tmp.zig:4:20: note: referenced here", | | |
| 1870 | }); | 1950 | }); |
| 1871 | | 1951 | |
| 1872 | cases.add("store vector pointer with unknown runtime index", | 1952 | ctx.objErrStage1("store vector pointer with unknown runtime index", |
| 1873 | \\export fn entry() void { | 1953 | \\export fn entry() void { |
| 1874 | \\ var v: @import("std").meta.Vector(4, i32) = [_]i32{ 1, 5, 3, undefined }; | 1954 | \\ var v: @import("std").meta.Vector(4, i32) = [_]i32{ 1, 5, 3, undefined }; |
| 1875 | \\ | 1955 | \\ |
| ... | @@ -1884,22 +1964,23 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -1884,22 +1964,23 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1884 | "tmp.zig:9:8: error: unable to determine vector element index of type '*align(16:0:4:?) i32", | 1964 | "tmp.zig:9:8: error: unable to determine vector element index of type '*align(16:0:4:?) i32", |
| 1885 | }); | 1965 | }); |
| 1886 | | 1966 | |
| 1887 | cases.add("load vector pointer with unknown runtime index", | 1967 | ctx.objErrStage1("load vector pointer with unknown runtime index", |
| 1888 | \\export fn entry() void { | 1968 | \\export fn entry() void { |
| 1889 | \\ var v: @import("std").meta.Vector(4, i32) = [_]i32{ 1, 5, 3, undefined }; | 1969 | \\ var v: @import("std").meta.Vector(4, i32) = [_]i32{ 1, 5, 3, undefined }; |
| 1890 | \\ | 1970 | \\ |
| 1891 | \\ var i: u32 = 0; | 1971 | \\ var i: u32 = 0; |
| 1892 | \\ var x = loadv(&v[i]); | 1972 | \\ var x = loadv(&v[i]); |
| | 1973 | \\ _ = x; |
| 1893 | \\} | 1974 | \\} |
| 1894 | \\ | 1975 | \\ |
| 1895 | \\fn loadv(ptr: anytype) i32 { | 1976 | \\fn loadv(ptr: anytype) i32 { |
| 1896 | \\ return ptr.*; | 1977 | \\ return ptr.*; |
| 1897 | \\} | 1978 | \\} |
| 1898 | , &[_][]const u8{ | 1979 | , &[_][]const u8{ |
| 1899 | "tmp.zig:9:12: error: unable to determine vector element index of type '*align(16:0:4:?) i32", | 1980 | "tmp.zig:10:12: error: unable to determine vector element index of type '*align(16:0:4:?) i32", |
| 1900 | }); | 1981 | }); |
| 1901 | | 1982 | |
| 1902 | cases.add("using an unknown len ptr type instead of array", | 1983 | ctx.objErrStage1("using an unknown len ptr type instead of array", |
| 1903 | \\const resolutions = [*][*]const u8{ | 1984 | \\const resolutions = [*][*]const u8{ |
| 1904 | \\ "[320 240 ]", | 1985 | \\ "[320 240 ]", |
| 1905 | \\ null, | 1986 | \\ null, |
| ... | @@ -1911,7 +1992,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -1911,7 +1992,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1911 | "tmp.zig:1:21: error: expected array type or [_], found '[*][*]const u8'", | 1992 | "tmp.zig:1:21: error: expected array type or [_], found '[*][*]const u8'", |
| 1912 | }); | 1993 | }); |
| 1913 | | 1994 | |
| 1914 | cases.add("comparison with error union and error value", | 1995 | ctx.objErrStage1("comparison with error union and error value", |
| 1915 | \\export fn entry() void { | 1996 | \\export fn entry() void { |
| 1916 | \\ var number_or_error: anyerror!i32 = error.SomethingAwful; | 1997 | \\ var number_or_error: anyerror!i32 = error.SomethingAwful; |
| 1917 | \\ _ = number_or_error == error.SomethingAwful; | 1998 | \\ _ = number_or_error == error.SomethingAwful; |
| ... | @@ -1920,7 +2001,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -1920,7 +2001,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1920 | "tmp.zig:3:25: error: operator not allowed for type 'anyerror!i32'", | 2001 | "tmp.zig:3:25: error: operator not allowed for type 'anyerror!i32'", |
| 1921 | }); | 2002 | }); |
| 1922 | | 2003 | |
| 1923 | cases.add("switch with overlapping case ranges", | 2004 | ctx.objErrStage1("switch with overlapping case ranges", |
| 1924 | \\export fn entry() void { | 2005 | \\export fn entry() void { |
| 1925 | \\ var q: u8 = 0; | 2006 | \\ var q: u8 = 0; |
| 1926 | \\ switch (q) { | 2007 | \\ switch (q) { |
| ... | @@ -1932,28 +2013,29 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -1932,28 +2013,29 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1932 | "tmp.zig:5:9: error: duplicate switch value", | 2013 | "tmp.zig:5:9: error: duplicate switch value", |
| 1933 | }); | 2014 | }); |
| 1934 | | 2015 | |
| 1935 | cases.add("invalid optional type in extern struct", | 2016 | ctx.objErrStage1("invalid optional type in extern struct", |
| 1936 | \\const stroo = extern struct { | 2017 | \\const stroo = extern struct { |
| 1937 | \\ moo: ?[*c]u8, | 2018 | \\ moo: ?[*c]u8, |
| 1938 | \\}; | 2019 | \\}; |
| 1939 | \\export fn testf(fluff: *stroo) void {} | 2020 | \\export fn testf(fluff: *stroo) void { _ = fluff; } |
| 1940 | , &[_][]const u8{ | 2021 | , &[_][]const u8{ |
| 1941 | "tmp.zig:2:5: error: extern structs cannot contain fields of type '?[*c]u8'", | 2022 | "tmp.zig:2:5: error: extern structs cannot contain fields of type '?[*c]u8'", |
| 1942 | }); | 2023 | }); |
| 1943 | | 2024 | |
| 1944 | cases.add("attempt to negate a non-integer, non-float or non-vector type", | 2025 | ctx.objErrStage1("attempt to negate a non-integer, non-float or non-vector type", |
| 1945 | \\fn foo() anyerror!u32 { | 2026 | \\fn foo() anyerror!u32 { |
| 1946 | \\ return 1; | 2027 | \\ return 1; |
| 1947 | \\} | 2028 | \\} |
| 1948 | \\ | 2029 | \\ |
| 1949 | \\export fn entry() void { | 2030 | \\export fn entry() void { |
| 1950 | \\ const x = -foo(); | 2031 | \\ const x = -foo(); |
| | 2032 | \\ _ = x; |
| 1951 | \\} | 2033 | \\} |
| 1952 | , &[_][]const u8{ | 2034 | , &[_][]const u8{ |
| 1953 | "tmp.zig:6:15: error: negation of type 'anyerror!u32'", | 2035 | "tmp.zig:6:15: error: negation of type 'anyerror!u32'", |
| 1954 | }); | 2036 | }); |
| 1955 | | 2037 | |
| 1956 | cases.add("attempt to create 17 bit float type", | 2038 | ctx.objErrStage1("attempt to create 17 bit float type", |
| 1957 | \\const builtin = @import("std").builtin; | 2039 | \\const builtin = @import("std").builtin; |
| 1958 | \\comptime { | 2040 | \\comptime { |
| 1959 | \\ _ = @Type(builtin.TypeInfo { .Float = builtin.TypeInfo.Float { .bits = 17 } }); | 2041 | \\ _ = @Type(builtin.TypeInfo { .Float = builtin.TypeInfo.Float { .bits = 17 } }); |
| ... | @@ -1962,7 +2044,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -1962,7 +2044,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1962 | "tmp.zig:3:32: error: 17-bit float unsupported", | 2044 | "tmp.zig:3:32: error: 17-bit float unsupported", |
| 1963 | }); | 2045 | }); |
| 1964 | | 2046 | |
| 1965 | cases.add("wrong type for @Type", | 2047 | ctx.objErrStage1("wrong type for @Type", |
| 1966 | \\export fn entry() void { | 2048 | \\export fn entry() void { |
| 1967 | \\ _ = @Type(0); | 2049 | \\ _ = @Type(0); |
| 1968 | \\} | 2050 | \\} |
| ... | @@ -1970,7 +2052,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -1970,7 +2052,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1970 | "tmp.zig:2:15: error: expected type 'std.builtin.TypeInfo', found 'comptime_int'", | 2052 | "tmp.zig:2:15: error: expected type 'std.builtin.TypeInfo', found 'comptime_int'", |
| 1971 | }); | 2053 | }); |
| 1972 | | 2054 | |
| 1973 | cases.add("@Type with non-constant expression", | 2055 | ctx.objErrStage1("@Type with non-constant expression", |
| 1974 | \\const builtin = @import("std").builtin; | 2056 | \\const builtin = @import("std").builtin; |
| 1975 | \\var globalTypeInfo : builtin.TypeInfo = undefined; | 2057 | \\var globalTypeInfo : builtin.TypeInfo = undefined; |
| 1976 | \\export fn entry() void { | 2058 | \\export fn entry() void { |
| ... | @@ -1980,7 +2062,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -1980,7 +2062,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1980 | "tmp.zig:4:15: error: unable to evaluate constant expression", | 2062 | "tmp.zig:4:15: error: unable to evaluate constant expression", |
| 1981 | }); | 2063 | }); |
| 1982 | | 2064 | |
| 1983 | cases.add("wrong type for argument tuple to @asyncCall", | 2065 | ctx.objErrStage1("wrong type for argument tuple to @asyncCall", |
| 1984 | \\export fn entry1() void { | 2066 | \\export fn entry1() void { |
| 1985 | \\ var frame: @Frame(foo) = undefined; | 2067 | \\ var frame: @Frame(foo) = undefined; |
| 1986 | \\ @asyncCall(&frame, {}, foo, {}); | 2068 | \\ @asyncCall(&frame, {}, foo, {}); |
| ... | @@ -1993,7 +2075,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -1993,7 +2075,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1993 | "tmp.zig:3:33: error: expected tuple or struct, found 'void'", | 2075 | "tmp.zig:3:33: error: expected tuple or struct, found 'void'", |
| 1994 | }); | 2076 | }); |
| 1995 | | 2077 | |
| 1996 | cases.add("wrong type for result ptr to @asyncCall", | 2078 | ctx.objErrStage1("wrong type for result ptr to @asyncCall", |
| 1997 | \\export fn entry() void { | 2079 | \\export fn entry() void { |
| 1998 | \\ _ = async amain(); | 2080 | \\ _ = async amain(); |
| 1999 | \\} | 2081 | \\} |
| ... | @@ -2008,25 +2090,27 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -2008,25 +2090,27 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2008 | "tmp.zig:6:37: error: expected type '*i32', found 'bool'", | 2090 | "tmp.zig:6:37: error: expected type '*i32', found 'bool'", |
| 2009 | }); | 2091 | }); |
| 2010 | | 2092 | |
| 2011 | cases.add("shift amount has to be an integer type", | 2093 | ctx.objErrStage1("shift amount has to be an integer type", |
| 2012 | \\export fn entry() void { | 2094 | \\export fn entry() void { |
| 2013 | \\ const x = 1 << &@as(u8, 10); | 2095 | \\ const x = 1 << &@as(u8, 10); |
| | 2096 | \\ _ = x; |
| 2014 | \\} | 2097 | \\} |
| 2015 | , &[_][]const u8{ | 2098 | , &[_][]const u8{ |
| 2016 | "tmp.zig:2:21: error: shift amount has to be an integer type, but found '*const u8'", | 2099 | "tmp.zig:2:21: error: shift amount has to be an integer type, but found '*const u8'", |
| 2017 | "tmp.zig:2:17: note: referenced here", | 2100 | "tmp.zig:2:17: note: referenced here", |
| 2018 | }); | 2101 | }); |
| 2019 | | 2102 | |
| 2020 | cases.add("bit shifting only works on integer types", | 2103 | ctx.objErrStage1("bit shifting only works on integer types", |
| 2021 | \\export fn entry() void { | 2104 | \\export fn entry() void { |
| 2022 | \\ const x = &@as(u8, 1) << 10; | 2105 | \\ const x = &@as(u8, 1) << 10; |
| | 2106 | \\ _ = x; |
| 2023 | \\} | 2107 | \\} |
| 2024 | , &[_][]const u8{ | 2108 | , &[_][]const u8{ |
| 2025 | "tmp.zig:2:16: error: bit shifting operation expected integer type, found '*const u8'", | 2109 | "tmp.zig:2:16: error: bit shifting operation expected integer type, found '*const u8'", |
| 2026 | "tmp.zig:2:27: note: referenced here", | 2110 | "tmp.zig:2:27: note: referenced here", |
| 2027 | }); | 2111 | }); |
| 2028 | | 2112 | |
| 2029 | cases.add("struct depends on itself via optional field", | 2113 | ctx.objErrStage1("struct depends on itself via optional field", |
| 2030 | \\const LhsExpr = struct { | 2114 | \\const LhsExpr = struct { |
| 2031 | \\ rhsExpr: ?AstObject, | 2115 | \\ rhsExpr: ?AstObject, |
| 2032 | \\}; | 2116 | \\}; |
| ... | @@ -2036,6 +2120,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -2036,6 +2120,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2036 | \\export fn entry() void { | 2120 | \\export fn entry() void { |
| 2037 | \\ const lhsExpr = LhsExpr{ .rhsExpr = null }; | 2121 | \\ const lhsExpr = LhsExpr{ .rhsExpr = null }; |
| 2038 | \\ const obj = AstObject{ .lhsExpr = lhsExpr }; | 2122 | \\ const obj = AstObject{ .lhsExpr = lhsExpr }; |
| | 2123 | \\ _ = obj; |
| 2039 | \\} | 2124 | \\} |
| 2040 | , &[_][]const u8{ | 2125 | , &[_][]const u8{ |
| 2041 | "tmp.zig:1:17: error: struct 'LhsExpr' depends on itself", | 2126 | "tmp.zig:1:17: error: struct 'LhsExpr' depends on itself", |
| ... | @@ -2043,51 +2128,54 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -2043,51 +2128,54 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2043 | "tmp.zig:2:5: note: while checking this field", | 2128 | "tmp.zig:2:5: note: while checking this field", |
| 2044 | }); | 2129 | }); |
| 2045 | | 2130 | |
| 2046 | cases.add("alignment of enum field specified", | 2131 | ctx.objErrStage1("alignment of enum field specified", |
| 2047 | \\const Number = enum { | 2132 | \\const Number = enum { |
| 2048 | \\ a, | 2133 | \\ a, |
| 2049 | \\ b align(i32), | 2134 | \\ b align(i32), |
| 2050 | \\}; | 2135 | \\}; |
| 2051 | \\export fn entry1() void { | 2136 | \\export fn entry1() void { |
| 2052 | \\ var x: Number = undefined; | 2137 | \\ var x: Number = undefined; |
| | 2138 | \\ _ = x; |
| 2053 | \\} | 2139 | \\} |
| 2054 | , &[_][]const u8{ | 2140 | , &[_][]const u8{ |
| 2055 | "tmp.zig:3:13: error: structs and unions, not enums, support field alignment", | 2141 | "tmp.zig:3:7: error: expected ',', found 'align'", |
| 2056 | "tmp.zig:1:16: note: consider 'union(enum)' here", | | |
| 2057 | }); | 2142 | }); |
| 2058 | | 2143 | |
| 2059 | cases.add("bad alignment type", | 2144 | ctx.objErrStage1("bad alignment type", |
| 2060 | \\export fn entry1() void { | 2145 | \\export fn entry1() void { |
| 2061 | \\ var x: []align(true) i32 = undefined; | 2146 | \\ var x: []align(true) i32 = undefined; |
| | 2147 | \\ _ = x; |
| 2062 | \\} | 2148 | \\} |
| 2063 | \\export fn entry2() void { | 2149 | \\export fn entry2() void { |
| 2064 | \\ var x: *align(@as(f64, 12.34)) i32 = undefined; | 2150 | \\ var x: *align(@as(f64, 12.34)) i32 = undefined; |
| | 2151 | \\ _ = x; |
| 2065 | \\} | 2152 | \\} |
| 2066 | , &[_][]const u8{ | 2153 | , &[_][]const u8{ |
| 2067 | "tmp.zig:2:20: error: expected type 'u29', found 'bool'", | 2154 | "tmp.zig:2:20: error: expected type 'u29', found 'bool'", |
| 2068 | "tmp.zig:5:19: error: fractional component prevents float value 12.340000 from being casted to type 'u29'", | 2155 | "tmp.zig:6:19: error: fractional component prevents float value 12.340000 from being casted to type 'u29'", |
| 2069 | }); | 2156 | }); |
| 2070 | | 2157 | |
| 2071 | cases.addCase(x: { | 2158 | { |
| 2072 | var tc = cases.create("variable in inline assembly template cannot be found", | 2159 | const case = ctx.obj("variable in inline assembly template cannot be found", .{ |
| | 2160 | .cpu_arch = .x86_64, |
| | 2161 | .os_tag = .linux, |
| | 2162 | .abi = .gnu, |
| | 2163 | }); |
| | 2164 | case.backend = .stage1; |
| | 2165 | case.addError( |
| 2073 | \\export fn entry() void { | 2166 | \\export fn entry() void { |
| 2074 | \\ var sp = asm volatile ( | 2167 | \\ var sp = asm volatile ( |
| 2075 | \\ "mov %[foo], sp" | 2168 | \\ "mov %[foo], sp" |
| 2076 | \\ : [bar] "=r" (-> usize) | 2169 | \\ : [bar] "=r" (-> usize) |
| 2077 | \\ ); | 2170 | \\ ); |
| | 2171 | \\ _ = sp; |
| 2078 | \\} | 2172 | \\} |
| 2079 | , &[_][]const u8{ | 2173 | , &[_][]const u8{ |
| 2080 | "tmp.zig:2:14: error: could not find 'foo' in the inputs or outputs", | 2174 | "tmp.zig:2:14: error: could not find 'foo' in the inputs or outputs", |
| 2081 | }); | 2175 | }); |
| 2082 | tc.target = std.zig.CrossTarget{ | 2176 | } |
| 2083 | .cpu_arch = .x86_64, | | |
| 2084 | .os_tag = .linux, | | |
| 2085 | .abi = .gnu, | | |
| 2086 | }; | | |
| 2087 | break :x tc; | | |
| 2088 | }); | | |
| 2089 | | 2177 | |
| 2090 | cases.add("indirect recursion of async functions detected", | 2178 | ctx.objErrStage1("indirect recursion of async functions detected", |
| 2091 | \\var frame: ?anyframe = null; | 2179 | \\var frame: ?anyframe = null; |
| 2092 | \\ | 2180 | \\ |
| 2093 | \\export fn a() void { | 2181 | \\export fn a() void { |
| ... | @@ -2122,7 +2210,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -2122,7 +2210,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2122 | "tmp.zig:26:25: note: when analyzing type '@Frame(rangeSumIndirect)' here", | 2210 | "tmp.zig:26:25: note: when analyzing type '@Frame(rangeSumIndirect)' here", |
| 2123 | }); | 2211 | }); |
| 2124 | | 2212 | |
| 2125 | cases.add("non-async function pointer eventually is inferred to become async", | 2213 | ctx.objErrStage1("non-async function pointer eventually is inferred to become async", |
| 2126 | \\export fn a() void { | 2214 | \\export fn a() void { |
| 2127 | \\ var non_async_fn: fn () void = undefined; | 2215 | \\ var non_async_fn: fn () void = undefined; |
| 2128 | \\ non_async_fn = func; | 2216 | \\ non_async_fn = func; |
| ... | @@ -2136,20 +2224,26 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -2136,20 +2224,26 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2136 | "tmp.zig:6:5: note: suspends here", | 2224 | "tmp.zig:6:5: note: suspends here", |
| 2137 | }); | 2225 | }); |
| 2138 | | 2226 | |
| 2139 | cases.add("bad alignment in @asyncCall", | 2227 | { |
| 2140 | \\export fn entry() void { | 2228 | const case = ctx.obj("bad alignment in @asyncCall", .{ |
| 2141 | \\ var ptr: fn () callconv(.Async) void = func; | 2229 | .cpu_arch = .aarch64, |
| 2142 | \\ var bytes: [64]u8 = undefined; | 2230 | .os_tag = .linux, |
| 2143 | \\ _ = @asyncCall(&bytes, {}, ptr, .{}); | 2231 | .abi = .none, |
| 2144 | \\} | 2232 | }); |
| 2145 | \\fn func() callconv(.Async) void {} | 2233 | case.backend = .stage1; |
| 2146 | , &[_][]const u8{ | 2234 | case.addError( |
| 2147 | // Split the check in two as the alignment value is target dependent. | 2235 | \\export fn entry() void { |
| 2148 | "tmp.zig:4:21: error: expected type '[]align(", | 2236 | \\ var ptr: fn () callconv(.Async) void = func; |
| 2149 | ") u8', found '*[64]u8'", | 2237 | \\ var bytes: [64]u8 = undefined; |
| 2150 | }); | 2238 | \\ _ = @asyncCall(&bytes, {}, ptr, .{}); |
| | 2239 | \\} |
| | 2240 | \\fn func() callconv(.Async) void {} |
| | 2241 | , &[_][]const u8{ |
| | 2242 | "tmp.zig:4:21: error: expected type '[]align(8) u8', found '*[64]u8'", |
| | 2243 | }); |
| | 2244 | } |
| 2151 | | 2245 | |
| 2152 | cases.add("atomic orderings of fence Acquire or stricter", | 2246 | ctx.objErrStage1("atomic orderings of fence Acquire or stricter", |
| 2153 | \\export fn entry() void { | 2247 | \\export fn entry() void { |
| 2154 | \\ @fence(.Monotonic); | 2248 | \\ @fence(.Monotonic); |
| 2155 | \\} | 2249 | \\} |
| ... | @@ -2157,20 +2251,22 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -2157,20 +2251,22 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2157 | "tmp.zig:2:12: error: atomic ordering must be Acquire or stricter", | 2251 | "tmp.zig:2:12: error: atomic ordering must be Acquire or stricter", |
| 2158 | }); | 2252 | }); |
| 2159 | | 2253 | |
| 2160 | cases.add("bad alignment in implicit cast from array pointer to slice", | 2254 | ctx.objErrStage1("bad alignment in implicit cast from array pointer to slice", |
| 2161 | \\export fn a() void { | 2255 | \\export fn a() void { |
| 2162 | \\ var x: [10]u8 = undefined; | 2256 | \\ var x: [10]u8 = undefined; |
| 2163 | \\ var y: []align(16) u8 = &x; | 2257 | \\ var y: []align(16) u8 = &x; |
| | 2258 | \\ _ = y; |
| 2164 | \\} | 2259 | \\} |
| 2165 | , &[_][]const u8{ | 2260 | , &[_][]const u8{ |
| 2166 | "tmp.zig:3:30: error: expected type '[]align(16) u8', found '*[10]u8'", | 2261 | "tmp.zig:3:30: error: expected type '[]align(16) u8', found '*[10]u8'", |
| 2167 | }); | 2262 | }); |
| 2168 | | 2263 | |
| 2169 | cases.add("result location incompatibility mismatching handle_is_ptr (generic call)", | 2264 | ctx.objErrStage1("result location incompatibility mismatching handle_is_ptr (generic call)", |
| 2170 | \\export fn entry() void { | 2265 | \\export fn entry() void { |
| 2171 | \\ var damn = Container{ | 2266 | \\ var damn = Container{ |
| 2172 | \\ .not_optional = getOptional(i32), | 2267 | \\ .not_optional = getOptional(i32), |
| 2173 | \\ }; | 2268 | \\ }; |
| | 2269 | \\ _ = damn; |
| 2174 | \\} | 2270 | \\} |
| 2175 | \\pub fn getOptional(comptime T: type) ?T { | 2271 | \\pub fn getOptional(comptime T: type) ?T { |
| 2176 | \\ return 0; | 2272 | \\ return 0; |
| ... | @@ -2182,11 +2278,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -2182,11 +2278,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2182 | "tmp.zig:3:36: error: expected type 'i32', found '?i32'", | 2278 | "tmp.zig:3:36: error: expected type 'i32', found '?i32'", |
| 2183 | }); | 2279 | }); |
| 2184 | | 2280 | |
| 2185 | cases.add("result location incompatibility mismatching handle_is_ptr", | 2281 | ctx.objErrStage1("result location incompatibility mismatching handle_is_ptr", |
| 2186 | \\export fn entry() void { | 2282 | \\export fn entry() void { |
| 2187 | \\ var damn = Container{ | 2283 | \\ var damn = Container{ |
| 2188 | \\ .not_optional = getOptional(), | 2284 | \\ .not_optional = getOptional(), |
| 2189 | \\ }; | 2285 | \\ }; |
| | 2286 | \\ _ = damn; |
| 2190 | \\} | 2287 | \\} |
| 2191 | \\pub fn getOptional() ?i32 { | 2288 | \\pub fn getOptional() ?i32 { |
| 2192 | \\ return 0; | 2289 | \\ return 0; |
| ... | @@ -2198,7 +2295,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -2198,7 +2295,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2198 | "tmp.zig:3:36: error: expected type 'i32', found '?i32'", | 2295 | "tmp.zig:3:36: error: expected type 'i32', found '?i32'", |
| 2199 | }); | 2296 | }); |
| 2200 | | 2297 | |
| 2201 | cases.add("const frame cast to anyframe", | 2298 | ctx.objErrStage1("const frame cast to anyframe", |
| 2202 | \\export fn a() void { | 2299 | \\export fn a() void { |
| 2203 | \\ const f = async func(); | 2300 | \\ const f = async func(); |
| 2204 | \\ resume f; | 2301 | \\ resume f; |
| ... | @@ -2206,6 +2303,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -2206,6 +2303,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2206 | \\export fn b() void { | 2303 | \\export fn b() void { |
| 2207 | \\ const f = async func(); | 2304 | \\ const f = async func(); |
| 2208 | \\ var x: anyframe = &f; | 2305 | \\ var x: anyframe = &f; |
| | 2306 | \\ _ = x; |
| 2209 | \\} | 2307 | \\} |
| 2210 | \\fn func() void { | 2308 | \\fn func() void { |
| 2211 | \\ suspend {} | 2309 | \\ suspend {} |
| ... | @@ -2215,27 +2313,30 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -2215,27 +2313,30 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2215 | "tmp.zig:7:24: error: expected type 'anyframe', found '*const @Frame(func)'", | 2313 | "tmp.zig:7:24: error: expected type 'anyframe', found '*const @Frame(func)'", |
| 2216 | }); | 2314 | }); |
| 2217 | | 2315 | |
| 2218 | cases.add("prevent bad implicit casting of anyframe types", | 2316 | ctx.objErrStage1("prevent bad implicit casting of anyframe types", |
| 2219 | \\export fn a() void { | 2317 | \\export fn a() void { |
| 2220 | \\ var x: anyframe = undefined; | 2318 | \\ var x: anyframe = undefined; |
| 2221 | \\ var y: anyframe->i32 = x; | 2319 | \\ var y: anyframe->i32 = x; |
| | 2320 | \\ _ = y; |
| 2222 | \\} | 2321 | \\} |
| 2223 | \\export fn b() void { | 2322 | \\export fn b() void { |
| 2224 | \\ var x: i32 = undefined; | 2323 | \\ var x: i32 = undefined; |
| 2225 | \\ var y: anyframe->i32 = x; | 2324 | \\ var y: anyframe->i32 = x; |
| | 2325 | \\ _ = y; |
| 2226 | \\} | 2326 | \\} |
| 2227 | \\export fn c() void { | 2327 | \\export fn c() void { |
| 2228 | \\ var x: @Frame(func) = undefined; | 2328 | \\ var x: @Frame(func) = undefined; |
| 2229 | \\ var y: anyframe->i32 = &x; | 2329 | \\ var y: anyframe->i32 = &x; |
| | 2330 | \\ _ = y; |
| 2230 | \\} | 2331 | \\} |
| 2231 | \\fn func() void {} | 2332 | \\fn func() void {} |
| 2232 | , &[_][]const u8{ | 2333 | , &[_][]const u8{ |
| 2233 | "tmp.zig:3:28: error: expected type 'anyframe->i32', found 'anyframe'", | 2334 | "tmp.zig:3:28: error: expected type 'anyframe->i32', found 'anyframe'", |
| 2234 | "tmp.zig:7:28: error: expected type 'anyframe->i32', found 'i32'", | 2335 | "tmp.zig:8:28: error: expected type 'anyframe->i32', found 'i32'", |
| 2235 | "tmp.zig:11:29: error: expected type 'anyframe->i32', found '*@Frame(func)'", | 2336 | "tmp.zig:13:29: error: expected type 'anyframe->i32', found '*@Frame(func)'", |
| 2236 | }); | 2337 | }); |
| 2237 | | 2338 | |
| 2238 | cases.add("wrong frame type used for async call", | 2339 | ctx.objErrStage1("wrong frame type used for async call", |
| 2239 | \\export fn entry() void { | 2340 | \\export fn entry() void { |
| 2240 | \\ var frame: @Frame(foo) = undefined; | 2341 | \\ var frame: @Frame(foo) = undefined; |
| 2241 | \\ frame = async bar(); | 2342 | \\ frame = async bar(); |
| ... | @@ -2250,18 +2351,20 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -2250,18 +2351,20 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2250 | "tmp.zig:3:13: error: expected type '*@Frame(bar)', found '*@Frame(foo)'", | 2351 | "tmp.zig:3:13: error: expected type '*@Frame(bar)', found '*@Frame(foo)'", |
| 2251 | }); | 2352 | }); |
| 2252 | | 2353 | |
| 2253 | cases.add("@Frame() of generic function", | 2354 | ctx.objErrStage1("@Frame() of generic function", |
| 2254 | \\export fn entry() void { | 2355 | \\export fn entry() void { |
| 2255 | \\ var frame: @Frame(func) = undefined; | 2356 | \\ var frame: @Frame(func) = undefined; |
| | 2357 | \\ _ = frame; |
| 2256 | \\} | 2358 | \\} |
| 2257 | \\fn func(comptime T: type) void { | 2359 | \\fn func(comptime T: type) void { |
| 2258 | \\ var x: T = undefined; | 2360 | \\ var x: T = undefined; |
| | 2361 | \\ _ = x; |
| 2259 | \\} | 2362 | \\} |
| 2260 | , &[_][]const u8{ | 2363 | , &[_][]const u8{ |
| 2261 | "tmp.zig:2:16: error: @Frame() of generic function", | 2364 | "tmp.zig:2:16: error: @Frame() of generic function", |
| 2262 | }); | 2365 | }); |
| 2263 | | 2366 | |
| 2264 | cases.add("@frame() causes function to be async", | 2367 | ctx.objErrStage1("@frame() causes function to be async", |
| 2265 | \\export fn entry() void { | 2368 | \\export fn entry() void { |
| 2266 | \\ func(); | 2369 | \\ func(); |
| 2267 | \\} | 2370 | \\} |
| ... | @@ -2273,10 +2376,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -2273,10 +2376,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2273 | "tmp.zig:5:9: note: @frame() causes function to be async", | 2376 | "tmp.zig:5:9: note: @frame() causes function to be async", |
| 2274 | }); | 2377 | }); |
| 2275 | | 2378 | |
| 2276 | cases.add("invalid suspend in exported function", | 2379 | ctx.objErrStage1("invalid suspend in exported function", |
| 2277 | \\export fn entry() void { | 2380 | \\export fn entry() void { |
| 2278 | \\ var frame = async func(); | 2381 | \\ var frame = async func(); |
| 2279 | \\ var result = await frame; | 2382 | \\ var result = await frame; |
| | 2383 | \\ _ = result; |
| 2280 | \\} | 2384 | \\} |
| 2281 | \\fn func() void { | 2385 | \\fn func() void { |
| 2282 | \\ suspend {} | 2386 | \\ suspend {} |
| ... | @@ -2286,7 +2390,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -2286,7 +2390,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2286 | "tmp.zig:3:18: note: await here is a suspend point", | 2390 | "tmp.zig:3:18: note: await here is a suspend point", |
| 2287 | }); | 2391 | }); |
| 2288 | | 2392 | |
| 2289 | cases.add("async function indirectly depends on its own frame", | 2393 | ctx.objErrStage1("async function indirectly depends on its own frame", |
| 2290 | \\export fn entry() void { | 2394 | \\export fn entry() void { |
| 2291 | \\ _ = async amain(); | 2395 | \\ _ = async amain(); |
| 2292 | \\} | 2396 | \\} |
| ... | @@ -2295,6 +2399,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -2295,6 +2399,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2295 | \\} | 2399 | \\} |
| 2296 | \\fn other() void { | 2400 | \\fn other() void { |
| 2297 | \\ var x: [@sizeOf(@Frame(amain))]u8 = undefined; | 2401 | \\ var x: [@sizeOf(@Frame(amain))]u8 = undefined; |
| | 2402 | \\ _ = x; |
| 2298 | \\} | 2403 | \\} |
| 2299 | , &[_][]const u8{ | 2404 | , &[_][]const u8{ |
| 2300 | "tmp.zig:4:1: error: unable to determine async function frame of 'amain'", | 2405 | "tmp.zig:4:1: error: unable to determine async function frame of 'amain'", |
| ... | @@ -2302,19 +2407,20 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -2302,19 +2407,20 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2302 | "tmp.zig:8:13: note: referenced here", | 2407 | "tmp.zig:8:13: note: referenced here", |
| 2303 | }); | 2408 | }); |
| 2304 | | 2409 | |
| 2305 | cases.add("async function depends on its own frame", | 2410 | ctx.objErrStage1("async function depends on its own frame", |
| 2306 | \\export fn entry() void { | 2411 | \\export fn entry() void { |
| 2307 | \\ _ = async amain(); | 2412 | \\ _ = async amain(); |
| 2308 | \\} | 2413 | \\} |
| 2309 | \\fn amain() callconv(.Async) void { | 2414 | \\fn amain() callconv(.Async) void { |
| 2310 | \\ var x: [@sizeOf(@Frame(amain))]u8 = undefined; | 2415 | \\ var x: [@sizeOf(@Frame(amain))]u8 = undefined; |
| | 2416 | \\ _ = x; |
| 2311 | \\} | 2417 | \\} |
| 2312 | , &[_][]const u8{ | 2418 | , &[_][]const u8{ |
| 2313 | "tmp.zig:4:1: error: cannot resolve '@Frame(amain)': function not fully analyzed yet", | 2419 | "tmp.zig:4:1: error: cannot resolve '@Frame(amain)': function not fully analyzed yet", |
| 2314 | "tmp.zig:5:13: note: referenced here", | 2420 | "tmp.zig:5:13: note: referenced here", |
| 2315 | }); | 2421 | }); |
| 2316 | | 2422 | |
| 2317 | cases.add("non async function pointer passed to @asyncCall", | 2423 | ctx.objErrStage1("non async function pointer passed to @asyncCall", |
| 2318 | \\export fn entry() void { | 2424 | \\export fn entry() void { |
| 2319 | \\ var ptr = afunc; | 2425 | \\ var ptr = afunc; |
| 2320 | \\ var bytes: [100]u8 align(16) = undefined; | 2426 | \\ var bytes: [100]u8 align(16) = undefined; |
| ... | @@ -2325,7 +2431,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -2325,7 +2431,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2325 | "tmp.zig:4:32: error: expected async function, found 'fn() void'", | 2431 | "tmp.zig:4:32: error: expected async function, found 'fn() void'", |
| 2326 | }); | 2432 | }); |
| 2327 | | 2433 | |
| 2328 | cases.add("runtime-known async function called", | 2434 | ctx.objErrStage1("runtime-known async function called", |
| 2329 | \\export fn entry() void { | 2435 | \\export fn entry() void { |
| 2330 | \\ _ = async amain(); | 2436 | \\ _ = async amain(); |
| 2331 | \\} | 2437 | \\} |
| ... | @@ -2338,7 +2444,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -2338,7 +2444,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2338 | "tmp.zig:6:12: error: function is not comptime-known; @asyncCall required", | 2444 | "tmp.zig:6:12: error: function is not comptime-known; @asyncCall required", |
| 2339 | }); | 2445 | }); |
| 2340 | | 2446 | |
| 2341 | cases.add("runtime-known function called with async keyword", | 2447 | ctx.objErrStage1("runtime-known function called with async keyword", |
| 2342 | \\export fn entry() void { | 2448 | \\export fn entry() void { |
| 2343 | \\ var ptr = afunc; | 2449 | \\ var ptr = afunc; |
| 2344 | \\ _ = async ptr(); | 2450 | \\ _ = async ptr(); |
| ... | @@ -2349,7 +2455,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -2349,7 +2455,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2349 | "tmp.zig:3:15: error: function is not comptime-known; @asyncCall required", | 2455 | "tmp.zig:3:15: error: function is not comptime-known; @asyncCall required", |
| 2350 | }); | 2456 | }); |
| 2351 | | 2457 | |
| 2352 | cases.add("function with ccc indirectly calling async function", | 2458 | ctx.objErrStage1("function with ccc indirectly calling async function", |
| 2353 | \\export fn entry() void { | 2459 | \\export fn entry() void { |
| 2354 | \\ foo(); | 2460 | \\ foo(); |
| 2355 | \\} | 2461 | \\} |
| ... | @@ -2366,7 +2472,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -2366,7 +2472,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2366 | "tmp.zig:8:5: note: suspends here", | 2472 | "tmp.zig:8:5: note: suspends here", |
| 2367 | }); | 2473 | }); |
| 2368 | | 2474 | |
| 2369 | cases.add("capture group on switch prong with incompatible payload types", | 2475 | ctx.objErrStage1("capture group on switch prong with incompatible payload types", |
| 2370 | \\const Union = union(enum) { | 2476 | \\const Union = union(enum) { |
| 2371 | \\ A: usize, | 2477 | \\ A: usize, |
| 2372 | \\ B: isize, | 2478 | \\ B: isize, |
| ... | @@ -2374,7 +2480,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -2374,7 +2480,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2374 | \\comptime { | 2480 | \\comptime { |
| 2375 | \\ var u = Union{ .A = 8 }; | 2481 | \\ var u = Union{ .A = 8 }; |
| 2376 | \\ switch (u) { | 2482 | \\ switch (u) { |
| 2377 | \\ .A, .B => |e| unreachable, | 2483 | \\ .A, .B => |e| { |
| | 2484 | \\ _ = e; |
| | 2485 | \\ unreachable; |
| | 2486 | \\ }, |
| 2378 | \\ } | 2487 | \\ } |
| 2379 | \\} | 2488 | \\} |
| 2380 | , &[_][]const u8{ | 2489 | , &[_][]const u8{ |
| ... | @@ -2383,7 +2492,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -2383,7 +2492,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2383 | "tmp.zig:8:13: note: type 'isize' here", | 2492 | "tmp.zig:8:13: note: type 'isize' here", |
| 2384 | }); | 2493 | }); |
| 2385 | | 2494 | |
| 2386 | cases.add("wrong type to @hasField", | 2495 | ctx.objErrStage1("wrong type to @hasField", |
| 2387 | \\export fn entry() bool { | 2496 | \\export fn entry() bool { |
| 2388 | \\ return @hasField(i32, "hi"); | 2497 | \\ return @hasField(i32, "hi"); |
| 2389 | \\} | 2498 | \\} |
| ... | @@ -2391,44 +2500,49 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -2391,44 +2500,49 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2391 | "tmp.zig:2:22: error: type 'i32' does not support @hasField", | 2500 | "tmp.zig:2:22: error: type 'i32' does not support @hasField", |
| 2392 | }); | 2501 | }); |
| 2393 | | 2502 | |
| 2394 | cases.add("slice passed as array init type with elems", | 2503 | ctx.objErrStage1("slice passed as array init type with elems", |
| 2395 | \\export fn entry() void { | 2504 | \\export fn entry() void { |
| 2396 | \\ const x = []u8{1, 2}; | 2505 | \\ const x = []u8{1, 2}; |
| | 2506 | \\ _ = x; |
| 2397 | \\} | 2507 | \\} |
| 2398 | , &[_][]const u8{ | 2508 | , &[_][]const u8{ |
| 2399 | "tmp.zig:2:15: error: array literal requires address-of operator to coerce to slice type '[]u8'", | 2509 | "tmp.zig:2:15: error: array literal requires address-of operator to coerce to slice type '[]u8'", |
| 2400 | }); | 2510 | }); |
| 2401 | | 2511 | |
| 2402 | cases.add("slice passed as array init type", | 2512 | ctx.objErrStage1("slice passed as array init type", |
| 2403 | \\export fn entry() void { | 2513 | \\export fn entry() void { |
| 2404 | \\ const x = []u8{}; | 2514 | \\ const x = []u8{}; |
| | 2515 | \\ _ = x; |
| 2405 | \\} | 2516 | \\} |
| 2406 | , &[_][]const u8{ | 2517 | , &[_][]const u8{ |
| 2407 | "tmp.zig:2:15: error: array literal requires address-of operator to coerce to slice type '[]u8'", | 2518 | "tmp.zig:2:15: error: array literal requires address-of operator to coerce to slice type '[]u8'", |
| 2408 | }); | 2519 | }); |
| 2409 | | 2520 | |
| 2410 | cases.add("inferred array size invalid here", | 2521 | ctx.objErrStage1("inferred array size invalid here", |
| 2411 | \\export fn entry() void { | 2522 | \\export fn entry() void { |
| 2412 | \\ const x = [_]u8; | 2523 | \\ const x = [_]u8; |
| | 2524 | \\ _ = x; |
| 2413 | \\} | 2525 | \\} |
| 2414 | \\export fn entry2() void { | 2526 | \\export fn entry2() void { |
| 2415 | \\ const S = struct { a: *const [_]u8 }; | 2527 | \\ const S = struct { a: *const [_]u8 }; |
| 2416 | \\ var a = .{ S{} }; | 2528 | \\ var a = .{ S{} }; |
| | 2529 | \\ _ = a; |
| 2417 | \\} | 2530 | \\} |
| 2418 | , &[_][]const u8{ | 2531 | , &[_][]const u8{ |
| 2419 | "tmp.zig:2:15: error: inferred array size invalid here", | 2532 | "tmp.zig:2:16: error: unable to infer array size", |
| 2420 | "tmp.zig:5:34: error: inferred array size invalid here", | 2533 | "tmp.zig:6:35: error: unable to infer array size", |
| 2421 | }); | 2534 | }); |
| 2422 | | 2535 | |
| 2423 | cases.add("initializing array with struct syntax", | 2536 | ctx.objErrStage1("initializing array with struct syntax", |
| 2424 | \\export fn entry() void { | 2537 | \\export fn entry() void { |
| 2425 | \\ const x = [_]u8{ .y = 2 }; | 2538 | \\ const x = [_]u8{ .y = 2 }; |
| | 2539 | \\ _ = x; |
| 2426 | \\} | 2540 | \\} |
| 2427 | , &[_][]const u8{ | 2541 | , &[_][]const u8{ |
| 2428 | "tmp.zig:2:15: error: initializing array with struct syntax", | 2542 | "tmp.zig:2:15: error: initializing array with struct syntax", |
| 2429 | }); | 2543 | }); |
| 2430 | | 2544 | |
| 2431 | cases.add("compile error in struct init expression", | 2545 | ctx.objErrStage1("compile error in struct init expression", |
| 2432 | \\const Foo = struct { | 2546 | \\const Foo = struct { |
| 2433 | \\ a: i32 = crap, | 2547 | \\ a: i32 = crap, |
| 2434 | \\ b: i32, | 2548 | \\ b: i32, |
| ... | @@ -2437,23 +2551,25 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -2437,23 +2551,25 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2437 | \\ var x = Foo{ | 2551 | \\ var x = Foo{ |
| 2438 | \\ .b = 5, | 2552 | \\ .b = 5, |
| 2439 | \\ }; | 2553 | \\ }; |
| | 2554 | \\ _ = x; |
| 2440 | \\} | 2555 | \\} |
| 2441 | , &[_][]const u8{ | 2556 | , &[_][]const u8{ |
| 2442 | "tmp.zig:2:14: error: use of undeclared identifier 'crap'", | 2557 | "tmp.zig:2:14: error: use of undeclared identifier 'crap'", |
| 2443 | }); | 2558 | }); |
| 2444 | | 2559 | |
| 2445 | cases.add("undefined as field type is rejected", | 2560 | ctx.objErrStage1("undefined as field type is rejected", |
| 2446 | \\const Foo = struct { | 2561 | \\const Foo = struct { |
| 2447 | \\ a: undefined, | 2562 | \\ a: undefined, |
| 2448 | \\}; | 2563 | \\}; |
| 2449 | \\export fn entry1() void { | 2564 | \\export fn entry1() void { |
| 2450 | \\ const foo: Foo = undefined; | 2565 | \\ const foo: Foo = undefined; |
| | 2566 | \\ _ = foo; |
| 2451 | \\} | 2567 | \\} |
| 2452 | , &[_][]const u8{ | 2568 | , &[_][]const u8{ |
| 2453 | "tmp.zig:2:8: error: use of undefined value here causes undefined behavior", | 2569 | "tmp.zig:2:8: error: use of undefined value here causes undefined behavior", |
| 2454 | }); | 2570 | }); |
| 2455 | | 2571 | |
| 2456 | cases.add("@hasDecl with non-container", | 2572 | ctx.objErrStage1("@hasDecl with non-container", |
| 2457 | \\export fn entry() void { | 2573 | \\export fn entry() void { |
| 2458 | \\ _ = @hasDecl(i32, "hi"); | 2574 | \\ _ = @hasDecl(i32, "hi"); |
| 2459 | \\} | 2575 | \\} |
| ... | @@ -2461,16 +2577,17 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -2461,16 +2577,17 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2461 | "tmp.zig:2:18: error: expected struct, enum, or union; found 'i32'", | 2577 | "tmp.zig:2:18: error: expected struct, enum, or union; found 'i32'", |
| 2462 | }); | 2578 | }); |
| 2463 | | 2579 | |
| 2464 | cases.add("field access of slices", | 2580 | ctx.objErrStage1("field access of slices", |
| 2465 | \\export fn entry() void { | 2581 | \\export fn entry() void { |
| 2466 | \\ var slice: []i32 = undefined; | 2582 | \\ var slice: []i32 = undefined; |
| 2467 | \\ const info = @TypeOf(slice).unknown; | 2583 | \\ const info = @TypeOf(slice).unknown; |
| | 2584 | \\ _ = info; |
| 2468 | \\} | 2585 | \\} |
| 2469 | , &[_][]const u8{ | 2586 | , &[_][]const u8{ |
| 2470 | "tmp.zig:3:32: error: type 'type' does not support field access", | 2587 | "tmp.zig:3:32: error: type 'type' does not support field access", |
| 2471 | }); | 2588 | }); |
| 2472 | | 2589 | |
| 2473 | cases.add("peer cast then implicit cast const pointer to mutable C pointer", | 2590 | ctx.objErrStage1("peer cast then implicit cast const pointer to mutable C pointer", |
| 2474 | \\export fn func() void { | 2591 | \\export fn func() void { |
| 2475 | \\ var strValue: [*c]u8 = undefined; | 2592 | \\ var strValue: [*c]u8 = undefined; |
| 2476 | \\ strValue = strValue orelse ""; | 2593 | \\ strValue = strValue orelse ""; |
| ... | @@ -2480,19 +2597,20 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -2480,19 +2597,20 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2480 | "tmp.zig:3:32: note: cast discards const qualifier", | 2597 | "tmp.zig:3:32: note: cast discards const qualifier", |
| 2481 | }); | 2598 | }); |
| 2482 | | 2599 | |
| 2483 | cases.add("overflow in enum value allocation", | 2600 | ctx.objErrStage1("overflow in enum value allocation", |
| 2484 | \\const Moo = enum(u8) { | 2601 | \\const Moo = enum(u8) { |
| 2485 | \\ Last = 255, | 2602 | \\ Last = 255, |
| 2486 | \\ Over, | 2603 | \\ Over, |
| 2487 | \\}; | 2604 | \\}; |
| 2488 | \\pub fn main() void { | 2605 | \\pub fn main() void { |
| 2489 | \\ var y = Moo.Last; | 2606 | \\ var y = Moo.Last; |
| | 2607 | \\ _ = y; |
| 2490 | \\} | 2608 | \\} |
| 2491 | , &[_][]const u8{ | 2609 | , &[_][]const u8{ |
| 2492 | "tmp.zig:3:5: error: enumeration value 256 too large for type 'u8'", | 2610 | "tmp.zig:3:5: error: enumeration value 256 too large for type 'u8'", |
| 2493 | }); | 2611 | }); |
| 2494 | | 2612 | |
| 2495 | cases.add("attempt to cast enum literal to error", | 2613 | ctx.objErrStage1("attempt to cast enum literal to error", |
| 2496 | \\export fn entry() void { | 2614 | \\export fn entry() void { |
| 2497 | \\ switch (error.Hi) { | 2615 | \\ switch (error.Hi) { |
| 2498 | \\ .Hi => {}, | 2616 | \\ .Hi => {}, |
| ... | @@ -2502,7 +2620,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -2502,7 +2620,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2502 | "tmp.zig:3:9: error: expected type 'error{Hi}', found '(enum literal)'", | 2620 | "tmp.zig:3:9: error: expected type 'error{Hi}', found '(enum literal)'", |
| 2503 | }); | 2621 | }); |
| 2504 | | 2622 | |
| 2505 | cases.add("@sizeOf bad type", | 2623 | ctx.objErrStage1("@sizeOf bad type", |
| 2506 | \\export fn entry() usize { | 2624 | \\export fn entry() usize { |
| 2507 | \\ return @sizeOf(@TypeOf(null)); | 2625 | \\ return @sizeOf(@TypeOf(null)); |
| 2508 | \\} | 2626 | \\} |
| ... | @@ -2510,7 +2628,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -2510,7 +2628,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2510 | "tmp.zig:2:20: error: no size available for type '(null)'", | 2628 | "tmp.zig:2:20: error: no size available for type '(null)'", |
| 2511 | }); | 2629 | }); |
| 2512 | | 2630 | |
| 2513 | cases.add("generic function where return type is self-referenced", | 2631 | ctx.objErrStage1("generic function where return type is self-referenced", |
| 2514 | \\fn Foo(comptime T: type) Foo(T) { | 2632 | \\fn Foo(comptime T: type) Foo(T) { |
| 2515 | \\ return struct{ x: T }; | 2633 | \\ return struct{ x: T }; |
| 2516 | \\} | 2634 | \\} |
| ... | @@ -2518,34 +2636,37 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -2518,34 +2636,37 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2518 | \\ const t = Foo(u32) { | 2636 | \\ const t = Foo(u32) { |
| 2519 | \\ .x = 1 | 2637 | \\ .x = 1 |
| 2520 | \\ }; | 2638 | \\ }; |
| | 2639 | \\ _ = t; |
| 2521 | \\} | 2640 | \\} |
| 2522 | , &[_][]const u8{ | 2641 | , &[_][]const u8{ |
| 2523 | "tmp.zig:1:29: error: evaluation exceeded 1000 backwards branches", | 2642 | "tmp.zig:1:29: error: evaluation exceeded 1000 backwards branches", |
| 2524 | "tmp.zig:5:18: note: referenced here", | 2643 | "tmp.zig:5:18: note: referenced here", |
| 2525 | }); | 2644 | }); |
| 2526 | | 2645 | |
| 2527 | cases.add("@ptrToInt 0 to non optional pointer", | 2646 | ctx.objErrStage1("@ptrToInt 0 to non optional pointer", |
| 2528 | \\export fn entry() void { | 2647 | \\export fn entry() void { |
| 2529 | \\ var b = @intToPtr(*i32, 0); | 2648 | \\ var b = @intToPtr(*i32, 0); |
| | 2649 | \\ _ = b; |
| 2530 | \\} | 2650 | \\} |
| 2531 | , &[_][]const u8{ | 2651 | , &[_][]const u8{ |
| 2532 | "tmp.zig:2:13: error: pointer type '*i32' does not allow address zero", | 2652 | "tmp.zig:2:13: error: pointer type '*i32' does not allow address zero", |
| 2533 | }); | 2653 | }); |
| 2534 | | 2654 | |
| 2535 | cases.add("cast enum literal to enum but it doesn't match", | 2655 | ctx.objErrStage1("cast enum literal to enum but it doesn't match", |
| 2536 | \\const Foo = enum { | 2656 | \\const Foo = enum { |
| 2537 | \\ a, | 2657 | \\ a, |
| 2538 | \\ b, | 2658 | \\ b, |
| 2539 | \\}; | 2659 | \\}; |
| 2540 | \\export fn entry() void { | 2660 | \\export fn entry() void { |
| 2541 | \\ const x: Foo = .c; | 2661 | \\ const x: Foo = .c; |
| | 2662 | \\ _ = x; |
| 2542 | \\} | 2663 | \\} |
| 2543 | , &[_][]const u8{ | 2664 | , &[_][]const u8{ |
| 2544 | "tmp.zig:6:20: error: enum 'Foo' has no field named 'c'", | 2665 | "tmp.zig:6:20: error: enum 'Foo' has no field named 'c'", |
| 2545 | "tmp.zig:1:13: note: 'Foo' declared here", | 2666 | "tmp.zig:1:13: note: 'Foo' declared here", |
| 2546 | }); | 2667 | }); |
| 2547 | | 2668 | |
| 2548 | cases.add("discarding error value", | 2669 | ctx.objErrStage1("discarding error value", |
| 2549 | \\export fn entry() void { | 2670 | \\export fn entry() void { |
| 2550 | \\ _ = foo(); | 2671 | \\ _ = foo(); |
| 2551 | \\} | 2672 | \\} |
| ... | @@ -2556,7 +2677,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -2556,7 +2677,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2556 | "tmp.zig:2:12: error: error is discarded. consider using `try`, `catch`, or `if`", | 2677 | "tmp.zig:2:12: error: error is discarded. consider using `try`, `catch`, or `if`", |
| 2557 | }); | 2678 | }); |
| 2558 | | 2679 | |
| 2559 | cases.add("volatile on global assembly", | 2680 | ctx.objErrStage1("volatile on global assembly", |
| 2560 | \\comptime { | 2681 | \\comptime { |
| 2561 | \\ asm volatile (""); | 2682 | \\ asm volatile (""); |
| 2562 | \\} | 2683 | \\} |
| ... | @@ -2564,7 +2685,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -2564,7 +2685,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2564 | "tmp.zig:2:9: error: volatile is meaningless on global assembly", | 2685 | "tmp.zig:2:9: error: volatile is meaningless on global assembly", |
| 2565 | }); | 2686 | }); |
| 2566 | | 2687 | |
| 2567 | cases.add("invalid multiple dereferences", | 2688 | ctx.objErrStage1("invalid multiple dereferences", |
| 2568 | \\export fn a() void { | 2689 | \\export fn a() void { |
| 2569 | \\ var box = Box{ .field = 0 }; | 2690 | \\ var box = Box{ .field = 0 }; |
| 2570 | \\ box.*.field = 1; | 2691 | \\ box.*.field = 1; |
| ... | @@ -2582,13 +2703,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -2582,13 +2703,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2582 | "tmp.zig:8:13: error: attempt to dereference non-pointer type 'Box'", | 2703 | "tmp.zig:8:13: error: attempt to dereference non-pointer type 'Box'", |
| 2583 | }); | 2704 | }); |
| 2584 | | 2705 | |
| 2585 | cases.add("usingnamespace with wrong type", | 2706 | ctx.objErrStage1("usingnamespace with wrong type", |
| 2586 | \\usingnamespace void; | 2707 | \\usingnamespace void; |
| 2587 | , &[_][]const u8{ | 2708 | , &[_][]const u8{ |
| 2588 | "tmp.zig:1:1: error: expected struct, enum, or union; found 'void'", | 2709 | "tmp.zig:1:1: error: expected struct, enum, or union; found 'void'", |
| 2589 | }); | 2710 | }); |
| 2590 | | 2711 | |
| 2591 | cases.add("ignored expression in while continuation", | 2712 | ctx.objErrStage1("ignored expression in while continuation", |
| 2592 | \\export fn a() void { | 2713 | \\export fn a() void { |
| 2593 | \\ while (true) : (bad()) {} | 2714 | \\ while (true) : (bad()) {} |
| 2594 | \\} | 2715 | \\} |
| ... | @@ -2609,31 +2730,31 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -2609,31 +2730,31 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2609 | "tmp.zig:10:25: error: error is ignored. consider using `try`, `catch`, or `if`", | 2730 | "tmp.zig:10:25: error: error is ignored. consider using `try`, `catch`, or `if`", |
| 2610 | }); | 2731 | }); |
| 2611 | | 2732 | |
| 2612 | cases.add("empty while loop body", | 2733 | ctx.objErrStage1("empty while loop body", |
| 2613 | \\export fn a() void { | 2734 | \\export fn a() void { |
| 2614 | \\ while(true); | 2735 | \\ while(true); |
| 2615 | \\} | 2736 | \\} |
| 2616 | , &[_][]const u8{ | 2737 | , &[_][]const u8{ |
| 2617 | "tmp.zig:2:16: error: expected loop body, found ';'", | 2738 | "tmp.zig:2:16: error: expected block or assignment, found ';'", |
| 2618 | }); | 2739 | }); |
| 2619 | | 2740 | |
| 2620 | cases.add("empty for loop body", | 2741 | ctx.objErrStage1("empty for loop body", |
| 2621 | \\export fn a() void { | 2742 | \\export fn a() void { |
| 2622 | \\ for(undefined) |x|; | 2743 | \\ for(undefined) |x|; |
| 2623 | \\} | 2744 | \\} |
| 2624 | , &[_][]const u8{ | 2745 | , &[_][]const u8{ |
| 2625 | "tmp.zig:2:23: error: expected loop body, found ';'", | 2746 | "tmp.zig:2:23: error: expected block or assignment, found ';'", |
| 2626 | }); | 2747 | }); |
| 2627 | | 2748 | |
| 2628 | cases.add("empty if body", | 2749 | ctx.objErrStage1("empty if body", |
| 2629 | \\export fn a() void { | 2750 | \\export fn a() void { |
| 2630 | \\ if(true); | 2751 | \\ if(true); |
| 2631 | \\} | 2752 | \\} |
| 2632 | , &[_][]const u8{ | 2753 | , &[_][]const u8{ |
| 2633 | "tmp.zig:2:13: error: expected if body, found ';'", | 2754 | "tmp.zig:2:13: error: expected block or assignment, found ';'", |
| 2634 | }); | 2755 | }); |
| 2635 | | 2756 | |
| 2636 | cases.add("import outside package path", | 2757 | ctx.objErrStage1("import outside package path", |
| 2637 | \\comptime{ | 2758 | \\comptime{ |
| 2638 | \\ _ = @import("../a.zig"); | 2759 | \\ _ = @import("../a.zig"); |
| 2639 | \\} | 2760 | \\} |
| ... | @@ -2641,14 +2762,14 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -2641,14 +2762,14 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2641 | "tmp.zig:2:9: error: import of file outside package path: '../a.zig'", | 2762 | "tmp.zig:2:9: error: import of file outside package path: '../a.zig'", |
| 2642 | }); | 2763 | }); |
| 2643 | | 2764 | |
| 2644 | cases.add("bogus compile var", | 2765 | ctx.objErrStage1("bogus compile var", |
| 2645 | \\const x = @import("builtin").bogus; | 2766 | \\const x = @import("builtin").bogus; |
| 2646 | \\export fn entry() usize { return @sizeOf(@TypeOf(x)); } | 2767 | \\export fn entry() usize { return @sizeOf(@TypeOf(x)); } |
| 2647 | , &[_][]const u8{ | 2768 | , &[_][]const u8{ |
| 2648 | "tmp.zig:1:29: error: container 'builtin' has no member called 'bogus'", | 2769 | "tmp.zig:1:29: error: container 'builtin' has no member called 'bogus'", |
| 2649 | }); | 2770 | }); |
| 2650 | | 2771 | |
| 2651 | cases.add("wrong panic signature, runtime function", | 2772 | ctx.objErrStage1("wrong panic signature, runtime function", |
| 2652 | \\test "" {} | 2773 | \\test "" {} |
| 2653 | \\ | 2774 | \\ |
| 2654 | \\pub fn panic() void {} | 2775 | \\pub fn panic() void {} |
| ... | @@ -2657,8 +2778,9 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -2657,8 +2778,9 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2657 | "error: expected type 'fn([]const u8, ?*std.builtin.StackTrace) noreturn', found 'fn() void'", | 2778 | "error: expected type 'fn([]const u8, ?*std.builtin.StackTrace) noreturn', found 'fn() void'", |
| 2658 | }); | 2779 | }); |
| 2659 | | 2780 | |
| 2660 | cases.add("wrong panic signature, generic function", | 2781 | ctx.objErrStage1("wrong panic signature, generic function", |
| 2661 | \\pub fn panic(comptime msg: []const u8, error_return_trace: ?*builtin.StackTrace) noreturn { | 2782 | \\pub fn panic(comptime msg: []const u8, error_return_trace: ?*builtin.StackTrace) noreturn { |
| | 2783 | \\ _ = msg; _ = error_return_trace; |
| 2662 | \\ while (true) {} | 2784 | \\ while (true) {} |
| 2663 | \\} | 2785 | \\} |
| 2664 | , &[_][]const u8{ | 2786 | , &[_][]const u8{ |
| ... | @@ -2666,14 +2788,14 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -2666,14 +2788,14 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2666 | "note: only one of the functions is generic", | 2788 | "note: only one of the functions is generic", |
| 2667 | }); | 2789 | }); |
| 2668 | | 2790 | |
| 2669 | cases.add("direct struct loop", | 2791 | ctx.objErrStage1("direct struct loop", |
| 2670 | \\const A = struct { a : A, }; | 2792 | \\const A = struct { a : A, }; |
| 2671 | \\export fn entry() usize { return @sizeOf(A); } | 2793 | \\export fn entry() usize { return @sizeOf(A); } |
| 2672 | , &[_][]const u8{ | 2794 | , &[_][]const u8{ |
| 2673 | "tmp.zig:1:11: error: struct 'A' depends on itself", | 2795 | "tmp.zig:1:11: error: struct 'A' depends on itself", |
| 2674 | }); | 2796 | }); |
| 2675 | | 2797 | |
| 2676 | cases.add("indirect struct loop", | 2798 | ctx.objErrStage1("indirect struct loop", |
| 2677 | \\const A = struct { b : B, }; | 2799 | \\const A = struct { b : B, }; |
| 2678 | \\const B = struct { c : C, }; | 2800 | \\const B = struct { c : C, }; |
| 2679 | \\const C = struct { a : A, }; | 2801 | \\const C = struct { a : A, }; |
| ... | @@ -2682,7 +2804,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -2682,7 +2804,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2682 | "tmp.zig:1:11: error: struct 'A' depends on itself", | 2804 | "tmp.zig:1:11: error: struct 'A' depends on itself", |
| 2683 | }); | 2805 | }); |
| 2684 | | 2806 | |
| 2685 | cases.add("instantiating an undefined value for an invalid struct that contains itself", | 2807 | ctx.objErrStage1("instantiating an undefined value for an invalid struct that contains itself", |
| 2686 | \\const Foo = struct { | 2808 | \\const Foo = struct { |
| 2687 | \\ x: Foo, | 2809 | \\ x: Foo, |
| 2688 | \\}; | 2810 | \\}; |
| ... | @@ -2697,23 +2819,25 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -2697,23 +2819,25 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2697 | "tmp.zig:8:28: note: referenced here", | 2819 | "tmp.zig:8:28: note: referenced here", |
| 2698 | }); | 2820 | }); |
| 2699 | | 2821 | |
| 2700 | cases.add("enum field value references enum", | 2822 | ctx.objErrStage1("enum field value references enum", |
| 2701 | \\pub const Foo = extern enum { | 2823 | \\pub const Foo = enum(c_int) { |
| 2702 | \\ A = Foo.B, | 2824 | \\ A = Foo.B, |
| 2703 | \\ C = D, | 2825 | \\ C = D, |
| 2704 | \\}; | 2826 | \\}; |
| 2705 | \\export fn entry() void { | 2827 | \\export fn entry() void { |
| 2706 | \\ var s: Foo = Foo.E; | 2828 | \\ var s: Foo = Foo.E; |
| | 2829 | \\ _ = s; |
| 2707 | \\} | 2830 | \\} |
| 2708 | , &[_][]const u8{ | 2831 | , &[_][]const u8{ |
| 2709 | "tmp.zig:1:17: error: enum 'Foo' depends on itself", | 2832 | "tmp.zig:1:17: error: enum 'Foo' depends on itself", |
| 2710 | }); | 2833 | }); |
| 2711 | | 2834 | |
| 2712 | cases.add("top level decl dependency loop", | 2835 | ctx.objErrStage1("top level decl dependency loop", |
| 2713 | \\const a : @TypeOf(b) = 0; | 2836 | \\const a : @TypeOf(b) = 0; |
| 2714 | \\const b : @TypeOf(a) = 0; | 2837 | \\const b : @TypeOf(a) = 0; |
| 2715 | \\export fn entry() void { | 2838 | \\export fn entry() void { |
| 2716 | \\ const c = a + b; | 2839 | \\ const c = a + b; |
| | 2840 | \\ _ = c; |
| 2717 | \\} | 2841 | \\} |
| 2718 | , &[_][]const u8{ | 2842 | , &[_][]const u8{ |
| 2719 | "tmp.zig:2:19: error: dependency loop detected", | 2843 | "tmp.zig:2:19: error: dependency loop detected", |
| ... | @@ -2721,7 +2845,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -2721,7 +2845,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2721 | "tmp.zig:4:15: note: referenced here", | 2845 | "tmp.zig:4:15: note: referenced here", |
| 2722 | }); | 2846 | }); |
| 2723 | | 2847 | |
| 2724 | cases.addTest("not an enum type", | 2848 | ctx.testErrStage1("not an enum type", |
| 2725 | \\export fn entry() void { | 2849 | \\export fn entry() void { |
| 2726 | \\ var self: Error = undefined; | 2850 | \\ var self: Error = undefined; |
| 2727 | \\ switch (self) { | 2851 | \\ switch (self) { |
| ... | @@ -2739,18 +2863,19 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -2739,18 +2863,19 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2739 | "tmp.zig:4:9: error: expected type '@typeInfo(Error).Union.tag_type.?', found 'type'", | 2863 | "tmp.zig:4:9: error: expected type '@typeInfo(Error).Union.tag_type.?', found 'type'", |
| 2740 | }); | 2864 | }); |
| 2741 | | 2865 | |
| 2742 | cases.addTest("binary OR operator on error sets", | 2866 | ctx.testErrStage1("binary OR operator on error sets", |
| 2743 | \\pub const A = error.A; | 2867 | \\pub const A = error.A; |
| 2744 | \\pub const AB = A | error.B; | 2868 | \\pub const AB = A | error.B; |
| 2745 | \\export fn entry() void { | 2869 | \\export fn entry() void { |
| 2746 | \\ var x: AB = undefined; | 2870 | \\ var x: AB = undefined; |
| | 2871 | \\ _ = x; |
| 2747 | \\} | 2872 | \\} |
| 2748 | , &[_][]const u8{ | 2873 | , &[_][]const u8{ |
| 2749 | "tmp.zig:2:18: error: invalid operands to binary expression: 'error{A}' and 'error{B}'", | 2874 | "tmp.zig:2:18: error: invalid operands to binary expression: 'error{A}' and 'error{B}'", |
| 2750 | }); | 2875 | }); |
| 2751 | | 2876 | |
| 2752 | if (std.Target.current.os.tag == .linux) { | 2877 | if (std.Target.current.os.tag == .linux) { |
| 2753 | cases.addTest("implicit dependency on libc", | 2878 | ctx.testErrStage1("implicit dependency on libc", |
| 2754 | \\extern "c" fn exit(u8) void; | 2879 | \\extern "c" fn exit(u8) void; |
| 2755 | \\export fn entry() void { | 2880 | \\export fn entry() void { |
| 2756 | \\ exit(0); | 2881 | \\ exit(0); |
| ... | @@ -2759,7 +2884,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -2759,7 +2884,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2759 | "tmp.zig:3:5: error: dependency on libc must be explicitly specified in the build command", | 2884 | "tmp.zig:3:5: error: dependency on libc must be explicitly specified in the build command", |
| 2760 | }); | 2885 | }); |
| 2761 | | 2886 | |
| 2762 | cases.addTest("libc headers note", | 2887 | ctx.testErrStage1("libc headers note", |
| 2763 | \\const c = @cImport(@cInclude("stdio.h")); | 2888 | \\const c = @cImport(@cInclude("stdio.h")); |
| 2764 | \\export fn entry() void { | 2889 | \\export fn entry() void { |
| 2765 | \\ _ = c.printf("hello, world!\n"); | 2890 | \\ _ = c.printf("hello, world!\n"); |
| ... | @@ -2770,18 +2895,19 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -2770,18 +2895,19 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2770 | }); | 2895 | }); |
| 2771 | } | 2896 | } |
| 2772 | | 2897 | |
| 2773 | cases.addTest("comptime vector overflow shows the index", | 2898 | ctx.testErrStage1("comptime vector overflow shows the index", |
| 2774 | \\comptime { | 2899 | \\comptime { |
| 2775 | \\ var a: @import("std").meta.Vector(4, u8) = [_]u8{ 1, 2, 255, 4 }; | 2900 | \\ var a: @import("std").meta.Vector(4, u8) = [_]u8{ 1, 2, 255, 4 }; |
| 2776 | \\ var b: @import("std").meta.Vector(4, u8) = [_]u8{ 5, 6, 1, 8 }; | 2901 | \\ var b: @import("std").meta.Vector(4, u8) = [_]u8{ 5, 6, 1, 8 }; |
| 2777 | \\ var x = a + b; | 2902 | \\ var x = a + b; |
| | 2903 | \\ _ = x; |
| 2778 | \\} | 2904 | \\} |
| 2779 | , &[_][]const u8{ | 2905 | , &[_][]const u8{ |
| 2780 | "tmp.zig:4:15: error: operation caused overflow", | 2906 | "tmp.zig:4:15: error: operation caused overflow", |
| 2781 | "tmp.zig:4:15: note: when computing vector element at index 2", | 2907 | "tmp.zig:4:15: note: when computing vector element at index 2", |
| 2782 | }); | 2908 | }); |
| 2783 | | 2909 | |
| 2784 | cases.addTest("packed struct with fields of not allowed types", | 2910 | ctx.testErrStage1("packed struct with fields of not allowed types", |
| 2785 | \\const A = packed struct { | 2911 | \\const A = packed struct { |
| 2786 | \\ x: anyerror, | 2912 | \\ x: anyerror, |
| 2787 | \\}; | 2913 | \\}; |
| ... | @@ -2805,24 +2931,31 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -2805,24 +2931,31 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2805 | \\}; | 2931 | \\}; |
| 2806 | \\export fn entry1() void { | 2932 | \\export fn entry1() void { |
| 2807 | \\ var a: A = undefined; | 2933 | \\ var a: A = undefined; |
| | 2934 | \\ _ = a; |
| 2808 | \\} | 2935 | \\} |
| 2809 | \\export fn entry2() void { | 2936 | \\export fn entry2() void { |
| 2810 | \\ var b: B = undefined; | 2937 | \\ var b: B = undefined; |
| | 2938 | \\ _ = b; |
| 2811 | \\} | 2939 | \\} |
| 2812 | \\export fn entry3() void { | 2940 | \\export fn entry3() void { |
| 2813 | \\ var r: C = undefined; | 2941 | \\ var r: C = undefined; |
| | 2942 | \\ _ = r; |
| 2814 | \\} | 2943 | \\} |
| 2815 | \\export fn entry4() void { | 2944 | \\export fn entry4() void { |
| 2816 | \\ var d: D = undefined; | 2945 | \\ var d: D = undefined; |
| | 2946 | \\ _ = d; |
| 2817 | \\} | 2947 | \\} |
| 2818 | \\export fn entry5() void { | 2948 | \\export fn entry5() void { |
| 2819 | \\ var e: E = undefined; | 2949 | \\ var e: E = undefined; |
| | 2950 | \\ _ = e; |
| 2820 | \\} | 2951 | \\} |
| 2821 | \\export fn entry6() void { | 2952 | \\export fn entry6() void { |
| 2822 | \\ var f: F = undefined; | 2953 | \\ var f: F = undefined; |
| | 2954 | \\ _ = f; |
| 2823 | \\} | 2955 | \\} |
| 2824 | \\export fn entry7() void { | 2956 | \\export fn entry7() void { |
| 2825 | \\ var g: G = undefined; | 2957 | \\ var g: G = undefined; |
| | 2958 | \\ _ = g; |
| 2826 | \\} | 2959 | \\} |
| 2827 | \\const S = struct { | 2960 | \\const S = struct { |
| 2828 | \\ x: i32, | 2961 | \\ x: i32, |
| ... | @@ -2843,42 +2976,40 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -2843,42 +2976,40 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2843 | "tmp.zig:14:5: error: non-packed, non-extern struct 'U' not allowed in packed struct; no guaranteed in-memory representation", | 2976 | "tmp.zig:14:5: error: non-packed, non-extern struct 'U' not allowed in packed struct; no guaranteed in-memory representation", |
| 2844 | "tmp.zig:17:5: error: type '?anyerror' not allowed in packed struct; no guaranteed in-memory representation", | 2977 | "tmp.zig:17:5: error: type '?anyerror' not allowed in packed struct; no guaranteed in-memory representation", |
| 2845 | "tmp.zig:20:5: error: type 'Enum' not allowed in packed struct; no guaranteed in-memory representation", | 2978 | "tmp.zig:20:5: error: type 'Enum' not allowed in packed struct; no guaranteed in-memory representation", |
| 2846 | "tmp.zig:50:14: note: enum declaration does not specify an integer tag type", | 2979 | "tmp.zig:57:14: note: enum declaration does not specify an integer tag type", |
| 2847 | }); | 2980 | }); |
| 2848 | | 2981 | |
| 2849 | cases.addCase(x: { | 2982 | ctx.objErrStage1("deduplicate undeclared identifier", |
| 2850 | var tc = cases.create("deduplicate undeclared identifier", | 2983 | \\export fn a() void { |
| 2851 | \\export fn a() void { | 2984 | \\ x += 1; |
| 2852 | \\ x += 1; | 2985 | \\} |
| 2853 | \\} | 2986 | \\export fn b() void { |
| 2854 | \\export fn b() void { | 2987 | \\ x += 1; |
| 2855 | \\ x += 1; | 2988 | \\} |
| 2856 | \\} | 2989 | , &[_][]const u8{ |
| 2857 | , &[_][]const u8{ | 2990 | "tmp.zig:2:5: error: use of undeclared identifier 'x'", |
| 2858 | "tmp.zig:2:5: error: use of undeclared identifier 'x'", | | |
| 2859 | }); | | |
| 2860 | tc.expect_exact = true; | | |
| 2861 | break :x tc; | | |
| 2862 | }); | 2991 | }); |
| 2863 | | 2992 | |
| 2864 | cases.add("export generic function", | 2993 | ctx.objErrStage1("export generic function", |
| 2865 | \\export fn foo(num: anytype) i32 { | 2994 | \\export fn foo(num: anytype) i32 { |
| | 2995 | \\ _ = num; |
| 2866 | \\ return 0; | 2996 | \\ return 0; |
| 2867 | \\} | 2997 | \\} |
| 2868 | , &[_][]const u8{ | 2998 | , &[_][]const u8{ |
| 2869 | "tmp.zig:1:15: error: parameter of type 'anytype' not allowed in function with calling convention 'C'", | 2999 | "tmp.zig:1:15: error: parameter of type 'anytype' not allowed in function with calling convention 'C'", |
| 2870 | }); | 3000 | }); |
| 2871 | | 3001 | |
| 2872 | cases.add("C pointer to c_void", | 3002 | ctx.objErrStage1("C pointer to c_void", |
| 2873 | \\export fn a() void { | 3003 | \\export fn a() void { |
| 2874 | \\ var x: *c_void = undefined; | 3004 | \\ var x: *c_void = undefined; |
| 2875 | \\ var y: [*c]c_void = x; | 3005 | \\ var y: [*c]c_void = x; |
| | 3006 | \\ _ = y; |
| 2876 | \\} | 3007 | \\} |
| 2877 | , &[_][]const u8{ | 3008 | , &[_][]const u8{ |
| 2878 | "tmp.zig:3:16: error: C pointers cannot point to opaque types", | 3009 | "tmp.zig:3:16: error: C pointers cannot point to opaque types", |
| 2879 | }); | 3010 | }); |
| 2880 | | 3011 | |
| 2881 | cases.add("directly embedding opaque type in struct and union", | 3012 | ctx.objErrStage1("directly embedding opaque type in struct and union", |
| 2882 | \\const O = opaque {}; | 3013 | \\const O = opaque {}; |
| 2883 | \\const Foo = struct { | 3014 | \\const Foo = struct { |
| 2884 | \\ o: O, | 3015 | \\ o: O, |
| ... | @@ -2889,74 +3020,85 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -2889,74 +3020,85 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2889 | \\}; | 3020 | \\}; |
| 2890 | \\export fn a() void { | 3021 | \\export fn a() void { |
| 2891 | \\ var foo: Foo = undefined; | 3022 | \\ var foo: Foo = undefined; |
| | 3023 | \\ _ = foo; |
| 2892 | \\} | 3024 | \\} |
| 2893 | \\export fn b() void { | 3025 | \\export fn b() void { |
| 2894 | \\ var bar: Bar = undefined; | 3026 | \\ var bar: Bar = undefined; |
| | 3027 | \\ _ = bar; |
| 2895 | \\} | 3028 | \\} |
| 2896 | \\export fn c() void { | 3029 | \\export fn c() void { |
| 2897 | \\ var baz: *opaque {} = undefined; | 3030 | \\ var baz: *opaque {} = undefined; |
| 2898 | \\ const qux = .{baz.*}; | 3031 | \\ const qux = .{baz.*}; |
| | 3032 | \\ _ = qux; |
| 2899 | \\} | 3033 | \\} |
| 2900 | , &[_][]const u8{ | 3034 | , &[_][]const u8{ |
| 2901 | "tmp.zig:3:5: error: opaque types have unknown size and therefore cannot be directly embedded in structs", | 3035 | "tmp.zig:3:5: error: opaque types have unknown size and therefore cannot be directly embedded in structs", |
| 2902 | "tmp.zig:7:5: error: opaque types have unknown size and therefore cannot be directly embedded in unions", | 3036 | "tmp.zig:7:5: error: opaque types have unknown size and therefore cannot be directly embedded in unions", |
| 2903 | "tmp.zig:17:22: error: opaque types have unknown size and therefore cannot be directly embedded in structs", | 3037 | "tmp.zig:19:22: error: opaque types have unknown size and therefore cannot be directly embedded in structs", |
| 2904 | }); | 3038 | }); |
| 2905 | | 3039 | |
| 2906 | cases.add("implicit cast between C pointer and Zig pointer - bad const/align/child", | 3040 | ctx.objErrStage1("implicit cast between C pointer and Zig pointer - bad const/align/child", |
| 2907 | \\export fn a() void { | 3041 | \\export fn a() void { |
| 2908 | \\ var x: [*c]u8 = undefined; | 3042 | \\ var x: [*c]u8 = undefined; |
| 2909 | \\ var y: *align(4) u8 = x; | 3043 | \\ var y: *align(4) u8 = x; |
| | 3044 | \\ _ = y; |
| 2910 | \\} | 3045 | \\} |
| 2911 | \\export fn b() void { | 3046 | \\export fn b() void { |
| 2912 | \\ var x: [*c]const u8 = undefined; | 3047 | \\ var x: [*c]const u8 = undefined; |
| 2913 | \\ var y: *u8 = x; | 3048 | \\ var y: *u8 = x; |
| | 3049 | \\ _ = y; |
| 2914 | \\} | 3050 | \\} |
| 2915 | \\export fn c() void { | 3051 | \\export fn c() void { |
| 2916 | \\ var x: [*c]u8 = undefined; | 3052 | \\ var x: [*c]u8 = undefined; |
| 2917 | \\ var y: *u32 = x; | 3053 | \\ var y: *u32 = x; |
| | 3054 | \\ _ = y; |
| 2918 | \\} | 3055 | \\} |
| 2919 | \\export fn d() void { | 3056 | \\export fn d() void { |
| 2920 | \\ var y: *align(1) u32 = undefined; | 3057 | \\ var y: *align(1) u32 = undefined; |
| 2921 | \\ var x: [*c]u32 = y; | 3058 | \\ var x: [*c]u32 = y; |
| | 3059 | \\ _ = x; |
| 2922 | \\} | 3060 | \\} |
| 2923 | \\export fn e() void { | 3061 | \\export fn e() void { |
| 2924 | \\ var y: *const u8 = undefined; | 3062 | \\ var y: *const u8 = undefined; |
| 2925 | \\ var x: [*c]u8 = y; | 3063 | \\ var x: [*c]u8 = y; |
| | 3064 | \\ _ = x; |
| 2926 | \\} | 3065 | \\} |
| 2927 | \\export fn f() void { | 3066 | \\export fn f() void { |
| 2928 | \\ var y: *u8 = undefined; | 3067 | \\ var y: *u8 = undefined; |
| 2929 | \\ var x: [*c]u32 = y; | 3068 | \\ var x: [*c]u32 = y; |
| | 3069 | \\ _ = x; |
| 2930 | \\} | 3070 | \\} |
| 2931 | , &[_][]const u8{ | 3071 | , &[_][]const u8{ |
| 2932 | "tmp.zig:3:27: error: cast increases pointer alignment", | 3072 | "tmp.zig:3:27: error: cast increases pointer alignment", |
| 2933 | "tmp.zig:7:18: error: cast discards const qualifier", | 3073 | "tmp.zig:8:18: error: cast discards const qualifier", |
| 2934 | "tmp.zig:11:19: error: expected type '*u32', found '[*c]u8'", | 3074 | "tmp.zig:13: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'", | 3075 | "tmp.zig:13:19: note: pointer type child 'u8' cannot cast into pointer type child 'u32'", |
| 2936 | "tmp.zig:15:22: error: cast increases pointer alignment", | 3076 | "tmp.zig:18:22: error: cast increases pointer alignment", |
| 2937 | "tmp.zig:19:21: error: cast discards const qualifier", | 3077 | "tmp.zig:23:21: error: cast discards const qualifier", |
| 2938 | "tmp.zig:23:22: error: expected type '[*c]u32', found '*u8'", | 3078 | "tmp.zig:28:22: error: expected type '[*c]u32', found '*u8'", |
| 2939 | }); | 3079 | }); |
| 2940 | | 3080 | |
| 2941 | cases.add("implicit casting null c pointer to zig pointer", | 3081 | ctx.objErrStage1("implicit casting null c pointer to zig pointer", |
| 2942 | \\comptime { | 3082 | \\comptime { |
| 2943 | \\ var c_ptr: [*c]u8 = 0; | 3083 | \\ var c_ptr: [*c]u8 = 0; |
| 2944 | \\ var zig_ptr: *u8 = c_ptr; | 3084 | \\ var zig_ptr: *u8 = c_ptr; |
| | 3085 | \\ _ = zig_ptr; |
| 2945 | \\} | 3086 | \\} |
| 2946 | , &[_][]const u8{ | 3087 | , &[_][]const u8{ |
| 2947 | "tmp.zig:3:24: error: null pointer casted to type '*u8'", | 3088 | "tmp.zig:3:24: error: null pointer casted to type '*u8'", |
| 2948 | }); | 3089 | }); |
| 2949 | | 3090 | |
| 2950 | cases.add("implicit casting undefined c pointer to zig pointer", | 3091 | ctx.objErrStage1("implicit casting undefined c pointer to zig pointer", |
| 2951 | \\comptime { | 3092 | \\comptime { |
| 2952 | \\ var c_ptr: [*c]u8 = undefined; | 3093 | \\ var c_ptr: [*c]u8 = undefined; |
| 2953 | \\ var zig_ptr: *u8 = c_ptr; | 3094 | \\ var zig_ptr: *u8 = c_ptr; |
| | 3095 | \\ _ = zig_ptr; |
| 2954 | \\} | 3096 | \\} |
| 2955 | , &[_][]const u8{ | 3097 | , &[_][]const u8{ |
| 2956 | "tmp.zig:3:24: error: use of undefined value here causes undefined behavior", | 3098 | "tmp.zig:3:24: error: use of undefined value here causes undefined behavior", |
| 2957 | }); | 3099 | }); |
| 2958 | | 3100 | |
| 2959 | cases.add("implicit casting C pointers which would mess up null semantics", | 3101 | ctx.objErrStage1("implicit casting C pointers which would mess up null semantics", |
| 2960 | \\export fn entry() void { | 3102 | \\export fn entry() void { |
| 2961 | \\ var slice: []const u8 = "aoeu"; | 3103 | \\ var slice: []const u8 = "aoeu"; |
| 2962 | \\ const opt_many_ptr: [*]const u8 = slice.ptr; | 3104 | \\ const opt_many_ptr: [*]const u8 = slice.ptr; |
| ... | @@ -2970,6 +3112,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -2970,6 +3112,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2970 | \\ var opt_many_ptr: [*]u8 = slice.ptr; | 3112 | \\ var opt_many_ptr: [*]u8 = slice.ptr; |
| 2971 | \\ var ptr_opt_many_ptr = &opt_many_ptr; | 3113 | \\ var ptr_opt_many_ptr = &opt_many_ptr; |
| 2972 | \\ var c_ptr: [*c][*c]const u8 = ptr_opt_many_ptr; | 3114 | \\ var c_ptr: [*c][*c]const u8 = ptr_opt_many_ptr; |
| | 3115 | \\ _ = c_ptr; |
| 2973 | \\} | 3116 | \\} |
| 2974 | , &[_][]const u8{ | 3117 | , &[_][]const u8{ |
| 2975 | "tmp.zig:6:24: error: expected type '*const [*]const u8', found '[*c]const [*c]const u8'", | 3118 | "tmp.zig:6:24: error: expected type '*const [*]const u8', found '[*c]const [*c]const u8'", |
| ... | @@ -2980,47 +3123,46 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -2980,47 +3123,46 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2980 | "tmp.zig:13:35: note: mutable '[*c]const u8' allows illegal null values stored to type '[*]u8'", | 3123 | "tmp.zig:13:35: note: mutable '[*c]const u8' allows illegal null values stored to type '[*]u8'", |
| 2981 | }); | 3124 | }); |
| 2982 | | 3125 | |
| 2983 | cases.add("implicit casting too big integers to C pointers", | 3126 | ctx.objErrStage1("implicit casting too big integers to C pointers", |
| 2984 | \\export fn a() void { | 3127 | \\export fn a() void { |
| 2985 | \\ var ptr: [*c]u8 = (1 << 64) + 1; | 3128 | \\ var ptr: [*c]u8 = (1 << 64) + 1; |
| | 3129 | \\ _ = ptr; |
| 2986 | \\} | 3130 | \\} |
| 2987 | \\export fn b() void { | 3131 | \\export fn b() void { |
| 2988 | \\ var x: u65 = 0x1234; | 3132 | \\ var x: u65 = 0x1234; |
| 2989 | \\ var ptr: [*c]u8 = x; | 3133 | \\ var ptr: [*c]u8 = x; |
| | 3134 | \\ _ = ptr; |
| 2990 | \\} | 3135 | \\} |
| 2991 | , &[_][]const u8{ | 3136 | , &[_][]const u8{ |
| 2992 | "tmp.zig:2:33: error: integer value 18446744073709551617 cannot be coerced to type 'usize'", | 3137 | "tmp.zig:2:33: error: integer value 18446744073709551617 cannot be coerced to type 'usize'", |
| 2993 | "tmp.zig:6:23: error: integer type 'u65' too big for implicit @intToPtr to type '[*c]u8'", | 3138 | "tmp.zig:7:23: error: integer type 'u65' too big for implicit @intToPtr to type '[*c]u8'", |
| 2994 | }); | 3139 | }); |
| 2995 | | 3140 | |
| 2996 | cases.add("C pointer pointing to non C ABI compatible type or has align attr", | 3141 | ctx.objErrStage1("C pointer pointing to non C ABI compatible type or has align attr", |
| 2997 | \\const Foo = struct {}; | 3142 | \\const Foo = struct {}; |
| 2998 | \\export fn a() void { | 3143 | \\export fn a() void { |
| 2999 | \\ const T = [*c]Foo; | 3144 | \\ const T = [*c]Foo; |
| 3000 | \\ var t: T = undefined; | 3145 | \\ var t: T = undefined; |
| | 3146 | \\ _ = t; |
| 3001 | \\} | 3147 | \\} |
| 3002 | , &[_][]const u8{ | 3148 | , &[_][]const u8{ |
| 3003 | "tmp.zig:3:19: error: C pointers cannot point to non-C-ABI-compatible type 'Foo'", | 3149 | "tmp.zig:3:19: error: C pointers cannot point to non-C-ABI-compatible type 'Foo'", |
| 3004 | }); | 3150 | }); |
| 3005 | | 3151 | |
| 3006 | cases.addCase(x: { | 3152 | ctx.objErrStage1("compile log statement warning deduplication in generic fn", |
| 3007 | var tc = cases.create("compile log statement warning deduplication in generic fn", | 3153 | \\export fn entry() void { |
| 3008 | \\export fn entry() void { | 3154 | \\ inner(1); |
| 3009 | \\ inner(1); | 3155 | \\ inner(2); |
| 3010 | \\ inner(2); | 3156 | \\} |
| 3011 | \\} | 3157 | \\fn inner(comptime n: usize) void { |
| 3012 | \\fn inner(comptime n: usize) void { | 3158 | \\ comptime var i = 0; |
| 3013 | \\ comptime var i = 0; | 3159 | \\ inline while (i < n) : (i += 1) { @compileLog("!@#$"); } |
| 3014 | \\ inline while (i < n) : (i += 1) { @compileLog("!@#$"); } | 3160 | \\} |
| 3015 | \\} | 3161 | , &[_][]const u8{ |
| 3016 | , &[_][]const u8{ | 3162 | "tmp.zig:7:39: error: found compile log statement", |
| 3017 | "tmp.zig:7:39: error: found compile log statement", | | |
| 3018 | }); | | |
| 3019 | tc.expect_exact = true; | | |
| 3020 | break :x tc; | | |
| 3021 | }); | 3163 | }); |
| 3022 | | 3164 | |
| 3023 | cases.add("assign to invalid dereference", | 3165 | ctx.objErrStage1("assign to invalid dereference", |
| 3024 | \\export fn entry() void { | 3166 | \\export fn entry() void { |
| 3025 | \\ 'a'.* = 1; | 3167 | \\ 'a'.* = 1; |
| 3026 | \\} | 3168 | \\} |
| ... | @@ -3028,54 +3170,58 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -3028,54 +3170,58 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3028 | "tmp.zig:2:8: error: attempt to dereference non-pointer type 'comptime_int'", | 3170 | "tmp.zig:2:8: error: attempt to dereference non-pointer type 'comptime_int'", |
| 3029 | }); | 3171 | }); |
| 3030 | | 3172 | |
| 3031 | cases.add("take slice of invalid dereference", | 3173 | ctx.objErrStage1("take slice of invalid dereference", |
| 3032 | \\export fn entry() void { | 3174 | \\export fn entry() void { |
| 3033 | \\ const x = 'a'.*[0..]; | 3175 | \\ const x = 'a'.*[0..]; |
| | 3176 | \\ _ = x; |
| 3034 | \\} | 3177 | \\} |
| 3035 | , &[_][]const u8{ | 3178 | , &[_][]const u8{ |
| 3036 | "tmp.zig:2:18: error: attempt to dereference non-pointer type 'comptime_int'", | 3179 | "tmp.zig:2:18: error: attempt to dereference non-pointer type 'comptime_int'", |
| 3037 | }); | 3180 | }); |
| 3038 | | 3181 | |
| 3039 | cases.add("@truncate undefined value", | 3182 | ctx.objErrStage1("@truncate undefined value", |
| 3040 | \\export fn entry() void { | 3183 | \\export fn entry() void { |
| 3041 | \\ var z = @truncate(u8, @as(u16, undefined)); | 3184 | \\ var z = @truncate(u8, @as(u16, undefined)); |
| | 3185 | \\ _ = z; |
| 3042 | \\} | 3186 | \\} |
| 3043 | , &[_][]const u8{ | 3187 | , &[_][]const u8{ |
| 3044 | "tmp.zig:2:27: error: use of undefined value here causes undefined behavior", | 3188 | "tmp.zig:2:27: error: use of undefined value here causes undefined behavior", |
| 3045 | }); | 3189 | }); |
| 3046 | | 3190 | |
| 3047 | cases.addTest("return invalid type from test", | 3191 | ctx.testErrStage1("return invalid type from test", |
| 3048 | \\test "example" { return 1; } | 3192 | \\test "example" { return 1; } |
| 3049 | , &[_][]const u8{ | 3193 | , &[_][]const u8{ |
| 3050 | "tmp.zig:1:25: error: expected type 'void', found 'comptime_int'", | 3194 | "tmp.zig:1:25: error: expected type 'void', found 'comptime_int'", |
| 3051 | }); | 3195 | }); |
| 3052 | | 3196 | |
| 3053 | cases.add("threadlocal qualifier on const", | 3197 | ctx.objErrStage1("threadlocal qualifier on const", |
| 3054 | \\threadlocal const x: i32 = 1234; | 3198 | \\threadlocal const x: i32 = 1234; |
| 3055 | \\export fn entry() i32 { | 3199 | \\export fn entry() i32 { |
| 3056 | \\ return x; | 3200 | \\ return x; |
| 3057 | \\} | 3201 | \\} |
| 3058 | , &[_][]const u8{ | 3202 | , &[_][]const u8{ |
| 3059 | "tmp.zig:1:13: error: threadlocal variable cannot be constant", | 3203 | "tmp.zig:1:1: error: threadlocal variable cannot be constant", |
| 3060 | }); | 3204 | }); |
| 3061 | | 3205 | |
| 3062 | cases.add("@bitCast same size but bit count mismatch", | 3206 | ctx.objErrStage1("@bitCast same size but bit count mismatch", |
| 3063 | \\export fn entry(byte: u8) void { | 3207 | \\export fn entry(byte: u8) void { |
| 3064 | \\ var oops = @bitCast(u7, byte); | 3208 | \\ var oops = @bitCast(u7, byte); |
| | 3209 | \\ _ = oops; |
| 3065 | \\} | 3210 | \\} |
| 3066 | , &[_][]const u8{ | 3211 | , &[_][]const u8{ |
| 3067 | "tmp.zig:2:25: error: destination type 'u7' has 7 bits but source type 'u8' has 8 bits", | 3212 | "tmp.zig:2:25: error: destination type 'u7' has 7 bits but source type 'u8' has 8 bits", |
| 3068 | }); | 3213 | }); |
| 3069 | | 3214 | |
| 3070 | cases.add("@bitCast with different sizes inside an expression", | 3215 | ctx.objErrStage1("@bitCast with different sizes inside an expression", |
| 3071 | \\export fn entry() void { | 3216 | \\export fn entry() void { |
| 3072 | \\ var foo = (@bitCast(u8, @as(f32, 1.0)) == 0xf); | 3217 | \\ var foo = (@bitCast(u8, @as(f32, 1.0)) == 0xf); |
| | 3218 | \\ _ = foo; |
| 3073 | \\} | 3219 | \\} |
| 3074 | , &[_][]const u8{ | 3220 | , &[_][]const u8{ |
| 3075 | "tmp.zig:2:25: error: destination type 'u8' has size 1 but source type 'f32' has size 4", | 3221 | "tmp.zig:2:25: error: destination type 'u8' has size 1 but source type 'f32' has size 4", |
| 3076 | }); | 3222 | }); |
| 3077 | | 3223 | |
| 3078 | cases.add("attempted `&&`", | 3224 | ctx.objErrStage1("attempted `&&`", |
| 3079 | \\export fn entry(a: bool, b: bool) i32 { | 3225 | \\export fn entry(a: bool, b: bool) i32 { |
| 3080 | \\ if (a && b) { | 3226 | \\ if (a && b) { |
| 3081 | \\ return 1234; | 3227 | \\ return 1234; |
| ... | @@ -3083,10 +3229,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -3083,10 +3229,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3083 | \\ return 5678; | 3229 | \\ return 5678; |
| 3084 | \\} | 3230 | \\} |
| 3085 | , &[_][]const u8{ | 3231 | , &[_][]const u8{ |
| 3086 | "tmp.zig:2:12: error: `&&` is invalid. Note that `and` is boolean AND", | 3232 | "tmp.zig:2:11: error: `&&` is invalid; note that `and` is boolean AND", |
| 3087 | }); | 3233 | }); |
| 3088 | | 3234 | |
| 3089 | cases.add("attempted `||` on boolean values", | 3235 | ctx.objErrStage1("attempted `||` on boolean values", |
| 3090 | \\export fn entry(a: bool, b: bool) i32 { | 3236 | \\export fn entry(a: bool, b: bool) i32 { |
| 3091 | \\ if (a || b) { | 3237 | \\ if (a || b) { |
| 3092 | \\ return 1234; | 3238 | \\ return 1234; |
| ... | @@ -3098,7 +3244,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -3098,7 +3244,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3098 | "tmp.zig:2:11: note: `||` merges error sets; `or` performs boolean OR", | 3244 | "tmp.zig:2:11: note: `||` merges error sets; `or` performs boolean OR", |
| 3099 | }); | 3245 | }); |
| 3100 | | 3246 | |
| 3101 | cases.add("compile log a pointer to an opaque value", | 3247 | ctx.objErrStage1("compile log a pointer to an opaque value", |
| 3102 | \\export fn entry() void { | 3248 | \\export fn entry() void { |
| 3103 | \\ @compileLog(@ptrCast(*const c_void, &entry)); | 3249 | \\ @compileLog(@ptrCast(*const c_void, &entry)); |
| 3104 | \\} | 3250 | \\} |
| ... | @@ -3106,13 +3252,14 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -3106,13 +3252,14 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3106 | "tmp.zig:2:5: error: found compile log statement", | 3252 | "tmp.zig:2:5: error: found compile log statement", |
| 3107 | }); | 3253 | }); |
| 3108 | | 3254 | |
| 3109 | cases.add("duplicate boolean switch value", | 3255 | ctx.objErrStage1("duplicate boolean switch value", |
| 3110 | \\comptime { | 3256 | \\comptime { |
| 3111 | \\ const x = switch (true) { | 3257 | \\ const x = switch (true) { |
| 3112 | \\ true => false, | 3258 | \\ true => false, |
| 3113 | \\ false => true, | 3259 | \\ false => true, |
| 3114 | \\ true => false, | 3260 | \\ true => false, |
| 3115 | \\ }; | 3261 | \\ }; |
| | 3262 | \\ _ = x; |
| 3116 | \\} | 3263 | \\} |
| 3117 | \\comptime { | 3264 | \\comptime { |
| 3118 | \\ const x = switch (true) { | 3265 | \\ const x = switch (true) { |
| ... | @@ -3120,42 +3267,46 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -3120,42 +3267,46 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3120 | \\ true => false, | 3267 | \\ true => false, |
| 3121 | \\ false => true, | 3268 | \\ false => true, |
| 3122 | \\ }; | 3269 | \\ }; |
| | 3270 | \\ _ = x; |
| 3123 | \\} | 3271 | \\} |
| 3124 | , &[_][]const u8{ | 3272 | , &[_][]const u8{ |
| 3125 | "tmp.zig:5:9: error: duplicate switch value", | 3273 | "tmp.zig:5:9: error: duplicate switch value", |
| 3126 | "tmp.zig:12:9: error: duplicate switch value", | 3274 | "tmp.zig:13:9: error: duplicate switch value", |
| 3127 | }); | 3275 | }); |
| 3128 | | 3276 | |
| 3129 | cases.add("missing boolean switch value", | 3277 | ctx.objErrStage1("missing boolean switch value", |
| 3130 | \\comptime { | 3278 | \\comptime { |
| 3131 | \\ const x = switch (true) { | 3279 | \\ const x = switch (true) { |
| 3132 | \\ true => false, | 3280 | \\ true => false, |
| 3133 | \\ }; | 3281 | \\ }; |
| | 3282 | \\ _ = x; |
| 3134 | \\} | 3283 | \\} |
| 3135 | \\comptime { | 3284 | \\comptime { |
| 3136 | \\ const x = switch (true) { | 3285 | \\ const x = switch (true) { |
| 3137 | \\ false => true, | 3286 | \\ false => true, |
| 3138 | \\ }; | 3287 | \\ }; |
| | 3288 | \\ _ = x; |
| 3139 | \\} | 3289 | \\} |
| 3140 | , &[_][]const u8{ | 3290 | , &[_][]const u8{ |
| 3141 | "tmp.zig:2:15: error: switch must handle all possibilities", | 3291 | "tmp.zig:2:15: error: switch must handle all possibilities", |
| 3142 | "tmp.zig:7:15: error: switch must handle all possibilities", | 3292 | "tmp.zig:8:15: error: switch must handle all possibilities", |
| 3143 | }); | 3293 | }); |
| 3144 | | 3294 | |
| 3145 | cases.add("reading past end of pointer casted array", | 3295 | ctx.objErrStage1("reading past end of pointer casted array", |
| 3146 | \\comptime { | 3296 | \\comptime { |
| 3147 | \\ const array: [4]u8 = "aoeu".*; | 3297 | \\ const array: [4]u8 = "aoeu".*; |
| 3148 | \\ const sub_array = array[1..]; | 3298 | \\ const sub_array = array[1..]; |
| 3149 | \\ const int_ptr = @ptrCast(*const u24, sub_array); | 3299 | \\ const int_ptr = @ptrCast(*const u24, sub_array); |
| 3150 | \\ const deref = int_ptr.*; | 3300 | \\ const deref = int_ptr.*; |
| | 3301 | \\ _ = deref; |
| 3151 | \\} | 3302 | \\} |
| 3152 | , &[_][]const u8{ | 3303 | , &[_][]const u8{ |
| 3153 | "tmp.zig:5:26: error: attempt to read 4 bytes from [4]u8 at index 1 which is 3 bytes", | 3304 | "tmp.zig:5:26: error: attempt to read 4 bytes from [4]u8 at index 1 which is 3 bytes", |
| 3154 | }); | 3305 | }); |
| 3155 | | 3306 | |
| 3156 | cases.add("error note for function parameter incompatibility", | 3307 | ctx.objErrStage1("error note for function parameter incompatibility", |
| 3157 | \\fn do_the_thing(func: fn (arg: i32) void) void {} | 3308 | \\fn do_the_thing(func: fn (arg: i32) void) void { _ = func; } |
| 3158 | \\fn bar(arg: bool) void {} | 3309 | \\fn bar(arg: bool) void { _ = arg; } |
| 3159 | \\export fn entry() void { | 3310 | \\export fn entry() void { |
| 3160 | \\ do_the_thing(bar); | 3311 | \\ do_the_thing(bar); |
| 3161 | \\} | 3312 | \\} |
| ... | @@ -3163,56 +3314,63 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -3163,56 +3314,63 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3163 | "tmp.zig:4:18: error: expected type 'fn(i32) void', found 'fn(bool) void", | 3314 | "tmp.zig:4:18: error: expected type 'fn(i32) void', found 'fn(bool) void", |
| 3164 | "tmp.zig:4:18: note: parameter 0: 'bool' cannot cast into 'i32'", | 3315 | "tmp.zig:4:18: note: parameter 0: 'bool' cannot cast into 'i32'", |
| 3165 | }); | 3316 | }); |
| 3166 | cases.add("cast negative value to unsigned integer", | 3317 | ctx.objErrStage1("cast negative value to unsigned integer", |
| 3167 | \\comptime { | 3318 | \\comptime { |
| 3168 | \\ const value: i32 = -1; | 3319 | \\ const value: i32 = -1; |
| 3169 | \\ const unsigned = @intCast(u32, value); | 3320 | \\ const unsigned = @intCast(u32, value); |
| | 3321 | \\ _ = unsigned; |
| 3170 | \\} | 3322 | \\} |
| 3171 | \\export fn entry1() void { | 3323 | \\export fn entry1() void { |
| 3172 | \\ const value: i32 = -1; | 3324 | \\ const value: i32 = -1; |
| 3173 | \\ const unsigned: u32 = value; | 3325 | \\ const unsigned: u32 = value; |
| | 3326 | \\ _ = unsigned; |
| 3174 | \\} | 3327 | \\} |
| 3175 | , &[_][]const u8{ | 3328 | , &[_][]const u8{ |
| 3176 | "tmp.zig:3:22: error: attempt to cast negative value to unsigned integer", | 3329 | "tmp.zig:3:22: error: attempt to cast negative value to unsigned integer", |
| 3177 | "tmp.zig:7:27: error: cannot cast negative value -1 to unsigned integer type 'u32'", | 3330 | "tmp.zig:8:27: error: cannot cast negative value -1 to unsigned integer type 'u32'", |
| 3178 | }); | 3331 | }); |
| 3179 | | 3332 | |
| 3180 | cases.add("integer cast truncates bits", | 3333 | ctx.objErrStage1("integer cast truncates bits", |
| 3181 | \\export fn entry1() void { | 3334 | \\export fn entry1() void { |
| 3182 | \\ const spartan_count: u16 = 300; | 3335 | \\ const spartan_count: u16 = 300; |
| 3183 | \\ const byte = @intCast(u8, spartan_count); | 3336 | \\ const byte = @intCast(u8, spartan_count); |
| | 3337 | \\ _ = byte; |
| 3184 | \\} | 3338 | \\} |
| 3185 | \\export fn entry2() void { | 3339 | \\export fn entry2() void { |
| 3186 | \\ const spartan_count: u16 = 300; | 3340 | \\ const spartan_count: u16 = 300; |
| 3187 | \\ const byte: u8 = spartan_count; | 3341 | \\ const byte: u8 = spartan_count; |
| | 3342 | \\ _ = byte; |
| 3188 | \\} | 3343 | \\} |
| 3189 | \\export fn entry3() void { | 3344 | \\export fn entry3() void { |
| 3190 | \\ var spartan_count: u16 = 300; | 3345 | \\ var spartan_count: u16 = 300; |
| 3191 | \\ var byte: u8 = spartan_count; | 3346 | \\ var byte: u8 = spartan_count; |
| | 3347 | \\ _ = byte; |
| 3192 | \\} | 3348 | \\} |
| 3193 | \\export fn entry4() void { | 3349 | \\export fn entry4() void { |
| 3194 | \\ var signed: i8 = -1; | 3350 | \\ var signed: i8 = -1; |
| 3195 | \\ var unsigned: u64 = signed; | 3351 | \\ var unsigned: u64 = signed; |
| | 3352 | \\ _ = unsigned; |
| 3196 | \\} | 3353 | \\} |
| 3197 | , &[_][]const u8{ | 3354 | , &[_][]const u8{ |
| 3198 | "tmp.zig:3:18: error: cast from 'u16' to 'u8' truncates bits", | 3355 | "tmp.zig:3:18: error: cast from 'u16' to 'u8' truncates bits", |
| 3199 | "tmp.zig:7:22: error: integer value 300 cannot be coerced to type 'u8'", | 3356 | "tmp.zig:8:22: error: integer value 300 cannot be coerced to type 'u8'", |
| 3200 | "tmp.zig:11:20: error: expected type 'u8', found 'u16'", | 3357 | "tmp.zig:13: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", | 3358 | "tmp.zig:13: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'", | 3359 | "tmp.zig:18: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", | 3360 | "tmp.zig:18:25: note: unsigned 64-bit int cannot represent all possible signed 8-bit values", |
| 3204 | }); | 3361 | }); |
| 3205 | | 3362 | |
| 3206 | cases.add("comptime implicit cast f64 to f32", | 3363 | ctx.objErrStage1("comptime implicit cast f64 to f32", |
| 3207 | \\export fn entry() void { | 3364 | \\export fn entry() void { |
| 3208 | \\ const x: f64 = 16777217; | 3365 | \\ const x: f64 = 16777217; |
| 3209 | \\ const y: f32 = x; | 3366 | \\ const y: f32 = x; |
| | 3367 | \\ _ = y; |
| 3210 | \\} | 3368 | \\} |
| 3211 | , &[_][]const u8{ | 3369 | , &[_][]const u8{ |
| 3212 | "tmp.zig:3:20: error: cast of value 16777217.000000 to type 'f32' loses information", | 3370 | "tmp.zig:3:20: error: cast of value 16777217.000000 to type 'f32' loses information", |
| 3213 | }); | 3371 | }); |
| 3214 | | 3372 | |
| 3215 | cases.add("implicit cast from f64 to f32", | 3373 | ctx.objErrStage1("implicit cast from f64 to f32", |
| 3216 | \\var x: f64 = 1.0; | 3374 | \\var x: f64 = 1.0; |
| 3217 | \\var y: f32 = x; | 3375 | \\var y: f32 = x; |
| 3218 | \\ | 3376 | \\ |
| ... | @@ -3221,41 +3379,46 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -3221,41 +3379,46 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3221 | "tmp.zig:2:14: error: expected type 'f32', found 'f64'", | 3379 | "tmp.zig:2:14: error: expected type 'f32', found 'f64'", |
| 3222 | }); | 3380 | }); |
| 3223 | | 3381 | |
| 3224 | cases.add("exceeded maximum bit width of integer", | 3382 | ctx.objErrStage1("exceeded maximum bit width of integer", |
| 3225 | \\export fn entry1() void { | 3383 | \\export fn entry1() void { |
| 3226 | \\ const T = u65536; | 3384 | \\ const T = u65536; |
| | 3385 | \\ _ = T; |
| 3227 | \\} | 3386 | \\} |
| 3228 | \\export fn entry2() void { | 3387 | \\export fn entry2() void { |
| 3229 | \\ var x: i65536 = 1; | 3388 | \\ var x: i65536 = 1; |
| | 3389 | \\ _ = x; |
| 3230 | \\} | 3390 | \\} |
| 3231 | , &[_][]const u8{ | 3391 | , &[_][]const u8{ |
| 3232 | "tmp.zig:5:12: error: primitive integer type 'i65536' exceeds maximum bit width of 65535", | 3392 | "tmp.zig:2:15: error: primitive integer type 'u65536' exceeds maximum bit width of 65535", |
| | 3393 | "tmp.zig:6:12: error: primitive integer type 'i65536' exceeds maximum bit width of 65535", |
| 3233 | }); | 3394 | }); |
| 3234 | | 3395 | |
| 3235 | cases.add("compile error when evaluating return type of inferred error set", | 3396 | ctx.objErrStage1("compile error when evaluating return type of inferred error set", |
| 3236 | \\const Car = struct { | 3397 | \\const Car = struct { |
| 3237 | \\ foo: *SymbolThatDoesNotExist, | 3398 | \\ foo: *SymbolThatDoesNotExist, |
| 3238 | \\ pub fn init() !Car {} | 3399 | \\ pub fn init() !Car {} |
| 3239 | \\}; | 3400 | \\}; |
| 3240 | \\export fn entry() void { | 3401 | \\export fn entry() void { |
| 3241 | \\ const car = Car.init(); | 3402 | \\ const car = Car.init(); |
| | 3403 | \\ _ = car; |
| 3242 | \\} | 3404 | \\} |
| 3243 | , &[_][]const u8{ | 3405 | , &[_][]const u8{ |
| 3244 | "tmp.zig:2:11: error: use of undeclared identifier 'SymbolThatDoesNotExist'", | 3406 | "tmp.zig:2:11: error: use of undeclared identifier 'SymbolThatDoesNotExist'", |
| 3245 | }); | 3407 | }); |
| 3246 | | 3408 | |
| 3247 | cases.add("don't implicit cast double pointer to *c_void", | 3409 | ctx.objErrStage1("don't implicit cast double pointer to *c_void", |
| 3248 | \\export fn entry() void { | 3410 | \\export fn entry() void { |
| 3249 | \\ var a: u32 = 1; | 3411 | \\ var a: u32 = 1; |
| 3250 | \\ var ptr: *align(@alignOf(u32)) c_void = &a; | 3412 | \\ var ptr: *align(@alignOf(u32)) c_void = &a; |
| 3251 | \\ var b: *u32 = @ptrCast(*u32, ptr); | 3413 | \\ var b: *u32 = @ptrCast(*u32, ptr); |
| 3252 | \\ var ptr2: *c_void = &b; | 3414 | \\ var ptr2: *c_void = &b; |
| | 3415 | \\ _ = ptr2; |
| 3253 | \\} | 3416 | \\} |
| 3254 | , &[_][]const u8{ | 3417 | , &[_][]const u8{ |
| 3255 | "tmp.zig:5:26: error: expected type '*c_void', found '**u32'", | 3418 | "tmp.zig:5:26: error: expected type '*c_void', found '**u32'", |
| 3256 | }); | 3419 | }); |
| 3257 | | 3420 | |
| 3258 | cases.add("runtime index into comptime type slice", | 3421 | ctx.objErrStage1("runtime index into comptime type slice", |
| 3259 | \\const Struct = struct { | 3422 | \\const Struct = struct { |
| 3260 | \\ a: u32, | 3423 | \\ a: u32, |
| 3261 | \\}; | 3424 | \\}; |
| ... | @@ -3265,12 +3428,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -3265,12 +3428,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3265 | \\export fn entry() void { | 3428 | \\export fn entry() void { |
| 3266 | \\ const index = getIndex(); | 3429 | \\ const index = getIndex(); |
| 3267 | \\ const field = @typeInfo(Struct).Struct.fields[index]; | 3430 | \\ const field = @typeInfo(Struct).Struct.fields[index]; |
| | 3431 | \\ _ = field; |
| 3268 | \\} | 3432 | \\} |
| 3269 | , &[_][]const u8{ | 3433 | , &[_][]const u8{ |
| 3270 | "tmp.zig:9:51: error: values of type 'std.builtin.StructField' must be comptime known, but index value is runtime known", | 3434 | "tmp.zig:9:51: error: values of type 'std.builtin.StructField' must be comptime known, but index value is runtime known", |
| 3271 | }); | 3435 | }); |
| 3272 | | 3436 | |
| 3273 | cases.add("compile log statement inside function which must be comptime evaluated", | 3437 | ctx.objErrStage1("compile log statement inside function which must be comptime evaluated", |
| 3274 | \\fn Foo(comptime T: type) type { | 3438 | \\fn Foo(comptime T: type) type { |
| 3275 | \\ @compileLog(@typeName(T)); | 3439 | \\ @compileLog(@typeName(T)); |
| 3276 | \\ return T; | 3440 | \\ return T; |
| ... | @@ -3283,25 +3447,27 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -3283,25 +3447,27 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3283 | "tmp.zig:2:5: error: found compile log statement", | 3447 | "tmp.zig:2:5: error: found compile log statement", |
| 3284 | }); | 3448 | }); |
| 3285 | | 3449 | |
| 3286 | cases.add("comptime slice of an undefined slice", | 3450 | ctx.objErrStage1("comptime slice of an undefined slice", |
| 3287 | \\comptime { | 3451 | \\comptime { |
| 3288 | \\ var a: []u8 = undefined; | 3452 | \\ var a: []u8 = undefined; |
| 3289 | \\ var b = a[0..10]; | 3453 | \\ var b = a[0..10]; |
| | 3454 | \\ _ = b; |
| 3290 | \\} | 3455 | \\} |
| 3291 | , &[_][]const u8{ | 3456 | , &[_][]const u8{ |
| 3292 | "tmp.zig:3:14: error: slice of undefined", | 3457 | "tmp.zig:3:14: error: slice of undefined", |
| 3293 | }); | 3458 | }); |
| 3294 | | 3459 | |
| 3295 | cases.add("implicit cast const array to mutable slice", | 3460 | ctx.objErrStage1("implicit cast const array to mutable slice", |
| 3296 | \\export fn entry() void { | 3461 | \\export fn entry() void { |
| 3297 | \\ const buffer: [1]u8 = [_]u8{8}; | 3462 | \\ const buffer: [1]u8 = [_]u8{8}; |
| 3298 | \\ const sliceA: []u8 = &buffer; | 3463 | \\ const sliceA: []u8 = &buffer; |
| | 3464 | \\ _ = sliceA; |
| 3299 | \\} | 3465 | \\} |
| 3300 | , &[_][]const u8{ | 3466 | , &[_][]const u8{ |
| 3301 | "tmp.zig:3:27: error: expected type '[]u8', found '*const [1]u8'", | 3467 | "tmp.zig:3:27: error: expected type '[]u8', found '*const [1]u8'", |
| 3302 | }); | 3468 | }); |
| 3303 | | 3469 | |
| 3304 | cases.add("deref slice and get len field", | 3470 | ctx.objErrStage1("deref slice and get len field", |
| 3305 | \\export fn entry() void { | 3471 | \\export fn entry() void { |
| 3306 | \\ var a: []u8 = undefined; | 3472 | \\ var a: []u8 = undefined; |
| 3307 | \\ _ = a.*.len; | 3473 | \\ _ = a.*.len; |
| ... | @@ -3310,7 +3476,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -3310,7 +3476,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3310 | "tmp.zig:3:10: error: attempt to dereference non-pointer type '[]u8'", | 3476 | "tmp.zig:3:10: error: attempt to dereference non-pointer type '[]u8'", |
| 3311 | }); | 3477 | }); |
| 3312 | | 3478 | |
| 3313 | cases.add("@ptrCast a 0 bit type to a non- 0 bit type", | 3479 | ctx.objErrStage1("@ptrCast a 0 bit type to a non- 0 bit type", |
| 3314 | \\export fn entry() bool { | 3480 | \\export fn entry() bool { |
| 3315 | \\ var x: u0 = 0; | 3481 | \\ var x: u0 = 0; |
| 3316 | \\ const p = @ptrCast(?*u0, &x); | 3482 | \\ const p = @ptrCast(?*u0, &x); |
| ... | @@ -3322,7 +3488,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -3322,7 +3488,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3322 | "tmp.zig:3:24: note: '?*u0' has in-memory bits", | 3488 | "tmp.zig:3:24: note: '?*u0' has in-memory bits", |
| 3323 | }); | 3489 | }); |
| 3324 | | 3490 | |
| 3325 | cases.add("comparing a non-optional pointer against null", | 3491 | ctx.objErrStage1("comparing a non-optional pointer against null", |
| 3326 | \\export fn entry() void { | 3492 | \\export fn entry() void { |
| 3327 | \\ var x: i32 = 1; | 3493 | \\ var x: i32 = 1; |
| 3328 | \\ _ = &x == null; | 3494 | \\ _ = &x == null; |
| ... | @@ -3331,21 +3497,23 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -3331,21 +3497,23 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3331 | "tmp.zig:3:12: error: comparison of '*i32' with null", | 3497 | "tmp.zig:3:12: error: comparison of '*i32' with null", |
| 3332 | }); | 3498 | }); |
| 3333 | | 3499 | |
| 3334 | cases.add("non error sets used in merge error sets operator", | 3500 | ctx.objErrStage1("non error sets used in merge error sets operator", |
| 3335 | \\export fn foo() void { | 3501 | \\export fn foo() void { |
| 3336 | \\ const Errors = u8 || u16; | 3502 | \\ const Errors = u8 || u16; |
| | 3503 | \\ _ = Errors; |
| 3337 | \\} | 3504 | \\} |
| 3338 | \\export fn bar() void { | 3505 | \\export fn bar() void { |
| 3339 | \\ const Errors = error{} || u16; | 3506 | \\ const Errors = error{} || u16; |
| | 3507 | \\ _ = Errors; |
| 3340 | \\} | 3508 | \\} |
| 3341 | , &[_][]const u8{ | 3509 | , &[_][]const u8{ |
| 3342 | "tmp.zig:2:20: error: expected error set type, found type 'u8'", | 3510 | "tmp.zig:2:20: error: expected error set type, found type 'u8'", |
| 3343 | "tmp.zig:2:23: note: `||` merges error sets; `or` performs boolean OR", | 3511 | "tmp.zig:2:23: note: `||` merges error sets; `or` performs boolean OR", |
| 3344 | "tmp.zig:5:31: error: expected error set type, found type 'u16'", | 3512 | "tmp.zig:6:31: error: expected error set type, found type 'u16'", |
| 3345 | "tmp.zig:5:28: note: `||` merges error sets; `or` performs boolean OR", | 3513 | "tmp.zig:6:28: note: `||` merges error sets; `or` performs boolean OR", |
| 3346 | }); | 3514 | }); |
| 3347 | | 3515 | |
| 3348 | cases.add("variable initialization compile error then referenced", | 3516 | ctx.objErrStage1("variable initialization compile error then referenced", |
| 3349 | \\fn Undeclared() type { | 3517 | \\fn Undeclared() type { |
| 3350 | \\ return T; | 3518 | \\ return T; |
| 3351 | \\} | 3519 | \\} |
| ... | @@ -3357,12 +3525,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -3357,12 +3525,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3357 | \\} | 3525 | \\} |
| 3358 | \\export fn entry() void { | 3526 | \\export fn entry() void { |
| 3359 | \\ const S = Gen(); | 3527 | \\ const S = Gen(); |
| | 3528 | \\ _ = S; |
| 3360 | \\} | 3529 | \\} |
| 3361 | , &[_][]const u8{ | 3530 | , &[_][]const u8{ |
| 3362 | "tmp.zig:2:12: error: use of undeclared identifier 'T'", | 3531 | "tmp.zig:2:12: error: use of undeclared identifier 'T'", |
| 3363 | }); | 3532 | }); |
| 3364 | | 3533 | |
| 3365 | cases.add("refer to the type of a generic function", | 3534 | ctx.objErrStage1("refer to the type of a generic function", |
| 3366 | \\export fn entry() void { | 3535 | \\export fn entry() void { |
| 3367 | \\ const Func = fn (type) void; | 3536 | \\ const Func = fn (type) void; |
| 3368 | \\ const f: Func = undefined; | 3537 | \\ const f: Func = undefined; |
| ... | @@ -3372,7 +3541,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -3372,7 +3541,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3372 | "tmp.zig:4:5: error: use of undefined value here causes undefined behavior", | 3541 | "tmp.zig:4:5: error: use of undefined value here causes undefined behavior", |
| 3373 | }); | 3542 | }); |
| 3374 | | 3543 | |
| 3375 | cases.add("accessing runtime parameter from outer function", | 3544 | ctx.objErrStage1("accessing runtime parameter from outer function", |
| 3376 | \\fn outer(y: u32) fn (u32) u32 { | 3545 | \\fn outer(y: u32) fn (u32) u32 { |
| 3377 | \\ const st = struct { | 3546 | \\ const st = struct { |
| 3378 | \\ fn get(z: u32) u32 { | 3547 | \\ fn get(z: u32) u32 { |
| ... | @@ -3384,6 +3553,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -3384,6 +3553,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3384 | \\export fn entry() void { | 3553 | \\export fn entry() void { |
| 3385 | \\ var func = outer(10); | 3554 | \\ var func = outer(10); |
| 3386 | \\ var x = func(3); | 3555 | \\ var x = func(3); |
| | 3556 | \\ _ = x; |
| 3387 | \\} | 3557 | \\} |
| 3388 | , &[_][]const u8{ | 3558 | , &[_][]const u8{ |
| 3389 | "tmp.zig:4:24: error: 'y' not accessible from inner function", | 3559 | "tmp.zig:4:24: error: 'y' not accessible from inner function", |
| ... | @@ -3391,69 +3561,74 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -3391,69 +3561,74 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3391 | "tmp.zig:1:10: note: declared here", | 3561 | "tmp.zig:1:10: note: declared here", |
| 3392 | }); | 3562 | }); |
| 3393 | | 3563 | |
| 3394 | cases.add("non int passed to @intToFloat", | 3564 | ctx.objErrStage1("non int passed to @intToFloat", |
| 3395 | \\export fn entry() void { | 3565 | \\export fn entry() void { |
| 3396 | \\ const x = @intToFloat(f32, 1.1); | 3566 | \\ const x = @intToFloat(f32, 1.1); |
| | 3567 | \\ _ = x; |
| 3397 | \\} | 3568 | \\} |
| 3398 | , &[_][]const u8{ | 3569 | , &[_][]const u8{ |
| 3399 | "tmp.zig:2:32: error: expected int type, found 'comptime_float'", | 3570 | "tmp.zig:2:32: error: expected int type, found 'comptime_float'", |
| 3400 | }); | 3571 | }); |
| 3401 | | 3572 | |
| 3402 | cases.add("non float passed to @floatToInt", | 3573 | ctx.objErrStage1("non float passed to @floatToInt", |
| 3403 | \\export fn entry() void { | 3574 | \\export fn entry() void { |
| 3404 | \\ const x = @floatToInt(i32, @as(i32, 54)); | 3575 | \\ const x = @floatToInt(i32, @as(i32, 54)); |
| | 3576 | \\ _ = x; |
| 3405 | \\} | 3577 | \\} |
| 3406 | , &[_][]const u8{ | 3578 | , &[_][]const u8{ |
| 3407 | "tmp.zig:2:32: error: expected float type, found 'i32'", | 3579 | "tmp.zig:2:32: error: expected float type, found 'i32'", |
| 3408 | }); | 3580 | }); |
| 3409 | | 3581 | |
| 3410 | cases.add("out of range comptime_int passed to @floatToInt", | 3582 | ctx.objErrStage1("out of range comptime_int passed to @floatToInt", |
| 3411 | \\export fn entry() void { | 3583 | \\export fn entry() void { |
| 3412 | \\ const x = @floatToInt(i8, 200); | 3584 | \\ const x = @floatToInt(i8, 200); |
| | 3585 | \\ _ = x; |
| 3413 | \\} | 3586 | \\} |
| 3414 | , &[_][]const u8{ | 3587 | , &[_][]const u8{ |
| 3415 | "tmp.zig:2:31: error: integer value 200 cannot be coerced to type 'i8'", | 3588 | "tmp.zig:2:31: error: integer value 200 cannot be coerced to type 'i8'", |
| 3416 | }); | 3589 | }); |
| 3417 | | 3590 | |
| 3418 | cases.add("load too many bytes from comptime reinterpreted pointer", | 3591 | ctx.objErrStage1("load too many bytes from comptime reinterpreted pointer", |
| 3419 | \\export fn entry() void { | 3592 | \\export fn entry() void { |
| 3420 | \\ const float: f32 = 5.99999999999994648725e-01; | 3593 | \\ const float: f32 = 5.99999999999994648725e-01; |
| 3421 | \\ const float_ptr = &float; | 3594 | \\ const float_ptr = &float; |
| 3422 | \\ const int_ptr = @ptrCast(*const i64, float_ptr); | 3595 | \\ const int_ptr = @ptrCast(*const i64, float_ptr); |
| 3423 | \\ const int_val = int_ptr.*; | 3596 | \\ const int_val = int_ptr.*; |
| | 3597 | \\ _ = int_val; |
| 3424 | \\} | 3598 | \\} |
| 3425 | , &[_][]const u8{ | 3599 | , &[_][]const u8{ |
| 3426 | "tmp.zig:5:28: error: attempt to read 8 bytes from pointer to f32 which is 4 bytes", | 3600 | "tmp.zig:5:28: error: attempt to read 8 bytes from pointer to f32 which is 4 bytes", |
| 3427 | }); | 3601 | }); |
| 3428 | | 3602 | |
| 3429 | cases.add("invalid type used in array type", | 3603 | ctx.objErrStage1("invalid type used in array type", |
| 3430 | \\const Item = struct { | 3604 | \\const Item = struct { |
| 3431 | \\ field: SomeNonexistentType, | 3605 | \\ field: SomeNonexistentType, |
| 3432 | \\}; | 3606 | \\}; |
| 3433 | \\var items: [100]Item = undefined; | 3607 | \\var items: [100]Item = undefined; |
| 3434 | \\export fn entry() void { | 3608 | \\export fn entry() void { |
| 3435 | \\ const a = items[0]; | 3609 | \\ const a = items[0]; |
| | 3610 | \\ _ = a; |
| 3436 | \\} | 3611 | \\} |
| 3437 | , &[_][]const u8{ | 3612 | , &[_][]const u8{ |
| 3438 | "tmp.zig:2:12: error: use of undeclared identifier 'SomeNonexistentType'", | 3613 | "tmp.zig:2:12: error: use of undeclared identifier 'SomeNonexistentType'", |
| 3439 | }); | 3614 | }); |
| 3440 | | 3615 | |
| 3441 | cases.add("comptime continue inside runtime catch", | 3616 | ctx.objErrStage1("comptime continue inside runtime catch", |
| 3442 | \\export fn entry(c: bool) void { | 3617 | \\export fn entry() void { |
| 3443 | \\ const ints = [_]u8{ 1, 2 }; | 3618 | \\ const ints = [_]u8{ 1, 2 }; |
| 3444 | \\ inline for (ints) |_| { | 3619 | \\ inline for (ints) |_| { |
| 3445 | \\ bad() catch |_| continue; | 3620 | \\ bad() catch continue; |
| 3446 | \\ } | 3621 | \\ } |
| 3447 | \\} | 3622 | \\} |
| 3448 | \\fn bad() !void { | 3623 | \\fn bad() !void { |
| 3449 | \\ return error.Bad; | 3624 | \\ return error.Bad; |
| 3450 | \\} | 3625 | \\} |
| 3451 | , &[_][]const u8{ | 3626 | , &[_][]const u8{ |
| 3452 | "tmp.zig:4:25: error: comptime control flow inside runtime block", | 3627 | "tmp.zig:4:21: error: comptime control flow inside runtime block", |
| 3453 | "tmp.zig:4:15: note: runtime block created here", | 3628 | "tmp.zig:4:15: note: runtime block created here", |
| 3454 | }); | 3629 | }); |
| 3455 | | 3630 | |
| 3456 | cases.add("comptime continue inside runtime switch", | 3631 | ctx.objErrStage1("comptime continue inside runtime switch", |
| 3457 | \\export fn entry() void { | 3632 | \\export fn entry() void { |
| 3458 | \\ var p: i32 = undefined; | 3633 | \\ var p: i32 = undefined; |
| 3459 | \\ comptime var q = true; | 3634 | \\ comptime var q = true; |
| ... | @@ -3470,7 +3645,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -3470,7 +3645,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3470 | "tmp.zig:5:9: note: runtime block created here", | 3645 | "tmp.zig:5:9: note: runtime block created here", |
| 3471 | }); | 3646 | }); |
| 3472 | | 3647 | |
| 3473 | cases.add("comptime continue inside runtime while error", | 3648 | ctx.objErrStage1("comptime continue inside runtime while error", |
| 3474 | \\export fn entry() void { | 3649 | \\export fn entry() void { |
| 3475 | \\ var p: anyerror!usize = undefined; | 3650 | \\ var p: anyerror!usize = undefined; |
| 3476 | \\ comptime var q = true; | 3651 | \\ comptime var q = true; |
| ... | @@ -3486,7 +3661,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -3486,7 +3661,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3486 | "tmp.zig:5:9: note: runtime block created here", | 3661 | "tmp.zig:5:9: note: runtime block created here", |
| 3487 | }); | 3662 | }); |
| 3488 | | 3663 | |
| 3489 | cases.add("comptime continue inside runtime while optional", | 3664 | ctx.objErrStage1("comptime continue inside runtime while optional", |
| 3490 | \\export fn entry() void { | 3665 | \\export fn entry() void { |
| 3491 | \\ var p: ?usize = undefined; | 3666 | \\ var p: ?usize = undefined; |
| 3492 | \\ comptime var q = true; | 3667 | \\ comptime var q = true; |
| ... | @@ -3500,7 +3675,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -3500,7 +3675,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3500 | "tmp.zig:5:9: note: runtime block created here", | 3675 | "tmp.zig:5:9: note: runtime block created here", |
| 3501 | }); | 3676 | }); |
| 3502 | | 3677 | |
| 3503 | cases.add("comptime continue inside runtime while bool", | 3678 | ctx.objErrStage1("comptime continue inside runtime while bool", |
| 3504 | \\export fn entry() void { | 3679 | \\export fn entry() void { |
| 3505 | \\ var p: usize = undefined; | 3680 | \\ var p: usize = undefined; |
| 3506 | \\ comptime var q = true; | 3681 | \\ comptime var q = true; |
| ... | @@ -3514,7 +3689,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -3514,7 +3689,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3514 | "tmp.zig:5:9: note: runtime block created here", | 3689 | "tmp.zig:5:9: note: runtime block created here", |
| 3515 | }); | 3690 | }); |
| 3516 | | 3691 | |
| 3517 | cases.add("comptime continue inside runtime if error", | 3692 | ctx.objErrStage1("comptime continue inside runtime if error", |
| 3518 | \\export fn entry() void { | 3693 | \\export fn entry() void { |
| 3519 | \\ var p: anyerror!i32 = undefined; | 3694 | \\ var p: anyerror!i32 = undefined; |
| 3520 | \\ comptime var q = true; | 3695 | \\ comptime var q = true; |
| ... | @@ -3528,7 +3703,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -3528,7 +3703,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3528 | "tmp.zig:5:9: note: runtime block created here", | 3703 | "tmp.zig:5:9: note: runtime block created here", |
| 3529 | }); | 3704 | }); |
| 3530 | | 3705 | |
| 3531 | cases.add("comptime continue inside runtime if optional", | 3706 | ctx.objErrStage1("comptime continue inside runtime if optional", |
| 3532 | \\export fn entry() void { | 3707 | \\export fn entry() void { |
| 3533 | \\ var p: ?i32 = undefined; | 3708 | \\ var p: ?i32 = undefined; |
| 3534 | \\ comptime var q = true; | 3709 | \\ comptime var q = true; |
| ... | @@ -3542,7 +3717,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -3542,7 +3717,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3542 | "tmp.zig:5:9: note: runtime block created here", | 3717 | "tmp.zig:5:9: note: runtime block created here", |
| 3543 | }); | 3718 | }); |
| 3544 | | 3719 | |
| 3545 | cases.add("comptime continue inside runtime if bool", | 3720 | ctx.objErrStage1("comptime continue inside runtime if bool", |
| 3546 | \\export fn entry() void { | 3721 | \\export fn entry() void { |
| 3547 | \\ var p: usize = undefined; | 3722 | \\ var p: usize = undefined; |
| 3548 | \\ comptime var q = true; | 3723 | \\ comptime var q = true; |
| ... | @@ -3556,22 +3731,23 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -3556,22 +3731,23 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3556 | "tmp.zig:5:9: note: runtime block created here", | 3731 | "tmp.zig:5:9: note: runtime block created here", |
| 3557 | }); | 3732 | }); |
| 3558 | | 3733 | |
| 3559 | cases.add("switch with invalid expression parameter", | 3734 | ctx.objErrStage1("switch with invalid expression parameter", |
| 3560 | \\export fn entry() void { | 3735 | \\export fn entry() void { |
| 3561 | \\ Test(i32); | 3736 | \\ Test(i32); |
| 3562 | \\} | 3737 | \\} |
| 3563 | \\fn Test(comptime T: type) void { | 3738 | \\fn Test(comptime T: type) void { |
| 3564 | \\ const x = switch (T) { | 3739 | \\ const x = switch (T) { |
| 3565 | \\ []u8 => |x| 123, | 3740 | \\ []u8 => |x| x, |
| 3566 | \\ i32 => |x| 456, | 3741 | \\ i32 => |x| x, |
| 3567 | \\ else => unreachable, | 3742 | \\ else => unreachable, |
| 3568 | \\ }; | 3743 | \\ }; |
| | 3744 | \\ _ = x; |
| 3569 | \\} | 3745 | \\} |
| 3570 | , &[_][]const u8{ | 3746 | , &[_][]const u8{ |
| 3571 | "tmp.zig:7:17: error: switch on type 'type' provides no expression parameter", | 3747 | "tmp.zig:7:17: error: switch on type 'type' provides no expression parameter", |
| 3572 | }); | 3748 | }); |
| 3573 | | 3749 | |
| 3574 | cases.add("function prototype with no body", | 3750 | ctx.objErrStage1("function prototype with no body", |
| 3575 | \\fn foo() void; | 3751 | \\fn foo() void; |
| 3576 | \\export fn entry() void { | 3752 | \\export fn entry() void { |
| 3577 | \\ foo(); | 3753 | \\ foo(); |
| ... | @@ -3580,7 +3756,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -3580,7 +3756,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3580 | "tmp.zig:1:1: error: non-extern function has no body", | 3756 | "tmp.zig:1:1: error: non-extern function has no body", |
| 3581 | }); | 3757 | }); |
| 3582 | | 3758 | |
| 3583 | cases.add("@frame() called outside of function definition", | 3759 | ctx.objErrStage1("@frame() called outside of function definition", |
| 3584 | \\var handle_undef: anyframe = undefined; | 3760 | \\var handle_undef: anyframe = undefined; |
| 3585 | \\var handle_dummy: anyframe = @frame(); | 3761 | \\var handle_dummy: anyframe = @frame(); |
| 3586 | \\export fn entry() bool { | 3762 | \\export fn entry() bool { |
| ... | @@ -3590,16 +3766,16 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -3590,16 +3766,16 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3590 | "tmp.zig:2:30: error: @frame() called outside of function definition", | 3766 | "tmp.zig:2:30: error: @frame() called outside of function definition", |
| 3591 | }); | 3767 | }); |
| 3592 | | 3768 | |
| 3593 | cases.add("`_` is not a declarable symbol", | 3769 | ctx.objErrStage1("`_` is not a declarable symbol", |
| 3594 | \\export fn f1() usize { | 3770 | \\export fn f1() usize { |
| 3595 | \\ var _: usize = 2; | 3771 | \\ var _: usize = 2; |
| 3596 | \\ return _; | 3772 | \\ return _; |
| 3597 | \\} | 3773 | \\} |
| 3598 | , &[_][]const u8{ | 3774 | , &[_][]const u8{ |
| 3599 | "tmp.zig:2:5: error: `_` is not a declarable symbol", | 3775 | "tmp.zig:2:9: error: '_' used as an identifier without @\"_\" syntax", |
| 3600 | }); | 3776 | }); |
| 3601 | | 3777 | |
| 3602 | cases.add("`_` should not be usable inside for", | 3778 | ctx.objErrStage1("`_` should not be usable inside for", |
| 3603 | \\export fn returns() void { | 3779 | \\export fn returns() void { |
| 3604 | \\ for ([_]void{}) |_, i| { | 3780 | \\ for ([_]void{}) |_, i| { |
| 3605 | \\ for ([_]void{}) |_, j| { | 3781 | \\ for ([_]void{}) |_, j| { |
| ... | @@ -3608,10 +3784,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -3608,10 +3784,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3608 | \\ } | 3784 | \\ } |
| 3609 | \\} | 3785 | \\} |
| 3610 | , &[_][]const u8{ | 3786 | , &[_][]const u8{ |
| 3611 | "tmp.zig:4:20: error: `_` may only be used to assign things to", | 3787 | "tmp.zig:4:20: error: '_' used as an identifier without @\"_\" syntax", |
| 3612 | }); | 3788 | }); |
| 3613 | | 3789 | |
| 3614 | cases.add("`_` should not be usable inside while", | 3790 | ctx.objErrStage1("`_` should not be usable inside while", |
| 3615 | \\export fn returns() void { | 3791 | \\export fn returns() void { |
| 3616 | \\ while (optionalReturn()) |_| { | 3792 | \\ while (optionalReturn()) |_| { |
| 3617 | \\ while (optionalReturn()) |_| { | 3793 | \\ while (optionalReturn()) |_| { |
| ... | @@ -3623,10 +3799,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -3623,10 +3799,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3623 | \\ return 1; | 3799 | \\ return 1; |
| 3624 | \\} | 3800 | \\} |
| 3625 | , &[_][]const u8{ | 3801 | , &[_][]const u8{ |
| 3626 | "tmp.zig:4:20: error: `_` may only be used to assign things to", | 3802 | "tmp.zig:4:20: error: '_' used as an identifier without @\"_\" syntax", |
| 3627 | }); | 3803 | }); |
| 3628 | | 3804 | |
| 3629 | cases.add("`_` should not be usable inside while else", | 3805 | ctx.objErrStage1("`_` should not be usable inside while else", |
| 3630 | \\export fn returns() void { | 3806 | \\export fn returns() void { |
| 3631 | \\ while (optionalReturnError()) |_| { | 3807 | \\ while (optionalReturnError()) |_| { |
| 3632 | \\ while (optionalReturnError()) |_| { | 3808 | \\ while (optionalReturnError()) |_| { |
| ... | @@ -3640,10 +3816,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -3640,10 +3816,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3640 | \\ return error.optionalReturnError; | 3816 | \\ return error.optionalReturnError; |
| 3641 | \\} | 3817 | \\} |
| 3642 | , &[_][]const u8{ | 3818 | , &[_][]const u8{ |
| 3643 | "tmp.zig:6:17: error: `_` may only be used to assign things to", | 3819 | "tmp.zig:6:17: error: '_' used as an identifier without @\"_\" syntax", |
| 3644 | }); | 3820 | }); |
| 3645 | | 3821 | |
| 3646 | cases.add("while loop body expression ignored", | 3822 | ctx.objErrStage1("while loop body expression ignored", |
| 3647 | \\fn returns() usize { | 3823 | \\fn returns() usize { |
| 3648 | \\ return 2; | 3824 | \\ return 2; |
| 3649 | \\} | 3825 | \\} |
| ... | @@ -3664,7 +3840,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -3664,7 +3840,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3664 | "tmp.zig:13:26: error: expression value is ignored", | 3840 | "tmp.zig:13:26: error: expression value is ignored", |
| 3665 | }); | 3841 | }); |
| 3666 | | 3842 | |
| 3667 | cases.add("missing parameter name of generic function", | 3843 | ctx.objErrStage1("missing parameter name of generic function", |
| 3668 | \\fn dump(anytype) void {} | 3844 | \\fn dump(anytype) void {} |
| 3669 | \\export fn entry() void { | 3845 | \\export fn entry() void { |
| 3670 | \\ var a: u8 = 9; | 3846 | \\ var a: u8 = 9; |
| ... | @@ -3674,20 +3850,20 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -3674,20 +3850,20 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3674 | "tmp.zig:1:9: error: missing parameter name", | 3850 | "tmp.zig:1:9: error: missing parameter name", |
| 3675 | }); | 3851 | }); |
| 3676 | | 3852 | |
| 3677 | cases.add("non-inline for loop on a type that requires comptime", | 3853 | ctx.objErrStage1("non-inline for loop on a type that requires comptime", |
| 3678 | \\const Foo = struct { | 3854 | \\const Foo = struct { |
| 3679 | \\ name: []const u8, | 3855 | \\ name: []const u8, |
| 3680 | \\ T: type, | 3856 | \\ T: type, |
| 3681 | \\}; | 3857 | \\}; |
| 3682 | \\export fn entry() void { | 3858 | \\export fn entry() void { |
| 3683 | \\ const xx: [2]Foo = undefined; | 3859 | \\ const xx: [2]Foo = undefined; |
| 3684 | \\ for (xx) |f| {} | 3860 | \\ for (xx) |f| { _ = f;} |
| 3685 | \\} | 3861 | \\} |
| 3686 | , &[_][]const u8{ | 3862 | , &[_][]const u8{ |
| 3687 | "tmp.zig:7:5: error: values of type 'Foo' must be comptime known, but index value is runtime known", | 3863 | "tmp.zig:7:5: error: values of type 'Foo' must be comptime known, but index value is runtime known", |
| 3688 | }); | 3864 | }); |
| 3689 | | 3865 | |
| 3690 | cases.add("generic fn as parameter without comptime keyword", | 3866 | ctx.objErrStage1("generic fn as parameter without comptime keyword", |
| 3691 | \\fn f(_: fn (anytype) void) void {} | 3867 | \\fn f(_: fn (anytype) void) void {} |
| 3692 | \\fn g(_: anytype) void {} | 3868 | \\fn g(_: anytype) void {} |
| 3693 | \\export fn entry() void { | 3869 | \\export fn entry() void { |
| ... | @@ -3697,7 +3873,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -3697,7 +3873,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3697 | "tmp.zig:1:9: error: parameter of type 'fn(anytype) anytype' must be declared comptime", | 3873 | "tmp.zig:1:9: error: parameter of type 'fn(anytype) anytype' must be declared comptime", |
| 3698 | }); | 3874 | }); |
| 3699 | | 3875 | |
| 3700 | cases.add("optional pointer to void in extern struct", | 3876 | ctx.objErrStage1("optional pointer to void in extern struct", |
| 3701 | \\const Foo = extern struct { | 3877 | \\const Foo = extern struct { |
| 3702 | \\ x: ?*const void, | 3878 | \\ x: ?*const void, |
| 3703 | \\}; | 3879 | \\}; |
| ... | @@ -3705,12 +3881,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -3705,12 +3881,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3705 | \\ foo: Foo, | 3881 | \\ foo: Foo, |
| 3706 | \\ y: i32, | 3882 | \\ y: i32, |
| 3707 | \\}; | 3883 | \\}; |
| 3708 | \\export fn entry(bar: *Bar) void {} | 3884 | \\export fn entry(bar: *Bar) void {_ = bar;} |
| 3709 | , &[_][]const u8{ | 3885 | , &[_][]const u8{ |
| 3710 | "tmp.zig:2:5: error: extern structs cannot contain fields of type '?*const void'", | 3886 | "tmp.zig:2:5: error: extern structs cannot contain fields of type '?*const void'", |
| 3711 | }); | 3887 | }); |
| 3712 | | 3888 | |
| 3713 | cases.add("use of comptime-known undefined function value", | 3889 | ctx.objErrStage1("use of comptime-known undefined function value", |
| 3714 | \\const Cmd = struct { | 3890 | \\const Cmd = struct { |
| 3715 | \\ exec: fn () void, | 3891 | \\ exec: fn () void, |
| 3716 | \\}; | 3892 | \\}; |
| ... | @@ -3722,7 +3898,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -3722,7 +3898,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3722 | "tmp.zig:6:12: error: use of undefined value here causes undefined behavior", | 3898 | "tmp.zig:6:12: error: use of undefined value here causes undefined behavior", |
| 3723 | }); | 3899 | }); |
| 3724 | | 3900 | |
| 3725 | cases.add("use of comptime-known undefined function value", | 3901 | ctx.objErrStage1("use of comptime-known undefined function value", |
| 3726 | \\const Cmd = struct { | 3902 | \\const Cmd = struct { |
| 3727 | \\ exec: fn () void, | 3903 | \\ exec: fn () void, |
| 3728 | \\}; | 3904 | \\}; |
| ... | @@ -3734,16 +3910,17 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -3734,16 +3910,17 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3734 | "tmp.zig:6:12: error: use of undefined value here causes undefined behavior", | 3910 | "tmp.zig:6:12: error: use of undefined value here causes undefined behavior", |
| 3735 | }); | 3911 | }); |
| 3736 | | 3912 | |
| 3737 | cases.add("bad @alignCast at comptime", | 3913 | ctx.objErrStage1("bad @alignCast at comptime", |
| 3738 | \\comptime { | 3914 | \\comptime { |
| 3739 | \\ const ptr = @intToPtr(*align(1) i32, 0x1); | 3915 | \\ const ptr = @intToPtr(*align(1) i32, 0x1); |
| 3740 | \\ const aligned = @alignCast(4, ptr); | 3916 | \\ const aligned = @alignCast(4, ptr); |
| | 3917 | \\ _ = aligned; |
| 3741 | \\} | 3918 | \\} |
| 3742 | , &[_][]const u8{ | 3919 | , &[_][]const u8{ |
| 3743 | "tmp.zig:3:35: error: pointer address 0x1 is not aligned to 4 bytes", | 3920 | "tmp.zig:3:35: error: pointer address 0x1 is not aligned to 4 bytes", |
| 3744 | }); | 3921 | }); |
| 3745 | | 3922 | |
| 3746 | cases.add("@ptrToInt on *void", | 3923 | ctx.objErrStage1("@ptrToInt on *void", |
| 3747 | \\export fn entry() bool { | 3924 | \\export fn entry() bool { |
| 3748 | \\ return @ptrToInt(&{}) == @ptrToInt(&{}); | 3925 | \\ return @ptrToInt(&{}) == @ptrToInt(&{}); |
| 3749 | \\} | 3926 | \\} |
| ... | @@ -3751,7 +3928,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -3751,7 +3928,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3751 | "tmp.zig:2:23: error: pointer to size 0 type has no address", | 3928 | "tmp.zig:2:23: error: pointer to size 0 type has no address", |
| 3752 | }); | 3929 | }); |
| 3753 | | 3930 | |
| 3754 | cases.add("@popCount - non-integer", | 3931 | ctx.objErrStage1("@popCount - non-integer", |
| 3755 | \\export fn entry(x: f32) u32 { | 3932 | \\export fn entry(x: f32) u32 { |
| 3756 | \\ return @popCount(f32, x); | 3933 | \\ return @popCount(f32, x); |
| 3757 | \\} | 3934 | \\} |
| ... | @@ -3759,8 +3936,23 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -3759,8 +3936,23 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3759 | "tmp.zig:2:22: error: expected integer type, found 'f32'", | 3936 | "tmp.zig:2:22: error: expected integer type, found 'f32'", |
| 3760 | }); | 3937 | }); |
| 3761 | | 3938 | |
| 3762 | cases.addCase(x: { | 3939 | { |
| 3763 | const tc = cases.create("wrong same named struct", | 3940 | const case = ctx.obj("wrong same named struct", .{}); |
| | 3941 | case.backend = .stage1; |
| | 3942 | |
| | 3943 | case.addSourceFile("a.zig", |
| | 3944 | \\pub const Foo = struct { |
| | 3945 | \\ x: i32, |
| | 3946 | \\}; |
| | 3947 | ); |
| | 3948 | |
| | 3949 | case.addSourceFile("b.zig", |
| | 3950 | \\pub const Foo = struct { |
| | 3951 | \\ z: f64, |
| | 3952 | \\}; |
| | 3953 | ); |
| | 3954 | |
| | 3955 | case.addError( |
| 3764 | \\const a = @import("a.zig"); | 3956 | \\const a = @import("a.zig"); |
| 3765 | \\const b = @import("b.zig"); | 3957 | \\const b = @import("b.zig"); |
| 3766 | \\ | 3958 | \\ |
| ... | @@ -3769,30 +3961,16 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -3769,30 +3961,16 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3769 | \\ bar(&a1); | 3961 | \\ bar(&a1); |
| 3770 | \\} | 3962 | \\} |
| 3771 | \\ | 3963 | \\ |
| 3772 | \\fn bar(x: *b.Foo) void {} | 3964 | \\fn bar(x: *b.Foo) void {_ = x;} |
| 3773 | , &[_][]const u8{ | 3965 | , &[_][]const u8{ |
| 3774 | "tmp.zig:6:10: error: expected type '*b.Foo', found '*a.Foo'", | 3966 | "tmp.zig:6:10: error: expected type '*b.Foo', found '*a.Foo'", |
| 3775 | "tmp.zig:6:10: note: pointer type child 'a.Foo' cannot cast into pointer type child 'b.Foo'", | 3967 | "tmp.zig:6:10: note: pointer type child 'a.Foo' cannot cast into pointer type child 'b.Foo'", |
| 3776 | "a.zig:1:17: note: a.Foo declared here", | 3968 | "a.zig:1:17: note: a.Foo declared here", |
| 3777 | "b.zig:1:17: note: b.Foo declared here", | 3969 | "b.zig:1:17: note: b.Foo declared here", |
| 3778 | }); | 3970 | }); |
| | 3971 | } |
| 3779 | | 3972 | |
| 3780 | tc.addSourceFile("a.zig", | 3973 | ctx.objErrStage1("@floatToInt comptime safety", |
| 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", | | |
| 3796 | \\comptime { | 3974 | \\comptime { |
| 3797 | \\ _ = @floatToInt(i8, @as(f32, -129.1)); | 3975 | \\ _ = @floatToInt(i8, @as(f32, -129.1)); |
| 3798 | \\} | 3976 | \\} |
| ... | @@ -3808,35 +3986,38 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -3808,35 +3986,38 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3808 | "tmp.zig:8:9: error: integer value '256' cannot be stored in type 'u8'", | 3986 | "tmp.zig:8:9: error: integer value '256' cannot be stored in type 'u8'", |
| 3809 | }); | 3987 | }); |
| 3810 | | 3988 | |
| 3811 | cases.add("use c_void as return type of fn ptr", | 3989 | ctx.objErrStage1("use c_void as return type of fn ptr", |
| 3812 | \\export fn entry() void { | 3990 | \\export fn entry() void { |
| 3813 | \\ const a: fn () c_void = undefined; | 3991 | \\ const a: fn () c_void = undefined; |
| | 3992 | \\ _ = a; |
| 3814 | \\} | 3993 | \\} |
| 3815 | , &[_][]const u8{ | 3994 | , &[_][]const u8{ |
| 3816 | "tmp.zig:2:20: error: return type cannot be opaque", | 3995 | "tmp.zig:2:20: error: return type cannot be opaque", |
| 3817 | }); | 3996 | }); |
| 3818 | | 3997 | |
| 3819 | cases.add("use implicit casts to assign null to non-nullable pointer", | 3998 | ctx.objErrStage1("use implicit casts to assign null to non-nullable pointer", |
| 3820 | \\export fn entry() void { | 3999 | \\export fn entry() void { |
| 3821 | \\ var x: i32 = 1234; | 4000 | \\ var x: i32 = 1234; |
| 3822 | \\ var p: *i32 = &x; | 4001 | \\ var p: *i32 = &x; |
| 3823 | \\ var pp: *?*i32 = &p; | 4002 | \\ var pp: *?*i32 = &p; |
| 3824 | \\ pp.* = null; | 4003 | \\ pp.* = null; |
| 3825 | \\ var y = p.*; | 4004 | \\ var y = p.*; |
| | 4005 | \\ _ = y; |
| 3826 | \\} | 4006 | \\} |
| 3827 | , &[_][]const u8{ | 4007 | , &[_][]const u8{ |
| 3828 | "tmp.zig:4:23: error: expected type '*?*i32', found '**i32'", | 4008 | "tmp.zig:4:23: error: expected type '*?*i32', found '**i32'", |
| 3829 | }); | 4009 | }); |
| 3830 | | 4010 | |
| 3831 | cases.add("attempted implicit cast from T to [*]const T", | 4011 | ctx.objErrStage1("attempted implicit cast from T to [*]const T", |
| 3832 | \\export fn entry() void { | 4012 | \\export fn entry() void { |
| 3833 | \\ const x: [*]const bool = true; | 4013 | \\ const x: [*]const bool = true; |
| | 4014 | \\ _ = x; |
| 3834 | \\} | 4015 | \\} |
| 3835 | , &[_][]const u8{ | 4016 | , &[_][]const u8{ |
| 3836 | "tmp.zig:2:30: error: expected type '[*]const bool', found 'bool'", | 4017 | "tmp.zig:2:30: error: expected type '[*]const bool', found 'bool'", |
| 3837 | }); | 4018 | }); |
| 3838 | | 4019 | |
| 3839 | cases.add("dereference unknown length pointer", | 4020 | ctx.objErrStage1("dereference unknown length pointer", |
| 3840 | \\export fn entry(x: [*]i32) i32 { | 4021 | \\export fn entry(x: [*]i32) i32 { |
| 3841 | \\ return x.*; | 4022 | \\ return x.*; |
| 3842 | \\} | 4023 | \\} |
| ... | @@ -3844,7 +4025,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -3844,7 +4025,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3844 | "tmp.zig:2:13: error: index syntax required for unknown-length pointer type '[*]i32'", | 4025 | "tmp.zig:2:13: error: index syntax required for unknown-length pointer type '[*]i32'", |
| 3845 | }); | 4026 | }); |
| 3846 | | 4027 | |
| 3847 | cases.add("field access of unknown length pointer", | 4028 | ctx.objErrStage1("field access of unknown length pointer", |
| 3848 | \\const Foo = extern struct { | 4029 | \\const Foo = extern struct { |
| 3849 | \\ a: i32, | 4030 | \\ a: i32, |
| 3850 | \\}; | 4031 | \\}; |
| ... | @@ -3856,13 +4037,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -3856,13 +4037,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3856 | "tmp.zig:6:8: error: type '[*]Foo' does not support field access", | 4037 | "tmp.zig:6:8: error: type '[*]Foo' does not support field access", |
| 3857 | }); | 4038 | }); |
| 3858 | | 4039 | |
| 3859 | cases.add("unknown length pointer to opaque", | 4040 | ctx.objErrStage1("unknown length pointer to opaque", |
| 3860 | \\export const T = [*]opaque {}; | 4041 | \\export const T = [*]opaque {}; |
| 3861 | , &[_][]const u8{ | 4042 | , &[_][]const u8{ |
| 3862 | "tmp.zig:1:21: error: unknown-length pointer to opaque", | 4043 | "tmp.zig:1:21: error: unknown-length pointer to opaque", |
| 3863 | }); | 4044 | }); |
| 3864 | | 4045 | |
| 3865 | cases.add("error when evaluating return type", | 4046 | ctx.objErrStage1("error when evaluating return type", |
| 3866 | \\const Foo = struct { | 4047 | \\const Foo = struct { |
| 3867 | \\ map: @as(i32, i32), | 4048 | \\ map: @as(i32, i32), |
| 3868 | \\ | 4049 | \\ |
| ... | @@ -3872,20 +4053,22 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -3872,20 +4053,22 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3872 | \\}; | 4053 | \\}; |
| 3873 | \\export fn entry() void { | 4054 | \\export fn entry() void { |
| 3874 | \\ var rule_set = try Foo.init(); | 4055 | \\ var rule_set = try Foo.init(); |
| | 4056 | \\ _ = rule_set; |
| 3875 | \\} | 4057 | \\} |
| 3876 | , &[_][]const u8{ | 4058 | , &[_][]const u8{ |
| 3877 | "tmp.zig:2:19: error: expected type 'i32', found 'type'", | 4059 | "tmp.zig:2:19: error: expected type 'i32', found 'type'", |
| 3878 | }); | 4060 | }); |
| 3879 | | 4061 | |
| 3880 | cases.add("slicing single-item pointer", | 4062 | ctx.objErrStage1("slicing single-item pointer", |
| 3881 | \\export fn entry(ptr: *i32) void { | 4063 | \\export fn entry(ptr: *i32) void { |
| 3882 | \\ const slice = ptr[0..2]; | 4064 | \\ const slice = ptr[0..2]; |
| | 4065 | \\ _ = slice; |
| 3883 | \\} | 4066 | \\} |
| 3884 | , &[_][]const u8{ | 4067 | , &[_][]const u8{ |
| 3885 | "tmp.zig:2:22: error: slice of single-item pointer", | 4068 | "tmp.zig:2:22: error: slice of single-item pointer", |
| 3886 | }); | 4069 | }); |
| 3887 | | 4070 | |
| 3888 | cases.add("indexing single-item pointer", | 4071 | ctx.objErrStage1("indexing single-item pointer", |
| 3889 | \\export fn entry(ptr: *i32) i32 { | 4072 | \\export fn entry(ptr: *i32) i32 { |
| 3890 | \\ return ptr[1]; | 4073 | \\ return ptr[1]; |
| 3891 | \\} | 4074 | \\} |
| ... | @@ -3893,12 +4076,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -3893,12 +4076,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3893 | "tmp.zig:2:15: error: index of single-item pointer", | 4076 | "tmp.zig:2:15: error: index of single-item pointer", |
| 3894 | }); | 4077 | }); |
| 3895 | | 4078 | |
| 3896 | cases.add("nested error set mismatch", | 4079 | ctx.objErrStage1("nested error set mismatch", |
| 3897 | \\const NextError = error{NextError}; | 4080 | \\const NextError = error{NextError}; |
| 3898 | \\const OtherError = error{OutOfMemory}; | 4081 | \\const OtherError = error{OutOfMemory}; |
| 3899 | \\ | 4082 | \\ |
| 3900 | \\export fn entry() void { | 4083 | \\export fn entry() void { |
| 3901 | \\ const a: ?NextError!i32 = foo(); | 4084 | \\ const a: ?NextError!i32 = foo(); |
| | 4085 | \\ _ = a; |
| 3902 | \\} | 4086 | \\} |
| 3903 | \\ | 4087 | \\ |
| 3904 | \\fn foo() ?OtherError!i32 { | 4088 | \\fn foo() ?OtherError!i32 { |
| ... | @@ -3911,7 +4095,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -3911,7 +4095,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3911 | "tmp.zig:2:26: note: 'error.OutOfMemory' not a member of destination error set", | 4095 | "tmp.zig:2:26: note: 'error.OutOfMemory' not a member of destination error set", |
| 3912 | }); | 4096 | }); |
| 3913 | | 4097 | |
| 3914 | cases.add("invalid deref on switch target", | 4098 | ctx.objErrStage1("invalid deref on switch target", |
| 3915 | \\comptime { | 4099 | \\comptime { |
| 3916 | \\ var tile = Tile.Empty; | 4100 | \\ var tile = Tile.Empty; |
| 3917 | \\ switch (tile.*) { | 4101 | \\ switch (tile.*) { |
| ... | @@ -3927,13 +4111,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -3927,13 +4111,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3927 | "tmp.zig:3:17: error: attempt to dereference non-pointer type 'Tile'", | 4111 | "tmp.zig:3:17: error: attempt to dereference non-pointer type 'Tile'", |
| 3928 | }); | 4112 | }); |
| 3929 | | 4113 | |
| 3930 | cases.add("invalid field access in comptime", | 4114 | ctx.objErrStage1("invalid field access in comptime", |
| 3931 | \\comptime { var x = doesnt_exist.whatever; } | 4115 | \\comptime { var x = doesnt_exist.whatever; _ = x; } |
| 3932 | , &[_][]const u8{ | 4116 | , &[_][]const u8{ |
| 3933 | "tmp.zig:1:20: error: use of undeclared identifier 'doesnt_exist'", | 4117 | "tmp.zig:1:20: error: use of undeclared identifier 'doesnt_exist'", |
| 3934 | }); | 4118 | }); |
| 3935 | | 4119 | |
| 3936 | cases.add("suspend inside suspend block", | 4120 | ctx.objErrStage1("suspend inside suspend block", |
| 3937 | \\export fn entry() void { | 4121 | \\export fn entry() void { |
| 3938 | \\ _ = async foo(); | 4122 | \\ _ = async foo(); |
| 3939 | \\} | 4123 | \\} |
| ... | @@ -3948,17 +4132,18 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -3948,17 +4132,18 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3948 | "tmp.zig:5:5: note: other suspend block here", | 4132 | "tmp.zig:5:5: note: other suspend block here", |
| 3949 | }); | 4133 | }); |
| 3950 | | 4134 | |
| 3951 | cases.add("assign inline fn to non-comptime var", | 4135 | ctx.objErrStage1("assign inline fn to non-comptime var", |
| 3952 | \\export fn entry() void { | 4136 | \\export fn entry() void { |
| 3953 | \\ var a = b; | 4137 | \\ var a = b; |
| | 4138 | \\ _ = a; |
| 3954 | \\} | 4139 | \\} |
| 3955 | \\fn b() callconv(.Inline) void { } | 4140 | \\fn b() callconv(.Inline) void { } |
| 3956 | , &[_][]const u8{ | 4141 | , &[_][]const u8{ |
| 3957 | "tmp.zig:2:5: error: functions marked inline must be stored in const or comptime var", | 4142 | "tmp.zig:2:5: error: functions marked inline must be stored in const or comptime var", |
| 3958 | "tmp.zig:4:1: note: declared here", | 4143 | "tmp.zig:5:1: note: declared here", |
| 3959 | }); | 4144 | }); |
| 3960 | | 4145 | |
| 3961 | cases.add("wrong type passed to @panic", | 4146 | ctx.objErrStage1("wrong type passed to @panic", |
| 3962 | \\export fn entry() void { | 4147 | \\export fn entry() void { |
| 3963 | \\ var e = error.Foo; | 4148 | \\ var e = error.Foo; |
| 3964 | \\ @panic(e); | 4149 | \\ @panic(e); |
| ... | @@ -3967,7 +4152,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -3967,7 +4152,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3967 | "tmp.zig:3:12: error: expected type '[]const u8', found 'error{Foo}'", | 4152 | "tmp.zig:3:12: error: expected type '[]const u8', found 'error{Foo}'", |
| 3968 | }); | 4153 | }); |
| 3969 | | 4154 | |
| 3970 | cases.add("@tagName used on union with no associated enum tag", | 4155 | ctx.objErrStage1("@tagName used on union with no associated enum tag", |
| 3971 | \\const FloatInt = extern union { | 4156 | \\const FloatInt = extern union { |
| 3972 | \\ Float: f32, | 4157 | \\ Float: f32, |
| 3973 | \\ Int: i32, | 4158 | \\ Int: i32, |
| ... | @@ -3975,13 +4160,14 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -3975,13 +4160,14 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3975 | \\export fn entry() void { | 4160 | \\export fn entry() void { |
| 3976 | \\ var fi = FloatInt{.Float = 123.45}; | 4161 | \\ var fi = FloatInt{.Float = 123.45}; |
| 3977 | \\ var tagName = @tagName(fi); | 4162 | \\ var tagName = @tagName(fi); |
| | 4163 | \\ _ = tagName; |
| 3978 | \\} | 4164 | \\} |
| 3979 | , &[_][]const u8{ | 4165 | , &[_][]const u8{ |
| 3980 | "tmp.zig:7:19: error: union has no associated enum", | 4166 | "tmp.zig:7:19: error: union has no associated enum", |
| 3981 | "tmp.zig:1:18: note: declared here", | 4167 | "tmp.zig:1:18: note: declared here", |
| 3982 | }); | 4168 | }); |
| 3983 | | 4169 | |
| 3984 | cases.add("returning error from void async function", | 4170 | ctx.objErrStage1("returning error from void async function", |
| 3985 | \\export fn entry() void { | 4171 | \\export fn entry() void { |
| 3986 | \\ _ = async amain(); | 4172 | \\ _ = async amain(); |
| 3987 | \\} | 4173 | \\} |
| ... | @@ -3992,37 +4178,40 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -3992,37 +4178,40 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3992 | "tmp.zig:5:17: error: expected type 'void', found 'error{ShouldBeCompileError}'", | 4178 | "tmp.zig:5:17: error: expected type 'void', found 'error{ShouldBeCompileError}'", |
| 3993 | }); | 4179 | }); |
| 3994 | | 4180 | |
| 3995 | cases.add("var makes structs required to be comptime known", | 4181 | ctx.objErrStage1("var makes structs required to be comptime known", |
| 3996 | \\export fn entry() void { | 4182 | \\export fn entry() void { |
| 3997 | \\ const S = struct{v: anytype}; | 4183 | \\ const S = struct{v: anytype}; |
| 3998 | \\ var s = S{.v=@as(i32, 10)}; | 4184 | \\ var s = S{.v=@as(i32, 10)}; |
| | 4185 | \\ _ = s; |
| 3999 | \\} | 4186 | \\} |
| 4000 | , &[_][]const u8{ | 4187 | , &[_][]const u8{ |
| 4001 | "tmp.zig:3:4: error: variable of type 'S' must be const or comptime", | 4188 | "tmp.zig:3:4: error: variable of type 'S' must be const or comptime", |
| 4002 | }); | 4189 | }); |
| 4003 | | 4190 | |
| 4004 | cases.add("@ptrCast discards const qualifier", | 4191 | ctx.objErrStage1("@ptrCast discards const qualifier", |
| 4005 | \\export fn entry() void { | 4192 | \\export fn entry() void { |
| 4006 | \\ const x: i32 = 1234; | 4193 | \\ const x: i32 = 1234; |
| 4007 | \\ const y = @ptrCast(*i32, &x); | 4194 | \\ const y = @ptrCast(*i32, &x); |
| | 4195 | \\ _ = y; |
| 4008 | \\} | 4196 | \\} |
| 4009 | , &[_][]const u8{ | 4197 | , &[_][]const u8{ |
| 4010 | "tmp.zig:3:15: error: cast discards const qualifier", | 4198 | "tmp.zig:3:15: error: cast discards const qualifier", |
| 4011 | }); | 4199 | }); |
| 4012 | | 4200 | |
| 4013 | cases.add("comptime slice of undefined pointer non-zero len", | 4201 | ctx.objErrStage1("comptime slice of undefined pointer non-zero len", |
| 4014 | \\export fn entry() void { | 4202 | \\export fn entry() void { |
| 4015 | \\ const slice = @as([*]i32, undefined)[0..1]; | 4203 | \\ const slice = @as([*]i32, undefined)[0..1]; |
| | 4204 | \\ _ = slice; |
| 4016 | \\} | 4205 | \\} |
| 4017 | , &[_][]const u8{ | 4206 | , &[_][]const u8{ |
| 4018 | "tmp.zig:2:41: error: non-zero length slice of undefined pointer", | 4207 | "tmp.zig:2:41: error: non-zero length slice of undefined pointer", |
| 4019 | }); | 4208 | }); |
| 4020 | | 4209 | |
| 4021 | cases.add("type checking function pointers", | 4210 | ctx.objErrStage1("type checking function pointers", |
| 4022 | \\fn a(b: fn (*const u8) void) void { | 4211 | \\fn a(b: fn (*const u8) void) void { |
| 4023 | \\ b('a'); | 4212 | \\ b('a'); |
| 4024 | \\} | 4213 | \\} |
| 4025 | \\fn c(d: u8) void {} | 4214 | \\fn c(d: u8) void {_ = d;} |
| 4026 | \\export fn entry() void { | 4215 | \\export fn entry() void { |
| 4027 | \\ a(c); | 4216 | \\ a(c); |
| 4028 | \\} | 4217 | \\} |
| ... | @@ -4030,7 +4219,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -4030,7 +4219,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4030 | "tmp.zig:6:7: error: expected type 'fn(*const u8) void', found 'fn(u8) void'", | 4219 | "tmp.zig:6:7: error: expected type 'fn(*const u8) void', found 'fn(u8) void'", |
| 4031 | }); | 4220 | }); |
| 4032 | | 4221 | |
| 4033 | cases.add("no else prong on switch on global error set", | 4222 | ctx.objErrStage1("no else prong on switch on global error set", |
| 4034 | \\export fn entry() void { | 4223 | \\export fn entry() void { |
| 4035 | \\ foo(error.A); | 4224 | \\ foo(error.A); |
| 4036 | \\} | 4225 | \\} |
| ... | @@ -4043,7 +4232,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -4043,7 +4232,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4043 | "tmp.zig:5:5: error: else prong required when switching on type 'anyerror'", | 4232 | "tmp.zig:5:5: error: else prong required when switching on type 'anyerror'", |
| 4044 | }); | 4233 | }); |
| 4045 | | 4234 | |
| 4046 | cases.add("error not handled in switch", | 4235 | ctx.objErrStage1("error not handled in switch", |
| 4047 | \\export fn entry() void { | 4236 | \\export fn entry() void { |
| 4048 | \\ foo(452) catch |err| switch (err) { | 4237 | \\ foo(452) catch |err| switch (err) { |
| 4049 | \\ error.Foo => {}, | 4238 | \\ error.Foo => {}, |
| ... | @@ -4062,7 +4251,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -4062,7 +4251,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4062 | "tmp.zig:2:26: error: error.Bar not handled in switch", | 4251 | "tmp.zig:2:26: error: error.Bar not handled in switch", |
| 4063 | }); | 4252 | }); |
| 4064 | | 4253 | |
| 4065 | cases.add("duplicate error in switch", | 4254 | ctx.objErrStage1("duplicate error in switch", |
| 4066 | \\export fn entry() void { | 4255 | \\export fn entry() void { |
| 4067 | \\ foo(452) catch |err| switch (err) { | 4256 | \\ foo(452) catch |err| switch (err) { |
| 4068 | \\ error.Foo => {}, | 4257 | \\ error.Foo => {}, |
| ... | @@ -4080,10 +4269,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -4080,10 +4269,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4080 | \\} | 4269 | \\} |
| 4081 | , &[_][]const u8{ | 4270 | , &[_][]const u8{ |
| 4082 | "tmp.zig:5:14: error: duplicate switch value: '@typeInfo(@typeInfo(@TypeOf(foo)).Fn.return_type.?).ErrorUnion.error_set.Foo'", | 4271 | "tmp.zig:5:14: error: duplicate switch value: '@typeInfo(@typeInfo(@TypeOf(foo)).Fn.return_type.?).ErrorUnion.error_set.Foo'", |
| 4083 | "tmp.zig:3:14: note: other value is here", | 4272 | "tmp.zig:3:14: note: other value here", |
| 4084 | }); | 4273 | }); |
| 4085 | | 4274 | |
| 4086 | cases.add("invalid cast from integral type to enum", | 4275 | ctx.objErrStage1("invalid cast from integral type to enum", |
| 4087 | \\const E = enum(usize) { One, Two }; | 4276 | \\const E = enum(usize) { One, Two }; |
| 4088 | \\ | 4277 | \\ |
| 4089 | \\export fn entry() void { | 4278 | \\export fn entry() void { |
| ... | @@ -4099,7 +4288,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -4099,7 +4288,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4099 | "tmp.zig:9:10: error: expected type 'usize', found 'E'", | 4288 | "tmp.zig:9:10: error: expected type 'usize', found 'E'", |
| 4100 | }); | 4289 | }); |
| 4101 | | 4290 | |
| 4102 | cases.add("range operator in switch used on error set", | 4291 | ctx.objErrStage1("range operator in switch used on error set", |
| 4103 | \\export fn entry() void { | 4292 | \\export fn entry() void { |
| 4104 | \\ try foo(452) catch |err| switch (err) { | 4293 | \\ try foo(452) catch |err| switch (err) { |
| 4105 | \\ error.A ... error.B => {}, | 4294 | \\ error.A ... error.B => {}, |
| ... | @@ -4117,33 +4306,35 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -4117,33 +4306,35 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4117 | "tmp.zig:3:17: error: operator not allowed for errors", | 4306 | "tmp.zig:3:17: error: operator not allowed for errors", |
| 4118 | }); | 4307 | }); |
| 4119 | | 4308 | |
| 4120 | cases.add("inferring error set of function pointer", | 4309 | ctx.objErrStage1("inferring error set of function pointer", |
| 4121 | \\comptime { | 4310 | \\comptime { |
| 4122 | \\ const z: ?fn()!void = null; | 4311 | \\ const z: ?fn()!void = null; |
| 4123 | \\} | 4312 | \\} |
| 4124 | , &[_][]const u8{ | 4313 | , &[_][]const u8{ |
| 4125 | "tmp.zig:2:15: error: inferring error set of return type valid only for function definitions", | 4314 | "tmp.zig:2:19: error: function prototype may not have inferred error set", |
| 4126 | }); | 4315 | }); |
| 4127 | | 4316 | |
| 4128 | cases.add("access non-existent member of error set", | 4317 | ctx.objErrStage1("access non-existent member of error set", |
| 4129 | \\const Foo = error{A}; | 4318 | \\const Foo = error{A}; |
| 4130 | \\comptime { | 4319 | \\comptime { |
| 4131 | \\ const z = Foo.Bar; | 4320 | \\ const z = Foo.Bar; |
| | 4321 | \\ _ = z; |
| 4132 | \\} | 4322 | \\} |
| 4133 | , &[_][]const u8{ | 4323 | , &[_][]const u8{ |
| 4134 | "tmp.zig:3:18: error: no error named 'Bar' in 'Foo'", | 4324 | "tmp.zig:3:18: error: no error named 'Bar' in 'Foo'", |
| 4135 | }); | 4325 | }); |
| 4136 | | 4326 | |
| 4137 | cases.add("error union operator with non error set LHS", | 4327 | ctx.objErrStage1("error union operator with non error set LHS", |
| 4138 | \\comptime { | 4328 | \\comptime { |
| 4139 | \\ const z = i32!i32; | 4329 | \\ const z = i32!i32; |
| 4140 | \\ var x: z = undefined; | 4330 | \\ var x: z = undefined; |
| | 4331 | \\ _ = x; |
| 4141 | \\} | 4332 | \\} |
| 4142 | , &[_][]const u8{ | 4333 | , &[_][]const u8{ |
| 4143 | "tmp.zig:2:15: error: expected error set type, found type 'i32'", | 4334 | "tmp.zig:2:15: error: expected error set type, found type 'i32'", |
| 4144 | }); | 4335 | }); |
| 4145 | | 4336 | |
| 4146 | cases.add("error equality but sets have no common members", | 4337 | ctx.objErrStage1("error equality but sets have no common members", |
| 4147 | \\const Set1 = error{A, C}; | 4338 | \\const Set1 = error{A, C}; |
| 4148 | \\const Set2 = error{B, D}; | 4339 | \\const Set2 = error{B, D}; |
| 4149 | \\export fn entry() void { | 4340 | \\export fn entry() void { |
| ... | @@ -4158,29 +4349,32 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -4158,29 +4349,32 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4158 | "tmp.zig:7:11: error: error sets 'Set1' and 'Set2' have no common errors", | 4349 | "tmp.zig:7:11: error: error sets 'Set1' and 'Set2' have no common errors", |
| 4159 | }); | 4350 | }); |
| 4160 | | 4351 | |
| 4161 | cases.add("only equality binary operator allowed for error sets", | 4352 | ctx.objErrStage1("only equality binary operator allowed for error sets", |
| 4162 | \\comptime { | 4353 | \\comptime { |
| 4163 | \\ const z = error.A > error.B; | 4354 | \\ const z = error.A > error.B; |
| | 4355 | \\ _ = z; |
| 4164 | \\} | 4356 | \\} |
| 4165 | , &[_][]const u8{ | 4357 | , &[_][]const u8{ |
| 4166 | "tmp.zig:2:23: error: operator not allowed for errors", | 4358 | "tmp.zig:2:23: error: operator not allowed for errors", |
| 4167 | }); | 4359 | }); |
| 4168 | | 4360 | |
| 4169 | cases.add("explicit error set cast known at comptime violates error sets", | 4361 | ctx.objErrStage1("explicit error set cast known at comptime violates error sets", |
| 4170 | \\const Set1 = error {A, B}; | 4362 | \\const Set1 = error {A, B}; |
| 4171 | \\const Set2 = error {A, C}; | 4363 | \\const Set2 = error {A, C}; |
| 4172 | \\comptime { | 4364 | \\comptime { |
| 4173 | \\ var x = Set1.B; | 4365 | \\ var x = Set1.B; |
| 4174 | \\ var y = @errSetCast(Set2, x); | 4366 | \\ var y = @errSetCast(Set2, x); |
| | 4367 | \\ _ = y; |
| 4175 | \\} | 4368 | \\} |
| 4176 | , &[_][]const u8{ | 4369 | , &[_][]const u8{ |
| 4177 | "tmp.zig:5:13: error: error.B not a member of error set 'Set2'", | 4370 | "tmp.zig:5:13: error: error.B not a member of error set 'Set2'", |
| 4178 | }); | 4371 | }); |
| 4179 | | 4372 | |
| 4180 | cases.add("cast error union of global error set to error union of smaller error set", | 4373 | ctx.objErrStage1("cast error union of global error set to error union of smaller error set", |
| 4181 | \\const SmallErrorSet = error{A}; | 4374 | \\const SmallErrorSet = error{A}; |
| 4182 | \\export fn entry() void { | 4375 | \\export fn entry() void { |
| 4183 | \\ var x: SmallErrorSet!i32 = foo(); | 4376 | \\ var x: SmallErrorSet!i32 = foo(); |
| | 4377 | \\ _ = x; |
| 4184 | \\} | 4378 | \\} |
| 4185 | \\fn foo() anyerror!i32 { | 4379 | \\fn foo() anyerror!i32 { |
| 4186 | \\ return error.B; | 4380 | \\ return error.B; |
| ... | @@ -4191,10 +4385,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -4191,10 +4385,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4191 | "tmp.zig:3:35: note: cannot cast global error set into smaller set", | 4385 | "tmp.zig:3:35: note: cannot cast global error set into smaller set", |
| 4192 | }); | 4386 | }); |
| 4193 | | 4387 | |
| 4194 | cases.add("cast global error set to error set", | 4388 | ctx.objErrStage1("cast global error set to error set", |
| 4195 | \\const SmallErrorSet = error{A}; | 4389 | \\const SmallErrorSet = error{A}; |
| 4196 | \\export fn entry() void { | 4390 | \\export fn entry() void { |
| 4197 | \\ var x: SmallErrorSet = foo(); | 4391 | \\ var x: SmallErrorSet = foo(); |
| | 4392 | \\ _ = x; |
| 4198 | \\} | 4393 | \\} |
| 4199 | \\fn foo() anyerror { | 4394 | \\fn foo() anyerror { |
| 4200 | \\ return error.B; | 4395 | \\ return error.B; |
| ... | @@ -4203,7 +4398,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -4203,7 +4398,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4203 | "tmp.zig:3:31: error: expected type 'SmallErrorSet', found 'anyerror'", | 4398 | "tmp.zig:3:31: error: expected type 'SmallErrorSet', found 'anyerror'", |
| 4204 | "tmp.zig:3:31: note: cannot cast global error set into smaller set", | 4399 | "tmp.zig:3:31: note: cannot cast global error set into smaller set", |
| 4205 | }); | 4400 | }); |
| 4206 | cases.add("recursive inferred error set", | 4401 | ctx.objErrStage1("recursive inferred error set", |
| 4207 | \\export fn entry() void { | 4402 | \\export fn entry() void { |
| 4208 | \\ foo() catch unreachable; | 4403 | \\ foo() catch unreachable; |
| 4209 | \\} | 4404 | \\} |
| ... | @@ -4214,7 +4409,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -4214,7 +4409,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4214 | "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", | 4409 | "tmp.zig:5:5: error: cannot resolve inferred error set '@typeInfo(@typeInfo(@TypeOf(foo)).Fn.return_type.?).ErrorUnion.error_set': function 'foo' not fully analyzed yet", |
| 4215 | }); | 4410 | }); |
| 4216 | | 4411 | |
| 4217 | cases.add("implicit cast of error set not a subset", | 4412 | ctx.objErrStage1("implicit cast of error set not a subset", |
| 4218 | \\const Set1 = error{A, B}; | 4413 | \\const Set1 = error{A, B}; |
| 4219 | \\const Set2 = error{A, C}; | 4414 | \\const Set2 = error{A, C}; |
| 4220 | \\export fn entry() void { | 4415 | \\export fn entry() void { |
| ... | @@ -4222,13 +4417,14 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -4222,13 +4417,14 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4222 | \\} | 4417 | \\} |
| 4223 | \\fn foo(set1: Set1) void { | 4418 | \\fn foo(set1: Set1) void { |
| 4224 | \\ var x: Set2 = set1; | 4419 | \\ var x: Set2 = set1; |
| | 4420 | \\ _ = x; |
| 4225 | \\} | 4421 | \\} |
| 4226 | , &[_][]const u8{ | 4422 | , &[_][]const u8{ |
| 4227 | "tmp.zig:7:19: error: expected type 'Set2', found 'Set1'", | 4423 | "tmp.zig:7:19: error: expected type 'Set2', found 'Set1'", |
| 4228 | "tmp.zig:1:23: note: 'error.B' not a member of destination error set", | 4424 | "tmp.zig:1:23: note: 'error.B' not a member of destination error set", |
| 4229 | }); | 4425 | }); |
| 4230 | | 4426 | |
| 4231 | cases.add("int to err global invalid number", | 4427 | ctx.objErrStage1("int to err global invalid number", |
| 4232 | \\const Set1 = error{ | 4428 | \\const Set1 = error{ |
| 4233 | \\ A, | 4429 | \\ A, |
| 4234 | \\ B, | 4430 | \\ B, |
| ... | @@ -4236,12 +4432,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -4236,12 +4432,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4236 | \\comptime { | 4432 | \\comptime { |
| 4237 | \\ var x: u16 = 3; | 4433 | \\ var x: u16 = 3; |
| 4238 | \\ var y = @intToError(x); | 4434 | \\ var y = @intToError(x); |
| | 4435 | \\ _ = y; |
| 4239 | \\} | 4436 | \\} |
| 4240 | , &[_][]const u8{ | 4437 | , &[_][]const u8{ |
| 4241 | "tmp.zig:7:13: error: integer value 3 represents no error", | 4438 | "tmp.zig:7:13: error: integer value 3 represents no error", |
| 4242 | }); | 4439 | }); |
| 4243 | | 4440 | |
| 4244 | cases.add("int to err non global invalid number", | 4441 | ctx.objErrStage1("int to err non global invalid number", |
| 4245 | \\const Set1 = error{ | 4442 | \\const Set1 = error{ |
| 4246 | \\ A, | 4443 | \\ A, |
| 4247 | \\ B, | 4444 | \\ B, |
| ... | @@ -4253,68 +4450,74 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -4253,68 +4450,74 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4253 | \\comptime { | 4450 | \\comptime { |
| 4254 | \\ var x = @errorToInt(Set1.B); | 4451 | \\ var x = @errorToInt(Set1.B); |
| 4255 | \\ var y = @errSetCast(Set2, @intToError(x)); | 4452 | \\ var y = @errSetCast(Set2, @intToError(x)); |
| | 4453 | \\ _ = y; |
| 4256 | \\} | 4454 | \\} |
| 4257 | , &[_][]const u8{ | 4455 | , &[_][]const u8{ |
| 4258 | "tmp.zig:11:13: error: error.B not a member of error set 'Set2'", | 4456 | "tmp.zig:11:13: error: error.B not a member of error set 'Set2'", |
| 4259 | }); | 4457 | }); |
| 4260 | | 4458 | |
| 4261 | cases.add("duplicate error value in error set", | 4459 | ctx.objErrStage1("duplicate error value in error set", |
| 4262 | \\const Foo = error { | 4460 | \\const Foo = error { |
| 4263 | \\ Bar, | 4461 | \\ Bar, |
| 4264 | \\ Bar, | 4462 | \\ Bar, |
| 4265 | \\}; | 4463 | \\}; |
| 4266 | \\export fn entry() void { | 4464 | \\export fn entry() void { |
| 4267 | \\ const a: Foo = undefined; | 4465 | \\ const a: Foo = undefined; |
| | 4466 | \\ _ = a; |
| 4268 | \\} | 4467 | \\} |
| 4269 | , &[_][]const u8{ | 4468 | , &[_][]const u8{ |
| 4270 | "tmp.zig:3:5: error: duplicate error: 'Bar'", | 4469 | "tmp.zig:3:5: error: duplicate error: 'Bar'", |
| 4271 | "tmp.zig:2:5: note: other error here", | 4470 | "tmp.zig:2:5: note: other error here", |
| 4272 | }); | 4471 | }); |
| 4273 | | 4472 | |
| 4274 | cases.add("cast negative integer literal to usize", | 4473 | ctx.objErrStage1("cast negative integer literal to usize", |
| 4275 | \\export fn entry() void { | 4474 | \\export fn entry() void { |
| 4276 | \\ const x = @as(usize, -10); | 4475 | \\ const x = @as(usize, -10); |
| | 4476 | \\ _ = x; |
| 4277 | \\} | 4477 | \\} |
| 4278 | , &[_][]const u8{ | 4478 | , &[_][]const u8{ |
| 4279 | "tmp.zig:2:26: error: cannot cast negative value -10 to unsigned integer type 'usize'", | 4479 | "tmp.zig:2:26: error: cannot cast negative value -10 to unsigned integer type 'usize'", |
| 4280 | }); | 4480 | }); |
| 4281 | | 4481 | |
| 4282 | cases.add("use invalid number literal as array index", | 4482 | ctx.objErrStage1("use invalid number literal as array index", |
| 4283 | \\var v = 25; | 4483 | \\var v = 25; |
| 4284 | \\export fn entry() void { | 4484 | \\export fn entry() void { |
| 4285 | \\ var arr: [v]u8 = undefined; | 4485 | \\ var arr: [v]u8 = undefined; |
| | 4486 | \\ _ = arr; |
| 4286 | \\} | 4487 | \\} |
| 4287 | , &[_][]const u8{ | 4488 | , &[_][]const u8{ |
| 4288 | "tmp.zig:1:1: error: unable to infer variable type", | 4489 | "tmp.zig:1:1: error: unable to infer variable type", |
| 4289 | }); | 4490 | }); |
| 4290 | | 4491 | |
| 4291 | cases.add("duplicate struct field", | 4492 | ctx.objErrStage1("duplicate struct field", |
| 4292 | \\const Foo = struct { | 4493 | \\const Foo = struct { |
| 4293 | \\ Bar: i32, | 4494 | \\ Bar: i32, |
| 4294 | \\ Bar: usize, | 4495 | \\ Bar: usize, |
| 4295 | \\}; | 4496 | \\}; |
| 4296 | \\export fn entry() void { | 4497 | \\export fn entry() void { |
| 4297 | \\ const a: Foo = undefined; | 4498 | \\ const a: Foo = undefined; |
| | 4499 | \\ _ = a; |
| 4298 | \\} | 4500 | \\} |
| 4299 | , &[_][]const u8{ | 4501 | , &[_][]const u8{ |
| 4300 | "tmp.zig:3:5: error: duplicate struct field: 'Bar'", | 4502 | "tmp.zig:3:5: error: duplicate struct field: 'Bar'", |
| 4301 | "tmp.zig:2:5: note: other field here", | 4503 | "tmp.zig:2:5: note: other field here", |
| 4302 | }); | 4504 | }); |
| 4303 | | 4505 | |
| 4304 | cases.add("duplicate union field", | 4506 | ctx.objErrStage1("duplicate union field", |
| 4305 | \\const Foo = union { | 4507 | \\const Foo = union { |
| 4306 | \\ Bar: i32, | 4508 | \\ Bar: i32, |
| 4307 | \\ Bar: usize, | 4509 | \\ Bar: usize, |
| 4308 | \\}; | 4510 | \\}; |
| 4309 | \\export fn entry() void { | 4511 | \\export fn entry() void { |
| 4310 | \\ const a: Foo = undefined; | 4512 | \\ const a: Foo = undefined; |
| | 4513 | \\ _ = a; |
| 4311 | \\} | 4514 | \\} |
| 4312 | , &[_][]const u8{ | 4515 | , &[_][]const u8{ |
| 4313 | "tmp.zig:3:5: error: duplicate union field: 'Bar'", | 4516 | "tmp.zig:3:5: error: duplicate union field: 'Bar'", |
| 4314 | "tmp.zig:2:5: note: other field here", | 4517 | "tmp.zig:2:5: note: other field here", |
| 4315 | }); | 4518 | }); |
| 4316 | | 4519 | |
| 4317 | cases.add("duplicate enum field", | 4520 | ctx.objErrStage1("duplicate enum field", |
| 4318 | \\const Foo = enum { | 4521 | \\const Foo = enum { |
| 4319 | \\ Bar, | 4522 | \\ Bar, |
| 4320 | \\ Bar, | 4523 | \\ Bar, |
| ... | @@ -4322,13 +4525,14 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -4322,13 +4525,14 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4322 | \\ | 4525 | \\ |
| 4323 | \\export fn entry() void { | 4526 | \\export fn entry() void { |
| 4324 | \\ const a: Foo = undefined; | 4527 | \\ const a: Foo = undefined; |
| | 4528 | \\ _ = a; |
| 4325 | \\} | 4529 | \\} |
| 4326 | , &[_][]const u8{ | 4530 | , &[_][]const u8{ |
| 4327 | "tmp.zig:3:5: error: duplicate enum field: 'Bar'", | 4531 | "tmp.zig:3:5: error: duplicate enum field: 'Bar'", |
| 4328 | "tmp.zig:2:5: note: other field here", | 4532 | "tmp.zig:2:5: note: other field here", |
| 4329 | }); | 4533 | }); |
| 4330 | | 4534 | |
| 4331 | cases.add("calling function with naked calling convention", | 4535 | ctx.objErrStage1("calling function with naked calling convention", |
| 4332 | \\export fn entry() void { | 4536 | \\export fn entry() void { |
| 4333 | \\ foo(); | 4537 | \\ foo(); |
| 4334 | \\} | 4538 | \\} |
| ... | @@ -4338,42 +4542,42 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -4338,42 +4542,42 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4338 | "tmp.zig:4:1: note: declared here", | 4542 | "tmp.zig:4:1: note: declared here", |
| 4339 | }); | 4543 | }); |
| 4340 | | 4544 | |
| 4341 | cases.add("function with invalid return type", | 4545 | ctx.objErrStage1("function with invalid return type", |
| 4342 | \\export fn foo() boid {} | 4546 | \\export fn foo() boid {} |
| 4343 | , &[_][]const u8{ | 4547 | , &[_][]const u8{ |
| 4344 | "tmp.zig:1:17: error: use of undeclared identifier 'boid'", | 4548 | "tmp.zig:1:17: error: use of undeclared identifier 'boid'", |
| 4345 | }); | 4549 | }); |
| 4346 | | 4550 | |
| 4347 | cases.add("function with non-extern non-packed enum parameter", | 4551 | ctx.objErrStage1("function with non-extern non-packed enum parameter", |
| 4348 | \\const Foo = enum { A, B, C }; | 4552 | \\const Foo = enum { A, B, C }; |
| 4349 | \\export fn entry(foo: Foo) void { } | 4553 | \\export fn entry(foo: Foo) void { _ = foo; } |
| 4350 | , &[_][]const u8{ | 4554 | , &[_][]const u8{ |
| 4351 | "tmp.zig:2:22: error: parameter of type 'Foo' not allowed in function with calling convention 'C'", | 4555 | "tmp.zig:2:22: error: parameter of type 'Foo' not allowed in function with calling convention 'C'", |
| 4352 | }); | 4556 | }); |
| 4353 | | 4557 | |
| 4354 | cases.add("function with non-extern non-packed struct parameter", | 4558 | ctx.objErrStage1("function with non-extern non-packed struct parameter", |
| 4355 | \\const Foo = struct { | 4559 | \\const Foo = struct { |
| 4356 | \\ A: i32, | 4560 | \\ A: i32, |
| 4357 | \\ B: f32, | 4561 | \\ B: f32, |
| 4358 | \\ C: bool, | 4562 | \\ C: bool, |
| 4359 | \\}; | 4563 | \\}; |
| 4360 | \\export fn entry(foo: Foo) void { } | 4564 | \\export fn entry(foo: Foo) void { _ = foo; } |
| 4361 | , &[_][]const u8{ | 4565 | , &[_][]const u8{ |
| 4362 | "tmp.zig:6:22: error: parameter of type 'Foo' not allowed in function with calling convention 'C'", | 4566 | "tmp.zig:6:22: error: parameter of type 'Foo' not allowed in function with calling convention 'C'", |
| 4363 | }); | 4567 | }); |
| 4364 | | 4568 | |
| 4365 | cases.add("function with non-extern non-packed union parameter", | 4569 | ctx.objErrStage1("function with non-extern non-packed union parameter", |
| 4366 | \\const Foo = union { | 4570 | \\const Foo = union { |
| 4367 | \\ A: i32, | 4571 | \\ A: i32, |
| 4368 | \\ B: f32, | 4572 | \\ B: f32, |
| 4369 | \\ C: bool, | 4573 | \\ C: bool, |
| 4370 | \\}; | 4574 | \\}; |
| 4371 | \\export fn entry(foo: Foo) void { } | 4575 | \\export fn entry(foo: Foo) void { _ = foo; } |
| 4372 | , &[_][]const u8{ | 4576 | , &[_][]const u8{ |
| 4373 | "tmp.zig:6:22: error: parameter of type 'Foo' not allowed in function with calling convention 'C'", | 4577 | "tmp.zig:6:22: error: parameter of type 'Foo' not allowed in function with calling convention 'C'", |
| 4374 | }); | 4578 | }); |
| 4375 | | 4579 | |
| 4376 | cases.add("switch on enum with 1 field with no prongs", | 4580 | ctx.objErrStage1("switch on enum with 1 field with no prongs", |
| 4377 | \\const Foo = enum { M }; | 4581 | \\const Foo = enum { M }; |
| 4378 | \\ | 4582 | \\ |
| 4379 | \\export fn entry() void { | 4583 | \\export fn entry() void { |
| ... | @@ -4384,15 +4588,16 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -4384,15 +4588,16 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4384 | "tmp.zig:5:5: error: enumeration value 'Foo.M' not handled in switch", | 4588 | "tmp.zig:5:5: error: enumeration value 'Foo.M' not handled in switch", |
| 4385 | }); | 4589 | }); |
| 4386 | | 4590 | |
| 4387 | cases.add("shift by negative comptime integer", | 4591 | ctx.objErrStage1("shift by negative comptime integer", |
| 4388 | \\comptime { | 4592 | \\comptime { |
| 4389 | \\ var a = 1 >> -1; | 4593 | \\ var a = 1 >> -1; |
| | 4594 | \\ _ = a; |
| 4390 | \\} | 4595 | \\} |
| 4391 | , &[_][]const u8{ | 4596 | , &[_][]const u8{ |
| 4392 | "tmp.zig:2:18: error: shift by negative value -1", | 4597 | "tmp.zig:2:18: error: shift by negative value -1", |
| 4393 | }); | 4598 | }); |
| 4394 | | 4599 | |
| 4395 | cases.add("@panic called at compile time", | 4600 | ctx.objErrStage1("@panic called at compile time", |
| 4396 | \\export fn entry() void { | 4601 | \\export fn entry() void { |
| 4397 | \\ comptime { | 4602 | \\ comptime { |
| 4398 | \\ @panic("aoeu",); | 4603 | \\ @panic("aoeu",); |
| ... | @@ -4402,20 +4607,20 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -4402,20 +4607,20 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4402 | "tmp.zig:3:9: error: encountered @panic at compile-time", | 4607 | "tmp.zig:3:9: error: encountered @panic at compile-time", |
| 4403 | }); | 4608 | }); |
| 4404 | | 4609 | |
| 4405 | cases.add("wrong return type for main", | 4610 | ctx.objErrStage1("wrong return type for main", |
| 4406 | \\pub fn main() f32 { } | 4611 | \\pub fn main() f32 { } |
| 4407 | , &[_][]const u8{ | 4612 | , &[_][]const u8{ |
| 4408 | "error: expected return type of main to be 'void', '!void', 'noreturn', 'u8', or '!u8'", | 4613 | "error: expected return type of main to be 'void', '!void', 'noreturn', 'u8', or '!u8'", |
| 4409 | }); | 4614 | }); |
| 4410 | | 4615 | |
| 4411 | cases.add("double ?? on main return value", | 4616 | ctx.objErrStage1("double ?? on main return value", |
| 4412 | \\pub fn main() ??void { | 4617 | \\pub fn main() ??void { |
| 4413 | \\} | 4618 | \\} |
| 4414 | , &[_][]const u8{ | 4619 | , &[_][]const u8{ |
| 4415 | "error: expected return type of main to be 'void', '!void', 'noreturn', 'u8', or '!u8'", | 4620 | "error: expected return type of main to be 'void', '!void', 'noreturn', 'u8', or '!u8'", |
| 4416 | }); | 4621 | }); |
| 4417 | | 4622 | |
| 4418 | cases.add("bad identifier in function with struct defined inside function which references local const", | 4623 | ctx.objErrStage1("bad identifier in function with struct defined inside function which references local const", |
| 4419 | \\export fn entry() void { | 4624 | \\export fn entry() void { |
| 4420 | \\ const BlockKind = u32; | 4625 | \\ const BlockKind = u32; |
| 4421 | \\ | 4626 | \\ |
| ... | @@ -4424,12 +4629,14 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -4424,12 +4629,14 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4424 | \\ }; | 4629 | \\ }; |
| 4425 | \\ | 4630 | \\ |
| 4426 | \\ bogus; | 4631 | \\ bogus; |
| | 4632 | \\ |
| | 4633 | \\ _ = Block; |
| 4427 | \\} | 4634 | \\} |
| 4428 | , &[_][]const u8{ | 4635 | , &[_][]const u8{ |
| 4429 | "tmp.zig:8:5: error: use of undeclared identifier 'bogus'", | 4636 | "tmp.zig:8:5: error: use of undeclared identifier 'bogus'", |
| 4430 | }); | 4637 | }); |
| 4431 | | 4638 | |
| 4432 | cases.add("labeled break not found", | 4639 | ctx.objErrStage1("labeled break not found", |
| 4433 | \\export fn entry() void { | 4640 | \\export fn entry() void { |
| 4434 | \\ blah: while (true) { | 4641 | \\ blah: while (true) { |
| 4435 | \\ while (true) { | 4642 | \\ while (true) { |
| ... | @@ -4438,10 +4645,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -4438,10 +4645,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4438 | \\ } | 4645 | \\ } |
| 4439 | \\} | 4646 | \\} |
| 4440 | , &[_][]const u8{ | 4647 | , &[_][]const u8{ |
| 4441 | "tmp.zig:4:13: error: label not found: 'outer'", | 4648 | "tmp.zig:4:20: error: label not found: 'outer'", |
| 4442 | }); | 4649 | }); |
| 4443 | | 4650 | |
| 4444 | cases.add("labeled continue not found", | 4651 | ctx.objErrStage1("labeled continue not found", |
| 4445 | \\export fn entry() void { | 4652 | \\export fn entry() void { |
| 4446 | \\ var i: usize = 0; | 4653 | \\ var i: usize = 0; |
| 4447 | \\ blah: while (i < 10) : (i += 1) { | 4654 | \\ blah: while (i < 10) : (i += 1) { |
| ... | @@ -4451,17 +4658,17 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -4451,17 +4658,17 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4451 | \\ } | 4658 | \\ } |
| 4452 | \\} | 4659 | \\} |
| 4453 | , &[_][]const u8{ | 4660 | , &[_][]const u8{ |
| 4454 | "tmp.zig:5:13: error: labeled loop not found: 'outer'", | 4661 | "tmp.zig:5:23: error: label not found: 'outer'", |
| 4455 | }); | 4662 | }); |
| 4456 | | 4663 | |
| 4457 | cases.add("attempt to use 0 bit type in extern fn", | 4664 | ctx.objErrStage1("attempt to use 0 bit type in extern fn", |
| 4458 | \\extern fn foo(ptr: fn(*void) callconv(.C) void) void; | 4665 | \\extern fn foo(ptr: fn(*void) callconv(.C) void) void; |
| 4459 | \\ | 4666 | \\ |
| 4460 | \\export fn entry() void { | 4667 | \\export fn entry() void { |
| 4461 | \\ foo(bar); | 4668 | \\ foo(bar); |
| 4462 | \\} | 4669 | \\} |
| 4463 | \\ | 4670 | \\ |
| 4464 | \\fn bar(x: *void) callconv(.C) void { } | 4671 | \\fn bar(x: *void) callconv(.C) void { _ = x; } |
| 4465 | \\export fn entry2() void { | 4672 | \\export fn entry2() void { |
| 4466 | \\ bar(&{}); | 4673 | \\ bar(&{}); |
| 4467 | \\} | 4674 | \\} |
| ... | @@ -4470,7 +4677,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -4470,7 +4677,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4470 | "tmp.zig:7:11: error: parameter of type '*void' has 0 bits; not allowed in function with calling convention 'C'", | 4677 | "tmp.zig:7:11: error: parameter of type '*void' has 0 bits; not allowed in function with calling convention 'C'", |
| 4471 | }); | 4678 | }); |
| 4472 | | 4679 | |
| 4473 | cases.add("implicit semicolon - block statement", | 4680 | ctx.objErrStage1("implicit semicolon - block statement", |
| 4474 | \\export fn entry() void { | 4681 | \\export fn entry() void { |
| 4475 | \\ {} | 4682 | \\ {} |
| 4476 | \\ var good = {}; | 4683 | \\ var good = {}; |
| ... | @@ -4478,10 +4685,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -4478,10 +4685,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4478 | \\ var bad = {}; | 4685 | \\ var bad = {}; |
| 4479 | \\} | 4686 | \\} |
| 4480 | , &[_][]const u8{ | 4687 | , &[_][]const u8{ |
| 4481 | "tmp.zig:5:5: error: expected token ';', found 'var'", | 4688 | "tmp.zig:5:5: error: expected ';', found 'var'", |
| 4482 | }); | 4689 | }); |
| 4483 | | 4690 | |
| 4484 | cases.add("implicit semicolon - block expr", | 4691 | ctx.objErrStage1("implicit semicolon - block expr", |
| 4485 | \\export fn entry() void { | 4692 | \\export fn entry() void { |
| 4486 | \\ _ = {}; | 4693 | \\ _ = {}; |
| 4487 | \\ var good = {}; | 4694 | \\ var good = {}; |
| ... | @@ -4489,10 +4696,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -4489,10 +4696,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4489 | \\ var bad = {}; | 4696 | \\ var bad = {}; |
| 4490 | \\} | 4697 | \\} |
| 4491 | , &[_][]const u8{ | 4698 | , &[_][]const u8{ |
| 4492 | "tmp.zig:5:5: error: expected token ';', found 'var'", | 4699 | "tmp.zig:5:5: error: expected ';', found 'var'", |
| 4493 | }); | 4700 | }); |
| 4494 | | 4701 | |
| 4495 | cases.add("implicit semicolon - comptime statement", | 4702 | ctx.objErrStage1("implicit semicolon - comptime statement", |
| 4496 | \\export fn entry() void { | 4703 | \\export fn entry() void { |
| 4497 | \\ comptime {} | 4704 | \\ comptime {} |
| 4498 | \\ var good = {}; | 4705 | \\ var good = {}; |
| ... | @@ -4500,10 +4707,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -4500,10 +4707,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4500 | \\ var bad = {}; | 4707 | \\ var bad = {}; |
| 4501 | \\} | 4708 | \\} |
| 4502 | , &[_][]const u8{ | 4709 | , &[_][]const u8{ |
| 4503 | "tmp.zig:5:5: error: expected token ';', found 'var'", | 4710 | "tmp.zig:5:5: error: expected ';', found 'var'", |
| 4504 | }); | 4711 | }); |
| 4505 | | 4712 | |
| 4506 | cases.add("implicit semicolon - comptime expression", | 4713 | ctx.objErrStage1("implicit semicolon - comptime expression", |
| 4507 | \\export fn entry() void { | 4714 | \\export fn entry() void { |
| 4508 | \\ _ = comptime {}; | 4715 | \\ _ = comptime {}; |
| 4509 | \\ var good = {}; | 4716 | \\ var good = {}; |
| ... | @@ -4511,10 +4718,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -4511,10 +4718,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4511 | \\ var bad = {}; | 4718 | \\ var bad = {}; |
| 4512 | \\} | 4719 | \\} |
| 4513 | , &[_][]const u8{ | 4720 | , &[_][]const u8{ |
| 4514 | "tmp.zig:5:5: error: expected token ';', found 'var'", | 4721 | "tmp.zig:5:5: error: expected ';', found 'var'", |
| 4515 | }); | 4722 | }); |
| 4516 | | 4723 | |
| 4517 | cases.add("implicit semicolon - defer", | 4724 | ctx.objErrStage1("implicit semicolon - defer", |
| 4518 | \\export fn entry() void { | 4725 | \\export fn entry() void { |
| 4519 | \\ defer {} | 4726 | \\ defer {} |
| 4520 | \\ var good = {}; | 4727 | \\ var good = {}; |
| ... | @@ -4522,10 +4729,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -4522,10 +4729,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4522 | \\ var bad = {}; | 4729 | \\ var bad = {}; |
| 4523 | \\} | 4730 | \\} |
| 4524 | , &[_][]const u8{ | 4731 | , &[_][]const u8{ |
| 4525 | "tmp.zig:5:5: error: expected token ';', found 'var'", | 4732 | "tmp.zig:5:5: error: expected ';', found 'var'", |
| 4526 | }); | 4733 | }); |
| 4527 | | 4734 | |
| 4528 | cases.add("implicit semicolon - if statement", | 4735 | ctx.objErrStage1("implicit semicolon - if statement", |
| 4529 | \\export fn entry() void { | 4736 | \\export fn entry() void { |
| 4530 | \\ if(true) {} | 4737 | \\ if(true) {} |
| 4531 | \\ var good = {}; | 4738 | \\ var good = {}; |
| ... | @@ -4533,10 +4740,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -4533,10 +4740,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4533 | \\ var bad = {}; | 4740 | \\ var bad = {}; |
| 4534 | \\} | 4741 | \\} |
| 4535 | , &[_][]const u8{ | 4742 | , &[_][]const u8{ |
| 4536 | "tmp.zig:5:5: error: expected token ';', found 'var'", | 4743 | "tmp.zig:5:5: error: expected ';' or 'else', found 'var'", |
| 4537 | }); | 4744 | }); |
| 4538 | | 4745 | |
| 4539 | cases.add("implicit semicolon - if expression", | 4746 | ctx.objErrStage1("implicit semicolon - if expression", |
| 4540 | \\export fn entry() void { | 4747 | \\export fn entry() void { |
| 4541 | \\ _ = if(true) {}; | 4748 | \\ _ = if(true) {}; |
| 4542 | \\ var good = {}; | 4749 | \\ var good = {}; |
| ... | @@ -4544,10 +4751,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -4544,10 +4751,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4544 | \\ var bad = {}; | 4751 | \\ var bad = {}; |
| 4545 | \\} | 4752 | \\} |
| 4546 | , &[_][]const u8{ | 4753 | , &[_][]const u8{ |
| 4547 | "tmp.zig:5:5: error: expected token ';', found 'var'", | 4754 | "tmp.zig:5:5: error: expected ';', found 'var'", |
| 4548 | }); | 4755 | }); |
| 4549 | | 4756 | |
| 4550 | cases.add("implicit semicolon - if-else statement", | 4757 | ctx.objErrStage1("implicit semicolon - if-else statement", |
| 4551 | \\export fn entry() void { | 4758 | \\export fn entry() void { |
| 4552 | \\ if(true) {} else {} | 4759 | \\ if(true) {} else {} |
| 4553 | \\ var good = {}; | 4760 | \\ var good = {}; |
| ... | @@ -4555,10 +4762,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -4555,10 +4762,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4555 | \\ var bad = {}; | 4762 | \\ var bad = {}; |
| 4556 | \\} | 4763 | \\} |
| 4557 | , &[_][]const u8{ | 4764 | , &[_][]const u8{ |
| 4558 | "tmp.zig:5:5: error: expected token ';', found 'var'", | 4765 | "tmp.zig:5:5: error: expected ';', found 'var'", |
| 4559 | }); | 4766 | }); |
| 4560 | | 4767 | |
| 4561 | cases.add("implicit semicolon - if-else expression", | 4768 | ctx.objErrStage1("implicit semicolon - if-else expression", |
| 4562 | \\export fn entry() void { | 4769 | \\export fn entry() void { |
| 4563 | \\ _ = if(true) {} else {}; | 4770 | \\ _ = if(true) {} else {}; |
| 4564 | \\ var good = {}; | 4771 | \\ var good = {}; |
| ... | @@ -4566,10 +4773,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -4566,10 +4773,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4566 | \\ var bad = {}; | 4773 | \\ var bad = {}; |
| 4567 | \\} | 4774 | \\} |
| 4568 | , &[_][]const u8{ | 4775 | , &[_][]const u8{ |
| 4569 | "tmp.zig:5:5: error: expected token ';', found 'var'", | 4776 | "tmp.zig:5:5: error: expected ';', found 'var'", |
| 4570 | }); | 4777 | }); |
| 4571 | | 4778 | |
| 4572 | cases.add("implicit semicolon - if-else-if statement", | 4779 | ctx.objErrStage1("implicit semicolon - if-else-if statement", |
| 4573 | \\export fn entry() void { | 4780 | \\export fn entry() void { |
| 4574 | \\ if(true) {} else if(true) {} | 4781 | \\ if(true) {} else if(true) {} |
| 4575 | \\ var good = {}; | 4782 | \\ var good = {}; |
| ... | @@ -4577,10 +4784,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -4577,10 +4784,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4577 | \\ var bad = {}; | 4784 | \\ var bad = {}; |
| 4578 | \\} | 4785 | \\} |
| 4579 | , &[_][]const u8{ | 4786 | , &[_][]const u8{ |
| 4580 | "tmp.zig:5:5: error: expected token ';', found 'var'", | 4787 | "tmp.zig:5:5: error: expected ';' or 'else', found 'var'", |
| 4581 | }); | 4788 | }); |
| 4582 | | 4789 | |
| 4583 | cases.add("implicit semicolon - if-else-if expression", | 4790 | ctx.objErrStage1("implicit semicolon - if-else-if expression", |
| 4584 | \\export fn entry() void { | 4791 | \\export fn entry() void { |
| 4585 | \\ _ = if(true) {} else if(true) {}; | 4792 | \\ _ = if(true) {} else if(true) {}; |
| 4586 | \\ var good = {}; | 4793 | \\ var good = {}; |
| ... | @@ -4588,10 +4795,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -4588,10 +4795,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4588 | \\ var bad = {}; | 4795 | \\ var bad = {}; |
| 4589 | \\} | 4796 | \\} |
| 4590 | , &[_][]const u8{ | 4797 | , &[_][]const u8{ |
| 4591 | "tmp.zig:5:5: error: expected token ';', found 'var'", | 4798 | "tmp.zig:5:5: error: expected ';', found 'var'", |
| 4592 | }); | 4799 | }); |
| 4593 | | 4800 | |
| 4594 | cases.add("implicit semicolon - if-else-if-else statement", | 4801 | ctx.objErrStage1("implicit semicolon - if-else-if-else statement", |
| 4595 | \\export fn entry() void { | 4802 | \\export fn entry() void { |
| 4596 | \\ if(true) {} else if(true) {} else {} | 4803 | \\ if(true) {} else if(true) {} else {} |
| 4597 | \\ var good = {}; | 4804 | \\ var good = {}; |
| ... | @@ -4599,10 +4806,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -4599,10 +4806,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4599 | \\ var bad = {}; | 4806 | \\ var bad = {}; |
| 4600 | \\} | 4807 | \\} |
| 4601 | , &[_][]const u8{ | 4808 | , &[_][]const u8{ |
| 4602 | "tmp.zig:5:5: error: expected token ';', found 'var'", | 4809 | "tmp.zig:5:5: error: expected ';', found 'var'", |
| 4603 | }); | 4810 | }); |
| 4604 | | 4811 | |
| 4605 | cases.add("implicit semicolon - if-else-if-else expression", | 4812 | ctx.objErrStage1("implicit semicolon - if-else-if-else expression", |
| 4606 | \\export fn entry() void { | 4813 | \\export fn entry() void { |
| 4607 | \\ _ = if(true) {} else if(true) {} else {}; | 4814 | \\ _ = if(true) {} else if(true) {} else {}; |
| 4608 | \\ var good = {}; | 4815 | \\ var good = {}; |
| ... | @@ -4610,10 +4817,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -4610,10 +4817,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4610 | \\ var bad = {}; | 4817 | \\ var bad = {}; |
| 4611 | \\} | 4818 | \\} |
| 4612 | , &[_][]const u8{ | 4819 | , &[_][]const u8{ |
| 4613 | "tmp.zig:5:5: error: expected token ';', found 'var'", | 4820 | "tmp.zig:5:5: error: expected ';', found 'var'", |
| 4614 | }); | 4821 | }); |
| 4615 | | 4822 | |
| 4616 | cases.add("implicit semicolon - test statement", | 4823 | ctx.objErrStage1("implicit semicolon - test statement", |
| 4617 | \\export fn entry() void { | 4824 | \\export fn entry() void { |
| 4618 | \\ if (foo()) |_| {} | 4825 | \\ if (foo()) |_| {} |
| 4619 | \\ var good = {}; | 4826 | \\ var good = {}; |
| ... | @@ -4621,10 +4828,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -4621,10 +4828,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4621 | \\ var bad = {}; | 4828 | \\ var bad = {}; |
| 4622 | \\} | 4829 | \\} |
| 4623 | , &[_][]const u8{ | 4830 | , &[_][]const u8{ |
| 4624 | "tmp.zig:5:5: error: expected token ';', found 'var'", | 4831 | "tmp.zig:5:5: error: expected ';' or 'else', found 'var'", |
| 4625 | }); | 4832 | }); |
| 4626 | | 4833 | |
| 4627 | cases.add("implicit semicolon - test expression", | 4834 | ctx.objErrStage1("implicit semicolon - test expression", |
| 4628 | \\export fn entry() void { | 4835 | \\export fn entry() void { |
| 4629 | \\ _ = if (foo()) |_| {}; | 4836 | \\ _ = if (foo()) |_| {}; |
| 4630 | \\ var good = {}; | 4837 | \\ var good = {}; |
| ... | @@ -4632,10 +4839,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -4632,10 +4839,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4632 | \\ var bad = {}; | 4839 | \\ var bad = {}; |
| 4633 | \\} | 4840 | \\} |
| 4634 | , &[_][]const u8{ | 4841 | , &[_][]const u8{ |
| 4635 | "tmp.zig:5:5: error: expected token ';', found 'var'", | 4842 | "tmp.zig:5:5: error: expected ';', found 'var'", |
| 4636 | }); | 4843 | }); |
| 4637 | | 4844 | |
| 4638 | cases.add("implicit semicolon - while statement", | 4845 | ctx.objErrStage1("implicit semicolon - while statement", |
| 4639 | \\export fn entry() void { | 4846 | \\export fn entry() void { |
| 4640 | \\ while(true) {} | 4847 | \\ while(true) {} |
| 4641 | \\ var good = {}; | 4848 | \\ var good = {}; |
| ... | @@ -4643,10 +4850,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -4643,10 +4850,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4643 | \\ var bad = {}; | 4850 | \\ var bad = {}; |
| 4644 | \\} | 4851 | \\} |
| 4645 | , &[_][]const u8{ | 4852 | , &[_][]const u8{ |
| 4646 | "tmp.zig:5:5: error: expected token ';', found 'var'", | 4853 | "tmp.zig:5:5: error: expected ';' or 'else', found 'var'", |
| 4647 | }); | 4854 | }); |
| 4648 | | 4855 | |
| 4649 | cases.add("implicit semicolon - while expression", | 4856 | ctx.objErrStage1("implicit semicolon - while expression", |
| 4650 | \\export fn entry() void { | 4857 | \\export fn entry() void { |
| 4651 | \\ _ = while(true) {}; | 4858 | \\ _ = while(true) {}; |
| 4652 | \\ var good = {}; | 4859 | \\ var good = {}; |
| ... | @@ -4654,10 +4861,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -4654,10 +4861,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4654 | \\ var bad = {}; | 4861 | \\ var bad = {}; |
| 4655 | \\} | 4862 | \\} |
| 4656 | , &[_][]const u8{ | 4863 | , &[_][]const u8{ |
| 4657 | "tmp.zig:5:5: error: expected token ';', found 'var'", | 4864 | "tmp.zig:5:5: error: expected ';', found 'var'", |
| 4658 | }); | 4865 | }); |
| 4659 | | 4866 | |
| 4660 | cases.add("implicit semicolon - while-continue statement", | 4867 | ctx.objErrStage1("implicit semicolon - while-continue statement", |
| 4661 | \\export fn entry() void { | 4868 | \\export fn entry() void { |
| 4662 | \\ while(true):({}) {} | 4869 | \\ while(true):({}) {} |
| 4663 | \\ var good = {}; | 4870 | \\ var good = {}; |
| ... | @@ -4665,10 +4872,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -4665,10 +4872,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4665 | \\ var bad = {}; | 4872 | \\ var bad = {}; |
| 4666 | \\} | 4873 | \\} |
| 4667 | , &[_][]const u8{ | 4874 | , &[_][]const u8{ |
| 4668 | "tmp.zig:5:5: error: expected token ';', found 'var'", | 4875 | "tmp.zig:5:5: error: expected ';' or 'else', found 'var'", |
| 4669 | }); | 4876 | }); |
| 4670 | | 4877 | |
| 4671 | cases.add("implicit semicolon - while-continue expression", | 4878 | ctx.objErrStage1("implicit semicolon - while-continue expression", |
| 4672 | \\export fn entry() void { | 4879 | \\export fn entry() void { |
| 4673 | \\ _ = while(true):({}) {}; | 4880 | \\ _ = while(true):({}) {}; |
| 4674 | \\ var good = {}; | 4881 | \\ var good = {}; |
| ... | @@ -4676,10 +4883,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -4676,10 +4883,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4676 | \\ var bad = {}; | 4883 | \\ var bad = {}; |
| 4677 | \\} | 4884 | \\} |
| 4678 | , &[_][]const u8{ | 4885 | , &[_][]const u8{ |
| 4679 | "tmp.zig:5:5: error: expected token ';', found 'var'", | 4886 | "tmp.zig:5:5: error: expected ';', found 'var'", |
| 4680 | }); | 4887 | }); |
| 4681 | | 4888 | |
| 4682 | cases.add("implicit semicolon - for statement", | 4889 | ctx.objErrStage1("implicit semicolon - for statement", |
| 4683 | \\export fn entry() void { | 4890 | \\export fn entry() void { |
| 4684 | \\ for(foo()) |_| {} | 4891 | \\ for(foo()) |_| {} |
| 4685 | \\ var good = {}; | 4892 | \\ var good = {}; |
| ... | @@ -4687,10 +4894,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -4687,10 +4894,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4687 | \\ var bad = {}; | 4894 | \\ var bad = {}; |
| 4688 | \\} | 4895 | \\} |
| 4689 | , &[_][]const u8{ | 4896 | , &[_][]const u8{ |
| 4690 | "tmp.zig:5:5: error: expected token ';', found 'var'", | 4897 | "tmp.zig:5:5: error: expected ';' or 'else', found 'var'", |
| 4691 | }); | 4898 | }); |
| 4692 | | 4899 | |
| 4693 | cases.add("implicit semicolon - for expression", | 4900 | ctx.objErrStage1("implicit semicolon - for expression", |
| 4694 | \\export fn entry() void { | 4901 | \\export fn entry() void { |
| 4695 | \\ _ = for(foo()) |_| {}; | 4902 | \\ _ = for(foo()) |_| {}; |
| 4696 | \\ var good = {}; | 4903 | \\ var good = {}; |
| ... | @@ -4698,32 +4905,33 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -4698,32 +4905,33 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4698 | \\ var bad = {}; | 4905 | \\ var bad = {}; |
| 4699 | \\} | 4906 | \\} |
| 4700 | , &[_][]const u8{ | 4907 | , &[_][]const u8{ |
| 4701 | "tmp.zig:5:5: error: expected token ';', found 'var'", | 4908 | "tmp.zig:5:5: error: expected ';', found 'var'", |
| 4702 | }); | 4909 | }); |
| 4703 | | 4910 | |
| 4704 | cases.add("multiple function definitions", | 4911 | ctx.objErrStage1("multiple function definitions", |
| 4705 | \\fn a() void {} | 4912 | \\fn a() void {} |
| 4706 | \\fn a() void {} | 4913 | \\fn a() void {} |
| 4707 | \\export fn entry() void { a(); } | 4914 | \\export fn entry() void { a(); } |
| 4708 | , &[_][]const u8{ | 4915 | , &[_][]const u8{ |
| 4709 | "tmp.zig:2:1: error: redefinition of 'a'", | 4916 | "tmp.zig:2:1: error: redeclaration of 'a'", |
| | 4917 | "tmp.zig:1:1: note: other declaration here", |
| 4710 | }); | 4918 | }); |
| 4711 | | 4919 | |
| 4712 | cases.add("unreachable with return", | 4920 | ctx.objErrStage1("unreachable with return", |
| 4713 | \\fn a() noreturn {return;} | 4921 | \\fn a() noreturn {return;} |
| 4714 | \\export fn entry() void { a(); } | 4922 | \\export fn entry() void { a(); } |
| 4715 | , &[_][]const u8{ | 4923 | , &[_][]const u8{ |
| 4716 | "tmp.zig:1:18: error: expected type 'noreturn', found 'void'", | 4924 | "tmp.zig:1:18: error: expected type 'noreturn', found 'void'", |
| 4717 | }); | 4925 | }); |
| 4718 | | 4926 | |
| 4719 | cases.add("control reaches end of non-void function", | 4927 | ctx.objErrStage1("control reaches end of non-void function", |
| 4720 | \\fn a() i32 {} | 4928 | \\fn a() i32 {} |
| 4721 | \\export fn entry() void { _ = a(); } | 4929 | \\export fn entry() void { _ = a(); } |
| 4722 | , &[_][]const u8{ | 4930 | , &[_][]const u8{ |
| 4723 | "tmp.zig:1:12: error: expected type 'i32', found 'void'", | 4931 | "tmp.zig:1:12: error: expected type 'i32', found 'void'", |
| 4724 | }); | 4932 | }); |
| 4725 | | 4933 | |
| 4726 | cases.add("undefined function call", | 4934 | ctx.objErrStage1("undefined function call", |
| 4727 | \\export fn a() void { | 4935 | \\export fn a() void { |
| 4728 | \\ b(); | 4936 | \\ b(); |
| 4729 | \\} | 4937 | \\} |
| ... | @@ -4731,30 +4939,30 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -4731,30 +4939,30 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4731 | "tmp.zig:2:5: error: use of undeclared identifier 'b'", | 4939 | "tmp.zig:2:5: error: use of undeclared identifier 'b'", |
| 4732 | }); | 4940 | }); |
| 4733 | | 4941 | |
| 4734 | cases.add("wrong number of arguments", | 4942 | ctx.objErrStage1("wrong number of arguments", |
| 4735 | \\export fn a() void { | 4943 | \\export fn a() void { |
| 4736 | \\ b(1); | 4944 | \\ c(1); |
| 4737 | \\} | 4945 | \\} |
| 4738 | \\fn b(a: i32, b: i32, c: i32) void { } | 4946 | \\fn c(d: i32, e: i32, f: i32) void { _ = d; _ = e; _ = f; } |
| 4739 | , &[_][]const u8{ | 4947 | , &[_][]const u8{ |
| 4740 | "tmp.zig:2:6: error: expected 3 argument(s), found 1", | 4948 | "tmp.zig:2:6: error: expected 3 argument(s), found 1", |
| 4741 | }); | 4949 | }); |
| 4742 | | 4950 | |
| 4743 | cases.add("invalid type", | 4951 | ctx.objErrStage1("invalid type", |
| 4744 | \\fn a() bogus {} | 4952 | \\fn a() bogus {} |
| 4745 | \\export fn entry() void { _ = a(); } | 4953 | \\export fn entry() void { _ = a(); } |
| 4746 | , &[_][]const u8{ | 4954 | , &[_][]const u8{ |
| 4747 | "tmp.zig:1:8: error: use of undeclared identifier 'bogus'", | 4955 | "tmp.zig:1:8: error: use of undeclared identifier 'bogus'", |
| 4748 | }); | 4956 | }); |
| 4749 | | 4957 | |
| 4750 | cases.add("pointer to noreturn", | 4958 | ctx.objErrStage1("pointer to noreturn", |
| 4751 | \\fn a() *noreturn {} | 4959 | \\fn a() *noreturn {} |
| 4752 | \\export fn entry() void { _ = a(); } | 4960 | \\export fn entry() void { _ = a(); } |
| 4753 | , &[_][]const u8{ | 4961 | , &[_][]const u8{ |
| 4754 | "tmp.zig:1:9: error: pointer to noreturn not allowed", | 4962 | "tmp.zig:1:9: error: pointer to noreturn not allowed", |
| 4755 | }); | 4963 | }); |
| 4756 | | 4964 | |
| 4757 | cases.add("unreachable code", | 4965 | ctx.objErrStage1("unreachable code", |
| 4758 | \\export fn a() void { | 4966 | \\export fn a() void { |
| 4759 | \\ return; | 4967 | \\ return; |
| 4760 | \\ b(); | 4968 | \\ b(); |
| ... | @@ -4762,17 +4970,17 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -4762,17 +4970,17 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4762 | \\ | 4970 | \\ |
| 4763 | \\fn b() void {} | 4971 | \\fn b() void {} |
| 4764 | , &[_][]const u8{ | 4972 | , &[_][]const u8{ |
| 4765 | "tmp.zig:3:5: error: unreachable code", | 4973 | "tmp.zig:3:6: error: unreachable code", |
| | 4974 | "tmp.zig:2:5: note: control flow is diverted here", |
| 4766 | }); | 4975 | }); |
| 4767 | | 4976 | |
| 4768 | cases.add("bad import", | 4977 | ctx.objErrStage1("bad import", |
| 4769 | \\const bogus = @import("bogus-does-not-exist.zig",); | 4978 | \\const bogus = @import("bogus-does-not-exist.zig",); |
| 4770 | \\export fn entry() void { bogus.bogo(); } | | |
| 4771 | , &[_][]const u8{ | 4979 | , &[_][]const u8{ |
| 4772 | "tmp.zig:1:15: error: unable to find 'bogus-does-not-exist.zig'", | 4980 | "tmp.zig:1:23: error: unable to load '${DIR}bogus-does-not-exist.zig': FileNotFound", |
| 4773 | }); | 4981 | }); |
| 4774 | | 4982 | |
| 4775 | cases.add("undeclared identifier", | 4983 | ctx.objErrStage1("undeclared identifier", |
| 4776 | \\export fn a() void { | 4984 | \\export fn a() void { |
| 4777 | \\ return | 4985 | \\ return |
| 4778 | \\ b + | 4986 | \\ b + |
| ... | @@ -4782,33 +4990,36 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -4782,33 +4990,36 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4782 | "tmp.zig:3:5: error: use of undeclared identifier 'b'", | 4990 | "tmp.zig:3:5: error: use of undeclared identifier 'b'", |
| 4783 | }); | 4991 | }); |
| 4784 | | 4992 | |
| 4785 | cases.add("parameter redeclaration", | 4993 | ctx.objErrStage1("parameter redeclaration", |
| 4786 | \\fn f(a : i32, a : i32) void { | 4994 | \\fn f(a : i32, a : i32) void { |
| 4787 | \\} | 4995 | \\} |
| 4788 | \\export fn entry() void { f(1, 2); } | 4996 | \\export fn entry() void { f(1, 2); } |
| 4789 | , &[_][]const u8{ | 4997 | , &[_][]const u8{ |
| 4790 | "tmp.zig:1:15: error: redeclaration of variable 'a'", | 4998 | "tmp.zig:1:15: error: redeclaration of function parameter 'a'", |
| | 4999 | "tmp.zig:1:6: note: previous declaration here", |
| 4791 | }); | 5000 | }); |
| 4792 | | 5001 | |
| 4793 | cases.add("local variable redeclaration", | 5002 | ctx.objErrStage1("local variable redeclaration", |
| 4794 | \\export fn f() void { | 5003 | \\export fn f() void { |
| 4795 | \\ const a : i32 = 0; | 5004 | \\ const a : i32 = 0; |
| 4796 | \\ const a = 0; | 5005 | \\ var a = 0; |
| 4797 | \\} | 5006 | \\} |
| 4798 | , &[_][]const u8{ | 5007 | , &[_][]const u8{ |
| 4799 | "tmp.zig:3:5: error: redeclaration of variable 'a'", | 5008 | "tmp.zig:3:9: error: redeclaration of local constant 'a'", |
| | 5009 | "tmp.zig:2:11: note: previous declaration here", |
| 4800 | }); | 5010 | }); |
| 4801 | | 5011 | |
| 4802 | cases.add("local variable redeclares parameter", | 5012 | ctx.objErrStage1("local variable redeclares parameter", |
| 4803 | \\fn f(a : i32) void { | 5013 | \\fn f(a : i32) void { |
| 4804 | \\ const a = 0; | 5014 | \\ const a = 0; |
| 4805 | \\} | 5015 | \\} |
| 4806 | \\export fn entry() void { f(1); } | 5016 | \\export fn entry() void { f(1); } |
| 4807 | , &[_][]const u8{ | 5017 | , &[_][]const u8{ |
| 4808 | "tmp.zig:2:5: error: redeclaration of variable 'a'", | 5018 | "tmp.zig:2:11: error: redeclaration of function parameter 'a'", |
| | 5019 | "tmp.zig:1:6: note: previous declaration here", |
| 4809 | }); | 5020 | }); |
| 4810 | | 5021 | |
| 4811 | cases.add("variable has wrong type", | 5022 | ctx.objErrStage1("variable has wrong type", |
| 4812 | \\export fn f() i32 { | 5023 | \\export fn f() i32 { |
| 4813 | \\ const a = "a"; | 5024 | \\ const a = "a"; |
| 4814 | \\ return a; | 5025 | \\ return a; |
| ... | @@ -4817,7 +5028,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -4817,7 +5028,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4817 | "tmp.zig:3:12: error: expected type 'i32', found '*const [1:0]u8'", | 5028 | "tmp.zig:3:12: error: expected type 'i32', found '*const [1:0]u8'", |
| 4818 | }); | 5029 | }); |
| 4819 | | 5030 | |
| 4820 | cases.add("if condition is bool, not int", | 5031 | ctx.objErrStage1("if condition is bool, not int", |
| 4821 | \\export fn f() void { | 5032 | \\export fn f() void { |
| 4822 | \\ if (0) {} | 5033 | \\ if (0) {} |
| 4823 | \\} | 5034 | \\} |
| ... | @@ -4825,30 +5036,32 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -4825,30 +5036,32 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4825 | "tmp.zig:2:9: error: expected type 'bool', found 'comptime_int'", | 5036 | "tmp.zig:2:9: error: expected type 'bool', found 'comptime_int'", |
| 4826 | }); | 5037 | }); |
| 4827 | | 5038 | |
| 4828 | cases.add("assign unreachable", | 5039 | ctx.objErrStage1("assign unreachable", |
| 4829 | \\export fn f() void { | 5040 | \\export fn f() void { |
| 4830 | \\ const a = return; | 5041 | \\ const a = return; |
| 4831 | \\} | 5042 | \\} |
| 4832 | , &[_][]const u8{ | 5043 | , &[_][]const u8{ |
| 4833 | "tmp.zig:2:5: error: unreachable code", | 5044 | "tmp.zig:2:5: error: unreachable code", |
| | 5045 | "tmp.zig:2:15: note: control flow is diverted here", |
| 4834 | }); | 5046 | }); |
| 4835 | | 5047 | |
| 4836 | cases.add("unreachable variable", | 5048 | ctx.objErrStage1("unreachable variable", |
| 4837 | \\export fn f() void { | 5049 | \\export fn f() void { |
| 4838 | \\ const a: noreturn = {}; | 5050 | \\ const a: noreturn = {}; |
| | 5051 | \\ _ = a; |
| 4839 | \\} | 5052 | \\} |
| 4840 | , &[_][]const u8{ | 5053 | , &[_][]const u8{ |
| 4841 | "tmp.zig:2:25: error: expected type 'noreturn', found 'void'", | 5054 | "tmp.zig:2:25: error: expected type 'noreturn', found 'void'", |
| 4842 | }); | 5055 | }); |
| 4843 | | 5056 | |
| 4844 | cases.add("unreachable parameter", | 5057 | ctx.objErrStage1("unreachable parameter", |
| 4845 | \\fn f(a: noreturn) void {} | 5058 | \\fn f(a: noreturn) void { _ = a; } |
| 4846 | \\export fn entry() void { f(); } | 5059 | \\export fn entry() void { f(); } |
| 4847 | , &[_][]const u8{ | 5060 | , &[_][]const u8{ |
| 4848 | "tmp.zig:1:9: error: parameter of type 'noreturn' not allowed", | 5061 | "tmp.zig:1:9: error: parameter of type 'noreturn' not allowed", |
| 4849 | }); | 5062 | }); |
| 4850 | | 5063 | |
| 4851 | cases.add("assign to constant variable", | 5064 | ctx.objErrStage1("assign to constant variable", |
| 4852 | \\export fn f() void { | 5065 | \\export fn f() void { |
| 4853 | \\ const a = 3; | 5066 | \\ const a = 3; |
| 4854 | \\ a = 4; | 5067 | \\ a = 4; |
| ... | @@ -4857,7 +5070,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -4857,7 +5070,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4857 | "tmp.zig:3:9: error: cannot assign to constant", | 5070 | "tmp.zig:3:9: error: cannot assign to constant", |
| 4858 | }); | 5071 | }); |
| 4859 | | 5072 | |
| 4860 | cases.add("use of undeclared identifier", | 5073 | ctx.objErrStage1("use of undeclared identifier", |
| 4861 | \\export fn f() void { | 5074 | \\export fn f() void { |
| 4862 | \\ b = 3; | 5075 | \\ b = 3; |
| 4863 | \\} | 5076 | \\} |
| ... | @@ -4865,15 +5078,15 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -4865,15 +5078,15 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4865 | "tmp.zig:2:5: error: use of undeclared identifier 'b'", | 5078 | "tmp.zig:2:5: error: use of undeclared identifier 'b'", |
| 4866 | }); | 5079 | }); |
| 4867 | | 5080 | |
| 4868 | cases.add("const is a statement, not an expression", | 5081 | ctx.objErrStage1("const is a statement, not an expression", |
| 4869 | \\export fn f() void { | 5082 | \\export fn f() void { |
| 4870 | \\ (const a = 0); | 5083 | \\ (const a = 0); |
| 4871 | \\} | 5084 | \\} |
| 4872 | , &[_][]const u8{ | 5085 | , &[_][]const u8{ |
| 4873 | "tmp.zig:2:6: error: invalid token: 'const'", | 5086 | "tmp.zig:2:6: error: expected expression, found 'const'", |
| 4874 | }); | 5087 | }); |
| 4875 | | 5088 | |
| 4876 | cases.add("array access of undeclared identifier", | 5089 | ctx.objErrStage1("array access of undeclared identifier", |
| 4877 | \\export fn f() void { | 5090 | \\export fn f() void { |
| 4878 | \\ i[i] = i[i]; | 5091 | \\ i[i] = i[i]; |
| 4879 | \\} | 5092 | \\} |
| ... | @@ -4881,7 +5094,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -4881,7 +5094,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4881 | "tmp.zig:2:5: error: use of undeclared identifier 'i'", | 5094 | "tmp.zig:2:5: error: use of undeclared identifier 'i'", |
| 4882 | }); | 5095 | }); |
| 4883 | | 5096 | |
| 4884 | cases.add("array access of non array", | 5097 | ctx.objErrStage1("array access of non array", |
| 4885 | \\export fn f() void { | 5098 | \\export fn f() void { |
| 4886 | \\ var bad : bool = undefined; | 5099 | \\ var bad : bool = undefined; |
| 4887 | \\ bad[0] = bad[0]; | 5100 | \\ bad[0] = bad[0]; |
| ... | @@ -4895,7 +5108,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -4895,7 +5108,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4895 | "tmp.zig:7:12: error: array access of non-array type 'bool'", | 5108 | "tmp.zig:7:12: error: array access of non-array type 'bool'", |
| 4896 | }); | 5109 | }); |
| 4897 | | 5110 | |
| 4898 | cases.add("array access with non integer index", | 5111 | ctx.objErrStage1("array access with non integer index", |
| 4899 | \\export fn f() void { | 5112 | \\export fn f() void { |
| 4900 | \\ var array = "aoeu"; | 5113 | \\ var array = "aoeu"; |
| 4901 | \\ var bad = false; | 5114 | \\ var bad = false; |
| ... | @@ -4911,7 +5124,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -4911,7 +5124,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4911 | "tmp.zig:9:15: error: expected type 'usize', found 'bool'", | 5124 | "tmp.zig:9:15: error: expected type 'usize', found 'bool'", |
| 4912 | }); | 5125 | }); |
| 4913 | | 5126 | |
| 4914 | cases.add("write to const global variable", | 5127 | ctx.objErrStage1("write to const global variable", |
| 4915 | \\const x : i32 = 99; | 5128 | \\const x : i32 = 99; |
| 4916 | \\fn f() void { | 5129 | \\fn f() void { |
| 4917 | \\ x = 1; | 5130 | \\ x = 1; |
| ... | @@ -4921,58 +5134,64 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -4921,58 +5134,64 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4921 | "tmp.zig:3:9: error: cannot assign to constant", | 5134 | "tmp.zig:3:9: error: cannot assign to constant", |
| 4922 | }); | 5135 | }); |
| 4923 | | 5136 | |
| 4924 | cases.add("missing else clause", | 5137 | ctx.objErrStage1("missing else clause", |
| 4925 | \\fn f(b: bool) void { | 5138 | \\fn f(b: bool) void { |
| 4926 | \\ const x : i32 = if (b) h: { break :h 1; }; | 5139 | \\ const x : i32 = if (b) h: { break :h 1; }; |
| | 5140 | \\ _ = x; |
| 4927 | \\} | 5141 | \\} |
| 4928 | \\fn g(b: bool) void { | 5142 | \\fn g(b: bool) void { |
| 4929 | \\ const y = if (b) h: { break :h @as(i32, 1); }; | 5143 | \\ const y = if (b) h: { break :h @as(i32, 1); }; |
| | 5144 | \\ _ = y; |
| 4930 | \\} | 5145 | \\} |
| 4931 | \\export fn entry() void { f(true); g(true); } | 5146 | \\export fn entry() void { f(true); g(true); } |
| 4932 | , &[_][]const u8{ | 5147 | , &[_][]const u8{ |
| 4933 | "tmp.zig:2:21: error: expected type 'i32', found 'void'", | 5148 | "tmp.zig:2:21: error: expected type 'i32', found 'void'", |
| 4934 | "tmp.zig:5:15: error: incompatible types: 'i32' and 'void'", | 5149 | "tmp.zig:6:15: error: incompatible types: 'i32' and 'void'", |
| 4935 | }); | 5150 | }); |
| 4936 | | 5151 | |
| 4937 | cases.add("invalid struct field", | 5152 | ctx.objErrStage1("invalid struct field", |
| 4938 | \\const A = struct { x : i32, }; | 5153 | \\const A = struct { x : i32, }; |
| 4939 | \\export fn f() void { | 5154 | \\export fn f() void { |
| 4940 | \\ var a : A = undefined; | 5155 | \\ var a : A = undefined; |
| 4941 | \\ a.foo = 1; | 5156 | \\ a.foo = 1; |
| 4942 | \\ const y = a.bar; | 5157 | \\ const y = a.bar; |
| | 5158 | \\ _ = y; |
| 4943 | \\} | 5159 | \\} |
| 4944 | \\export fn g() void { | 5160 | \\export fn g() void { |
| 4945 | \\ var a : A = undefined; | 5161 | \\ var a : A = undefined; |
| 4946 | \\ const y = a.bar; | 5162 | \\ const y = a.bar; |
| | 5163 | \\ _ = y; |
| 4947 | \\} | 5164 | \\} |
| 4948 | , &[_][]const u8{ | 5165 | , &[_][]const u8{ |
| 4949 | "tmp.zig:4:6: error: no member named 'foo' in struct 'A'", | 5166 | "tmp.zig:4:6: error: no member named 'foo' in struct 'A'", |
| 4950 | "tmp.zig:9:16: error: no member named 'bar' in struct 'A'", | 5167 | "tmp.zig:10:16: error: no member named 'bar' in struct 'A'", |
| 4951 | }); | 5168 | }); |
| 4952 | | 5169 | |
| 4953 | cases.add("redefinition of struct", | 5170 | ctx.objErrStage1("redefinition of struct", |
| 4954 | \\const A = struct { x : i32, }; | 5171 | \\const A = struct { x : i32, }; |
| 4955 | \\const A = struct { y : i32, }; | 5172 | \\const A = struct { y : i32, }; |
| 4956 | , &[_][]const u8{ | 5173 | , &[_][]const u8{ |
| 4957 | "tmp.zig:2:1: error: redefinition of 'A'", | 5174 | "tmp.zig:2:1: error: redeclaration of 'A'", |
| | 5175 | "tmp.zig:1:1: note: other declaration here", |
| 4958 | }); | 5176 | }); |
| 4959 | | 5177 | |
| 4960 | cases.add("redefinition of enums", | 5178 | ctx.objErrStage1("redefinition of enums", |
| 4961 | \\const A = enum {}; | 5179 | \\const A = enum {x}; |
| 4962 | \\const A = enum {}; | 5180 | \\const A = enum {x}; |
| 4963 | , &[_][]const u8{ | 5181 | , &[_][]const u8{ |
| 4964 | "tmp.zig:2:1: error: redefinition of 'A'", | 5182 | "tmp.zig:2:1: error: redeclaration of 'A'", |
| | 5183 | "tmp.zig:1:1: note: other declaration here", |
| 4965 | }); | 5184 | }); |
| 4966 | | 5185 | |
| 4967 | cases.add("redefinition of global variables", | 5186 | ctx.objErrStage1("redefinition of global variables", |
| 4968 | \\var a : i32 = 1; | 5187 | \\var a : i32 = 1; |
| 4969 | \\var a : i32 = 2; | 5188 | \\var a : i32 = 2; |
| 4970 | , &[_][]const u8{ | 5189 | , &[_][]const u8{ |
| 4971 | "tmp.zig:2:1: error: redefinition of 'a'", | 5190 | "tmp.zig:2:1: error: redeclaration of 'a'", |
| 4972 | "tmp.zig:1:1: note: previous definition is here", | 5191 | "tmp.zig:1:1: note: other declaration here", |
| 4973 | }); | 5192 | }); |
| 4974 | | 5193 | |
| 4975 | cases.add("duplicate field in struct value expression", | 5194 | ctx.objErrStage1("duplicate field in struct value expression", |
| 4976 | \\const A = struct { | 5195 | \\const A = struct { |
| 4977 | \\ x : i32, | 5196 | \\ x : i32, |
| 4978 | \\ y : i32, | 5197 | \\ y : i32, |
| ... | @@ -4985,12 +5204,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -4985,12 +5204,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4985 | \\ .x = 3, | 5204 | \\ .x = 3, |
| 4986 | \\ .z = 4, | 5205 | \\ .z = 4, |
| 4987 | \\ }; | 5206 | \\ }; |
| | 5207 | \\ _ = a; |
| 4988 | \\} | 5208 | \\} |
| 4989 | , &[_][]const u8{ | 5209 | , &[_][]const u8{ |
| 4990 | "tmp.zig:11:9: error: duplicate field", | 5210 | "tmp.zig:11:9: error: duplicate field", |
| 4991 | }); | 5211 | }); |
| 4992 | | 5212 | |
| 4993 | cases.add("missing field in struct value expression", | 5213 | ctx.objErrStage1("missing field in struct value expression", |
| 4994 | \\const A = struct { | 5214 | \\const A = struct { |
| 4995 | \\ x : i32, | 5215 | \\ x : i32, |
| 4996 | \\ y : i32, | 5216 | \\ y : i32, |
| ... | @@ -5003,12 +5223,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -5003,12 +5223,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5003 | \\ .z = 4, | 5223 | \\ .z = 4, |
| 5004 | \\ .y = 2, | 5224 | \\ .y = 2, |
| 5005 | \\ }; | 5225 | \\ }; |
| | 5226 | \\ _ = a; |
| 5006 | \\} | 5227 | \\} |
| 5007 | , &[_][]const u8{ | 5228 | , &[_][]const u8{ |
| 5008 | "tmp.zig:9:17: error: missing field: 'x'", | 5229 | "tmp.zig:9:17: error: missing field: 'x'", |
| 5009 | }); | 5230 | }); |
| 5010 | | 5231 | |
| 5011 | cases.add("invalid field in struct value expression", | 5232 | ctx.objErrStage1("invalid field in struct value expression", |
| 5012 | \\const A = struct { | 5233 | \\const A = struct { |
| 5013 | \\ x : i32, | 5234 | \\ x : i32, |
| 5014 | \\ y : i32, | 5235 | \\ y : i32, |
| ... | @@ -5020,12 +5241,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -5020,12 +5241,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5020 | \\ .y = 2, | 5241 | \\ .y = 2, |
| 5021 | \\ .foo = 42, | 5242 | \\ .foo = 42, |
| 5022 | \\ }; | 5243 | \\ }; |
| | 5244 | \\ _ = a; |
| 5023 | \\} | 5245 | \\} |
| 5024 | , &[_][]const u8{ | 5246 | , &[_][]const u8{ |
| 5025 | "tmp.zig:10:9: error: no member named 'foo' in struct 'A'", | 5247 | "tmp.zig:10:9: error: no member named 'foo' in struct 'A'", |
| 5026 | }); | 5248 | }); |
| 5027 | | 5249 | |
| 5028 | cases.add("invalid break expression", | 5250 | ctx.objErrStage1("invalid break expression", |
| 5029 | \\export fn f() void { | 5251 | \\export fn f() void { |
| 5030 | \\ break; | 5252 | \\ break; |
| 5031 | \\} | 5253 | \\} |
| ... | @@ -5033,7 +5255,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -5033,7 +5255,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5033 | "tmp.zig:2:5: error: break expression outside loop", | 5255 | "tmp.zig:2:5: error: break expression outside loop", |
| 5034 | }); | 5256 | }); |
| 5035 | | 5257 | |
| 5036 | cases.add("invalid continue expression", | 5258 | ctx.objErrStage1("invalid continue expression", |
| 5037 | \\export fn f() void { | 5259 | \\export fn f() void { |
| 5038 | \\ continue; | 5260 | \\ continue; |
| 5039 | \\} | 5261 | \\} |
| ... | @@ -5041,48 +5263,49 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -5041,48 +5263,49 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5041 | "tmp.zig:2:5: error: continue expression outside loop", | 5263 | "tmp.zig:2:5: error: continue expression outside loop", |
| 5042 | }); | 5264 | }); |
| 5043 | | 5265 | |
| 5044 | cases.add("invalid maybe type", | 5266 | ctx.objErrStage1("invalid maybe type", |
| 5045 | \\export fn f() void { | 5267 | \\export fn f() void { |
| 5046 | \\ if (true) |x| { } | 5268 | \\ if (true) |x| { _ = x; } |
| 5047 | \\} | 5269 | \\} |
| 5048 | , &[_][]const u8{ | 5270 | , &[_][]const u8{ |
| 5049 | "tmp.zig:2:9: error: expected optional type, found 'bool'", | 5271 | "tmp.zig:2:9: error: expected optional type, found 'bool'", |
| 5050 | }); | 5272 | }); |
| 5051 | | 5273 | |
| 5052 | cases.add("cast unreachable", | 5274 | ctx.objErrStage1("cast unreachable", |
| 5053 | \\fn f() i32 { | 5275 | \\fn f() i32 { |
| 5054 | \\ return @as(i32, return 1); | 5276 | \\ return @as(i32, return 1); |
| 5055 | \\} | 5277 | \\} |
| 5056 | \\export fn entry() void { _ = f(); } | 5278 | \\export fn entry() void { _ = f(); } |
| 5057 | , &[_][]const u8{ | 5279 | , &[_][]const u8{ |
| 5058 | "tmp.zig:2:12: error: unreachable code", | 5280 | "tmp.zig:2:12: error: unreachable code", |
| | 5281 | "tmp.zig:2:21: note: control flow is diverted here", |
| 5059 | }); | 5282 | }); |
| 5060 | | 5283 | |
| 5061 | cases.add("invalid builtin fn", | 5284 | ctx.objErrStage1("invalid builtin fn", |
| 5062 | \\fn f() @bogus(foo) { | 5285 | \\fn f() @bogus(foo) { |
| 5063 | \\} | 5286 | \\} |
| 5064 | \\export fn entry() void { _ = f(); } | 5287 | \\export fn entry() void { _ = f(); } |
| 5065 | , &[_][]const u8{ | 5288 | , &[_][]const u8{ |
| 5066 | "tmp.zig:1:8: error: invalid builtin function: 'bogus'", | 5289 | "tmp.zig:1:8: error: invalid builtin function: '@bogus'", |
| 5067 | }); | 5290 | }); |
| 5068 | | 5291 | |
| 5069 | cases.add("noalias on non pointer param", | 5292 | ctx.objErrStage1("noalias on non pointer param", |
| 5070 | \\fn f(noalias x: i32) void {} | 5293 | \\fn f(noalias x: i32) void { _ = x; } |
| 5071 | \\export fn entry() void { f(1234); } | 5294 | \\export fn entry() void { f(1234); } |
| 5072 | , &[_][]const u8{ | 5295 | , &[_][]const u8{ |
| 5073 | "tmp.zig:1:6: error: noalias on non-pointer parameter", | 5296 | "tmp.zig:1:6: error: noalias on non-pointer parameter", |
| 5074 | }); | 5297 | }); |
| 5075 | | 5298 | |
| 5076 | cases.add("struct init syntax for array", | 5299 | ctx.objErrStage1("struct init syntax for array", |
| 5077 | \\const foo = [3]u16{ .x = 1024 }; | 5300 | \\const foo = [3]u16{ .x = 1024 }; |
| 5078 | \\comptime { | 5301 | \\comptime { |
| 5079 | \\ _ = foo; | 5302 | \\ _ = foo; |
| 5080 | \\} | 5303 | \\} |
| 5081 | , &[_][]const u8{ | 5304 | , &[_][]const u8{ |
| 5082 | "tmp.zig:1:21: error: type '[3]u16' does not support struct initialization syntax", | 5305 | "tmp.zig:1:13: error: initializing array with struct syntax", |
| 5083 | }); | 5306 | }); |
| 5084 | | 5307 | |
| 5085 | cases.add("type variables must be constant", | 5308 | ctx.objErrStage1("type variables must be constant", |
| 5086 | \\var foo = u8; | 5309 | \\var foo = u8; |
| 5087 | \\export fn entry() foo { | 5310 | \\export fn entry() foo { |
| 5088 | \\ return 1; | 5311 | \\ return 1; |
| ... | @@ -5091,25 +5314,31 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -5091,25 +5314,31 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5091 | "tmp.zig:1:1: error: variable of type 'type' must be constant", | 5314 | "tmp.zig:1:1: error: variable of type 'type' must be constant", |
| 5092 | }); | 5315 | }); |
| 5093 | | 5316 | |
| 5094 | cases.add("variables shadowing types", | 5317 | ctx.objErrStage1("parameter shadowing global", |
| 5095 | \\const Foo = struct {}; | 5318 | \\const Foo = struct {}; |
| 5096 | \\const Bar = struct {}; | 5319 | \\fn f(Foo: i32) void {} |
| 5097 | \\ | 5320 | \\export fn entry() void { |
| 5098 | \\fn f(Foo: i32) void { | 5321 | \\ f(1234); |
| 5099 | \\ var Bar : i32 = undefined; | | |
| 5100 | \\} | 5322 | \\} |
| | 5323 | , &[_][]const u8{ |
| | 5324 | "tmp.zig:2:6: error: local shadows declaration of 'Foo'", |
| | 5325 | "tmp.zig:1:1: note: declared here", |
| | 5326 | }); |
| | 5327 | |
| | 5328 | ctx.objErrStage1("local variable shadowing global", |
| | 5329 | \\const Foo = struct {}; |
| | 5330 | \\const Bar = struct {}; |
| 5101 | \\ | 5331 | \\ |
| 5102 | \\export fn entry() void { | 5332 | \\export fn entry() void { |
| 5103 | \\ f(1234); | 5333 | \\ var Bar : i32 = undefined; |
| | 5334 | \\ _ = Bar; |
| 5104 | \\} | 5335 | \\} |
| 5105 | , &[_][]const u8{ | 5336 | , &[_][]const u8{ |
| 5106 | "tmp.zig:4:6: error: redefinition of 'Foo'", | 5337 | "tmp.zig:5:9: error: local shadows declaration of 'Bar'", |
| 5107 | "tmp.zig:1:1: note: previous definition is here", | 5338 | "tmp.zig:2:1: note: declared here", |
| 5108 | "tmp.zig:5:5: error: redefinition of 'Bar'", | | |
| 5109 | "tmp.zig:2:1: note: previous definition is here", | | |
| 5110 | }); | 5339 | }); |
| 5111 | | 5340 | |
| 5112 | cases.add("switch expression - missing enumeration prong", | 5341 | ctx.objErrStage1("switch expression - missing enumeration prong", |
| 5113 | \\const Number = enum { | 5342 | \\const Number = enum { |
| 5114 | \\ One, | 5343 | \\ One, |
| 5115 | \\ Two, | 5344 | \\ Two, |
| ... | @@ -5129,7 +5358,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -5129,7 +5358,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5129 | "tmp.zig:8:5: error: enumeration value 'Number.Four' not handled in switch", | 5358 | "tmp.zig:8:5: error: enumeration value 'Number.Four' not handled in switch", |
| 5130 | }); | 5359 | }); |
| 5131 | | 5360 | |
| 5132 | cases.add("switch expression - duplicate enumeration prong", | 5361 | ctx.objErrStage1("switch expression - duplicate enumeration prong", |
| 5133 | \\const Number = enum { | 5362 | \\const Number = enum { |
| 5134 | \\ One, | 5363 | \\ One, |
| 5135 | \\ Two, | 5364 | \\ Two, |
| ... | @@ -5149,10 +5378,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -5149,10 +5378,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5149 | \\export fn entry() usize { return @sizeOf(@TypeOf(f)); } | 5378 | \\export fn entry() usize { return @sizeOf(@TypeOf(f)); } |
| 5150 | , &[_][]const u8{ | 5379 | , &[_][]const u8{ |
| 5151 | "tmp.zig:13:15: error: duplicate switch value", | 5380 | "tmp.zig:13:15: error: duplicate switch value", |
| 5152 | "tmp.zig:10:15: note: other value is here", | 5381 | "tmp.zig:10:15: note: other value here", |
| 5153 | }); | 5382 | }); |
| 5154 | | 5383 | |
| 5155 | cases.add("switch expression - duplicate enumeration prong when else present", | 5384 | ctx.objErrStage1("switch expression - duplicate enumeration prong when else present", |
| 5156 | \\const Number = enum { | 5385 | \\const Number = enum { |
| 5157 | \\ One, | 5386 | \\ One, |
| 5158 | \\ Two, | 5387 | \\ Two, |
| ... | @@ -5173,10 +5402,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -5173,10 +5402,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5173 | \\export fn entry() usize { return @sizeOf(@TypeOf(f)); } | 5402 | \\export fn entry() usize { return @sizeOf(@TypeOf(f)); } |
| 5174 | , &[_][]const u8{ | 5403 | , &[_][]const u8{ |
| 5175 | "tmp.zig:13:15: error: duplicate switch value", | 5404 | "tmp.zig:13:15: error: duplicate switch value", |
| 5176 | "tmp.zig:10:15: note: other value is here", | 5405 | "tmp.zig:10:15: note: other value here", |
| 5177 | }); | 5406 | }); |
| 5178 | | 5407 | |
| 5179 | cases.add("switch expression - multiple else prongs", | 5408 | ctx.objErrStage1("switch expression - multiple else prongs", |
| 5180 | \\fn f(x: u32) void { | 5409 | \\fn f(x: u32) void { |
| 5181 | \\ const value: bool = switch (x) { | 5410 | \\ const value: bool = switch (x) { |
| 5182 | \\ 1234 => false, | 5411 | \\ 1234 => false, |
| ... | @@ -5191,7 +5420,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -5191,7 +5420,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5191 | "tmp.zig:5:9: error: multiple else prongs in switch expression", | 5420 | "tmp.zig:5:9: error: multiple else prongs in switch expression", |
| 5192 | }); | 5421 | }); |
| 5193 | | 5422 | |
| 5194 | cases.add("switch expression - non exhaustive integer prongs", | 5423 | ctx.objErrStage1("switch expression - non exhaustive integer prongs", |
| 5195 | \\fn foo(x: u8) void { | 5424 | \\fn foo(x: u8) void { |
| 5196 | \\ switch (x) { | 5425 | \\ switch (x) { |
| 5197 | \\ 0 => {}, | 5426 | \\ 0 => {}, |
| ... | @@ -5202,7 +5431,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -5202,7 +5431,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5202 | "tmp.zig:2:5: error: switch must handle all possibilities", | 5431 | "tmp.zig:2:5: error: switch must handle all possibilities", |
| 5203 | }); | 5432 | }); |
| 5204 | | 5433 | |
| 5205 | cases.add("switch expression - duplicate or overlapping integer value", | 5434 | ctx.objErrStage1("switch expression - duplicate or overlapping integer value", |
| 5206 | \\fn foo(x: u8) u8 { | 5435 | \\fn foo(x: u8) u8 { |
| 5207 | \\ return switch (x) { | 5436 | \\ return switch (x) { |
| 5208 | \\ 0 ... 100 => @as(u8, 0), | 5437 | \\ 0 ... 100 => @as(u8, 0), |
| ... | @@ -5214,11 +5443,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -5214,11 +5443,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5214 | \\export fn entry() usize { return @sizeOf(@TypeOf(foo)); } | 5443 | \\export fn entry() usize { return @sizeOf(@TypeOf(foo)); } |
| 5215 | , &[_][]const u8{ | 5444 | , &[_][]const u8{ |
| 5216 | "tmp.zig:6:9: error: duplicate switch value", | 5445 | "tmp.zig:6:9: error: duplicate switch value", |
| 5217 | "tmp.zig:5:14: note: previous value is here", | 5446 | "tmp.zig:5:14: note: previous value here", |
| 5218 | }); | 5447 | }); |
| 5219 | | 5448 | |
| 5220 | cases.add("switch expression - duplicate type", | 5449 | ctx.objErrStage1("switch expression - duplicate type", |
| 5221 | \\fn foo(comptime T: type, x: T) u8 { | 5450 | \\fn foo(comptime T: type, x: T) u8 { |
| | 5451 | \\ _ = x; |
| 5222 | \\ return switch (T) { | 5452 | \\ return switch (T) { |
| 5223 | \\ u32 => 0, | 5453 | \\ u32 => 0, |
| 5224 | \\ u64 => 1, | 5454 | \\ u64 => 1, |
| ... | @@ -5228,16 +5458,17 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -5228,16 +5458,17 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5228 | \\} | 5458 | \\} |
| 5229 | \\export fn entry() usize { return @sizeOf(@TypeOf(foo(u32, 0))); } | 5459 | \\export fn entry() usize { return @sizeOf(@TypeOf(foo(u32, 0))); } |
| 5230 | , &[_][]const u8{ | 5460 | , &[_][]const u8{ |
| 5231 | "tmp.zig:5:9: error: duplicate switch value", | 5461 | "tmp.zig:6:9: error: duplicate switch value", |
| 5232 | "tmp.zig:3:9: note: previous value is here", | 5462 | "tmp.zig:4:9: note: previous value here", |
| 5233 | }); | 5463 | }); |
| 5234 | | 5464 | |
| 5235 | cases.add("switch expression - duplicate type (struct alias)", | 5465 | ctx.objErrStage1("switch expression - duplicate type (struct alias)", |
| 5236 | \\const Test = struct { | 5466 | \\const Test = struct { |
| 5237 | \\ bar: i32, | 5467 | \\ bar: i32, |
| 5238 | \\}; | 5468 | \\}; |
| 5239 | \\const Test2 = Test; | 5469 | \\const Test2 = Test; |
| 5240 | \\fn foo(comptime T: type, x: T) u8 { | 5470 | \\fn foo(comptime T: type, x: T) u8 { |
| | 5471 | \\ _ = x; |
| 5241 | \\ return switch (T) { | 5472 | \\ return switch (T) { |
| 5242 | \\ Test => 0, | 5473 | \\ Test => 0, |
| 5243 | \\ u64 => 1, | 5474 | \\ u64 => 1, |
| ... | @@ -5247,11 +5478,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -5247,11 +5478,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5247 | \\} | 5478 | \\} |
| 5248 | \\export fn entry() usize { return @sizeOf(@TypeOf(foo(u32, 0))); } | 5479 | \\export fn entry() usize { return @sizeOf(@TypeOf(foo(u32, 0))); } |
| 5249 | , &[_][]const u8{ | 5480 | , &[_][]const u8{ |
| 5250 | "tmp.zig:9:9: error: duplicate switch value", | 5481 | "tmp.zig:10:9: error: duplicate switch value", |
| 5251 | "tmp.zig:7:9: note: previous value is here", | 5482 | "tmp.zig:8:9: note: previous value here", |
| 5252 | }); | 5483 | }); |
| 5253 | | 5484 | |
| 5254 | cases.add("switch expression - switch on pointer type with no else", | 5485 | ctx.objErrStage1("switch expression - switch on pointer type with no else", |
| 5255 | \\fn foo(x: *u8) void { | 5486 | \\fn foo(x: *u8) void { |
| 5256 | \\ switch (x) { | 5487 | \\ switch (x) { |
| 5257 | \\ &y => {}, | 5488 | \\ &y => {}, |
| ... | @@ -5263,7 +5494,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -5263,7 +5494,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5263 | "tmp.zig:2:5: error: else prong required when switching on type '*u8'", | 5494 | "tmp.zig:2:5: error: else prong required when switching on type '*u8'", |
| 5264 | }); | 5495 | }); |
| 5265 | | 5496 | |
| 5266 | cases.add("global variable initializer must be constant expression", | 5497 | ctx.objErrStage1("global variable initializer must be constant expression", |
| 5267 | \\extern fn foo() i32; | 5498 | \\extern fn foo() i32; |
| 5268 | \\const x = foo(); | 5499 | \\const x = foo(); |
| 5269 | \\export fn entry() i32 { return x; } | 5500 | \\export fn entry() i32 { return x; } |
| ... | @@ -5271,7 +5502,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -5271,7 +5502,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5271 | "tmp.zig:2:11: error: unable to evaluate constant expression", | 5502 | "tmp.zig:2:11: error: unable to evaluate constant expression", |
| 5272 | }); | 5503 | }); |
| 5273 | | 5504 | |
| 5274 | cases.add("array concatenation with wrong type", | 5505 | ctx.objErrStage1("array concatenation with wrong type", |
| 5275 | \\const src = "aoeu"; | 5506 | \\const src = "aoeu"; |
| 5276 | \\const derp: usize = 1234; | 5507 | \\const derp: usize = 1234; |
| 5277 | \\const a = derp ++ "foo"; | 5508 | \\const a = derp ++ "foo"; |
| ... | @@ -5281,7 +5512,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -5281,7 +5512,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5281 | "tmp.zig:3:11: error: expected array, found 'usize'", | 5512 | "tmp.zig:3:11: error: expected array, found 'usize'", |
| 5282 | }); | 5513 | }); |
| 5283 | | 5514 | |
| 5284 | cases.add("non compile time array concatenation", | 5515 | ctx.objErrStage1("non compile time array concatenation", |
| 5285 | \\fn f() []u8 { | 5516 | \\fn f() []u8 { |
| 5286 | \\ return s ++ "foo"; | 5517 | \\ return s ++ "foo"; |
| 5287 | \\} | 5518 | \\} |
| ... | @@ -5291,7 +5522,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -5291,7 +5522,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5291 | "tmp.zig:2:12: error: unable to evaluate constant expression", | 5522 | "tmp.zig:2:12: error: unable to evaluate constant expression", |
| 5292 | }); | 5523 | }); |
| 5293 | | 5524 | |
| 5294 | cases.add("@cImport with bogus include", | 5525 | ctx.objErrStage1("@cImport with bogus include", |
| 5295 | \\const c = @cImport(@cInclude("bogus.h")); | 5526 | \\const c = @cImport(@cInclude("bogus.h")); |
| 5296 | \\export fn entry() usize { return @sizeOf(@TypeOf(c.bogo)); } | 5527 | \\export fn entry() usize { return @sizeOf(@TypeOf(c.bogo)); } |
| 5297 | , &[_][]const u8{ | 5528 | , &[_][]const u8{ |
| ... | @@ -5299,7 +5530,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -5299,7 +5530,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5299 | ".h:1:10: note: 'bogus.h' file not found", | 5530 | ".h:1:10: note: 'bogus.h' file not found", |
| 5300 | }); | 5531 | }); |
| 5301 | | 5532 | |
| 5302 | cases.add("address of number literal", | 5533 | ctx.objErrStage1("address of number literal", |
| 5303 | \\const x = 3; | 5534 | \\const x = 3; |
| 5304 | \\const y = &x; | 5535 | \\const y = &x; |
| 5305 | \\fn foo() *const i32 { return y; } | 5536 | \\fn foo() *const i32 { return y; } |
| ... | @@ -5308,14 +5539,14 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -5308,14 +5539,14 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5308 | "tmp.zig:3:30: error: expected type '*const i32', found '*const comptime_int'", | 5539 | "tmp.zig:3:30: error: expected type '*const i32', found '*const comptime_int'", |
| 5309 | }); | 5540 | }); |
| 5310 | | 5541 | |
| 5311 | cases.add("integer overflow error", | 5542 | ctx.objErrStage1("integer overflow error", |
| 5312 | \\const x : u8 = 300; | 5543 | \\const x : u8 = 300; |
| 5313 | \\export fn entry() usize { return @sizeOf(@TypeOf(x)); } | 5544 | \\export fn entry() usize { return @sizeOf(@TypeOf(x)); } |
| 5314 | , &[_][]const u8{ | 5545 | , &[_][]const u8{ |
| 5315 | "tmp.zig:1:16: error: integer value 300 cannot be coerced to type 'u8'", | 5546 | "tmp.zig:1:16: error: integer value 300 cannot be coerced to type 'u8'", |
| 5316 | }); | 5547 | }); |
| 5317 | | 5548 | |
| 5318 | cases.add("invalid shift amount error", | 5549 | ctx.objErrStage1("invalid shift amount error", |
| 5319 | \\const x : u8 = 2; | 5550 | \\const x : u8 = 2; |
| 5320 | \\fn f() u16 { | 5551 | \\fn f() u16 { |
| 5321 | \\ return x << 8; | 5552 | \\ return x << 8; |
| ... | @@ -5325,7 +5556,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -5325,7 +5556,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5325 | "tmp.zig:3:17: error: integer value 8 cannot be coerced to type 'u3'", | 5556 | "tmp.zig:3:17: error: integer value 8 cannot be coerced to type 'u3'", |
| 5326 | }); | 5557 | }); |
| 5327 | | 5558 | |
| 5328 | cases.add("missing function call param", | 5559 | ctx.objErrStage1("missing function call param", |
| 5329 | \\const Foo = struct { | 5560 | \\const Foo = struct { |
| 5330 | \\ a: i32, | 5561 | \\ a: i32, |
| 5331 | \\ b: i32, | 5562 | \\ b: i32, |
| ... | @@ -5346,6 +5577,8 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -5346,6 +5577,8 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5346 | \\ | 5577 | \\ |
| 5347 | \\fn f(foo: *const Foo, index: usize) void { | 5578 | \\fn f(foo: *const Foo, index: usize) void { |
| 5348 | \\ const result = members[index](); | 5579 | \\ const result = members[index](); |
| | 5580 | \\ _ = foo; |
| | 5581 | \\ _ = result; |
| 5349 | \\} | 5582 | \\} |
| 5350 | \\ | 5583 | \\ |
| 5351 | \\export fn entry() usize { return @sizeOf(@TypeOf(f)); } | 5584 | \\export fn entry() usize { return @sizeOf(@TypeOf(f)); } |
| ... | @@ -5353,21 +5586,21 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -5353,21 +5586,21 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5353 | "tmp.zig:20:34: error: expected 1 argument(s), found 0", | 5586 | "tmp.zig:20:34: error: expected 1 argument(s), found 0", |
| 5354 | }); | 5587 | }); |
| 5355 | | 5588 | |
| 5356 | cases.add("missing function name", | 5589 | ctx.objErrStage1("missing function name", |
| 5357 | \\fn () void {} | 5590 | \\fn () void {} |
| 5358 | \\export fn entry() usize { return @sizeOf(@TypeOf(f)); } | 5591 | \\export fn entry() usize { return @sizeOf(@TypeOf(f)); } |
| 5359 | , &[_][]const u8{ | 5592 | , &[_][]const u8{ |
| 5360 | "tmp.zig:1:1: error: missing function name", | 5593 | "tmp.zig:1:1: error: missing function name", |
| 5361 | }); | 5594 | }); |
| 5362 | | 5595 | |
| 5363 | cases.add("missing param name", | 5596 | ctx.objErrStage1("missing param name", |
| 5364 | \\fn f(i32) void {} | 5597 | \\fn f(i32) void {} |
| 5365 | \\export fn entry() usize { return @sizeOf(@TypeOf(f)); } | 5598 | \\export fn entry() usize { return @sizeOf(@TypeOf(f)); } |
| 5366 | , &[_][]const u8{ | 5599 | , &[_][]const u8{ |
| 5367 | "tmp.zig:1:6: error: missing parameter name", | 5600 | "tmp.zig:1:6: error: missing parameter name", |
| 5368 | }); | 5601 | }); |
| 5369 | | 5602 | |
| 5370 | cases.add("wrong function type", | 5603 | ctx.objErrStage1("wrong function type", |
| 5371 | \\const fns = [_]fn() void { a, b, c }; | 5604 | \\const fns = [_]fn() void { a, b, c }; |
| 5372 | \\fn a() i32 {return 0;} | 5605 | \\fn a() i32 {return 0;} |
| 5373 | \\fn b() i32 {return 1;} | 5606 | \\fn b() i32 {return 1;} |
| ... | @@ -5377,7 +5610,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -5377,7 +5610,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5377 | "tmp.zig:1:28: error: expected type 'fn() void', found 'fn() i32'", | 5610 | "tmp.zig:1:28: error: expected type 'fn() void', found 'fn() i32'", |
| 5378 | }); | 5611 | }); |
| 5379 | | 5612 | |
| 5380 | cases.add("extern function pointer mismatch", | 5613 | ctx.objErrStage1("extern function pointer mismatch", |
| 5381 | \\const fns = [_](fn(i32)i32) { a, b, c }; | 5614 | \\const fns = [_](fn(i32)i32) { a, b, c }; |
| 5382 | \\pub fn a(x: i32) i32 {return x + 0;} | 5615 | \\pub fn a(x: i32) i32 {return x + 0;} |
| 5383 | \\pub fn b(x: i32) i32 {return x + 1;} | 5616 | \\pub fn b(x: i32) i32 {return x + 1;} |
| ... | @@ -5388,15 +5621,16 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -5388,15 +5621,16 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5388 | "tmp.zig:1:37: error: expected type 'fn(i32) i32', found 'fn(i32) callconv(.C) i32'", | 5621 | "tmp.zig:1:37: error: expected type 'fn(i32) i32', found 'fn(i32) callconv(.C) i32'", |
| 5389 | }); | 5622 | }); |
| 5390 | | 5623 | |
| 5391 | cases.add("colliding invalid top level functions", | 5624 | ctx.objErrStage1("colliding invalid top level functions", |
| 5392 | \\fn func() bogus {} | 5625 | \\fn func() bogus {} |
| 5393 | \\fn func() bogus {} | 5626 | \\fn func() bogus {} |
| 5394 | \\export fn entry() usize { return @sizeOf(@TypeOf(func)); } | 5627 | \\export fn entry() usize { return @sizeOf(@TypeOf(func)); } |
| 5395 | , &[_][]const u8{ | 5628 | , &[_][]const u8{ |
| 5396 | "tmp.zig:2:1: error: redefinition of 'func'", | 5629 | "tmp.zig:2:1: error: redeclaration of 'func'", |
| | 5630 | "tmp.zig:1:1: note: other declaration here", |
| 5397 | }); | 5631 | }); |
| 5398 | | 5632 | |
| 5399 | cases.add("non constant expression in array size", | 5633 | ctx.objErrStage1("non constant expression in array size", |
| 5400 | \\const Foo = struct { | 5634 | \\const Foo = struct { |
| 5401 | \\ y: [get()]u8, | 5635 | \\ y: [get()]u8, |
| 5402 | \\}; | 5636 | \\}; |
| ... | @@ -5409,7 +5643,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -5409,7 +5643,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5409 | "tmp.zig:2:12: note: called from here", | 5643 | "tmp.zig:2:12: note: called from here", |
| 5410 | }); | 5644 | }); |
| 5411 | | 5645 | |
| 5412 | cases.add("addition with non numbers", | 5646 | ctx.objErrStage1("addition with non numbers", |
| 5413 | \\const Foo = struct { | 5647 | \\const Foo = struct { |
| 5414 | \\ field: i32, | 5648 | \\ field: i32, |
| 5415 | \\}; | 5649 | \\}; |
| ... | @@ -5420,7 +5654,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -5420,7 +5654,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5420 | "tmp.zig:4:28: error: invalid operands to binary expression: 'Foo' and 'Foo'", | 5654 | "tmp.zig:4:28: error: invalid operands to binary expression: 'Foo' and 'Foo'", |
| 5421 | }); | 5655 | }); |
| 5422 | | 5656 | |
| 5423 | cases.add("division by zero", | 5657 | ctx.objErrStage1("division by zero", |
| 5424 | \\const lit_int_x = 1 / 0; | 5658 | \\const lit_int_x = 1 / 0; |
| 5425 | \\const lit_float_x = 1.0 / 0.0; | 5659 | \\const lit_float_x = 1.0 / 0.0; |
| 5426 | \\const int_x = @as(u32, 1) / @as(u32, 0); | 5660 | \\const int_x = @as(u32, 1) / @as(u32, 0); |
| ... | @@ -5437,16 +5671,15 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -5437,16 +5671,15 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5437 | "tmp.zig:4:31: error: division by zero", | 5671 | "tmp.zig:4:31: error: division by zero", |
| 5438 | }); | 5672 | }); |
| 5439 | | 5673 | |
| 5440 | cases.add("normal string with newline", | 5674 | ctx.objErrStage1("normal string with newline", |
| 5441 | \\const foo = "a | 5675 | \\const foo = "a |
| 5442 | \\b"; | 5676 | \\b"; |
| 5443 | \\ | | |
| 5444 | \\export fn entry() usize { return @sizeOf(@TypeOf(foo)); } | | |
| 5445 | , &[_][]const u8{ | 5677 | , &[_][]const u8{ |
| 5446 | "tmp.zig:1:15: error: newline not allowed in string literal", | 5678 | "tmp.zig:1:13: error: expected expression, found 'invalid'", |
| | 5679 | "tmp.zig:1:15: note: invalid byte: '\\n'", |
| 5447 | }); | 5680 | }); |
| 5448 | | 5681 | |
| 5449 | cases.add("invalid comparison for function pointers", | 5682 | ctx.objErrStage1("invalid comparison for function pointers", |
| 5450 | \\fn foo() void {} | 5683 | \\fn foo() void {} |
| 5451 | \\const invalid = foo > foo; | 5684 | \\const invalid = foo > foo; |
| 5452 | \\ | 5685 | \\ |
| ... | @@ -5455,7 +5688,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -5455,7 +5688,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5455 | "tmp.zig:2:21: error: operator not allowed for type 'fn() void'", | 5688 | "tmp.zig:2:21: error: operator not allowed for type 'fn() void'", |
| 5456 | }); | 5689 | }); |
| 5457 | | 5690 | |
| 5458 | cases.add("generic function instance with non-constant expression", | 5691 | ctx.objErrStage1("generic function instance with non-constant expression", |
| 5459 | \\fn foo(comptime x: i32, y: i32) i32 { return x + y; } | 5692 | \\fn foo(comptime x: i32, y: i32) i32 { return x + y; } |
| 5460 | \\fn test1(a: i32, b: i32) i32 { | 5693 | \\fn test1(a: i32, b: i32) i32 { |
| 5461 | \\ return foo(a, b); | 5694 | \\ return foo(a, b); |
| ... | @@ -5466,7 +5699,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -5466,7 +5699,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5466 | "tmp.zig:3:16: error: runtime value cannot be passed to comptime arg", | 5699 | "tmp.zig:3:16: error: runtime value cannot be passed to comptime arg", |
| 5467 | }); | 5700 | }); |
| 5468 | | 5701 | |
| 5469 | cases.add("assign null to non-optional pointer", | 5702 | ctx.objErrStage1("assign null to non-optional pointer", |
| 5470 | \\const a: *u8 = null; | 5703 | \\const a: *u8 = null; |
| 5471 | \\ | 5704 | \\ |
| 5472 | \\export fn entry() usize { return @sizeOf(@TypeOf(a)); } | 5705 | \\export fn entry() usize { return @sizeOf(@TypeOf(a)); } |
| ... | @@ -5474,26 +5707,28 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -5474,26 +5707,28 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5474 | "tmp.zig:1:16: error: expected type '*u8', found '(null)'", | 5707 | "tmp.zig:1:16: error: expected type '*u8', found '(null)'", |
| 5475 | }); | 5708 | }); |
| 5476 | | 5709 | |
| 5477 | cases.add("indexing an array of size zero", | 5710 | ctx.objErrStage1("indexing an array of size zero", |
| 5478 | \\const array = [_]u8{}; | 5711 | \\const array = [_]u8{}; |
| 5479 | \\export fn foo() void { | 5712 | \\export fn foo() void { |
| 5480 | \\ const pointer = &array[0]; | 5713 | \\ const pointer = &array[0]; |
| | 5714 | \\ _ = pointer; |
| 5481 | \\} | 5715 | \\} |
| 5482 | , &[_][]const u8{ | 5716 | , &[_][]const u8{ |
| 5483 | "tmp.zig:3:27: error: accessing a zero length array is not allowed", | 5717 | "tmp.zig:3:27: error: accessing a zero length array is not allowed", |
| 5484 | }); | 5718 | }); |
| 5485 | | 5719 | |
| 5486 | cases.add("indexing an array of size zero with runtime index", | 5720 | ctx.objErrStage1("indexing an array of size zero with runtime index", |
| 5487 | \\const array = [_]u8{}; | 5721 | \\const array = [_]u8{}; |
| 5488 | \\export fn foo() void { | 5722 | \\export fn foo() void { |
| 5489 | \\ var index: usize = 0; | 5723 | \\ var index: usize = 0; |
| 5490 | \\ const pointer = &array[index]; | 5724 | \\ const pointer = &array[index]; |
| | 5725 | \\ _ = pointer; |
| 5491 | \\} | 5726 | \\} |
| 5492 | , &[_][]const u8{ | 5727 | , &[_][]const u8{ |
| 5493 | "tmp.zig:4:27: error: accessing a zero length array is not allowed", | 5728 | "tmp.zig:4:27: error: accessing a zero length array is not allowed", |
| 5494 | }); | 5729 | }); |
| 5495 | | 5730 | |
| 5496 | cases.add("compile time division by zero", | 5731 | ctx.objErrStage1("compile time division by zero", |
| 5497 | \\const y = foo(0); | 5732 | \\const y = foo(0); |
| 5498 | \\fn foo(x: u32) u32 { | 5733 | \\fn foo(x: u32) u32 { |
| 5499 | \\ return 1 / x; | 5734 | \\ return 1 / x; |
| ... | @@ -5505,7 +5740,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -5505,7 +5740,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5505 | "tmp.zig:1:14: note: referenced here", | 5740 | "tmp.zig:1:14: note: referenced here", |
| 5506 | }); | 5741 | }); |
| 5507 | | 5742 | |
| 5508 | cases.add("branch on undefined value", | 5743 | ctx.objErrStage1("branch on undefined value", |
| 5509 | \\const x = if (undefined) true else false; | 5744 | \\const x = if (undefined) true else false; |
| 5510 | \\ | 5745 | \\ |
| 5511 | \\export fn entry() usize { return @sizeOf(@TypeOf(x)); } | 5746 | \\export fn entry() usize { return @sizeOf(@TypeOf(x)); } |
| ... | @@ -5513,7 +5748,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -5513,7 +5748,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5513 | "tmp.zig:1:15: error: use of undefined value here causes undefined behavior", | 5748 | "tmp.zig:1:15: error: use of undefined value here causes undefined behavior", |
| 5514 | }); | 5749 | }); |
| 5515 | | 5750 | |
| 5516 | cases.add("div on undefined value", | 5751 | ctx.objErrStage1("div on undefined value", |
| 5517 | \\comptime { | 5752 | \\comptime { |
| 5518 | \\ var a: i64 = undefined; | 5753 | \\ var a: i64 = undefined; |
| 5519 | \\ _ = a / a; | 5754 | \\ _ = a / a; |
| ... | @@ -5522,7 +5757,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -5522,7 +5757,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5522 | "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", | 5757 | "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", |
| 5523 | }); | 5758 | }); |
| 5524 | | 5759 | |
| 5525 | cases.add("div assign on undefined value", | 5760 | ctx.objErrStage1("div assign on undefined value", |
| 5526 | \\comptime { | 5761 | \\comptime { |
| 5527 | \\ var a: i64 = undefined; | 5762 | \\ var a: i64 = undefined; |
| 5528 | \\ a /= a; | 5763 | \\ a /= a; |
| ... | @@ -5531,7 +5766,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -5531,7 +5766,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5531 | "tmp.zig:3:5: error: use of undefined value here causes undefined behavior", | 5766 | "tmp.zig:3:5: error: use of undefined value here causes undefined behavior", |
| 5532 | }); | 5767 | }); |
| 5533 | | 5768 | |
| 5534 | cases.add("mod on undefined value", | 5769 | ctx.objErrStage1("mod on undefined value", |
| 5535 | \\comptime { | 5770 | \\comptime { |
| 5536 | \\ var a: i64 = undefined; | 5771 | \\ var a: i64 = undefined; |
| 5537 | \\ _ = a % a; | 5772 | \\ _ = a % a; |
| ... | @@ -5540,7 +5775,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -5540,7 +5775,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5540 | "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", | 5775 | "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", |
| 5541 | }); | 5776 | }); |
| 5542 | | 5777 | |
| 5543 | cases.add("mod assign on undefined value", | 5778 | ctx.objErrStage1("mod assign on undefined value", |
| 5544 | \\comptime { | 5779 | \\comptime { |
| 5545 | \\ var a: i64 = undefined; | 5780 | \\ var a: i64 = undefined; |
| 5546 | \\ a %= a; | 5781 | \\ a %= a; |
| ... | @@ -5549,7 +5784,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -5549,7 +5784,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5549 | "tmp.zig:3:5: error: use of undefined value here causes undefined behavior", | 5784 | "tmp.zig:3:5: error: use of undefined value here causes undefined behavior", |
| 5550 | }); | 5785 | }); |
| 5551 | | 5786 | |
| 5552 | cases.add("add on undefined value", | 5787 | ctx.objErrStage1("add on undefined value", |
| 5553 | \\comptime { | 5788 | \\comptime { |
| 5554 | \\ var a: i64 = undefined; | 5789 | \\ var a: i64 = undefined; |
| 5555 | \\ _ = a + a; | 5790 | \\ _ = a + a; |
| ... | @@ -5558,7 +5793,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -5558,7 +5793,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5558 | "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", | 5793 | "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", |
| 5559 | }); | 5794 | }); |
| 5560 | | 5795 | |
| 5561 | cases.add("add assign on undefined value", | 5796 | ctx.objErrStage1("add assign on undefined value", |
| 5562 | \\comptime { | 5797 | \\comptime { |
| 5563 | \\ var a: i64 = undefined; | 5798 | \\ var a: i64 = undefined; |
| 5564 | \\ a += a; | 5799 | \\ a += a; |
| ... | @@ -5567,7 +5802,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -5567,7 +5802,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5567 | "tmp.zig:3:5: error: use of undefined value here causes undefined behavior", | 5802 | "tmp.zig:3:5: error: use of undefined value here causes undefined behavior", |
| 5568 | }); | 5803 | }); |
| 5569 | | 5804 | |
| 5570 | cases.add("add wrap on undefined value", | 5805 | ctx.objErrStage1("add wrap on undefined value", |
| 5571 | \\comptime { | 5806 | \\comptime { |
| 5572 | \\ var a: i64 = undefined; | 5807 | \\ var a: i64 = undefined; |
| 5573 | \\ _ = a +% a; | 5808 | \\ _ = a +% a; |
| ... | @@ -5576,7 +5811,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -5576,7 +5811,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5576 | "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", | 5811 | "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", |
| 5577 | }); | 5812 | }); |
| 5578 | | 5813 | |
| 5579 | cases.add("add wrap assign on undefined value", | 5814 | ctx.objErrStage1("add wrap assign on undefined value", |
| 5580 | \\comptime { | 5815 | \\comptime { |
| 5581 | \\ var a: i64 = undefined; | 5816 | \\ var a: i64 = undefined; |
| 5582 | \\ a +%= a; | 5817 | \\ a +%= a; |
| ... | @@ -5585,7 +5820,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -5585,7 +5820,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5585 | "tmp.zig:3:5: error: use of undefined value here causes undefined behavior", | 5820 | "tmp.zig:3:5: error: use of undefined value here causes undefined behavior", |
| 5586 | }); | 5821 | }); |
| 5587 | | 5822 | |
| 5588 | cases.add("sub on undefined value", | 5823 | ctx.objErrStage1("sub on undefined value", |
| 5589 | \\comptime { | 5824 | \\comptime { |
| 5590 | \\ var a: i64 = undefined; | 5825 | \\ var a: i64 = undefined; |
| 5591 | \\ _ = a - a; | 5826 | \\ _ = a - a; |
| ... | @@ -5594,7 +5829,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -5594,7 +5829,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5594 | "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", | 5829 | "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", |
| 5595 | }); | 5830 | }); |
| 5596 | | 5831 | |
| 5597 | cases.add("sub assign on undefined value", | 5832 | ctx.objErrStage1("sub assign on undefined value", |
| 5598 | \\comptime { | 5833 | \\comptime { |
| 5599 | \\ var a: i64 = undefined; | 5834 | \\ var a: i64 = undefined; |
| 5600 | \\ a -= a; | 5835 | \\ a -= a; |
| ... | @@ -5603,7 +5838,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -5603,7 +5838,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5603 | "tmp.zig:3:5: error: use of undefined value here causes undefined behavior", | 5838 | "tmp.zig:3:5: error: use of undefined value here causes undefined behavior", |
| 5604 | }); | 5839 | }); |
| 5605 | | 5840 | |
| 5606 | cases.add("sub wrap on undefined value", | 5841 | ctx.objErrStage1("sub wrap on undefined value", |
| 5607 | \\comptime { | 5842 | \\comptime { |
| 5608 | \\ var a: i64 = undefined; | 5843 | \\ var a: i64 = undefined; |
| 5609 | \\ _ = a -% a; | 5844 | \\ _ = a -% a; |
| ... | @@ -5612,7 +5847,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -5612,7 +5847,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5612 | "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", | 5847 | "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", |
| 5613 | }); | 5848 | }); |
| 5614 | | 5849 | |
| 5615 | cases.add("sub wrap assign on undefined value", | 5850 | ctx.objErrStage1("sub wrap assign on undefined value", |
| 5616 | \\comptime { | 5851 | \\comptime { |
| 5617 | \\ var a: i64 = undefined; | 5852 | \\ var a: i64 = undefined; |
| 5618 | \\ a -%= a; | 5853 | \\ a -%= a; |
| ... | @@ -5621,7 +5856,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -5621,7 +5856,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5621 | "tmp.zig:3:5: error: use of undefined value here causes undefined behavior", | 5856 | "tmp.zig:3:5: error: use of undefined value here causes undefined behavior", |
| 5622 | }); | 5857 | }); |
| 5623 | | 5858 | |
| 5624 | cases.add("mult on undefined value", | 5859 | ctx.objErrStage1("mult on undefined value", |
| 5625 | \\comptime { | 5860 | \\comptime { |
| 5626 | \\ var a: i64 = undefined; | 5861 | \\ var a: i64 = undefined; |
| 5627 | \\ _ = a * a; | 5862 | \\ _ = a * a; |
| ... | @@ -5630,7 +5865,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -5630,7 +5865,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5630 | "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", | 5865 | "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", |
| 5631 | }); | 5866 | }); |
| 5632 | | 5867 | |
| 5633 | cases.add("mult assign on undefined value", | 5868 | ctx.objErrStage1("mult assign on undefined value", |
| 5634 | \\comptime { | 5869 | \\comptime { |
| 5635 | \\ var a: i64 = undefined; | 5870 | \\ var a: i64 = undefined; |
| 5636 | \\ a *= a; | 5871 | \\ a *= a; |
| ... | @@ -5639,7 +5874,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -5639,7 +5874,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5639 | "tmp.zig:3:5: error: use of undefined value here causes undefined behavior", | 5874 | "tmp.zig:3:5: error: use of undefined value here causes undefined behavior", |
| 5640 | }); | 5875 | }); |
| 5641 | | 5876 | |
| 5642 | cases.add("mult wrap on undefined value", | 5877 | ctx.objErrStage1("mult wrap on undefined value", |
| 5643 | \\comptime { | 5878 | \\comptime { |
| 5644 | \\ var a: i64 = undefined; | 5879 | \\ var a: i64 = undefined; |
| 5645 | \\ _ = a *% a; | 5880 | \\ _ = a *% a; |
| ... | @@ -5648,7 +5883,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -5648,7 +5883,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5648 | "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", | 5883 | "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", |
| 5649 | }); | 5884 | }); |
| 5650 | | 5885 | |
| 5651 | cases.add("mult wrap assign on undefined value", | 5886 | ctx.objErrStage1("mult wrap assign on undefined value", |
| 5652 | \\comptime { | 5887 | \\comptime { |
| 5653 | \\ var a: i64 = undefined; | 5888 | \\ var a: i64 = undefined; |
| 5654 | \\ a *%= a; | 5889 | \\ a *%= a; |
| ... | @@ -5657,7 +5892,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -5657,7 +5892,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5657 | "tmp.zig:3:5: error: use of undefined value here causes undefined behavior", | 5892 | "tmp.zig:3:5: error: use of undefined value here causes undefined behavior", |
| 5658 | }); | 5893 | }); |
| 5659 | | 5894 | |
| 5660 | cases.add("shift left on undefined value", | 5895 | ctx.objErrStage1("shift left on undefined value", |
| 5661 | \\comptime { | 5896 | \\comptime { |
| 5662 | \\ var a: i64 = undefined; | 5897 | \\ var a: i64 = undefined; |
| 5663 | \\ _ = a << 2; | 5898 | \\ _ = a << 2; |
| ... | @@ -5666,7 +5901,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -5666,7 +5901,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5666 | "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", | 5901 | "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", |
| 5667 | }); | 5902 | }); |
| 5668 | | 5903 | |
| 5669 | cases.add("shift left assign on undefined value", | 5904 | ctx.objErrStage1("shift left assign on undefined value", |
| 5670 | \\comptime { | 5905 | \\comptime { |
| 5671 | \\ var a: i64 = undefined; | 5906 | \\ var a: i64 = undefined; |
| 5672 | \\ a <<= 2; | 5907 | \\ a <<= 2; |
| ... | @@ -5675,7 +5910,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -5675,7 +5910,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5675 | "tmp.zig:3:5: error: use of undefined value here causes undefined behavior", | 5910 | "tmp.zig:3:5: error: use of undefined value here causes undefined behavior", |
| 5676 | }); | 5911 | }); |
| 5677 | | 5912 | |
| 5678 | cases.add("shift right on undefined value", | 5913 | ctx.objErrStage1("shift right on undefined value", |
| 5679 | \\comptime { | 5914 | \\comptime { |
| 5680 | \\ var a: i64 = undefined; | 5915 | \\ var a: i64 = undefined; |
| 5681 | \\ _ = a >> 2; | 5916 | \\ _ = a >> 2; |
| ... | @@ -5684,7 +5919,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -5684,7 +5919,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5684 | "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", | 5919 | "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", |
| 5685 | }); | 5920 | }); |
| 5686 | | 5921 | |
| 5687 | cases.add("shift left assign on undefined value", | 5922 | ctx.objErrStage1("shift left assign on undefined value", |
| 5688 | \\comptime { | 5923 | \\comptime { |
| 5689 | \\ var a: i64 = undefined; | 5924 | \\ var a: i64 = undefined; |
| 5690 | \\ a >>= 2; | 5925 | \\ a >>= 2; |
| ... | @@ -5693,7 +5928,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -5693,7 +5928,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5693 | "tmp.zig:3:5: error: use of undefined value here causes undefined behavior", | 5928 | "tmp.zig:3:5: error: use of undefined value here causes undefined behavior", |
| 5694 | }); | 5929 | }); |
| 5695 | | 5930 | |
| 5696 | cases.add("bin and on undefined value", | 5931 | ctx.objErrStage1("bin and on undefined value", |
| 5697 | \\comptime { | 5932 | \\comptime { |
| 5698 | \\ var a: i64 = undefined; | 5933 | \\ var a: i64 = undefined; |
| 5699 | \\ _ = a & a; | 5934 | \\ _ = a & a; |
| ... | @@ -5702,7 +5937,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -5702,7 +5937,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5702 | "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", | 5937 | "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", |
| 5703 | }); | 5938 | }); |
| 5704 | | 5939 | |
| 5705 | cases.add("bin and assign on undefined value", | 5940 | ctx.objErrStage1("bin and assign on undefined value", |
| 5706 | \\comptime { | 5941 | \\comptime { |
| 5707 | \\ var a: i64 = undefined; | 5942 | \\ var a: i64 = undefined; |
| 5708 | \\ a &= a; | 5943 | \\ a &= a; |
| ... | @@ -5711,7 +5946,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -5711,7 +5946,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5711 | "tmp.zig:3:5: error: use of undefined value here causes undefined behavior", | 5946 | "tmp.zig:3:5: error: use of undefined value here causes undefined behavior", |
| 5712 | }); | 5947 | }); |
| 5713 | | 5948 | |
| 5714 | cases.add("bin or on undefined value", | 5949 | ctx.objErrStage1("bin or on undefined value", |
| 5715 | \\comptime { | 5950 | \\comptime { |
| 5716 | \\ var a: i64 = undefined; | 5951 | \\ var a: i64 = undefined; |
| 5717 | \\ _ = a | a; | 5952 | \\ _ = a | a; |
| ... | @@ -5720,7 +5955,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -5720,7 +5955,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5720 | "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", | 5955 | "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", |
| 5721 | }); | 5956 | }); |
| 5722 | | 5957 | |
| 5723 | cases.add("bin or assign on undefined value", | 5958 | ctx.objErrStage1("bin or assign on undefined value", |
| 5724 | \\comptime { | 5959 | \\comptime { |
| 5725 | \\ var a: i64 = undefined; | 5960 | \\ var a: i64 = undefined; |
| 5726 | \\ a |= a; | 5961 | \\ a |= a; |
| ... | @@ -5729,7 +5964,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -5729,7 +5964,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5729 | "tmp.zig:3:5: error: use of undefined value here causes undefined behavior", | 5964 | "tmp.zig:3:5: error: use of undefined value here causes undefined behavior", |
| 5730 | }); | 5965 | }); |
| 5731 | | 5966 | |
| 5732 | cases.add("bin xor on undefined value", | 5967 | ctx.objErrStage1("bin xor on undefined value", |
| 5733 | \\comptime { | 5968 | \\comptime { |
| 5734 | \\ var a: i64 = undefined; | 5969 | \\ var a: i64 = undefined; |
| 5735 | \\ _ = a ^ a; | 5970 | \\ _ = a ^ a; |
| ... | @@ -5738,7 +5973,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -5738,7 +5973,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5738 | "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", | 5973 | "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", |
| 5739 | }); | 5974 | }); |
| 5740 | | 5975 | |
| 5741 | cases.add("bin xor assign on undefined value", | 5976 | ctx.objErrStage1("bin xor assign on undefined value", |
| 5742 | \\comptime { | 5977 | \\comptime { |
| 5743 | \\ var a: i64 = undefined; | 5978 | \\ var a: i64 = undefined; |
| 5744 | \\ a ^= a; | 5979 | \\ a ^= a; |
| ... | @@ -5747,7 +5982,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -5747,7 +5982,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5747 | "tmp.zig:3:5: error: use of undefined value here causes undefined behavior", | 5982 | "tmp.zig:3:5: error: use of undefined value here causes undefined behavior", |
| 5748 | }); | 5983 | }); |
| 5749 | | 5984 | |
| 5750 | cases.add("comparison operators with undefined value", | 5985 | ctx.objErrStage1("comparison operators with undefined value", |
| 5751 | \\// operator == | 5986 | \\// operator == |
| 5752 | \\comptime { | 5987 | \\comptime { |
| 5753 | \\ var a: i64 = undefined; | 5988 | \\ var a: i64 = undefined; |
| ... | @@ -5793,7 +6028,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -5793,7 +6028,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5793 | "tmp.zig:35:11: error: use of undefined value here causes undefined behavior", | 6028 | "tmp.zig:35:11: error: use of undefined value here causes undefined behavior", |
| 5794 | }); | 6029 | }); |
| 5795 | | 6030 | |
| 5796 | cases.add("and on undefined value", | 6031 | ctx.objErrStage1("and on undefined value", |
| 5797 | \\comptime { | 6032 | \\comptime { |
| 5798 | \\ var a: bool = undefined; | 6033 | \\ var a: bool = undefined; |
| 5799 | \\ _ = a and a; | 6034 | \\ _ = a and a; |
| ... | @@ -5802,7 +6037,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -5802,7 +6037,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5802 | "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", | 6037 | "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", |
| 5803 | }); | 6038 | }); |
| 5804 | | 6039 | |
| 5805 | cases.add("or on undefined value", | 6040 | ctx.objErrStage1("or on undefined value", |
| 5806 | \\comptime { | 6041 | \\comptime { |
| 5807 | \\ var a: bool = undefined; | 6042 | \\ var a: bool = undefined; |
| 5808 | \\ _ = a or a; | 6043 | \\ _ = a or a; |
| ... | @@ -5811,7 +6046,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -5811,7 +6046,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5811 | "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", | 6046 | "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", |
| 5812 | }); | 6047 | }); |
| 5813 | | 6048 | |
| 5814 | cases.add("negate on undefined value", | 6049 | ctx.objErrStage1("negate on undefined value", |
| 5815 | \\comptime { | 6050 | \\comptime { |
| 5816 | \\ var a: i64 = undefined; | 6051 | \\ var a: i64 = undefined; |
| 5817 | \\ _ = -a; | 6052 | \\ _ = -a; |
| ... | @@ -5820,7 +6055,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -5820,7 +6055,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5820 | "tmp.zig:3:10: error: use of undefined value here causes undefined behavior", | 6055 | "tmp.zig:3:10: error: use of undefined value here causes undefined behavior", |
| 5821 | }); | 6056 | }); |
| 5822 | | 6057 | |
| 5823 | cases.add("negate wrap on undefined value", | 6058 | ctx.objErrStage1("negate wrap on undefined value", |
| 5824 | \\comptime { | 6059 | \\comptime { |
| 5825 | \\ var a: i64 = undefined; | 6060 | \\ var a: i64 = undefined; |
| 5826 | \\ _ = -%a; | 6061 | \\ _ = -%a; |
| ... | @@ -5829,7 +6064,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -5829,7 +6064,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5829 | "tmp.zig:3:11: error: use of undefined value here causes undefined behavior", | 6064 | "tmp.zig:3:11: error: use of undefined value here causes undefined behavior", |
| 5830 | }); | 6065 | }); |
| 5831 | | 6066 | |
| 5832 | cases.add("bin not on undefined value", | 6067 | ctx.objErrStage1("bin not on undefined value", |
| 5833 | \\comptime { | 6068 | \\comptime { |
| 5834 | \\ var a: i64 = undefined; | 6069 | \\ var a: i64 = undefined; |
| 5835 | \\ _ = ~a; | 6070 | \\ _ = ~a; |
| ... | @@ -5838,7 +6073,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -5838,7 +6073,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5838 | "tmp.zig:3:10: error: use of undefined value here causes undefined behavior", | 6073 | "tmp.zig:3:10: error: use of undefined value here causes undefined behavior", |
| 5839 | }); | 6074 | }); |
| 5840 | | 6075 | |
| 5841 | cases.add("bool not on undefined value", | 6076 | ctx.objErrStage1("bool not on undefined value", |
| 5842 | \\comptime { | 6077 | \\comptime { |
| 5843 | \\ var a: bool = undefined; | 6078 | \\ var a: bool = undefined; |
| 5844 | \\ _ = !a; | 6079 | \\ _ = !a; |
| ... | @@ -5847,7 +6082,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -5847,7 +6082,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5847 | "tmp.zig:3:10: error: use of undefined value here causes undefined behavior", | 6082 | "tmp.zig:3:10: error: use of undefined value here causes undefined behavior", |
| 5848 | }); | 6083 | }); |
| 5849 | | 6084 | |
| 5850 | cases.add("orelse on undefined value", | 6085 | ctx.objErrStage1("orelse on undefined value", |
| 5851 | \\comptime { | 6086 | \\comptime { |
| 5852 | \\ var a: ?bool = undefined; | 6087 | \\ var a: ?bool = undefined; |
| 5853 | \\ _ = a orelse false; | 6088 | \\ _ = a orelse false; |
| ... | @@ -5856,16 +6091,16 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -5856,16 +6091,16 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5856 | "tmp.zig:3:11: error: use of undefined value here causes undefined behavior", | 6091 | "tmp.zig:3:11: error: use of undefined value here causes undefined behavior", |
| 5857 | }); | 6092 | }); |
| 5858 | | 6093 | |
| 5859 | cases.add("catch on undefined value", | 6094 | ctx.objErrStage1("catch on undefined value", |
| 5860 | \\comptime { | 6095 | \\comptime { |
| 5861 | \\ var a: anyerror!bool = undefined; | 6096 | \\ var a: anyerror!bool = undefined; |
| 5862 | \\ _ = a catch |err| false; | 6097 | \\ _ = a catch false; |
| 5863 | \\} | 6098 | \\} |
| 5864 | , &[_][]const u8{ | 6099 | , &[_][]const u8{ |
| 5865 | "tmp.zig:3:11: error: use of undefined value here causes undefined behavior", | 6100 | "tmp.zig:3:11: error: use of undefined value here causes undefined behavior", |
| 5866 | }); | 6101 | }); |
| 5867 | | 6102 | |
| 5868 | cases.add("deref on undefined value", | 6103 | ctx.objErrStage1("deref on undefined value", |
| 5869 | \\comptime { | 6104 | \\comptime { |
| 5870 | \\ var a: *u8 = undefined; | 6105 | \\ var a: *u8 = undefined; |
| 5871 | \\ _ = a.*; | 6106 | \\ _ = a.*; |
| ... | @@ -5874,7 +6109,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -5874,7 +6109,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5874 | "tmp.zig:3:9: error: attempt to dereference undefined value", | 6109 | "tmp.zig:3:9: error: attempt to dereference undefined value", |
| 5875 | }); | 6110 | }); |
| 5876 | | 6111 | |
| 5877 | cases.add("endless loop in function evaluation", | 6112 | ctx.objErrStage1("endless loop in function evaluation", |
| 5878 | \\const seventh_fib_number = fibbonaci(7); | 6113 | \\const seventh_fib_number = fibbonaci(7); |
| 5879 | \\fn fibbonaci(x: i32) i32 { | 6114 | \\fn fibbonaci(x: i32) i32 { |
| 5880 | \\ return fibbonaci(x - 1) + fibbonaci(x - 2); | 6115 | \\ return fibbonaci(x - 1) + fibbonaci(x - 2); |
| ... | @@ -5887,16 +6122,15 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -5887,16 +6122,15 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5887 | "tmp.zig:6:50: note: referenced here", | 6122 | "tmp.zig:6:50: note: referenced here", |
| 5888 | }); | 6123 | }); |
| 5889 | | 6124 | |
| 5890 | cases.add("@embedFile with bogus file", | 6125 | ctx.objErrStage1("@embedFile with bogus file", |
| 5891 | \\const resource = @embedFile("bogus.txt",); | 6126 | \\const resource = @embedFile("bogus.txt",); |
| 5892 | \\ | 6127 | \\ |
| 5893 | \\export fn entry() usize { return @sizeOf(@TypeOf(resource)); } | 6128 | \\export fn entry() usize { return @sizeOf(@TypeOf(resource)); } |
| 5894 | , &[_][]const u8{ | 6129 | , &[_][]const u8{ |
| 5895 | "tmp.zig:1:29: error: unable to find '", | 6130 | "tmp.zig:1:29: error: unable to find '", |
| 5896 | "bogus.txt'", | | |
| 5897 | }); | 6131 | }); |
| 5898 | | 6132 | |
| 5899 | cases.add("non-const expression in struct literal outside function", | 6133 | ctx.objErrStage1("non-const expression in struct literal outside function", |
| 5900 | \\const Foo = struct { | 6134 | \\const Foo = struct { |
| 5901 | \\ x: i32, | 6135 | \\ x: i32, |
| 5902 | \\}; | 6136 | \\}; |
| ... | @@ -5908,7 +6142,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -5908,7 +6142,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5908 | "tmp.zig:4:21: error: unable to evaluate constant expression", | 6142 | "tmp.zig:4:21: error: unable to evaluate constant expression", |
| 5909 | }); | 6143 | }); |
| 5910 | | 6144 | |
| 5911 | cases.add("non-const expression function call with struct return value outside function", | 6145 | ctx.objErrStage1("non-const expression function call with struct return value outside function", |
| 5912 | \\const Foo = struct { | 6146 | \\const Foo = struct { |
| 5913 | \\ x: i32, | 6147 | \\ x: i32, |
| 5914 | \\}; | 6148 | \\}; |
| ... | @@ -5925,7 +6159,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -5925,7 +6159,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5925 | "tmp.zig:4:17: note: referenced here", | 6159 | "tmp.zig:4:17: note: referenced here", |
| 5926 | }); | 6160 | }); |
| 5927 | | 6161 | |
| 5928 | cases.add("undeclared identifier error should mark fn as impure", | 6162 | ctx.objErrStage1("undeclared identifier error should mark fn as impure", |
| 5929 | \\export fn foo() void { | 6163 | \\export fn foo() void { |
| 5930 | \\ test_a_thing(); | 6164 | \\ test_a_thing(); |
| 5931 | \\} | 6165 | \\} |
| ... | @@ -5936,7 +6170,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -5936,7 +6170,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5936 | "tmp.zig:5:5: error: use of undeclared identifier 'bad_fn_call'", | 6170 | "tmp.zig:5:5: error: use of undeclared identifier 'bad_fn_call'", |
| 5937 | }); | 6171 | }); |
| 5938 | | 6172 | |
| 5939 | cases.add("illegal comparison of types", | 6173 | ctx.objErrStage1("illegal comparison of types", |
| 5940 | \\fn bad_eql_1(a: []u8, b: []u8) bool { | 6174 | \\fn bad_eql_1(a: []u8, b: []u8) bool { |
| 5941 | \\ return a == b; | 6175 | \\ return a == b; |
| 5942 | \\} | 6176 | \\} |
| ... | @@ -5955,13 +6189,14 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -5955,13 +6189,14 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5955 | "tmp.zig:9:16: error: operator not allowed for type 'EnumWithData'", | 6189 | "tmp.zig:9:16: error: operator not allowed for type 'EnumWithData'", |
| 5956 | }); | 6190 | }); |
| 5957 | | 6191 | |
| 5958 | cases.add("non-const switch number literal", | 6192 | ctx.objErrStage1("non-const switch number literal", |
| 5959 | \\export fn foo() void { | 6193 | \\export fn foo() void { |
| 5960 | \\ const x = switch (bar()) { | 6194 | \\ const x = switch (bar()) { |
| 5961 | \\ 1, 2 => 1, | 6195 | \\ 1, 2 => 1, |
| 5962 | \\ 3, 4 => 2, | 6196 | \\ 3, 4 => 2, |
| 5963 | \\ else => 3, | 6197 | \\ else => 3, |
| 5964 | \\ }; | 6198 | \\ }; |
| | 6199 | \\ _ = x; |
| 5965 | \\} | 6200 | \\} |
| 5966 | \\fn bar() i32 { | 6201 | \\fn bar() i32 { |
| 5967 | \\ return 2; | 6202 | \\ return 2; |
| ... | @@ -5970,7 +6205,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -5970,7 +6205,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5970 | "tmp.zig:5:17: error: cannot store runtime value in type 'comptime_int'", | 6205 | "tmp.zig:5:17: error: cannot store runtime value in type 'comptime_int'", |
| 5971 | }); | 6206 | }); |
| 5972 | | 6207 | |
| 5973 | cases.add("atomic orderings of cmpxchg - failure stricter than success", | 6208 | ctx.objErrStage1("atomic orderings of cmpxchg - failure stricter than success", |
| 5974 | \\const AtomicOrder = @import("std").builtin.AtomicOrder; | 6209 | \\const AtomicOrder = @import("std").builtin.AtomicOrder; |
| 5975 | \\export fn f() void { | 6210 | \\export fn f() void { |
| 5976 | \\ var x: i32 = 1234; | 6211 | \\ var x: i32 = 1234; |
| ... | @@ -5980,7 +6215,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -5980,7 +6215,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5980 | "tmp.zig:4:81: error: failure atomic ordering must be no stricter than success", | 6215 | "tmp.zig:4:81: error: failure atomic ordering must be no stricter than success", |
| 5981 | }); | 6216 | }); |
| 5982 | | 6217 | |
| 5983 | cases.add("atomic orderings of cmpxchg - success Monotonic or stricter", | 6218 | ctx.objErrStage1("atomic orderings of cmpxchg - success Monotonic or stricter", |
| 5984 | \\const AtomicOrder = @import("std").builtin.AtomicOrder; | 6219 | \\const AtomicOrder = @import("std").builtin.AtomicOrder; |
| 5985 | \\export fn f() void { | 6220 | \\export fn f() void { |
| 5986 | \\ var x: i32 = 1234; | 6221 | \\ var x: i32 = 1234; |
| ... | @@ -5990,7 +6225,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -5990,7 +6225,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5990 | "tmp.zig:4:58: error: success atomic ordering must be Monotonic or stricter", | 6225 | "tmp.zig:4:58: error: success atomic ordering must be Monotonic or stricter", |
| 5991 | }); | 6226 | }); |
| 5992 | | 6227 | |
| 5993 | cases.add("negation overflow in function evaluation", | 6228 | ctx.objErrStage1("negation overflow in function evaluation", |
| 5994 | \\const y = neg(-128); | 6229 | \\const y = neg(-128); |
| 5995 | \\fn neg(x: i8) i8 { | 6230 | \\fn neg(x: i8) i8 { |
| 5996 | \\ return -x; | 6231 | \\ return -x; |
| ... | @@ -6002,7 +6237,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -6002,7 +6237,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6002 | "tmp.zig:1:14: note: referenced here", | 6237 | "tmp.zig:1:14: note: referenced here", |
| 6003 | }); | 6238 | }); |
| 6004 | | 6239 | |
| 6005 | cases.add("add overflow in function evaluation", | 6240 | ctx.objErrStage1("add overflow in function evaluation", |
| 6006 | \\const y = add(65530, 10); | 6241 | \\const y = add(65530, 10); |
| 6007 | \\fn add(a: u16, b: u16) u16 { | 6242 | \\fn add(a: u16, b: u16) u16 { |
| 6008 | \\ return a + b; | 6243 | \\ return a + b; |
| ... | @@ -6014,7 +6249,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -6014,7 +6249,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6014 | "tmp.zig:1:14: note: referenced here", | 6249 | "tmp.zig:1:14: note: referenced here", |
| 6015 | }); | 6250 | }); |
| 6016 | | 6251 | |
| 6017 | cases.add("sub overflow in function evaluation", | 6252 | ctx.objErrStage1("sub overflow in function evaluation", |
| 6018 | \\const y = sub(10, 20); | 6253 | \\const y = sub(10, 20); |
| 6019 | \\fn sub(a: u16, b: u16) u16 { | 6254 | \\fn sub(a: u16, b: u16) u16 { |
| 6020 | \\ return a - b; | 6255 | \\ return a - b; |
| ... | @@ -6026,7 +6261,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -6026,7 +6261,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6026 | "tmp.zig:1:14: note: referenced here", | 6261 | "tmp.zig:1:14: note: referenced here", |
| 6027 | }); | 6262 | }); |
| 6028 | | 6263 | |
| 6029 | cases.add("mul overflow in function evaluation", | 6264 | ctx.objErrStage1("mul overflow in function evaluation", |
| 6030 | \\const y = mul(300, 6000); | 6265 | \\const y = mul(300, 6000); |
| 6031 | \\fn mul(a: u16, b: u16) u16 { | 6266 | \\fn mul(a: u16, b: u16) u16 { |
| 6032 | \\ return a * b; | 6267 | \\ return a * b; |
| ... | @@ -6038,7 +6273,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -6038,7 +6273,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6038 | "tmp.zig:1:14: note: referenced here", | 6273 | "tmp.zig:1:14: note: referenced here", |
| 6039 | }); | 6274 | }); |
| 6040 | | 6275 | |
| 6041 | cases.add("truncate sign mismatch", | 6276 | ctx.objErrStage1("truncate sign mismatch", |
| 6042 | \\export fn entry1() i8 { | 6277 | \\export fn entry1() i8 { |
| 6043 | \\ var x: u32 = 10; | 6278 | \\ var x: u32 = 10; |
| 6044 | \\ return @truncate(i8, x); | 6279 | \\ return @truncate(i8, x); |
| ... | @@ -6062,7 +6297,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -6062,7 +6297,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6062 | "tmp.zig:15:26: error: expected unsigned integer type, found 'i32'", | 6297 | "tmp.zig:15:26: error: expected unsigned integer type, found 'i32'", |
| 6063 | }); | 6298 | }); |
| 6064 | | 6299 | |
| 6065 | cases.add("try in function with non error return type", | 6300 | ctx.objErrStage1("try in function with non error return type", |
| 6066 | \\export fn f() void { | 6301 | \\export fn f() void { |
| 6067 | \\ try something(); | 6302 | \\ try something(); |
| 6068 | \\} | 6303 | \\} |
| ... | @@ -6071,7 +6306,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -6071,7 +6306,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6071 | "tmp.zig:2:5: error: expected type 'void', found 'anyerror'", | 6306 | "tmp.zig:2:5: error: expected type 'void', found 'anyerror'", |
| 6072 | }); | 6307 | }); |
| 6073 | | 6308 | |
| 6074 | cases.add("invalid pointer for var type", | 6309 | ctx.objErrStage1("invalid pointer for var type", |
| 6075 | \\extern fn ext() usize; | 6310 | \\extern fn ext() usize; |
| 6076 | \\var bytes: [ext()]u8 = undefined; | 6311 | \\var bytes: [ext()]u8 = undefined; |
| 6077 | \\export fn f() void { | 6312 | \\export fn f() void { |
| ... | @@ -6083,7 +6318,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -6083,7 +6318,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6083 | "tmp.zig:2:13: error: unable to evaluate constant expression", | 6318 | "tmp.zig:2:13: error: unable to evaluate constant expression", |
| 6084 | }); | 6319 | }); |
| 6085 | | 6320 | |
| 6086 | cases.add("export function with comptime parameter", | 6321 | ctx.objErrStage1("export function with comptime parameter", |
| 6087 | \\export fn foo(comptime x: i32, y: i32) i32{ | 6322 | \\export fn foo(comptime x: i32, y: i32) i32{ |
| 6088 | \\ return x + y; | 6323 | \\ return x + y; |
| 6089 | \\} | 6324 | \\} |
| ... | @@ -6091,7 +6326,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -6091,7 +6326,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6091 | "tmp.zig:1:15: error: comptime parameter not allowed in function with calling convention 'C'", | 6326 | "tmp.zig:1:15: error: comptime parameter not allowed in function with calling convention 'C'", |
| 6092 | }); | 6327 | }); |
| 6093 | | 6328 | |
| 6094 | cases.add("extern function with comptime parameter", | 6329 | ctx.objErrStage1("extern function with comptime parameter", |
| 6095 | \\extern fn foo(comptime x: i32, y: i32) i32; | 6330 | \\extern fn foo(comptime x: i32, y: i32) i32; |
| 6096 | \\fn f() i32 { | 6331 | \\fn f() i32 { |
| 6097 | \\ return foo(1, 2); | 6332 | \\ return foo(1, 2); |
| ... | @@ -6101,7 +6336,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -6101,7 +6336,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6101 | "tmp.zig:1:15: error: comptime parameter not allowed in function with calling convention 'C'", | 6336 | "tmp.zig:1:15: error: comptime parameter not allowed in function with calling convention 'C'", |
| 6102 | }); | 6337 | }); |
| 6103 | | 6338 | |
| 6104 | cases.add("non-pure function returns type", | 6339 | ctx.objErrStage1("non-pure function returns type", |
| 6105 | \\var a: u32 = 0; | 6340 | \\var a: u32 = 0; |
| 6106 | \\pub fn List(comptime T: type) type { | 6341 | \\pub fn List(comptime T: type) type { |
| 6107 | \\ a += 1; | 6342 | \\ a += 1; |
| ... | @@ -6125,7 +6360,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -6125,7 +6360,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6125 | "tmp.zig:16:19: note: referenced here", | 6360 | "tmp.zig:16:19: note: referenced here", |
| 6126 | }); | 6361 | }); |
| 6127 | | 6362 | |
| 6128 | cases.add("bogus method call on slice", | 6363 | ctx.objErrStage1("bogus method call on slice", |
| 6129 | \\var self = "aoeu"; | 6364 | \\var self = "aoeu"; |
| 6130 | \\fn f(m: []const u8) void { | 6365 | \\fn f(m: []const u8) void { |
| 6131 | \\ m.copy(u8, self[0..], m); | 6366 | \\ m.copy(u8, self[0..], m); |
| ... | @@ -6135,9 +6370,9 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -6135,9 +6370,9 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6135 | "tmp.zig:3:6: error: no member named 'copy' in '[]const u8'", | 6370 | "tmp.zig:3:6: error: no member named 'copy' in '[]const u8'", |
| 6136 | }); | 6371 | }); |
| 6137 | | 6372 | |
| 6138 | cases.add("wrong number of arguments for method fn call", | 6373 | ctx.objErrStage1("wrong number of arguments for method fn call", |
| 6139 | \\const Foo = struct { | 6374 | \\const Foo = struct { |
| 6140 | \\ fn method(self: *const Foo, a: i32) void {} | 6375 | \\ fn method(self: *const Foo, a: i32) void {_ = self; _ = a;} |
| 6141 | \\}; | 6376 | \\}; |
| 6142 | \\fn f(foo: *const Foo) void { | 6377 | \\fn f(foo: *const Foo) void { |
| 6143 | \\ | 6378 | \\ |
| ... | @@ -6148,7 +6383,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -6148,7 +6383,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6148 | "tmp.zig:6:15: error: expected 2 argument(s), found 3", | 6383 | "tmp.zig:6:15: error: expected 2 argument(s), found 3", |
| 6149 | }); | 6384 | }); |
| 6150 | | 6385 | |
| 6151 | cases.add("assign through constant pointer", | 6386 | ctx.objErrStage1("assign through constant pointer", |
| 6152 | \\export fn f() void { | 6387 | \\export fn f() void { |
| 6153 | \\ var cstr = "Hat"; | 6388 | \\ var cstr = "Hat"; |
| 6154 | \\ cstr[0] = 'W'; | 6389 | \\ cstr[0] = 'W'; |
| ... | @@ -6157,7 +6392,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -6157,7 +6392,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6157 | "tmp.zig:3:13: error: cannot assign to constant", | 6392 | "tmp.zig:3:13: error: cannot assign to constant", |
| 6158 | }); | 6393 | }); |
| 6159 | | 6394 | |
| 6160 | cases.add("assign through constant slice", | 6395 | ctx.objErrStage1("assign through constant slice", |
| 6161 | \\export fn f() void { | 6396 | \\export fn f() void { |
| 6162 | \\ var cstr: []const u8 = "Hat"; | 6397 | \\ var cstr: []const u8 = "Hat"; |
| 6163 | \\ cstr[0] = 'W'; | 6398 | \\ cstr[0] = 'W'; |
| ... | @@ -6166,13 +6401,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -6166,13 +6401,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6166 | "tmp.zig:3:13: error: cannot assign to constant", | 6401 | "tmp.zig:3:13: error: cannot assign to constant", |
| 6167 | }); | 6402 | }); |
| 6168 | | 6403 | |
| 6169 | cases.add("main function with bogus args type", | 6404 | ctx.objErrStage1("main function with bogus args type", |
| 6170 | \\pub fn main(args: [][]bogus) !void {} | 6405 | \\pub fn main(args: [][]bogus) !void {_ = args;} |
| 6171 | , &[_][]const u8{ | 6406 | , &[_][]const u8{ |
| 6172 | "tmp.zig:1:23: error: use of undeclared identifier 'bogus'", | 6407 | "tmp.zig:1:23: error: use of undeclared identifier 'bogus'", |
| 6173 | }); | 6408 | }); |
| 6174 | | 6409 | |
| 6175 | cases.add("misspelled type with pointer only reference", | 6410 | ctx.objErrStage1("misspelled type with pointer only reference", |
| 6176 | \\const JasonHM = u8; | 6411 | \\const JasonHM = u8; |
| 6177 | \\const JasonList = *JsonNode; | 6412 | \\const JasonList = *JsonNode; |
| 6178 | \\ | 6413 | \\ |
| ... | @@ -6200,6 +6435,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -6200,6 +6435,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6200 | \\ var jll: JasonList = undefined; | 6435 | \\ var jll: JasonList = undefined; |
| 6201 | \\ jll.init(1234); | 6436 | \\ jll.init(1234); |
| 6202 | \\ var jd = JsonNode {.kind = JsonType.JSONArray , .jobject = JsonOA.JSONArray {jll} }; | 6437 | \\ var jd = JsonNode {.kind = JsonType.JSONArray , .jobject = JsonOA.JSONArray {jll} }; |
| | 6438 | \\ _ = jd; |
| 6203 | \\} | 6439 | \\} |
| 6204 | \\ | 6440 | \\ |
| 6205 | \\export fn entry() usize { return @sizeOf(@TypeOf(foo)); } | 6441 | \\export fn entry() usize { return @sizeOf(@TypeOf(foo)); } |
| ... | @@ -6207,7 +6443,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -6207,7 +6443,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6207 | "tmp.zig:5:16: error: use of undeclared identifier 'JsonList'", | 6443 | "tmp.zig:5:16: error: use of undeclared identifier 'JsonList'", |
| 6208 | }); | 6444 | }); |
| 6209 | | 6445 | |
| 6210 | cases.add("method call with first arg type primitive", | 6446 | ctx.objErrStage1("method call with first arg type primitive", |
| 6211 | \\const Foo = struct { | 6447 | \\const Foo = struct { |
| 6212 | \\ x: i32, | 6448 | \\ x: i32, |
| 6213 | \\ | 6449 | \\ |
| ... | @@ -6227,7 +6463,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -6227,7 +6463,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6227 | "tmp.zig:14:5: error: expected type 'i32', found 'Foo'", | 6463 | "tmp.zig:14:5: error: expected type 'i32', found 'Foo'", |
| 6228 | }); | 6464 | }); |
| 6229 | | 6465 | |
| 6230 | cases.add("method call with first arg type wrong container", | 6466 | ctx.objErrStage1("method call with first arg type wrong container", |
| 6231 | \\pub const List = struct { | 6467 | \\pub const List = struct { |
| 6232 | \\ len: usize, | 6468 | \\ len: usize, |
| 6233 | \\ allocator: *Allocator, | 6469 | \\ allocator: *Allocator, |
| ... | @@ -6256,7 +6492,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -6256,7 +6492,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6256 | "tmp.zig:23:5: error: expected type '*Allocator', found '*List'", | 6492 | "tmp.zig:23:5: error: expected type '*Allocator', found '*List'", |
| 6257 | }); | 6493 | }); |
| 6258 | | 6494 | |
| 6259 | cases.add("binary not on number literal", | 6495 | ctx.objErrStage1("binary not on number literal", |
| 6260 | \\const TINY_QUANTUM_SHIFT = 4; | 6496 | \\const TINY_QUANTUM_SHIFT = 4; |
| 6261 | \\const TINY_QUANTUM_SIZE = 1 << TINY_QUANTUM_SHIFT; | 6497 | \\const TINY_QUANTUM_SIZE = 1 << TINY_QUANTUM_SHIFT; |
| 6262 | \\var block_aligned_stuff: usize = (4 + TINY_QUANTUM_SIZE) & ~(TINY_QUANTUM_SIZE - 1); | 6498 | \\var block_aligned_stuff: usize = (4 + TINY_QUANTUM_SIZE) & ~(TINY_QUANTUM_SIZE - 1); |
| ... | @@ -6266,8 +6502,15 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -6266,8 +6502,15 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6266 | "tmp.zig:3:60: error: unable to perform binary not operation on type 'comptime_int'", | 6502 | "tmp.zig:3:60: error: unable to perform binary not operation on type 'comptime_int'", |
| 6267 | }); | 6503 | }); |
| 6268 | | 6504 | |
| 6269 | cases.addCase(x: { | 6505 | { |
| 6270 | const tc = cases.create("multiple files with private function error", | 6506 | const case = ctx.obj("multiple files with private function error", .{}); |
| | 6507 | case.backend = .stage1; |
| | 6508 | |
| | 6509 | case.addSourceFile("foo.zig", |
| | 6510 | \\fn privateFunction() void { } |
| | 6511 | ); |
| | 6512 | |
| | 6513 | case.addError( |
| 6271 | \\const foo = @import("foo.zig",); | 6514 | \\const foo = @import("foo.zig",); |
| 6272 | \\ | 6515 | \\ |
| 6273 | \\export fn callPrivFunction() void { | 6516 | \\export fn callPrivFunction() void { |
| ... | @@ -6277,16 +6520,19 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -6277,16 +6520,19 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6277 | "tmp.zig:4:8: error: 'privateFunction' is private", | 6520 | "tmp.zig:4:8: error: 'privateFunction' is private", |
| 6278 | "foo.zig:1:1: note: declared here", | 6521 | "foo.zig:1:1: note: declared here", |
| 6279 | }); | 6522 | }); |
| | 6523 | } |
| 6280 | | 6524 | |
| 6281 | tc.addSourceFile("foo.zig", | 6525 | { |
| 6282 | \\fn privateFunction() void { } | 6526 | const case = ctx.obj("multiple files with private member instance function (canonical invocation) error", .{}); |
| 6283 | ); | 6527 | case.backend = .stage1; |
| 6284 | | 6528 | |
| 6285 | break :x tc; | 6529 | case.addSourceFile("foo.zig", |
| 6286 | }); | 6530 | \\pub const Foo = struct { |
| | 6531 | \\ fn privateFunction(self: *Foo) void { _ = self; } |
| | 6532 | \\}; |
| | 6533 | ); |
| 6287 | | 6534 | |
| 6288 | cases.addCase(x: { | 6535 | case.addError( |
| 6289 | const tc = cases.create("multiple files with private member instance function (canonical invocation) error", | | |
| 6290 | \\const Foo = @import("foo.zig",).Foo; | 6536 | \\const Foo = @import("foo.zig",).Foo; |
| 6291 | \\ | 6537 | \\ |
| 6292 | \\export fn callPrivFunction() void { | 6538 | \\export fn callPrivFunction() void { |
| ... | @@ -6297,18 +6543,19 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -6297,18 +6543,19 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6297 | "tmp.zig:5:8: error: 'privateFunction' is private", | 6543 | "tmp.zig:5:8: error: 'privateFunction' is private", |
| 6298 | "foo.zig:2:5: note: declared here", | 6544 | "foo.zig:2:5: note: declared here", |
| 6299 | }); | 6545 | }); |
| | 6546 | } |
| | 6547 | |
| | 6548 | { |
| | 6549 | const case = ctx.obj("multiple files with private member instance function error", .{}); |
| | 6550 | case.backend = .stage1; |
| 6300 | | 6551 | |
| 6301 | tc.addSourceFile("foo.zig", | 6552 | case.addSourceFile("foo.zig", |
| 6302 | \\pub const Foo = struct { | 6553 | \\pub const Foo = struct { |
| 6303 | \\ fn privateFunction(self: *Foo) void { } | 6554 | \\ fn privateFunction(self: *Foo) void { _ = self; } |
| 6304 | \\}; | 6555 | \\}; |
| 6305 | ); | 6556 | ); |
| 6306 | | 6557 | |
| 6307 | break :x tc; | 6558 | case.addError( |
| 6308 | }); | | |
| 6309 | | | |
| 6310 | cases.addCase(x: { | | |
| 6311 | const tc = cases.create("multiple files with private member instance function error", | | |
| 6312 | \\const Foo = @import("foo.zig",).Foo; | 6559 | \\const Foo = @import("foo.zig",).Foo; |
| 6313 | \\ | 6560 | \\ |
| 6314 | \\export fn callPrivFunction() void { | 6561 | \\export fn callPrivFunction() void { |
| ... | @@ -6319,17 +6566,9 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -6319,17 +6566,9 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6319 | "tmp.zig:5:8: error: 'privateFunction' is private", | 6566 | "tmp.zig:5:8: error: 'privateFunction' is private", |
| 6320 | "foo.zig:2:5: note: declared here", | 6567 | "foo.zig:2:5: note: declared here", |
| 6321 | }); | 6568 | }); |
| | 6569 | } |
| 6322 | | 6570 | |
| 6323 | tc.addSourceFile("foo.zig", | 6571 | ctx.objErrStage1("container init with non-type", |
| 6324 | \\pub const Foo = struct { | | |
| 6325 | \\ fn privateFunction(self: *Foo) void { } | | |
| 6326 | \\}; | | |
| 6327 | ); | | |
| 6328 | | | |
| 6329 | break :x tc; | | |
| 6330 | }); | | |
| 6331 | | | |
| 6332 | cases.add("container init with non-type", | | |
| 6333 | \\const zero: i32 = 0; | 6572 | \\const zero: i32 = 0; |
| 6334 | \\const a = zero{1}; | 6573 | \\const a = zero{1}; |
| 6335 | \\ | 6574 | \\ |
| ... | @@ -6338,7 +6577,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -6338,7 +6577,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6338 | "tmp.zig:2:11: error: expected type 'type', found 'i32'", | 6577 | "tmp.zig:2:11: error: expected type 'type', found 'i32'", |
| 6339 | }); | 6578 | }); |
| 6340 | | 6579 | |
| 6341 | cases.add("assign to constant field", | 6580 | ctx.objErrStage1("assign to constant field", |
| 6342 | \\const Foo = struct { | 6581 | \\const Foo = struct { |
| 6343 | \\ field: i32, | 6582 | \\ field: i32, |
| 6344 | \\}; | 6583 | \\}; |
| ... | @@ -6350,7 +6589,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -6350,7 +6589,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6350 | "tmp.zig:6:15: error: cannot assign to constant", | 6589 | "tmp.zig:6:15: error: cannot assign to constant", |
| 6351 | }); | 6590 | }); |
| 6352 | | 6591 | |
| 6353 | cases.add("return from defer expression", | 6592 | ctx.objErrStage1("return from defer expression", |
| 6354 | \\pub fn testTrickyDefer() !void { | 6593 | \\pub fn testTrickyDefer() !void { |
| 6355 | \\ defer canFail() catch {}; | 6594 | \\ defer canFail() catch {}; |
| 6356 | \\ | 6595 | \\ |
| ... | @@ -6367,32 +6606,33 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -6367,32 +6606,33 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6367 | \\ | 6606 | \\ |
| 6368 | \\export fn entry() usize { return @sizeOf(@TypeOf(testTrickyDefer)); } | 6607 | \\export fn entry() usize { return @sizeOf(@TypeOf(testTrickyDefer)); } |
| 6369 | , &[_][]const u8{ | 6608 | , &[_][]const u8{ |
| 6370 | "tmp.zig:4:11: error: cannot return from defer expression", | 6609 | "tmp.zig:4:11: error: 'try' not allowed inside defer expression", |
| 6371 | }); | 6610 | }); |
| 6372 | | 6611 | |
| 6373 | cases.add("assign too big number to u16", | 6612 | ctx.objErrStage1("assign too big number to u16", |
| 6374 | \\export fn foo() void { | 6613 | \\export fn foo() void { |
| 6375 | \\ var vga_mem: u16 = 0xB8000; | 6614 | \\ var vga_mem: u16 = 0xB8000; |
| | 6615 | \\ _ = vga_mem; |
| 6376 | \\} | 6616 | \\} |
| 6377 | , &[_][]const u8{ | 6617 | , &[_][]const u8{ |
| 6378 | "tmp.zig:2:24: error: integer value 753664 cannot be coerced to type 'u16'", | 6618 | "tmp.zig:2:24: error: integer value 753664 cannot be coerced to type 'u16'", |
| 6379 | }); | 6619 | }); |
| 6380 | | 6620 | |
| 6381 | cases.add("global variable alignment non power of 2", | 6621 | ctx.objErrStage1("global variable alignment non power of 2", |
| 6382 | \\const some_data: [100]u8 align(3) = undefined; | 6622 | \\const some_data: [100]u8 align(3) = undefined; |
| 6383 | \\export fn entry() usize { return @sizeOf(@TypeOf(some_data)); } | 6623 | \\export fn entry() usize { return @sizeOf(@TypeOf(some_data)); } |
| 6384 | , &[_][]const u8{ | 6624 | , &[_][]const u8{ |
| 6385 | "tmp.zig:1:32: error: alignment value 3 is not a power of 2", | 6625 | "tmp.zig:1:32: error: alignment value 3 is not a power of 2", |
| 6386 | }); | 6626 | }); |
| 6387 | | 6627 | |
| 6388 | cases.add("function alignment non power of 2", | 6628 | ctx.objErrStage1("function alignment non power of 2", |
| 6389 | \\extern fn foo() align(3) void; | 6629 | \\extern fn foo() align(3) void; |
| 6390 | \\export fn entry() void { return foo(); } | 6630 | \\export fn entry() void { return foo(); } |
| 6391 | , &[_][]const u8{ | 6631 | , &[_][]const u8{ |
| 6392 | "tmp.zig:1:23: error: alignment value 3 is not a power of 2", | 6632 | "tmp.zig:1:23: error: alignment value 3 is not a power of 2", |
| 6393 | }); | 6633 | }); |
| 6394 | | 6634 | |
| 6395 | cases.add("compile log", | 6635 | ctx.objErrStage1("compile log", |
| 6396 | \\export fn foo() void { | 6636 | \\export fn foo() void { |
| 6397 | \\ comptime bar(12, "hi",); | 6637 | \\ comptime bar(12, "hi",); |
| 6398 | \\} | 6638 | \\} |
| ... | @@ -6407,7 +6647,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -6407,7 +6647,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6407 | "tmp.zig:7:5: error: found compile log statement", | 6647 | "tmp.zig:7:5: error: found compile log statement", |
| 6408 | }); | 6648 | }); |
| 6409 | | 6649 | |
| 6410 | cases.add("casting bit offset pointer to regular pointer", | 6650 | ctx.objErrStage1("casting bit offset pointer to regular pointer", |
| 6411 | \\const BitField = packed struct { | 6651 | \\const BitField = packed struct { |
| 6412 | \\ a: u3, | 6652 | \\ a: u3, |
| 6413 | \\ b: u3, | 6653 | \\ b: u3, |
| ... | @@ -6427,7 +6667,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -6427,7 +6667,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6427 | "tmp.zig:8:26: error: expected type '*const u3', found '*align(:3:1) const u3'", | 6667 | "tmp.zig:8:26: error: expected type '*const u3', found '*align(:3:1) const u3'", |
| 6428 | }); | 6668 | }); |
| 6429 | | 6669 | |
| 6430 | cases.add("referring to a struct that is invalid", | 6670 | ctx.objErrStage1("referring to a struct that is invalid", |
| 6431 | \\const UsbDeviceRequest = struct { | 6671 | \\const UsbDeviceRequest = struct { |
| 6432 | \\ Type: u8, | 6672 | \\ Type: u8, |
| 6433 | \\}; | 6673 | \\}; |
| ... | @@ -6444,7 +6684,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -6444,7 +6684,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6444 | "tmp.zig:6:20: note: referenced here", | 6684 | "tmp.zig:6:20: note: referenced here", |
| 6445 | }); | 6685 | }); |
| 6446 | | 6686 | |
| 6447 | cases.add("control flow uses comptime var at runtime", | 6687 | ctx.objErrStage1("control flow uses comptime var at runtime", |
| 6448 | \\export fn foo() void { | 6688 | \\export fn foo() void { |
| 6449 | \\ comptime var i = 0; | 6689 | \\ comptime var i = 0; |
| 6450 | \\ while (i < 5) : (i += 1) { | 6690 | \\ while (i < 5) : (i += 1) { |
| ... | @@ -6458,7 +6698,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -6458,7 +6698,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6458 | "tmp.zig:3:24: note: compile-time variable assigned here", | 6698 | "tmp.zig:3:24: note: compile-time variable assigned here", |
| 6459 | }); | 6699 | }); |
| 6460 | | 6700 | |
| 6461 | cases.add("ignored return value", | 6701 | ctx.objErrStage1("ignored return value", |
| 6462 | \\export fn foo() void { | 6702 | \\export fn foo() void { |
| 6463 | \\ bar(); | 6703 | \\ bar(); |
| 6464 | \\} | 6704 | \\} |
| ... | @@ -6467,7 +6707,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -6467,7 +6707,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6467 | "tmp.zig:2:8: error: expression value is ignored", | 6707 | "tmp.zig:2:8: error: expression value is ignored", |
| 6468 | }); | 6708 | }); |
| 6469 | | 6709 | |
| 6470 | cases.add("ignored assert-err-ok return value", | 6710 | ctx.objErrStage1("ignored assert-err-ok return value", |
| 6471 | \\export fn foo() void { | 6711 | \\export fn foo() void { |
| 6472 | \\ bar() catch unreachable; | 6712 | \\ bar() catch unreachable; |
| 6473 | \\} | 6713 | \\} |
| ... | @@ -6476,7 +6716,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -6476,7 +6716,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6476 | "tmp.zig:2:11: error: expression value is ignored", | 6716 | "tmp.zig:2:11: error: expression value is ignored", |
| 6477 | }); | 6717 | }); |
| 6478 | | 6718 | |
| 6479 | cases.add("ignored statement value", | 6719 | ctx.objErrStage1("ignored statement value", |
| 6480 | \\export fn foo() void { | 6720 | \\export fn foo() void { |
| 6481 | \\ 1; | 6721 | \\ 1; |
| 6482 | \\} | 6722 | \\} |
| ... | @@ -6484,7 +6724,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -6484,7 +6724,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6484 | "tmp.zig:2:5: error: expression value is ignored", | 6724 | "tmp.zig:2:5: error: expression value is ignored", |
| 6485 | }); | 6725 | }); |
| 6486 | | 6726 | |
| 6487 | cases.add("ignored comptime statement value", | 6727 | ctx.objErrStage1("ignored comptime statement value", |
| 6488 | \\export fn foo() void { | 6728 | \\export fn foo() void { |
| 6489 | \\ comptime {1;} | 6729 | \\ comptime {1;} |
| 6490 | \\} | 6730 | \\} |
| ... | @@ -6492,7 +6732,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -6492,7 +6732,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6492 | "tmp.zig:2:15: error: expression value is ignored", | 6732 | "tmp.zig:2:15: error: expression value is ignored", |
| 6493 | }); | 6733 | }); |
| 6494 | | 6734 | |
| 6495 | cases.add("ignored comptime value", | 6735 | ctx.objErrStage1("ignored comptime value", |
| 6496 | \\export fn foo() void { | 6736 | \\export fn foo() void { |
| 6497 | \\ comptime 1; | 6737 | \\ comptime 1; |
| 6498 | \\} | 6738 | \\} |
| ... | @@ -6500,7 +6740,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -6500,7 +6740,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6500 | "tmp.zig:2:5: error: expression value is ignored", | 6740 | "tmp.zig:2:5: error: expression value is ignored", |
| 6501 | }); | 6741 | }); |
| 6502 | | 6742 | |
| 6503 | cases.add("ignored defered statement value", | 6743 | ctx.objErrStage1("ignored defered statement value", |
| 6504 | \\export fn foo() void { | 6744 | \\export fn foo() void { |
| 6505 | \\ defer {1;} | 6745 | \\ defer {1;} |
| 6506 | \\} | 6746 | \\} |
| ... | @@ -6508,7 +6748,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -6508,7 +6748,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6508 | "tmp.zig:2:12: error: expression value is ignored", | 6748 | "tmp.zig:2:12: error: expression value is ignored", |
| 6509 | }); | 6749 | }); |
| 6510 | | 6750 | |
| 6511 | cases.add("ignored defered function call", | 6751 | ctx.objErrStage1("ignored defered function call", |
| 6512 | \\export fn foo() void { | 6752 | \\export fn foo() void { |
| 6513 | \\ defer bar(); | 6753 | \\ defer bar(); |
| 6514 | \\} | 6754 | \\} |
| ... | @@ -6517,7 +6757,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -6517,7 +6757,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6517 | "tmp.zig:2:14: error: error is ignored. consider using `try`, `catch`, or `if`", | 6757 | "tmp.zig:2:14: error: error is ignored. consider using `try`, `catch`, or `if`", |
| 6518 | }); | 6758 | }); |
| 6519 | | 6759 | |
| 6520 | cases.add("dereference an array", | 6760 | ctx.objErrStage1("dereference an array", |
| 6521 | \\var s_buffer: [10]u8 = undefined; | 6761 | \\var s_buffer: [10]u8 = undefined; |
| 6522 | \\pub fn pass(in: []u8) []u8 { | 6762 | \\pub fn pass(in: []u8) []u8 { |
| 6523 | \\ var out = &s_buffer; | 6763 | \\ var out = &s_buffer; |
| ... | @@ -6530,13 +6770,14 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -6530,13 +6770,14 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6530 | "tmp.zig:4:10: error: attempt to dereference non-pointer type '[10]u8'", | 6770 | "tmp.zig:4:10: error: attempt to dereference non-pointer type '[10]u8'", |
| 6531 | }); | 6771 | }); |
| 6532 | | 6772 | |
| 6533 | cases.add("pass const ptr to mutable ptr fn", | 6773 | ctx.objErrStage1("pass const ptr to mutable ptr fn", |
| 6534 | \\fn foo() bool { | 6774 | \\fn foo() bool { |
| 6535 | \\ const a = @as([]const u8, "a",); | 6775 | \\ const a = @as([]const u8, "a",); |
| 6536 | \\ const b = &a; | 6776 | \\ const b = &a; |
| 6537 | \\ return ptrEql(b, b); | 6777 | \\ return ptrEql(b, b); |
| 6538 | \\} | 6778 | \\} |
| 6539 | \\fn ptrEql(a: *[]const u8, b: *[]const u8) bool { | 6779 | \\fn ptrEql(a: *[]const u8, b: *[]const u8) bool { |
| | 6780 | \\ _ = a; _ = b; |
| 6540 | \\ return true; | 6781 | \\ return true; |
| 6541 | \\} | 6782 | \\} |
| 6542 | \\ | 6783 | \\ |
| ... | @@ -6545,8 +6786,16 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -6545,8 +6786,16 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6545 | "tmp.zig:4:19: error: expected type '*[]const u8', found '*const []const u8'", | 6786 | "tmp.zig:4:19: error: expected type '*[]const u8', found '*const []const u8'", |
| 6546 | }); | 6787 | }); |
| 6547 | | 6788 | |
| 6548 | cases.addCase(x: { | 6789 | { |
| 6549 | const tc = cases.create("export collision", | 6790 | const case = ctx.obj("export collision", .{}); |
| | 6791 | case.backend = .stage1; |
| | 6792 | |
| | 6793 | case.addSourceFile("foo.zig", |
| | 6794 | \\export fn bar() void {} |
| | 6795 | \\pub const baz = 1234; |
| | 6796 | ); |
| | 6797 | |
| | 6798 | case.addError( |
| 6550 | \\const foo = @import("foo.zig",); | 6799 | \\const foo = @import("foo.zig",); |
| 6551 | \\ | 6800 | \\ |
| 6552 | \\export fn bar() usize { | 6801 | \\export fn bar() usize { |
| ... | @@ -6556,18 +6805,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -6556,18 +6805,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6556 | "foo.zig:1:1: error: exported symbol collision: 'bar'", | 6805 | "foo.zig:1:1: error: exported symbol collision: 'bar'", |
| 6557 | "tmp.zig:3:1: note: other symbol here", | 6806 | "tmp.zig:3:1: note: other symbol here", |
| 6558 | }); | 6807 | }); |
| | 6808 | } |
| 6559 | | 6809 | |
| 6560 | tc.addSourceFile("foo.zig", | 6810 | ctx.objErrStage1("implicit cast from array to mutable slice", |
| 6561 | \\export fn bar() void {} | | |
| 6562 | \\pub const baz = 1234; | | |
| 6563 | ); | | |
| 6564 | | | |
| 6565 | break :x tc; | | |
| 6566 | }); | | |
| 6567 | | | |
| 6568 | cases.add("implicit cast from array to mutable slice", | | |
| 6569 | \\var global_array: [10]i32 = undefined; | 6811 | \\var global_array: [10]i32 = undefined; |
| 6570 | \\fn foo(param: []i32) void {} | 6812 | \\fn foo(param: []i32) void {_ = param;} |
| 6571 | \\export fn entry() void { | 6813 | \\export fn entry() void { |
| 6572 | \\ foo(global_array); | 6814 | \\ foo(global_array); |
| 6573 | \\} | 6815 | \\} |
| ... | @@ -6575,7 +6817,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -6575,7 +6817,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6575 | "tmp.zig:4:9: error: expected type '[]i32', found '[10]i32'", | 6817 | "tmp.zig:4:9: error: expected type '[]i32', found '[10]i32'", |
| 6576 | }); | 6818 | }); |
| 6577 | | 6819 | |
| 6578 | cases.add("ptrcast to non-pointer", | 6820 | ctx.objErrStage1("ptrcast to non-pointer", |
| 6579 | \\export fn entry(a: *i32) usize { | 6821 | \\export fn entry(a: *i32) usize { |
| 6580 | \\ return @ptrCast(usize, a); | 6822 | \\ return @ptrCast(usize, a); |
| 6581 | \\} | 6823 | \\} |
| ... | @@ -6583,7 +6825,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -6583,7 +6825,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6583 | "tmp.zig:2:21: error: expected pointer, found 'usize'", | 6825 | "tmp.zig:2:21: error: expected pointer, found 'usize'", |
| 6584 | }); | 6826 | }); |
| 6585 | | 6827 | |
| 6586 | cases.add("asm at compile time", | 6828 | ctx.objErrStage1("asm at compile time", |
| 6587 | \\comptime { | 6829 | \\comptime { |
| 6588 | \\ doSomeAsm(); | 6830 | \\ doSomeAsm(); |
| 6589 | \\} | 6831 | \\} |
| ... | @@ -6599,25 +6841,27 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -6599,25 +6841,27 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6599 | "tmp.zig:6:5: error: unable to evaluate constant expression", | 6841 | "tmp.zig:6:5: error: unable to evaluate constant expression", |
| 6600 | }); | 6842 | }); |
| 6601 | | 6843 | |
| 6602 | cases.add("invalid member of builtin enum", | 6844 | ctx.objErrStage1("invalid member of builtin enum", |
| 6603 | \\const builtin = @import("std").builtin; | 6845 | \\const builtin = @import("std").builtin; |
| 6604 | \\export fn entry() void { | 6846 | \\export fn entry() void { |
| 6605 | \\ const foo = builtin.Mode.x86; | 6847 | \\ const foo = builtin.Mode.x86; |
| | 6848 | \\ _ = foo; |
| 6606 | \\} | 6849 | \\} |
| 6607 | , &[_][]const u8{ | 6850 | , &[_][]const u8{ |
| 6608 | "tmp.zig:3:29: error: container 'std.builtin.Mode' has no member called 'x86'", | 6851 | "tmp.zig:3:29: error: container 'std.builtin.Mode' has no member called 'x86'", |
| 6609 | }); | 6852 | }); |
| 6610 | | 6853 | |
| 6611 | cases.add("int to ptr of 0 bits", | 6854 | ctx.objErrStage1("int to ptr of 0 bits", |
| 6612 | \\export fn foo() void { | 6855 | \\export fn foo() void { |
| 6613 | \\ var x: usize = 0x1000; | 6856 | \\ var x: usize = 0x1000; |
| 6614 | \\ var y: *void = @intToPtr(*void, x); | 6857 | \\ var y: *void = @intToPtr(*void, x); |
| | 6858 | \\ _ = y; |
| 6615 | \\} | 6859 | \\} |
| 6616 | , &[_][]const u8{ | 6860 | , &[_][]const u8{ |
| 6617 | "tmp.zig:3:30: error: type '*void' has 0 bits and cannot store information", | 6861 | "tmp.zig:3:30: error: type '*void' has 0 bits and cannot store information", |
| 6618 | }); | 6862 | }); |
| 6619 | | 6863 | |
| 6620 | cases.add("@fieldParentPtr - non struct", | 6864 | ctx.objErrStage1("@fieldParentPtr - non struct", |
| 6621 | \\const Foo = i32; | 6865 | \\const Foo = i32; |
| 6622 | \\export fn foo(a: *i32) *Foo { | 6866 | \\export fn foo(a: *i32) *Foo { |
| 6623 | \\ return @fieldParentPtr(Foo, "a", a); | 6867 | \\ return @fieldParentPtr(Foo, "a", a); |
| ... | @@ -6626,7 +6870,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -6626,7 +6870,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6626 | "tmp.zig:3:28: error: expected struct type, found 'i32'", | 6870 | "tmp.zig:3:28: error: expected struct type, found 'i32'", |
| 6627 | }); | 6871 | }); |
| 6628 | | 6872 | |
| 6629 | cases.add("@fieldParentPtr - bad field name", | 6873 | ctx.objErrStage1("@fieldParentPtr - bad field name", |
| 6630 | \\const Foo = extern struct { | 6874 | \\const Foo = extern struct { |
| 6631 | \\ derp: i32, | 6875 | \\ derp: i32, |
| 6632 | \\}; | 6876 | \\}; |
| ... | @@ -6637,7 +6881,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -6637,7 +6881,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6637 | "tmp.zig:5:33: error: struct 'Foo' has no field 'a'", | 6881 | "tmp.zig:5:33: error: struct 'Foo' has no field 'a'", |
| 6638 | }); | 6882 | }); |
| 6639 | | 6883 | |
| 6640 | cases.add("@fieldParentPtr - field pointer is not pointer", | 6884 | ctx.objErrStage1("@fieldParentPtr - field pointer is not pointer", |
| 6641 | \\const Foo = extern struct { | 6885 | \\const Foo = extern struct { |
| 6642 | \\ a: i32, | 6886 | \\ a: i32, |
| 6643 | \\}; | 6887 | \\}; |
| ... | @@ -6648,7 +6892,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -6648,7 +6892,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6648 | "tmp.zig:5:38: error: expected pointer, found 'i32'", | 6892 | "tmp.zig:5:38: error: expected pointer, found 'i32'", |
| 6649 | }); | 6893 | }); |
| 6650 | | 6894 | |
| 6651 | cases.add("@fieldParentPtr - comptime field ptr not based on struct", | 6895 | ctx.objErrStage1("@fieldParentPtr - comptime field ptr not based on struct", |
| 6652 | \\const Foo = struct { | 6896 | \\const Foo = struct { |
| 6653 | \\ a: i32, | 6897 | \\ a: i32, |
| 6654 | \\ b: i32, | 6898 | \\ b: i32, |
| ... | @@ -6658,12 +6902,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -6658,12 +6902,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6658 | \\comptime { | 6902 | \\comptime { |
| 6659 | \\ const field_ptr = @intToPtr(*i32, 0x1234); | 6903 | \\ const field_ptr = @intToPtr(*i32, 0x1234); |
| 6660 | \\ const another_foo_ptr = @fieldParentPtr(Foo, "b", field_ptr); | 6904 | \\ const another_foo_ptr = @fieldParentPtr(Foo, "b", field_ptr); |
| | 6905 | \\ _ = another_foo_ptr; |
| 6661 | \\} | 6906 | \\} |
| 6662 | , &[_][]const u8{ | 6907 | , &[_][]const u8{ |
| 6663 | "tmp.zig:9:55: error: pointer value not based on parent struct", | 6908 | "tmp.zig:9:55: error: pointer value not based on parent struct", |
| 6664 | }); | 6909 | }); |
| 6665 | | 6910 | |
| 6666 | cases.add("@fieldParentPtr - comptime wrong field index", | 6911 | ctx.objErrStage1("@fieldParentPtr - comptime wrong field index", |
| 6667 | \\const Foo = struct { | 6912 | \\const Foo = struct { |
| 6668 | \\ a: i32, | 6913 | \\ a: i32, |
| 6669 | \\ b: i32, | 6914 | \\ b: i32, |
| ... | @@ -6672,12 +6917,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -6672,12 +6917,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6672 | \\ | 6917 | \\ |
| 6673 | \\comptime { | 6918 | \\comptime { |
| 6674 | \\ const another_foo_ptr = @fieldParentPtr(Foo, "b", &foo.a); | 6919 | \\ const another_foo_ptr = @fieldParentPtr(Foo, "b", &foo.a); |
| | 6920 | \\ _ = another_foo_ptr; |
| 6675 | \\} | 6921 | \\} |
| 6676 | , &[_][]const u8{ | 6922 | , &[_][]const u8{ |
| 6677 | "tmp.zig:8:29: error: field 'b' has index 1 but pointer value is index 0 of struct 'Foo'", | 6923 | "tmp.zig:8:29: error: field 'b' has index 1 but pointer value is index 0 of struct 'Foo'", |
| 6678 | }); | 6924 | }); |
| 6679 | | 6925 | |
| 6680 | cases.add("@offsetOf - non struct", | 6926 | ctx.objErrStage1("@offsetOf - non struct", |
| 6681 | \\const Foo = i32; | 6927 | \\const Foo = i32; |
| 6682 | \\export fn foo() usize { | 6928 | \\export fn foo() usize { |
| 6683 | \\ return @offsetOf(Foo, "a",); | 6929 | \\ return @offsetOf(Foo, "a",); |
| ... | @@ -6686,7 +6932,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -6686,7 +6932,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6686 | "tmp.zig:3:22: error: expected struct type, found 'i32'", | 6932 | "tmp.zig:3:22: error: expected struct type, found 'i32'", |
| 6687 | }); | 6933 | }); |
| 6688 | | 6934 | |
| 6689 | cases.add("@offsetOf - bad field name", | 6935 | ctx.objErrStage1("@offsetOf - bad field name", |
| 6690 | \\const Foo = struct { | 6936 | \\const Foo = struct { |
| 6691 | \\ derp: i32, | 6937 | \\ derp: i32, |
| 6692 | \\}; | 6938 | \\}; |
| ... | @@ -6697,20 +6943,20 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -6697,20 +6943,20 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6697 | "tmp.zig:5:27: error: struct 'Foo' has no field 'a'", | 6943 | "tmp.zig:5:27: error: struct 'Foo' has no field 'a'", |
| 6698 | }); | 6944 | }); |
| 6699 | | 6945 | |
| 6700 | cases.addExe("missing main fn in executable", | 6946 | ctx.exeErrStage1("missing main fn in executable", |
| 6701 | \\ | 6947 | \\ |
| 6702 | , &[_][]const u8{ | 6948 | , &[_][]const u8{ |
| 6703 | "error: root source file has no member called 'main'", | 6949 | "error: root source file has no member called 'main'", |
| 6704 | }); | 6950 | }); |
| 6705 | | 6951 | |
| 6706 | cases.addExe("private main fn", | 6952 | ctx.exeErrStage1("private main fn", |
| 6707 | \\fn main() void {} | 6953 | \\fn main() void {} |
| 6708 | , &[_][]const u8{ | 6954 | , &[_][]const u8{ |
| 6709 | "error: 'main' is private", | 6955 | "error: 'main' is private", |
| 6710 | "tmp.zig:1:1: note: declared here", | 6956 | "tmp.zig:1:1: note: declared here", |
| 6711 | }); | 6957 | }); |
| 6712 | | 6958 | |
| 6713 | cases.add("setting a section on a local variable", | 6959 | ctx.objErrStage1("setting a section on a local variable", |
| 6714 | \\export fn entry() i32 { | 6960 | \\export fn entry() i32 { |
| 6715 | \\ var foo: i32 linksection(".text2") = 1234; | 6961 | \\ var foo: i32 linksection(".text2") = 1234; |
| 6716 | \\ return foo; | 6962 | \\ return foo; |
| ... | @@ -6719,7 +6965,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -6719,7 +6965,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6719 | "tmp.zig:2:30: error: cannot set section of local variable 'foo'", | 6965 | "tmp.zig:2:30: error: cannot set section of local variable 'foo'", |
| 6720 | }); | 6966 | }); |
| 6721 | | 6967 | |
| 6722 | cases.add("inner struct member shadowing outer struct member", | 6968 | ctx.objErrStage1("inner struct member shadowing outer struct member", |
| 6723 | \\fn A() type { | 6969 | \\fn A() type { |
| 6724 | \\ return struct { | 6970 | \\ return struct { |
| 6725 | \\ b: B(), | 6971 | \\ b: B(), |
| ... | @@ -6741,10 +6987,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -6741,10 +6987,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6741 | \\} | 6987 | \\} |
| 6742 | , &[_][]const u8{ | 6988 | , &[_][]const u8{ |
| 6743 | "tmp.zig:9:17: error: redefinition of 'Self'", | 6989 | "tmp.zig:9:17: error: redefinition of 'Self'", |
| 6744 | "tmp.zig:5:9: note: previous definition is here", | 6990 | "tmp.zig:5:9: note: previous definition here", |
| 6745 | }); | 6991 | }); |
| 6746 | | 6992 | |
| 6747 | cases.add("while expected bool, got optional", | 6993 | ctx.objErrStage1("while expected bool, got optional", |
| 6748 | \\export fn foo() void { | 6994 | \\export fn foo() void { |
| 6749 | \\ while (bar()) {} | 6995 | \\ while (bar()) {} |
| 6750 | \\} | 6996 | \\} |
| ... | @@ -6753,7 +6999,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -6753,7 +6999,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6753 | "tmp.zig:2:15: error: expected type 'bool', found '?i32'", | 6999 | "tmp.zig:2:15: error: expected type 'bool', found '?i32'", |
| 6754 | }); | 7000 | }); |
| 6755 | | 7001 | |
| 6756 | cases.add("while expected bool, got error union", | 7002 | ctx.objErrStage1("while expected bool, got error union", |
| 6757 | \\export fn foo() void { | 7003 | \\export fn foo() void { |
| 6758 | \\ while (bar()) {} | 7004 | \\ while (bar()) {} |
| 6759 | \\} | 7005 | \\} |
| ... | @@ -6762,36 +7008,36 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -6762,36 +7008,36 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6762 | "tmp.zig:2:15: error: expected type 'bool', found 'anyerror!i32'", | 7008 | "tmp.zig:2:15: error: expected type 'bool', found 'anyerror!i32'", |
| 6763 | }); | 7009 | }); |
| 6764 | | 7010 | |
| 6765 | cases.add("while expected optional, got bool", | 7011 | ctx.objErrStage1("while expected optional, got bool", |
| 6766 | \\export fn foo() void { | 7012 | \\export fn foo() void { |
| 6767 | \\ while (bar()) |x| {} | 7013 | \\ while (bar()) |x| {_ = x;} |
| 6768 | \\} | 7014 | \\} |
| 6769 | \\fn bar() bool { return true; } | 7015 | \\fn bar() bool { return true; } |
| 6770 | , &[_][]const u8{ | 7016 | , &[_][]const u8{ |
| 6771 | "tmp.zig:2:15: error: expected optional type, found 'bool'", | 7017 | "tmp.zig:2:15: error: expected optional type, found 'bool'", |
| 6772 | }); | 7018 | }); |
| 6773 | | 7019 | |
| 6774 | cases.add("while expected optional, got error union", | 7020 | ctx.objErrStage1("while expected optional, got error union", |
| 6775 | \\export fn foo() void { | 7021 | \\export fn foo() void { |
| 6776 | \\ while (bar()) |x| {} | 7022 | \\ while (bar()) |x| {_ = x;} |
| 6777 | \\} | 7023 | \\} |
| 6778 | \\fn bar() anyerror!i32 { return 1; } | 7024 | \\fn bar() anyerror!i32 { return 1; } |
| 6779 | , &[_][]const u8{ | 7025 | , &[_][]const u8{ |
| 6780 | "tmp.zig:2:15: error: expected optional type, found 'anyerror!i32'", | 7026 | "tmp.zig:2:15: error: expected optional type, found 'anyerror!i32'", |
| 6781 | }); | 7027 | }); |
| 6782 | | 7028 | |
| 6783 | cases.add("while expected error union, got bool", | 7029 | ctx.objErrStage1("while expected error union, got bool", |
| 6784 | \\export fn foo() void { | 7030 | \\export fn foo() void { |
| 6785 | \\ while (bar()) |x| {} else |err| {} | 7031 | \\ while (bar()) |x| {_ = x;} else |err| {_ = err;} |
| 6786 | \\} | 7032 | \\} |
| 6787 | \\fn bar() bool { return true; } | 7033 | \\fn bar() bool { return true; } |
| 6788 | , &[_][]const u8{ | 7034 | , &[_][]const u8{ |
| 6789 | "tmp.zig:2:15: error: expected error union type, found 'bool'", | 7035 | "tmp.zig:2:15: error: expected error union type, found 'bool'", |
| 6790 | }); | 7036 | }); |
| 6791 | | 7037 | |
| 6792 | cases.add("while expected error union, got optional", | 7038 | ctx.objErrStage1("while expected error union, got optional", |
| 6793 | \\export fn foo() void { | 7039 | \\export fn foo() void { |
| 6794 | \\ while (bar()) |x| {} else |err| {} | 7040 | \\ while (bar()) |x| {_ = x;} else |err| {_ = err;} |
| 6795 | \\} | 7041 | \\} |
| 6796 | \\fn bar() ?i32 { return 1; } | 7042 | \\fn bar() ?i32 { return 1; } |
| 6797 | , &[_][]const u8{ | 7043 | , &[_][]const u8{ |
| ... | @@ -6799,7 +7045,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -6799,7 +7045,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6799 | }); | 7045 | }); |
| 6800 | | 7046 | |
| 6801 | // TODO test this in stage2, but we won't even try in stage1 | 7047 | // TODO test this in stage2, but we won't even try in stage1 |
| 6802 | //cases.add("inline fn calls itself indirectly", | 7048 | //ctx.objErrStage1("inline fn calls itself indirectly", |
| 6803 | // \\export fn foo() void { | 7049 | // \\export fn foo() void { |
| 6804 | // \\ bar(); | 7050 | // \\ bar(); |
| 6805 | // \\} | 7051 | // \\} |
| ... | @@ -6816,7 +7062,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -6816,7 +7062,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6816 | // "tmp.zig:4:1: error: unable to inline function", | 7062 | // "tmp.zig:4:1: error: unable to inline function", |
| 6817 | //}); | 7063 | //}); |
| 6818 | | 7064 | |
| 6819 | //cases.add("save reference to inline function", | 7065 | //ctx.objErrStage1("save reference to inline function", |
| 6820 | // \\export fn foo() void { | 7066 | // \\export fn foo() void { |
| 6821 | // \\ quux(@ptrToInt(bar)); | 7067 | // \\ quux(@ptrToInt(bar)); |
| 6822 | // \\} | 7068 | // \\} |
| ... | @@ -6826,7 +7072,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -6826,7 +7072,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6826 | // "tmp.zig:4:1: error: unable to inline function", | 7072 | // "tmp.zig:4:1: error: unable to inline function", |
| 6827 | //}); | 7073 | //}); |
| 6828 | | 7074 | |
| 6829 | cases.add("signed integer division", | 7075 | ctx.objErrStage1("signed integer division", |
| 6830 | \\export fn foo(a: i32, b: i32) i32 { | 7076 | \\export fn foo(a: i32, b: i32) i32 { |
| 6831 | \\ return a / b; | 7077 | \\ return a / b; |
| 6832 | \\} | 7078 | \\} |
| ... | @@ -6834,7 +7080,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -6834,7 +7080,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6834 | "tmp.zig:2:14: error: division with 'i32' and 'i32': signed integers must use @divTrunc, @divFloor, or @divExact", | 7080 | "tmp.zig:2:14: error: division with 'i32' and 'i32': signed integers must use @divTrunc, @divFloor, or @divExact", |
| 6835 | }); | 7081 | }); |
| 6836 | | 7082 | |
| 6837 | cases.add("signed integer remainder division", | 7083 | ctx.objErrStage1("signed integer remainder division", |
| 6838 | \\export fn foo(a: i32, b: i32) i32 { | 7084 | \\export fn foo(a: i32, b: i32) i32 { |
| 6839 | \\ return a % b; | 7085 | \\ return a % b; |
| 6840 | \\} | 7086 | \\} |
| ... | @@ -6842,27 +7088,29 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -6842,27 +7088,29 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6842 | "tmp.zig:2:14: error: remainder division with 'i32' and 'i32': signed integers and floats must use @rem or @mod", | 7088 | "tmp.zig:2:14: error: remainder division with 'i32' and 'i32': signed integers and floats must use @rem or @mod", |
| 6843 | }); | 7089 | }); |
| 6844 | | 7090 | |
| 6845 | cases.add("compile-time division by zero", | 7091 | ctx.objErrStage1("compile-time division by zero", |
| 6846 | \\comptime { | 7092 | \\comptime { |
| 6847 | \\ const a: i32 = 1; | 7093 | \\ const a: i32 = 1; |
| 6848 | \\ const b: i32 = 0; | 7094 | \\ const b: i32 = 0; |
| 6849 | \\ const c = a / b; | 7095 | \\ const c = a / b; |
| | 7096 | \\ _ = c; |
| 6850 | \\} | 7097 | \\} |
| 6851 | , &[_][]const u8{ | 7098 | , &[_][]const u8{ |
| 6852 | "tmp.zig:4:17: error: division by zero", | 7099 | "tmp.zig:4:17: error: division by zero", |
| 6853 | }); | 7100 | }); |
| 6854 | | 7101 | |
| 6855 | cases.add("compile-time remainder division by zero", | 7102 | ctx.objErrStage1("compile-time remainder division by zero", |
| 6856 | \\comptime { | 7103 | \\comptime { |
| 6857 | \\ const a: i32 = 1; | 7104 | \\ const a: i32 = 1; |
| 6858 | \\ const b: i32 = 0; | 7105 | \\ const b: i32 = 0; |
| 6859 | \\ const c = a % b; | 7106 | \\ const c = a % b; |
| | 7107 | \\ _ = c; |
| 6860 | \\} | 7108 | \\} |
| 6861 | , &[_][]const u8{ | 7109 | , &[_][]const u8{ |
| 6862 | "tmp.zig:4:17: error: division by zero", | 7110 | "tmp.zig:4:17: error: division by zero", |
| 6863 | }); | 7111 | }); |
| 6864 | | 7112 | |
| 6865 | cases.add("@setRuntimeSafety twice for same scope", | 7113 | ctx.objErrStage1("@setRuntimeSafety twice for same scope", |
| 6866 | \\export fn foo() void { | 7114 | \\export fn foo() void { |
| 6867 | \\ @setRuntimeSafety(false); | 7115 | \\ @setRuntimeSafety(false); |
| 6868 | \\ @setRuntimeSafety(false); | 7116 | \\ @setRuntimeSafety(false); |
| ... | @@ -6872,7 +7120,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -6872,7 +7120,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6872 | "tmp.zig:2:5: note: first set here", | 7120 | "tmp.zig:2:5: note: first set here", |
| 6873 | }); | 7121 | }); |
| 6874 | | 7122 | |
| 6875 | cases.add("@setFloatMode twice for same scope", | 7123 | ctx.objErrStage1("@setFloatMode twice for same scope", |
| 6876 | \\export fn foo() void { | 7124 | \\export fn foo() void { |
| 6877 | \\ @setFloatMode(@import("std").builtin.FloatMode.Optimized); | 7125 | \\ @setFloatMode(@import("std").builtin.FloatMode.Optimized); |
| 6878 | \\ @setFloatMode(@import("std").builtin.FloatMode.Optimized); | 7126 | \\ @setFloatMode(@import("std").builtin.FloatMode.Optimized); |
| ... | @@ -6882,15 +7130,16 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -6882,15 +7130,16 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6882 | "tmp.zig:2:5: note: first set here", | 7130 | "tmp.zig:2:5: note: first set here", |
| 6883 | }); | 7131 | }); |
| 6884 | | 7132 | |
| 6885 | cases.add("array access of type", | 7133 | ctx.objErrStage1("array access of type", |
| 6886 | \\export fn foo() void { | 7134 | \\export fn foo() void { |
| 6887 | \\ var b: u8[40] = undefined; | 7135 | \\ var b: u8[40] = undefined; |
| | 7136 | \\ _ = b; |
| 6888 | \\} | 7137 | \\} |
| 6889 | , &[_][]const u8{ | 7138 | , &[_][]const u8{ |
| 6890 | "tmp.zig:2:14: error: array access of non-array type 'type'", | 7139 | "tmp.zig:2:14: error: array access of non-array type 'type'", |
| 6891 | }); | 7140 | }); |
| 6892 | | 7141 | |
| 6893 | cases.add("cannot break out of defer expression", | 7142 | ctx.objErrStage1("cannot break out of defer expression", |
| 6894 | \\export fn foo() void { | 7143 | \\export fn foo() void { |
| 6895 | \\ while (true) { | 7144 | \\ while (true) { |
| 6896 | \\ defer { | 7145 | \\ defer { |
| ... | @@ -6902,7 +7151,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -6902,7 +7151,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6902 | "tmp.zig:4:13: error: cannot break out of defer expression", | 7151 | "tmp.zig:4:13: error: cannot break out of defer expression", |
| 6903 | }); | 7152 | }); |
| 6904 | | 7153 | |
| 6905 | cases.add("cannot continue out of defer expression", | 7154 | ctx.objErrStage1("cannot continue out of defer expression", |
| 6906 | \\export fn foo() void { | 7155 | \\export fn foo() void { |
| 6907 | \\ while (true) { | 7156 | \\ while (true) { |
| 6908 | \\ defer { | 7157 | \\ defer { |
| ... | @@ -6914,11 +7163,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -6914,11 +7163,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6914 | "tmp.zig:4:13: error: cannot continue out of defer expression", | 7163 | "tmp.zig:4:13: error: cannot continue out of defer expression", |
| 6915 | }); | 7164 | }); |
| 6916 | | 7165 | |
| 6917 | cases.add("calling a generic function only known at runtime", | 7166 | ctx.objErrStage1("calling a generic function only known at runtime", |
| 6918 | \\var foos = [_]fn(anytype) void { foo1, foo2 }; | 7167 | \\var foos = [_]fn(anytype) void { foo1, foo2 }; |
| 6919 | \\ | 7168 | \\ |
| 6920 | \\fn foo1(arg: anytype) void {} | 7169 | \\fn foo1(arg: anytype) void {_ = arg;} |
| 6921 | \\fn foo2(arg: anytype) void {} | 7170 | \\fn foo2(arg: anytype) void {_ = arg;} |
| 6922 | \\ | 7171 | \\ |
| 6923 | \\pub fn main() !void { | 7172 | \\pub fn main() !void { |
| 6924 | \\ foos[0](true); | 7173 | \\ foos[0](true); |
| ... | @@ -6927,7 +7176,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -6927,7 +7176,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6927 | "tmp.zig:7:9: error: calling a generic function requires compile-time known function value", | 7176 | "tmp.zig:7:9: error: calling a generic function requires compile-time known function value", |
| 6928 | }); | 7177 | }); |
| 6929 | | 7178 | |
| 6930 | cases.add("@compileError shows traceback of references that caused it", | 7179 | ctx.objErrStage1("@compileError shows traceback of references that caused it", |
| 6931 | \\const foo = @compileError("aoeu",); | 7180 | \\const foo = @compileError("aoeu",); |
| 6932 | \\ | 7181 | \\ |
| 6933 | \\const bar = baz + foo; | 7182 | \\const bar = baz + foo; |
| ... | @@ -6942,23 +7191,25 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -6942,23 +7191,25 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6942 | "tmp.zig:7:12: note: referenced here", | 7191 | "tmp.zig:7:12: note: referenced here", |
| 6943 | }); | 7192 | }); |
| 6944 | | 7193 | |
| 6945 | cases.add("float literal too large error", | 7194 | ctx.objErrStage1("float literal too large error", |
| 6946 | \\comptime { | 7195 | \\comptime { |
| 6947 | \\ const a = 0x1.0p18495; | 7196 | \\ const a = 0x1.0p18495; |
| | 7197 | \\ _ = a; |
| 6948 | \\} | 7198 | \\} |
| 6949 | , &[_][]const u8{ | 7199 | , &[_][]const u8{ |
| 6950 | "tmp.zig:2:15: error: float literal out of range of any type", | 7200 | "tmp.zig:2:15: error: float literal out of range of any type", |
| 6951 | }); | 7201 | }); |
| 6952 | | 7202 | |
| 6953 | cases.add("float literal too small error (denormal)", | 7203 | ctx.objErrStage1("float literal too small error (denormal)", |
| 6954 | \\comptime { | 7204 | \\comptime { |
| 6955 | \\ const a = 0x1.0p-19000; | 7205 | \\ const a = 0x1.0p-19000; |
| | 7206 | \\ _ = a; |
| 6956 | \\} | 7207 | \\} |
| 6957 | , &[_][]const u8{ | 7208 | , &[_][]const u8{ |
| 6958 | "tmp.zig:2:15: error: float literal out of range of any type", | 7209 | "tmp.zig:2:15: error: float literal out of range of any type", |
| 6959 | }); | 7210 | }); |
| 6960 | | 7211 | |
| 6961 | cases.add("explicit cast float literal to integer when there is a fraction component", | 7212 | ctx.objErrStage1("explicit cast float literal to integer when there is a fraction component", |
| 6962 | \\export fn entry() i32 { | 7213 | \\export fn entry() i32 { |
| 6963 | \\ return @as(i32, 12.34); | 7214 | \\ return @as(i32, 12.34); |
| 6964 | \\} | 7215 | \\} |
| ... | @@ -6966,7 +7217,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -6966,7 +7217,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6966 | "tmp.zig:2:21: error: fractional component prevents float value 12.340000 from being casted to type 'i32'", | 7217 | "tmp.zig:2:21: error: fractional component prevents float value 12.340000 from being casted to type 'i32'", |
| 6967 | }); | 7218 | }); |
| 6968 | | 7219 | |
| 6969 | cases.add("non pointer given to @ptrToInt", | 7220 | ctx.objErrStage1("non pointer given to @ptrToInt", |
| 6970 | \\export fn entry(x: i32) usize { | 7221 | \\export fn entry(x: i32) usize { |
| 6971 | \\ return @ptrToInt(x); | 7222 | \\ return @ptrToInt(x); |
| 6972 | \\} | 7223 | \\} |
| ... | @@ -6974,23 +7225,25 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -6974,23 +7225,25 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6974 | "tmp.zig:2:22: error: expected pointer, found 'i32'", | 7225 | "tmp.zig:2:22: error: expected pointer, found 'i32'", |
| 6975 | }); | 7226 | }); |
| 6976 | | 7227 | |
| 6977 | cases.add("@shlExact shifts out 1 bits", | 7228 | ctx.objErrStage1("@shlExact shifts out 1 bits", |
| 6978 | \\comptime { | 7229 | \\comptime { |
| 6979 | \\ const x = @shlExact(@as(u8, 0b01010101), 2); | 7230 | \\ const x = @shlExact(@as(u8, 0b01010101), 2); |
| | 7231 | \\ _ = x; |
| 6980 | \\} | 7232 | \\} |
| 6981 | , &[_][]const u8{ | 7233 | , &[_][]const u8{ |
| 6982 | "tmp.zig:2:15: error: operation caused overflow", | 7234 | "tmp.zig:2:15: error: operation caused overflow", |
| 6983 | }); | 7235 | }); |
| 6984 | | 7236 | |
| 6985 | cases.add("@shrExact shifts out 1 bits", | 7237 | ctx.objErrStage1("@shrExact shifts out 1 bits", |
| 6986 | \\comptime { | 7238 | \\comptime { |
| 6987 | \\ const x = @shrExact(@as(u8, 0b10101010), 2); | 7239 | \\ const x = @shrExact(@as(u8, 0b10101010), 2); |
| | 7240 | \\ _ = x; |
| 6988 | \\} | 7241 | \\} |
| 6989 | , &[_][]const u8{ | 7242 | , &[_][]const u8{ |
| 6990 | "tmp.zig:2:15: error: exact shift shifted out 1 bits", | 7243 | "tmp.zig:2:15: error: exact shift shifted out 1 bits", |
| 6991 | }); | 7244 | }); |
| 6992 | | 7245 | |
| 6993 | cases.add("shifting without int type or comptime known", | 7246 | ctx.objErrStage1("shifting without int type or comptime known", |
| 6994 | \\export fn entry(x: u8) u8 { | 7247 | \\export fn entry(x: u8) u8 { |
| 6995 | \\ return 0x11 << x; | 7248 | \\ return 0x11 << x; |
| 6996 | \\} | 7249 | \\} |
| ... | @@ -6998,7 +7251,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -6998,7 +7251,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6998 | "tmp.zig:2:17: error: LHS of shift must be a fixed-width integer type, or RHS must be compile-time known", | 7251 | "tmp.zig:2:17: error: LHS of shift must be a fixed-width integer type, or RHS must be compile-time known", |
| 6999 | }); | 7252 | }); |
| 7000 | | 7253 | |
| 7001 | cases.add("shifting RHS is log2 of LHS int bit width", | 7254 | ctx.objErrStage1("shifting RHS is log2 of LHS int bit width", |
| 7002 | \\export fn entry(x: u8, y: u8) u8 { | 7255 | \\export fn entry(x: u8, y: u8) u8 { |
| 7003 | \\ return x << y; | 7256 | \\ return x << y; |
| 7004 | \\} | 7257 | \\} |
| ... | @@ -7006,16 +7259,17 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -7006,16 +7259,17 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7006 | "tmp.zig:2:17: error: expected type 'u3', found 'u8'", | 7259 | "tmp.zig:2:17: error: expected type 'u3', found 'u8'", |
| 7007 | }); | 7260 | }); |
| 7008 | | 7261 | |
| 7009 | cases.add("globally shadowing a primitive type", | 7262 | ctx.objErrStage1("globally shadowing a primitive type", |
| 7010 | \\const u16 = u8; | 7263 | \\const u16 = u8; |
| 7011 | \\export fn entry() void { | 7264 | \\export fn entry() void { |
| 7012 | \\ const a: u16 = 300; | 7265 | \\ const a: u16 = 300; |
| | 7266 | \\ _ = a; |
| 7013 | \\} | 7267 | \\} |
| 7014 | , &[_][]const u8{ | 7268 | , &[_][]const u8{ |
| 7015 | "tmp.zig:1:1: error: declaration shadows primitive type 'u16'", | 7269 | "tmp.zig:1:1: error: declaration shadows primitive type 'u16'", |
| 7016 | }); | 7270 | }); |
| 7017 | | 7271 | |
| 7018 | cases.add("implicitly increasing pointer alignment", | 7272 | ctx.objErrStage1("implicitly increasing pointer alignment", |
| 7019 | \\const Foo = packed struct { | 7273 | \\const Foo = packed struct { |
| 7020 | \\ a: u8, | 7274 | \\ a: u8, |
| 7021 | \\ b: u32, | 7275 | \\ b: u32, |
| ... | @@ -7033,7 +7287,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -7033,7 +7287,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7033 | "tmp.zig:8:13: error: expected type '*u32', found '*align(1) u32'", | 7287 | "tmp.zig:8:13: error: expected type '*u32', found '*align(1) u32'", |
| 7034 | }); | 7288 | }); |
| 7035 | | 7289 | |
| 7036 | cases.add("implicitly increasing slice alignment", | 7290 | ctx.objErrStage1("implicitly increasing slice alignment", |
| 7037 | \\const Foo = packed struct { | 7291 | \\const Foo = packed struct { |
| 7038 | \\ a: u8, | 7292 | \\ a: u8, |
| 7039 | \\ b: u32, | 7293 | \\ b: u32, |
| ... | @@ -7054,7 +7308,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -7054,7 +7308,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7054 | "tmp.zig:9:26: note: '*[1]u32' has alignment 4", | 7308 | "tmp.zig:9:26: note: '*[1]u32' has alignment 4", |
| 7055 | }); | 7309 | }); |
| 7056 | | 7310 | |
| 7057 | cases.add("increase pointer alignment in @ptrCast", | 7311 | ctx.objErrStage1("increase pointer alignment in @ptrCast", |
| 7058 | \\export fn entry() u32 { | 7312 | \\export fn entry() u32 { |
| 7059 | \\ var bytes: [4]u8 = [_]u8{0x01, 0x02, 0x03, 0x04}; | 7313 | \\ var bytes: [4]u8 = [_]u8{0x01, 0x02, 0x03, 0x04}; |
| 7060 | \\ const ptr = @ptrCast(*u32, &bytes[0]); | 7314 | \\ const ptr = @ptrCast(*u32, &bytes[0]); |
| ... | @@ -7066,7 +7320,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -7066,7 +7320,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7066 | "tmp.zig:3:26: note: '*u32' has alignment 4", | 7320 | "tmp.zig:3:26: note: '*u32' has alignment 4", |
| 7067 | }); | 7321 | }); |
| 7068 | | 7322 | |
| 7069 | cases.add("@alignCast expects pointer or slice", | 7323 | ctx.objErrStage1("@alignCast expects pointer or slice", |
| 7070 | \\export fn entry() void { | 7324 | \\export fn entry() void { |
| 7071 | \\ @alignCast(4, @as(u32, 3)); | 7325 | \\ @alignCast(4, @as(u32, 3)); |
| 7072 | \\} | 7326 | \\} |
| ... | @@ -7074,7 +7328,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -7074,7 +7328,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7074 | "tmp.zig:2:19: error: expected pointer or slice, found 'u32'", | 7328 | "tmp.zig:2:19: error: expected pointer or slice, found 'u32'", |
| 7075 | }); | 7329 | }); |
| 7076 | | 7330 | |
| 7077 | cases.add("passing an under-aligned function pointer", | 7331 | ctx.objErrStage1("passing an under-aligned function pointer", |
| 7078 | \\export fn entry() void { | 7332 | \\export fn entry() void { |
| 7079 | \\ testImplicitlyDecreaseFnAlign(alignedSmall, 1234); | 7333 | \\ testImplicitlyDecreaseFnAlign(alignedSmall, 1234); |
| 7080 | \\} | 7334 | \\} |
| ... | @@ -7086,7 +7340,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -7086,7 +7340,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7086 | "tmp.zig:2:35: error: expected type 'fn() align(8) i32', found 'fn() align(4) i32'", | 7340 | "tmp.zig:2:35: error: expected type 'fn() align(8) i32', found 'fn() align(4) i32'", |
| 7087 | }); | 7341 | }); |
| 7088 | | 7342 | |
| 7089 | cases.add("passing a not-aligned-enough pointer to cmpxchg", | 7343 | ctx.objErrStage1("passing a not-aligned-enough pointer to cmpxchg", |
| 7090 | \\const AtomicOrder = @import("std").builtin.AtomicOrder; | 7344 | \\const AtomicOrder = @import("std").builtin.AtomicOrder; |
| 7091 | \\export fn entry() bool { | 7345 | \\export fn entry() bool { |
| 7092 | \\ var x: i32 align(1) = 1234; | 7346 | \\ var x: i32 align(1) = 1234; |
| ... | @@ -7097,15 +7351,16 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -7097,15 +7351,16 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7097 | "tmp.zig:4:32: error: expected type '*i32', found '*align(1) i32'", | 7351 | "tmp.zig:4:32: error: expected type '*i32', found '*align(1) i32'", |
| 7098 | }); | 7352 | }); |
| 7099 | | 7353 | |
| 7100 | cases.add("wrong size to an array literal", | 7354 | ctx.objErrStage1("wrong size to an array literal", |
| 7101 | \\comptime { | 7355 | \\comptime { |
| 7102 | \\ const array = [2]u8{1, 2, 3}; | 7356 | \\ const array = [2]u8{1, 2, 3}; |
| | 7357 | \\ _ = array; |
| 7103 | \\} | 7358 | \\} |
| 7104 | , &[_][]const u8{ | 7359 | , &[_][]const u8{ |
| 7105 | "tmp.zig:2:31: error: index 2 outside array of size 2", | 7360 | "tmp.zig:2:31: error: index 2 outside array of size 2", |
| 7106 | }); | 7361 | }); |
| 7107 | | 7362 | |
| 7108 | cases.add("wrong pointer coerced to pointer to opaque {}", | 7363 | ctx.objErrStage1("wrong pointer coerced to pointer to opaque {}", |
| 7109 | \\const Derp = opaque {}; | 7364 | \\const Derp = opaque {}; |
| 7110 | \\extern fn bar(d: *Derp) void; | 7365 | \\extern fn bar(d: *Derp) void; |
| 7111 | \\export fn foo() void { | 7366 | \\export fn foo() void { |
| ... | @@ -7116,53 +7371,66 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -7116,53 +7371,66 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7116 | "tmp.zig:5:9: error: expected type '*Derp', found '*c_void'", | 7371 | "tmp.zig:5:9: error: expected type '*Derp', found '*c_void'", |
| 7117 | }); | 7372 | }); |
| 7118 | | 7373 | |
| 7119 | cases.add("non-const variables of things that require const variables", | 7374 | ctx.objErrStage1("non-const variables of things that require const variables", |
| 7120 | \\export fn entry1() void { | 7375 | \\export fn entry1() void { |
| 7121 | \\ var m2 = &2; | 7376 | \\ var m2 = &2; |
| | 7377 | \\ _ = m2; |
| 7122 | \\} | 7378 | \\} |
| 7123 | \\export fn entry2() void { | 7379 | \\export fn entry2() void { |
| 7124 | \\ var a = undefined; | 7380 | \\ var a = undefined; |
| | 7381 | \\ _ = a; |
| 7125 | \\} | 7382 | \\} |
| 7126 | \\export fn entry3() void { | 7383 | \\export fn entry3() void { |
| 7127 | \\ var b = 1; | 7384 | \\ var b = 1; |
| | 7385 | \\ _ = b; |
| 7128 | \\} | 7386 | \\} |
| 7129 | \\export fn entry4() void { | 7387 | \\export fn entry4() void { |
| 7130 | \\ var c = 1.0; | 7388 | \\ var c = 1.0; |
| | 7389 | \\ _ = c; |
| 7131 | \\} | 7390 | \\} |
| 7132 | \\export fn entry5() void { | 7391 | \\export fn entry5() void { |
| 7133 | \\ var d = null; | 7392 | \\ var d = null; |
| | 7393 | \\ _ = d; |
| 7134 | \\} | 7394 | \\} |
| 7135 | \\export fn entry6(opaque_: *Opaque) void { | 7395 | \\export fn entry6(opaque_: *Opaque) void { |
| 7136 | \\ var e = opaque_.*; | 7396 | \\ var e = opaque_.*; |
| | 7397 | \\ _ = e; |
| 7137 | \\} | 7398 | \\} |
| 7138 | \\export fn entry7() void { | 7399 | \\export fn entry7() void { |
| 7139 | \\ var f = i32; | 7400 | \\ var f = i32; |
| | 7401 | \\ _ = f; |
| 7140 | \\} | 7402 | \\} |
| 7141 | \\export fn entry8() void { | 7403 | \\export fn entry8() void { |
| 7142 | \\ var h = (Foo {}).bar; | 7404 | \\ var h = (Foo {}).bar; |
| 7143 | \\} | 7405 | \\ _ = h; |
| 7144 | \\export fn entry9() void { | | |
| 7145 | \\ var z: noreturn = return; | | |
| 7146 | \\} | 7406 | \\} |
| 7147 | \\const Opaque = opaque {}; | 7407 | \\const Opaque = opaque {}; |
| 7148 | \\const Foo = struct { | 7408 | \\const Foo = struct { |
| 7149 | \\ fn bar(self: *const Foo) void {} | 7409 | \\ fn bar(self: *const Foo) void {_ = self;} |
| 7150 | \\}; | 7410 | \\}; |
| 7151 | , &[_][]const u8{ | 7411 | , &[_][]const u8{ |
| 7152 | "tmp.zig:2:4: error: variable of type '*const comptime_int' must be const or comptime", | 7412 | "tmp.zig:2:4: error: variable of type '*const comptime_int' must be const or comptime", |
| 7153 | "tmp.zig:5:4: error: variable of type '(undefined)' must be const or comptime", | 7413 | "tmp.zig:6: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", | 7414 | "tmp.zig:10: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", | 7415 | "tmp.zig:10: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", | 7416 | "tmp.zig:14: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", | 7417 | "tmp.zig:14: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", | 7418 | "tmp.zig:18:4: error: variable of type '(null)' must be const or comptime", |
| 7159 | "tmp.zig:17:4: error: variable of type 'Opaque' not allowed", | 7419 | "tmp.zig:22:4: error: variable of type 'Opaque' not allowed", |
| 7160 | "tmp.zig:20:4: error: variable of type 'type' must be const or comptime", | 7420 | "tmp.zig:26: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", | 7421 | "tmp.zig:30:4: error: variable of type '(bound fn(*const Foo) void)' must be const or comptime", |
| 7162 | "tmp.zig:26:22: error: unreachable code", | 7422 | }); |
| | 7423 | |
| | 7424 | ctx.objErrStage1("variable with type 'noreturn'", |
| | 7425 | \\export fn entry9() void { |
| | 7426 | \\ var z: noreturn = return; |
| | 7427 | \\} |
| | 7428 | , &[_][]const u8{ |
| | 7429 | "tmp.zig:2:5: error: unreachable code", |
| | 7430 | "tmp.zig:2:23: note: control flow is diverted here", |
| 7163 | }); | 7431 | }); |
| 7164 | | 7432 | |
| 7165 | cases.add("wrong types given to atomic order args in cmpxchg", | 7433 | ctx.objErrStage1("wrong types given to atomic order args in cmpxchg", |
| 7166 | \\export fn entry() void { | 7434 | \\export fn entry() void { |
| 7167 | \\ var x: i32 = 1234; | 7435 | \\ var x: i32 = 1234; |
| 7168 | \\ while (!@cmpxchgWeak(i32, &x, 1234, 5678, @as(u32, 1234), @as(u32, 1234))) {} | 7436 | \\ while (!@cmpxchgWeak(i32, &x, 1234, 5678, @as(u32, 1234), @as(u32, 1234))) {} |
| ... | @@ -7171,7 +7439,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -7171,7 +7439,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7171 | "tmp.zig:3:47: error: expected type 'std.builtin.AtomicOrder', found 'u32'", | 7439 | "tmp.zig:3:47: error: expected type 'std.builtin.AtomicOrder', found 'u32'", |
| 7172 | }); | 7440 | }); |
| 7173 | | 7441 | |
| 7174 | cases.add("wrong types given to @export", | 7442 | ctx.objErrStage1("wrong types given to @export", |
| 7175 | \\fn entry() callconv(.C) void { } | 7443 | \\fn entry() callconv(.C) void { } |
| 7176 | \\comptime { | 7444 | \\comptime { |
| 7177 | \\ @export(entry, .{.name = "entry", .linkage = @as(u32, 1234) }); | 7445 | \\ @export(entry, .{.name = "entry", .linkage = @as(u32, 1234) }); |
| ... | @@ -7180,7 +7448,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -7180,7 +7448,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7180 | "tmp.zig:3:59: error: expected type 'std.builtin.GlobalLinkage', found 'comptime_int'", | 7448 | "tmp.zig:3:59: error: expected type 'std.builtin.GlobalLinkage', found 'comptime_int'", |
| 7181 | }); | 7449 | }); |
| 7182 | | 7450 | |
| 7183 | cases.add("struct with invalid field", | 7451 | ctx.objErrStage1("struct with invalid field", |
| 7184 | \\const std = @import("std",); | 7452 | \\const std = @import("std",); |
| 7185 | \\const Allocator = std.mem.Allocator; | 7453 | \\const Allocator = std.mem.Allocator; |
| 7186 | \\const ArrayList = std.ArrayList; | 7454 | \\const ArrayList = std.ArrayList; |
| ... | @@ -7203,12 +7471,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -7203,12 +7471,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7203 | \\ .text = MdText.init(&std.testing.allocator), | 7471 | \\ .text = MdText.init(&std.testing.allocator), |
| 7204 | \\ .weight = HeaderWeight.H1, | 7472 | \\ .weight = HeaderWeight.H1, |
| 7205 | \\ }; | 7473 | \\ }; |
| | 7474 | \\ _ = a; |
| 7206 | \\} | 7475 | \\} |
| 7207 | , &[_][]const u8{ | 7476 | , &[_][]const u8{ |
| 7208 | "tmp.zig:14:17: error: use of undeclared identifier 'HeaderValue'", | 7477 | "tmp.zig:14:17: error: use of undeclared identifier 'HeaderValue'", |
| 7209 | }); | 7478 | }); |
| 7210 | | 7479 | |
| 7211 | cases.add("@setAlignStack outside function", | 7480 | ctx.objErrStage1("@setAlignStack outside function", |
| 7212 | \\comptime { | 7481 | \\comptime { |
| 7213 | \\ @setAlignStack(16); | 7482 | \\ @setAlignStack(16); |
| 7214 | \\} | 7483 | \\} |
| ... | @@ -7216,7 +7485,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -7216,7 +7485,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7216 | "tmp.zig:2:5: error: @setAlignStack outside function", | 7485 | "tmp.zig:2:5: error: @setAlignStack outside function", |
| 7217 | }); | 7486 | }); |
| 7218 | | 7487 | |
| 7219 | cases.add("@setAlignStack in naked function", | 7488 | ctx.objErrStage1("@setAlignStack in naked function", |
| 7220 | \\export fn entry() callconv(.Naked) void { | 7489 | \\export fn entry() callconv(.Naked) void { |
| 7221 | \\ @setAlignStack(16); | 7490 | \\ @setAlignStack(16); |
| 7222 | \\} | 7491 | \\} |
| ... | @@ -7224,7 +7493,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -7224,7 +7493,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7224 | "tmp.zig:2:5: error: @setAlignStack in naked function", | 7493 | "tmp.zig:2:5: error: @setAlignStack in naked function", |
| 7225 | }); | 7494 | }); |
| 7226 | | 7495 | |
| 7227 | cases.add("@setAlignStack in inline function", | 7496 | ctx.objErrStage1("@setAlignStack in inline function", |
| 7228 | \\export fn entry() void { | 7497 | \\export fn entry() void { |
| 7229 | \\ foo(); | 7498 | \\ foo(); |
| 7230 | \\} | 7499 | \\} |
| ... | @@ -7235,7 +7504,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -7235,7 +7504,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7235 | "tmp.zig:5:5: error: @setAlignStack in inline function", | 7504 | "tmp.zig:5:5: error: @setAlignStack in inline function", |
| 7236 | }); | 7505 | }); |
| 7237 | | 7506 | |
| 7238 | cases.add("@setAlignStack set twice", | 7507 | ctx.objErrStage1("@setAlignStack set twice", |
| 7239 | \\export fn entry() void { | 7508 | \\export fn entry() void { |
| 7240 | \\ @setAlignStack(16); | 7509 | \\ @setAlignStack(16); |
| 7241 | \\ @setAlignStack(16); | 7510 | \\ @setAlignStack(16); |
| ... | @@ -7245,7 +7514,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -7245,7 +7514,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7245 | "tmp.zig:2:5: note: first set here", | 7514 | "tmp.zig:2:5: note: first set here", |
| 7246 | }); | 7515 | }); |
| 7247 | | 7516 | |
| 7248 | cases.add("@setAlignStack too big", | 7517 | ctx.objErrStage1("@setAlignStack too big", |
| 7249 | \\export fn entry() void { | 7518 | \\export fn entry() void { |
| 7250 | \\ @setAlignStack(511 + 1); | 7519 | \\ @setAlignStack(511 + 1); |
| 7251 | \\} | 7520 | \\} |
| ... | @@ -7253,7 +7522,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -7253,7 +7522,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7253 | "tmp.zig:2:5: error: attempt to @setAlignStack(512); maximum is 256", | 7522 | "tmp.zig:2:5: error: attempt to @setAlignStack(512); maximum is 256", |
| 7254 | }); | 7523 | }); |
| 7255 | | 7524 | |
| 7256 | cases.add("storing runtime value in compile time variable then using it", | 7525 | ctx.objErrStage1("storing runtime value in compile time variable then using it", |
| 7257 | \\const Mode = @import("std").builtin.Mode; | 7526 | \\const Mode = @import("std").builtin.Mode; |
| 7258 | \\ | 7527 | \\ |
| 7259 | \\fn Free(comptime filename: []const u8) TestCase { | 7528 | \\fn Free(comptime filename: []const u8) TestCase { |
| ... | @@ -7290,24 +7559,27 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -7290,24 +7559,27 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7290 | \\ }; | 7559 | \\ }; |
| 7291 | \\ | 7560 | \\ |
| 7292 | \\ for ([_]Mode { Mode.Debug, Mode.ReleaseSafe, Mode.ReleaseFast }) |mode| { | 7561 | \\ for ([_]Mode { Mode.Debug, Mode.ReleaseSafe, Mode.ReleaseFast }) |mode| { |
| | 7562 | \\ _ = mode; |
| 7293 | \\ inline for (tests) |test_case| { | 7563 | \\ inline for (tests) |test_case| { |
| 7294 | \\ const foo = test_case.filename ++ ".zig"; | 7564 | \\ const foo = test_case.filename ++ ".zig"; |
| | 7565 | \\ _ = foo; |
| 7295 | \\ } | 7566 | \\ } |
| 7296 | \\ } | 7567 | \\ } |
| 7297 | \\} | 7568 | \\} |
| 7298 | , &[_][]const u8{ | 7569 | , &[_][]const u8{ |
| 7299 | "tmp.zig:37:29: error: cannot store runtime value in compile time variable", | 7570 | "tmp.zig:38:29: error: cannot store runtime value in compile time variable", |
| 7300 | }); | 7571 | }); |
| 7301 | | 7572 | |
| 7302 | cases.add("invalid legacy unicode escape", | 7573 | ctx.objErrStage1("invalid legacy unicode escape", |
| 7303 | \\export fn entry() void { | 7574 | \\export fn entry() void { |
| 7304 | \\ const a = '\U1234'; | 7575 | \\ const a = '\U1234'; |
| 7305 | \\} | 7576 | \\} |
| 7306 | , &[_][]const u8{ | 7577 | , &[_][]const u8{ |
| 7307 | "tmp.zig:2:17: error: invalid character: 'U'", | 7578 | "tmp.zig:2:15: error: expected expression, found 'invalid'", |
| | 7579 | "tmp.zig:2:18: note: invalid byte: '1'", |
| 7308 | }); | 7580 | }); |
| 7309 | | 7581 | |
| 7310 | cases.add("invalid empty unicode escape", | 7582 | ctx.objErrStage1("invalid empty unicode escape", |
| 7311 | \\export fn entry() void { | 7583 | \\export fn entry() void { |
| 7312 | \\ const a = '\u{}'; | 7584 | \\ const a = '\u{}'; |
| 7313 | \\} | 7585 | \\} |
| ... | @@ -7315,21 +7587,21 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -7315,21 +7587,21 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7315 | "tmp.zig:2:19: error: empty unicode escape sequence", | 7587 | "tmp.zig:2:19: error: empty unicode escape sequence", |
| 7316 | }); | 7588 | }); |
| 7317 | | 7589 | |
| 7318 | cases.add("non-printable invalid character", "\xff\xfe" ++ | 7590 | ctx.objErrStage1("non-printable invalid character", "\xff\xfe" ++ |
| 7319 | \\fn test() bool {\r | 7591 | "fn foo() bool {\r\n" ++ |
| 7320 | \\ true\r | 7592 | " return true;\r\n" ++ |
| 7321 | \\} | 7593 | "}\r\n", &[_][]const u8{ |
| 7322 | , &[_][]const u8{ | 7594 | "tmp.zig:1:1: error: expected test, comptime, var decl, or container field, found 'invalid'", |
| 7323 | "tmp.zig:1:1: error: invalid character: '\\xff'", | 7595 | "tmp.zig:1:1: note: invalid byte: '\\xff'", |
| 7324 | }); | 7596 | }); |
| 7325 | | 7597 | |
| 7326 | cases.add("non-printable invalid character with escape alternative", "fn test() bool {\n" ++ | 7598 | ctx.objErrStage1("non-printable invalid character with escape alternative", "fn foo() bool {\n" ++ |
| 7327 | "\ttrue\n" ++ | 7599 | "\treturn true;\n" ++ |
| 7328 | "}\n", &[_][]const u8{ | 7600 | "}\n", &[_][]const u8{ |
| 7329 | "tmp.zig:2:1: error: invalid character: '\\t'", | 7601 | "tmp.zig:2:1: error: invalid character: '\\t'", |
| 7330 | }); | 7602 | }); |
| 7331 | | 7603 | |
| 7332 | cases.add("calling var args extern function, passing array instead of pointer", | 7604 | ctx.objErrStage1("calling var args extern function, passing array instead of pointer", |
| 7333 | \\export fn entry() void { | 7605 | \\export fn entry() void { |
| 7334 | \\ foo("hello".*,); | 7606 | \\ foo("hello".*,); |
| 7335 | \\} | 7607 | \\} |
| ... | @@ -7338,7 +7610,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -7338,7 +7610,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7338 | "tmp.zig:2:16: error: expected type '*const u8', found '[5:0]u8'", | 7610 | "tmp.zig:2:16: error: expected type '*const u8', found '[5:0]u8'", |
| 7339 | }); | 7611 | }); |
| 7340 | | 7612 | |
| 7341 | cases.add("constant inside comptime function has compile error", | 7613 | ctx.objErrStage1("constant inside comptime function has compile error", |
| 7342 | \\const ContextAllocator = MemoryPool(usize); | 7614 | \\const ContextAllocator = MemoryPool(usize); |
| 7343 | \\ | 7615 | \\ |
| 7344 | \\pub fn MemoryPool(comptime T: type) type { | 7616 | \\pub fn MemoryPool(comptime T: type) type { |
| ... | @@ -7353,12 +7625,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -7353,12 +7625,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7353 | \\ var allocator: ContextAllocator = undefined; | 7625 | \\ var allocator: ContextAllocator = undefined; |
| 7354 | \\} | 7626 | \\} |
| 7355 | , &[_][]const u8{ | 7627 | , &[_][]const u8{ |
| 7356 | "tmp.zig:4:25: error: aoeu", | 7628 | "tmp.zig:4:5: error: unreachable code", |
| 7357 | "tmp.zig:1:36: note: referenced here", | 7629 | "tmp.zig:4:25: note: control flow is diverted here", |
| 7358 | "tmp.zig:12:20: note: referenced here", | 7630 | "tmp.zig:12:9: error: unused local variable", |
| 7359 | }); | 7631 | }); |
| 7360 | | 7632 | |
| 7361 | cases.add("specify enum tag type that is too small", | 7633 | ctx.objErrStage1("specify enum tag type that is too small", |
| 7362 | \\const Small = enum (u2) { | 7634 | \\const Small = enum (u2) { |
| 7363 | \\ One, | 7635 | \\ One, |
| 7364 | \\ Two, | 7636 | \\ Two, |
| ... | @@ -7369,12 +7641,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -7369,12 +7641,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7369 | \\ | 7641 | \\ |
| 7370 | \\export fn entry() void { | 7642 | \\export fn entry() void { |
| 7371 | \\ var x = Small.One; | 7643 | \\ var x = Small.One; |
| | 7644 | \\ _ = x; |
| 7372 | \\} | 7645 | \\} |
| 7373 | , &[_][]const u8{ | 7646 | , &[_][]const u8{ |
| 7374 | "tmp.zig:6:5: error: enumeration value 4 too large for type 'u2'", | 7647 | "tmp.zig:6:5: error: enumeration value 4 too large for type 'u2'", |
| 7375 | }); | 7648 | }); |
| 7376 | | 7649 | |
| 7377 | cases.add("specify non-integer enum tag type", | 7650 | ctx.objErrStage1("specify non-integer enum tag type", |
| 7378 | \\const Small = enum (f32) { | 7651 | \\const Small = enum (f32) { |
| 7379 | \\ One, | 7652 | \\ One, |
| 7380 | \\ Two, | 7653 | \\ Two, |
| ... | @@ -7383,12 +7656,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -7383,12 +7656,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7383 | \\ | 7656 | \\ |
| 7384 | \\export fn entry() void { | 7657 | \\export fn entry() void { |
| 7385 | \\ var x = Small.One; | 7658 | \\ var x = Small.One; |
| | 7659 | \\ _ = x; |
| 7386 | \\} | 7660 | \\} |
| 7387 | , &[_][]const u8{ | 7661 | , &[_][]const u8{ |
| 7388 | "tmp.zig:1:21: error: expected integer, found 'f32'", | 7662 | "tmp.zig:1:21: error: expected integer, found 'f32'", |
| 7389 | }); | 7663 | }); |
| 7390 | | 7664 | |
| 7391 | cases.add("implicitly casting enum to tag type", | 7665 | ctx.objErrStage1("implicitly casting enum to tag type", |
| 7392 | \\const Small = enum(u2) { | 7666 | \\const Small = enum(u2) { |
| 7393 | \\ One, | 7667 | \\ One, |
| 7394 | \\ Two, | 7668 | \\ Two, |
| ... | @@ -7398,12 +7672,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -7398,12 +7672,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7398 | \\ | 7672 | \\ |
| 7399 | \\export fn entry() void { | 7673 | \\export fn entry() void { |
| 7400 | \\ var x: u2 = Small.Two; | 7674 | \\ var x: u2 = Small.Two; |
| | 7675 | \\ _ = x; |
| 7401 | \\} | 7676 | \\} |
| 7402 | , &[_][]const u8{ | 7677 | , &[_][]const u8{ |
| 7403 | "tmp.zig:9:22: error: expected type 'u2', found 'Small'", | 7678 | "tmp.zig:9:22: error: expected type 'u2', found 'Small'", |
| 7404 | }); | 7679 | }); |
| 7405 | | 7680 | |
| 7406 | cases.add("explicitly casting non tag type to enum", | 7681 | ctx.objErrStage1("explicitly casting non tag type to enum", |
| 7407 | \\const Small = enum(u2) { | 7682 | \\const Small = enum(u2) { |
| 7408 | \\ One, | 7683 | \\ One, |
| 7409 | \\ Two, | 7684 | \\ Two, |
| ... | @@ -7414,42 +7689,38 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -7414,42 +7689,38 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7414 | \\export fn entry() void { | 7689 | \\export fn entry() void { |
| 7415 | \\ var y = @as(u3, 3); | 7690 | \\ var y = @as(u3, 3); |
| 7416 | \\ var x = @intToEnum(Small, y); | 7691 | \\ var x = @intToEnum(Small, y); |
| | 7692 | \\ _ = x; |
| 7417 | \\} | 7693 | \\} |
| 7418 | , &[_][]const u8{ | 7694 | , &[_][]const u8{ |
| 7419 | "tmp.zig:10:31: error: expected type 'u2', found 'u3'", | 7695 | "tmp.zig:10:31: error: expected type 'u2', found 'u3'", |
| 7420 | }); | 7696 | }); |
| 7421 | | 7697 | |
| 7422 | cases.add("union fields with value assignments", | 7698 | ctx.objErrStage1("union fields with value assignments", |
| 7423 | \\const MultipleChoice = union { | 7699 | \\const MultipleChoice = union { |
| 7424 | \\ A: i32 = 20, | 7700 | \\ A: i32 = 20, |
| 7425 | \\}; | 7701 | \\}; |
| 7426 | \\export fn entry() void { | 7702 | \\export fn entry() void { |
| 7427 | \\ var x: MultipleChoice = undefined; | 7703 | \\ var x: MultipleChoice = undefined; |
| | 7704 | \\ _ = x; |
| 7428 | \\} | 7705 | \\} |
| 7429 | , &[_][]const u8{ | 7706 | , &[_][]const u8{ |
| 7430 | "tmp.zig:2:14: error: untagged union field assignment", | 7707 | "tmp.zig:1:24: error: explicitly valued tagged union missing integer tag type", |
| 7431 | "tmp.zig:1:24: note: consider 'union(enum)' here", | 7708 | "tmp.zig:2:14: note: tag value specified here", |
| 7432 | }); | 7709 | }); |
| 7433 | | 7710 | |
| 7434 | cases.add("enum with 0 fields", | 7711 | ctx.objErrStage1("enum with 0 fields", |
| 7435 | \\const Foo = enum {}; | 7712 | \\const Foo = enum {}; |
| 7436 | \\export fn entry() usize { | | |
| 7437 | \\ return @sizeOf(Foo); | | |
| 7438 | \\} | | |
| 7439 | , &[_][]const u8{ | 7713 | , &[_][]const u8{ |
| 7440 | "tmp.zig:1:13: error: enums must have 1 or more fields", | 7714 | "tmp.zig:1:13: error: enum declarations must have at least one tag", |
| 7441 | }); | 7715 | }); |
| 7442 | | 7716 | |
| 7443 | cases.add("union with 0 fields", | 7717 | ctx.objErrStage1("union with 0 fields", |
| 7444 | \\const Foo = union {}; | 7718 | \\const Foo = union {}; |
| 7445 | \\export fn entry() usize { | | |
| 7446 | \\ return @sizeOf(Foo); | | |
| 7447 | \\} | | |
| 7448 | , &[_][]const u8{ | 7719 | , &[_][]const u8{ |
| 7449 | "tmp.zig:1:13: error: unions must have 1 or more fields", | 7720 | "tmp.zig:1:13: error: union declarations must have at least one tag", |
| 7450 | }); | 7721 | }); |
| 7451 | | 7722 | |
| 7452 | cases.add("enum value already taken", | 7723 | ctx.objErrStage1("enum value already taken", |
| 7453 | \\const MultipleChoice = enum(u32) { | 7724 | \\const MultipleChoice = enum(u32) { |
| 7454 | \\ A = 20, | 7725 | \\ A = 20, |
| 7455 | \\ B = 40, | 7726 | \\ B = 40, |
| ... | @@ -7459,13 +7730,14 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -7459,13 +7730,14 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7459 | \\}; | 7730 | \\}; |
| 7460 | \\export fn entry() void { | 7731 | \\export fn entry() void { |
| 7461 | \\ var x = MultipleChoice.C; | 7732 | \\ var x = MultipleChoice.C; |
| | 7733 | \\ _ = x; |
| 7462 | \\} | 7734 | \\} |
| 7463 | , &[_][]const u8{ | 7735 | , &[_][]const u8{ |
| 7464 | "tmp.zig:6:5: error: enum tag value 60 already taken", | 7736 | "tmp.zig:6:5: error: enum tag value 60 already taken", |
| 7465 | "tmp.zig:4:5: note: other occurrence here", | 7737 | "tmp.zig:4:5: note: other occurrence here", |
| 7466 | }); | 7738 | }); |
| 7467 | | 7739 | |
| 7468 | cases.add("union with specified enum omits field", | 7740 | ctx.objErrStage1("union with specified enum omits field", |
| 7469 | \\const Letter = enum { | 7741 | \\const Letter = enum { |
| 7470 | \\ A, | 7742 | \\ A, |
| 7471 | \\ B, | 7743 | \\ B, |
| ... | @@ -7483,29 +7755,31 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -7483,29 +7755,31 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7483 | "tmp.zig:4:5: note: declared here", | 7755 | "tmp.zig:4:5: note: declared here", |
| 7484 | }); | 7756 | }); |
| 7485 | | 7757 | |
| 7486 | cases.add("non-integer tag type to automatic union enum", | 7758 | ctx.objErrStage1("non-integer tag type to automatic union enum", |
| 7487 | \\const Foo = union(enum(f32)) { | 7759 | \\const Foo = union(enum(f32)) { |
| 7488 | \\ A: i32, | 7760 | \\ A: i32, |
| 7489 | \\}; | 7761 | \\}; |
| 7490 | \\export fn entry() void { | 7762 | \\export fn entry() void { |
| 7491 | \\ const x = @typeInfo(Foo).Union.tag_type.?; | 7763 | \\ const x = @typeInfo(Foo).Union.tag_type.?; |
| | 7764 | \\ _ = x; |
| 7492 | \\} | 7765 | \\} |
| 7493 | , &[_][]const u8{ | 7766 | , &[_][]const u8{ |
| 7494 | "tmp.zig:1:24: error: expected integer tag type, found 'f32'", | 7767 | "tmp.zig:1:24: error: expected integer tag type, found 'f32'", |
| 7495 | }); | 7768 | }); |
| 7496 | | 7769 | |
| 7497 | cases.add("non-enum tag type passed to union", | 7770 | ctx.objErrStage1("non-enum tag type passed to union", |
| 7498 | \\const Foo = union(u32) { | 7771 | \\const Foo = union(u32) { |
| 7499 | \\ A: i32, | 7772 | \\ A: i32, |
| 7500 | \\}; | 7773 | \\}; |
| 7501 | \\export fn entry() void { | 7774 | \\export fn entry() void { |
| 7502 | \\ const x = @typeInfo(Foo).Union.tag_type.?; | 7775 | \\ const x = @typeInfo(Foo).Union.tag_type.?; |
| | 7776 | \\ _ = x; |
| 7503 | \\} | 7777 | \\} |
| 7504 | , &[_][]const u8{ | 7778 | , &[_][]const u8{ |
| 7505 | "tmp.zig:1:19: error: expected enum tag type, found 'u32'", | 7779 | "tmp.zig:1:19: error: expected enum tag type, found 'u32'", |
| 7506 | }); | 7780 | }); |
| 7507 | | 7781 | |
| 7508 | cases.add("union auto-enum value already taken", | 7782 | ctx.objErrStage1("union auto-enum value already taken", |
| 7509 | \\const MultipleChoice = union(enum(u32)) { | 7783 | \\const MultipleChoice = union(enum(u32)) { |
| 7510 | \\ A = 20, | 7784 | \\ A = 20, |
| 7511 | \\ B = 40, | 7785 | \\ B = 40, |
| ... | @@ -7515,13 +7789,14 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -7515,13 +7789,14 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7515 | \\}; | 7789 | \\}; |
| 7516 | \\export fn entry() void { | 7790 | \\export fn entry() void { |
| 7517 | \\ var x = MultipleChoice { .C = {} }; | 7791 | \\ var x = MultipleChoice { .C = {} }; |
| | 7792 | \\ _ = x; |
| 7518 | \\} | 7793 | \\} |
| 7519 | , &[_][]const u8{ | 7794 | , &[_][]const u8{ |
| 7520 | "tmp.zig:6:9: error: enum tag value 60 already taken", | 7795 | "tmp.zig:6:9: error: enum tag value 60 already taken", |
| 7521 | "tmp.zig:4:9: note: other occurrence here", | 7796 | "tmp.zig:4:9: note: other occurrence here", |
| 7522 | }); | 7797 | }); |
| 7523 | | 7798 | |
| 7524 | cases.add("union enum field does not match enum", | 7799 | ctx.objErrStage1("union enum field does not match enum", |
| 7525 | \\const Letter = enum { | 7800 | \\const Letter = enum { |
| 7526 | \\ A, | 7801 | \\ A, |
| 7527 | \\ B, | 7802 | \\ B, |
| ... | @@ -7535,49 +7810,49 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -7535,49 +7810,49 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7535 | \\}; | 7810 | \\}; |
| 7536 | \\export fn entry() void { | 7811 | \\export fn entry() void { |
| 7537 | \\ var a = Payload {.A = 1234}; | 7812 | \\ var a = Payload {.A = 1234}; |
| | 7813 | \\ _ = a; |
| 7538 | \\} | 7814 | \\} |
| 7539 | , &[_][]const u8{ | 7815 | , &[_][]const u8{ |
| 7540 | "tmp.zig:10:5: error: enum field not found: 'D'", | 7816 | "tmp.zig:10:5: error: enum field not found: 'D'", |
| 7541 | "tmp.zig:1:16: note: enum declared here", | 7817 | "tmp.zig:1:16: note: enum declared here", |
| 7542 | }); | 7818 | }); |
| 7543 | | 7819 | |
| 7544 | cases.add("field type supplied in an enum", | 7820 | ctx.objErrStage1("field type supplied in an enum", |
| 7545 | \\const Letter = enum { | 7821 | \\const Letter = enum { |
| 7546 | \\ A: void, | 7822 | \\ A: void, |
| 7547 | \\ B, | 7823 | \\ B, |
| 7548 | \\ C, | 7824 | \\ C, |
| 7549 | \\}; | 7825 | \\}; |
| 7550 | \\export fn entry() void { | | |
| 7551 | \\ var b = Letter.B; | | |
| 7552 | \\} | | |
| 7553 | , &[_][]const u8{ | 7826 | , &[_][]const u8{ |
| 7554 | "tmp.zig:2:8: error: structs and unions, not enums, support field types", | 7827 | "tmp.zig:2:8: error: enum fields do not have types", |
| 7555 | "tmp.zig:1:16: note: consider 'union(enum)' here", | 7828 | "tmp.zig:1:16: note: consider 'union(enum)' here to make it a tagged union", |
| 7556 | }); | 7829 | }); |
| 7557 | | 7830 | |
| 7558 | cases.add("struct field missing type", | 7831 | ctx.objErrStage1("struct field missing type", |
| 7559 | \\const Letter = struct { | 7832 | \\const Letter = struct { |
| 7560 | \\ A, | 7833 | \\ A, |
| 7561 | \\}; | 7834 | \\}; |
| 7562 | \\export fn entry() void { | 7835 | \\export fn entry() void { |
| 7563 | \\ var a = Letter { .A = {} }; | 7836 | \\ var a = Letter { .A = {} }; |
| | 7837 | \\ _ = a; |
| 7564 | \\} | 7838 | \\} |
| 7565 | , &[_][]const u8{ | 7839 | , &[_][]const u8{ |
| 7566 | "tmp.zig:2:5: error: struct field missing type", | 7840 | "tmp.zig:2:5: error: struct field missing type", |
| 7567 | }); | 7841 | }); |
| 7568 | | 7842 | |
| 7569 | cases.add("extern union field missing type", | 7843 | ctx.objErrStage1("extern union field missing type", |
| 7570 | \\const Letter = extern union { | 7844 | \\const Letter = extern union { |
| 7571 | \\ A, | 7845 | \\ A, |
| 7572 | \\}; | 7846 | \\}; |
| 7573 | \\export fn entry() void { | 7847 | \\export fn entry() void { |
| 7574 | \\ var a = Letter { .A = {} }; | 7848 | \\ var a = Letter { .A = {} }; |
| | 7849 | \\ _ = a; |
| 7575 | \\} | 7850 | \\} |
| 7576 | , &[_][]const u8{ | 7851 | , &[_][]const u8{ |
| 7577 | "tmp.zig:2:5: error: union field missing type", | 7852 | "tmp.zig:2:5: error: union field missing type", |
| 7578 | }); | 7853 | }); |
| 7579 | | 7854 | |
| 7580 | cases.add("extern union given enum tag type", | 7855 | ctx.objErrStage1("extern union given enum tag type", |
| 7581 | \\const Letter = enum { | 7856 | \\const Letter = enum { |
| 7582 | \\ A, | 7857 | \\ A, |
| 7583 | \\ B, | 7858 | \\ B, |
| ... | @@ -7590,12 +7865,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -7590,12 +7865,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7590 | \\}; | 7865 | \\}; |
| 7591 | \\export fn entry() void { | 7866 | \\export fn entry() void { |
| 7592 | \\ var a = Payload { .A = 1234 }; | 7867 | \\ var a = Payload { .A = 1234 }; |
| | 7868 | \\ _ = a; |
| 7593 | \\} | 7869 | \\} |
| 7594 | , &[_][]const u8{ | 7870 | , &[_][]const u8{ |
| 7595 | "tmp.zig:6:30: error: extern union does not support enum tag type", | 7871 | "tmp.zig:6:30: error: extern union does not support enum tag type", |
| 7596 | }); | 7872 | }); |
| 7597 | | 7873 | |
| 7598 | cases.add("packed union given enum tag type", | 7874 | ctx.objErrStage1("packed union given enum tag type", |
| 7599 | \\const Letter = enum { | 7875 | \\const Letter = enum { |
| 7600 | \\ A, | 7876 | \\ A, |
| 7601 | \\ B, | 7877 | \\ B, |
| ... | @@ -7608,12 +7884,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -7608,12 +7884,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7608 | \\}; | 7884 | \\}; |
| 7609 | \\export fn entry() void { | 7885 | \\export fn entry() void { |
| 7610 | \\ var a = Payload { .A = 1234 }; | 7886 | \\ var a = Payload { .A = 1234 }; |
| | 7887 | \\ _ = a; |
| 7611 | \\} | 7888 | \\} |
| 7612 | , &[_][]const u8{ | 7889 | , &[_][]const u8{ |
| 7613 | "tmp.zig:6:30: error: packed union does not support enum tag type", | 7890 | "tmp.zig:6:30: error: packed union does not support enum tag type", |
| 7614 | }); | 7891 | }); |
| 7615 | | 7892 | |
| 7616 | cases.add("packed union with automatic layout field", | 7893 | ctx.objErrStage1("packed union with automatic layout field", |
| 7617 | \\const Foo = struct { | 7894 | \\const Foo = struct { |
| 7618 | \\ a: u32, | 7895 | \\ a: u32, |
| 7619 | \\ b: f32, | 7896 | \\ b: f32, |
| ... | @@ -7624,12 +7901,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -7624,12 +7901,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7624 | \\}; | 7901 | \\}; |
| 7625 | \\export fn entry() void { | 7902 | \\export fn entry() void { |
| 7626 | \\ var a = Payload { .B = true }; | 7903 | \\ var a = Payload { .B = true }; |
| | 7904 | \\ _ = a; |
| 7627 | \\} | 7905 | \\} |
| 7628 | , &[_][]const u8{ | 7906 | , &[_][]const u8{ |
| 7629 | "tmp.zig:6:5: error: non-packed, non-extern struct 'Foo' not allowed in packed union; no guaranteed in-memory representation", | 7907 | "tmp.zig:6:5: error: non-packed, non-extern struct 'Foo' not allowed in packed union; no guaranteed in-memory representation", |
| 7630 | }); | 7908 | }); |
| 7631 | | 7909 | |
| 7632 | cases.add("switch on union with no attached enum", | 7910 | ctx.objErrStage1("switch on union with no attached enum", |
| 7633 | \\const Payload = union { | 7911 | \\const Payload = union { |
| 7634 | \\ A: i32, | 7912 | \\ A: i32, |
| 7635 | \\ B: f64, | 7913 | \\ B: f64, |
| ... | @@ -7650,20 +7928,21 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -7650,20 +7928,21 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7650 | "tmp.zig:1:17: note: consider 'union(enum)' here", | 7928 | "tmp.zig:1:17: note: consider 'union(enum)' here", |
| 7651 | }); | 7929 | }); |
| 7652 | | 7930 | |
| 7653 | cases.add("enum in field count range but not matching tag", | 7931 | ctx.objErrStage1("enum in field count range but not matching tag", |
| 7654 | \\const Foo = enum(u32) { | 7932 | \\const Foo = enum(u32) { |
| 7655 | \\ A = 10, | 7933 | \\ A = 10, |
| 7656 | \\ B = 11, | 7934 | \\ B = 11, |
| 7657 | \\}; | 7935 | \\}; |
| 7658 | \\export fn entry() void { | 7936 | \\export fn entry() void { |
| 7659 | \\ var x = @intToEnum(Foo, 0); | 7937 | \\ var x = @intToEnum(Foo, 0); |
| | 7938 | \\ _ = x; |
| 7660 | \\} | 7939 | \\} |
| 7661 | , &[_][]const u8{ | 7940 | , &[_][]const u8{ |
| 7662 | "tmp.zig:6:13: error: enum 'Foo' has no tag matching integer value 0", | 7941 | "tmp.zig:6:13: error: enum 'Foo' has no tag matching integer value 0", |
| 7663 | "tmp.zig:1:13: note: 'Foo' declared here", | 7942 | "tmp.zig:1:13: note: 'Foo' declared here", |
| 7664 | }); | 7943 | }); |
| 7665 | | 7944 | |
| 7666 | cases.add("comptime cast enum to union but field has payload", | 7945 | ctx.objErrStage1("comptime cast enum to union but field has payload", |
| 7667 | \\const Letter = enum { A, B, C }; | 7946 | \\const Letter = enum { A, B, C }; |
| 7668 | \\const Value = union(Letter) { | 7947 | \\const Value = union(Letter) { |
| 7669 | \\ A: i32, | 7948 | \\ A: i32, |
| ... | @@ -7672,13 +7951,14 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -7672,13 +7951,14 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7672 | \\}; | 7951 | \\}; |
| 7673 | \\export fn entry() void { | 7952 | \\export fn entry() void { |
| 7674 | \\ var x: Value = Letter.A; | 7953 | \\ var x: Value = Letter.A; |
| | 7954 | \\ _ = x; |
| 7675 | \\} | 7955 | \\} |
| 7676 | , &[_][]const u8{ | 7956 | , &[_][]const u8{ |
| 7677 | "tmp.zig:8:26: error: cast to union 'Value' must initialize 'i32' field 'A'", | 7957 | "tmp.zig:8:26: error: cast to union 'Value' must initialize 'i32' field 'A'", |
| 7678 | "tmp.zig:3:5: note: field 'A' declared here", | 7958 | "tmp.zig:3:5: note: field 'A' declared here", |
| 7679 | }); | 7959 | }); |
| 7680 | | 7960 | |
| 7681 | cases.add("runtime cast to union which has non-void fields", | 7961 | ctx.objErrStage1("runtime cast to union which has non-void fields", |
| 7682 | \\const Letter = enum { A, B, C }; | 7962 | \\const Letter = enum { A, B, C }; |
| 7683 | \\const Value = union(Letter) { | 7963 | \\const Value = union(Letter) { |
| 7684 | \\ A: i32, | 7964 | \\ A: i32, |
| ... | @@ -7690,35 +7970,38 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -7690,35 +7970,38 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7690 | \\} | 7970 | \\} |
| 7691 | \\fn foo(l: Letter) void { | 7971 | \\fn foo(l: Letter) void { |
| 7692 | \\ var x: Value = l; | 7972 | \\ var x: Value = l; |
| | 7973 | \\ _ = x; |
| 7693 | \\} | 7974 | \\} |
| 7694 | , &[_][]const u8{ | 7975 | , &[_][]const u8{ |
| 7695 | "tmp.zig:11:20: error: runtime cast to union 'Value' which has non-void fields", | 7976 | "tmp.zig:11:20: error: runtime cast to union 'Value' which has non-void fields", |
| 7696 | "tmp.zig:3:5: note: field 'A' has type 'i32'", | 7977 | "tmp.zig:3:5: note: field 'A' has type 'i32'", |
| 7697 | }); | 7978 | }); |
| 7698 | | 7979 | |
| 7699 | cases.add("taking byte offset of void field in struct", | 7980 | ctx.objErrStage1("taking byte offset of void field in struct", |
| 7700 | \\const Empty = struct { | 7981 | \\const Empty = struct { |
| 7701 | \\ val: void, | 7982 | \\ val: void, |
| 7702 | \\}; | 7983 | \\}; |
| 7703 | \\export fn foo() void { | 7984 | \\export fn foo() void { |
| 7704 | \\ const fieldOffset = @offsetOf(Empty, "val",); | 7985 | \\ const fieldOffset = @offsetOf(Empty, "val",); |
| | 7986 | \\ _ = fieldOffset; |
| 7705 | \\} | 7987 | \\} |
| 7706 | , &[_][]const u8{ | 7988 | , &[_][]const u8{ |
| 7707 | "tmp.zig:5:42: error: zero-bit field 'val' in struct 'Empty' has no offset", | 7989 | "tmp.zig:5:42: error: zero-bit field 'val' in struct 'Empty' has no offset", |
| 7708 | }); | 7990 | }); |
| 7709 | | 7991 | |
| 7710 | cases.add("taking bit offset of void field in struct", | 7992 | ctx.objErrStage1("taking bit offset of void field in struct", |
| 7711 | \\const Empty = struct { | 7993 | \\const Empty = struct { |
| 7712 | \\ val: void, | 7994 | \\ val: void, |
| 7713 | \\}; | 7995 | \\}; |
| 7714 | \\export fn foo() void { | 7996 | \\export fn foo() void { |
| 7715 | \\ const fieldOffset = @bitOffsetOf(Empty, "val",); | 7997 | \\ const fieldOffset = @bitOffsetOf(Empty, "val",); |
| | 7998 | \\ _ = fieldOffset; |
| 7716 | \\} | 7999 | \\} |
| 7717 | , &[_][]const u8{ | 8000 | , &[_][]const u8{ |
| 7718 | "tmp.zig:5:45: error: zero-bit field 'val' in struct 'Empty' has no offset", | 8001 | "tmp.zig:5:45: error: zero-bit field 'val' in struct 'Empty' has no offset", |
| 7719 | }); | 8002 | }); |
| 7720 | | 8003 | |
| 7721 | cases.add("invalid union field access in comptime", | 8004 | ctx.objErrStage1("invalid union field access in comptime", |
| 7722 | \\const Foo = union { | 8005 | \\const Foo = union { |
| 7723 | \\ Bar: u8, | 8006 | \\ Bar: u8, |
| 7724 | \\ Baz: void, | 8007 | \\ Baz: void, |
| ... | @@ -7726,12 +8009,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -7726,12 +8009,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7726 | \\comptime { | 8009 | \\comptime { |
| 7727 | \\ var foo = Foo {.Baz = {}}; | 8010 | \\ var foo = Foo {.Baz = {}}; |
| 7728 | \\ const bar_val = foo.Bar; | 8011 | \\ const bar_val = foo.Bar; |
| | 8012 | \\ _ = bar_val; |
| 7729 | \\} | 8013 | \\} |
| 7730 | , &[_][]const u8{ | 8014 | , &[_][]const u8{ |
| 7731 | "tmp.zig:7:24: error: accessing union field 'Bar' while field 'Baz' is set", | 8015 | "tmp.zig:7:24: error: accessing union field 'Bar' while field 'Baz' is set", |
| 7732 | }); | 8016 | }); |
| 7733 | | 8017 | |
| 7734 | cases.add("unsupported modifier at start of asm output constraint", | 8018 | ctx.objErrStage1("unsupported modifier at start of asm output constraint", |
| 7735 | \\export fn foo() void { | 8019 | \\export fn foo() void { |
| 7736 | \\ var bar: u32 = 3; | 8020 | \\ var bar: u32 = 3; |
| 7737 | \\ asm volatile ("" : [baz]"+r"(bar) : : ""); | 8021 | \\ asm volatile ("" : [baz]"+r"(bar) : : ""); |
| ... | @@ -7740,7 +8024,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -7740,7 +8024,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7740 | "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", | 8024 | "tmp.zig:3:5: error: invalid modifier starting output constraint for 'baz': '+', only '=' is supported. Compiler TODO: see https://github.com/ziglang/zig/issues/215", |
| 7741 | }); | 8025 | }); |
| 7742 | | 8026 | |
| 7743 | cases.add("comptime_int in asm input", | 8027 | ctx.objErrStage1("comptime_int in asm input", |
| 7744 | \\export fn foo() void { | 8028 | \\export fn foo() void { |
| 7745 | \\ asm volatile ("" : : [bar]"r"(3) : ""); | 8029 | \\ asm volatile ("" : : [bar]"r"(3) : ""); |
| 7746 | \\} | 8030 | \\} |
| ... | @@ -7748,7 +8032,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -7748,7 +8032,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7748 | "tmp.zig:2:35: error: expected sized integer or sized float, found comptime_int", | 8032 | "tmp.zig:2:35: error: expected sized integer or sized float, found comptime_int", |
| 7749 | }); | 8033 | }); |
| 7750 | | 8034 | |
| 7751 | cases.add("comptime_float in asm input", | 8035 | ctx.objErrStage1("comptime_float in asm input", |
| 7752 | \\export fn foo() void { | 8036 | \\export fn foo() void { |
| 7753 | \\ asm volatile ("" : : [bar]"r"(3.17) : ""); | 8037 | \\ asm volatile ("" : : [bar]"r"(3.17) : ""); |
| 7754 | \\} | 8038 | \\} |
| ... | @@ -7756,7 +8040,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -7756,7 +8040,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7756 | "tmp.zig:2:35: error: expected sized integer or sized float, found comptime_float", | 8040 | "tmp.zig:2:35: error: expected sized integer or sized float, found comptime_float", |
| 7757 | }); | 8041 | }); |
| 7758 | | 8042 | |
| 7759 | cases.add("runtime assignment to comptime struct type", | 8043 | ctx.objErrStage1("runtime assignment to comptime struct type", |
| 7760 | \\const Foo = struct { | 8044 | \\const Foo = struct { |
| 7761 | \\ Bar: u8, | 8045 | \\ Bar: u8, |
| 7762 | \\ Baz: type, | 8046 | \\ Baz: type, |
| ... | @@ -7764,12 +8048,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -7764,12 +8048,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7764 | \\export fn f() void { | 8048 | \\export fn f() void { |
| 7765 | \\ var x: u8 = 0; | 8049 | \\ var x: u8 = 0; |
| 7766 | \\ const foo = Foo { .Bar = x, .Baz = u8 }; | 8050 | \\ const foo = Foo { .Bar = x, .Baz = u8 }; |
| | 8051 | \\ _ = foo; |
| 7767 | \\} | 8052 | \\} |
| 7768 | , &[_][]const u8{ | 8053 | , &[_][]const u8{ |
| 7769 | "tmp.zig:7:23: error: unable to evaluate constant expression", | 8054 | "tmp.zig:7:23: error: unable to evaluate constant expression", |
| 7770 | }); | 8055 | }); |
| 7771 | | 8056 | |
| 7772 | cases.add("runtime assignment to comptime union type", | 8057 | ctx.objErrStage1("runtime assignment to comptime union type", |
| 7773 | \\const Foo = union { | 8058 | \\const Foo = union { |
| 7774 | \\ Bar: u8, | 8059 | \\ Bar: u8, |
| 7775 | \\ Baz: type, | 8060 | \\ Baz: type, |
| ... | @@ -7777,16 +8062,18 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -7777,16 +8062,18 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7777 | \\export fn f() void { | 8062 | \\export fn f() void { |
| 7778 | \\ var x: u8 = 0; | 8063 | \\ var x: u8 = 0; |
| 7779 | \\ const foo = Foo { .Bar = x }; | 8064 | \\ const foo = Foo { .Bar = x }; |
| | 8065 | \\ _ = foo; |
| 7780 | \\} | 8066 | \\} |
| 7781 | , &[_][]const u8{ | 8067 | , &[_][]const u8{ |
| 7782 | "tmp.zig:7:23: error: unable to evaluate constant expression", | 8068 | "tmp.zig:7:23: error: unable to evaluate constant expression", |
| 7783 | }); | 8069 | }); |
| 7784 | | 8070 | |
| 7785 | cases.addTest("@shuffle with selected index past first vector length", | 8071 | ctx.testErrStage1("@shuffle with selected index past first vector length", |
| 7786 | \\export fn entry() void { | 8072 | \\export fn entry() void { |
| 7787 | \\ const v: @import("std").meta.Vector(4, u32) = [4]u32{ 10, 11, 12, 13 }; | 8073 | \\ const v: @import("std").meta.Vector(4, u32) = [4]u32{ 10, 11, 12, 13 }; |
| 7788 | \\ const x: @import("std").meta.Vector(4, u32) = [4]u32{ 14, 15, 16, 17 }; | 8074 | \\ const x: @import("std").meta.Vector(4, u32) = [4]u32{ 14, 15, 16, 17 }; |
| 7789 | \\ var z = @shuffle(u32, v, x, [8]i32{ 0, 1, 2, 3, 7, 6, 5, 4 }); | 8075 | \\ var z = @shuffle(u32, v, x, [8]i32{ 0, 1, 2, 3, 7, 6, 5, 4 }); |
| | 8076 | \\ _ = z; |
| 7790 | \\} | 8077 | \\} |
| 7791 | , &[_][]const u8{ | 8078 | , &[_][]const u8{ |
| 7792 | "tmp.zig:4:39: error: mask index '4' has out-of-bounds selection", | 8079 | "tmp.zig:4:39: error: mask index '4' has out-of-bounds selection", |
| ... | @@ -7794,27 +8081,29 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -7794,27 +8081,29 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7794 | "tmp.zig:4:30: note: selections from the second vector are specified with negative numbers", | 8081 | "tmp.zig:4:30: note: selections from the second vector are specified with negative numbers", |
| 7795 | }); | 8082 | }); |
| 7796 | | 8083 | |
| 7797 | cases.addTest("nested vectors", | 8084 | ctx.testErrStage1("nested vectors", |
| 7798 | \\export fn entry() void { | 8085 | \\export fn entry() void { |
| 7799 | \\ const V1 = @import("std").meta.Vector(4, u8); | 8086 | \\ const V1 = @import("std").meta.Vector(4, u8); |
| 7800 | \\ const V2 = @Type(@import("std").builtin.TypeInfo{ .Vector = .{ .len = 4, .child = V1 } }); | 8087 | \\ const V2 = @Type(@import("std").builtin.TypeInfo{ .Vector = .{ .len = 4, .child = V1 } }); |
| 7801 | \\ var v: V2 = undefined; | 8088 | \\ var v: V2 = undefined; |
| | 8089 | \\ _ = v; |
| 7802 | \\} | 8090 | \\} |
| 7803 | , &[_][]const u8{ | 8091 | , &[_][]const u8{ |
| 7804 | "tmp.zig:3:53: error: vector element type must be integer, float, bool, or pointer; '@Vector(4, u8)' is invalid", | 8092 | "tmp.zig:3:53: error: vector element type must be integer, float, bool, or pointer; '@Vector(4, u8)' is invalid", |
| 7805 | "tmp.zig:3:16: note: referenced here", | 8093 | "tmp.zig:3:16: note: referenced here", |
| 7806 | }); | 8094 | }); |
| 7807 | | 8095 | |
| 7808 | cases.addTest("bad @splat type", | 8096 | ctx.testErrStage1("bad @splat type", |
| 7809 | \\export fn entry() void { | 8097 | \\export fn entry() void { |
| 7810 | \\ const c = 4; | 8098 | \\ const c = 4; |
| 7811 | \\ var v = @splat(4, c); | 8099 | \\ var v = @splat(4, c); |
| | 8100 | \\ _ = v; |
| 7812 | \\} | 8101 | \\} |
| 7813 | , &[_][]const u8{ | 8102 | , &[_][]const u8{ |
| 7814 | "tmp.zig:3:23: error: vector element type must be integer, float, bool, or pointer; 'comptime_int' is invalid", | 8103 | "tmp.zig:3:23: error: vector element type must be integer, float, bool, or pointer; 'comptime_int' is invalid", |
| 7815 | }); | 8104 | }); |
| 7816 | | 8105 | |
| 7817 | cases.add("compileLog of tagged enum doesn't crash the compiler", | 8106 | ctx.objErrStage1("compileLog of tagged enum doesn't crash the compiler", |
| 7818 | \\const Bar = union(enum(u32)) { | 8107 | \\const Bar = union(enum(u32)) { |
| 7819 | \\ X: i32 = 1 | 8108 | \\ X: i32 = 1 |
| 7820 | \\}; | 8109 | \\}; |
| ... | @@ -7830,28 +8119,30 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -7830,28 +8119,30 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7830 | "tmp.zig:6:5: error: found compile log statement", | 8119 | "tmp.zig:6:5: error: found compile log statement", |
| 7831 | }); | 8120 | }); |
| 7832 | | 8121 | |
| 7833 | cases.add("attempted implicit cast from *const T to *[1]T", | 8122 | ctx.objErrStage1("attempted implicit cast from *const T to *[1]T", |
| 7834 | \\export fn entry(byte: u8) void { | 8123 | \\export fn entry(byte: u8) void { |
| 7835 | \\ const w: i32 = 1234; | 8124 | \\ const w: i32 = 1234; |
| 7836 | \\ var x: *const i32 = &w; | 8125 | \\ var x: *const i32 = &w; |
| 7837 | \\ var y: *[1]i32 = x; | 8126 | \\ var y: *[1]i32 = x; |
| 7838 | \\ y[0] += 1; | 8127 | \\ y[0] += 1; |
| | 8128 | \\ _ = byte; |
| 7839 | \\} | 8129 | \\} |
| 7840 | , &[_][]const u8{ | 8130 | , &[_][]const u8{ |
| 7841 | "tmp.zig:4:22: error: expected type '*[1]i32', found '*const i32'", | 8131 | "tmp.zig:4:22: error: expected type '*[1]i32', found '*const i32'", |
| 7842 | "tmp.zig:4:22: note: cast discards const qualifier", | 8132 | "tmp.zig:4:22: note: cast discards const qualifier", |
| 7843 | }); | 8133 | }); |
| 7844 | | 8134 | |
| 7845 | cases.add("attempted implicit cast from *const T to []T", | 8135 | ctx.objErrStage1("attempted implicit cast from *const T to []T", |
| 7846 | \\export fn entry() void { | 8136 | \\export fn entry() void { |
| 7847 | \\ const u: u32 = 42; | 8137 | \\ const u: u32 = 42; |
| 7848 | \\ const x: []u32 = &u; | 8138 | \\ const x: []u32 = &u; |
| | 8139 | \\ _ = x; |
| 7849 | \\} | 8140 | \\} |
| 7850 | , &[_][]const u8{ | 8141 | , &[_][]const u8{ |
| 7851 | "tmp.zig:3:23: error: expected type '[]u32', found '*const u32'", | 8142 | "tmp.zig:3:23: error: expected type '[]u32', found '*const u32'", |
| 7852 | }); | 8143 | }); |
| 7853 | | 8144 | |
| 7854 | cases.add("for loop body expression ignored", | 8145 | ctx.objErrStage1("for loop body expression ignored", |
| 7855 | \\fn returns() usize { | 8146 | \\fn returns() usize { |
| 7856 | \\ return 2; | 8147 | \\ return 2; |
| 7857 | \\} | 8148 | \\} |
| ... | @@ -7861,21 +8152,23 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -7861,21 +8152,23 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7861 | \\export fn f2() void { | 8152 | \\export fn f2() void { |
| 7862 | \\ var x: anyerror!i32 = error.Bad; | 8153 | \\ var x: anyerror!i32 = error.Bad; |
| 7863 | \\ for ("hello") |_| returns() else unreachable; | 8154 | \\ for ("hello") |_| returns() else unreachable; |
| | 8155 | \\ _ = x; |
| 7864 | \\} | 8156 | \\} |
| 7865 | , &[_][]const u8{ | 8157 | , &[_][]const u8{ |
| 7866 | "tmp.zig:5:30: error: expression value is ignored", | 8158 | "tmp.zig:5:30: error: expression value is ignored", |
| 7867 | "tmp.zig:9:30: error: expression value is ignored", | 8159 | "tmp.zig:9:30: error: expression value is ignored", |
| 7868 | }); | 8160 | }); |
| 7869 | | 8161 | |
| 7870 | cases.add("aligned variable of zero-bit type", | 8162 | ctx.objErrStage1("aligned variable of zero-bit type", |
| 7871 | \\export fn f() void { | 8163 | \\export fn f() void { |
| 7872 | \\ var s: struct {} align(4) = undefined; | 8164 | \\ var s: struct {} align(4) = undefined; |
| | 8165 | \\ _ = s; |
| 7873 | \\} | 8166 | \\} |
| 7874 | , &[_][]const u8{ | 8167 | , &[_][]const u8{ |
| 7875 | "tmp.zig:2:5: error: variable 's' of zero-bit type 'struct:2:12' has no in-memory representation, it cannot be aligned", | 8168 | "tmp.zig:2:5: error: variable 's' of zero-bit type 'struct:2:12' has no in-memory representation, it cannot be aligned", |
| 7876 | }); | 8169 | }); |
| 7877 | | 8170 | |
| 7878 | cases.add("function returning opaque type", | 8171 | ctx.objErrStage1("function returning opaque type", |
| 7879 | \\const FooType = opaque {}; | 8172 | \\const FooType = opaque {}; |
| 7880 | \\export fn bar() !FooType { | 8173 | \\export fn bar() !FooType { |
| 7881 | \\ return error.InvalidValue; | 8174 | \\ return error.InvalidValue; |
| ... | @@ -7893,7 +8186,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -7893,7 +8186,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7893 | "tmp.zig:8:18: error: Undefined return type '(undefined)' not allowed", | 8186 | "tmp.zig:8:18: error: Undefined return type '(undefined)' not allowed", |
| 7894 | }); | 8187 | }); |
| 7895 | | 8188 | |
| 7896 | cases.add("generic function returning opaque type", | 8189 | ctx.objErrStage1("generic function returning opaque type", |
| 7897 | \\const FooType = opaque {}; | 8190 | \\const FooType = opaque {}; |
| 7898 | \\fn generic(comptime T: type) !T { | 8191 | \\fn generic(comptime T: type) !T { |
| 7899 | \\ return undefined; | 8192 | \\ return undefined; |
| ... | @@ -7917,81 +8210,89 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -7917,81 +8210,89 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7917 | "tmp.zig:2:1: note: function declared here", | 8210 | "tmp.zig:2:1: note: function declared here", |
| 7918 | }); | 8211 | }); |
| 7919 | | 8212 | |
| 7920 | cases.add("function parameter is opaque", | 8213 | ctx.objErrStage1("function parameter is opaque", |
| 7921 | \\const FooType = opaque {}; | 8214 | \\const FooType = opaque {}; |
| 7922 | \\export fn entry1() void { | 8215 | \\export fn entry1() void { |
| 7923 | \\ const someFuncPtr: fn (FooType) void = undefined; | 8216 | \\ const someFuncPtr: fn (FooType) void = undefined; |
| | 8217 | \\ _ = someFuncPtr; |
| 7924 | \\} | 8218 | \\} |
| 7925 | \\ | 8219 | \\ |
| 7926 | \\export fn entry2() void { | 8220 | \\export fn entry2() void { |
| 7927 | \\ const someFuncPtr: fn (@TypeOf(null)) void = undefined; | 8221 | \\ const someFuncPtr: fn (@TypeOf(null)) void = undefined; |
| | 8222 | \\ _ = someFuncPtr; |
| 7928 | \\} | 8223 | \\} |
| 7929 | \\ | 8224 | \\ |
| 7930 | \\fn foo(p: FooType) void {} | 8225 | \\fn foo(p: FooType) void {_ = p;} |
| 7931 | \\export fn entry3() void { | 8226 | \\export fn entry3() void { |
| 7932 | \\ _ = foo; | 8227 | \\ _ = foo; |
| 7933 | \\} | 8228 | \\} |
| 7934 | \\ | 8229 | \\ |
| 7935 | \\fn bar(p: @TypeOf(null)) void {} | 8230 | \\fn bar(p: @TypeOf(null)) void {_ = p;} |
| 7936 | \\export fn entry4() void { | 8231 | \\export fn entry4() void { |
| 7937 | \\ _ = bar; | 8232 | \\ _ = bar; |
| 7938 | \\} | 8233 | \\} |
| 7939 | , &[_][]const u8{ | 8234 | , &[_][]const u8{ |
| 7940 | "tmp.zig:3:28: error: parameter of opaque type 'FooType' not allowed", | 8235 | "tmp.zig:3:28: error: parameter of opaque type 'FooType' not allowed", |
| 7941 | "tmp.zig:7:28: error: parameter of type '(null)' not allowed", | 8236 | "tmp.zig:8:28: error: parameter of type '(null)' not allowed", |
| 7942 | "tmp.zig:10:11: error: parameter of opaque type 'FooType' not allowed", | 8237 | "tmp.zig:12:11: error: parameter of opaque type 'FooType' not allowed", |
| 7943 | "tmp.zig:15:11: error: parameter of type '(null)' not allowed", | 8238 | "tmp.zig:17:11: error: parameter of type '(null)' not allowed", |
| 7944 | }); | 8239 | }); |
| 7945 | | 8240 | |
| 7946 | cases.add( // fixed bug #2032 | 8241 | ctx.objErrStage1( // fixed bug #2032 |
| 7947 | "compile diagnostic string for top level decl type", | 8242 | "compile diagnostic string for top level decl type", |
| 7948 | \\export fn entry() void { | 8243 | \\export fn entry() void { |
| 7949 | \\ var foo: u32 = @This(){}; | 8244 | \\ var foo: u32 = @This(){}; |
| | 8245 | \\ _ = foo; |
| 7950 | \\} | 8246 | \\} |
| 7951 | , &[_][]const u8{ | 8247 | , &[_][]const u8{ |
| 7952 | "tmp.zig:2:27: error: type 'u32' does not support array initialization", | 8248 | "tmp.zig:2:27: error: type 'u32' does not support array initialization", |
| 7953 | }); | 8249 | }); |
| 7954 | | 8250 | |
| 7955 | cases.add("issue #2687: coerce from undefined array pointer to slice", | 8251 | ctx.objErrStage1("issue #2687: coerce from undefined array pointer to slice", |
| 7956 | \\export fn foo1() void { | 8252 | \\export fn foo1() void { |
| 7957 | \\ const a: *[1]u8 = undefined; | 8253 | \\ const a: *[1]u8 = undefined; |
| 7958 | \\ var b: []u8 = a; | 8254 | \\ var b: []u8 = a; |
| | 8255 | \\ _ = b; |
| 7959 | \\} | 8256 | \\} |
| 7960 | \\export fn foo2() void { | 8257 | \\export fn foo2() void { |
| 7961 | \\ comptime { | 8258 | \\ comptime { |
| 7962 | \\ var a: *[1]u8 = undefined; | 8259 | \\ var a: *[1]u8 = undefined; |
| 7963 | \\ var b: []u8 = a; | 8260 | \\ var b: []u8 = a; |
| | 8261 | \\ _ = b; |
| 7964 | \\ } | 8262 | \\ } |
| 7965 | \\} | 8263 | \\} |
| 7966 | \\export fn foo3() void { | 8264 | \\export fn foo3() void { |
| 7967 | \\ comptime { | 8265 | \\ comptime { |
| 7968 | \\ const a: *[1]u8 = undefined; | 8266 | \\ const a: *[1]u8 = undefined; |
| 7969 | \\ var b: []u8 = a; | 8267 | \\ var b: []u8 = a; |
| | 8268 | \\ _ = b; |
| 7970 | \\ } | 8269 | \\ } |
| 7971 | \\} | 8270 | \\} |
| 7972 | , &[_][]const u8{ | 8271 | , &[_][]const u8{ |
| 7973 | "tmp.zig:3:19: error: use of undefined value here causes undefined behavior", | 8272 | "tmp.zig:3:19: error: use of undefined value here causes undefined behavior", |
| 7974 | "tmp.zig:8:23: error: use of undefined value here causes undefined behavior", | 8273 | "tmp.zig:9:23: error: use of undefined value here causes undefined behavior", |
| 7975 | "tmp.zig:14:23: error: use of undefined value here causes undefined behavior", | 8274 | "tmp.zig:16:23: error: use of undefined value here causes undefined behavior", |
| 7976 | }); | 8275 | }); |
| 7977 | | 8276 | |
| 7978 | cases.add("issue #3818: bitcast from parray/slice to u16", | 8277 | ctx.objErrStage1("issue #3818: bitcast from parray/slice to u16", |
| 7979 | \\export fn foo1() void { | 8278 | \\export fn foo1() void { |
| 7980 | \\ var bytes = [_]u8{1, 2}; | 8279 | \\ var bytes = [_]u8{1, 2}; |
| 7981 | \\ const word: u16 = @bitCast(u16, bytes[0..]); | 8280 | \\ const word: u16 = @bitCast(u16, bytes[0..]); |
| | 8281 | \\ _ = word; |
| 7982 | \\} | 8282 | \\} |
| 7983 | \\export fn foo2() void { | 8283 | \\export fn foo2() void { |
| 7984 | \\ var bytes: []const u8 = &[_]u8{1, 2}; | 8284 | \\ var bytes: []const u8 = &[_]u8{1, 2}; |
| 7985 | \\ const word: u16 = @bitCast(u16, bytes); | 8285 | \\ const word: u16 = @bitCast(u16, bytes); |
| | 8286 | \\ _ = word; |
| 7986 | \\} | 8287 | \\} |
| 7987 | , &[_][]const u8{ | 8288 | , &[_][]const u8{ |
| 7988 | "tmp.zig:3:42: error: unable to @bitCast from pointer type '*[2]u8'", | 8289 | "tmp.zig:3:42: error: unable to @bitCast from pointer type '*[2]u8'", |
| 7989 | "tmp.zig:7:32: error: destination type 'u16' has size 2 but source type '[]const u8' has size 16", | 8290 | "tmp.zig:8:32: error: destination type 'u16' has size 2 but source type '[]const u8' has size 16", |
| 7990 | "tmp.zig:7:37: note: referenced here", | 8291 | "tmp.zig:8:37: note: referenced here", |
| 7991 | }); | 8292 | }); |
| 7992 | | 8293 | |
| 7993 | // issue #7810 | 8294 | // issue #7810 |
| 7994 | cases.add("comptime slice-len increment beyond bounds", | 8295 | ctx.objErrStage1("comptime slice-len increment beyond bounds", |
| 7995 | \\export fn foo_slice_len_increment_beyond_bounds() void { | 8296 | \\export fn foo_slice_len_increment_beyond_bounds() void { |
| 7996 | \\ comptime { | 8297 | \\ comptime { |
| 7997 | \\ var buf_storage: [8]u8 = undefined; | 8298 | \\ var buf_storage: [8]u8 = undefined; |
| ... | @@ -8004,11 +8305,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -8004,11 +8305,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 8004 | ":6:12: error: out of bounds slice", | 8305 | ":6:12: error: out of bounds slice", |
| 8005 | }); | 8306 | }); |
| 8006 | | 8307 | |
| 8007 | cases.add("comptime slice-sentinel is out of bounds (unterminated)", | 8308 | ctx.objErrStage1("comptime slice-sentinel is out of bounds (unterminated)", |
| 8008 | \\export fn foo_array() void { | 8309 | \\export fn foo_array() void { |
| 8009 | \\ comptime { | 8310 | \\ comptime { |
| 8010 | \\ var target = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; | 8311 | \\ var target = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; |
| 8011 | \\ const slice = target[0..14 :0]; | 8312 | \\ const slice = target[0..14 :0]; |
| | 8313 | \\ _ = slice; |
| 8012 | \\ } | 8314 | \\ } |
| 8013 | \\} | 8315 | \\} |
| 8014 | \\export fn foo_ptr_array() void { | 8316 | \\export fn foo_ptr_array() void { |
| ... | @@ -8016,6 +8318,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -8016,6 +8318,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 8016 | \\ var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; | 8318 | \\ var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; |
| 8017 | \\ var target = &buf; | 8319 | \\ var target = &buf; |
| 8018 | \\ const slice = target[0..14 :0]; | 8320 | \\ const slice = target[0..14 :0]; |
| | 8321 | \\ _ = slice; |
| 8019 | \\ } | 8322 | \\ } |
| 8020 | \\} | 8323 | \\} |
| 8021 | \\export fn foo_vector_ConstPtrSpecialBaseArray() void { | 8324 | \\export fn foo_vector_ConstPtrSpecialBaseArray() void { |
| ... | @@ -8023,6 +8326,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -8023,6 +8326,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 8023 | \\ var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; | 8326 | \\ var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; |
| 8024 | \\ var target: [*]u8 = &buf; | 8327 | \\ var target: [*]u8 = &buf; |
| 8025 | \\ const slice = target[0..14 :0]; | 8328 | \\ const slice = target[0..14 :0]; |
| | 8329 | \\ _ = slice; |
| 8026 | \\ } | 8330 | \\ } |
| 8027 | \\} | 8331 | \\} |
| 8028 | \\export fn foo_vector_ConstPtrSpecialRef() void { | 8332 | \\export fn foo_vector_ConstPtrSpecialRef() void { |
| ... | @@ -8030,6 +8334,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -8030,6 +8334,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 8030 | \\ var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; | 8334 | \\ var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; |
| 8031 | \\ var target: [*]u8 = @ptrCast([*]u8, &buf); | 8335 | \\ var target: [*]u8 = @ptrCast([*]u8, &buf); |
| 8032 | \\ const slice = target[0..14 :0]; | 8336 | \\ const slice = target[0..14 :0]; |
| | 8337 | \\ _ = slice; |
| 8033 | \\ } | 8338 | \\ } |
| 8034 | \\} | 8339 | \\} |
| 8035 | \\export fn foo_cvector_ConstPtrSpecialBaseArray() void { | 8340 | \\export fn foo_cvector_ConstPtrSpecialBaseArray() void { |
| ... | @@ -8037,6 +8342,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -8037,6 +8342,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 8037 | \\ var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; | 8342 | \\ var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; |
| 8038 | \\ var target: [*c]u8 = &buf; | 8343 | \\ var target: [*c]u8 = &buf; |
| 8039 | \\ const slice = target[0..14 :0]; | 8344 | \\ const slice = target[0..14 :0]; |
| | 8345 | \\ _ = slice; |
| 8040 | \\ } | 8346 | \\ } |
| 8041 | \\} | 8347 | \\} |
| 8042 | \\export fn foo_cvector_ConstPtrSpecialRef() void { | 8348 | \\export fn foo_cvector_ConstPtrSpecialRef() void { |
| ... | @@ -8044,6 +8350,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -8044,6 +8350,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 8044 | \\ var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; | 8350 | \\ var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; |
| 8045 | \\ var target: [*c]u8 = @ptrCast([*c]u8, &buf); | 8351 | \\ var target: [*c]u8 = @ptrCast([*c]u8, &buf); |
| 8046 | \\ const slice = target[0..14 :0]; | 8352 | \\ const slice = target[0..14 :0]; |
| | 8353 | \\ _ = slice; |
| 8047 | \\ } | 8354 | \\ } |
| 8048 | \\} | 8355 | \\} |
| 8049 | \\export fn foo_slice() void { | 8356 | \\export fn foo_slice() void { |
| ... | @@ -8051,23 +8358,25 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -8051,23 +8358,25 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 8051 | \\ var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; | 8358 | \\ var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; |
| 8052 | \\ var target: []u8 = &buf; | 8359 | \\ var target: []u8 = &buf; |
| 8053 | \\ const slice = target[0..14 :0]; | 8360 | \\ const slice = target[0..14 :0]; |
| | 8361 | \\ _ = slice; |
| 8054 | \\ } | 8362 | \\ } |
| 8055 | \\} | 8363 | \\} |
| 8056 | , &[_][]const u8{ | 8364 | , &[_][]const u8{ |
| 8057 | ":4:29: error: slice-sentinel is out of bounds", | 8365 | ":4:29: error: slice-sentinel is out of bounds", |
| 8058 | ":11:29: error: slice-sentinel is out of bounds", | 8366 | ":12:29: error: slice-sentinel is out of bounds", |
| 8059 | ":18:29: error: slice-sentinel is out of bounds", | 8367 | ":20:29: error: slice-sentinel is out of bounds", |
| 8060 | ":25:29: error: slice-sentinel is out of bounds", | 8368 | ":28:29: error: slice-sentinel is out of bounds", |
| 8061 | ":32:29: error: slice-sentinel is out of bounds", | 8369 | ":36:29: error: slice-sentinel is out of bounds", |
| 8062 | ":39:29: error: slice-sentinel is out of bounds", | 8370 | ":44:29: error: slice-sentinel is out of bounds", |
| 8063 | ":46:29: error: slice-sentinel is out of bounds", | 8371 | ":52:29: error: slice-sentinel is out of bounds", |
| 8064 | }); | 8372 | }); |
| 8065 | | 8373 | |
| 8066 | cases.add("comptime slice-sentinel is out of bounds (terminated)", | 8374 | ctx.objErrStage1("comptime slice-sentinel is out of bounds (terminated)", |
| 8067 | \\export fn foo_array() void { | 8375 | \\export fn foo_array() void { |
| 8068 | \\ comptime { | 8376 | \\ comptime { |
| 8069 | \\ var target = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; | 8377 | \\ var target = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; |
| 8070 | \\ const slice = target[0..15 :1]; | 8378 | \\ const slice = target[0..15 :1]; |
| | 8379 | \\ _ = slice; |
| 8071 | \\ } | 8380 | \\ } |
| 8072 | \\} | 8381 | \\} |
| 8073 | \\export fn foo_ptr_array() void { | 8382 | \\export fn foo_ptr_array() void { |
| ... | @@ -8075,6 +8384,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -8075,6 +8384,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 8075 | \\ var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; | 8384 | \\ var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; |
| 8076 | \\ var target = &buf; | 8385 | \\ var target = &buf; |
| 8077 | \\ const slice = target[0..15 :0]; | 8386 | \\ const slice = target[0..15 :0]; |
| | 8387 | \\ _ = slice; |
| 8078 | \\ } | 8388 | \\ } |
| 8079 | \\} | 8389 | \\} |
| 8080 | \\export fn foo_vector_ConstPtrSpecialBaseArray() void { | 8390 | \\export fn foo_vector_ConstPtrSpecialBaseArray() void { |
| ... | @@ -8082,6 +8392,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -8082,6 +8392,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 8082 | \\ var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; | 8392 | \\ var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; |
| 8083 | \\ var target: [*]u8 = &buf; | 8393 | \\ var target: [*]u8 = &buf; |
| 8084 | \\ const slice = target[0..15 :0]; | 8394 | \\ const slice = target[0..15 :0]; |
| | 8395 | \\ _ = slice; |
| 8085 | \\ } | 8396 | \\ } |
| 8086 | \\} | 8397 | \\} |
| 8087 | \\export fn foo_vector_ConstPtrSpecialRef() void { | 8398 | \\export fn foo_vector_ConstPtrSpecialRef() void { |
| ... | @@ -8089,6 +8400,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -8089,6 +8400,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 8089 | \\ var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; | 8400 | \\ var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; |
| 8090 | \\ var target: [*]u8 = @ptrCast([*]u8, &buf); | 8401 | \\ var target: [*]u8 = @ptrCast([*]u8, &buf); |
| 8091 | \\ const slice = target[0..15 :0]; | 8402 | \\ const slice = target[0..15 :0]; |
| | 8403 | \\ _ = slice; |
| 8092 | \\ } | 8404 | \\ } |
| 8093 | \\} | 8405 | \\} |
| 8094 | \\export fn foo_cvector_ConstPtrSpecialBaseArray() void { | 8406 | \\export fn foo_cvector_ConstPtrSpecialBaseArray() void { |
| ... | @@ -8096,6 +8408,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -8096,6 +8408,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 8096 | \\ var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; | 8408 | \\ var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; |
| 8097 | \\ var target: [*c]u8 = &buf; | 8409 | \\ var target: [*c]u8 = &buf; |
| 8098 | \\ const slice = target[0..15 :0]; | 8410 | \\ const slice = target[0..15 :0]; |
| | 8411 | \\ _ = slice; |
| 8099 | \\ } | 8412 | \\ } |
| 8100 | \\} | 8413 | \\} |
| 8101 | \\export fn foo_cvector_ConstPtrSpecialRef() void { | 8414 | \\export fn foo_cvector_ConstPtrSpecialRef() void { |
| ... | @@ -8103,6 +8416,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -8103,6 +8416,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 8103 | \\ var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; | 8416 | \\ var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; |
| 8104 | \\ var target: [*c]u8 = @ptrCast([*c]u8, &buf); | 8417 | \\ var target: [*c]u8 = @ptrCast([*c]u8, &buf); |
| 8105 | \\ const slice = target[0..15 :0]; | 8418 | \\ const slice = target[0..15 :0]; |
| | 8419 | \\ _ = slice; |
| 8106 | \\ } | 8420 | \\ } |
| 8107 | \\} | 8421 | \\} |
| 8108 | \\export fn foo_slice() void { | 8422 | \\export fn foo_slice() void { |
| ... | @@ -8110,23 +8424,25 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -8110,23 +8424,25 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 8110 | \\ var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; | 8424 | \\ var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; |
| 8111 | \\ var target: []u8 = &buf; | 8425 | \\ var target: []u8 = &buf; |
| 8112 | \\ const slice = target[0..15 :0]; | 8426 | \\ const slice = target[0..15 :0]; |
| | 8427 | \\ _ = slice; |
| 8113 | \\ } | 8428 | \\ } |
| 8114 | \\} | 8429 | \\} |
| 8115 | , &[_][]const u8{ | 8430 | , &[_][]const u8{ |
| 8116 | ":4:29: error: out of bounds slice", | 8431 | ":4:29: error: out of bounds slice", |
| 8117 | ":11:29: error: out of bounds slice", | 8432 | ":12:29: error: out of bounds slice", |
| 8118 | ":18:29: error: out of bounds slice", | 8433 | ":20:29: error: out of bounds slice", |
| 8119 | ":25:29: error: out of bounds slice", | 8434 | ":28:29: error: out of bounds slice", |
| 8120 | ":32:29: error: out of bounds slice", | 8435 | ":36:29: error: out of bounds slice", |
| 8121 | ":39:29: error: out of bounds slice", | 8436 | ":44:29: error: out of bounds slice", |
| 8122 | ":46:29: error: out of bounds slice", | 8437 | ":52:29: error: out of bounds slice", |
| 8123 | }); | 8438 | }); |
| 8124 | | 8439 | |
| 8125 | cases.add("comptime slice-sentinel does not match memory at target index (unterminated)", | 8440 | ctx.objErrStage1("comptime slice-sentinel does not match memory at target index (unterminated)", |
| 8126 | \\export fn foo_array() void { | 8441 | \\export fn foo_array() void { |
| 8127 | \\ comptime { | 8442 | \\ comptime { |
| 8128 | \\ var target = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; | 8443 | \\ var target = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; |
| 8129 | \\ const slice = target[0..3 :0]; | 8444 | \\ const slice = target[0..3 :0]; |
| | 8445 | \\ _ = slice; |
| 8130 | \\ } | 8446 | \\ } |
| 8131 | \\} | 8447 | \\} |
| 8132 | \\export fn foo_ptr_array() void { | 8448 | \\export fn foo_ptr_array() void { |
| ... | @@ -8134,6 +8450,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -8134,6 +8450,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 8134 | \\ var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; | 8450 | \\ var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; |
| 8135 | \\ var target = &buf; | 8451 | \\ var target = &buf; |
| 8136 | \\ const slice = target[0..3 :0]; | 8452 | \\ const slice = target[0..3 :0]; |
| | 8453 | \\ _ = slice; |
| 8137 | \\ } | 8454 | \\ } |
| 8138 | \\} | 8455 | \\} |
| 8139 | \\export fn foo_vector_ConstPtrSpecialBaseArray() void { | 8456 | \\export fn foo_vector_ConstPtrSpecialBaseArray() void { |
| ... | @@ -8141,6 +8458,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -8141,6 +8458,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 8141 | \\ var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; | 8458 | \\ var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; |
| 8142 | \\ var target: [*]u8 = &buf; | 8459 | \\ var target: [*]u8 = &buf; |
| 8143 | \\ const slice = target[0..3 :0]; | 8460 | \\ const slice = target[0..3 :0]; |
| | 8461 | \\ _ = slice; |
| 8144 | \\ } | 8462 | \\ } |
| 8145 | \\} | 8463 | \\} |
| 8146 | \\export fn foo_vector_ConstPtrSpecialRef() void { | 8464 | \\export fn foo_vector_ConstPtrSpecialRef() void { |
| ... | @@ -8148,6 +8466,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -8148,6 +8466,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 8148 | \\ var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; | 8466 | \\ var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; |
| 8149 | \\ var target: [*]u8 = @ptrCast([*]u8, &buf); | 8467 | \\ var target: [*]u8 = @ptrCast([*]u8, &buf); |
| 8150 | \\ const slice = target[0..3 :0]; | 8468 | \\ const slice = target[0..3 :0]; |
| | 8469 | \\ _ = slice; |
| 8151 | \\ } | 8470 | \\ } |
| 8152 | \\} | 8471 | \\} |
| 8153 | \\export fn foo_cvector_ConstPtrSpecialBaseArray() void { | 8472 | \\export fn foo_cvector_ConstPtrSpecialBaseArray() void { |
| ... | @@ -8155,6 +8474,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -8155,6 +8474,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 8155 | \\ var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; | 8474 | \\ var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; |
| 8156 | \\ var target: [*c]u8 = &buf; | 8475 | \\ var target: [*c]u8 = &buf; |
| 8157 | \\ const slice = target[0..3 :0]; | 8476 | \\ const slice = target[0..3 :0]; |
| | 8477 | \\ _ = slice; |
| 8158 | \\ } | 8478 | \\ } |
| 8159 | \\} | 8479 | \\} |
| 8160 | \\export fn foo_cvector_ConstPtrSpecialRef() void { | 8480 | \\export fn foo_cvector_ConstPtrSpecialRef() void { |
| ... | @@ -8162,6 +8482,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -8162,6 +8482,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 8162 | \\ var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; | 8482 | \\ var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; |
| 8163 | \\ var target: [*c]u8 = @ptrCast([*c]u8, &buf); | 8483 | \\ var target: [*c]u8 = @ptrCast([*c]u8, &buf); |
| 8164 | \\ const slice = target[0..3 :0]; | 8484 | \\ const slice = target[0..3 :0]; |
| | 8485 | \\ _ = slice; |
| 8165 | \\ } | 8486 | \\ } |
| 8166 | \\} | 8487 | \\} |
| 8167 | \\export fn foo_slice() void { | 8488 | \\export fn foo_slice() void { |
| ... | @@ -8169,23 +8490,25 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -8169,23 +8490,25 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 8169 | \\ var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; | 8490 | \\ var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; |
| 8170 | \\ var target: []u8 = &buf; | 8491 | \\ var target: []u8 = &buf; |
| 8171 | \\ const slice = target[0..3 :0]; | 8492 | \\ const slice = target[0..3 :0]; |
| | 8493 | \\ _ = slice; |
| 8172 | \\ } | 8494 | \\ } |
| 8173 | \\} | 8495 | \\} |
| 8174 | , &[_][]const u8{ | 8496 | , &[_][]const u8{ |
| 8175 | ":4:29: error: slice-sentinel does not match memory at target index", | 8497 | ":4:29: error: slice-sentinel does not match memory at target index", |
| 8176 | ":11:29: error: slice-sentinel does not match memory at target index", | 8498 | ":12:29: error: slice-sentinel does not match memory at target index", |
| 8177 | ":18:29: error: slice-sentinel does not match memory at target index", | 8499 | ":20:29: error: slice-sentinel does not match memory at target index", |
| 8178 | ":25:29: error: slice-sentinel does not match memory at target index", | 8500 | ":28:29: error: slice-sentinel does not match memory at target index", |
| 8179 | ":32:29: error: slice-sentinel does not match memory at target index", | 8501 | ":36:29: error: slice-sentinel does not match memory at target index", |
| 8180 | ":39:29: error: slice-sentinel does not match memory at target index", | 8502 | ":44:29: error: slice-sentinel does not match memory at target index", |
| 8181 | ":46:29: error: slice-sentinel does not match memory at target index", | 8503 | ":52:29: error: slice-sentinel does not match memory at target index", |
| 8182 | }); | 8504 | }); |
| 8183 | | 8505 | |
| 8184 | cases.add("comptime slice-sentinel does not match memory at target index (terminated)", | 8506 | ctx.objErrStage1("comptime slice-sentinel does not match memory at target index (terminated)", |
| 8185 | \\export fn foo_array() void { | 8507 | \\export fn foo_array() void { |
| 8186 | \\ comptime { | 8508 | \\ comptime { |
| 8187 | \\ var target = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; | 8509 | \\ var target = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; |
| 8188 | \\ const slice = target[0..3 :0]; | 8510 | \\ const slice = target[0..3 :0]; |
| | 8511 | \\ _ = slice; |
| 8189 | \\ } | 8512 | \\ } |
| 8190 | \\} | 8513 | \\} |
| 8191 | \\export fn foo_ptr_array() void { | 8514 | \\export fn foo_ptr_array() void { |
| ... | @@ -8193,6 +8516,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -8193,6 +8516,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 8193 | \\ var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; | 8516 | \\ var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; |
| 8194 | \\ var target = &buf; | 8517 | \\ var target = &buf; |
| 8195 | \\ const slice = target[0..3 :0]; | 8518 | \\ const slice = target[0..3 :0]; |
| | 8519 | \\ _ = slice; |
| 8196 | \\ } | 8520 | \\ } |
| 8197 | \\} | 8521 | \\} |
| 8198 | \\export fn foo_vector_ConstPtrSpecialBaseArray() void { | 8522 | \\export fn foo_vector_ConstPtrSpecialBaseArray() void { |
| ... | @@ -8200,6 +8524,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -8200,6 +8524,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 8200 | \\ var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; | 8524 | \\ var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; |
| 8201 | \\ var target: [*]u8 = &buf; | 8525 | \\ var target: [*]u8 = &buf; |
| 8202 | \\ const slice = target[0..3 :0]; | 8526 | \\ const slice = target[0..3 :0]; |
| | 8527 | \\ _ = slice; |
| 8203 | \\ } | 8528 | \\ } |
| 8204 | \\} | 8529 | \\} |
| 8205 | \\export fn foo_vector_ConstPtrSpecialRef() void { | 8530 | \\export fn foo_vector_ConstPtrSpecialRef() void { |
| ... | @@ -8207,6 +8532,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -8207,6 +8532,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 8207 | \\ var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; | 8532 | \\ var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; |
| 8208 | \\ var target: [*]u8 = @ptrCast([*]u8, &buf); | 8533 | \\ var target: [*]u8 = @ptrCast([*]u8, &buf); |
| 8209 | \\ const slice = target[0..3 :0]; | 8534 | \\ const slice = target[0..3 :0]; |
| | 8535 | \\ _ = slice; |
| 8210 | \\ } | 8536 | \\ } |
| 8211 | \\} | 8537 | \\} |
| 8212 | \\export fn foo_cvector_ConstPtrSpecialBaseArray() void { | 8538 | \\export fn foo_cvector_ConstPtrSpecialBaseArray() void { |
| ... | @@ -8214,6 +8540,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -8214,6 +8540,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 8214 | \\ var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; | 8540 | \\ var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; |
| 8215 | \\ var target: [*c]u8 = &buf; | 8541 | \\ var target: [*c]u8 = &buf; |
| 8216 | \\ const slice = target[0..3 :0]; | 8542 | \\ const slice = target[0..3 :0]; |
| | 8543 | \\ _ = slice; |
| 8217 | \\ } | 8544 | \\ } |
| 8218 | \\} | 8545 | \\} |
| 8219 | \\export fn foo_cvector_ConstPtrSpecialRef() void { | 8546 | \\export fn foo_cvector_ConstPtrSpecialRef() void { |
| ... | @@ -8221,6 +8548,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -8221,6 +8548,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 8221 | \\ var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; | 8548 | \\ var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; |
| 8222 | \\ var target: [*c]u8 = @ptrCast([*c]u8, &buf); | 8549 | \\ var target: [*c]u8 = @ptrCast([*c]u8, &buf); |
| 8223 | \\ const slice = target[0..3 :0]; | 8550 | \\ const slice = target[0..3 :0]; |
| | 8551 | \\ _ = slice; |
| 8224 | \\ } | 8552 | \\ } |
| 8225 | \\} | 8553 | \\} |
| 8226 | \\export fn foo_slice() void { | 8554 | \\export fn foo_slice() void { |
| ... | @@ -8228,23 +8556,25 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -8228,23 +8556,25 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 8228 | \\ var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; | 8556 | \\ var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; |
| 8229 | \\ var target: []u8 = &buf; | 8557 | \\ var target: []u8 = &buf; |
| 8230 | \\ const slice = target[0..3 :0]; | 8558 | \\ const slice = target[0..3 :0]; |
| | 8559 | \\ _ = slice; |
| 8231 | \\ } | 8560 | \\ } |
| 8232 | \\} | 8561 | \\} |
| 8233 | , &[_][]const u8{ | 8562 | , &[_][]const u8{ |
| 8234 | ":4:29: error: slice-sentinel does not match memory at target index", | 8563 | ":4:29: error: slice-sentinel does not match memory at target index", |
| 8235 | ":11:29: error: slice-sentinel does not match memory at target index", | 8564 | ":12:29: error: slice-sentinel does not match memory at target index", |
| 8236 | ":18:29: error: slice-sentinel does not match memory at target index", | 8565 | ":20:29: error: slice-sentinel does not match memory at target index", |
| 8237 | ":25:29: error: slice-sentinel does not match memory at target index", | 8566 | ":28:29: error: slice-sentinel does not match memory at target index", |
| 8238 | ":32:29: error: slice-sentinel does not match memory at target index", | 8567 | ":36:29: error: slice-sentinel does not match memory at target index", |
| 8239 | ":39:29: error: slice-sentinel does not match memory at target index", | 8568 | ":44:29: error: slice-sentinel does not match memory at target index", |
| 8240 | ":46:29: error: slice-sentinel does not match memory at target index", | 8569 | ":52:29: error: slice-sentinel does not match memory at target index", |
| 8241 | }); | 8570 | }); |
| 8242 | | 8571 | |
| 8243 | cases.add("comptime slice-sentinel does not match target-sentinel", | 8572 | ctx.objErrStage1("comptime slice-sentinel does not match target-sentinel", |
| 8244 | \\export fn foo_array() void { | 8573 | \\export fn foo_array() void { |
| 8245 | \\ comptime { | 8574 | \\ comptime { |
| 8246 | \\ var target = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; | 8575 | \\ var target = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; |
| 8247 | \\ const slice = target[0..14 :255]; | 8576 | \\ const slice = target[0..14 :255]; |
| | 8577 | \\ _ = slice; |
| 8248 | \\ } | 8578 | \\ } |
| 8249 | \\} | 8579 | \\} |
| 8250 | \\export fn foo_ptr_array() void { | 8580 | \\export fn foo_ptr_array() void { |
| ... | @@ -8252,6 +8582,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -8252,6 +8582,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 8252 | \\ var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; | 8582 | \\ var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; |
| 8253 | \\ var target = &buf; | 8583 | \\ var target = &buf; |
| 8254 | \\ const slice = target[0..14 :255]; | 8584 | \\ const slice = target[0..14 :255]; |
| | 8585 | \\ _ = slice; |
| 8255 | \\ } | 8586 | \\ } |
| 8256 | \\} | 8587 | \\} |
| 8257 | \\export fn foo_vector_ConstPtrSpecialBaseArray() void { | 8588 | \\export fn foo_vector_ConstPtrSpecialBaseArray() void { |
| ... | @@ -8259,6 +8590,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -8259,6 +8590,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 8259 | \\ var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; | 8590 | \\ var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; |
| 8260 | \\ var target: [*]u8 = &buf; | 8591 | \\ var target: [*]u8 = &buf; |
| 8261 | \\ const slice = target[0..14 :255]; | 8592 | \\ const slice = target[0..14 :255]; |
| | 8593 | \\ _ = slice; |
| 8262 | \\ } | 8594 | \\ } |
| 8263 | \\} | 8595 | \\} |
| 8264 | \\export fn foo_vector_ConstPtrSpecialRef() void { | 8596 | \\export fn foo_vector_ConstPtrSpecialRef() void { |
| ... | @@ -8266,6 +8598,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -8266,6 +8598,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 8266 | \\ var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; | 8598 | \\ var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; |
| 8267 | \\ var target: [*]u8 = @ptrCast([*]u8, &buf); | 8599 | \\ var target: [*]u8 = @ptrCast([*]u8, &buf); |
| 8268 | \\ const slice = target[0..14 :255]; | 8600 | \\ const slice = target[0..14 :255]; |
| | 8601 | \\ _ = slice; |
| 8269 | \\ } | 8602 | \\ } |
| 8270 | \\} | 8603 | \\} |
| 8271 | \\export fn foo_cvector_ConstPtrSpecialBaseArray() void { | 8604 | \\export fn foo_cvector_ConstPtrSpecialBaseArray() void { |
| ... | @@ -8273,6 +8606,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -8273,6 +8606,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 8273 | \\ var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; | 8606 | \\ var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; |
| 8274 | \\ var target: [*c]u8 = &buf; | 8607 | \\ var target: [*c]u8 = &buf; |
| 8275 | \\ const slice = target[0..14 :255]; | 8608 | \\ const slice = target[0..14 :255]; |
| | 8609 | \\ _ = slice; |
| 8276 | \\ } | 8610 | \\ } |
| 8277 | \\} | 8611 | \\} |
| 8278 | \\export fn foo_cvector_ConstPtrSpecialRef() void { | 8612 | \\export fn foo_cvector_ConstPtrSpecialRef() void { |
| ... | @@ -8280,6 +8614,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -8280,6 +8614,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 8280 | \\ var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; | 8614 | \\ var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; |
| 8281 | \\ var target: [*c]u8 = @ptrCast([*c]u8, &buf); | 8615 | \\ var target: [*c]u8 = @ptrCast([*c]u8, &buf); |
| 8282 | \\ const slice = target[0..14 :255]; | 8616 | \\ const slice = target[0..14 :255]; |
| | 8617 | \\ _ = slice; |
| 8283 | \\ } | 8618 | \\ } |
| 8284 | \\} | 8619 | \\} |
| 8285 | \\export fn foo_slice() void { | 8620 | \\export fn foo_slice() void { |
| ... | @@ -8287,19 +8622,20 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -8287,19 +8622,20 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 8287 | \\ var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; | 8622 | \\ var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; |
| 8288 | \\ var target: []u8 = &buf; | 8623 | \\ var target: []u8 = &buf; |
| 8289 | \\ const slice = target[0..14 :255]; | 8624 | \\ const slice = target[0..14 :255]; |
| | 8625 | \\ _ = slice; |
| 8290 | \\ } | 8626 | \\ } |
| 8291 | \\} | 8627 | \\} |
| 8292 | , &[_][]const u8{ | 8628 | , &[_][]const u8{ |
| 8293 | ":4:29: error: slice-sentinel does not match target-sentinel", | 8629 | ":4:29: error: slice-sentinel does not match target-sentinel", |
| 8294 | ":11:29: error: slice-sentinel does not match target-sentinel", | 8630 | ":12:29: error: slice-sentinel does not match target-sentinel", |
| 8295 | ":18:29: error: slice-sentinel does not match target-sentinel", | 8631 | ":20:29: error: slice-sentinel does not match target-sentinel", |
| 8296 | ":25:29: error: slice-sentinel does not match target-sentinel", | 8632 | ":28:29: error: slice-sentinel does not match target-sentinel", |
| 8297 | ":32:29: error: slice-sentinel does not match target-sentinel", | 8633 | ":36:29: error: slice-sentinel does not match target-sentinel", |
| 8298 | ":39:29: error: slice-sentinel does not match target-sentinel", | 8634 | ":44:29: error: slice-sentinel does not match target-sentinel", |
| 8299 | ":46:29: error: slice-sentinel does not match target-sentinel", | 8635 | ":52:29: error: slice-sentinel does not match target-sentinel", |
| 8300 | }); | 8636 | }); |
| 8301 | | 8637 | |
| 8302 | cases.add("issue #4207: coerce from non-terminated-slice to terminated-pointer", | 8638 | ctx.objErrStage1("issue #4207: coerce from non-terminated-slice to terminated-pointer", |
| 8303 | \\export fn foo() [*:0]const u8 { | 8639 | \\export fn foo() [*:0]const u8 { |
| 8304 | \\ var buffer: [64]u8 = undefined; | 8640 | \\ var buffer: [64]u8 = undefined; |
| 8305 | \\ return buffer[0..]; | 8641 | \\ return buffer[0..]; |
| ... | @@ -8309,8 +8645,8 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -8309,8 +8645,8 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 8309 | ":3:18: note: destination pointer requires a terminating '0' sentinel", | 8645 | ":3:18: note: destination pointer requires a terminating '0' sentinel", |
| 8310 | }); | 8646 | }); |
| 8311 | | 8647 | |
| 8312 | cases.add("issue #5221: invalid struct init type referenced by @typeInfo and passed into function", | 8648 | ctx.objErrStage1("issue #5221: invalid struct init type referenced by @typeInfo and passed into function", |
| 8313 | \\fn ignore(comptime param: anytype) void {} | 8649 | \\fn ignore(comptime param: anytype) void {_ = param;} |
| 8314 | \\ | 8650 | \\ |
| 8315 | \\export fn foo() void { | 8651 | \\export fn foo() void { |
| 8316 | \\ const MyStruct = struct { | 8652 | \\ const MyStruct = struct { |
| ... | @@ -8323,7 +8659,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -8323,7 +8659,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 8323 | ":5:28: error: expected type '[]u8', found '*const [3:0]u8'", | 8659 | ":5:28: error: expected type '[]u8', found '*const [3:0]u8'", |
| 8324 | }); | 8660 | }); |
| 8325 | | 8661 | |
| 8326 | cases.add("integer underflow error", | 8662 | ctx.objErrStage1("integer underflow error", |
| 8327 | \\export fn entry() void { | 8663 | \\export fn entry() void { |
| 8328 | \\ _ = @intToPtr(*c_void, ~@as(usize, @import("std").math.maxInt(usize)) - 1); | 8664 | \\ _ = @intToPtr(*c_void, ~@as(usize, @import("std").math.maxInt(usize)) - 1); |
| 8329 | \\} | 8665 | \\} |
| ... | @@ -8331,23 +8667,24 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -8331,23 +8667,24 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 8331 | ":2:75: error: operation caused overflow", | 8667 | ":2:75: error: operation caused overflow", |
| 8332 | }); | 8668 | }); |
| 8333 | | 8669 | |
| 8334 | cases.addCase(x: { | 8670 | { |
| 8335 | var tc = cases.create("align(N) expr function pointers is a compile error", | 8671 | const case = ctx.obj("align(N) expr function pointers is a compile error", .{ |
| | 8672 | .cpu_arch = .wasm32, |
| | 8673 | .os_tag = .freestanding, |
| | 8674 | .abi = .none, |
| | 8675 | }); |
| | 8676 | case.backend = .stage1; |
| | 8677 | |
| | 8678 | case.addError( |
| 8336 | \\export fn foo() align(1) void { | 8679 | \\export fn foo() align(1) void { |
| 8337 | \\ return; | 8680 | \\ return; |
| 8338 | \\} | 8681 | \\} |
| 8339 | , &[_][]const u8{ | 8682 | , &[_][]const u8{ |
| 8340 | "tmp.zig:1:23: error: align(N) expr is not allowed on function prototypes in wasm32/wasm64", | 8683 | "tmp.zig:1:23: error: align(N) expr is not allowed on function prototypes in wasm32/wasm64", |
| 8341 | }); | 8684 | }); |
| 8342 | tc.target = std.zig.CrossTarget{ | 8685 | } |
| 8343 | .cpu_arch = .wasm32, | | |
| 8344 | .os_tag = .freestanding, | | |
| 8345 | .abi = .none, | | |
| 8346 | }; | | |
| 8347 | break :x tc; | | |
| 8348 | }); | | |
| 8349 | | 8686 | |
| 8350 | cases.add("compare optional to non-optional with invalid types", | 8687 | ctx.objErrStage1("compare optional to non-optional with invalid types", |
| 8351 | \\export fn inconsistentChildType() void { | 8688 | \\export fn inconsistentChildType() void { |
| 8352 | \\ var x: ?i32 = undefined; | 8689 | \\ var x: ?i32 = undefined; |
| 8353 | \\ const y: comptime_int = 10; | 8690 | \\ const y: comptime_int = 10; |
| ... | @@ -8381,16 +8718,17 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -8381,16 +8718,17 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 8381 | ":22:12: note: operator not supported for type '[3]i32'", | 8718 | ":22:12: note: operator not supported for type '[3]i32'", |
| 8382 | }); | 8719 | }); |
| 8383 | | 8720 | |
| 8384 | cases.add("slice cannot have its bytes reinterpreted", | 8721 | ctx.objErrStage1("slice cannot have its bytes reinterpreted", |
| 8385 | \\export fn foo() void { | 8722 | \\export fn foo() void { |
| 8386 | \\ const bytes = [1]u8{ 0xfa } ** 16; | 8723 | \\ const bytes = [1]u8{ 0xfa } ** 16; |
| 8387 | \\ var value = @ptrCast(*const []const u8, &bytes).*; | 8724 | \\ var value = @ptrCast(*const []const u8, &bytes).*; |
| | 8725 | \\ _ = value; |
| 8388 | \\} | 8726 | \\} |
| 8389 | , &[_][]const u8{ | 8727 | , &[_][]const u8{ |
| 8390 | ":3:52: error: slice '[]const u8' cannot have its bytes reinterpreted", | 8728 | ":3:52: error: slice '[]const u8' cannot have its bytes reinterpreted", |
| 8391 | }); | 8729 | }); |
| 8392 | | 8730 | |
| 8393 | cases.add("wasmMemorySize is a compile error in non-Wasm targets", | 8731 | ctx.objErrStage1("wasmMemorySize is a compile error in non-Wasm targets", |
| 8394 | \\export fn foo() void { | 8732 | \\export fn foo() void { |
| 8395 | \\ _ = @wasmMemorySize(0); | 8733 | \\ _ = @wasmMemorySize(0); |
| 8396 | \\ return; | 8734 | \\ return; |
| ... | @@ -8399,7 +8737,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -8399,7 +8737,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 8399 | "tmp.zig:2:9: error: @wasmMemorySize is a wasm32 feature only", | 8737 | "tmp.zig:2:9: error: @wasmMemorySize is a wasm32 feature only", |
| 8400 | }); | 8738 | }); |
| 8401 | | 8739 | |
| 8402 | cases.add("wasmMemoryGrow is a compile error in non-Wasm targets", | 8740 | ctx.objErrStage1("wasmMemoryGrow is a compile error in non-Wasm targets", |
| 8403 | \\export fn foo() void { | 8741 | \\export fn foo() void { |
| 8404 | \\ _ = @wasmMemoryGrow(0, 1); | 8742 | \\ _ = @wasmMemoryGrow(0, 1); |
| 8405 | \\ return; | 8743 | \\ return; |
| ... | @@ -8407,7 +8745,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -8407,7 +8745,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 8407 | , &[_][]const u8{ | 8745 | , &[_][]const u8{ |
| 8408 | "tmp.zig:2:9: error: @wasmMemoryGrow is a wasm32 feature only", | 8746 | "tmp.zig:2:9: error: @wasmMemoryGrow is a wasm32 feature only", |
| 8409 | }); | 8747 | }); |
| 8410 | cases.add("Issue #5586: Make unary minus for unsigned types a compile error", | 8748 | ctx.objErrStage1("Issue #5586: Make unary minus for unsigned types a compile error", |
| 8411 | \\export fn f1(x: u32) u32 { | 8749 | \\export fn f1(x: u32) u32 { |
| 8412 | \\ const y = -%x; | 8750 | \\ const y = -%x; |
| 8413 | \\ return -y; | 8751 | \\ return -y; |
| ... | @@ -8422,7 +8760,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -8422,7 +8760,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 8422 | "tmp.zig:8:12: error: negation of type 'u32'", | 8760 | "tmp.zig:8:12: error: negation of type 'u32'", |
| 8423 | }); | 8761 | }); |
| 8424 | | 8762 | |
| 8425 | cases.add("Issue #5618: coercion of ?*c_void to *c_void must fail.", | 8763 | ctx.objErrStage1("Issue #5618: coercion of ?*c_void to *c_void must fail.", |
| 8426 | \\export fn foo() void { | 8764 | \\export fn foo() void { |
| 8427 | \\ var u: ?*c_void = null; | 8765 | \\ var u: ?*c_void = null; |
| 8428 | \\ var v: *c_void = undefined; | 8766 | \\ var v: *c_void = undefined; |
| ... | @@ -8432,15 +8770,17 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -8432,15 +8770,17 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 8432 | "tmp.zig:4:9: error: expected type '*c_void', found '?*c_void'", | 8770 | "tmp.zig:4:9: error: expected type '*c_void', found '?*c_void'", |
| 8433 | }); | 8771 | }); |
| 8434 | | 8772 | |
| 8435 | cases.add("Issue #6823: don't allow .* to be followed by **", | 8773 | ctx.objErrStage1("Issue #6823: don't allow .* to be followed by **", |
| 8436 | \\fn foo() void { | 8774 | \\fn foo() void { |
| 8437 | \\ var sequence = "repeat".*** 10; | 8775 | \\ var sequence = "repeat".*** 10; |
| | 8776 | \\ _ = sequence; |
| 8438 | \\} | 8777 | \\} |
| 8439 | , &[_][]const u8{ | 8778 | , &[_][]const u8{ |
| 8440 | "tmp.zig:2:30: error: `.*` cannot be followed by `*`. Are you missing a space?", | 8779 | // Ideally this would be column 30 but it's not very important. |
| | 8780 | "tmp.zig:2:28: error: '.*' cannot be followed by '*'. Are you missing a space?", |
| 8441 | }); | 8781 | }); |
| 8442 | | 8782 | |
| 8443 | cases.add("Issue #9165: windows tcp server compilation error", | 8783 | ctx.objErrStage1("Issue #9165: windows tcp server compilation error", |
| 8444 | \\const std = @import("std"); | 8784 | \\const std = @import("std"); |
| 8445 | \\pub const io_mode = .evented; | 8785 | \\pub const io_mode = .evented; |
| 8446 | \\pub fn main() !void { | 8786 | \\pub fn main() !void { |