| ... | @@ -1,53 +1,50 @@ | ... | @@ -1,53 +1,50 @@ |
| 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.objErrStage1("lazy pointer with undefined element type", |
| 6 | \\pub fn main() !void { | | |
| 7 | \\ @import("std").debug.print("{d} {d} {d} {d} {d}", .{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15}); | | |
| 8 | \\} | | |
| 9 | , &.{ | | |
| 10 | \\error: 10 unused arguments in "{d} {d} {d} {d} {d}" | | |
| 11 | }); | | |
| 12 | | | |
| 13 | cases.add("lazy pointer with undefined element type", | | |
| 14 | \\export fn foo() void { | 6 | \\export fn foo() void { |
| 15 | \\ comptime var T: type = undefined; | 7 | \\ comptime var T: type = undefined; |
| 16 | \\ const S = struct { x: *T }; | 8 | \\ const S = struct { x: *T }; |
| 17 | \\ const I = @typeInfo(S); | 9 | \\ const I = @typeInfo(S); |
| | 10 | \\ _ = I; |
| 18 | \\} | 11 | \\} |
| 19 | , &[_][]const u8{ | 12 | , &[_][]const u8{ |
| 20 | "tmp.zig:3:28: error: use of undefined value here causes undefined behavior", | 13 | ":3:28: error: use of undefined value here causes undefined behavior", |
| 21 | }); | 14 | }); |
| 22 | | 15 | |
| 23 | cases.add("pointer arithmetic on pointer-to-array", | 16 | ctx.objErrStage1("pointer arithmetic on pointer-to-array", |
| 24 | \\export fn foo() void { | 17 | \\export fn foo() void { |
| 25 | \\ var x: [10]u8 = undefined; | 18 | \\ var x: [10]u8 = undefined; |
| 26 | \\ var y = &x; | 19 | \\ var y = &x; |
| 27 | \\ var z = y + 1; | 20 | \\ var z = y + 1; |
| | 21 | \\ _ = z; |
| 28 | \\} | 22 | \\} |
| 29 | , &[_][]const u8{ | 23 | , &[_][]const u8{ |
| 30 | "tmp.zig:4:17: error: integer value 1 cannot be coerced to type '*[10]u8'", | 24 | "tmp.zig:4:17: error: integer value 1 cannot be coerced to type '*[10]u8'", |
| 31 | }); | 25 | }); |
| 32 | | 26 | |
| 33 | cases.add("pointer attributes checked when coercing pointer to anon literal", | 27 | ctx.objErrStage1("pointer attributes checked when coercing pointer to anon literal", |
| 34 | \\comptime { | 28 | \\comptime { |
| 35 | \\ const c: [][]const u8 = &.{"hello", "world" }; | 29 | \\ const c: [][]const u8 = &.{"hello", "world" }; |
| | 30 | \\ _ = c; |
| 36 | \\} | 31 | \\} |
| 37 | \\comptime { | 32 | \\comptime { |
| 38 | \\ const c: *[2][]const u8 = &.{"hello", "world" }; | 33 | \\ const c: *[2][]const u8 = &.{"hello", "world" }; |
| | 34 | \\ _ = c; |
| 39 | \\} | 35 | \\} |
| 40 | \\const S = struct {a: u8 = 1, b: u32 = 2}; | 36 | \\const S = struct {a: u8 = 1, b: u32 = 2}; |
| 41 | \\comptime { | 37 | \\comptime { |
| 42 | \\ const c: *S = &.{}; | 38 | \\ const c: *S = &.{}; |
| | 39 | \\ _ = c; |
| 43 | \\} | 40 | \\} |
| 44 | , &[_][]const u8{ | 41 | , &[_][]const u8{ |
| 45 | "tmp.zig:2:31: error: expected type '[][]const u8', found '*const struct:2:31'", | 42 | "tmp.zig:2:31: error: expected type '[][]const u8', found '*const struct:2:31'", |
| 46 | "tmp.zig:5:33: error: expected type '*[2][]const u8', found '*const struct:5:33'", | 43 | "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'", | 44 | "tmp.zig:11:21: error: expected type '*S', found '*const struct:11:21'", |
| 48 | }); | 45 | }); |
| 49 | | 46 | |
| 50 | cases.add("@Type() union payload is undefined", | 47 | ctx.objErrStage1("@Type() union payload is undefined", |
| 51 | \\const Foo = @Type(@import("std").builtin.TypeInfo{ | 48 | \\const Foo = @Type(@import("std").builtin.TypeInfo{ |
| 52 | \\ .Struct = undefined, | 49 | \\ .Struct = undefined, |
| 53 | \\}); | 50 | \\}); |
| ... | @@ -56,7 +53,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -56,7 +53,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 56 | "tmp.zig:1:50: error: use of undefined value here causes undefined behavior", | 53 | "tmp.zig:1:50: error: use of undefined value here causes undefined behavior", |
| 57 | }); | 54 | }); |
| 58 | | 55 | |
| 59 | cases.add("wrong initializer for union payload of type 'type'", | 56 | ctx.objErrStage1("wrong initializer for union payload of type 'type'", |
| 60 | \\const U = union(enum) { | 57 | \\const U = union(enum) { |
| 61 | \\ A: type, | 58 | \\ A: type, |
| 62 | \\}; | 59 | \\}; |
| ... | @@ -71,7 +68,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -71,7 +68,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 71 | "tmp.zig:9:8: error: use of undefined value here causes undefined behavior", | 68 | "tmp.zig:9:8: error: use of undefined value here causes undefined behavior", |
| 72 | }); | 69 | }); |
| 73 | | 70 | |
| 74 | cases.add("union with too small explicit signed tag type", | 71 | ctx.objErrStage1("union with too small explicit signed tag type", |
| 75 | \\const U = union(enum(i2)) { | 72 | \\const U = union(enum(i2)) { |
| 76 | \\ A: u8, | 73 | \\ A: u8, |
| 77 | \\ B: u8, | 74 | \\ B: u8, |
| ... | @@ -86,7 +83,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -86,7 +83,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 86 | "tmp.zig:1:22: note: type i2 cannot fit values in range 0...3", | 83 | "tmp.zig:1:22: note: type i2 cannot fit values in range 0...3", |
| 87 | }); | 84 | }); |
| 88 | | 85 | |
| 89 | cases.add("union with too small explicit unsigned tag type", | 86 | ctx.objErrStage1("union with too small explicit unsigned tag type", |
| 90 | \\const U = union(enum(u2)) { | 87 | \\const U = union(enum(u2)) { |
| 91 | \\ A: u8, | 88 | \\ A: u8, |
| 92 | \\ B: u8, | 89 | \\ B: u8, |
| ... | @@ -102,56 +99,60 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -102,56 +99,60 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 102 | "tmp.zig:1:22: note: type u2 cannot fit values in range 0...4", | 99 | "tmp.zig:1:22: note: type u2 cannot fit values in range 0...4", |
| 103 | }); | 100 | }); |
| 104 | | 101 | |
| 105 | cases.addCase(x: { | 102 | { |
| 106 | var tc = cases.create("callconv(.Interrupt) on unsupported platform", | 103 | const case = ctx.obj("callconv(.Interrupt) on unsupported platform", .{ |
| | 104 | .cpu_arch = .aarch64, |
| | 105 | .os_tag = .linux, |
| | 106 | .abi = .none, |
| | 107 | }); |
| | 108 | case.backend = .stage1; |
| | 109 | case.addError( |
| 107 | \\export fn entry() callconv(.Interrupt) void {} | 110 | \\export fn entry() callconv(.Interrupt) void {} |
| 108 | , &[_][]const u8{ | 111 | , &[_][]const u8{ |
| 109 | "tmp.zig:1:28: error: callconv 'Interrupt' is only available on x86, x86_64, AVR, and MSP430, not aarch64", | 112 | "tmp.zig:1:28: error: callconv 'Interrupt' is only available on x86, x86_64, AVR, and MSP430, not aarch64", |
| 110 | }); | 113 | }); |
| 111 | tc.target = std.zig.CrossTarget{ | 114 | } |
| 112 | .cpu_arch = .aarch64, | 115 | { |
| | 116 | var case = ctx.obj("callconv(.Signal) on unsupported platform", .{ |
| | 117 | .cpu_arch = .x86_64, |
| 113 | .os_tag = .linux, | 118 | .os_tag = .linux, |
| 114 | .abi = .none, | 119 | .abi = .none, |
| 115 | }; | 120 | }); |
| 116 | break :x tc; | 121 | case.backend = .stage1; |
| 117 | }); | 122 | case.addError( |
| 118 | | | |
| 119 | cases.addCase(x: { | | |
| 120 | var tc = cases.create("callconv(.Signal) on unsupported platform", | | |
| 121 | \\export fn entry() callconv(.Signal) void {} | 123 | \\export fn entry() callconv(.Signal) void {} |
| 122 | , &[_][]const u8{ | 124 | , &[_][]const u8{ |
| 123 | "tmp.zig:1:28: error: callconv 'Signal' is only available on AVR, not x86_64", | 125 | "tmp.zig:1:28: error: callconv 'Signal' is only available on AVR, not x86_64", |
| 124 | }); | 126 | }); |
| 125 | tc.target = std.zig.CrossTarget{ | 127 | } |
| | 128 | { |
| | 129 | const case = ctx.obj("callconv(.Stdcall, .Fastcall, .Thiscall) on unsupported platform", .{ |
| 126 | .cpu_arch = .x86_64, | 130 | .cpu_arch = .x86_64, |
| 127 | .os_tag = .linux, | 131 | .os_tag = .linux, |
| 128 | .abi = .none, | 132 | .abi = .none, |
| 129 | }; | 133 | }); |
| 130 | break :x tc; | 134 | case.backend = .stage1; |
| 131 | }); | 135 | 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; | 136 | \\const F1 = fn () callconv(.Stdcall) void; |
| 135 | \\const F2 = fn () callconv(.Fastcall) void; | 137 | \\const F2 = fn () callconv(.Fastcall) void; |
| 136 | \\const F3 = fn () callconv(.Thiscall) void; | 138 | \\const F3 = fn () callconv(.Thiscall) void; |
| 137 | \\export fn entry1() void { var a: F1 = undefined; } | 139 | \\export fn entry1() void { var a: F1 = undefined; _ = a; } |
| 138 | \\export fn entry2() void { var a: F2 = undefined; } | 140 | \\export fn entry2() void { var a: F2 = undefined; _ = a; } |
| 139 | \\export fn entry3() void { var a: F3 = undefined; } | 141 | \\export fn entry3() void { var a: F3 = undefined; _ = a; } |
| 140 | , &[_][]const u8{ | 142 | , &[_][]const u8{ |
| 141 | "tmp.zig:1:27: error: callconv 'Stdcall' is only available on x86, not x86_64", | 143 | "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", | 144 | "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", | 145 | "tmp.zig:3:27: error: callconv 'Thiscall' is only available on x86, not x86_64", |
| 144 | }); | 146 | }); |
| 145 | tc.target = std.zig.CrossTarget{ | 147 | } |
| | 148 | { |
| | 149 | const case = ctx.obj("callconv(.Stdcall, .Fastcall, .Thiscall) on unsupported platform", .{ |
| 146 | .cpu_arch = .x86_64, | 150 | .cpu_arch = .x86_64, |
| 147 | .os_tag = .linux, | 151 | .os_tag = .linux, |
| 148 | .abi = .none, | 152 | .abi = .none, |
| 149 | }; | 153 | }); |
| 150 | break :x tc; | 154 | case.backend = .stage1; |
| 151 | }); | 155 | 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 {} | 156 | \\export fn entry1() callconv(.Stdcall) void {} |
| 156 | \\export fn entry2() callconv(.Fastcall) void {} | 157 | \\export fn entry2() callconv(.Fastcall) void {} |
| 157 | \\export fn entry3() callconv(.Thiscall) void {} | 158 | \\export fn entry3() callconv(.Thiscall) void {} |
| ... | @@ -160,30 +161,28 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -160,30 +161,28 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 160 | "tmp.zig:2:29: error: callconv 'Fastcall' is only available on x86, not x86_64", | 161 | "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", | 162 | "tmp.zig:3:29: error: callconv 'Thiscall' is only available on x86, not x86_64", |
| 162 | }); | 163 | }); |
| 163 | tc.target = std.zig.CrossTarget{ | 164 | } |
| | 165 | { |
| | 166 | const case = ctx.obj("callconv(.Vectorcall) on unsupported platform", .{ |
| 164 | .cpu_arch = .x86_64, | 167 | .cpu_arch = .x86_64, |
| 165 | .os_tag = .linux, | 168 | .os_tag = .linux, |
| 166 | .abi = .none, | 169 | .abi = .none, |
| 167 | }; | 170 | }); |
| 168 | break :x tc; | 171 | case.backend = .stage1; |
| 169 | }); | 172 | case.addError( |
| 170 | | | |
| 171 | cases.addCase(x: { | | |
| 172 | var tc = cases.create("callconv(.Vectorcall) on unsupported platform", | | |
| 173 | \\export fn entry() callconv(.Vectorcall) void {} | 173 | \\export fn entry() callconv(.Vectorcall) void {} |
| 174 | , &[_][]const u8{ | 174 | , &[_][]const u8{ |
| 175 | "tmp.zig:1:28: error: callconv 'Vectorcall' is only available on x86 and AArch64, not x86_64", | 175 | "tmp.zig:1:28: error: callconv 'Vectorcall' is only available on x86 and AArch64, not x86_64", |
| 176 | }); | 176 | }); |
| 177 | tc.target = std.zig.CrossTarget{ | 177 | } |
| | 178 | { |
| | 179 | const case = ctx.obj("callconv(.APCS, .AAPCS, .AAPCSVFP) on unsupported platform", .{ |
| 178 | .cpu_arch = .x86_64, | 180 | .cpu_arch = .x86_64, |
| 179 | .os_tag = .linux, | 181 | .os_tag = .linux, |
| 180 | .abi = .none, | 182 | .abi = .none, |
| 181 | }; | 183 | }); |
| 182 | break :x tc; | 184 | case.backend = .stage1; |
| 183 | }); | 185 | 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 {} | 186 | \\export fn entry1() callconv(.APCS) void {} |
| 188 | \\export fn entry2() callconv(.AAPCS) void {} | 187 | \\export fn entry2() callconv(.AAPCS) void {} |
| 189 | \\export fn entry3() callconv(.AAPCSVFP) void {} | 188 | \\export fn entry3() callconv(.AAPCSVFP) void {} |
| ... | @@ -192,15 +191,9 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -192,15 +191,9 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 192 | "tmp.zig:2:29: error: callconv 'AAPCS' is only available on ARM, not x86_64", | 191 | "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", | 192 | "tmp.zig:3:29: error: callconv 'AAPCSVFP' is only available on ARM, not x86_64", |
| 194 | }); | 193 | }); |
| 195 | tc.target = std.zig.CrossTarget{ | 194 | } |
| 196 | .cpu_arch = .x86_64, | | |
| 197 | .os_tag = .linux, | | |
| 198 | .abi = .none, | | |
| 199 | }; | | |
| 200 | break :x tc; | | |
| 201 | }); | | |
| 202 | | 195 | |
| 203 | cases.add("unreachable executed at comptime", | 196 | ctx.objErrStage1("unreachable executed at comptime", |
| 204 | \\fn foo(comptime x: i32) i32 { | 197 | \\fn foo(comptime x: i32) i32 { |
| 205 | \\ comptime { | 198 | \\ comptime { |
| 206 | \\ if (x >= 0) return -x; | 199 | \\ if (x >= 0) return -x; |
| ... | @@ -215,7 +208,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -215,7 +208,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 215 | "tmp.zig:8:12: note: called from here", | 208 | "tmp.zig:8:12: note: called from here", |
| 216 | }); | 209 | }); |
| 217 | | 210 | |
| 218 | cases.add("@Type with TypeInfo.Int", | 211 | ctx.objErrStage1("@Type with TypeInfo.Int", |
| 219 | \\const builtin = @import("std").builtin; | 212 | \\const builtin = @import("std").builtin; |
| 220 | \\export fn entry() void { | 213 | \\export fn entry() void { |
| 221 | \\ _ = @Type(builtin.TypeInfo.Int { | 214 | \\ _ = @Type(builtin.TypeInfo.Int { |
| ... | @@ -227,7 +220,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -227,7 +220,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 227 | "tmp.zig:3:36: error: expected type 'std.builtin.TypeInfo', found 'std.builtin.Int'", | 220 | "tmp.zig:3:36: error: expected type 'std.builtin.TypeInfo', found 'std.builtin.Int'", |
| 228 | }); | 221 | }); |
| 229 | | 222 | |
| 230 | cases.add("indexing a undefined slice at comptime", | 223 | ctx.objErrStage1("indexing a undefined slice at comptime", |
| 231 | \\comptime { | 224 | \\comptime { |
| 232 | \\ var slice: []u8 = undefined; | 225 | \\ var slice: []u8 = undefined; |
| 233 | \\ slice[0] = 2; | 226 | \\ slice[0] = 2; |
| ... | @@ -236,7 +229,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -236,7 +229,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 236 | "tmp.zig:3:10: error: index 0 outside slice of size 0", | 229 | "tmp.zig:3:10: error: index 0 outside slice of size 0", |
| 237 | }); | 230 | }); |
| 238 | | 231 | |
| 239 | cases.add("array in c exported function", | 232 | ctx.objErrStage1("array in c exported function", |
| 240 | \\export fn zig_array(x: [10]u8) void { | 233 | \\export fn zig_array(x: [10]u8) void { |
| 241 | \\try expect(std.mem.eql(u8, &x, "1234567890")); | 234 | \\try expect(std.mem.eql(u8, &x, "1234567890")); |
| 242 | \\} | 235 | \\} |
| ... | @@ -249,7 +242,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -249,7 +242,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'", | 242 | "tmp.zig:5:30: error: return type '[10]u8' not allowed in function with calling convention 'C'", |
| 250 | }); | 243 | }); |
| 251 | | 244 | |
| 252 | cases.add("@Type for exhaustive enum with undefined tag type", | 245 | ctx.objErrStage1("@Type for exhaustive enum with undefined tag type", |
| 253 | \\const TypeInfo = @import("std").builtin.TypeInfo; | 246 | \\const TypeInfo = @import("std").builtin.TypeInfo; |
| 254 | \\const Tag = @Type(.{ | 247 | \\const Tag = @Type(.{ |
| 255 | \\ .Enum = .{ | 248 | \\ .Enum = .{ |
| ... | @@ -267,19 +260,20 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -267,19 +260,20 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 267 | "tmp.zig:2:20: error: use of undefined value here causes undefined behavior", | 260 | "tmp.zig:2:20: error: use of undefined value here causes undefined behavior", |
| 268 | }); | 261 | }); |
| 269 | | 262 | |
| 270 | cases.add("extern struct with non-extern-compatible integer tag type", | 263 | ctx.objErrStage1("extern struct with non-extern-compatible integer tag type", |
| 271 | \\pub const E = enum(u31) { A, B, C }; | 264 | \\pub const E = enum(u31) { A, B, C }; |
| 272 | \\pub const S = extern struct { | 265 | \\pub const S = extern struct { |
| 273 | \\ e: E, | 266 | \\ e: E, |
| 274 | \\}; | 267 | \\}; |
| 275 | \\export fn entry() void { | 268 | \\export fn entry() void { |
| 276 | \\ const s: S = undefined; | 269 | \\ const s: S = undefined; |
| | 270 | \\ _ = s; |
| 277 | \\} | 271 | \\} |
| 278 | , &[_][]const u8{ | 272 | , &[_][]const u8{ |
| 279 | "tmp.zig:3:5: error: extern structs cannot contain fields of type 'E'", | 273 | "tmp.zig:3:5: error: extern structs cannot contain fields of type 'E'", |
| 280 | }); | 274 | }); |
| 281 | | 275 | |
| 282 | cases.add("@Type for exhaustive enum with non-integer tag type", | 276 | ctx.objErrStage1("@Type for exhaustive enum with non-integer tag type", |
| 283 | \\const TypeInfo = @import("std").builtin.TypeInfo; | 277 | \\const TypeInfo = @import("std").builtin.TypeInfo; |
| 284 | \\const Tag = @Type(.{ | 278 | \\const Tag = @Type(.{ |
| 285 | \\ .Enum = .{ | 279 | \\ .Enum = .{ |
| ... | @@ -297,7 +291,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -297,7 +291,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'", | 291 | "tmp.zig:2:20: error: TypeInfo.Enum.tag_type must be an integer type, not 'bool'", |
| 298 | }); | 292 | }); |
| 299 | | 293 | |
| 300 | cases.add("extern struct with extern-compatible but inferred integer tag type", | 294 | ctx.objErrStage1("extern struct with extern-compatible but inferred integer tag type", |
| 301 | \\pub const E = enum { | 295 | \\pub const E = enum { |
| 302 | \\@"0",@"1",@"2",@"3",@"4",@"5",@"6",@"7",@"8",@"9",@"10",@"11",@"12", | 296 | \\@"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", | 297 | \\@"13",@"14",@"15",@"16",@"17",@"18",@"19",@"20",@"21",@"22",@"23", |
| ... | @@ -333,12 +327,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -333,12 +327,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 333 | \\export fn entry() void { | 327 | \\export fn entry() void { |
| 334 | \\ if (@typeInfo(E).Enum.tag_type != u8) @compileError("did not infer u8 tag type"); | 328 | \\ if (@typeInfo(E).Enum.tag_type != u8) @compileError("did not infer u8 tag type"); |
| 335 | \\ const s: S = undefined; | 329 | \\ const s: S = undefined; |
| | 330 | \\ _ = s; |
| 336 | \\} | 331 | \\} |
| 337 | , &[_][]const u8{ | 332 | , &[_][]const u8{ |
| 338 | "tmp.zig:31:5: error: extern structs cannot contain fields of type 'E'", | 333 | "tmp.zig:31:5: error: extern structs cannot contain fields of type 'E'", |
| 339 | }); | 334 | }); |
| 340 | | 335 | |
| 341 | cases.add("@Type for tagged union with extra enum field", | 336 | ctx.objErrStage1("@Type for tagged union with extra enum field", |
| 342 | \\const TypeInfo = @import("std").builtin.TypeInfo; | 337 | \\const TypeInfo = @import("std").builtin.TypeInfo; |
| 343 | \\const Tag = @Type(.{ | 338 | \\const Tag = @Type(.{ |
| 344 | \\ .Enum = .{ | 339 | \\ .Enum = .{ |
| ... | @@ -373,7 +368,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -373,7 +368,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 373 | "tmp.zig:27:24: note: referenced here", | 368 | "tmp.zig:27:24: note: referenced here", |
| 374 | }); | 369 | }); |
| 375 | | 370 | |
| 376 | cases.add("field access of opaque type", | 371 | ctx.objErrStage1("field access of opaque type", |
| 377 | \\const MyType = opaque {}; | 372 | \\const MyType = opaque {}; |
| 378 | \\ | 373 | \\ |
| 379 | \\export fn entry() bool { | 374 | \\export fn entry() bool { |
| ... | @@ -388,16 +383,17 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -388,16 +383,17 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 388 | "tmp.zig:9:13: error: no member named 'blah' in opaque type 'MyType'", | 383 | "tmp.zig:9:13: error: no member named 'blah' in opaque type 'MyType'", |
| 389 | }); | 384 | }); |
| 390 | | 385 | |
| 391 | cases.add("opaque type with field", | 386 | ctx.objErrStage1("opaque type with field", |
| 392 | \\const Opaque = opaque { foo: i32 }; | 387 | \\const Opaque = opaque { foo: i32 }; |
| 393 | \\export fn entry() void { | 388 | \\export fn entry() void { |
| 394 | \\ const foo: ?*Opaque = null; | 389 | \\ const foo: ?*Opaque = null; |
| | 390 | \\ _ = foo; |
| 395 | \\} | 391 | \\} |
| 396 | , &[_][]const u8{ | 392 | , &[_][]const u8{ |
| 397 | "tmp.zig:1:25: error: opaque types cannot have fields", | 393 | "tmp.zig:1:25: error: opaque types cannot have fields", |
| 398 | }); | 394 | }); |
| 399 | | 395 | |
| 400 | cases.add("@Type(.Fn) with is_generic = true", | 396 | ctx.objErrStage1("@Type(.Fn) with is_generic = true", |
| 401 | \\const Foo = @Type(.{ | 397 | \\const Foo = @Type(.{ |
| 402 | \\ .Fn = .{ | 398 | \\ .Fn = .{ |
| 403 | \\ .calling_convention = .Unspecified, | 399 | \\ .calling_convention = .Unspecified, |
| ... | @@ -413,7 +409,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -413,7 +409,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 413 | "tmp.zig:1:20: error: TypeInfo.Fn.is_generic must be false for @Type", | 409 | "tmp.zig:1:20: error: TypeInfo.Fn.is_generic must be false for @Type", |
| 414 | }); | 410 | }); |
| 415 | | 411 | |
| 416 | cases.add("@Type(.Fn) with is_var_args = true and non-C callconv", | 412 | ctx.objErrStage1("@Type(.Fn) with is_var_args = true and non-C callconv", |
| 417 | \\const Foo = @Type(.{ | 413 | \\const Foo = @Type(.{ |
| 418 | \\ .Fn = .{ | 414 | \\ .Fn = .{ |
| 419 | \\ .calling_convention = .Unspecified, | 415 | \\ .calling_convention = .Unspecified, |
| ... | @@ -429,7 +425,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -429,7 +425,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 429 | "tmp.zig:1:20: error: varargs functions must have C calling convention", | 425 | "tmp.zig:1:20: error: varargs functions must have C calling convention", |
| 430 | }); | 426 | }); |
| 431 | | 427 | |
| 432 | cases.add("@Type(.Fn) with return_type = null", | 428 | ctx.objErrStage1("@Type(.Fn) with return_type = null", |
| 433 | \\const Foo = @Type(.{ | 429 | \\const Foo = @Type(.{ |
| 434 | \\ .Fn = .{ | 430 | \\ .Fn = .{ |
| 435 | \\ .calling_convention = .Unspecified, | 431 | \\ .calling_convention = .Unspecified, |
| ... | @@ -445,7 +441,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -445,7 +441,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 445 | "tmp.zig:1:20: error: TypeInfo.Fn.return_type must be non-null for @Type", | 441 | "tmp.zig:1:20: error: TypeInfo.Fn.return_type must be non-null for @Type", |
| 446 | }); | 442 | }); |
| 447 | | 443 | |
| 448 | cases.add("@Type for union with opaque field", | 444 | ctx.objErrStage1("@Type for union with opaque field", |
| 449 | \\const TypeInfo = @import("std").builtin.TypeInfo; | 445 | \\const TypeInfo = @import("std").builtin.TypeInfo; |
| 450 | \\const Untagged = @Type(.{ | 446 | \\const Untagged = @Type(.{ |
| 451 | \\ .Union = .{ | 447 | \\ .Union = .{ |
| ... | @@ -465,23 +461,25 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -465,23 +461,25 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 465 | "tmp.zig:13:17: note: referenced here", | 461 | "tmp.zig:13:17: note: referenced here", |
| 466 | }); | 462 | }); |
| 467 | | 463 | |
| 468 | cases.add("slice sentinel mismatch", | 464 | ctx.objErrStage1("slice sentinel mismatch", |
| 469 | \\export fn entry() void { | 465 | \\export fn entry() void { |
| 470 | \\ const x = @import("std").meta.Vector(3, f32){ 25, 75, 5, 0 }; | 466 | \\ const x = @import("std").meta.Vector(3, f32){ 25, 75, 5, 0 }; |
| | 467 | \\ _ = x; |
| 471 | \\} | 468 | \\} |
| 472 | , &[_][]const u8{ | 469 | , &[_][]const u8{ |
| 473 | "tmp.zig:2:62: error: index 3 outside vector of size 3", | 470 | "tmp.zig:2:62: error: index 3 outside vector of size 3", |
| 474 | }); | 471 | }); |
| 475 | | 472 | |
| 476 | cases.add("slice sentinel mismatch", | 473 | ctx.objErrStage1("slice sentinel mismatch", |
| 477 | \\export fn entry() void { | 474 | \\export fn entry() void { |
| 478 | \\ const y: [:1]const u8 = &[_:2]u8{ 1, 2 }; | 475 | \\ const y: [:1]const u8 = &[_:2]u8{ 1, 2 }; |
| | 476 | \\ _ = y; |
| 479 | \\} | 477 | \\} |
| 480 | , &[_][]const u8{ | 478 | , &[_][]const u8{ |
| 481 | "tmp.zig:2:37: error: expected type '[:1]const u8', found '*const [2:2]u8'", | 479 | "tmp.zig:2:37: error: expected type '[:1]const u8', found '*const [2:2]u8'", |
| 482 | }); | 480 | }); |
| 483 | | 481 | |
| 484 | cases.add("@Type for union with zero fields", | 482 | ctx.objErrStage1("@Type for union with zero fields", |
| 485 | \\const TypeInfo = @import("std").builtin.TypeInfo; | 483 | \\const TypeInfo = @import("std").builtin.TypeInfo; |
| 486 | \\const Untagged = @Type(.{ | 484 | \\const Untagged = @Type(.{ |
| 487 | \\ .Union = .{ | 485 | \\ .Union = .{ |
| ... | @@ -499,7 +497,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -499,7 +497,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 499 | "tmp.zig:11:17: note: referenced here", | 497 | "tmp.zig:11:17: note: referenced here", |
| 500 | }); | 498 | }); |
| 501 | | 499 | |
| 502 | cases.add("@Type for exhaustive enum with zero fields", | 500 | ctx.objErrStage1("@Type for exhaustive enum with zero fields", |
| 503 | \\const TypeInfo = @import("std").builtin.TypeInfo; | 501 | \\const TypeInfo = @import("std").builtin.TypeInfo; |
| 504 | \\const Tag = @Type(.{ | 502 | \\const Tag = @Type(.{ |
| 505 | \\ .Enum = .{ | 503 | \\ .Enum = .{ |
| ... | @@ -518,7 +516,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -518,7 +516,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 518 | "tmp.zig:12:9: note: referenced here", | 516 | "tmp.zig:12:9: note: referenced here", |
| 519 | }); | 517 | }); |
| 520 | | 518 | |
| 521 | cases.add("@Type for tagged union with extra union field", | 519 | ctx.objErrStage1("@Type for tagged union with extra union field", |
| 522 | \\const TypeInfo = @import("std").builtin.TypeInfo; | 520 | \\const TypeInfo = @import("std").builtin.TypeInfo; |
| 523 | \\const Tag = @Type(.{ | 521 | \\const Tag = @Type(.{ |
| 524 | \\ .Enum = .{ | 522 | \\ .Enum = .{ |
| ... | @@ -554,7 +552,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -554,7 +552,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 554 | "tmp.zig:27:24: note: referenced here", | 552 | "tmp.zig:27:24: note: referenced here", |
| 555 | }); | 553 | }); |
| 556 | | 554 | |
| 557 | cases.add("@Type with undefined", | 555 | ctx.objErrStage1("@Type with undefined", |
| 558 | \\comptime { | 556 | \\comptime { |
| 559 | \\ _ = @Type(.{ .Array = .{ .len = 0, .child = u8, .sentinel = undefined } }); | 557 | \\ _ = @Type(.{ .Array = .{ .len = 0, .child = u8, .sentinel = undefined } }); |
| 560 | \\} | 558 | \\} |
| ... | @@ -573,7 +571,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -573,7 +571,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 573 | "tmp.zig:5:16: error: use of undefined value here causes undefined behavior", | 571 | "tmp.zig:5:16: error: use of undefined value here causes undefined behavior", |
| 574 | }); | 572 | }); |
| 575 | | 573 | |
| 576 | cases.add("struct with declarations unavailable for @Type", | 574 | ctx.objErrStage1("struct with declarations unavailable for @Type", |
| 577 | \\export fn entry() void { | 575 | \\export fn entry() void { |
| 578 | \\ _ = @Type(@typeInfo(struct { const foo = 1; })); | 576 | \\ _ = @Type(@typeInfo(struct { const foo = 1; })); |
| 579 | \\} | 577 | \\} |
| ... | @@ -581,7 +579,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -581,7 +579,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 581 | "tmp.zig:2:15: error: TypeInfo.Struct.decls must be empty for @Type", | 579 | "tmp.zig:2:15: error: TypeInfo.Struct.decls must be empty for @Type", |
| 582 | }); | 580 | }); |
| 583 | | 581 | |
| 584 | cases.add("enum with declarations unavailable for @Type", | 582 | ctx.objErrStage1("enum with declarations unavailable for @Type", |
| 585 | \\export fn entry() void { | 583 | \\export fn entry() void { |
| 586 | \\ _ = @Type(@typeInfo(enum { foo, const bar = 1; })); | 584 | \\ _ = @Type(@typeInfo(enum { foo, const bar = 1; })); |
| 587 | \\} | 585 | \\} |
| ... | @@ -589,36 +587,44 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -589,36 +587,44 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 589 | "tmp.zig:2:15: error: TypeInfo.Enum.decls must be empty for @Type", | 587 | "tmp.zig:2:15: error: TypeInfo.Enum.decls must be empty for @Type", |
| 590 | }); | 588 | }); |
| 591 | | 589 | |
| 592 | cases.addTest("reject extern variables with initializers", | 590 | ctx.testErrStage1("reject extern variables with initializers", |
| 593 | \\extern var foo: int = 2; | 591 | \\extern var foo: int = 2; |
| 594 | , &[_][]const u8{ | 592 | , &[_][]const u8{ |
| 595 | "tmp.zig:1:1: error: extern variables have no initializers", | 593 | "tmp.zig:1:23: error: extern variables have no initializers", |
| 596 | }); | 594 | }); |
| 597 | | 595 | |
| 598 | cases.addTest("duplicate/unused labels", | 596 | ctx.testErrStage1("duplicate/unused labels", |
| 599 | \\comptime { | 597 | \\comptime { |
| 600 | \\ blk: { blk: while (false) {} } | 598 | \\ blk: { blk: while (false) {} } |
| | 599 | \\} |
| | 600 | \\comptime { |
| 601 | \\ blk: while (false) { blk: for (@as([0]void, undefined)) |_| {} } | 601 | \\ blk: while (false) { blk: for (@as([0]void, undefined)) |_| {} } |
| | 602 | \\} |
| | 603 | \\comptime { |
| 602 | \\ blk: for (@as([0]void, undefined)) |_| { blk: {} } | 604 | \\ blk: for (@as([0]void, undefined)) |_| { blk: {} } |
| 603 | \\} | 605 | \\} |
| 604 | \\comptime { | 606 | \\comptime { |
| 605 | \\ blk: {} | 607 | \\ blk: {} |
| | 608 | \\} |
| | 609 | \\comptime { |
| 606 | \\ blk: while(false) {} | 610 | \\ blk: while(false) {} |
| | 611 | \\} |
| | 612 | \\comptime { |
| 607 | \\ blk: for(@as([0]void, undefined)) |_| {} | 613 | \\ blk: for(@as([0]void, undefined)) |_| {} |
| 608 | \\} | 614 | \\} |
| 609 | , &[_][]const u8{ | 615 | , &[_][]const u8{ |
| 610 | "tmp.zig:2:17: error: redeclaration of label 'blk'", | 616 | "tmp.zig:2:12: error: redefinition of label 'blk'", |
| 611 | "tmp.zig:2:10: note: previous declaration is here", | 617 | "tmp.zig:2:5: note: previous definition is here", |
| 612 | "tmp.zig:3:31: error: redeclaration of label 'blk'", | 618 | "tmp.zig:5:26: error: redefinition of label 'blk'", |
| 613 | "tmp.zig:3:10: note: previous declaration is here", | 619 | "tmp.zig:5:5: note: previous definition is here", |
| 614 | "tmp.zig:4:51: error: redeclaration of label 'blk'", | 620 | "tmp.zig:8:46: error: redefinition of label 'blk'", |
| 615 | "tmp.zig:4:10: note: previous declaration is here", | 621 | "tmp.zig:8:5: note: previous definition is here", |
| 616 | "tmp.zig:7:10: error: unused block label", | 622 | "tmp.zig:11:5: error: unused block label", |
| 617 | "tmp.zig:8:10: error: unused while label", | 623 | "tmp.zig:14:5: error: unused while loop label", |
| 618 | "tmp.zig:9:10: error: unused for label", | 624 | "tmp.zig:17:5: error: unused for loop label", |
| 619 | }); | 625 | }); |
| 620 | | 626 | |
| 621 | cases.addTest("@alignCast of zero sized types", | 627 | ctx.testErrStage1("@alignCast of zero sized types", |
| 622 | \\export fn foo() void { | 628 | \\export fn foo() void { |
| 623 | \\ const a: *void = undefined; | 629 | \\ const a: *void = undefined; |
| 624 | \\ _ = @alignCast(2, a); | 630 | \\ _ = @alignCast(2, a); |
| ... | @@ -633,7 +639,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -633,7 +639,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 633 | \\} | 639 | \\} |
| 634 | \\export fn qux() void { | 640 | \\export fn qux() void { |
| 635 | \\ const a = struct { | 641 | \\ const a = struct { |
| 636 | \\ fn a(comptime b: u32) void {} | 642 | \\ fn a(comptime b: u32) void { _ = b; } |
| 637 | \\ }.a; | 643 | \\ }.a; |
| 638 | \\ _ = @alignCast(2, a); | 644 | \\ _ = @alignCast(2, a); |
| 639 | \\} | 645 | \\} |
| ... | @@ -644,7 +650,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -644,7 +650,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 644 | "tmp.zig:17:23: error: cannot adjust alignment of zero sized type 'fn(u32) anytype'", | 650 | "tmp.zig:17:23: error: cannot adjust alignment of zero sized type 'fn(u32) anytype'", |
| 645 | }); | 651 | }); |
| 646 | | 652 | |
| 647 | cases.addTest("invalid non-exhaustive enum to union", | 653 | ctx.testErrStage1("invalid non-exhaustive enum to union", |
| 648 | \\const E = enum(u8) { | 654 | \\const E = enum(u8) { |
| 649 | \\ a, | 655 | \\ a, |
| 650 | \\ b, | 656 | \\ b, |
| ... | @@ -657,17 +663,19 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -657,17 +663,19 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 657 | \\export fn foo() void { | 663 | \\export fn foo() void { |
| 658 | \\ var e = @intToEnum(E, 15); | 664 | \\ var e = @intToEnum(E, 15); |
| 659 | \\ var u: U = e; | 665 | \\ var u: U = e; |
| | 666 | \\ _ = u; |
| 660 | \\} | 667 | \\} |
| 661 | \\export fn bar() void { | 668 | \\export fn bar() void { |
| 662 | \\ const e = @intToEnum(E, 15); | 669 | \\ const e = @intToEnum(E, 15); |
| 663 | \\ var u: U = e; | 670 | \\ var u: U = e; |
| | 671 | \\ _ = u; |
| 664 | \\} | 672 | \\} |
| 665 | , &[_][]const u8{ | 673 | , &[_][]const u8{ |
| 666 | "tmp.zig:12:16: error: runtime cast to union 'U' from non-exhustive enum", | 674 | "tmp.zig:12:16: error: runtime cast to union 'U' from non-exhustive enum", |
| 667 | "tmp.zig:16:16: error: no tag by value 15", | 675 | "tmp.zig:17:16: error: no tag by value 15", |
| 668 | }); | 676 | }); |
| 669 | | 677 | |
| 670 | cases.addTest("switching with exhaustive enum has '_' prong ", | 678 | ctx.testErrStage1("switching with exhaustive enum has '_' prong ", |
| 671 | \\const E = enum{ | 679 | \\const E = enum{ |
| 672 | \\ a, | 680 | \\ a, |
| 673 | \\ b, | 681 | \\ b, |
| ... | @@ -684,7 +692,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -684,7 +692,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 684 | "tmp.zig:7:5: error: switch on exhaustive enum has `_` prong", | 692 | "tmp.zig:7:5: error: switch on exhaustive enum has `_` prong", |
| 685 | }); | 693 | }); |
| 686 | | 694 | |
| 687 | cases.addTest("invalid pointer with @Type", | 695 | ctx.testErrStage1("invalid pointer with @Type", |
| 688 | \\export fn entry() void { | 696 | \\export fn entry() void { |
| 689 | \\ _ = @Type(.{ .Pointer = .{ | 697 | \\ _ = @Type(.{ .Pointer = .{ |
| 690 | \\ .size = .One, | 698 | \\ .size = .One, |
| ... | @@ -700,7 +708,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -700,7 +708,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 700 | "tmp.zig:2:16: error: sentinels are only allowed on slices and unknown-length pointers", | 708 | "tmp.zig:2:16: error: sentinels are only allowed on slices and unknown-length pointers", |
| 701 | }); | 709 | }); |
| 702 | | 710 | |
| 703 | cases.addTest("helpful return type error message", | 711 | ctx.testErrStage1("helpful return type error message", |
| 704 | \\export fn foo() u32 { | 712 | \\export fn foo() u32 { |
| 705 | \\ return error.Ohno; | 713 | \\ return error.Ohno; |
| 706 | \\} | 714 | \\} |
| ... | @@ -728,7 +736,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -728,7 +736,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 728 | "tmp.zig:14:5: note: cannot store an error in type 'u32'", | 736 | "tmp.zig:14:5: note: cannot store an error in type 'u32'", |
| 729 | }); | 737 | }); |
| 730 | | 738 | |
| 731 | cases.addTest("int/float conversion to comptime_int/float", | 739 | ctx.testErrStage1("int/float conversion to comptime_int/float", |
| 732 | \\export fn foo() void { | 740 | \\export fn foo() void { |
| 733 | \\ var a: f32 = 2; | 741 | \\ var a: f32 = 2; |
| 734 | \\ _ = @floatToInt(comptime_int, a); | 742 | \\ _ = @floatToInt(comptime_int, a); |
| ... | @@ -744,16 +752,16 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -744,16 +752,16 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 744 | "tmp.zig:7:9: note: referenced here", | 752 | "tmp.zig:7:9: note: referenced here", |
| 745 | }); | 753 | }); |
| 746 | | 754 | |
| 747 | cases.add("extern variable has no type", | 755 | ctx.objErrStage1("extern variable has no type", |
| 748 | \\extern var foo; | 756 | \\extern var foo; |
| 749 | \\pub export fn entry() void { | 757 | \\pub export fn entry() void { |
| 750 | \\ foo; | 758 | \\ foo; |
| 751 | \\} | 759 | \\} |
| 752 | , &[_][]const u8{ | 760 | , &[_][]const u8{ |
| 753 | "tmp.zig:1:1: error: unable to infer variable type", | 761 | "tmp.zig:1:8: error: unable to infer variable type", |
| 754 | }); | 762 | }); |
| 755 | | 763 | |
| 756 | cases.add("@src outside function", | 764 | ctx.objErrStage1("@src outside function", |
| 757 | \\comptime { | 765 | \\comptime { |
| 758 | \\ @src(); | 766 | \\ @src(); |
| 759 | \\} | 767 | \\} |
| ... | @@ -761,7 +769,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -761,7 +769,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 761 | "tmp.zig:2:5: error: @src outside function", | 769 | "tmp.zig:2:5: error: @src outside function", |
| 762 | }); | 770 | }); |
| 763 | | 771 | |
| 764 | cases.add("call assigned to constant", | 772 | ctx.objErrStage1("call assigned to constant", |
| 765 | \\const Foo = struct { | 773 | \\const Foo = struct { |
| 766 | \\ x: i32, | 774 | \\ x: i32, |
| 767 | \\}; | 775 | \\}; |
| ... | @@ -784,15 +792,15 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -784,15 +792,15 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 784 | "tmp.zig:16:14: error: cannot assign to constant", | 792 | "tmp.zig:16:14: error: cannot assign to constant", |
| 785 | }); | 793 | }); |
| 786 | | 794 | |
| 787 | cases.add("invalid pointer syntax", | 795 | ctx.objErrStage1("invalid pointer syntax", |
| 788 | \\export fn foo() void { | 796 | \\export fn foo() void { |
| 789 | \\ var guid: *:0 const u8 = undefined; | 797 | \\ var guid: *:0 const u8 = undefined; |
| 790 | \\} | 798 | \\} |
| 791 | , &[_][]const u8{ | 799 | , &[_][]const u8{ |
| 792 | "tmp.zig:2:15: error: sentinels are only allowed on unknown-length pointers", | 800 | "tmp.zig:2:16: error: expected type expression, found ':'", |
| 793 | }); | 801 | }); |
| 794 | | 802 | |
| 795 | cases.add("declaration between fields", | 803 | ctx.objErrStage1("declaration between fields", |
| 796 | \\const S = struct { | 804 | \\const S = struct { |
| 797 | \\ const foo = 2; | 805 | \\ const foo = 2; |
| 798 | \\ const bar = 2; | 806 | \\ const bar = 2; |
| ... | @@ -810,16 +818,16 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -810,16 +818,16 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 810 | "tmp.zig:6:5: error: declarations are not allowed between container fields", | 818 | "tmp.zig:6:5: error: declarations are not allowed between container fields", |
| 811 | }); | 819 | }); |
| 812 | | 820 | |
| 813 | cases.add("non-extern function with var args", | 821 | ctx.objErrStage1("non-extern function with var args", |
| 814 | \\fn foo(args: ...) void {} | 822 | \\fn foo(args: ...) void {} |
| 815 | \\export fn entry() void { | 823 | \\export fn entry() void { |
| 816 | \\ foo(); | 824 | \\ foo(); |
| 817 | \\} | 825 | \\} |
| 818 | , &[_][]const u8{ | 826 | , &[_][]const u8{ |
| 819 | "tmp.zig:1:1: error: non-extern function is variadic", | 827 | "tmp.zig:1:14: error: expected type expression, found '...'", |
| 820 | }); | 828 | }); |
| 821 | | 829 | |
| 822 | cases.addTest("invalid int casts", | 830 | ctx.testErrStage1("invalid int casts", |
| 823 | \\export fn foo() void { | 831 | \\export fn foo() void { |
| 824 | \\ var a: u32 = 2; | 832 | \\ var a: u32 = 2; |
| 825 | \\ _ = @intCast(comptime_int, a); | 833 | \\ _ = @intCast(comptime_int, a); |
| ... | @@ -847,7 +855,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -847,7 +855,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 847 | "tmp.zig:15:9: note: referenced here", | 855 | "tmp.zig:15:9: note: referenced here", |
| 848 | }); | 856 | }); |
| 849 | | 857 | |
| 850 | cases.addTest("invalid float casts", | 858 | ctx.testErrStage1("invalid float casts", |
| 851 | \\export fn foo() void { | 859 | \\export fn foo() void { |
| 852 | \\ var a: f32 = 2; | 860 | \\ var a: f32 = 2; |
| 853 | \\ _ = @floatCast(comptime_float, a); | 861 | \\ _ = @floatCast(comptime_float, a); |
| ... | @@ -875,7 +883,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -875,7 +883,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 875 | "tmp.zig:15:9: note: referenced here", | 883 | "tmp.zig:15:9: note: referenced here", |
| 876 | }); | 884 | }); |
| 877 | | 885 | |
| 878 | cases.addTest("invalid assignments", | 886 | ctx.testErrStage1("invalid assignments", |
| 879 | \\export fn entry1() void { | 887 | \\export fn entry1() void { |
| 880 | \\ var a: []const u8 = "foo"; | 888 | \\ var a: []const u8 = "foo"; |
| 881 | \\ a[0..2] = "bar"; | 889 | \\ a[0..2] = "bar"; |
| ... | @@ -893,7 +901,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -893,7 +901,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 893 | "tmp.zig:10:7: error: invalid left-hand side to assignment", | 901 | "tmp.zig:10:7: error: invalid left-hand side to assignment", |
| 894 | }); | 902 | }); |
| 895 | | 903 | |
| 896 | cases.addTest("reassign to array parameter", | 904 | ctx.testErrStage1("reassign to array parameter", |
| 897 | \\fn reassign(a: [3]f32) void { | 905 | \\fn reassign(a: [3]f32) void { |
| 898 | \\ a = [3]f32{4, 5, 6}; | 906 | \\ a = [3]f32{4, 5, 6}; |
| 899 | \\} | 907 | \\} |
| ... | @@ -904,7 +912,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -904,7 +912,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 904 | "tmp.zig:2:15: error: cannot assign to constant", | 912 | "tmp.zig:2:15: error: cannot assign to constant", |
| 905 | }); | 913 | }); |
| 906 | | 914 | |
| 907 | cases.addTest("reassign to slice parameter", | 915 | ctx.testErrStage1("reassign to slice parameter", |
| 908 | \\pub fn reassign(s: []const u8) void { | 916 | \\pub fn reassign(s: []const u8) void { |
| 909 | \\ s = s[0..]; | 917 | \\ s = s[0..]; |
| 910 | \\} | 918 | \\} |
| ... | @@ -915,7 +923,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -915,7 +923,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 915 | "tmp.zig:2:10: error: cannot assign to constant", | 923 | "tmp.zig:2:10: error: cannot assign to constant", |
| 916 | }); | 924 | }); |
| 917 | | 925 | |
| 918 | cases.addTest("reassign to struct parameter", | 926 | ctx.testErrStage1("reassign to struct parameter", |
| 919 | \\const S = struct { | 927 | \\const S = struct { |
| 920 | \\ x: u32, | 928 | \\ x: u32, |
| 921 | \\}; | 929 | \\}; |
| ... | @@ -929,7 +937,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -929,7 +937,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 929 | "tmp.zig:5:10: error: cannot assign to constant", | 937 | "tmp.zig:5:10: error: cannot assign to constant", |
| 930 | }); | 938 | }); |
| 931 | | 939 | |
| 932 | cases.addTest("reference to const data", | 940 | ctx.testErrStage1("reference to const data", |
| 933 | \\export fn foo() void { | 941 | \\export fn foo() void { |
| 934 | \\ var ptr = &[_]u8{0,0,0,0}; | 942 | \\ var ptr = &[_]u8{0,0,0,0}; |
| 935 | \\ ptr[1] = 2; | 943 | \\ ptr[1] = 2; |
| ... | @@ -957,7 +965,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -957,7 +965,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 957 | "tmp.zig:19:13: error: cannot assign to constant", | 965 | "tmp.zig:19:13: error: cannot assign to constant", |
| 958 | }); | 966 | }); |
| 959 | | 967 | |
| 960 | cases.addTest("cast between ?T where T is not a pointer", | 968 | ctx.testErrStage1("cast between ?T where T is not a pointer", |
| 961 | \\pub const fnty1 = ?fn (i8) void; | 969 | \\pub const fnty1 = ?fn (i8) void; |
| 962 | \\pub const fnty2 = ?fn (u64) void; | 970 | \\pub const fnty2 = ?fn (u64) void; |
| 963 | \\export fn entry() void { | 971 | \\export fn entry() void { |
| ... | @@ -970,7 +978,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -970,7 +978,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'", | 978 | "tmp.zig:6:9: note: optional type child 'fn(u64) void' cannot cast into optional type child 'fn(i8) void'", |
| 971 | }); | 979 | }); |
| 972 | | 980 | |
| 973 | cases.addTest("unused variable error on errdefer", | 981 | ctx.testErrStage1("unused variable error on errdefer", |
| 974 | \\fn foo() !void { | 982 | \\fn foo() !void { |
| 975 | \\ errdefer |a| unreachable; | 983 | \\ errdefer |a| unreachable; |
| 976 | \\ return error.A; | 984 | \\ return error.A; |
| ... | @@ -982,18 +990,19 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -982,18 +990,19 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 982 | "tmp.zig:2:15: error: unused variable: 'a'", | 990 | "tmp.zig:2:15: error: unused variable: 'a'", |
| 983 | }); | 991 | }); |
| 984 | | 992 | |
| 985 | cases.addTest("comparison of non-tagged union and enum literal", | 993 | ctx.testErrStage1("comparison of non-tagged union and enum literal", |
| 986 | \\export fn entry() void { | 994 | \\export fn entry() void { |
| 987 | \\ const U = union { A: u32, B: u64 }; | 995 | \\ const U = union { A: u32, B: u64 }; |
| 988 | \\ var u = U{ .A = 42 }; | 996 | \\ var u = U{ .A = 42 }; |
| 989 | \\ var ok = u == .A; | 997 | \\ var ok = u == .A; |
| | 998 | \\ _ = ok; |
| 990 | \\} | 999 | \\} |
| 991 | , &[_][]const u8{ | 1000 | , &[_][]const u8{ |
| 992 | "tmp.zig:4:16: error: comparison of union and enum literal is only valid for tagged union types", | 1001 | "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", | 1002 | "tmp.zig:2:15: note: type U is not a tagged union", |
| 994 | }); | 1003 | }); |
| 995 | | 1004 | |
| 996 | cases.addTest("shift on type with non-power-of-two size", | 1005 | ctx.testErrStage1("shift on type with non-power-of-two size", |
| 997 | \\export fn entry() void { | 1006 | \\export fn entry() void { |
| 998 | \\ const S = struct { | 1007 | \\ const S = struct { |
| 999 | \\ fn a() void { | 1008 | \\ fn a() void { |
| ... | @@ -1025,7 +1034,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -1025,7 +1034,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1025 | "tmp.zig:17:17: error: RHS of shift is too large for LHS type", | 1034 | "tmp.zig:17:17: error: RHS of shift is too large for LHS type", |
| 1026 | }); | 1035 | }); |
| 1027 | | 1036 | |
| 1028 | cases.addTest("combination of nosuspend and async", | 1037 | ctx.testErrStage1("combination of nosuspend and async", |
| 1029 | \\export fn entry() void { | 1038 | \\export fn entry() void { |
| 1030 | \\ nosuspend { | 1039 | \\ nosuspend { |
| 1031 | \\ const bar = async foo(); | 1040 | \\ const bar = async foo(); |
| ... | @@ -1035,10 +1044,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -1035,10 +1044,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1035 | \\} | 1044 | \\} |
| 1036 | \\fn foo() void {} | 1045 | \\fn foo() void {} |
| 1037 | , &[_][]const u8{ | 1046 | , &[_][]const u8{ |
| 1038 | "tmp.zig:4:9: error: suspend in nosuspend scope", | 1047 | "tmp.zig:4:9: error: suspend inside nosuspend block", |
| | 1048 | "tmp.zig:2:5: note: nosuspend block here", |
| 1039 | }); | 1049 | }); |
| 1040 | | 1050 | |
| 1041 | cases.add("atomicrmw with bool op not .Xchg", | 1051 | ctx.objErrStage1("atomicrmw with bool op not .Xchg", |
| 1042 | \\export fn entry() void { | 1052 | \\export fn entry() void { |
| 1043 | \\ var x = false; | 1053 | \\ var x = false; |
| 1044 | \\ _ = @atomicRmw(bool, &x, .Add, true, .SeqCst); | 1054 | \\ _ = @atomicRmw(bool, &x, .Add, true, .SeqCst); |
| ... | @@ -1047,7 +1057,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -1047,7 +1057,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1047 | "tmp.zig:3:30: error: @atomicRmw with bool only allowed with .Xchg", | 1057 | "tmp.zig:3:30: error: @atomicRmw with bool only allowed with .Xchg", |
| 1048 | }); | 1058 | }); |
| 1049 | | 1059 | |
| 1050 | cases.addTest("@TypeOf with no arguments", | 1060 | ctx.testErrStage1("@TypeOf with no arguments", |
| 1051 | \\export fn entry() void { | 1061 | \\export fn entry() void { |
| 1052 | \\ _ = @TypeOf(); | 1062 | \\ _ = @TypeOf(); |
| 1053 | \\} | 1063 | \\} |
| ... | @@ -1055,7 +1065,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -1055,7 +1065,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1055 | "tmp.zig:2:9: error: expected at least 1 argument, found 0", | 1065 | "tmp.zig:2:9: error: expected at least 1 argument, found 0", |
| 1056 | }); | 1066 | }); |
| 1057 | | 1067 | |
| 1058 | cases.addTest("@TypeOf with incompatible arguments", | 1068 | ctx.testErrStage1("@TypeOf with incompatible arguments", |
| 1059 | \\export fn entry() void { | 1069 | \\export fn entry() void { |
| 1060 | \\ var var_1: f32 = undefined; | 1070 | \\ var var_1: f32 = undefined; |
| 1061 | \\ var var_2: u32 = undefined; | 1071 | \\ var var_2: u32 = undefined; |
| ... | @@ -1065,7 +1075,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -1065,7 +1075,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1065 | "tmp.zig:4:9: error: incompatible types: 'f32' and 'u32'", | 1075 | "tmp.zig:4:9: error: incompatible types: 'f32' and 'u32'", |
| 1066 | }); | 1076 | }); |
| 1067 | | 1077 | |
| 1068 | cases.addTest("type mismatch with tuple concatenation", | 1078 | ctx.testErrStage1("type mismatch with tuple concatenation", |
| 1069 | \\export fn entry() void { | 1079 | \\export fn entry() void { |
| 1070 | \\ var x = .{}; | 1080 | \\ var x = .{}; |
| 1071 | \\ x = x ++ .{ 1, 2, 3 }; | 1081 | \\ x = x ++ .{ 1, 2, 3 }; |
| ... | @@ -1074,7 +1084,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -1074,7 +1084,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1074 | "tmp.zig:3:11: error: expected type 'struct:2:14', found 'struct:3:11'", | 1084 | "tmp.zig:3:11: error: expected type 'struct:2:14', found 'struct:3:11'", |
| 1075 | }); | 1085 | }); |
| 1076 | | 1086 | |
| 1077 | cases.addTest("@tagName on invalid value of non-exhaustive enum", | 1087 | ctx.testErrStage1("@tagName on invalid value of non-exhaustive enum", |
| 1078 | \\test "enum" { | 1088 | \\test "enum" { |
| 1079 | \\ const E = enum(u8) {A, B, _}; | 1089 | \\ const E = enum(u8) {A, B, _}; |
| 1080 | \\ _ = @tagName(@intToEnum(E, 5)); | 1090 | \\ _ = @tagName(@intToEnum(E, 5)); |
| ... | @@ -1083,16 +1093,17 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -1083,16 +1093,17 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1083 | "tmp.zig:3:18: error: no tag by value 5", | 1093 | "tmp.zig:3:18: error: no tag by value 5", |
| 1084 | }); | 1094 | }); |
| 1085 | | 1095 | |
| 1086 | cases.addTest("@ptrToInt with pointer to zero-sized type", | 1096 | ctx.testErrStage1("@ptrToInt with pointer to zero-sized type", |
| 1087 | \\export fn entry() void { | 1097 | \\export fn entry() void { |
| 1088 | \\ var pointer: ?*u0 = null; | 1098 | \\ var pointer: ?*u0 = null; |
| 1089 | \\ var x = @ptrToInt(pointer); | 1099 | \\ var x = @ptrToInt(pointer); |
| | 1100 | \\ _ = x; |
| 1090 | \\} | 1101 | \\} |
| 1091 | , &[_][]const u8{ | 1102 | , &[_][]const u8{ |
| 1092 | "tmp.zig:3:23: error: pointer to size 0 type has no address", | 1103 | "tmp.zig:3:23: error: pointer to size 0 type has no address", |
| 1093 | }); | 1104 | }); |
| 1094 | | 1105 | |
| 1095 | cases.addTest("access invalid @typeInfo decl", | 1106 | ctx.testErrStage1("access invalid @typeInfo decl", |
| 1096 | \\const A = B; | 1107 | \\const A = B; |
| 1097 | \\test "Crash" { | 1108 | \\test "Crash" { |
| 1098 | \\ _ = @typeInfo(@This()).Struct.decls[0]; | 1109 | \\ _ = @typeInfo(@This()).Struct.decls[0]; |
| ... | @@ -1101,7 +1112,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -1101,7 +1112,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1101 | "tmp.zig:1:11: error: use of undeclared identifier 'B'", | 1112 | "tmp.zig:1:11: error: use of undeclared identifier 'B'", |
| 1102 | }); | 1113 | }); |
| 1103 | | 1114 | |
| 1104 | cases.addTest("reject extern function definitions with body", | 1115 | ctx.testErrStage1("reject extern function definitions with body", |
| 1105 | \\extern "c" fn definitelyNotInLibC(a: i32, b: i32) i32 { | 1116 | \\extern "c" fn definitelyNotInLibC(a: i32, b: i32) i32 { |
| 1106 | \\ return a + b; | 1117 | \\ return a + b; |
| 1107 | \\} | 1118 | \\} |
| ... | @@ -1109,7 +1120,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -1109,7 +1120,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1109 | "tmp.zig:1:1: error: extern functions have no body", | 1120 | "tmp.zig:1:1: error: extern functions have no body", |
| 1110 | }); | 1121 | }); |
| 1111 | | 1122 | |
| 1112 | cases.addTest("duplicate field in anonymous struct literal", | 1123 | ctx.testErrStage1("duplicate field in anonymous struct literal", |
| 1113 | \\export fn entry() void { | 1124 | \\export fn entry() void { |
| 1114 | \\ const anon = .{ | 1125 | \\ const anon = .{ |
| 1115 | \\ .inner = .{ | 1126 | \\ .inner = .{ |
| ... | @@ -1119,31 +1130,33 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -1119,31 +1130,33 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1119 | \\ .a = .{}, | 1130 | \\ .a = .{}, |
| 1120 | \\ }, | 1131 | \\ }, |
| 1121 | \\ }; | 1132 | \\ }; |
| | 1133 | \\ _ = anon; |
| 1122 | \\} | 1134 | \\} |
| 1123 | , &[_][]const u8{ | 1135 | , &[_][]const u8{ |
| 1124 | "tmp.zig:7:13: error: duplicate field", | 1136 | "tmp.zig:7:13: error: duplicate field", |
| 1125 | "tmp.zig:4:13: note: other field here", | 1137 | "tmp.zig:4:13: note: other field here", |
| 1126 | }); | 1138 | }); |
| 1127 | | 1139 | |
| 1128 | cases.addTest("type mismatch in C prototype with varargs", | 1140 | ctx.testErrStage1("type mismatch in C prototype with varargs", |
| 1129 | \\const fn_ty = ?fn ([*c]u8, ...) callconv(.C) void; | 1141 | \\const fn_ty = ?fn ([*c]u8, ...) callconv(.C) void; |
| 1130 | \\extern fn fn_decl(fmt: [*:0]u8, ...) void; | 1142 | \\extern fn fn_decl(fmt: [*:0]u8, ...) void; |
| 1131 | \\ | 1143 | \\ |
| 1132 | \\export fn main() void { | 1144 | \\export fn main() void { |
| 1133 | \\ const x: fn_ty = fn_decl; | 1145 | \\ const x: fn_ty = fn_decl; |
| | 1146 | \\ _ = x; |
| 1134 | \\} | 1147 | \\} |
| 1135 | , &[_][]const u8{ | 1148 | , &[_][]const u8{ |
| 1136 | "tmp.zig:5:22: error: expected type 'fn([*c]u8, ...) callconv(.C) void', found 'fn([*:0]u8, ...) callconv(.C) void'", | 1149 | "tmp.zig:5:22: error: expected type 'fn([*c]u8, ...) callconv(.C) void', found 'fn([*:0]u8, ...) callconv(.C) void'", |
| 1137 | }); | 1150 | }); |
| 1138 | | 1151 | |
| 1139 | cases.addTest("dependency loop in top-level decl with @TypeInfo when accessing the decls", | 1152 | ctx.testErrStage1("dependency loop in top-level decl with @TypeInfo when accessing the decls", |
| 1140 | \\export const foo = @typeInfo(@This()).Struct.decls; | 1153 | \\export const foo = @typeInfo(@This()).Struct.decls; |
| 1141 | , &[_][]const u8{ | 1154 | , &[_][]const u8{ |
| 1142 | "tmp.zig:1:20: error: dependency loop detected", | 1155 | "tmp.zig:1:20: error: dependency loop detected", |
| 1143 | "tmp.zig:1:45: note: referenced here", | 1156 | "tmp.zig:1:45: note: referenced here", |
| 1144 | }); | 1157 | }); |
| 1145 | | 1158 | |
| 1146 | cases.add("function call assigned to incorrect type", | 1159 | ctx.objErrStage1("function call assigned to incorrect type", |
| 1147 | \\export fn entry() void { | 1160 | \\export fn entry() void { |
| 1148 | \\ var arr: [4]f32 = undefined; | 1161 | \\ var arr: [4]f32 = undefined; |
| 1149 | \\ arr = concat(); | 1162 | \\ arr = concat(); |
| ... | @@ -1155,7 +1168,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -1155,7 +1168,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1155 | "tmp.zig:3:17: error: expected type '[4]f32', found '[16]f32'", | 1168 | "tmp.zig:3:17: error: expected type '[4]f32', found '[16]f32'", |
| 1156 | }); | 1169 | }); |
| 1157 | | 1170 | |
| 1158 | cases.add("generic function call assigned to incorrect type", | 1171 | ctx.objErrStage1("generic function call assigned to incorrect type", |
| 1159 | \\pub export fn entry() void { | 1172 | \\pub export fn entry() void { |
| 1160 | \\ var res: []i32 = undefined; | 1173 | \\ var res: []i32 = undefined; |
| 1161 | \\ res = myAlloc(i32); | 1174 | \\ res = myAlloc(i32); |
| ... | @@ -1167,12 +1180,25 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -1167,12 +1180,25 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1167 | "tmp.zig:3:18: error: expected type '[]i32', found 'anyerror!i32", | 1180 | "tmp.zig:3:18: error: expected type '[]i32', found 'anyerror!i32", |
| 1168 | }); | 1181 | }); |
| 1169 | | 1182 | |
| 1170 | cases.addTest("non-exhaustive enums", | 1183 | ctx.testErrStage1("non-exhaustive enum marker assigned a value", |
| 1171 | \\const A = enum { | 1184 | \\const A = enum { |
| 1172 | \\ a, | 1185 | \\ a, |
| 1173 | \\ b, | 1186 | \\ b, |
| 1174 | \\ _ = 1, | 1187 | \\ _ = 1, |
| 1175 | \\}; | 1188 | \\}; |
| | 1189 | \\const B = enum { |
| | 1190 | \\ a, |
| | 1191 | \\ b, |
| | 1192 | \\ _, |
| | 1193 | \\}; |
| | 1194 | \\comptime { _ = A; _ = B; } |
| | 1195 | , &[_][]const u8{ |
| | 1196 | "tmp.zig:4:9: error: '_' is used to mark an enum as non-exhaustive and cannot be assigned a value", |
| | 1197 | "tmp.zig:6:11: error: non-exhaustive enum missing integer tag type", |
| | 1198 | "tmp.zig:9:5: note: marked non-exhaustive here", |
| | 1199 | }); |
| | 1200 | |
| | 1201 | ctx.testErrStage1("non-exhaustive enums", |
| 1176 | \\const B = enum(u1) { | 1202 | \\const B = enum(u1) { |
| 1177 | \\ a, | 1203 | \\ a, |
| 1178 | \\ _, | 1204 | \\ _, |
| ... | @@ -1184,18 +1210,15 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -1184,18 +1210,15 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1184 | \\ _, | 1210 | \\ _, |
| 1185 | \\}; | 1211 | \\}; |
| 1186 | \\pub export fn entry() void { | 1212 | \\pub export fn entry() void { |
| 1187 | \\ _ = A; | | |
| 1188 | \\ _ = B; | 1213 | \\ _ = B; |
| 1189 | \\ _ = C; | 1214 | \\ _ = C; |
| 1190 | \\} | 1215 | \\} |
| 1191 | , &[_][]const u8{ | 1216 | , &[_][]const u8{ |
| 1192 | "tmp.zig:4:5: error: value assigned to '_' field of non-exhaustive enum", | 1217 | "tmp.zig:3:5: error: '_' field of non-exhaustive enum must be last", |
| 1193 | "error: non-exhaustive enum must specify size", | 1218 | "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 | }); | 1219 | }); |
| 1197 | | 1220 | |
| 1198 | cases.addTest("switching with non-exhaustive enums", | 1221 | ctx.testErrStage1("switching with non-exhaustive enums", |
| 1199 | \\const E = enum(u8) { | 1222 | \\const E = enum(u8) { |
| 1200 | \\ a, | 1223 | \\ a, |
| 1201 | \\ b, | 1224 | \\ b, |
| ... | @@ -1228,7 +1251,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -1228,7 +1251,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1228 | "tmp.zig:21:5: error: `_` prong not allowed when switching on tagged union", | 1251 | "tmp.zig:21:5: error: `_` prong not allowed when switching on tagged union", |
| 1229 | }); | 1252 | }); |
| 1230 | | 1253 | |
| 1231 | cases.add("switch expression - unreachable else prong (bool)", | 1254 | ctx.objErrStage1("switch expression - unreachable else prong (bool)", |
| 1232 | \\fn foo(x: bool) void { | 1255 | \\fn foo(x: bool) void { |
| 1233 | \\ switch (x) { | 1256 | \\ switch (x) { |
| 1234 | \\ true => {}, | 1257 | \\ true => {}, |
| ... | @@ -1241,7 +1264,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -1241,7 +1264,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1241 | "tmp.zig:5:9: error: unreachable else prong, all cases already handled", | 1264 | "tmp.zig:5:9: error: unreachable else prong, all cases already handled", |
| 1242 | }); | 1265 | }); |
| 1243 | | 1266 | |
| 1244 | cases.add("switch expression - unreachable else prong (u1)", | 1267 | ctx.objErrStage1("switch expression - unreachable else prong (u1)", |
| 1245 | \\fn foo(x: u1) void { | 1268 | \\fn foo(x: u1) void { |
| 1246 | \\ switch (x) { | 1269 | \\ switch (x) { |
| 1247 | \\ 0 => {}, | 1270 | \\ 0 => {}, |
| ... | @@ -1254,7 +1277,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -1254,7 +1277,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1254 | "tmp.zig:5:9: error: unreachable else prong, all cases already handled", | 1277 | "tmp.zig:5:9: error: unreachable else prong, all cases already handled", |
| 1255 | }); | 1278 | }); |
| 1256 | | 1279 | |
| 1257 | cases.add("switch expression - unreachable else prong (u2)", | 1280 | ctx.objErrStage1("switch expression - unreachable else prong (u2)", |
| 1258 | \\fn foo(x: u2) void { | 1281 | \\fn foo(x: u2) void { |
| 1259 | \\ switch (x) { | 1282 | \\ switch (x) { |
| 1260 | \\ 0 => {}, | 1283 | \\ 0 => {}, |
| ... | @@ -1269,7 +1292,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -1269,7 +1292,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1269 | "tmp.zig:7:9: error: unreachable else prong, all cases already handled", | 1292 | "tmp.zig:7:9: error: unreachable else prong, all cases already handled", |
| 1270 | }); | 1293 | }); |
| 1271 | | 1294 | |
| 1272 | cases.add("switch expression - unreachable else prong (range u8)", | 1295 | ctx.objErrStage1("switch expression - unreachable else prong (range u8)", |
| 1273 | \\fn foo(x: u8) void { | 1296 | \\fn foo(x: u8) void { |
| 1274 | \\ switch (x) { | 1297 | \\ switch (x) { |
| 1275 | \\ 0 => {}, | 1298 | \\ 0 => {}, |
| ... | @@ -1285,7 +1308,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -1285,7 +1308,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1285 | "tmp.zig:8:9: error: unreachable else prong, all cases already handled", | 1308 | "tmp.zig:8:9: error: unreachable else prong, all cases already handled", |
| 1286 | }); | 1309 | }); |
| 1287 | | 1310 | |
| 1288 | cases.add("switch expression - unreachable else prong (range i8)", | 1311 | ctx.objErrStage1("switch expression - unreachable else prong (range i8)", |
| 1289 | \\fn foo(x: i8) void { | 1312 | \\fn foo(x: i8) void { |
| 1290 | \\ switch (x) { | 1313 | \\ switch (x) { |
| 1291 | \\ -128...0 => {}, | 1314 | \\ -128...0 => {}, |
| ... | @@ -1301,7 +1324,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -1301,7 +1324,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1301 | "tmp.zig:8:9: error: unreachable else prong, all cases already handled", | 1324 | "tmp.zig:8:9: error: unreachable else prong, all cases already handled", |
| 1302 | }); | 1325 | }); |
| 1303 | | 1326 | |
| 1304 | cases.add("switch expression - unreachable else prong (enum)", | 1327 | ctx.objErrStage1("switch expression - unreachable else prong (enum)", |
| 1305 | \\const TestEnum = enum{ T1, T2 }; | 1328 | \\const TestEnum = enum{ T1, T2 }; |
| 1306 | \\ | 1329 | \\ |
| 1307 | \\fn err(x: u8) TestEnum { | 1330 | \\fn err(x: u8) TestEnum { |
| ... | @@ -1324,7 +1347,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -1324,7 +1347,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1324 | "tmp.zig:14:9: error: unreachable else prong, all cases already handled", | 1347 | "tmp.zig:14:9: error: unreachable else prong, all cases already handled", |
| 1325 | }); | 1348 | }); |
| 1326 | | 1349 | |
| 1327 | cases.addTest("@export with empty name string", | 1350 | ctx.testErrStage1("@export with empty name string", |
| 1328 | \\pub export fn entry() void { } | 1351 | \\pub export fn entry() void { } |
| 1329 | \\comptime { | 1352 | \\comptime { |
| 1330 | \\ @export(entry, .{ .name = "" }); | 1353 | \\ @export(entry, .{ .name = "" }); |
| ... | @@ -1333,7 +1356,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -1333,7 +1356,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1333 | "tmp.zig:3:5: error: exported symbol name cannot be empty", | 1356 | "tmp.zig:3:5: error: exported symbol name cannot be empty", |
| 1334 | }); | 1357 | }); |
| 1335 | | 1358 | |
| 1336 | cases.addTest("switch ranges endpoints are validated", | 1359 | ctx.testErrStage1("switch ranges endpoints are validated", |
| 1337 | \\pub export fn entry() void { | 1360 | \\pub export fn entry() void { |
| 1338 | \\ var x: i32 = 0; | 1361 | \\ var x: i32 = 0; |
| 1339 | \\ switch (x) { | 1362 | \\ switch (x) { |
| ... | @@ -1347,16 +1370,16 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -1347,16 +1370,16 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1347 | "tmp.zig:5:9: error: range start value is greater than the end value", | 1370 | "tmp.zig:5:9: error: range start value is greater than the end value", |
| 1348 | }); | 1371 | }); |
| 1349 | | 1372 | |
| 1350 | cases.addTest("errors in for loop bodies are propagated", | 1373 | ctx.testErrStage1("errors in for loop bodies are propagated", |
| 1351 | \\pub export fn entry() void { | 1374 | \\pub export fn entry() void { |
| 1352 | \\ var arr: [100]u8 = undefined; | 1375 | \\ var arr: [100]u8 = undefined; |
| 1353 | \\ for (arr) |bits| _ = @popCount(bits); | 1376 | \\ for (arr) |bits| _ = @popCount(bits); |
| 1354 | \\} | 1377 | \\} |
| 1355 | , &[_][]const u8{ | 1378 | , &[_][]const u8{ |
| 1356 | "tmp.zig:3:26: error: expected 2 argument(s), found 1", | 1379 | "tmp.zig:3:26: error: expected 2 arguments, found 1", |
| 1357 | }); | 1380 | }); |
| 1358 | | 1381 | |
| 1359 | cases.addTest("@call rejects non comptime-known fn - always_inline", | 1382 | ctx.testErrStage1("@call rejects non comptime-known fn - always_inline", |
| 1360 | \\pub export fn entry() void { | 1383 | \\pub export fn entry() void { |
| 1361 | \\ var call_me: fn () void = undefined; | 1384 | \\ var call_me: fn () void = undefined; |
| 1362 | \\ @call(.{ .modifier = .always_inline }, call_me, .{}); | 1385 | \\ @call(.{ .modifier = .always_inline }, call_me, .{}); |
| ... | @@ -1365,7 +1388,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -1365,7 +1388,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1365 | "tmp.zig:3:5: error: the specified modifier requires a comptime-known function", | 1388 | "tmp.zig:3:5: error: the specified modifier requires a comptime-known function", |
| 1366 | }); | 1389 | }); |
| 1367 | | 1390 | |
| 1368 | cases.addTest("@call rejects non comptime-known fn - compile_time", | 1391 | ctx.testErrStage1("@call rejects non comptime-known fn - compile_time", |
| 1369 | \\pub export fn entry() void { | 1392 | \\pub export fn entry() void { |
| 1370 | \\ var call_me: fn () void = undefined; | 1393 | \\ var call_me: fn () void = undefined; |
| 1371 | \\ @call(.{ .modifier = .compile_time }, call_me, .{}); | 1394 | \\ @call(.{ .modifier = .compile_time }, call_me, .{}); |
| ... | @@ -1374,19 +1397,20 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -1374,19 +1397,20 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1374 | "tmp.zig:3:5: error: the specified modifier requires a comptime-known function", | 1397 | "tmp.zig:3:5: error: the specified modifier requires a comptime-known function", |
| 1375 | }); | 1398 | }); |
| 1376 | | 1399 | |
| 1377 | cases.addTest("error in struct initializer doesn't crash the compiler", | 1400 | ctx.testErrStage1("error in struct initializer doesn't crash the compiler", |
| 1378 | \\pub export fn entry() void { | 1401 | \\pub export fn entry() void { |
| 1379 | \\ const bitfield = struct { | 1402 | \\ const bitfield = struct { |
| 1380 | \\ e: u8, | 1403 | \\ e: u8, |
| 1381 | \\ e: u8, | 1404 | \\ e: u8, |
| 1382 | \\ }; | 1405 | \\ }; |
| 1383 | \\ var a = .{@sizeOf(bitfield)}; | 1406 | \\ var a = .{@sizeOf(bitfield)}; |
| | 1407 | \\ _ = a; |
| 1384 | \\} | 1408 | \\} |
| 1385 | , &[_][]const u8{ | 1409 | , &[_][]const u8{ |
| 1386 | "tmp.zig:4:9: error: duplicate struct field: 'e'", | 1410 | "tmp.zig:4:9: error: duplicate struct field: 'e'", |
| 1387 | }); | 1411 | }); |
| 1388 | | 1412 | |
| 1389 | cases.addTest("repeated invalid field access to generic function returning type crashes compiler. #2655", | 1413 | ctx.testErrStage1("repeated invalid field access to generic function returning type crashes compiler. #2655", |
| 1390 | \\pub fn A() type { | 1414 | \\pub fn A() type { |
| 1391 | \\ return Q; | 1415 | \\ return Q; |
| 1392 | \\} | 1416 | \\} |
| ... | @@ -1398,15 +1422,16 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -1398,15 +1422,16 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1398 | "tmp.zig:2:12: error: use of undeclared identifier 'Q'", | 1422 | "tmp.zig:2:12: error: use of undeclared identifier 'Q'", |
| 1399 | }); | 1423 | }); |
| 1400 | | 1424 | |
| 1401 | cases.add("bitCast to enum type", | 1425 | ctx.objErrStage1("bitCast to enum type", |
| 1402 | \\export fn entry() void { | 1426 | \\export fn entry() void { |
| 1403 | \\ const y = @bitCast(enum(u32) { a, b }, @as(u32, 3)); | 1427 | \\ const y = @bitCast(enum(u32) { a, b }, @as(u32, 3)); |
| | 1428 | \\ _ = y; |
| 1404 | \\} | 1429 | \\} |
| 1405 | , &[_][]const u8{ | 1430 | , &[_][]const u8{ |
| 1406 | "tmp.zig:2:24: error: cannot cast a value of type 'y'", | 1431 | "tmp.zig:2:24: error: cannot cast a value of type 'y'", |
| 1407 | }); | 1432 | }); |
| 1408 | | 1433 | |
| 1409 | cases.add("comparing against undefined produces undefined value", | 1434 | ctx.objErrStage1("comparing against undefined produces undefined value", |
| 1410 | \\export fn entry() void { | 1435 | \\export fn entry() void { |
| 1411 | \\ if (2 == undefined) {} | 1436 | \\ if (2 == undefined) {} |
| 1412 | \\} | 1437 | \\} |
| ... | @@ -1414,17 +1439,18 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -1414,17 +1439,18 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1414 | "tmp.zig:2:11: error: use of undefined value here causes undefined behavior", | 1439 | "tmp.zig:2:11: error: use of undefined value here causes undefined behavior", |
| 1415 | }); | 1440 | }); |
| 1416 | | 1441 | |
| 1417 | cases.add("comptime ptrcast of zero-sized type", | 1442 | ctx.objErrStage1("comptime ptrcast of zero-sized type", |
| 1418 | \\fn foo() void { | 1443 | \\fn foo() void { |
| 1419 | \\ const node: struct {} = undefined; | 1444 | \\ const node: struct {} = undefined; |
| 1420 | \\ const vla_ptr = @ptrCast([*]const u8, &node); | 1445 | \\ const vla_ptr = @ptrCast([*]const u8, &node); |
| | 1446 | \\ _ = vla_ptr; |
| 1421 | \\} | 1447 | \\} |
| 1422 | \\comptime { foo(); } | 1448 | \\comptime { foo(); } |
| 1423 | , &[_][]const u8{ | 1449 | , &[_][]const u8{ |
| 1424 | "tmp.zig:3:21: error: '*const struct:2:17' and '[*]const u8' do not have the same in-memory representation", | 1450 | "tmp.zig:3:21: error: '*const struct:2:17' and '[*]const u8' do not have the same in-memory representation", |
| 1425 | }); | 1451 | }); |
| 1426 | | 1452 | |
| 1427 | cases.add("slice sentinel mismatch", | 1453 | ctx.objErrStage1("slice sentinel mismatch", |
| 1428 | \\fn foo() [:0]u8 { | 1454 | \\fn foo() [:0]u8 { |
| 1429 | \\ var x: []u8 = undefined; | 1455 | \\ var x: []u8 = undefined; |
| 1430 | \\ return x; | 1456 | \\ return x; |
| ... | @@ -1435,7 +1461,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -1435,7 +1461,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1435 | "tmp.zig:3:12: note: destination pointer requires a terminating '0' sentinel", | 1461 | "tmp.zig:3:12: note: destination pointer requires a terminating '0' sentinel", |
| 1436 | }); | 1462 | }); |
| 1437 | | 1463 | |
| 1438 | cases.add("cmpxchg with float", | 1464 | ctx.objErrStage1("cmpxchg with float", |
| 1439 | \\export fn entry() void { | 1465 | \\export fn entry() void { |
| 1440 | \\ var x: f32 = 0; | 1466 | \\ var x: f32 = 0; |
| 1441 | \\ _ = @cmpxchgWeak(f32, &x, 1, 2, .SeqCst, .SeqCst); | 1467 | \\ _ = @cmpxchgWeak(f32, &x, 1, 2, .SeqCst, .SeqCst); |
| ... | @@ -1444,7 +1470,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -1444,7 +1470,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1444 | "tmp.zig:3:22: error: expected bool, integer, enum or pointer type, found 'f32'", | 1470 | "tmp.zig:3:22: error: expected bool, integer, enum or pointer type, found 'f32'", |
| 1445 | }); | 1471 | }); |
| 1446 | | 1472 | |
| 1447 | cases.add("atomicrmw with float op not .Xchg, .Add or .Sub", | 1473 | ctx.objErrStage1("atomicrmw with float op not .Xchg, .Add or .Sub", |
| 1448 | \\export fn entry() void { | 1474 | \\export fn entry() void { |
| 1449 | \\ var x: f32 = 0; | 1475 | \\ var x: f32 = 0; |
| 1450 | \\ _ = @atomicRmw(f32, &x, .And, 2, .SeqCst); | 1476 | \\ _ = @atomicRmw(f32, &x, .And, 2, .SeqCst); |
| ... | @@ -1453,15 +1479,16 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -1453,15 +1479,16 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1453 | "tmp.zig:3:29: error: @atomicRmw with float only allowed with .Xchg, .Add and .Sub", | 1479 | "tmp.zig:3:29: error: @atomicRmw with float only allowed with .Xchg, .Add and .Sub", |
| 1454 | }); | 1480 | }); |
| 1455 | | 1481 | |
| 1456 | cases.add("intToPtr with misaligned address", | 1482 | ctx.objErrStage1("intToPtr with misaligned address", |
| 1457 | \\pub fn main() void { | 1483 | \\pub fn main() void { |
| 1458 | \\ var y = @intToPtr([*]align(4) u8, 5); | 1484 | \\ var y = @intToPtr([*]align(4) u8, 5); |
| | 1485 | \\ _ = y; |
| 1459 | \\} | 1486 | \\} |
| 1460 | , &[_][]const u8{ | 1487 | , &[_][]const u8{ |
| 1461 | "tmp.zig:2:13: error: pointer type '[*]align(4) u8' requires aligned address", | 1488 | "tmp.zig:2:13: error: pointer type '[*]align(4) u8' requires aligned address", |
| 1462 | }); | 1489 | }); |
| 1463 | | 1490 | |
| 1464 | cases.add("invalid float literal", | 1491 | ctx.objErrStage1("invalid float literal", |
| 1465 | \\const std = @import("std"); | 1492 | \\const std = @import("std"); |
| 1466 | \\ | 1493 | \\ |
| 1467 | \\pub fn main() void { | 1494 | \\pub fn main() void { |
| ... | @@ -1473,170 +1500,190 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -1473,170 +1500,190 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1473 | "tmp.zig:5:29: error: invalid token: '.'", | 1500 | "tmp.zig:5:29: error: invalid token: '.'", |
| 1474 | }); | 1501 | }); |
| 1475 | | 1502 | |
| 1476 | cases.add("invalid exponent in float literal - 1", | 1503 | ctx.objErrStage1("invalid exponent in float literal - 1", |
| 1477 | \\fn main() void { | 1504 | \\fn main() void { |
| 1478 | \\ var bad: f128 = 0x1.0p1ab1; | 1505 | \\ var bad: f128 = 0x1.0p1ab1; |
| | 1506 | \\ _ = bad; |
| 1479 | \\} | 1507 | \\} |
| 1480 | , &[_][]const u8{ | 1508 | , &[_][]const u8{ |
| 1481 | "tmp.zig:2:28: error: invalid character: 'a'", | 1509 | "tmp.zig:2:28: error: invalid character: 'a'", |
| 1482 | }); | 1510 | }); |
| 1483 | | 1511 | |
| 1484 | cases.add("invalid exponent in float literal - 2", | 1512 | ctx.objErrStage1("invalid exponent in float literal - 2", |
| 1485 | \\fn main() void { | 1513 | \\fn main() void { |
| 1486 | \\ var bad: f128 = 0x1.0p50F; | 1514 | \\ var bad: f128 = 0x1.0p50F; |
| | 1515 | \\ _ = bad; |
| 1487 | \\} | 1516 | \\} |
| 1488 | , &[_][]const u8{ | 1517 | , &[_][]const u8{ |
| 1489 | "tmp.zig:2:29: error: invalid character: 'F'", | 1518 | "tmp.zig:2:29: error: invalid character: 'F'", |
| 1490 | }); | 1519 | }); |
| 1491 | | 1520 | |
| 1492 | cases.add("invalid underscore placement in float literal - 1", | 1521 | ctx.objErrStage1("invalid underscore placement in float literal - 1", |
| 1493 | \\fn main() void { | 1522 | \\fn main() void { |
| 1494 | \\ var bad: f128 = 0._0; | 1523 | \\ var bad: f128 = 0._0; |
| | 1524 | \\ _ = bad; |
| 1495 | \\} | 1525 | \\} |
| 1496 | , &[_][]const u8{ | 1526 | , &[_][]const u8{ |
| 1497 | "tmp.zig:2:23: error: invalid character: '_'", | 1527 | "tmp.zig:2:23: error: invalid character: '_'", |
| 1498 | }); | 1528 | }); |
| 1499 | | 1529 | |
| 1500 | cases.add("invalid underscore placement in float literal - 2", | 1530 | ctx.objErrStage1("invalid underscore placement in float literal - 2", |
| 1501 | \\fn main() void { | 1531 | \\fn main() void { |
| 1502 | \\ var bad: f128 = 0_.0; | 1532 | \\ var bad: f128 = 0_.0; |
| | 1533 | \\ _ = bad; |
| 1503 | \\} | 1534 | \\} |
| 1504 | , &[_][]const u8{ | 1535 | , &[_][]const u8{ |
| 1505 | "tmp.zig:2:23: error: invalid character: '.'", | 1536 | "tmp.zig:2:23: error: invalid character: '.'", |
| 1506 | }); | 1537 | }); |
| 1507 | | 1538 | |
| 1508 | cases.add("invalid underscore placement in float literal - 3", | 1539 | ctx.objErrStage1("invalid underscore placement in float literal - 3", |
| 1509 | \\fn main() void { | 1540 | \\fn main() void { |
| 1510 | \\ var bad: f128 = 0.0_; | 1541 | \\ var bad: f128 = 0.0_; |
| | 1542 | \\ _ = bad; |
| 1511 | \\} | 1543 | \\} |
| 1512 | , &[_][]const u8{ | 1544 | , &[_][]const u8{ |
| 1513 | "tmp.zig:2:25: error: invalid character: ';'", | 1545 | "tmp.zig:2:25: error: invalid character: ';'", |
| 1514 | }); | 1546 | }); |
| 1515 | | 1547 | |
| 1516 | cases.add("invalid underscore placement in float literal - 4", | 1548 | ctx.objErrStage1("invalid underscore placement in float literal - 4", |
| 1517 | \\fn main() void { | 1549 | \\fn main() void { |
| 1518 | \\ var bad: f128 = 1.0e_1; | 1550 | \\ var bad: f128 = 1.0e_1; |
| | 1551 | \\ _ = bad; |
| 1519 | \\} | 1552 | \\} |
| 1520 | , &[_][]const u8{ | 1553 | , &[_][]const u8{ |
| 1521 | "tmp.zig:2:25: error: invalid character: '_'", | 1554 | "tmp.zig:2:25: error: invalid character: '_'", |
| 1522 | }); | 1555 | }); |
| 1523 | | 1556 | |
| 1524 | cases.add("invalid underscore placement in float literal - 5", | 1557 | ctx.objErrStage1("invalid underscore placement in float literal - 5", |
| 1525 | \\fn main() void { | 1558 | \\fn main() void { |
| 1526 | \\ var bad: f128 = 1.0e+_1; | 1559 | \\ var bad: f128 = 1.0e+_1; |
| | 1560 | \\ _ = bad; |
| 1527 | \\} | 1561 | \\} |
| 1528 | , &[_][]const u8{ | 1562 | , &[_][]const u8{ |
| 1529 | "tmp.zig:2:26: error: invalid character: '_'", | 1563 | "tmp.zig:2:26: error: invalid character: '_'", |
| 1530 | }); | 1564 | }); |
| 1531 | | 1565 | |
| 1532 | cases.add("invalid underscore placement in float literal - 6", | 1566 | ctx.objErrStage1("invalid underscore placement in float literal - 6", |
| 1533 | \\fn main() void { | 1567 | \\fn main() void { |
| 1534 | \\ var bad: f128 = 1.0e-_1; | 1568 | \\ var bad: f128 = 1.0e-_1; |
| | 1569 | \\ _ = bad; |
| 1535 | \\} | 1570 | \\} |
| 1536 | , &[_][]const u8{ | 1571 | , &[_][]const u8{ |
| 1537 | "tmp.zig:2:26: error: invalid character: '_'", | 1572 | "tmp.zig:2:26: error: invalid character: '_'", |
| 1538 | }); | 1573 | }); |
| 1539 | | 1574 | |
| 1540 | cases.add("invalid underscore placement in float literal - 7", | 1575 | ctx.objErrStage1("invalid underscore placement in float literal - 7", |
| 1541 | \\fn main() void { | 1576 | \\fn main() void { |
| 1542 | \\ var bad: f128 = 1.0e-1_; | 1577 | \\ var bad: f128 = 1.0e-1_; |
| | 1578 | \\ _ = bad; |
| 1543 | \\} | 1579 | \\} |
| 1544 | , &[_][]const u8{ | 1580 | , &[_][]const u8{ |
| 1545 | "tmp.zig:2:28: error: invalid character: ';'", | 1581 | "tmp.zig:2:28: error: invalid character: ';'", |
| 1546 | }); | 1582 | }); |
| 1547 | | 1583 | |
| 1548 | cases.add("invalid underscore placement in float literal - 9", | 1584 | ctx.objErrStage1("invalid underscore placement in float literal - 9", |
| 1549 | \\fn main() void { | 1585 | \\fn main() void { |
| 1550 | \\ var bad: f128 = 1__0.0e-1; | 1586 | \\ var bad: f128 = 1__0.0e-1; |
| | 1587 | \\ _ = bad; |
| 1551 | \\} | 1588 | \\} |
| 1552 | , &[_][]const u8{ | 1589 | , &[_][]const u8{ |
| 1553 | "tmp.zig:2:23: error: invalid character: '_'", | 1590 | "tmp.zig:2:23: error: invalid character: '_'", |
| 1554 | }); | 1591 | }); |
| 1555 | | 1592 | |
| 1556 | cases.add("invalid underscore placement in float literal - 10", | 1593 | ctx.objErrStage1("invalid underscore placement in float literal - 10", |
| 1557 | \\fn main() void { | 1594 | \\fn main() void { |
| 1558 | \\ var bad: f128 = 1.0__0e-1; | 1595 | \\ var bad: f128 = 1.0__0e-1; |
| | 1596 | \\ _ = bad; |
| 1559 | \\} | 1597 | \\} |
| 1560 | , &[_][]const u8{ | 1598 | , &[_][]const u8{ |
| 1561 | "tmp.zig:2:25: error: invalid character: '_'", | 1599 | "tmp.zig:2:25: error: invalid character: '_'", |
| 1562 | }); | 1600 | }); |
| 1563 | | 1601 | |
| 1564 | cases.add("invalid underscore placement in float literal - 11", | 1602 | ctx.objErrStage1("invalid underscore placement in float literal - 11", |
| 1565 | \\fn main() void { | 1603 | \\fn main() void { |
| 1566 | \\ var bad: f128 = 1.0e-1__0; | 1604 | \\ var bad: f128 = 1.0e-1__0; |
| | 1605 | \\ _ = bad; |
| 1567 | \\} | 1606 | \\} |
| 1568 | , &[_][]const u8{ | 1607 | , &[_][]const u8{ |
| 1569 | "tmp.zig:2:28: error: invalid character: '_'", | 1608 | "tmp.zig:2:28: error: invalid character: '_'", |
| 1570 | }); | 1609 | }); |
| 1571 | | 1610 | |
| 1572 | cases.add("invalid underscore placement in float literal - 12", | 1611 | ctx.objErrStage1("invalid underscore placement in float literal - 12", |
| 1573 | \\fn main() void { | 1612 | \\fn main() void { |
| 1574 | \\ var bad: f128 = 0_x0.0; | 1613 | \\ var bad: f128 = 0_x0.0; |
| | 1614 | \\ _ = bad; |
| 1575 | \\} | 1615 | \\} |
| 1576 | , &[_][]const u8{ | 1616 | , &[_][]const u8{ |
| 1577 | "tmp.zig:2:23: error: invalid character: 'x'", | 1617 | "tmp.zig:2:23: error: invalid character: 'x'", |
| 1578 | }); | 1618 | }); |
| 1579 | | 1619 | |
| 1580 | cases.add("invalid underscore placement in float literal - 13", | 1620 | ctx.objErrStage1("invalid underscore placement in float literal - 13", |
| 1581 | \\fn main() void { | 1621 | \\fn main() void { |
| 1582 | \\ var bad: f128 = 0x_0.0; | 1622 | \\ var bad: f128 = 0x_0.0; |
| | 1623 | \\ _ = bad; |
| 1583 | \\} | 1624 | \\} |
| 1584 | , &[_][]const u8{ | 1625 | , &[_][]const u8{ |
| 1585 | "tmp.zig:2:23: error: invalid character: '_'", | 1626 | "tmp.zig:2:23: error: invalid character: '_'", |
| 1586 | }); | 1627 | }); |
| 1587 | | 1628 | |
| 1588 | cases.add("invalid underscore placement in float literal - 14", | 1629 | ctx.objErrStage1("invalid underscore placement in float literal - 14", |
| 1589 | \\fn main() void { | 1630 | \\fn main() void { |
| 1590 | \\ var bad: f128 = 0x0.0_p1; | 1631 | \\ var bad: f128 = 0x0.0_p1; |
| | 1632 | \\ _ = bad; |
| 1591 | \\} | 1633 | \\} |
| 1592 | , &[_][]const u8{ | 1634 | , &[_][]const u8{ |
| 1593 | "tmp.zig:2:27: error: invalid character: 'p'", | 1635 | "tmp.zig:2:27: error: invalid character: 'p'", |
| 1594 | }); | 1636 | }); |
| 1595 | | 1637 | |
| 1596 | cases.add("invalid underscore placement in int literal - 1", | 1638 | ctx.objErrStage1("invalid underscore placement in int literal - 1", |
| 1597 | \\fn main() void { | 1639 | \\fn main() void { |
| 1598 | \\ var bad: u128 = 0010_; | 1640 | \\ var bad: u128 = 0010_; |
| | 1641 | \\ _ = bad; |
| 1599 | \\} | 1642 | \\} |
| 1600 | , &[_][]const u8{ | 1643 | , &[_][]const u8{ |
| 1601 | "tmp.zig:2:26: error: invalid character: ';'", | 1644 | "tmp.zig:2:26: error: invalid character: ';'", |
| 1602 | }); | 1645 | }); |
| 1603 | | 1646 | |
| 1604 | cases.add("invalid underscore placement in int literal - 2", | 1647 | ctx.objErrStage1("invalid underscore placement in int literal - 2", |
| 1605 | \\fn main() void { | 1648 | \\fn main() void { |
| 1606 | \\ var bad: u128 = 0b0010_; | 1649 | \\ var bad: u128 = 0b0010_; |
| | 1650 | \\ _ = bad; |
| 1607 | \\} | 1651 | \\} |
| 1608 | , &[_][]const u8{ | 1652 | , &[_][]const u8{ |
| 1609 | "tmp.zig:2:28: error: invalid character: ';'", | 1653 | "tmp.zig:2:28: error: invalid character: ';'", |
| 1610 | }); | 1654 | }); |
| 1611 | | 1655 | |
| 1612 | cases.add("invalid underscore placement in int literal - 3", | 1656 | ctx.objErrStage1("invalid underscore placement in int literal - 3", |
| 1613 | \\fn main() void { | 1657 | \\fn main() void { |
| 1614 | \\ var bad: u128 = 0o0010_; | 1658 | \\ var bad: u128 = 0o0010_; |
| | 1659 | \\ _ = bad; |
| 1615 | \\} | 1660 | \\} |
| 1616 | , &[_][]const u8{ | 1661 | , &[_][]const u8{ |
| 1617 | "tmp.zig:2:28: error: invalid character: ';'", | 1662 | "tmp.zig:2:28: error: invalid character: ';'", |
| 1618 | }); | 1663 | }); |
| 1619 | | 1664 | |
| 1620 | cases.add("invalid underscore placement in int literal - 4", | 1665 | ctx.objErrStage1("invalid underscore placement in int literal - 4", |
| 1621 | \\fn main() void { | 1666 | \\fn main() void { |
| 1622 | \\ var bad: u128 = 0x0010_; | 1667 | \\ var bad: u128 = 0x0010_; |
| | 1668 | \\ _ = bad; |
| 1623 | \\} | 1669 | \\} |
| 1624 | , &[_][]const u8{ | 1670 | , &[_][]const u8{ |
| 1625 | "tmp.zig:2:28: error: invalid character: ';'", | 1671 | "tmp.zig:2:28: error: invalid character: ';'", |
| 1626 | }); | 1672 | }); |
| 1627 | | 1673 | |
| 1628 | cases.add("comptime struct field, no init value", | 1674 | ctx.objErrStage1("comptime struct field, no init value", |
| 1629 | \\const Foo = struct { | 1675 | \\const Foo = struct { |
| 1630 | \\ comptime b: i32, | 1676 | \\ comptime b: i32, |
| 1631 | \\}; | 1677 | \\}; |
| 1632 | \\export fn entry() void { | 1678 | \\export fn entry() void { |
| 1633 | \\ var f: Foo = undefined; | 1679 | \\ var f: Foo = undefined; |
| | 1680 | \\ _ = f; |
| 1634 | \\} | 1681 | \\} |
| 1635 | , &[_][]const u8{ | 1682 | , &[_][]const u8{ |
| 1636 | "tmp.zig:2:5: error: comptime struct field missing initialization value", | 1683 | "tmp.zig:2:5: error: comptime field without default initialization value", |
| 1637 | }); | 1684 | }); |
| 1638 | | 1685 | |
| 1639 | cases.add("bad usage of @call", | 1686 | ctx.objErrStage1("bad usage of @call", |
| 1640 | \\export fn entry1() void { | 1687 | \\export fn entry1() void { |
| 1641 | \\ @call(.{}, foo, {}); | 1688 | \\ @call(.{}, foo, {}); |
| 1642 | \\} | 1689 | \\} |
| ... | @@ -1665,20 +1712,26 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -1665,20 +1712,26 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1665 | "tmp.zig:15:5: error: the specified modifier requires a comptime-known function", | 1712 | "tmp.zig:15:5: error: the specified modifier requires a comptime-known function", |
| 1666 | }); | 1713 | }); |
| 1667 | | 1714 | |
| 1668 | cases.add("exported async function", | 1715 | ctx.objErrStage1("exported async function", |
| 1669 | \\export fn foo() callconv(.Async) void {} | 1716 | \\export fn foo() callconv(.Async) void {} |
| 1670 | , &[_][]const u8{ | 1717 | , &[_][]const u8{ |
| 1671 | "tmp.zig:1:1: error: exported function cannot be async", | 1718 | "tmp.zig:1:1: error: exported function cannot be async", |
| 1672 | }); | 1719 | }); |
| 1673 | | 1720 | |
| 1674 | cases.addExe("main missing name", | 1721 | ctx.exeErrStage1("main missing name", |
| 1675 | \\pub fn (main) void {} | 1722 | \\pub fn (main) void {} |
| 1676 | , &[_][]const u8{ | 1723 | , &[_][]const u8{ |
| 1677 | "tmp.zig:1:5: error: missing function name", | 1724 | "tmp.zig:1:5: error: missing function name", |
| 1678 | }); | 1725 | }); |
| 1679 | | 1726 | |
| 1680 | cases.addCase(x: { | 1727 | { |
| 1681 | var tc = cases.create("call with new stack on unsupported target", | 1728 | const case = ctx.obj("call with new stack on unsupported target", .{ |
| | 1729 | .cpu_arch = .wasm32, |
| | 1730 | .os_tag = .wasi, |
| | 1731 | .abi = .none, |
| | 1732 | }); |
| | 1733 | case.backend = .stage1; |
| | 1734 | case.addError( |
| 1682 | \\var buf: [10]u8 align(16) = undefined; | 1735 | \\var buf: [10]u8 align(16) = undefined; |
| 1683 | \\export fn entry() void { | 1736 | \\export fn entry() void { |
| 1684 | \\ @call(.{.stack = &buf}, foo, .{}); | 1737 | \\ @call(.{.stack = &buf}, foo, .{}); |
| ... | @@ -1687,17 +1740,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -1687,17 +1740,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1687 | , &[_][]const u8{ | 1740 | , &[_][]const u8{ |
| 1688 | "tmp.zig:3:5: error: target arch 'wasm32' does not support calling with a new stack", | 1741 | "tmp.zig:3:5: error: target arch 'wasm32' does not support calling with a new stack", |
| 1689 | }); | 1742 | }); |
| 1690 | tc.target = std.zig.CrossTarget{ | 1743 | } |
| 1691 | .cpu_arch = .wasm32, | | |
| 1692 | .os_tag = .wasi, | | |
| 1693 | .abi = .none, | | |
| 1694 | }; | | |
| 1695 | break :x tc; | | |
| 1696 | }); | | |
| 1697 | | 1744 | |
| 1698 | // Note: One of the error messages here is backwards. It would be nice to fix, but that's not | 1745 | // 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. | 1746 | // going to stop me from merging this branch which fixes a bunch of other stuff. |
| 1700 | cases.add("incompatible sentinels", | 1747 | ctx.objErrStage1("incompatible sentinels", |
| 1701 | \\export fn entry1(ptr: [*:255]u8) [*:0]u8 { | 1748 | \\export fn entry1(ptr: [*:255]u8) [*:0]u8 { |
| 1702 | \\ return ptr; | 1749 | \\ return ptr; |
| 1703 | \\} | 1750 | \\} |
| ... | @@ -1706,9 +1753,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -1706,9 +1753,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1706 | \\} | 1753 | \\} |
| 1707 | \\export fn entry3() void { | 1754 | \\export fn entry3() void { |
| 1708 | \\ var array: [2:0]u8 = [_:255]u8{1, 2}; | 1755 | \\ var array: [2:0]u8 = [_:255]u8{1, 2}; |
| | 1756 | \\ _ = array; |
| 1709 | \\} | 1757 | \\} |
| 1710 | \\export fn entry4() void { | 1758 | \\export fn entry4() void { |
| 1711 | \\ var array: [2:0]u8 = [_]u8{1, 2}; | 1759 | \\ var array: [2:0]u8 = [_]u8{1, 2}; |
| | 1760 | \\ _ = array; |
| 1712 | \\} | 1761 | \\} |
| 1713 | , &[_][]const u8{ | 1762 | , &[_][]const u8{ |
| 1714 | "tmp.zig:2:12: error: expected type '[*:0]u8', found '[*:255]u8'", | 1763 | "tmp.zig:2:12: error: expected type '[*:0]u8', found '[*:255]u8'", |
| ... | @@ -1718,11 +1767,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -1718,11 +1767,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1718 | | 1767 | |
| 1719 | "tmp.zig:8:35: error: expected type '[2:255]u8', found '[2:0]u8'", | 1768 | "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", | 1769 | "tmp.zig:8:35: note: destination array requires a terminating '255' sentinel, but source array has a terminating '0' sentinel", |
| 1721 | "tmp.zig:11:31: error: expected type '[2:0]u8', found '[2]u8'", | 1770 | "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", | 1771 | "tmp.zig:12:31: note: destination array requires a terminating '0' sentinel", |
| 1723 | }); | 1772 | }); |
| 1724 | | 1773 | |
| 1725 | cases.add("empty switch on an integer", | 1774 | ctx.objErrStage1("empty switch on an integer", |
| 1726 | \\export fn entry() void { | 1775 | \\export fn entry() void { |
| 1727 | \\ var x: u32 = 0; | 1776 | \\ var x: u32 = 0; |
| 1728 | \\ switch(x) {} | 1777 | \\ switch(x) {} |
| ... | @@ -1731,7 +1780,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -1731,7 +1780,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1731 | "tmp.zig:3:5: error: switch must handle all possibilities", | 1780 | "tmp.zig:3:5: error: switch must handle all possibilities", |
| 1732 | }); | 1781 | }); |
| 1733 | | 1782 | |
| 1734 | cases.add("incorrect return type", | 1783 | ctx.objErrStage1("incorrect return type", |
| 1735 | \\ pub export fn entry() void{ | 1784 | \\ pub export fn entry() void{ |
| 1736 | \\ _ = foo(); | 1785 | \\ _ = foo(); |
| 1737 | \\ } | 1786 | \\ } |
| ... | @@ -1751,12 +1800,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -1751,12 +1800,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1751 | "tmp.zig:8:16: error: expected type 'A', found 'B'", | 1800 | "tmp.zig:8:16: error: expected type 'A', found 'B'", |
| 1752 | }); | 1801 | }); |
| 1753 | | 1802 | |
| 1754 | cases.add("regression test #2980: base type u32 is not type checked properly when assigning a value within a struct", | 1803 | ctx.objErrStage1("regression test #2980: base type u32 is not type checked properly when assigning a value within a struct", |
| 1755 | \\const Foo = struct { | 1804 | \\const Foo = struct { |
| 1756 | \\ ptr: ?*usize, | 1805 | \\ ptr: ?*usize, |
| 1757 | \\ uval: u32, | 1806 | \\ uval: u32, |
| 1758 | \\}; | 1807 | \\}; |
| 1759 | \\fn get_uval(x: u32) !u32 { | 1808 | \\fn get_uval(x: u32) !u32 { |
| | 1809 | \\ _ = x; |
| 1760 | \\ return error.NotFound; | 1810 | \\ return error.NotFound; |
| 1761 | \\} | 1811 | \\} |
| 1762 | \\export fn entry() void { | 1812 | \\export fn entry() void { |
| ... | @@ -1764,12 +1814,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -1764,12 +1814,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1764 | \\ .ptr = null, | 1814 | \\ .ptr = null, |
| 1765 | \\ .uval = get_uval(42), | 1815 | \\ .uval = get_uval(42), |
| 1766 | \\ }; | 1816 | \\ }; |
| | 1817 | \\ _ = afoo; |
| 1767 | \\} | 1818 | \\} |
| 1768 | , &[_][]const u8{ | 1819 | , &[_][]const u8{ |
| 1769 | "tmp.zig:11:25: error: expected type 'u32', found '@typeInfo(@typeInfo(@TypeOf(get_uval)).Fn.return_type.?).ErrorUnion.error_set!u32'", | 1820 | "tmp.zig:12:25: error: expected type 'u32', found '@typeInfo(@typeInfo(@TypeOf(get_uval)).Fn.return_type.?).ErrorUnion.error_set!u32'", |
| 1770 | }); | 1821 | }); |
| 1771 | | 1822 | |
| 1772 | cases.add("assigning to struct or union fields that are not optionals with a function that returns an optional", | 1823 | ctx.objErrStage1("assigning to struct or union fields that are not optionals with a function that returns an optional", |
| 1773 | \\fn maybe(is: bool) ?u8 { | 1824 | \\fn maybe(is: bool) ?u8 { |
| 1774 | \\ if (is) return @as(u8, 10) else return null; | 1825 | \\ if (is) return @as(u8, 10) else return null; |
| 1775 | \\} | 1826 | \\} |
| ... | @@ -1782,12 +1833,14 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -1782,12 +1833,14 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1782 | \\export fn entry() void { | 1833 | \\export fn entry() void { |
| 1783 | \\ var u = U{ .Ye = maybe(false) }; | 1834 | \\ var u = U{ .Ye = maybe(false) }; |
| 1784 | \\ var s = S{ .num = maybe(false) }; | 1835 | \\ var s = S{ .num = maybe(false) }; |
| | 1836 | \\ _ = u; |
| | 1837 | \\ _ = s; |
| 1785 | \\} | 1838 | \\} |
| 1786 | , &[_][]const u8{ | 1839 | , &[_][]const u8{ |
| 1787 | "tmp.zig:11:27: error: expected type 'u8', found '?u8'", | 1840 | "tmp.zig:11:27: error: expected type 'u8', found '?u8'", |
| 1788 | }); | 1841 | }); |
| 1789 | | 1842 | |
| 1790 | cases.add("missing result type for phi node", | 1843 | ctx.objErrStage1("missing result type for phi node", |
| 1791 | \\fn foo() !void { | 1844 | \\fn foo() !void { |
| 1792 | \\ return anyerror.Foo; | 1845 | \\ return anyerror.Foo; |
| 1793 | \\} | 1846 | \\} |
| ... | @@ -1798,7 +1851,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -1798,7 +1851,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1798 | "tmp.zig:5:17: error: integer value 0 cannot be coerced to type 'void'", | 1851 | "tmp.zig:5:17: error: integer value 0 cannot be coerced to type 'void'", |
| 1799 | }); | 1852 | }); |
| 1800 | | 1853 | |
| 1801 | cases.add("atomicrmw with enum op not .Xchg", | 1854 | ctx.objErrStage1("atomicrmw with enum op not .Xchg", |
| 1802 | \\export fn entry() void { | 1855 | \\export fn entry() void { |
| 1803 | \\ const E = enum(u8) { | 1856 | \\ const E = enum(u8) { |
| 1804 | \\ a, | 1857 | \\ a, |
| ... | @@ -1813,7 +1866,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -1813,7 +1866,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1813 | "tmp.zig:9:27: error: @atomicRmw with enum only allowed with .Xchg", | 1866 | "tmp.zig:9:27: error: @atomicRmw with enum only allowed with .Xchg", |
| 1814 | }); | 1867 | }); |
| 1815 | | 1868 | |
| 1816 | cases.add("disallow coercion from non-null-terminated pointer to null-terminated pointer", | 1869 | ctx.objErrStage1("disallow coercion from non-null-terminated pointer to null-terminated pointer", |
| 1817 | \\extern fn puts(s: [*:0]const u8) c_int; | 1870 | \\extern fn puts(s: [*:0]const u8) c_int; |
| 1818 | \\pub fn main() void { | 1871 | \\pub fn main() void { |
| 1819 | \\ const no_zero_array = [_]u8{'h', 'e', 'l', 'l', 'o'}; | 1872 | \\ const no_zero_array = [_]u8{'h', 'e', 'l', 'l', 'o'}; |
| ... | @@ -1824,7 +1877,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -1824,7 +1877,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1824 | "tmp.zig:5:14: error: expected type '[*:0]const u8', found '[*]const u8'", | 1877 | "tmp.zig:5:14: error: expected type '[*:0]const u8', found '[*]const u8'", |
| 1825 | }); | 1878 | }); |
| 1826 | | 1879 | |
| 1827 | cases.add("atomic orderings of atomicStore Acquire or AcqRel", | 1880 | ctx.objErrStage1("atomic orderings of atomicStore Acquire or AcqRel", |
| 1828 | \\export fn entry() void { | 1881 | \\export fn entry() void { |
| 1829 | \\ var x: u32 = 0; | 1882 | \\ var x: u32 = 0; |
| 1830 | \\ @atomicStore(u32, &x, 1, .Acquire); | 1883 | \\ @atomicStore(u32, &x, 1, .Acquire); |
| ... | @@ -1833,7 +1886,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -1833,7 +1886,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1833 | "tmp.zig:3:30: error: @atomicStore atomic ordering must not be Acquire or AcqRel", | 1886 | "tmp.zig:3:30: error: @atomicStore atomic ordering must not be Acquire or AcqRel", |
| 1834 | }); | 1887 | }); |
| 1835 | | 1888 | |
| 1836 | cases.add("missing const in slice with nested array type", | 1889 | ctx.objErrStage1("missing const in slice with nested array type", |
| 1837 | \\const Geo3DTex2D = struct { vertices: [][2]f32 }; | 1890 | \\const Geo3DTex2D = struct { vertices: [][2]f32 }; |
| 1838 | \\pub fn getGeo3DTex2D() Geo3DTex2D { | 1891 | \\pub fn getGeo3DTex2D() Geo3DTex2D { |
| 1839 | \\ return Geo3DTex2D{ | 1892 | \\ return Geo3DTex2D{ |
| ... | @@ -1844,12 +1897,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -1844,12 +1897,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1844 | \\} | 1897 | \\} |
| 1845 | \\export fn entry() void { | 1898 | \\export fn entry() void { |
| 1846 | \\ var geo_data = getGeo3DTex2D(); | 1899 | \\ var geo_data = getGeo3DTex2D(); |
| | 1900 | \\ _ = geo_data; |
| 1847 | \\} | 1901 | \\} |
| 1848 | , &[_][]const u8{ | 1902 | , &[_][]const u8{ |
| 1849 | "tmp.zig:4:30: error: array literal requires address-of operator to coerce to slice type '[][2]f32'", | 1903 | "tmp.zig:4:30: error: array literal requires address-of operator to coerce to slice type '[][2]f32'", |
| 1850 | }); | 1904 | }); |
| 1851 | | 1905 | |
| 1852 | cases.add("slicing of global undefined pointer", | 1906 | ctx.objErrStage1("slicing of global undefined pointer", |
| 1853 | \\var buf: *[1]u8 = undefined; | 1907 | \\var buf: *[1]u8 = undefined; |
| 1854 | \\export fn entry() void { | 1908 | \\export fn entry() void { |
| 1855 | \\ _ = buf[0..1]; | 1909 | \\ _ = buf[0..1]; |
| ... | @@ -1858,18 +1912,17 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -1858,18 +1912,17 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1858 | "tmp.zig:3:12: error: non-zero length slice of undefined pointer", | 1912 | "tmp.zig:3:12: error: non-zero length slice of undefined pointer", |
| 1859 | }); | 1913 | }); |
| 1860 | | 1914 | |
| 1861 | cases.add("using invalid types in function call raises an error", | 1915 | ctx.objErrStage1("using invalid types in function call raises an error", |
| 1862 | \\const MenuEffect = enum {}; | 1916 | \\const MenuEffect = enum {}; |
| 1863 | \\fn func(effect: MenuEffect) void {} | 1917 | \\fn func(effect: MenuEffect) void { _ = effect; } |
| 1864 | \\export fn entry() void { | 1918 | \\export fn entry() void { |
| 1865 | \\ func(MenuEffect.ThisDoesNotExist); | 1919 | \\ func(MenuEffect.ThisDoesNotExist); |
| 1866 | \\} | 1920 | \\} |
| 1867 | , &[_][]const u8{ | 1921 | , &[_][]const u8{ |
| 1868 | "tmp.zig:1:20: error: enums must have 1 or more fields", | 1922 | "tmp.zig:1:20: error: enum declarations must have at least one tag", |
| 1869 | "tmp.zig:4:20: note: referenced here", | | |
| 1870 | }); | 1923 | }); |
| 1871 | | 1924 | |
| 1872 | cases.add("store vector pointer with unknown runtime index", | 1925 | ctx.objErrStage1("store vector pointer with unknown runtime index", |
| 1873 | \\export fn entry() void { | 1926 | \\export fn entry() void { |
| 1874 | \\ var v: @import("std").meta.Vector(4, i32) = [_]i32{ 1, 5, 3, undefined }; | 1927 | \\ var v: @import("std").meta.Vector(4, i32) = [_]i32{ 1, 5, 3, undefined }; |
| 1875 | \\ | 1928 | \\ |
| ... | @@ -1884,22 +1937,23 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -1884,22 +1937,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", | 1937 | "tmp.zig:9:8: error: unable to determine vector element index of type '*align(16:0:4:?) i32", |
| 1885 | }); | 1938 | }); |
| 1886 | | 1939 | |
| 1887 | cases.add("load vector pointer with unknown runtime index", | 1940 | ctx.objErrStage1("load vector pointer with unknown runtime index", |
| 1888 | \\export fn entry() void { | 1941 | \\export fn entry() void { |
| 1889 | \\ var v: @import("std").meta.Vector(4, i32) = [_]i32{ 1, 5, 3, undefined }; | 1942 | \\ var v: @import("std").meta.Vector(4, i32) = [_]i32{ 1, 5, 3, undefined }; |
| 1890 | \\ | 1943 | \\ |
| 1891 | \\ var i: u32 = 0; | 1944 | \\ var i: u32 = 0; |
| 1892 | \\ var x = loadv(&v[i]); | 1945 | \\ var x = loadv(&v[i]); |
| | 1946 | \\ _ = x; |
| 1893 | \\} | 1947 | \\} |
| 1894 | \\ | 1948 | \\ |
| 1895 | \\fn loadv(ptr: anytype) i32 { | 1949 | \\fn loadv(ptr: anytype) i32 { |
| 1896 | \\ return ptr.*; | 1950 | \\ return ptr.*; |
| 1897 | \\} | 1951 | \\} |
| 1898 | , &[_][]const u8{ | 1952 | , &[_][]const u8{ |
| 1899 | "tmp.zig:9:12: error: unable to determine vector element index of type '*align(16:0:4:?) i32", | 1953 | "tmp.zig:10:12: error: unable to determine vector element index of type '*align(16:0:4:?) i32", |
| 1900 | }); | 1954 | }); |
| 1901 | | 1955 | |
| 1902 | cases.add("using an unknown len ptr type instead of array", | 1956 | ctx.objErrStage1("using an unknown len ptr type instead of array", |
| 1903 | \\const resolutions = [*][*]const u8{ | 1957 | \\const resolutions = [*][*]const u8{ |
| 1904 | \\ "[320 240 ]", | 1958 | \\ "[320 240 ]", |
| 1905 | \\ null, | 1959 | \\ null, |
| ... | @@ -1911,7 +1965,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -1911,7 +1965,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1911 | "tmp.zig:1:21: error: expected array type or [_], found '[*][*]const u8'", | 1965 | "tmp.zig:1:21: error: expected array type or [_], found '[*][*]const u8'", |
| 1912 | }); | 1966 | }); |
| 1913 | | 1967 | |
| 1914 | cases.add("comparison with error union and error value", | 1968 | ctx.objErrStage1("comparison with error union and error value", |
| 1915 | \\export fn entry() void { | 1969 | \\export fn entry() void { |
| 1916 | \\ var number_or_error: anyerror!i32 = error.SomethingAwful; | 1970 | \\ var number_or_error: anyerror!i32 = error.SomethingAwful; |
| 1917 | \\ _ = number_or_error == error.SomethingAwful; | 1971 | \\ _ = number_or_error == error.SomethingAwful; |
| ... | @@ -1920,7 +1974,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -1920,7 +1974,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1920 | "tmp.zig:3:25: error: operator not allowed for type 'anyerror!i32'", | 1974 | "tmp.zig:3:25: error: operator not allowed for type 'anyerror!i32'", |
| 1921 | }); | 1975 | }); |
| 1922 | | 1976 | |
| 1923 | cases.add("switch with overlapping case ranges", | 1977 | ctx.objErrStage1("switch with overlapping case ranges", |
| 1924 | \\export fn entry() void { | 1978 | \\export fn entry() void { |
| 1925 | \\ var q: u8 = 0; | 1979 | \\ var q: u8 = 0; |
| 1926 | \\ switch (q) { | 1980 | \\ switch (q) { |
| ... | @@ -1932,28 +1986,29 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -1932,28 +1986,29 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1932 | "tmp.zig:5:9: error: duplicate switch value", | 1986 | "tmp.zig:5:9: error: duplicate switch value", |
| 1933 | }); | 1987 | }); |
| 1934 | | 1988 | |
| 1935 | cases.add("invalid optional type in extern struct", | 1989 | ctx.objErrStage1("invalid optional type in extern struct", |
| 1936 | \\const stroo = extern struct { | 1990 | \\const stroo = extern struct { |
| 1937 | \\ moo: ?[*c]u8, | 1991 | \\ moo: ?[*c]u8, |
| 1938 | \\}; | 1992 | \\}; |
| 1939 | \\export fn testf(fluff: *stroo) void {} | 1993 | \\export fn testf(fluff: *stroo) void { _ = fluff; } |
| 1940 | , &[_][]const u8{ | 1994 | , &[_][]const u8{ |
| 1941 | "tmp.zig:2:5: error: extern structs cannot contain fields of type '?[*c]u8'", | 1995 | "tmp.zig:2:5: error: extern structs cannot contain fields of type '?[*c]u8'", |
| 1942 | }); | 1996 | }); |
| 1943 | | 1997 | |
| 1944 | cases.add("attempt to negate a non-integer, non-float or non-vector type", | 1998 | ctx.objErrStage1("attempt to negate a non-integer, non-float or non-vector type", |
| 1945 | \\fn foo() anyerror!u32 { | 1999 | \\fn foo() anyerror!u32 { |
| 1946 | \\ return 1; | 2000 | \\ return 1; |
| 1947 | \\} | 2001 | \\} |
| 1948 | \\ | 2002 | \\ |
| 1949 | \\export fn entry() void { | 2003 | \\export fn entry() void { |
| 1950 | \\ const x = -foo(); | 2004 | \\ const x = -foo(); |
| | 2005 | \\ _ = x; |
| 1951 | \\} | 2006 | \\} |
| 1952 | , &[_][]const u8{ | 2007 | , &[_][]const u8{ |
| 1953 | "tmp.zig:6:15: error: negation of type 'anyerror!u32'", | 2008 | "tmp.zig:6:15: error: negation of type 'anyerror!u32'", |
| 1954 | }); | 2009 | }); |
| 1955 | | 2010 | |
| 1956 | cases.add("attempt to create 17 bit float type", | 2011 | ctx.objErrStage1("attempt to create 17 bit float type", |
| 1957 | \\const builtin = @import("std").builtin; | 2012 | \\const builtin = @import("std").builtin; |
| 1958 | \\comptime { | 2013 | \\comptime { |
| 1959 | \\ _ = @Type(builtin.TypeInfo { .Float = builtin.TypeInfo.Float { .bits = 17 } }); | 2014 | \\ _ = @Type(builtin.TypeInfo { .Float = builtin.TypeInfo.Float { .bits = 17 } }); |
| ... | @@ -1962,7 +2017,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -1962,7 +2017,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1962 | "tmp.zig:3:32: error: 17-bit float unsupported", | 2017 | "tmp.zig:3:32: error: 17-bit float unsupported", |
| 1963 | }); | 2018 | }); |
| 1964 | | 2019 | |
| 1965 | cases.add("wrong type for @Type", | 2020 | ctx.objErrStage1("wrong type for @Type", |
| 1966 | \\export fn entry() void { | 2021 | \\export fn entry() void { |
| 1967 | \\ _ = @Type(0); | 2022 | \\ _ = @Type(0); |
| 1968 | \\} | 2023 | \\} |
| ... | @@ -1970,7 +2025,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -1970,7 +2025,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1970 | "tmp.zig:2:15: error: expected type 'std.builtin.TypeInfo', found 'comptime_int'", | 2025 | "tmp.zig:2:15: error: expected type 'std.builtin.TypeInfo', found 'comptime_int'", |
| 1971 | }); | 2026 | }); |
| 1972 | | 2027 | |
| 1973 | cases.add("@Type with non-constant expression", | 2028 | ctx.objErrStage1("@Type with non-constant expression", |
| 1974 | \\const builtin = @import("std").builtin; | 2029 | \\const builtin = @import("std").builtin; |
| 1975 | \\var globalTypeInfo : builtin.TypeInfo = undefined; | 2030 | \\var globalTypeInfo : builtin.TypeInfo = undefined; |
| 1976 | \\export fn entry() void { | 2031 | \\export fn entry() void { |
| ... | @@ -1980,7 +2035,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -1980,7 +2035,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1980 | "tmp.zig:4:15: error: unable to evaluate constant expression", | 2035 | "tmp.zig:4:15: error: unable to evaluate constant expression", |
| 1981 | }); | 2036 | }); |
| 1982 | | 2037 | |
| 1983 | cases.add("wrong type for argument tuple to @asyncCall", | 2038 | ctx.objErrStage1("wrong type for argument tuple to @asyncCall", |
| 1984 | \\export fn entry1() void { | 2039 | \\export fn entry1() void { |
| 1985 | \\ var frame: @Frame(foo) = undefined; | 2040 | \\ var frame: @Frame(foo) = undefined; |
| 1986 | \\ @asyncCall(&frame, {}, foo, {}); | 2041 | \\ @asyncCall(&frame, {}, foo, {}); |
| ... | @@ -1993,7 +2048,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -1993,7 +2048,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1993 | "tmp.zig:3:33: error: expected tuple or struct, found 'void'", | 2048 | "tmp.zig:3:33: error: expected tuple or struct, found 'void'", |
| 1994 | }); | 2049 | }); |
| 1995 | | 2050 | |
| 1996 | cases.add("wrong type for result ptr to @asyncCall", | 2051 | ctx.objErrStage1("wrong type for result ptr to @asyncCall", |
| 1997 | \\export fn entry() void { | 2052 | \\export fn entry() void { |
| 1998 | \\ _ = async amain(); | 2053 | \\ _ = async amain(); |
| 1999 | \\} | 2054 | \\} |
| ... | @@ -2008,25 +2063,27 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -2008,25 +2063,27 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2008 | "tmp.zig:6:37: error: expected type '*i32', found 'bool'", | 2063 | "tmp.zig:6:37: error: expected type '*i32', found 'bool'", |
| 2009 | }); | 2064 | }); |
| 2010 | | 2065 | |
| 2011 | cases.add("shift amount has to be an integer type", | 2066 | ctx.objErrStage1("shift amount has to be an integer type", |
| 2012 | \\export fn entry() void { | 2067 | \\export fn entry() void { |
| 2013 | \\ const x = 1 << &@as(u8, 10); | 2068 | \\ const x = 1 << &@as(u8, 10); |
| | 2069 | \\ _ = x; |
| 2014 | \\} | 2070 | \\} |
| 2015 | , &[_][]const u8{ | 2071 | , &[_][]const u8{ |
| 2016 | "tmp.zig:2:21: error: shift amount has to be an integer type, but found '*const u8'", | 2072 | "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", | 2073 | "tmp.zig:2:17: note: referenced here", |
| 2018 | }); | 2074 | }); |
| 2019 | | 2075 | |
| 2020 | cases.add("bit shifting only works on integer types", | 2076 | ctx.objErrStage1("bit shifting only works on integer types", |
| 2021 | \\export fn entry() void { | 2077 | \\export fn entry() void { |
| 2022 | \\ const x = &@as(u8, 1) << 10; | 2078 | \\ const x = &@as(u8, 1) << 10; |
| | 2079 | \\ _ = x; |
| 2023 | \\} | 2080 | \\} |
| 2024 | , &[_][]const u8{ | 2081 | , &[_][]const u8{ |
| 2025 | "tmp.zig:2:16: error: bit shifting operation expected integer type, found '*const u8'", | 2082 | "tmp.zig:2:16: error: bit shifting operation expected integer type, found '*const u8'", |
| 2026 | "tmp.zig:2:27: note: referenced here", | 2083 | "tmp.zig:2:27: note: referenced here", |
| 2027 | }); | 2084 | }); |
| 2028 | | 2085 | |
| 2029 | cases.add("struct depends on itself via optional field", | 2086 | ctx.objErrStage1("struct depends on itself via optional field", |
| 2030 | \\const LhsExpr = struct { | 2087 | \\const LhsExpr = struct { |
| 2031 | \\ rhsExpr: ?AstObject, | 2088 | \\ rhsExpr: ?AstObject, |
| 2032 | \\}; | 2089 | \\}; |
| ... | @@ -2036,6 +2093,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -2036,6 +2093,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2036 | \\export fn entry() void { | 2093 | \\export fn entry() void { |
| 2037 | \\ const lhsExpr = LhsExpr{ .rhsExpr = null }; | 2094 | \\ const lhsExpr = LhsExpr{ .rhsExpr = null }; |
| 2038 | \\ const obj = AstObject{ .lhsExpr = lhsExpr }; | 2095 | \\ const obj = AstObject{ .lhsExpr = lhsExpr }; |
| | 2096 | \\ _ = obj; |
| 2039 | \\} | 2097 | \\} |
| 2040 | , &[_][]const u8{ | 2098 | , &[_][]const u8{ |
| 2041 | "tmp.zig:1:17: error: struct 'LhsExpr' depends on itself", | 2099 | "tmp.zig:1:17: error: struct 'LhsExpr' depends on itself", |
| ... | @@ -2043,51 +2101,55 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -2043,51 +2101,55 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2043 | "tmp.zig:2:5: note: while checking this field", | 2101 | "tmp.zig:2:5: note: while checking this field", |
| 2044 | }); | 2102 | }); |
| 2045 | | 2103 | |
| 2046 | cases.add("alignment of enum field specified", | 2104 | ctx.objErrStage1("alignment of enum field specified", |
| 2047 | \\const Number = enum { | 2105 | \\const Number = enum { |
| 2048 | \\ a, | 2106 | \\ a, |
| 2049 | \\ b align(i32), | 2107 | \\ b align(i32), |
| 2050 | \\}; | 2108 | \\}; |
| 2051 | \\export fn entry1() void { | 2109 | \\export fn entry1() void { |
| 2052 | \\ var x: Number = undefined; | 2110 | \\ var x: Number = undefined; |
| | 2111 | \\ _ = x; |
| 2053 | \\} | 2112 | \\} |
| 2054 | , &[_][]const u8{ | 2113 | , &[_][]const u8{ |
| 2055 | "tmp.zig:3:13: error: structs and unions, not enums, support field alignment", | 2114 | "tmp.zig:3:13: error: structs and unions, not enums, support field alignment", |
| 2056 | "tmp.zig:1:16: note: consider 'union(enum)' here", | 2115 | "tmp.zig:1:16: note: consider 'union(enum)' here", |
| 2057 | }); | 2116 | }); |
| 2058 | | 2117 | |
| 2059 | cases.add("bad alignment type", | 2118 | ctx.objErrStage1("bad alignment type", |
| 2060 | \\export fn entry1() void { | 2119 | \\export fn entry1() void { |
| 2061 | \\ var x: []align(true) i32 = undefined; | 2120 | \\ var x: []align(true) i32 = undefined; |
| | 2121 | \\ _ = x; |
| 2062 | \\} | 2122 | \\} |
| 2063 | \\export fn entry2() void { | 2123 | \\export fn entry2() void { |
| 2064 | \\ var x: *align(@as(f64, 12.34)) i32 = undefined; | 2124 | \\ var x: *align(@as(f64, 12.34)) i32 = undefined; |
| | 2125 | \\ _ = x; |
| 2065 | \\} | 2126 | \\} |
| 2066 | , &[_][]const u8{ | 2127 | , &[_][]const u8{ |
| 2067 | "tmp.zig:2:20: error: expected type 'u29', found 'bool'", | 2128 | "tmp.zig:2:20: error: expected type 'u29', found 'bool'", |
| 2068 | "tmp.zig:5:19: error: fractional component prevents float value 12.340000 from being casted to type 'u29'", | 2129 | "tmp.zig:6:19: error: fractional component prevents float value 12.340000 from being casted to type 'u29'", |
| 2069 | }); | 2130 | }); |
| 2070 | | 2131 | |
| 2071 | cases.addCase(x: { | 2132 | { |
| 2072 | var tc = cases.create("variable in inline assembly template cannot be found", | 2133 | const case = ctx.obj("variable in inline assembly template cannot be found", .{ |
| | 2134 | .cpu_arch = .x86_64, |
| | 2135 | .os_tag = .linux, |
| | 2136 | .abi = .gnu, |
| | 2137 | }); |
| | 2138 | case.backend = .stage1; |
| | 2139 | case.addError( |
| 2073 | \\export fn entry() void { | 2140 | \\export fn entry() void { |
| 2074 | \\ var sp = asm volatile ( | 2141 | \\ var sp = asm volatile ( |
| 2075 | \\ "mov %[foo], sp" | 2142 | \\ "mov %[foo], sp" |
| 2076 | \\ : [bar] "=r" (-> usize) | 2143 | \\ : [bar] "=r" (-> usize) |
| 2077 | \\ ); | 2144 | \\ ); |
| | 2145 | \\ _ = sp; |
| 2078 | \\} | 2146 | \\} |
| 2079 | , &[_][]const u8{ | 2147 | , &[_][]const u8{ |
| 2080 | "tmp.zig:2:14: error: could not find 'foo' in the inputs or outputs", | 2148 | "tmp.zig:2:14: error: could not find 'foo' in the inputs or outputs", |
| 2081 | }); | 2149 | }); |
| 2082 | tc.target = std.zig.CrossTarget{ | 2150 | } |
| 2083 | .cpu_arch = .x86_64, | | |
| 2084 | .os_tag = .linux, | | |
| 2085 | .abi = .gnu, | | |
| 2086 | }; | | |
| 2087 | break :x tc; | | |
| 2088 | }); | | |
| 2089 | | 2151 | |
| 2090 | cases.add("indirect recursion of async functions detected", | 2152 | ctx.objErrStage1("indirect recursion of async functions detected", |
| 2091 | \\var frame: ?anyframe = null; | 2153 | \\var frame: ?anyframe = null; |
| 2092 | \\ | 2154 | \\ |
| 2093 | \\export fn a() void { | 2155 | \\export fn a() void { |
| ... | @@ -2122,7 +2184,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -2122,7 +2184,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2122 | "tmp.zig:26:25: note: when analyzing type '@Frame(rangeSumIndirect)' here", | 2184 | "tmp.zig:26:25: note: when analyzing type '@Frame(rangeSumIndirect)' here", |
| 2123 | }); | 2185 | }); |
| 2124 | | 2186 | |
| 2125 | cases.add("non-async function pointer eventually is inferred to become async", | 2187 | ctx.objErrStage1("non-async function pointer eventually is inferred to become async", |
| 2126 | \\export fn a() void { | 2188 | \\export fn a() void { |
| 2127 | \\ var non_async_fn: fn () void = undefined; | 2189 | \\ var non_async_fn: fn () void = undefined; |
| 2128 | \\ non_async_fn = func; | 2190 | \\ non_async_fn = func; |
| ... | @@ -2136,20 +2198,26 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -2136,20 +2198,26 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2136 | "tmp.zig:6:5: note: suspends here", | 2198 | "tmp.zig:6:5: note: suspends here", |
| 2137 | }); | 2199 | }); |
| 2138 | | 2200 | |
| 2139 | cases.add("bad alignment in @asyncCall", | 2201 | { |
| 2140 | \\export fn entry() void { | 2202 | const case = ctx.obj("bad alignment in @asyncCall", .{ |
| 2141 | \\ var ptr: fn () callconv(.Async) void = func; | 2203 | .cpu_arch = .aarch64, |
| 2142 | \\ var bytes: [64]u8 = undefined; | 2204 | .os_tag = .linux, |
| 2143 | \\ _ = @asyncCall(&bytes, {}, ptr, .{}); | 2205 | .abi = .none, |
| 2144 | \\} | 2206 | }); |
| 2145 | \\fn func() callconv(.Async) void {} | 2207 | case.backend = .stage1; |
| 2146 | , &[_][]const u8{ | 2208 | case.addError( |
| 2147 | // Split the check in two as the alignment value is target dependent. | 2209 | \\export fn entry() void { |
| 2148 | "tmp.zig:4:21: error: expected type '[]align(", | 2210 | \\ var ptr: fn () callconv(.Async) void = func; |
| 2149 | ") u8', found '*[64]u8'", | 2211 | \\ var bytes: [64]u8 = undefined; |
| 2150 | }); | 2212 | \\ _ = @asyncCall(&bytes, {}, ptr, .{}); |
| | 2213 | \\} |
| | 2214 | \\fn func() callconv(.Async) void {} |
| | 2215 | , &[_][]const u8{ |
| | 2216 | "tmp.zig:4:21: error: expected type '[]align(8) u8', found '*[64]u8'", |
| | 2217 | }); |
| | 2218 | } |
| 2151 | | 2219 | |
| 2152 | cases.add("atomic orderings of fence Acquire or stricter", | 2220 | ctx.objErrStage1("atomic orderings of fence Acquire or stricter", |
| 2153 | \\export fn entry() void { | 2221 | \\export fn entry() void { |
| 2154 | \\ @fence(.Monotonic); | 2222 | \\ @fence(.Monotonic); |
| 2155 | \\} | 2223 | \\} |
| ... | @@ -2157,20 +2225,22 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -2157,20 +2225,22 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2157 | "tmp.zig:2:12: error: atomic ordering must be Acquire or stricter", | 2225 | "tmp.zig:2:12: error: atomic ordering must be Acquire or stricter", |
| 2158 | }); | 2226 | }); |
| 2159 | | 2227 | |
| 2160 | cases.add("bad alignment in implicit cast from array pointer to slice", | 2228 | ctx.objErrStage1("bad alignment in implicit cast from array pointer to slice", |
| 2161 | \\export fn a() void { | 2229 | \\export fn a() void { |
| 2162 | \\ var x: [10]u8 = undefined; | 2230 | \\ var x: [10]u8 = undefined; |
| 2163 | \\ var y: []align(16) u8 = &x; | 2231 | \\ var y: []align(16) u8 = &x; |
| | 2232 | \\ _ = y; |
| 2164 | \\} | 2233 | \\} |
| 2165 | , &[_][]const u8{ | 2234 | , &[_][]const u8{ |
| 2166 | "tmp.zig:3:30: error: expected type '[]align(16) u8', found '*[10]u8'", | 2235 | "tmp.zig:3:30: error: expected type '[]align(16) u8', found '*[10]u8'", |
| 2167 | }); | 2236 | }); |
| 2168 | | 2237 | |
| 2169 | cases.add("result location incompatibility mismatching handle_is_ptr (generic call)", | 2238 | ctx.objErrStage1("result location incompatibility mismatching handle_is_ptr (generic call)", |
| 2170 | \\export fn entry() void { | 2239 | \\export fn entry() void { |
| 2171 | \\ var damn = Container{ | 2240 | \\ var damn = Container{ |
| 2172 | \\ .not_optional = getOptional(i32), | 2241 | \\ .not_optional = getOptional(i32), |
| 2173 | \\ }; | 2242 | \\ }; |
| | 2243 | \\ _ = damn; |
| 2174 | \\} | 2244 | \\} |
| 2175 | \\pub fn getOptional(comptime T: type) ?T { | 2245 | \\pub fn getOptional(comptime T: type) ?T { |
| 2176 | \\ return 0; | 2246 | \\ return 0; |
| ... | @@ -2182,11 +2252,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -2182,11 +2252,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2182 | "tmp.zig:3:36: error: expected type 'i32', found '?i32'", | 2252 | "tmp.zig:3:36: error: expected type 'i32', found '?i32'", |
| 2183 | }); | 2253 | }); |
| 2184 | | 2254 | |
| 2185 | cases.add("result location incompatibility mismatching handle_is_ptr", | 2255 | ctx.objErrStage1("result location incompatibility mismatching handle_is_ptr", |
| 2186 | \\export fn entry() void { | 2256 | \\export fn entry() void { |
| 2187 | \\ var damn = Container{ | 2257 | \\ var damn = Container{ |
| 2188 | \\ .not_optional = getOptional(), | 2258 | \\ .not_optional = getOptional(), |
| 2189 | \\ }; | 2259 | \\ }; |
| | 2260 | \\ _ = damn; |
| 2190 | \\} | 2261 | \\} |
| 2191 | \\pub fn getOptional() ?i32 { | 2262 | \\pub fn getOptional() ?i32 { |
| 2192 | \\ return 0; | 2263 | \\ return 0; |
| ... | @@ -2198,7 +2269,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -2198,7 +2269,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2198 | "tmp.zig:3:36: error: expected type 'i32', found '?i32'", | 2269 | "tmp.zig:3:36: error: expected type 'i32', found '?i32'", |
| 2199 | }); | 2270 | }); |
| 2200 | | 2271 | |
| 2201 | cases.add("const frame cast to anyframe", | 2272 | ctx.objErrStage1("const frame cast to anyframe", |
| 2202 | \\export fn a() void { | 2273 | \\export fn a() void { |
| 2203 | \\ const f = async func(); | 2274 | \\ const f = async func(); |
| 2204 | \\ resume f; | 2275 | \\ resume f; |
| ... | @@ -2206,6 +2277,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -2206,6 +2277,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2206 | \\export fn b() void { | 2277 | \\export fn b() void { |
| 2207 | \\ const f = async func(); | 2278 | \\ const f = async func(); |
| 2208 | \\ var x: anyframe = &f; | 2279 | \\ var x: anyframe = &f; |
| | 2280 | \\ _ = x; |
| 2209 | \\} | 2281 | \\} |
| 2210 | \\fn func() void { | 2282 | \\fn func() void { |
| 2211 | \\ suspend {} | 2283 | \\ suspend {} |
| ... | @@ -2215,27 +2287,30 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -2215,27 +2287,30 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2215 | "tmp.zig:7:24: error: expected type 'anyframe', found '*const @Frame(func)'", | 2287 | "tmp.zig:7:24: error: expected type 'anyframe', found '*const @Frame(func)'", |
| 2216 | }); | 2288 | }); |
| 2217 | | 2289 | |
| 2218 | cases.add("prevent bad implicit casting of anyframe types", | 2290 | ctx.objErrStage1("prevent bad implicit casting of anyframe types", |
| 2219 | \\export fn a() void { | 2291 | \\export fn a() void { |
| 2220 | \\ var x: anyframe = undefined; | 2292 | \\ var x: anyframe = undefined; |
| 2221 | \\ var y: anyframe->i32 = x; | 2293 | \\ var y: anyframe->i32 = x; |
| | 2294 | \\ _ = y; |
| 2222 | \\} | 2295 | \\} |
| 2223 | \\export fn b() void { | 2296 | \\export fn b() void { |
| 2224 | \\ var x: i32 = undefined; | 2297 | \\ var x: i32 = undefined; |
| 2225 | \\ var y: anyframe->i32 = x; | 2298 | \\ var y: anyframe->i32 = x; |
| | 2299 | \\ _ = y; |
| 2226 | \\} | 2300 | \\} |
| 2227 | \\export fn c() void { | 2301 | \\export fn c() void { |
| 2228 | \\ var x: @Frame(func) = undefined; | 2302 | \\ var x: @Frame(func) = undefined; |
| 2229 | \\ var y: anyframe->i32 = &x; | 2303 | \\ var y: anyframe->i32 = &x; |
| | 2304 | \\ _ = y; |
| 2230 | \\} | 2305 | \\} |
| 2231 | \\fn func() void {} | 2306 | \\fn func() void {} |
| 2232 | , &[_][]const u8{ | 2307 | , &[_][]const u8{ |
| 2233 | "tmp.zig:3:28: error: expected type 'anyframe->i32', found 'anyframe'", | 2308 | "tmp.zig:3:28: error: expected type 'anyframe->i32', found 'anyframe'", |
| 2234 | "tmp.zig:7:28: error: expected type 'anyframe->i32', found 'i32'", | 2309 | "tmp.zig:8:28: error: expected type 'anyframe->i32', found 'i32'", |
| 2235 | "tmp.zig:11:29: error: expected type 'anyframe->i32', found '*@Frame(func)'", | 2310 | "tmp.zig:13:29: error: expected type 'anyframe->i32', found '*@Frame(func)'", |
| 2236 | }); | 2311 | }); |
| 2237 | | 2312 | |
| 2238 | cases.add("wrong frame type used for async call", | 2313 | ctx.objErrStage1("wrong frame type used for async call", |
| 2239 | \\export fn entry() void { | 2314 | \\export fn entry() void { |
| 2240 | \\ var frame: @Frame(foo) = undefined; | 2315 | \\ var frame: @Frame(foo) = undefined; |
| 2241 | \\ frame = async bar(); | 2316 | \\ frame = async bar(); |
| ... | @@ -2250,18 +2325,20 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -2250,18 +2325,20 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2250 | "tmp.zig:3:13: error: expected type '*@Frame(bar)', found '*@Frame(foo)'", | 2325 | "tmp.zig:3:13: error: expected type '*@Frame(bar)', found '*@Frame(foo)'", |
| 2251 | }); | 2326 | }); |
| 2252 | | 2327 | |
| 2253 | cases.add("@Frame() of generic function", | 2328 | ctx.objErrStage1("@Frame() of generic function", |
| 2254 | \\export fn entry() void { | 2329 | \\export fn entry() void { |
| 2255 | \\ var frame: @Frame(func) = undefined; | 2330 | \\ var frame: @Frame(func) = undefined; |
| | 2331 | \\ _ = frame; |
| 2256 | \\} | 2332 | \\} |
| 2257 | \\fn func(comptime T: type) void { | 2333 | \\fn func(comptime T: type) void { |
| 2258 | \\ var x: T = undefined; | 2334 | \\ var x: T = undefined; |
| | 2335 | \\ _ = x; |
| 2259 | \\} | 2336 | \\} |
| 2260 | , &[_][]const u8{ | 2337 | , &[_][]const u8{ |
| 2261 | "tmp.zig:2:16: error: @Frame() of generic function", | 2338 | "tmp.zig:2:16: error: @Frame() of generic function", |
| 2262 | }); | 2339 | }); |
| 2263 | | 2340 | |
| 2264 | cases.add("@frame() causes function to be async", | 2341 | ctx.objErrStage1("@frame() causes function to be async", |
| 2265 | \\export fn entry() void { | 2342 | \\export fn entry() void { |
| 2266 | \\ func(); | 2343 | \\ func(); |
| 2267 | \\} | 2344 | \\} |
| ... | @@ -2273,10 +2350,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -2273,10 +2350,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2273 | "tmp.zig:5:9: note: @frame() causes function to be async", | 2350 | "tmp.zig:5:9: note: @frame() causes function to be async", |
| 2274 | }); | 2351 | }); |
| 2275 | | 2352 | |
| 2276 | cases.add("invalid suspend in exported function", | 2353 | ctx.objErrStage1("invalid suspend in exported function", |
| 2277 | \\export fn entry() void { | 2354 | \\export fn entry() void { |
| 2278 | \\ var frame = async func(); | 2355 | \\ var frame = async func(); |
| 2279 | \\ var result = await frame; | 2356 | \\ var result = await frame; |
| | 2357 | \\ _ = result; |
| 2280 | \\} | 2358 | \\} |
| 2281 | \\fn func() void { | 2359 | \\fn func() void { |
| 2282 | \\ suspend {} | 2360 | \\ suspend {} |
| ... | @@ -2286,7 +2364,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -2286,7 +2364,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2286 | "tmp.zig:3:18: note: await here is a suspend point", | 2364 | "tmp.zig:3:18: note: await here is a suspend point", |
| 2287 | }); | 2365 | }); |
| 2288 | | 2366 | |
| 2289 | cases.add("async function indirectly depends on its own frame", | 2367 | ctx.objErrStage1("async function indirectly depends on its own frame", |
| 2290 | \\export fn entry() void { | 2368 | \\export fn entry() void { |
| 2291 | \\ _ = async amain(); | 2369 | \\ _ = async amain(); |
| 2292 | \\} | 2370 | \\} |
| ... | @@ -2295,6 +2373,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -2295,6 +2373,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2295 | \\} | 2373 | \\} |
| 2296 | \\fn other() void { | 2374 | \\fn other() void { |
| 2297 | \\ var x: [@sizeOf(@Frame(amain))]u8 = undefined; | 2375 | \\ var x: [@sizeOf(@Frame(amain))]u8 = undefined; |
| | 2376 | \\ _ = x; |
| 2298 | \\} | 2377 | \\} |
| 2299 | , &[_][]const u8{ | 2378 | , &[_][]const u8{ |
| 2300 | "tmp.zig:4:1: error: unable to determine async function frame of 'amain'", | 2379 | "tmp.zig:4:1: error: unable to determine async function frame of 'amain'", |
| ... | @@ -2302,19 +2381,20 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -2302,19 +2381,20 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2302 | "tmp.zig:8:13: note: referenced here", | 2381 | "tmp.zig:8:13: note: referenced here", |
| 2303 | }); | 2382 | }); |
| 2304 | | 2383 | |
| 2305 | cases.add("async function depends on its own frame", | 2384 | ctx.objErrStage1("async function depends on its own frame", |
| 2306 | \\export fn entry() void { | 2385 | \\export fn entry() void { |
| 2307 | \\ _ = async amain(); | 2386 | \\ _ = async amain(); |
| 2308 | \\} | 2387 | \\} |
| 2309 | \\fn amain() callconv(.Async) void { | 2388 | \\fn amain() callconv(.Async) void { |
| 2310 | \\ var x: [@sizeOf(@Frame(amain))]u8 = undefined; | 2389 | \\ var x: [@sizeOf(@Frame(amain))]u8 = undefined; |
| | 2390 | \\ _ = x; |
| 2311 | \\} | 2391 | \\} |
| 2312 | , &[_][]const u8{ | 2392 | , &[_][]const u8{ |
| 2313 | "tmp.zig:4:1: error: cannot resolve '@Frame(amain)': function not fully analyzed yet", | 2393 | "tmp.zig:4:1: error: cannot resolve '@Frame(amain)': function not fully analyzed yet", |
| 2314 | "tmp.zig:5:13: note: referenced here", | 2394 | "tmp.zig:5:13: note: referenced here", |
| 2315 | }); | 2395 | }); |
| 2316 | | 2396 | |
| 2317 | cases.add("non async function pointer passed to @asyncCall", | 2397 | ctx.objErrStage1("non async function pointer passed to @asyncCall", |
| 2318 | \\export fn entry() void { | 2398 | \\export fn entry() void { |
| 2319 | \\ var ptr = afunc; | 2399 | \\ var ptr = afunc; |
| 2320 | \\ var bytes: [100]u8 align(16) = undefined; | 2400 | \\ var bytes: [100]u8 align(16) = undefined; |
| ... | @@ -2325,7 +2405,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -2325,7 +2405,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2325 | "tmp.zig:4:32: error: expected async function, found 'fn() void'", | 2405 | "tmp.zig:4:32: error: expected async function, found 'fn() void'", |
| 2326 | }); | 2406 | }); |
| 2327 | | 2407 | |
| 2328 | cases.add("runtime-known async function called", | 2408 | ctx.objErrStage1("runtime-known async function called", |
| 2329 | \\export fn entry() void { | 2409 | \\export fn entry() void { |
| 2330 | \\ _ = async amain(); | 2410 | \\ _ = async amain(); |
| 2331 | \\} | 2411 | \\} |
| ... | @@ -2338,7 +2418,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -2338,7 +2418,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2338 | "tmp.zig:6:12: error: function is not comptime-known; @asyncCall required", | 2418 | "tmp.zig:6:12: error: function is not comptime-known; @asyncCall required", |
| 2339 | }); | 2419 | }); |
| 2340 | | 2420 | |
| 2341 | cases.add("runtime-known function called with async keyword", | 2421 | ctx.objErrStage1("runtime-known function called with async keyword", |
| 2342 | \\export fn entry() void { | 2422 | \\export fn entry() void { |
| 2343 | \\ var ptr = afunc; | 2423 | \\ var ptr = afunc; |
| 2344 | \\ _ = async ptr(); | 2424 | \\ _ = async ptr(); |
| ... | @@ -2349,7 +2429,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -2349,7 +2429,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2349 | "tmp.zig:3:15: error: function is not comptime-known; @asyncCall required", | 2429 | "tmp.zig:3:15: error: function is not comptime-known; @asyncCall required", |
| 2350 | }); | 2430 | }); |
| 2351 | | 2431 | |
| 2352 | cases.add("function with ccc indirectly calling async function", | 2432 | ctx.objErrStage1("function with ccc indirectly calling async function", |
| 2353 | \\export fn entry() void { | 2433 | \\export fn entry() void { |
| 2354 | \\ foo(); | 2434 | \\ foo(); |
| 2355 | \\} | 2435 | \\} |
| ... | @@ -2366,7 +2446,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -2366,7 +2446,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2366 | "tmp.zig:8:5: note: suspends here", | 2446 | "tmp.zig:8:5: note: suspends here", |
| 2367 | }); | 2447 | }); |
| 2368 | | 2448 | |
| 2369 | cases.add("capture group on switch prong with incompatible payload types", | 2449 | ctx.objErrStage1("capture group on switch prong with incompatible payload types", |
| 2370 | \\const Union = union(enum) { | 2450 | \\const Union = union(enum) { |
| 2371 | \\ A: usize, | 2451 | \\ A: usize, |
| 2372 | \\ B: isize, | 2452 | \\ B: isize, |
| ... | @@ -2374,7 +2454,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -2374,7 +2454,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2374 | \\comptime { | 2454 | \\comptime { |
| 2375 | \\ var u = Union{ .A = 8 }; | 2455 | \\ var u = Union{ .A = 8 }; |
| 2376 | \\ switch (u) { | 2456 | \\ switch (u) { |
| 2377 | \\ .A, .B => |e| unreachable, | 2457 | \\ .A, .B => |e| { |
| | 2458 | \\ _ = e; |
| | 2459 | \\ unreachable; |
| | 2460 | \\ }, |
| 2378 | \\ } | 2461 | \\ } |
| 2379 | \\} | 2462 | \\} |
| 2380 | , &[_][]const u8{ | 2463 | , &[_][]const u8{ |
| ... | @@ -2383,7 +2466,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -2383,7 +2466,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2383 | "tmp.zig:8:13: note: type 'isize' here", | 2466 | "tmp.zig:8:13: note: type 'isize' here", |
| 2384 | }); | 2467 | }); |
| 2385 | | 2468 | |
| 2386 | cases.add("wrong type to @hasField", | 2469 | ctx.objErrStage1("wrong type to @hasField", |
| 2387 | \\export fn entry() bool { | 2470 | \\export fn entry() bool { |
| 2388 | \\ return @hasField(i32, "hi"); | 2471 | \\ return @hasField(i32, "hi"); |
| 2389 | \\} | 2472 | \\} |
| ... | @@ -2391,44 +2474,49 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -2391,44 +2474,49 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2391 | "tmp.zig:2:22: error: type 'i32' does not support @hasField", | 2474 | "tmp.zig:2:22: error: type 'i32' does not support @hasField", |
| 2392 | }); | 2475 | }); |
| 2393 | | 2476 | |
| 2394 | cases.add("slice passed as array init type with elems", | 2477 | ctx.objErrStage1("slice passed as array init type with elems", |
| 2395 | \\export fn entry() void { | 2478 | \\export fn entry() void { |
| 2396 | \\ const x = []u8{1, 2}; | 2479 | \\ const x = []u8{1, 2}; |
| | 2480 | \\ _ = x; |
| 2397 | \\} | 2481 | \\} |
| 2398 | , &[_][]const u8{ | 2482 | , &[_][]const u8{ |
| 2399 | "tmp.zig:2:15: error: array literal requires address-of operator to coerce to slice type '[]u8'", | 2483 | "tmp.zig:2:15: error: array literal requires address-of operator to coerce to slice type '[]u8'", |
| 2400 | }); | 2484 | }); |
| 2401 | | 2485 | |
| 2402 | cases.add("slice passed as array init type", | 2486 | ctx.objErrStage1("slice passed as array init type", |
| 2403 | \\export fn entry() void { | 2487 | \\export fn entry() void { |
| 2404 | \\ const x = []u8{}; | 2488 | \\ const x = []u8{}; |
| | 2489 | \\ _ = x; |
| 2405 | \\} | 2490 | \\} |
| 2406 | , &[_][]const u8{ | 2491 | , &[_][]const u8{ |
| 2407 | "tmp.zig:2:15: error: array literal requires address-of operator to coerce to slice type '[]u8'", | 2492 | "tmp.zig:2:15: error: array literal requires address-of operator to coerce to slice type '[]u8'", |
| 2408 | }); | 2493 | }); |
| 2409 | | 2494 | |
| 2410 | cases.add("inferred array size invalid here", | 2495 | ctx.objErrStage1("inferred array size invalid here", |
| 2411 | \\export fn entry() void { | 2496 | \\export fn entry() void { |
| 2412 | \\ const x = [_]u8; | 2497 | \\ const x = [_]u8; |
| | 2498 | \\ _ = x; |
| 2413 | \\} | 2499 | \\} |
| 2414 | \\export fn entry2() void { | 2500 | \\export fn entry2() void { |
| 2415 | \\ const S = struct { a: *const [_]u8 }; | 2501 | \\ const S = struct { a: *const [_]u8 }; |
| 2416 | \\ var a = .{ S{} }; | 2502 | \\ var a = .{ S{} }; |
| | 2503 | \\ _ = a; |
| 2417 | \\} | 2504 | \\} |
| 2418 | , &[_][]const u8{ | 2505 | , &[_][]const u8{ |
| 2419 | "tmp.zig:2:15: error: inferred array size invalid here", | 2506 | "tmp.zig:2:16: error: unable to infer array size", |
| 2420 | "tmp.zig:5:34: error: inferred array size invalid here", | 2507 | "tmp.zig:6:35: error: unable to infer array size", |
| 2421 | }); | 2508 | }); |
| 2422 | | 2509 | |
| 2423 | cases.add("initializing array with struct syntax", | 2510 | ctx.objErrStage1("initializing array with struct syntax", |
| 2424 | \\export fn entry() void { | 2511 | \\export fn entry() void { |
| 2425 | \\ const x = [_]u8{ .y = 2 }; | 2512 | \\ const x = [_]u8{ .y = 2 }; |
| | 2513 | \\ _ = x; |
| 2426 | \\} | 2514 | \\} |
| 2427 | , &[_][]const u8{ | 2515 | , &[_][]const u8{ |
| 2428 | "tmp.zig:2:15: error: initializing array with struct syntax", | 2516 | "tmp.zig:2:15: error: initializing array with struct syntax", |
| 2429 | }); | 2517 | }); |
| 2430 | | 2518 | |
| 2431 | cases.add("compile error in struct init expression", | 2519 | ctx.objErrStage1("compile error in struct init expression", |
| 2432 | \\const Foo = struct { | 2520 | \\const Foo = struct { |
| 2433 | \\ a: i32 = crap, | 2521 | \\ a: i32 = crap, |
| 2434 | \\ b: i32, | 2522 | \\ b: i32, |
| ... | @@ -2437,23 +2525,25 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -2437,23 +2525,25 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2437 | \\ var x = Foo{ | 2525 | \\ var x = Foo{ |
| 2438 | \\ .b = 5, | 2526 | \\ .b = 5, |
| 2439 | \\ }; | 2527 | \\ }; |
| | 2528 | \\ _ = x; |
| 2440 | \\} | 2529 | \\} |
| 2441 | , &[_][]const u8{ | 2530 | , &[_][]const u8{ |
| 2442 | "tmp.zig:2:14: error: use of undeclared identifier 'crap'", | 2531 | "tmp.zig:2:14: error: use of undeclared identifier 'crap'", |
| 2443 | }); | 2532 | }); |
| 2444 | | 2533 | |
| 2445 | cases.add("undefined as field type is rejected", | 2534 | ctx.objErrStage1("undefined as field type is rejected", |
| 2446 | \\const Foo = struct { | 2535 | \\const Foo = struct { |
| 2447 | \\ a: undefined, | 2536 | \\ a: undefined, |
| 2448 | \\}; | 2537 | \\}; |
| 2449 | \\export fn entry1() void { | 2538 | \\export fn entry1() void { |
| 2450 | \\ const foo: Foo = undefined; | 2539 | \\ const foo: Foo = undefined; |
| | 2540 | \\ _ = foo; |
| 2451 | \\} | 2541 | \\} |
| 2452 | , &[_][]const u8{ | 2542 | , &[_][]const u8{ |
| 2453 | "tmp.zig:2:8: error: use of undefined value here causes undefined behavior", | 2543 | "tmp.zig:2:8: error: use of undefined value here causes undefined behavior", |
| 2454 | }); | 2544 | }); |
| 2455 | | 2545 | |
| 2456 | cases.add("@hasDecl with non-container", | 2546 | ctx.objErrStage1("@hasDecl with non-container", |
| 2457 | \\export fn entry() void { | 2547 | \\export fn entry() void { |
| 2458 | \\ _ = @hasDecl(i32, "hi"); | 2548 | \\ _ = @hasDecl(i32, "hi"); |
| 2459 | \\} | 2549 | \\} |
| ... | @@ -2461,16 +2551,17 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -2461,16 +2551,17 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2461 | "tmp.zig:2:18: error: expected struct, enum, or union; found 'i32'", | 2551 | "tmp.zig:2:18: error: expected struct, enum, or union; found 'i32'", |
| 2462 | }); | 2552 | }); |
| 2463 | | 2553 | |
| 2464 | cases.add("field access of slices", | 2554 | ctx.objErrStage1("field access of slices", |
| 2465 | \\export fn entry() void { | 2555 | \\export fn entry() void { |
| 2466 | \\ var slice: []i32 = undefined; | 2556 | \\ var slice: []i32 = undefined; |
| 2467 | \\ const info = @TypeOf(slice).unknown; | 2557 | \\ const info = @TypeOf(slice).unknown; |
| | 2558 | \\ _ = info; |
| 2468 | \\} | 2559 | \\} |
| 2469 | , &[_][]const u8{ | 2560 | , &[_][]const u8{ |
| 2470 | "tmp.zig:3:32: error: type 'type' does not support field access", | 2561 | "tmp.zig:3:32: error: type 'type' does not support field access", |
| 2471 | }); | 2562 | }); |
| 2472 | | 2563 | |
| 2473 | cases.add("peer cast then implicit cast const pointer to mutable C pointer", | 2564 | ctx.objErrStage1("peer cast then implicit cast const pointer to mutable C pointer", |
| 2474 | \\export fn func() void { | 2565 | \\export fn func() void { |
| 2475 | \\ var strValue: [*c]u8 = undefined; | 2566 | \\ var strValue: [*c]u8 = undefined; |
| 2476 | \\ strValue = strValue orelse ""; | 2567 | \\ strValue = strValue orelse ""; |
| ... | @@ -2480,19 +2571,20 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -2480,19 +2571,20 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2480 | "tmp.zig:3:32: note: cast discards const qualifier", | 2571 | "tmp.zig:3:32: note: cast discards const qualifier", |
| 2481 | }); | 2572 | }); |
| 2482 | | 2573 | |
| 2483 | cases.add("overflow in enum value allocation", | 2574 | ctx.objErrStage1("overflow in enum value allocation", |
| 2484 | \\const Moo = enum(u8) { | 2575 | \\const Moo = enum(u8) { |
| 2485 | \\ Last = 255, | 2576 | \\ Last = 255, |
| 2486 | \\ Over, | 2577 | \\ Over, |
| 2487 | \\}; | 2578 | \\}; |
| 2488 | \\pub fn main() void { | 2579 | \\pub fn main() void { |
| 2489 | \\ var y = Moo.Last; | 2580 | \\ var y = Moo.Last; |
| | 2581 | \\ _ = y; |
| 2490 | \\} | 2582 | \\} |
| 2491 | , &[_][]const u8{ | 2583 | , &[_][]const u8{ |
| 2492 | "tmp.zig:3:5: error: enumeration value 256 too large for type 'u8'", | 2584 | "tmp.zig:3:5: error: enumeration value 256 too large for type 'u8'", |
| 2493 | }); | 2585 | }); |
| 2494 | | 2586 | |
| 2495 | cases.add("attempt to cast enum literal to error", | 2587 | ctx.objErrStage1("attempt to cast enum literal to error", |
| 2496 | \\export fn entry() void { | 2588 | \\export fn entry() void { |
| 2497 | \\ switch (error.Hi) { | 2589 | \\ switch (error.Hi) { |
| 2498 | \\ .Hi => {}, | 2590 | \\ .Hi => {}, |
| ... | @@ -2502,7 +2594,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -2502,7 +2594,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2502 | "tmp.zig:3:9: error: expected type 'error{Hi}', found '(enum literal)'", | 2594 | "tmp.zig:3:9: error: expected type 'error{Hi}', found '(enum literal)'", |
| 2503 | }); | 2595 | }); |
| 2504 | | 2596 | |
| 2505 | cases.add("@sizeOf bad type", | 2597 | ctx.objErrStage1("@sizeOf bad type", |
| 2506 | \\export fn entry() usize { | 2598 | \\export fn entry() usize { |
| 2507 | \\ return @sizeOf(@TypeOf(null)); | 2599 | \\ return @sizeOf(@TypeOf(null)); |
| 2508 | \\} | 2600 | \\} |
| ... | @@ -2510,7 +2602,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -2510,7 +2602,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2510 | "tmp.zig:2:20: error: no size available for type '(null)'", | 2602 | "tmp.zig:2:20: error: no size available for type '(null)'", |
| 2511 | }); | 2603 | }); |
| 2512 | | 2604 | |
| 2513 | cases.add("generic function where return type is self-referenced", | 2605 | ctx.objErrStage1("generic function where return type is self-referenced", |
| 2514 | \\fn Foo(comptime T: type) Foo(T) { | 2606 | \\fn Foo(comptime T: type) Foo(T) { |
| 2515 | \\ return struct{ x: T }; | 2607 | \\ return struct{ x: T }; |
| 2516 | \\} | 2608 | \\} |
| ... | @@ -2518,34 +2610,37 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -2518,34 +2610,37 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2518 | \\ const t = Foo(u32) { | 2610 | \\ const t = Foo(u32) { |
| 2519 | \\ .x = 1 | 2611 | \\ .x = 1 |
| 2520 | \\ }; | 2612 | \\ }; |
| | 2613 | \\ _ = t; |
| 2521 | \\} | 2614 | \\} |
| 2522 | , &[_][]const u8{ | 2615 | , &[_][]const u8{ |
| 2523 | "tmp.zig:1:29: error: evaluation exceeded 1000 backwards branches", | 2616 | "tmp.zig:1:29: error: evaluation exceeded 1000 backwards branches", |
| 2524 | "tmp.zig:5:18: note: referenced here", | 2617 | "tmp.zig:5:18: note: referenced here", |
| 2525 | }); | 2618 | }); |
| 2526 | | 2619 | |
| 2527 | cases.add("@ptrToInt 0 to non optional pointer", | 2620 | ctx.objErrStage1("@ptrToInt 0 to non optional pointer", |
| 2528 | \\export fn entry() void { | 2621 | \\export fn entry() void { |
| 2529 | \\ var b = @intToPtr(*i32, 0); | 2622 | \\ var b = @intToPtr(*i32, 0); |
| | 2623 | \\ _ = b; |
| 2530 | \\} | 2624 | \\} |
| 2531 | , &[_][]const u8{ | 2625 | , &[_][]const u8{ |
| 2532 | "tmp.zig:2:13: error: pointer type '*i32' does not allow address zero", | 2626 | "tmp.zig:2:13: error: pointer type '*i32' does not allow address zero", |
| 2533 | }); | 2627 | }); |
| 2534 | | 2628 | |
| 2535 | cases.add("cast enum literal to enum but it doesn't match", | 2629 | ctx.objErrStage1("cast enum literal to enum but it doesn't match", |
| 2536 | \\const Foo = enum { | 2630 | \\const Foo = enum { |
| 2537 | \\ a, | 2631 | \\ a, |
| 2538 | \\ b, | 2632 | \\ b, |
| 2539 | \\}; | 2633 | \\}; |
| 2540 | \\export fn entry() void { | 2634 | \\export fn entry() void { |
| 2541 | \\ const x: Foo = .c; | 2635 | \\ const x: Foo = .c; |
| | 2636 | \\ _ = x; |
| 2542 | \\} | 2637 | \\} |
| 2543 | , &[_][]const u8{ | 2638 | , &[_][]const u8{ |
| 2544 | "tmp.zig:6:20: error: enum 'Foo' has no field named 'c'", | 2639 | "tmp.zig:6:20: error: enum 'Foo' has no field named 'c'", |
| 2545 | "tmp.zig:1:13: note: 'Foo' declared here", | 2640 | "tmp.zig:1:13: note: 'Foo' declared here", |
| 2546 | }); | 2641 | }); |
| 2547 | | 2642 | |
| 2548 | cases.add("discarding error value", | 2643 | ctx.objErrStage1("discarding error value", |
| 2549 | \\export fn entry() void { | 2644 | \\export fn entry() void { |
| 2550 | \\ _ = foo(); | 2645 | \\ _ = foo(); |
| 2551 | \\} | 2646 | \\} |
| ... | @@ -2556,7 +2651,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -2556,7 +2651,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2556 | "tmp.zig:2:12: error: error is discarded. consider using `try`, `catch`, or `if`", | 2651 | "tmp.zig:2:12: error: error is discarded. consider using `try`, `catch`, or `if`", |
| 2557 | }); | 2652 | }); |
| 2558 | | 2653 | |
| 2559 | cases.add("volatile on global assembly", | 2654 | ctx.objErrStage1("volatile on global assembly", |
| 2560 | \\comptime { | 2655 | \\comptime { |
| 2561 | \\ asm volatile (""); | 2656 | \\ asm volatile (""); |
| 2562 | \\} | 2657 | \\} |
| ... | @@ -2564,7 +2659,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -2564,7 +2659,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2564 | "tmp.zig:2:9: error: volatile is meaningless on global assembly", | 2659 | "tmp.zig:2:9: error: volatile is meaningless on global assembly", |
| 2565 | }); | 2660 | }); |
| 2566 | | 2661 | |
| 2567 | cases.add("invalid multiple dereferences", | 2662 | ctx.objErrStage1("invalid multiple dereferences", |
| 2568 | \\export fn a() void { | 2663 | \\export fn a() void { |
| 2569 | \\ var box = Box{ .field = 0 }; | 2664 | \\ var box = Box{ .field = 0 }; |
| 2570 | \\ box.*.field = 1; | 2665 | \\ box.*.field = 1; |
| ... | @@ -2582,13 +2677,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -2582,13 +2677,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2582 | "tmp.zig:8:13: error: attempt to dereference non-pointer type 'Box'", | 2677 | "tmp.zig:8:13: error: attempt to dereference non-pointer type 'Box'", |
| 2583 | }); | 2678 | }); |
| 2584 | | 2679 | |
| 2585 | cases.add("usingnamespace with wrong type", | 2680 | ctx.objErrStage1("usingnamespace with wrong type", |
| 2586 | \\usingnamespace void; | 2681 | \\usingnamespace void; |
| 2587 | , &[_][]const u8{ | 2682 | , &[_][]const u8{ |
| 2588 | "tmp.zig:1:1: error: expected struct, enum, or union; found 'void'", | 2683 | "tmp.zig:1:1: error: expected struct, enum, or union; found 'void'", |
| 2589 | }); | 2684 | }); |
| 2590 | | 2685 | |
| 2591 | cases.add("ignored expression in while continuation", | 2686 | ctx.objErrStage1("ignored expression in while continuation", |
| 2592 | \\export fn a() void { | 2687 | \\export fn a() void { |
| 2593 | \\ while (true) : (bad()) {} | 2688 | \\ while (true) : (bad()) {} |
| 2594 | \\} | 2689 | \\} |
| ... | @@ -2609,31 +2704,31 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -2609,31 +2704,31 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2609 | "tmp.zig:10:25: error: error is ignored. consider using `try`, `catch`, or `if`", | 2704 | "tmp.zig:10:25: error: error is ignored. consider using `try`, `catch`, or `if`", |
| 2610 | }); | 2705 | }); |
| 2611 | | 2706 | |
| 2612 | cases.add("empty while loop body", | 2707 | ctx.objErrStage1("empty while loop body", |
| 2613 | \\export fn a() void { | 2708 | \\export fn a() void { |
| 2614 | \\ while(true); | 2709 | \\ while(true); |
| 2615 | \\} | 2710 | \\} |
| 2616 | , &[_][]const u8{ | 2711 | , &[_][]const u8{ |
| 2617 | "tmp.zig:2:16: error: expected loop body, found ';'", | 2712 | "tmp.zig:2:16: error: expected block or assignment, found ';'", |
| 2618 | }); | 2713 | }); |
| 2619 | | 2714 | |
| 2620 | cases.add("empty for loop body", | 2715 | ctx.objErrStage1("empty for loop body", |
| 2621 | \\export fn a() void { | 2716 | \\export fn a() void { |
| 2622 | \\ for(undefined) |x|; | 2717 | \\ for(undefined) |x|; |
| 2623 | \\} | 2718 | \\} |
| 2624 | , &[_][]const u8{ | 2719 | , &[_][]const u8{ |
| 2625 | "tmp.zig:2:23: error: expected loop body, found ';'", | 2720 | "tmp.zig:2:23: error: expected block or assignment, found ';'", |
| 2626 | }); | 2721 | }); |
| 2627 | | 2722 | |
| 2628 | cases.add("empty if body", | 2723 | ctx.objErrStage1("empty if body", |
| 2629 | \\export fn a() void { | 2724 | \\export fn a() void { |
| 2630 | \\ if(true); | 2725 | \\ if(true); |
| 2631 | \\} | 2726 | \\} |
| 2632 | , &[_][]const u8{ | 2727 | , &[_][]const u8{ |
| 2633 | "tmp.zig:2:13: error: expected if body, found ';'", | 2728 | "tmp.zig:2:13: error: expected block or assignment, found ';'", |
| 2634 | }); | 2729 | }); |
| 2635 | | 2730 | |
| 2636 | cases.add("import outside package path", | 2731 | ctx.objErrStage1("import outside package path", |
| 2637 | \\comptime{ | 2732 | \\comptime{ |
| 2638 | \\ _ = @import("../a.zig"); | 2733 | \\ _ = @import("../a.zig"); |
| 2639 | \\} | 2734 | \\} |
| ... | @@ -2641,14 +2736,14 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -2641,14 +2736,14 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2641 | "tmp.zig:2:9: error: import of file outside package path: '../a.zig'", | 2736 | "tmp.zig:2:9: error: import of file outside package path: '../a.zig'", |
| 2642 | }); | 2737 | }); |
| 2643 | | 2738 | |
| 2644 | cases.add("bogus compile var", | 2739 | ctx.objErrStage1("bogus compile var", |
| 2645 | \\const x = @import("builtin").bogus; | 2740 | \\const x = @import("builtin").bogus; |
| 2646 | \\export fn entry() usize { return @sizeOf(@TypeOf(x)); } | 2741 | \\export fn entry() usize { return @sizeOf(@TypeOf(x)); } |
| 2647 | , &[_][]const u8{ | 2742 | , &[_][]const u8{ |
| 2648 | "tmp.zig:1:29: error: container 'builtin' has no member called 'bogus'", | 2743 | "tmp.zig:1:29: error: container 'builtin' has no member called 'bogus'", |
| 2649 | }); | 2744 | }); |
| 2650 | | 2745 | |
| 2651 | cases.add("wrong panic signature, runtime function", | 2746 | ctx.objErrStage1("wrong panic signature, runtime function", |
| 2652 | \\test "" {} | 2747 | \\test "" {} |
| 2653 | \\ | 2748 | \\ |
| 2654 | \\pub fn panic() void {} | 2749 | \\pub fn panic() void {} |
| ... | @@ -2657,8 +2752,9 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -2657,8 +2752,9 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2657 | "error: expected type 'fn([]const u8, ?*std.builtin.StackTrace) noreturn', found 'fn() void'", | 2752 | "error: expected type 'fn([]const u8, ?*std.builtin.StackTrace) noreturn', found 'fn() void'", |
| 2658 | }); | 2753 | }); |
| 2659 | | 2754 | |
| 2660 | cases.add("wrong panic signature, generic function", | 2755 | ctx.objErrStage1("wrong panic signature, generic function", |
| 2661 | \\pub fn panic(comptime msg: []const u8, error_return_trace: ?*builtin.StackTrace) noreturn { | 2756 | \\pub fn panic(comptime msg: []const u8, error_return_trace: ?*builtin.StackTrace) noreturn { |
| | 2757 | \\ _ = msg; _ = error_return_trace; |
| 2662 | \\ while (true) {} | 2758 | \\ while (true) {} |
| 2663 | \\} | 2759 | \\} |
| 2664 | , &[_][]const u8{ | 2760 | , &[_][]const u8{ |
| ... | @@ -2666,14 +2762,14 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -2666,14 +2762,14 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2666 | "note: only one of the functions is generic", | 2762 | "note: only one of the functions is generic", |
| 2667 | }); | 2763 | }); |
| 2668 | | 2764 | |
| 2669 | cases.add("direct struct loop", | 2765 | ctx.objErrStage1("direct struct loop", |
| 2670 | \\const A = struct { a : A, }; | 2766 | \\const A = struct { a : A, }; |
| 2671 | \\export fn entry() usize { return @sizeOf(A); } | 2767 | \\export fn entry() usize { return @sizeOf(A); } |
| 2672 | , &[_][]const u8{ | 2768 | , &[_][]const u8{ |
| 2673 | "tmp.zig:1:11: error: struct 'A' depends on itself", | 2769 | "tmp.zig:1:11: error: struct 'A' depends on itself", |
| 2674 | }); | 2770 | }); |
| 2675 | | 2771 | |
| 2676 | cases.add("indirect struct loop", | 2772 | ctx.objErrStage1("indirect struct loop", |
| 2677 | \\const A = struct { b : B, }; | 2773 | \\const A = struct { b : B, }; |
| 2678 | \\const B = struct { c : C, }; | 2774 | \\const B = struct { c : C, }; |
| 2679 | \\const C = struct { a : A, }; | 2775 | \\const C = struct { a : A, }; |
| ... | @@ -2682,7 +2778,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -2682,7 +2778,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2682 | "tmp.zig:1:11: error: struct 'A' depends on itself", | 2778 | "tmp.zig:1:11: error: struct 'A' depends on itself", |
| 2683 | }); | 2779 | }); |
| 2684 | | 2780 | |
| 2685 | cases.add("instantiating an undefined value for an invalid struct that contains itself", | 2781 | ctx.objErrStage1("instantiating an undefined value for an invalid struct that contains itself", |
| 2686 | \\const Foo = struct { | 2782 | \\const Foo = struct { |
| 2687 | \\ x: Foo, | 2783 | \\ x: Foo, |
| 2688 | \\}; | 2784 | \\}; |
| ... | @@ -2697,23 +2793,25 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -2697,23 +2793,25 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2697 | "tmp.zig:8:28: note: referenced here", | 2793 | "tmp.zig:8:28: note: referenced here", |
| 2698 | }); | 2794 | }); |
| 2699 | | 2795 | |
| 2700 | cases.add("enum field value references enum", | 2796 | ctx.objErrStage1("enum field value references enum", |
| 2701 | \\pub const Foo = extern enum { | 2797 | \\pub const Foo = enum(c_int) { |
| 2702 | \\ A = Foo.B, | 2798 | \\ A = Foo.B, |
| 2703 | \\ C = D, | 2799 | \\ C = D, |
| 2704 | \\}; | 2800 | \\}; |
| 2705 | \\export fn entry() void { | 2801 | \\export fn entry() void { |
| 2706 | \\ var s: Foo = Foo.E; | 2802 | \\ var s: Foo = Foo.E; |
| | 2803 | \\ _ = s; |
| 2707 | \\} | 2804 | \\} |
| 2708 | , &[_][]const u8{ | 2805 | , &[_][]const u8{ |
| 2709 | "tmp.zig:1:17: error: enum 'Foo' depends on itself", | 2806 | "tmp.zig:1:17: error: enum 'Foo' depends on itself", |
| 2710 | }); | 2807 | }); |
| 2711 | | 2808 | |
| 2712 | cases.add("top level decl dependency loop", | 2809 | ctx.objErrStage1("top level decl dependency loop", |
| 2713 | \\const a : @TypeOf(b) = 0; | 2810 | \\const a : @TypeOf(b) = 0; |
| 2714 | \\const b : @TypeOf(a) = 0; | 2811 | \\const b : @TypeOf(a) = 0; |
| 2715 | \\export fn entry() void { | 2812 | \\export fn entry() void { |
| 2716 | \\ const c = a + b; | 2813 | \\ const c = a + b; |
| | 2814 | \\ _ = c; |
| 2717 | \\} | 2815 | \\} |
| 2718 | , &[_][]const u8{ | 2816 | , &[_][]const u8{ |
| 2719 | "tmp.zig:2:19: error: dependency loop detected", | 2817 | "tmp.zig:2:19: error: dependency loop detected", |
| ... | @@ -2721,7 +2819,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -2721,7 +2819,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2721 | "tmp.zig:4:15: note: referenced here", | 2819 | "tmp.zig:4:15: note: referenced here", |
| 2722 | }); | 2820 | }); |
| 2723 | | 2821 | |
| 2724 | cases.addTest("not an enum type", | 2822 | ctx.testErrStage1("not an enum type", |
| 2725 | \\export fn entry() void { | 2823 | \\export fn entry() void { |
| 2726 | \\ var self: Error = undefined; | 2824 | \\ var self: Error = undefined; |
| 2727 | \\ switch (self) { | 2825 | \\ switch (self) { |
| ... | @@ -2739,18 +2837,19 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -2739,18 +2837,19 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2739 | "tmp.zig:4:9: error: expected type '@typeInfo(Error).Union.tag_type.?', found 'type'", | 2837 | "tmp.zig:4:9: error: expected type '@typeInfo(Error).Union.tag_type.?', found 'type'", |
| 2740 | }); | 2838 | }); |
| 2741 | | 2839 | |
| 2742 | cases.addTest("binary OR operator on error sets", | 2840 | ctx.testErrStage1("binary OR operator on error sets", |
| 2743 | \\pub const A = error.A; | 2841 | \\pub const A = error.A; |
| 2744 | \\pub const AB = A | error.B; | 2842 | \\pub const AB = A | error.B; |
| 2745 | \\export fn entry() void { | 2843 | \\export fn entry() void { |
| 2746 | \\ var x: AB = undefined; | 2844 | \\ var x: AB = undefined; |
| | 2845 | \\ _ = x; |
| 2747 | \\} | 2846 | \\} |
| 2748 | , &[_][]const u8{ | 2847 | , &[_][]const u8{ |
| 2749 | "tmp.zig:2:18: error: invalid operands to binary expression: 'error{A}' and 'error{B}'", | 2848 | "tmp.zig:2:18: error: invalid operands to binary expression: 'error{A}' and 'error{B}'", |
| 2750 | }); | 2849 | }); |
| 2751 | | 2850 | |
| 2752 | if (std.Target.current.os.tag == .linux) { | 2851 | if (std.Target.current.os.tag == .linux) { |
| 2753 | cases.addTest("implicit dependency on libc", | 2852 | ctx.testErrStage1("implicit dependency on libc", |
| 2754 | \\extern "c" fn exit(u8) void; | 2853 | \\extern "c" fn exit(u8) void; |
| 2755 | \\export fn entry() void { | 2854 | \\export fn entry() void { |
| 2756 | \\ exit(0); | 2855 | \\ exit(0); |
| ... | @@ -2759,7 +2858,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -2759,7 +2858,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", | 2858 | "tmp.zig:3:5: error: dependency on libc must be explicitly specified in the build command", |
| 2760 | }); | 2859 | }); |
| 2761 | | 2860 | |
| 2762 | cases.addTest("libc headers note", | 2861 | ctx.testErrStage1("libc headers note", |
| 2763 | \\const c = @cImport(@cInclude("stdio.h")); | 2862 | \\const c = @cImport(@cInclude("stdio.h")); |
| 2764 | \\export fn entry() void { | 2863 | \\export fn entry() void { |
| 2765 | \\ _ = c.printf("hello, world!\n"); | 2864 | \\ _ = c.printf("hello, world!\n"); |
| ... | @@ -2770,18 +2869,19 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -2770,18 +2869,19 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2770 | }); | 2869 | }); |
| 2771 | } | 2870 | } |
| 2772 | | 2871 | |
| 2773 | cases.addTest("comptime vector overflow shows the index", | 2872 | ctx.testErrStage1("comptime vector overflow shows the index", |
| 2774 | \\comptime { | 2873 | \\comptime { |
| 2775 | \\ var a: @import("std").meta.Vector(4, u8) = [_]u8{ 1, 2, 255, 4 }; | 2874 | \\ 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 }; | 2875 | \\ var b: @import("std").meta.Vector(4, u8) = [_]u8{ 5, 6, 1, 8 }; |
| 2777 | \\ var x = a + b; | 2876 | \\ var x = a + b; |
| | 2877 | \\ _ = x; |
| 2778 | \\} | 2878 | \\} |
| 2779 | , &[_][]const u8{ | 2879 | , &[_][]const u8{ |
| 2780 | "tmp.zig:4:15: error: operation caused overflow", | 2880 | "tmp.zig:4:15: error: operation caused overflow", |
| 2781 | "tmp.zig:4:15: note: when computing vector element at index 2", | 2881 | "tmp.zig:4:15: note: when computing vector element at index 2", |
| 2782 | }); | 2882 | }); |
| 2783 | | 2883 | |
| 2784 | cases.addTest("packed struct with fields of not allowed types", | 2884 | ctx.testErrStage1("packed struct with fields of not allowed types", |
| 2785 | \\const A = packed struct { | 2885 | \\const A = packed struct { |
| 2786 | \\ x: anyerror, | 2886 | \\ x: anyerror, |
| 2787 | \\}; | 2887 | \\}; |
| ... | @@ -2805,24 +2905,31 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -2805,24 +2905,31 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2805 | \\}; | 2905 | \\}; |
| 2806 | \\export fn entry1() void { | 2906 | \\export fn entry1() void { |
| 2807 | \\ var a: A = undefined; | 2907 | \\ var a: A = undefined; |
| | 2908 | \\ _ = a; |
| 2808 | \\} | 2909 | \\} |
| 2809 | \\export fn entry2() void { | 2910 | \\export fn entry2() void { |
| 2810 | \\ var b: B = undefined; | 2911 | \\ var b: B = undefined; |
| | 2912 | \\ _ = b; |
| 2811 | \\} | 2913 | \\} |
| 2812 | \\export fn entry3() void { | 2914 | \\export fn entry3() void { |
| 2813 | \\ var r: C = undefined; | 2915 | \\ var r: C = undefined; |
| | 2916 | \\ _ = r; |
| 2814 | \\} | 2917 | \\} |
| 2815 | \\export fn entry4() void { | 2918 | \\export fn entry4() void { |
| 2816 | \\ var d: D = undefined; | 2919 | \\ var d: D = undefined; |
| | 2920 | \\ _ = d; |
| 2817 | \\} | 2921 | \\} |
| 2818 | \\export fn entry5() void { | 2922 | \\export fn entry5() void { |
| 2819 | \\ var e: E = undefined; | 2923 | \\ var e: E = undefined; |
| | 2924 | \\ _ = e; |
| 2820 | \\} | 2925 | \\} |
| 2821 | \\export fn entry6() void { | 2926 | \\export fn entry6() void { |
| 2822 | \\ var f: F = undefined; | 2927 | \\ var f: F = undefined; |
| | 2928 | \\ _ = f; |
| 2823 | \\} | 2929 | \\} |
| 2824 | \\export fn entry7() void { | 2930 | \\export fn entry7() void { |
| 2825 | \\ var g: G = undefined; | 2931 | \\ var g: G = undefined; |
| | 2932 | \\ _ = g; |
| 2826 | \\} | 2933 | \\} |
| 2827 | \\const S = struct { | 2934 | \\const S = struct { |
| 2828 | \\ x: i32, | 2935 | \\ x: i32, |
| ... | @@ -2843,42 +2950,40 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -2843,42 +2950,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", | 2950 | "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", | 2951 | "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", | 2952 | "tmp.zig:20:5: error: type 'Enum' not allowed in packed struct; no guaranteed in-memory representation", |
| 2846 | "tmp.zig:50:14: note: enum declaration does not specify an integer tag type", | 2953 | "tmp.zig:57:14: note: enum declaration does not specify an integer tag type", |
| 2847 | }); | 2954 | }); |
| 2848 | | 2955 | |
| 2849 | cases.addCase(x: { | 2956 | ctx.objErrStage1("deduplicate undeclared identifier", |
| 2850 | var tc = cases.create("deduplicate undeclared identifier", | 2957 | \\export fn a() void { |
| 2851 | \\export fn a() void { | 2958 | \\ x += 1; |
| 2852 | \\ x += 1; | 2959 | \\} |
| 2853 | \\} | 2960 | \\export fn b() void { |
| 2854 | \\export fn b() void { | 2961 | \\ x += 1; |
| 2855 | \\ x += 1; | 2962 | \\} |
| 2856 | \\} | 2963 | , &[_][]const u8{ |
| 2857 | , &[_][]const u8{ | 2964 | "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 | }); | 2965 | }); |
| 2863 | | 2966 | |
| 2864 | cases.add("export generic function", | 2967 | ctx.objErrStage1("export generic function", |
| 2865 | \\export fn foo(num: anytype) i32 { | 2968 | \\export fn foo(num: anytype) i32 { |
| | 2969 | \\ _ = num; |
| 2866 | \\ return 0; | 2970 | \\ return 0; |
| 2867 | \\} | 2971 | \\} |
| 2868 | , &[_][]const u8{ | 2972 | , &[_][]const u8{ |
| 2869 | "tmp.zig:1:15: error: parameter of type 'anytype' not allowed in function with calling convention 'C'", | 2973 | "tmp.zig:1:15: error: parameter of type 'anytype' not allowed in function with calling convention 'C'", |
| 2870 | }); | 2974 | }); |
| 2871 | | 2975 | |
| 2872 | cases.add("C pointer to c_void", | 2976 | ctx.objErrStage1("C pointer to c_void", |
| 2873 | \\export fn a() void { | 2977 | \\export fn a() void { |
| 2874 | \\ var x: *c_void = undefined; | 2978 | \\ var x: *c_void = undefined; |
| 2875 | \\ var y: [*c]c_void = x; | 2979 | \\ var y: [*c]c_void = x; |
| | 2980 | \\ _ = y; |
| 2876 | \\} | 2981 | \\} |
| 2877 | , &[_][]const u8{ | 2982 | , &[_][]const u8{ |
| 2878 | "tmp.zig:3:16: error: C pointers cannot point to opaque types", | 2983 | "tmp.zig:3:16: error: C pointers cannot point to opaque types", |
| 2879 | }); | 2984 | }); |
| 2880 | | 2985 | |
| 2881 | cases.add("directly embedding opaque type in struct and union", | 2986 | ctx.objErrStage1("directly embedding opaque type in struct and union", |
| 2882 | \\const O = opaque {}; | 2987 | \\const O = opaque {}; |
| 2883 | \\const Foo = struct { | 2988 | \\const Foo = struct { |
| 2884 | \\ o: O, | 2989 | \\ o: O, |
| ... | @@ -2889,74 +2994,85 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -2889,74 +2994,85 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2889 | \\}; | 2994 | \\}; |
| 2890 | \\export fn a() void { | 2995 | \\export fn a() void { |
| 2891 | \\ var foo: Foo = undefined; | 2996 | \\ var foo: Foo = undefined; |
| | 2997 | \\ _ = foo; |
| 2892 | \\} | 2998 | \\} |
| 2893 | \\export fn b() void { | 2999 | \\export fn b() void { |
| 2894 | \\ var bar: Bar = undefined; | 3000 | \\ var bar: Bar = undefined; |
| | 3001 | \\ _ = bar; |
| 2895 | \\} | 3002 | \\} |
| 2896 | \\export fn c() void { | 3003 | \\export fn c() void { |
| 2897 | \\ var baz: *opaque {} = undefined; | 3004 | \\ var baz: *opaque {} = undefined; |
| 2898 | \\ const qux = .{baz.*}; | 3005 | \\ const qux = .{baz.*}; |
| | 3006 | \\ _ = qux; |
| 2899 | \\} | 3007 | \\} |
| 2900 | , &[_][]const u8{ | 3008 | , &[_][]const u8{ |
| 2901 | "tmp.zig:3:5: error: opaque types have unknown size and therefore cannot be directly embedded in structs", | 3009 | "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", | 3010 | "tmp.zig:7:5: error: opaque types have unknown size and therefore cannot be directly embedded in unions", |
| 2903 | "tmp.zig:17:22: error: opaque types have unknown size and therefore cannot be directly embedded in structs", | 3011 | "tmp.zig:19:22: error: opaque types have unknown size and therefore cannot be directly embedded in structs", |
| 2904 | }); | 3012 | }); |
| 2905 | | 3013 | |
| 2906 | cases.add("implicit cast between C pointer and Zig pointer - bad const/align/child", | 3014 | ctx.objErrStage1("implicit cast between C pointer and Zig pointer - bad const/align/child", |
| 2907 | \\export fn a() void { | 3015 | \\export fn a() void { |
| 2908 | \\ var x: [*c]u8 = undefined; | 3016 | \\ var x: [*c]u8 = undefined; |
| 2909 | \\ var y: *align(4) u8 = x; | 3017 | \\ var y: *align(4) u8 = x; |
| | 3018 | \\ _ = y; |
| 2910 | \\} | 3019 | \\} |
| 2911 | \\export fn b() void { | 3020 | \\export fn b() void { |
| 2912 | \\ var x: [*c]const u8 = undefined; | 3021 | \\ var x: [*c]const u8 = undefined; |
| 2913 | \\ var y: *u8 = x; | 3022 | \\ var y: *u8 = x; |
| | 3023 | \\ _ = y; |
| 2914 | \\} | 3024 | \\} |
| 2915 | \\export fn c() void { | 3025 | \\export fn c() void { |
| 2916 | \\ var x: [*c]u8 = undefined; | 3026 | \\ var x: [*c]u8 = undefined; |
| 2917 | \\ var y: *u32 = x; | 3027 | \\ var y: *u32 = x; |
| | 3028 | \\ _ = y; |
| 2918 | \\} | 3029 | \\} |
| 2919 | \\export fn d() void { | 3030 | \\export fn d() void { |
| 2920 | \\ var y: *align(1) u32 = undefined; | 3031 | \\ var y: *align(1) u32 = undefined; |
| 2921 | \\ var x: [*c]u32 = y; | 3032 | \\ var x: [*c]u32 = y; |
| | 3033 | \\ _ = x; |
| 2922 | \\} | 3034 | \\} |
| 2923 | \\export fn e() void { | 3035 | \\export fn e() void { |
| 2924 | \\ var y: *const u8 = undefined; | 3036 | \\ var y: *const u8 = undefined; |
| 2925 | \\ var x: [*c]u8 = y; | 3037 | \\ var x: [*c]u8 = y; |
| | 3038 | \\ _ = x; |
| 2926 | \\} | 3039 | \\} |
| 2927 | \\export fn f() void { | 3040 | \\export fn f() void { |
| 2928 | \\ var y: *u8 = undefined; | 3041 | \\ var y: *u8 = undefined; |
| 2929 | \\ var x: [*c]u32 = y; | 3042 | \\ var x: [*c]u32 = y; |
| | 3043 | \\ _ = x; |
| 2930 | \\} | 3044 | \\} |
| 2931 | , &[_][]const u8{ | 3045 | , &[_][]const u8{ |
| 2932 | "tmp.zig:3:27: error: cast increases pointer alignment", | 3046 | "tmp.zig:3:27: error: cast increases pointer alignment", |
| 2933 | "tmp.zig:7:18: error: cast discards const qualifier", | 3047 | "tmp.zig:8:18: error: cast discards const qualifier", |
| 2934 | "tmp.zig:11:19: error: expected type '*u32', found '[*c]u8'", | 3048 | "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'", | 3049 | "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", | 3050 | "tmp.zig:18:22: error: cast increases pointer alignment", |
| 2937 | "tmp.zig:19:21: error: cast discards const qualifier", | 3051 | "tmp.zig:23:21: error: cast discards const qualifier", |
| 2938 | "tmp.zig:23:22: error: expected type '[*c]u32', found '*u8'", | 3052 | "tmp.zig:28:22: error: expected type '[*c]u32', found '*u8'", |
| 2939 | }); | 3053 | }); |
| 2940 | | 3054 | |
| 2941 | cases.add("implicit casting null c pointer to zig pointer", | 3055 | ctx.objErrStage1("implicit casting null c pointer to zig pointer", |
| 2942 | \\comptime { | 3056 | \\comptime { |
| 2943 | \\ var c_ptr: [*c]u8 = 0; | 3057 | \\ var c_ptr: [*c]u8 = 0; |
| 2944 | \\ var zig_ptr: *u8 = c_ptr; | 3058 | \\ var zig_ptr: *u8 = c_ptr; |
| | 3059 | \\ _ = zig_ptr; |
| 2945 | \\} | 3060 | \\} |
| 2946 | , &[_][]const u8{ | 3061 | , &[_][]const u8{ |
| 2947 | "tmp.zig:3:24: error: null pointer casted to type '*u8'", | 3062 | "tmp.zig:3:24: error: null pointer casted to type '*u8'", |
| 2948 | }); | 3063 | }); |
| 2949 | | 3064 | |
| 2950 | cases.add("implicit casting undefined c pointer to zig pointer", | 3065 | ctx.objErrStage1("implicit casting undefined c pointer to zig pointer", |
| 2951 | \\comptime { | 3066 | \\comptime { |
| 2952 | \\ var c_ptr: [*c]u8 = undefined; | 3067 | \\ var c_ptr: [*c]u8 = undefined; |
| 2953 | \\ var zig_ptr: *u8 = c_ptr; | 3068 | \\ var zig_ptr: *u8 = c_ptr; |
| | 3069 | \\ _ = zig_ptr; |
| 2954 | \\} | 3070 | \\} |
| 2955 | , &[_][]const u8{ | 3071 | , &[_][]const u8{ |
| 2956 | "tmp.zig:3:24: error: use of undefined value here causes undefined behavior", | 3072 | "tmp.zig:3:24: error: use of undefined value here causes undefined behavior", |
| 2957 | }); | 3073 | }); |
| 2958 | | 3074 | |
| 2959 | cases.add("implicit casting C pointers which would mess up null semantics", | 3075 | ctx.objErrStage1("implicit casting C pointers which would mess up null semantics", |
| 2960 | \\export fn entry() void { | 3076 | \\export fn entry() void { |
| 2961 | \\ var slice: []const u8 = "aoeu"; | 3077 | \\ var slice: []const u8 = "aoeu"; |
| 2962 | \\ const opt_many_ptr: [*]const u8 = slice.ptr; | 3078 | \\ const opt_many_ptr: [*]const u8 = slice.ptr; |
| ... | @@ -2970,6 +3086,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -2970,6 +3086,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2970 | \\ var opt_many_ptr: [*]u8 = slice.ptr; | 3086 | \\ var opt_many_ptr: [*]u8 = slice.ptr; |
| 2971 | \\ var ptr_opt_many_ptr = &opt_many_ptr; | 3087 | \\ var ptr_opt_many_ptr = &opt_many_ptr; |
| 2972 | \\ var c_ptr: [*c][*c]const u8 = ptr_opt_many_ptr; | 3088 | \\ var c_ptr: [*c][*c]const u8 = ptr_opt_many_ptr; |
| | 3089 | \\ _ = c_ptr; |
| 2973 | \\} | 3090 | \\} |
| 2974 | , &[_][]const u8{ | 3091 | , &[_][]const u8{ |
| 2975 | "tmp.zig:6:24: error: expected type '*const [*]const u8', found '[*c]const [*c]const u8'", | 3092 | "tmp.zig:6:24: error: expected type '*const [*]const u8', found '[*c]const [*c]const u8'", |
| ... | @@ -2980,47 +3097,46 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -2980,47 +3097,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'", | 3097 | "tmp.zig:13:35: note: mutable '[*c]const u8' allows illegal null values stored to type '[*]u8'", |
| 2981 | }); | 3098 | }); |
| 2982 | | 3099 | |
| 2983 | cases.add("implicit casting too big integers to C pointers", | 3100 | ctx.objErrStage1("implicit casting too big integers to C pointers", |
| 2984 | \\export fn a() void { | 3101 | \\export fn a() void { |
| 2985 | \\ var ptr: [*c]u8 = (1 << 64) + 1; | 3102 | \\ var ptr: [*c]u8 = (1 << 64) + 1; |
| | 3103 | \\ _ = ptr; |
| 2986 | \\} | 3104 | \\} |
| 2987 | \\export fn b() void { | 3105 | \\export fn b() void { |
| 2988 | \\ var x: u65 = 0x1234; | 3106 | \\ var x: u65 = 0x1234; |
| 2989 | \\ var ptr: [*c]u8 = x; | 3107 | \\ var ptr: [*c]u8 = x; |
| | 3108 | \\ _ = ptr; |
| 2990 | \\} | 3109 | \\} |
| 2991 | , &[_][]const u8{ | 3110 | , &[_][]const u8{ |
| 2992 | "tmp.zig:2:33: error: integer value 18446744073709551617 cannot be coerced to type 'usize'", | 3111 | "tmp.zig:2:33: error: integer value 18446744073709551617 cannot be coerced to type 'usize'", |
| 2993 | "tmp.zig:6:23: error: integer type 'u65' too big for implicit @intToPtr to type '[*c]u8'", | 3112 | "tmp.zig:7:23: error: integer type 'u65' too big for implicit @intToPtr to type '[*c]u8'", |
| 2994 | }); | 3113 | }); |
| 2995 | | 3114 | |
| 2996 | cases.add("C pointer pointing to non C ABI compatible type or has align attr", | 3115 | ctx.objErrStage1("C pointer pointing to non C ABI compatible type or has align attr", |
| 2997 | \\const Foo = struct {}; | 3116 | \\const Foo = struct {}; |
| 2998 | \\export fn a() void { | 3117 | \\export fn a() void { |
| 2999 | \\ const T = [*c]Foo; | 3118 | \\ const T = [*c]Foo; |
| 3000 | \\ var t: T = undefined; | 3119 | \\ var t: T = undefined; |
| | 3120 | \\ _ = t; |
| 3001 | \\} | 3121 | \\} |
| 3002 | , &[_][]const u8{ | 3122 | , &[_][]const u8{ |
| 3003 | "tmp.zig:3:19: error: C pointers cannot point to non-C-ABI-compatible type 'Foo'", | 3123 | "tmp.zig:3:19: error: C pointers cannot point to non-C-ABI-compatible type 'Foo'", |
| 3004 | }); | 3124 | }); |
| 3005 | | 3125 | |
| 3006 | cases.addCase(x: { | 3126 | ctx.objErrStage1("compile log statement warning deduplication in generic fn", |
| 3007 | var tc = cases.create("compile log statement warning deduplication in generic fn", | 3127 | \\export fn entry() void { |
| 3008 | \\export fn entry() void { | 3128 | \\ inner(1); |
| 3009 | \\ inner(1); | 3129 | \\ inner(2); |
| 3010 | \\ inner(2); | 3130 | \\} |
| 3011 | \\} | 3131 | \\fn inner(comptime n: usize) void { |
| 3012 | \\fn inner(comptime n: usize) void { | 3132 | \\ comptime var i = 0; |
| 3013 | \\ comptime var i = 0; | 3133 | \\ inline while (i < n) : (i += 1) { @compileLog("!@#$"); } |
| 3014 | \\ inline while (i < n) : (i += 1) { @compileLog("!@#$"); } | 3134 | \\} |
| 3015 | \\} | 3135 | , &[_][]const u8{ |
| 3016 | , &[_][]const u8{ | 3136 | "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 | }); | 3137 | }); |
| 3022 | | 3138 | |
| 3023 | cases.add("assign to invalid dereference", | 3139 | ctx.objErrStage1("assign to invalid dereference", |
| 3024 | \\export fn entry() void { | 3140 | \\export fn entry() void { |
| 3025 | \\ 'a'.* = 1; | 3141 | \\ 'a'.* = 1; |
| 3026 | \\} | 3142 | \\} |
| ... | @@ -3028,54 +3144,58 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -3028,54 +3144,58 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3028 | "tmp.zig:2:8: error: attempt to dereference non-pointer type 'comptime_int'", | 3144 | "tmp.zig:2:8: error: attempt to dereference non-pointer type 'comptime_int'", |
| 3029 | }); | 3145 | }); |
| 3030 | | 3146 | |
| 3031 | cases.add("take slice of invalid dereference", | 3147 | ctx.objErrStage1("take slice of invalid dereference", |
| 3032 | \\export fn entry() void { | 3148 | \\export fn entry() void { |
| 3033 | \\ const x = 'a'.*[0..]; | 3149 | \\ const x = 'a'.*[0..]; |
| | 3150 | \\ _ = x; |
| 3034 | \\} | 3151 | \\} |
| 3035 | , &[_][]const u8{ | 3152 | , &[_][]const u8{ |
| 3036 | "tmp.zig:2:18: error: attempt to dereference non-pointer type 'comptime_int'", | 3153 | "tmp.zig:2:18: error: attempt to dereference non-pointer type 'comptime_int'", |
| 3037 | }); | 3154 | }); |
| 3038 | | 3155 | |
| 3039 | cases.add("@truncate undefined value", | 3156 | ctx.objErrStage1("@truncate undefined value", |
| 3040 | \\export fn entry() void { | 3157 | \\export fn entry() void { |
| 3041 | \\ var z = @truncate(u8, @as(u16, undefined)); | 3158 | \\ var z = @truncate(u8, @as(u16, undefined)); |
| | 3159 | \\ _ = z; |
| 3042 | \\} | 3160 | \\} |
| 3043 | , &[_][]const u8{ | 3161 | , &[_][]const u8{ |
| 3044 | "tmp.zig:2:27: error: use of undefined value here causes undefined behavior", | 3162 | "tmp.zig:2:27: error: use of undefined value here causes undefined behavior", |
| 3045 | }); | 3163 | }); |
| 3046 | | 3164 | |
| 3047 | cases.addTest("return invalid type from test", | 3165 | ctx.testErrStage1("return invalid type from test", |
| 3048 | \\test "example" { return 1; } | 3166 | \\test "example" { return 1; } |
| 3049 | , &[_][]const u8{ | 3167 | , &[_][]const u8{ |
| 3050 | "tmp.zig:1:25: error: expected type 'void', found 'comptime_int'", | 3168 | "tmp.zig:1:25: error: expected type 'void', found 'comptime_int'", |
| 3051 | }); | 3169 | }); |
| 3052 | | 3170 | |
| 3053 | cases.add("threadlocal qualifier on const", | 3171 | ctx.objErrStage1("threadlocal qualifier on const", |
| 3054 | \\threadlocal const x: i32 = 1234; | 3172 | \\threadlocal const x: i32 = 1234; |
| 3055 | \\export fn entry() i32 { | 3173 | \\export fn entry() i32 { |
| 3056 | \\ return x; | 3174 | \\ return x; |
| 3057 | \\} | 3175 | \\} |
| 3058 | , &[_][]const u8{ | 3176 | , &[_][]const u8{ |
| 3059 | "tmp.zig:1:13: error: threadlocal variable cannot be constant", | 3177 | "tmp.zig:1:1: error: threadlocal variable cannot be constant", |
| 3060 | }); | 3178 | }); |
| 3061 | | 3179 | |
| 3062 | cases.add("@bitCast same size but bit count mismatch", | 3180 | ctx.objErrStage1("@bitCast same size but bit count mismatch", |
| 3063 | \\export fn entry(byte: u8) void { | 3181 | \\export fn entry(byte: u8) void { |
| 3064 | \\ var oops = @bitCast(u7, byte); | 3182 | \\ var oops = @bitCast(u7, byte); |
| | 3183 | \\ _ = oops; |
| 3065 | \\} | 3184 | \\} |
| 3066 | , &[_][]const u8{ | 3185 | , &[_][]const u8{ |
| 3067 | "tmp.zig:2:25: error: destination type 'u7' has 7 bits but source type 'u8' has 8 bits", | 3186 | "tmp.zig:2:25: error: destination type 'u7' has 7 bits but source type 'u8' has 8 bits", |
| 3068 | }); | 3187 | }); |
| 3069 | | 3188 | |
| 3070 | cases.add("@bitCast with different sizes inside an expression", | 3189 | ctx.objErrStage1("@bitCast with different sizes inside an expression", |
| 3071 | \\export fn entry() void { | 3190 | \\export fn entry() void { |
| 3072 | \\ var foo = (@bitCast(u8, @as(f32, 1.0)) == 0xf); | 3191 | \\ var foo = (@bitCast(u8, @as(f32, 1.0)) == 0xf); |
| | 3192 | \\ _ = foo; |
| 3073 | \\} | 3193 | \\} |
| 3074 | , &[_][]const u8{ | 3194 | , &[_][]const u8{ |
| 3075 | "tmp.zig:2:25: error: destination type 'u8' has size 1 but source type 'f32' has size 4", | 3195 | "tmp.zig:2:25: error: destination type 'u8' has size 1 but source type 'f32' has size 4", |
| 3076 | }); | 3196 | }); |
| 3077 | | 3197 | |
| 3078 | cases.add("attempted `&&`", | 3198 | ctx.objErrStage1("attempted `&&`", |
| 3079 | \\export fn entry(a: bool, b: bool) i32 { | 3199 | \\export fn entry(a: bool, b: bool) i32 { |
| 3080 | \\ if (a && b) { | 3200 | \\ if (a && b) { |
| 3081 | \\ return 1234; | 3201 | \\ return 1234; |
| ... | @@ -3083,10 +3203,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -3083,10 +3203,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3083 | \\ return 5678; | 3203 | \\ return 5678; |
| 3084 | \\} | 3204 | \\} |
| 3085 | , &[_][]const u8{ | 3205 | , &[_][]const u8{ |
| 3086 | "tmp.zig:2:12: error: `&&` is invalid. Note that `and` is boolean AND", | 3206 | "tmp.zig:2:11: error: `&&` is invalid; note that `and` is boolean AND", |
| 3087 | }); | 3207 | }); |
| 3088 | | 3208 | |
| 3089 | cases.add("attempted `||` on boolean values", | 3209 | ctx.objErrStage1("attempted `||` on boolean values", |
| 3090 | \\export fn entry(a: bool, b: bool) i32 { | 3210 | \\export fn entry(a: bool, b: bool) i32 { |
| 3091 | \\ if (a || b) { | 3211 | \\ if (a || b) { |
| 3092 | \\ return 1234; | 3212 | \\ return 1234; |
| ... | @@ -3098,7 +3218,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -3098,7 +3218,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3098 | "tmp.zig:2:11: note: `||` merges error sets; `or` performs boolean OR", | 3218 | "tmp.zig:2:11: note: `||` merges error sets; `or` performs boolean OR", |
| 3099 | }); | 3219 | }); |
| 3100 | | 3220 | |
| 3101 | cases.add("compile log a pointer to an opaque value", | 3221 | ctx.objErrStage1("compile log a pointer to an opaque value", |
| 3102 | \\export fn entry() void { | 3222 | \\export fn entry() void { |
| 3103 | \\ @compileLog(@ptrCast(*const c_void, &entry)); | 3223 | \\ @compileLog(@ptrCast(*const c_void, &entry)); |
| 3104 | \\} | 3224 | \\} |
| ... | @@ -3106,13 +3226,14 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -3106,13 +3226,14 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3106 | "tmp.zig:2:5: error: found compile log statement", | 3226 | "tmp.zig:2:5: error: found compile log statement", |
| 3107 | }); | 3227 | }); |
| 3108 | | 3228 | |
| 3109 | cases.add("duplicate boolean switch value", | 3229 | ctx.objErrStage1("duplicate boolean switch value", |
| 3110 | \\comptime { | 3230 | \\comptime { |
| 3111 | \\ const x = switch (true) { | 3231 | \\ const x = switch (true) { |
| 3112 | \\ true => false, | 3232 | \\ true => false, |
| 3113 | \\ false => true, | 3233 | \\ false => true, |
| 3114 | \\ true => false, | 3234 | \\ true => false, |
| 3115 | \\ }; | 3235 | \\ }; |
| | 3236 | \\ _ = x; |
| 3116 | \\} | 3237 | \\} |
| 3117 | \\comptime { | 3238 | \\comptime { |
| 3118 | \\ const x = switch (true) { | 3239 | \\ const x = switch (true) { |
| ... | @@ -3120,42 +3241,46 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -3120,42 +3241,46 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3120 | \\ true => false, | 3241 | \\ true => false, |
| 3121 | \\ false => true, | 3242 | \\ false => true, |
| 3122 | \\ }; | 3243 | \\ }; |
| | 3244 | \\ _ = x; |
| 3123 | \\} | 3245 | \\} |
| 3124 | , &[_][]const u8{ | 3246 | , &[_][]const u8{ |
| 3125 | "tmp.zig:5:9: error: duplicate switch value", | 3247 | "tmp.zig:5:9: error: duplicate switch value", |
| 3126 | "tmp.zig:12:9: error: duplicate switch value", | 3248 | "tmp.zig:13:9: error: duplicate switch value", |
| 3127 | }); | 3249 | }); |
| 3128 | | 3250 | |
| 3129 | cases.add("missing boolean switch value", | 3251 | ctx.objErrStage1("missing boolean switch value", |
| 3130 | \\comptime { | 3252 | \\comptime { |
| 3131 | \\ const x = switch (true) { | 3253 | \\ const x = switch (true) { |
| 3132 | \\ true => false, | 3254 | \\ true => false, |
| 3133 | \\ }; | 3255 | \\ }; |
| | 3256 | \\ _ = x; |
| 3134 | \\} | 3257 | \\} |
| 3135 | \\comptime { | 3258 | \\comptime { |
| 3136 | \\ const x = switch (true) { | 3259 | \\ const x = switch (true) { |
| 3137 | \\ false => true, | 3260 | \\ false => true, |
| 3138 | \\ }; | 3261 | \\ }; |
| | 3262 | \\ _ = x; |
| 3139 | \\} | 3263 | \\} |
| 3140 | , &[_][]const u8{ | 3264 | , &[_][]const u8{ |
| 3141 | "tmp.zig:2:15: error: switch must handle all possibilities", | 3265 | "tmp.zig:2:15: error: switch must handle all possibilities", |
| 3142 | "tmp.zig:7:15: error: switch must handle all possibilities", | 3266 | "tmp.zig:8:15: error: switch must handle all possibilities", |
| 3143 | }); | 3267 | }); |
| 3144 | | 3268 | |
| 3145 | cases.add("reading past end of pointer casted array", | 3269 | ctx.objErrStage1("reading past end of pointer casted array", |
| 3146 | \\comptime { | 3270 | \\comptime { |
| 3147 | \\ const array: [4]u8 = "aoeu".*; | 3271 | \\ const array: [4]u8 = "aoeu".*; |
| 3148 | \\ const sub_array = array[1..]; | 3272 | \\ const sub_array = array[1..]; |
| 3149 | \\ const int_ptr = @ptrCast(*const u24, sub_array); | 3273 | \\ const int_ptr = @ptrCast(*const u24, sub_array); |
| 3150 | \\ const deref = int_ptr.*; | 3274 | \\ const deref = int_ptr.*; |
| | 3275 | \\ _ = deref; |
| 3151 | \\} | 3276 | \\} |
| 3152 | , &[_][]const u8{ | 3277 | , &[_][]const u8{ |
| 3153 | "tmp.zig:5:26: error: attempt to read 4 bytes from [4]u8 at index 1 which is 3 bytes", | 3278 | "tmp.zig:5:26: error: attempt to read 4 bytes from [4]u8 at index 1 which is 3 bytes", |
| 3154 | }); | 3279 | }); |
| 3155 | | 3280 | |
| 3156 | cases.add("error note for function parameter incompatibility", | 3281 | ctx.objErrStage1("error note for function parameter incompatibility", |
| 3157 | \\fn do_the_thing(func: fn (arg: i32) void) void {} | 3282 | \\fn do_the_thing(func: fn (arg: i32) void) void { _ = func; } |
| 3158 | \\fn bar(arg: bool) void {} | 3283 | \\fn bar(arg: bool) void { _ = arg; } |
| 3159 | \\export fn entry() void { | 3284 | \\export fn entry() void { |
| 3160 | \\ do_the_thing(bar); | 3285 | \\ do_the_thing(bar); |
| 3161 | \\} | 3286 | \\} |
| ... | @@ -3163,56 +3288,63 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -3163,56 +3288,63 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3163 | "tmp.zig:4:18: error: expected type 'fn(i32) void', found 'fn(bool) void", | 3288 | "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'", | 3289 | "tmp.zig:4:18: note: parameter 0: 'bool' cannot cast into 'i32'", |
| 3165 | }); | 3290 | }); |
| 3166 | cases.add("cast negative value to unsigned integer", | 3291 | ctx.objErrStage1("cast negative value to unsigned integer", |
| 3167 | \\comptime { | 3292 | \\comptime { |
| 3168 | \\ const value: i32 = -1; | 3293 | \\ const value: i32 = -1; |
| 3169 | \\ const unsigned = @intCast(u32, value); | 3294 | \\ const unsigned = @intCast(u32, value); |
| | 3295 | \\ _ = unsigned; |
| 3170 | \\} | 3296 | \\} |
| 3171 | \\export fn entry1() void { | 3297 | \\export fn entry1() void { |
| 3172 | \\ const value: i32 = -1; | 3298 | \\ const value: i32 = -1; |
| 3173 | \\ const unsigned: u32 = value; | 3299 | \\ const unsigned: u32 = value; |
| | 3300 | \\ _ = unsigned; |
| 3174 | \\} | 3301 | \\} |
| 3175 | , &[_][]const u8{ | 3302 | , &[_][]const u8{ |
| 3176 | "tmp.zig:3:22: error: attempt to cast negative value to unsigned integer", | 3303 | "tmp.zig:3:22: error: attempt to cast negative value to unsigned integer", |
| 3177 | "tmp.zig:7:27: error: cannot cast negative value -1 to unsigned integer type 'u32'", | 3304 | "tmp.zig:8:27: error: cannot cast negative value -1 to unsigned integer type 'u32'", |
| 3178 | }); | 3305 | }); |
| 3179 | | 3306 | |
| 3180 | cases.add("integer cast truncates bits", | 3307 | ctx.objErrStage1("integer cast truncates bits", |
| 3181 | \\export fn entry1() void { | 3308 | \\export fn entry1() void { |
| 3182 | \\ const spartan_count: u16 = 300; | 3309 | \\ const spartan_count: u16 = 300; |
| 3183 | \\ const byte = @intCast(u8, spartan_count); | 3310 | \\ const byte = @intCast(u8, spartan_count); |
| | 3311 | \\ _ = byte; |
| 3184 | \\} | 3312 | \\} |
| 3185 | \\export fn entry2() void { | 3313 | \\export fn entry2() void { |
| 3186 | \\ const spartan_count: u16 = 300; | 3314 | \\ const spartan_count: u16 = 300; |
| 3187 | \\ const byte: u8 = spartan_count; | 3315 | \\ const byte: u8 = spartan_count; |
| | 3316 | \\ _ = byte; |
| 3188 | \\} | 3317 | \\} |
| 3189 | \\export fn entry3() void { | 3318 | \\export fn entry3() void { |
| 3190 | \\ var spartan_count: u16 = 300; | 3319 | \\ var spartan_count: u16 = 300; |
| 3191 | \\ var byte: u8 = spartan_count; | 3320 | \\ var byte: u8 = spartan_count; |
| | 3321 | \\ _ = byte; |
| 3192 | \\} | 3322 | \\} |
| 3193 | \\export fn entry4() void { | 3323 | \\export fn entry4() void { |
| 3194 | \\ var signed: i8 = -1; | 3324 | \\ var signed: i8 = -1; |
| 3195 | \\ var unsigned: u64 = signed; | 3325 | \\ var unsigned: u64 = signed; |
| | 3326 | \\ _ = unsigned; |
| 3196 | \\} | 3327 | \\} |
| 3197 | , &[_][]const u8{ | 3328 | , &[_][]const u8{ |
| 3198 | "tmp.zig:3:18: error: cast from 'u16' to 'u8' truncates bits", | 3329 | "tmp.zig:3:18: error: cast from 'u16' to 'u8' truncates bits", |
| 3199 | "tmp.zig:7:22: error: integer value 300 cannot be coerced to type 'u8'", | 3330 | "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'", | 3331 | "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", | 3332 | "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'", | 3333 | "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", | 3334 | "tmp.zig:18:25: note: unsigned 64-bit int cannot represent all possible signed 8-bit values", |
| 3204 | }); | 3335 | }); |
| 3205 | | 3336 | |
| 3206 | cases.add("comptime implicit cast f64 to f32", | 3337 | ctx.objErrStage1("comptime implicit cast f64 to f32", |
| 3207 | \\export fn entry() void { | 3338 | \\export fn entry() void { |
| 3208 | \\ const x: f64 = 16777217; | 3339 | \\ const x: f64 = 16777217; |
| 3209 | \\ const y: f32 = x; | 3340 | \\ const y: f32 = x; |
| | 3341 | \\ _ = y; |
| 3210 | \\} | 3342 | \\} |
| 3211 | , &[_][]const u8{ | 3343 | , &[_][]const u8{ |
| 3212 | "tmp.zig:3:20: error: cast of value 16777217.000000 to type 'f32' loses information", | 3344 | "tmp.zig:3:20: error: cast of value 16777217.000000 to type 'f32' loses information", |
| 3213 | }); | 3345 | }); |
| 3214 | | 3346 | |
| 3215 | cases.add("implicit cast from f64 to f32", | 3347 | ctx.objErrStage1("implicit cast from f64 to f32", |
| 3216 | \\var x: f64 = 1.0; | 3348 | \\var x: f64 = 1.0; |
| 3217 | \\var y: f32 = x; | 3349 | \\var y: f32 = x; |
| 3218 | \\ | 3350 | \\ |
| ... | @@ -3221,41 +3353,46 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -3221,41 +3353,46 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3221 | "tmp.zig:2:14: error: expected type 'f32', found 'f64'", | 3353 | "tmp.zig:2:14: error: expected type 'f32', found 'f64'", |
| 3222 | }); | 3354 | }); |
| 3223 | | 3355 | |
| 3224 | cases.add("exceeded maximum bit width of integer", | 3356 | ctx.objErrStage1("exceeded maximum bit width of integer", |
| 3225 | \\export fn entry1() void { | 3357 | \\export fn entry1() void { |
| 3226 | \\ const T = u65536; | 3358 | \\ const T = u65536; |
| | 3359 | \\ _ = T; |
| 3227 | \\} | 3360 | \\} |
| 3228 | \\export fn entry2() void { | 3361 | \\export fn entry2() void { |
| 3229 | \\ var x: i65536 = 1; | 3362 | \\ var x: i65536 = 1; |
| | 3363 | \\ _ = x; |
| 3230 | \\} | 3364 | \\} |
| 3231 | , &[_][]const u8{ | 3365 | , &[_][]const u8{ |
| 3232 | "tmp.zig:5:12: error: primitive integer type 'i65536' exceeds maximum bit width of 65535", | 3366 | "tmp.zig:2:15: error: primitive integer type 'u65536' exceeds maximum bit width of 65535", |
| | 3367 | "tmp.zig:6:12: error: primitive integer type 'i65536' exceeds maximum bit width of 65535", |
| 3233 | }); | 3368 | }); |
| 3234 | | 3369 | |
| 3235 | cases.add("compile error when evaluating return type of inferred error set", | 3370 | ctx.objErrStage1("compile error when evaluating return type of inferred error set", |
| 3236 | \\const Car = struct { | 3371 | \\const Car = struct { |
| 3237 | \\ foo: *SymbolThatDoesNotExist, | 3372 | \\ foo: *SymbolThatDoesNotExist, |
| 3238 | \\ pub fn init() !Car {} | 3373 | \\ pub fn init() !Car {} |
| 3239 | \\}; | 3374 | \\}; |
| 3240 | \\export fn entry() void { | 3375 | \\export fn entry() void { |
| 3241 | \\ const car = Car.init(); | 3376 | \\ const car = Car.init(); |
| | 3377 | \\ _ = car; |
| 3242 | \\} | 3378 | \\} |
| 3243 | , &[_][]const u8{ | 3379 | , &[_][]const u8{ |
| 3244 | "tmp.zig:2:11: error: use of undeclared identifier 'SymbolThatDoesNotExist'", | 3380 | "tmp.zig:2:11: error: use of undeclared identifier 'SymbolThatDoesNotExist'", |
| 3245 | }); | 3381 | }); |
| 3246 | | 3382 | |
| 3247 | cases.add("don't implicit cast double pointer to *c_void", | 3383 | ctx.objErrStage1("don't implicit cast double pointer to *c_void", |
| 3248 | \\export fn entry() void { | 3384 | \\export fn entry() void { |
| 3249 | \\ var a: u32 = 1; | 3385 | \\ var a: u32 = 1; |
| 3250 | \\ var ptr: *align(@alignOf(u32)) c_void = &a; | 3386 | \\ var ptr: *align(@alignOf(u32)) c_void = &a; |
| 3251 | \\ var b: *u32 = @ptrCast(*u32, ptr); | 3387 | \\ var b: *u32 = @ptrCast(*u32, ptr); |
| 3252 | \\ var ptr2: *c_void = &b; | 3388 | \\ var ptr2: *c_void = &b; |
| | 3389 | \\ _ = ptr2; |
| 3253 | \\} | 3390 | \\} |
| 3254 | , &[_][]const u8{ | 3391 | , &[_][]const u8{ |
| 3255 | "tmp.zig:5:26: error: expected type '*c_void', found '**u32'", | 3392 | "tmp.zig:5:26: error: expected type '*c_void', found '**u32'", |
| 3256 | }); | 3393 | }); |
| 3257 | | 3394 | |
| 3258 | cases.add("runtime index into comptime type slice", | 3395 | ctx.objErrStage1("runtime index into comptime type slice", |
| 3259 | \\const Struct = struct { | 3396 | \\const Struct = struct { |
| 3260 | \\ a: u32, | 3397 | \\ a: u32, |
| 3261 | \\}; | 3398 | \\}; |
| ... | @@ -3265,12 +3402,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -3265,12 +3402,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3265 | \\export fn entry() void { | 3402 | \\export fn entry() void { |
| 3266 | \\ const index = getIndex(); | 3403 | \\ const index = getIndex(); |
| 3267 | \\ const field = @typeInfo(Struct).Struct.fields[index]; | 3404 | \\ const field = @typeInfo(Struct).Struct.fields[index]; |
| | 3405 | \\ _ = field; |
| 3268 | \\} | 3406 | \\} |
| 3269 | , &[_][]const u8{ | 3407 | , &[_][]const u8{ |
| 3270 | "tmp.zig:9:51: error: values of type 'std.builtin.StructField' must be comptime known, but index value is runtime known", | 3408 | "tmp.zig:9:51: error: values of type 'std.builtin.StructField' must be comptime known, but index value is runtime known", |
| 3271 | }); | 3409 | }); |
| 3272 | | 3410 | |
| 3273 | cases.add("compile log statement inside function which must be comptime evaluated", | 3411 | ctx.objErrStage1("compile log statement inside function which must be comptime evaluated", |
| 3274 | \\fn Foo(comptime T: type) type { | 3412 | \\fn Foo(comptime T: type) type { |
| 3275 | \\ @compileLog(@typeName(T)); | 3413 | \\ @compileLog(@typeName(T)); |
| 3276 | \\ return T; | 3414 | \\ return T; |
| ... | @@ -3283,25 +3421,27 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -3283,25 +3421,27 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3283 | "tmp.zig:2:5: error: found compile log statement", | 3421 | "tmp.zig:2:5: error: found compile log statement", |
| 3284 | }); | 3422 | }); |
| 3285 | | 3423 | |
| 3286 | cases.add("comptime slice of an undefined slice", | 3424 | ctx.objErrStage1("comptime slice of an undefined slice", |
| 3287 | \\comptime { | 3425 | \\comptime { |
| 3288 | \\ var a: []u8 = undefined; | 3426 | \\ var a: []u8 = undefined; |
| 3289 | \\ var b = a[0..10]; | 3427 | \\ var b = a[0..10]; |
| | 3428 | \\ _ = b; |
| 3290 | \\} | 3429 | \\} |
| 3291 | , &[_][]const u8{ | 3430 | , &[_][]const u8{ |
| 3292 | "tmp.zig:3:14: error: slice of undefined", | 3431 | "tmp.zig:3:14: error: slice of undefined", |
| 3293 | }); | 3432 | }); |
| 3294 | | 3433 | |
| 3295 | cases.add("implicit cast const array to mutable slice", | 3434 | ctx.objErrStage1("implicit cast const array to mutable slice", |
| 3296 | \\export fn entry() void { | 3435 | \\export fn entry() void { |
| 3297 | \\ const buffer: [1]u8 = [_]u8{8}; | 3436 | \\ const buffer: [1]u8 = [_]u8{8}; |
| 3298 | \\ const sliceA: []u8 = &buffer; | 3437 | \\ const sliceA: []u8 = &buffer; |
| | 3438 | \\ _ = sliceA; |
| 3299 | \\} | 3439 | \\} |
| 3300 | , &[_][]const u8{ | 3440 | , &[_][]const u8{ |
| 3301 | "tmp.zig:3:27: error: expected type '[]u8', found '*const [1]u8'", | 3441 | "tmp.zig:3:27: error: expected type '[]u8', found '*const [1]u8'", |
| 3302 | }); | 3442 | }); |
| 3303 | | 3443 | |
| 3304 | cases.add("deref slice and get len field", | 3444 | ctx.objErrStage1("deref slice and get len field", |
| 3305 | \\export fn entry() void { | 3445 | \\export fn entry() void { |
| 3306 | \\ var a: []u8 = undefined; | 3446 | \\ var a: []u8 = undefined; |
| 3307 | \\ _ = a.*.len; | 3447 | \\ _ = a.*.len; |
| ... | @@ -3310,7 +3450,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -3310,7 +3450,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3310 | "tmp.zig:3:10: error: attempt to dereference non-pointer type '[]u8'", | 3450 | "tmp.zig:3:10: error: attempt to dereference non-pointer type '[]u8'", |
| 3311 | }); | 3451 | }); |
| 3312 | | 3452 | |
| 3313 | cases.add("@ptrCast a 0 bit type to a non- 0 bit type", | 3453 | ctx.objErrStage1("@ptrCast a 0 bit type to a non- 0 bit type", |
| 3314 | \\export fn entry() bool { | 3454 | \\export fn entry() bool { |
| 3315 | \\ var x: u0 = 0; | 3455 | \\ var x: u0 = 0; |
| 3316 | \\ const p = @ptrCast(?*u0, &x); | 3456 | \\ const p = @ptrCast(?*u0, &x); |
| ... | @@ -3322,7 +3462,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -3322,7 +3462,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3322 | "tmp.zig:3:24: note: '?*u0' has in-memory bits", | 3462 | "tmp.zig:3:24: note: '?*u0' has in-memory bits", |
| 3323 | }); | 3463 | }); |
| 3324 | | 3464 | |
| 3325 | cases.add("comparing a non-optional pointer against null", | 3465 | ctx.objErrStage1("comparing a non-optional pointer against null", |
| 3326 | \\export fn entry() void { | 3466 | \\export fn entry() void { |
| 3327 | \\ var x: i32 = 1; | 3467 | \\ var x: i32 = 1; |
| 3328 | \\ _ = &x == null; | 3468 | \\ _ = &x == null; |
| ... | @@ -3331,21 +3471,23 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -3331,21 +3471,23 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3331 | "tmp.zig:3:12: error: comparison of '*i32' with null", | 3471 | "tmp.zig:3:12: error: comparison of '*i32' with null", |
| 3332 | }); | 3472 | }); |
| 3333 | | 3473 | |
| 3334 | cases.add("non error sets used in merge error sets operator", | 3474 | ctx.objErrStage1("non error sets used in merge error sets operator", |
| 3335 | \\export fn foo() void { | 3475 | \\export fn foo() void { |
| 3336 | \\ const Errors = u8 || u16; | 3476 | \\ const Errors = u8 || u16; |
| | 3477 | \\ _ = Errors; |
| 3337 | \\} | 3478 | \\} |
| 3338 | \\export fn bar() void { | 3479 | \\export fn bar() void { |
| 3339 | \\ const Errors = error{} || u16; | 3480 | \\ const Errors = error{} || u16; |
| | 3481 | \\ _ = Errors; |
| 3340 | \\} | 3482 | \\} |
| 3341 | , &[_][]const u8{ | 3483 | , &[_][]const u8{ |
| 3342 | "tmp.zig:2:20: error: expected error set type, found type 'u8'", | 3484 | "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", | 3485 | "tmp.zig:2:23: note: `||` merges error sets; `or` performs boolean OR", |
| 3344 | "tmp.zig:5:31: error: expected error set type, found type 'u16'", | 3486 | "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", | 3487 | "tmp.zig:6:28: note: `||` merges error sets; `or` performs boolean OR", |
| 3346 | }); | 3488 | }); |
| 3347 | | 3489 | |
| 3348 | cases.add("variable initialization compile error then referenced", | 3490 | ctx.objErrStage1("variable initialization compile error then referenced", |
| 3349 | \\fn Undeclared() type { | 3491 | \\fn Undeclared() type { |
| 3350 | \\ return T; | 3492 | \\ return T; |
| 3351 | \\} | 3493 | \\} |
| ... | @@ -3357,12 +3499,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -3357,12 +3499,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3357 | \\} | 3499 | \\} |
| 3358 | \\export fn entry() void { | 3500 | \\export fn entry() void { |
| 3359 | \\ const S = Gen(); | 3501 | \\ const S = Gen(); |
| | 3502 | \\ _ = S; |
| 3360 | \\} | 3503 | \\} |
| 3361 | , &[_][]const u8{ | 3504 | , &[_][]const u8{ |
| 3362 | "tmp.zig:2:12: error: use of undeclared identifier 'T'", | 3505 | "tmp.zig:2:12: error: use of undeclared identifier 'T'", |
| 3363 | }); | 3506 | }); |
| 3364 | | 3507 | |
| 3365 | cases.add("refer to the type of a generic function", | 3508 | ctx.objErrStage1("refer to the type of a generic function", |
| 3366 | \\export fn entry() void { | 3509 | \\export fn entry() void { |
| 3367 | \\ const Func = fn (type) void; | 3510 | \\ const Func = fn (type) void; |
| 3368 | \\ const f: Func = undefined; | 3511 | \\ const f: Func = undefined; |
| ... | @@ -3372,7 +3515,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -3372,7 +3515,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3372 | "tmp.zig:4:5: error: use of undefined value here causes undefined behavior", | 3515 | "tmp.zig:4:5: error: use of undefined value here causes undefined behavior", |
| 3373 | }); | 3516 | }); |
| 3374 | | 3517 | |
| 3375 | cases.add("accessing runtime parameter from outer function", | 3518 | ctx.objErrStage1("accessing runtime parameter from outer function", |
| 3376 | \\fn outer(y: u32) fn (u32) u32 { | 3519 | \\fn outer(y: u32) fn (u32) u32 { |
| 3377 | \\ const st = struct { | 3520 | \\ const st = struct { |
| 3378 | \\ fn get(z: u32) u32 { | 3521 | \\ fn get(z: u32) u32 { |
| ... | @@ -3384,6 +3527,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -3384,6 +3527,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3384 | \\export fn entry() void { | 3527 | \\export fn entry() void { |
| 3385 | \\ var func = outer(10); | 3528 | \\ var func = outer(10); |
| 3386 | \\ var x = func(3); | 3529 | \\ var x = func(3); |
| | 3530 | \\ _ = x; |
| 3387 | \\} | 3531 | \\} |
| 3388 | , &[_][]const u8{ | 3532 | , &[_][]const u8{ |
| 3389 | "tmp.zig:4:24: error: 'y' not accessible from inner function", | 3533 | "tmp.zig:4:24: error: 'y' not accessible from inner function", |
| ... | @@ -3391,69 +3535,74 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -3391,69 +3535,74 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3391 | "tmp.zig:1:10: note: declared here", | 3535 | "tmp.zig:1:10: note: declared here", |
| 3392 | }); | 3536 | }); |
| 3393 | | 3537 | |
| 3394 | cases.add("non int passed to @intToFloat", | 3538 | ctx.objErrStage1("non int passed to @intToFloat", |
| 3395 | \\export fn entry() void { | 3539 | \\export fn entry() void { |
| 3396 | \\ const x = @intToFloat(f32, 1.1); | 3540 | \\ const x = @intToFloat(f32, 1.1); |
| | 3541 | \\ _ = x; |
| 3397 | \\} | 3542 | \\} |
| 3398 | , &[_][]const u8{ | 3543 | , &[_][]const u8{ |
| 3399 | "tmp.zig:2:32: error: expected int type, found 'comptime_float'", | 3544 | "tmp.zig:2:32: error: expected int type, found 'comptime_float'", |
| 3400 | }); | 3545 | }); |
| 3401 | | 3546 | |
| 3402 | cases.add("non float passed to @floatToInt", | 3547 | ctx.objErrStage1("non float passed to @floatToInt", |
| 3403 | \\export fn entry() void { | 3548 | \\export fn entry() void { |
| 3404 | \\ const x = @floatToInt(i32, @as(i32, 54)); | 3549 | \\ const x = @floatToInt(i32, @as(i32, 54)); |
| | 3550 | \\ _ = x; |
| 3405 | \\} | 3551 | \\} |
| 3406 | , &[_][]const u8{ | 3552 | , &[_][]const u8{ |
| 3407 | "tmp.zig:2:32: error: expected float type, found 'i32'", | 3553 | "tmp.zig:2:32: error: expected float type, found 'i32'", |
| 3408 | }); | 3554 | }); |
| 3409 | | 3555 | |
| 3410 | cases.add("out of range comptime_int passed to @floatToInt", | 3556 | ctx.objErrStage1("out of range comptime_int passed to @floatToInt", |
| 3411 | \\export fn entry() void { | 3557 | \\export fn entry() void { |
| 3412 | \\ const x = @floatToInt(i8, 200); | 3558 | \\ const x = @floatToInt(i8, 200); |
| | 3559 | \\ _ = x; |
| 3413 | \\} | 3560 | \\} |
| 3414 | , &[_][]const u8{ | 3561 | , &[_][]const u8{ |
| 3415 | "tmp.zig:2:31: error: integer value 200 cannot be coerced to type 'i8'", | 3562 | "tmp.zig:2:31: error: integer value 200 cannot be coerced to type 'i8'", |
| 3416 | }); | 3563 | }); |
| 3417 | | 3564 | |
| 3418 | cases.add("load too many bytes from comptime reinterpreted pointer", | 3565 | ctx.objErrStage1("load too many bytes from comptime reinterpreted pointer", |
| 3419 | \\export fn entry() void { | 3566 | \\export fn entry() void { |
| 3420 | \\ const float: f32 = 5.99999999999994648725e-01; | 3567 | \\ const float: f32 = 5.99999999999994648725e-01; |
| 3421 | \\ const float_ptr = &float; | 3568 | \\ const float_ptr = &float; |
| 3422 | \\ const int_ptr = @ptrCast(*const i64, float_ptr); | 3569 | \\ const int_ptr = @ptrCast(*const i64, float_ptr); |
| 3423 | \\ const int_val = int_ptr.*; | 3570 | \\ const int_val = int_ptr.*; |
| | 3571 | \\ _ = int_val; |
| 3424 | \\} | 3572 | \\} |
| 3425 | , &[_][]const u8{ | 3573 | , &[_][]const u8{ |
| 3426 | "tmp.zig:5:28: error: attempt to read 8 bytes from pointer to f32 which is 4 bytes", | 3574 | "tmp.zig:5:28: error: attempt to read 8 bytes from pointer to f32 which is 4 bytes", |
| 3427 | }); | 3575 | }); |
| 3428 | | 3576 | |
| 3429 | cases.add("invalid type used in array type", | 3577 | ctx.objErrStage1("invalid type used in array type", |
| 3430 | \\const Item = struct { | 3578 | \\const Item = struct { |
| 3431 | \\ field: SomeNonexistentType, | 3579 | \\ field: SomeNonexistentType, |
| 3432 | \\}; | 3580 | \\}; |
| 3433 | \\var items: [100]Item = undefined; | 3581 | \\var items: [100]Item = undefined; |
| 3434 | \\export fn entry() void { | 3582 | \\export fn entry() void { |
| 3435 | \\ const a = items[0]; | 3583 | \\ const a = items[0]; |
| | 3584 | \\ _ = a; |
| 3436 | \\} | 3585 | \\} |
| 3437 | , &[_][]const u8{ | 3586 | , &[_][]const u8{ |
| 3438 | "tmp.zig:2:12: error: use of undeclared identifier 'SomeNonexistentType'", | 3587 | "tmp.zig:2:12: error: use of undeclared identifier 'SomeNonexistentType'", |
| 3439 | }); | 3588 | }); |
| 3440 | | 3589 | |
| 3441 | cases.add("comptime continue inside runtime catch", | 3590 | ctx.objErrStage1("comptime continue inside runtime catch", |
| 3442 | \\export fn entry(c: bool) void { | 3591 | \\export fn entry() void { |
| 3443 | \\ const ints = [_]u8{ 1, 2 }; | 3592 | \\ const ints = [_]u8{ 1, 2 }; |
| 3444 | \\ inline for (ints) |_| { | 3593 | \\ inline for (ints) |_| { |
| 3445 | \\ bad() catch |_| continue; | 3594 | \\ bad() catch continue; |
| 3446 | \\ } | 3595 | \\ } |
| 3447 | \\} | 3596 | \\} |
| 3448 | \\fn bad() !void { | 3597 | \\fn bad() !void { |
| 3449 | \\ return error.Bad; | 3598 | \\ return error.Bad; |
| 3450 | \\} | 3599 | \\} |
| 3451 | , &[_][]const u8{ | 3600 | , &[_][]const u8{ |
| 3452 | "tmp.zig:4:25: error: comptime control flow inside runtime block", | 3601 | "tmp.zig:4:21: error: comptime control flow inside runtime block", |
| 3453 | "tmp.zig:4:15: note: runtime block created here", | 3602 | "tmp.zig:4:15: note: runtime block created here", |
| 3454 | }); | 3603 | }); |
| 3455 | | 3604 | |
| 3456 | cases.add("comptime continue inside runtime switch", | 3605 | ctx.objErrStage1("comptime continue inside runtime switch", |
| 3457 | \\export fn entry() void { | 3606 | \\export fn entry() void { |
| 3458 | \\ var p: i32 = undefined; | 3607 | \\ var p: i32 = undefined; |
| 3459 | \\ comptime var q = true; | 3608 | \\ comptime var q = true; |
| ... | @@ -3470,7 +3619,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -3470,7 +3619,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3470 | "tmp.zig:5:9: note: runtime block created here", | 3619 | "tmp.zig:5:9: note: runtime block created here", |
| 3471 | }); | 3620 | }); |
| 3472 | | 3621 | |
| 3473 | cases.add("comptime continue inside runtime while error", | 3622 | ctx.objErrStage1("comptime continue inside runtime while error", |
| 3474 | \\export fn entry() void { | 3623 | \\export fn entry() void { |
| 3475 | \\ var p: anyerror!usize = undefined; | 3624 | \\ var p: anyerror!usize = undefined; |
| 3476 | \\ comptime var q = true; | 3625 | \\ comptime var q = true; |
| ... | @@ -3486,7 +3635,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -3486,7 +3635,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3486 | "tmp.zig:5:9: note: runtime block created here", | 3635 | "tmp.zig:5:9: note: runtime block created here", |
| 3487 | }); | 3636 | }); |
| 3488 | | 3637 | |
| 3489 | cases.add("comptime continue inside runtime while optional", | 3638 | ctx.objErrStage1("comptime continue inside runtime while optional", |
| 3490 | \\export fn entry() void { | 3639 | \\export fn entry() void { |
| 3491 | \\ var p: ?usize = undefined; | 3640 | \\ var p: ?usize = undefined; |
| 3492 | \\ comptime var q = true; | 3641 | \\ comptime var q = true; |
| ... | @@ -3500,7 +3649,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -3500,7 +3649,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3500 | "tmp.zig:5:9: note: runtime block created here", | 3649 | "tmp.zig:5:9: note: runtime block created here", |
| 3501 | }); | 3650 | }); |
| 3502 | | 3651 | |
| 3503 | cases.add("comptime continue inside runtime while bool", | 3652 | ctx.objErrStage1("comptime continue inside runtime while bool", |
| 3504 | \\export fn entry() void { | 3653 | \\export fn entry() void { |
| 3505 | \\ var p: usize = undefined; | 3654 | \\ var p: usize = undefined; |
| 3506 | \\ comptime var q = true; | 3655 | \\ comptime var q = true; |
| ... | @@ -3514,7 +3663,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -3514,7 +3663,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3514 | "tmp.zig:5:9: note: runtime block created here", | 3663 | "tmp.zig:5:9: note: runtime block created here", |
| 3515 | }); | 3664 | }); |
| 3516 | | 3665 | |
| 3517 | cases.add("comptime continue inside runtime if error", | 3666 | ctx.objErrStage1("comptime continue inside runtime if error", |
| 3518 | \\export fn entry() void { | 3667 | \\export fn entry() void { |
| 3519 | \\ var p: anyerror!i32 = undefined; | 3668 | \\ var p: anyerror!i32 = undefined; |
| 3520 | \\ comptime var q = true; | 3669 | \\ comptime var q = true; |
| ... | @@ -3528,7 +3677,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -3528,7 +3677,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3528 | "tmp.zig:5:9: note: runtime block created here", | 3677 | "tmp.zig:5:9: note: runtime block created here", |
| 3529 | }); | 3678 | }); |
| 3530 | | 3679 | |
| 3531 | cases.add("comptime continue inside runtime if optional", | 3680 | ctx.objErrStage1("comptime continue inside runtime if optional", |
| 3532 | \\export fn entry() void { | 3681 | \\export fn entry() void { |
| 3533 | \\ var p: ?i32 = undefined; | 3682 | \\ var p: ?i32 = undefined; |
| 3534 | \\ comptime var q = true; | 3683 | \\ comptime var q = true; |
| ... | @@ -3542,7 +3691,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -3542,7 +3691,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3542 | "tmp.zig:5:9: note: runtime block created here", | 3691 | "tmp.zig:5:9: note: runtime block created here", |
| 3543 | }); | 3692 | }); |
| 3544 | | 3693 | |
| 3545 | cases.add("comptime continue inside runtime if bool", | 3694 | ctx.objErrStage1("comptime continue inside runtime if bool", |
| 3546 | \\export fn entry() void { | 3695 | \\export fn entry() void { |
| 3547 | \\ var p: usize = undefined; | 3696 | \\ var p: usize = undefined; |
| 3548 | \\ comptime var q = true; | 3697 | \\ comptime var q = true; |
| ... | @@ -3556,22 +3705,23 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -3556,22 +3705,23 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3556 | "tmp.zig:5:9: note: runtime block created here", | 3705 | "tmp.zig:5:9: note: runtime block created here", |
| 3557 | }); | 3706 | }); |
| 3558 | | 3707 | |
| 3559 | cases.add("switch with invalid expression parameter", | 3708 | ctx.objErrStage1("switch with invalid expression parameter", |
| 3560 | \\export fn entry() void { | 3709 | \\export fn entry() void { |
| 3561 | \\ Test(i32); | 3710 | \\ Test(i32); |
| 3562 | \\} | 3711 | \\} |
| 3563 | \\fn Test(comptime T: type) void { | 3712 | \\fn Test(comptime T: type) void { |
| 3564 | \\ const x = switch (T) { | 3713 | \\ const x = switch (T) { |
| 3565 | \\ []u8 => |x| 123, | 3714 | \\ []u8 => |x| x, |
| 3566 | \\ i32 => |x| 456, | 3715 | \\ i32 => |x| x, |
| 3567 | \\ else => unreachable, | 3716 | \\ else => unreachable, |
| 3568 | \\ }; | 3717 | \\ }; |
| | 3718 | \\ _ = x; |
| 3569 | \\} | 3719 | \\} |
| 3570 | , &[_][]const u8{ | 3720 | , &[_][]const u8{ |
| 3571 | "tmp.zig:7:17: error: switch on type 'type' provides no expression parameter", | 3721 | "tmp.zig:7:17: error: switch on type 'type' provides no expression parameter", |
| 3572 | }); | 3722 | }); |
| 3573 | | 3723 | |
| 3574 | cases.add("function prototype with no body", | 3724 | ctx.objErrStage1("function prototype with no body", |
| 3575 | \\fn foo() void; | 3725 | \\fn foo() void; |
| 3576 | \\export fn entry() void { | 3726 | \\export fn entry() void { |
| 3577 | \\ foo(); | 3727 | \\ foo(); |
| ... | @@ -3580,7 +3730,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -3580,7 +3730,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3580 | "tmp.zig:1:1: error: non-extern function has no body", | 3730 | "tmp.zig:1:1: error: non-extern function has no body", |
| 3581 | }); | 3731 | }); |
| 3582 | | 3732 | |
| 3583 | cases.add("@frame() called outside of function definition", | 3733 | ctx.objErrStage1("@frame() called outside of function definition", |
| 3584 | \\var handle_undef: anyframe = undefined; | 3734 | \\var handle_undef: anyframe = undefined; |
| 3585 | \\var handle_dummy: anyframe = @frame(); | 3735 | \\var handle_dummy: anyframe = @frame(); |
| 3586 | \\export fn entry() bool { | 3736 | \\export fn entry() bool { |
| ... | @@ -3590,16 +3740,17 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -3590,16 +3740,17 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3590 | "tmp.zig:2:30: error: @frame() called outside of function definition", | 3740 | "tmp.zig:2:30: error: @frame() called outside of function definition", |
| 3591 | }); | 3741 | }); |
| 3592 | | 3742 | |
| 3593 | cases.add("`_` is not a declarable symbol", | 3743 | ctx.objErrStage1("`_` is not a declarable symbol", |
| 3594 | \\export fn f1() usize { | 3744 | \\export fn f1() usize { |
| 3595 | \\ var _: usize = 2; | 3745 | \\ var _: usize = 2; |
| 3596 | \\ return _; | 3746 | \\ return _; |
| 3597 | \\} | 3747 | \\} |
| 3598 | , &[_][]const u8{ | 3748 | , &[_][]const u8{ |
| 3599 | "tmp.zig:2:5: error: `_` is not a declarable symbol", | 3749 | "tmp.zig:2:5: error: '_' used as an identifier without @\"_\" syntax", |
| | 3750 | "tmp.zig:3:12: error: '_' used as an identifier without @\"_\" syntax", |
| 3600 | }); | 3751 | }); |
| 3601 | | 3752 | |
| 3602 | cases.add("`_` should not be usable inside for", | 3753 | ctx.objErrStage1("`_` should not be usable inside for", |
| 3603 | \\export fn returns() void { | 3754 | \\export fn returns() void { |
| 3604 | \\ for ([_]void{}) |_, i| { | 3755 | \\ for ([_]void{}) |_, i| { |
| 3605 | \\ for ([_]void{}) |_, j| { | 3756 | \\ for ([_]void{}) |_, j| { |
| ... | @@ -3608,10 +3759,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -3608,10 +3759,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3608 | \\ } | 3759 | \\ } |
| 3609 | \\} | 3760 | \\} |
| 3610 | , &[_][]const u8{ | 3761 | , &[_][]const u8{ |
| 3611 | "tmp.zig:4:20: error: `_` may only be used to assign things to", | 3762 | "tmp.zig:4:20: error: '_' used as an identifier without @\"_\" syntax", |
| 3612 | }); | 3763 | }); |
| 3613 | | 3764 | |
| 3614 | cases.add("`_` should not be usable inside while", | 3765 | ctx.objErrStage1("`_` should not be usable inside while", |
| 3615 | \\export fn returns() void { | 3766 | \\export fn returns() void { |
| 3616 | \\ while (optionalReturn()) |_| { | 3767 | \\ while (optionalReturn()) |_| { |
| 3617 | \\ while (optionalReturn()) |_| { | 3768 | \\ while (optionalReturn()) |_| { |
| ... | @@ -3623,10 +3774,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -3623,10 +3774,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3623 | \\ return 1; | 3774 | \\ return 1; |
| 3624 | \\} | 3775 | \\} |
| 3625 | , &[_][]const u8{ | 3776 | , &[_][]const u8{ |
| 3626 | "tmp.zig:4:20: error: `_` may only be used to assign things to", | 3777 | "tmp.zig:4:20: error: '_' used as an identifier without @\"_\" syntax", |
| 3627 | }); | 3778 | }); |
| 3628 | | 3779 | |
| 3629 | cases.add("`_` should not be usable inside while else", | 3780 | ctx.objErrStage1("`_` should not be usable inside while else", |
| 3630 | \\export fn returns() void { | 3781 | \\export fn returns() void { |
| 3631 | \\ while (optionalReturnError()) |_| { | 3782 | \\ while (optionalReturnError()) |_| { |
| 3632 | \\ while (optionalReturnError()) |_| { | 3783 | \\ while (optionalReturnError()) |_| { |
| ... | @@ -3640,10 +3791,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -3640,10 +3791,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3640 | \\ return error.optionalReturnError; | 3791 | \\ return error.optionalReturnError; |
| 3641 | \\} | 3792 | \\} |
| 3642 | , &[_][]const u8{ | 3793 | , &[_][]const u8{ |
| 3643 | "tmp.zig:6:17: error: `_` may only be used to assign things to", | 3794 | "tmp.zig:6:17: error: '_' used as an identifier without @\"_\" syntax", |
| 3644 | }); | 3795 | }); |
| 3645 | | 3796 | |
| 3646 | cases.add("while loop body expression ignored", | 3797 | ctx.objErrStage1("while loop body expression ignored", |
| 3647 | \\fn returns() usize { | 3798 | \\fn returns() usize { |
| 3648 | \\ return 2; | 3799 | \\ return 2; |
| 3649 | \\} | 3800 | \\} |
| ... | @@ -3664,7 +3815,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -3664,7 +3815,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3664 | "tmp.zig:13:26: error: expression value is ignored", | 3815 | "tmp.zig:13:26: error: expression value is ignored", |
| 3665 | }); | 3816 | }); |
| 3666 | | 3817 | |
| 3667 | cases.add("missing parameter name of generic function", | 3818 | ctx.objErrStage1("missing parameter name of generic function", |
| 3668 | \\fn dump(anytype) void {} | 3819 | \\fn dump(anytype) void {} |
| 3669 | \\export fn entry() void { | 3820 | \\export fn entry() void { |
| 3670 | \\ var a: u8 = 9; | 3821 | \\ var a: u8 = 9; |
| ... | @@ -3674,20 +3825,20 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -3674,20 +3825,20 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3674 | "tmp.zig:1:9: error: missing parameter name", | 3825 | "tmp.zig:1:9: error: missing parameter name", |
| 3675 | }); | 3826 | }); |
| 3676 | | 3827 | |
| 3677 | cases.add("non-inline for loop on a type that requires comptime", | 3828 | ctx.objErrStage1("non-inline for loop on a type that requires comptime", |
| 3678 | \\const Foo = struct { | 3829 | \\const Foo = struct { |
| 3679 | \\ name: []const u8, | 3830 | \\ name: []const u8, |
| 3680 | \\ T: type, | 3831 | \\ T: type, |
| 3681 | \\}; | 3832 | \\}; |
| 3682 | \\export fn entry() void { | 3833 | \\export fn entry() void { |
| 3683 | \\ const xx: [2]Foo = undefined; | 3834 | \\ const xx: [2]Foo = undefined; |
| 3684 | \\ for (xx) |f| {} | 3835 | \\ for (xx) |f| { _ = f;} |
| 3685 | \\} | 3836 | \\} |
| 3686 | , &[_][]const u8{ | 3837 | , &[_][]const u8{ |
| 3687 | "tmp.zig:7:5: error: values of type 'Foo' must be comptime known, but index value is runtime known", | 3838 | "tmp.zig:7:5: error: values of type 'Foo' must be comptime known, but index value is runtime known", |
| 3688 | }); | 3839 | }); |
| 3689 | | 3840 | |
| 3690 | cases.add("generic fn as parameter without comptime keyword", | 3841 | ctx.objErrStage1("generic fn as parameter without comptime keyword", |
| 3691 | \\fn f(_: fn (anytype) void) void {} | 3842 | \\fn f(_: fn (anytype) void) void {} |
| 3692 | \\fn g(_: anytype) void {} | 3843 | \\fn g(_: anytype) void {} |
| 3693 | \\export fn entry() void { | 3844 | \\export fn entry() void { |
| ... | @@ -3697,7 +3848,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -3697,7 +3848,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3697 | "tmp.zig:1:9: error: parameter of type 'fn(anytype) anytype' must be declared comptime", | 3848 | "tmp.zig:1:9: error: parameter of type 'fn(anytype) anytype' must be declared comptime", |
| 3698 | }); | 3849 | }); |
| 3699 | | 3850 | |
| 3700 | cases.add("optional pointer to void in extern struct", | 3851 | ctx.objErrStage1("optional pointer to void in extern struct", |
| 3701 | \\const Foo = extern struct { | 3852 | \\const Foo = extern struct { |
| 3702 | \\ x: ?*const void, | 3853 | \\ x: ?*const void, |
| 3703 | \\}; | 3854 | \\}; |
| ... | @@ -3705,12 +3856,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -3705,12 +3856,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3705 | \\ foo: Foo, | 3856 | \\ foo: Foo, |
| 3706 | \\ y: i32, | 3857 | \\ y: i32, |
| 3707 | \\}; | 3858 | \\}; |
| 3708 | \\export fn entry(bar: *Bar) void {} | 3859 | \\export fn entry(bar: *Bar) void {_ = bar;} |
| 3709 | , &[_][]const u8{ | 3860 | , &[_][]const u8{ |
| 3710 | "tmp.zig:2:5: error: extern structs cannot contain fields of type '?*const void'", | 3861 | "tmp.zig:2:5: error: extern structs cannot contain fields of type '?*const void'", |
| 3711 | }); | 3862 | }); |
| 3712 | | 3863 | |
| 3713 | cases.add("use of comptime-known undefined function value", | 3864 | ctx.objErrStage1("use of comptime-known undefined function value", |
| 3714 | \\const Cmd = struct { | 3865 | \\const Cmd = struct { |
| 3715 | \\ exec: fn () void, | 3866 | \\ exec: fn () void, |
| 3716 | \\}; | 3867 | \\}; |
| ... | @@ -3722,7 +3873,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -3722,7 +3873,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3722 | "tmp.zig:6:12: error: use of undefined value here causes undefined behavior", | 3873 | "tmp.zig:6:12: error: use of undefined value here causes undefined behavior", |
| 3723 | }); | 3874 | }); |
| 3724 | | 3875 | |
| 3725 | cases.add("use of comptime-known undefined function value", | 3876 | ctx.objErrStage1("use of comptime-known undefined function value", |
| 3726 | \\const Cmd = struct { | 3877 | \\const Cmd = struct { |
| 3727 | \\ exec: fn () void, | 3878 | \\ exec: fn () void, |
| 3728 | \\}; | 3879 | \\}; |
| ... | @@ -3734,16 +3885,17 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -3734,16 +3885,17 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3734 | "tmp.zig:6:12: error: use of undefined value here causes undefined behavior", | 3885 | "tmp.zig:6:12: error: use of undefined value here causes undefined behavior", |
| 3735 | }); | 3886 | }); |
| 3736 | | 3887 | |
| 3737 | cases.add("bad @alignCast at comptime", | 3888 | ctx.objErrStage1("bad @alignCast at comptime", |
| 3738 | \\comptime { | 3889 | \\comptime { |
| 3739 | \\ const ptr = @intToPtr(*align(1) i32, 0x1); | 3890 | \\ const ptr = @intToPtr(*align(1) i32, 0x1); |
| 3740 | \\ const aligned = @alignCast(4, ptr); | 3891 | \\ const aligned = @alignCast(4, ptr); |
| | 3892 | \\ _ = aligned; |
| 3741 | \\} | 3893 | \\} |
| 3742 | , &[_][]const u8{ | 3894 | , &[_][]const u8{ |
| 3743 | "tmp.zig:3:35: error: pointer address 0x1 is not aligned to 4 bytes", | 3895 | "tmp.zig:3:35: error: pointer address 0x1 is not aligned to 4 bytes", |
| 3744 | }); | 3896 | }); |
| 3745 | | 3897 | |
| 3746 | cases.add("@ptrToInt on *void", | 3898 | ctx.objErrStage1("@ptrToInt on *void", |
| 3747 | \\export fn entry() bool { | 3899 | \\export fn entry() bool { |
| 3748 | \\ return @ptrToInt(&{}) == @ptrToInt(&{}); | 3900 | \\ return @ptrToInt(&{}) == @ptrToInt(&{}); |
| 3749 | \\} | 3901 | \\} |
| ... | @@ -3751,7 +3903,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -3751,7 +3903,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3751 | "tmp.zig:2:23: error: pointer to size 0 type has no address", | 3903 | "tmp.zig:2:23: error: pointer to size 0 type has no address", |
| 3752 | }); | 3904 | }); |
| 3753 | | 3905 | |
| 3754 | cases.add("@popCount - non-integer", | 3906 | ctx.objErrStage1("@popCount - non-integer", |
| 3755 | \\export fn entry(x: f32) u32 { | 3907 | \\export fn entry(x: f32) u32 { |
| 3756 | \\ return @popCount(f32, x); | 3908 | \\ return @popCount(f32, x); |
| 3757 | \\} | 3909 | \\} |
| ... | @@ -3759,8 +3911,23 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -3759,8 +3911,23 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3759 | "tmp.zig:2:22: error: expected integer type, found 'f32'", | 3911 | "tmp.zig:2:22: error: expected integer type, found 'f32'", |
| 3760 | }); | 3912 | }); |
| 3761 | | 3913 | |
| 3762 | cases.addCase(x: { | 3914 | { |
| 3763 | const tc = cases.create("wrong same named struct", | 3915 | const case = ctx.obj("wrong same named struct", .{}); |
| | 3916 | case.backend = .stage1; |
| | 3917 | |
| | 3918 | case.addSourceFile("a.zig", |
| | 3919 | \\pub const Foo = struct { |
| | 3920 | \\ x: i32, |
| | 3921 | \\}; |
| | 3922 | ); |
| | 3923 | |
| | 3924 | case.addSourceFile("b.zig", |
| | 3925 | \\pub const Foo = struct { |
| | 3926 | \\ z: f64, |
| | 3927 | \\}; |
| | 3928 | ); |
| | 3929 | |
| | 3930 | case.addError( |
| 3764 | \\const a = @import("a.zig"); | 3931 | \\const a = @import("a.zig"); |
| 3765 | \\const b = @import("b.zig"); | 3932 | \\const b = @import("b.zig"); |
| 3766 | \\ | 3933 | \\ |
| ... | @@ -3769,30 +3936,16 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -3769,30 +3936,16 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3769 | \\ bar(&a1); | 3936 | \\ bar(&a1); |
| 3770 | \\} | 3937 | \\} |
| 3771 | \\ | 3938 | \\ |
| 3772 | \\fn bar(x: *b.Foo) void {} | 3939 | \\fn bar(x: *b.Foo) void {_ = x;} |
| 3773 | , &[_][]const u8{ | 3940 | , &[_][]const u8{ |
| 3774 | "tmp.zig:6:10: error: expected type '*b.Foo', found '*a.Foo'", | 3941 | "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'", | 3942 | "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", | 3943 | "a.zig:1:17: note: a.Foo declared here", |
| 3777 | "b.zig:1:17: note: b.Foo declared here", | 3944 | "b.zig:1:17: note: b.Foo declared here", |
| 3778 | }); | 3945 | }); |
| | 3946 | } |
| 3779 | | 3947 | |
| 3780 | tc.addSourceFile("a.zig", | 3948 | 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 { | 3949 | \\comptime { |
| 3797 | \\ _ = @floatToInt(i8, @as(f32, -129.1)); | 3950 | \\ _ = @floatToInt(i8, @as(f32, -129.1)); |
| 3798 | \\} | 3951 | \\} |
| ... | @@ -3808,35 +3961,38 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -3808,35 +3961,38 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3808 | "tmp.zig:8:9: error: integer value '256' cannot be stored in type 'u8'", | 3961 | "tmp.zig:8:9: error: integer value '256' cannot be stored in type 'u8'", |
| 3809 | }); | 3962 | }); |
| 3810 | | 3963 | |
| 3811 | cases.add("use c_void as return type of fn ptr", | 3964 | ctx.objErrStage1("use c_void as return type of fn ptr", |
| 3812 | \\export fn entry() void { | 3965 | \\export fn entry() void { |
| 3813 | \\ const a: fn () c_void = undefined; | 3966 | \\ const a: fn () c_void = undefined; |
| | 3967 | \\ _ = a; |
| 3814 | \\} | 3968 | \\} |
| 3815 | , &[_][]const u8{ | 3969 | , &[_][]const u8{ |
| 3816 | "tmp.zig:2:20: error: return type cannot be opaque", | 3970 | "tmp.zig:2:20: error: return type cannot be opaque", |
| 3817 | }); | 3971 | }); |
| 3818 | | 3972 | |
| 3819 | cases.add("use implicit casts to assign null to non-nullable pointer", | 3973 | ctx.objErrStage1("use implicit casts to assign null to non-nullable pointer", |
| 3820 | \\export fn entry() void { | 3974 | \\export fn entry() void { |
| 3821 | \\ var x: i32 = 1234; | 3975 | \\ var x: i32 = 1234; |
| 3822 | \\ var p: *i32 = &x; | 3976 | \\ var p: *i32 = &x; |
| 3823 | \\ var pp: *?*i32 = &p; | 3977 | \\ var pp: *?*i32 = &p; |
| 3824 | \\ pp.* = null; | 3978 | \\ pp.* = null; |
| 3825 | \\ var y = p.*; | 3979 | \\ var y = p.*; |
| | 3980 | \\ _ = y; |
| 3826 | \\} | 3981 | \\} |
| 3827 | , &[_][]const u8{ | 3982 | , &[_][]const u8{ |
| 3828 | "tmp.zig:4:23: error: expected type '*?*i32', found '**i32'", | 3983 | "tmp.zig:4:23: error: expected type '*?*i32', found '**i32'", |
| 3829 | }); | 3984 | }); |
| 3830 | | 3985 | |
| 3831 | cases.add("attempted implicit cast from T to [*]const T", | 3986 | ctx.objErrStage1("attempted implicit cast from T to [*]const T", |
| 3832 | \\export fn entry() void { | 3987 | \\export fn entry() void { |
| 3833 | \\ const x: [*]const bool = true; | 3988 | \\ const x: [*]const bool = true; |
| | 3989 | \\ _ = x; |
| 3834 | \\} | 3990 | \\} |
| 3835 | , &[_][]const u8{ | 3991 | , &[_][]const u8{ |
| 3836 | "tmp.zig:2:30: error: expected type '[*]const bool', found 'bool'", | 3992 | "tmp.zig:2:30: error: expected type '[*]const bool', found 'bool'", |
| 3837 | }); | 3993 | }); |
| 3838 | | 3994 | |
| 3839 | cases.add("dereference unknown length pointer", | 3995 | ctx.objErrStage1("dereference unknown length pointer", |
| 3840 | \\export fn entry(x: [*]i32) i32 { | 3996 | \\export fn entry(x: [*]i32) i32 { |
| 3841 | \\ return x.*; | 3997 | \\ return x.*; |
| 3842 | \\} | 3998 | \\} |
| ... | @@ -3844,7 +4000,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -3844,7 +4000,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3844 | "tmp.zig:2:13: error: index syntax required for unknown-length pointer type '[*]i32'", | 4000 | "tmp.zig:2:13: error: index syntax required for unknown-length pointer type '[*]i32'", |
| 3845 | }); | 4001 | }); |
| 3846 | | 4002 | |
| 3847 | cases.add("field access of unknown length pointer", | 4003 | ctx.objErrStage1("field access of unknown length pointer", |
| 3848 | \\const Foo = extern struct { | 4004 | \\const Foo = extern struct { |
| 3849 | \\ a: i32, | 4005 | \\ a: i32, |
| 3850 | \\}; | 4006 | \\}; |
| ... | @@ -3856,13 +4012,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -3856,13 +4012,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3856 | "tmp.zig:6:8: error: type '[*]Foo' does not support field access", | 4012 | "tmp.zig:6:8: error: type '[*]Foo' does not support field access", |
| 3857 | }); | 4013 | }); |
| 3858 | | 4014 | |
| 3859 | cases.add("unknown length pointer to opaque", | 4015 | ctx.objErrStage1("unknown length pointer to opaque", |
| 3860 | \\export const T = [*]opaque {}; | 4016 | \\export const T = [*]opaque {}; |
| 3861 | , &[_][]const u8{ | 4017 | , &[_][]const u8{ |
| 3862 | "tmp.zig:1:21: error: unknown-length pointer to opaque", | 4018 | "tmp.zig:1:21: error: unknown-length pointer to opaque", |
| 3863 | }); | 4019 | }); |
| 3864 | | 4020 | |
| 3865 | cases.add("error when evaluating return type", | 4021 | ctx.objErrStage1("error when evaluating return type", |
| 3866 | \\const Foo = struct { | 4022 | \\const Foo = struct { |
| 3867 | \\ map: @as(i32, i32), | 4023 | \\ map: @as(i32, i32), |
| 3868 | \\ | 4024 | \\ |
| ... | @@ -3872,20 +4028,22 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -3872,20 +4028,22 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3872 | \\}; | 4028 | \\}; |
| 3873 | \\export fn entry() void { | 4029 | \\export fn entry() void { |
| 3874 | \\ var rule_set = try Foo.init(); | 4030 | \\ var rule_set = try Foo.init(); |
| | 4031 | \\ _ = rule_set; |
| 3875 | \\} | 4032 | \\} |
| 3876 | , &[_][]const u8{ | 4033 | , &[_][]const u8{ |
| 3877 | "tmp.zig:2:19: error: expected type 'i32', found 'type'", | 4034 | "tmp.zig:2:19: error: expected type 'i32', found 'type'", |
| 3878 | }); | 4035 | }); |
| 3879 | | 4036 | |
| 3880 | cases.add("slicing single-item pointer", | 4037 | ctx.objErrStage1("slicing single-item pointer", |
| 3881 | \\export fn entry(ptr: *i32) void { | 4038 | \\export fn entry(ptr: *i32) void { |
| 3882 | \\ const slice = ptr[0..2]; | 4039 | \\ const slice = ptr[0..2]; |
| | 4040 | \\ _ = slice; |
| 3883 | \\} | 4041 | \\} |
| 3884 | , &[_][]const u8{ | 4042 | , &[_][]const u8{ |
| 3885 | "tmp.zig:2:22: error: slice of single-item pointer", | 4043 | "tmp.zig:2:22: error: slice of single-item pointer", |
| 3886 | }); | 4044 | }); |
| 3887 | | 4045 | |
| 3888 | cases.add("indexing single-item pointer", | 4046 | ctx.objErrStage1("indexing single-item pointer", |
| 3889 | \\export fn entry(ptr: *i32) i32 { | 4047 | \\export fn entry(ptr: *i32) i32 { |
| 3890 | \\ return ptr[1]; | 4048 | \\ return ptr[1]; |
| 3891 | \\} | 4049 | \\} |
| ... | @@ -3893,12 +4051,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -3893,12 +4051,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3893 | "tmp.zig:2:15: error: index of single-item pointer", | 4051 | "tmp.zig:2:15: error: index of single-item pointer", |
| 3894 | }); | 4052 | }); |
| 3895 | | 4053 | |
| 3896 | cases.add("nested error set mismatch", | 4054 | ctx.objErrStage1("nested error set mismatch", |
| 3897 | \\const NextError = error{NextError}; | 4055 | \\const NextError = error{NextError}; |
| 3898 | \\const OtherError = error{OutOfMemory}; | 4056 | \\const OtherError = error{OutOfMemory}; |
| 3899 | \\ | 4057 | \\ |
| 3900 | \\export fn entry() void { | 4058 | \\export fn entry() void { |
| 3901 | \\ const a: ?NextError!i32 = foo(); | 4059 | \\ const a: ?NextError!i32 = foo(); |
| | 4060 | \\ _ = a; |
| 3902 | \\} | 4061 | \\} |
| 3903 | \\ | 4062 | \\ |
| 3904 | \\fn foo() ?OtherError!i32 { | 4063 | \\fn foo() ?OtherError!i32 { |
| ... | @@ -3911,7 +4070,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -3911,7 +4070,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3911 | "tmp.zig:2:26: note: 'error.OutOfMemory' not a member of destination error set", | 4070 | "tmp.zig:2:26: note: 'error.OutOfMemory' not a member of destination error set", |
| 3912 | }); | 4071 | }); |
| 3913 | | 4072 | |
| 3914 | cases.add("invalid deref on switch target", | 4073 | ctx.objErrStage1("invalid deref on switch target", |
| 3915 | \\comptime { | 4074 | \\comptime { |
| 3916 | \\ var tile = Tile.Empty; | 4075 | \\ var tile = Tile.Empty; |
| 3917 | \\ switch (tile.*) { | 4076 | \\ switch (tile.*) { |
| ... | @@ -3927,13 +4086,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -3927,13 +4086,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3927 | "tmp.zig:3:17: error: attempt to dereference non-pointer type 'Tile'", | 4086 | "tmp.zig:3:17: error: attempt to dereference non-pointer type 'Tile'", |
| 3928 | }); | 4087 | }); |
| 3929 | | 4088 | |
| 3930 | cases.add("invalid field access in comptime", | 4089 | ctx.objErrStage1("invalid field access in comptime", |
| 3931 | \\comptime { var x = doesnt_exist.whatever; } | 4090 | \\comptime { var x = doesnt_exist.whatever; _ = x; } |
| 3932 | , &[_][]const u8{ | 4091 | , &[_][]const u8{ |
| 3933 | "tmp.zig:1:20: error: use of undeclared identifier 'doesnt_exist'", | 4092 | "tmp.zig:1:20: error: use of undeclared identifier 'doesnt_exist'", |
| 3934 | }); | 4093 | }); |
| 3935 | | 4094 | |
| 3936 | cases.add("suspend inside suspend block", | 4095 | ctx.objErrStage1("suspend inside suspend block", |
| 3937 | \\export fn entry() void { | 4096 | \\export fn entry() void { |
| 3938 | \\ _ = async foo(); | 4097 | \\ _ = async foo(); |
| 3939 | \\} | 4098 | \\} |
| ... | @@ -3948,17 +4107,18 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -3948,17 +4107,18 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3948 | "tmp.zig:5:5: note: other suspend block here", | 4107 | "tmp.zig:5:5: note: other suspend block here", |
| 3949 | }); | 4108 | }); |
| 3950 | | 4109 | |
| 3951 | cases.add("assign inline fn to non-comptime var", | 4110 | ctx.objErrStage1("assign inline fn to non-comptime var", |
| 3952 | \\export fn entry() void { | 4111 | \\export fn entry() void { |
| 3953 | \\ var a = b; | 4112 | \\ var a = b; |
| | 4113 | \\ _ = a; |
| 3954 | \\} | 4114 | \\} |
| 3955 | \\fn b() callconv(.Inline) void { } | 4115 | \\fn b() callconv(.Inline) void { } |
| 3956 | , &[_][]const u8{ | 4116 | , &[_][]const u8{ |
| 3957 | "tmp.zig:2:5: error: functions marked inline must be stored in const or comptime var", | 4117 | "tmp.zig:2:5: error: functions marked inline must be stored in const or comptime var", |
| 3958 | "tmp.zig:4:1: note: declared here", | 4118 | "tmp.zig:5:1: note: declared here", |
| 3959 | }); | 4119 | }); |
| 3960 | | 4120 | |
| 3961 | cases.add("wrong type passed to @panic", | 4121 | ctx.objErrStage1("wrong type passed to @panic", |
| 3962 | \\export fn entry() void { | 4122 | \\export fn entry() void { |
| 3963 | \\ var e = error.Foo; | 4123 | \\ var e = error.Foo; |
| 3964 | \\ @panic(e); | 4124 | \\ @panic(e); |
| ... | @@ -3967,7 +4127,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -3967,7 +4127,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3967 | "tmp.zig:3:12: error: expected type '[]const u8', found 'error{Foo}'", | 4127 | "tmp.zig:3:12: error: expected type '[]const u8', found 'error{Foo}'", |
| 3968 | }); | 4128 | }); |
| 3969 | | 4129 | |
| 3970 | cases.add("@tagName used on union with no associated enum tag", | 4130 | ctx.objErrStage1("@tagName used on union with no associated enum tag", |
| 3971 | \\const FloatInt = extern union { | 4131 | \\const FloatInt = extern union { |
| 3972 | \\ Float: f32, | 4132 | \\ Float: f32, |
| 3973 | \\ Int: i32, | 4133 | \\ Int: i32, |
| ... | @@ -3975,13 +4135,14 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -3975,13 +4135,14 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3975 | \\export fn entry() void { | 4135 | \\export fn entry() void { |
| 3976 | \\ var fi = FloatInt{.Float = 123.45}; | 4136 | \\ var fi = FloatInt{.Float = 123.45}; |
| 3977 | \\ var tagName = @tagName(fi); | 4137 | \\ var tagName = @tagName(fi); |
| | 4138 | \\ _ = tagName; |
| 3978 | \\} | 4139 | \\} |
| 3979 | , &[_][]const u8{ | 4140 | , &[_][]const u8{ |
| 3980 | "tmp.zig:7:19: error: union has no associated enum", | 4141 | "tmp.zig:7:19: error: union has no associated enum", |
| 3981 | "tmp.zig:1:18: note: declared here", | 4142 | "tmp.zig:1:18: note: declared here", |
| 3982 | }); | 4143 | }); |
| 3983 | | 4144 | |
| 3984 | cases.add("returning error from void async function", | 4145 | ctx.objErrStage1("returning error from void async function", |
| 3985 | \\export fn entry() void { | 4146 | \\export fn entry() void { |
| 3986 | \\ _ = async amain(); | 4147 | \\ _ = async amain(); |
| 3987 | \\} | 4148 | \\} |
| ... | @@ -3992,37 +4153,40 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -3992,37 +4153,40 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3992 | "tmp.zig:5:17: error: expected type 'void', found 'error{ShouldBeCompileError}'", | 4153 | "tmp.zig:5:17: error: expected type 'void', found 'error{ShouldBeCompileError}'", |
| 3993 | }); | 4154 | }); |
| 3994 | | 4155 | |
| 3995 | cases.add("var makes structs required to be comptime known", | 4156 | ctx.objErrStage1("var makes structs required to be comptime known", |
| 3996 | \\export fn entry() void { | 4157 | \\export fn entry() void { |
| 3997 | \\ const S = struct{v: anytype}; | 4158 | \\ const S = struct{v: anytype}; |
| 3998 | \\ var s = S{.v=@as(i32, 10)}; | 4159 | \\ var s = S{.v=@as(i32, 10)}; |
| | 4160 | \\ _ = s; |
| 3999 | \\} | 4161 | \\} |
| 4000 | , &[_][]const u8{ | 4162 | , &[_][]const u8{ |
| 4001 | "tmp.zig:3:4: error: variable of type 'S' must be const or comptime", | 4163 | "tmp.zig:3:4: error: variable of type 'S' must be const or comptime", |
| 4002 | }); | 4164 | }); |
| 4003 | | 4165 | |
| 4004 | cases.add("@ptrCast discards const qualifier", | 4166 | ctx.objErrStage1("@ptrCast discards const qualifier", |
| 4005 | \\export fn entry() void { | 4167 | \\export fn entry() void { |
| 4006 | \\ const x: i32 = 1234; | 4168 | \\ const x: i32 = 1234; |
| 4007 | \\ const y = @ptrCast(*i32, &x); | 4169 | \\ const y = @ptrCast(*i32, &x); |
| | 4170 | \\ _ = y; |
| 4008 | \\} | 4171 | \\} |
| 4009 | , &[_][]const u8{ | 4172 | , &[_][]const u8{ |
| 4010 | "tmp.zig:3:15: error: cast discards const qualifier", | 4173 | "tmp.zig:3:15: error: cast discards const qualifier", |
| 4011 | }); | 4174 | }); |
| 4012 | | 4175 | |
| 4013 | cases.add("comptime slice of undefined pointer non-zero len", | 4176 | ctx.objErrStage1("comptime slice of undefined pointer non-zero len", |
| 4014 | \\export fn entry() void { | 4177 | \\export fn entry() void { |
| 4015 | \\ const slice = @as([*]i32, undefined)[0..1]; | 4178 | \\ const slice = @as([*]i32, undefined)[0..1]; |
| | 4179 | \\ _ = slice; |
| 4016 | \\} | 4180 | \\} |
| 4017 | , &[_][]const u8{ | 4181 | , &[_][]const u8{ |
| 4018 | "tmp.zig:2:41: error: non-zero length slice of undefined pointer", | 4182 | "tmp.zig:2:41: error: non-zero length slice of undefined pointer", |
| 4019 | }); | 4183 | }); |
| 4020 | | 4184 | |
| 4021 | cases.add("type checking function pointers", | 4185 | ctx.objErrStage1("type checking function pointers", |
| 4022 | \\fn a(b: fn (*const u8) void) void { | 4186 | \\fn a(b: fn (*const u8) void) void { |
| 4023 | \\ b('a'); | 4187 | \\ b('a'); |
| 4024 | \\} | 4188 | \\} |
| 4025 | \\fn c(d: u8) void {} | 4189 | \\fn c(d: u8) void {_ = d;} |
| 4026 | \\export fn entry() void { | 4190 | \\export fn entry() void { |
| 4027 | \\ a(c); | 4191 | \\ a(c); |
| 4028 | \\} | 4192 | \\} |
| ... | @@ -4030,7 +4194,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -4030,7 +4194,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4030 | "tmp.zig:6:7: error: expected type 'fn(*const u8) void', found 'fn(u8) void'", | 4194 | "tmp.zig:6:7: error: expected type 'fn(*const u8) void', found 'fn(u8) void'", |
| 4031 | }); | 4195 | }); |
| 4032 | | 4196 | |
| 4033 | cases.add("no else prong on switch on global error set", | 4197 | ctx.objErrStage1("no else prong on switch on global error set", |
| 4034 | \\export fn entry() void { | 4198 | \\export fn entry() void { |
| 4035 | \\ foo(error.A); | 4199 | \\ foo(error.A); |
| 4036 | \\} | 4200 | \\} |
| ... | @@ -4043,7 +4207,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -4043,7 +4207,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4043 | "tmp.zig:5:5: error: else prong required when switching on type 'anyerror'", | 4207 | "tmp.zig:5:5: error: else prong required when switching on type 'anyerror'", |
| 4044 | }); | 4208 | }); |
| 4045 | | 4209 | |
| 4046 | cases.add("error not handled in switch", | 4210 | ctx.objErrStage1("error not handled in switch", |
| 4047 | \\export fn entry() void { | 4211 | \\export fn entry() void { |
| 4048 | \\ foo(452) catch |err| switch (err) { | 4212 | \\ foo(452) catch |err| switch (err) { |
| 4049 | \\ error.Foo => {}, | 4213 | \\ error.Foo => {}, |
| ... | @@ -4062,7 +4226,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -4062,7 +4226,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4062 | "tmp.zig:2:26: error: error.Bar not handled in switch", | 4226 | "tmp.zig:2:26: error: error.Bar not handled in switch", |
| 4063 | }); | 4227 | }); |
| 4064 | | 4228 | |
| 4065 | cases.add("duplicate error in switch", | 4229 | ctx.objErrStage1("duplicate error in switch", |
| 4066 | \\export fn entry() void { | 4230 | \\export fn entry() void { |
| 4067 | \\ foo(452) catch |err| switch (err) { | 4231 | \\ foo(452) catch |err| switch (err) { |
| 4068 | \\ error.Foo => {}, | 4232 | \\ error.Foo => {}, |
| ... | @@ -4083,7 +4247,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -4083,7 +4247,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4083 | "tmp.zig:3:14: note: other value is here", | 4247 | "tmp.zig:3:14: note: other value is here", |
| 4084 | }); | 4248 | }); |
| 4085 | | 4249 | |
| 4086 | cases.add("invalid cast from integral type to enum", | 4250 | ctx.objErrStage1("invalid cast from integral type to enum", |
| 4087 | \\const E = enum(usize) { One, Two }; | 4251 | \\const E = enum(usize) { One, Two }; |
| 4088 | \\ | 4252 | \\ |
| 4089 | \\export fn entry() void { | 4253 | \\export fn entry() void { |
| ... | @@ -4099,7 +4263,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -4099,7 +4263,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4099 | "tmp.zig:9:10: error: expected type 'usize', found 'E'", | 4263 | "tmp.zig:9:10: error: expected type 'usize', found 'E'", |
| 4100 | }); | 4264 | }); |
| 4101 | | 4265 | |
| 4102 | cases.add("range operator in switch used on error set", | 4266 | ctx.objErrStage1("range operator in switch used on error set", |
| 4103 | \\export fn entry() void { | 4267 | \\export fn entry() void { |
| 4104 | \\ try foo(452) catch |err| switch (err) { | 4268 | \\ try foo(452) catch |err| switch (err) { |
| 4105 | \\ error.A ... error.B => {}, | 4269 | \\ error.A ... error.B => {}, |
| ... | @@ -4117,33 +4281,35 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -4117,33 +4281,35 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4117 | "tmp.zig:3:17: error: operator not allowed for errors", | 4281 | "tmp.zig:3:17: error: operator not allowed for errors", |
| 4118 | }); | 4282 | }); |
| 4119 | | 4283 | |
| 4120 | cases.add("inferring error set of function pointer", | 4284 | ctx.objErrStage1("inferring error set of function pointer", |
| 4121 | \\comptime { | 4285 | \\comptime { |
| 4122 | \\ const z: ?fn()!void = null; | 4286 | \\ const z: ?fn()!void = null; |
| 4123 | \\} | 4287 | \\} |
| 4124 | , &[_][]const u8{ | 4288 | , &[_][]const u8{ |
| 4125 | "tmp.zig:2:15: error: inferring error set of return type valid only for function definitions", | 4289 | "tmp.zig:2:19: error: function prototype may not have inferred error set", |
| 4126 | }); | 4290 | }); |
| 4127 | | 4291 | |
| 4128 | cases.add("access non-existent member of error set", | 4292 | ctx.objErrStage1("access non-existent member of error set", |
| 4129 | \\const Foo = error{A}; | 4293 | \\const Foo = error{A}; |
| 4130 | \\comptime { | 4294 | \\comptime { |
| 4131 | \\ const z = Foo.Bar; | 4295 | \\ const z = Foo.Bar; |
| | 4296 | \\ _ = z; |
| 4132 | \\} | 4297 | \\} |
| 4133 | , &[_][]const u8{ | 4298 | , &[_][]const u8{ |
| 4134 | "tmp.zig:3:18: error: no error named 'Bar' in 'Foo'", | 4299 | "tmp.zig:3:18: error: no error named 'Bar' in 'Foo'", |
| 4135 | }); | 4300 | }); |
| 4136 | | 4301 | |
| 4137 | cases.add("error union operator with non error set LHS", | 4302 | ctx.objErrStage1("error union operator with non error set LHS", |
| 4138 | \\comptime { | 4303 | \\comptime { |
| 4139 | \\ const z = i32!i32; | 4304 | \\ const z = i32!i32; |
| 4140 | \\ var x: z = undefined; | 4305 | \\ var x: z = undefined; |
| | 4306 | \\ _ = x; |
| 4141 | \\} | 4307 | \\} |
| 4142 | , &[_][]const u8{ | 4308 | , &[_][]const u8{ |
| 4143 | "tmp.zig:2:15: error: expected error set type, found type 'i32'", | 4309 | "tmp.zig:2:15: error: expected error set type, found type 'i32'", |
| 4144 | }); | 4310 | }); |
| 4145 | | 4311 | |
| 4146 | cases.add("error equality but sets have no common members", | 4312 | ctx.objErrStage1("error equality but sets have no common members", |
| 4147 | \\const Set1 = error{A, C}; | 4313 | \\const Set1 = error{A, C}; |
| 4148 | \\const Set2 = error{B, D}; | 4314 | \\const Set2 = error{B, D}; |
| 4149 | \\export fn entry() void { | 4315 | \\export fn entry() void { |
| ... | @@ -4158,29 +4324,32 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -4158,29 +4324,32 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4158 | "tmp.zig:7:11: error: error sets 'Set1' and 'Set2' have no common errors", | 4324 | "tmp.zig:7:11: error: error sets 'Set1' and 'Set2' have no common errors", |
| 4159 | }); | 4325 | }); |
| 4160 | | 4326 | |
| 4161 | cases.add("only equality binary operator allowed for error sets", | 4327 | ctx.objErrStage1("only equality binary operator allowed for error sets", |
| 4162 | \\comptime { | 4328 | \\comptime { |
| 4163 | \\ const z = error.A > error.B; | 4329 | \\ const z = error.A > error.B; |
| | 4330 | \\ _ = z; |
| 4164 | \\} | 4331 | \\} |
| 4165 | , &[_][]const u8{ | 4332 | , &[_][]const u8{ |
| 4166 | "tmp.zig:2:23: error: operator not allowed for errors", | 4333 | "tmp.zig:2:23: error: operator not allowed for errors", |
| 4167 | }); | 4334 | }); |
| 4168 | | 4335 | |
| 4169 | cases.add("explicit error set cast known at comptime violates error sets", | 4336 | ctx.objErrStage1("explicit error set cast known at comptime violates error sets", |
| 4170 | \\const Set1 = error {A, B}; | 4337 | \\const Set1 = error {A, B}; |
| 4171 | \\const Set2 = error {A, C}; | 4338 | \\const Set2 = error {A, C}; |
| 4172 | \\comptime { | 4339 | \\comptime { |
| 4173 | \\ var x = Set1.B; | 4340 | \\ var x = Set1.B; |
| 4174 | \\ var y = @errSetCast(Set2, x); | 4341 | \\ var y = @errSetCast(Set2, x); |
| | 4342 | \\ _ = y; |
| 4175 | \\} | 4343 | \\} |
| 4176 | , &[_][]const u8{ | 4344 | , &[_][]const u8{ |
| 4177 | "tmp.zig:5:13: error: error.B not a member of error set 'Set2'", | 4345 | "tmp.zig:5:13: error: error.B not a member of error set 'Set2'", |
| 4178 | }); | 4346 | }); |
| 4179 | | 4347 | |
| 4180 | cases.add("cast error union of global error set to error union of smaller error set", | 4348 | ctx.objErrStage1("cast error union of global error set to error union of smaller error set", |
| 4181 | \\const SmallErrorSet = error{A}; | 4349 | \\const SmallErrorSet = error{A}; |
| 4182 | \\export fn entry() void { | 4350 | \\export fn entry() void { |
| 4183 | \\ var x: SmallErrorSet!i32 = foo(); | 4351 | \\ var x: SmallErrorSet!i32 = foo(); |
| | 4352 | \\ _ = x; |
| 4184 | \\} | 4353 | \\} |
| 4185 | \\fn foo() anyerror!i32 { | 4354 | \\fn foo() anyerror!i32 { |
| 4186 | \\ return error.B; | 4355 | \\ return error.B; |
| ... | @@ -4191,10 +4360,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -4191,10 +4360,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4191 | "tmp.zig:3:35: note: cannot cast global error set into smaller set", | 4360 | "tmp.zig:3:35: note: cannot cast global error set into smaller set", |
| 4192 | }); | 4361 | }); |
| 4193 | | 4362 | |
| 4194 | cases.add("cast global error set to error set", | 4363 | ctx.objErrStage1("cast global error set to error set", |
| 4195 | \\const SmallErrorSet = error{A}; | 4364 | \\const SmallErrorSet = error{A}; |
| 4196 | \\export fn entry() void { | 4365 | \\export fn entry() void { |
| 4197 | \\ var x: SmallErrorSet = foo(); | 4366 | \\ var x: SmallErrorSet = foo(); |
| | 4367 | \\ _ = x; |
| 4198 | \\} | 4368 | \\} |
| 4199 | \\fn foo() anyerror { | 4369 | \\fn foo() anyerror { |
| 4200 | \\ return error.B; | 4370 | \\ return error.B; |
| ... | @@ -4203,7 +4373,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -4203,7 +4373,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4203 | "tmp.zig:3:31: error: expected type 'SmallErrorSet', found 'anyerror'", | 4373 | "tmp.zig:3:31: error: expected type 'SmallErrorSet', found 'anyerror'", |
| 4204 | "tmp.zig:3:31: note: cannot cast global error set into smaller set", | 4374 | "tmp.zig:3:31: note: cannot cast global error set into smaller set", |
| 4205 | }); | 4375 | }); |
| 4206 | cases.add("recursive inferred error set", | 4376 | ctx.objErrStage1("recursive inferred error set", |
| 4207 | \\export fn entry() void { | 4377 | \\export fn entry() void { |
| 4208 | \\ foo() catch unreachable; | 4378 | \\ foo() catch unreachable; |
| 4209 | \\} | 4379 | \\} |
| ... | @@ -4214,7 +4384,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -4214,7 +4384,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", | 4384 | "tmp.zig:5:5: error: cannot resolve inferred error set '@typeInfo(@typeInfo(@TypeOf(foo)).Fn.return_type.?).ErrorUnion.error_set': function 'foo' not fully analyzed yet", |
| 4215 | }); | 4385 | }); |
| 4216 | | 4386 | |
| 4217 | cases.add("implicit cast of error set not a subset", | 4387 | ctx.objErrStage1("implicit cast of error set not a subset", |
| 4218 | \\const Set1 = error{A, B}; | 4388 | \\const Set1 = error{A, B}; |
| 4219 | \\const Set2 = error{A, C}; | 4389 | \\const Set2 = error{A, C}; |
| 4220 | \\export fn entry() void { | 4390 | \\export fn entry() void { |
| ... | @@ -4222,13 +4392,14 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -4222,13 +4392,14 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4222 | \\} | 4392 | \\} |
| 4223 | \\fn foo(set1: Set1) void { | 4393 | \\fn foo(set1: Set1) void { |
| 4224 | \\ var x: Set2 = set1; | 4394 | \\ var x: Set2 = set1; |
| | 4395 | \\ _ = x; |
| 4225 | \\} | 4396 | \\} |
| 4226 | , &[_][]const u8{ | 4397 | , &[_][]const u8{ |
| 4227 | "tmp.zig:7:19: error: expected type 'Set2', found 'Set1'", | 4398 | "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", | 4399 | "tmp.zig:1:23: note: 'error.B' not a member of destination error set", |
| 4229 | }); | 4400 | }); |
| 4230 | | 4401 | |
| 4231 | cases.add("int to err global invalid number", | 4402 | ctx.objErrStage1("int to err global invalid number", |
| 4232 | \\const Set1 = error{ | 4403 | \\const Set1 = error{ |
| 4233 | \\ A, | 4404 | \\ A, |
| 4234 | \\ B, | 4405 | \\ B, |
| ... | @@ -4236,12 +4407,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -4236,12 +4407,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4236 | \\comptime { | 4407 | \\comptime { |
| 4237 | \\ var x: u16 = 3; | 4408 | \\ var x: u16 = 3; |
| 4238 | \\ var y = @intToError(x); | 4409 | \\ var y = @intToError(x); |
| | 4410 | \\ _ = y; |
| 4239 | \\} | 4411 | \\} |
| 4240 | , &[_][]const u8{ | 4412 | , &[_][]const u8{ |
| 4241 | "tmp.zig:7:13: error: integer value 3 represents no error", | 4413 | "tmp.zig:7:13: error: integer value 3 represents no error", |
| 4242 | }); | 4414 | }); |
| 4243 | | 4415 | |
| 4244 | cases.add("int to err non global invalid number", | 4416 | ctx.objErrStage1("int to err non global invalid number", |
| 4245 | \\const Set1 = error{ | 4417 | \\const Set1 = error{ |
| 4246 | \\ A, | 4418 | \\ A, |
| 4247 | \\ B, | 4419 | \\ B, |
| ... | @@ -4253,68 +4425,74 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -4253,68 +4425,74 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4253 | \\comptime { | 4425 | \\comptime { |
| 4254 | \\ var x = @errorToInt(Set1.B); | 4426 | \\ var x = @errorToInt(Set1.B); |
| 4255 | \\ var y = @errSetCast(Set2, @intToError(x)); | 4427 | \\ var y = @errSetCast(Set2, @intToError(x)); |
| | 4428 | \\ _ = y; |
| 4256 | \\} | 4429 | \\} |
| 4257 | , &[_][]const u8{ | 4430 | , &[_][]const u8{ |
| 4258 | "tmp.zig:11:13: error: error.B not a member of error set 'Set2'", | 4431 | "tmp.zig:11:13: error: error.B not a member of error set 'Set2'", |
| 4259 | }); | 4432 | }); |
| 4260 | | 4433 | |
| 4261 | cases.add("duplicate error value in error set", | 4434 | ctx.objErrStage1("duplicate error value in error set", |
| 4262 | \\const Foo = error { | 4435 | \\const Foo = error { |
| 4263 | \\ Bar, | 4436 | \\ Bar, |
| 4264 | \\ Bar, | 4437 | \\ Bar, |
| 4265 | \\}; | 4438 | \\}; |
| 4266 | \\export fn entry() void { | 4439 | \\export fn entry() void { |
| 4267 | \\ const a: Foo = undefined; | 4440 | \\ const a: Foo = undefined; |
| | 4441 | \\ _ = a; |
| 4268 | \\} | 4442 | \\} |
| 4269 | , &[_][]const u8{ | 4443 | , &[_][]const u8{ |
| 4270 | "tmp.zig:3:5: error: duplicate error: 'Bar'", | 4444 | "tmp.zig:3:5: error: duplicate error: 'Bar'", |
| 4271 | "tmp.zig:2:5: note: other error here", | 4445 | "tmp.zig:2:5: note: other error here", |
| 4272 | }); | 4446 | }); |
| 4273 | | 4447 | |
| 4274 | cases.add("cast negative integer literal to usize", | 4448 | ctx.objErrStage1("cast negative integer literal to usize", |
| 4275 | \\export fn entry() void { | 4449 | \\export fn entry() void { |
| 4276 | \\ const x = @as(usize, -10); | 4450 | \\ const x = @as(usize, -10); |
| | 4451 | \\ _ = x; |
| 4277 | \\} | 4452 | \\} |
| 4278 | , &[_][]const u8{ | 4453 | , &[_][]const u8{ |
| 4279 | "tmp.zig:2:26: error: cannot cast negative value -10 to unsigned integer type 'usize'", | 4454 | "tmp.zig:2:26: error: cannot cast negative value -10 to unsigned integer type 'usize'", |
| 4280 | }); | 4455 | }); |
| 4281 | | 4456 | |
| 4282 | cases.add("use invalid number literal as array index", | 4457 | ctx.objErrStage1("use invalid number literal as array index", |
| 4283 | \\var v = 25; | 4458 | \\var v = 25; |
| 4284 | \\export fn entry() void { | 4459 | \\export fn entry() void { |
| 4285 | \\ var arr: [v]u8 = undefined; | 4460 | \\ var arr: [v]u8 = undefined; |
| | 4461 | \\ _ = arr; |
| 4286 | \\} | 4462 | \\} |
| 4287 | , &[_][]const u8{ | 4463 | , &[_][]const u8{ |
| 4288 | "tmp.zig:1:1: error: unable to infer variable type", | 4464 | "tmp.zig:1:1: error: unable to infer variable type", |
| 4289 | }); | 4465 | }); |
| 4290 | | 4466 | |
| 4291 | cases.add("duplicate struct field", | 4467 | ctx.objErrStage1("duplicate struct field", |
| 4292 | \\const Foo = struct { | 4468 | \\const Foo = struct { |
| 4293 | \\ Bar: i32, | 4469 | \\ Bar: i32, |
| 4294 | \\ Bar: usize, | 4470 | \\ Bar: usize, |
| 4295 | \\}; | 4471 | \\}; |
| 4296 | \\export fn entry() void { | 4472 | \\export fn entry() void { |
| 4297 | \\ const a: Foo = undefined; | 4473 | \\ const a: Foo = undefined; |
| | 4474 | \\ _ = a; |
| 4298 | \\} | 4475 | \\} |
| 4299 | , &[_][]const u8{ | 4476 | , &[_][]const u8{ |
| 4300 | "tmp.zig:3:5: error: duplicate struct field: 'Bar'", | 4477 | "tmp.zig:3:5: error: duplicate struct field: 'Bar'", |
| 4301 | "tmp.zig:2:5: note: other field here", | 4478 | "tmp.zig:2:5: note: other field here", |
| 4302 | }); | 4479 | }); |
| 4303 | | 4480 | |
| 4304 | cases.add("duplicate union field", | 4481 | ctx.objErrStage1("duplicate union field", |
| 4305 | \\const Foo = union { | 4482 | \\const Foo = union { |
| 4306 | \\ Bar: i32, | 4483 | \\ Bar: i32, |
| 4307 | \\ Bar: usize, | 4484 | \\ Bar: usize, |
| 4308 | \\}; | 4485 | \\}; |
| 4309 | \\export fn entry() void { | 4486 | \\export fn entry() void { |
| 4310 | \\ const a: Foo = undefined; | 4487 | \\ const a: Foo = undefined; |
| | 4488 | \\ _ = a; |
| 4311 | \\} | 4489 | \\} |
| 4312 | , &[_][]const u8{ | 4490 | , &[_][]const u8{ |
| 4313 | "tmp.zig:3:5: error: duplicate union field: 'Bar'", | 4491 | "tmp.zig:3:5: error: duplicate union field: 'Bar'", |
| 4314 | "tmp.zig:2:5: note: other field here", | 4492 | "tmp.zig:2:5: note: other field here", |
| 4315 | }); | 4493 | }); |
| 4316 | | 4494 | |
| 4317 | cases.add("duplicate enum field", | 4495 | ctx.objErrStage1("duplicate enum field", |
| 4318 | \\const Foo = enum { | 4496 | \\const Foo = enum { |
| 4319 | \\ Bar, | 4497 | \\ Bar, |
| 4320 | \\ Bar, | 4498 | \\ Bar, |
| ... | @@ -4322,13 +4500,14 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -4322,13 +4500,14 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4322 | \\ | 4500 | \\ |
| 4323 | \\export fn entry() void { | 4501 | \\export fn entry() void { |
| 4324 | \\ const a: Foo = undefined; | 4502 | \\ const a: Foo = undefined; |
| | 4503 | \\ _ = a; |
| 4325 | \\} | 4504 | \\} |
| 4326 | , &[_][]const u8{ | 4505 | , &[_][]const u8{ |
| 4327 | "tmp.zig:3:5: error: duplicate enum field: 'Bar'", | 4506 | "tmp.zig:3:5: error: duplicate enum field: 'Bar'", |
| 4328 | "tmp.zig:2:5: note: other field here", | 4507 | "tmp.zig:2:5: note: other field here", |
| 4329 | }); | 4508 | }); |
| 4330 | | 4509 | |
| 4331 | cases.add("calling function with naked calling convention", | 4510 | ctx.objErrStage1("calling function with naked calling convention", |
| 4332 | \\export fn entry() void { | 4511 | \\export fn entry() void { |
| 4333 | \\ foo(); | 4512 | \\ foo(); |
| 4334 | \\} | 4513 | \\} |
| ... | @@ -4338,42 +4517,42 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -4338,42 +4517,42 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4338 | "tmp.zig:4:1: note: declared here", | 4517 | "tmp.zig:4:1: note: declared here", |
| 4339 | }); | 4518 | }); |
| 4340 | | 4519 | |
| 4341 | cases.add("function with invalid return type", | 4520 | ctx.objErrStage1("function with invalid return type", |
| 4342 | \\export fn foo() boid {} | 4521 | \\export fn foo() boid {} |
| 4343 | , &[_][]const u8{ | 4522 | , &[_][]const u8{ |
| 4344 | "tmp.zig:1:17: error: use of undeclared identifier 'boid'", | 4523 | "tmp.zig:1:17: error: use of undeclared identifier 'boid'", |
| 4345 | }); | 4524 | }); |
| 4346 | | 4525 | |
| 4347 | cases.add("function with non-extern non-packed enum parameter", | 4526 | ctx.objErrStage1("function with non-extern non-packed enum parameter", |
| 4348 | \\const Foo = enum { A, B, C }; | 4527 | \\const Foo = enum { A, B, C }; |
| 4349 | \\export fn entry(foo: Foo) void { } | 4528 | \\export fn entry(foo: Foo) void { _ = foo; } |
| 4350 | , &[_][]const u8{ | 4529 | , &[_][]const u8{ |
| 4351 | "tmp.zig:2:22: error: parameter of type 'Foo' not allowed in function with calling convention 'C'", | 4530 | "tmp.zig:2:22: error: parameter of type 'Foo' not allowed in function with calling convention 'C'", |
| 4352 | }); | 4531 | }); |
| 4353 | | 4532 | |
| 4354 | cases.add("function with non-extern non-packed struct parameter", | 4533 | ctx.objErrStage1("function with non-extern non-packed struct parameter", |
| 4355 | \\const Foo = struct { | 4534 | \\const Foo = struct { |
| 4356 | \\ A: i32, | 4535 | \\ A: i32, |
| 4357 | \\ B: f32, | 4536 | \\ B: f32, |
| 4358 | \\ C: bool, | 4537 | \\ C: bool, |
| 4359 | \\}; | 4538 | \\}; |
| 4360 | \\export fn entry(foo: Foo) void { } | 4539 | \\export fn entry(foo: Foo) void { _ = foo; } |
| 4361 | , &[_][]const u8{ | 4540 | , &[_][]const u8{ |
| 4362 | "tmp.zig:6:22: error: parameter of type 'Foo' not allowed in function with calling convention 'C'", | 4541 | "tmp.zig:6:22: error: parameter of type 'Foo' not allowed in function with calling convention 'C'", |
| 4363 | }); | 4542 | }); |
| 4364 | | 4543 | |
| 4365 | cases.add("function with non-extern non-packed union parameter", | 4544 | ctx.objErrStage1("function with non-extern non-packed union parameter", |
| 4366 | \\const Foo = union { | 4545 | \\const Foo = union { |
| 4367 | \\ A: i32, | 4546 | \\ A: i32, |
| 4368 | \\ B: f32, | 4547 | \\ B: f32, |
| 4369 | \\ C: bool, | 4548 | \\ C: bool, |
| 4370 | \\}; | 4549 | \\}; |
| 4371 | \\export fn entry(foo: Foo) void { } | 4550 | \\export fn entry(foo: Foo) void { _ = foo; } |
| 4372 | , &[_][]const u8{ | 4551 | , &[_][]const u8{ |
| 4373 | "tmp.zig:6:22: error: parameter of type 'Foo' not allowed in function with calling convention 'C'", | 4552 | "tmp.zig:6:22: error: parameter of type 'Foo' not allowed in function with calling convention 'C'", |
| 4374 | }); | 4553 | }); |
| 4375 | | 4554 | |
| 4376 | cases.add("switch on enum with 1 field with no prongs", | 4555 | ctx.objErrStage1("switch on enum with 1 field with no prongs", |
| 4377 | \\const Foo = enum { M }; | 4556 | \\const Foo = enum { M }; |
| 4378 | \\ | 4557 | \\ |
| 4379 | \\export fn entry() void { | 4558 | \\export fn entry() void { |
| ... | @@ -4384,15 +4563,16 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -4384,15 +4563,16 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4384 | "tmp.zig:5:5: error: enumeration value 'Foo.M' not handled in switch", | 4563 | "tmp.zig:5:5: error: enumeration value 'Foo.M' not handled in switch", |
| 4385 | }); | 4564 | }); |
| 4386 | | 4565 | |
| 4387 | cases.add("shift by negative comptime integer", | 4566 | ctx.objErrStage1("shift by negative comptime integer", |
| 4388 | \\comptime { | 4567 | \\comptime { |
| 4389 | \\ var a = 1 >> -1; | 4568 | \\ var a = 1 >> -1; |
| | 4569 | \\ _ = a; |
| 4390 | \\} | 4570 | \\} |
| 4391 | , &[_][]const u8{ | 4571 | , &[_][]const u8{ |
| 4392 | "tmp.zig:2:18: error: shift by negative value -1", | 4572 | "tmp.zig:2:18: error: shift by negative value -1", |
| 4393 | }); | 4573 | }); |
| 4394 | | 4574 | |
| 4395 | cases.add("@panic called at compile time", | 4575 | ctx.objErrStage1("@panic called at compile time", |
| 4396 | \\export fn entry() void { | 4576 | \\export fn entry() void { |
| 4397 | \\ comptime { | 4577 | \\ comptime { |
| 4398 | \\ @panic("aoeu",); | 4578 | \\ @panic("aoeu",); |
| ... | @@ -4402,20 +4582,20 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -4402,20 +4582,20 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4402 | "tmp.zig:3:9: error: encountered @panic at compile-time", | 4582 | "tmp.zig:3:9: error: encountered @panic at compile-time", |
| 4403 | }); | 4583 | }); |
| 4404 | | 4584 | |
| 4405 | cases.add("wrong return type for main", | 4585 | ctx.objErrStage1("wrong return type for main", |
| 4406 | \\pub fn main() f32 { } | 4586 | \\pub fn main() f32 { } |
| 4407 | , &[_][]const u8{ | 4587 | , &[_][]const u8{ |
| 4408 | "error: expected return type of main to be 'void', '!void', 'noreturn', 'u8', or '!u8'", | 4588 | "error: expected return type of main to be 'void', '!void', 'noreturn', 'u8', or '!u8'", |
| 4409 | }); | 4589 | }); |
| 4410 | | 4590 | |
| 4411 | cases.add("double ?? on main return value", | 4591 | ctx.objErrStage1("double ?? on main return value", |
| 4412 | \\pub fn main() ??void { | 4592 | \\pub fn main() ??void { |
| 4413 | \\} | 4593 | \\} |
| 4414 | , &[_][]const u8{ | 4594 | , &[_][]const u8{ |
| 4415 | "error: expected return type of main to be 'void', '!void', 'noreturn', 'u8', or '!u8'", | 4595 | "error: expected return type of main to be 'void', '!void', 'noreturn', 'u8', or '!u8'", |
| 4416 | }); | 4596 | }); |
| 4417 | | 4597 | |
| 4418 | cases.add("bad identifier in function with struct defined inside function which references local const", | 4598 | ctx.objErrStage1("bad identifier in function with struct defined inside function which references local const", |
| 4419 | \\export fn entry() void { | 4599 | \\export fn entry() void { |
| 4420 | \\ const BlockKind = u32; | 4600 | \\ const BlockKind = u32; |
| 4421 | \\ | 4601 | \\ |
| ... | @@ -4424,12 +4604,14 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -4424,12 +4604,14 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4424 | \\ }; | 4604 | \\ }; |
| 4425 | \\ | 4605 | \\ |
| 4426 | \\ bogus; | 4606 | \\ bogus; |
| | 4607 | \\ |
| | 4608 | \\ _ = Block; |
| 4427 | \\} | 4609 | \\} |
| 4428 | , &[_][]const u8{ | 4610 | , &[_][]const u8{ |
| 4429 | "tmp.zig:8:5: error: use of undeclared identifier 'bogus'", | 4611 | "tmp.zig:8:5: error: use of undeclared identifier 'bogus'", |
| 4430 | }); | 4612 | }); |
| 4431 | | 4613 | |
| 4432 | cases.add("labeled break not found", | 4614 | ctx.objErrStage1("labeled break not found", |
| 4433 | \\export fn entry() void { | 4615 | \\export fn entry() void { |
| 4434 | \\ blah: while (true) { | 4616 | \\ blah: while (true) { |
| 4435 | \\ while (true) { | 4617 | \\ while (true) { |
| ... | @@ -4438,10 +4620,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -4438,10 +4620,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4438 | \\ } | 4620 | \\ } |
| 4439 | \\} | 4621 | \\} |
| 4440 | , &[_][]const u8{ | 4622 | , &[_][]const u8{ |
| 4441 | "tmp.zig:4:13: error: label not found: 'outer'", | 4623 | "tmp.zig:4:20: error: label not found: 'outer'", |
| 4442 | }); | 4624 | }); |
| 4443 | | 4625 | |
| 4444 | cases.add("labeled continue not found", | 4626 | ctx.objErrStage1("labeled continue not found", |
| 4445 | \\export fn entry() void { | 4627 | \\export fn entry() void { |
| 4446 | \\ var i: usize = 0; | 4628 | \\ var i: usize = 0; |
| 4447 | \\ blah: while (i < 10) : (i += 1) { | 4629 | \\ blah: while (i < 10) : (i += 1) { |
| ... | @@ -4451,17 +4633,17 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -4451,17 +4633,17 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4451 | \\ } | 4633 | \\ } |
| 4452 | \\} | 4634 | \\} |
| 4453 | , &[_][]const u8{ | 4635 | , &[_][]const u8{ |
| 4454 | "tmp.zig:5:13: error: labeled loop not found: 'outer'", | 4636 | "tmp.zig:5:23: error: label not found: 'outer'", |
| 4455 | }); | 4637 | }); |
| 4456 | | 4638 | |
| 4457 | cases.add("attempt to use 0 bit type in extern fn", | 4639 | ctx.objErrStage1("attempt to use 0 bit type in extern fn", |
| 4458 | \\extern fn foo(ptr: fn(*void) callconv(.C) void) void; | 4640 | \\extern fn foo(ptr: fn(*void) callconv(.C) void) void; |
| 4459 | \\ | 4641 | \\ |
| 4460 | \\export fn entry() void { | 4642 | \\export fn entry() void { |
| 4461 | \\ foo(bar); | 4643 | \\ foo(bar); |
| 4462 | \\} | 4644 | \\} |
| 4463 | \\ | 4645 | \\ |
| 4464 | \\fn bar(x: *void) callconv(.C) void { } | 4646 | \\fn bar(x: *void) callconv(.C) void { _ = x; } |
| 4465 | \\export fn entry2() void { | 4647 | \\export fn entry2() void { |
| 4466 | \\ bar(&{}); | 4648 | \\ bar(&{}); |
| 4467 | \\} | 4649 | \\} |
| ... | @@ -4470,7 +4652,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -4470,7 +4652,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'", | 4652 | "tmp.zig:7:11: error: parameter of type '*void' has 0 bits; not allowed in function with calling convention 'C'", |
| 4471 | }); | 4653 | }); |
| 4472 | | 4654 | |
| 4473 | cases.add("implicit semicolon - block statement", | 4655 | ctx.objErrStage1("implicit semicolon - block statement", |
| 4474 | \\export fn entry() void { | 4656 | \\export fn entry() void { |
| 4475 | \\ {} | 4657 | \\ {} |
| 4476 | \\ var good = {}; | 4658 | \\ var good = {}; |
| ... | @@ -4478,10 +4660,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -4478,10 +4660,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4478 | \\ var bad = {}; | 4660 | \\ var bad = {}; |
| 4479 | \\} | 4661 | \\} |
| 4480 | , &[_][]const u8{ | 4662 | , &[_][]const u8{ |
| 4481 | "tmp.zig:5:5: error: expected token ';', found 'var'", | 4663 | "tmp.zig:5:5: error: expected ';', found 'var'", |
| 4482 | }); | 4664 | }); |
| 4483 | | 4665 | |
| 4484 | cases.add("implicit semicolon - block expr", | 4666 | ctx.objErrStage1("implicit semicolon - block expr", |
| 4485 | \\export fn entry() void { | 4667 | \\export fn entry() void { |
| 4486 | \\ _ = {}; | 4668 | \\ _ = {}; |
| 4487 | \\ var good = {}; | 4669 | \\ var good = {}; |
| ... | @@ -4489,10 +4671,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -4489,10 +4671,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4489 | \\ var bad = {}; | 4671 | \\ var bad = {}; |
| 4490 | \\} | 4672 | \\} |
| 4491 | , &[_][]const u8{ | 4673 | , &[_][]const u8{ |
| 4492 | "tmp.zig:5:5: error: expected token ';', found 'var'", | 4674 | "tmp.zig:5:5: error: expected ';', found 'var'", |
| 4493 | }); | 4675 | }); |
| 4494 | | 4676 | |
| 4495 | cases.add("implicit semicolon - comptime statement", | 4677 | ctx.objErrStage1("implicit semicolon - comptime statement", |
| 4496 | \\export fn entry() void { | 4678 | \\export fn entry() void { |
| 4497 | \\ comptime {} | 4679 | \\ comptime {} |
| 4498 | \\ var good = {}; | 4680 | \\ var good = {}; |
| ... | @@ -4500,10 +4682,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -4500,10 +4682,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4500 | \\ var bad = {}; | 4682 | \\ var bad = {}; |
| 4501 | \\} | 4683 | \\} |
| 4502 | , &[_][]const u8{ | 4684 | , &[_][]const u8{ |
| 4503 | "tmp.zig:5:5: error: expected token ';', found 'var'", | 4685 | "tmp.zig:5:5: error: expected ';', found 'var'", |
| 4504 | }); | 4686 | }); |
| 4505 | | 4687 | |
| 4506 | cases.add("implicit semicolon - comptime expression", | 4688 | ctx.objErrStage1("implicit semicolon - comptime expression", |
| 4507 | \\export fn entry() void { | 4689 | \\export fn entry() void { |
| 4508 | \\ _ = comptime {}; | 4690 | \\ _ = comptime {}; |
| 4509 | \\ var good = {}; | 4691 | \\ var good = {}; |
| ... | @@ -4511,10 +4693,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -4511,10 +4693,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4511 | \\ var bad = {}; | 4693 | \\ var bad = {}; |
| 4512 | \\} | 4694 | \\} |
| 4513 | , &[_][]const u8{ | 4695 | , &[_][]const u8{ |
| 4514 | "tmp.zig:5:5: error: expected token ';', found 'var'", | 4696 | "tmp.zig:5:5: error: expected ';', found 'var'", |
| 4515 | }); | 4697 | }); |
| 4516 | | 4698 | |
| 4517 | cases.add("implicit semicolon - defer", | 4699 | ctx.objErrStage1("implicit semicolon - defer", |
| 4518 | \\export fn entry() void { | 4700 | \\export fn entry() void { |
| 4519 | \\ defer {} | 4701 | \\ defer {} |
| 4520 | \\ var good = {}; | 4702 | \\ var good = {}; |
| ... | @@ -4522,10 +4704,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -4522,10 +4704,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4522 | \\ var bad = {}; | 4704 | \\ var bad = {}; |
| 4523 | \\} | 4705 | \\} |
| 4524 | , &[_][]const u8{ | 4706 | , &[_][]const u8{ |
| 4525 | "tmp.zig:5:5: error: expected token ';', found 'var'", | 4707 | "tmp.zig:5:5: error: expected ';', found 'var'", |
| 4526 | }); | 4708 | }); |
| 4527 | | 4709 | |
| 4528 | cases.add("implicit semicolon - if statement", | 4710 | ctx.objErrStage1("implicit semicolon - if statement", |
| 4529 | \\export fn entry() void { | 4711 | \\export fn entry() void { |
| 4530 | \\ if(true) {} | 4712 | \\ if(true) {} |
| 4531 | \\ var good = {}; | 4713 | \\ var good = {}; |
| ... | @@ -4533,10 +4715,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -4533,10 +4715,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4533 | \\ var bad = {}; | 4715 | \\ var bad = {}; |
| 4534 | \\} | 4716 | \\} |
| 4535 | , &[_][]const u8{ | 4717 | , &[_][]const u8{ |
| 4536 | "tmp.zig:5:5: error: expected token ';', found 'var'", | 4718 | "tmp.zig:5:5: error: expected ';' or 'else', found 'var'", |
| 4537 | }); | 4719 | }); |
| 4538 | | 4720 | |
| 4539 | cases.add("implicit semicolon - if expression", | 4721 | ctx.objErrStage1("implicit semicolon - if expression", |
| 4540 | \\export fn entry() void { | 4722 | \\export fn entry() void { |
| 4541 | \\ _ = if(true) {}; | 4723 | \\ _ = if(true) {}; |
| 4542 | \\ var good = {}; | 4724 | \\ var good = {}; |
| ... | @@ -4544,10 +4726,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -4544,10 +4726,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4544 | \\ var bad = {}; | 4726 | \\ var bad = {}; |
| 4545 | \\} | 4727 | \\} |
| 4546 | , &[_][]const u8{ | 4728 | , &[_][]const u8{ |
| 4547 | "tmp.zig:5:5: error: expected token ';', found 'var'", | 4729 | "tmp.zig:5:5: error: expected ';', found 'var'", |
| 4548 | }); | 4730 | }); |
| 4549 | | 4731 | |
| 4550 | cases.add("implicit semicolon - if-else statement", | 4732 | ctx.objErrStage1("implicit semicolon - if-else statement", |
| 4551 | \\export fn entry() void { | 4733 | \\export fn entry() void { |
| 4552 | \\ if(true) {} else {} | 4734 | \\ if(true) {} else {} |
| 4553 | \\ var good = {}; | 4735 | \\ var good = {}; |
| ... | @@ -4555,10 +4737,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -4555,10 +4737,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4555 | \\ var bad = {}; | 4737 | \\ var bad = {}; |
| 4556 | \\} | 4738 | \\} |
| 4557 | , &[_][]const u8{ | 4739 | , &[_][]const u8{ |
| 4558 | "tmp.zig:5:5: error: expected token ';', found 'var'", | 4740 | "tmp.zig:5:5: error: expected ';', found 'var'", |
| 4559 | }); | 4741 | }); |
| 4560 | | 4742 | |
| 4561 | cases.add("implicit semicolon - if-else expression", | 4743 | ctx.objErrStage1("implicit semicolon - if-else expression", |
| 4562 | \\export fn entry() void { | 4744 | \\export fn entry() void { |
| 4563 | \\ _ = if(true) {} else {}; | 4745 | \\ _ = if(true) {} else {}; |
| 4564 | \\ var good = {}; | 4746 | \\ var good = {}; |
| ... | @@ -4566,10 +4748,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -4566,10 +4748,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4566 | \\ var bad = {}; | 4748 | \\ var bad = {}; |
| 4567 | \\} | 4749 | \\} |
| 4568 | , &[_][]const u8{ | 4750 | , &[_][]const u8{ |
| 4569 | "tmp.zig:5:5: error: expected token ';', found 'var'", | 4751 | "tmp.zig:5:5: error: expected ';', found 'var'", |
| 4570 | }); | 4752 | }); |
| 4571 | | 4753 | |
| 4572 | cases.add("implicit semicolon - if-else-if statement", | 4754 | ctx.objErrStage1("implicit semicolon - if-else-if statement", |
| 4573 | \\export fn entry() void { | 4755 | \\export fn entry() void { |
| 4574 | \\ if(true) {} else if(true) {} | 4756 | \\ if(true) {} else if(true) {} |
| 4575 | \\ var good = {}; | 4757 | \\ var good = {}; |
| ... | @@ -4577,10 +4759,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -4577,10 +4759,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4577 | \\ var bad = {}; | 4759 | \\ var bad = {}; |
| 4578 | \\} | 4760 | \\} |
| 4579 | , &[_][]const u8{ | 4761 | , &[_][]const u8{ |
| 4580 | "tmp.zig:5:5: error: expected token ';', found 'var'", | 4762 | "tmp.zig:5:5: error: expected ';' or 'else', found 'var'", |
| 4581 | }); | 4763 | }); |
| 4582 | | 4764 | |
| 4583 | cases.add("implicit semicolon - if-else-if expression", | 4765 | ctx.objErrStage1("implicit semicolon - if-else-if expression", |
| 4584 | \\export fn entry() void { | 4766 | \\export fn entry() void { |
| 4585 | \\ _ = if(true) {} else if(true) {}; | 4767 | \\ _ = if(true) {} else if(true) {}; |
| 4586 | \\ var good = {}; | 4768 | \\ var good = {}; |
| ... | @@ -4588,10 +4770,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -4588,10 +4770,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4588 | \\ var bad = {}; | 4770 | \\ var bad = {}; |
| 4589 | \\} | 4771 | \\} |
| 4590 | , &[_][]const u8{ | 4772 | , &[_][]const u8{ |
| 4591 | "tmp.zig:5:5: error: expected token ';', found 'var'", | 4773 | "tmp.zig:5:5: error: expected ';', found 'var'", |
| 4592 | }); | 4774 | }); |
| 4593 | | 4775 | |
| 4594 | cases.add("implicit semicolon - if-else-if-else statement", | 4776 | ctx.objErrStage1("implicit semicolon - if-else-if-else statement", |
| 4595 | \\export fn entry() void { | 4777 | \\export fn entry() void { |
| 4596 | \\ if(true) {} else if(true) {} else {} | 4778 | \\ if(true) {} else if(true) {} else {} |
| 4597 | \\ var good = {}; | 4779 | \\ var good = {}; |
| ... | @@ -4599,10 +4781,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -4599,10 +4781,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4599 | \\ var bad = {}; | 4781 | \\ var bad = {}; |
| 4600 | \\} | 4782 | \\} |
| 4601 | , &[_][]const u8{ | 4783 | , &[_][]const u8{ |
| 4602 | "tmp.zig:5:5: error: expected token ';', found 'var'", | 4784 | "tmp.zig:5:5: error: expected ';', found 'var'", |
| 4603 | }); | 4785 | }); |
| 4604 | | 4786 | |
| 4605 | cases.add("implicit semicolon - if-else-if-else expression", | 4787 | ctx.objErrStage1("implicit semicolon - if-else-if-else expression", |
| 4606 | \\export fn entry() void { | 4788 | \\export fn entry() void { |
| 4607 | \\ _ = if(true) {} else if(true) {} else {}; | 4789 | \\ _ = if(true) {} else if(true) {} else {}; |
| 4608 | \\ var good = {}; | 4790 | \\ var good = {}; |
| ... | @@ -4610,10 +4792,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -4610,10 +4792,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4610 | \\ var bad = {}; | 4792 | \\ var bad = {}; |
| 4611 | \\} | 4793 | \\} |
| 4612 | , &[_][]const u8{ | 4794 | , &[_][]const u8{ |
| 4613 | "tmp.zig:5:5: error: expected token ';', found 'var'", | 4795 | "tmp.zig:5:5: error: expected ';', found 'var'", |
| 4614 | }); | 4796 | }); |
| 4615 | | 4797 | |
| 4616 | cases.add("implicit semicolon - test statement", | 4798 | ctx.objErrStage1("implicit semicolon - test statement", |
| 4617 | \\export fn entry() void { | 4799 | \\export fn entry() void { |
| 4618 | \\ if (foo()) |_| {} | 4800 | \\ if (foo()) |_| {} |
| 4619 | \\ var good = {}; | 4801 | \\ var good = {}; |
| ... | @@ -4621,10 +4803,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -4621,10 +4803,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4621 | \\ var bad = {}; | 4803 | \\ var bad = {}; |
| 4622 | \\} | 4804 | \\} |
| 4623 | , &[_][]const u8{ | 4805 | , &[_][]const u8{ |
| 4624 | "tmp.zig:5:5: error: expected token ';', found 'var'", | 4806 | "tmp.zig:5:5: error: expected ';' or 'else', found 'var'", |
| 4625 | }); | 4807 | }); |
| 4626 | | 4808 | |
| 4627 | cases.add("implicit semicolon - test expression", | 4809 | ctx.objErrStage1("implicit semicolon - test expression", |
| 4628 | \\export fn entry() void { | 4810 | \\export fn entry() void { |
| 4629 | \\ _ = if (foo()) |_| {}; | 4811 | \\ _ = if (foo()) |_| {}; |
| 4630 | \\ var good = {}; | 4812 | \\ var good = {}; |
| ... | @@ -4632,10 +4814,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -4632,10 +4814,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4632 | \\ var bad = {}; | 4814 | \\ var bad = {}; |
| 4633 | \\} | 4815 | \\} |
| 4634 | , &[_][]const u8{ | 4816 | , &[_][]const u8{ |
| 4635 | "tmp.zig:5:5: error: expected token ';', found 'var'", | 4817 | "tmp.zig:5:5: error: expected ';', found 'var'", |
| 4636 | }); | 4818 | }); |
| 4637 | | 4819 | |
| 4638 | cases.add("implicit semicolon - while statement", | 4820 | ctx.objErrStage1("implicit semicolon - while statement", |
| 4639 | \\export fn entry() void { | 4821 | \\export fn entry() void { |
| 4640 | \\ while(true) {} | 4822 | \\ while(true) {} |
| 4641 | \\ var good = {}; | 4823 | \\ var good = {}; |
| ... | @@ -4643,10 +4825,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -4643,10 +4825,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4643 | \\ var bad = {}; | 4825 | \\ var bad = {}; |
| 4644 | \\} | 4826 | \\} |
| 4645 | , &[_][]const u8{ | 4827 | , &[_][]const u8{ |
| 4646 | "tmp.zig:5:5: error: expected token ';', found 'var'", | 4828 | "tmp.zig:5:5: error: expected ';' or 'else', found 'var'", |
| 4647 | }); | 4829 | }); |
| 4648 | | 4830 | |
| 4649 | cases.add("implicit semicolon - while expression", | 4831 | ctx.objErrStage1("implicit semicolon - while expression", |
| 4650 | \\export fn entry() void { | 4832 | \\export fn entry() void { |
| 4651 | \\ _ = while(true) {}; | 4833 | \\ _ = while(true) {}; |
| 4652 | \\ var good = {}; | 4834 | \\ var good = {}; |
| ... | @@ -4654,10 +4836,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -4654,10 +4836,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4654 | \\ var bad = {}; | 4836 | \\ var bad = {}; |
| 4655 | \\} | 4837 | \\} |
| 4656 | , &[_][]const u8{ | 4838 | , &[_][]const u8{ |
| 4657 | "tmp.zig:5:5: error: expected token ';', found 'var'", | 4839 | "tmp.zig:5:5: error: expected ';', found 'var'", |
| 4658 | }); | 4840 | }); |
| 4659 | | 4841 | |
| 4660 | cases.add("implicit semicolon - while-continue statement", | 4842 | ctx.objErrStage1("implicit semicolon - while-continue statement", |
| 4661 | \\export fn entry() void { | 4843 | \\export fn entry() void { |
| 4662 | \\ while(true):({}) {} | 4844 | \\ while(true):({}) {} |
| 4663 | \\ var good = {}; | 4845 | \\ var good = {}; |
| ... | @@ -4665,10 +4847,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -4665,10 +4847,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4665 | \\ var bad = {}; | 4847 | \\ var bad = {}; |
| 4666 | \\} | 4848 | \\} |
| 4667 | , &[_][]const u8{ | 4849 | , &[_][]const u8{ |
| 4668 | "tmp.zig:5:5: error: expected token ';', found 'var'", | 4850 | "tmp.zig:5:5: error: expected ';' or 'else', found 'var'", |
| 4669 | }); | 4851 | }); |
| 4670 | | 4852 | |
| 4671 | cases.add("implicit semicolon - while-continue expression", | 4853 | ctx.objErrStage1("implicit semicolon - while-continue expression", |
| 4672 | \\export fn entry() void { | 4854 | \\export fn entry() void { |
| 4673 | \\ _ = while(true):({}) {}; | 4855 | \\ _ = while(true):({}) {}; |
| 4674 | \\ var good = {}; | 4856 | \\ var good = {}; |
| ... | @@ -4676,10 +4858,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -4676,10 +4858,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4676 | \\ var bad = {}; | 4858 | \\ var bad = {}; |
| 4677 | \\} | 4859 | \\} |
| 4678 | , &[_][]const u8{ | 4860 | , &[_][]const u8{ |
| 4679 | "tmp.zig:5:5: error: expected token ';', found 'var'", | 4861 | "tmp.zig:5:5: error: expected ';', found 'var'", |
| 4680 | }); | 4862 | }); |
| 4681 | | 4863 | |
| 4682 | cases.add("implicit semicolon - for statement", | 4864 | ctx.objErrStage1("implicit semicolon - for statement", |
| 4683 | \\export fn entry() void { | 4865 | \\export fn entry() void { |
| 4684 | \\ for(foo()) |_| {} | 4866 | \\ for(foo()) |_| {} |
| 4685 | \\ var good = {}; | 4867 | \\ var good = {}; |
| ... | @@ -4687,10 +4869,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -4687,10 +4869,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4687 | \\ var bad = {}; | 4869 | \\ var bad = {}; |
| 4688 | \\} | 4870 | \\} |
| 4689 | , &[_][]const u8{ | 4871 | , &[_][]const u8{ |
| 4690 | "tmp.zig:5:5: error: expected token ';', found 'var'", | 4872 | "tmp.zig:5:5: error: expected ';' or 'else', found 'var'", |
| 4691 | }); | 4873 | }); |
| 4692 | | 4874 | |
| 4693 | cases.add("implicit semicolon - for expression", | 4875 | ctx.objErrStage1("implicit semicolon - for expression", |
| 4694 | \\export fn entry() void { | 4876 | \\export fn entry() void { |
| 4695 | \\ _ = for(foo()) |_| {}; | 4877 | \\ _ = for(foo()) |_| {}; |
| 4696 | \\ var good = {}; | 4878 | \\ var good = {}; |
| ... | @@ -4698,32 +4880,33 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -4698,32 +4880,33 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4698 | \\ var bad = {}; | 4880 | \\ var bad = {}; |
| 4699 | \\} | 4881 | \\} |
| 4700 | , &[_][]const u8{ | 4882 | , &[_][]const u8{ |
| 4701 | "tmp.zig:5:5: error: expected token ';', found 'var'", | 4883 | "tmp.zig:5:5: error: expected ';', found 'var'", |
| 4702 | }); | 4884 | }); |
| 4703 | | 4885 | |
| 4704 | cases.add("multiple function definitions", | 4886 | ctx.objErrStage1("multiple function definitions", |
| 4705 | \\fn a() void {} | 4887 | \\fn a() void {} |
| 4706 | \\fn a() void {} | 4888 | \\fn a() void {} |
| 4707 | \\export fn entry() void { a(); } | 4889 | \\export fn entry() void { a(); } |
| 4708 | , &[_][]const u8{ | 4890 | , &[_][]const u8{ |
| 4709 | "tmp.zig:2:1: error: redefinition of 'a'", | 4891 | "tmp.zig:2:1: error: redeclaration of 'a'", |
| | 4892 | "tmp.zig:1:1: error: other declaration here", |
| 4710 | }); | 4893 | }); |
| 4711 | | 4894 | |
| 4712 | cases.add("unreachable with return", | 4895 | ctx.objErrStage1("unreachable with return", |
| 4713 | \\fn a() noreturn {return;} | 4896 | \\fn a() noreturn {return;} |
| 4714 | \\export fn entry() void { a(); } | 4897 | \\export fn entry() void { a(); } |
| 4715 | , &[_][]const u8{ | 4898 | , &[_][]const u8{ |
| 4716 | "tmp.zig:1:18: error: expected type 'noreturn', found 'void'", | 4899 | "tmp.zig:1:18: error: expected type 'noreturn', found 'void'", |
| 4717 | }); | 4900 | }); |
| 4718 | | 4901 | |
| 4719 | cases.add("control reaches end of non-void function", | 4902 | ctx.objErrStage1("control reaches end of non-void function", |
| 4720 | \\fn a() i32 {} | 4903 | \\fn a() i32 {} |
| 4721 | \\export fn entry() void { _ = a(); } | 4904 | \\export fn entry() void { _ = a(); } |
| 4722 | , &[_][]const u8{ | 4905 | , &[_][]const u8{ |
| 4723 | "tmp.zig:1:12: error: expected type 'i32', found 'void'", | 4906 | "tmp.zig:1:12: error: expected type 'i32', found 'void'", |
| 4724 | }); | 4907 | }); |
| 4725 | | 4908 | |
| 4726 | cases.add("undefined function call", | 4909 | ctx.objErrStage1("undefined function call", |
| 4727 | \\export fn a() void { | 4910 | \\export fn a() void { |
| 4728 | \\ b(); | 4911 | \\ b(); |
| 4729 | \\} | 4912 | \\} |
| ... | @@ -4731,30 +4914,30 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -4731,30 +4914,30 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4731 | "tmp.zig:2:5: error: use of undeclared identifier 'b'", | 4914 | "tmp.zig:2:5: error: use of undeclared identifier 'b'", |
| 4732 | }); | 4915 | }); |
| 4733 | | 4916 | |
| 4734 | cases.add("wrong number of arguments", | 4917 | ctx.objErrStage1("wrong number of arguments", |
| 4735 | \\export fn a() void { | 4918 | \\export fn a() void { |
| 4736 | \\ b(1); | 4919 | \\ b(1); |
| 4737 | \\} | 4920 | \\} |
| 4738 | \\fn b(a: i32, b: i32, c: i32) void { } | 4921 | \\fn b(a: i32, b: i32, c: i32) void { _ = a; _ = b; _ = c; } |
| 4739 | , &[_][]const u8{ | 4922 | , &[_][]const u8{ |
| 4740 | "tmp.zig:2:6: error: expected 3 argument(s), found 1", | 4923 | "tmp.zig:2:6: error: expected 3 argument(s), found 1", |
| 4741 | }); | 4924 | }); |
| 4742 | | 4925 | |
| 4743 | cases.add("invalid type", | 4926 | ctx.objErrStage1("invalid type", |
| 4744 | \\fn a() bogus {} | 4927 | \\fn a() bogus {} |
| 4745 | \\export fn entry() void { _ = a(); } | 4928 | \\export fn entry() void { _ = a(); } |
| 4746 | , &[_][]const u8{ | 4929 | , &[_][]const u8{ |
| 4747 | "tmp.zig:1:8: error: use of undeclared identifier 'bogus'", | 4930 | "tmp.zig:1:8: error: use of undeclared identifier 'bogus'", |
| 4748 | }); | 4931 | }); |
| 4749 | | 4932 | |
| 4750 | cases.add("pointer to noreturn", | 4933 | ctx.objErrStage1("pointer to noreturn", |
| 4751 | \\fn a() *noreturn {} | 4934 | \\fn a() *noreturn {} |
| 4752 | \\export fn entry() void { _ = a(); } | 4935 | \\export fn entry() void { _ = a(); } |
| 4753 | , &[_][]const u8{ | 4936 | , &[_][]const u8{ |
| 4754 | "tmp.zig:1:9: error: pointer to noreturn not allowed", | 4937 | "tmp.zig:1:9: error: pointer to noreturn not allowed", |
| 4755 | }); | 4938 | }); |
| 4756 | | 4939 | |
| 4757 | cases.add("unreachable code", | 4940 | ctx.objErrStage1("unreachable code", |
| 4758 | \\export fn a() void { | 4941 | \\export fn a() void { |
| 4759 | \\ return; | 4942 | \\ return; |
| 4760 | \\ b(); | 4943 | \\ b(); |
| ... | @@ -4766,14 +4949,14 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -4766,14 +4949,14 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4766 | "tmp.zig:2:5: note: control flow is diverted here", | 4949 | "tmp.zig:2:5: note: control flow is diverted here", |
| 4767 | }); | 4950 | }); |
| 4768 | | 4951 | |
| 4769 | cases.add("bad import", | 4952 | ctx.objErrStage1("bad import", |
| 4770 | \\const bogus = @import("bogus-does-not-exist.zig",); | 4953 | \\const bogus = @import("bogus-does-not-exist.zig",); |
| 4771 | \\export fn entry() void { bogus.bogo(); } | 4954 | \\export fn entry() void { bogus.bogo(); } |
| 4772 | , &[_][]const u8{ | 4955 | , &[_][]const u8{ |
| 4773 | "tmp.zig:1:15: error: unable to find 'bogus-does-not-exist.zig'", | 4956 | "tmp.zig:1:15: error: unable to find 'bogus-does-not-exist.zig'", |
| 4774 | }); | 4957 | }); |
| 4775 | | 4958 | |
| 4776 | cases.add("undeclared identifier", | 4959 | ctx.objErrStage1("undeclared identifier", |
| 4777 | \\export fn a() void { | 4960 | \\export fn a() void { |
| 4778 | \\ return | 4961 | \\ return |
| 4779 | \\ b + | 4962 | \\ b + |
| ... | @@ -4783,33 +4966,36 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -4783,33 +4966,36 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4783 | "tmp.zig:3:5: error: use of undeclared identifier 'b'", | 4966 | "tmp.zig:3:5: error: use of undeclared identifier 'b'", |
| 4784 | }); | 4967 | }); |
| 4785 | | 4968 | |
| 4786 | cases.add("parameter redeclaration", | 4969 | ctx.objErrStage1("parameter redeclaration", |
| 4787 | \\fn f(a : i32, a : i32) void { | 4970 | \\fn f(a : i32, a : i32) void { |
| 4788 | \\} | 4971 | \\} |
| 4789 | \\export fn entry() void { f(1, 2); } | 4972 | \\export fn entry() void { f(1, 2); } |
| 4790 | , &[_][]const u8{ | 4973 | , &[_][]const u8{ |
| 4791 | "tmp.zig:1:15: error: redeclaration of variable 'a'", | 4974 | "tmp.zig:1:15: error: redeclaration of parameter 'a'", |
| | 4975 | "tmp.zig:1:6: note: previous declaration here", |
| 4792 | }); | 4976 | }); |
| 4793 | | 4977 | |
| 4794 | cases.add("local variable redeclaration", | 4978 | ctx.objErrStage1("local variable redeclaration", |
| 4795 | \\export fn f() void { | 4979 | \\export fn f() void { |
| 4796 | \\ const a : i32 = 0; | 4980 | \\ const a : i32 = 0; |
| 4797 | \\ const a = 0; | 4981 | \\ var a = 0; |
| 4798 | \\} | 4982 | \\} |
| 4799 | , &[_][]const u8{ | 4983 | , &[_][]const u8{ |
| 4800 | "tmp.zig:3:5: error: redeclaration of variable 'a'", | 4984 | "tmp.zig:3:9: error: redeclaration of local const 'a'", |
| | 4985 | "tmp.zig:2:11: note: previous declaration here", |
| 4801 | }); | 4986 | }); |
| 4802 | | 4987 | |
| 4803 | cases.add("local variable redeclares parameter", | 4988 | ctx.objErrStage1("local variable redeclares parameter", |
| 4804 | \\fn f(a : i32) void { | 4989 | \\fn f(a : i32) void { |
| 4805 | \\ const a = 0; | 4990 | \\ const a = 0; |
| 4806 | \\} | 4991 | \\} |
| 4807 | \\export fn entry() void { f(1); } | 4992 | \\export fn entry() void { f(1); } |
| 4808 | , &[_][]const u8{ | 4993 | , &[_][]const u8{ |
| 4809 | "tmp.zig:2:5: error: redeclaration of variable 'a'", | 4994 | "tmp.zig:2:11: error: redeclaration of parameter 'a'", |
| | 4995 | "tmp.zig:1:6: note: previous declaration here", |
| 4810 | }); | 4996 | }); |
| 4811 | | 4997 | |
| 4812 | cases.add("variable has wrong type", | 4998 | ctx.objErrStage1("variable has wrong type", |
| 4813 | \\export fn f() i32 { | 4999 | \\export fn f() i32 { |
| 4814 | \\ const a = "a"; | 5000 | \\ const a = "a"; |
| 4815 | \\ return a; | 5001 | \\ return a; |
| ... | @@ -4818,7 +5004,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -4818,7 +5004,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4818 | "tmp.zig:3:12: error: expected type 'i32', found '*const [1:0]u8'", | 5004 | "tmp.zig:3:12: error: expected type 'i32', found '*const [1:0]u8'", |
| 4819 | }); | 5005 | }); |
| 4820 | | 5006 | |
| 4821 | cases.add("if condition is bool, not int", | 5007 | ctx.objErrStage1("if condition is bool, not int", |
| 4822 | \\export fn f() void { | 5008 | \\export fn f() void { |
| 4823 | \\ if (0) {} | 5009 | \\ if (0) {} |
| 4824 | \\} | 5010 | \\} |
| ... | @@ -4826,7 +5012,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -4826,7 +5012,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4826 | "tmp.zig:2:9: error: expected type 'bool', found 'comptime_int'", | 5012 | "tmp.zig:2:9: error: expected type 'bool', found 'comptime_int'", |
| 4827 | }); | 5013 | }); |
| 4828 | | 5014 | |
| 4829 | cases.add("assign unreachable", | 5015 | ctx.objErrStage1("assign unreachable", |
| 4830 | \\export fn f() void { | 5016 | \\export fn f() void { |
| 4831 | \\ const a = return; | 5017 | \\ const a = return; |
| 4832 | \\} | 5018 | \\} |
| ... | @@ -4835,22 +5021,23 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -4835,22 +5021,23 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4835 | "tmp.zig:2:15: note: control flow is diverted here", | 5021 | "tmp.zig:2:15: note: control flow is diverted here", |
| 4836 | }); | 5022 | }); |
| 4837 | | 5023 | |
| 4838 | cases.add("unreachable variable", | 5024 | ctx.objErrStage1("unreachable variable", |
| 4839 | \\export fn f() void { | 5025 | \\export fn f() void { |
| 4840 | \\ const a: noreturn = {}; | 5026 | \\ const a: noreturn = {}; |
| | 5027 | \\ _ = a; |
| 4841 | \\} | 5028 | \\} |
| 4842 | , &[_][]const u8{ | 5029 | , &[_][]const u8{ |
| 4843 | "tmp.zig:2:25: error: expected type 'noreturn', found 'void'", | 5030 | "tmp.zig:2:25: error: expected type 'noreturn', found 'void'", |
| 4844 | }); | 5031 | }); |
| 4845 | | 5032 | |
| 4846 | cases.add("unreachable parameter", | 5033 | ctx.objErrStage1("unreachable parameter", |
| 4847 | \\fn f(a: noreturn) void {} | 5034 | \\fn f(a: noreturn) void { _ = a; } |
| 4848 | \\export fn entry() void { f(); } | 5035 | \\export fn entry() void { f(); } |
| 4849 | , &[_][]const u8{ | 5036 | , &[_][]const u8{ |
| 4850 | "tmp.zig:1:9: error: parameter of type 'noreturn' not allowed", | 5037 | "tmp.zig:1:9: error: parameter of type 'noreturn' not allowed", |
| 4851 | }); | 5038 | }); |
| 4852 | | 5039 | |
| 4853 | cases.add("assign to constant variable", | 5040 | ctx.objErrStage1("assign to constant variable", |
| 4854 | \\export fn f() void { | 5041 | \\export fn f() void { |
| 4855 | \\ const a = 3; | 5042 | \\ const a = 3; |
| 4856 | \\ a = 4; | 5043 | \\ a = 4; |
| ... | @@ -4859,7 +5046,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -4859,7 +5046,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4859 | "tmp.zig:3:9: error: cannot assign to constant", | 5046 | "tmp.zig:3:9: error: cannot assign to constant", |
| 4860 | }); | 5047 | }); |
| 4861 | | 5048 | |
| 4862 | cases.add("use of undeclared identifier", | 5049 | ctx.objErrStage1("use of undeclared identifier", |
| 4863 | \\export fn f() void { | 5050 | \\export fn f() void { |
| 4864 | \\ b = 3; | 5051 | \\ b = 3; |
| 4865 | \\} | 5052 | \\} |
| ... | @@ -4867,15 +5054,15 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -4867,15 +5054,15 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4867 | "tmp.zig:2:5: error: use of undeclared identifier 'b'", | 5054 | "tmp.zig:2:5: error: use of undeclared identifier 'b'", |
| 4868 | }); | 5055 | }); |
| 4869 | | 5056 | |
| 4870 | cases.add("const is a statement, not an expression", | 5057 | ctx.objErrStage1("const is a statement, not an expression", |
| 4871 | \\export fn f() void { | 5058 | \\export fn f() void { |
| 4872 | \\ (const a = 0); | 5059 | \\ (const a = 0); |
| 4873 | \\} | 5060 | \\} |
| 4874 | , &[_][]const u8{ | 5061 | , &[_][]const u8{ |
| 4875 | "tmp.zig:2:6: error: invalid token: 'const'", | 5062 | "tmp.zig:2:6: error: expected expression, found 'const'", |
| 4876 | }); | 5063 | }); |
| 4877 | | 5064 | |
| 4878 | cases.add("array access of undeclared identifier", | 5065 | ctx.objErrStage1("array access of undeclared identifier", |
| 4879 | \\export fn f() void { | 5066 | \\export fn f() void { |
| 4880 | \\ i[i] = i[i]; | 5067 | \\ i[i] = i[i]; |
| 4881 | \\} | 5068 | \\} |
| ... | @@ -4883,7 +5070,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -4883,7 +5070,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4883 | "tmp.zig:2:5: error: use of undeclared identifier 'i'", | 5070 | "tmp.zig:2:5: error: use of undeclared identifier 'i'", |
| 4884 | }); | 5071 | }); |
| 4885 | | 5072 | |
| 4886 | cases.add("array access of non array", | 5073 | ctx.objErrStage1("array access of non array", |
| 4887 | \\export fn f() void { | 5074 | \\export fn f() void { |
| 4888 | \\ var bad : bool = undefined; | 5075 | \\ var bad : bool = undefined; |
| 4889 | \\ bad[0] = bad[0]; | 5076 | \\ bad[0] = bad[0]; |
| ... | @@ -4897,7 +5084,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -4897,7 +5084,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4897 | "tmp.zig:7:12: error: array access of non-array type 'bool'", | 5084 | "tmp.zig:7:12: error: array access of non-array type 'bool'", |
| 4898 | }); | 5085 | }); |
| 4899 | | 5086 | |
| 4900 | cases.add("array access with non integer index", | 5087 | ctx.objErrStage1("array access with non integer index", |
| 4901 | \\export fn f() void { | 5088 | \\export fn f() void { |
| 4902 | \\ var array = "aoeu"; | 5089 | \\ var array = "aoeu"; |
| 4903 | \\ var bad = false; | 5090 | \\ var bad = false; |
| ... | @@ -4913,7 +5100,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -4913,7 +5100,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4913 | "tmp.zig:9:15: error: expected type 'usize', found 'bool'", | 5100 | "tmp.zig:9:15: error: expected type 'usize', found 'bool'", |
| 4914 | }); | 5101 | }); |
| 4915 | | 5102 | |
| 4916 | cases.add("write to const global variable", | 5103 | ctx.objErrStage1("write to const global variable", |
| 4917 | \\const x : i32 = 99; | 5104 | \\const x : i32 = 99; |
| 4918 | \\fn f() void { | 5105 | \\fn f() void { |
| 4919 | \\ x = 1; | 5106 | \\ x = 1; |
| ... | @@ -4923,58 +5110,64 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -4923,58 +5110,64 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4923 | "tmp.zig:3:9: error: cannot assign to constant", | 5110 | "tmp.zig:3:9: error: cannot assign to constant", |
| 4924 | }); | 5111 | }); |
| 4925 | | 5112 | |
| 4926 | cases.add("missing else clause", | 5113 | ctx.objErrStage1("missing else clause", |
| 4927 | \\fn f(b: bool) void { | 5114 | \\fn f(b: bool) void { |
| 4928 | \\ const x : i32 = if (b) h: { break :h 1; }; | 5115 | \\ const x : i32 = if (b) h: { break :h 1; }; |
| | 5116 | \\ _ = x; |
| 4929 | \\} | 5117 | \\} |
| 4930 | \\fn g(b: bool) void { | 5118 | \\fn g(b: bool) void { |
| 4931 | \\ const y = if (b) h: { break :h @as(i32, 1); }; | 5119 | \\ const y = if (b) h: { break :h @as(i32, 1); }; |
| | 5120 | \\ _ = y; |
| 4932 | \\} | 5121 | \\} |
| 4933 | \\export fn entry() void { f(true); g(true); } | 5122 | \\export fn entry() void { f(true); g(true); } |
| 4934 | , &[_][]const u8{ | 5123 | , &[_][]const u8{ |
| 4935 | "tmp.zig:2:21: error: expected type 'i32', found 'void'", | 5124 | "tmp.zig:2:21: error: expected type 'i32', found 'void'", |
| 4936 | "tmp.zig:5:15: error: incompatible types: 'i32' and 'void'", | 5125 | "tmp.zig:6:15: error: incompatible types: 'i32' and 'void'", |
| 4937 | }); | 5126 | }); |
| 4938 | | 5127 | |
| 4939 | cases.add("invalid struct field", | 5128 | ctx.objErrStage1("invalid struct field", |
| 4940 | \\const A = struct { x : i32, }; | 5129 | \\const A = struct { x : i32, }; |
| 4941 | \\export fn f() void { | 5130 | \\export fn f() void { |
| 4942 | \\ var a : A = undefined; | 5131 | \\ var a : A = undefined; |
| 4943 | \\ a.foo = 1; | 5132 | \\ a.foo = 1; |
| 4944 | \\ const y = a.bar; | 5133 | \\ const y = a.bar; |
| | 5134 | \\ _ = y; |
| 4945 | \\} | 5135 | \\} |
| 4946 | \\export fn g() void { | 5136 | \\export fn g() void { |
| 4947 | \\ var a : A = undefined; | 5137 | \\ var a : A = undefined; |
| 4948 | \\ const y = a.bar; | 5138 | \\ const y = a.bar; |
| | 5139 | \\ _ = y; |
| 4949 | \\} | 5140 | \\} |
| 4950 | , &[_][]const u8{ | 5141 | , &[_][]const u8{ |
| 4951 | "tmp.zig:4:6: error: no member named 'foo' in struct 'A'", | 5142 | "tmp.zig:4:6: error: no member named 'foo' in struct 'A'", |
| 4952 | "tmp.zig:9:16: error: no member named 'bar' in struct 'A'", | 5143 | "tmp.zig:10:16: error: no member named 'bar' in struct 'A'", |
| 4953 | }); | 5144 | }); |
| 4954 | | 5145 | |
| 4955 | cases.add("redefinition of struct", | 5146 | ctx.objErrStage1("redefinition of struct", |
| 4956 | \\const A = struct { x : i32, }; | 5147 | \\const A = struct { x : i32, }; |
| 4957 | \\const A = struct { y : i32, }; | 5148 | \\const A = struct { y : i32, }; |
| 4958 | , &[_][]const u8{ | 5149 | , &[_][]const u8{ |
| 4959 | "tmp.zig:2:1: error: redefinition of 'A'", | 5150 | "tmp.zig:2:1: error: redeclaration of 'A'", |
| | 5151 | "tmp.zig:1:1: note: other declaration here", |
| 4960 | }); | 5152 | }); |
| 4961 | | 5153 | |
| 4962 | cases.add("redefinition of enums", | 5154 | ctx.objErrStage1("redefinition of enums", |
| 4963 | \\const A = enum {}; | 5155 | \\const A = enum {x}; |
| 4964 | \\const A = enum {}; | 5156 | \\const A = enum {x}; |
| 4965 | , &[_][]const u8{ | 5157 | , &[_][]const u8{ |
| 4966 | "tmp.zig:2:1: error: redefinition of 'A'", | 5158 | "tmp.zig:2:1: error: redeclaration of 'A'", |
| | 5159 | "tmp.zig:1:1: note: other declaration here", |
| 4967 | }); | 5160 | }); |
| 4968 | | 5161 | |
| 4969 | cases.add("redefinition of global variables", | 5162 | ctx.objErrStage1("redefinition of global variables", |
| 4970 | \\var a : i32 = 1; | 5163 | \\var a : i32 = 1; |
| 4971 | \\var a : i32 = 2; | 5164 | \\var a : i32 = 2; |
| 4972 | , &[_][]const u8{ | 5165 | , &[_][]const u8{ |
| 4973 | "tmp.zig:2:1: error: redefinition of 'a'", | 5166 | "tmp.zig:2:1: error: redeclaration of 'a'", |
| 4974 | "tmp.zig:1:1: note: previous definition is here", | 5167 | "tmp.zig:1:1: note: other declaration here", |
| 4975 | }); | 5168 | }); |
| 4976 | | 5169 | |
| 4977 | cases.add("duplicate field in struct value expression", | 5170 | ctx.objErrStage1("duplicate field in struct value expression", |
| 4978 | \\const A = struct { | 5171 | \\const A = struct { |
| 4979 | \\ x : i32, | 5172 | \\ x : i32, |
| 4980 | \\ y : i32, | 5173 | \\ y : i32, |
| ... | @@ -4987,12 +5180,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -4987,12 +5180,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4987 | \\ .x = 3, | 5180 | \\ .x = 3, |
| 4988 | \\ .z = 4, | 5181 | \\ .z = 4, |
| 4989 | \\ }; | 5182 | \\ }; |
| | 5183 | \\ _ = a; |
| 4990 | \\} | 5184 | \\} |
| 4991 | , &[_][]const u8{ | 5185 | , &[_][]const u8{ |
| 4992 | "tmp.zig:11:9: error: duplicate field", | 5186 | "tmp.zig:11:9: error: duplicate field", |
| 4993 | }); | 5187 | }); |
| 4994 | | 5188 | |
| 4995 | cases.add("missing field in struct value expression", | 5189 | ctx.objErrStage1("missing field in struct value expression", |
| 4996 | \\const A = struct { | 5190 | \\const A = struct { |
| 4997 | \\ x : i32, | 5191 | \\ x : i32, |
| 4998 | \\ y : i32, | 5192 | \\ y : i32, |
| ... | @@ -5010,7 +5204,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -5010,7 +5204,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5010 | "tmp.zig:9:17: error: missing field: 'x'", | 5204 | "tmp.zig:9:17: error: missing field: 'x'", |
| 5011 | }); | 5205 | }); |
| 5012 | | 5206 | |
| 5013 | cases.add("invalid field in struct value expression", | 5207 | ctx.objErrStage1("invalid field in struct value expression", |
| 5014 | \\const A = struct { | 5208 | \\const A = struct { |
| 5015 | \\ x : i32, | 5209 | \\ x : i32, |
| 5016 | \\ y : i32, | 5210 | \\ y : i32, |
| ... | @@ -5022,12 +5216,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -5022,12 +5216,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5022 | \\ .y = 2, | 5216 | \\ .y = 2, |
| 5023 | \\ .foo = 42, | 5217 | \\ .foo = 42, |
| 5024 | \\ }; | 5218 | \\ }; |
| | 5219 | \\ _ = a; |
| 5025 | \\} | 5220 | \\} |
| 5026 | , &[_][]const u8{ | 5221 | , &[_][]const u8{ |
| 5027 | "tmp.zig:10:9: error: no member named 'foo' in struct 'A'", | 5222 | "tmp.zig:10:9: error: no member named 'foo' in struct 'A'", |
| 5028 | }); | 5223 | }); |
| 5029 | | 5224 | |
| 5030 | cases.add("invalid break expression", | 5225 | ctx.objErrStage1("invalid break expression", |
| 5031 | \\export fn f() void { | 5226 | \\export fn f() void { |
| 5032 | \\ break; | 5227 | \\ break; |
| 5033 | \\} | 5228 | \\} |
| ... | @@ -5035,7 +5230,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -5035,7 +5230,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5035 | "tmp.zig:2:5: error: break expression outside loop", | 5230 | "tmp.zig:2:5: error: break expression outside loop", |
| 5036 | }); | 5231 | }); |
| 5037 | | 5232 | |
| 5038 | cases.add("invalid continue expression", | 5233 | ctx.objErrStage1("invalid continue expression", |
| 5039 | \\export fn f() void { | 5234 | \\export fn f() void { |
| 5040 | \\ continue; | 5235 | \\ continue; |
| 5041 | \\} | 5236 | \\} |
| ... | @@ -5043,15 +5238,15 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -5043,15 +5238,15 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5043 | "tmp.zig:2:5: error: continue expression outside loop", | 5238 | "tmp.zig:2:5: error: continue expression outside loop", |
| 5044 | }); | 5239 | }); |
| 5045 | | 5240 | |
| 5046 | cases.add("invalid maybe type", | 5241 | ctx.objErrStage1("invalid maybe type", |
| 5047 | \\export fn f() void { | 5242 | \\export fn f() void { |
| 5048 | \\ if (true) |x| { } | 5243 | \\ if (true) |x| { _ = x; } |
| 5049 | \\} | 5244 | \\} |
| 5050 | , &[_][]const u8{ | 5245 | , &[_][]const u8{ |
| 5051 | "tmp.zig:2:9: error: expected optional type, found 'bool'", | 5246 | "tmp.zig:2:9: error: expected optional type, found 'bool'", |
| 5052 | }); | 5247 | }); |
| 5053 | | 5248 | |
| 5054 | cases.add("cast unreachable", | 5249 | ctx.objErrStage1("cast unreachable", |
| 5055 | \\fn f() i32 { | 5250 | \\fn f() i32 { |
| 5056 | \\ return @as(i32, return 1); | 5251 | \\ return @as(i32, return 1); |
| 5057 | \\} | 5252 | \\} |
| ... | @@ -5061,22 +5256,22 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -5061,22 +5256,22 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5061 | "tmp.zig:2:21: note: control flow is diverted here", | 5256 | "tmp.zig:2:21: note: control flow is diverted here", |
| 5062 | }); | 5257 | }); |
| 5063 | | 5258 | |
| 5064 | cases.add("invalid builtin fn", | 5259 | ctx.objErrStage1("invalid builtin fn", |
| 5065 | \\fn f() @bogus(foo) { | 5260 | \\fn f() @bogus(foo) { |
| 5066 | \\} | 5261 | \\} |
| 5067 | \\export fn entry() void { _ = f(); } | 5262 | \\export fn entry() void { _ = f(); } |
| 5068 | , &[_][]const u8{ | 5263 | , &[_][]const u8{ |
| 5069 | "tmp.zig:1:8: error: invalid builtin function: 'bogus'", | 5264 | "tmp.zig:1:8: error: invalid builtin function: '@bogus'", |
| 5070 | }); | 5265 | }); |
| 5071 | | 5266 | |
| 5072 | cases.add("noalias on non pointer param", | 5267 | ctx.objErrStage1("noalias on non pointer param", |
| 5073 | \\fn f(noalias x: i32) void {} | 5268 | \\fn f(noalias x: i32) void { _ = x; } |
| 5074 | \\export fn entry() void { f(1234); } | 5269 | \\export fn entry() void { f(1234); } |
| 5075 | , &[_][]const u8{ | 5270 | , &[_][]const u8{ |
| 5076 | "tmp.zig:1:6: error: noalias on non-pointer parameter", | 5271 | "tmp.zig:1:6: error: noalias on non-pointer parameter", |
| 5077 | }); | 5272 | }); |
| 5078 | | 5273 | |
| 5079 | cases.add("struct init syntax for array", | 5274 | ctx.objErrStage1("struct init syntax for array", |
| 5080 | \\const foo = [3]u16{ .x = 1024 }; | 5275 | \\const foo = [3]u16{ .x = 1024 }; |
| 5081 | \\comptime { | 5276 | \\comptime { |
| 5082 | \\ _ = foo; | 5277 | \\ _ = foo; |
| ... | @@ -5085,7 +5280,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -5085,7 +5280,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5085 | "tmp.zig:1:21: error: type '[3]u16' does not support struct initialization syntax", | 5280 | "tmp.zig:1:21: error: type '[3]u16' does not support struct initialization syntax", |
| 5086 | }); | 5281 | }); |
| 5087 | | 5282 | |
| 5088 | cases.add("type variables must be constant", | 5283 | ctx.objErrStage1("type variables must be constant", |
| 5089 | \\var foo = u8; | 5284 | \\var foo = u8; |
| 5090 | \\export fn entry() foo { | 5285 | \\export fn entry() foo { |
| 5091 | \\ return 1; | 5286 | \\ return 1; |
| ... | @@ -5094,12 +5289,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -5094,12 +5289,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5094 | "tmp.zig:1:1: error: variable of type 'type' must be constant", | 5289 | "tmp.zig:1:1: error: variable of type 'type' must be constant", |
| 5095 | }); | 5290 | }); |
| 5096 | | 5291 | |
| 5097 | cases.add("variables shadowing types", | 5292 | ctx.objErrStage1("variables shadowing types", |
| 5098 | \\const Foo = struct {}; | 5293 | \\const Foo = struct {}; |
| 5099 | \\const Bar = struct {}; | 5294 | \\const Bar = struct {}; |
| 5100 | \\ | 5295 | \\ |
| 5101 | \\fn f(Foo: i32) void { | 5296 | \\fn f(Foo: i32) void { |
| 5102 | \\ var Bar : i32 = undefined; | 5297 | \\ var Bar : i32 = undefined; |
| | 5298 | \\ _ = Bar; |
| 5103 | \\} | 5299 | \\} |
| 5104 | \\ | 5300 | \\ |
| 5105 | \\export fn entry() void { | 5301 | \\export fn entry() void { |
| ... | @@ -5112,7 +5308,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -5112,7 +5308,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5112 | "tmp.zig:2:1: note: previous definition is here", | 5308 | "tmp.zig:2:1: note: previous definition is here", |
| 5113 | }); | 5309 | }); |
| 5114 | | 5310 | |
| 5115 | cases.add("switch expression - missing enumeration prong", | 5311 | ctx.objErrStage1("switch expression - missing enumeration prong", |
| 5116 | \\const Number = enum { | 5312 | \\const Number = enum { |
| 5117 | \\ One, | 5313 | \\ One, |
| 5118 | \\ Two, | 5314 | \\ Two, |
| ... | @@ -5132,7 +5328,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -5132,7 +5328,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5132 | "tmp.zig:8:5: error: enumeration value 'Number.Four' not handled in switch", | 5328 | "tmp.zig:8:5: error: enumeration value 'Number.Four' not handled in switch", |
| 5133 | }); | 5329 | }); |
| 5134 | | 5330 | |
| 5135 | cases.add("switch expression - duplicate enumeration prong", | 5331 | ctx.objErrStage1("switch expression - duplicate enumeration prong", |
| 5136 | \\const Number = enum { | 5332 | \\const Number = enum { |
| 5137 | \\ One, | 5333 | \\ One, |
| 5138 | \\ Two, | 5334 | \\ Two, |
| ... | @@ -5155,7 +5351,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -5155,7 +5351,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5155 | "tmp.zig:10:15: note: other value is here", | 5351 | "tmp.zig:10:15: note: other value is here", |
| 5156 | }); | 5352 | }); |
| 5157 | | 5353 | |
| 5158 | cases.add("switch expression - duplicate enumeration prong when else present", | 5354 | ctx.objErrStage1("switch expression - duplicate enumeration prong when else present", |
| 5159 | \\const Number = enum { | 5355 | \\const Number = enum { |
| 5160 | \\ One, | 5356 | \\ One, |
| 5161 | \\ Two, | 5357 | \\ Two, |
| ... | @@ -5179,7 +5375,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -5179,7 +5375,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5179 | "tmp.zig:10:15: note: other value is here", | 5375 | "tmp.zig:10:15: note: other value is here", |
| 5180 | }); | 5376 | }); |
| 5181 | | 5377 | |
| 5182 | cases.add("switch expression - multiple else prongs", | 5378 | ctx.objErrStage1("switch expression - multiple else prongs", |
| 5183 | \\fn f(x: u32) void { | 5379 | \\fn f(x: u32) void { |
| 5184 | \\ const value: bool = switch (x) { | 5380 | \\ const value: bool = switch (x) { |
| 5185 | \\ 1234 => false, | 5381 | \\ 1234 => false, |
| ... | @@ -5194,7 +5390,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -5194,7 +5390,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5194 | "tmp.zig:5:9: error: multiple else prongs in switch expression", | 5390 | "tmp.zig:5:9: error: multiple else prongs in switch expression", |
| 5195 | }); | 5391 | }); |
| 5196 | | 5392 | |
| 5197 | cases.add("switch expression - non exhaustive integer prongs", | 5393 | ctx.objErrStage1("switch expression - non exhaustive integer prongs", |
| 5198 | \\fn foo(x: u8) void { | 5394 | \\fn foo(x: u8) void { |
| 5199 | \\ switch (x) { | 5395 | \\ switch (x) { |
| 5200 | \\ 0 => {}, | 5396 | \\ 0 => {}, |
| ... | @@ -5205,7 +5401,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -5205,7 +5401,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5205 | "tmp.zig:2:5: error: switch must handle all possibilities", | 5401 | "tmp.zig:2:5: error: switch must handle all possibilities", |
| 5206 | }); | 5402 | }); |
| 5207 | | 5403 | |
| 5208 | cases.add("switch expression - duplicate or overlapping integer value", | 5404 | ctx.objErrStage1("switch expression - duplicate or overlapping integer value", |
| 5209 | \\fn foo(x: u8) u8 { | 5405 | \\fn foo(x: u8) u8 { |
| 5210 | \\ return switch (x) { | 5406 | \\ return switch (x) { |
| 5211 | \\ 0 ... 100 => @as(u8, 0), | 5407 | \\ 0 ... 100 => @as(u8, 0), |
| ... | @@ -5220,8 +5416,9 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -5220,8 +5416,9 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5220 | "tmp.zig:5:14: note: previous value is here", | 5416 | "tmp.zig:5:14: note: previous value is here", |
| 5221 | }); | 5417 | }); |
| 5222 | | 5418 | |
| 5223 | cases.add("switch expression - duplicate type", | 5419 | ctx.objErrStage1("switch expression - duplicate type", |
| 5224 | \\fn foo(comptime T: type, x: T) u8 { | 5420 | \\fn foo(comptime T: type, x: T) u8 { |
| | 5421 | \\ _ = x; |
| 5225 | \\ return switch (T) { | 5422 | \\ return switch (T) { |
| 5226 | \\ u32 => 0, | 5423 | \\ u32 => 0, |
| 5227 | \\ u64 => 1, | 5424 | \\ u64 => 1, |
| ... | @@ -5231,16 +5428,17 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -5231,16 +5428,17 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5231 | \\} | 5428 | \\} |
| 5232 | \\export fn entry() usize { return @sizeOf(@TypeOf(foo(u32, 0))); } | 5429 | \\export fn entry() usize { return @sizeOf(@TypeOf(foo(u32, 0))); } |
| 5233 | , &[_][]const u8{ | 5430 | , &[_][]const u8{ |
| 5234 | "tmp.zig:5:9: error: duplicate switch value", | 5431 | "tmp.zig:6:9: error: duplicate switch value", |
| 5235 | "tmp.zig:3:9: note: previous value is here", | 5432 | "tmp.zig:4:9: note: previous value is here", |
| 5236 | }); | 5433 | }); |
| 5237 | | 5434 | |
| 5238 | cases.add("switch expression - duplicate type (struct alias)", | 5435 | ctx.objErrStage1("switch expression - duplicate type (struct alias)", |
| 5239 | \\const Test = struct { | 5436 | \\const Test = struct { |
| 5240 | \\ bar: i32, | 5437 | \\ bar: i32, |
| 5241 | \\}; | 5438 | \\}; |
| 5242 | \\const Test2 = Test; | 5439 | \\const Test2 = Test; |
| 5243 | \\fn foo(comptime T: type, x: T) u8 { | 5440 | \\fn foo(comptime T: type, x: T) u8 { |
| | 5441 | \\ _ = x; |
| 5244 | \\ return switch (T) { | 5442 | \\ return switch (T) { |
| 5245 | \\ Test => 0, | 5443 | \\ Test => 0, |
| 5246 | \\ u64 => 1, | 5444 | \\ u64 => 1, |
| ... | @@ -5250,11 +5448,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -5250,11 +5448,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5250 | \\} | 5448 | \\} |
| 5251 | \\export fn entry() usize { return @sizeOf(@TypeOf(foo(u32, 0))); } | 5449 | \\export fn entry() usize { return @sizeOf(@TypeOf(foo(u32, 0))); } |
| 5252 | , &[_][]const u8{ | 5450 | , &[_][]const u8{ |
| 5253 | "tmp.zig:9:9: error: duplicate switch value", | 5451 | "tmp.zig:10:9: error: duplicate switch value", |
| 5254 | "tmp.zig:7:9: note: previous value is here", | 5452 | "tmp.zig:8:9: note: previous value is here", |
| 5255 | }); | 5453 | }); |
| 5256 | | 5454 | |
| 5257 | cases.add("switch expression - switch on pointer type with no else", | 5455 | ctx.objErrStage1("switch expression - switch on pointer type with no else", |
| 5258 | \\fn foo(x: *u8) void { | 5456 | \\fn foo(x: *u8) void { |
| 5259 | \\ switch (x) { | 5457 | \\ switch (x) { |
| 5260 | \\ &y => {}, | 5458 | \\ &y => {}, |
| ... | @@ -5266,7 +5464,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -5266,7 +5464,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5266 | "tmp.zig:2:5: error: else prong required when switching on type '*u8'", | 5464 | "tmp.zig:2:5: error: else prong required when switching on type '*u8'", |
| 5267 | }); | 5465 | }); |
| 5268 | | 5466 | |
| 5269 | cases.add("global variable initializer must be constant expression", | 5467 | ctx.objErrStage1("global variable initializer must be constant expression", |
| 5270 | \\extern fn foo() i32; | 5468 | \\extern fn foo() i32; |
| 5271 | \\const x = foo(); | 5469 | \\const x = foo(); |
| 5272 | \\export fn entry() i32 { return x; } | 5470 | \\export fn entry() i32 { return x; } |
| ... | @@ -5274,7 +5472,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -5274,7 +5472,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5274 | "tmp.zig:2:11: error: unable to evaluate constant expression", | 5472 | "tmp.zig:2:11: error: unable to evaluate constant expression", |
| 5275 | }); | 5473 | }); |
| 5276 | | 5474 | |
| 5277 | cases.add("array concatenation with wrong type", | 5475 | ctx.objErrStage1("array concatenation with wrong type", |
| 5278 | \\const src = "aoeu"; | 5476 | \\const src = "aoeu"; |
| 5279 | \\const derp: usize = 1234; | 5477 | \\const derp: usize = 1234; |
| 5280 | \\const a = derp ++ "foo"; | 5478 | \\const a = derp ++ "foo"; |
| ... | @@ -5284,7 +5482,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -5284,7 +5482,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5284 | "tmp.zig:3:11: error: expected array, found 'usize'", | 5482 | "tmp.zig:3:11: error: expected array, found 'usize'", |
| 5285 | }); | 5483 | }); |
| 5286 | | 5484 | |
| 5287 | cases.add("non compile time array concatenation", | 5485 | ctx.objErrStage1("non compile time array concatenation", |
| 5288 | \\fn f() []u8 { | 5486 | \\fn f() []u8 { |
| 5289 | \\ return s ++ "foo"; | 5487 | \\ return s ++ "foo"; |
| 5290 | \\} | 5488 | \\} |
| ... | @@ -5294,7 +5492,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -5294,7 +5492,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5294 | "tmp.zig:2:12: error: unable to evaluate constant expression", | 5492 | "tmp.zig:2:12: error: unable to evaluate constant expression", |
| 5295 | }); | 5493 | }); |
| 5296 | | 5494 | |
| 5297 | cases.add("@cImport with bogus include", | 5495 | ctx.objErrStage1("@cImport with bogus include", |
| 5298 | \\const c = @cImport(@cInclude("bogus.h")); | 5496 | \\const c = @cImport(@cInclude("bogus.h")); |
| 5299 | \\export fn entry() usize { return @sizeOf(@TypeOf(c.bogo)); } | 5497 | \\export fn entry() usize { return @sizeOf(@TypeOf(c.bogo)); } |
| 5300 | , &[_][]const u8{ | 5498 | , &[_][]const u8{ |
| ... | @@ -5302,7 +5500,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -5302,7 +5500,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5302 | ".h:1:10: note: 'bogus.h' file not found", | 5500 | ".h:1:10: note: 'bogus.h' file not found", |
| 5303 | }); | 5501 | }); |
| 5304 | | 5502 | |
| 5305 | cases.add("address of number literal", | 5503 | ctx.objErrStage1("address of number literal", |
| 5306 | \\const x = 3; | 5504 | \\const x = 3; |
| 5307 | \\const y = &x; | 5505 | \\const y = &x; |
| 5308 | \\fn foo() *const i32 { return y; } | 5506 | \\fn foo() *const i32 { return y; } |
| ... | @@ -5311,14 +5509,14 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -5311,14 +5509,14 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5311 | "tmp.zig:3:30: error: expected type '*const i32', found '*const comptime_int'", | 5509 | "tmp.zig:3:30: error: expected type '*const i32', found '*const comptime_int'", |
| 5312 | }); | 5510 | }); |
| 5313 | | 5511 | |
| 5314 | cases.add("integer overflow error", | 5512 | ctx.objErrStage1("integer overflow error", |
| 5315 | \\const x : u8 = 300; | 5513 | \\const x : u8 = 300; |
| 5316 | \\export fn entry() usize { return @sizeOf(@TypeOf(x)); } | 5514 | \\export fn entry() usize { return @sizeOf(@TypeOf(x)); } |
| 5317 | , &[_][]const u8{ | 5515 | , &[_][]const u8{ |
| 5318 | "tmp.zig:1:16: error: integer value 300 cannot be coerced to type 'u8'", | 5516 | "tmp.zig:1:16: error: integer value 300 cannot be coerced to type 'u8'", |
| 5319 | }); | 5517 | }); |
| 5320 | | 5518 | |
| 5321 | cases.add("invalid shift amount error", | 5519 | ctx.objErrStage1("invalid shift amount error", |
| 5322 | \\const x : u8 = 2; | 5520 | \\const x : u8 = 2; |
| 5323 | \\fn f() u16 { | 5521 | \\fn f() u16 { |
| 5324 | \\ return x << 8; | 5522 | \\ return x << 8; |
| ... | @@ -5328,7 +5526,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -5328,7 +5526,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5328 | "tmp.zig:3:17: error: integer value 8 cannot be coerced to type 'u3'", | 5526 | "tmp.zig:3:17: error: integer value 8 cannot be coerced to type 'u3'", |
| 5329 | }); | 5527 | }); |
| 5330 | | 5528 | |
| 5331 | cases.add("missing function call param", | 5529 | ctx.objErrStage1("missing function call param", |
| 5332 | \\const Foo = struct { | 5530 | \\const Foo = struct { |
| 5333 | \\ a: i32, | 5531 | \\ a: i32, |
| 5334 | \\ b: i32, | 5532 | \\ b: i32, |
| ... | @@ -5349,6 +5547,8 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -5349,6 +5547,8 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5349 | \\ | 5547 | \\ |
| 5350 | \\fn f(foo: *const Foo, index: usize) void { | 5548 | \\fn f(foo: *const Foo, index: usize) void { |
| 5351 | \\ const result = members[index](); | 5549 | \\ const result = members[index](); |
| | 5550 | \\ _ = foo; |
| | 5551 | \\ _ = result; |
| 5352 | \\} | 5552 | \\} |
| 5353 | \\ | 5553 | \\ |
| 5354 | \\export fn entry() usize { return @sizeOf(@TypeOf(f)); } | 5554 | \\export fn entry() usize { return @sizeOf(@TypeOf(f)); } |
| ... | @@ -5356,21 +5556,21 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -5356,21 +5556,21 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5356 | "tmp.zig:20:34: error: expected 1 argument(s), found 0", | 5556 | "tmp.zig:20:34: error: expected 1 argument(s), found 0", |
| 5357 | }); | 5557 | }); |
| 5358 | | 5558 | |
| 5359 | cases.add("missing function name", | 5559 | ctx.objErrStage1("missing function name", |
| 5360 | \\fn () void {} | 5560 | \\fn () void {} |
| 5361 | \\export fn entry() usize { return @sizeOf(@TypeOf(f)); } | 5561 | \\export fn entry() usize { return @sizeOf(@TypeOf(f)); } |
| 5362 | , &[_][]const u8{ | 5562 | , &[_][]const u8{ |
| 5363 | "tmp.zig:1:1: error: missing function name", | 5563 | "tmp.zig:1:1: error: missing function name", |
| 5364 | }); | 5564 | }); |
| 5365 | | 5565 | |
| 5366 | cases.add("missing param name", | 5566 | ctx.objErrStage1("missing param name", |
| 5367 | \\fn f(i32) void {} | 5567 | \\fn f(i32) void {} |
| 5368 | \\export fn entry() usize { return @sizeOf(@TypeOf(f)); } | 5568 | \\export fn entry() usize { return @sizeOf(@TypeOf(f)); } |
| 5369 | , &[_][]const u8{ | 5569 | , &[_][]const u8{ |
| 5370 | "tmp.zig:1:6: error: missing parameter name", | 5570 | "tmp.zig:1:6: error: missing parameter name", |
| 5371 | }); | 5571 | }); |
| 5372 | | 5572 | |
| 5373 | cases.add("wrong function type", | 5573 | ctx.objErrStage1("wrong function type", |
| 5374 | \\const fns = [_]fn() void { a, b, c }; | 5574 | \\const fns = [_]fn() void { a, b, c }; |
| 5375 | \\fn a() i32 {return 0;} | 5575 | \\fn a() i32 {return 0;} |
| 5376 | \\fn b() i32 {return 1;} | 5576 | \\fn b() i32 {return 1;} |
| ... | @@ -5380,7 +5580,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -5380,7 +5580,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5380 | "tmp.zig:1:28: error: expected type 'fn() void', found 'fn() i32'", | 5580 | "tmp.zig:1:28: error: expected type 'fn() void', found 'fn() i32'", |
| 5381 | }); | 5581 | }); |
| 5382 | | 5582 | |
| 5383 | cases.add("extern function pointer mismatch", | 5583 | ctx.objErrStage1("extern function pointer mismatch", |
| 5384 | \\const fns = [_](fn(i32)i32) { a, b, c }; | 5584 | \\const fns = [_](fn(i32)i32) { a, b, c }; |
| 5385 | \\pub fn a(x: i32) i32 {return x + 0;} | 5585 | \\pub fn a(x: i32) i32 {return x + 0;} |
| 5386 | \\pub fn b(x: i32) i32 {return x + 1;} | 5586 | \\pub fn b(x: i32) i32 {return x + 1;} |
| ... | @@ -5391,15 +5591,16 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -5391,15 +5591,16 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5391 | "tmp.zig:1:37: error: expected type 'fn(i32) i32', found 'fn(i32) callconv(.C) i32'", | 5591 | "tmp.zig:1:37: error: expected type 'fn(i32) i32', found 'fn(i32) callconv(.C) i32'", |
| 5392 | }); | 5592 | }); |
| 5393 | | 5593 | |
| 5394 | cases.add("colliding invalid top level functions", | 5594 | ctx.objErrStage1("colliding invalid top level functions", |
| 5395 | \\fn func() bogus {} | 5595 | \\fn func() bogus {} |
| 5396 | \\fn func() bogus {} | 5596 | \\fn func() bogus {} |
| 5397 | \\export fn entry() usize { return @sizeOf(@TypeOf(func)); } | 5597 | \\export fn entry() usize { return @sizeOf(@TypeOf(func)); } |
| 5398 | , &[_][]const u8{ | 5598 | , &[_][]const u8{ |
| 5399 | "tmp.zig:2:1: error: redefinition of 'func'", | 5599 | "tmp.zig:2:1: error: redeclaration of 'func'", |
| | 5600 | "tmp.zig:1:1: note: other declaration here", |
| 5400 | }); | 5601 | }); |
| 5401 | | 5602 | |
| 5402 | cases.add("non constant expression in array size", | 5603 | ctx.objErrStage1("non constant expression in array size", |
| 5403 | \\const Foo = struct { | 5604 | \\const Foo = struct { |
| 5404 | \\ y: [get()]u8, | 5605 | \\ y: [get()]u8, |
| 5405 | \\}; | 5606 | \\}; |
| ... | @@ -5412,7 +5613,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -5412,7 +5613,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5412 | "tmp.zig:2:12: note: called from here", | 5613 | "tmp.zig:2:12: note: called from here", |
| 5413 | }); | 5614 | }); |
| 5414 | | 5615 | |
| 5415 | cases.add("addition with non numbers", | 5616 | ctx.objErrStage1("addition with non numbers", |
| 5416 | \\const Foo = struct { | 5617 | \\const Foo = struct { |
| 5417 | \\ field: i32, | 5618 | \\ field: i32, |
| 5418 | \\}; | 5619 | \\}; |
| ... | @@ -5423,7 +5624,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -5423,7 +5624,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5423 | "tmp.zig:4:28: error: invalid operands to binary expression: 'Foo' and 'Foo'", | 5624 | "tmp.zig:4:28: error: invalid operands to binary expression: 'Foo' and 'Foo'", |
| 5424 | }); | 5625 | }); |
| 5425 | | 5626 | |
| 5426 | cases.add("division by zero", | 5627 | ctx.objErrStage1("division by zero", |
| 5427 | \\const lit_int_x = 1 / 0; | 5628 | \\const lit_int_x = 1 / 0; |
| 5428 | \\const lit_float_x = 1.0 / 0.0; | 5629 | \\const lit_float_x = 1.0 / 0.0; |
| 5429 | \\const int_x = @as(u32, 1) / @as(u32, 0); | 5630 | \\const int_x = @as(u32, 1) / @as(u32, 0); |
| ... | @@ -5440,7 +5641,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -5440,7 +5641,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5440 | "tmp.zig:4:31: error: division by zero", | 5641 | "tmp.zig:4:31: error: division by zero", |
| 5441 | }); | 5642 | }); |
| 5442 | | 5643 | |
| 5443 | cases.add("normal string with newline", | 5644 | ctx.objErrStage1("normal string with newline", |
| 5444 | \\const foo = "a | 5645 | \\const foo = "a |
| 5445 | \\b"; | 5646 | \\b"; |
| 5446 | \\ | 5647 | \\ |
| ... | @@ -5449,7 +5650,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -5449,7 +5650,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5449 | "tmp.zig:1:15: error: newline not allowed in string literal", | 5650 | "tmp.zig:1:15: error: newline not allowed in string literal", |
| 5450 | }); | 5651 | }); |
| 5451 | | 5652 | |
| 5452 | cases.add("invalid comparison for function pointers", | 5653 | ctx.objErrStage1("invalid comparison for function pointers", |
| 5453 | \\fn foo() void {} | 5654 | \\fn foo() void {} |
| 5454 | \\const invalid = foo > foo; | 5655 | \\const invalid = foo > foo; |
| 5455 | \\ | 5656 | \\ |
| ... | @@ -5458,7 +5659,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -5458,7 +5659,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5458 | "tmp.zig:2:21: error: operator not allowed for type 'fn() void'", | 5659 | "tmp.zig:2:21: error: operator not allowed for type 'fn() void'", |
| 5459 | }); | 5660 | }); |
| 5460 | | 5661 | |
| 5461 | cases.add("generic function instance with non-constant expression", | 5662 | ctx.objErrStage1("generic function instance with non-constant expression", |
| 5462 | \\fn foo(comptime x: i32, y: i32) i32 { return x + y; } | 5663 | \\fn foo(comptime x: i32, y: i32) i32 { return x + y; } |
| 5463 | \\fn test1(a: i32, b: i32) i32 { | 5664 | \\fn test1(a: i32, b: i32) i32 { |
| 5464 | \\ return foo(a, b); | 5665 | \\ return foo(a, b); |
| ... | @@ -5469,7 +5670,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -5469,7 +5670,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5469 | "tmp.zig:3:16: error: runtime value cannot be passed to comptime arg", | 5670 | "tmp.zig:3:16: error: runtime value cannot be passed to comptime arg", |
| 5470 | }); | 5671 | }); |
| 5471 | | 5672 | |
| 5472 | cases.add("assign null to non-optional pointer", | 5673 | ctx.objErrStage1("assign null to non-optional pointer", |
| 5473 | \\const a: *u8 = null; | 5674 | \\const a: *u8 = null; |
| 5474 | \\ | 5675 | \\ |
| 5475 | \\export fn entry() usize { return @sizeOf(@TypeOf(a)); } | 5676 | \\export fn entry() usize { return @sizeOf(@TypeOf(a)); } |
| ... | @@ -5477,26 +5678,28 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -5477,26 +5678,28 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5477 | "tmp.zig:1:16: error: expected type '*u8', found '(null)'", | 5678 | "tmp.zig:1:16: error: expected type '*u8', found '(null)'", |
| 5478 | }); | 5679 | }); |
| 5479 | | 5680 | |
| 5480 | cases.add("indexing an array of size zero", | 5681 | ctx.objErrStage1("indexing an array of size zero", |
| 5481 | \\const array = [_]u8{}; | 5682 | \\const array = [_]u8{}; |
| 5482 | \\export fn foo() void { | 5683 | \\export fn foo() void { |
| 5483 | \\ const pointer = &array[0]; | 5684 | \\ const pointer = &array[0]; |
| | 5685 | \\ _ = pointer; |
| 5484 | \\} | 5686 | \\} |
| 5485 | , &[_][]const u8{ | 5687 | , &[_][]const u8{ |
| 5486 | "tmp.zig:3:27: error: accessing a zero length array is not allowed", | 5688 | "tmp.zig:3:27: error: accessing a zero length array is not allowed", |
| 5487 | }); | 5689 | }); |
| 5488 | | 5690 | |
| 5489 | cases.add("indexing an array of size zero with runtime index", | 5691 | ctx.objErrStage1("indexing an array of size zero with runtime index", |
| 5490 | \\const array = [_]u8{}; | 5692 | \\const array = [_]u8{}; |
| 5491 | \\export fn foo() void { | 5693 | \\export fn foo() void { |
| 5492 | \\ var index: usize = 0; | 5694 | \\ var index: usize = 0; |
| 5493 | \\ const pointer = &array[index]; | 5695 | \\ const pointer = &array[index]; |
| | 5696 | \\ _ = pointer; |
| 5494 | \\} | 5697 | \\} |
| 5495 | , &[_][]const u8{ | 5698 | , &[_][]const u8{ |
| 5496 | "tmp.zig:4:27: error: accessing a zero length array is not allowed", | 5699 | "tmp.zig:4:27: error: accessing a zero length array is not allowed", |
| 5497 | }); | 5700 | }); |
| 5498 | | 5701 | |
| 5499 | cases.add("compile time division by zero", | 5702 | ctx.objErrStage1("compile time division by zero", |
| 5500 | \\const y = foo(0); | 5703 | \\const y = foo(0); |
| 5501 | \\fn foo(x: u32) u32 { | 5704 | \\fn foo(x: u32) u32 { |
| 5502 | \\ return 1 / x; | 5705 | \\ return 1 / x; |
| ... | @@ -5508,7 +5711,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -5508,7 +5711,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5508 | "tmp.zig:1:14: note: referenced here", | 5711 | "tmp.zig:1:14: note: referenced here", |
| 5509 | }); | 5712 | }); |
| 5510 | | 5713 | |
| 5511 | cases.add("branch on undefined value", | 5714 | ctx.objErrStage1("branch on undefined value", |
| 5512 | \\const x = if (undefined) true else false; | 5715 | \\const x = if (undefined) true else false; |
| 5513 | \\ | 5716 | \\ |
| 5514 | \\export fn entry() usize { return @sizeOf(@TypeOf(x)); } | 5717 | \\export fn entry() usize { return @sizeOf(@TypeOf(x)); } |
| ... | @@ -5516,7 +5719,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -5516,7 +5719,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5516 | "tmp.zig:1:15: error: use of undefined value here causes undefined behavior", | 5719 | "tmp.zig:1:15: error: use of undefined value here causes undefined behavior", |
| 5517 | }); | 5720 | }); |
| 5518 | | 5721 | |
| 5519 | cases.add("div on undefined value", | 5722 | ctx.objErrStage1("div on undefined value", |
| 5520 | \\comptime { | 5723 | \\comptime { |
| 5521 | \\ var a: i64 = undefined; | 5724 | \\ var a: i64 = undefined; |
| 5522 | \\ _ = a / a; | 5725 | \\ _ = a / a; |
| ... | @@ -5525,7 +5728,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -5525,7 +5728,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5525 | "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", | 5728 | "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", |
| 5526 | }); | 5729 | }); |
| 5527 | | 5730 | |
| 5528 | cases.add("div assign on undefined value", | 5731 | ctx.objErrStage1("div assign on undefined value", |
| 5529 | \\comptime { | 5732 | \\comptime { |
| 5530 | \\ var a: i64 = undefined; | 5733 | \\ var a: i64 = undefined; |
| 5531 | \\ a /= a; | 5734 | \\ a /= a; |
| ... | @@ -5534,7 +5737,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -5534,7 +5737,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5534 | "tmp.zig:3:5: error: use of undefined value here causes undefined behavior", | 5737 | "tmp.zig:3:5: error: use of undefined value here causes undefined behavior", |
| 5535 | }); | 5738 | }); |
| 5536 | | 5739 | |
| 5537 | cases.add("mod on undefined value", | 5740 | ctx.objErrStage1("mod on undefined value", |
| 5538 | \\comptime { | 5741 | \\comptime { |
| 5539 | \\ var a: i64 = undefined; | 5742 | \\ var a: i64 = undefined; |
| 5540 | \\ _ = a % a; | 5743 | \\ _ = a % a; |
| ... | @@ -5543,7 +5746,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -5543,7 +5746,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5543 | "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", | 5746 | "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", |
| 5544 | }); | 5747 | }); |
| 5545 | | 5748 | |
| 5546 | cases.add("mod assign on undefined value", | 5749 | ctx.objErrStage1("mod assign on undefined value", |
| 5547 | \\comptime { | 5750 | \\comptime { |
| 5548 | \\ var a: i64 = undefined; | 5751 | \\ var a: i64 = undefined; |
| 5549 | \\ a %= a; | 5752 | \\ a %= a; |
| ... | @@ -5552,7 +5755,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -5552,7 +5755,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5552 | "tmp.zig:3:5: error: use of undefined value here causes undefined behavior", | 5755 | "tmp.zig:3:5: error: use of undefined value here causes undefined behavior", |
| 5553 | }); | 5756 | }); |
| 5554 | | 5757 | |
| 5555 | cases.add("add on undefined value", | 5758 | ctx.objErrStage1("add on undefined value", |
| 5556 | \\comptime { | 5759 | \\comptime { |
| 5557 | \\ var a: i64 = undefined; | 5760 | \\ var a: i64 = undefined; |
| 5558 | \\ _ = a + a; | 5761 | \\ _ = a + a; |
| ... | @@ -5561,7 +5764,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -5561,7 +5764,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5561 | "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", | 5764 | "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", |
| 5562 | }); | 5765 | }); |
| 5563 | | 5766 | |
| 5564 | cases.add("add assign on undefined value", | 5767 | ctx.objErrStage1("add assign on undefined value", |
| 5565 | \\comptime { | 5768 | \\comptime { |
| 5566 | \\ var a: i64 = undefined; | 5769 | \\ var a: i64 = undefined; |
| 5567 | \\ a += a; | 5770 | \\ a += a; |
| ... | @@ -5570,7 +5773,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -5570,7 +5773,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5570 | "tmp.zig:3:5: error: use of undefined value here causes undefined behavior", | 5773 | "tmp.zig:3:5: error: use of undefined value here causes undefined behavior", |
| 5571 | }); | 5774 | }); |
| 5572 | | 5775 | |
| 5573 | cases.add("add wrap on undefined value", | 5776 | ctx.objErrStage1("add wrap on undefined value", |
| 5574 | \\comptime { | 5777 | \\comptime { |
| 5575 | \\ var a: i64 = undefined; | 5778 | \\ var a: i64 = undefined; |
| 5576 | \\ _ = a +% a; | 5779 | \\ _ = a +% a; |
| ... | @@ -5579,7 +5782,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -5579,7 +5782,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5579 | "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", | 5782 | "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", |
| 5580 | }); | 5783 | }); |
| 5581 | | 5784 | |
| 5582 | cases.add("add wrap assign on undefined value", | 5785 | ctx.objErrStage1("add wrap assign on undefined value", |
| 5583 | \\comptime { | 5786 | \\comptime { |
| 5584 | \\ var a: i64 = undefined; | 5787 | \\ var a: i64 = undefined; |
| 5585 | \\ a +%= a; | 5788 | \\ a +%= a; |
| ... | @@ -5588,7 +5791,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -5588,7 +5791,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5588 | "tmp.zig:3:5: error: use of undefined value here causes undefined behavior", | 5791 | "tmp.zig:3:5: error: use of undefined value here causes undefined behavior", |
| 5589 | }); | 5792 | }); |
| 5590 | | 5793 | |
| 5591 | cases.add("sub on undefined value", | 5794 | ctx.objErrStage1("sub on undefined value", |
| 5592 | \\comptime { | 5795 | \\comptime { |
| 5593 | \\ var a: i64 = undefined; | 5796 | \\ var a: i64 = undefined; |
| 5594 | \\ _ = a - a; | 5797 | \\ _ = a - a; |
| ... | @@ -5597,7 +5800,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -5597,7 +5800,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5597 | "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", | 5800 | "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", |
| 5598 | }); | 5801 | }); |
| 5599 | | 5802 | |
| 5600 | cases.add("sub assign on undefined value", | 5803 | ctx.objErrStage1("sub assign on undefined value", |
| 5601 | \\comptime { | 5804 | \\comptime { |
| 5602 | \\ var a: i64 = undefined; | 5805 | \\ var a: i64 = undefined; |
| 5603 | \\ a -= a; | 5806 | \\ a -= a; |
| ... | @@ -5606,7 +5809,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -5606,7 +5809,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5606 | "tmp.zig:3:5: error: use of undefined value here causes undefined behavior", | 5809 | "tmp.zig:3:5: error: use of undefined value here causes undefined behavior", |
| 5607 | }); | 5810 | }); |
| 5608 | | 5811 | |
| 5609 | cases.add("sub wrap on undefined value", | 5812 | ctx.objErrStage1("sub wrap on undefined value", |
| 5610 | \\comptime { | 5813 | \\comptime { |
| 5611 | \\ var a: i64 = undefined; | 5814 | \\ var a: i64 = undefined; |
| 5612 | \\ _ = a -% a; | 5815 | \\ _ = a -% a; |
| ... | @@ -5615,7 +5818,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -5615,7 +5818,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5615 | "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", | 5818 | "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", |
| 5616 | }); | 5819 | }); |
| 5617 | | 5820 | |
| 5618 | cases.add("sub wrap assign on undefined value", | 5821 | ctx.objErrStage1("sub wrap assign on undefined value", |
| 5619 | \\comptime { | 5822 | \\comptime { |
| 5620 | \\ var a: i64 = undefined; | 5823 | \\ var a: i64 = undefined; |
| 5621 | \\ a -%= a; | 5824 | \\ a -%= a; |
| ... | @@ -5624,7 +5827,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -5624,7 +5827,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5624 | "tmp.zig:3:5: error: use of undefined value here causes undefined behavior", | 5827 | "tmp.zig:3:5: error: use of undefined value here causes undefined behavior", |
| 5625 | }); | 5828 | }); |
| 5626 | | 5829 | |
| 5627 | cases.add("mult on undefined value", | 5830 | ctx.objErrStage1("mult on undefined value", |
| 5628 | \\comptime { | 5831 | \\comptime { |
| 5629 | \\ var a: i64 = undefined; | 5832 | \\ var a: i64 = undefined; |
| 5630 | \\ _ = a * a; | 5833 | \\ _ = a * a; |
| ... | @@ -5633,7 +5836,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -5633,7 +5836,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5633 | "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", | 5836 | "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", |
| 5634 | }); | 5837 | }); |
| 5635 | | 5838 | |
| 5636 | cases.add("mult assign on undefined value", | 5839 | ctx.objErrStage1("mult assign on undefined value", |
| 5637 | \\comptime { | 5840 | \\comptime { |
| 5638 | \\ var a: i64 = undefined; | 5841 | \\ var a: i64 = undefined; |
| 5639 | \\ a *= a; | 5842 | \\ a *= a; |
| ... | @@ -5642,7 +5845,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -5642,7 +5845,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5642 | "tmp.zig:3:5: error: use of undefined value here causes undefined behavior", | 5845 | "tmp.zig:3:5: error: use of undefined value here causes undefined behavior", |
| 5643 | }); | 5846 | }); |
| 5644 | | 5847 | |
| 5645 | cases.add("mult wrap on undefined value", | 5848 | ctx.objErrStage1("mult wrap on undefined value", |
| 5646 | \\comptime { | 5849 | \\comptime { |
| 5647 | \\ var a: i64 = undefined; | 5850 | \\ var a: i64 = undefined; |
| 5648 | \\ _ = a *% a; | 5851 | \\ _ = a *% a; |
| ... | @@ -5651,7 +5854,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -5651,7 +5854,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5651 | "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", | 5854 | "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", |
| 5652 | }); | 5855 | }); |
| 5653 | | 5856 | |
| 5654 | cases.add("mult wrap assign on undefined value", | 5857 | ctx.objErrStage1("mult wrap assign on undefined value", |
| 5655 | \\comptime { | 5858 | \\comptime { |
| 5656 | \\ var a: i64 = undefined; | 5859 | \\ var a: i64 = undefined; |
| 5657 | \\ a *%= a; | 5860 | \\ a *%= a; |
| ... | @@ -5660,7 +5863,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -5660,7 +5863,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5660 | "tmp.zig:3:5: error: use of undefined value here causes undefined behavior", | 5863 | "tmp.zig:3:5: error: use of undefined value here causes undefined behavior", |
| 5661 | }); | 5864 | }); |
| 5662 | | 5865 | |
| 5663 | cases.add("shift left on undefined value", | 5866 | ctx.objErrStage1("shift left on undefined value", |
| 5664 | \\comptime { | 5867 | \\comptime { |
| 5665 | \\ var a: i64 = undefined; | 5868 | \\ var a: i64 = undefined; |
| 5666 | \\ _ = a << 2; | 5869 | \\ _ = a << 2; |
| ... | @@ -5669,7 +5872,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -5669,7 +5872,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5669 | "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", | 5872 | "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", |
| 5670 | }); | 5873 | }); |
| 5671 | | 5874 | |
| 5672 | cases.add("shift left assign on undefined value", | 5875 | ctx.objErrStage1("shift left assign on undefined value", |
| 5673 | \\comptime { | 5876 | \\comptime { |
| 5674 | \\ var a: i64 = undefined; | 5877 | \\ var a: i64 = undefined; |
| 5675 | \\ a <<= 2; | 5878 | \\ a <<= 2; |
| ... | @@ -5678,7 +5881,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -5678,7 +5881,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5678 | "tmp.zig:3:5: error: use of undefined value here causes undefined behavior", | 5881 | "tmp.zig:3:5: error: use of undefined value here causes undefined behavior", |
| 5679 | }); | 5882 | }); |
| 5680 | | 5883 | |
| 5681 | cases.add("shift right on undefined value", | 5884 | ctx.objErrStage1("shift right on undefined value", |
| 5682 | \\comptime { | 5885 | \\comptime { |
| 5683 | \\ var a: i64 = undefined; | 5886 | \\ var a: i64 = undefined; |
| 5684 | \\ _ = a >> 2; | 5887 | \\ _ = a >> 2; |
| ... | @@ -5687,7 +5890,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -5687,7 +5890,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5687 | "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", | 5890 | "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", |
| 5688 | }); | 5891 | }); |
| 5689 | | 5892 | |
| 5690 | cases.add("shift left assign on undefined value", | 5893 | ctx.objErrStage1("shift left assign on undefined value", |
| 5691 | \\comptime { | 5894 | \\comptime { |
| 5692 | \\ var a: i64 = undefined; | 5895 | \\ var a: i64 = undefined; |
| 5693 | \\ a >>= 2; | 5896 | \\ a >>= 2; |
| ... | @@ -5696,7 +5899,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -5696,7 +5899,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5696 | "tmp.zig:3:5: error: use of undefined value here causes undefined behavior", | 5899 | "tmp.zig:3:5: error: use of undefined value here causes undefined behavior", |
| 5697 | }); | 5900 | }); |
| 5698 | | 5901 | |
| 5699 | cases.add("bin and on undefined value", | 5902 | ctx.objErrStage1("bin and on undefined value", |
| 5700 | \\comptime { | 5903 | \\comptime { |
| 5701 | \\ var a: i64 = undefined; | 5904 | \\ var a: i64 = undefined; |
| 5702 | \\ _ = a & a; | 5905 | \\ _ = a & a; |
| ... | @@ -5705,7 +5908,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -5705,7 +5908,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5705 | "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", | 5908 | "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", |
| 5706 | }); | 5909 | }); |
| 5707 | | 5910 | |
| 5708 | cases.add("bin and assign on undefined value", | 5911 | ctx.objErrStage1("bin and assign on undefined value", |
| 5709 | \\comptime { | 5912 | \\comptime { |
| 5710 | \\ var a: i64 = undefined; | 5913 | \\ var a: i64 = undefined; |
| 5711 | \\ a &= a; | 5914 | \\ a &= a; |
| ... | @@ -5714,7 +5917,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -5714,7 +5917,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5714 | "tmp.zig:3:5: error: use of undefined value here causes undefined behavior", | 5917 | "tmp.zig:3:5: error: use of undefined value here causes undefined behavior", |
| 5715 | }); | 5918 | }); |
| 5716 | | 5919 | |
| 5717 | cases.add("bin or on undefined value", | 5920 | ctx.objErrStage1("bin or on undefined value", |
| 5718 | \\comptime { | 5921 | \\comptime { |
| 5719 | \\ var a: i64 = undefined; | 5922 | \\ var a: i64 = undefined; |
| 5720 | \\ _ = a | a; | 5923 | \\ _ = a | a; |
| ... | @@ -5723,7 +5926,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -5723,7 +5926,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5723 | "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", | 5926 | "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", |
| 5724 | }); | 5927 | }); |
| 5725 | | 5928 | |
| 5726 | cases.add("bin or assign on undefined value", | 5929 | ctx.objErrStage1("bin or assign on undefined value", |
| 5727 | \\comptime { | 5930 | \\comptime { |
| 5728 | \\ var a: i64 = undefined; | 5931 | \\ var a: i64 = undefined; |
| 5729 | \\ a |= a; | 5932 | \\ a |= a; |
| ... | @@ -5732,7 +5935,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -5732,7 +5935,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5732 | "tmp.zig:3:5: error: use of undefined value here causes undefined behavior", | 5935 | "tmp.zig:3:5: error: use of undefined value here causes undefined behavior", |
| 5733 | }); | 5936 | }); |
| 5734 | | 5937 | |
| 5735 | cases.add("bin xor on undefined value", | 5938 | ctx.objErrStage1("bin xor on undefined value", |
| 5736 | \\comptime { | 5939 | \\comptime { |
| 5737 | \\ var a: i64 = undefined; | 5940 | \\ var a: i64 = undefined; |
| 5738 | \\ _ = a ^ a; | 5941 | \\ _ = a ^ a; |
| ... | @@ -5741,7 +5944,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -5741,7 +5944,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5741 | "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", | 5944 | "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", |
| 5742 | }); | 5945 | }); |
| 5743 | | 5946 | |
| 5744 | cases.add("bin xor assign on undefined value", | 5947 | ctx.objErrStage1("bin xor assign on undefined value", |
| 5745 | \\comptime { | 5948 | \\comptime { |
| 5746 | \\ var a: i64 = undefined; | 5949 | \\ var a: i64 = undefined; |
| 5747 | \\ a ^= a; | 5950 | \\ a ^= a; |
| ... | @@ -5750,7 +5953,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -5750,7 +5953,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5750 | "tmp.zig:3:5: error: use of undefined value here causes undefined behavior", | 5953 | "tmp.zig:3:5: error: use of undefined value here causes undefined behavior", |
| 5751 | }); | 5954 | }); |
| 5752 | | 5955 | |
| 5753 | cases.add("comparison operators with undefined value", | 5956 | ctx.objErrStage1("comparison operators with undefined value", |
| 5754 | \\// operator == | 5957 | \\// operator == |
| 5755 | \\comptime { | 5958 | \\comptime { |
| 5756 | \\ var a: i64 = undefined; | 5959 | \\ var a: i64 = undefined; |
| ... | @@ -5796,7 +5999,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -5796,7 +5999,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5796 | "tmp.zig:35:11: error: use of undefined value here causes undefined behavior", | 5999 | "tmp.zig:35:11: error: use of undefined value here causes undefined behavior", |
| 5797 | }); | 6000 | }); |
| 5798 | | 6001 | |
| 5799 | cases.add("and on undefined value", | 6002 | ctx.objErrStage1("and on undefined value", |
| 5800 | \\comptime { | 6003 | \\comptime { |
| 5801 | \\ var a: bool = undefined; | 6004 | \\ var a: bool = undefined; |
| 5802 | \\ _ = a and a; | 6005 | \\ _ = a and a; |
| ... | @@ -5805,7 +6008,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -5805,7 +6008,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5805 | "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", | 6008 | "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", |
| 5806 | }); | 6009 | }); |
| 5807 | | 6010 | |
| 5808 | cases.add("or on undefined value", | 6011 | ctx.objErrStage1("or on undefined value", |
| 5809 | \\comptime { | 6012 | \\comptime { |
| 5810 | \\ var a: bool = undefined; | 6013 | \\ var a: bool = undefined; |
| 5811 | \\ _ = a or a; | 6014 | \\ _ = a or a; |
| ... | @@ -5814,7 +6017,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -5814,7 +6017,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5814 | "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", | 6017 | "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", |
| 5815 | }); | 6018 | }); |
| 5816 | | 6019 | |
| 5817 | cases.add("negate on undefined value", | 6020 | ctx.objErrStage1("negate on undefined value", |
| 5818 | \\comptime { | 6021 | \\comptime { |
| 5819 | \\ var a: i64 = undefined; | 6022 | \\ var a: i64 = undefined; |
| 5820 | \\ _ = -a; | 6023 | \\ _ = -a; |
| ... | @@ -5823,7 +6026,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -5823,7 +6026,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5823 | "tmp.zig:3:10: error: use of undefined value here causes undefined behavior", | 6026 | "tmp.zig:3:10: error: use of undefined value here causes undefined behavior", |
| 5824 | }); | 6027 | }); |
| 5825 | | 6028 | |
| 5826 | cases.add("negate wrap on undefined value", | 6029 | ctx.objErrStage1("negate wrap on undefined value", |
| 5827 | \\comptime { | 6030 | \\comptime { |
| 5828 | \\ var a: i64 = undefined; | 6031 | \\ var a: i64 = undefined; |
| 5829 | \\ _ = -%a; | 6032 | \\ _ = -%a; |
| ... | @@ -5832,7 +6035,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -5832,7 +6035,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5832 | "tmp.zig:3:11: error: use of undefined value here causes undefined behavior", | 6035 | "tmp.zig:3:11: error: use of undefined value here causes undefined behavior", |
| 5833 | }); | 6036 | }); |
| 5834 | | 6037 | |
| 5835 | cases.add("bin not on undefined value", | 6038 | ctx.objErrStage1("bin not on undefined value", |
| 5836 | \\comptime { | 6039 | \\comptime { |
| 5837 | \\ var a: i64 = undefined; | 6040 | \\ var a: i64 = undefined; |
| 5838 | \\ _ = ~a; | 6041 | \\ _ = ~a; |
| ... | @@ -5841,7 +6044,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -5841,7 +6044,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5841 | "tmp.zig:3:10: error: use of undefined value here causes undefined behavior", | 6044 | "tmp.zig:3:10: error: use of undefined value here causes undefined behavior", |
| 5842 | }); | 6045 | }); |
| 5843 | | 6046 | |
| 5844 | cases.add("bool not on undefined value", | 6047 | ctx.objErrStage1("bool not on undefined value", |
| 5845 | \\comptime { | 6048 | \\comptime { |
| 5846 | \\ var a: bool = undefined; | 6049 | \\ var a: bool = undefined; |
| 5847 | \\ _ = !a; | 6050 | \\ _ = !a; |
| ... | @@ -5850,7 +6053,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -5850,7 +6053,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5850 | "tmp.zig:3:10: error: use of undefined value here causes undefined behavior", | 6053 | "tmp.zig:3:10: error: use of undefined value here causes undefined behavior", |
| 5851 | }); | 6054 | }); |
| 5852 | | 6055 | |
| 5853 | cases.add("orelse on undefined value", | 6056 | ctx.objErrStage1("orelse on undefined value", |
| 5854 | \\comptime { | 6057 | \\comptime { |
| 5855 | \\ var a: ?bool = undefined; | 6058 | \\ var a: ?bool = undefined; |
| 5856 | \\ _ = a orelse false; | 6059 | \\ _ = a orelse false; |
| ... | @@ -5859,16 +6062,16 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -5859,16 +6062,16 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5859 | "tmp.zig:3:11: error: use of undefined value here causes undefined behavior", | 6062 | "tmp.zig:3:11: error: use of undefined value here causes undefined behavior", |
| 5860 | }); | 6063 | }); |
| 5861 | | 6064 | |
| 5862 | cases.add("catch on undefined value", | 6065 | ctx.objErrStage1("catch on undefined value", |
| 5863 | \\comptime { | 6066 | \\comptime { |
| 5864 | \\ var a: anyerror!bool = undefined; | 6067 | \\ var a: anyerror!bool = undefined; |
| 5865 | \\ _ = a catch |err| false; | 6068 | \\ _ = a catch false; |
| 5866 | \\} | 6069 | \\} |
| 5867 | , &[_][]const u8{ | 6070 | , &[_][]const u8{ |
| 5868 | "tmp.zig:3:11: error: use of undefined value here causes undefined behavior", | 6071 | "tmp.zig:3:11: error: use of undefined value here causes undefined behavior", |
| 5869 | }); | 6072 | }); |
| 5870 | | 6073 | |
| 5871 | cases.add("deref on undefined value", | 6074 | ctx.objErrStage1("deref on undefined value", |
| 5872 | \\comptime { | 6075 | \\comptime { |
| 5873 | \\ var a: *u8 = undefined; | 6076 | \\ var a: *u8 = undefined; |
| 5874 | \\ _ = a.*; | 6077 | \\ _ = a.*; |
| ... | @@ -5877,7 +6080,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -5877,7 +6080,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5877 | "tmp.zig:3:9: error: attempt to dereference undefined value", | 6080 | "tmp.zig:3:9: error: attempt to dereference undefined value", |
| 5878 | }); | 6081 | }); |
| 5879 | | 6082 | |
| 5880 | cases.add("endless loop in function evaluation", | 6083 | ctx.objErrStage1("endless loop in function evaluation", |
| 5881 | \\const seventh_fib_number = fibbonaci(7); | 6084 | \\const seventh_fib_number = fibbonaci(7); |
| 5882 | \\fn fibbonaci(x: i32) i32 { | 6085 | \\fn fibbonaci(x: i32) i32 { |
| 5883 | \\ return fibbonaci(x - 1) + fibbonaci(x - 2); | 6086 | \\ return fibbonaci(x - 1) + fibbonaci(x - 2); |
| ... | @@ -5890,16 +6093,15 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -5890,16 +6093,15 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5890 | "tmp.zig:6:50: note: referenced here", | 6093 | "tmp.zig:6:50: note: referenced here", |
| 5891 | }); | 6094 | }); |
| 5892 | | 6095 | |
| 5893 | cases.add("@embedFile with bogus file", | 6096 | ctx.objErrStage1("@embedFile with bogus file", |
| 5894 | \\const resource = @embedFile("bogus.txt",); | 6097 | \\const resource = @embedFile("bogus.txt",); |
| 5895 | \\ | 6098 | \\ |
| 5896 | \\export fn entry() usize { return @sizeOf(@TypeOf(resource)); } | 6099 | \\export fn entry() usize { return @sizeOf(@TypeOf(resource)); } |
| 5897 | , &[_][]const u8{ | 6100 | , &[_][]const u8{ |
| 5898 | "tmp.zig:1:29: error: unable to find '", | 6101 | "tmp.zig:1:29: error: unable to find 'bogus.txt'", |
| 5899 | "bogus.txt'", | | |
| 5900 | }); | 6102 | }); |
| 5901 | | 6103 | |
| 5902 | cases.add("non-const expression in struct literal outside function", | 6104 | ctx.objErrStage1("non-const expression in struct literal outside function", |
| 5903 | \\const Foo = struct { | 6105 | \\const Foo = struct { |
| 5904 | \\ x: i32, | 6106 | \\ x: i32, |
| 5905 | \\}; | 6107 | \\}; |
| ... | @@ -5911,7 +6113,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -5911,7 +6113,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5911 | "tmp.zig:4:21: error: unable to evaluate constant expression", | 6113 | "tmp.zig:4:21: error: unable to evaluate constant expression", |
| 5912 | }); | 6114 | }); |
| 5913 | | 6115 | |
| 5914 | cases.add("non-const expression function call with struct return value outside function", | 6116 | ctx.objErrStage1("non-const expression function call with struct return value outside function", |
| 5915 | \\const Foo = struct { | 6117 | \\const Foo = struct { |
| 5916 | \\ x: i32, | 6118 | \\ x: i32, |
| 5917 | \\}; | 6119 | \\}; |
| ... | @@ -5928,7 +6130,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -5928,7 +6130,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5928 | "tmp.zig:4:17: note: referenced here", | 6130 | "tmp.zig:4:17: note: referenced here", |
| 5929 | }); | 6131 | }); |
| 5930 | | 6132 | |
| 5931 | cases.add("undeclared identifier error should mark fn as impure", | 6133 | ctx.objErrStage1("undeclared identifier error should mark fn as impure", |
| 5932 | \\export fn foo() void { | 6134 | \\export fn foo() void { |
| 5933 | \\ test_a_thing(); | 6135 | \\ test_a_thing(); |
| 5934 | \\} | 6136 | \\} |
| ... | @@ -5939,7 +6141,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -5939,7 +6141,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5939 | "tmp.zig:5:5: error: use of undeclared identifier 'bad_fn_call'", | 6141 | "tmp.zig:5:5: error: use of undeclared identifier 'bad_fn_call'", |
| 5940 | }); | 6142 | }); |
| 5941 | | 6143 | |
| 5942 | cases.add("illegal comparison of types", | 6144 | ctx.objErrStage1("illegal comparison of types", |
| 5943 | \\fn bad_eql_1(a: []u8, b: []u8) bool { | 6145 | \\fn bad_eql_1(a: []u8, b: []u8) bool { |
| 5944 | \\ return a == b; | 6146 | \\ return a == b; |
| 5945 | \\} | 6147 | \\} |
| ... | @@ -5958,13 +6160,14 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -5958,13 +6160,14 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5958 | "tmp.zig:9:16: error: operator not allowed for type 'EnumWithData'", | 6160 | "tmp.zig:9:16: error: operator not allowed for type 'EnumWithData'", |
| 5959 | }); | 6161 | }); |
| 5960 | | 6162 | |
| 5961 | cases.add("non-const switch number literal", | 6163 | ctx.objErrStage1("non-const switch number literal", |
| 5962 | \\export fn foo() void { | 6164 | \\export fn foo() void { |
| 5963 | \\ const x = switch (bar()) { | 6165 | \\ const x = switch (bar()) { |
| 5964 | \\ 1, 2 => 1, | 6166 | \\ 1, 2 => 1, |
| 5965 | \\ 3, 4 => 2, | 6167 | \\ 3, 4 => 2, |
| 5966 | \\ else => 3, | 6168 | \\ else => 3, |
| 5967 | \\ }; | 6169 | \\ }; |
| | 6170 | \\ _ = x; |
| 5968 | \\} | 6171 | \\} |
| 5969 | \\fn bar() i32 { | 6172 | \\fn bar() i32 { |
| 5970 | \\ return 2; | 6173 | \\ return 2; |
| ... | @@ -5973,7 +6176,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -5973,7 +6176,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5973 | "tmp.zig:5:17: error: cannot store runtime value in type 'comptime_int'", | 6176 | "tmp.zig:5:17: error: cannot store runtime value in type 'comptime_int'", |
| 5974 | }); | 6177 | }); |
| 5975 | | 6178 | |
| 5976 | cases.add("atomic orderings of cmpxchg - failure stricter than success", | 6179 | ctx.objErrStage1("atomic orderings of cmpxchg - failure stricter than success", |
| 5977 | \\const AtomicOrder = @import("std").builtin.AtomicOrder; | 6180 | \\const AtomicOrder = @import("std").builtin.AtomicOrder; |
| 5978 | \\export fn f() void { | 6181 | \\export fn f() void { |
| 5979 | \\ var x: i32 = 1234; | 6182 | \\ var x: i32 = 1234; |
| ... | @@ -5983,7 +6186,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -5983,7 +6186,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5983 | "tmp.zig:4:81: error: failure atomic ordering must be no stricter than success", | 6186 | "tmp.zig:4:81: error: failure atomic ordering must be no stricter than success", |
| 5984 | }); | 6187 | }); |
| 5985 | | 6188 | |
| 5986 | cases.add("atomic orderings of cmpxchg - success Monotonic or stricter", | 6189 | ctx.objErrStage1("atomic orderings of cmpxchg - success Monotonic or stricter", |
| 5987 | \\const AtomicOrder = @import("std").builtin.AtomicOrder; | 6190 | \\const AtomicOrder = @import("std").builtin.AtomicOrder; |
| 5988 | \\export fn f() void { | 6191 | \\export fn f() void { |
| 5989 | \\ var x: i32 = 1234; | 6192 | \\ var x: i32 = 1234; |
| ... | @@ -5993,7 +6196,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -5993,7 +6196,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5993 | "tmp.zig:4:58: error: success atomic ordering must be Monotonic or stricter", | 6196 | "tmp.zig:4:58: error: success atomic ordering must be Monotonic or stricter", |
| 5994 | }); | 6197 | }); |
| 5995 | | 6198 | |
| 5996 | cases.add("negation overflow in function evaluation", | 6199 | ctx.objErrStage1("negation overflow in function evaluation", |
| 5997 | \\const y = neg(-128); | 6200 | \\const y = neg(-128); |
| 5998 | \\fn neg(x: i8) i8 { | 6201 | \\fn neg(x: i8) i8 { |
| 5999 | \\ return -x; | 6202 | \\ return -x; |
| ... | @@ -6005,7 +6208,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -6005,7 +6208,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6005 | "tmp.zig:1:14: note: referenced here", | 6208 | "tmp.zig:1:14: note: referenced here", |
| 6006 | }); | 6209 | }); |
| 6007 | | 6210 | |
| 6008 | cases.add("add overflow in function evaluation", | 6211 | ctx.objErrStage1("add overflow in function evaluation", |
| 6009 | \\const y = add(65530, 10); | 6212 | \\const y = add(65530, 10); |
| 6010 | \\fn add(a: u16, b: u16) u16 { | 6213 | \\fn add(a: u16, b: u16) u16 { |
| 6011 | \\ return a + b; | 6214 | \\ return a + b; |
| ... | @@ -6017,7 +6220,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -6017,7 +6220,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6017 | "tmp.zig:1:14: note: referenced here", | 6220 | "tmp.zig:1:14: note: referenced here", |
| 6018 | }); | 6221 | }); |
| 6019 | | 6222 | |
| 6020 | cases.add("sub overflow in function evaluation", | 6223 | ctx.objErrStage1("sub overflow in function evaluation", |
| 6021 | \\const y = sub(10, 20); | 6224 | \\const y = sub(10, 20); |
| 6022 | \\fn sub(a: u16, b: u16) u16 { | 6225 | \\fn sub(a: u16, b: u16) u16 { |
| 6023 | \\ return a - b; | 6226 | \\ return a - b; |
| ... | @@ -6029,7 +6232,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -6029,7 +6232,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6029 | "tmp.zig:1:14: note: referenced here", | 6232 | "tmp.zig:1:14: note: referenced here", |
| 6030 | }); | 6233 | }); |
| 6031 | | 6234 | |
| 6032 | cases.add("mul overflow in function evaluation", | 6235 | ctx.objErrStage1("mul overflow in function evaluation", |
| 6033 | \\const y = mul(300, 6000); | 6236 | \\const y = mul(300, 6000); |
| 6034 | \\fn mul(a: u16, b: u16) u16 { | 6237 | \\fn mul(a: u16, b: u16) u16 { |
| 6035 | \\ return a * b; | 6238 | \\ return a * b; |
| ... | @@ -6041,7 +6244,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -6041,7 +6244,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6041 | "tmp.zig:1:14: note: referenced here", | 6244 | "tmp.zig:1:14: note: referenced here", |
| 6042 | }); | 6245 | }); |
| 6043 | | 6246 | |
| 6044 | cases.add("truncate sign mismatch", | 6247 | ctx.objErrStage1("truncate sign mismatch", |
| 6045 | \\export fn entry1() i8 { | 6248 | \\export fn entry1() i8 { |
| 6046 | \\ var x: u32 = 10; | 6249 | \\ var x: u32 = 10; |
| 6047 | \\ return @truncate(i8, x); | 6250 | \\ return @truncate(i8, x); |
| ... | @@ -6065,7 +6268,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -6065,7 +6268,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6065 | "tmp.zig:15:26: error: expected unsigned integer type, found 'i32'", | 6268 | "tmp.zig:15:26: error: expected unsigned integer type, found 'i32'", |
| 6066 | }); | 6269 | }); |
| 6067 | | 6270 | |
| 6068 | cases.add("try in function with non error return type", | 6271 | ctx.objErrStage1("try in function with non error return type", |
| 6069 | \\export fn f() void { | 6272 | \\export fn f() void { |
| 6070 | \\ try something(); | 6273 | \\ try something(); |
| 6071 | \\} | 6274 | \\} |
| ... | @@ -6074,7 +6277,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -6074,7 +6277,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6074 | "tmp.zig:2:5: error: expected type 'void', found 'anyerror'", | 6277 | "tmp.zig:2:5: error: expected type 'void', found 'anyerror'", |
| 6075 | }); | 6278 | }); |
| 6076 | | 6279 | |
| 6077 | cases.add("invalid pointer for var type", | 6280 | ctx.objErrStage1("invalid pointer for var type", |
| 6078 | \\extern fn ext() usize; | 6281 | \\extern fn ext() usize; |
| 6079 | \\var bytes: [ext()]u8 = undefined; | 6282 | \\var bytes: [ext()]u8 = undefined; |
| 6080 | \\export fn f() void { | 6283 | \\export fn f() void { |
| ... | @@ -6086,7 +6289,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -6086,7 +6289,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6086 | "tmp.zig:2:13: error: unable to evaluate constant expression", | 6289 | "tmp.zig:2:13: error: unable to evaluate constant expression", |
| 6087 | }); | 6290 | }); |
| 6088 | | 6291 | |
| 6089 | cases.add("export function with comptime parameter", | 6292 | ctx.objErrStage1("export function with comptime parameter", |
| 6090 | \\export fn foo(comptime x: i32, y: i32) i32{ | 6293 | \\export fn foo(comptime x: i32, y: i32) i32{ |
| 6091 | \\ return x + y; | 6294 | \\ return x + y; |
| 6092 | \\} | 6295 | \\} |
| ... | @@ -6094,7 +6297,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -6094,7 +6297,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6094 | "tmp.zig:1:15: error: comptime parameter not allowed in function with calling convention 'C'", | 6297 | "tmp.zig:1:15: error: comptime parameter not allowed in function with calling convention 'C'", |
| 6095 | }); | 6298 | }); |
| 6096 | | 6299 | |
| 6097 | cases.add("extern function with comptime parameter", | 6300 | ctx.objErrStage1("extern function with comptime parameter", |
| 6098 | \\extern fn foo(comptime x: i32, y: i32) i32; | 6301 | \\extern fn foo(comptime x: i32, y: i32) i32; |
| 6099 | \\fn f() i32 { | 6302 | \\fn f() i32 { |
| 6100 | \\ return foo(1, 2); | 6303 | \\ return foo(1, 2); |
| ... | @@ -6104,7 +6307,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -6104,7 +6307,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6104 | "tmp.zig:1:15: error: comptime parameter not allowed in function with calling convention 'C'", | 6307 | "tmp.zig:1:15: error: comptime parameter not allowed in function with calling convention 'C'", |
| 6105 | }); | 6308 | }); |
| 6106 | | 6309 | |
| 6107 | cases.add("non-pure function returns type", | 6310 | ctx.objErrStage1("non-pure function returns type", |
| 6108 | \\var a: u32 = 0; | 6311 | \\var a: u32 = 0; |
| 6109 | \\pub fn List(comptime T: type) type { | 6312 | \\pub fn List(comptime T: type) type { |
| 6110 | \\ a += 1; | 6313 | \\ a += 1; |
| ... | @@ -6128,7 +6331,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -6128,7 +6331,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6128 | "tmp.zig:16:19: note: referenced here", | 6331 | "tmp.zig:16:19: note: referenced here", |
| 6129 | }); | 6332 | }); |
| 6130 | | 6333 | |
| 6131 | cases.add("bogus method call on slice", | 6334 | ctx.objErrStage1("bogus method call on slice", |
| 6132 | \\var self = "aoeu"; | 6335 | \\var self = "aoeu"; |
| 6133 | \\fn f(m: []const u8) void { | 6336 | \\fn f(m: []const u8) void { |
| 6134 | \\ m.copy(u8, self[0..], m); | 6337 | \\ m.copy(u8, self[0..], m); |
| ... | @@ -6138,9 +6341,9 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -6138,9 +6341,9 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6138 | "tmp.zig:3:6: error: no member named 'copy' in '[]const u8'", | 6341 | "tmp.zig:3:6: error: no member named 'copy' in '[]const u8'", |
| 6139 | }); | 6342 | }); |
| 6140 | | 6343 | |
| 6141 | cases.add("wrong number of arguments for method fn call", | 6344 | ctx.objErrStage1("wrong number of arguments for method fn call", |
| 6142 | \\const Foo = struct { | 6345 | \\const Foo = struct { |
| 6143 | \\ fn method(self: *const Foo, a: i32) void {} | 6346 | \\ fn method(self: *const Foo, a: i32) void {_ = self; _ = a;} |
| 6144 | \\}; | 6347 | \\}; |
| 6145 | \\fn f(foo: *const Foo) void { | 6348 | \\fn f(foo: *const Foo) void { |
| 6146 | \\ | 6349 | \\ |
| ... | @@ -6151,7 +6354,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -6151,7 +6354,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6151 | "tmp.zig:6:15: error: expected 2 argument(s), found 3", | 6354 | "tmp.zig:6:15: error: expected 2 argument(s), found 3", |
| 6152 | }); | 6355 | }); |
| 6153 | | 6356 | |
| 6154 | cases.add("assign through constant pointer", | 6357 | ctx.objErrStage1("assign through constant pointer", |
| 6155 | \\export fn f() void { | 6358 | \\export fn f() void { |
| 6156 | \\ var cstr = "Hat"; | 6359 | \\ var cstr = "Hat"; |
| 6157 | \\ cstr[0] = 'W'; | 6360 | \\ cstr[0] = 'W'; |
| ... | @@ -6160,7 +6363,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -6160,7 +6363,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6160 | "tmp.zig:3:13: error: cannot assign to constant", | 6363 | "tmp.zig:3:13: error: cannot assign to constant", |
| 6161 | }); | 6364 | }); |
| 6162 | | 6365 | |
| 6163 | cases.add("assign through constant slice", | 6366 | ctx.objErrStage1("assign through constant slice", |
| 6164 | \\export fn f() void { | 6367 | \\export fn f() void { |
| 6165 | \\ var cstr: []const u8 = "Hat"; | 6368 | \\ var cstr: []const u8 = "Hat"; |
| 6166 | \\ cstr[0] = 'W'; | 6369 | \\ cstr[0] = 'W'; |
| ... | @@ -6169,13 +6372,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -6169,13 +6372,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6169 | "tmp.zig:3:13: error: cannot assign to constant", | 6372 | "tmp.zig:3:13: error: cannot assign to constant", |
| 6170 | }); | 6373 | }); |
| 6171 | | 6374 | |
| 6172 | cases.add("main function with bogus args type", | 6375 | ctx.objErrStage1("main function with bogus args type", |
| 6173 | \\pub fn main(args: [][]bogus) !void {} | 6376 | \\pub fn main(args: [][]bogus) !void {_ = args;} |
| 6174 | , &[_][]const u8{ | 6377 | , &[_][]const u8{ |
| 6175 | "tmp.zig:1:23: error: use of undeclared identifier 'bogus'", | 6378 | "tmp.zig:1:23: error: use of undeclared identifier 'bogus'", |
| 6176 | }); | 6379 | }); |
| 6177 | | 6380 | |
| 6178 | cases.add("misspelled type with pointer only reference", | 6381 | ctx.objErrStage1("misspelled type with pointer only reference", |
| 6179 | \\const JasonHM = u8; | 6382 | \\const JasonHM = u8; |
| 6180 | \\const JasonList = *JsonNode; | 6383 | \\const JasonList = *JsonNode; |
| 6181 | \\ | 6384 | \\ |
| ... | @@ -6203,6 +6406,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -6203,6 +6406,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6203 | \\ var jll: JasonList = undefined; | 6406 | \\ var jll: JasonList = undefined; |
| 6204 | \\ jll.init(1234); | 6407 | \\ jll.init(1234); |
| 6205 | \\ var jd = JsonNode {.kind = JsonType.JSONArray , .jobject = JsonOA.JSONArray {jll} }; | 6408 | \\ var jd = JsonNode {.kind = JsonType.JSONArray , .jobject = JsonOA.JSONArray {jll} }; |
| | 6409 | \\ _ = jd; |
| 6206 | \\} | 6410 | \\} |
| 6207 | \\ | 6411 | \\ |
| 6208 | \\export fn entry() usize { return @sizeOf(@TypeOf(foo)); } | 6412 | \\export fn entry() usize { return @sizeOf(@TypeOf(foo)); } |
| ... | @@ -6210,7 +6414,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -6210,7 +6414,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6210 | "tmp.zig:5:16: error: use of undeclared identifier 'JsonList'", | 6414 | "tmp.zig:5:16: error: use of undeclared identifier 'JsonList'", |
| 6211 | }); | 6415 | }); |
| 6212 | | 6416 | |
| 6213 | cases.add("method call with first arg type primitive", | 6417 | ctx.objErrStage1("method call with first arg type primitive", |
| 6214 | \\const Foo = struct { | 6418 | \\const Foo = struct { |
| 6215 | \\ x: i32, | 6419 | \\ x: i32, |
| 6216 | \\ | 6420 | \\ |
| ... | @@ -6230,7 +6434,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -6230,7 +6434,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6230 | "tmp.zig:14:5: error: expected type 'i32', found 'Foo'", | 6434 | "tmp.zig:14:5: error: expected type 'i32', found 'Foo'", |
| 6231 | }); | 6435 | }); |
| 6232 | | 6436 | |
| 6233 | cases.add("method call with first arg type wrong container", | 6437 | ctx.objErrStage1("method call with first arg type wrong container", |
| 6234 | \\pub const List = struct { | 6438 | \\pub const List = struct { |
| 6235 | \\ len: usize, | 6439 | \\ len: usize, |
| 6236 | \\ allocator: *Allocator, | 6440 | \\ allocator: *Allocator, |
| ... | @@ -6259,7 +6463,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -6259,7 +6463,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6259 | "tmp.zig:23:5: error: expected type '*Allocator', found '*List'", | 6463 | "tmp.zig:23:5: error: expected type '*Allocator', found '*List'", |
| 6260 | }); | 6464 | }); |
| 6261 | | 6465 | |
| 6262 | cases.add("binary not on number literal", | 6466 | ctx.objErrStage1("binary not on number literal", |
| 6263 | \\const TINY_QUANTUM_SHIFT = 4; | 6467 | \\const TINY_QUANTUM_SHIFT = 4; |
| 6264 | \\const TINY_QUANTUM_SIZE = 1 << TINY_QUANTUM_SHIFT; | 6468 | \\const TINY_QUANTUM_SIZE = 1 << TINY_QUANTUM_SHIFT; |
| 6265 | \\var block_aligned_stuff: usize = (4 + TINY_QUANTUM_SIZE) & ~(TINY_QUANTUM_SIZE - 1); | 6469 | \\var block_aligned_stuff: usize = (4 + TINY_QUANTUM_SIZE) & ~(TINY_QUANTUM_SIZE - 1); |
| ... | @@ -6269,8 +6473,15 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -6269,8 +6473,15 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6269 | "tmp.zig:3:60: error: unable to perform binary not operation on type 'comptime_int'", | 6473 | "tmp.zig:3:60: error: unable to perform binary not operation on type 'comptime_int'", |
| 6270 | }); | 6474 | }); |
| 6271 | | 6475 | |
| 6272 | cases.addCase(x: { | 6476 | { |
| 6273 | const tc = cases.create("multiple files with private function error", | 6477 | const case = ctx.obj("multiple files with private function error", .{}); |
| | 6478 | case.backend = .stage1; |
| | 6479 | |
| | 6480 | case.addSourceFile("foo.zig", |
| | 6481 | \\fn privateFunction() void { } |
| | 6482 | ); |
| | 6483 | |
| | 6484 | case.addError( |
| 6274 | \\const foo = @import("foo.zig",); | 6485 | \\const foo = @import("foo.zig",); |
| 6275 | \\ | 6486 | \\ |
| 6276 | \\export fn callPrivFunction() void { | 6487 | \\export fn callPrivFunction() void { |
| ... | @@ -6280,16 +6491,19 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -6280,16 +6491,19 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6280 | "tmp.zig:4:8: error: 'privateFunction' is private", | 6491 | "tmp.zig:4:8: error: 'privateFunction' is private", |
| 6281 | "foo.zig:1:1: note: declared here", | 6492 | "foo.zig:1:1: note: declared here", |
| 6282 | }); | 6493 | }); |
| | 6494 | } |
| 6283 | | 6495 | |
| 6284 | tc.addSourceFile("foo.zig", | 6496 | { |
| 6285 | \\fn privateFunction() void { } | 6497 | const case = ctx.obj("multiple files with private member instance function (canonical invocation) error", .{}); |
| 6286 | ); | 6498 | case.backend = .stage1; |
| 6287 | | 6499 | |
| 6288 | break :x tc; | 6500 | case.addSourceFile("foo.zig", |
| 6289 | }); | 6501 | \\pub const Foo = struct { |
| | 6502 | \\ fn privateFunction(self: *Foo) void { _ = self; } |
| | 6503 | \\}; |
| | 6504 | ); |
| 6290 | | 6505 | |
| 6291 | cases.addCase(x: { | 6506 | case.addError( |
| 6292 | const tc = cases.create("multiple files with private member instance function (canonical invocation) error", | | |
| 6293 | \\const Foo = @import("foo.zig",).Foo; | 6507 | \\const Foo = @import("foo.zig",).Foo; |
| 6294 | \\ | 6508 | \\ |
| 6295 | \\export fn callPrivFunction() void { | 6509 | \\export fn callPrivFunction() void { |
| ... | @@ -6300,18 +6514,19 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -6300,18 +6514,19 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6300 | "tmp.zig:5:8: error: 'privateFunction' is private", | 6514 | "tmp.zig:5:8: error: 'privateFunction' is private", |
| 6301 | "foo.zig:2:5: note: declared here", | 6515 | "foo.zig:2:5: note: declared here", |
| 6302 | }); | 6516 | }); |
| | 6517 | } |
| 6303 | | 6518 | |
| 6304 | tc.addSourceFile("foo.zig", | 6519 | { |
| | 6520 | const case = ctx.obj("multiple files with private member instance function error", .{}); |
| | 6521 | case.backend = .stage1; |
| | 6522 | |
| | 6523 | case.addSourceFile("foo.zig", |
| 6305 | \\pub const Foo = struct { | 6524 | \\pub const Foo = struct { |
| 6306 | \\ fn privateFunction(self: *Foo) void { } | 6525 | \\ fn privateFunction(self: *Foo) void { _ = self; } |
| 6307 | \\}; | 6526 | \\}; |
| 6308 | ); | 6527 | ); |
| 6309 | | 6528 | |
| 6310 | break :x tc; | 6529 | case.addError( |
| 6311 | }); | | |
| 6312 | | | |
| 6313 | cases.addCase(x: { | | |
| 6314 | const tc = cases.create("multiple files with private member instance function error", | | |
| 6315 | \\const Foo = @import("foo.zig",).Foo; | 6530 | \\const Foo = @import("foo.zig",).Foo; |
| 6316 | \\ | 6531 | \\ |
| 6317 | \\export fn callPrivFunction() void { | 6532 | \\export fn callPrivFunction() void { |
| ... | @@ -6322,17 +6537,9 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -6322,17 +6537,9 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6322 | "tmp.zig:5:8: error: 'privateFunction' is private", | 6537 | "tmp.zig:5:8: error: 'privateFunction' is private", |
| 6323 | "foo.zig:2:5: note: declared here", | 6538 | "foo.zig:2:5: note: declared here", |
| 6324 | }); | 6539 | }); |
| | 6540 | } |
| 6325 | | 6541 | |
| 6326 | tc.addSourceFile("foo.zig", | 6542 | ctx.objErrStage1("container init with non-type", |
| 6327 | \\pub const Foo = struct { | | |
| 6328 | \\ fn privateFunction(self: *Foo) void { } | | |
| 6329 | \\}; | | |
| 6330 | ); | | |
| 6331 | | | |
| 6332 | break :x tc; | | |
| 6333 | }); | | |
| 6334 | | | |
| 6335 | cases.add("container init with non-type", | | |
| 6336 | \\const zero: i32 = 0; | 6543 | \\const zero: i32 = 0; |
| 6337 | \\const a = zero{1}; | 6544 | \\const a = zero{1}; |
| 6338 | \\ | 6545 | \\ |
| ... | @@ -6341,7 +6548,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -6341,7 +6548,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6341 | "tmp.zig:2:11: error: expected type 'type', found 'i32'", | 6548 | "tmp.zig:2:11: error: expected type 'type', found 'i32'", |
| 6342 | }); | 6549 | }); |
| 6343 | | 6550 | |
| 6344 | cases.add("assign to constant field", | 6551 | ctx.objErrStage1("assign to constant field", |
| 6345 | \\const Foo = struct { | 6552 | \\const Foo = struct { |
| 6346 | \\ field: i32, | 6553 | \\ field: i32, |
| 6347 | \\}; | 6554 | \\}; |
| ... | @@ -6353,7 +6560,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -6353,7 +6560,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6353 | "tmp.zig:6:15: error: cannot assign to constant", | 6560 | "tmp.zig:6:15: error: cannot assign to constant", |
| 6354 | }); | 6561 | }); |
| 6355 | | 6562 | |
| 6356 | cases.add("return from defer expression", | 6563 | ctx.objErrStage1("return from defer expression", |
| 6357 | \\pub fn testTrickyDefer() !void { | 6564 | \\pub fn testTrickyDefer() !void { |
| 6358 | \\ defer canFail() catch {}; | 6565 | \\ defer canFail() catch {}; |
| 6359 | \\ | 6566 | \\ |
| ... | @@ -6370,32 +6577,33 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -6370,32 +6577,33 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6370 | \\ | 6577 | \\ |
| 6371 | \\export fn entry() usize { return @sizeOf(@TypeOf(testTrickyDefer)); } | 6578 | \\export fn entry() usize { return @sizeOf(@TypeOf(testTrickyDefer)); } |
| 6372 | , &[_][]const u8{ | 6579 | , &[_][]const u8{ |
| 6373 | "tmp.zig:4:11: error: cannot return from defer expression", | 6580 | "tmp.zig:4:11: error: 'try' is not allowed inside defer expression", |
| 6374 | }); | 6581 | }); |
| 6375 | | 6582 | |
| 6376 | cases.add("assign too big number to u16", | 6583 | ctx.objErrStage1("assign too big number to u16", |
| 6377 | \\export fn foo() void { | 6584 | \\export fn foo() void { |
| 6378 | \\ var vga_mem: u16 = 0xB8000; | 6585 | \\ var vga_mem: u16 = 0xB8000; |
| | 6586 | \\ _ = vga_mem; |
| 6379 | \\} | 6587 | \\} |
| 6380 | , &[_][]const u8{ | 6588 | , &[_][]const u8{ |
| 6381 | "tmp.zig:2:24: error: integer value 753664 cannot be coerced to type 'u16'", | 6589 | "tmp.zig:2:24: error: integer value 753664 cannot be coerced to type 'u16'", |
| 6382 | }); | 6590 | }); |
| 6383 | | 6591 | |
| 6384 | cases.add("global variable alignment non power of 2", | 6592 | ctx.objErrStage1("global variable alignment non power of 2", |
| 6385 | \\const some_data: [100]u8 align(3) = undefined; | 6593 | \\const some_data: [100]u8 align(3) = undefined; |
| 6386 | \\export fn entry() usize { return @sizeOf(@TypeOf(some_data)); } | 6594 | \\export fn entry() usize { return @sizeOf(@TypeOf(some_data)); } |
| 6387 | , &[_][]const u8{ | 6595 | , &[_][]const u8{ |
| 6388 | "tmp.zig:1:32: error: alignment value 3 is not a power of 2", | 6596 | "tmp.zig:1:32: error: alignment value 3 is not a power of 2", |
| 6389 | }); | 6597 | }); |
| 6390 | | 6598 | |
| 6391 | cases.add("function alignment non power of 2", | 6599 | ctx.objErrStage1("function alignment non power of 2", |
| 6392 | \\extern fn foo() align(3) void; | 6600 | \\extern fn foo() align(3) void; |
| 6393 | \\export fn entry() void { return foo(); } | 6601 | \\export fn entry() void { return foo(); } |
| 6394 | , &[_][]const u8{ | 6602 | , &[_][]const u8{ |
| 6395 | "tmp.zig:1:23: error: alignment value 3 is not a power of 2", | 6603 | "tmp.zig:1:23: error: alignment value 3 is not a power of 2", |
| 6396 | }); | 6604 | }); |
| 6397 | | 6605 | |
| 6398 | cases.add("compile log", | 6606 | ctx.objErrStage1("compile log", |
| 6399 | \\export fn foo() void { | 6607 | \\export fn foo() void { |
| 6400 | \\ comptime bar(12, "hi",); | 6608 | \\ comptime bar(12, "hi",); |
| 6401 | \\} | 6609 | \\} |
| ... | @@ -6410,7 +6618,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -6410,7 +6618,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6410 | "tmp.zig:7:5: error: found compile log statement", | 6618 | "tmp.zig:7:5: error: found compile log statement", |
| 6411 | }); | 6619 | }); |
| 6412 | | 6620 | |
| 6413 | cases.add("casting bit offset pointer to regular pointer", | 6621 | ctx.objErrStage1("casting bit offset pointer to regular pointer", |
| 6414 | \\const BitField = packed struct { | 6622 | \\const BitField = packed struct { |
| 6415 | \\ a: u3, | 6623 | \\ a: u3, |
| 6416 | \\ b: u3, | 6624 | \\ b: u3, |
| ... | @@ -6430,7 +6638,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -6430,7 +6638,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6430 | "tmp.zig:8:26: error: expected type '*const u3', found '*align(:3:1) const u3'", | 6638 | "tmp.zig:8:26: error: expected type '*const u3', found '*align(:3:1) const u3'", |
| 6431 | }); | 6639 | }); |
| 6432 | | 6640 | |
| 6433 | cases.add("referring to a struct that is invalid", | 6641 | ctx.objErrStage1("referring to a struct that is invalid", |
| 6434 | \\const UsbDeviceRequest = struct { | 6642 | \\const UsbDeviceRequest = struct { |
| 6435 | \\ Type: u8, | 6643 | \\ Type: u8, |
| 6436 | \\}; | 6644 | \\}; |
| ... | @@ -6447,7 +6655,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -6447,7 +6655,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6447 | "tmp.zig:6:20: note: referenced here", | 6655 | "tmp.zig:6:20: note: referenced here", |
| 6448 | }); | 6656 | }); |
| 6449 | | 6657 | |
| 6450 | cases.add("control flow uses comptime var at runtime", | 6658 | ctx.objErrStage1("control flow uses comptime var at runtime", |
| 6451 | \\export fn foo() void { | 6659 | \\export fn foo() void { |
| 6452 | \\ comptime var i = 0; | 6660 | \\ comptime var i = 0; |
| 6453 | \\ while (i < 5) : (i += 1) { | 6661 | \\ while (i < 5) : (i += 1) { |
| ... | @@ -6461,7 +6669,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -6461,7 +6669,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6461 | "tmp.zig:3:24: note: compile-time variable assigned here", | 6669 | "tmp.zig:3:24: note: compile-time variable assigned here", |
| 6462 | }); | 6670 | }); |
| 6463 | | 6671 | |
| 6464 | cases.add("ignored return value", | 6672 | ctx.objErrStage1("ignored return value", |
| 6465 | \\export fn foo() void { | 6673 | \\export fn foo() void { |
| 6466 | \\ bar(); | 6674 | \\ bar(); |
| 6467 | \\} | 6675 | \\} |
| ... | @@ -6470,7 +6678,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -6470,7 +6678,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6470 | "tmp.zig:2:8: error: expression value is ignored", | 6678 | "tmp.zig:2:8: error: expression value is ignored", |
| 6471 | }); | 6679 | }); |
| 6472 | | 6680 | |
| 6473 | cases.add("ignored assert-err-ok return value", | 6681 | ctx.objErrStage1("ignored assert-err-ok return value", |
| 6474 | \\export fn foo() void { | 6682 | \\export fn foo() void { |
| 6475 | \\ bar() catch unreachable; | 6683 | \\ bar() catch unreachable; |
| 6476 | \\} | 6684 | \\} |
| ... | @@ -6479,7 +6687,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -6479,7 +6687,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6479 | "tmp.zig:2:11: error: expression value is ignored", | 6687 | "tmp.zig:2:11: error: expression value is ignored", |
| 6480 | }); | 6688 | }); |
| 6481 | | 6689 | |
| 6482 | cases.add("ignored statement value", | 6690 | ctx.objErrStage1("ignored statement value", |
| 6483 | \\export fn foo() void { | 6691 | \\export fn foo() void { |
| 6484 | \\ 1; | 6692 | \\ 1; |
| 6485 | \\} | 6693 | \\} |
| ... | @@ -6487,7 +6695,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -6487,7 +6695,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6487 | "tmp.zig:2:5: error: expression value is ignored", | 6695 | "tmp.zig:2:5: error: expression value is ignored", |
| 6488 | }); | 6696 | }); |
| 6489 | | 6697 | |
| 6490 | cases.add("ignored comptime statement value", | 6698 | ctx.objErrStage1("ignored comptime statement value", |
| 6491 | \\export fn foo() void { | 6699 | \\export fn foo() void { |
| 6492 | \\ comptime {1;} | 6700 | \\ comptime {1;} |
| 6493 | \\} | 6701 | \\} |
| ... | @@ -6495,7 +6703,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -6495,7 +6703,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6495 | "tmp.zig:2:15: error: expression value is ignored", | 6703 | "tmp.zig:2:15: error: expression value is ignored", |
| 6496 | }); | 6704 | }); |
| 6497 | | 6705 | |
| 6498 | cases.add("ignored comptime value", | 6706 | ctx.objErrStage1("ignored comptime value", |
| 6499 | \\export fn foo() void { | 6707 | \\export fn foo() void { |
| 6500 | \\ comptime 1; | 6708 | \\ comptime 1; |
| 6501 | \\} | 6709 | \\} |
| ... | @@ -6503,7 +6711,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -6503,7 +6711,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6503 | "tmp.zig:2:5: error: expression value is ignored", | 6711 | "tmp.zig:2:5: error: expression value is ignored", |
| 6504 | }); | 6712 | }); |
| 6505 | | 6713 | |
| 6506 | cases.add("ignored defered statement value", | 6714 | ctx.objErrStage1("ignored defered statement value", |
| 6507 | \\export fn foo() void { | 6715 | \\export fn foo() void { |
| 6508 | \\ defer {1;} | 6716 | \\ defer {1;} |
| 6509 | \\} | 6717 | \\} |
| ... | @@ -6511,7 +6719,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -6511,7 +6719,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6511 | "tmp.zig:2:12: error: expression value is ignored", | 6719 | "tmp.zig:2:12: error: expression value is ignored", |
| 6512 | }); | 6720 | }); |
| 6513 | | 6721 | |
| 6514 | cases.add("ignored defered function call", | 6722 | ctx.objErrStage1("ignored defered function call", |
| 6515 | \\export fn foo() void { | 6723 | \\export fn foo() void { |
| 6516 | \\ defer bar(); | 6724 | \\ defer bar(); |
| 6517 | \\} | 6725 | \\} |
| ... | @@ -6520,7 +6728,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -6520,7 +6728,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6520 | "tmp.zig:2:14: error: error is ignored. consider using `try`, `catch`, or `if`", | 6728 | "tmp.zig:2:14: error: error is ignored. consider using `try`, `catch`, or `if`", |
| 6521 | }); | 6729 | }); |
| 6522 | | 6730 | |
| 6523 | cases.add("dereference an array", | 6731 | ctx.objErrStage1("dereference an array", |
| 6524 | \\var s_buffer: [10]u8 = undefined; | 6732 | \\var s_buffer: [10]u8 = undefined; |
| 6525 | \\pub fn pass(in: []u8) []u8 { | 6733 | \\pub fn pass(in: []u8) []u8 { |
| 6526 | \\ var out = &s_buffer; | 6734 | \\ var out = &s_buffer; |
| ... | @@ -6533,13 +6741,14 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -6533,13 +6741,14 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6533 | "tmp.zig:4:10: error: attempt to dereference non-pointer type '[10]u8'", | 6741 | "tmp.zig:4:10: error: attempt to dereference non-pointer type '[10]u8'", |
| 6534 | }); | 6742 | }); |
| 6535 | | 6743 | |
| 6536 | cases.add("pass const ptr to mutable ptr fn", | 6744 | ctx.objErrStage1("pass const ptr to mutable ptr fn", |
| 6537 | \\fn foo() bool { | 6745 | \\fn foo() bool { |
| 6538 | \\ const a = @as([]const u8, "a",); | 6746 | \\ const a = @as([]const u8, "a",); |
| 6539 | \\ const b = &a; | 6747 | \\ const b = &a; |
| 6540 | \\ return ptrEql(b, b); | 6748 | \\ return ptrEql(b, b); |
| 6541 | \\} | 6749 | \\} |
| 6542 | \\fn ptrEql(a: *[]const u8, b: *[]const u8) bool { | 6750 | \\fn ptrEql(a: *[]const u8, b: *[]const u8) bool { |
| | 6751 | \\ _ = a; _ = b; |
| 6543 | \\ return true; | 6752 | \\ return true; |
| 6544 | \\} | 6753 | \\} |
| 6545 | \\ | 6754 | \\ |
| ... | @@ -6548,8 +6757,16 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -6548,8 +6757,16 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6548 | "tmp.zig:4:19: error: expected type '*[]const u8', found '*const []const u8'", | 6757 | "tmp.zig:4:19: error: expected type '*[]const u8', found '*const []const u8'", |
| 6549 | }); | 6758 | }); |
| 6550 | | 6759 | |
| 6551 | cases.addCase(x: { | 6760 | { |
| 6552 | const tc = cases.create("export collision", | 6761 | const case = ctx.obj("export collision", .{}); |
| | 6762 | case.backend = .stage1; |
| | 6763 | |
| | 6764 | case.addSourceFile("foo.zig", |
| | 6765 | \\export fn bar() void {} |
| | 6766 | \\pub const baz = 1234; |
| | 6767 | ); |
| | 6768 | |
| | 6769 | case.addError( |
| 6553 | \\const foo = @import("foo.zig",); | 6770 | \\const foo = @import("foo.zig",); |
| 6554 | \\ | 6771 | \\ |
| 6555 | \\export fn bar() usize { | 6772 | \\export fn bar() usize { |
| ... | @@ -6559,18 +6776,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -6559,18 +6776,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6559 | "foo.zig:1:1: error: exported symbol collision: 'bar'", | 6776 | "foo.zig:1:1: error: exported symbol collision: 'bar'", |
| 6560 | "tmp.zig:3:1: note: other symbol here", | 6777 | "tmp.zig:3:1: note: other symbol here", |
| 6561 | }); | 6778 | }); |
| | 6779 | } |
| 6562 | | 6780 | |
| 6563 | tc.addSourceFile("foo.zig", | 6781 | ctx.objErrStage1("implicit cast from array to mutable slice", |
| 6564 | \\export fn bar() void {} | | |
| 6565 | \\pub const baz = 1234; | | |
| 6566 | ); | | |
| 6567 | | | |
| 6568 | break :x tc; | | |
| 6569 | }); | | |
| 6570 | | | |
| 6571 | cases.add("implicit cast from array to mutable slice", | | |
| 6572 | \\var global_array: [10]i32 = undefined; | 6782 | \\var global_array: [10]i32 = undefined; |
| 6573 | \\fn foo(param: []i32) void {} | 6783 | \\fn foo(param: []i32) void {_ = param;} |
| 6574 | \\export fn entry() void { | 6784 | \\export fn entry() void { |
| 6575 | \\ foo(global_array); | 6785 | \\ foo(global_array); |
| 6576 | \\} | 6786 | \\} |
| ... | @@ -6578,7 +6788,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -6578,7 +6788,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6578 | "tmp.zig:4:9: error: expected type '[]i32', found '[10]i32'", | 6788 | "tmp.zig:4:9: error: expected type '[]i32', found '[10]i32'", |
| 6579 | }); | 6789 | }); |
| 6580 | | 6790 | |
| 6581 | cases.add("ptrcast to non-pointer", | 6791 | ctx.objErrStage1("ptrcast to non-pointer", |
| 6582 | \\export fn entry(a: *i32) usize { | 6792 | \\export fn entry(a: *i32) usize { |
| 6583 | \\ return @ptrCast(usize, a); | 6793 | \\ return @ptrCast(usize, a); |
| 6584 | \\} | 6794 | \\} |
| ... | @@ -6586,7 +6796,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -6586,7 +6796,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6586 | "tmp.zig:2:21: error: expected pointer, found 'usize'", | 6796 | "tmp.zig:2:21: error: expected pointer, found 'usize'", |
| 6587 | }); | 6797 | }); |
| 6588 | | 6798 | |
| 6589 | cases.add("asm at compile time", | 6799 | ctx.objErrStage1("asm at compile time", |
| 6590 | \\comptime { | 6800 | \\comptime { |
| 6591 | \\ doSomeAsm(); | 6801 | \\ doSomeAsm(); |
| 6592 | \\} | 6802 | \\} |
| ... | @@ -6602,25 +6812,27 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -6602,25 +6812,27 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6602 | "tmp.zig:6:5: error: unable to evaluate constant expression", | 6812 | "tmp.zig:6:5: error: unable to evaluate constant expression", |
| 6603 | }); | 6813 | }); |
| 6604 | | 6814 | |
| 6605 | cases.add("invalid member of builtin enum", | 6815 | ctx.objErrStage1("invalid member of builtin enum", |
| 6606 | \\const builtin = @import("std").builtin; | 6816 | \\const builtin = @import("std").builtin; |
| 6607 | \\export fn entry() void { | 6817 | \\export fn entry() void { |
| 6608 | \\ const foo = builtin.Mode.x86; | 6818 | \\ const foo = builtin.Mode.x86; |
| | 6819 | \\ _ = foo; |
| 6609 | \\} | 6820 | \\} |
| 6610 | , &[_][]const u8{ | 6821 | , &[_][]const u8{ |
| 6611 | "tmp.zig:3:29: error: container 'std.builtin.Mode' has no member called 'x86'", | 6822 | "tmp.zig:3:29: error: container 'std.builtin.Mode' has no member called 'x86'", |
| 6612 | }); | 6823 | }); |
| 6613 | | 6824 | |
| 6614 | cases.add("int to ptr of 0 bits", | 6825 | ctx.objErrStage1("int to ptr of 0 bits", |
| 6615 | \\export fn foo() void { | 6826 | \\export fn foo() void { |
| 6616 | \\ var x: usize = 0x1000; | 6827 | \\ var x: usize = 0x1000; |
| 6617 | \\ var y: *void = @intToPtr(*void, x); | 6828 | \\ var y: *void = @intToPtr(*void, x); |
| | 6829 | \\ _ = y; |
| 6618 | \\} | 6830 | \\} |
| 6619 | , &[_][]const u8{ | 6831 | , &[_][]const u8{ |
| 6620 | "tmp.zig:3:30: error: type '*void' has 0 bits and cannot store information", | 6832 | "tmp.zig:3:30: error: type '*void' has 0 bits and cannot store information", |
| 6621 | }); | 6833 | }); |
| 6622 | | 6834 | |
| 6623 | cases.add("@fieldParentPtr - non struct", | 6835 | ctx.objErrStage1("@fieldParentPtr - non struct", |
| 6624 | \\const Foo = i32; | 6836 | \\const Foo = i32; |
| 6625 | \\export fn foo(a: *i32) *Foo { | 6837 | \\export fn foo(a: *i32) *Foo { |
| 6626 | \\ return @fieldParentPtr(Foo, "a", a); | 6838 | \\ return @fieldParentPtr(Foo, "a", a); |
| ... | @@ -6629,7 +6841,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -6629,7 +6841,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6629 | "tmp.zig:3:28: error: expected struct type, found 'i32'", | 6841 | "tmp.zig:3:28: error: expected struct type, found 'i32'", |
| 6630 | }); | 6842 | }); |
| 6631 | | 6843 | |
| 6632 | cases.add("@fieldParentPtr - bad field name", | 6844 | ctx.objErrStage1("@fieldParentPtr - bad field name", |
| 6633 | \\const Foo = extern struct { | 6845 | \\const Foo = extern struct { |
| 6634 | \\ derp: i32, | 6846 | \\ derp: i32, |
| 6635 | \\}; | 6847 | \\}; |
| ... | @@ -6640,7 +6852,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -6640,7 +6852,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6640 | "tmp.zig:5:33: error: struct 'Foo' has no field 'a'", | 6852 | "tmp.zig:5:33: error: struct 'Foo' has no field 'a'", |
| 6641 | }); | 6853 | }); |
| 6642 | | 6854 | |
| 6643 | cases.add("@fieldParentPtr - field pointer is not pointer", | 6855 | ctx.objErrStage1("@fieldParentPtr - field pointer is not pointer", |
| 6644 | \\const Foo = extern struct { | 6856 | \\const Foo = extern struct { |
| 6645 | \\ a: i32, | 6857 | \\ a: i32, |
| 6646 | \\}; | 6858 | \\}; |
| ... | @@ -6651,7 +6863,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -6651,7 +6863,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6651 | "tmp.zig:5:38: error: expected pointer, found 'i32'", | 6863 | "tmp.zig:5:38: error: expected pointer, found 'i32'", |
| 6652 | }); | 6864 | }); |
| 6653 | | 6865 | |
| 6654 | cases.add("@fieldParentPtr - comptime field ptr not based on struct", | 6866 | ctx.objErrStage1("@fieldParentPtr - comptime field ptr not based on struct", |
| 6655 | \\const Foo = struct { | 6867 | \\const Foo = struct { |
| 6656 | \\ a: i32, | 6868 | \\ a: i32, |
| 6657 | \\ b: i32, | 6869 | \\ b: i32, |
| ... | @@ -6661,12 +6873,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -6661,12 +6873,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6661 | \\comptime { | 6873 | \\comptime { |
| 6662 | \\ const field_ptr = @intToPtr(*i32, 0x1234); | 6874 | \\ const field_ptr = @intToPtr(*i32, 0x1234); |
| 6663 | \\ const another_foo_ptr = @fieldParentPtr(Foo, "b", field_ptr); | 6875 | \\ const another_foo_ptr = @fieldParentPtr(Foo, "b", field_ptr); |
| | 6876 | \\ _ = another_foo_ptr; |
| 6664 | \\} | 6877 | \\} |
| 6665 | , &[_][]const u8{ | 6878 | , &[_][]const u8{ |
| 6666 | "tmp.zig:9:55: error: pointer value not based on parent struct", | 6879 | "tmp.zig:9:55: error: pointer value not based on parent struct", |
| 6667 | }); | 6880 | }); |
| 6668 | | 6881 | |
| 6669 | cases.add("@fieldParentPtr - comptime wrong field index", | 6882 | ctx.objErrStage1("@fieldParentPtr - comptime wrong field index", |
| 6670 | \\const Foo = struct { | 6883 | \\const Foo = struct { |
| 6671 | \\ a: i32, | 6884 | \\ a: i32, |
| 6672 | \\ b: i32, | 6885 | \\ b: i32, |
| ... | @@ -6675,12 +6888,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -6675,12 +6888,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6675 | \\ | 6888 | \\ |
| 6676 | \\comptime { | 6889 | \\comptime { |
| 6677 | \\ const another_foo_ptr = @fieldParentPtr(Foo, "b", &foo.a); | 6890 | \\ const another_foo_ptr = @fieldParentPtr(Foo, "b", &foo.a); |
| | 6891 | \\ _ = another_foo_ptr; |
| 6678 | \\} | 6892 | \\} |
| 6679 | , &[_][]const u8{ | 6893 | , &[_][]const u8{ |
| 6680 | "tmp.zig:8:29: error: field 'b' has index 1 but pointer value is index 0 of struct 'Foo'", | 6894 | "tmp.zig:8:29: error: field 'b' has index 1 but pointer value is index 0 of struct 'Foo'", |
| 6681 | }); | 6895 | }); |
| 6682 | | 6896 | |
| 6683 | cases.add("@offsetOf - non struct", | 6897 | ctx.objErrStage1("@offsetOf - non struct", |
| 6684 | \\const Foo = i32; | 6898 | \\const Foo = i32; |
| 6685 | \\export fn foo() usize { | 6899 | \\export fn foo() usize { |
| 6686 | \\ return @offsetOf(Foo, "a",); | 6900 | \\ return @offsetOf(Foo, "a",); |
| ... | @@ -6689,7 +6903,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -6689,7 +6903,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6689 | "tmp.zig:3:22: error: expected struct type, found 'i32'", | 6903 | "tmp.zig:3:22: error: expected struct type, found 'i32'", |
| 6690 | }); | 6904 | }); |
| 6691 | | 6905 | |
| 6692 | cases.add("@offsetOf - bad field name", | 6906 | ctx.objErrStage1("@offsetOf - bad field name", |
| 6693 | \\const Foo = struct { | 6907 | \\const Foo = struct { |
| 6694 | \\ derp: i32, | 6908 | \\ derp: i32, |
| 6695 | \\}; | 6909 | \\}; |
| ... | @@ -6700,20 +6914,20 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -6700,20 +6914,20 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6700 | "tmp.zig:5:27: error: struct 'Foo' has no field 'a'", | 6914 | "tmp.zig:5:27: error: struct 'Foo' has no field 'a'", |
| 6701 | }); | 6915 | }); |
| 6702 | | 6916 | |
| 6703 | cases.addExe("missing main fn in executable", | 6917 | ctx.exeErrStage1("missing main fn in executable", |
| 6704 | \\ | 6918 | \\ |
| 6705 | , &[_][]const u8{ | 6919 | , &[_][]const u8{ |
| 6706 | "error: root source file has no member called 'main'", | 6920 | "error: root source file has no member called 'main'", |
| 6707 | }); | 6921 | }); |
| 6708 | | 6922 | |
| 6709 | cases.addExe("private main fn", | 6923 | ctx.exeErrStage1("private main fn", |
| 6710 | \\fn main() void {} | 6924 | \\fn main() void {} |
| 6711 | , &[_][]const u8{ | 6925 | , &[_][]const u8{ |
| 6712 | "error: 'main' is private", | 6926 | "error: 'main' is private", |
| 6713 | "tmp.zig:1:1: note: declared here", | 6927 | "tmp.zig:1:1: note: declared here", |
| 6714 | }); | 6928 | }); |
| 6715 | | 6929 | |
| 6716 | cases.add("setting a section on a local variable", | 6930 | ctx.objErrStage1("setting a section on a local variable", |
| 6717 | \\export fn entry() i32 { | 6931 | \\export fn entry() i32 { |
| 6718 | \\ var foo: i32 linksection(".text2") = 1234; | 6932 | \\ var foo: i32 linksection(".text2") = 1234; |
| 6719 | \\ return foo; | 6933 | \\ return foo; |
| ... | @@ -6722,7 +6936,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -6722,7 +6936,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6722 | "tmp.zig:2:30: error: cannot set section of local variable 'foo'", | 6936 | "tmp.zig:2:30: error: cannot set section of local variable 'foo'", |
| 6723 | }); | 6937 | }); |
| 6724 | | 6938 | |
| 6725 | cases.add("inner struct member shadowing outer struct member", | 6939 | ctx.objErrStage1("inner struct member shadowing outer struct member", |
| 6726 | \\fn A() type { | 6940 | \\fn A() type { |
| 6727 | \\ return struct { | 6941 | \\ return struct { |
| 6728 | \\ b: B(), | 6942 | \\ b: B(), |
| ... | @@ -6747,7 +6961,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -6747,7 +6961,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6747 | "tmp.zig:5:9: note: previous definition is here", | 6961 | "tmp.zig:5:9: note: previous definition is here", |
| 6748 | }); | 6962 | }); |
| 6749 | | 6963 | |
| 6750 | cases.add("while expected bool, got optional", | 6964 | ctx.objErrStage1("while expected bool, got optional", |
| 6751 | \\export fn foo() void { | 6965 | \\export fn foo() void { |
| 6752 | \\ while (bar()) {} | 6966 | \\ while (bar()) {} |
| 6753 | \\} | 6967 | \\} |
| ... | @@ -6756,7 +6970,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -6756,7 +6970,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6756 | "tmp.zig:2:15: error: expected type 'bool', found '?i32'", | 6970 | "tmp.zig:2:15: error: expected type 'bool', found '?i32'", |
| 6757 | }); | 6971 | }); |
| 6758 | | 6972 | |
| 6759 | cases.add("while expected bool, got error union", | 6973 | ctx.objErrStage1("while expected bool, got error union", |
| 6760 | \\export fn foo() void { | 6974 | \\export fn foo() void { |
| 6761 | \\ while (bar()) {} | 6975 | \\ while (bar()) {} |
| 6762 | \\} | 6976 | \\} |
| ... | @@ -6765,36 +6979,36 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -6765,36 +6979,36 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6765 | "tmp.zig:2:15: error: expected type 'bool', found 'anyerror!i32'", | 6979 | "tmp.zig:2:15: error: expected type 'bool', found 'anyerror!i32'", |
| 6766 | }); | 6980 | }); |
| 6767 | | 6981 | |
| 6768 | cases.add("while expected optional, got bool", | 6982 | ctx.objErrStage1("while expected optional, got bool", |
| 6769 | \\export fn foo() void { | 6983 | \\export fn foo() void { |
| 6770 | \\ while (bar()) |x| {} | 6984 | \\ while (bar()) |x| {_ = x;} |
| 6771 | \\} | 6985 | \\} |
| 6772 | \\fn bar() bool { return true; } | 6986 | \\fn bar() bool { return true; } |
| 6773 | , &[_][]const u8{ | 6987 | , &[_][]const u8{ |
| 6774 | "tmp.zig:2:15: error: expected optional type, found 'bool'", | 6988 | "tmp.zig:2:15: error: expected optional type, found 'bool'", |
| 6775 | }); | 6989 | }); |
| 6776 | | 6990 | |
| 6777 | cases.add("while expected optional, got error union", | 6991 | ctx.objErrStage1("while expected optional, got error union", |
| 6778 | \\export fn foo() void { | 6992 | \\export fn foo() void { |
| 6779 | \\ while (bar()) |x| {} | 6993 | \\ while (bar()) |x| {_ = x;} |
| 6780 | \\} | 6994 | \\} |
| 6781 | \\fn bar() anyerror!i32 { return 1; } | 6995 | \\fn bar() anyerror!i32 { return 1; } |
| 6782 | , &[_][]const u8{ | 6996 | , &[_][]const u8{ |
| 6783 | "tmp.zig:2:15: error: expected optional type, found 'anyerror!i32'", | 6997 | "tmp.zig:2:15: error: expected optional type, found 'anyerror!i32'", |
| 6784 | }); | 6998 | }); |
| 6785 | | 6999 | |
| 6786 | cases.add("while expected error union, got bool", | 7000 | ctx.objErrStage1("while expected error union, got bool", |
| 6787 | \\export fn foo() void { | 7001 | \\export fn foo() void { |
| 6788 | \\ while (bar()) |x| {} else |err| {} | 7002 | \\ while (bar()) |x| {_ = x;} else |err| {_ = err;} |
| 6789 | \\} | 7003 | \\} |
| 6790 | \\fn bar() bool { return true; } | 7004 | \\fn bar() bool { return true; } |
| 6791 | , &[_][]const u8{ | 7005 | , &[_][]const u8{ |
| 6792 | "tmp.zig:2:15: error: expected error union type, found 'bool'", | 7006 | "tmp.zig:2:15: error: expected error union type, found 'bool'", |
| 6793 | }); | 7007 | }); |
| 6794 | | 7008 | |
| 6795 | cases.add("while expected error union, got optional", | 7009 | ctx.objErrStage1("while expected error union, got optional", |
| 6796 | \\export fn foo() void { | 7010 | \\export fn foo() void { |
| 6797 | \\ while (bar()) |x| {} else |err| {} | 7011 | \\ while (bar()) |x| {_ = x;} else |err| {_ = err;} |
| 6798 | \\} | 7012 | \\} |
| 6799 | \\fn bar() ?i32 { return 1; } | 7013 | \\fn bar() ?i32 { return 1; } |
| 6800 | , &[_][]const u8{ | 7014 | , &[_][]const u8{ |
| ... | @@ -6802,7 +7016,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -6802,7 +7016,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6802 | }); | 7016 | }); |
| 6803 | | 7017 | |
| 6804 | // TODO test this in stage2, but we won't even try in stage1 | 7018 | // TODO test this in stage2, but we won't even try in stage1 |
| 6805 | //cases.add("inline fn calls itself indirectly", | 7019 | //ctx.objErrStage1("inline fn calls itself indirectly", |
| 6806 | // \\export fn foo() void { | 7020 | // \\export fn foo() void { |
| 6807 | // \\ bar(); | 7021 | // \\ bar(); |
| 6808 | // \\} | 7022 | // \\} |
| ... | @@ -6819,7 +7033,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -6819,7 +7033,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6819 | // "tmp.zig:4:1: error: unable to inline function", | 7033 | // "tmp.zig:4:1: error: unable to inline function", |
| 6820 | //}); | 7034 | //}); |
| 6821 | | 7035 | |
| 6822 | //cases.add("save reference to inline function", | 7036 | //ctx.objErrStage1("save reference to inline function", |
| 6823 | // \\export fn foo() void { | 7037 | // \\export fn foo() void { |
| 6824 | // \\ quux(@ptrToInt(bar)); | 7038 | // \\ quux(@ptrToInt(bar)); |
| 6825 | // \\} | 7039 | // \\} |
| ... | @@ -6829,7 +7043,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -6829,7 +7043,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6829 | // "tmp.zig:4:1: error: unable to inline function", | 7043 | // "tmp.zig:4:1: error: unable to inline function", |
| 6830 | //}); | 7044 | //}); |
| 6831 | | 7045 | |
| 6832 | cases.add("signed integer division", | 7046 | ctx.objErrStage1("signed integer division", |
| 6833 | \\export fn foo(a: i32, b: i32) i32 { | 7047 | \\export fn foo(a: i32, b: i32) i32 { |
| 6834 | \\ return a / b; | 7048 | \\ return a / b; |
| 6835 | \\} | 7049 | \\} |
| ... | @@ -6837,7 +7051,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -6837,7 +7051,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6837 | "tmp.zig:2:14: error: division with 'i32' and 'i32': signed integers must use @divTrunc, @divFloor, or @divExact", | 7051 | "tmp.zig:2:14: error: division with 'i32' and 'i32': signed integers must use @divTrunc, @divFloor, or @divExact", |
| 6838 | }); | 7052 | }); |
| 6839 | | 7053 | |
| 6840 | cases.add("signed integer remainder division", | 7054 | ctx.objErrStage1("signed integer remainder division", |
| 6841 | \\export fn foo(a: i32, b: i32) i32 { | 7055 | \\export fn foo(a: i32, b: i32) i32 { |
| 6842 | \\ return a % b; | 7056 | \\ return a % b; |
| 6843 | \\} | 7057 | \\} |
| ... | @@ -6845,27 +7059,29 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -6845,27 +7059,29 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6845 | "tmp.zig:2:14: error: remainder division with 'i32' and 'i32': signed integers and floats must use @rem or @mod", | 7059 | "tmp.zig:2:14: error: remainder division with 'i32' and 'i32': signed integers and floats must use @rem or @mod", |
| 6846 | }); | 7060 | }); |
| 6847 | | 7061 | |
| 6848 | cases.add("compile-time division by zero", | 7062 | ctx.objErrStage1("compile-time division by zero", |
| 6849 | \\comptime { | 7063 | \\comptime { |
| 6850 | \\ const a: i32 = 1; | 7064 | \\ const a: i32 = 1; |
| 6851 | \\ const b: i32 = 0; | 7065 | \\ const b: i32 = 0; |
| 6852 | \\ const c = a / b; | 7066 | \\ const c = a / b; |
| | 7067 | \\ _ = c; |
| 6853 | \\} | 7068 | \\} |
| 6854 | , &[_][]const u8{ | 7069 | , &[_][]const u8{ |
| 6855 | "tmp.zig:4:17: error: division by zero", | 7070 | "tmp.zig:4:17: error: division by zero", |
| 6856 | }); | 7071 | }); |
| 6857 | | 7072 | |
| 6858 | cases.add("compile-time remainder division by zero", | 7073 | ctx.objErrStage1("compile-time remainder division by zero", |
| 6859 | \\comptime { | 7074 | \\comptime { |
| 6860 | \\ const a: i32 = 1; | 7075 | \\ const a: i32 = 1; |
| 6861 | \\ const b: i32 = 0; | 7076 | \\ const b: i32 = 0; |
| 6862 | \\ const c = a % b; | 7077 | \\ const c = a % b; |
| | 7078 | \\ _ = c; |
| 6863 | \\} | 7079 | \\} |
| 6864 | , &[_][]const u8{ | 7080 | , &[_][]const u8{ |
| 6865 | "tmp.zig:4:17: error: division by zero", | 7081 | "tmp.zig:4:17: error: division by zero", |
| 6866 | }); | 7082 | }); |
| 6867 | | 7083 | |
| 6868 | cases.add("@setRuntimeSafety twice for same scope", | 7084 | ctx.objErrStage1("@setRuntimeSafety twice for same scope", |
| 6869 | \\export fn foo() void { | 7085 | \\export fn foo() void { |
| 6870 | \\ @setRuntimeSafety(false); | 7086 | \\ @setRuntimeSafety(false); |
| 6871 | \\ @setRuntimeSafety(false); | 7087 | \\ @setRuntimeSafety(false); |
| ... | @@ -6875,7 +7091,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -6875,7 +7091,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6875 | "tmp.zig:2:5: note: first set here", | 7091 | "tmp.zig:2:5: note: first set here", |
| 6876 | }); | 7092 | }); |
| 6877 | | 7093 | |
| 6878 | cases.add("@setFloatMode twice for same scope", | 7094 | ctx.objErrStage1("@setFloatMode twice for same scope", |
| 6879 | \\export fn foo() void { | 7095 | \\export fn foo() void { |
| 6880 | \\ @setFloatMode(@import("std").builtin.FloatMode.Optimized); | 7096 | \\ @setFloatMode(@import("std").builtin.FloatMode.Optimized); |
| 6881 | \\ @setFloatMode(@import("std").builtin.FloatMode.Optimized); | 7097 | \\ @setFloatMode(@import("std").builtin.FloatMode.Optimized); |
| ... | @@ -6885,15 +7101,16 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -6885,15 +7101,16 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6885 | "tmp.zig:2:5: note: first set here", | 7101 | "tmp.zig:2:5: note: first set here", |
| 6886 | }); | 7102 | }); |
| 6887 | | 7103 | |
| 6888 | cases.add("array access of type", | 7104 | ctx.objErrStage1("array access of type", |
| 6889 | \\export fn foo() void { | 7105 | \\export fn foo() void { |
| 6890 | \\ var b: u8[40] = undefined; | 7106 | \\ var b: u8[40] = undefined; |
| | 7107 | \\ _ = b; |
| 6891 | \\} | 7108 | \\} |
| 6892 | , &[_][]const u8{ | 7109 | , &[_][]const u8{ |
| 6893 | "tmp.zig:2:14: error: array access of non-array type 'type'", | 7110 | "tmp.zig:2:14: error: array access of non-array type 'type'", |
| 6894 | }); | 7111 | }); |
| 6895 | | 7112 | |
| 6896 | cases.add("cannot break out of defer expression", | 7113 | ctx.objErrStage1("cannot break out of defer expression", |
| 6897 | \\export fn foo() void { | 7114 | \\export fn foo() void { |
| 6898 | \\ while (true) { | 7115 | \\ while (true) { |
| 6899 | \\ defer { | 7116 | \\ defer { |
| ... | @@ -6905,7 +7122,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -6905,7 +7122,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6905 | "tmp.zig:4:13: error: cannot break out of defer expression", | 7122 | "tmp.zig:4:13: error: cannot break out of defer expression", |
| 6906 | }); | 7123 | }); |
| 6907 | | 7124 | |
| 6908 | cases.add("cannot continue out of defer expression", | 7125 | ctx.objErrStage1("cannot continue out of defer expression", |
| 6909 | \\export fn foo() void { | 7126 | \\export fn foo() void { |
| 6910 | \\ while (true) { | 7127 | \\ while (true) { |
| 6911 | \\ defer { | 7128 | \\ defer { |
| ... | @@ -6917,11 +7134,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -6917,11 +7134,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6917 | "tmp.zig:4:13: error: cannot continue out of defer expression", | 7134 | "tmp.zig:4:13: error: cannot continue out of defer expression", |
| 6918 | }); | 7135 | }); |
| 6919 | | 7136 | |
| 6920 | cases.add("calling a generic function only known at runtime", | 7137 | ctx.objErrStage1("calling a generic function only known at runtime", |
| 6921 | \\var foos = [_]fn(anytype) void { foo1, foo2 }; | 7138 | \\var foos = [_]fn(anytype) void { foo1, foo2 }; |
| 6922 | \\ | 7139 | \\ |
| 6923 | \\fn foo1(arg: anytype) void {} | 7140 | \\fn foo1(arg: anytype) void {_ = arg;} |
| 6924 | \\fn foo2(arg: anytype) void {} | 7141 | \\fn foo2(arg: anytype) void {_ = arg;} |
| 6925 | \\ | 7142 | \\ |
| 6926 | \\pub fn main() !void { | 7143 | \\pub fn main() !void { |
| 6927 | \\ foos[0](true); | 7144 | \\ foos[0](true); |
| ... | @@ -6930,7 +7147,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -6930,7 +7147,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6930 | "tmp.zig:7:9: error: calling a generic function requires compile-time known function value", | 7147 | "tmp.zig:7:9: error: calling a generic function requires compile-time known function value", |
| 6931 | }); | 7148 | }); |
| 6932 | | 7149 | |
| 6933 | cases.add("@compileError shows traceback of references that caused it", | 7150 | ctx.objErrStage1("@compileError shows traceback of references that caused it", |
| 6934 | \\const foo = @compileError("aoeu",); | 7151 | \\const foo = @compileError("aoeu",); |
| 6935 | \\ | 7152 | \\ |
| 6936 | \\const bar = baz + foo; | 7153 | \\const bar = baz + foo; |
| ... | @@ -6945,23 +7162,25 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -6945,23 +7162,25 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6945 | "tmp.zig:7:12: note: referenced here", | 7162 | "tmp.zig:7:12: note: referenced here", |
| 6946 | }); | 7163 | }); |
| 6947 | | 7164 | |
| 6948 | cases.add("float literal too large error", | 7165 | ctx.objErrStage1("float literal too large error", |
| 6949 | \\comptime { | 7166 | \\comptime { |
| 6950 | \\ const a = 0x1.0p18495; | 7167 | \\ const a = 0x1.0p18495; |
| | 7168 | \\ _ = a; |
| 6951 | \\} | 7169 | \\} |
| 6952 | , &[_][]const u8{ | 7170 | , &[_][]const u8{ |
| 6953 | "tmp.zig:2:15: error: float literal out of range of any type", | 7171 | "tmp.zig:2:15: error: float literal out of range of any type", |
| 6954 | }); | 7172 | }); |
| 6955 | | 7173 | |
| 6956 | cases.add("float literal too small error (denormal)", | 7174 | ctx.objErrStage1("float literal too small error (denormal)", |
| 6957 | \\comptime { | 7175 | \\comptime { |
| 6958 | \\ const a = 0x1.0p-19000; | 7176 | \\ const a = 0x1.0p-19000; |
| | 7177 | \\ _ = a; |
| 6959 | \\} | 7178 | \\} |
| 6960 | , &[_][]const u8{ | 7179 | , &[_][]const u8{ |
| 6961 | "tmp.zig:2:15: error: float literal out of range of any type", | 7180 | "tmp.zig:2:15: error: float literal out of range of any type", |
| 6962 | }); | 7181 | }); |
| 6963 | | 7182 | |
| 6964 | cases.add("explicit cast float literal to integer when there is a fraction component", | 7183 | ctx.objErrStage1("explicit cast float literal to integer when there is a fraction component", |
| 6965 | \\export fn entry() i32 { | 7184 | \\export fn entry() i32 { |
| 6966 | \\ return @as(i32, 12.34); | 7185 | \\ return @as(i32, 12.34); |
| 6967 | \\} | 7186 | \\} |
| ... | @@ -6969,7 +7188,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -6969,7 +7188,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6969 | "tmp.zig:2:21: error: fractional component prevents float value 12.340000 from being casted to type 'i32'", | 7188 | "tmp.zig:2:21: error: fractional component prevents float value 12.340000 from being casted to type 'i32'", |
| 6970 | }); | 7189 | }); |
| 6971 | | 7190 | |
| 6972 | cases.add("non pointer given to @ptrToInt", | 7191 | ctx.objErrStage1("non pointer given to @ptrToInt", |
| 6973 | \\export fn entry(x: i32) usize { | 7192 | \\export fn entry(x: i32) usize { |
| 6974 | \\ return @ptrToInt(x); | 7193 | \\ return @ptrToInt(x); |
| 6975 | \\} | 7194 | \\} |
| ... | @@ -6977,23 +7196,25 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -6977,23 +7196,25 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6977 | "tmp.zig:2:22: error: expected pointer, found 'i32'", | 7196 | "tmp.zig:2:22: error: expected pointer, found 'i32'", |
| 6978 | }); | 7197 | }); |
| 6979 | | 7198 | |
| 6980 | cases.add("@shlExact shifts out 1 bits", | 7199 | ctx.objErrStage1("@shlExact shifts out 1 bits", |
| 6981 | \\comptime { | 7200 | \\comptime { |
| 6982 | \\ const x = @shlExact(@as(u8, 0b01010101), 2); | 7201 | \\ const x = @shlExact(@as(u8, 0b01010101), 2); |
| | 7202 | \\ _ = x; |
| 6983 | \\} | 7203 | \\} |
| 6984 | , &[_][]const u8{ | 7204 | , &[_][]const u8{ |
| 6985 | "tmp.zig:2:15: error: operation caused overflow", | 7205 | "tmp.zig:2:15: error: operation caused overflow", |
| 6986 | }); | 7206 | }); |
| 6987 | | 7207 | |
| 6988 | cases.add("@shrExact shifts out 1 bits", | 7208 | ctx.objErrStage1("@shrExact shifts out 1 bits", |
| 6989 | \\comptime { | 7209 | \\comptime { |
| 6990 | \\ const x = @shrExact(@as(u8, 0b10101010), 2); | 7210 | \\ const x = @shrExact(@as(u8, 0b10101010), 2); |
| | 7211 | \\ _ = x; |
| 6991 | \\} | 7212 | \\} |
| 6992 | , &[_][]const u8{ | 7213 | , &[_][]const u8{ |
| 6993 | "tmp.zig:2:15: error: exact shift shifted out 1 bits", | 7214 | "tmp.zig:2:15: error: exact shift shifted out 1 bits", |
| 6994 | }); | 7215 | }); |
| 6995 | | 7216 | |
| 6996 | cases.add("shifting without int type or comptime known", | 7217 | ctx.objErrStage1("shifting without int type or comptime known", |
| 6997 | \\export fn entry(x: u8) u8 { | 7218 | \\export fn entry(x: u8) u8 { |
| 6998 | \\ return 0x11 << x; | 7219 | \\ return 0x11 << x; |
| 6999 | \\} | 7220 | \\} |
| ... | @@ -7001,7 +7222,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -7001,7 +7222,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7001 | "tmp.zig:2:17: error: LHS of shift must be a fixed-width integer type, or RHS must be compile-time known", | 7222 | "tmp.zig:2:17: error: LHS of shift must be a fixed-width integer type, or RHS must be compile-time known", |
| 7002 | }); | 7223 | }); |
| 7003 | | 7224 | |
| 7004 | cases.add("shifting RHS is log2 of LHS int bit width", | 7225 | ctx.objErrStage1("shifting RHS is log2 of LHS int bit width", |
| 7005 | \\export fn entry(x: u8, y: u8) u8 { | 7226 | \\export fn entry(x: u8, y: u8) u8 { |
| 7006 | \\ return x << y; | 7227 | \\ return x << y; |
| 7007 | \\} | 7228 | \\} |
| ... | @@ -7009,16 +7230,17 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -7009,16 +7230,17 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7009 | "tmp.zig:2:17: error: expected type 'u3', found 'u8'", | 7230 | "tmp.zig:2:17: error: expected type 'u3', found 'u8'", |
| 7010 | }); | 7231 | }); |
| 7011 | | 7232 | |
| 7012 | cases.add("globally shadowing a primitive type", | 7233 | ctx.objErrStage1("globally shadowing a primitive type", |
| 7013 | \\const u16 = u8; | 7234 | \\const u16 = u8; |
| 7014 | \\export fn entry() void { | 7235 | \\export fn entry() void { |
| 7015 | \\ const a: u16 = 300; | 7236 | \\ const a: u16 = 300; |
| | 7237 | \\ _ = a; |
| 7016 | \\} | 7238 | \\} |
| 7017 | , &[_][]const u8{ | 7239 | , &[_][]const u8{ |
| 7018 | "tmp.zig:1:1: error: declaration shadows primitive type 'u16'", | 7240 | "tmp.zig:1:1: error: declaration shadows primitive type 'u16'", |
| 7019 | }); | 7241 | }); |
| 7020 | | 7242 | |
| 7021 | cases.add("implicitly increasing pointer alignment", | 7243 | ctx.objErrStage1("implicitly increasing pointer alignment", |
| 7022 | \\const Foo = packed struct { | 7244 | \\const Foo = packed struct { |
| 7023 | \\ a: u8, | 7245 | \\ a: u8, |
| 7024 | \\ b: u32, | 7246 | \\ b: u32, |
| ... | @@ -7036,7 +7258,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -7036,7 +7258,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7036 | "tmp.zig:8:13: error: expected type '*u32', found '*align(1) u32'", | 7258 | "tmp.zig:8:13: error: expected type '*u32', found '*align(1) u32'", |
| 7037 | }); | 7259 | }); |
| 7038 | | 7260 | |
| 7039 | cases.add("implicitly increasing slice alignment", | 7261 | ctx.objErrStage1("implicitly increasing slice alignment", |
| 7040 | \\const Foo = packed struct { | 7262 | \\const Foo = packed struct { |
| 7041 | \\ a: u8, | 7263 | \\ a: u8, |
| 7042 | \\ b: u32, | 7264 | \\ b: u32, |
| ... | @@ -7057,7 +7279,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -7057,7 +7279,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7057 | "tmp.zig:9:26: note: '*[1]u32' has alignment 4", | 7279 | "tmp.zig:9:26: note: '*[1]u32' has alignment 4", |
| 7058 | }); | 7280 | }); |
| 7059 | | 7281 | |
| 7060 | cases.add("increase pointer alignment in @ptrCast", | 7282 | ctx.objErrStage1("increase pointer alignment in @ptrCast", |
| 7061 | \\export fn entry() u32 { | 7283 | \\export fn entry() u32 { |
| 7062 | \\ var bytes: [4]u8 = [_]u8{0x01, 0x02, 0x03, 0x04}; | 7284 | \\ var bytes: [4]u8 = [_]u8{0x01, 0x02, 0x03, 0x04}; |
| 7063 | \\ const ptr = @ptrCast(*u32, &bytes[0]); | 7285 | \\ const ptr = @ptrCast(*u32, &bytes[0]); |
| ... | @@ -7069,7 +7291,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -7069,7 +7291,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7069 | "tmp.zig:3:26: note: '*u32' has alignment 4", | 7291 | "tmp.zig:3:26: note: '*u32' has alignment 4", |
| 7070 | }); | 7292 | }); |
| 7071 | | 7293 | |
| 7072 | cases.add("@alignCast expects pointer or slice", | 7294 | ctx.objErrStage1("@alignCast expects pointer or slice", |
| 7073 | \\export fn entry() void { | 7295 | \\export fn entry() void { |
| 7074 | \\ @alignCast(4, @as(u32, 3)); | 7296 | \\ @alignCast(4, @as(u32, 3)); |
| 7075 | \\} | 7297 | \\} |
| ... | @@ -7077,7 +7299,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -7077,7 +7299,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7077 | "tmp.zig:2:19: error: expected pointer or slice, found 'u32'", | 7299 | "tmp.zig:2:19: error: expected pointer or slice, found 'u32'", |
| 7078 | }); | 7300 | }); |
| 7079 | | 7301 | |
| 7080 | cases.add("passing an under-aligned function pointer", | 7302 | ctx.objErrStage1("passing an under-aligned function pointer", |
| 7081 | \\export fn entry() void { | 7303 | \\export fn entry() void { |
| 7082 | \\ testImplicitlyDecreaseFnAlign(alignedSmall, 1234); | 7304 | \\ testImplicitlyDecreaseFnAlign(alignedSmall, 1234); |
| 7083 | \\} | 7305 | \\} |
| ... | @@ -7089,7 +7311,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -7089,7 +7311,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7089 | "tmp.zig:2:35: error: expected type 'fn() align(8) i32', found 'fn() align(4) i32'", | 7311 | "tmp.zig:2:35: error: expected type 'fn() align(8) i32', found 'fn() align(4) i32'", |
| 7090 | }); | 7312 | }); |
| 7091 | | 7313 | |
| 7092 | cases.add("passing a not-aligned-enough pointer to cmpxchg", | 7314 | ctx.objErrStage1("passing a not-aligned-enough pointer to cmpxchg", |
| 7093 | \\const AtomicOrder = @import("std").builtin.AtomicOrder; | 7315 | \\const AtomicOrder = @import("std").builtin.AtomicOrder; |
| 7094 | \\export fn entry() bool { | 7316 | \\export fn entry() bool { |
| 7095 | \\ var x: i32 align(1) = 1234; | 7317 | \\ var x: i32 align(1) = 1234; |
| ... | @@ -7100,15 +7322,16 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -7100,15 +7322,16 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7100 | "tmp.zig:4:32: error: expected type '*i32', found '*align(1) i32'", | 7322 | "tmp.zig:4:32: error: expected type '*i32', found '*align(1) i32'", |
| 7101 | }); | 7323 | }); |
| 7102 | | 7324 | |
| 7103 | cases.add("wrong size to an array literal", | 7325 | ctx.objErrStage1("wrong size to an array literal", |
| 7104 | \\comptime { | 7326 | \\comptime { |
| 7105 | \\ const array = [2]u8{1, 2, 3}; | 7327 | \\ const array = [2]u8{1, 2, 3}; |
| | 7328 | \\ _ = array; |
| 7106 | \\} | 7329 | \\} |
| 7107 | , &[_][]const u8{ | 7330 | , &[_][]const u8{ |
| 7108 | "tmp.zig:2:31: error: index 2 outside array of size 2", | 7331 | "tmp.zig:2:31: error: index 2 outside array of size 2", |
| 7109 | }); | 7332 | }); |
| 7110 | | 7333 | |
| 7111 | cases.add("wrong pointer coerced to pointer to opaque {}", | 7334 | ctx.objErrStage1("wrong pointer coerced to pointer to opaque {}", |
| 7112 | \\const Derp = opaque {}; | 7335 | \\const Derp = opaque {}; |
| 7113 | \\extern fn bar(d: *Derp) void; | 7336 | \\extern fn bar(d: *Derp) void; |
| 7114 | \\export fn foo() void { | 7337 | \\export fn foo() void { |
| ... | @@ -7119,49 +7342,57 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -7119,49 +7342,57 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7119 | "tmp.zig:5:9: error: expected type '*Derp', found '*c_void'", | 7342 | "tmp.zig:5:9: error: expected type '*Derp', found '*c_void'", |
| 7120 | }); | 7343 | }); |
| 7121 | | 7344 | |
| 7122 | cases.add("non-const variables of things that require const variables", | 7345 | ctx.objErrStage1("non-const variables of things that require const variables", |
| 7123 | \\export fn entry1() void { | 7346 | \\export fn entry1() void { |
| 7124 | \\ var m2 = &2; | 7347 | \\ var m2 = &2; |
| | 7348 | \\ _ = m2; |
| 7125 | \\} | 7349 | \\} |
| 7126 | \\export fn entry2() void { | 7350 | \\export fn entry2() void { |
| 7127 | \\ var a = undefined; | 7351 | \\ var a = undefined; |
| | 7352 | \\ _ = a; |
| 7128 | \\} | 7353 | \\} |
| 7129 | \\export fn entry3() void { | 7354 | \\export fn entry3() void { |
| 7130 | \\ var b = 1; | 7355 | \\ var b = 1; |
| | 7356 | \\ _ = b; |
| 7131 | \\} | 7357 | \\} |
| 7132 | \\export fn entry4() void { | 7358 | \\export fn entry4() void { |
| 7133 | \\ var c = 1.0; | 7359 | \\ var c = 1.0; |
| | 7360 | \\ _ = c; |
| 7134 | \\} | 7361 | \\} |
| 7135 | \\export fn entry5() void { | 7362 | \\export fn entry5() void { |
| 7136 | \\ var d = null; | 7363 | \\ var d = null; |
| | 7364 | \\ _ = d; |
| 7137 | \\} | 7365 | \\} |
| 7138 | \\export fn entry6(opaque_: *Opaque) void { | 7366 | \\export fn entry6(opaque_: *Opaque) void { |
| 7139 | \\ var e = opaque_.*; | 7367 | \\ var e = opaque_.*; |
| | 7368 | \\ _ = e; |
| 7140 | \\} | 7369 | \\} |
| 7141 | \\export fn entry7() void { | 7370 | \\export fn entry7() void { |
| 7142 | \\ var f = i32; | 7371 | \\ var f = i32; |
| | 7372 | \\ _ = f; |
| 7143 | \\} | 7373 | \\} |
| 7144 | \\export fn entry8() void { | 7374 | \\export fn entry8() void { |
| 7145 | \\ var h = (Foo {}).bar; | 7375 | \\ var h = (Foo {}).bar; |
| | 7376 | \\ _ = h; |
| 7146 | \\} | 7377 | \\} |
| 7147 | \\const Opaque = opaque {}; | 7378 | \\const Opaque = opaque {}; |
| 7148 | \\const Foo = struct { | 7379 | \\const Foo = struct { |
| 7149 | \\ fn bar(self: *const Foo) void {} | 7380 | \\ fn bar(self: *const Foo) void {_ = self;} |
| 7150 | \\}; | 7381 | \\}; |
| 7151 | , &[_][]const u8{ | 7382 | , &[_][]const u8{ |
| 7152 | "tmp.zig:2:4: error: variable of type '*const comptime_int' must be const or comptime", | 7383 | "tmp.zig:2:4: error: variable of type '*const comptime_int' must be const or comptime", |
| 7153 | "tmp.zig:5:4: error: variable of type '(undefined)' must be const or comptime", | 7384 | "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", | 7385 | "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", | 7386 | "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", | 7387 | "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", | 7388 | "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", | 7389 | "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", | 7390 | "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", | 7391 | "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", | 7392 | "tmp.zig:30:4: error: variable of type '(bound fn(*const Foo) void)' must be const or comptime", |
| 7162 | }); | 7393 | }); |
| 7163 | | 7394 | |
| 7164 | cases.add("variable with type 'noreturn'", | 7395 | ctx.objErrStage1("variable with type 'noreturn'", |
| 7165 | \\export fn entry9() void { | 7396 | \\export fn entry9() void { |
| 7166 | \\ var z: noreturn = return; | 7397 | \\ var z: noreturn = return; |
| 7167 | \\} | 7398 | \\} |
| ... | @@ -7170,7 +7401,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -7170,7 +7401,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7170 | "tmp.zig:2:23: note: control flow is diverted here", | 7401 | "tmp.zig:2:23: note: control flow is diverted here", |
| 7171 | }); | 7402 | }); |
| 7172 | | 7403 | |
| 7173 | cases.add("wrong types given to atomic order args in cmpxchg", | 7404 | ctx.objErrStage1("wrong types given to atomic order args in cmpxchg", |
| 7174 | \\export fn entry() void { | 7405 | \\export fn entry() void { |
| 7175 | \\ var x: i32 = 1234; | 7406 | \\ var x: i32 = 1234; |
| 7176 | \\ while (!@cmpxchgWeak(i32, &x, 1234, 5678, @as(u32, 1234), @as(u32, 1234))) {} | 7407 | \\ while (!@cmpxchgWeak(i32, &x, 1234, 5678, @as(u32, 1234), @as(u32, 1234))) {} |
| ... | @@ -7179,7 +7410,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -7179,7 +7410,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7179 | "tmp.zig:3:47: error: expected type 'std.builtin.AtomicOrder', found 'u32'", | 7410 | "tmp.zig:3:47: error: expected type 'std.builtin.AtomicOrder', found 'u32'", |
| 7180 | }); | 7411 | }); |
| 7181 | | 7412 | |
| 7182 | cases.add("wrong types given to @export", | 7413 | ctx.objErrStage1("wrong types given to @export", |
| 7183 | \\fn entry() callconv(.C) void { } | 7414 | \\fn entry() callconv(.C) void { } |
| 7184 | \\comptime { | 7415 | \\comptime { |
| 7185 | \\ @export(entry, .{.name = "entry", .linkage = @as(u32, 1234) }); | 7416 | \\ @export(entry, .{.name = "entry", .linkage = @as(u32, 1234) }); |
| ... | @@ -7188,7 +7419,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -7188,7 +7419,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7188 | "tmp.zig:3:59: error: expected type 'std.builtin.GlobalLinkage', found 'comptime_int'", | 7419 | "tmp.zig:3:59: error: expected type 'std.builtin.GlobalLinkage', found 'comptime_int'", |
| 7189 | }); | 7420 | }); |
| 7190 | | 7421 | |
| 7191 | cases.add("struct with invalid field", | 7422 | ctx.objErrStage1("struct with invalid field", |
| 7192 | \\const std = @import("std",); | 7423 | \\const std = @import("std",); |
| 7193 | \\const Allocator = std.mem.Allocator; | 7424 | \\const Allocator = std.mem.Allocator; |
| 7194 | \\const ArrayList = std.ArrayList; | 7425 | \\const ArrayList = std.ArrayList; |
| ... | @@ -7211,12 +7442,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -7211,12 +7442,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7211 | \\ .text = MdText.init(&std.testing.allocator), | 7442 | \\ .text = MdText.init(&std.testing.allocator), |
| 7212 | \\ .weight = HeaderWeight.H1, | 7443 | \\ .weight = HeaderWeight.H1, |
| 7213 | \\ }; | 7444 | \\ }; |
| | 7445 | \\ _ = a; |
| 7214 | \\} | 7446 | \\} |
| 7215 | , &[_][]const u8{ | 7447 | , &[_][]const u8{ |
| 7216 | "tmp.zig:14:17: error: use of undeclared identifier 'HeaderValue'", | 7448 | "tmp.zig:14:17: error: use of undeclared identifier 'HeaderValue'", |
| 7217 | }); | 7449 | }); |
| 7218 | | 7450 | |
| 7219 | cases.add("@setAlignStack outside function", | 7451 | ctx.objErrStage1("@setAlignStack outside function", |
| 7220 | \\comptime { | 7452 | \\comptime { |
| 7221 | \\ @setAlignStack(16); | 7453 | \\ @setAlignStack(16); |
| 7222 | \\} | 7454 | \\} |
| ... | @@ -7224,7 +7456,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -7224,7 +7456,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7224 | "tmp.zig:2:5: error: @setAlignStack outside function", | 7456 | "tmp.zig:2:5: error: @setAlignStack outside function", |
| 7225 | }); | 7457 | }); |
| 7226 | | 7458 | |
| 7227 | cases.add("@setAlignStack in naked function", | 7459 | ctx.objErrStage1("@setAlignStack in naked function", |
| 7228 | \\export fn entry() callconv(.Naked) void { | 7460 | \\export fn entry() callconv(.Naked) void { |
| 7229 | \\ @setAlignStack(16); | 7461 | \\ @setAlignStack(16); |
| 7230 | \\} | 7462 | \\} |
| ... | @@ -7232,7 +7464,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -7232,7 +7464,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7232 | "tmp.zig:2:5: error: @setAlignStack in naked function", | 7464 | "tmp.zig:2:5: error: @setAlignStack in naked function", |
| 7233 | }); | 7465 | }); |
| 7234 | | 7466 | |
| 7235 | cases.add("@setAlignStack in inline function", | 7467 | ctx.objErrStage1("@setAlignStack in inline function", |
| 7236 | \\export fn entry() void { | 7468 | \\export fn entry() void { |
| 7237 | \\ foo(); | 7469 | \\ foo(); |
| 7238 | \\} | 7470 | \\} |
| ... | @@ -7243,7 +7475,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -7243,7 +7475,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7243 | "tmp.zig:5:5: error: @setAlignStack in inline function", | 7475 | "tmp.zig:5:5: error: @setAlignStack in inline function", |
| 7244 | }); | 7476 | }); |
| 7245 | | 7477 | |
| 7246 | cases.add("@setAlignStack set twice", | 7478 | ctx.objErrStage1("@setAlignStack set twice", |
| 7247 | \\export fn entry() void { | 7479 | \\export fn entry() void { |
| 7248 | \\ @setAlignStack(16); | 7480 | \\ @setAlignStack(16); |
| 7249 | \\ @setAlignStack(16); | 7481 | \\ @setAlignStack(16); |
| ... | @@ -7253,7 +7485,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -7253,7 +7485,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7253 | "tmp.zig:2:5: note: first set here", | 7485 | "tmp.zig:2:5: note: first set here", |
| 7254 | }); | 7486 | }); |
| 7255 | | 7487 | |
| 7256 | cases.add("@setAlignStack too big", | 7488 | ctx.objErrStage1("@setAlignStack too big", |
| 7257 | \\export fn entry() void { | 7489 | \\export fn entry() void { |
| 7258 | \\ @setAlignStack(511 + 1); | 7490 | \\ @setAlignStack(511 + 1); |
| 7259 | \\} | 7491 | \\} |
| ... | @@ -7261,7 +7493,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -7261,7 +7493,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7261 | "tmp.zig:2:5: error: attempt to @setAlignStack(512); maximum is 256", | 7493 | "tmp.zig:2:5: error: attempt to @setAlignStack(512); maximum is 256", |
| 7262 | }); | 7494 | }); |
| 7263 | | 7495 | |
| 7264 | cases.add("storing runtime value in compile time variable then using it", | 7496 | ctx.objErrStage1("storing runtime value in compile time variable then using it", |
| 7265 | \\const Mode = @import("std").builtin.Mode; | 7497 | \\const Mode = @import("std").builtin.Mode; |
| 7266 | \\ | 7498 | \\ |
| 7267 | \\fn Free(comptime filename: []const u8) TestCase { | 7499 | \\fn Free(comptime filename: []const u8) TestCase { |
| ... | @@ -7307,7 +7539,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -7307,7 +7539,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7307 | "tmp.zig:37:29: error: cannot store runtime value in compile time variable", | 7539 | "tmp.zig:37:29: error: cannot store runtime value in compile time variable", |
| 7308 | }); | 7540 | }); |
| 7309 | | 7541 | |
| 7310 | cases.add("invalid legacy unicode escape", | 7542 | ctx.objErrStage1("invalid legacy unicode escape", |
| 7311 | \\export fn entry() void { | 7543 | \\export fn entry() void { |
| 7312 | \\ const a = '\U1234'; | 7544 | \\ const a = '\U1234'; |
| 7313 | \\} | 7545 | \\} |
| ... | @@ -7315,7 +7547,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -7315,7 +7547,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7315 | "tmp.zig:2:17: error: invalid character: 'U'", | 7547 | "tmp.zig:2:17: error: invalid character: 'U'", |
| 7316 | }); | 7548 | }); |
| 7317 | | 7549 | |
| 7318 | cases.add("invalid empty unicode escape", | 7550 | ctx.objErrStage1("invalid empty unicode escape", |
| 7319 | \\export fn entry() void { | 7551 | \\export fn entry() void { |
| 7320 | \\ const a = '\u{}'; | 7552 | \\ const a = '\u{}'; |
| 7321 | \\} | 7553 | \\} |
| ... | @@ -7323,21 +7555,20 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -7323,21 +7555,20 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7323 | "tmp.zig:2:19: error: empty unicode escape sequence", | 7555 | "tmp.zig:2:19: error: empty unicode escape sequence", |
| 7324 | }); | 7556 | }); |
| 7325 | | 7557 | |
| 7326 | cases.add("non-printable invalid character", "\xff\xfe" ++ | 7558 | ctx.objErrStage1("non-printable invalid character", "\xff\xfe" ++ |
| 7327 | \\fn test() bool {\r | 7559 | "fn foo() bool {\r\n" ++ |
| 7328 | \\ true\r | 7560 | " return true;\r\n" ++ |
| 7329 | \\} | 7561 | "}\r\n", &[_][]const u8{ |
| 7330 | , &[_][]const u8{ | | |
| 7331 | "tmp.zig:1:1: error: invalid character: '\\xff'", | 7562 | "tmp.zig:1:1: error: invalid character: '\\xff'", |
| 7332 | }); | 7563 | }); |
| 7333 | | 7564 | |
| 7334 | cases.add("non-printable invalid character with escape alternative", "fn test() bool {\n" ++ | 7565 | ctx.objErrStage1("non-printable invalid character with escape alternative", "fn foo() bool {\n" ++ |
| 7335 | "\ttrue\n" ++ | 7566 | "\treturn true;\n" ++ |
| 7336 | "}\n", &[_][]const u8{ | 7567 | "}\n", &[_][]const u8{ |
| 7337 | "tmp.zig:2:1: error: invalid character: '\\t'", | 7568 | "tmp.zig:2:1: error: invalid character: '\\t'", |
| 7338 | }); | 7569 | }); |
| 7339 | | 7570 | |
| 7340 | cases.add("calling var args extern function, passing array instead of pointer", | 7571 | ctx.objErrStage1("calling var args extern function, passing array instead of pointer", |
| 7341 | \\export fn entry() void { | 7572 | \\export fn entry() void { |
| 7342 | \\ foo("hello".*,); | 7573 | \\ foo("hello".*,); |
| 7343 | \\} | 7574 | \\} |
| ... | @@ -7346,7 +7577,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -7346,7 +7577,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7346 | "tmp.zig:2:16: error: expected type '*const u8', found '[5:0]u8'", | 7577 | "tmp.zig:2:16: error: expected type '*const u8', found '[5:0]u8'", |
| 7347 | }); | 7578 | }); |
| 7348 | | 7579 | |
| 7349 | cases.add("constant inside comptime function has compile error", | 7580 | ctx.objErrStage1("constant inside comptime function has compile error", |
| 7350 | \\const ContextAllocator = MemoryPool(usize); | 7581 | \\const ContextAllocator = MemoryPool(usize); |
| 7351 | \\ | 7582 | \\ |
| 7352 | \\pub fn MemoryPool(comptime T: type) type { | 7583 | \\pub fn MemoryPool(comptime T: type) type { |
| ... | @@ -7361,12 +7592,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -7361,12 +7592,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7361 | \\ var allocator: ContextAllocator = undefined; | 7592 | \\ var allocator: ContextAllocator = undefined; |
| 7362 | \\} | 7593 | \\} |
| 7363 | , &[_][]const u8{ | 7594 | , &[_][]const u8{ |
| 7364 | "tmp.zig:4:25: error: aoeu", | 7595 | "tmp.zig:4:5: error: unreachable code", |
| 7365 | "tmp.zig:1:36: note: referenced here", | 7596 | "tmp.zig:4:25: note: control flow is diverted here", |
| 7366 | "tmp.zig:12:20: note: referenced here", | 7597 | "tmp.zig:12:9: error: unused local variable", |
| 7367 | }); | 7598 | }); |
| 7368 | | 7599 | |
| 7369 | cases.add("specify enum tag type that is too small", | 7600 | ctx.objErrStage1("specify enum tag type that is too small", |
| 7370 | \\const Small = enum (u2) { | 7601 | \\const Small = enum (u2) { |
| 7371 | \\ One, | 7602 | \\ One, |
| 7372 | \\ Two, | 7603 | \\ Two, |
| ... | @@ -7377,12 +7608,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -7377,12 +7608,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7377 | \\ | 7608 | \\ |
| 7378 | \\export fn entry() void { | 7609 | \\export fn entry() void { |
| 7379 | \\ var x = Small.One; | 7610 | \\ var x = Small.One; |
| | 7611 | \\ _ = x; |
| 7380 | \\} | 7612 | \\} |
| 7381 | , &[_][]const u8{ | 7613 | , &[_][]const u8{ |
| 7382 | "tmp.zig:6:5: error: enumeration value 4 too large for type 'u2'", | 7614 | "tmp.zig:6:5: error: enumeration value 4 too large for type 'u2'", |
| 7383 | }); | 7615 | }); |
| 7384 | | 7616 | |
| 7385 | cases.add("specify non-integer enum tag type", | 7617 | ctx.objErrStage1("specify non-integer enum tag type", |
| 7386 | \\const Small = enum (f32) { | 7618 | \\const Small = enum (f32) { |
| 7387 | \\ One, | 7619 | \\ One, |
| 7388 | \\ Two, | 7620 | \\ Two, |
| ... | @@ -7391,12 +7623,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -7391,12 +7623,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7391 | \\ | 7623 | \\ |
| 7392 | \\export fn entry() void { | 7624 | \\export fn entry() void { |
| 7393 | \\ var x = Small.One; | 7625 | \\ var x = Small.One; |
| | 7626 | \\ _ = x; |
| 7394 | \\} | 7627 | \\} |
| 7395 | , &[_][]const u8{ | 7628 | , &[_][]const u8{ |
| 7396 | "tmp.zig:1:21: error: expected integer, found 'f32'", | 7629 | "tmp.zig:1:21: error: expected integer, found 'f32'", |
| 7397 | }); | 7630 | }); |
| 7398 | | 7631 | |
| 7399 | cases.add("implicitly casting enum to tag type", | 7632 | ctx.objErrStage1("implicitly casting enum to tag type", |
| 7400 | \\const Small = enum(u2) { | 7633 | \\const Small = enum(u2) { |
| 7401 | \\ One, | 7634 | \\ One, |
| 7402 | \\ Two, | 7635 | \\ Two, |
| ... | @@ -7406,12 +7639,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -7406,12 +7639,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7406 | \\ | 7639 | \\ |
| 7407 | \\export fn entry() void { | 7640 | \\export fn entry() void { |
| 7408 | \\ var x: u2 = Small.Two; | 7641 | \\ var x: u2 = Small.Two; |
| | 7642 | \\ _ = x; |
| 7409 | \\} | 7643 | \\} |
| 7410 | , &[_][]const u8{ | 7644 | , &[_][]const u8{ |
| 7411 | "tmp.zig:9:22: error: expected type 'u2', found 'Small'", | 7645 | "tmp.zig:9:22: error: expected type 'u2', found 'Small'", |
| 7412 | }); | 7646 | }); |
| 7413 | | 7647 | |
| 7414 | cases.add("explicitly casting non tag type to enum", | 7648 | ctx.objErrStage1("explicitly casting non tag type to enum", |
| 7415 | \\const Small = enum(u2) { | 7649 | \\const Small = enum(u2) { |
| 7416 | \\ One, | 7650 | \\ One, |
| 7417 | \\ Two, | 7651 | \\ Two, |
| ... | @@ -7422,24 +7656,26 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -7422,24 +7656,26 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7422 | \\export fn entry() void { | 7656 | \\export fn entry() void { |
| 7423 | \\ var y = @as(u3, 3); | 7657 | \\ var y = @as(u3, 3); |
| 7424 | \\ var x = @intToEnum(Small, y); | 7658 | \\ var x = @intToEnum(Small, y); |
| | 7659 | \\ _ = x; |
| 7425 | \\} | 7660 | \\} |
| 7426 | , &[_][]const u8{ | 7661 | , &[_][]const u8{ |
| 7427 | "tmp.zig:10:31: error: expected type 'u2', found 'u3'", | 7662 | "tmp.zig:10:31: error: expected type 'u2', found 'u3'", |
| 7428 | }); | 7663 | }); |
| 7429 | | 7664 | |
| 7430 | cases.add("union fields with value assignments", | 7665 | ctx.objErrStage1("union fields with value assignments", |
| 7431 | \\const MultipleChoice = union { | 7666 | \\const MultipleChoice = union { |
| 7432 | \\ A: i32 = 20, | 7667 | \\ A: i32 = 20, |
| 7433 | \\}; | 7668 | \\}; |
| 7434 | \\export fn entry() void { | 7669 | \\export fn entry() void { |
| 7435 | \\ var x: MultipleChoice = undefined; | 7670 | \\ var x: MultipleChoice = undefined; |
| | 7671 | \\ _ = x; |
| 7436 | \\} | 7672 | \\} |
| 7437 | , &[_][]const u8{ | 7673 | , &[_][]const u8{ |
| 7438 | "tmp.zig:2:14: error: untagged union field assignment", | 7674 | "tmp.zig:2:14: error: untagged union field assignment", |
| 7439 | "tmp.zig:1:24: note: consider 'union(enum)' here", | 7675 | "tmp.zig:1:24: note: consider 'union(enum)' here", |
| 7440 | }); | 7676 | }); |
| 7441 | | 7677 | |
| 7442 | cases.add("enum with 0 fields", | 7678 | ctx.objErrStage1("enum with 0 fields", |
| 7443 | \\const Foo = enum {}; | 7679 | \\const Foo = enum {}; |
| 7444 | \\export fn entry() usize { | 7680 | \\export fn entry() usize { |
| 7445 | \\ return @sizeOf(Foo); | 7681 | \\ return @sizeOf(Foo); |
| ... | @@ -7448,16 +7684,16 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -7448,16 +7684,16 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7448 | "tmp.zig:1:13: error: enums must have 1 or more fields", | 7684 | "tmp.zig:1:13: error: enums must have 1 or more fields", |
| 7449 | }); | 7685 | }); |
| 7450 | | 7686 | |
| 7451 | cases.add("union with 0 fields", | 7687 | ctx.objErrStage1("union with 0 fields", |
| 7452 | \\const Foo = union {}; | 7688 | \\const Foo = union {}; |
| 7453 | \\export fn entry() usize { | 7689 | \\export fn entry() usize { |
| 7454 | \\ return @sizeOf(Foo); | 7690 | \\ return @sizeOf(Foo); |
| 7455 | \\} | 7691 | \\} |
| 7456 | , &[_][]const u8{ | 7692 | , &[_][]const u8{ |
| 7457 | "tmp.zig:1:13: error: unions must have 1 or more fields", | 7693 | "tmp.zig:1:13: error: union declarations must have at least one tag", |
| 7458 | }); | 7694 | }); |
| 7459 | | 7695 | |
| 7460 | cases.add("enum value already taken", | 7696 | ctx.objErrStage1("enum value already taken", |
| 7461 | \\const MultipleChoice = enum(u32) { | 7697 | \\const MultipleChoice = enum(u32) { |
| 7462 | \\ A = 20, | 7698 | \\ A = 20, |
| 7463 | \\ B = 40, | 7699 | \\ B = 40, |
| ... | @@ -7467,13 +7703,14 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -7467,13 +7703,14 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7467 | \\}; | 7703 | \\}; |
| 7468 | \\export fn entry() void { | 7704 | \\export fn entry() void { |
| 7469 | \\ var x = MultipleChoice.C; | 7705 | \\ var x = MultipleChoice.C; |
| | 7706 | \\ _ = x; |
| 7470 | \\} | 7707 | \\} |
| 7471 | , &[_][]const u8{ | 7708 | , &[_][]const u8{ |
| 7472 | "tmp.zig:6:5: error: enum tag value 60 already taken", | 7709 | "tmp.zig:6:5: error: enum tag value 60 already taken", |
| 7473 | "tmp.zig:4:5: note: other occurrence here", | 7710 | "tmp.zig:4:5: note: other occurrence here", |
| 7474 | }); | 7711 | }); |
| 7475 | | 7712 | |
| 7476 | cases.add("union with specified enum omits field", | 7713 | ctx.objErrStage1("union with specified enum omits field", |
| 7477 | \\const Letter = enum { | 7714 | \\const Letter = enum { |
| 7478 | \\ A, | 7715 | \\ A, |
| 7479 | \\ B, | 7716 | \\ B, |
| ... | @@ -7491,29 +7728,31 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -7491,29 +7728,31 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7491 | "tmp.zig:4:5: note: declared here", | 7728 | "tmp.zig:4:5: note: declared here", |
| 7492 | }); | 7729 | }); |
| 7493 | | 7730 | |
| 7494 | cases.add("non-integer tag type to automatic union enum", | 7731 | ctx.objErrStage1("non-integer tag type to automatic union enum", |
| 7495 | \\const Foo = union(enum(f32)) { | 7732 | \\const Foo = union(enum(f32)) { |
| 7496 | \\ A: i32, | 7733 | \\ A: i32, |
| 7497 | \\}; | 7734 | \\}; |
| 7498 | \\export fn entry() void { | 7735 | \\export fn entry() void { |
| 7499 | \\ const x = @typeInfo(Foo).Union.tag_type.?; | 7736 | \\ const x = @typeInfo(Foo).Union.tag_type.?; |
| | 7737 | \\ _ = x; |
| 7500 | \\} | 7738 | \\} |
| 7501 | , &[_][]const u8{ | 7739 | , &[_][]const u8{ |
| 7502 | "tmp.zig:1:24: error: expected integer tag type, found 'f32'", | 7740 | "tmp.zig:1:24: error: expected integer tag type, found 'f32'", |
| 7503 | }); | 7741 | }); |
| 7504 | | 7742 | |
| 7505 | cases.add("non-enum tag type passed to union", | 7743 | ctx.objErrStage1("non-enum tag type passed to union", |
| 7506 | \\const Foo = union(u32) { | 7744 | \\const Foo = union(u32) { |
| 7507 | \\ A: i32, | 7745 | \\ A: i32, |
| 7508 | \\}; | 7746 | \\}; |
| 7509 | \\export fn entry() void { | 7747 | \\export fn entry() void { |
| 7510 | \\ const x = @typeInfo(Foo).Union.tag_type.?; | 7748 | \\ const x = @typeInfo(Foo).Union.tag_type.?; |
| | 7749 | \\ _ = x; |
| 7511 | \\} | 7750 | \\} |
| 7512 | , &[_][]const u8{ | 7751 | , &[_][]const u8{ |
| 7513 | "tmp.zig:1:19: error: expected enum tag type, found 'u32'", | 7752 | "tmp.zig:1:19: error: expected enum tag type, found 'u32'", |
| 7514 | }); | 7753 | }); |
| 7515 | | 7754 | |
| 7516 | cases.add("union auto-enum value already taken", | 7755 | ctx.objErrStage1("union auto-enum value already taken", |
| 7517 | \\const MultipleChoice = union(enum(u32)) { | 7756 | \\const MultipleChoice = union(enum(u32)) { |
| 7518 | \\ A = 20, | 7757 | \\ A = 20, |
| 7519 | \\ B = 40, | 7758 | \\ B = 40, |
| ... | @@ -7523,13 +7762,14 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -7523,13 +7762,14 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7523 | \\}; | 7762 | \\}; |
| 7524 | \\export fn entry() void { | 7763 | \\export fn entry() void { |
| 7525 | \\ var x = MultipleChoice { .C = {} }; | 7764 | \\ var x = MultipleChoice { .C = {} }; |
| | 7765 | \\ _ = x; |
| 7526 | \\} | 7766 | \\} |
| 7527 | , &[_][]const u8{ | 7767 | , &[_][]const u8{ |
| 7528 | "tmp.zig:6:9: error: enum tag value 60 already taken", | 7768 | "tmp.zig:6:9: error: enum tag value 60 already taken", |
| 7529 | "tmp.zig:4:9: note: other occurrence here", | 7769 | "tmp.zig:4:9: note: other occurrence here", |
| 7530 | }); | 7770 | }); |
| 7531 | | 7771 | |
| 7532 | cases.add("union enum field does not match enum", | 7772 | ctx.objErrStage1("union enum field does not match enum", |
| 7533 | \\const Letter = enum { | 7773 | \\const Letter = enum { |
| 7534 | \\ A, | 7774 | \\ A, |
| 7535 | \\ B, | 7775 | \\ B, |
| ... | @@ -7543,13 +7783,14 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -7543,13 +7783,14 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7543 | \\}; | 7783 | \\}; |
| 7544 | \\export fn entry() void { | 7784 | \\export fn entry() void { |
| 7545 | \\ var a = Payload {.A = 1234}; | 7785 | \\ var a = Payload {.A = 1234}; |
| | 7786 | \\ _ = a; |
| 7546 | \\} | 7787 | \\} |
| 7547 | , &[_][]const u8{ | 7788 | , &[_][]const u8{ |
| 7548 | "tmp.zig:10:5: error: enum field not found: 'D'", | 7789 | "tmp.zig:10:5: error: enum field not found: 'D'", |
| 7549 | "tmp.zig:1:16: note: enum declared here", | 7790 | "tmp.zig:1:16: note: enum declared here", |
| 7550 | }); | 7791 | }); |
| 7551 | | 7792 | |
| 7552 | cases.add("field type supplied in an enum", | 7793 | ctx.objErrStage1("field type supplied in an enum", |
| 7553 | \\const Letter = enum { | 7794 | \\const Letter = enum { |
| 7554 | \\ A: void, | 7795 | \\ A: void, |
| 7555 | \\ B, | 7796 | \\ B, |
| ... | @@ -7557,35 +7798,38 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -7557,35 +7798,38 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7557 | \\}; | 7798 | \\}; |
| 7558 | \\export fn entry() void { | 7799 | \\export fn entry() void { |
| 7559 | \\ var b = Letter.B; | 7800 | \\ var b = Letter.B; |
| | 7801 | \\ _ = b; |
| 7560 | \\} | 7802 | \\} |
| 7561 | , &[_][]const u8{ | 7803 | , &[_][]const u8{ |
| 7562 | "tmp.zig:2:8: error: structs and unions, not enums, support field types", | 7804 | "tmp.zig:2:8: error: structs and unions, not enums, support field types", |
| 7563 | "tmp.zig:1:16: note: consider 'union(enum)' here", | 7805 | "tmp.zig:1:16: note: consider 'union(enum)' here", |
| 7564 | }); | 7806 | }); |
| 7565 | | 7807 | |
| 7566 | cases.add("struct field missing type", | 7808 | ctx.objErrStage1("struct field missing type", |
| 7567 | \\const Letter = struct { | 7809 | \\const Letter = struct { |
| 7568 | \\ A, | 7810 | \\ A, |
| 7569 | \\}; | 7811 | \\}; |
| 7570 | \\export fn entry() void { | 7812 | \\export fn entry() void { |
| 7571 | \\ var a = Letter { .A = {} }; | 7813 | \\ var a = Letter { .A = {} }; |
| | 7814 | \\ _ = a; |
| 7572 | \\} | 7815 | \\} |
| 7573 | , &[_][]const u8{ | 7816 | , &[_][]const u8{ |
| 7574 | "tmp.zig:2:5: error: struct field missing type", | 7817 | "tmp.zig:2:5: error: struct field missing type", |
| 7575 | }); | 7818 | }); |
| 7576 | | 7819 | |
| 7577 | cases.add("extern union field missing type", | 7820 | ctx.objErrStage1("extern union field missing type", |
| 7578 | \\const Letter = extern union { | 7821 | \\const Letter = extern union { |
| 7579 | \\ A, | 7822 | \\ A, |
| 7580 | \\}; | 7823 | \\}; |
| 7581 | \\export fn entry() void { | 7824 | \\export fn entry() void { |
| 7582 | \\ var a = Letter { .A = {} }; | 7825 | \\ var a = Letter { .A = {} }; |
| | 7826 | \\ _ = a; |
| 7583 | \\} | 7827 | \\} |
| 7584 | , &[_][]const u8{ | 7828 | , &[_][]const u8{ |
| 7585 | "tmp.zig:2:5: error: union field missing type", | 7829 | "tmp.zig:2:5: error: union field missing type", |
| 7586 | }); | 7830 | }); |
| 7587 | | 7831 | |
| 7588 | cases.add("extern union given enum tag type", | 7832 | ctx.objErrStage1("extern union given enum tag type", |
| 7589 | \\const Letter = enum { | 7833 | \\const Letter = enum { |
| 7590 | \\ A, | 7834 | \\ A, |
| 7591 | \\ B, | 7835 | \\ B, |
| ... | @@ -7598,12 +7842,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -7598,12 +7842,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7598 | \\}; | 7842 | \\}; |
| 7599 | \\export fn entry() void { | 7843 | \\export fn entry() void { |
| 7600 | \\ var a = Payload { .A = 1234 }; | 7844 | \\ var a = Payload { .A = 1234 }; |
| | 7845 | \\ _ = a; |
| 7601 | \\} | 7846 | \\} |
| 7602 | , &[_][]const u8{ | 7847 | , &[_][]const u8{ |
| 7603 | "tmp.zig:6:30: error: extern union does not support enum tag type", | 7848 | "tmp.zig:6:30: error: extern union does not support enum tag type", |
| 7604 | }); | 7849 | }); |
| 7605 | | 7850 | |
| 7606 | cases.add("packed union given enum tag type", | 7851 | ctx.objErrStage1("packed union given enum tag type", |
| 7607 | \\const Letter = enum { | 7852 | \\const Letter = enum { |
| 7608 | \\ A, | 7853 | \\ A, |
| 7609 | \\ B, | 7854 | \\ B, |
| ... | @@ -7616,12 +7861,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -7616,12 +7861,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7616 | \\}; | 7861 | \\}; |
| 7617 | \\export fn entry() void { | 7862 | \\export fn entry() void { |
| 7618 | \\ var a = Payload { .A = 1234 }; | 7863 | \\ var a = Payload { .A = 1234 }; |
| | 7864 | \\ _ = a; |
| 7619 | \\} | 7865 | \\} |
| 7620 | , &[_][]const u8{ | 7866 | , &[_][]const u8{ |
| 7621 | "tmp.zig:6:30: error: packed union does not support enum tag type", | 7867 | "tmp.zig:6:30: error: packed union does not support enum tag type", |
| 7622 | }); | 7868 | }); |
| 7623 | | 7869 | |
| 7624 | cases.add("packed union with automatic layout field", | 7870 | ctx.objErrStage1("packed union with automatic layout field", |
| 7625 | \\const Foo = struct { | 7871 | \\const Foo = struct { |
| 7626 | \\ a: u32, | 7872 | \\ a: u32, |
| 7627 | \\ b: f32, | 7873 | \\ b: f32, |
| ... | @@ -7632,12 +7878,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -7632,12 +7878,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7632 | \\}; | 7878 | \\}; |
| 7633 | \\export fn entry() void { | 7879 | \\export fn entry() void { |
| 7634 | \\ var a = Payload { .B = true }; | 7880 | \\ var a = Payload { .B = true }; |
| | 7881 | \\ _ = a; |
| 7635 | \\} | 7882 | \\} |
| 7636 | , &[_][]const u8{ | 7883 | , &[_][]const u8{ |
| 7637 | "tmp.zig:6:5: error: non-packed, non-extern struct 'Foo' not allowed in packed union; no guaranteed in-memory representation", | 7884 | "tmp.zig:6:5: error: non-packed, non-extern struct 'Foo' not allowed in packed union; no guaranteed in-memory representation", |
| 7638 | }); | 7885 | }); |
| 7639 | | 7886 | |
| 7640 | cases.add("switch on union with no attached enum", | 7887 | ctx.objErrStage1("switch on union with no attached enum", |
| 7641 | \\const Payload = union { | 7888 | \\const Payload = union { |
| 7642 | \\ A: i32, | 7889 | \\ A: i32, |
| 7643 | \\ B: f64, | 7890 | \\ B: f64, |
| ... | @@ -7658,20 +7905,21 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -7658,20 +7905,21 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7658 | "tmp.zig:1:17: note: consider 'union(enum)' here", | 7905 | "tmp.zig:1:17: note: consider 'union(enum)' here", |
| 7659 | }); | 7906 | }); |
| 7660 | | 7907 | |
| 7661 | cases.add("enum in field count range but not matching tag", | 7908 | ctx.objErrStage1("enum in field count range but not matching tag", |
| 7662 | \\const Foo = enum(u32) { | 7909 | \\const Foo = enum(u32) { |
| 7663 | \\ A = 10, | 7910 | \\ A = 10, |
| 7664 | \\ B = 11, | 7911 | \\ B = 11, |
| 7665 | \\}; | 7912 | \\}; |
| 7666 | \\export fn entry() void { | 7913 | \\export fn entry() void { |
| 7667 | \\ var x = @intToEnum(Foo, 0); | 7914 | \\ var x = @intToEnum(Foo, 0); |
| | 7915 | \\ _ = x; |
| 7668 | \\} | 7916 | \\} |
| 7669 | , &[_][]const u8{ | 7917 | , &[_][]const u8{ |
| 7670 | "tmp.zig:6:13: error: enum 'Foo' has no tag matching integer value 0", | 7918 | "tmp.zig:6:13: error: enum 'Foo' has no tag matching integer value 0", |
| 7671 | "tmp.zig:1:13: note: 'Foo' declared here", | 7919 | "tmp.zig:1:13: note: 'Foo' declared here", |
| 7672 | }); | 7920 | }); |
| 7673 | | 7921 | |
| 7674 | cases.add("comptime cast enum to union but field has payload", | 7922 | ctx.objErrStage1("comptime cast enum to union but field has payload", |
| 7675 | \\const Letter = enum { A, B, C }; | 7923 | \\const Letter = enum { A, B, C }; |
| 7676 | \\const Value = union(Letter) { | 7924 | \\const Value = union(Letter) { |
| 7677 | \\ A: i32, | 7925 | \\ A: i32, |
| ... | @@ -7680,13 +7928,14 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -7680,13 +7928,14 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7680 | \\}; | 7928 | \\}; |
| 7681 | \\export fn entry() void { | 7929 | \\export fn entry() void { |
| 7682 | \\ var x: Value = Letter.A; | 7930 | \\ var x: Value = Letter.A; |
| | 7931 | \\ _ = x; |
| 7683 | \\} | 7932 | \\} |
| 7684 | , &[_][]const u8{ | 7933 | , &[_][]const u8{ |
| 7685 | "tmp.zig:8:26: error: cast to union 'Value' must initialize 'i32' field 'A'", | 7934 | "tmp.zig:8:26: error: cast to union 'Value' must initialize 'i32' field 'A'", |
| 7686 | "tmp.zig:3:5: note: field 'A' declared here", | 7935 | "tmp.zig:3:5: note: field 'A' declared here", |
| 7687 | }); | 7936 | }); |
| 7688 | | 7937 | |
| 7689 | cases.add("runtime cast to union which has non-void fields", | 7938 | ctx.objErrStage1("runtime cast to union which has non-void fields", |
| 7690 | \\const Letter = enum { A, B, C }; | 7939 | \\const Letter = enum { A, B, C }; |
| 7691 | \\const Value = union(Letter) { | 7940 | \\const Value = union(Letter) { |
| 7692 | \\ A: i32, | 7941 | \\ A: i32, |
| ... | @@ -7698,13 +7947,14 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -7698,13 +7947,14 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7698 | \\} | 7947 | \\} |
| 7699 | \\fn foo(l: Letter) void { | 7948 | \\fn foo(l: Letter) void { |
| 7700 | \\ var x: Value = l; | 7949 | \\ var x: Value = l; |
| | 7950 | \\ _ = x; |
| 7701 | \\} | 7951 | \\} |
| 7702 | , &[_][]const u8{ | 7952 | , &[_][]const u8{ |
| 7703 | "tmp.zig:11:20: error: runtime cast to union 'Value' which has non-void fields", | 7953 | "tmp.zig:11:20: error: runtime cast to union 'Value' which has non-void fields", |
| 7704 | "tmp.zig:3:5: note: field 'A' has type 'i32'", | 7954 | "tmp.zig:3:5: note: field 'A' has type 'i32'", |
| 7705 | }); | 7955 | }); |
| 7706 | | 7956 | |
| 7707 | cases.add("taking byte offset of void field in struct", | 7957 | ctx.objErrStage1("taking byte offset of void field in struct", |
| 7708 | \\const Empty = struct { | 7958 | \\const Empty = struct { |
| 7709 | \\ val: void, | 7959 | \\ val: void, |
| 7710 | \\}; | 7960 | \\}; |
| ... | @@ -7715,7 +7965,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -7715,7 +7965,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7715 | "tmp.zig:5:42: error: zero-bit field 'val' in struct 'Empty' has no offset", | 7965 | "tmp.zig:5:42: error: zero-bit field 'val' in struct 'Empty' has no offset", |
| 7716 | }); | 7966 | }); |
| 7717 | | 7967 | |
| 7718 | cases.add("taking bit offset of void field in struct", | 7968 | ctx.objErrStage1("taking bit offset of void field in struct", |
| 7719 | \\const Empty = struct { | 7969 | \\const Empty = struct { |
| 7720 | \\ val: void, | 7970 | \\ val: void, |
| 7721 | \\}; | 7971 | \\}; |
| ... | @@ -7726,7 +7976,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -7726,7 +7976,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7726 | "tmp.zig:5:45: error: zero-bit field 'val' in struct 'Empty' has no offset", | 7976 | "tmp.zig:5:45: error: zero-bit field 'val' in struct 'Empty' has no offset", |
| 7727 | }); | 7977 | }); |
| 7728 | | 7978 | |
| 7729 | cases.add("invalid union field access in comptime", | 7979 | ctx.objErrStage1("invalid union field access in comptime", |
| 7730 | \\const Foo = union { | 7980 | \\const Foo = union { |
| 7731 | \\ Bar: u8, | 7981 | \\ Bar: u8, |
| 7732 | \\ Baz: void, | 7982 | \\ Baz: void, |
| ... | @@ -7739,7 +7989,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -7739,7 +7989,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7739 | "tmp.zig:7:24: error: accessing union field 'Bar' while field 'Baz' is set", | 7989 | "tmp.zig:7:24: error: accessing union field 'Bar' while field 'Baz' is set", |
| 7740 | }); | 7990 | }); |
| 7741 | | 7991 | |
| 7742 | cases.add("unsupported modifier at start of asm output constraint", | 7992 | ctx.objErrStage1("unsupported modifier at start of asm output constraint", |
| 7743 | \\export fn foo() void { | 7993 | \\export fn foo() void { |
| 7744 | \\ var bar: u32 = 3; | 7994 | \\ var bar: u32 = 3; |
| 7745 | \\ asm volatile ("" : [baz]"+r"(bar) : : ""); | 7995 | \\ asm volatile ("" : [baz]"+r"(bar) : : ""); |
| ... | @@ -7748,7 +7998,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -7748,7 +7998,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7748 | "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", | 7998 | "tmp.zig:3:5: error: invalid modifier starting output constraint for 'baz': '+', only '=' is supported. Compiler TODO: see https://github.com/ziglang/zig/issues/215", |
| 7749 | }); | 7999 | }); |
| 7750 | | 8000 | |
| 7751 | cases.add("comptime_int in asm input", | 8001 | ctx.objErrStage1("comptime_int in asm input", |
| 7752 | \\export fn foo() void { | 8002 | \\export fn foo() void { |
| 7753 | \\ asm volatile ("" : : [bar]"r"(3) : ""); | 8003 | \\ asm volatile ("" : : [bar]"r"(3) : ""); |
| 7754 | \\} | 8004 | \\} |
| ... | @@ -7756,7 +8006,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -7756,7 +8006,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7756 | "tmp.zig:2:35: error: expected sized integer or sized float, found comptime_int", | 8006 | "tmp.zig:2:35: error: expected sized integer or sized float, found comptime_int", |
| 7757 | }); | 8007 | }); |
| 7758 | | 8008 | |
| 7759 | cases.add("comptime_float in asm input", | 8009 | ctx.objErrStage1("comptime_float in asm input", |
| 7760 | \\export fn foo() void { | 8010 | \\export fn foo() void { |
| 7761 | \\ asm volatile ("" : : [bar]"r"(3.17) : ""); | 8011 | \\ asm volatile ("" : : [bar]"r"(3.17) : ""); |
| 7762 | \\} | 8012 | \\} |
| ... | @@ -7764,7 +8014,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -7764,7 +8014,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7764 | "tmp.zig:2:35: error: expected sized integer or sized float, found comptime_float", | 8014 | "tmp.zig:2:35: error: expected sized integer or sized float, found comptime_float", |
| 7765 | }); | 8015 | }); |
| 7766 | | 8016 | |
| 7767 | cases.add("runtime assignment to comptime struct type", | 8017 | ctx.objErrStage1("runtime assignment to comptime struct type", |
| 7768 | \\const Foo = struct { | 8018 | \\const Foo = struct { |
| 7769 | \\ Bar: u8, | 8019 | \\ Bar: u8, |
| 7770 | \\ Baz: type, | 8020 | \\ Baz: type, |
| ... | @@ -7772,12 +8022,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -7772,12 +8022,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7772 | \\export fn f() void { | 8022 | \\export fn f() void { |
| 7773 | \\ var x: u8 = 0; | 8023 | \\ var x: u8 = 0; |
| 7774 | \\ const foo = Foo { .Bar = x, .Baz = u8 }; | 8024 | \\ const foo = Foo { .Bar = x, .Baz = u8 }; |
| | 8025 | \\ _ = foo; |
| 7775 | \\} | 8026 | \\} |
| 7776 | , &[_][]const u8{ | 8027 | , &[_][]const u8{ |
| 7777 | "tmp.zig:7:23: error: unable to evaluate constant expression", | 8028 | "tmp.zig:7:23: error: unable to evaluate constant expression", |
| 7778 | }); | 8029 | }); |
| 7779 | | 8030 | |
| 7780 | cases.add("runtime assignment to comptime union type", | 8031 | ctx.objErrStage1("runtime assignment to comptime union type", |
| 7781 | \\const Foo = union { | 8032 | \\const Foo = union { |
| 7782 | \\ Bar: u8, | 8033 | \\ Bar: u8, |
| 7783 | \\ Baz: type, | 8034 | \\ Baz: type, |
| ... | @@ -7785,16 +8036,18 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -7785,16 +8036,18 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7785 | \\export fn f() void { | 8036 | \\export fn f() void { |
| 7786 | \\ var x: u8 = 0; | 8037 | \\ var x: u8 = 0; |
| 7787 | \\ const foo = Foo { .Bar = x }; | 8038 | \\ const foo = Foo { .Bar = x }; |
| | 8039 | \\ _ = foo; |
| 7788 | \\} | 8040 | \\} |
| 7789 | , &[_][]const u8{ | 8041 | , &[_][]const u8{ |
| 7790 | "tmp.zig:7:23: error: unable to evaluate constant expression", | 8042 | "tmp.zig:7:23: error: unable to evaluate constant expression", |
| 7791 | }); | 8043 | }); |
| 7792 | | 8044 | |
| 7793 | cases.addTest("@shuffle with selected index past first vector length", | 8045 | ctx.testErrStage1("@shuffle with selected index past first vector length", |
| 7794 | \\export fn entry() void { | 8046 | \\export fn entry() void { |
| 7795 | \\ const v: @import("std").meta.Vector(4, u32) = [4]u32{ 10, 11, 12, 13 }; | 8047 | \\ const v: @import("std").meta.Vector(4, u32) = [4]u32{ 10, 11, 12, 13 }; |
| 7796 | \\ const x: @import("std").meta.Vector(4, u32) = [4]u32{ 14, 15, 16, 17 }; | 8048 | \\ const x: @import("std").meta.Vector(4, u32) = [4]u32{ 14, 15, 16, 17 }; |
| 7797 | \\ var z = @shuffle(u32, v, x, [8]i32{ 0, 1, 2, 3, 7, 6, 5, 4 }); | 8049 | \\ var z = @shuffle(u32, v, x, [8]i32{ 0, 1, 2, 3, 7, 6, 5, 4 }); |
| | 8050 | \\ _ = z; |
| 7798 | \\} | 8051 | \\} |
| 7799 | , &[_][]const u8{ | 8052 | , &[_][]const u8{ |
| 7800 | "tmp.zig:4:39: error: mask index '4' has out-of-bounds selection", | 8053 | "tmp.zig:4:39: error: mask index '4' has out-of-bounds selection", |
| ... | @@ -7802,27 +8055,29 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -7802,27 +8055,29 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7802 | "tmp.zig:4:30: note: selections from the second vector are specified with negative numbers", | 8055 | "tmp.zig:4:30: note: selections from the second vector are specified with negative numbers", |
| 7803 | }); | 8056 | }); |
| 7804 | | 8057 | |
| 7805 | cases.addTest("nested vectors", | 8058 | ctx.testErrStage1("nested vectors", |
| 7806 | \\export fn entry() void { | 8059 | \\export fn entry() void { |
| 7807 | \\ const V1 = @import("std").meta.Vector(4, u8); | 8060 | \\ const V1 = @import("std").meta.Vector(4, u8); |
| 7808 | \\ const V2 = @Type(@import("std").builtin.TypeInfo{ .Vector = .{ .len = 4, .child = V1 } }); | 8061 | \\ const V2 = @Type(@import("std").builtin.TypeInfo{ .Vector = .{ .len = 4, .child = V1 } }); |
| 7809 | \\ var v: V2 = undefined; | 8062 | \\ var v: V2 = undefined; |
| | 8063 | \\ _ = v; |
| 7810 | \\} | 8064 | \\} |
| 7811 | , &[_][]const u8{ | 8065 | , &[_][]const u8{ |
| 7812 | "tmp.zig:3:53: error: vector element type must be integer, float, bool, or pointer; '@Vector(4, u8)' is invalid", | 8066 | "tmp.zig:3:53: error: vector element type must be integer, float, bool, or pointer; '@Vector(4, u8)' is invalid", |
| 7813 | "tmp.zig:3:16: note: referenced here", | 8067 | "tmp.zig:3:16: note: referenced here", |
| 7814 | }); | 8068 | }); |
| 7815 | | 8069 | |
| 7816 | cases.addTest("bad @splat type", | 8070 | ctx.testErrStage1("bad @splat type", |
| 7817 | \\export fn entry() void { | 8071 | \\export fn entry() void { |
| 7818 | \\ const c = 4; | 8072 | \\ const c = 4; |
| 7819 | \\ var v = @splat(4, c); | 8073 | \\ var v = @splat(4, c); |
| | 8074 | \\ _ = v; |
| 7820 | \\} | 8075 | \\} |
| 7821 | , &[_][]const u8{ | 8076 | , &[_][]const u8{ |
| 7822 | "tmp.zig:3:23: error: vector element type must be integer, float, bool, or pointer; 'comptime_int' is invalid", | 8077 | "tmp.zig:3:23: error: vector element type must be integer, float, bool, or pointer; 'comptime_int' is invalid", |
| 7823 | }); | 8078 | }); |
| 7824 | | 8079 | |
| 7825 | cases.add("compileLog of tagged enum doesn't crash the compiler", | 8080 | ctx.objErrStage1("compileLog of tagged enum doesn't crash the compiler", |
| 7826 | \\const Bar = union(enum(u32)) { | 8081 | \\const Bar = union(enum(u32)) { |
| 7827 | \\ X: i32 = 1 | 8082 | \\ X: i32 = 1 |
| 7828 | \\}; | 8083 | \\}; |
| ... | @@ -7838,7 +8093,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -7838,7 +8093,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7838 | "tmp.zig:6:5: error: found compile log statement", | 8093 | "tmp.zig:6:5: error: found compile log statement", |
| 7839 | }); | 8094 | }); |
| 7840 | | 8095 | |
| 7841 | cases.add("attempted implicit cast from *const T to *[1]T", | 8096 | ctx.objErrStage1("attempted implicit cast from *const T to *[1]T", |
| 7842 | \\export fn entry(byte: u8) void { | 8097 | \\export fn entry(byte: u8) void { |
| 7843 | \\ const w: i32 = 1234; | 8098 | \\ const w: i32 = 1234; |
| 7844 | \\ var x: *const i32 = &w; | 8099 | \\ var x: *const i32 = &w; |
| ... | @@ -7850,16 +8105,17 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -7850,16 +8105,17 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7850 | "tmp.zig:4:22: note: cast discards const qualifier", | 8105 | "tmp.zig:4:22: note: cast discards const qualifier", |
| 7851 | }); | 8106 | }); |
| 7852 | | 8107 | |
| 7853 | cases.add("attempted implicit cast from *const T to []T", | 8108 | ctx.objErrStage1("attempted implicit cast from *const T to []T", |
| 7854 | \\export fn entry() void { | 8109 | \\export fn entry() void { |
| 7855 | \\ const u: u32 = 42; | 8110 | \\ const u: u32 = 42; |
| 7856 | \\ const x: []u32 = &u; | 8111 | \\ const x: []u32 = &u; |
| | 8112 | \\ _ = x; |
| 7857 | \\} | 8113 | \\} |
| 7858 | , &[_][]const u8{ | 8114 | , &[_][]const u8{ |
| 7859 | "tmp.zig:3:23: error: expected type '[]u32', found '*const u32'", | 8115 | "tmp.zig:3:23: error: expected type '[]u32', found '*const u32'", |
| 7860 | }); | 8116 | }); |
| 7861 | | 8117 | |
| 7862 | cases.add("for loop body expression ignored", | 8118 | ctx.objErrStage1("for loop body expression ignored", |
| 7863 | \\fn returns() usize { | 8119 | \\fn returns() usize { |
| 7864 | \\ return 2; | 8120 | \\ return 2; |
| 7865 | \\} | 8121 | \\} |
| ... | @@ -7875,7 +8131,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -7875,7 +8131,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7875 | "tmp.zig:9:30: error: expression value is ignored", | 8131 | "tmp.zig:9:30: error: expression value is ignored", |
| 7876 | }); | 8132 | }); |
| 7877 | | 8133 | |
| 7878 | cases.add("aligned variable of zero-bit type", | 8134 | ctx.objErrStage1("aligned variable of zero-bit type", |
| 7879 | \\export fn f() void { | 8135 | \\export fn f() void { |
| 7880 | \\ var s: struct {} align(4) = undefined; | 8136 | \\ var s: struct {} align(4) = undefined; |
| 7881 | \\} | 8137 | \\} |
| ... | @@ -7883,7 +8139,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -7883,7 +8139,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7883 | "tmp.zig:2:5: error: variable 's' of zero-bit type 'struct:2:12' has no in-memory representation, it cannot be aligned", | 8139 | "tmp.zig:2:5: error: variable 's' of zero-bit type 'struct:2:12' has no in-memory representation, it cannot be aligned", |
| 7884 | }); | 8140 | }); |
| 7885 | | 8141 | |
| 7886 | cases.add("function returning opaque type", | 8142 | ctx.objErrStage1("function returning opaque type", |
| 7887 | \\const FooType = opaque {}; | 8143 | \\const FooType = opaque {}; |
| 7888 | \\export fn bar() !FooType { | 8144 | \\export fn bar() !FooType { |
| 7889 | \\ return error.InvalidValue; | 8145 | \\ return error.InvalidValue; |
| ... | @@ -7901,7 +8157,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -7901,7 +8157,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7901 | "tmp.zig:8:18: error: Undefined return type '(undefined)' not allowed", | 8157 | "tmp.zig:8:18: error: Undefined return type '(undefined)' not allowed", |
| 7902 | }); | 8158 | }); |
| 7903 | | 8159 | |
| 7904 | cases.add("generic function returning opaque type", | 8160 | ctx.objErrStage1("generic function returning opaque type", |
| 7905 | \\const FooType = opaque {}; | 8161 | \\const FooType = opaque {}; |
| 7906 | \\fn generic(comptime T: type) !T { | 8162 | \\fn generic(comptime T: type) !T { |
| 7907 | \\ return undefined; | 8163 | \\ return undefined; |
| ... | @@ -7925,22 +8181,24 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -7925,22 +8181,24 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7925 | "tmp.zig:2:1: note: function declared here", | 8181 | "tmp.zig:2:1: note: function declared here", |
| 7926 | }); | 8182 | }); |
| 7927 | | 8183 | |
| 7928 | cases.add("function parameter is opaque", | 8184 | ctx.objErrStage1("function parameter is opaque", |
| 7929 | \\const FooType = opaque {}; | 8185 | \\const FooType = opaque {}; |
| 7930 | \\export fn entry1() void { | 8186 | \\export fn entry1() void { |
| 7931 | \\ const someFuncPtr: fn (FooType) void = undefined; | 8187 | \\ const someFuncPtr: fn (FooType) void = undefined; |
| | 8188 | \\ _ = someFuncPtr; |
| 7932 | \\} | 8189 | \\} |
| 7933 | \\ | 8190 | \\ |
| 7934 | \\export fn entry2() void { | 8191 | \\export fn entry2() void { |
| 7935 | \\ const someFuncPtr: fn (@TypeOf(null)) void = undefined; | 8192 | \\ const someFuncPtr: fn (@TypeOf(null)) void = undefined; |
| | 8193 | \\ _ = someFuncPtr; |
| 7936 | \\} | 8194 | \\} |
| 7937 | \\ | 8195 | \\ |
| 7938 | \\fn foo(p: FooType) void {} | 8196 | \\fn foo(p: FooType) void {_ = p;} |
| 7939 | \\export fn entry3() void { | 8197 | \\export fn entry3() void { |
| 7940 | \\ _ = foo; | 8198 | \\ _ = foo; |
| 7941 | \\} | 8199 | \\} |
| 7942 | \\ | 8200 | \\ |
| 7943 | \\fn bar(p: @TypeOf(null)) void {} | 8201 | \\fn bar(p: @TypeOf(null)) void {_ = p;} |
| 7944 | \\export fn entry4() void { | 8202 | \\export fn entry4() void { |
| 7945 | \\ _ = bar; | 8203 | \\ _ = bar; |
| 7946 | \\} | 8204 | \\} |
| ... | @@ -7951,30 +8209,34 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -7951,30 +8209,34 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7951 | "tmp.zig:15:11: error: parameter of type '(null)' not allowed", | 8209 | "tmp.zig:15:11: error: parameter of type '(null)' not allowed", |
| 7952 | }); | 8210 | }); |
| 7953 | | 8211 | |
| 7954 | cases.add( // fixed bug #2032 | 8212 | ctx.objErrStage1( // fixed bug #2032 |
| 7955 | "compile diagnostic string for top level decl type", | 8213 | "compile diagnostic string for top level decl type", |
| 7956 | \\export fn entry() void { | 8214 | \\export fn entry() void { |
| 7957 | \\ var foo: u32 = @This(){}; | 8215 | \\ var foo: u32 = @This(){}; |
| | 8216 | \\ _ = foo; |
| 7958 | \\} | 8217 | \\} |
| 7959 | , &[_][]const u8{ | 8218 | , &[_][]const u8{ |
| 7960 | "tmp.zig:2:27: error: type 'u32' does not support array initialization", | 8219 | "tmp.zig:2:27: error: type 'u32' does not support array initialization", |
| 7961 | }); | 8220 | }); |
| 7962 | | 8221 | |
| 7963 | cases.add("issue #2687: coerce from undefined array pointer to slice", | 8222 | ctx.objErrStage1("issue #2687: coerce from undefined array pointer to slice", |
| 7964 | \\export fn foo1() void { | 8223 | \\export fn foo1() void { |
| 7965 | \\ const a: *[1]u8 = undefined; | 8224 | \\ const a: *[1]u8 = undefined; |
| 7966 | \\ var b: []u8 = a; | 8225 | \\ var b: []u8 = a; |
| | 8226 | \\ _ = b; |
| 7967 | \\} | 8227 | \\} |
| 7968 | \\export fn foo2() void { | 8228 | \\export fn foo2() void { |
| 7969 | \\ comptime { | 8229 | \\ comptime { |
| 7970 | \\ var a: *[1]u8 = undefined; | 8230 | \\ var a: *[1]u8 = undefined; |
| 7971 | \\ var b: []u8 = a; | 8231 | \\ var b: []u8 = a; |
| | 8232 | \\ _ = b; |
| 7972 | \\ } | 8233 | \\ } |
| 7973 | \\} | 8234 | \\} |
| 7974 | \\export fn foo3() void { | 8235 | \\export fn foo3() void { |
| 7975 | \\ comptime { | 8236 | \\ comptime { |
| 7976 | \\ const a: *[1]u8 = undefined; | 8237 | \\ const a: *[1]u8 = undefined; |
| 7977 | \\ var b: []u8 = a; | 8238 | \\ var b: []u8 = a; |
| | 8239 | \\ _ = b; |
| 7978 | \\ } | 8240 | \\ } |
| 7979 | \\} | 8241 | \\} |
| 7980 | , &[_][]const u8{ | 8242 | , &[_][]const u8{ |
| ... | @@ -7983,14 +8245,16 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -7983,14 +8245,16 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7983 | "tmp.zig:14:23: error: use of undefined value here causes undefined behavior", | 8245 | "tmp.zig:14:23: error: use of undefined value here causes undefined behavior", |
| 7984 | }); | 8246 | }); |
| 7985 | | 8247 | |
| 7986 | cases.add("issue #3818: bitcast from parray/slice to u16", | 8248 | ctx.objErrStage1("issue #3818: bitcast from parray/slice to u16", |
| 7987 | \\export fn foo1() void { | 8249 | \\export fn foo1() void { |
| 7988 | \\ var bytes = [_]u8{1, 2}; | 8250 | \\ var bytes = [_]u8{1, 2}; |
| 7989 | \\ const word: u16 = @bitCast(u16, bytes[0..]); | 8251 | \\ const word: u16 = @bitCast(u16, bytes[0..]); |
| | 8252 | \\ _ = word; |
| 7990 | \\} | 8253 | \\} |
| 7991 | \\export fn foo2() void { | 8254 | \\export fn foo2() void { |
| 7992 | \\ var bytes: []const u8 = &[_]u8{1, 2}; | 8255 | \\ var bytes: []const u8 = &[_]u8{1, 2}; |
| 7993 | \\ const word: u16 = @bitCast(u16, bytes); | 8256 | \\ const word: u16 = @bitCast(u16, bytes); |
| | 8257 | \\ _ = word; |
| 7994 | \\} | 8258 | \\} |
| 7995 | , &[_][]const u8{ | 8259 | , &[_][]const u8{ |
| 7996 | "tmp.zig:3:42: error: unable to @bitCast from pointer type '*[2]u8'", | 8260 | "tmp.zig:3:42: error: unable to @bitCast from pointer type '*[2]u8'", |
| ... | @@ -7999,7 +8263,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -7999,7 +8263,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7999 | }); | 8263 | }); |
| 8000 | | 8264 | |
| 8001 | // issue #7810 | 8265 | // issue #7810 |
| 8002 | cases.add("comptime slice-len increment beyond bounds", | 8266 | ctx.objErrStage1("comptime slice-len increment beyond bounds", |
| 8003 | \\export fn foo_slice_len_increment_beyond_bounds() void { | 8267 | \\export fn foo_slice_len_increment_beyond_bounds() void { |
| 8004 | \\ comptime { | 8268 | \\ comptime { |
| 8005 | \\ var buf_storage: [8]u8 = undefined; | 8269 | \\ var buf_storage: [8]u8 = undefined; |
| ... | @@ -8012,11 +8276,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -8012,11 +8276,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 8012 | ":6:12: error: out of bounds slice", | 8276 | ":6:12: error: out of bounds slice", |
| 8013 | }); | 8277 | }); |
| 8014 | | 8278 | |
| 8015 | cases.add("comptime slice-sentinel is out of bounds (unterminated)", | 8279 | ctx.objErrStage1("comptime slice-sentinel is out of bounds (unterminated)", |
| 8016 | \\export fn foo_array() void { | 8280 | \\export fn foo_array() void { |
| 8017 | \\ comptime { | 8281 | \\ comptime { |
| 8018 | \\ var target = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; | 8282 | \\ var target = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; |
| 8019 | \\ const slice = target[0..14 :0]; | 8283 | \\ const slice = target[0..14 :0]; |
| | 8284 | \\ _ = slice; |
| 8020 | \\ } | 8285 | \\ } |
| 8021 | \\} | 8286 | \\} |
| 8022 | \\export fn foo_ptr_array() void { | 8287 | \\export fn foo_ptr_array() void { |
| ... | @@ -8024,6 +8289,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -8024,6 +8289,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 8024 | \\ var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; | 8289 | \\ var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; |
| 8025 | \\ var target = &buf; | 8290 | \\ var target = &buf; |
| 8026 | \\ const slice = target[0..14 :0]; | 8291 | \\ const slice = target[0..14 :0]; |
| | 8292 | \\ _ = slice; |
| 8027 | \\ } | 8293 | \\ } |
| 8028 | \\} | 8294 | \\} |
| 8029 | \\export fn foo_vector_ConstPtrSpecialBaseArray() void { | 8295 | \\export fn foo_vector_ConstPtrSpecialBaseArray() void { |
| ... | @@ -8031,6 +8297,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -8031,6 +8297,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 8031 | \\ var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; | 8297 | \\ var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; |
| 8032 | \\ var target: [*]u8 = &buf; | 8298 | \\ var target: [*]u8 = &buf; |
| 8033 | \\ const slice = target[0..14 :0]; | 8299 | \\ const slice = target[0..14 :0]; |
| | 8300 | \\ _ = slice; |
| 8034 | \\ } | 8301 | \\ } |
| 8035 | \\} | 8302 | \\} |
| 8036 | \\export fn foo_vector_ConstPtrSpecialRef() void { | 8303 | \\export fn foo_vector_ConstPtrSpecialRef() void { |
| ... | @@ -8038,6 +8305,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -8038,6 +8305,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 8038 | \\ var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; | 8305 | \\ var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; |
| 8039 | \\ var target: [*]u8 = @ptrCast([*]u8, &buf); | 8306 | \\ var target: [*]u8 = @ptrCast([*]u8, &buf); |
| 8040 | \\ const slice = target[0..14 :0]; | 8307 | \\ const slice = target[0..14 :0]; |
| | 8308 | \\ _ = slice; |
| 8041 | \\ } | 8309 | \\ } |
| 8042 | \\} | 8310 | \\} |
| 8043 | \\export fn foo_cvector_ConstPtrSpecialBaseArray() void { | 8311 | \\export fn foo_cvector_ConstPtrSpecialBaseArray() void { |
| ... | @@ -8045,6 +8313,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -8045,6 +8313,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 8045 | \\ var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; | 8313 | \\ var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; |
| 8046 | \\ var target: [*c]u8 = &buf; | 8314 | \\ var target: [*c]u8 = &buf; |
| 8047 | \\ const slice = target[0..14 :0]; | 8315 | \\ const slice = target[0..14 :0]; |
| | 8316 | \\ _ = slice; |
| 8048 | \\ } | 8317 | \\ } |
| 8049 | \\} | 8318 | \\} |
| 8050 | \\export fn foo_cvector_ConstPtrSpecialRef() void { | 8319 | \\export fn foo_cvector_ConstPtrSpecialRef() void { |
| ... | @@ -8052,6 +8321,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -8052,6 +8321,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 8052 | \\ var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; | 8321 | \\ var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; |
| 8053 | \\ var target: [*c]u8 = @ptrCast([*c]u8, &buf); | 8322 | \\ var target: [*c]u8 = @ptrCast([*c]u8, &buf); |
| 8054 | \\ const slice = target[0..14 :0]; | 8323 | \\ const slice = target[0..14 :0]; |
| | 8324 | \\ _ = slice; |
| 8055 | \\ } | 8325 | \\ } |
| 8056 | \\} | 8326 | \\} |
| 8057 | \\export fn foo_slice() void { | 8327 | \\export fn foo_slice() void { |
| ... | @@ -8059,6 +8329,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -8059,6 +8329,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 8059 | \\ var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; | 8329 | \\ var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; |
| 8060 | \\ var target: []u8 = &buf; | 8330 | \\ var target: []u8 = &buf; |
| 8061 | \\ const slice = target[0..14 :0]; | 8331 | \\ const slice = target[0..14 :0]; |
| | 8332 | \\ _ = slice; |
| 8062 | \\ } | 8333 | \\ } |
| 8063 | \\} | 8334 | \\} |
| 8064 | , &[_][]const u8{ | 8335 | , &[_][]const u8{ |
| ... | @@ -8071,11 +8342,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -8071,11 +8342,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 8071 | ":46:29: error: slice-sentinel is out of bounds", | 8342 | ":46:29: error: slice-sentinel is out of bounds", |
| 8072 | }); | 8343 | }); |
| 8073 | | 8344 | |
| 8074 | cases.add("comptime slice-sentinel is out of bounds (terminated)", | 8345 | ctx.objErrStage1("comptime slice-sentinel is out of bounds (terminated)", |
| 8075 | \\export fn foo_array() void { | 8346 | \\export fn foo_array() void { |
| 8076 | \\ comptime { | 8347 | \\ comptime { |
| 8077 | \\ var target = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; | 8348 | \\ var target = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; |
| 8078 | \\ const slice = target[0..15 :1]; | 8349 | \\ const slice = target[0..15 :1]; |
| | 8350 | \\ _ = slice; |
| 8079 | \\ } | 8351 | \\ } |
| 8080 | \\} | 8352 | \\} |
| 8081 | \\export fn foo_ptr_array() void { | 8353 | \\export fn foo_ptr_array() void { |
| ... | @@ -8083,6 +8355,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -8083,6 +8355,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 8083 | \\ var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; | 8355 | \\ var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; |
| 8084 | \\ var target = &buf; | 8356 | \\ var target = &buf; |
| 8085 | \\ const slice = target[0..15 :0]; | 8357 | \\ const slice = target[0..15 :0]; |
| | 8358 | \\ _ = slice; |
| 8086 | \\ } | 8359 | \\ } |
| 8087 | \\} | 8360 | \\} |
| 8088 | \\export fn foo_vector_ConstPtrSpecialBaseArray() void { | 8361 | \\export fn foo_vector_ConstPtrSpecialBaseArray() void { |
| ... | @@ -8090,6 +8363,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -8090,6 +8363,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 8090 | \\ var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; | 8363 | \\ var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; |
| 8091 | \\ var target: [*]u8 = &buf; | 8364 | \\ var target: [*]u8 = &buf; |
| 8092 | \\ const slice = target[0..15 :0]; | 8365 | \\ const slice = target[0..15 :0]; |
| | 8366 | \\ _ = slice; |
| 8093 | \\ } | 8367 | \\ } |
| 8094 | \\} | 8368 | \\} |
| 8095 | \\export fn foo_vector_ConstPtrSpecialRef() void { | 8369 | \\export fn foo_vector_ConstPtrSpecialRef() void { |
| ... | @@ -8097,6 +8371,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -8097,6 +8371,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 8097 | \\ var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; | 8371 | \\ var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; |
| 8098 | \\ var target: [*]u8 = @ptrCast([*]u8, &buf); | 8372 | \\ var target: [*]u8 = @ptrCast([*]u8, &buf); |
| 8099 | \\ const slice = target[0..15 :0]; | 8373 | \\ const slice = target[0..15 :0]; |
| | 8374 | \\ _ = slice; |
| 8100 | \\ } | 8375 | \\ } |
| 8101 | \\} | 8376 | \\} |
| 8102 | \\export fn foo_cvector_ConstPtrSpecialBaseArray() void { | 8377 | \\export fn foo_cvector_ConstPtrSpecialBaseArray() void { |
| ... | @@ -8104,6 +8379,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -8104,6 +8379,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 8104 | \\ var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; | 8379 | \\ var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; |
| 8105 | \\ var target: [*c]u8 = &buf; | 8380 | \\ var target: [*c]u8 = &buf; |
| 8106 | \\ const slice = target[0..15 :0]; | 8381 | \\ const slice = target[0..15 :0]; |
| | 8382 | \\ _ = slice; |
| 8107 | \\ } | 8383 | \\ } |
| 8108 | \\} | 8384 | \\} |
| 8109 | \\export fn foo_cvector_ConstPtrSpecialRef() void { | 8385 | \\export fn foo_cvector_ConstPtrSpecialRef() void { |
| ... | @@ -8111,6 +8387,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -8111,6 +8387,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 8111 | \\ var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; | 8387 | \\ var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; |
| 8112 | \\ var target: [*c]u8 = @ptrCast([*c]u8, &buf); | 8388 | \\ var target: [*c]u8 = @ptrCast([*c]u8, &buf); |
| 8113 | \\ const slice = target[0..15 :0]; | 8389 | \\ const slice = target[0..15 :0]; |
| | 8390 | \\ _ = slice; |
| 8114 | \\ } | 8391 | \\ } |
| 8115 | \\} | 8392 | \\} |
| 8116 | \\export fn foo_slice() void { | 8393 | \\export fn foo_slice() void { |
| ... | @@ -8118,6 +8395,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -8118,6 +8395,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 8118 | \\ var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; | 8395 | \\ var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; |
| 8119 | \\ var target: []u8 = &buf; | 8396 | \\ var target: []u8 = &buf; |
| 8120 | \\ const slice = target[0..15 :0]; | 8397 | \\ const slice = target[0..15 :0]; |
| | 8398 | \\ _ = slice; |
| 8121 | \\ } | 8399 | \\ } |
| 8122 | \\} | 8400 | \\} |
| 8123 | , &[_][]const u8{ | 8401 | , &[_][]const u8{ |
| ... | @@ -8130,11 +8408,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -8130,11 +8408,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 8130 | ":46:29: error: out of bounds slice", | 8408 | ":46:29: error: out of bounds slice", |
| 8131 | }); | 8409 | }); |
| 8132 | | 8410 | |
| 8133 | cases.add("comptime slice-sentinel does not match memory at target index (unterminated)", | 8411 | ctx.objErrStage1("comptime slice-sentinel does not match memory at target index (unterminated)", |
| 8134 | \\export fn foo_array() void { | 8412 | \\export fn foo_array() void { |
| 8135 | \\ comptime { | 8413 | \\ comptime { |
| 8136 | \\ var target = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; | 8414 | \\ var target = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; |
| 8137 | \\ const slice = target[0..3 :0]; | 8415 | \\ const slice = target[0..3 :0]; |
| | 8416 | \\ _ = slice; |
| 8138 | \\ } | 8417 | \\ } |
| 8139 | \\} | 8418 | \\} |
| 8140 | \\export fn foo_ptr_array() void { | 8419 | \\export fn foo_ptr_array() void { |
| ... | @@ -8142,6 +8421,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -8142,6 +8421,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 8142 | \\ var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; | 8421 | \\ var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; |
| 8143 | \\ var target = &buf; | 8422 | \\ var target = &buf; |
| 8144 | \\ const slice = target[0..3 :0]; | 8423 | \\ const slice = target[0..3 :0]; |
| | 8424 | \\ _ = slice; |
| 8145 | \\ } | 8425 | \\ } |
| 8146 | \\} | 8426 | \\} |
| 8147 | \\export fn foo_vector_ConstPtrSpecialBaseArray() void { | 8427 | \\export fn foo_vector_ConstPtrSpecialBaseArray() void { |
| ... | @@ -8149,6 +8429,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -8149,6 +8429,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 8149 | \\ var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; | 8429 | \\ var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; |
| 8150 | \\ var target: [*]u8 = &buf; | 8430 | \\ var target: [*]u8 = &buf; |
| 8151 | \\ const slice = target[0..3 :0]; | 8431 | \\ const slice = target[0..3 :0]; |
| | 8432 | \\ _ = slice; |
| 8152 | \\ } | 8433 | \\ } |
| 8153 | \\} | 8434 | \\} |
| 8154 | \\export fn foo_vector_ConstPtrSpecialRef() void { | 8435 | \\export fn foo_vector_ConstPtrSpecialRef() void { |
| ... | @@ -8156,6 +8437,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -8156,6 +8437,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 8156 | \\ var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; | 8437 | \\ var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; |
| 8157 | \\ var target: [*]u8 = @ptrCast([*]u8, &buf); | 8438 | \\ var target: [*]u8 = @ptrCast([*]u8, &buf); |
| 8158 | \\ const slice = target[0..3 :0]; | 8439 | \\ const slice = target[0..3 :0]; |
| | 8440 | \\ _ = slice; |
| 8159 | \\ } | 8441 | \\ } |
| 8160 | \\} | 8442 | \\} |
| 8161 | \\export fn foo_cvector_ConstPtrSpecialBaseArray() void { | 8443 | \\export fn foo_cvector_ConstPtrSpecialBaseArray() void { |
| ... | @@ -8163,6 +8445,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -8163,6 +8445,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 8163 | \\ var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; | 8445 | \\ var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; |
| 8164 | \\ var target: [*c]u8 = &buf; | 8446 | \\ var target: [*c]u8 = &buf; |
| 8165 | \\ const slice = target[0..3 :0]; | 8447 | \\ const slice = target[0..3 :0]; |
| | 8448 | \\ _ = slice; |
| 8166 | \\ } | 8449 | \\ } |
| 8167 | \\} | 8450 | \\} |
| 8168 | \\export fn foo_cvector_ConstPtrSpecialRef() void { | 8451 | \\export fn foo_cvector_ConstPtrSpecialRef() void { |
| ... | @@ -8170,6 +8453,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -8170,6 +8453,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 8170 | \\ var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; | 8453 | \\ var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; |
| 8171 | \\ var target: [*c]u8 = @ptrCast([*c]u8, &buf); | 8454 | \\ var target: [*c]u8 = @ptrCast([*c]u8, &buf); |
| 8172 | \\ const slice = target[0..3 :0]; | 8455 | \\ const slice = target[0..3 :0]; |
| | 8456 | \\ _ = slice; |
| 8173 | \\ } | 8457 | \\ } |
| 8174 | \\} | 8458 | \\} |
| 8175 | \\export fn foo_slice() void { | 8459 | \\export fn foo_slice() void { |
| ... | @@ -8177,6 +8461,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -8177,6 +8461,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 8177 | \\ var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; | 8461 | \\ var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; |
| 8178 | \\ var target: []u8 = &buf; | 8462 | \\ var target: []u8 = &buf; |
| 8179 | \\ const slice = target[0..3 :0]; | 8463 | \\ const slice = target[0..3 :0]; |
| | 8464 | \\ _ = slice; |
| 8180 | \\ } | 8465 | \\ } |
| 8181 | \\} | 8466 | \\} |
| 8182 | , &[_][]const u8{ | 8467 | , &[_][]const u8{ |
| ... | @@ -8189,11 +8474,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -8189,11 +8474,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 8189 | ":46:29: error: slice-sentinel does not match memory at target index", | 8474 | ":46:29: error: slice-sentinel does not match memory at target index", |
| 8190 | }); | 8475 | }); |
| 8191 | | 8476 | |
| 8192 | cases.add("comptime slice-sentinel does not match memory at target index (terminated)", | 8477 | ctx.objErrStage1("comptime slice-sentinel does not match memory at target index (terminated)", |
| 8193 | \\export fn foo_array() void { | 8478 | \\export fn foo_array() void { |
| 8194 | \\ comptime { | 8479 | \\ comptime { |
| 8195 | \\ var target = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; | 8480 | \\ var target = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; |
| 8196 | \\ const slice = target[0..3 :0]; | 8481 | \\ const slice = target[0..3 :0]; |
| | 8482 | \\ _ = slice; |
| 8197 | \\ } | 8483 | \\ } |
| 8198 | \\} | 8484 | \\} |
| 8199 | \\export fn foo_ptr_array() void { | 8485 | \\export fn foo_ptr_array() void { |
| ... | @@ -8201,6 +8487,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -8201,6 +8487,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 8201 | \\ var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; | 8487 | \\ var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; |
| 8202 | \\ var target = &buf; | 8488 | \\ var target = &buf; |
| 8203 | \\ const slice = target[0..3 :0]; | 8489 | \\ const slice = target[0..3 :0]; |
| | 8490 | \\ _ = slice; |
| 8204 | \\ } | 8491 | \\ } |
| 8205 | \\} | 8492 | \\} |
| 8206 | \\export fn foo_vector_ConstPtrSpecialBaseArray() void { | 8493 | \\export fn foo_vector_ConstPtrSpecialBaseArray() void { |
| ... | @@ -8208,6 +8495,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -8208,6 +8495,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 8208 | \\ var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; | 8495 | \\ var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; |
| 8209 | \\ var target: [*]u8 = &buf; | 8496 | \\ var target: [*]u8 = &buf; |
| 8210 | \\ const slice = target[0..3 :0]; | 8497 | \\ const slice = target[0..3 :0]; |
| | 8498 | \\ _ = slice; |
| 8211 | \\ } | 8499 | \\ } |
| 8212 | \\} | 8500 | \\} |
| 8213 | \\export fn foo_vector_ConstPtrSpecialRef() void { | 8501 | \\export fn foo_vector_ConstPtrSpecialRef() void { |
| ... | @@ -8215,6 +8503,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -8215,6 +8503,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 8215 | \\ var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; | 8503 | \\ var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; |
| 8216 | \\ var target: [*]u8 = @ptrCast([*]u8, &buf); | 8504 | \\ var target: [*]u8 = @ptrCast([*]u8, &buf); |
| 8217 | \\ const slice = target[0..3 :0]; | 8505 | \\ const slice = target[0..3 :0]; |
| | 8506 | \\ _ = slice; |
| 8218 | \\ } | 8507 | \\ } |
| 8219 | \\} | 8508 | \\} |
| 8220 | \\export fn foo_cvector_ConstPtrSpecialBaseArray() void { | 8509 | \\export fn foo_cvector_ConstPtrSpecialBaseArray() void { |
| ... | @@ -8222,6 +8511,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -8222,6 +8511,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 8222 | \\ var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; | 8511 | \\ var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; |
| 8223 | \\ var target: [*c]u8 = &buf; | 8512 | \\ var target: [*c]u8 = &buf; |
| 8224 | \\ const slice = target[0..3 :0]; | 8513 | \\ const slice = target[0..3 :0]; |
| | 8514 | \\ _ = slice; |
| 8225 | \\ } | 8515 | \\ } |
| 8226 | \\} | 8516 | \\} |
| 8227 | \\export fn foo_cvector_ConstPtrSpecialRef() void { | 8517 | \\export fn foo_cvector_ConstPtrSpecialRef() void { |
| ... | @@ -8229,6 +8519,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -8229,6 +8519,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 8229 | \\ var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; | 8519 | \\ var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; |
| 8230 | \\ var target: [*c]u8 = @ptrCast([*c]u8, &buf); | 8520 | \\ var target: [*c]u8 = @ptrCast([*c]u8, &buf); |
| 8231 | \\ const slice = target[0..3 :0]; | 8521 | \\ const slice = target[0..3 :0]; |
| | 8522 | \\ _ = slice; |
| 8232 | \\ } | 8523 | \\ } |
| 8233 | \\} | 8524 | \\} |
| 8234 | \\export fn foo_slice() void { | 8525 | \\export fn foo_slice() void { |
| ... | @@ -8236,6 +8527,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -8236,6 +8527,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 8236 | \\ var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; | 8527 | \\ var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; |
| 8237 | \\ var target: []u8 = &buf; | 8528 | \\ var target: []u8 = &buf; |
| 8238 | \\ const slice = target[0..3 :0]; | 8529 | \\ const slice = target[0..3 :0]; |
| | 8530 | \\ _ = slice; |
| 8239 | \\ } | 8531 | \\ } |
| 8240 | \\} | 8532 | \\} |
| 8241 | , &[_][]const u8{ | 8533 | , &[_][]const u8{ |
| ... | @@ -8248,11 +8540,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -8248,11 +8540,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 8248 | ":46:29: error: slice-sentinel does not match memory at target index", | 8540 | ":46:29: error: slice-sentinel does not match memory at target index", |
| 8249 | }); | 8541 | }); |
| 8250 | | 8542 | |
| 8251 | cases.add("comptime slice-sentinel does not match target-sentinel", | 8543 | ctx.objErrStage1("comptime slice-sentinel does not match target-sentinel", |
| 8252 | \\export fn foo_array() void { | 8544 | \\export fn foo_array() void { |
| 8253 | \\ comptime { | 8545 | \\ comptime { |
| 8254 | \\ var target = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; | 8546 | \\ var target = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; |
| 8255 | \\ const slice = target[0..14 :255]; | 8547 | \\ const slice = target[0..14 :255]; |
| | 8548 | \\ _ = slice; |
| 8256 | \\ } | 8549 | \\ } |
| 8257 | \\} | 8550 | \\} |
| 8258 | \\export fn foo_ptr_array() void { | 8551 | \\export fn foo_ptr_array() void { |
| ... | @@ -8260,6 +8553,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -8260,6 +8553,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 8260 | \\ var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; | 8553 | \\ var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; |
| 8261 | \\ var target = &buf; | 8554 | \\ var target = &buf; |
| 8262 | \\ const slice = target[0..14 :255]; | 8555 | \\ const slice = target[0..14 :255]; |
| | 8556 | \\ _ = slice; |
| 8263 | \\ } | 8557 | \\ } |
| 8264 | \\} | 8558 | \\} |
| 8265 | \\export fn foo_vector_ConstPtrSpecialBaseArray() void { | 8559 | \\export fn foo_vector_ConstPtrSpecialBaseArray() void { |
| ... | @@ -8267,6 +8561,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -8267,6 +8561,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 8267 | \\ var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; | 8561 | \\ var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; |
| 8268 | \\ var target: [*]u8 = &buf; | 8562 | \\ var target: [*]u8 = &buf; |
| 8269 | \\ const slice = target[0..14 :255]; | 8563 | \\ const slice = target[0..14 :255]; |
| | 8564 | \\ _ = slice; |
| 8270 | \\ } | 8565 | \\ } |
| 8271 | \\} | 8566 | \\} |
| 8272 | \\export fn foo_vector_ConstPtrSpecialRef() void { | 8567 | \\export fn foo_vector_ConstPtrSpecialRef() void { |
| ... | @@ -8274,6 +8569,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -8274,6 +8569,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 8274 | \\ var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; | 8569 | \\ var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; |
| 8275 | \\ var target: [*]u8 = @ptrCast([*]u8, &buf); | 8570 | \\ var target: [*]u8 = @ptrCast([*]u8, &buf); |
| 8276 | \\ const slice = target[0..14 :255]; | 8571 | \\ const slice = target[0..14 :255]; |
| | 8572 | \\ _ = slice; |
| 8277 | \\ } | 8573 | \\ } |
| 8278 | \\} | 8574 | \\} |
| 8279 | \\export fn foo_cvector_ConstPtrSpecialBaseArray() void { | 8575 | \\export fn foo_cvector_ConstPtrSpecialBaseArray() void { |
| ... | @@ -8281,6 +8577,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -8281,6 +8577,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 8281 | \\ var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; | 8577 | \\ var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; |
| 8282 | \\ var target: [*c]u8 = &buf; | 8578 | \\ var target: [*c]u8 = &buf; |
| 8283 | \\ const slice = target[0..14 :255]; | 8579 | \\ const slice = target[0..14 :255]; |
| | 8580 | \\ _ = slice; |
| 8284 | \\ } | 8581 | \\ } |
| 8285 | \\} | 8582 | \\} |
| 8286 | \\export fn foo_cvector_ConstPtrSpecialRef() void { | 8583 | \\export fn foo_cvector_ConstPtrSpecialRef() void { |
| ... | @@ -8288,6 +8585,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -8288,6 +8585,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 8288 | \\ var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; | 8585 | \\ var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; |
| 8289 | \\ var target: [*c]u8 = @ptrCast([*c]u8, &buf); | 8586 | \\ var target: [*c]u8 = @ptrCast([*c]u8, &buf); |
| 8290 | \\ const slice = target[0..14 :255]; | 8587 | \\ const slice = target[0..14 :255]; |
| | 8588 | \\ _ = slice; |
| 8291 | \\ } | 8589 | \\ } |
| 8292 | \\} | 8590 | \\} |
| 8293 | \\export fn foo_slice() void { | 8591 | \\export fn foo_slice() void { |
| ... | @@ -8295,6 +8593,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -8295,6 +8593,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 8295 | \\ var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; | 8593 | \\ var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; |
| 8296 | \\ var target: []u8 = &buf; | 8594 | \\ var target: []u8 = &buf; |
| 8297 | \\ const slice = target[0..14 :255]; | 8595 | \\ const slice = target[0..14 :255]; |
| | 8596 | \\ _ = slice; |
| 8298 | \\ } | 8597 | \\ } |
| 8299 | \\} | 8598 | \\} |
| 8300 | , &[_][]const u8{ | 8599 | , &[_][]const u8{ |
| ... | @@ -8307,7 +8606,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -8307,7 +8606,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 8307 | ":46:29: error: slice-sentinel does not match target-sentinel", | 8606 | ":46:29: error: slice-sentinel does not match target-sentinel", |
| 8308 | }); | 8607 | }); |
| 8309 | | 8608 | |
| 8310 | cases.add("issue #4207: coerce from non-terminated-slice to terminated-pointer", | 8609 | ctx.objErrStage1("issue #4207: coerce from non-terminated-slice to terminated-pointer", |
| 8311 | \\export fn foo() [*:0]const u8 { | 8610 | \\export fn foo() [*:0]const u8 { |
| 8312 | \\ var buffer: [64]u8 = undefined; | 8611 | \\ var buffer: [64]u8 = undefined; |
| 8313 | \\ return buffer[0..]; | 8612 | \\ return buffer[0..]; |
| ... | @@ -8317,7 +8616,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -8317,7 +8616,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 8317 | ":3:18: note: destination pointer requires a terminating '0' sentinel", | 8616 | ":3:18: note: destination pointer requires a terminating '0' sentinel", |
| 8318 | }); | 8617 | }); |
| 8319 | | 8618 | |
| 8320 | cases.add("issue #5221: invalid struct init type referenced by @typeInfo and passed into function", | 8619 | ctx.objErrStage1("issue #5221: invalid struct init type referenced by @typeInfo and passed into function", |
| 8321 | \\fn ignore(comptime param: anytype) void {} | 8620 | \\fn ignore(comptime param: anytype) void {} |
| 8322 | \\ | 8621 | \\ |
| 8323 | \\export fn foo() void { | 8622 | \\export fn foo() void { |
| ... | @@ -8331,7 +8630,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -8331,7 +8630,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 8331 | ":5:28: error: expected type '[]u8', found '*const [3:0]u8'", | 8630 | ":5:28: error: expected type '[]u8', found '*const [3:0]u8'", |
| 8332 | }); | 8631 | }); |
| 8333 | | 8632 | |
| 8334 | cases.add("integer underflow error", | 8633 | ctx.objErrStage1("integer underflow error", |
| 8335 | \\export fn entry() void { | 8634 | \\export fn entry() void { |
| 8336 | \\ _ = @intToPtr(*c_void, ~@as(usize, @import("std").math.maxInt(usize)) - 1); | 8635 | \\ _ = @intToPtr(*c_void, ~@as(usize, @import("std").math.maxInt(usize)) - 1); |
| 8337 | \\} | 8636 | \\} |
| ... | @@ -8339,23 +8638,24 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -8339,23 +8638,24 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 8339 | ":2:75: error: operation caused overflow", | 8638 | ":2:75: error: operation caused overflow", |
| 8340 | }); | 8639 | }); |
| 8341 | | 8640 | |
| 8342 | cases.addCase(x: { | 8641 | { |
| 8343 | var tc = cases.create("align(N) expr function pointers is a compile error", | 8642 | const case = ctx.obj("align(N) expr function pointers is a compile error", .{ |
| | 8643 | .cpu_arch = .wasm32, |
| | 8644 | .os_tag = .freestanding, |
| | 8645 | .abi = .none, |
| | 8646 | }); |
| | 8647 | case.backend = .stage1; |
| | 8648 | |
| | 8649 | case.addError( |
| 8344 | \\export fn foo() align(1) void { | 8650 | \\export fn foo() align(1) void { |
| 8345 | \\ return; | 8651 | \\ return; |
| 8346 | \\} | 8652 | \\} |
| 8347 | , &[_][]const u8{ | 8653 | , &[_][]const u8{ |
| 8348 | "tmp.zig:1:23: error: align(N) expr is not allowed on function prototypes in wasm32/wasm64", | 8654 | "tmp.zig:1:23: error: align(N) expr is not allowed on function prototypes in wasm32/wasm64", |
| 8349 | }); | 8655 | }); |
| 8350 | tc.target = std.zig.CrossTarget{ | 8656 | } |
| 8351 | .cpu_arch = .wasm32, | | |
| 8352 | .os_tag = .freestanding, | | |
| 8353 | .abi = .none, | | |
| 8354 | }; | | |
| 8355 | break :x tc; | | |
| 8356 | }); | | |
| 8357 | | 8657 | |
| 8358 | cases.add("compare optional to non-optional with invalid types", | 8658 | ctx.objErrStage1("compare optional to non-optional with invalid types", |
| 8359 | \\export fn inconsistentChildType() void { | 8659 | \\export fn inconsistentChildType() void { |
| 8360 | \\ var x: ?i32 = undefined; | 8660 | \\ var x: ?i32 = undefined; |
| 8361 | \\ const y: comptime_int = 10; | 8661 | \\ const y: comptime_int = 10; |
| ... | @@ -8389,16 +8689,17 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -8389,16 +8689,17 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 8389 | ":22:12: note: operator not supported for type '[3]i32'", | 8689 | ":22:12: note: operator not supported for type '[3]i32'", |
| 8390 | }); | 8690 | }); |
| 8391 | | 8691 | |
| 8392 | cases.add("slice cannot have its bytes reinterpreted", | 8692 | ctx.objErrStage1("slice cannot have its bytes reinterpreted", |
| 8393 | \\export fn foo() void { | 8693 | \\export fn foo() void { |
| 8394 | \\ const bytes = [1]u8{ 0xfa } ** 16; | 8694 | \\ const bytes = [1]u8{ 0xfa } ** 16; |
| 8395 | \\ var value = @ptrCast(*const []const u8, &bytes).*; | 8695 | \\ var value = @ptrCast(*const []const u8, &bytes).*; |
| | 8696 | \\ _ = value; |
| 8396 | \\} | 8697 | \\} |
| 8397 | , &[_][]const u8{ | 8698 | , &[_][]const u8{ |
| 8398 | ":3:52: error: slice '[]const u8' cannot have its bytes reinterpreted", | 8699 | ":3:52: error: slice '[]const u8' cannot have its bytes reinterpreted", |
| 8399 | }); | 8700 | }); |
| 8400 | | 8701 | |
| 8401 | cases.add("wasmMemorySize is a compile error in non-Wasm targets", | 8702 | ctx.objErrStage1("wasmMemorySize is a compile error in non-Wasm targets", |
| 8402 | \\export fn foo() void { | 8703 | \\export fn foo() void { |
| 8403 | \\ _ = @wasmMemorySize(0); | 8704 | \\ _ = @wasmMemorySize(0); |
| 8404 | \\ return; | 8705 | \\ return; |
| ... | @@ -8407,7 +8708,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -8407,7 +8708,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 8407 | "tmp.zig:2:9: error: @wasmMemorySize is a wasm32 feature only", | 8708 | "tmp.zig:2:9: error: @wasmMemorySize is a wasm32 feature only", |
| 8408 | }); | 8709 | }); |
| 8409 | | 8710 | |
| 8410 | cases.add("wasmMemoryGrow is a compile error in non-Wasm targets", | 8711 | ctx.objErrStage1("wasmMemoryGrow is a compile error in non-Wasm targets", |
| 8411 | \\export fn foo() void { | 8712 | \\export fn foo() void { |
| 8412 | \\ _ = @wasmMemoryGrow(0, 1); | 8713 | \\ _ = @wasmMemoryGrow(0, 1); |
| 8413 | \\ return; | 8714 | \\ return; |
| ... | @@ -8415,7 +8716,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -8415,7 +8716,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 8415 | , &[_][]const u8{ | 8716 | , &[_][]const u8{ |
| 8416 | "tmp.zig:2:9: error: @wasmMemoryGrow is a wasm32 feature only", | 8717 | "tmp.zig:2:9: error: @wasmMemoryGrow is a wasm32 feature only", |
| 8417 | }); | 8718 | }); |
| 8418 | cases.add("Issue #5586: Make unary minus for unsigned types a compile error", | 8719 | ctx.objErrStage1("Issue #5586: Make unary minus for unsigned types a compile error", |
| 8419 | \\export fn f1(x: u32) u32 { | 8720 | \\export fn f1(x: u32) u32 { |
| 8420 | \\ const y = -%x; | 8721 | \\ const y = -%x; |
| 8421 | \\ return -y; | 8722 | \\ return -y; |
| ... | @@ -8430,7 +8731,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -8430,7 +8731,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 8430 | "tmp.zig:8:12: error: negation of type 'u32'", | 8731 | "tmp.zig:8:12: error: negation of type 'u32'", |
| 8431 | }); | 8732 | }); |
| 8432 | | 8733 | |
| 8433 | cases.add("Issue #5618: coercion of ?*c_void to *c_void must fail.", | 8734 | ctx.objErrStage1("Issue #5618: coercion of ?*c_void to *c_void must fail.", |
| 8434 | \\export fn foo() void { | 8735 | \\export fn foo() void { |
| 8435 | \\ var u: ?*c_void = null; | 8736 | \\ var u: ?*c_void = null; |
| 8436 | \\ var v: *c_void = undefined; | 8737 | \\ var v: *c_void = undefined; |
| ... | @@ -8440,15 +8741,16 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -8440,15 +8741,16 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 8440 | "tmp.zig:4:9: error: expected type '*c_void', found '?*c_void'", | 8741 | "tmp.zig:4:9: error: expected type '*c_void', found '?*c_void'", |
| 8441 | }); | 8742 | }); |
| 8442 | | 8743 | |
| 8443 | cases.add("Issue #6823: don't allow .* to be followed by **", | 8744 | ctx.objErrStage1("Issue #6823: don't allow .* to be followed by **", |
| 8444 | \\fn foo() void { | 8745 | \\fn foo() void { |
| 8445 | \\ var sequence = "repeat".*** 10; | 8746 | \\ var sequence = "repeat".*** 10; |
| | 8747 | \\ _ = sequence; |
| 8446 | \\} | 8748 | \\} |
| 8447 | , &[_][]const u8{ | 8749 | , &[_][]const u8{ |
| 8448 | "tmp.zig:2:30: error: `.*` cannot be followed by `*`. Are you missing a space?", | 8750 | "tmp.zig:2:30: error: `.*` cannot be followed by `*`. Are you missing a space?", |
| 8449 | }); | 8751 | }); |
| 8450 | | 8752 | |
| 8451 | cases.add("Issue #9165: windows tcp server compilation error", | 8753 | ctx.objErrStage1("Issue #9165: windows tcp server compilation error", |
| 8452 | \\const std = @import("std"); | 8754 | \\const std = @import("std"); |
| 8453 | \\pub const io_mode = .evented; | 8755 | \\pub const io_mode = .evented; |
| 8454 | \\pub fn main() !void { | 8756 | \\pub fn main() !void { |