| ... | @@ -2,6 +2,15 @@ const tests = @import("tests.zig"); | ... | @@ -2,6 +2,15 @@ const tests = @import("tests.zig"); |
| 2 | const builtin = @import("builtin"); | 2 | const builtin = @import("builtin"); |
| 3 | | 3 | |
| 4 | pub fn addCases(cases: *tests.CompileErrorContext) void { | 4 | pub fn addCases(cases: *tests.CompileErrorContext) void { |
| | 5 | cases.add("var args without c calling conv", |
| | 6 | \\fn foo(args: ...) void {} |
| | 7 | \\comptime { |
| | 8 | \\ _ = foo; |
| | 9 | \\} |
| | 10 | , &[_][]const u8{ |
| | 11 | "tmp.zig:1:8: error: var args only allowed in functions with C calling convention", |
| | 12 | }); |
| | 13 | |
| 5 | cases.add("comptime struct field, no init value", | 14 | cases.add("comptime struct field, no init value", |
| 6 | \\const Foo = struct { | 15 | \\const Foo = struct { |
| 7 | \\ comptime b: i32, | 16 | \\ comptime b: i32, |
| ... | @@ -9,10 +18,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -9,10 +18,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 9 | \\export fn entry() void { | 18 | \\export fn entry() void { |
| 10 | \\ var f: Foo = undefined; | 19 | \\ var f: Foo = undefined; |
| 11 | \\} | 20 | \\} |
| 12 | , "tmp.zig:2:5: error: comptime struct field missing initialization value"); | 21 | , &[_][]const u8{ |
| | 22 | "tmp.zig:2:5: error: comptime struct field missing initialization value", |
| | 23 | }); |
| 13 | | 24 | |
| 14 | cases.add( | 25 | cases.add("bad usage of @call", |
| 15 | "bad usage of @call", | | |
| 16 | \\export fn entry1() void { | 26 | \\export fn entry1() void { |
| 17 | \\ @call(.{}, foo, {}); | 27 | \\ @call(.{}, foo, {}); |
| 18 | \\} | 28 | \\} |
| ... | @@ -33,24 +43,25 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -33,24 +43,25 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 33 | \\inline fn bar() void {} | 43 | \\inline fn bar() void {} |
| 34 | \\fn baz1() void {} | 44 | \\fn baz1() void {} |
| 35 | \\fn baz2() void {} | 45 | \\fn baz2() void {} |
| 36 | , | 46 | , &[_][]const u8{ |
| 37 | "tmp.zig:2:21: error: expected tuple or struct, found 'void'", | 47 | "tmp.zig:2:21: error: expected tuple or struct, found 'void'", |
| 38 | "tmp.zig:5:14: error: unable to perform 'never_inline' call at compile-time", | 48 | "tmp.zig:5:14: error: unable to perform 'never_inline' call at compile-time", |
| 39 | "tmp.zig:8:14: error: unable to perform 'never_tail' call at compile-time", | 49 | "tmp.zig:8:14: error: unable to perform 'never_tail' call at compile-time", |
| 40 | "tmp.zig:11:5: error: no-inline call of inline function", | 50 | "tmp.zig:11:5: error: no-inline call of inline function", |
| 41 | "tmp.zig:15:43: error: unable to evaluate constant expression", | 51 | "tmp.zig:15:43: error: unable to evaluate constant expression", |
| 42 | ); | 52 | }); |
| 43 | | 53 | |
| 44 | cases.add("exported async function", | 54 | cases.add("exported async function", |
| 45 | \\export async fn foo() void {} | 55 | \\export async fn foo() void {} |
| 46 | , "tmp.zig:1:1: error: exported function cannot be async"); | 56 | , &[_][]const u8{ |
| | 57 | "tmp.zig:1:1: error: exported function cannot be async", |
| | 58 | }); |
| 47 | | 59 | |
| 48 | cases.addExe( | 60 | cases.addExe("main missing name", |
| 49 | "main missing name", | | |
| 50 | \\pub fn (main) void {} | 61 | \\pub fn (main) void {} |
| 51 | , | 62 | , &[_][]const u8{ |
| 52 | "tmp.zig:1:5: error: missing function name", | 63 | "tmp.zig:1:5: error: missing function name", |
| 53 | ); | 64 | }); |
| 54 | | 65 | |
| 55 | cases.addCase(x: { | 66 | cases.addCase(x: { |
| 56 | var tc = cases.create("call with new stack on unsupported target", | 67 | var tc = cases.create("call with new stack on unsupported target", |
| ... | @@ -59,7 +70,9 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -59,7 +70,9 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 59 | \\ @call(.{.stack = &buf}, foo, .{}); | 70 | \\ @call(.{.stack = &buf}, foo, .{}); |
| 60 | \\} | 71 | \\} |
| 61 | \\fn foo() void {} | 72 | \\fn foo() void {} |
| 62 | , "tmp.zig:3:5: error: target arch 'wasm32' does not support calling with a new stack"); | 73 | , &[_][]const u8{ |
| | 74 | "tmp.zig:3:5: error: target arch 'wasm32' does not support calling with a new stack", |
| | 75 | }); |
| 63 | tc.target = tests.Target{ | 76 | tc.target = tests.Target{ |
| 64 | .Cross = tests.CrossTarget{ | 77 | .Cross = tests.CrossTarget{ |
| 65 | .arch = .wasm32, | 78 | .arch = .wasm32, |
| ... | @@ -72,8 +85,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -72,8 +85,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 72 | | 85 | |
| 73 | // Note: One of the error messages here is backwards. It would be nice to fix, but that's not | 86 | // Note: One of the error messages here is backwards. It would be nice to fix, but that's not |
| 74 | // going to stop me from merging this branch which fixes a bunch of other stuff. | 87 | // going to stop me from merging this branch which fixes a bunch of other stuff. |
| 75 | cases.add( | 88 | cases.add("incompatible sentinels", |
| 76 | "incompatible sentinels", | | |
| 77 | \\export fn entry1(ptr: [*:255]u8) [*:0]u8 { | 89 | \\export fn entry1(ptr: [*:255]u8) [*:0]u8 { |
| 78 | \\ return ptr; | 90 | \\ return ptr; |
| 79 | \\} | 91 | \\} |
| ... | @@ -86,7 +98,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -86,7 +98,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 86 | \\export fn entry4() void { | 98 | \\export fn entry4() void { |
| 87 | \\ var array: [2:0]u8 = [_]u8{1, 2}; | 99 | \\ var array: [2:0]u8 = [_]u8{1, 2}; |
| 88 | \\} | 100 | \\} |
| 89 | , | 101 | , &[_][]const u8{ |
| 90 | "tmp.zig:2:12: error: expected type '[*:0]u8', found '[*:255]u8'", | 102 | "tmp.zig:2:12: error: expected type '[*:0]u8', found '[*:255]u8'", |
| 91 | "tmp.zig:2:12: note: destination pointer requires a terminating '0' sentinel, but source pointer has a terminating '255' sentinel", | 103 | "tmp.zig:2:12: note: destination pointer requires a terminating '0' sentinel, but source pointer has a terminating '255' sentinel", |
| 92 | "tmp.zig:5:12: error: expected type '[*:0]u8', found '[*]u8'", | 104 | "tmp.zig:5:12: error: expected type '[*:0]u8', found '[*]u8'", |
| ... | @@ -96,20 +108,18 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -96,20 +108,18 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 96 | "tmp.zig:8:35: note: destination array requires a terminating '255' sentinel, but source array has a terminating '0' sentinel", | 108 | "tmp.zig:8:35: note: destination array requires a terminating '255' sentinel, but source array has a terminating '0' sentinel", |
| 97 | "tmp.zig:11:31: error: expected type '[2:0]u8', found '[2]u8'", | 109 | "tmp.zig:11:31: error: expected type '[2:0]u8', found '[2]u8'", |
| 98 | "tmp.zig:11:31: note: destination array requires a terminating '0' sentinel", | 110 | "tmp.zig:11:31: note: destination array requires a terminating '0' sentinel", |
| 99 | ); | 111 | }); |
| 100 | | 112 | |
| 101 | cases.add( | 113 | cases.add("empty switch on an integer", |
| 102 | "empty switch on an integer", | | |
| 103 | \\export fn entry() void { | 114 | \\export fn entry() void { |
| 104 | \\ var x: u32 = 0; | 115 | \\ var x: u32 = 0; |
| 105 | \\ switch(x) {} | 116 | \\ switch(x) {} |
| 106 | \\} | 117 | \\} |
| 107 | , | 118 | , &[_][]const u8{ |
| 108 | "tmp.zig:3:5: error: switch must handle all possibilities", | 119 | "tmp.zig:3:5: error: switch must handle all possibilities", |
| 109 | ); | 120 | }); |
| 110 | | 121 | |
| 111 | cases.add( | 122 | cases.add("incorrect return type", |
| 112 | "incorrect return type", | | |
| 113 | \\ pub export fn entry() void{ | 123 | \\ pub export fn entry() void{ |
| 114 | \\ _ = foo(); | 124 | \\ _ = foo(); |
| 115 | \\ } | 125 | \\ } |
| ... | @@ -125,12 +135,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -125,12 +135,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 125 | \\ fn bar() B { | 135 | \\ fn bar() B { |
| 126 | \\ unreachable; | 136 | \\ unreachable; |
| 127 | \\ } | 137 | \\ } |
| 128 | , | 138 | , &[_][]const u8{ |
| 129 | "tmp.zig:8:16: error: expected type 'A', found 'B'", | 139 | "tmp.zig:8:16: error: expected type 'A', found 'B'", |
| 130 | ); | 140 | }); |
| 131 | | 141 | |
| 132 | cases.add( | 142 | cases.add("regression test #2980: base type u32 is not type checked properly when assigning a value within a struct", |
| 133 | "regression test #2980: base type u32 is not type checked properly when assigning a value within a struct", | | |
| 134 | \\const Foo = struct { | 143 | \\const Foo = struct { |
| 135 | \\ ptr: ?*usize, | 144 | \\ ptr: ?*usize, |
| 136 | \\ uval: u32, | 145 | \\ uval: u32, |
| ... | @@ -144,12 +153,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -144,12 +153,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 144 | \\ .uval = get_uval(42), | 153 | \\ .uval = get_uval(42), |
| 145 | \\ }; | 154 | \\ }; |
| 146 | \\} | 155 | \\} |
| 147 | , | 156 | , &[_][]const u8{ |
| 148 | "tmp.zig:11:25: error: expected type 'u32', found '@typeOf(get_uval).ReturnType.ErrorSet!u32'", | 157 | "tmp.zig:11:25: error: expected type 'u32', found '@typeOf(get_uval).ReturnType.ErrorSet!u32'", |
| 149 | ); | 158 | }); |
| 150 | | 159 | |
| 151 | cases.add( | 160 | cases.add("asigning to struct or union fields that are not optionals with a function that returns an optional", |
| 152 | "asigning to struct or union fields that are not optionals with a function that returns an optional", | | |
| 153 | \\fn maybe(is: bool) ?u8 { | 161 | \\fn maybe(is: bool) ?u8 { |
| 154 | \\ if (is) return @as(u8, 10) else return null; | 162 | \\ if (is) return @as(u8, 10) else return null; |
| 155 | \\} | 163 | \\} |
| ... | @@ -163,24 +171,22 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -163,24 +171,22 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 163 | \\ var u = U{ .Ye = maybe(false) }; | 171 | \\ var u = U{ .Ye = maybe(false) }; |
| 164 | \\ var s = S{ .num = maybe(false) }; | 172 | \\ var s = S{ .num = maybe(false) }; |
| 165 | \\} | 173 | \\} |
| 166 | , | 174 | , &[_][]const u8{ |
| 167 | "tmp.zig:11:27: error: expected type 'u8', found '?u8'", | 175 | "tmp.zig:11:27: error: expected type 'u8', found '?u8'", |
| 168 | ); | 176 | }); |
| 169 | | 177 | |
| 170 | cases.add( | 178 | cases.add("missing result type for phi node", |
| 171 | "missing result type for phi node", | | |
| 172 | \\fn foo() !void { | 179 | \\fn foo() !void { |
| 173 | \\ return anyerror.Foo; | 180 | \\ return anyerror.Foo; |
| 174 | \\} | 181 | \\} |
| 175 | \\export fn entry() void { | 182 | \\export fn entry() void { |
| 176 | \\ foo() catch 0; | 183 | \\ foo() catch 0; |
| 177 | \\} | 184 | \\} |
| 178 | , | 185 | , &[_][]const u8{ |
| 179 | "tmp.zig:5:17: error: integer value 0 cannot be coerced to type 'void'", | 186 | "tmp.zig:5:17: error: integer value 0 cannot be coerced to type 'void'", |
| 180 | ); | 187 | }); |
| 181 | | 188 | |
| 182 | cases.add( | 189 | cases.add("atomicrmw with enum op not .Xchg", |
| 183 | "atomicrmw with enum op not .Xchg", | | |
| 184 | \\export fn entry() void { | 190 | \\export fn entry() void { |
| 185 | \\ const E = enum(u8) { | 191 | \\ const E = enum(u8) { |
| 186 | \\ a, | 192 | \\ a, |
| ... | @@ -191,34 +197,31 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -191,34 +197,31 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 191 | \\ var x: E = .a; | 197 | \\ var x: E = .a; |
| 192 | \\ _ = @atomicRmw(E, &x, .Add, .b, .SeqCst); | 198 | \\ _ = @atomicRmw(E, &x, .Add, .b, .SeqCst); |
| 193 | \\} | 199 | \\} |
| 194 | , | 200 | , &[_][]const u8{ |
| 195 | "tmp.zig:9:27: error: @atomicRmw on enum only works with .Xchg", | 201 | "tmp.zig:9:27: error: @atomicRmw on enum only works with .Xchg", |
| 196 | ); | 202 | }); |
| 197 | | 203 | |
| 198 | cases.add( | 204 | cases.add("disallow coercion from non-null-terminated pointer to null-terminated pointer", |
| 199 | "disallow coercion from non-null-terminated pointer to null-terminated pointer", | | |
| 200 | \\extern fn puts(s: [*:0]const u8) c_int; | 205 | \\extern fn puts(s: [*:0]const u8) c_int; |
| 201 | \\pub fn main() void { | 206 | \\pub fn main() void { |
| 202 | \\ const no_zero_array = [_]u8{'h', 'e', 'l', 'l', 'o'}; | 207 | \\ const no_zero_array = [_]u8{'h', 'e', 'l', 'l', 'o'}; |
| 203 | \\ const no_zero_ptr: [*]const u8 = &no_zero_array; | 208 | \\ const no_zero_ptr: [*]const u8 = &no_zero_array; |
| 204 | \\ _ = puts(no_zero_ptr); | 209 | \\ _ = puts(no_zero_ptr); |
| 205 | \\} | 210 | \\} |
| 206 | , | 211 | , &[_][]const u8{ |
| 207 | "tmp.zig:5:14: error: expected type '[*:0]const u8', found '[*]const u8'", | 212 | "tmp.zig:5:14: error: expected type '[*:0]const u8', found '[*]const u8'", |
| 208 | ); | 213 | }); |
| 209 | | 214 | |
| 210 | cases.add( | 215 | cases.add("atomic orderings of atomicStore Acquire or AcqRel", |
| 211 | "atomic orderings of atomicStore Acquire or AcqRel", | | |
| 212 | \\export fn entry() void { | 216 | \\export fn entry() void { |
| 213 | \\ var x: u32 = 0; | 217 | \\ var x: u32 = 0; |
| 214 | \\ @atomicStore(u32, &x, 1, .Acquire); | 218 | \\ @atomicStore(u32, &x, 1, .Acquire); |
| 215 | \\} | 219 | \\} |
| 216 | , | 220 | , &[_][]const u8{ |
| 217 | "tmp.zig:3:30: error: @atomicStore atomic ordering must not be Acquire or AcqRel", | 221 | "tmp.zig:3:30: error: @atomicStore atomic ordering must not be Acquire or AcqRel", |
| 218 | ); | 222 | }); |
| 219 | | 223 | |
| 220 | cases.add( | 224 | cases.add("missing const in slice with nested array type", |
| 221 | "missing const in slice with nested array type", | | |
| 222 | \\const Geo3DTex2D = struct { vertices: [][2]f32 }; | 225 | \\const Geo3DTex2D = struct { vertices: [][2]f32 }; |
| 223 | \\pub fn getGeo3DTex2D() Geo3DTex2D { | 226 | \\pub fn getGeo3DTex2D() Geo3DTex2D { |
| 224 | \\ return Geo3DTex2D{ | 227 | \\ return Geo3DTex2D{ |
| ... | @@ -230,34 +233,31 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -230,34 +233,31 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 230 | \\export fn entry() void { | 233 | \\export fn entry() void { |
| 231 | \\ var geo_data = getGeo3DTex2D(); | 234 | \\ var geo_data = getGeo3DTex2D(); |
| 232 | \\} | 235 | \\} |
| 233 | , | 236 | , &[_][]const u8{ |
| 234 | "tmp.zig:4:30: error: array literal requires address-of operator to coerce to slice type '[][2]f32'", | 237 | "tmp.zig:4:30: error: array literal requires address-of operator to coerce to slice type '[][2]f32'", |
| 235 | ); | 238 | }); |
| 236 | | 239 | |
| 237 | cases.add( | 240 | cases.add("slicing of global undefined pointer", |
| 238 | "slicing of global undefined pointer", | | |
| 239 | \\var buf: *[1]u8 = undefined; | 241 | \\var buf: *[1]u8 = undefined; |
| 240 | \\export fn entry() void { | 242 | \\export fn entry() void { |
| 241 | \\ _ = buf[0..1]; | 243 | \\ _ = buf[0..1]; |
| 242 | \\} | 244 | \\} |
| 243 | , | 245 | , &[_][]const u8{ |
| 244 | "tmp.zig:3:12: error: non-zero length slice of undefined pointer", | 246 | "tmp.zig:3:12: error: non-zero length slice of undefined pointer", |
| 245 | ); | 247 | }); |
| 246 | | 248 | |
| 247 | cases.add( | 249 | cases.add("using invalid types in function call raises an error", |
| 248 | "using invalid types in function call raises an error", | | |
| 249 | \\const MenuEffect = enum {}; | 250 | \\const MenuEffect = enum {}; |
| 250 | \\fn func(effect: MenuEffect) void {} | 251 | \\fn func(effect: MenuEffect) void {} |
| 251 | \\export fn entry() void { | 252 | \\export fn entry() void { |
| 252 | \\ func(MenuEffect.ThisDoesNotExist); | 253 | \\ func(MenuEffect.ThisDoesNotExist); |
| 253 | \\} | 254 | \\} |
| 254 | , | 255 | , &[_][]const u8{ |
| 255 | "tmp.zig:1:20: error: enums must have 1 or more fields", | 256 | "tmp.zig:1:20: error: enums must have 1 or more fields", |
| 256 | "tmp.zig:4:20: note: referenced here", | 257 | "tmp.zig:4:20: note: referenced here", |
| 257 | ); | 258 | }); |
| 258 | | 259 | |
| 259 | cases.add( | 260 | cases.add("store vector pointer with unknown runtime index", |
| 260 | "store vector pointer with unknown runtime index", | | |
| 261 | \\export fn entry() void { | 261 | \\export fn entry() void { |
| 262 | \\ var v: @Vector(4, i32) = [_]i32{ 1, 5, 3, undefined }; | 262 | \\ var v: @Vector(4, i32) = [_]i32{ 1, 5, 3, undefined }; |
| 263 | \\ | 263 | \\ |
| ... | @@ -268,12 +268,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -268,12 +268,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 268 | \\fn storev(ptr: var, val: i32) void { | 268 | \\fn storev(ptr: var, val: i32) void { |
| 269 | \\ ptr.* = val; | 269 | \\ ptr.* = val; |
| 270 | \\} | 270 | \\} |
| 271 | , | 271 | , &[_][]const u8{ |
| 272 | "tmp.zig:9:8: error: unable to determine vector element index of type '*align(16:0:4:?) i32", | 272 | "tmp.zig:9:8: error: unable to determine vector element index of type '*align(16:0:4:?) i32", |
| 273 | ); | 273 | }); |
| 274 | | 274 | |
| 275 | cases.add( | 275 | cases.add("load vector pointer with unknown runtime index", |
| 276 | "load vector pointer with unknown runtime index", | | |
| 277 | \\export fn entry() void { | 276 | \\export fn entry() void { |
| 278 | \\ var v: @Vector(4, i32) = [_]i32{ 1, 5, 3, undefined }; | 277 | \\ var v: @Vector(4, i32) = [_]i32{ 1, 5, 3, undefined }; |
| 279 | \\ | 278 | \\ |
| ... | @@ -284,12 +283,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -284,12 +283,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 284 | \\fn loadv(ptr: var) i32 { | 283 | \\fn loadv(ptr: var) i32 { |
| 285 | \\ return ptr.*; | 284 | \\ return ptr.*; |
| 286 | \\} | 285 | \\} |
| 287 | , | 286 | , &[_][]const u8{ |
| 288 | "tmp.zig:9:12: error: unable to determine vector element index of type '*align(16:0:4:?) i32", | 287 | "tmp.zig:9:12: error: unable to determine vector element index of type '*align(16:0:4:?) i32", |
| 289 | ); | 288 | }); |
| 290 | | 289 | |
| 291 | cases.add( | 290 | cases.add("using an unknown len ptr type instead of array", |
| 292 | "using an unknown len ptr type instead of array", | | |
| 293 | \\const resolutions = [*][*]const u8{ | 291 | \\const resolutions = [*][*]const u8{ |
| 294 | \\ "[320 240 ]", | 292 | \\ "[320 240 ]", |
| 295 | \\ null, | 293 | \\ null, |
| ... | @@ -297,22 +295,20 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -297,22 +295,20 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 297 | \\comptime { | 295 | \\comptime { |
| 298 | \\ _ = resolutions; | 296 | \\ _ = resolutions; |
| 299 | \\} | 297 | \\} |
| 300 | , | 298 | , &[_][]const u8{ |
| 301 | "tmp.zig:1:21: error: expected array type or [_], found '[*][*]const u8'", | 299 | "tmp.zig:1:21: error: expected array type or [_], found '[*][*]const u8'", |
| 302 | ); | 300 | }); |
| 303 | | 301 | |
| 304 | cases.add( | 302 | cases.add("comparison with error union and error value", |
| 305 | "comparison with error union and error value", | | |
| 306 | \\export fn entry() void { | 303 | \\export fn entry() void { |
| 307 | \\ var number_or_error: anyerror!i32 = error.SomethingAwful; | 304 | \\ var number_or_error: anyerror!i32 = error.SomethingAwful; |
| 308 | \\ _ = number_or_error == error.SomethingAwful; | 305 | \\ _ = number_or_error == error.SomethingAwful; |
| 309 | \\} | 306 | \\} |
| 310 | , | 307 | , &[_][]const u8{ |
| 311 | "tmp.zig:3:25: error: operator not allowed for type 'anyerror!i32'", | 308 | "tmp.zig:3:25: error: operator not allowed for type 'anyerror!i32'", |
| 312 | ); | 309 | }); |
| 313 | | 310 | |
| 314 | cases.add( | 311 | cases.add("switch with overlapping case ranges", |
| 315 | "switch with overlapping case ranges", | | |
| 316 | \\export fn entry() void { | 312 | \\export fn entry() void { |
| 317 | \\ var q: u8 = 0; | 313 | \\ var q: u8 = 0; |
| 318 | \\ switch (q) { | 314 | \\ switch (q) { |
| ... | @@ -320,22 +316,20 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -320,22 +316,20 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 320 | \\ 0...255 => {}, | 316 | \\ 0...255 => {}, |
| 321 | \\ } | 317 | \\ } |
| 322 | \\} | 318 | \\} |
| 323 | , | 319 | , &[_][]const u8{ |
| 324 | "tmp.zig:5:9: error: duplicate switch value", | 320 | "tmp.zig:5:9: error: duplicate switch value", |
| 325 | ); | 321 | }); |
| 326 | | 322 | |
| 327 | cases.add( | 323 | cases.add("invalid optional type in extern struct", |
| 328 | "invalid optional type in extern struct", | | |
| 329 | \\const stroo = extern struct { | 324 | \\const stroo = extern struct { |
| 330 | \\ moo: ?[*c]u8, | 325 | \\ moo: ?[*c]u8, |
| 331 | \\}; | 326 | \\}; |
| 332 | \\export fn testf(fluff: *stroo) void {} | 327 | \\export fn testf(fluff: *stroo) void {} |
| 333 | , | 328 | , &[_][]const u8{ |
| 334 | "tmp.zig:2:5: error: extern structs cannot contain fields of type '?[*c]u8'", | 329 | "tmp.zig:2:5: error: extern structs cannot contain fields of type '?[*c]u8'", |
| 335 | ); | 330 | }); |
| 336 | | 331 | |
| 337 | cases.add( | 332 | cases.add("attempt to negate a non-integer, non-float or non-vector type", |
| 338 | "attempt to negate a non-integer, non-float or non-vector type", | | |
| 339 | \\fn foo() anyerror!u32 { | 333 | \\fn foo() anyerror!u32 { |
| 340 | \\ return 1; | 334 | \\ return 1; |
| 341 | \\} | 335 | \\} |
| ... | @@ -343,42 +337,38 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -343,42 +337,38 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 343 | \\export fn entry() void { | 337 | \\export fn entry() void { |
| 344 | \\ const x = -foo(); | 338 | \\ const x = -foo(); |
| 345 | \\} | 339 | \\} |
| 346 | , | 340 | , &[_][]const u8{ |
| 347 | "tmp.zig:6:15: error: negation of type 'anyerror!u32'", | 341 | "tmp.zig:6:15: error: negation of type 'anyerror!u32'", |
| 348 | ); | 342 | }); |
| 349 | | 343 | |
| 350 | cases.add( | 344 | cases.add("attempt to create 17 bit float type", |
| 351 | "attempt to create 17 bit float type", | | |
| 352 | \\const builtin = @import("builtin"); | 345 | \\const builtin = @import("builtin"); |
| 353 | \\comptime { | 346 | \\comptime { |
| 354 | \\ _ = @Type(builtin.TypeInfo { .Float = builtin.TypeInfo.Float { .bits = 17 } }); | 347 | \\ _ = @Type(builtin.TypeInfo { .Float = builtin.TypeInfo.Float { .bits = 17 } }); |
| 355 | \\} | 348 | \\} |
| 356 | , | 349 | , &[_][]const u8{ |
| 357 | "tmp.zig:3:32: error: 17-bit float unsupported", | 350 | "tmp.zig:3:32: error: 17-bit float unsupported", |
| 358 | ); | 351 | }); |
| 359 | | 352 | |
| 360 | cases.add( | 353 | cases.add("wrong type for @Type", |
| 361 | "wrong type for @Type", | | |
| 362 | \\export fn entry() void { | 354 | \\export fn entry() void { |
| 363 | \\ _ = @Type(0); | 355 | \\ _ = @Type(0); |
| 364 | \\} | 356 | \\} |
| 365 | , | 357 | , &[_][]const u8{ |
| 366 | "tmp.zig:2:15: error: expected type 'std.builtin.TypeInfo', found 'comptime_int'", | 358 | "tmp.zig:2:15: error: expected type 'std.builtin.TypeInfo', found 'comptime_int'", |
| 367 | ); | 359 | }); |
| 368 | | 360 | |
| 369 | cases.add( | 361 | cases.add("@Type with non-constant expression", |
| 370 | "@Type with non-constant expression", | | |
| 371 | \\const builtin = @import("builtin"); | 362 | \\const builtin = @import("builtin"); |
| 372 | \\var globalTypeInfo : builtin.TypeInfo = undefined; | 363 | \\var globalTypeInfo : builtin.TypeInfo = undefined; |
| 373 | \\export fn entry() void { | 364 | \\export fn entry() void { |
| 374 | \\ _ = @Type(globalTypeInfo); | 365 | \\ _ = @Type(globalTypeInfo); |
| 375 | \\} | 366 | \\} |
| 376 | , | 367 | , &[_][]const u8{ |
| 377 | "tmp.zig:4:15: error: unable to evaluate constant expression", | 368 | "tmp.zig:4:15: error: unable to evaluate constant expression", |
| 378 | ); | 369 | }); |
| 379 | | 370 | |
| 380 | cases.add( | 371 | cases.add("@Type with TypeInfo.Int", |
| 381 | "@Type with TypeInfo.Int", | | |
| 382 | \\const builtin = @import("builtin"); | 372 | \\const builtin = @import("builtin"); |
| 383 | \\export fn entry() void { | 373 | \\export fn entry() void { |
| 384 | \\ _ = @Type(builtin.TypeInfo.Int { | 374 | \\ _ = @Type(builtin.TypeInfo.Int { |
| ... | @@ -386,21 +376,19 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -386,21 +376,19 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 386 | \\ .bits = 8, | 376 | \\ .bits = 8, |
| 387 | \\ }); | 377 | \\ }); |
| 388 | \\} | 378 | \\} |
| 389 | , | 379 | , &[_][]const u8{ |
| 390 | "tmp.zig:3:36: error: expected type 'std.builtin.TypeInfo', found 'std.builtin.Int'", | 380 | "tmp.zig:3:36: error: expected type 'std.builtin.TypeInfo', found 'std.builtin.Int'", |
| 391 | ); | 381 | }); |
| 392 | | 382 | |
| 393 | cases.add( | 383 | cases.add("Struct unavailable for @Type", |
| 394 | "Struct unavailable for @Type", | | |
| 395 | \\export fn entry() void { | 384 | \\export fn entry() void { |
| 396 | \\ _ = @Type(@typeInfo(struct { })); | 385 | \\ _ = @Type(@typeInfo(struct { })); |
| 397 | \\} | 386 | \\} |
| 398 | , | 387 | , &[_][]const u8{ |
| 399 | "tmp.zig:2:15: error: @Type not availble for 'TypeInfo.Struct'", | 388 | "tmp.zig:2:15: error: @Type not availble for 'TypeInfo.Struct'", |
| 400 | ); | 389 | }); |
| 401 | | 390 | |
| 402 | cases.add( | 391 | cases.add("wrong type for result ptr to @asyncCall", |
| 403 | "wrong type for result ptr to @asyncCall", | | |
| 404 | \\export fn entry() void { | 392 | \\export fn entry() void { |
| 405 | \\ _ = async amain(); | 393 | \\ _ = async amain(); |
| 406 | \\} | 394 | \\} |
| ... | @@ -411,32 +399,29 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -411,32 +399,29 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 411 | \\fn foo() i32 { | 399 | \\fn foo() i32 { |
| 412 | \\ return 1234; | 400 | \\ return 1234; |
| 413 | \\} | 401 | \\} |
| 414 | , | 402 | , &[_][]const u8{ |
| 415 | "tmp.zig:6:37: error: expected type '*i32', found 'bool'", | 403 | "tmp.zig:6:37: error: expected type '*i32', found 'bool'", |
| 416 | ); | 404 | }); |
| 417 | | 405 | |
| 418 | cases.add( | 406 | cases.add("shift amount has to be an integer type", |
| 419 | "shift amount has to be an integer type", | | |
| 420 | \\export fn entry() void { | 407 | \\export fn entry() void { |
| 421 | \\ const x = 1 << &@as(u8, 10); | 408 | \\ const x = 1 << &@as(u8, 10); |
| 422 | \\} | 409 | \\} |
| 423 | , | 410 | , &[_][]const u8{ |
| 424 | "tmp.zig:2:21: error: shift amount has to be an integer type, but found '*u8'", | 411 | "tmp.zig:2:21: error: shift amount has to be an integer type, but found '*u8'", |
| 425 | "tmp.zig:2:17: note: referenced here", | 412 | "tmp.zig:2:17: note: referenced here", |
| 426 | ); | 413 | }); |
| 427 | | 414 | |
| 428 | cases.add( | 415 | cases.add("bit shifting only works on integer types", |
| 429 | "bit shifting only works on integer types", | | |
| 430 | \\export fn entry() void { | 416 | \\export fn entry() void { |
| 431 | \\ const x = &@as(u8, 1) << 10; | 417 | \\ const x = &@as(u8, 1) << 10; |
| 432 | \\} | 418 | \\} |
| 433 | , | 419 | , &[_][]const u8{ |
| 434 | "tmp.zig:2:16: error: bit shifting operation expected integer type, found '*u8'", | 420 | "tmp.zig:2:16: error: bit shifting operation expected integer type, found '*u8'", |
| 435 | "tmp.zig:2:27: note: referenced here", | 421 | "tmp.zig:2:27: note: referenced here", |
| 436 | ); | 422 | }); |
| 437 | | 423 | |
| 438 | cases.add( | 424 | cases.add("struct depends on itself via optional field", |
| 439 | "struct depends on itself via optional field", | | |
| 440 | \\const LhsExpr = struct { | 425 | \\const LhsExpr = struct { |
| 441 | \\ rhsExpr: ?AstObject, | 426 | \\ rhsExpr: ?AstObject, |
| 442 | \\}; | 427 | \\}; |
| ... | @@ -447,14 +432,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -447,14 +432,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 447 | \\ const lhsExpr = LhsExpr{ .rhsExpr = null }; | 432 | \\ const lhsExpr = LhsExpr{ .rhsExpr = null }; |
| 448 | \\ const obj = AstObject{ .lhsExpr = lhsExpr }; | 433 | \\ const obj = AstObject{ .lhsExpr = lhsExpr }; |
| 449 | \\} | 434 | \\} |
| 450 | , | 435 | , &[_][]const u8{ |
| 451 | "tmp.zig:1:17: error: struct 'LhsExpr' depends on itself", | 436 | "tmp.zig:1:17: error: struct 'LhsExpr' depends on itself", |
| 452 | "tmp.zig:5:5: note: while checking this field", | 437 | "tmp.zig:5:5: note: while checking this field", |
| 453 | "tmp.zig:2:5: note: while checking this field", | 438 | "tmp.zig:2:5: note: while checking this field", |
| 454 | ); | 439 | }); |
| 455 | | 440 | |
| 456 | cases.add( | 441 | cases.add("alignment of enum field specified", |
| 457 | "alignment of enum field specified", | | |
| 458 | \\const Number = enum { | 442 | \\const Number = enum { |
| 459 | \\ a, | 443 | \\ a, |
| 460 | \\ b align(i32), | 444 | \\ b align(i32), |
| ... | @@ -462,23 +446,22 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -462,23 +446,22 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 462 | \\export fn entry1() void { | 446 | \\export fn entry1() void { |
| 463 | \\ var x: Number = undefined; | 447 | \\ var x: Number = undefined; |
| 464 | \\} | 448 | \\} |
| 465 | , | 449 | , &[_][]const u8{ |
| 466 | "tmp.zig:3:13: error: structs and unions, not enums, support field alignment", | 450 | "tmp.zig:3:13: error: structs and unions, not enums, support field alignment", |
| 467 | "tmp.zig:1:16: note: consider 'union(enum)' here", | 451 | "tmp.zig:1:16: note: consider 'union(enum)' here", |
| 468 | ); | 452 | }); |
| 469 | | 453 | |
| 470 | cases.add( | 454 | cases.add("bad alignment type", |
| 471 | "bad alignment type", | | |
| 472 | \\export fn entry1() void { | 455 | \\export fn entry1() void { |
| 473 | \\ var x: []align(true) i32 = undefined; | 456 | \\ var x: []align(true) i32 = undefined; |
| 474 | \\} | 457 | \\} |
| 475 | \\export fn entry2() void { | 458 | \\export fn entry2() void { |
| 476 | \\ var x: *align(@as(f64, 12.34)) i32 = undefined; | 459 | \\ var x: *align(@as(f64, 12.34)) i32 = undefined; |
| 477 | \\} | 460 | \\} |
| 478 | , | 461 | , &[_][]const u8{ |
| 479 | "tmp.zig:2:20: error: expected type 'u29', found 'bool'", | 462 | "tmp.zig:2:20: error: expected type 'u29', found 'bool'", |
| 480 | "tmp.zig:5:19: error: fractional component prevents float value 12.340000 from being casted to type 'u29'", | 463 | "tmp.zig:5:19: error: fractional component prevents float value 12.340000 from being casted to type 'u29'", |
| 481 | ); | 464 | }); |
| 482 | | 465 | |
| 483 | cases.addCase(x: { | 466 | cases.addCase(x: { |
| 484 | var tc = cases.create("variable in inline assembly template cannot be found", | 467 | var tc = cases.create("variable in inline assembly template cannot be found", |
| ... | @@ -488,7 +471,9 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -488,7 +471,9 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 488 | \\ : [bar] "=r" (-> usize) | 471 | \\ : [bar] "=r" (-> usize) |
| 489 | \\ ); | 472 | \\ ); |
| 490 | \\} | 473 | \\} |
| 491 | , "tmp.zig:2:14: error: could not find 'foo' in the inputs or outputs"); | 474 | , &[_][]const u8{ |
| | 475 | "tmp.zig:2:14: error: could not find 'foo' in the inputs or outputs", |
| | 476 | }); |
| 492 | tc.target = tests.Target{ | 477 | tc.target = tests.Target{ |
| 493 | .Cross = tests.CrossTarget{ | 478 | .Cross = tests.CrossTarget{ |
| 494 | .arch = .x86_64, | 479 | .arch = .x86_64, |
| ... | @@ -499,8 +484,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -499,8 +484,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 499 | break :x tc; | 484 | break :x tc; |
| 500 | }); | 485 | }); |
| 501 | | 486 | |
| 502 | cases.add( | 487 | cases.add("indirect recursion of async functions detected", |
| 503 | "indirect recursion of async functions detected", | | |
| 504 | \\var frame: ?anyframe = null; | 488 | \\var frame: ?anyframe = null; |
| 505 | \\ | 489 | \\ |
| 506 | \\export fn a() void { | 490 | \\export fn a() void { |
| ... | @@ -529,14 +513,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -529,14 +513,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 529 | \\ var child = rangeSum(x - 1); | 513 | \\ var child = rangeSum(x - 1); |
| 530 | \\ return child + 1; | 514 | \\ return child + 1; |
| 531 | \\} | 515 | \\} |
| 532 | , | 516 | , &[_][]const u8{ |
| 533 | "tmp.zig:8:1: error: '@Frame(rangeSum)' depends on itself", | 517 | "tmp.zig:8:1: error: '@Frame(rangeSum)' depends on itself", |
| 534 | "tmp.zig:15:33: note: when analyzing type '@Frame(rangeSum)' here", | 518 | "tmp.zig:15:33: note: when analyzing type '@Frame(rangeSum)' here", |
| 535 | "tmp.zig:26:25: note: when analyzing type '@Frame(rangeSumIndirect)' here", | 519 | "tmp.zig:26:25: note: when analyzing type '@Frame(rangeSumIndirect)' here", |
| 536 | ); | 520 | }); |
| 537 | | 521 | |
| 538 | cases.add( | 522 | cases.add("non-async function pointer eventually is inferred to become async", |
| 539 | "non-async function pointer eventually is inferred to become async", | | |
| 540 | \\export fn a() void { | 523 | \\export fn a() void { |
| 541 | \\ var non_async_fn: fn () void = undefined; | 524 | \\ var non_async_fn: fn () void = undefined; |
| 542 | \\ non_async_fn = func; | 525 | \\ non_async_fn = func; |
| ... | @@ -544,45 +527,41 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -544,45 +527,41 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 544 | \\fn func() void { | 527 | \\fn func() void { |
| 545 | \\ suspend; | 528 | \\ suspend; |
| 546 | \\} | 529 | \\} |
| 547 | , | 530 | , &[_][]const u8{ |
| 548 | "tmp.zig:5:1: error: 'func' cannot be async", | 531 | "tmp.zig:5:1: error: 'func' cannot be async", |
| 549 | "tmp.zig:3:20: note: required to be non-async here", | 532 | "tmp.zig:3:20: note: required to be non-async here", |
| 550 | "tmp.zig:6:5: note: suspends here", | 533 | "tmp.zig:6:5: note: suspends here", |
| 551 | ); | 534 | }); |
| 552 | | 535 | |
| 553 | cases.add( | 536 | cases.add("bad alignment in @asyncCall", |
| 554 | "bad alignment in @asyncCall", | | |
| 555 | \\export fn entry() void { | 537 | \\export fn entry() void { |
| 556 | \\ var ptr: async fn () void = func; | 538 | \\ var ptr: async fn () void = func; |
| 557 | \\ var bytes: [64]u8 = undefined; | 539 | \\ var bytes: [64]u8 = undefined; |
| 558 | \\ _ = @asyncCall(&bytes, {}, ptr); | 540 | \\ _ = @asyncCall(&bytes, {}, ptr); |
| 559 | \\} | 541 | \\} |
| 560 | \\async fn func() void {} | 542 | \\async fn func() void {} |
| 561 | , | 543 | , &[_][]const u8{ |
| 562 | "tmp.zig:4:21: error: expected type '[]align(16) u8', found '*[64]u8'", | 544 | "tmp.zig:4:21: error: expected type '[]align(16) u8', found '*[64]u8'", |
| 563 | ); | 545 | }); |
| 564 | | 546 | |
| 565 | cases.add( | 547 | cases.add("atomic orderings of fence Acquire or stricter", |
| 566 | "atomic orderings of fence Acquire or stricter", | | |
| 567 | \\export fn entry() void { | 548 | \\export fn entry() void { |
| 568 | \\ @fence(.Monotonic); | 549 | \\ @fence(.Monotonic); |
| 569 | \\} | 550 | \\} |
| 570 | , | 551 | , &[_][]const u8{ |
| 571 | "tmp.zig:2:12: error: atomic ordering must be Acquire or stricter", | 552 | "tmp.zig:2:12: error: atomic ordering must be Acquire or stricter", |
| 572 | ); | 553 | }); |
| 573 | | 554 | |
| 574 | cases.add( | 555 | cases.add("bad alignment in implicit cast from array pointer to slice", |
| 575 | "bad alignment in implicit cast from array pointer to slice", | | |
| 576 | \\export fn a() void { | 556 | \\export fn a() void { |
| 577 | \\ var x: [10]u8 = undefined; | 557 | \\ var x: [10]u8 = undefined; |
| 578 | \\ var y: []align(16) u8 = &x; | 558 | \\ var y: []align(16) u8 = &x; |
| 579 | \\} | 559 | \\} |
| 580 | , | 560 | , &[_][]const u8{ |
| 581 | "tmp.zig:3:30: error: expected type '[]align(16) u8', found '*[10]u8'", | 561 | "tmp.zig:3:30: error: expected type '[]align(16) u8', found '*[10]u8'", |
| 582 | ); | 562 | }); |
| 583 | | 563 | |
| 584 | cases.add( | 564 | cases.add("result location incompatibility mismatching handle_is_ptr (generic call)", |
| 585 | "result location incompatibility mismatching handle_is_ptr (generic call)", | | |
| 586 | \\export fn entry() void { | 565 | \\export fn entry() void { |
| 587 | \\ var damn = Container{ | 566 | \\ var damn = Container{ |
| 588 | \\ .not_optional = getOptional(i32), | 567 | \\ .not_optional = getOptional(i32), |
| ... | @@ -594,12 +573,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -594,12 +573,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 594 | \\pub const Container = struct { | 573 | \\pub const Container = struct { |
| 595 | \\ not_optional: i32, | 574 | \\ not_optional: i32, |
| 596 | \\}; | 575 | \\}; |
| 597 | , | 576 | , &[_][]const u8{ |
| 598 | "tmp.zig:3:36: error: expected type 'i32', found '?i32'", | 577 | "tmp.zig:3:36: error: expected type 'i32', found '?i32'", |
| 599 | ); | 578 | }); |
| 600 | | 579 | |
| 601 | cases.add( | 580 | cases.add("result location incompatibility mismatching handle_is_ptr", |
| 602 | "result location incompatibility mismatching handle_is_ptr", | | |
| 603 | \\export fn entry() void { | 581 | \\export fn entry() void { |
| 604 | \\ var damn = Container{ | 582 | \\ var damn = Container{ |
| 605 | \\ .not_optional = getOptional(), | 583 | \\ .not_optional = getOptional(), |
| ... | @@ -611,12 +589,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -611,12 +589,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 611 | \\pub const Container = struct { | 589 | \\pub const Container = struct { |
| 612 | \\ not_optional: i32, | 590 | \\ not_optional: i32, |
| 613 | \\}; | 591 | \\}; |
| 614 | , | 592 | , &[_][]const u8{ |
| 615 | "tmp.zig:3:36: error: expected type 'i32', found '?i32'", | 593 | "tmp.zig:3:36: error: expected type 'i32', found '?i32'", |
| 616 | ); | 594 | }); |
| 617 | | 595 | |
| 618 | cases.add( | 596 | cases.add("const frame cast to anyframe", |
| 619 | "const frame cast to anyframe", | | |
| 620 | \\export fn a() void { | 597 | \\export fn a() void { |
| 621 | \\ const f = async func(); | 598 | \\ const f = async func(); |
| 622 | \\ resume f; | 599 | \\ resume f; |
| ... | @@ -628,13 +605,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -628,13 +605,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 628 | \\fn func() void { | 605 | \\fn func() void { |
| 629 | \\ suspend; | 606 | \\ suspend; |
| 630 | \\} | 607 | \\} |
| 631 | , | 608 | , &[_][]const u8{ |
| 632 | "tmp.zig:3:12: error: expected type 'anyframe', found '*const @Frame(func)'", | 609 | "tmp.zig:3:12: error: expected type 'anyframe', found '*const @Frame(func)'", |
| 633 | "tmp.zig:7:24: error: expected type 'anyframe', found '*const @Frame(func)'", | 610 | "tmp.zig:7:24: error: expected type 'anyframe', found '*const @Frame(func)'", |
| 634 | ); | 611 | }); |
| 635 | | 612 | |
| 636 | cases.add( | 613 | cases.add("prevent bad implicit casting of anyframe types", |
| 637 | "prevent bad implicit casting of anyframe types", | | |
| 638 | \\export fn a() void { | 614 | \\export fn a() void { |
| 639 | \\ var x: anyframe = undefined; | 615 | \\ var x: anyframe = undefined; |
| 640 | \\ var y: anyframe->i32 = x; | 616 | \\ var y: anyframe->i32 = x; |
| ... | @@ -648,14 +624,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -648,14 +624,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 648 | \\ var y: anyframe->i32 = &x; | 624 | \\ var y: anyframe->i32 = &x; |
| 649 | \\} | 625 | \\} |
| 650 | \\fn func() void {} | 626 | \\fn func() void {} |
| 651 | , | 627 | , &[_][]const u8{ |
| 652 | "tmp.zig:3:28: error: expected type 'anyframe->i32', found 'anyframe'", | 628 | "tmp.zig:3:28: error: expected type 'anyframe->i32', found 'anyframe'", |
| 653 | "tmp.zig:7:28: error: expected type 'anyframe->i32', found 'i32'", | 629 | "tmp.zig:7:28: error: expected type 'anyframe->i32', found 'i32'", |
| 654 | "tmp.zig:11:29: error: expected type 'anyframe->i32', found '*@Frame(func)'", | 630 | "tmp.zig:11:29: error: expected type 'anyframe->i32', found '*@Frame(func)'", |
| 655 | ); | 631 | }); |
| 656 | | 632 | |
| 657 | cases.add( | 633 | cases.add("wrong frame type used for async call", |
| 658 | "wrong frame type used for async call", | | |
| 659 | \\export fn entry() void { | 634 | \\export fn entry() void { |
| 660 | \\ var frame: @Frame(foo) = undefined; | 635 | \\ var frame: @Frame(foo) = undefined; |
| 661 | \\ frame = async bar(); | 636 | \\ frame = async bar(); |
| ... | @@ -666,37 +641,34 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -666,37 +641,34 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 666 | \\fn bar() void { | 641 | \\fn bar() void { |
| 667 | \\ suspend; | 642 | \\ suspend; |
| 668 | \\} | 643 | \\} |
| 669 | , | 644 | , &[_][]const u8{ |
| 670 | "tmp.zig:3:5: error: expected type '*@Frame(bar)', found '*@Frame(foo)'", | 645 | "tmp.zig:3:5: error: expected type '*@Frame(bar)', found '*@Frame(foo)'", |
| 671 | ); | 646 | }); |
| 672 | | 647 | |
| 673 | cases.add( | 648 | cases.add("@Frame() of generic function", |
| 674 | "@Frame() of generic function", | | |
| 675 | \\export fn entry() void { | 649 | \\export fn entry() void { |
| 676 | \\ var frame: @Frame(func) = undefined; | 650 | \\ var frame: @Frame(func) = undefined; |
| 677 | \\} | 651 | \\} |
| 678 | \\fn func(comptime T: type) void { | 652 | \\fn func(comptime T: type) void { |
| 679 | \\ var x: T = undefined; | 653 | \\ var x: T = undefined; |
| 680 | \\} | 654 | \\} |
| 681 | , | 655 | , &[_][]const u8{ |
| 682 | "tmp.zig:2:16: error: @Frame() of generic function", | 656 | "tmp.zig:2:16: error: @Frame() of generic function", |
| 683 | ); | 657 | }); |
| 684 | | 658 | |
| 685 | cases.add( | 659 | cases.add("@frame() causes function to be async", |
| 686 | "@frame() causes function to be async", | | |
| 687 | \\export fn entry() void { | 660 | \\export fn entry() void { |
| 688 | \\ func(); | 661 | \\ func(); |
| 689 | \\} | 662 | \\} |
| 690 | \\fn func() void { | 663 | \\fn func() void { |
| 691 | \\ _ = @frame(); | 664 | \\ _ = @frame(); |
| 692 | \\} | 665 | \\} |
| 693 | , | 666 | , &[_][]const u8{ |
| 694 | "tmp.zig:1:1: error: function with calling convention 'ccc' cannot be async", | 667 | "tmp.zig:1:1: error: function with calling convention 'ccc' cannot be async", |
| 695 | "tmp.zig:5:9: note: @frame() causes function to be async", | 668 | "tmp.zig:5:9: note: @frame() causes function to be async", |
| 696 | ); | 669 | }); |
| 697 | | 670 | |
| 698 | cases.add( | 671 | cases.add("invalid suspend in exported function", |
| 699 | "invalid suspend in exported function", | | |
| 700 | \\export fn entry() void { | 672 | \\export fn entry() void { |
| 701 | \\ var frame = async func(); | 673 | \\ var frame = async func(); |
| 702 | \\ var result = await frame; | 674 | \\ var result = await frame; |
| ... | @@ -704,13 +676,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -704,13 +676,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 704 | \\fn func() void { | 676 | \\fn func() void { |
| 705 | \\ suspend; | 677 | \\ suspend; |
| 706 | \\} | 678 | \\} |
| 707 | , | 679 | , &[_][]const u8{ |
| 708 | "tmp.zig:1:1: error: function with calling convention 'ccc' cannot be async", | 680 | "tmp.zig:1:1: error: function with calling convention 'ccc' cannot be async", |
| 709 | "tmp.zig:3:18: note: await here is a suspend point", | 681 | "tmp.zig:3:18: note: await here is a suspend point", |
| 710 | ); | 682 | }); |
| 711 | | 683 | |
| 712 | cases.add( | 684 | cases.add("async function indirectly depends on its own frame", |
| 713 | "async function indirectly depends on its own frame", | | |
| 714 | \\export fn entry() void { | 685 | \\export fn entry() void { |
| 715 | \\ _ = async amain(); | 686 | \\ _ = async amain(); |
| 716 | \\} | 687 | \\} |
| ... | @@ -720,39 +691,36 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -720,39 +691,36 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 720 | \\fn other() void { | 691 | \\fn other() void { |
| 721 | \\ var x: [@sizeOf(@Frame(amain))]u8 = undefined; | 692 | \\ var x: [@sizeOf(@Frame(amain))]u8 = undefined; |
| 722 | \\} | 693 | \\} |
| 723 | , | 694 | , &[_][]const u8{ |
| 724 | "tmp.zig:4:1: error: unable to determine async function frame of 'amain'", | 695 | "tmp.zig:4:1: error: unable to determine async function frame of 'amain'", |
| 725 | "tmp.zig:5:10: note: analysis of function 'other' depends on the frame", | 696 | "tmp.zig:5:10: note: analysis of function 'other' depends on the frame", |
| 726 | "tmp.zig:8:13: note: referenced here", | 697 | "tmp.zig:8:13: note: referenced here", |
| 727 | ); | 698 | }); |
| 728 | | 699 | |
| 729 | cases.add( | 700 | cases.add("async function depends on its own frame", |
| 730 | "async function depends on its own frame", | | |
| 731 | \\export fn entry() void { | 701 | \\export fn entry() void { |
| 732 | \\ _ = async amain(); | 702 | \\ _ = async amain(); |
| 733 | \\} | 703 | \\} |
| 734 | \\async fn amain() void { | 704 | \\async fn amain() void { |
| 735 | \\ var x: [@sizeOf(@Frame(amain))]u8 = undefined; | 705 | \\ var x: [@sizeOf(@Frame(amain))]u8 = undefined; |
| 736 | \\} | 706 | \\} |
| 737 | , | 707 | , &[_][]const u8{ |
| 738 | "tmp.zig:4:1: error: cannot resolve '@Frame(amain)': function not fully analyzed yet", | 708 | "tmp.zig:4:1: error: cannot resolve '@Frame(amain)': function not fully analyzed yet", |
| 739 | "tmp.zig:5:13: note: referenced here", | 709 | "tmp.zig:5:13: note: referenced here", |
| 740 | ); | 710 | }); |
| 741 | | 711 | |
| 742 | cases.add( | 712 | cases.add("non async function pointer passed to @asyncCall", |
| 743 | "non async function pointer passed to @asyncCall", | | |
| 744 | \\export fn entry() void { | 713 | \\export fn entry() void { |
| 745 | \\ var ptr = afunc; | 714 | \\ var ptr = afunc; |
| 746 | \\ var bytes: [100]u8 align(16) = undefined; | 715 | \\ var bytes: [100]u8 align(16) = undefined; |
| 747 | \\ _ = @asyncCall(&bytes, {}, ptr); | 716 | \\ _ = @asyncCall(&bytes, {}, ptr); |
| 748 | \\} | 717 | \\} |
| 749 | \\fn afunc() void { } | 718 | \\fn afunc() void { } |
| 750 | , | 719 | , &[_][]const u8{ |
| 751 | "tmp.zig:4:32: error: expected async function, found 'fn() void'", | 720 | "tmp.zig:4:32: error: expected async function, found 'fn() void'", |
| 752 | ); | 721 | }); |
| 753 | | 722 | |
| 754 | cases.add( | 723 | cases.add("runtime-known async function called", |
| 755 | "runtime-known async function called", | | |
| 756 | \\export fn entry() void { | 724 | \\export fn entry() void { |
| 757 | \\ _ = async amain(); | 725 | \\ _ = async amain(); |
| 758 | \\} | 726 | \\} |
| ... | @@ -761,24 +729,22 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -761,24 +729,22 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 761 | \\ _ = ptr(); | 729 | \\ _ = ptr(); |
| 762 | \\} | 730 | \\} |
| 763 | \\async fn afunc() void {} | 731 | \\async fn afunc() void {} |
| 764 | , | 732 | , &[_][]const u8{ |
| 765 | "tmp.zig:6:12: error: function is not comptime-known; @asyncCall required", | 733 | "tmp.zig:6:12: error: function is not comptime-known; @asyncCall required", |
| 766 | ); | 734 | }); |
| 767 | | 735 | |
| 768 | cases.add( | 736 | cases.add("runtime-known function called with async keyword", |
| 769 | "runtime-known function called with async keyword", | | |
| 770 | \\export fn entry() void { | 737 | \\export fn entry() void { |
| 771 | \\ var ptr = afunc; | 738 | \\ var ptr = afunc; |
| 772 | \\ _ = async ptr(); | 739 | \\ _ = async ptr(); |
| 773 | \\} | 740 | \\} |
| 774 | \\ | 741 | \\ |
| 775 | \\async fn afunc() void { } | 742 | \\async fn afunc() void { } |
| 776 | , | 743 | , &[_][]const u8{ |
| 777 | "tmp.zig:3:15: error: function is not comptime-known; @asyncCall required", | 744 | "tmp.zig:3:15: error: function is not comptime-known; @asyncCall required", |
| 778 | ); | 745 | }); |
| 779 | | 746 | |
| 780 | cases.add( | 747 | cases.add("function with ccc indirectly calling async function", |
| 781 | "function with ccc indirectly calling async function", | | |
| 782 | \\export fn entry() void { | 748 | \\export fn entry() void { |
| 783 | \\ foo(); | 749 | \\ foo(); |
| 784 | \\} | 750 | \\} |
| ... | @@ -788,15 +754,14 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -788,15 +754,14 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 788 | \\fn bar() void { | 754 | \\fn bar() void { |
| 789 | \\ suspend; | 755 | \\ suspend; |
| 790 | \\} | 756 | \\} |
| 791 | , | 757 | , &[_][]const u8{ |
| 792 | "tmp.zig:1:1: error: function with calling convention 'ccc' cannot be async", | 758 | "tmp.zig:1:1: error: function with calling convention 'ccc' cannot be async", |
| 793 | "tmp.zig:2:8: note: async function call here", | 759 | "tmp.zig:2:8: note: async function call here", |
| 794 | "tmp.zig:5:8: note: async function call here", | 760 | "tmp.zig:5:8: note: async function call here", |
| 795 | "tmp.zig:8:5: note: suspends here", | 761 | "tmp.zig:8:5: note: suspends here", |
| 796 | ); | 762 | }); |
| 797 | | 763 | |
| 798 | cases.add( | 764 | cases.add("capture group on switch prong with incompatible payload types", |
| 799 | "capture group on switch prong with incompatible payload types", | | |
| 800 | \\const Union = union(enum) { | 765 | \\const Union = union(enum) { |
| 801 | \\ A: usize, | 766 | \\ A: usize, |
| 802 | \\ B: isize, | 767 | \\ B: isize, |
| ... | @@ -807,59 +772,53 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -807,59 +772,53 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 807 | \\ .A, .B => |e| unreachable, | 772 | \\ .A, .B => |e| unreachable, |
| 808 | \\ } | 773 | \\ } |
| 809 | \\} | 774 | \\} |
| 810 | , | 775 | , &[_][]const u8{ |
| 811 | "tmp.zig:8:20: error: capture group with incompatible types", | 776 | "tmp.zig:8:20: error: capture group with incompatible types", |
| 812 | "tmp.zig:8:9: note: type 'usize' here", | 777 | "tmp.zig:8:9: note: type 'usize' here", |
| 813 | "tmp.zig:8:13: note: type 'isize' here", | 778 | "tmp.zig:8:13: note: type 'isize' here", |
| 814 | ); | 779 | }); |
| 815 | | 780 | |
| 816 | cases.add( | 781 | cases.add("wrong type to @hasField", |
| 817 | "wrong type to @hasField", | | |
| 818 | \\export fn entry() bool { | 782 | \\export fn entry() bool { |
| 819 | \\ return @hasField(i32, "hi"); | 783 | \\ return @hasField(i32, "hi"); |
| 820 | \\} | 784 | \\} |
| 821 | , | 785 | , &[_][]const u8{ |
| 822 | "tmp.zig:2:22: error: type 'i32' does not support @hasField", | 786 | "tmp.zig:2:22: error: type 'i32' does not support @hasField", |
| 823 | ); | 787 | }); |
| 824 | | 788 | |
| 825 | cases.add( | 789 | cases.add("slice passed as array init type with elems", |
| 826 | "slice passed as array init type with elems", | | |
| 827 | \\export fn entry() void { | 790 | \\export fn entry() void { |
| 828 | \\ const x = []u8{1, 2}; | 791 | \\ const x = []u8{1, 2}; |
| 829 | \\} | 792 | \\} |
| 830 | , | 793 | , &[_][]const u8{ |
| 831 | "tmp.zig:2:15: error: array literal requires address-of operator to coerce to slice type '[]u8'", | 794 | "tmp.zig:2:15: error: array literal requires address-of operator to coerce to slice type '[]u8'", |
| 832 | ); | 795 | }); |
| 833 | | 796 | |
| 834 | cases.add( | 797 | cases.add("slice passed as array init type", |
| 835 | "slice passed as array init type", | | |
| 836 | \\export fn entry() void { | 798 | \\export fn entry() void { |
| 837 | \\ const x = []u8{}; | 799 | \\ const x = []u8{}; |
| 838 | \\} | 800 | \\} |
| 839 | , | 801 | , &[_][]const u8{ |
| 840 | "tmp.zig:2:15: error: array literal requires address-of operator to coerce to slice type '[]u8'", | 802 | "tmp.zig:2:15: error: array literal requires address-of operator to coerce to slice type '[]u8'", |
| 841 | ); | 803 | }); |
| 842 | | 804 | |
| 843 | cases.add( | 805 | cases.add("inferred array size invalid here", |
| 844 | "inferred array size invalid here", | | |
| 845 | \\export fn entry() void { | 806 | \\export fn entry() void { |
| 846 | \\ const x = [_]u8; | 807 | \\ const x = [_]u8; |
| 847 | \\} | 808 | \\} |
| 848 | , | 809 | , &[_][]const u8{ |
| 849 | "tmp.zig:2:15: error: inferred array size invalid here", | 810 | "tmp.zig:2:15: error: inferred array size invalid here", |
| 850 | ); | 811 | }); |
| 851 | | 812 | |
| 852 | cases.add( | 813 | cases.add("initializing array with struct syntax", |
| 853 | "initializing array with struct syntax", | | |
| 854 | \\export fn entry() void { | 814 | \\export fn entry() void { |
| 855 | \\ const x = [_]u8{ .y = 2 }; | 815 | \\ const x = [_]u8{ .y = 2 }; |
| 856 | \\} | 816 | \\} |
| 857 | , | 817 | , &[_][]const u8{ |
| 858 | "tmp.zig:2:15: error: initializing array with struct syntax", | 818 | "tmp.zig:2:15: error: initializing array with struct syntax", |
| 859 | ); | 819 | }); |
| 860 | | 820 | |
| 861 | cases.add( | 821 | cases.add("compile error in struct init expression", |
| 862 | "compile error in struct init expression", | | |
| 863 | \\const Foo = struct { | 822 | \\const Foo = struct { |
| 864 | \\ a: i32 = crap, | 823 | \\ a: i32 = crap, |
| 865 | \\ b: i32, | 824 | \\ b: i32, |
| ... | @@ -869,54 +828,49 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -869,54 +828,49 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 869 | \\ .b = 5, | 828 | \\ .b = 5, |
| 870 | \\ }; | 829 | \\ }; |
| 871 | \\} | 830 | \\} |
| 872 | , | 831 | , &[_][]const u8{ |
| 873 | "tmp.zig:2:14: error: use of undeclared identifier 'crap'", | 832 | "tmp.zig:2:14: error: use of undeclared identifier 'crap'", |
| 874 | ); | 833 | }); |
| 875 | | 834 | |
| 876 | cases.add( | 835 | cases.add("undefined as field type is rejected", |
| 877 | "undefined as field type is rejected", | | |
| 878 | \\const Foo = struct { | 836 | \\const Foo = struct { |
| 879 | \\ a: undefined, | 837 | \\ a: undefined, |
| 880 | \\}; | 838 | \\}; |
| 881 | \\export fn entry1() void { | 839 | \\export fn entry1() void { |
| 882 | \\ const foo: Foo = undefined; | 840 | \\ const foo: Foo = undefined; |
| 883 | \\} | 841 | \\} |
| 884 | , | 842 | , &[_][]const u8{ |
| 885 | "tmp.zig:2:8: error: use of undefined value here causes undefined behavior", | 843 | "tmp.zig:2:8: error: use of undefined value here causes undefined behavior", |
| 886 | ); | 844 | }); |
| 887 | | 845 | |
| 888 | cases.add( | 846 | cases.add("@hasDecl with non-container", |
| 889 | "@hasDecl with non-container", | | |
| 890 | \\export fn entry() void { | 847 | \\export fn entry() void { |
| 891 | \\ _ = @hasDecl(i32, "hi"); | 848 | \\ _ = @hasDecl(i32, "hi"); |
| 892 | \\} | 849 | \\} |
| 893 | , | 850 | , &[_][]const u8{ |
| 894 | "tmp.zig:2:18: error: expected struct, enum, or union; found 'i32'", | 851 | "tmp.zig:2:18: error: expected struct, enum, or union; found 'i32'", |
| 895 | ); | 852 | }); |
| 896 | | 853 | |
| 897 | cases.add( | 854 | cases.add("field access of slices", |
| 898 | "field access of slices", | | |
| 899 | \\export fn entry() void { | 855 | \\export fn entry() void { |
| 900 | \\ var slice: []i32 = undefined; | 856 | \\ var slice: []i32 = undefined; |
| 901 | \\ const info = @typeOf(slice).unknown; | 857 | \\ const info = @typeOf(slice).unknown; |
| 902 | \\} | 858 | \\} |
| 903 | , | 859 | , &[_][]const u8{ |
| 904 | "tmp.zig:3:32: error: type '[]i32' does not support field access", | 860 | "tmp.zig:3:32: error: type '[]i32' does not support field access", |
| 905 | ); | 861 | }); |
| 906 | | 862 | |
| 907 | cases.add( | 863 | cases.add("peer cast then implicit cast const pointer to mutable C pointer", |
| 908 | "peer cast then implicit cast const pointer to mutable C pointer", | | |
| 909 | \\export fn func() void { | 864 | \\export fn func() void { |
| 910 | \\ var strValue: [*c]u8 = undefined; | 865 | \\ var strValue: [*c]u8 = undefined; |
| 911 | \\ strValue = strValue orelse ""; | 866 | \\ strValue = strValue orelse ""; |
| 912 | \\} | 867 | \\} |
| 913 | , | 868 | , &[_][]const u8{ |
| 914 | "tmp.zig:3:32: error: expected type '[*c]u8', found '*const [0:0]u8'", | 869 | "tmp.zig:3:32: error: expected type '[*c]u8', found '*const [0:0]u8'", |
| 915 | "tmp.zig:3:32: note: cast discards const qualifier", | 870 | "tmp.zig:3:32: note: cast discards const qualifier", |
| 916 | ); | 871 | }); |
| 917 | | 872 | |
| 918 | cases.add( | 873 | cases.add("overflow in enum value allocation", |
| 919 | "overflow in enum value allocation", | | |
| 920 | \\const Moo = enum(u8) { | 874 | \\const Moo = enum(u8) { |
| 921 | \\ Last = 255, | 875 | \\ Last = 255, |
| 922 | \\ Over, | 876 | \\ Over, |
| ... | @@ -924,32 +878,29 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -924,32 +878,29 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 924 | \\pub fn main() void { | 878 | \\pub fn main() void { |
| 925 | \\ var y = Moo.Last; | 879 | \\ var y = Moo.Last; |
| 926 | \\} | 880 | \\} |
| 927 | , | 881 | , &[_][]const u8{ |
| 928 | "tmp.zig:3:5: error: enumeration value 256 too large for type 'u8'", | 882 | "tmp.zig:3:5: error: enumeration value 256 too large for type 'u8'", |
| 929 | ); | 883 | }); |
| 930 | | 884 | |
| 931 | cases.add( | 885 | cases.add("attempt to cast enum literal to error", |
| 932 | "attempt to cast enum literal to error", | | |
| 933 | \\export fn entry() void { | 886 | \\export fn entry() void { |
| 934 | \\ switch (error.Hi) { | 887 | \\ switch (error.Hi) { |
| 935 | \\ .Hi => {}, | 888 | \\ .Hi => {}, |
| 936 | \\ } | 889 | \\ } |
| 937 | \\} | 890 | \\} |
| 938 | , | 891 | , &[_][]const u8{ |
| 939 | "tmp.zig:3:9: error: expected type 'error{Hi}', found '(enum literal)'", | 892 | "tmp.zig:3:9: error: expected type 'error{Hi}', found '(enum literal)'", |
| 940 | ); | 893 | }); |
| 941 | | 894 | |
| 942 | cases.add( | 895 | cases.add("@sizeOf bad type", |
| 943 | "@sizeOf bad type", | | |
| 944 | \\export fn entry() usize { | 896 | \\export fn entry() usize { |
| 945 | \\ return @sizeOf(@typeOf(null)); | 897 | \\ return @sizeOf(@typeOf(null)); |
| 946 | \\} | 898 | \\} |
| 947 | , | 899 | , &[_][]const u8{ |
| 948 | "tmp.zig:2:20: error: no size available for type '(null)'", | 900 | "tmp.zig:2:20: error: no size available for type '(null)'", |
| 949 | ); | 901 | }); |
| 950 | | 902 | |
| 951 | cases.add( | 903 | cases.add("generic function where return type is self-referenced", |
| 952 | "generic function where return type is self-referenced", | | |
| 953 | \\fn Foo(comptime T: type) Foo(T) { | 904 | \\fn Foo(comptime T: type) Foo(T) { |
| 954 | \\ return struct{ x: T }; | 905 | \\ return struct{ x: T }; |
| 955 | \\} | 906 | \\} |
| ... | @@ -958,22 +909,20 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -958,22 +909,20 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 958 | \\ .x = 1 | 909 | \\ .x = 1 |
| 959 | \\ }; | 910 | \\ }; |
| 960 | \\} | 911 | \\} |
| 961 | , | 912 | , &[_][]const u8{ |
| 962 | "tmp.zig:1:29: error: evaluation exceeded 1000 backwards branches", | 913 | "tmp.zig:1:29: error: evaluation exceeded 1000 backwards branches", |
| 963 | "tmp.zig:5:18: note: referenced here", | 914 | "tmp.zig:5:18: note: referenced here", |
| 964 | ); | 915 | }); |
| 965 | | 916 | |
| 966 | cases.add( | 917 | cases.add("@ptrToInt 0 to non optional pointer", |
| 967 | "@ptrToInt 0 to non optional pointer", | | |
| 968 | \\export fn entry() void { | 918 | \\export fn entry() void { |
| 969 | \\ var b = @intToPtr(*i32, 0); | 919 | \\ var b = @intToPtr(*i32, 0); |
| 970 | \\} | 920 | \\} |
| 971 | , | 921 | , &[_][]const u8{ |
| 972 | "tmp.zig:2:13: error: pointer type '*i32' does not allow address zero", | 922 | "tmp.zig:2:13: error: pointer type '*i32' does not allow address zero", |
| 973 | ); | 923 | }); |
| 974 | | 924 | |
| 975 | cases.add( | 925 | cases.add("cast enum literal to enum but it doesn't match", |
| 976 | "cast enum literal to enum but it doesn't match", | | |
| 977 | \\const Foo = enum { | 926 | \\const Foo = enum { |
| 978 | \\ a, | 927 | \\ a, |
| 979 | \\ b, | 928 | \\ b, |
| ... | @@ -981,34 +930,31 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -981,34 +930,31 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 981 | \\export fn entry() void { | 930 | \\export fn entry() void { |
| 982 | \\ const x: Foo = .c; | 931 | \\ const x: Foo = .c; |
| 983 | \\} | 932 | \\} |
| 984 | , | 933 | , &[_][]const u8{ |
| 985 | "tmp.zig:6:20: error: enum 'Foo' has no field named 'c'", | 934 | "tmp.zig:6:20: error: enum 'Foo' has no field named 'c'", |
| 986 | "tmp.zig:1:13: note: 'Foo' declared here", | 935 | "tmp.zig:1:13: note: 'Foo' declared here", |
| 987 | ); | 936 | }); |
| 988 | | 937 | |
| 989 | cases.add( | 938 | cases.add("discarding error value", |
| 990 | "discarding error value", | | |
| 991 | \\export fn entry() void { | 939 | \\export fn entry() void { |
| 992 | \\ _ = foo(); | 940 | \\ _ = foo(); |
| 993 | \\} | 941 | \\} |
| 994 | \\fn foo() !void { | 942 | \\fn foo() !void { |
| 995 | \\ return error.OutOfMemory; | 943 | \\ return error.OutOfMemory; |
| 996 | \\} | 944 | \\} |
| 997 | , | 945 | , &[_][]const u8{ |
| 998 | "tmp.zig:2:12: error: error is discarded", | 946 | "tmp.zig:2:12: error: error is discarded", |
| 999 | ); | 947 | }); |
| 1000 | | 948 | |
| 1001 | cases.add( | 949 | cases.add("volatile on global assembly", |
| 1002 | "volatile on global assembly", | | |
| 1003 | \\comptime { | 950 | \\comptime { |
| 1004 | \\ asm volatile (""); | 951 | \\ asm volatile (""); |
| 1005 | \\} | 952 | \\} |
| 1006 | , | 953 | , &[_][]const u8{ |
| 1007 | "tmp.zig:2:9: error: volatile is meaningless on global assembly", | 954 | "tmp.zig:2:9: error: volatile is meaningless on global assembly", |
| 1008 | ); | 955 | }); |
| 1009 | | 956 | |
| 1010 | cases.add( | 957 | cases.add("invalid multiple dereferences", |
| 1011 | "invalid multiple dereferences", | | |
| 1012 | \\export fn a() void { | 958 | \\export fn a() void { |
| 1013 | \\ var box = Box{ .field = 0 }; | 959 | \\ var box = Box{ .field = 0 }; |
| 1014 | \\ box.*.field = 1; | 960 | \\ box.*.field = 1; |
| ... | @@ -1021,20 +967,18 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -1021,20 +967,18 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1021 | \\pub const Box = struct { | 967 | \\pub const Box = struct { |
| 1022 | \\ field: i32, | 968 | \\ field: i32, |
| 1023 | \\}; | 969 | \\}; |
| 1024 | , | 970 | , &[_][]const u8{ |
| 1025 | "tmp.zig:3:8: error: attempt to dereference non-pointer type 'Box'", | 971 | "tmp.zig:3:8: error: attempt to dereference non-pointer type 'Box'", |
| 1026 | "tmp.zig:8:13: error: attempt to dereference non-pointer type 'Box'", | 972 | "tmp.zig:8:13: error: attempt to dereference non-pointer type 'Box'", |
| 1027 | ); | 973 | }); |
| 1028 | | 974 | |
| 1029 | cases.add( | 975 | cases.add("usingnamespace with wrong type", |
| 1030 | "usingnamespace with wrong type", | | |
| 1031 | \\usingnamespace void; | 976 | \\usingnamespace void; |
| 1032 | , | 977 | , &[_][]const u8{ |
| 1033 | "tmp.zig:1:1: error: expected struct, enum, or union; found 'void'", | 978 | "tmp.zig:1:1: error: expected struct, enum, or union; found 'void'", |
| 1034 | ); | 979 | }); |
| 1035 | | 980 | |
| 1036 | cases.add( | 981 | cases.add("ignored expression in while continuation", |
| 1037 | "ignored expression in while continuation", | | |
| 1038 | \\export fn a() void { | 982 | \\export fn a() void { |
| 1039 | \\ while (true) : (bad()) {} | 983 | \\ while (true) : (bad()) {} |
| 1040 | \\} | 984 | \\} |
| ... | @@ -1049,96 +993,86 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -1049,96 +993,86 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1049 | \\fn bad() anyerror!void { | 993 | \\fn bad() anyerror!void { |
| 1050 | \\ return error.Bad; | 994 | \\ return error.Bad; |
| 1051 | \\} | 995 | \\} |
| 1052 | , | 996 | , &[_][]const u8{ |
| 1053 | "tmp.zig:2:24: error: expression value is ignored", | 997 | "tmp.zig:2:24: error: expression value is ignored", |
| 1054 | "tmp.zig:6:25: error: expression value is ignored", | 998 | "tmp.zig:6:25: error: expression value is ignored", |
| 1055 | "tmp.zig:10:25: error: expression value is ignored", | 999 | "tmp.zig:10:25: error: expression value is ignored", |
| 1056 | ); | 1000 | }); |
| 1057 | | 1001 | |
| 1058 | cases.add( | 1002 | cases.add("empty while loop body", |
| 1059 | "empty while loop body", | | |
| 1060 | \\export fn a() void { | 1003 | \\export fn a() void { |
| 1061 | \\ while(true); | 1004 | \\ while(true); |
| 1062 | \\} | 1005 | \\} |
| 1063 | , | 1006 | , &[_][]const u8{ |
| 1064 | "tmp.zig:2:16: error: expected loop body, found ';'", | 1007 | "tmp.zig:2:16: error: expected loop body, found ';'", |
| 1065 | ); | 1008 | }); |
| 1066 | | 1009 | |
| 1067 | cases.add( | 1010 | cases.add("empty for loop body", |
| 1068 | "empty for loop body", | | |
| 1069 | \\export fn a() void { | 1011 | \\export fn a() void { |
| 1070 | \\ for(undefined) |x|; | 1012 | \\ for(undefined) |x|; |
| 1071 | \\} | 1013 | \\} |
| 1072 | , | 1014 | , &[_][]const u8{ |
| 1073 | "tmp.zig:2:23: error: expected loop body, found ';'", | 1015 | "tmp.zig:2:23: error: expected loop body, found ';'", |
| 1074 | ); | 1016 | }); |
| 1075 | | 1017 | |
| 1076 | cases.add( | 1018 | cases.add("empty if body", |
| 1077 | "empty if body", | | |
| 1078 | \\export fn a() void { | 1019 | \\export fn a() void { |
| 1079 | \\ if(true); | 1020 | \\ if(true); |
| 1080 | \\} | 1021 | \\} |
| 1081 | , | 1022 | , &[_][]const u8{ |
| 1082 | "tmp.zig:2:13: error: expected if body, found ';'", | 1023 | "tmp.zig:2:13: error: expected if body, found ';'", |
| 1083 | ); | 1024 | }); |
| 1084 | | 1025 | |
| 1085 | cases.add( | 1026 | cases.add("import outside package path", |
| 1086 | "import outside package path", | | |
| 1087 | \\comptime{ | 1027 | \\comptime{ |
| 1088 | \\ _ = @import("../a.zig"); | 1028 | \\ _ = @import("../a.zig"); |
| 1089 | \\} | 1029 | \\} |
| 1090 | , | 1030 | , &[_][]const u8{ |
| 1091 | "tmp.zig:2:9: error: import of file outside package path: '../a.zig'", | 1031 | "tmp.zig:2:9: error: import of file outside package path: '../a.zig'", |
| 1092 | ); | 1032 | }); |
| 1093 | | 1033 | |
| 1094 | cases.add( | 1034 | cases.add("bogus compile var", |
| 1095 | "bogus compile var", | | |
| 1096 | \\const x = @import("builtin").bogus; | 1035 | \\const x = @import("builtin").bogus; |
| 1097 | \\export fn entry() usize { return @sizeOf(@typeOf(x)); } | 1036 | \\export fn entry() usize { return @sizeOf(@typeOf(x)); } |
| 1098 | , | 1037 | , &[_][]const u8{ |
| 1099 | "tmp.zig:1:29: error: container 'builtin' has no member called 'bogus'", | 1038 | "tmp.zig:1:29: error: container 'builtin' has no member called 'bogus'", |
| 1100 | ); | 1039 | }); |
| 1101 | | 1040 | |
| 1102 | cases.add( | 1041 | cases.add("wrong panic signature, runtime function", |
| 1103 | "wrong panic signature, runtime function", | | |
| 1104 | \\test "" {} | 1042 | \\test "" {} |
| 1105 | \\ | 1043 | \\ |
| 1106 | \\pub fn panic() void {} | 1044 | \\pub fn panic() void {} |
| 1107 | \\ | 1045 | \\ |
| 1108 | , | 1046 | , &[_][]const u8{ |
| 1109 | "error: expected type 'fn([]const u8, ?*std.builtin.StackTrace) noreturn', found 'fn() void'", | 1047 | "error: expected type 'fn([]const u8, ?*std.builtin.StackTrace) noreturn', found 'fn() void'", |
| 1110 | ); | 1048 | }); |
| 1111 | | 1049 | |
| 1112 | cases.add( | 1050 | cases.add("wrong panic signature, generic function", |
| 1113 | "wrong panic signature, generic function", | | |
| 1114 | \\pub fn panic(comptime msg: []const u8, error_return_trace: ?*builtin.StackTrace) noreturn { | 1051 | \\pub fn panic(comptime msg: []const u8, error_return_trace: ?*builtin.StackTrace) noreturn { |
| 1115 | \\ while (true) {} | 1052 | \\ while (true) {} |
| 1116 | \\} | 1053 | \\} |
| 1117 | , | 1054 | , &[_][]const u8{ |
| 1118 | "error: expected type 'fn([]const u8, ?*std.builtin.StackTrace) noreturn', found 'fn([]const u8,var)var'", | 1055 | "error: expected type 'fn([]const u8, ?*std.builtin.StackTrace) noreturn', found 'fn([]const u8,var)var'", |
| 1119 | "note: only one of the functions is generic", | 1056 | "note: only one of the functions is generic", |
| 1120 | ); | 1057 | }); |
| 1121 | | 1058 | |
| 1122 | cases.add( | 1059 | cases.add("direct struct loop", |
| 1123 | "direct struct loop", | | |
| 1124 | \\const A = struct { a : A, }; | 1060 | \\const A = struct { a : A, }; |
| 1125 | \\export fn entry() usize { return @sizeOf(A); } | 1061 | \\export fn entry() usize { return @sizeOf(A); } |
| 1126 | , | 1062 | , &[_][]const u8{ |
| 1127 | "tmp.zig:1:11: error: struct 'A' depends on itself", | 1063 | "tmp.zig:1:11: error: struct 'A' depends on itself", |
| 1128 | ); | 1064 | }); |
| 1129 | | 1065 | |
| 1130 | cases.add( | 1066 | cases.add("indirect struct loop", |
| 1131 | "indirect struct loop", | | |
| 1132 | \\const A = struct { b : B, }; | 1067 | \\const A = struct { b : B, }; |
| 1133 | \\const B = struct { c : C, }; | 1068 | \\const B = struct { c : C, }; |
| 1134 | \\const C = struct { a : A, }; | 1069 | \\const C = struct { a : A, }; |
| 1135 | \\export fn entry() usize { return @sizeOf(A); } | 1070 | \\export fn entry() usize { return @sizeOf(A); } |
| 1136 | , | 1071 | , &[_][]const u8{ |
| 1137 | "tmp.zig:1:11: error: struct 'A' depends on itself", | 1072 | "tmp.zig:1:11: error: struct 'A' depends on itself", |
| 1138 | ); | 1073 | }); |
| 1139 | | 1074 | |
| 1140 | cases.add( | 1075 | cases.add("instantiating an undefined value for an invalid struct that contains itself", |
| 1141 | "instantiating an undefined value for an invalid struct that contains itself", | | |
| 1142 | \\const Foo = struct { | 1076 | \\const Foo = struct { |
| 1143 | \\ x: Foo, | 1077 | \\ x: Foo, |
| 1144 | \\}; | 1078 | \\}; |
| ... | @@ -1148,13 +1082,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -1148,13 +1082,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1148 | \\export fn entry() usize { | 1082 | \\export fn entry() usize { |
| 1149 | \\ return @sizeOf(@typeOf(foo.x)); | 1083 | \\ return @sizeOf(@typeOf(foo.x)); |
| 1150 | \\} | 1084 | \\} |
| 1151 | , | 1085 | , &[_][]const u8{ |
| 1152 | "tmp.zig:1:13: error: struct 'Foo' depends on itself", | 1086 | "tmp.zig:1:13: error: struct 'Foo' depends on itself", |
| 1153 | "tmp.zig:8:28: note: referenced here", | 1087 | "tmp.zig:8:28: note: referenced here", |
| 1154 | ); | 1088 | }); |
| 1155 | | 1089 | |
| 1156 | cases.add( | 1090 | cases.add("@typeInfo causing depend on itself compile error", |
| 1157 | "@typeInfo causing depend on itself compile error", | | |
| 1158 | \\const start = struct { | 1091 | \\const start = struct { |
| 1159 | \\ fn crash() bug() { | 1092 | \\ fn crash() bug() { |
| 1160 | \\ return bug; | 1093 | \\ return bug; |
| ... | @@ -1166,14 +1099,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -1166,14 +1099,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1166 | \\export fn entry() void { | 1099 | \\export fn entry() void { |
| 1167 | \\ var boom = start.crash(); | 1100 | \\ var boom = start.crash(); |
| 1168 | \\} | 1101 | \\} |
| 1169 | , | 1102 | , &[_][]const u8{ |
| 1170 | "tmp.zig:7:9: error: dependency loop detected", | 1103 | "tmp.zig:7:9: error: dependency loop detected", |
| 1171 | "tmp.zig:2:19: note: referenced here", | 1104 | "tmp.zig:2:19: note: referenced here", |
| 1172 | "tmp.zig:10:21: note: referenced here", | 1105 | "tmp.zig:10:21: note: referenced here", |
| 1173 | ); | 1106 | }); |
| 1174 | | 1107 | |
| 1175 | cases.add( | 1108 | cases.add("enum field value references enum", |
| 1176 | "enum field value references enum", | | |
| 1177 | \\pub const Foo = extern enum { | 1109 | \\pub const Foo = extern enum { |
| 1178 | \\ A = Foo.B, | 1110 | \\ A = Foo.B, |
| 1179 | \\ C = D, | 1111 | \\ C = D, |
| ... | @@ -1181,25 +1113,23 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -1181,25 +1113,23 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1181 | \\export fn entry() void { | 1113 | \\export fn entry() void { |
| 1182 | \\ var s: Foo = Foo.E; | 1114 | \\ var s: Foo = Foo.E; |
| 1183 | \\} | 1115 | \\} |
| 1184 | , | 1116 | , &[_][]const u8{ |
| 1185 | "tmp.zig:1:17: error: enum 'Foo' depends on itself", | 1117 | "tmp.zig:1:17: error: enum 'Foo' depends on itself", |
| 1186 | ); | 1118 | }); |
| 1187 | | 1119 | |
| 1188 | cases.add( | 1120 | cases.add("top level decl dependency loop", |
| 1189 | "top level decl dependency loop", | | |
| 1190 | \\const a : @typeOf(b) = 0; | 1121 | \\const a : @typeOf(b) = 0; |
| 1191 | \\const b : @typeOf(a) = 0; | 1122 | \\const b : @typeOf(a) = 0; |
| 1192 | \\export fn entry() void { | 1123 | \\export fn entry() void { |
| 1193 | \\ const c = a + b; | 1124 | \\ const c = a + b; |
| 1194 | \\} | 1125 | \\} |
| 1195 | , | 1126 | , &[_][]const u8{ |
| 1196 | "tmp.zig:2:19: error: dependency loop detected", | 1127 | "tmp.zig:2:19: error: dependency loop detected", |
| 1197 | "tmp.zig:1:19: note: referenced here", | 1128 | "tmp.zig:1:19: note: referenced here", |
| 1198 | "tmp.zig:4:15: note: referenced here", | 1129 | "tmp.zig:4:15: note: referenced here", |
| 1199 | ); | 1130 | }); |
| 1200 | | 1131 | |
| 1201 | cases.addTest( | 1132 | cases.addTest("not an enum type", |
| 1202 | "not an enum type", | | |
| 1203 | \\export fn entry() void { | 1133 | \\export fn entry() void { |
| 1204 | \\ var self: Error = undefined; | 1134 | \\ var self: Error = undefined; |
| 1205 | \\ switch (self) { | 1135 | \\ switch (self) { |
| ... | @@ -1213,58 +1143,53 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -1213,58 +1143,53 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1213 | \\}; | 1143 | \\}; |
| 1214 | \\const InvalidToken = struct {}; | 1144 | \\const InvalidToken = struct {}; |
| 1215 | \\const ExpectedVarDeclOrFn = struct {}; | 1145 | \\const ExpectedVarDeclOrFn = struct {}; |
| 1216 | , | 1146 | , &[_][]const u8{ |
| 1217 | "tmp.zig:4:9: error: expected type '@TagType(Error)', found 'type'", | 1147 | "tmp.zig:4:9: error: expected type '@TagType(Error)', found 'type'", |
| 1218 | ); | 1148 | }); |
| 1219 | | 1149 | |
| 1220 | cases.addTest( | 1150 | cases.addTest("binary OR operator on error sets", |
| 1221 | "binary OR operator on error sets", | | |
| 1222 | \\pub const A = error.A; | 1151 | \\pub const A = error.A; |
| 1223 | \\pub const AB = A | error.B; | 1152 | \\pub const AB = A | error.B; |
| 1224 | \\export fn entry() void { | 1153 | \\export fn entry() void { |
| 1225 | \\ var x: AB = undefined; | 1154 | \\ var x: AB = undefined; |
| 1226 | \\} | 1155 | \\} |
| 1227 | , | 1156 | , &[_][]const u8{ |
| 1228 | "tmp.zig:2:18: error: invalid operands to binary expression: 'error{A}' and 'error{B}'", | 1157 | "tmp.zig:2:18: error: invalid operands to binary expression: 'error{A}' and 'error{B}'", |
| 1229 | ); | 1158 | }); |
| 1230 | | 1159 | |
| 1231 | if (builtin.os == builtin.Os.linux) { | 1160 | if (builtin.os == builtin.Os.linux) { |
| 1232 | cases.addTest( | 1161 | cases.addTest("implicit dependency on libc", |
| 1233 | "implicit dependency on libc", | | |
| 1234 | \\extern "c" fn exit(u8) void; | 1162 | \\extern "c" fn exit(u8) void; |
| 1235 | \\export fn entry() void { | 1163 | \\export fn entry() void { |
| 1236 | \\ exit(0); | 1164 | \\ exit(0); |
| 1237 | \\} | 1165 | \\} |
| 1238 | , | 1166 | , &[_][]const u8{ |
| 1239 | "tmp.zig:3:5: error: dependency on library c must be explicitly specified in the build command", | 1167 | "tmp.zig:3:5: error: dependency on library c must be explicitly specified in the build command", |
| 1240 | ); | 1168 | }); |
| 1241 | | 1169 | |
| 1242 | cases.addTest( | 1170 | cases.addTest("libc headers note", |
| 1243 | "libc headers note", | | |
| 1244 | \\const c = @cImport(@cInclude("stdio.h")); | 1171 | \\const c = @cImport(@cInclude("stdio.h")); |
| 1245 | \\export fn entry() void { | 1172 | \\export fn entry() void { |
| 1246 | \\ _ = c.printf("hello, world!\n"); | 1173 | \\ _ = c.printf("hello, world!\n"); |
| 1247 | \\} | 1174 | \\} |
| 1248 | , | 1175 | , &[_][]const u8{ |
| 1249 | "tmp.zig:1:11: error: C import failed", | 1176 | "tmp.zig:1:11: error: C import failed", |
| 1250 | "tmp.zig:1:11: note: libc headers not available; compilation does not link against libc", | 1177 | "tmp.zig:1:11: note: libc headers not available; compilation does not link against libc", |
| 1251 | ); | 1178 | }); |
| 1252 | } | 1179 | } |
| 1253 | | 1180 | |
| 1254 | cases.addTest( | 1181 | cases.addTest("comptime vector overflow shows the index", |
| 1255 | "comptime vector overflow shows the index", | | |
| 1256 | \\comptime { | 1182 | \\comptime { |
| 1257 | \\ var a: @Vector(4, u8) = [_]u8{ 1, 2, 255, 4 }; | 1183 | \\ var a: @Vector(4, u8) = [_]u8{ 1, 2, 255, 4 }; |
| 1258 | \\ var b: @Vector(4, u8) = [_]u8{ 5, 6, 1, 8 }; | 1184 | \\ var b: @Vector(4, u8) = [_]u8{ 5, 6, 1, 8 }; |
| 1259 | \\ var x = a + b; | 1185 | \\ var x = a + b; |
| 1260 | \\} | 1186 | \\} |
| 1261 | , | 1187 | , &[_][]const u8{ |
| 1262 | "tmp.zig:4:15: error: operation caused overflow", | 1188 | "tmp.zig:4:15: error: operation caused overflow", |
| 1263 | "tmp.zig:4:15: note: when computing vector element at index 2", | 1189 | "tmp.zig:4:15: note: when computing vector element at index 2", |
| 1264 | ); | 1190 | }); |
| 1265 | | 1191 | |
| 1266 | cases.addTest( | 1192 | cases.addTest("packed struct with fields of not allowed types", |
| 1267 | "packed struct with fields of not allowed types", | | |
| 1268 | \\const A = packed struct { | 1193 | \\const A = packed struct { |
| 1269 | \\ x: anyerror, | 1194 | \\ x: anyerror, |
| 1270 | \\}; | 1195 | \\}; |
| ... | @@ -1318,7 +1243,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -1318,7 +1243,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1318 | \\ A, | 1243 | \\ A, |
| 1319 | \\ B, | 1244 | \\ B, |
| 1320 | \\}; | 1245 | \\}; |
| 1321 | , | 1246 | , &[_][]const u8{ |
| 1322 | "tmp.zig:2:5: error: type 'anyerror' not allowed in packed struct; no guaranteed in-memory representation", | 1247 | "tmp.zig:2:5: error: type 'anyerror' not allowed in packed struct; no guaranteed in-memory representation", |
| 1323 | "tmp.zig:5:5: error: array of 'u24' not allowed in packed struct due to padding bits", | 1248 | "tmp.zig:5:5: error: array of 'u24' not allowed in packed struct due to padding bits", |
| 1324 | "tmp.zig:8:5: error: type 'anyerror' not allowed in packed struct; no guaranteed in-memory representation", | 1249 | "tmp.zig:8:5: error: type 'anyerror' not allowed in packed struct; no guaranteed in-memory representation", |
| ... | @@ -1327,45 +1252,41 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -1327,45 +1252,41 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1327 | "tmp.zig:17:5: error: type '?anyerror' not allowed in packed struct; no guaranteed in-memory representation", | 1252 | "tmp.zig:17:5: error: type '?anyerror' not allowed in packed struct; no guaranteed in-memory representation", |
| 1328 | "tmp.zig:20:5: error: type 'Enum' not allowed in packed struct; no guaranteed in-memory representation", | 1253 | "tmp.zig:20:5: error: type 'Enum' not allowed in packed struct; no guaranteed in-memory representation", |
| 1329 | "tmp.zig:50:14: note: enum declaration does not specify an integer tag type", | 1254 | "tmp.zig:50:14: note: enum declaration does not specify an integer tag type", |
| 1330 | ); | 1255 | }); |
| 1331 | | 1256 | |
| 1332 | cases.addCase(x: { | 1257 | cases.addCase(x: { |
| 1333 | var tc = cases.create( | 1258 | var tc = cases.create("deduplicate undeclared identifier", |
| 1334 | "deduplicate undeclared identifier", | | |
| 1335 | \\export fn a() void { | 1259 | \\export fn a() void { |
| 1336 | \\ x += 1; | 1260 | \\ x += 1; |
| 1337 | \\} | 1261 | \\} |
| 1338 | \\export fn b() void { | 1262 | \\export fn b() void { |
| 1339 | \\ x += 1; | 1263 | \\ x += 1; |
| 1340 | \\} | 1264 | \\} |
| 1341 | , | 1265 | , &[_][]const u8{ |
| 1342 | "tmp.zig:2:5: error: use of undeclared identifier 'x'", | 1266 | "tmp.zig:2:5: error: use of undeclared identifier 'x'", |
| 1343 | ); | 1267 | }); |
| 1344 | tc.expect_exact = true; | 1268 | tc.expect_exact = true; |
| 1345 | break :x tc; | 1269 | break :x tc; |
| 1346 | }); | 1270 | }); |
| 1347 | | 1271 | |
| 1348 | cases.add( | 1272 | cases.add("export generic function", |
| 1349 | "export generic function", | | |
| 1350 | \\export fn foo(num: var) i32 { | 1273 | \\export fn foo(num: var) i32 { |
| 1351 | \\ return 0; | 1274 | \\ return 0; |
| 1352 | \\} | 1275 | \\} |
| 1353 | , | 1276 | , &[_][]const u8{ |
| 1354 | "tmp.zig:1:15: error: parameter of type 'var' not allowed in function with calling convention 'ccc'", | 1277 | "tmp.zig:1:15: error: parameter of type 'var' not allowed in function with calling convention 'ccc'", |
| 1355 | ); | 1278 | }); |
| 1356 | | 1279 | |
| 1357 | cases.add( | 1280 | cases.add("C pointer to c_void", |
| 1358 | "C pointer to c_void", | | |
| 1359 | \\export fn a() void { | 1281 | \\export fn a() void { |
| 1360 | \\ var x: *c_void = undefined; | 1282 | \\ var x: *c_void = undefined; |
| 1361 | \\ var y: [*c]c_void = x; | 1283 | \\ var y: [*c]c_void = x; |
| 1362 | \\} | 1284 | \\} |
| 1363 | , | 1285 | , &[_][]const u8{ |
| 1364 | "tmp.zig:3:16: error: C pointers cannot point opaque types", | 1286 | "tmp.zig:3:16: error: C pointers cannot point opaque types", |
| 1365 | ); | 1287 | }); |
| 1366 | | 1288 | |
| 1367 | cases.add( | 1289 | cases.add("directly embedding opaque type in struct and union", |
| 1368 | "directly embedding opaque type in struct and union", | | |
| 1369 | \\const O = @OpaqueType(); | 1290 | \\const O = @OpaqueType(); |
| 1370 | \\const Foo = struct { | 1291 | \\const Foo = struct { |
| 1371 | \\ o: O, | 1292 | \\ o: O, |
| ... | @@ -1380,13 +1301,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -1380,13 +1301,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1380 | \\export fn b() void { | 1301 | \\export fn b() void { |
| 1381 | \\ var bar: Bar = undefined; | 1302 | \\ var bar: Bar = undefined; |
| 1382 | \\} | 1303 | \\} |
| 1383 | , | 1304 | , &[_][]const u8{ |
| 1384 | "tmp.zig:3:8: error: opaque types have unknown size and therefore cannot be directly embedded in structs", | 1305 | "tmp.zig:3:8: error: opaque types have unknown size and therefore cannot be directly embedded in structs", |
| 1385 | "tmp.zig:7:10: error: opaque types have unknown size and therefore cannot be directly embedded in unions", | 1306 | "tmp.zig:7:10: error: opaque types have unknown size and therefore cannot be directly embedded in unions", |
| 1386 | ); | 1307 | }); |
| 1387 | | 1308 | |
| 1388 | cases.add( | 1309 | cases.add("implicit cast between C pointer and Zig pointer - bad const/align/child", |
| 1389 | "implicit cast between C pointer and Zig pointer - bad const/align/child", | | |
| 1390 | \\export fn a() void { | 1310 | \\export fn a() void { |
| 1391 | \\ var x: [*c]u8 = undefined; | 1311 | \\ var x: [*c]u8 = undefined; |
| 1392 | \\ var y: *align(4) u8 = x; | 1312 | \\ var y: *align(4) u8 = x; |
| ... | @@ -1411,7 +1331,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -1411,7 +1331,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1411 | \\ var y: *u8 = undefined; | 1331 | \\ var y: *u8 = undefined; |
| 1412 | \\ var x: [*c]u32 = y; | 1332 | \\ var x: [*c]u32 = y; |
| 1413 | \\} | 1333 | \\} |
| 1414 | , | 1334 | , &[_][]const u8{ |
| 1415 | "tmp.zig:3:27: error: cast increases pointer alignment", | 1335 | "tmp.zig:3:27: error: cast increases pointer alignment", |
| 1416 | "tmp.zig:7:18: error: cast discards const qualifier", | 1336 | "tmp.zig:7:18: error: cast discards const qualifier", |
| 1417 | "tmp.zig:11:19: error: expected type '*u32', found '[*c]u8'", | 1337 | "tmp.zig:11:19: error: expected type '*u32', found '[*c]u8'", |
| ... | @@ -1419,30 +1339,27 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -1419,30 +1339,27 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1419 | "tmp.zig:15:22: error: cast increases pointer alignment", | 1339 | "tmp.zig:15:22: error: cast increases pointer alignment", |
| 1420 | "tmp.zig:19:21: error: cast discards const qualifier", | 1340 | "tmp.zig:19:21: error: cast discards const qualifier", |
| 1421 | "tmp.zig:23:22: error: expected type '[*c]u32', found '*u8'", | 1341 | "tmp.zig:23:22: error: expected type '[*c]u32', found '*u8'", |
| 1422 | ); | 1342 | }); |
| 1423 | | 1343 | |
| 1424 | cases.add( | 1344 | cases.add("implicit casting null c pointer to zig pointer", |
| 1425 | "implicit casting null c pointer to zig pointer", | | |
| 1426 | \\comptime { | 1345 | \\comptime { |
| 1427 | \\ var c_ptr: [*c]u8 = 0; | 1346 | \\ var c_ptr: [*c]u8 = 0; |
| 1428 | \\ var zig_ptr: *u8 = c_ptr; | 1347 | \\ var zig_ptr: *u8 = c_ptr; |
| 1429 | \\} | 1348 | \\} |
| 1430 | , | 1349 | , &[_][]const u8{ |
| 1431 | "tmp.zig:3:24: error: null pointer casted to type '*u8'", | 1350 | "tmp.zig:3:24: error: null pointer casted to type '*u8'", |
| 1432 | ); | 1351 | }); |
| 1433 | | 1352 | |
| 1434 | cases.add( | 1353 | cases.add("implicit casting undefined c pointer to zig pointer", |
| 1435 | "implicit casting undefined c pointer to zig pointer", | | |
| 1436 | \\comptime { | 1354 | \\comptime { |
| 1437 | \\ var c_ptr: [*c]u8 = undefined; | 1355 | \\ var c_ptr: [*c]u8 = undefined; |
| 1438 | \\ var zig_ptr: *u8 = c_ptr; | 1356 | \\ var zig_ptr: *u8 = c_ptr; |
| 1439 | \\} | 1357 | \\} |
| 1440 | , | 1358 | , &[_][]const u8{ |
| 1441 | "tmp.zig:3:24: error: use of undefined value here causes undefined behavior", | 1359 | "tmp.zig:3:24: error: use of undefined value here causes undefined behavior", |
| 1442 | ); | 1360 | }); |
| 1443 | | 1361 | |
| 1444 | cases.add( | 1362 | cases.add("implicit casting C pointers which would mess up null semantics", |
| 1445 | "implicit casting C pointers which would mess up null semantics", | | |
| 1446 | \\export fn entry() void { | 1363 | \\export fn entry() void { |
| 1447 | \\ var slice: []const u8 = "aoeu"; | 1364 | \\ var slice: []const u8 = "aoeu"; |
| 1448 | \\ const opt_many_ptr: [*]const u8 = slice.ptr; | 1365 | \\ const opt_many_ptr: [*]const u8 = slice.ptr; |
| ... | @@ -1457,17 +1374,16 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -1457,17 +1374,16 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1457 | \\ var ptr_opt_many_ptr = &opt_many_ptr; | 1374 | \\ var ptr_opt_many_ptr = &opt_many_ptr; |
| 1458 | \\ var c_ptr: [*c][*c]const u8 = ptr_opt_many_ptr; | 1375 | \\ var c_ptr: [*c][*c]const u8 = ptr_opt_many_ptr; |
| 1459 | \\} | 1376 | \\} |
| 1460 | , | 1377 | , &[_][]const u8{ |
| 1461 | "tmp.zig:6:24: error: expected type '*const [*]const u8', found '[*c]const [*c]const u8'", | 1378 | "tmp.zig:6:24: error: expected type '*const [*]const u8', found '[*c]const [*c]const u8'", |
| 1462 | "tmp.zig:6:24: note: pointer type child '[*c]const u8' cannot cast into pointer type child '[*]const u8'", | 1379 | "tmp.zig:6:24: note: pointer type child '[*c]const u8' cannot cast into pointer type child '[*]const u8'", |
| 1463 | "tmp.zig:6:24: note: '[*c]const u8' could have null values which are illegal in type '[*]const u8'", | 1380 | "tmp.zig:6:24: note: '[*c]const u8' could have null values which are illegal in type '[*]const u8'", |
| 1464 | "tmp.zig:13:35: error: expected type '[*c][*c]const u8', found '*[*]u8'", | 1381 | "tmp.zig:13:35: error: expected type '[*c][*c]const u8', found '*[*]u8'", |
| 1465 | "tmp.zig:13:35: note: pointer type child '[*]u8' cannot cast into pointer type child '[*c]const u8'", | 1382 | "tmp.zig:13:35: note: pointer type child '[*]u8' cannot cast into pointer type child '[*c]const u8'", |
| 1466 | "tmp.zig:13:35: note: mutable '[*c]const u8' allows illegal null values stored to type '[*]u8'", | 1383 | "tmp.zig:13:35: note: mutable '[*c]const u8' allows illegal null values stored to type '[*]u8'", |
| 1467 | ); | 1384 | }); |
| 1468 | | 1385 | |
| 1469 | cases.add( | 1386 | cases.add("implicit casting too big integers to C pointers", |
| 1470 | "implicit casting too big integers to C pointers", | | |
| 1471 | \\export fn a() void { | 1387 | \\export fn a() void { |
| 1472 | \\ var ptr: [*c]u8 = (1 << 64) + 1; | 1388 | \\ var ptr: [*c]u8 = (1 << 64) + 1; |
| 1473 | \\} | 1389 | \\} |
| ... | @@ -1475,25 +1391,23 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -1475,25 +1391,23 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1475 | \\ var x: @IntType(false, 65) = 0x1234; | 1391 | \\ var x: @IntType(false, 65) = 0x1234; |
| 1476 | \\ var ptr: [*c]u8 = x; | 1392 | \\ var ptr: [*c]u8 = x; |
| 1477 | \\} | 1393 | \\} |
| 1478 | , | 1394 | , &[_][]const u8{ |
| 1479 | "tmp.zig:2:33: error: integer value 18446744073709551617 cannot be coerced to type 'usize'", | 1395 | "tmp.zig:2:33: error: integer value 18446744073709551617 cannot be coerced to type 'usize'", |
| 1480 | "tmp.zig:6:23: error: integer type 'u65' too big for implicit @intToPtr to type '[*c]u8'", | 1396 | "tmp.zig:6:23: error: integer type 'u65' too big for implicit @intToPtr to type '[*c]u8'", |
| 1481 | ); | 1397 | }); |
| 1482 | | 1398 | |
| 1483 | cases.add( | 1399 | cases.add("C pointer pointing to non C ABI compatible type or has align attr", |
| 1484 | "C pointer pointing to non C ABI compatible type or has align attr", | | |
| 1485 | \\const Foo = struct {}; | 1400 | \\const Foo = struct {}; |
| 1486 | \\export fn a() void { | 1401 | \\export fn a() void { |
| 1487 | \\ const T = [*c]Foo; | 1402 | \\ const T = [*c]Foo; |
| 1488 | \\ var t: T = undefined; | 1403 | \\ var t: T = undefined; |
| 1489 | \\} | 1404 | \\} |
| 1490 | , | 1405 | , &[_][]const u8{ |
| 1491 | "tmp.zig:3:19: error: C pointers cannot point to non-C-ABI-compatible type 'Foo'", | 1406 | "tmp.zig:3:19: error: C pointers cannot point to non-C-ABI-compatible type 'Foo'", |
| 1492 | ); | 1407 | }); |
| 1493 | | 1408 | |
| 1494 | cases.addCase(x: { | 1409 | cases.addCase(x: { |
| 1495 | var tc = cases.create( | 1410 | var tc = cases.create("compile log statement warning deduplication in generic fn", |
| 1496 | "compile log statement warning deduplication in generic fn", | | |
| 1497 | \\export fn entry() void { | 1411 | \\export fn entry() void { |
| 1498 | \\ inner(1); | 1412 | \\ inner(1); |
| 1499 | \\ inner(2); | 1413 | \\ inner(2); |
| ... | @@ -1502,111 +1416,100 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -1502,111 +1416,100 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1502 | \\ comptime var i = 0; | 1416 | \\ comptime var i = 0; |
| 1503 | \\ inline while (i < n) : (i += 1) { @compileLog("!@#$"); } | 1417 | \\ inline while (i < n) : (i += 1) { @compileLog("!@#$"); } |
| 1504 | \\} | 1418 | \\} |
| 1505 | , | 1419 | , &[_][]const u8{ |
| 1506 | "tmp.zig:7:39: error: found compile log statement", | 1420 | "tmp.zig:7:39: error: found compile log statement", |
| 1507 | ); | 1421 | }); |
| 1508 | tc.expect_exact = true; | 1422 | tc.expect_exact = true; |
| 1509 | break :x tc; | 1423 | break :x tc; |
| 1510 | }); | 1424 | }); |
| 1511 | | 1425 | |
| 1512 | cases.add( | 1426 | cases.add("assign to invalid dereference", |
| 1513 | "assign to invalid dereference", | | |
| 1514 | \\export fn entry() void { | 1427 | \\export fn entry() void { |
| 1515 | \\ 'a'.* = 1; | 1428 | \\ 'a'.* = 1; |
| 1516 | \\} | 1429 | \\} |
| 1517 | , | 1430 | , &[_][]const u8{ |
| 1518 | "tmp.zig:2:8: error: attempt to dereference non-pointer type 'comptime_int'", | 1431 | "tmp.zig:2:8: error: attempt to dereference non-pointer type 'comptime_int'", |
| 1519 | ); | 1432 | }); |
| 1520 | | 1433 | |
| 1521 | cases.add( | 1434 | cases.add("take slice of invalid dereference", |
| 1522 | "take slice of invalid dereference", | | |
| 1523 | \\export fn entry() void { | 1435 | \\export fn entry() void { |
| 1524 | \\ const x = 'a'.*[0..]; | 1436 | \\ const x = 'a'.*[0..]; |
| 1525 | \\} | 1437 | \\} |
| 1526 | , | 1438 | , &[_][]const u8{ |
| 1527 | "tmp.zig:2:18: error: attempt to dereference non-pointer type 'comptime_int'", | 1439 | "tmp.zig:2:18: error: attempt to dereference non-pointer type 'comptime_int'", |
| 1528 | ); | 1440 | }); |
| 1529 | | 1441 | |
| 1530 | cases.add( | 1442 | cases.add("@truncate undefined value", |
| 1531 | "@truncate undefined value", | | |
| 1532 | \\export fn entry() void { | 1443 | \\export fn entry() void { |
| 1533 | \\ var z = @truncate(u8, @as(u16, undefined)); | 1444 | \\ var z = @truncate(u8, @as(u16, undefined)); |
| 1534 | \\} | 1445 | \\} |
| 1535 | , | 1446 | , &[_][]const u8{ |
| 1536 | "tmp.zig:2:27: error: use of undefined value here causes undefined behavior", | 1447 | "tmp.zig:2:27: error: use of undefined value here causes undefined behavior", |
| 1537 | ); | 1448 | }); |
| 1538 | | 1449 | |
| 1539 | cases.addTest( | 1450 | cases.addTest("return invalid type from test", |
| 1540 | "return invalid type from test", | | |
| 1541 | \\test "example" { return 1; } | 1451 | \\test "example" { return 1; } |
| 1542 | , | 1452 | , &[_][]const u8{ |
| 1543 | "tmp.zig:1:25: error: integer value 1 cannot be coerced to type 'void'", | 1453 | "tmp.zig:1:25: error: integer value 1 cannot be coerced to type 'void'", |
| 1544 | ); | 1454 | }); |
| 1545 | | 1455 | |
| 1546 | cases.add( | 1456 | cases.add("threadlocal qualifier on const", |
| 1547 | "threadlocal qualifier on const", | | |
| 1548 | \\threadlocal const x: i32 = 1234; | 1457 | \\threadlocal const x: i32 = 1234; |
| 1549 | \\export fn entry() i32 { | 1458 | \\export fn entry() i32 { |
| 1550 | \\ return x; | 1459 | \\ return x; |
| 1551 | \\} | 1460 | \\} |
| 1552 | , | 1461 | , &[_][]const u8{ |
| 1553 | "tmp.zig:1:13: error: threadlocal variable cannot be constant", | 1462 | "tmp.zig:1:13: error: threadlocal variable cannot be constant", |
| 1554 | ); | 1463 | }); |
| 1555 | | 1464 | |
| 1556 | cases.add( | 1465 | cases.add("@bitCast same size but bit count mismatch", |
| 1557 | "@bitCast same size but bit count mismatch", | | |
| 1558 | \\export fn entry(byte: u8) void { | 1466 | \\export fn entry(byte: u8) void { |
| 1559 | \\ var oops = @bitCast(u7, byte); | 1467 | \\ var oops = @bitCast(u7, byte); |
| 1560 | \\} | 1468 | \\} |
| 1561 | , | 1469 | , &[_][]const u8{ |
| 1562 | "tmp.zig:2:25: error: destination type 'u7' has 7 bits but source type 'u8' has 8 bits", | 1470 | "tmp.zig:2:25: error: destination type 'u7' has 7 bits but source type 'u8' has 8 bits", |
| 1563 | ); | 1471 | }); |
| 1564 | | 1472 | |
| 1565 | cases.add( | 1473 | cases.add("@bitCast with different sizes inside an expression", |
| 1566 | "@bitCast with different sizes inside an expression", | | |
| 1567 | \\export fn entry() void { | 1474 | \\export fn entry() void { |
| 1568 | \\ var foo = (@bitCast(u8, @as(f32, 1.0)) == 0xf); | 1475 | \\ var foo = (@bitCast(u8, @as(f32, 1.0)) == 0xf); |
| 1569 | \\} | 1476 | \\} |
| 1570 | , | 1477 | , &[_][]const u8{ |
| 1571 | "tmp.zig:2:25: error: destination type 'u8' has size 1 but source type 'f32' has size 4", | 1478 | "tmp.zig:2:25: error: destination type 'u8' has size 1 but source type 'f32' has size 4", |
| 1572 | ); | 1479 | }); |
| 1573 | | 1480 | |
| 1574 | cases.add( | 1481 | cases.add("attempted `&&`", |
| 1575 | "attempted `&&`", | | |
| 1576 | \\export fn entry(a: bool, b: bool) i32 { | 1482 | \\export fn entry(a: bool, b: bool) i32 { |
| 1577 | \\ if (a && b) { | 1483 | \\ if (a && b) { |
| 1578 | \\ return 1234; | 1484 | \\ return 1234; |
| 1579 | \\ } | 1485 | \\ } |
| 1580 | \\ return 5678; | 1486 | \\ return 5678; |
| 1581 | \\} | 1487 | \\} |
| 1582 | , | 1488 | , &[_][]const u8{ |
| 1583 | "tmp.zig:2:12: error: `&&` is invalid. Note that `and` is boolean AND", | 1489 | "tmp.zig:2:12: error: `&&` is invalid. Note that `and` is boolean AND", |
| 1584 | ); | 1490 | }); |
| 1585 | | 1491 | |
| 1586 | cases.add( | 1492 | cases.add("attempted `||` on boolean values", |
| 1587 | "attempted `||` on boolean values", | | |
| 1588 | \\export fn entry(a: bool, b: bool) i32 { | 1493 | \\export fn entry(a: bool, b: bool) i32 { |
| 1589 | \\ if (a || b) { | 1494 | \\ if (a || b) { |
| 1590 | \\ return 1234; | 1495 | \\ return 1234; |
| 1591 | \\ } | 1496 | \\ } |
| 1592 | \\ return 5678; | 1497 | \\ return 5678; |
| 1593 | \\} | 1498 | \\} |
| 1594 | , | 1499 | , &[_][]const u8{ |
| 1595 | "tmp.zig:2:9: error: expected error set type, found 'bool'", | 1500 | "tmp.zig:2:9: error: expected error set type, found 'bool'", |
| 1596 | "tmp.zig:2:11: note: `||` merges error sets; `or` performs boolean OR", | 1501 | "tmp.zig:2:11: note: `||` merges error sets; `or` performs boolean OR", |
| 1597 | ); | 1502 | }); |
| 1598 | | 1503 | |
| 1599 | cases.add( | 1504 | cases.add("compile log a pointer to an opaque value", |
| 1600 | "compile log a pointer to an opaque value", | | |
| 1601 | \\export fn entry() void { | 1505 | \\export fn entry() void { |
| 1602 | \\ @compileLog(@ptrCast(*const c_void, &entry)); | 1506 | \\ @compileLog(@ptrCast(*const c_void, &entry)); |
| 1603 | \\} | 1507 | \\} |
| 1604 | , | 1508 | , &[_][]const u8{ |
| 1605 | "tmp.zig:2:5: error: found compile log statement", | 1509 | "tmp.zig:2:5: error: found compile log statement", |
| 1606 | ); | 1510 | }); |
| 1607 | | 1511 | |
| 1608 | cases.add( | 1512 | cases.add("duplicate boolean switch value", |
| 1609 | "duplicate boolean switch value", | | |
| 1610 | \\comptime { | 1513 | \\comptime { |
| 1611 | \\ const x = switch (true) { | 1514 | \\ const x = switch (true) { |
| 1612 | \\ true => false, | 1515 | \\ true => false, |
| ... | @@ -1621,13 +1524,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -1621,13 +1524,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1621 | \\ false => true, | 1524 | \\ false => true, |
| 1622 | \\ }; | 1525 | \\ }; |
| 1623 | \\} | 1526 | \\} |
| 1624 | , | 1527 | , &[_][]const u8{ |
| 1625 | "tmp.zig:5:9: error: duplicate switch value", | 1528 | "tmp.zig:5:9: error: duplicate switch value", |
| 1626 | "tmp.zig:12:9: error: duplicate switch value", | 1529 | "tmp.zig:12:9: error: duplicate switch value", |
| 1627 | ); | 1530 | }); |
| 1628 | | 1531 | |
| 1629 | cases.add( | 1532 | cases.add("missing boolean switch value", |
| 1630 | "missing boolean switch value", | | |
| 1631 | \\comptime { | 1533 | \\comptime { |
| 1632 | \\ const x = switch (true) { | 1534 | \\ const x = switch (true) { |
| 1633 | \\ true => false, | 1535 | \\ true => false, |
| ... | @@ -1638,37 +1540,34 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -1638,37 +1540,34 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1638 | \\ false => true, | 1540 | \\ false => true, |
| 1639 | \\ }; | 1541 | \\ }; |
| 1640 | \\} | 1542 | \\} |
| 1641 | , | 1543 | , &[_][]const u8{ |
| 1642 | "tmp.zig:2:15: error: switch must handle all possibilities", | 1544 | "tmp.zig:2:15: error: switch must handle all possibilities", |
| 1643 | "tmp.zig:7:15: error: switch must handle all possibilities", | 1545 | "tmp.zig:7:15: error: switch must handle all possibilities", |
| 1644 | ); | 1546 | }); |
| 1645 | | 1547 | |
| 1646 | cases.add( | 1548 | cases.add("reading past end of pointer casted array", |
| 1647 | "reading past end of pointer casted array", | | |
| 1648 | \\comptime { | 1549 | \\comptime { |
| 1649 | \\ const array: [4]u8 = "aoeu".*; | 1550 | \\ const array: [4]u8 = "aoeu".*; |
| 1650 | \\ const slice = array[1..]; | 1551 | \\ const slice = array[1..]; |
| 1651 | \\ const int_ptr = @ptrCast(*const u24, slice.ptr); | 1552 | \\ const int_ptr = @ptrCast(*const u24, slice.ptr); |
| 1652 | \\ const deref = int_ptr.*; | 1553 | \\ const deref = int_ptr.*; |
| 1653 | \\} | 1554 | \\} |
| 1654 | , | 1555 | , &[_][]const u8{ |
| 1655 | "tmp.zig:5:26: error: attempt to read 4 bytes from [4]u8 at index 1 which is 3 bytes", | 1556 | "tmp.zig:5:26: error: attempt to read 4 bytes from [4]u8 at index 1 which is 3 bytes", |
| 1656 | ); | 1557 | }); |
| 1657 | | 1558 | |
| 1658 | cases.add( | 1559 | cases.add("error note for function parameter incompatibility", |
| 1659 | "error note for function parameter incompatibility", | | |
| 1660 | \\fn do_the_thing(func: fn (arg: i32) void) void {} | 1560 | \\fn do_the_thing(func: fn (arg: i32) void) void {} |
| 1661 | \\fn bar(arg: bool) void {} | 1561 | \\fn bar(arg: bool) void {} |
| 1662 | \\export fn entry() void { | 1562 | \\export fn entry() void { |
| 1663 | \\ do_the_thing(bar); | 1563 | \\ do_the_thing(bar); |
| 1664 | \\} | 1564 | \\} |
| 1665 | , | 1565 | , &[_][]const u8{ |
| 1666 | "tmp.zig:4:18: error: expected type 'fn(i32) void', found 'fn(bool) void", | 1566 | "tmp.zig:4:18: error: expected type 'fn(i32) void', found 'fn(bool) void", |
| 1667 | "tmp.zig:4:18: note: parameter 0: 'bool' cannot cast into 'i32'", | 1567 | "tmp.zig:4:18: note: parameter 0: 'bool' cannot cast into 'i32'", |
| 1668 | ); | 1568 | }); |
| 1669 | | 1569 | |
| 1670 | cases.add( | 1570 | cases.add("cast negative value to unsigned integer", |
| 1671 | "cast negative value to unsigned integer", | | |
| 1672 | \\comptime { | 1571 | \\comptime { |
| 1673 | \\ const value: i32 = -1; | 1572 | \\ const value: i32 = -1; |
| 1674 | \\ const unsigned = @intCast(u32, value); | 1573 | \\ const unsigned = @intCast(u32, value); |
| ... | @@ -1677,13 +1576,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -1677,13 +1576,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1677 | \\ const value: i32 = -1; | 1576 | \\ const value: i32 = -1; |
| 1678 | \\ const unsigned: u32 = value; | 1577 | \\ const unsigned: u32 = value; |
| 1679 | \\} | 1578 | \\} |
| 1680 | , | 1579 | , &[_][]const u8{ |
| 1681 | "tmp.zig:3:36: error: cannot cast negative value -1 to unsigned integer type 'u32'", | 1580 | "tmp.zig:3:36: error: cannot cast negative value -1 to unsigned integer type 'u32'", |
| 1682 | "tmp.zig:7:27: error: cannot cast negative value -1 to unsigned integer type 'u32'", | 1581 | "tmp.zig:7:27: error: cannot cast negative value -1 to unsigned integer type 'u32'", |
| 1683 | ); | 1582 | }); |
| 1684 | | 1583 | |
| 1685 | cases.add( | 1584 | cases.add("integer cast truncates bits", |
| 1686 | "integer cast truncates bits", | | |
| 1687 | \\export fn entry1() void { | 1585 | \\export fn entry1() void { |
| 1688 | \\ const spartan_count: u16 = 300; | 1586 | \\ const spartan_count: u16 = 300; |
| 1689 | \\ const byte = @intCast(u8, spartan_count); | 1587 | \\ const byte = @intCast(u8, spartan_count); |
| ... | @@ -1700,50 +1598,46 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -1700,50 +1598,46 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1700 | \\ var signed: i8 = -1; | 1598 | \\ var signed: i8 = -1; |
| 1701 | \\ var unsigned: u64 = signed; | 1599 | \\ var unsigned: u64 = signed; |
| 1702 | \\} | 1600 | \\} |
| 1703 | , | 1601 | , &[_][]const u8{ |
| 1704 | "tmp.zig:3:31: error: integer value 300 cannot be coerced to type 'u8'", | 1602 | "tmp.zig:3:31: error: integer value 300 cannot be coerced to type 'u8'", |
| 1705 | "tmp.zig:7:22: error: integer value 300 cannot be coerced to type 'u8'", | 1603 | "tmp.zig:7:22: error: integer value 300 cannot be coerced to type 'u8'", |
| 1706 | "tmp.zig:11:20: error: expected type 'u8', found 'u16'", | 1604 | "tmp.zig:11:20: error: expected type 'u8', found 'u16'", |
| 1707 | "tmp.zig:11:20: note: unsigned 8-bit int cannot represent all possible unsigned 16-bit values", | 1605 | "tmp.zig:11:20: note: unsigned 8-bit int cannot represent all possible unsigned 16-bit values", |
| 1708 | "tmp.zig:15:25: error: expected type 'u64', found 'i8'", | 1606 | "tmp.zig:15:25: error: expected type 'u64', found 'i8'", |
| 1709 | "tmp.zig:15:25: note: unsigned 64-bit int cannot represent all possible signed 8-bit values", | 1607 | "tmp.zig:15:25: note: unsigned 64-bit int cannot represent all possible signed 8-bit values", |
| 1710 | ); | 1608 | }); |
| 1711 | | 1609 | |
| 1712 | cases.add( | 1610 | cases.add("comptime implicit cast f64 to f32", |
| 1713 | "comptime implicit cast f64 to f32", | | |
| 1714 | \\export fn entry() void { | 1611 | \\export fn entry() void { |
| 1715 | \\ const x: f64 = 16777217; | 1612 | \\ const x: f64 = 16777217; |
| 1716 | \\ const y: f32 = x; | 1613 | \\ const y: f32 = x; |
| 1717 | \\} | 1614 | \\} |
| 1718 | , | 1615 | , &[_][]const u8{ |
| 1719 | "tmp.zig:3:20: error: cast of value 16777217.000000 to type 'f32' loses information", | 1616 | "tmp.zig:3:20: error: cast of value 16777217.000000 to type 'f32' loses information", |
| 1720 | ); | 1617 | }); |
| 1721 | | 1618 | |
| 1722 | cases.add( | 1619 | cases.add("implicit cast from f64 to f32", |
| 1723 | "implicit cast from f64 to f32", | | |
| 1724 | \\var x: f64 = 1.0; | 1620 | \\var x: f64 = 1.0; |
| 1725 | \\var y: f32 = x; | 1621 | \\var y: f32 = x; |
| 1726 | \\ | 1622 | \\ |
| 1727 | \\export fn entry() usize { return @sizeOf(@typeOf(y)); } | 1623 | \\export fn entry() usize { return @sizeOf(@typeOf(y)); } |
| 1728 | , | 1624 | , &[_][]const u8{ |
| 1729 | "tmp.zig:2:14: error: expected type 'f32', found 'f64'", | 1625 | "tmp.zig:2:14: error: expected type 'f32', found 'f64'", |
| 1730 | ); | 1626 | }); |
| 1731 | | 1627 | |
| 1732 | cases.add( | 1628 | cases.add("exceeded maximum bit width of integer", |
| 1733 | "exceeded maximum bit width of integer", | | |
| 1734 | \\export fn entry1() void { | 1629 | \\export fn entry1() void { |
| 1735 | \\ const T = @IntType(false, 65536); | 1630 | \\ const T = @IntType(false, 65536); |
| 1736 | \\} | 1631 | \\} |
| 1737 | \\export fn entry2() void { | 1632 | \\export fn entry2() void { |
| 1738 | \\ var x: i65536 = 1; | 1633 | \\ var x: i65536 = 1; |
| 1739 | \\} | 1634 | \\} |
| 1740 | , | 1635 | , &[_][]const u8{ |
| 1741 | "tmp.zig:2:31: error: integer value 65536 cannot be coerced to type 'u16'", | 1636 | "tmp.zig:2:31: error: integer value 65536 cannot be coerced to type 'u16'", |
| 1742 | "tmp.zig:5:12: error: primitive integer type 'i65536' exceeds maximum bit width of 65535", | 1637 | "tmp.zig:5:12: error: primitive integer type 'i65536' exceeds maximum bit width of 65535", |
| 1743 | ); | 1638 | }); |
| 1744 | | 1639 | |
| 1745 | cases.add( | 1640 | cases.add("compile error when evaluating return type of inferred error set", |
| 1746 | "compile error when evaluating return type of inferred error set", | | |
| 1747 | \\const Car = struct { | 1641 | \\const Car = struct { |
| 1748 | \\ foo: *SymbolThatDoesNotExist, | 1642 | \\ foo: *SymbolThatDoesNotExist, |
| 1749 | \\ pub fn init() !Car {} | 1643 | \\ pub fn init() !Car {} |
| ... | @@ -1751,24 +1645,22 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -1751,24 +1645,22 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1751 | \\export fn entry() void { | 1645 | \\export fn entry() void { |
| 1752 | \\ const car = Car.init(); | 1646 | \\ const car = Car.init(); |
| 1753 | \\} | 1647 | \\} |
| 1754 | , | 1648 | , &[_][]const u8{ |
| 1755 | "tmp.zig:2:11: error: use of undeclared identifier 'SymbolThatDoesNotExist'", | 1649 | "tmp.zig:2:11: error: use of undeclared identifier 'SymbolThatDoesNotExist'", |
| 1756 | ); | 1650 | }); |
| 1757 | | 1651 | |
| 1758 | cases.add( | 1652 | cases.add("don't implicit cast double pointer to *c_void", |
| 1759 | "don't implicit cast double pointer to *c_void", | | |
| 1760 | \\export fn entry() void { | 1653 | \\export fn entry() void { |
| 1761 | \\ var a: u32 = 1; | 1654 | \\ var a: u32 = 1; |
| 1762 | \\ var ptr: *c_void = &a; | 1655 | \\ var ptr: *c_void = &a; |
| 1763 | \\ var b: *u32 = @ptrCast(*u32, ptr); | 1656 | \\ var b: *u32 = @ptrCast(*u32, ptr); |
| 1764 | \\ var ptr2: *c_void = &b; | 1657 | \\ var ptr2: *c_void = &b; |
| 1765 | \\} | 1658 | \\} |
| 1766 | , | 1659 | , &[_][]const u8{ |
| 1767 | "tmp.zig:5:26: error: expected type '*c_void', found '**u32'", | 1660 | "tmp.zig:5:26: error: expected type '*c_void', found '**u32'", |
| 1768 | ); | 1661 | }); |
| 1769 | | 1662 | |
| 1770 | cases.add( | 1663 | cases.add("runtime index into comptime type slice", |
| 1771 | "runtime index into comptime type slice", | | |
| 1772 | \\const Struct = struct { | 1664 | \\const Struct = struct { |
| 1773 | \\ a: u32, | 1665 | \\ a: u32, |
| 1774 | \\}; | 1666 | \\}; |
| ... | @@ -1779,12 +1671,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -1779,12 +1671,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1779 | \\ const index = getIndex(); | 1671 | \\ const index = getIndex(); |
| 1780 | \\ const field = @typeInfo(Struct).Struct.fields[index]; | 1672 | \\ const field = @typeInfo(Struct).Struct.fields[index]; |
| 1781 | \\} | 1673 | \\} |
| 1782 | , | 1674 | , &[_][]const u8{ |
| 1783 | "tmp.zig:9:51: error: values of type 'std.builtin.StructField' must be comptime known, but index value is runtime known", | 1675 | "tmp.zig:9:51: error: values of type 'std.builtin.StructField' must be comptime known, but index value is runtime known", |
| 1784 | ); | 1676 | }); |
| 1785 | | 1677 | |
| 1786 | cases.add( | 1678 | cases.add("compile log statement inside function which must be comptime evaluated", |
| 1787 | "compile log statement inside function which must be comptime evaluated", | | |
| 1788 | \\fn Foo(comptime T: type) type { | 1679 | \\fn Foo(comptime T: type) type { |
| 1789 | \\ @compileLog(@typeName(T)); | 1680 | \\ @compileLog(@typeName(T)); |
| 1790 | \\ return T; | 1681 | \\ return T; |
| ... | @@ -1793,80 +1684,73 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -1793,80 +1684,73 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1793 | \\ _ = Foo(i32); | 1684 | \\ _ = Foo(i32); |
| 1794 | \\ _ = @typeName(Foo(i32)); | 1685 | \\ _ = @typeName(Foo(i32)); |
| 1795 | \\} | 1686 | \\} |
| 1796 | , | 1687 | , &[_][]const u8{ |
| 1797 | "tmp.zig:2:5: error: found compile log statement", | 1688 | "tmp.zig:2:5: error: found compile log statement", |
| 1798 | ); | 1689 | }); |
| 1799 | | 1690 | |
| 1800 | cases.add( | 1691 | cases.add("comptime slice of an undefined slice", |
| 1801 | "comptime slice of an undefined slice", | | |
| 1802 | \\comptime { | 1692 | \\comptime { |
| 1803 | \\ var a: []u8 = undefined; | 1693 | \\ var a: []u8 = undefined; |
| 1804 | \\ var b = a[0..10]; | 1694 | \\ var b = a[0..10]; |
| 1805 | \\} | 1695 | \\} |
| 1806 | , | 1696 | , &[_][]const u8{ |
| 1807 | "tmp.zig:3:14: error: slice of undefined", | 1697 | "tmp.zig:3:14: error: slice of undefined", |
| 1808 | ); | 1698 | }); |
| 1809 | | 1699 | |
| 1810 | cases.add( | 1700 | cases.add("implicit cast const array to mutable slice", |
| 1811 | "implicit cast const array to mutable slice", | | |
| 1812 | \\export fn entry() void { | 1701 | \\export fn entry() void { |
| 1813 | \\ const buffer: [1]u8 = [_]u8{8}; | 1702 | \\ const buffer: [1]u8 = [_]u8{8}; |
| 1814 | \\ const sliceA: []u8 = &buffer; | 1703 | \\ const sliceA: []u8 = &buffer; |
| 1815 | \\} | 1704 | \\} |
| 1816 | , | 1705 | , &[_][]const u8{ |
| 1817 | "tmp.zig:3:27: error: expected type '[]u8', found '*const [1]u8'", | 1706 | "tmp.zig:3:27: error: expected type '[]u8', found '*const [1]u8'", |
| 1818 | ); | 1707 | }); |
| 1819 | | 1708 | |
| 1820 | cases.add( | 1709 | cases.add("deref slice and get len field", |
| 1821 | "deref slice and get len field", | | |
| 1822 | \\export fn entry() void { | 1710 | \\export fn entry() void { |
| 1823 | \\ var a: []u8 = undefined; | 1711 | \\ var a: []u8 = undefined; |
| 1824 | \\ _ = a.*.len; | 1712 | \\ _ = a.*.len; |
| 1825 | \\} | 1713 | \\} |
| 1826 | , | 1714 | , &[_][]const u8{ |
| 1827 | "tmp.zig:3:10: error: attempt to dereference non-pointer type '[]u8'", | 1715 | "tmp.zig:3:10: error: attempt to dereference non-pointer type '[]u8'", |
| 1828 | ); | 1716 | }); |
| 1829 | | 1717 | |
| 1830 | cases.add( | 1718 | cases.add("@ptrCast a 0 bit type to a non- 0 bit type", |
| 1831 | "@ptrCast a 0 bit type to a non- 0 bit type", | | |
| 1832 | \\export fn entry() bool { | 1719 | \\export fn entry() bool { |
| 1833 | \\ var x: u0 = 0; | 1720 | \\ var x: u0 = 0; |
| 1834 | \\ const p = @ptrCast(?*u0, &x); | 1721 | \\ const p = @ptrCast(?*u0, &x); |
| 1835 | \\ return p == null; | 1722 | \\ return p == null; |
| 1836 | \\} | 1723 | \\} |
| 1837 | , | 1724 | , &[_][]const u8{ |
| 1838 | "tmp.zig:3:15: error: '*u0' and '?*u0' do not have the same in-memory representation", | 1725 | "tmp.zig:3:15: error: '*u0' and '?*u0' do not have the same in-memory representation", |
| 1839 | "tmp.zig:3:31: note: '*u0' has no in-memory bits", | 1726 | "tmp.zig:3:31: note: '*u0' has no in-memory bits", |
| 1840 | "tmp.zig:3:24: note: '?*u0' has in-memory bits", | 1727 | "tmp.zig:3:24: note: '?*u0' has in-memory bits", |
| 1841 | ); | 1728 | }); |
| 1842 | | 1729 | |
| 1843 | cases.add( | 1730 | cases.add("comparing a non-optional pointer against null", |
| 1844 | "comparing a non-optional pointer against null", | | |
| 1845 | \\export fn entry() void { | 1731 | \\export fn entry() void { |
| 1846 | \\ var x: i32 = 1; | 1732 | \\ var x: i32 = 1; |
| 1847 | \\ _ = &x == null; | 1733 | \\ _ = &x == null; |
| 1848 | \\} | 1734 | \\} |
| 1849 | , | 1735 | , &[_][]const u8{ |
| 1850 | "tmp.zig:3:12: error: comparison of '*i32' with null", | 1736 | "tmp.zig:3:12: error: comparison of '*i32' with null", |
| 1851 | ); | 1737 | }); |
| 1852 | | 1738 | |
| 1853 | cases.add( | 1739 | cases.add("non error sets used in merge error sets operator", |
| 1854 | "non error sets used in merge error sets operator", | | |
| 1855 | \\export fn foo() void { | 1740 | \\export fn foo() void { |
| 1856 | \\ const Errors = u8 || u16; | 1741 | \\ const Errors = u8 || u16; |
| 1857 | \\} | 1742 | \\} |
| 1858 | \\export fn bar() void { | 1743 | \\export fn bar() void { |
| 1859 | \\ const Errors = error{} || u16; | 1744 | \\ const Errors = error{} || u16; |
| 1860 | \\} | 1745 | \\} |
| 1861 | , | 1746 | , &[_][]const u8{ |
| 1862 | "tmp.zig:2:20: error: expected error set type, found type 'u8'", | 1747 | "tmp.zig:2:20: error: expected error set type, found type 'u8'", |
| 1863 | "tmp.zig:2:23: note: `||` merges error sets; `or` performs boolean OR", | 1748 | "tmp.zig:2:23: note: `||` merges error sets; `or` performs boolean OR", |
| 1864 | "tmp.zig:5:31: error: expected error set type, found type 'u16'", | 1749 | "tmp.zig:5:31: error: expected error set type, found type 'u16'", |
| 1865 | "tmp.zig:5:28: note: `||` merges error sets; `or` performs boolean OR", | 1750 | "tmp.zig:5:28: note: `||` merges error sets; `or` performs boolean OR", |
| 1866 | ); | 1751 | }); |
| 1867 | | 1752 | |
| 1868 | cases.add( | 1753 | cases.add("variable initialization compile error then referenced", |
| 1869 | "variable initialization compile error then referenced", | | |
| 1870 | \\fn Undeclared() type { | 1754 | \\fn Undeclared() type { |
| 1871 | \\ return T; | 1755 | \\ return T; |
| 1872 | \\} | 1756 | \\} |
| ... | @@ -1879,23 +1763,21 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -1879,23 +1763,21 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1879 | \\export fn entry() void { | 1763 | \\export fn entry() void { |
| 1880 | \\ const S = Gen(); | 1764 | \\ const S = Gen(); |
| 1881 | \\} | 1765 | \\} |
| 1882 | , | 1766 | , &[_][]const u8{ |
| 1883 | "tmp.zig:2:12: error: use of undeclared identifier 'T'", | 1767 | "tmp.zig:2:12: error: use of undeclared identifier 'T'", |
| 1884 | ); | 1768 | }); |
| 1885 | | 1769 | |
| 1886 | cases.add( | 1770 | cases.add("refer to the type of a generic function", |
| 1887 | "refer to the type of a generic function", | | |
| 1888 | \\export fn entry() void { | 1771 | \\export fn entry() void { |
| 1889 | \\ const Func = fn (type) void; | 1772 | \\ const Func = fn (type) void; |
| 1890 | \\ const f: Func = undefined; | 1773 | \\ const f: Func = undefined; |
| 1891 | \\ f(i32); | 1774 | \\ f(i32); |
| 1892 | \\} | 1775 | \\} |
| 1893 | , | 1776 | , &[_][]const u8{ |
| 1894 | "tmp.zig:4:5: error: use of undefined value here causes undefined behavior", | 1777 | "tmp.zig:4:5: error: use of undefined value here causes undefined behavior", |
| 1895 | ); | 1778 | }); |
| 1896 | | 1779 | |
| 1897 | cases.add( | 1780 | cases.add("accessing runtime parameter from outer function", |
| 1898 | "accessing runtime parameter from outer function", | | |
| 1899 | \\fn outer(y: u32) fn (u32) u32 { | 1781 | \\fn outer(y: u32) fn (u32) u32 { |
| 1900 | \\ const st = struct { | 1782 | \\ const st = struct { |
| 1901 | \\ fn get(z: u32) u32 { | 1783 | \\ fn get(z: u32) u32 { |
| ... | @@ -1908,53 +1790,48 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -1908,53 +1790,48 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1908 | \\ var func = outer(10); | 1790 | \\ var func = outer(10); |
| 1909 | \\ var x = func(3); | 1791 | \\ var x = func(3); |
| 1910 | \\} | 1792 | \\} |
| 1911 | , | 1793 | , &[_][]const u8{ |
| 1912 | "tmp.zig:4:24: error: 'y' not accessible from inner function", | 1794 | "tmp.zig:4:24: error: 'y' not accessible from inner function", |
| 1913 | "tmp.zig:3:28: note: crossed function definition here", | 1795 | "tmp.zig:3:28: note: crossed function definition here", |
| 1914 | "tmp.zig:1:10: note: declared here", | 1796 | "tmp.zig:1:10: note: declared here", |
| 1915 | ); | 1797 | }); |
| 1916 | | 1798 | |
| 1917 | cases.add( | 1799 | cases.add("non int passed to @intToFloat", |
| 1918 | "non int passed to @intToFloat", | | |
| 1919 | \\export fn entry() void { | 1800 | \\export fn entry() void { |
| 1920 | \\ const x = @intToFloat(f32, 1.1); | 1801 | \\ const x = @intToFloat(f32, 1.1); |
| 1921 | \\} | 1802 | \\} |
| 1922 | , | 1803 | , &[_][]const u8{ |
| 1923 | "tmp.zig:2:32: error: expected int type, found 'comptime_float'", | 1804 | "tmp.zig:2:32: error: expected int type, found 'comptime_float'", |
| 1924 | ); | 1805 | }); |
| 1925 | | 1806 | |
| 1926 | cases.add( | 1807 | cases.add("non float passed to @floatToInt", |
| 1927 | "non float passed to @floatToInt", | | |
| 1928 | \\export fn entry() void { | 1808 | \\export fn entry() void { |
| 1929 | \\ const x = @floatToInt(i32, @as(i32, 54)); | 1809 | \\ const x = @floatToInt(i32, @as(i32, 54)); |
| 1930 | \\} | 1810 | \\} |
| 1931 | , | 1811 | , &[_][]const u8{ |
| 1932 | "tmp.zig:2:32: error: expected float type, found 'i32'", | 1812 | "tmp.zig:2:32: error: expected float type, found 'i32'", |
| 1933 | ); | 1813 | }); |
| 1934 | | 1814 | |
| 1935 | cases.add( | 1815 | cases.add("out of range comptime_int passed to @floatToInt", |
| 1936 | "out of range comptime_int passed to @floatToInt", | | |
| 1937 | \\export fn entry() void { | 1816 | \\export fn entry() void { |
| 1938 | \\ const x = @floatToInt(i8, 200); | 1817 | \\ const x = @floatToInt(i8, 200); |
| 1939 | \\} | 1818 | \\} |
| 1940 | , | 1819 | , &[_][]const u8{ |
| 1941 | "tmp.zig:2:31: error: integer value 200 cannot be coerced to type 'i8'", | 1820 | "tmp.zig:2:31: error: integer value 200 cannot be coerced to type 'i8'", |
| 1942 | ); | 1821 | }); |
| 1943 | | 1822 | |
| 1944 | cases.add( | 1823 | cases.add("load too many bytes from comptime reinterpreted pointer", |
| 1945 | "load too many bytes from comptime reinterpreted pointer", | | |
| 1946 | \\export fn entry() void { | 1824 | \\export fn entry() void { |
| 1947 | \\ const float: f32 = 5.99999999999994648725e-01; | 1825 | \\ const float: f32 = 5.99999999999994648725e-01; |
| 1948 | \\ const float_ptr = &float; | 1826 | \\ const float_ptr = &float; |
| 1949 | \\ const int_ptr = @ptrCast(*const i64, float_ptr); | 1827 | \\ const int_ptr = @ptrCast(*const i64, float_ptr); |
| 1950 | \\ const int_val = int_ptr.*; | 1828 | \\ const int_val = int_ptr.*; |
| 1951 | \\} | 1829 | \\} |
| 1952 | , | 1830 | , &[_][]const u8{ |
| 1953 | "tmp.zig:5:28: error: attempt to read 8 bytes from pointer to f32 which is 4 bytes", | 1831 | "tmp.zig:5:28: error: attempt to read 8 bytes from pointer to f32 which is 4 bytes", |
| 1954 | ); | 1832 | }); |
| 1955 | | 1833 | |
| 1956 | cases.add( | 1834 | cases.add("invalid type used in array type", |
| 1957 | "invalid type used in array type", | | |
| 1958 | \\const Item = struct { | 1835 | \\const Item = struct { |
| 1959 | \\ field: SomeNonexistentType, | 1836 | \\ field: SomeNonexistentType, |
| 1960 | \\}; | 1837 | \\}; |
| ... | @@ -1962,12 +1839,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -1962,12 +1839,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1962 | \\export fn entry() void { | 1839 | \\export fn entry() void { |
| 1963 | \\ const a = items[0]; | 1840 | \\ const a = items[0]; |
| 1964 | \\} | 1841 | \\} |
| 1965 | , | 1842 | , &[_][]const u8{ |
| 1966 | "tmp.zig:2:12: error: use of undeclared identifier 'SomeNonexistentType'", | 1843 | "tmp.zig:2:12: error: use of undeclared identifier 'SomeNonexistentType'", |
| 1967 | ); | 1844 | }); |
| 1968 | | 1845 | |
| 1969 | cases.add( | 1846 | cases.add("comptime continue inside runtime catch", |
| 1970 | "comptime continue inside runtime catch", | | |
| 1971 | \\export fn entry(c: bool) void { | 1847 | \\export fn entry(c: bool) void { |
| 1972 | \\ const ints = [_]u8{ 1, 2 }; | 1848 | \\ const ints = [_]u8{ 1, 2 }; |
| 1973 | \\ inline for (ints) |_| { | 1849 | \\ inline for (ints) |_| { |
| ... | @@ -1977,13 +1853,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -1977,13 +1853,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1977 | \\fn bad() !void { | 1853 | \\fn bad() !void { |
| 1978 | \\ return error.Bad; | 1854 | \\ return error.Bad; |
| 1979 | \\} | 1855 | \\} |
| 1980 | , | 1856 | , &[_][]const u8{ |
| 1981 | "tmp.zig:4:25: error: comptime control flow inside runtime block", | 1857 | "tmp.zig:4:25: error: comptime control flow inside runtime block", |
| 1982 | "tmp.zig:4:15: note: runtime block created here", | 1858 | "tmp.zig:4:15: note: runtime block created here", |
| 1983 | ); | 1859 | }); |
| 1984 | | 1860 | |
| 1985 | cases.add( | 1861 | cases.add("comptime continue inside runtime switch", |
| 1986 | "comptime continue inside runtime switch", | | |
| 1987 | \\export fn entry() void { | 1862 | \\export fn entry() void { |
| 1988 | \\ var p: i32 = undefined; | 1863 | \\ var p: i32 = undefined; |
| 1989 | \\ comptime var q = true; | 1864 | \\ comptime var q = true; |
| ... | @@ -1995,13 +1870,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -1995,13 +1870,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1995 | \\ q = false; | 1870 | \\ q = false; |
| 1996 | \\ } | 1871 | \\ } |
| 1997 | \\} | 1872 | \\} |
| 1998 | , | 1873 | , &[_][]const u8{ |
| 1999 | "tmp.zig:6:19: error: comptime control flow inside runtime block", | 1874 | "tmp.zig:6:19: error: comptime control flow inside runtime block", |
| 2000 | "tmp.zig:5:9: note: runtime block created here", | 1875 | "tmp.zig:5:9: note: runtime block created here", |
| 2001 | ); | 1876 | }); |
| 2002 | | 1877 | |
| 2003 | cases.add( | 1878 | cases.add("comptime continue inside runtime while error", |
| 2004 | "comptime continue inside runtime while error", | | |
| 2005 | \\export fn entry() void { | 1879 | \\export fn entry() void { |
| 2006 | \\ var p: anyerror!usize = undefined; | 1880 | \\ var p: anyerror!usize = undefined; |
| 2007 | \\ comptime var q = true; | 1881 | \\ comptime var q = true; |
| ... | @@ -2012,13 +1886,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -2012,13 +1886,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2012 | \\ q = false; | 1886 | \\ q = false; |
| 2013 | \\ } | 1887 | \\ } |
| 2014 | \\} | 1888 | \\} |
| 2015 | , | 1889 | , &[_][]const u8{ |
| 2016 | "tmp.zig:6:13: error: comptime control flow inside runtime block", | 1890 | "tmp.zig:6:13: error: comptime control flow inside runtime block", |
| 2017 | "tmp.zig:5:9: note: runtime block created here", | 1891 | "tmp.zig:5:9: note: runtime block created here", |
| 2018 | ); | 1892 | }); |
| 2019 | | 1893 | |
| 2020 | cases.add( | 1894 | cases.add("comptime continue inside runtime while optional", |
| 2021 | "comptime continue inside runtime while optional", | | |
| 2022 | \\export fn entry() void { | 1895 | \\export fn entry() void { |
| 2023 | \\ var p: ?usize = undefined; | 1896 | \\ var p: ?usize = undefined; |
| 2024 | \\ comptime var q = true; | 1897 | \\ comptime var q = true; |
| ... | @@ -2027,13 +1900,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -2027,13 +1900,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2027 | \\ q = false; | 1900 | \\ q = false; |
| 2028 | \\ } | 1901 | \\ } |
| 2029 | \\} | 1902 | \\} |
| 2030 | , | 1903 | , &[_][]const u8{ |
| 2031 | "tmp.zig:5:23: error: comptime control flow inside runtime block", | 1904 | "tmp.zig:5:23: error: comptime control flow inside runtime block", |
| 2032 | "tmp.zig:5:9: note: runtime block created here", | 1905 | "tmp.zig:5:9: note: runtime block created here", |
| 2033 | ); | 1906 | }); |
| 2034 | | 1907 | |
| 2035 | cases.add( | 1908 | cases.add("comptime continue inside runtime while bool", |
| 2036 | "comptime continue inside runtime while bool", | | |
| 2037 | \\export fn entry() void { | 1909 | \\export fn entry() void { |
| 2038 | \\ var p: usize = undefined; | 1910 | \\ var p: usize = undefined; |
| 2039 | \\ comptime var q = true; | 1911 | \\ comptime var q = true; |
| ... | @@ -2042,13 +1914,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -2042,13 +1914,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2042 | \\ q = false; | 1914 | \\ q = false; |
| 2043 | \\ } | 1915 | \\ } |
| 2044 | \\} | 1916 | \\} |
| 2045 | , | 1917 | , &[_][]const u8{ |
| 2046 | "tmp.zig:5:25: error: comptime control flow inside runtime block", | 1918 | "tmp.zig:5:25: error: comptime control flow inside runtime block", |
| 2047 | "tmp.zig:5:9: note: runtime block created here", | 1919 | "tmp.zig:5:9: note: runtime block created here", |
| 2048 | ); | 1920 | }); |
| 2049 | | 1921 | |
| 2050 | cases.add( | 1922 | cases.add("comptime continue inside runtime if error", |
| 2051 | "comptime continue inside runtime if error", | | |
| 2052 | \\export fn entry() void { | 1923 | \\export fn entry() void { |
| 2053 | \\ var p: anyerror!i32 = undefined; | 1924 | \\ var p: anyerror!i32 = undefined; |
| 2054 | \\ comptime var q = true; | 1925 | \\ comptime var q = true; |
| ... | @@ -2057,13 +1928,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -2057,13 +1928,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2057 | \\ q = false; | 1928 | \\ q = false; |
| 2058 | \\ } | 1929 | \\ } |
| 2059 | \\} | 1930 | \\} |
| 2060 | , | 1931 | , &[_][]const u8{ |
| 2061 | "tmp.zig:5:20: error: comptime control flow inside runtime block", | 1932 | "tmp.zig:5:20: error: comptime control flow inside runtime block", |
| 2062 | "tmp.zig:5:9: note: runtime block created here", | 1933 | "tmp.zig:5:9: note: runtime block created here", |
| 2063 | ); | 1934 | }); |
| 2064 | | 1935 | |
| 2065 | cases.add( | 1936 | cases.add("comptime continue inside runtime if optional", |
| 2066 | "comptime continue inside runtime if optional", | | |
| 2067 | \\export fn entry() void { | 1937 | \\export fn entry() void { |
| 2068 | \\ var p: ?i32 = undefined; | 1938 | \\ var p: ?i32 = undefined; |
| 2069 | \\ comptime var q = true; | 1939 | \\ comptime var q = true; |
| ... | @@ -2072,13 +1942,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -2072,13 +1942,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2072 | \\ q = false; | 1942 | \\ q = false; |
| 2073 | \\ } | 1943 | \\ } |
| 2074 | \\} | 1944 | \\} |
| 2075 | , | 1945 | , &[_][]const u8{ |
| 2076 | "tmp.zig:5:20: error: comptime control flow inside runtime block", | 1946 | "tmp.zig:5:20: error: comptime control flow inside runtime block", |
| 2077 | "tmp.zig:5:9: note: runtime block created here", | 1947 | "tmp.zig:5:9: note: runtime block created here", |
| 2078 | ); | 1948 | }); |
| 2079 | | 1949 | |
| 2080 | cases.add( | 1950 | cases.add("comptime continue inside runtime if bool", |
| 2081 | "comptime continue inside runtime if bool", | | |
| 2082 | \\export fn entry() void { | 1951 | \\export fn entry() void { |
| 2083 | \\ var p: usize = undefined; | 1952 | \\ var p: usize = undefined; |
| 2084 | \\ comptime var q = true; | 1953 | \\ comptime var q = true; |
| ... | @@ -2087,13 +1956,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -2087,13 +1956,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2087 | \\ q = false; | 1956 | \\ q = false; |
| 2088 | \\ } | 1957 | \\ } |
| 2089 | \\} | 1958 | \\} |
| 2090 | , | 1959 | , &[_][]const u8{ |
| 2091 | "tmp.zig:5:22: error: comptime control flow inside runtime block", | 1960 | "tmp.zig:5:22: error: comptime control flow inside runtime block", |
| 2092 | "tmp.zig:5:9: note: runtime block created here", | 1961 | "tmp.zig:5:9: note: runtime block created here", |
| 2093 | ); | 1962 | }); |
| 2094 | | 1963 | |
| 2095 | cases.add( | 1964 | cases.add("switch with invalid expression parameter", |
| 2096 | "switch with invalid expression parameter", | | |
| 2097 | \\export fn entry() void { | 1965 | \\export fn entry() void { |
| 2098 | \\ Test(i32); | 1966 | \\ Test(i32); |
| 2099 | \\} | 1967 | \\} |
| ... | @@ -2104,43 +1972,39 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -2104,43 +1972,39 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2104 | \\ else => unreachable, | 1972 | \\ else => unreachable, |
| 2105 | \\ }; | 1973 | \\ }; |
| 2106 | \\} | 1974 | \\} |
| 2107 | , | 1975 | , &[_][]const u8{ |
| 2108 | "tmp.zig:7:17: error: switch on type 'type' provides no expression parameter", | 1976 | "tmp.zig:7:17: error: switch on type 'type' provides no expression parameter", |
| 2109 | ); | 1977 | }); |
| 2110 | | 1978 | |
| 2111 | cases.add( | 1979 | cases.add("function protoype with no body", |
| 2112 | "function protoype with no body", | | |
| 2113 | \\fn foo() void; | 1980 | \\fn foo() void; |
| 2114 | \\export fn entry() void { | 1981 | \\export fn entry() void { |
| 2115 | \\ foo(); | 1982 | \\ foo(); |
| 2116 | \\} | 1983 | \\} |
| 2117 | , | 1984 | , &[_][]const u8{ |
| 2118 | "tmp.zig:1:1: error: non-extern function has no body", | 1985 | "tmp.zig:1:1: error: non-extern function has no body", |
| 2119 | ); | 1986 | }); |
| 2120 | | 1987 | |
| 2121 | cases.add( | 1988 | cases.add("@frame() called outside of function definition", |
| 2122 | "@frame() called outside of function definition", | | |
| 2123 | \\var handle_undef: anyframe = undefined; | 1989 | \\var handle_undef: anyframe = undefined; |
| 2124 | \\var handle_dummy: anyframe = @frame(); | 1990 | \\var handle_dummy: anyframe = @frame(); |
| 2125 | \\export fn entry() bool { | 1991 | \\export fn entry() bool { |
| 2126 | \\ return handle_undef == handle_dummy; | 1992 | \\ return handle_undef == handle_dummy; |
| 2127 | \\} | 1993 | \\} |
| 2128 | , | 1994 | , &[_][]const u8{ |
| 2129 | "tmp.zig:2:30: error: @frame() called outside of function definition", | 1995 | "tmp.zig:2:30: error: @frame() called outside of function definition", |
| 2130 | ); | 1996 | }); |
| 2131 | | 1997 | |
| 2132 | cases.add( | 1998 | cases.add("`_` is not a declarable symbol", |
| 2133 | "`_` is not a declarable symbol", | | |
| 2134 | \\export fn f1() usize { | 1999 | \\export fn f1() usize { |
| 2135 | \\ var _: usize = 2; | 2000 | \\ var _: usize = 2; |
| 2136 | \\ return _; | 2001 | \\ return _; |
| 2137 | \\} | 2002 | \\} |
| 2138 | , | 2003 | , &[_][]const u8{ |
| 2139 | "tmp.zig:2:5: error: `_` is not a declarable symbol", | 2004 | "tmp.zig:2:5: error: `_` is not a declarable symbol", |
| 2140 | ); | 2005 | }); |
| 2141 | | 2006 | |
| 2142 | cases.add( | 2007 | cases.add("`_` should not be usable inside for", |
| 2143 | "`_` should not be usable inside for", | | |
| 2144 | \\export fn returns() void { | 2008 | \\export fn returns() void { |
| 2145 | \\ for ([_]void{}) |_, i| { | 2009 | \\ for ([_]void{}) |_, i| { |
| 2146 | \\ for ([_]void{}) |_, j| { | 2010 | \\ for ([_]void{}) |_, j| { |
| ... | @@ -2148,12 +2012,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -2148,12 +2012,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2148 | \\ } | 2012 | \\ } |
| 2149 | \\ } | 2013 | \\ } |
| 2150 | \\} | 2014 | \\} |
| 2151 | , | 2015 | , &[_][]const u8{ |
| 2152 | "tmp.zig:4:20: error: `_` may only be used to assign things to", | 2016 | "tmp.zig:4:20: error: `_` may only be used to assign things to", |
| 2153 | ); | 2017 | }); |
| 2154 | | 2018 | |
| 2155 | cases.add( | 2019 | cases.add("`_` should not be usable inside while", |
| 2156 | "`_` should not be usable inside while", | | |
| 2157 | \\export fn returns() void { | 2020 | \\export fn returns() void { |
| 2158 | \\ while (optionalReturn()) |_| { | 2021 | \\ while (optionalReturn()) |_| { |
| 2159 | \\ while (optionalReturn()) |_| { | 2022 | \\ while (optionalReturn()) |_| { |
| ... | @@ -2164,12 +2027,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -2164,12 +2027,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2164 | \\fn optionalReturn() ?u32 { | 2027 | \\fn optionalReturn() ?u32 { |
| 2165 | \\ return 1; | 2028 | \\ return 1; |
| 2166 | \\} | 2029 | \\} |
| 2167 | , | 2030 | , &[_][]const u8{ |
| 2168 | "tmp.zig:4:20: error: `_` may only be used to assign things to", | 2031 | "tmp.zig:4:20: error: `_` may only be used to assign things to", |
| 2169 | ); | 2032 | }); |
| 2170 | | 2033 | |
| 2171 | cases.add( | 2034 | cases.add("`_` should not be usable inside while else", |
| 2172 | "`_` should not be usable inside while else", | | |
| 2173 | \\export fn returns() void { | 2035 | \\export fn returns() void { |
| 2174 | \\ while (optionalReturnError()) |_| { | 2036 | \\ while (optionalReturnError()) |_| { |
| 2175 | \\ while (optionalReturnError()) |_| { | 2037 | \\ while (optionalReturnError()) |_| { |
| ... | @@ -2182,12 +2044,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -2182,12 +2044,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2182 | \\fn optionalReturnError() !?u32 { | 2044 | \\fn optionalReturnError() !?u32 { |
| 2183 | \\ return error.optionalReturnError; | 2045 | \\ return error.optionalReturnError; |
| 2184 | \\} | 2046 | \\} |
| 2185 | , | 2047 | , &[_][]const u8{ |
| 2186 | "tmp.zig:6:17: error: `_` may only be used to assign things to", | 2048 | "tmp.zig:6:17: error: `_` may only be used to assign things to", |
| 2187 | ); | 2049 | }); |
| 2188 | | 2050 | |
| 2189 | cases.add( | 2051 | cases.add("while loop body expression ignored", |
| 2190 | "while loop body expression ignored", | | |
| 2191 | \\fn returns() usize { | 2052 | \\fn returns() usize { |
| 2192 | \\ return 2; | 2053 | \\ return 2; |
| 2193 | \\} | 2054 | \\} |
| ... | @@ -2202,25 +2063,23 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -2202,25 +2063,23 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2202 | \\ var x: anyerror!i32 = error.Bad; | 2063 | \\ var x: anyerror!i32 = error.Bad; |
| 2203 | \\ while (x) |_| returns() else |_| unreachable; | 2064 | \\ while (x) |_| returns() else |_| unreachable; |
| 2204 | \\} | 2065 | \\} |
| 2205 | , | 2066 | , &[_][]const u8{ |
| 2206 | "tmp.zig:5:25: error: expression value is ignored", | 2067 | "tmp.zig:5:25: error: expression value is ignored", |
| 2207 | "tmp.zig:9:26: error: expression value is ignored", | 2068 | "tmp.zig:9:26: error: expression value is ignored", |
| 2208 | "tmp.zig:13:26: error: expression value is ignored", | 2069 | "tmp.zig:13:26: error: expression value is ignored", |
| 2209 | ); | 2070 | }); |
| 2210 | | 2071 | |
| 2211 | cases.add( | 2072 | cases.add("missing parameter name of generic function", |
| 2212 | "missing parameter name of generic function", | | |
| 2213 | \\fn dump(var) void {} | 2073 | \\fn dump(var) void {} |
| 2214 | \\export fn entry() void { | 2074 | \\export fn entry() void { |
| 2215 | \\ var a: u8 = 9; | 2075 | \\ var a: u8 = 9; |
| 2216 | \\ dump(a); | 2076 | \\ dump(a); |
| 2217 | \\} | 2077 | \\} |
| 2218 | , | 2078 | , &[_][]const u8{ |
| 2219 | "tmp.zig:1:9: error: missing parameter name", | 2079 | "tmp.zig:1:9: error: missing parameter name", |
| 2220 | ); | 2080 | }); |
| 2221 | | 2081 | |
| 2222 | cases.add( | 2082 | cases.add("non-inline for loop on a type that requires comptime", |
| 2223 | "non-inline for loop on a type that requires comptime", | | |
| 2224 | \\const Foo = struct { | 2083 | \\const Foo = struct { |
| 2225 | \\ name: []const u8, | 2084 | \\ name: []const u8, |
| 2226 | \\ T: type, | 2085 | \\ T: type, |
| ... | @@ -2229,23 +2088,21 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -2229,23 +2088,21 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2229 | \\ const xx: [2]Foo = undefined; | 2088 | \\ const xx: [2]Foo = undefined; |
| 2230 | \\ for (xx) |f| {} | 2089 | \\ for (xx) |f| {} |
| 2231 | \\} | 2090 | \\} |
| 2232 | , | 2091 | , &[_][]const u8{ |
| 2233 | "tmp.zig:7:5: error: values of type 'Foo' must be comptime known, but index value is runtime known", | 2092 | "tmp.zig:7:5: error: values of type 'Foo' must be comptime known, but index value is runtime known", |
| 2234 | ); | 2093 | }); |
| 2235 | | 2094 | |
| 2236 | cases.add( | 2095 | cases.add("generic fn as parameter without comptime keyword", |
| 2237 | "generic fn as parameter without comptime keyword", | | |
| 2238 | \\fn f(_: fn (var) void) void {} | 2096 | \\fn f(_: fn (var) void) void {} |
| 2239 | \\fn g(_: var) void {} | 2097 | \\fn g(_: var) void {} |
| 2240 | \\export fn entry() void { | 2098 | \\export fn entry() void { |
| 2241 | \\ f(g); | 2099 | \\ f(g); |
| 2242 | \\} | 2100 | \\} |
| 2243 | , | 2101 | , &[_][]const u8{ |
| 2244 | "tmp.zig:1:9: error: parameter of type 'fn(var)var' must be declared comptime", | 2102 | "tmp.zig:1:9: error: parameter of type 'fn(var)var' must be declared comptime", |
| 2245 | ); | 2103 | }); |
| 2246 | | 2104 | |
| 2247 | cases.add( | 2105 | cases.add("optional pointer to void in extern struct", |
| 2248 | "optional pointer to void in extern struct", | | |
| 2249 | \\const Foo = extern struct { | 2106 | \\const Foo = extern struct { |
| 2250 | \\ x: ?*const void, | 2107 | \\ x: ?*const void, |
| 2251 | \\}; | 2108 | \\}; |
| ... | @@ -2254,12 +2111,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -2254,12 +2111,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2254 | \\ y: i32, | 2111 | \\ y: i32, |
| 2255 | \\}; | 2112 | \\}; |
| 2256 | \\export fn entry(bar: *Bar) void {} | 2113 | \\export fn entry(bar: *Bar) void {} |
| 2257 | , | 2114 | , &[_][]const u8{ |
| 2258 | "tmp.zig:2:5: error: extern structs cannot contain fields of type '?*const void'", | 2115 | "tmp.zig:2:5: error: extern structs cannot contain fields of type '?*const void'", |
| 2259 | ); | 2116 | }); |
| 2260 | | 2117 | |
| 2261 | cases.add( | 2118 | cases.add("use of comptime-known undefined function value", |
| 2262 | "use of comptime-known undefined function value", | | |
| 2263 | \\const Cmd = struct { | 2119 | \\const Cmd = struct { |
| 2264 | \\ exec: fn () void, | 2120 | \\ exec: fn () void, |
| 2265 | \\}; | 2121 | \\}; |
| ... | @@ -2267,12 +2123,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -2267,12 +2123,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2267 | \\ const command = Cmd{ .exec = undefined }; | 2123 | \\ const command = Cmd{ .exec = undefined }; |
| 2268 | \\ command.exec(); | 2124 | \\ command.exec(); |
| 2269 | \\} | 2125 | \\} |
| 2270 | , | 2126 | , &[_][]const u8{ |
| 2271 | "tmp.zig:6:12: error: use of undefined value here causes undefined behavior", | 2127 | "tmp.zig:6:12: error: use of undefined value here causes undefined behavior", |
| 2272 | ); | 2128 | }); |
| 2273 | | 2129 | |
| 2274 | cases.add( | 2130 | cases.add("use of comptime-known undefined function value", |
| 2275 | "use of comptime-known undefined function value", | | |
| 2276 | \\const Cmd = struct { | 2131 | \\const Cmd = struct { |
| 2277 | \\ exec: fn () void, | 2132 | \\ exec: fn () void, |
| 2278 | \\}; | 2133 | \\}; |
| ... | @@ -2280,41 +2135,37 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -2280,41 +2135,37 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2280 | \\ const command = Cmd{ .exec = undefined }; | 2135 | \\ const command = Cmd{ .exec = undefined }; |
| 2281 | \\ command.exec(); | 2136 | \\ command.exec(); |
| 2282 | \\} | 2137 | \\} |
| 2283 | , | 2138 | , &[_][]const u8{ |
| 2284 | "tmp.zig:6:12: error: use of undefined value here causes undefined behavior", | 2139 | "tmp.zig:6:12: error: use of undefined value here causes undefined behavior", |
| 2285 | ); | 2140 | }); |
| 2286 | | 2141 | |
| 2287 | cases.add( | 2142 | cases.add("bad @alignCast at comptime", |
| 2288 | "bad @alignCast at comptime", | | |
| 2289 | \\comptime { | 2143 | \\comptime { |
| 2290 | \\ const ptr = @intToPtr(*i32, 0x1); | 2144 | \\ const ptr = @intToPtr(*i32, 0x1); |
| 2291 | \\ const aligned = @alignCast(4, ptr); | 2145 | \\ const aligned = @alignCast(4, ptr); |
| 2292 | \\} | 2146 | \\} |
| 2293 | , | 2147 | , &[_][]const u8{ |
| 2294 | "tmp.zig:3:35: error: pointer address 0x1 is not aligned to 4 bytes", | 2148 | "tmp.zig:3:35: error: pointer address 0x1 is not aligned to 4 bytes", |
| 2295 | ); | 2149 | }); |
| 2296 | | 2150 | |
| 2297 | cases.add( | 2151 | cases.add("@ptrToInt on *void", |
| 2298 | "@ptrToInt on *void", | | |
| 2299 | \\export fn entry() bool { | 2152 | \\export fn entry() bool { |
| 2300 | \\ return @ptrToInt(&{}) == @ptrToInt(&{}); | 2153 | \\ return @ptrToInt(&{}) == @ptrToInt(&{}); |
| 2301 | \\} | 2154 | \\} |
| 2302 | , | 2155 | , &[_][]const u8{ |
| 2303 | "tmp.zig:2:23: error: pointer to size 0 type has no address", | 2156 | "tmp.zig:2:23: error: pointer to size 0 type has no address", |
| 2304 | ); | 2157 | }); |
| 2305 | | 2158 | |
| 2306 | cases.add( | 2159 | cases.add("@popCount - non-integer", |
| 2307 | "@popCount - non-integer", | | |
| 2308 | \\export fn entry(x: f32) u32 { | 2160 | \\export fn entry(x: f32) u32 { |
| 2309 | \\ return @popCount(f32, x); | 2161 | \\ return @popCount(f32, x); |
| 2310 | \\} | 2162 | \\} |
| 2311 | , | 2163 | , &[_][]const u8{ |
| 2312 | "tmp.zig:2:22: error: expected integer type, found 'f32'", | 2164 | "tmp.zig:2:22: error: expected integer type, found 'f32'", |
| 2313 | ); | 2165 | }); |
| 2314 | | 2166 | |
| 2315 | cases.addCase(x: { | 2167 | cases.addCase(x: { |
| 2316 | const tc = cases.create( | 2168 | const tc = cases.create("wrong same named struct", |
| 2317 | "wrong same named struct", | | |
| 2318 | \\const a = @import("a.zig"); | 2169 | \\const a = @import("a.zig"); |
| 2319 | \\const b = @import("b.zig"); | 2170 | \\const b = @import("b.zig"); |
| 2320 | \\ | 2171 | \\ |
| ... | @@ -2324,12 +2175,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -2324,12 +2175,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2324 | \\} | 2175 | \\} |
| 2325 | \\ | 2176 | \\ |
| 2326 | \\fn bar(x: *b.Foo) void {} | 2177 | \\fn bar(x: *b.Foo) void {} |
| 2327 | , | 2178 | , &[_][]const u8{ |
| 2328 | "tmp.zig:6:10: error: expected type '*b.Foo', found '*a.Foo'", | 2179 | "tmp.zig:6:10: error: expected type '*b.Foo', found '*a.Foo'", |
| 2329 | "tmp.zig:6:10: note: pointer type child 'a.Foo' cannot cast into pointer type child 'b.Foo'", | 2180 | "tmp.zig:6:10: note: pointer type child 'a.Foo' cannot cast into pointer type child 'b.Foo'", |
| 2330 | "a.zig:1:17: note: a.Foo declared here", | 2181 | "a.zig:1:17: note: a.Foo declared here", |
| 2331 | "b.zig:1:17: note: b.Foo declared here", | 2182 | "b.zig:1:17: note: b.Foo declared here", |
| 2332 | ); | 2183 | }); |
| 2333 | | 2184 | |
| 2334 | tc.addSourceFile("a.zig", | 2185 | tc.addSourceFile("a.zig", |
| 2335 | \\pub const Foo = struct { | 2186 | \\pub const Foo = struct { |
| ... | @@ -2346,8 +2197,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -2346,8 +2197,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2346 | break :x tc; | 2197 | break :x tc; |
| 2347 | }); | 2198 | }); |
| 2348 | | 2199 | |
| 2349 | cases.add( | 2200 | cases.add("@floatToInt comptime safety", |
| 2350 | "@floatToInt comptime safety", | | |
| 2351 | \\comptime { | 2201 | \\comptime { |
| 2352 | \\ _ = @floatToInt(i8, @as(f32, -129.1)); | 2202 | \\ _ = @floatToInt(i8, @as(f32, -129.1)); |
| 2353 | \\} | 2203 | \\} |
| ... | @@ -2357,23 +2207,21 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -2357,23 +2207,21 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2357 | \\comptime { | 2207 | \\comptime { |
| 2358 | \\ _ = @floatToInt(u8, @as(f32, 256.1)); | 2208 | \\ _ = @floatToInt(u8, @as(f32, 256.1)); |
| 2359 | \\} | 2209 | \\} |
| 2360 | , | 2210 | , &[_][]const u8{ |
| 2361 | "tmp.zig:2:9: error: integer value '-129' cannot be stored in type 'i8'", | 2211 | "tmp.zig:2:9: error: integer value '-129' cannot be stored in type 'i8'", |
| 2362 | "tmp.zig:5:9: error: integer value '-1' cannot be stored in type 'u8'", | 2212 | "tmp.zig:5:9: error: integer value '-1' cannot be stored in type 'u8'", |
| 2363 | "tmp.zig:8:9: error: integer value '256' cannot be stored in type 'u8'", | 2213 | "tmp.zig:8:9: error: integer value '256' cannot be stored in type 'u8'", |
| 2364 | ); | 2214 | }); |
| 2365 | | 2215 | |
| 2366 | cases.add( | 2216 | cases.add("use c_void as return type of fn ptr", |
| 2367 | "use c_void as return type of fn ptr", | | |
| 2368 | \\export fn entry() void { | 2217 | \\export fn entry() void { |
| 2369 | \\ const a: fn () c_void = undefined; | 2218 | \\ const a: fn () c_void = undefined; |
| 2370 | \\} | 2219 | \\} |
| 2371 | , | 2220 | , &[_][]const u8{ |
| 2372 | "tmp.zig:2:20: error: return type cannot be opaque", | 2221 | "tmp.zig:2:20: error: return type cannot be opaque", |
| 2373 | ); | 2222 | }); |
| 2374 | | 2223 | |
| 2375 | cases.add( | 2224 | cases.add("use implicit casts to assign null to non-nullable pointer", |
| 2376 | "use implicit casts to assign null to non-nullable pointer", | | |
| 2377 | \\export fn entry() void { | 2225 | \\export fn entry() void { |
| 2378 | \\ var x: i32 = 1234; | 2226 | \\ var x: i32 = 1234; |
| 2379 | \\ var p: *i32 = &x; | 2227 | \\ var p: *i32 = &x; |
| ... | @@ -2381,30 +2229,27 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -2381,30 +2229,27 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2381 | \\ pp.* = null; | 2229 | \\ pp.* = null; |
| 2382 | \\ var y = p.*; | 2230 | \\ var y = p.*; |
| 2383 | \\} | 2231 | \\} |
| 2384 | , | 2232 | , &[_][]const u8{ |
| 2385 | "tmp.zig:4:23: error: expected type '*?*i32', found '**i32'", | 2233 | "tmp.zig:4:23: error: expected type '*?*i32', found '**i32'", |
| 2386 | ); | 2234 | }); |
| 2387 | | 2235 | |
| 2388 | cases.add( | 2236 | cases.add("attempted implicit cast from T to [*]const T", |
| 2389 | "attempted implicit cast from T to [*]const T", | | |
| 2390 | \\export fn entry() void { | 2237 | \\export fn entry() void { |
| 2391 | \\ const x: [*]const bool = true; | 2238 | \\ const x: [*]const bool = true; |
| 2392 | \\} | 2239 | \\} |
| 2393 | , | 2240 | , &[_][]const u8{ |
| 2394 | "tmp.zig:2:30: error: expected type '[*]const bool', found 'bool'", | 2241 | "tmp.zig:2:30: error: expected type '[*]const bool', found 'bool'", |
| 2395 | ); | 2242 | }); |
| 2396 | | 2243 | |
| 2397 | cases.add( | 2244 | cases.add("dereference unknown length pointer", |
| 2398 | "dereference unknown length pointer", | | |
| 2399 | \\export fn entry(x: [*]i32) i32 { | 2245 | \\export fn entry(x: [*]i32) i32 { |
| 2400 | \\ return x.*; | 2246 | \\ return x.*; |
| 2401 | \\} | 2247 | \\} |
| 2402 | , | 2248 | , &[_][]const u8{ |
| 2403 | "tmp.zig:2:13: error: index syntax required for unknown-length pointer type '[*]i32'", | 2249 | "tmp.zig:2:13: error: index syntax required for unknown-length pointer type '[*]i32'", |
| 2404 | ); | 2250 | }); |
| 2405 | | 2251 | |
| 2406 | cases.add( | 2252 | cases.add("field access of unknown length pointer", |
| 2407 | "field access of unknown length pointer", | | |
| 2408 | \\const Foo = extern struct { | 2253 | \\const Foo = extern struct { |
| 2409 | \\ a: i32, | 2254 | \\ a: i32, |
| 2410 | \\}; | 2255 | \\}; |
| ... | @@ -2412,19 +2257,17 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -2412,19 +2257,17 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2412 | \\export fn entry(foo: [*]Foo) void { | 2257 | \\export fn entry(foo: [*]Foo) void { |
| 2413 | \\ foo.a += 1; | 2258 | \\ foo.a += 1; |
| 2414 | \\} | 2259 | \\} |
| 2415 | , | 2260 | , &[_][]const u8{ |
| 2416 | "tmp.zig:6:8: error: type '[*]Foo' does not support field access", | 2261 | "tmp.zig:6:8: error: type '[*]Foo' does not support field access", |
| 2417 | ); | 2262 | }); |
| 2418 | | 2263 | |
| 2419 | cases.add( | 2264 | cases.add("unknown length pointer to opaque", |
| 2420 | "unknown length pointer to opaque", | | |
| 2421 | \\export const T = [*]@OpaqueType(); | 2265 | \\export const T = [*]@OpaqueType(); |
| 2422 | , | 2266 | , &[_][]const u8{ |
| 2423 | "tmp.zig:1:21: error: unknown-length pointer to opaque", | 2267 | "tmp.zig:1:21: error: unknown-length pointer to opaque", |
| 2424 | ); | 2268 | }); |
| 2425 | | 2269 | |
| 2426 | cases.add( | 2270 | cases.add("error when evaluating return type", |
| 2427 | "error when evaluating return type", | | |
| 2428 | \\const Foo = struct { | 2271 | \\const Foo = struct { |
| 2429 | \\ map: @as(i32, i32), | 2272 | \\ map: @as(i32, i32), |
| 2430 | \\ | 2273 | \\ |
| ... | @@ -2435,30 +2278,27 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -2435,30 +2278,27 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2435 | \\export fn entry() void { | 2278 | \\export fn entry() void { |
| 2436 | \\ var rule_set = try Foo.init(); | 2279 | \\ var rule_set = try Foo.init(); |
| 2437 | \\} | 2280 | \\} |
| 2438 | , | 2281 | , &[_][]const u8{ |
| 2439 | "tmp.zig:2:10: error: expected type 'i32', found 'type'", | 2282 | "tmp.zig:2:10: error: expected type 'i32', found 'type'", |
| 2440 | ); | 2283 | }); |
| 2441 | | 2284 | |
| 2442 | cases.add( | 2285 | cases.add("slicing single-item pointer", |
| 2443 | "slicing single-item pointer", | | |
| 2444 | \\export fn entry(ptr: *i32) void { | 2286 | \\export fn entry(ptr: *i32) void { |
| 2445 | \\ const slice = ptr[0..2]; | 2287 | \\ const slice = ptr[0..2]; |
| 2446 | \\} | 2288 | \\} |
| 2447 | , | 2289 | , &[_][]const u8{ |
| 2448 | "tmp.zig:2:22: error: slice of single-item pointer", | 2290 | "tmp.zig:2:22: error: slice of single-item pointer", |
| 2449 | ); | 2291 | }); |
| 2450 | | 2292 | |
| 2451 | cases.add( | 2293 | cases.add("indexing single-item pointer", |
| 2452 | "indexing single-item pointer", | | |
| 2453 | \\export fn entry(ptr: *i32) i32 { | 2294 | \\export fn entry(ptr: *i32) i32 { |
| 2454 | \\ return ptr[1]; | 2295 | \\ return ptr[1]; |
| 2455 | \\} | 2296 | \\} |
| 2456 | , | 2297 | , &[_][]const u8{ |
| 2457 | "tmp.zig:2:15: error: index of single-item pointer", | 2298 | "tmp.zig:2:15: error: index of single-item pointer", |
| 2458 | ); | 2299 | }); |
| 2459 | | 2300 | |
| 2460 | cases.add( | 2301 | cases.add("nested error set mismatch", |
| 2461 | "nested error set mismatch", | | |
| 2462 | \\const NextError = error{NextError}; | 2302 | \\const NextError = error{NextError}; |
| 2463 | \\const OtherError = error{OutOfMemory}; | 2303 | \\const OtherError = error{OutOfMemory}; |
| 2464 | \\ | 2304 | \\ |
| ... | @@ -2469,15 +2309,14 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -2469,15 +2309,14 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2469 | \\fn foo() ?OtherError!i32 { | 2309 | \\fn foo() ?OtherError!i32 { |
| 2470 | \\ return null; | 2310 | \\ return null; |
| 2471 | \\} | 2311 | \\} |
| 2472 | , | 2312 | , &[_][]const u8{ |
| 2473 | "tmp.zig:5:34: error: expected type '?NextError!i32', found '?OtherError!i32'", | 2313 | "tmp.zig:5:34: error: expected type '?NextError!i32', found '?OtherError!i32'", |
| 2474 | "tmp.zig:5:34: note: optional type child 'OtherError!i32' cannot cast into optional type child 'NextError!i32'", | 2314 | "tmp.zig:5:34: note: optional type child 'OtherError!i32' cannot cast into optional type child 'NextError!i32'", |
| 2475 | "tmp.zig:5:34: note: error set 'OtherError' cannot cast into error set 'NextError'", | 2315 | "tmp.zig:5:34: note: error set 'OtherError' cannot cast into error set 'NextError'", |
| 2476 | "tmp.zig:2:26: note: 'error.OutOfMemory' not a member of destination error set", | 2316 | "tmp.zig:2:26: note: 'error.OutOfMemory' not a member of destination error set", |
| 2477 | ); | 2317 | }); |
| 2478 | | 2318 | |
| 2479 | cases.add( | 2319 | cases.add("invalid deref on switch target", |
| 2480 | "invalid deref on switch target", | | |
| 2481 | \\comptime { | 2320 | \\comptime { |
| 2482 | \\ var tile = Tile.Empty; | 2321 | \\ var tile = Tile.Empty; |
| 2483 | \\ switch (tile.*) { | 2322 | \\ switch (tile.*) { |
| ... | @@ -2489,19 +2328,17 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -2489,19 +2328,17 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2489 | \\ Empty, | 2328 | \\ Empty, |
| 2490 | \\ Filled, | 2329 | \\ Filled, |
| 2491 | \\}; | 2330 | \\}; |
| 2492 | , | 2331 | , &[_][]const u8{ |
| 2493 | "tmp.zig:3:17: error: attempt to dereference non-pointer type 'Tile'", | 2332 | "tmp.zig:3:17: error: attempt to dereference non-pointer type 'Tile'", |
| 2494 | ); | 2333 | }); |
| 2495 | | 2334 | |
| 2496 | cases.add( | 2335 | cases.add("invalid field access in comptime", |
| 2497 | "invalid field access in comptime", | | |
| 2498 | \\comptime { var x = doesnt_exist.whatever; } | 2336 | \\comptime { var x = doesnt_exist.whatever; } |
| 2499 | , | 2337 | , &[_][]const u8{ |
| 2500 | "tmp.zig:1:20: error: use of undeclared identifier 'doesnt_exist'", | 2338 | "tmp.zig:1:20: error: use of undeclared identifier 'doesnt_exist'", |
| 2501 | ); | 2339 | }); |
| 2502 | | 2340 | |
| 2503 | cases.add( | 2341 | cases.add("suspend inside suspend block", |
| 2504 | "suspend inside suspend block", | | |
| 2505 | \\export fn entry() void { | 2342 | \\export fn entry() void { |
| 2506 | \\ _ = async foo(); | 2343 | \\ _ = async foo(); |
| 2507 | \\} | 2344 | \\} |
| ... | @@ -2511,34 +2348,31 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -2511,34 +2348,31 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2511 | \\ } | 2348 | \\ } |
| 2512 | \\ } | 2349 | \\ } |
| 2513 | \\} | 2350 | \\} |
| 2514 | , | 2351 | , &[_][]const u8{ |
| 2515 | "tmp.zig:6:9: error: cannot suspend inside suspend block", | 2352 | "tmp.zig:6:9: error: cannot suspend inside suspend block", |
| 2516 | "tmp.zig:5:5: note: other suspend block here", | 2353 | "tmp.zig:5:5: note: other suspend block here", |
| 2517 | ); | 2354 | }); |
| 2518 | | 2355 | |
| 2519 | cases.add( | 2356 | cases.add("assign inline fn to non-comptime var", |
| 2520 | "assign inline fn to non-comptime var", | | |
| 2521 | \\export fn entry() void { | 2357 | \\export fn entry() void { |
| 2522 | \\ var a = b; | 2358 | \\ var a = b; |
| 2523 | \\} | 2359 | \\} |
| 2524 | \\inline fn b() void { } | 2360 | \\inline fn b() void { } |
| 2525 | , | 2361 | , &[_][]const u8{ |
| 2526 | "tmp.zig:2:5: error: functions marked inline must be stored in const or comptime var", | 2362 | "tmp.zig:2:5: error: functions marked inline must be stored in const or comptime var", |
| 2527 | "tmp.zig:4:1: note: declared here", | 2363 | "tmp.zig:4:1: note: declared here", |
| 2528 | ); | 2364 | }); |
| 2529 | | 2365 | |
| 2530 | cases.add( | 2366 | cases.add("wrong type passed to @panic", |
| 2531 | "wrong type passed to @panic", | | |
| 2532 | \\export fn entry() void { | 2367 | \\export fn entry() void { |
| 2533 | \\ var e = error.Foo; | 2368 | \\ var e = error.Foo; |
| 2534 | \\ @panic(e); | 2369 | \\ @panic(e); |
| 2535 | \\} | 2370 | \\} |
| 2536 | , | 2371 | , &[_][]const u8{ |
| 2537 | "tmp.zig:3:12: error: expected type '[]const u8', found 'error{Foo}'", | 2372 | "tmp.zig:3:12: error: expected type '[]const u8', found 'error{Foo}'", |
| 2538 | ); | 2373 | }); |
| 2539 | | 2374 | |
| 2540 | cases.add( | 2375 | cases.add("@tagName used on union with no associated enum tag", |
| 2541 | "@tagName used on union with no associated enum tag", | | |
| 2542 | \\const FloatInt = extern union { | 2376 | \\const FloatInt = extern union { |
| 2543 | \\ Float: f32, | 2377 | \\ Float: f32, |
| 2544 | \\ Int: i32, | 2378 | \\ Int: i32, |
| ... | @@ -2547,54 +2381,49 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -2547,54 +2381,49 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2547 | \\ var fi = FloatInt{.Float = 123.45}; | 2381 | \\ var fi = FloatInt{.Float = 123.45}; |
| 2548 | \\ var tagName = @tagName(fi); | 2382 | \\ var tagName = @tagName(fi); |
| 2549 | \\} | 2383 | \\} |
| 2550 | , | 2384 | , &[_][]const u8{ |
| 2551 | "tmp.zig:7:19: error: union has no associated enum", | 2385 | "tmp.zig:7:19: error: union has no associated enum", |
| 2552 | "tmp.zig:1:18: note: declared here", | 2386 | "tmp.zig:1:18: note: declared here", |
| 2553 | ); | 2387 | }); |
| 2554 | | 2388 | |
| 2555 | cases.add( | 2389 | cases.add("returning error from void async function", |
| 2556 | "returning error from void async function", | | |
| 2557 | \\export fn entry() void { | 2390 | \\export fn entry() void { |
| 2558 | \\ _ = async amain(); | 2391 | \\ _ = async amain(); |
| 2559 | \\} | 2392 | \\} |
| 2560 | \\async fn amain() void { | 2393 | \\async fn amain() void { |
| 2561 | \\ return error.ShouldBeCompileError; | 2394 | \\ return error.ShouldBeCompileError; |
| 2562 | \\} | 2395 | \\} |
| 2563 | , | 2396 | , &[_][]const u8{ |
| 2564 | "tmp.zig:5:17: error: expected type 'void', found 'error{ShouldBeCompileError}'", | 2397 | "tmp.zig:5:17: error: expected type 'void', found 'error{ShouldBeCompileError}'", |
| 2565 | ); | 2398 | }); |
| 2566 | | 2399 | |
| 2567 | cases.add( | 2400 | cases.add("var makes structs required to be comptime known", |
| 2568 | "var makes structs required to be comptime known", | | |
| 2569 | \\export fn entry() void { | 2401 | \\export fn entry() void { |
| 2570 | \\ const S = struct{v: var}; | 2402 | \\ const S = struct{v: var}; |
| 2571 | \\ var s = S{.v=@as(i32, 10)}; | 2403 | \\ var s = S{.v=@as(i32, 10)}; |
| 2572 | \\} | 2404 | \\} |
| 2573 | , | 2405 | , &[_][]const u8{ |
| 2574 | "tmp.zig:3:4: error: variable of type 'S' must be const or comptime", | 2406 | "tmp.zig:3:4: error: variable of type 'S' must be const or comptime", |
| 2575 | ); | 2407 | }); |
| 2576 | | 2408 | |
| 2577 | cases.add( | 2409 | cases.add("@ptrCast discards const qualifier", |
| 2578 | "@ptrCast discards const qualifier", | | |
| 2579 | \\export fn entry() void { | 2410 | \\export fn entry() void { |
| 2580 | \\ const x: i32 = 1234; | 2411 | \\ const x: i32 = 1234; |
| 2581 | \\ const y = @ptrCast(*i32, &x); | 2412 | \\ const y = @ptrCast(*i32, &x); |
| 2582 | \\} | 2413 | \\} |
| 2583 | , | 2414 | , &[_][]const u8{ |
| 2584 | "tmp.zig:3:15: error: cast discards const qualifier", | 2415 | "tmp.zig:3:15: error: cast discards const qualifier", |
| 2585 | ); | 2416 | }); |
| 2586 | | 2417 | |
| 2587 | cases.add( | 2418 | cases.add("comptime slice of undefined pointer non-zero len", |
| 2588 | "comptime slice of undefined pointer non-zero len", | | |
| 2589 | \\export fn entry() void { | 2419 | \\export fn entry() void { |
| 2590 | \\ const slice = @as([*]i32, undefined)[0..1]; | 2420 | \\ const slice = @as([*]i32, undefined)[0..1]; |
| 2591 | \\} | 2421 | \\} |
| 2592 | , | 2422 | , &[_][]const u8{ |
| 2593 | "tmp.zig:2:41: error: non-zero length slice of undefined pointer", | 2423 | "tmp.zig:2:41: error: non-zero length slice of undefined pointer", |
| 2594 | ); | 2424 | }); |
| 2595 | | 2425 | |
| 2596 | cases.add( | 2426 | cases.add("type checking function pointers", |
| 2597 | "type checking function pointers", | | |
| 2598 | \\fn a(b: fn (*const u8) void) void { | 2427 | \\fn a(b: fn (*const u8) void) void { |
| 2599 | \\ b('a'); | 2428 | \\ b('a'); |
| 2600 | \\} | 2429 | \\} |
| ... | @@ -2602,12 +2431,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -2602,12 +2431,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2602 | \\export fn entry() void { | 2431 | \\export fn entry() void { |
| 2603 | \\ a(c); | 2432 | \\ a(c); |
| 2604 | \\} | 2433 | \\} |
| 2605 | , | 2434 | , &[_][]const u8{ |
| 2606 | "tmp.zig:6:7: error: expected type 'fn(*const u8) void', found 'fn(u8) void'", | 2435 | "tmp.zig:6:7: error: expected type 'fn(*const u8) void', found 'fn(u8) void'", |
| 2607 | ); | 2436 | }); |
| 2608 | | 2437 | |
| 2609 | cases.add( | 2438 | cases.add("no else prong on switch on global error set", |
| 2610 | "no else prong on switch on global error set", | | |
| 2611 | \\export fn entry() void { | 2439 | \\export fn entry() void { |
| 2612 | \\ foo(error.A); | 2440 | \\ foo(error.A); |
| 2613 | \\} | 2441 | \\} |
| ... | @@ -2616,23 +2444,21 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -2616,23 +2444,21 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2616 | \\ error.A => {}, | 2444 | \\ error.A => {}, |
| 2617 | \\ } | 2445 | \\ } |
| 2618 | \\} | 2446 | \\} |
| 2619 | , | 2447 | , &[_][]const u8{ |
| 2620 | "tmp.zig:5:5: error: else prong required when switching on type 'anyerror'", | 2448 | "tmp.zig:5:5: error: else prong required when switching on type 'anyerror'", |
| 2621 | ); | 2449 | }); |
| 2622 | | 2450 | |
| 2623 | cases.add( | 2451 | cases.add("inferred error set with no returned error", |
| 2624 | "inferred error set with no returned error", | | |
| 2625 | \\export fn entry() void { | 2452 | \\export fn entry() void { |
| 2626 | \\ foo() catch unreachable; | 2453 | \\ foo() catch unreachable; |
| 2627 | \\} | 2454 | \\} |
| 2628 | \\fn foo() !void { | 2455 | \\fn foo() !void { |
| 2629 | \\} | 2456 | \\} |
| 2630 | , | 2457 | , &[_][]const u8{ |
| 2631 | "tmp.zig:4:11: error: function with inferred error set must return at least one possible error", | 2458 | "tmp.zig:4:11: error: function with inferred error set must return at least one possible error", |
| 2632 | ); | 2459 | }); |
| 2633 | | 2460 | |
| 2634 | cases.add( | 2461 | cases.add("error not handled in switch", |
| 2635 | "error not handled in switch", | | |
| 2636 | \\export fn entry() void { | 2462 | \\export fn entry() void { |
| 2637 | \\ foo(452) catch |err| switch (err) { | 2463 | \\ foo(452) catch |err| switch (err) { |
| 2638 | \\ error.Foo => {}, | 2464 | \\ error.Foo => {}, |
| ... | @@ -2646,13 +2472,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -2646,13 +2472,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2646 | \\ else => {}, | 2472 | \\ else => {}, |
| 2647 | \\ } | 2473 | \\ } |
| 2648 | \\} | 2474 | \\} |
| 2649 | , | 2475 | , &[_][]const u8{ |
| 2650 | "tmp.zig:2:26: error: error.Baz not handled in switch", | 2476 | "tmp.zig:2:26: error: error.Baz not handled in switch", |
| 2651 | "tmp.zig:2:26: error: error.Bar not handled in switch", | 2477 | "tmp.zig:2:26: error: error.Bar not handled in switch", |
| 2652 | ); | 2478 | }); |
| 2653 | | 2479 | |
| 2654 | cases.add( | 2480 | cases.add("duplicate error in switch", |
| 2655 | "duplicate error in switch", | | |
| 2656 | \\export fn entry() void { | 2481 | \\export fn entry() void { |
| 2657 | \\ foo(452) catch |err| switch (err) { | 2482 | \\ foo(452) catch |err| switch (err) { |
| 2658 | \\ error.Foo => {}, | 2483 | \\ error.Foo => {}, |
| ... | @@ -2668,10 +2493,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -2668,10 +2493,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2668 | \\ else => {}, | 2493 | \\ else => {}, |
| 2669 | \\ } | 2494 | \\ } |
| 2670 | \\} | 2495 | \\} |
| 2671 | , | 2496 | , &[_][]const u8{ |
| 2672 | "tmp.zig:5:14: error: duplicate switch value: '@typeOf(foo).ReturnType.ErrorSet.Foo'", | 2497 | "tmp.zig:5:14: error: duplicate switch value: '@typeOf(foo).ReturnType.ErrorSet.Foo'", |
| 2673 | "tmp.zig:3:14: note: other value is here", | 2498 | "tmp.zig:3:14: note: other value is here", |
| 2674 | ); | 2499 | }); |
| 2675 | | 2500 | |
| 2676 | cases.add("invalid cast from integral type to enum", | 2501 | cases.add("invalid cast from integral type to enum", |
| 2677 | \\const E = enum(usize) { One, Two }; | 2502 | \\const E = enum(usize) { One, Two }; |
| ... | @@ -2685,10 +2510,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -2685,10 +2510,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2685 | \\ E.One => {}, | 2510 | \\ E.One => {}, |
| 2686 | \\ } | 2511 | \\ } |
| 2687 | \\} | 2512 | \\} |
| 2688 | , "tmp.zig:9:10: error: expected type 'usize', found 'E'"); | 2513 | , &[_][]const u8{ |
| | 2514 | "tmp.zig:9:10: error: expected type 'usize', found 'E'", |
| | 2515 | }); |
| 2689 | | 2516 | |
| 2690 | cases.add( | 2517 | cases.add("range operator in switch used on error set", |
| 2691 | "range operator in switch used on error set", | | |
| 2692 | \\export fn entry() void { | 2518 | \\export fn entry() void { |
| 2693 | \\ try foo(452) catch |err| switch (err) { | 2519 | \\ try foo(452) catch |err| switch (err) { |
| 2694 | \\ error.A ... error.B => {}, | 2520 | \\ error.A ... error.B => {}, |
| ... | @@ -2702,41 +2528,37 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -2702,41 +2528,37 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2702 | \\ else => {}, | 2528 | \\ else => {}, |
| 2703 | \\ } | 2529 | \\ } |
| 2704 | \\} | 2530 | \\} |
| 2705 | , | 2531 | , &[_][]const u8{ |
| 2706 | "tmp.zig:3:17: error: operator not allowed for errors", | 2532 | "tmp.zig:3:17: error: operator not allowed for errors", |
| 2707 | ); | 2533 | }); |
| 2708 | | 2534 | |
| 2709 | cases.add( | 2535 | cases.add("inferring error set of function pointer", |
| 2710 | "inferring error set of function pointer", | | |
| 2711 | \\comptime { | 2536 | \\comptime { |
| 2712 | \\ const z: ?fn()!void = null; | 2537 | \\ const z: ?fn()!void = null; |
| 2713 | \\} | 2538 | \\} |
| 2714 | , | 2539 | , &[_][]const u8{ |
| 2715 | "tmp.zig:2:15: error: inferring error set of return type valid only for function definitions", | 2540 | "tmp.zig:2:15: error: inferring error set of return type valid only for function definitions", |
| 2716 | ); | 2541 | }); |
| 2717 | | 2542 | |
| 2718 | cases.add( | 2543 | cases.add("access non-existent member of error set", |
| 2719 | "access non-existent member of error set", | | |
| 2720 | \\const Foo = error{A}; | 2544 | \\const Foo = error{A}; |
| 2721 | \\comptime { | 2545 | \\comptime { |
| 2722 | \\ const z = Foo.Bar; | 2546 | \\ const z = Foo.Bar; |
| 2723 | \\} | 2547 | \\} |
| 2724 | , | 2548 | , &[_][]const u8{ |
| 2725 | "tmp.zig:3:18: error: no error named 'Bar' in 'Foo'", | 2549 | "tmp.zig:3:18: error: no error named 'Bar' in 'Foo'", |
| 2726 | ); | 2550 | }); |
| 2727 | | 2551 | |
| 2728 | cases.add( | 2552 | cases.add("error union operator with non error set LHS", |
| 2729 | "error union operator with non error set LHS", | | |
| 2730 | \\comptime { | 2553 | \\comptime { |
| 2731 | \\ const z = i32!i32; | 2554 | \\ const z = i32!i32; |
| 2732 | \\ var x: z = undefined; | 2555 | \\ var x: z = undefined; |
| 2733 | \\} | 2556 | \\} |
| 2734 | , | 2557 | , &[_][]const u8{ |
| 2735 | "tmp.zig:2:15: error: expected error set type, found type 'i32'", | 2558 | "tmp.zig:2:15: error: expected error set type, found type 'i32'", |
| 2736 | ); | 2559 | }); |
| 2737 | | 2560 | |
| 2738 | cases.add( | 2561 | cases.add("error equality but sets have no common members", |
| 2739 | "error equality but sets have no common members", | | |
| 2740 | \\const Set1 = error{A, C}; | 2562 | \\const Set1 = error{A, C}; |
| 2741 | \\const Set2 = error{B, D}; | 2563 | \\const Set2 = error{B, D}; |
| 2742 | \\export fn entry() void { | 2564 | \\export fn entry() void { |
| ... | @@ -2747,33 +2569,30 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -2747,33 +2569,30 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2747 | \\ | 2569 | \\ |
| 2748 | \\ } | 2570 | \\ } |
| 2749 | \\} | 2571 | \\} |
| 2750 | , | 2572 | , &[_][]const u8{ |
| 2751 | "tmp.zig:7:11: error: error sets 'Set1' and 'Set2' have no common errors", | 2573 | "tmp.zig:7:11: error: error sets 'Set1' and 'Set2' have no common errors", |
| 2752 | ); | 2574 | }); |
| 2753 | | 2575 | |
| 2754 | cases.add( | 2576 | cases.add("only equality binary operator allowed for error sets", |
| 2755 | "only equality binary operator allowed for error sets", | | |
| 2756 | \\comptime { | 2577 | \\comptime { |
| 2757 | \\ const z = error.A > error.B; | 2578 | \\ const z = error.A > error.B; |
| 2758 | \\} | 2579 | \\} |
| 2759 | , | 2580 | , &[_][]const u8{ |
| 2760 | "tmp.zig:2:23: error: operator not allowed for errors", | 2581 | "tmp.zig:2:23: error: operator not allowed for errors", |
| 2761 | ); | 2582 | }); |
| 2762 | | 2583 | |
| 2763 | cases.add( | 2584 | cases.add("explicit error set cast known at comptime violates error sets", |
| 2764 | "explicit error set cast known at comptime violates error sets", | | |
| 2765 | \\const Set1 = error {A, B}; | 2585 | \\const Set1 = error {A, B}; |
| 2766 | \\const Set2 = error {A, C}; | 2586 | \\const Set2 = error {A, C}; |
| 2767 | \\comptime { | 2587 | \\comptime { |
| 2768 | \\ var x = Set1.B; | 2588 | \\ var x = Set1.B; |
| 2769 | \\ var y = @errSetCast(Set2, x); | 2589 | \\ var y = @errSetCast(Set2, x); |
| 2770 | \\} | 2590 | \\} |
| 2771 | , | 2591 | , &[_][]const u8{ |
| 2772 | "tmp.zig:5:13: error: error.B not a member of error set 'Set2'", | 2592 | "tmp.zig:5:13: error: error.B not a member of error set 'Set2'", |
| 2773 | ); | 2593 | }); |
| 2774 | | 2594 | |
| 2775 | cases.add( | 2595 | cases.add("cast error union of global error set to error union of smaller error set", |
| 2776 | "cast error union of global error set to error union of smaller error set", | | |
| 2777 | \\const SmallErrorSet = error{A}; | 2596 | \\const SmallErrorSet = error{A}; |
| 2778 | \\export fn entry() void { | 2597 | \\export fn entry() void { |
| 2779 | \\ var x: SmallErrorSet!i32 = foo(); | 2598 | \\ var x: SmallErrorSet!i32 = foo(); |
| ... | @@ -2781,14 +2600,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -2781,14 +2600,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2781 | \\fn foo() anyerror!i32 { | 2600 | \\fn foo() anyerror!i32 { |
| 2782 | \\ return error.B; | 2601 | \\ return error.B; |
| 2783 | \\} | 2602 | \\} |
| 2784 | , | 2603 | , &[_][]const u8{ |
| 2785 | "tmp.zig:3:35: error: expected type 'SmallErrorSet!i32', found 'anyerror!i32'", | 2604 | "tmp.zig:3:35: error: expected type 'SmallErrorSet!i32', found 'anyerror!i32'", |
| 2786 | "tmp.zig:3:35: note: error set 'anyerror' cannot cast into error set 'SmallErrorSet'", | 2605 | "tmp.zig:3:35: note: error set 'anyerror' cannot cast into error set 'SmallErrorSet'", |
| 2787 | "tmp.zig:3:35: note: cannot cast global error set into smaller set", | 2606 | "tmp.zig:3:35: note: cannot cast global error set into smaller set", |
| 2788 | ); | 2607 | }); |
| 2789 | | 2608 | |
| 2790 | cases.add( | 2609 | cases.add("cast global error set to error set", |
| 2791 | "cast global error set to error set", | | |
| 2792 | \\const SmallErrorSet = error{A}; | 2610 | \\const SmallErrorSet = error{A}; |
| 2793 | \\export fn entry() void { | 2611 | \\export fn entry() void { |
| 2794 | \\ var x: SmallErrorSet = foo(); | 2612 | \\ var x: SmallErrorSet = foo(); |
| ... | @@ -2796,24 +2614,22 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -2796,24 +2614,22 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2796 | \\fn foo() anyerror { | 2614 | \\fn foo() anyerror { |
| 2797 | \\ return error.B; | 2615 | \\ return error.B; |
| 2798 | \\} | 2616 | \\} |
| 2799 | , | 2617 | , &[_][]const u8{ |
| 2800 | "tmp.zig:3:31: error: expected type 'SmallErrorSet', found 'anyerror'", | 2618 | "tmp.zig:3:31: error: expected type 'SmallErrorSet', found 'anyerror'", |
| 2801 | "tmp.zig:3:31: note: cannot cast global error set into smaller set", | 2619 | "tmp.zig:3:31: note: cannot cast global error set into smaller set", |
| 2802 | ); | 2620 | }); |
| 2803 | cases.add( | 2621 | cases.add("recursive inferred error set", |
| 2804 | "recursive inferred error set", | | |
| 2805 | \\export fn entry() void { | 2622 | \\export fn entry() void { |
| 2806 | \\ foo() catch unreachable; | 2623 | \\ foo() catch unreachable; |
| 2807 | \\} | 2624 | \\} |
| 2808 | \\fn foo() !void { | 2625 | \\fn foo() !void { |
| 2809 | \\ try foo(); | 2626 | \\ try foo(); |
| 2810 | \\} | 2627 | \\} |
| 2811 | , | 2628 | , &[_][]const u8{ |
| 2812 | "tmp.zig:5:5: error: cannot resolve inferred error set '@typeOf(foo).ReturnType.ErrorSet': function 'foo' not fully analyzed yet", | 2629 | "tmp.zig:5:5: error: cannot resolve inferred error set '@typeOf(foo).ReturnType.ErrorSet': function 'foo' not fully analyzed yet", |
| 2813 | ); | 2630 | }); |
| 2814 | | 2631 | |
| 2815 | cases.add( | 2632 | cases.add("implicit cast of error set not a subset", |
| 2816 | "implicit cast of error set not a subset", | | |
| 2817 | \\const Set1 = error{A, B}; | 2633 | \\const Set1 = error{A, B}; |
| 2818 | \\const Set2 = error{A, C}; | 2634 | \\const Set2 = error{A, C}; |
| 2819 | \\export fn entry() void { | 2635 | \\export fn entry() void { |
| ... | @@ -2822,13 +2638,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -2822,13 +2638,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2822 | \\fn foo(set1: Set1) void { | 2638 | \\fn foo(set1: Set1) void { |
| 2823 | \\ var x: Set2 = set1; | 2639 | \\ var x: Set2 = set1; |
| 2824 | \\} | 2640 | \\} |
| 2825 | , | 2641 | , &[_][]const u8{ |
| 2826 | "tmp.zig:7:19: error: expected type 'Set2', found 'Set1'", | 2642 | "tmp.zig:7:19: error: expected type 'Set2', found 'Set1'", |
| 2827 | "tmp.zig:1:23: note: 'error.B' not a member of destination error set", | 2643 | "tmp.zig:1:23: note: 'error.B' not a member of destination error set", |
| 2828 | ); | 2644 | }); |
| 2829 | | 2645 | |
| 2830 | cases.add( | 2646 | cases.add("int to err global invalid number", |
| 2831 | "int to err global invalid number", | | |
| 2832 | \\const Set1 = error{ | 2647 | \\const Set1 = error{ |
| 2833 | \\ A, | 2648 | \\ A, |
| 2834 | \\ B, | 2649 | \\ B, |
| ... | @@ -2837,12 +2652,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -2837,12 +2652,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2837 | \\ var x: u16 = 3; | 2652 | \\ var x: u16 = 3; |
| 2838 | \\ var y = @intToError(x); | 2653 | \\ var y = @intToError(x); |
| 2839 | \\} | 2654 | \\} |
| 2840 | , | 2655 | , &[_][]const u8{ |
| 2841 | "tmp.zig:7:13: error: integer value 3 represents no error", | 2656 | "tmp.zig:7:13: error: integer value 3 represents no error", |
| 2842 | ); | 2657 | }); |
| 2843 | | 2658 | |
| 2844 | cases.add( | 2659 | cases.add("int to err non global invalid number", |
| 2845 | "int to err non global invalid number", | | |
| 2846 | \\const Set1 = error{ | 2660 | \\const Set1 = error{ |
| 2847 | \\ A, | 2661 | \\ A, |
| 2848 | \\ B, | 2662 | \\ B, |
| ... | @@ -2855,21 +2669,19 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -2855,21 +2669,19 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2855 | \\ var x = @errorToInt(Set1.B); | 2669 | \\ var x = @errorToInt(Set1.B); |
| 2856 | \\ var y = @errSetCast(Set2, @intToError(x)); | 2670 | \\ var y = @errSetCast(Set2, @intToError(x)); |
| 2857 | \\} | 2671 | \\} |
| 2858 | , | 2672 | , &[_][]const u8{ |
| 2859 | "tmp.zig:11:13: error: error.B not a member of error set 'Set2'", | 2673 | "tmp.zig:11:13: error: error.B not a member of error set 'Set2'", |
| 2860 | ); | 2674 | }); |
| 2861 | | 2675 | |
| 2862 | cases.add( | 2676 | cases.add("@memberCount of error", |
| 2863 | "@memberCount of error", | | |
| 2864 | \\comptime { | 2677 | \\comptime { |
| 2865 | \\ _ = @memberCount(anyerror); | 2678 | \\ _ = @memberCount(anyerror); |
| 2866 | \\} | 2679 | \\} |
| 2867 | , | 2680 | , &[_][]const u8{ |
| 2868 | "tmp.zig:2:9: error: global error set member count not available at comptime", | 2681 | "tmp.zig:2:9: error: global error set member count not available at comptime", |
| 2869 | ); | 2682 | }); |
| 2870 | | 2683 | |
| 2871 | cases.add( | 2684 | cases.add("duplicate error value in error set", |
| 2872 | "duplicate error value in error set", | | |
| 2873 | \\const Foo = error { | 2685 | \\const Foo = error { |
| 2874 | \\ Bar, | 2686 | \\ Bar, |
| 2875 | \\ Bar, | 2687 | \\ Bar, |
| ... | @@ -2877,32 +2689,29 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -2877,32 +2689,29 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2877 | \\export fn entry() void { | 2689 | \\export fn entry() void { |
| 2878 | \\ const a: Foo = undefined; | 2690 | \\ const a: Foo = undefined; |
| 2879 | \\} | 2691 | \\} |
| 2880 | , | 2692 | , &[_][]const u8{ |
| 2881 | "tmp.zig:3:5: error: duplicate error: 'Bar'", | 2693 | "tmp.zig:3:5: error: duplicate error: 'Bar'", |
| 2882 | "tmp.zig:2:5: note: other error here", | 2694 | "tmp.zig:2:5: note: other error here", |
| 2883 | ); | 2695 | }); |
| 2884 | | 2696 | |
| 2885 | cases.add( | 2697 | cases.add("cast negative integer literal to usize", |
| 2886 | "cast negative integer literal to usize", | | |
| 2887 | \\export fn entry() void { | 2698 | \\export fn entry() void { |
| 2888 | \\ const x = @as(usize, -10); | 2699 | \\ const x = @as(usize, -10); |
| 2889 | \\} | 2700 | \\} |
| 2890 | , | 2701 | , &[_][]const u8{ |
| 2891 | "tmp.zig:2:26: error: cannot cast negative value -10 to unsigned integer type 'usize'", | 2702 | "tmp.zig:2:26: error: cannot cast negative value -10 to unsigned integer type 'usize'", |
| 2892 | ); | 2703 | }); |
| 2893 | | 2704 | |
| 2894 | cases.add( | 2705 | cases.add("use invalid number literal as array index", |
| 2895 | "use invalid number literal as array index", | | |
| 2896 | \\var v = 25; | 2706 | \\var v = 25; |
| 2897 | \\export fn entry() void { | 2707 | \\export fn entry() void { |
| 2898 | \\ var arr: [v]u8 = undefined; | 2708 | \\ var arr: [v]u8 = undefined; |
| 2899 | \\} | 2709 | \\} |
| 2900 | , | 2710 | , &[_][]const u8{ |
| 2901 | "tmp.zig:1:1: error: unable to infer variable type", | 2711 | "tmp.zig:1:1: error: unable to infer variable type", |
| 2902 | ); | 2712 | }); |
| 2903 | | 2713 | |
| 2904 | cases.add( | 2714 | cases.add("duplicate struct field", |
| 2905 | "duplicate struct field", | | |
| 2906 | \\const Foo = struct { | 2715 | \\const Foo = struct { |
| 2907 | \\ Bar: i32, | 2716 | \\ Bar: i32, |
| 2908 | \\ Bar: usize, | 2717 | \\ Bar: usize, |
| ... | @@ -2910,13 +2719,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -2910,13 +2719,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2910 | \\export fn entry() void { | 2719 | \\export fn entry() void { |
| 2911 | \\ const a: Foo = undefined; | 2720 | \\ const a: Foo = undefined; |
| 2912 | \\} | 2721 | \\} |
| 2913 | , | 2722 | , &[_][]const u8{ |
| 2914 | "tmp.zig:3:5: error: duplicate struct field: 'Bar'", | 2723 | "tmp.zig:3:5: error: duplicate struct field: 'Bar'", |
| 2915 | "tmp.zig:2:5: note: other field here", | 2724 | "tmp.zig:2:5: note: other field here", |
| 2916 | ); | 2725 | }); |
| 2917 | | 2726 | |
| 2918 | cases.add( | 2727 | cases.add("duplicate union field", |
| 2919 | "duplicate union field", | | |
| 2920 | \\const Foo = union { | 2728 | \\const Foo = union { |
| 2921 | \\ Bar: i32, | 2729 | \\ Bar: i32, |
| 2922 | \\ Bar: usize, | 2730 | \\ Bar: usize, |
| ... | @@ -2924,13 +2732,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -2924,13 +2732,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2924 | \\export fn entry() void { | 2732 | \\export fn entry() void { |
| 2925 | \\ const a: Foo = undefined; | 2733 | \\ const a: Foo = undefined; |
| 2926 | \\} | 2734 | \\} |
| 2927 | , | 2735 | , &[_][]const u8{ |
| 2928 | "tmp.zig:3:5: error: duplicate union field: 'Bar'", | 2736 | "tmp.zig:3:5: error: duplicate union field: 'Bar'", |
| 2929 | "tmp.zig:2:5: note: other field here", | 2737 | "tmp.zig:2:5: note: other field here", |
| 2930 | ); | 2738 | }); |
| 2931 | | 2739 | |
| 2932 | cases.add( | 2740 | cases.add("duplicate enum field", |
| 2933 | "duplicate enum field", | | |
| 2934 | \\const Foo = enum { | 2741 | \\const Foo = enum { |
| 2935 | \\ Bar, | 2742 | \\ Bar, |
| 2936 | \\ Bar, | 2743 | \\ Bar, |
| ... | @@ -2939,110 +2746,99 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -2939,110 +2746,99 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2939 | \\export fn entry() void { | 2746 | \\export fn entry() void { |
| 2940 | \\ const a: Foo = undefined; | 2747 | \\ const a: Foo = undefined; |
| 2941 | \\} | 2748 | \\} |
| 2942 | , | 2749 | , &[_][]const u8{ |
| 2943 | "tmp.zig:3:5: error: duplicate enum field: 'Bar'", | 2750 | "tmp.zig:3:5: error: duplicate enum field: 'Bar'", |
| 2944 | "tmp.zig:2:5: note: other field here", | 2751 | "tmp.zig:2:5: note: other field here", |
| 2945 | ); | 2752 | }); |
| 2946 | | 2753 | |
| 2947 | cases.add( | 2754 | cases.add("calling function with naked calling convention", |
| 2948 | "calling function with naked calling convention", | | |
| 2949 | \\export fn entry() void { | 2755 | \\export fn entry() void { |
| 2950 | \\ foo(); | 2756 | \\ foo(); |
| 2951 | \\} | 2757 | \\} |
| 2952 | \\nakedcc fn foo() void { } | 2758 | \\nakedcc fn foo() void { } |
| 2953 | , | 2759 | , &[_][]const u8{ |
| 2954 | "tmp.zig:2:5: error: unable to call function with naked calling convention", | 2760 | "tmp.zig:2:5: error: unable to call function with naked calling convention", |
| 2955 | "tmp.zig:4:1: note: declared here", | 2761 | "tmp.zig:4:1: note: declared here", |
| 2956 | ); | 2762 | }); |
| 2957 | | 2763 | |
| 2958 | cases.add( | 2764 | cases.add("function with invalid return type", |
| 2959 | "function with invalid return type", | | |
| 2960 | \\export fn foo() boid {} | 2765 | \\export fn foo() boid {} |
| 2961 | , | 2766 | , &[_][]const u8{ |
| 2962 | "tmp.zig:1:17: error: use of undeclared identifier 'boid'", | 2767 | "tmp.zig:1:17: error: use of undeclared identifier 'boid'", |
| 2963 | ); | 2768 | }); |
| 2964 | | 2769 | |
| 2965 | cases.add( | 2770 | cases.add("function with non-extern non-packed enum parameter", |
| 2966 | "function with non-extern non-packed enum parameter", | | |
| 2967 | \\const Foo = enum { A, B, C }; | 2771 | \\const Foo = enum { A, B, C }; |
| 2968 | \\export fn entry(foo: Foo) void { } | 2772 | \\export fn entry(foo: Foo) void { } |
| 2969 | , | 2773 | , &[_][]const u8{ |
| 2970 | "tmp.zig:2:22: error: parameter of type 'Foo' not allowed in function with calling convention 'ccc'", | 2774 | "tmp.zig:2:22: error: parameter of type 'Foo' not allowed in function with calling convention 'ccc'", |
| 2971 | ); | 2775 | }); |
| 2972 | | 2776 | |
| 2973 | cases.add( | 2777 | cases.add("function with non-extern non-packed struct parameter", |
| 2974 | "function with non-extern non-packed struct parameter", | | |
| 2975 | \\const Foo = struct { | 2778 | \\const Foo = struct { |
| 2976 | \\ A: i32, | 2779 | \\ A: i32, |
| 2977 | \\ B: f32, | 2780 | \\ B: f32, |
| 2978 | \\ C: bool, | 2781 | \\ C: bool, |
| 2979 | \\}; | 2782 | \\}; |
| 2980 | \\export fn entry(foo: Foo) void { } | 2783 | \\export fn entry(foo: Foo) void { } |
| 2981 | , | 2784 | , &[_][]const u8{ |
| 2982 | "tmp.zig:6:22: error: parameter of type 'Foo' not allowed in function with calling convention 'ccc'", | 2785 | "tmp.zig:6:22: error: parameter of type 'Foo' not allowed in function with calling convention 'ccc'", |
| 2983 | ); | 2786 | }); |
| 2984 | | 2787 | |
| 2985 | cases.add( | 2788 | cases.add("function with non-extern non-packed union parameter", |
| 2986 | "function with non-extern non-packed union parameter", | | |
| 2987 | \\const Foo = union { | 2789 | \\const Foo = union { |
| 2988 | \\ A: i32, | 2790 | \\ A: i32, |
| 2989 | \\ B: f32, | 2791 | \\ B: f32, |
| 2990 | \\ C: bool, | 2792 | \\ C: bool, |
| 2991 | \\}; | 2793 | \\}; |
| 2992 | \\export fn entry(foo: Foo) void { } | 2794 | \\export fn entry(foo: Foo) void { } |
| 2993 | , | 2795 | , &[_][]const u8{ |
| 2994 | "tmp.zig:6:22: error: parameter of type 'Foo' not allowed in function with calling convention 'ccc'", | 2796 | "tmp.zig:6:22: error: parameter of type 'Foo' not allowed in function with calling convention 'ccc'", |
| 2995 | ); | 2797 | }); |
| 2996 | | 2798 | |
| 2997 | cases.add( | 2799 | cases.add("switch on enum with 1 field with no prongs", |
| 2998 | "switch on enum with 1 field with no prongs", | | |
| 2999 | \\const Foo = enum { M }; | 2800 | \\const Foo = enum { M }; |
| 3000 | \\ | 2801 | \\ |
| 3001 | \\export fn entry() void { | 2802 | \\export fn entry() void { |
| 3002 | \\ var f = Foo.M; | 2803 | \\ var f = Foo.M; |
| 3003 | \\ switch (f) {} | 2804 | \\ switch (f) {} |
| 3004 | \\} | 2805 | \\} |
| 3005 | , | 2806 | , &[_][]const u8{ |
| 3006 | "tmp.zig:5:5: error: enumeration value 'Foo.M' not handled in switch", | 2807 | "tmp.zig:5:5: error: enumeration value 'Foo.M' not handled in switch", |
| 3007 | ); | 2808 | }); |
| 3008 | | 2809 | |
| 3009 | cases.add( | 2810 | cases.add("shift by negative comptime integer", |
| 3010 | "shift by negative comptime integer", | | |
| 3011 | \\comptime { | 2811 | \\comptime { |
| 3012 | \\ var a = 1 >> -1; | 2812 | \\ var a = 1 >> -1; |
| 3013 | \\} | 2813 | \\} |
| 3014 | , | 2814 | , &[_][]const u8{ |
| 3015 | "tmp.zig:2:18: error: shift by negative value -1", | 2815 | "tmp.zig:2:18: error: shift by negative value -1", |
| 3016 | ); | 2816 | }); |
| 3017 | | 2817 | |
| 3018 | cases.add( | 2818 | cases.add("@panic called at compile time", |
| 3019 | "@panic called at compile time", | | |
| 3020 | \\export fn entry() void { | 2819 | \\export fn entry() void { |
| 3021 | \\ comptime { | 2820 | \\ comptime { |
| 3022 | \\ @panic("aoeu",); | 2821 | \\ @panic("aoeu",); |
| 3023 | \\ } | 2822 | \\ } |
| 3024 | \\} | 2823 | \\} |
| 3025 | , | 2824 | , &[_][]const u8{ |
| 3026 | "tmp.zig:3:9: error: encountered @panic at compile-time", | 2825 | "tmp.zig:3:9: error: encountered @panic at compile-time", |
| 3027 | ); | 2826 | }); |
| 3028 | | 2827 | |
| 3029 | cases.add( | 2828 | cases.add("wrong return type for main", |
| 3030 | "wrong return type for main", | | |
| 3031 | \\pub fn main() f32 { } | 2829 | \\pub fn main() f32 { } |
| 3032 | , | 2830 | , &[_][]const u8{ |
| 3033 | "error: expected return type of main to be 'void', '!void', 'noreturn', 'u8', or '!u8'", | 2831 | "error: expected return type of main to be 'void', '!void', 'noreturn', 'u8', or '!u8'", |
| 3034 | ); | 2832 | }); |
| 3035 | | 2833 | |
| 3036 | cases.add( | 2834 | cases.add("double ?? on main return value", |
| 3037 | "double ?? on main return value", | | |
| 3038 | \\pub fn main() ??void { | 2835 | \\pub fn main() ??void { |
| 3039 | \\} | 2836 | \\} |
| 3040 | , | 2837 | , &[_][]const u8{ |
| 3041 | "error: expected return type of main to be 'void', '!void', 'noreturn', 'u8', or '!u8'", | 2838 | "error: expected return type of main to be 'void', '!void', 'noreturn', 'u8', or '!u8'", |
| 3042 | ); | 2839 | }); |
| 3043 | | 2840 | |
| 3044 | cases.add( | 2841 | cases.add("bad identifier in function with struct defined inside function which references local const", |
| 3045 | "bad identifier in function with struct defined inside function which references local const", | | |
| 3046 | \\export fn entry() void { | 2842 | \\export fn entry() void { |
| 3047 | \\ const BlockKind = u32; | 2843 | \\ const BlockKind = u32; |
| 3048 | \\ | 2844 | \\ |
| ... | @@ -3052,12 +2848,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -3052,12 +2848,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3052 | \\ | 2848 | \\ |
| 3053 | \\ bogus; | 2849 | \\ bogus; |
| 3054 | \\} | 2850 | \\} |
| 3055 | , | 2851 | , &[_][]const u8{ |
| 3056 | "tmp.zig:8:5: error: use of undeclared identifier 'bogus'", | 2852 | "tmp.zig:8:5: error: use of undeclared identifier 'bogus'", |
| 3057 | ); | 2853 | }); |
| 3058 | | 2854 | |
| 3059 | cases.add( | 2855 | cases.add("labeled break not found", |
| 3060 | "labeled break not found", | | |
| 3061 | \\export fn entry() void { | 2856 | \\export fn entry() void { |
| 3062 | \\ blah: while (true) { | 2857 | \\ blah: while (true) { |
| 3063 | \\ while (true) { | 2858 | \\ while (true) { |
| ... | @@ -3065,12 +2860,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -3065,12 +2860,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3065 | \\ } | 2860 | \\ } |
| 3066 | \\ } | 2861 | \\ } |
| 3067 | \\} | 2862 | \\} |
| 3068 | , | 2863 | , &[_][]const u8{ |
| 3069 | "tmp.zig:4:13: error: label not found: 'outer'", | 2864 | "tmp.zig:4:13: error: label not found: 'outer'", |
| 3070 | ); | 2865 | }); |
| 3071 | | 2866 | |
| 3072 | cases.add( | 2867 | cases.add("labeled continue not found", |
| 3073 | "labeled continue not found", | | |
| 3074 | \\export fn entry() void { | 2868 | \\export fn entry() void { |
| 3075 | \\ var i: usize = 0; | 2869 | \\ var i: usize = 0; |
| 3076 | \\ blah: while (i < 10) : (i += 1) { | 2870 | \\ blah: while (i < 10) : (i += 1) { |
| ... | @@ -3079,12 +2873,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -3079,12 +2873,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3079 | \\ } | 2873 | \\ } |
| 3080 | \\ } | 2874 | \\ } |
| 3081 | \\} | 2875 | \\} |
| 3082 | , | 2876 | , &[_][]const u8{ |
| 3083 | "tmp.zig:5:13: error: labeled loop not found: 'outer'", | 2877 | "tmp.zig:5:13: error: labeled loop not found: 'outer'", |
| 3084 | ); | 2878 | }); |
| 3085 | | 2879 | |
| 3086 | cases.add( | 2880 | cases.add("attempt to use 0 bit type in extern fn", |
| 3087 | "attempt to use 0 bit type in extern fn", | | |
| 3088 | \\extern fn foo(ptr: extern fn(*void) void) void; | 2881 | \\extern fn foo(ptr: extern fn(*void) void) void; |
| 3089 | \\ | 2882 | \\ |
| 3090 | \\export fn entry() void { | 2883 | \\export fn entry() void { |
| ... | @@ -3095,476 +2888,431 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -3095,476 +2888,431 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3095 | \\export fn entry2() void { | 2888 | \\export fn entry2() void { |
| 3096 | \\ bar(&{}); | 2889 | \\ bar(&{}); |
| 3097 | \\} | 2890 | \\} |
| 3098 | , | 2891 | , &[_][]const u8{ |
| 3099 | "tmp.zig:1:30: error: parameter of type '*void' has 0 bits; not allowed in function with calling convention 'ccc'", | 2892 | "tmp.zig:1:30: error: parameter of type '*void' has 0 bits; not allowed in function with calling convention 'ccc'", |
| 3100 | "tmp.zig:7:18: error: parameter of type '*void' has 0 bits; not allowed in function with calling convention 'ccc'", | 2893 | "tmp.zig:7:18: error: parameter of type '*void' has 0 bits; not allowed in function with calling convention 'ccc'", |
| 3101 | ); | 2894 | }); |
| 3102 | | 2895 | |
| 3103 | cases.add( | 2896 | cases.add("implicit semicolon - block statement", |
| 3104 | "implicit semicolon - block statement", | | |
| 3105 | \\export fn entry() void { | 2897 | \\export fn entry() void { |
| 3106 | \\ {} | 2898 | \\ {} |
| 3107 | \\ var good = {}; | 2899 | \\ var good = {}; |
| 3108 | \\ ({}) | 2900 | \\ ({}) |
| 3109 | \\ var bad = {}; | 2901 | \\ var bad = {}; |
| 3110 | \\} | 2902 | \\} |
| 3111 | , | 2903 | , &[_][]const u8{ |
| 3112 | "tmp.zig:5:5: error: expected token ';', found 'var'", | 2904 | "tmp.zig:5:5: error: expected token ';', found 'var'", |
| 3113 | ); | 2905 | }); |
| 3114 | | 2906 | |
| 3115 | cases.add( | 2907 | cases.add("implicit semicolon - block expr", |
| 3116 | "implicit semicolon - block expr", | | |
| 3117 | \\export fn entry() void { | 2908 | \\export fn entry() void { |
| 3118 | \\ _ = {}; | 2909 | \\ _ = {}; |
| 3119 | \\ var good = {}; | 2910 | \\ var good = {}; |
| 3120 | \\ _ = {} | 2911 | \\ _ = {} |
| 3121 | \\ var bad = {}; | 2912 | \\ var bad = {}; |
| 3122 | \\} | 2913 | \\} |
| 3123 | , | 2914 | , &[_][]const u8{ |
| 3124 | "tmp.zig:5:5: error: expected token ';', found 'var'", | 2915 | "tmp.zig:5:5: error: expected token ';', found 'var'", |
| 3125 | ); | 2916 | }); |
| 3126 | | 2917 | |
| 3127 | cases.add( | 2918 | cases.add("implicit semicolon - comptime statement", |
| 3128 | "implicit semicolon - comptime statement", | | |
| 3129 | \\export fn entry() void { | 2919 | \\export fn entry() void { |
| 3130 | \\ comptime {} | 2920 | \\ comptime {} |
| 3131 | \\ var good = {}; | 2921 | \\ var good = {}; |
| 3132 | \\ comptime ({}) | 2922 | \\ comptime ({}) |
| 3133 | \\ var bad = {}; | 2923 | \\ var bad = {}; |
| 3134 | \\} | 2924 | \\} |
| 3135 | , | 2925 | , &[_][]const u8{ |
| 3136 | "tmp.zig:5:5: error: expected token ';', found 'var'", | 2926 | "tmp.zig:5:5: error: expected token ';', found 'var'", |
| 3137 | ); | 2927 | }); |
| 3138 | | 2928 | |
| 3139 | cases.add( | 2929 | cases.add("implicit semicolon - comptime expression", |
| 3140 | "implicit semicolon - comptime expression", | | |
| 3141 | \\export fn entry() void { | 2930 | \\export fn entry() void { |
| 3142 | \\ _ = comptime {}; | 2931 | \\ _ = comptime {}; |
| 3143 | \\ var good = {}; | 2932 | \\ var good = {}; |
| 3144 | \\ _ = comptime {} | 2933 | \\ _ = comptime {} |
| 3145 | \\ var bad = {}; | 2934 | \\ var bad = {}; |
| 3146 | \\} | 2935 | \\} |
| 3147 | , | 2936 | , &[_][]const u8{ |
| 3148 | "tmp.zig:5:5: error: expected token ';', found 'var'", | 2937 | "tmp.zig:5:5: error: expected token ';', found 'var'", |
| 3149 | ); | 2938 | }); |
| 3150 | | 2939 | |
| 3151 | cases.add( | 2940 | cases.add("implicit semicolon - defer", |
| 3152 | "implicit semicolon - defer", | | |
| 3153 | \\export fn entry() void { | 2941 | \\export fn entry() void { |
| 3154 | \\ defer {} | 2942 | \\ defer {} |
| 3155 | \\ var good = {}; | 2943 | \\ var good = {}; |
| 3156 | \\ defer ({}) | 2944 | \\ defer ({}) |
| 3157 | \\ var bad = {}; | 2945 | \\ var bad = {}; |
| 3158 | \\} | 2946 | \\} |
| 3159 | , | 2947 | , &[_][]const u8{ |
| 3160 | "tmp.zig:5:5: error: expected token ';', found 'var'", | 2948 | "tmp.zig:5:5: error: expected token ';', found 'var'", |
| 3161 | ); | 2949 | }); |
| 3162 | | 2950 | |
| 3163 | cases.add( | 2951 | cases.add("implicit semicolon - if statement", |
| 3164 | "implicit semicolon - if statement", | | |
| 3165 | \\export fn entry() void { | 2952 | \\export fn entry() void { |
| 3166 | \\ if(true) {} | 2953 | \\ if(true) {} |
| 3167 | \\ var good = {}; | 2954 | \\ var good = {}; |
| 3168 | \\ if(true) ({}) | 2955 | \\ if(true) ({}) |
| 3169 | \\ var bad = {}; | 2956 | \\ var bad = {}; |
| 3170 | \\} | 2957 | \\} |
| 3171 | , | 2958 | , &[_][]const u8{ |
| 3172 | "tmp.zig:5:5: error: expected token ';', found 'var'", | 2959 | "tmp.zig:5:5: error: expected token ';', found 'var'", |
| 3173 | ); | 2960 | }); |
| 3174 | | 2961 | |
| 3175 | cases.add( | 2962 | cases.add("implicit semicolon - if expression", |
| 3176 | "implicit semicolon - if expression", | | |
| 3177 | \\export fn entry() void { | 2963 | \\export fn entry() void { |
| 3178 | \\ _ = if(true) {}; | 2964 | \\ _ = if(true) {}; |
| 3179 | \\ var good = {}; | 2965 | \\ var good = {}; |
| 3180 | \\ _ = if(true) {} | 2966 | \\ _ = if(true) {} |
| 3181 | \\ var bad = {}; | 2967 | \\ var bad = {}; |
| 3182 | \\} | 2968 | \\} |
| 3183 | , | 2969 | , &[_][]const u8{ |
| 3184 | "tmp.zig:5:5: error: expected token ';', found 'var'", | 2970 | "tmp.zig:5:5: error: expected token ';', found 'var'", |
| 3185 | ); | 2971 | }); |
| 3186 | | 2972 | |
| 3187 | cases.add( | 2973 | cases.add("implicit semicolon - if-else statement", |
| 3188 | "implicit semicolon - if-else statement", | | |
| 3189 | \\export fn entry() void { | 2974 | \\export fn entry() void { |
| 3190 | \\ if(true) {} else {} | 2975 | \\ if(true) {} else {} |
| 3191 | \\ var good = {}; | 2976 | \\ var good = {}; |
| 3192 | \\ if(true) ({}) else ({}) | 2977 | \\ if(true) ({}) else ({}) |
| 3193 | \\ var bad = {}; | 2978 | \\ var bad = {}; |
| 3194 | \\} | 2979 | \\} |
| 3195 | , | 2980 | , &[_][]const u8{ |
| 3196 | "tmp.zig:5:5: error: expected token ';', found 'var'", | 2981 | "tmp.zig:5:5: error: expected token ';', found 'var'", |
| 3197 | ); | 2982 | }); |
| 3198 | | 2983 | |
| 3199 | cases.add( | 2984 | cases.add("implicit semicolon - if-else expression", |
| 3200 | "implicit semicolon - if-else expression", | | |
| 3201 | \\export fn entry() void { | 2985 | \\export fn entry() void { |
| 3202 | \\ _ = if(true) {} else {}; | 2986 | \\ _ = if(true) {} else {}; |
| 3203 | \\ var good = {}; | 2987 | \\ var good = {}; |
| 3204 | \\ _ = if(true) {} else {} | 2988 | \\ _ = if(true) {} else {} |
| 3205 | \\ var bad = {}; | 2989 | \\ var bad = {}; |
| 3206 | \\} | 2990 | \\} |
| 3207 | , | 2991 | , &[_][]const u8{ |
| 3208 | "tmp.zig:5:5: error: expected token ';', found 'var'", | 2992 | "tmp.zig:5:5: error: expected token ';', found 'var'", |
| 3209 | ); | 2993 | }); |
| 3210 | | 2994 | |
| 3211 | cases.add( | 2995 | cases.add("implicit semicolon - if-else-if statement", |
| 3212 | "implicit semicolon - if-else-if statement", | | |
| 3213 | \\export fn entry() void { | 2996 | \\export fn entry() void { |
| 3214 | \\ if(true) {} else if(true) {} | 2997 | \\ if(true) {} else if(true) {} |
| 3215 | \\ var good = {}; | 2998 | \\ var good = {}; |
| 3216 | \\ if(true) ({}) else if(true) ({}) | 2999 | \\ if(true) ({}) else if(true) ({}) |
| 3217 | \\ var bad = {}; | 3000 | \\ var bad = {}; |
| 3218 | \\} | 3001 | \\} |
| 3219 | , | 3002 | , &[_][]const u8{ |
| 3220 | "tmp.zig:5:5: error: expected token ';', found 'var'", | 3003 | "tmp.zig:5:5: error: expected token ';', found 'var'", |
| 3221 | ); | 3004 | }); |
| 3222 | | 3005 | |
| 3223 | cases.add( | 3006 | cases.add("implicit semicolon - if-else-if expression", |
| 3224 | "implicit semicolon - if-else-if expression", | | |
| 3225 | \\export fn entry() void { | 3007 | \\export fn entry() void { |
| 3226 | \\ _ = if(true) {} else if(true) {}; | 3008 | \\ _ = if(true) {} else if(true) {}; |
| 3227 | \\ var good = {}; | 3009 | \\ var good = {}; |
| 3228 | \\ _ = if(true) {} else if(true) {} | 3010 | \\ _ = if(true) {} else if(true) {} |
| 3229 | \\ var bad = {}; | 3011 | \\ var bad = {}; |
| 3230 | \\} | 3012 | \\} |
| 3231 | , | 3013 | , &[_][]const u8{ |
| 3232 | "tmp.zig:5:5: error: expected token ';', found 'var'", | 3014 | "tmp.zig:5:5: error: expected token ';', found 'var'", |
| 3233 | ); | 3015 | }); |
| 3234 | | 3016 | |
| 3235 | cases.add( | 3017 | cases.add("implicit semicolon - if-else-if-else statement", |
| 3236 | "implicit semicolon - if-else-if-else statement", | | |
| 3237 | \\export fn entry() void { | 3018 | \\export fn entry() void { |
| 3238 | \\ if(true) {} else if(true) {} else {} | 3019 | \\ if(true) {} else if(true) {} else {} |
| 3239 | \\ var good = {}; | 3020 | \\ var good = {}; |
| 3240 | \\ if(true) ({}) else if(true) ({}) else ({}) | 3021 | \\ if(true) ({}) else if(true) ({}) else ({}) |
| 3241 | \\ var bad = {}; | 3022 | \\ var bad = {}; |
| 3242 | \\} | 3023 | \\} |
| 3243 | , | 3024 | , &[_][]const u8{ |
| 3244 | "tmp.zig:5:5: error: expected token ';', found 'var'", | 3025 | "tmp.zig:5:5: error: expected token ';', found 'var'", |
| 3245 | ); | 3026 | }); |
| 3246 | | 3027 | |
| 3247 | cases.add( | 3028 | cases.add("implicit semicolon - if-else-if-else expression", |
| 3248 | "implicit semicolon - if-else-if-else expression", | | |
| 3249 | \\export fn entry() void { | 3029 | \\export fn entry() void { |
| 3250 | \\ _ = if(true) {} else if(true) {} else {}; | 3030 | \\ _ = if(true) {} else if(true) {} else {}; |
| 3251 | \\ var good = {}; | 3031 | \\ var good = {}; |
| 3252 | \\ _ = if(true) {} else if(true) {} else {} | 3032 | \\ _ = if(true) {} else if(true) {} else {} |
| 3253 | \\ var bad = {}; | 3033 | \\ var bad = {}; |
| 3254 | \\} | 3034 | \\} |
| 3255 | , | 3035 | , &[_][]const u8{ |
| 3256 | "tmp.zig:5:5: error: expected token ';', found 'var'", | 3036 | "tmp.zig:5:5: error: expected token ';', found 'var'", |
| 3257 | ); | 3037 | }); |
| 3258 | | 3038 | |
| 3259 | cases.add( | 3039 | cases.add("implicit semicolon - test statement", |
| 3260 | "implicit semicolon - test statement", | | |
| 3261 | \\export fn entry() void { | 3040 | \\export fn entry() void { |
| 3262 | \\ if (foo()) |_| {} | 3041 | \\ if (foo()) |_| {} |
| 3263 | \\ var good = {}; | 3042 | \\ var good = {}; |
| 3264 | \\ if (foo()) |_| ({}) | 3043 | \\ if (foo()) |_| ({}) |
| 3265 | \\ var bad = {}; | 3044 | \\ var bad = {}; |
| 3266 | \\} | 3045 | \\} |
| 3267 | , | 3046 | , &[_][]const u8{ |
| 3268 | "tmp.zig:5:5: error: expected token ';', found 'var'", | 3047 | "tmp.zig:5:5: error: expected token ';', found 'var'", |
| 3269 | ); | 3048 | }); |
| 3270 | | 3049 | |
| 3271 | cases.add( | 3050 | cases.add("implicit semicolon - test expression", |
| 3272 | "implicit semicolon - test expression", | | |
| 3273 | \\export fn entry() void { | 3051 | \\export fn entry() void { |
| 3274 | \\ _ = if (foo()) |_| {}; | 3052 | \\ _ = if (foo()) |_| {}; |
| 3275 | \\ var good = {}; | 3053 | \\ var good = {}; |
| 3276 | \\ _ = if (foo()) |_| {} | 3054 | \\ _ = if (foo()) |_| {} |
| 3277 | \\ var bad = {}; | 3055 | \\ var bad = {}; |
| 3278 | \\} | 3056 | \\} |
| 3279 | , | 3057 | , &[_][]const u8{ |
| 3280 | "tmp.zig:5:5: error: expected token ';', found 'var'", | 3058 | "tmp.zig:5:5: error: expected token ';', found 'var'", |
| 3281 | ); | 3059 | }); |
| 3282 | | 3060 | |
| 3283 | cases.add( | 3061 | cases.add("implicit semicolon - while statement", |
| 3284 | "implicit semicolon - while statement", | | |
| 3285 | \\export fn entry() void { | 3062 | \\export fn entry() void { |
| 3286 | \\ while(true) {} | 3063 | \\ while(true) {} |
| 3287 | \\ var good = {}; | 3064 | \\ var good = {}; |
| 3288 | \\ while(true) ({}) | 3065 | \\ while(true) ({}) |
| 3289 | \\ var bad = {}; | 3066 | \\ var bad = {}; |
| 3290 | \\} | 3067 | \\} |
| 3291 | , | 3068 | , &[_][]const u8{ |
| 3292 | "tmp.zig:5:5: error: expected token ';', found 'var'", | 3069 | "tmp.zig:5:5: error: expected token ';', found 'var'", |
| 3293 | ); | 3070 | }); |
| 3294 | | 3071 | |
| 3295 | cases.add( | 3072 | cases.add("implicit semicolon - while expression", |
| 3296 | "implicit semicolon - while expression", | | |
| 3297 | \\export fn entry() void { | 3073 | \\export fn entry() void { |
| 3298 | \\ _ = while(true) {}; | 3074 | \\ _ = while(true) {}; |
| 3299 | \\ var good = {}; | 3075 | \\ var good = {}; |
| 3300 | \\ _ = while(true) {} | 3076 | \\ _ = while(true) {} |
| 3301 | \\ var bad = {}; | 3077 | \\ var bad = {}; |
| 3302 | \\} | 3078 | \\} |
| 3303 | , | 3079 | , &[_][]const u8{ |
| 3304 | "tmp.zig:5:5: error: expected token ';', found 'var'", | 3080 | "tmp.zig:5:5: error: expected token ';', found 'var'", |
| 3305 | ); | 3081 | }); |
| 3306 | | 3082 | |
| 3307 | cases.add( | 3083 | cases.add("implicit semicolon - while-continue statement", |
| 3308 | "implicit semicolon - while-continue statement", | | |
| 3309 | \\export fn entry() void { | 3084 | \\export fn entry() void { |
| 3310 | \\ while(true):({}) {} | 3085 | \\ while(true):({}) {} |
| 3311 | \\ var good = {}; | 3086 | \\ var good = {}; |
| 3312 | \\ while(true):({}) ({}) | 3087 | \\ while(true):({}) ({}) |
| 3313 | \\ var bad = {}; | 3088 | \\ var bad = {}; |
| 3314 | \\} | 3089 | \\} |
| 3315 | , | 3090 | , &[_][]const u8{ |
| 3316 | "tmp.zig:5:5: error: expected token ';', found 'var'", | 3091 | "tmp.zig:5:5: error: expected token ';', found 'var'", |
| 3317 | ); | 3092 | }); |
| 3318 | | 3093 | |
| 3319 | cases.add( | 3094 | cases.add("implicit semicolon - while-continue expression", |
| 3320 | "implicit semicolon - while-continue expression", | | |
| 3321 | \\export fn entry() void { | 3095 | \\export fn entry() void { |
| 3322 | \\ _ = while(true):({}) {}; | 3096 | \\ _ = while(true):({}) {}; |
| 3323 | \\ var good = {}; | 3097 | \\ var good = {}; |
| 3324 | \\ _ = while(true):({}) {} | 3098 | \\ _ = while(true):({}) {} |
| 3325 | \\ var bad = {}; | 3099 | \\ var bad = {}; |
| 3326 | \\} | 3100 | \\} |
| 3327 | , | 3101 | , &[_][]const u8{ |
| 3328 | "tmp.zig:5:5: error: expected token ';', found 'var'", | 3102 | "tmp.zig:5:5: error: expected token ';', found 'var'", |
| 3329 | ); | 3103 | }); |
| 3330 | | 3104 | |
| 3331 | cases.add( | 3105 | cases.add("implicit semicolon - for statement", |
| 3332 | "implicit semicolon - for statement", | | |
| 3333 | \\export fn entry() void { | 3106 | \\export fn entry() void { |
| 3334 | \\ for(foo()) |_| {} | 3107 | \\ for(foo()) |_| {} |
| 3335 | \\ var good = {}; | 3108 | \\ var good = {}; |
| 3336 | \\ for(foo()) |_| ({}) | 3109 | \\ for(foo()) |_| ({}) |
| 3337 | \\ var bad = {}; | 3110 | \\ var bad = {}; |
| 3338 | \\} | 3111 | \\} |
| 3339 | , | 3112 | , &[_][]const u8{ |
| 3340 | "tmp.zig:5:5: error: expected token ';', found 'var'", | 3113 | "tmp.zig:5:5: error: expected token ';', found 'var'", |
| 3341 | ); | 3114 | }); |
| 3342 | | 3115 | |
| 3343 | cases.add( | 3116 | cases.add("implicit semicolon - for expression", |
| 3344 | "implicit semicolon - for expression", | | |
| 3345 | \\export fn entry() void { | 3117 | \\export fn entry() void { |
| 3346 | \\ _ = for(foo()) |_| {}; | 3118 | \\ _ = for(foo()) |_| {}; |
| 3347 | \\ var good = {}; | 3119 | \\ var good = {}; |
| 3348 | \\ _ = for(foo()) |_| {} | 3120 | \\ _ = for(foo()) |_| {} |
| 3349 | \\ var bad = {}; | 3121 | \\ var bad = {}; |
| 3350 | \\} | 3122 | \\} |
| 3351 | , | 3123 | , &[_][]const u8{ |
| 3352 | "tmp.zig:5:5: error: expected token ';', found 'var'", | 3124 | "tmp.zig:5:5: error: expected token ';', found 'var'", |
| 3353 | ); | 3125 | }); |
| 3354 | | 3126 | |
| 3355 | cases.add( | 3127 | cases.add("multiple function definitions", |
| 3356 | "multiple function definitions", | | |
| 3357 | \\fn a() void {} | 3128 | \\fn a() void {} |
| 3358 | \\fn a() void {} | 3129 | \\fn a() void {} |
| 3359 | \\export fn entry() void { a(); } | 3130 | \\export fn entry() void { a(); } |
| 3360 | , | 3131 | , &[_][]const u8{ |
| 3361 | "tmp.zig:2:1: error: redefinition of 'a'", | 3132 | "tmp.zig:2:1: error: redefinition of 'a'", |
| 3362 | ); | 3133 | }); |
| 3363 | | 3134 | |
| 3364 | cases.add( | 3135 | cases.add("unreachable with return", |
| 3365 | "unreachable with return", | | |
| 3366 | \\fn a() noreturn {return;} | 3136 | \\fn a() noreturn {return;} |
| 3367 | \\export fn entry() void { a(); } | 3137 | \\export fn entry() void { a(); } |
| 3368 | , | 3138 | , &[_][]const u8{ |
| 3369 | "tmp.zig:1:18: error: expected type 'noreturn', found 'void'", | 3139 | "tmp.zig:1:18: error: expected type 'noreturn', found 'void'", |
| 3370 | ); | 3140 | }); |
| 3371 | | 3141 | |
| 3372 | cases.add( | 3142 | cases.add("control reaches end of non-void function", |
| 3373 | "control reaches end of non-void function", | | |
| 3374 | \\fn a() i32 {} | 3143 | \\fn a() i32 {} |
| 3375 | \\export fn entry() void { _ = a(); } | 3144 | \\export fn entry() void { _ = a(); } |
| 3376 | , | 3145 | , &[_][]const u8{ |
| 3377 | "tmp.zig:1:12: error: expected type 'i32', found 'void'", | 3146 | "tmp.zig:1:12: error: expected type 'i32', found 'void'", |
| 3378 | ); | 3147 | }); |
| 3379 | | 3148 | |
| 3380 | cases.add( | 3149 | cases.add("undefined function call", |
| 3381 | "undefined function call", | | |
| 3382 | \\export fn a() void { | 3150 | \\export fn a() void { |
| 3383 | \\ b(); | 3151 | \\ b(); |
| 3384 | \\} | 3152 | \\} |
| 3385 | , | 3153 | , &[_][]const u8{ |
| 3386 | "tmp.zig:2:5: error: use of undeclared identifier 'b'", | 3154 | "tmp.zig:2:5: error: use of undeclared identifier 'b'", |
| 3387 | ); | 3155 | }); |
| 3388 | | 3156 | |
| 3389 | cases.add( | 3157 | cases.add("wrong number of arguments", |
| 3390 | "wrong number of arguments", | | |
| 3391 | \\export fn a() void { | 3158 | \\export fn a() void { |
| 3392 | \\ b(1); | 3159 | \\ b(1); |
| 3393 | \\} | 3160 | \\} |
| 3394 | \\fn b(a: i32, b: i32, c: i32) void { } | 3161 | \\fn b(a: i32, b: i32, c: i32) void { } |
| 3395 | , | 3162 | , &[_][]const u8{ |
| 3396 | "tmp.zig:2:6: error: expected 3 arguments, found 1", | 3163 | "tmp.zig:2:6: error: expected 3 arguments, found 1", |
| 3397 | ); | 3164 | }); |
| 3398 | | 3165 | |
| 3399 | cases.add( | 3166 | cases.add("invalid type", |
| 3400 | "invalid type", | | |
| 3401 | \\fn a() bogus {} | 3167 | \\fn a() bogus {} |
| 3402 | \\export fn entry() void { _ = a(); } | 3168 | \\export fn entry() void { _ = a(); } |
| 3403 | , | 3169 | , &[_][]const u8{ |
| 3404 | "tmp.zig:1:8: error: use of undeclared identifier 'bogus'", | 3170 | "tmp.zig:1:8: error: use of undeclared identifier 'bogus'", |
| 3405 | ); | 3171 | }); |
| 3406 | | 3172 | |
| 3407 | cases.add( | 3173 | cases.add("pointer to noreturn", |
| 3408 | "pointer to noreturn", | | |
| 3409 | \\fn a() *noreturn {} | 3174 | \\fn a() *noreturn {} |
| 3410 | \\export fn entry() void { _ = a(); } | 3175 | \\export fn entry() void { _ = a(); } |
| 3411 | , | 3176 | , &[_][]const u8{ |
| 3412 | "tmp.zig:1:9: error: pointer to noreturn not allowed", | 3177 | "tmp.zig:1:9: error: pointer to noreturn not allowed", |
| 3413 | ); | 3178 | }); |
| 3414 | | 3179 | |
| 3415 | cases.add( | 3180 | cases.add("unreachable code", |
| 3416 | "unreachable code", | | |
| 3417 | \\export fn a() void { | 3181 | \\export fn a() void { |
| 3418 | \\ return; | 3182 | \\ return; |
| 3419 | \\ b(); | 3183 | \\ b(); |
| 3420 | \\} | 3184 | \\} |
| 3421 | \\ | 3185 | \\ |
| 3422 | \\fn b() void {} | 3186 | \\fn b() void {} |
| 3423 | , | 3187 | , &[_][]const u8{ |
| 3424 | "tmp.zig:3:6: error: unreachable code", | 3188 | "tmp.zig:3:6: error: unreachable code", |
| 3425 | ); | 3189 | }); |
| 3426 | | 3190 | |
| 3427 | cases.add( | 3191 | cases.add("bad import", |
| 3428 | "bad import", | | |
| 3429 | \\const bogus = @import("bogus-does-not-exist.zig",); | 3192 | \\const bogus = @import("bogus-does-not-exist.zig",); |
| 3430 | \\export fn entry() void { bogus.bogo(); } | 3193 | \\export fn entry() void { bogus.bogo(); } |
| 3431 | , | 3194 | , &[_][]const u8{ |
| 3432 | "tmp.zig:1:15: error: unable to find 'bogus-does-not-exist.zig'", | 3195 | "tmp.zig:1:15: error: unable to find 'bogus-does-not-exist.zig'", |
| 3433 | ); | 3196 | }); |
| 3434 | | 3197 | |
| 3435 | cases.add( | 3198 | cases.add("undeclared identifier", |
| 3436 | "undeclared identifier", | | |
| 3437 | \\export fn a() void { | 3199 | \\export fn a() void { |
| 3438 | \\ return | 3200 | \\ return |
| 3439 | \\ b + | 3201 | \\ b + |
| 3440 | \\ c; | 3202 | \\ c; |
| 3441 | \\} | 3203 | \\} |
| 3442 | , | 3204 | , &[_][]const u8{ |
| 3443 | "tmp.zig:3:5: error: use of undeclared identifier 'b'", | 3205 | "tmp.zig:3:5: error: use of undeclared identifier 'b'", |
| 3444 | ); | 3206 | }); |
| 3445 | | 3207 | |
| 3446 | cases.add( | 3208 | cases.add("parameter redeclaration", |
| 3447 | "parameter redeclaration", | | |
| 3448 | \\fn f(a : i32, a : i32) void { | 3209 | \\fn f(a : i32, a : i32) void { |
| 3449 | \\} | 3210 | \\} |
| 3450 | \\export fn entry() void { f(1, 2); } | 3211 | \\export fn entry() void { f(1, 2); } |
| 3451 | , | 3212 | , &[_][]const u8{ |
| 3452 | "tmp.zig:1:15: error: redeclaration of variable 'a'", | 3213 | "tmp.zig:1:15: error: redeclaration of variable 'a'", |
| 3453 | ); | 3214 | }); |
| 3454 | | 3215 | |
| 3455 | cases.add( | 3216 | cases.add("local variable redeclaration", |
| 3456 | "local variable redeclaration", | | |
| 3457 | \\export fn f() void { | 3217 | \\export fn f() void { |
| 3458 | \\ const a : i32 = 0; | 3218 | \\ const a : i32 = 0; |
| 3459 | \\ const a = 0; | 3219 | \\ const a = 0; |
| 3460 | \\} | 3220 | \\} |
| 3461 | , | 3221 | , &[_][]const u8{ |
| 3462 | "tmp.zig:3:5: error: redeclaration of variable 'a'", | 3222 | "tmp.zig:3:5: error: redeclaration of variable 'a'", |
| 3463 | ); | 3223 | }); |
| 3464 | | 3224 | |
| 3465 | cases.add( | 3225 | cases.add("local variable redeclares parameter", |
| 3466 | "local variable redeclares parameter", | | |
| 3467 | \\fn f(a : i32) void { | 3226 | \\fn f(a : i32) void { |
| 3468 | \\ const a = 0; | 3227 | \\ const a = 0; |
| 3469 | \\} | 3228 | \\} |
| 3470 | \\export fn entry() void { f(1); } | 3229 | \\export fn entry() void { f(1); } |
| 3471 | , | 3230 | , &[_][]const u8{ |
| 3472 | "tmp.zig:2:5: error: redeclaration of variable 'a'", | 3231 | "tmp.zig:2:5: error: redeclaration of variable 'a'", |
| 3473 | ); | 3232 | }); |
| 3474 | | 3233 | |
| 3475 | cases.add( | 3234 | cases.add("variable has wrong type", |
| 3476 | "variable has wrong type", | | |
| 3477 | \\export fn f() i32 { | 3235 | \\export fn f() i32 { |
| 3478 | \\ const a = "a"; | 3236 | \\ const a = "a"; |
| 3479 | \\ return a; | 3237 | \\ return a; |
| 3480 | \\} | 3238 | \\} |
| 3481 | , | 3239 | , &[_][]const u8{ |
| 3482 | "tmp.zig:3:12: error: expected type 'i32', found '*const [1:0]u8'", | 3240 | "tmp.zig:3:12: error: expected type 'i32', found '*const [1:0]u8'", |
| 3483 | ); | 3241 | }); |
| 3484 | | 3242 | |
| 3485 | cases.add( | 3243 | cases.add("if condition is bool, not int", |
| 3486 | "if condition is bool, not int", | | |
| 3487 | \\export fn f() void { | 3244 | \\export fn f() void { |
| 3488 | \\ if (0) {} | 3245 | \\ if (0) {} |
| 3489 | \\} | 3246 | \\} |
| 3490 | , | 3247 | , &[_][]const u8{ |
| 3491 | "tmp.zig:2:9: error: expected type 'bool', found 'comptime_int'", | 3248 | "tmp.zig:2:9: error: expected type 'bool', found 'comptime_int'", |
| 3492 | ); | 3249 | }); |
| 3493 | | 3250 | |
| 3494 | cases.add( | 3251 | cases.add("assign unreachable", |
| 3495 | "assign unreachable", | | |
| 3496 | \\export fn f() void { | 3252 | \\export fn f() void { |
| 3497 | \\ const a = return; | 3253 | \\ const a = return; |
| 3498 | \\} | 3254 | \\} |
| 3499 | , | 3255 | , &[_][]const u8{ |
| 3500 | "tmp.zig:2:5: error: unreachable code", | 3256 | "tmp.zig:2:5: error: unreachable code", |
| 3501 | ); | 3257 | }); |
| 3502 | | 3258 | |
| 3503 | cases.add( | 3259 | cases.add("unreachable variable", |
| 3504 | "unreachable variable", | | |
| 3505 | \\export fn f() void { | 3260 | \\export fn f() void { |
| 3506 | \\ const a: noreturn = {}; | 3261 | \\ const a: noreturn = {}; |
| 3507 | \\} | 3262 | \\} |
| 3508 | , | 3263 | , &[_][]const u8{ |
| 3509 | "tmp.zig:2:25: error: expected type 'noreturn', found 'void'", | 3264 | "tmp.zig:2:25: error: expected type 'noreturn', found 'void'", |
| 3510 | ); | 3265 | }); |
| 3511 | | 3266 | |
| 3512 | cases.add( | 3267 | cases.add("unreachable parameter", |
| 3513 | "unreachable parameter", | | |
| 3514 | \\fn f(a: noreturn) void {} | 3268 | \\fn f(a: noreturn) void {} |
| 3515 | \\export fn entry() void { f(); } | 3269 | \\export fn entry() void { f(); } |
| 3516 | , | 3270 | , &[_][]const u8{ |
| 3517 | "tmp.zig:1:9: error: parameter of type 'noreturn' not allowed", | 3271 | "tmp.zig:1:9: error: parameter of type 'noreturn' not allowed", |
| 3518 | ); | 3272 | }); |
| 3519 | | 3273 | |
| 3520 | cases.add( | 3274 | cases.add("bad assignment target", |
| 3521 | "bad assignment target", | | |
| 3522 | \\export fn f() void { | 3275 | \\export fn f() void { |
| 3523 | \\ 3 = 3; | 3276 | \\ 3 = 3; |
| 3524 | \\} | 3277 | \\} |
| 3525 | , | 3278 | , &[_][]const u8{ |
| 3526 | "tmp.zig:2:9: error: cannot assign to constant", | 3279 | "tmp.zig:2:9: error: cannot assign to constant", |
| 3527 | ); | 3280 | }); |
| 3528 | | 3281 | |
| 3529 | cases.add( | 3282 | cases.add("assign to constant variable", |
| 3530 | "assign to constant variable", | | |
| 3531 | \\export fn f() void { | 3283 | \\export fn f() void { |
| 3532 | \\ const a = 3; | 3284 | \\ const a = 3; |
| 3533 | \\ a = 4; | 3285 | \\ a = 4; |
| 3534 | \\} | 3286 | \\} |
| 3535 | , | 3287 | , &[_][]const u8{ |
| 3536 | "tmp.zig:3:9: error: cannot assign to constant", | 3288 | "tmp.zig:3:9: error: cannot assign to constant", |
| 3537 | ); | 3289 | }); |
| 3538 | | 3290 | |
| 3539 | cases.add( | 3291 | cases.add("use of undeclared identifier", |
| 3540 | "use of undeclared identifier", | | |
| 3541 | \\export fn f() void { | 3292 | \\export fn f() void { |
| 3542 | \\ b = 3; | 3293 | \\ b = 3; |
| 3543 | \\} | 3294 | \\} |
| 3544 | , | 3295 | , &[_][]const u8{ |
| 3545 | "tmp.zig:2:5: error: use of undeclared identifier 'b'", | 3296 | "tmp.zig:2:5: error: use of undeclared identifier 'b'", |
| 3546 | ); | 3297 | }); |
| 3547 | | 3298 | |
| 3548 | cases.add( | 3299 | cases.add("const is a statement, not an expression", |
| 3549 | "const is a statement, not an expression", | | |
| 3550 | \\export fn f() void { | 3300 | \\export fn f() void { |
| 3551 | \\ (const a = 0); | 3301 | \\ (const a = 0); |
| 3552 | \\} | 3302 | \\} |
| 3553 | , | 3303 | , &[_][]const u8{ |
| 3554 | "tmp.zig:2:6: error: invalid token: 'const'", | 3304 | "tmp.zig:2:6: error: invalid token: 'const'", |
| 3555 | ); | 3305 | }); |
| 3556 | | 3306 | |
| 3557 | cases.add( | 3307 | cases.add("array access of undeclared identifier", |
| 3558 | "array access of undeclared identifier", | | |
| 3559 | \\export fn f() void { | 3308 | \\export fn f() void { |
| 3560 | \\ i[i] = i[i]; | 3309 | \\ i[i] = i[i]; |
| 3561 | \\} | 3310 | \\} |
| 3562 | , | 3311 | , &[_][]const u8{ |
| 3563 | "tmp.zig:2:5: error: use of undeclared identifier 'i'", | 3312 | "tmp.zig:2:5: error: use of undeclared identifier 'i'", |
| 3564 | ); | 3313 | }); |
| 3565 | | 3314 | |
| 3566 | cases.add( | 3315 | cases.add("array access of non array", |
| 3567 | "array access of non array", | | |
| 3568 | \\export fn f() void { | 3316 | \\export fn f() void { |
| 3569 | \\ var bad : bool = undefined; | 3317 | \\ var bad : bool = undefined; |
| 3570 | \\ bad[bad] = bad[bad]; | 3318 | \\ bad[bad] = bad[bad]; |
| ... | @@ -3573,13 +3321,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -3573,13 +3321,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3573 | \\ var bad : bool = undefined; | 3321 | \\ var bad : bool = undefined; |
| 3574 | \\ _ = bad[bad]; | 3322 | \\ _ = bad[bad]; |
| 3575 | \\} | 3323 | \\} |
| 3576 | , | 3324 | , &[_][]const u8{ |
| 3577 | "tmp.zig:3:8: error: array access of non-array type 'bool'", | 3325 | "tmp.zig:3:8: error: array access of non-array type 'bool'", |
| 3578 | "tmp.zig:7:12: error: array access of non-array type 'bool'", | 3326 | "tmp.zig:7:12: error: array access of non-array type 'bool'", |
| 3579 | ); | 3327 | }); |
| 3580 | | 3328 | |
| 3581 | cases.add( | 3329 | cases.add("array access with non integer index", |
| 3582 | "array access with non integer index", | | |
| 3583 | \\export fn f() void { | 3330 | \\export fn f() void { |
| 3584 | \\ var array = "aoeu"; | 3331 | \\ var array = "aoeu"; |
| 3585 | \\ var bad = false; | 3332 | \\ var bad = false; |
| ... | @@ -3590,24 +3337,22 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -3590,24 +3337,22 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3590 | \\ var bad = false; | 3337 | \\ var bad = false; |
| 3591 | \\ _ = array[bad]; | 3338 | \\ _ = array[bad]; |
| 3592 | \\} | 3339 | \\} |
| 3593 | , | 3340 | , &[_][]const u8{ |
| 3594 | "tmp.zig:4:11: error: expected type 'usize', found 'bool'", | 3341 | "tmp.zig:4:11: error: expected type 'usize', found 'bool'", |
| 3595 | "tmp.zig:9:15: error: expected type 'usize', found 'bool'", | 3342 | "tmp.zig:9:15: error: expected type 'usize', found 'bool'", |
| 3596 | ); | 3343 | }); |
| 3597 | | 3344 | |
| 3598 | cases.add( | 3345 | cases.add("write to const global variable", |
| 3599 | "write to const global variable", | | |
| 3600 | \\const x : i32 = 99; | 3346 | \\const x : i32 = 99; |
| 3601 | \\fn f() void { | 3347 | \\fn f() void { |
| 3602 | \\ x = 1; | 3348 | \\ x = 1; |
| 3603 | \\} | 3349 | \\} |
| 3604 | \\export fn entry() void { f(); } | 3350 | \\export fn entry() void { f(); } |
| 3605 | , | 3351 | , &[_][]const u8{ |
| 3606 | "tmp.zig:3:9: error: cannot assign to constant", | 3352 | "tmp.zig:3:9: error: cannot assign to constant", |
| 3607 | ); | 3353 | }); |
| 3608 | | 3354 | |
| 3609 | cases.add( | 3355 | cases.add("missing else clause", |
| 3610 | "missing else clause", | | |
| 3611 | \\fn f(b: bool) void { | 3356 | \\fn f(b: bool) void { |
| 3612 | \\ const x : i32 = if (b) h: { break :h 1; }; | 3357 | \\ const x : i32 = if (b) h: { break :h 1; }; |
| 3613 | \\} | 3358 | \\} |
| ... | @@ -3615,13 +3360,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -3615,13 +3360,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3615 | \\ const y = if (b) h: { break :h @as(i32, 1); }; | 3360 | \\ const y = if (b) h: { break :h @as(i32, 1); }; |
| 3616 | \\} | 3361 | \\} |
| 3617 | \\export fn entry() void { f(true); g(true); } | 3362 | \\export fn entry() void { f(true); g(true); } |
| 3618 | , | 3363 | , &[_][]const u8{ |
| 3619 | "tmp.zig:2:21: error: expected type 'i32', found 'void'", | 3364 | "tmp.zig:2:21: error: expected type 'i32', found 'void'", |
| 3620 | "tmp.zig:5:15: error: incompatible types: 'i32' and 'void'", | 3365 | "tmp.zig:5:15: error: incompatible types: 'i32' and 'void'", |
| 3621 | ); | 3366 | }); |
| 3622 | | 3367 | |
| 3623 | cases.add( | 3368 | cases.add("invalid struct field", |
| 3624 | "invalid struct field", | | |
| 3625 | \\const A = struct { x : i32, }; | 3369 | \\const A = struct { x : i32, }; |
| 3626 | \\export fn f() void { | 3370 | \\export fn f() void { |
| 3627 | \\ var a : A = undefined; | 3371 | \\ var a : A = undefined; |
| ... | @@ -3632,38 +3376,34 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -3632,38 +3376,34 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3632 | \\ var a : A = undefined; | 3376 | \\ var a : A = undefined; |
| 3633 | \\ const y = a.bar; | 3377 | \\ const y = a.bar; |
| 3634 | \\} | 3378 | \\} |
| 3635 | , | 3379 | , &[_][]const u8{ |
| 3636 | "tmp.zig:4:6: error: no member named 'foo' in struct 'A'", | 3380 | "tmp.zig:4:6: error: no member named 'foo' in struct 'A'", |
| 3637 | "tmp.zig:9:16: error: no member named 'bar' in struct 'A'", | 3381 | "tmp.zig:9:16: error: no member named 'bar' in struct 'A'", |
| 3638 | ); | 3382 | }); |
| 3639 | | 3383 | |
| 3640 | cases.add( | 3384 | cases.add("redefinition of struct", |
| 3641 | "redefinition of struct", | | |
| 3642 | \\const A = struct { x : i32, }; | 3385 | \\const A = struct { x : i32, }; |
| 3643 | \\const A = struct { y : i32, }; | 3386 | \\const A = struct { y : i32, }; |
| 3644 | , | 3387 | , &[_][]const u8{ |
| 3645 | "tmp.zig:2:1: error: redefinition of 'A'", | 3388 | "tmp.zig:2:1: error: redefinition of 'A'", |
| 3646 | ); | 3389 | }); |
| 3647 | | 3390 | |
| 3648 | cases.add( | 3391 | cases.add("redefinition of enums", |
| 3649 | "redefinition of enums", | | |
| 3650 | \\const A = enum {}; | 3392 | \\const A = enum {}; |
| 3651 | \\const A = enum {}; | 3393 | \\const A = enum {}; |
| 3652 | , | 3394 | , &[_][]const u8{ |
| 3653 | "tmp.zig:2:1: error: redefinition of 'A'", | 3395 | "tmp.zig:2:1: error: redefinition of 'A'", |
| 3654 | ); | 3396 | }); |
| 3655 | | 3397 | |
| 3656 | cases.add( | 3398 | cases.add("redefinition of global variables", |
| 3657 | "redefinition of global variables", | | |
| 3658 | \\var a : i32 = 1; | 3399 | \\var a : i32 = 1; |
| 3659 | \\var a : i32 = 2; | 3400 | \\var a : i32 = 2; |
| 3660 | , | 3401 | , &[_][]const u8{ |
| 3661 | "tmp.zig:2:1: error: redefinition of 'a'", | 3402 | "tmp.zig:2:1: error: redefinition of 'a'", |
| 3662 | "tmp.zig:1:1: note: previous definition is here", | 3403 | "tmp.zig:1:1: note: previous definition is here", |
| 3663 | ); | 3404 | }); |
| 3664 | | 3405 | |
| 3665 | cases.add( | 3406 | cases.add("duplicate field in struct value expression", |
| 3666 | "duplicate field in struct value expression", | | |
| 3667 | \\const A = struct { | 3407 | \\const A = struct { |
| 3668 | \\ x : i32, | 3408 | \\ x : i32, |
| 3669 | \\ y : i32, | 3409 | \\ y : i32, |
| ... | @@ -3677,12 +3417,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -3677,12 +3417,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3677 | \\ .z = 4, | 3417 | \\ .z = 4, |
| 3678 | \\ }; | 3418 | \\ }; |
| 3679 | \\} | 3419 | \\} |
| 3680 | , | 3420 | , &[_][]const u8{ |
| 3681 | "tmp.zig:11:9: error: duplicate field", | 3421 | "tmp.zig:11:9: error: duplicate field", |
| 3682 | ); | 3422 | }); |
| 3683 | | 3423 | |
| 3684 | cases.add( | 3424 | cases.add("missing field in struct value expression", |
| 3685 | "missing field in struct value expression", | | |
| 3686 | \\const A = struct { | 3425 | \\const A = struct { |
| 3687 | \\ x : i32, | 3426 | \\ x : i32, |
| 3688 | \\ y : i32, | 3427 | \\ y : i32, |
| ... | @@ -3696,12 +3435,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -3696,12 +3435,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3696 | \\ .y = 2, | 3435 | \\ .y = 2, |
| 3697 | \\ }; | 3436 | \\ }; |
| 3698 | \\} | 3437 | \\} |
| 3699 | , | 3438 | , &[_][]const u8{ |
| 3700 | "tmp.zig:9:17: error: missing field: 'x'", | 3439 | "tmp.zig:9:17: error: missing field: 'x'", |
| 3701 | ); | 3440 | }); |
| 3702 | | 3441 | |
| 3703 | cases.add( | 3442 | cases.add("invalid field in struct value expression", |
| 3704 | "invalid field in struct value expression", | | |
| 3705 | \\const A = struct { | 3443 | \\const A = struct { |
| 3706 | \\ x : i32, | 3444 | \\ x : i32, |
| 3707 | \\ y : i32, | 3445 | \\ y : i32, |
| ... | @@ -3714,86 +3452,77 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -3714,86 +3452,77 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3714 | \\ .foo = 42, | 3452 | \\ .foo = 42, |
| 3715 | \\ }; | 3453 | \\ }; |
| 3716 | \\} | 3454 | \\} |
| 3717 | , | 3455 | , &[_][]const u8{ |
| 3718 | "tmp.zig:10:9: error: no member named 'foo' in struct 'A'", | 3456 | "tmp.zig:10:9: error: no member named 'foo' in struct 'A'", |
| 3719 | ); | 3457 | }); |
| 3720 | | 3458 | |
| 3721 | cases.add( | 3459 | cases.add("invalid break expression", |
| 3722 | "invalid break expression", | | |
| 3723 | \\export fn f() void { | 3460 | \\export fn f() void { |
| 3724 | \\ break; | 3461 | \\ break; |
| 3725 | \\} | 3462 | \\} |
| 3726 | , | 3463 | , &[_][]const u8{ |
| 3727 | "tmp.zig:2:5: error: break expression outside loop", | 3464 | "tmp.zig:2:5: error: break expression outside loop", |
| 3728 | ); | 3465 | }); |
| 3729 | | 3466 | |
| 3730 | cases.add( | 3467 | cases.add("invalid continue expression", |
| 3731 | "invalid continue expression", | | |
| 3732 | \\export fn f() void { | 3468 | \\export fn f() void { |
| 3733 | \\ continue; | 3469 | \\ continue; |
| 3734 | \\} | 3470 | \\} |
| 3735 | , | 3471 | , &[_][]const u8{ |
| 3736 | "tmp.zig:2:5: error: continue expression outside loop", | 3472 | "tmp.zig:2:5: error: continue expression outside loop", |
| 3737 | ); | 3473 | }); |
| 3738 | | 3474 | |
| 3739 | cases.add( | 3475 | cases.add("invalid maybe type", |
| 3740 | "invalid maybe type", | | |
| 3741 | \\export fn f() void { | 3476 | \\export fn f() void { |
| 3742 | \\ if (true) |x| { } | 3477 | \\ if (true) |x| { } |
| 3743 | \\} | 3478 | \\} |
| 3744 | , | 3479 | , &[_][]const u8{ |
| 3745 | "tmp.zig:2:9: error: expected optional type, found 'bool'", | 3480 | "tmp.zig:2:9: error: expected optional type, found 'bool'", |
| 3746 | ); | 3481 | }); |
| 3747 | | 3482 | |
| 3748 | cases.add( | 3483 | cases.add("cast unreachable", |
| 3749 | "cast unreachable", | | |
| 3750 | \\fn f() i32 { | 3484 | \\fn f() i32 { |
| 3751 | \\ return @as(i32, return 1); | 3485 | \\ return @as(i32, return 1); |
| 3752 | \\} | 3486 | \\} |
| 3753 | \\export fn entry() void { _ = f(); } | 3487 | \\export fn entry() void { _ = f(); } |
| 3754 | , | 3488 | , &[_][]const u8{ |
| 3755 | "tmp.zig:2:12: error: unreachable code", | 3489 | "tmp.zig:2:12: error: unreachable code", |
| 3756 | ); | 3490 | }); |
| 3757 | | 3491 | |
| 3758 | cases.add( | 3492 | cases.add("invalid builtin fn", |
| 3759 | "invalid builtin fn", | | |
| 3760 | \\fn f() @bogus(foo) { | 3493 | \\fn f() @bogus(foo) { |
| 3761 | \\} | 3494 | \\} |
| 3762 | \\export fn entry() void { _ = f(); } | 3495 | \\export fn entry() void { _ = f(); } |
| 3763 | , | 3496 | , &[_][]const u8{ |
| 3764 | "tmp.zig:1:8: error: invalid builtin function: 'bogus'", | 3497 | "tmp.zig:1:8: error: invalid builtin function: 'bogus'", |
| 3765 | ); | 3498 | }); |
| 3766 | | 3499 | |
| 3767 | cases.add( | 3500 | cases.add("noalias on non pointer param", |
| 3768 | "noalias on non pointer param", | | |
| 3769 | \\fn f(noalias x: i32) void {} | 3501 | \\fn f(noalias x: i32) void {} |
| 3770 | \\export fn entry() void { f(1234); } | 3502 | \\export fn entry() void { f(1234); } |
| 3771 | , | 3503 | , &[_][]const u8{ |
| 3772 | "tmp.zig:1:6: error: noalias on non-pointer parameter", | 3504 | "tmp.zig:1:6: error: noalias on non-pointer parameter", |
| 3773 | ); | 3505 | }); |
| 3774 | | 3506 | |
| 3775 | cases.add( | 3507 | cases.add("struct init syntax for array", |
| 3776 | "struct init syntax for array", | | |
| 3777 | \\const foo = [3]u16{ .x = 1024 }; | 3508 | \\const foo = [3]u16{ .x = 1024 }; |
| 3778 | \\comptime { | 3509 | \\comptime { |
| 3779 | \\ _ = foo; | 3510 | \\ _ = foo; |
| 3780 | \\} | 3511 | \\} |
| 3781 | , | 3512 | , &[_][]const u8{ |
| 3782 | "tmp.zig:1:21: error: type '[3]u16' does not support struct initialization syntax", | 3513 | "tmp.zig:1:21: error: type '[3]u16' does not support struct initialization syntax", |
| 3783 | ); | 3514 | }); |
| 3784 | | 3515 | |
| 3785 | cases.add( | 3516 | cases.add("type variables must be constant", |
| 3786 | "type variables must be constant", | | |
| 3787 | \\var foo = u8; | 3517 | \\var foo = u8; |
| 3788 | \\export fn entry() foo { | 3518 | \\export fn entry() foo { |
| 3789 | \\ return 1; | 3519 | \\ return 1; |
| 3790 | \\} | 3520 | \\} |
| 3791 | , | 3521 | , &[_][]const u8{ |
| 3792 | "tmp.zig:1:1: error: variable of type 'type' must be constant", | 3522 | "tmp.zig:1:1: error: variable of type 'type' must be constant", |
| 3793 | ); | 3523 | }); |
| 3794 | | 3524 | |
| 3795 | cases.add( | 3525 | cases.add("variables shadowing types", |
| 3796 | "variables shadowing types", | | |
| 3797 | \\const Foo = struct {}; | 3526 | \\const Foo = struct {}; |
| 3798 | \\const Bar = struct {}; | 3527 | \\const Bar = struct {}; |
| 3799 | \\ | 3528 | \\ |
| ... | @@ -3804,15 +3533,14 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -3804,15 +3533,14 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3804 | \\export fn entry() void { | 3533 | \\export fn entry() void { |
| 3805 | \\ f(1234); | 3534 | \\ f(1234); |
| 3806 | \\} | 3535 | \\} |
| 3807 | , | 3536 | , &[_][]const u8{ |
| 3808 | "tmp.zig:4:6: error: redefinition of 'Foo'", | 3537 | "tmp.zig:4:6: error: redefinition of 'Foo'", |
| 3809 | "tmp.zig:1:1: note: previous definition is here", | 3538 | "tmp.zig:1:1: note: previous definition is here", |
| 3810 | "tmp.zig:5:5: error: redefinition of 'Bar'", | 3539 | "tmp.zig:5:5: error: redefinition of 'Bar'", |
| 3811 | "tmp.zig:2:1: note: previous definition is here", | 3540 | "tmp.zig:2:1: note: previous definition is here", |
| 3812 | ); | 3541 | }); |
| 3813 | | 3542 | |
| 3814 | cases.add( | 3543 | cases.add("switch expression - missing enumeration prong", |
| 3815 | "switch expression - missing enumeration prong", | | |
| 3816 | \\const Number = enum { | 3544 | \\const Number = enum { |
| 3817 | \\ One, | 3545 | \\ One, |
| 3818 | \\ Two, | 3546 | \\ Two, |
| ... | @@ -3828,12 +3556,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -3828,12 +3556,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3828 | \\} | 3556 | \\} |
| 3829 | \\ | 3557 | \\ |
| 3830 | \\export fn entry() usize { return @sizeOf(@typeOf(f)); } | 3558 | \\export fn entry() usize { return @sizeOf(@typeOf(f)); } |
| 3831 | , | 3559 | , &[_][]const u8{ |
| 3832 | "tmp.zig:8:5: error: enumeration value 'Number.Four' not handled in switch", | 3560 | "tmp.zig:8:5: error: enumeration value 'Number.Four' not handled in switch", |
| 3833 | ); | 3561 | }); |
| 3834 | | 3562 | |
| 3835 | cases.add( | 3563 | cases.add("switch expression - duplicate enumeration prong", |
| 3836 | "switch expression - duplicate enumeration prong", | | |
| 3837 | \\const Number = enum { | 3564 | \\const Number = enum { |
| 3838 | \\ One, | 3565 | \\ One, |
| 3839 | \\ Two, | 3566 | \\ Two, |
| ... | @@ -3851,13 +3578,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -3851,13 +3578,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3851 | \\} | 3578 | \\} |
| 3852 | \\ | 3579 | \\ |
| 3853 | \\export fn entry() usize { return @sizeOf(@typeOf(f)); } | 3580 | \\export fn entry() usize { return @sizeOf(@typeOf(f)); } |
| 3854 | , | 3581 | , &[_][]const u8{ |
| 3855 | "tmp.zig:13:15: error: duplicate switch value", | 3582 | "tmp.zig:13:15: error: duplicate switch value", |
| 3856 | "tmp.zig:10:15: note: other value is here", | 3583 | "tmp.zig:10:15: note: other value is here", |
| 3857 | ); | 3584 | }); |
| 3858 | | 3585 | |
| 3859 | cases.add( | 3586 | cases.add("switch expression - duplicate enumeration prong when else present", |
| 3860 | "switch expression - duplicate enumeration prong when else present", | | |
| 3861 | \\const Number = enum { | 3587 | \\const Number = enum { |
| 3862 | \\ One, | 3588 | \\ One, |
| 3863 | \\ Two, | 3589 | \\ Two, |
| ... | @@ -3876,13 +3602,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -3876,13 +3602,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3876 | \\} | 3602 | \\} |
| 3877 | \\ | 3603 | \\ |
| 3878 | \\export fn entry() usize { return @sizeOf(@typeOf(f)); } | 3604 | \\export fn entry() usize { return @sizeOf(@typeOf(f)); } |
| 3879 | , | 3605 | , &[_][]const u8{ |
| 3880 | "tmp.zig:13:15: error: duplicate switch value", | 3606 | "tmp.zig:13:15: error: duplicate switch value", |
| 3881 | "tmp.zig:10:15: note: other value is here", | 3607 | "tmp.zig:10:15: note: other value is here", |
| 3882 | ); | 3608 | }); |
| 3883 | | 3609 | |
| 3884 | cases.add( | 3610 | cases.add("switch expression - multiple else prongs", |
| 3885 | "switch expression - multiple else prongs", | | |
| 3886 | \\fn f(x: u32) void { | 3611 | \\fn f(x: u32) void { |
| 3887 | \\ const value: bool = switch (x) { | 3612 | \\ const value: bool = switch (x) { |
| 3888 | \\ 1234 => false, | 3613 | \\ 1234 => false, |
| ... | @@ -3893,24 +3618,22 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -3893,24 +3618,22 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3893 | \\export fn entry() void { | 3618 | \\export fn entry() void { |
| 3894 | \\ f(1234); | 3619 | \\ f(1234); |
| 3895 | \\} | 3620 | \\} |
| 3896 | , | 3621 | , &[_][]const u8{ |
| 3897 | "tmp.zig:5:9: error: multiple else prongs in switch expression", | 3622 | "tmp.zig:5:9: error: multiple else prongs in switch expression", |
| 3898 | ); | 3623 | }); |
| 3899 | | 3624 | |
| 3900 | cases.add( | 3625 | cases.add("switch expression - non exhaustive integer prongs", |
| 3901 | "switch expression - non exhaustive integer prongs", | | |
| 3902 | \\fn foo(x: u8) void { | 3626 | \\fn foo(x: u8) void { |
| 3903 | \\ switch (x) { | 3627 | \\ switch (x) { |
| 3904 | \\ 0 => {}, | 3628 | \\ 0 => {}, |
| 3905 | \\ } | 3629 | \\ } |
| 3906 | \\} | 3630 | \\} |
| 3907 | \\export fn entry() usize { return @sizeOf(@typeOf(foo)); } | 3631 | \\export fn entry() usize { return @sizeOf(@typeOf(foo)); } |
| 3908 | , | 3632 | , &[_][]const u8{ |
| 3909 | "tmp.zig:2:5: error: switch must handle all possibilities", | 3633 | "tmp.zig:2:5: error: switch must handle all possibilities", |
| 3910 | ); | 3634 | }); |
| 3911 | | 3635 | |
| 3912 | cases.add( | 3636 | cases.add("switch expression - duplicate or overlapping integer value", |
| 3913 | "switch expression - duplicate or overlapping integer value", | | |
| 3914 | \\fn foo(x: u8) u8 { | 3637 | \\fn foo(x: u8) u8 { |
| 3915 | \\ return switch (x) { | 3638 | \\ return switch (x) { |
| 3916 | \\ 0 ... 100 => @as(u8, 0), | 3639 | \\ 0 ... 100 => @as(u8, 0), |
| ... | @@ -3920,13 +3643,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -3920,13 +3643,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3920 | \\ }; | 3643 | \\ }; |
| 3921 | \\} | 3644 | \\} |
| 3922 | \\export fn entry() usize { return @sizeOf(@typeOf(foo)); } | 3645 | \\export fn entry() usize { return @sizeOf(@typeOf(foo)); } |
| 3923 | , | 3646 | , &[_][]const u8{ |
| 3924 | "tmp.zig:6:9: error: duplicate switch value", | 3647 | "tmp.zig:6:9: error: duplicate switch value", |
| 3925 | "tmp.zig:5:14: note: previous value is here", | 3648 | "tmp.zig:5:14: note: previous value is here", |
| 3926 | ); | 3649 | }); |
| 3927 | | 3650 | |
| 3928 | cases.add( | 3651 | cases.add("switch expression - switch on pointer type with no else", |
| 3929 | "switch expression - switch on pointer type with no else", | | |
| 3930 | \\fn foo(x: *u8) void { | 3652 | \\fn foo(x: *u8) void { |
| 3931 | \\ switch (x) { | 3653 | \\ switch (x) { |
| 3932 | \\ &y => {}, | 3654 | \\ &y => {}, |
| ... | @@ -3934,82 +3656,74 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -3934,82 +3656,74 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3934 | \\} | 3656 | \\} |
| 3935 | \\const y: u8 = 100; | 3657 | \\const y: u8 = 100; |
| 3936 | \\export fn entry() usize { return @sizeOf(@typeOf(foo)); } | 3658 | \\export fn entry() usize { return @sizeOf(@typeOf(foo)); } |
| 3937 | , | 3659 | , &[_][]const u8{ |
| 3938 | "tmp.zig:2:5: error: else prong required when switching on type '*u8'", | 3660 | "tmp.zig:2:5: error: else prong required when switching on type '*u8'", |
| 3939 | ); | 3661 | }); |
| 3940 | | 3662 | |
| 3941 | cases.add( | 3663 | cases.add("global variable initializer must be constant expression", |
| 3942 | "global variable initializer must be constant expression", | | |
| 3943 | \\extern fn foo() i32; | 3664 | \\extern fn foo() i32; |
| 3944 | \\const x = foo(); | 3665 | \\const x = foo(); |
| 3945 | \\export fn entry() i32 { return x; } | 3666 | \\export fn entry() i32 { return x; } |
| 3946 | , | 3667 | , &[_][]const u8{ |
| 3947 | "tmp.zig:2:11: error: unable to evaluate constant expression", | 3668 | "tmp.zig:2:11: error: unable to evaluate constant expression", |
| 3948 | ); | 3669 | }); |
| 3949 | | 3670 | |
| 3950 | cases.add( | 3671 | cases.add("array concatenation with wrong type", |
| 3951 | "array concatenation with wrong type", | | |
| 3952 | \\const src = "aoeu"; | 3672 | \\const src = "aoeu"; |
| 3953 | \\const derp: usize = 1234; | 3673 | \\const derp: usize = 1234; |
| 3954 | \\const a = derp ++ "foo"; | 3674 | \\const a = derp ++ "foo"; |
| 3955 | \\ | 3675 | \\ |
| 3956 | \\export fn entry() usize { return @sizeOf(@typeOf(a)); } | 3676 | \\export fn entry() usize { return @sizeOf(@typeOf(a)); } |
| 3957 | , | 3677 | , &[_][]const u8{ |
| 3958 | "tmp.zig:3:11: error: expected array, found 'usize'", | 3678 | "tmp.zig:3:11: error: expected array, found 'usize'", |
| 3959 | ); | 3679 | }); |
| 3960 | | 3680 | |
| 3961 | cases.add( | 3681 | cases.add("non compile time array concatenation", |
| 3962 | "non compile time array concatenation", | | |
| 3963 | \\fn f() []u8 { | 3682 | \\fn f() []u8 { |
| 3964 | \\ return s ++ "foo"; | 3683 | \\ return s ++ "foo"; |
| 3965 | \\} | 3684 | \\} |
| 3966 | \\var s: [10]u8 = undefined; | 3685 | \\var s: [10]u8 = undefined; |
| 3967 | \\export fn entry() usize { return @sizeOf(@typeOf(f)); } | 3686 | \\export fn entry() usize { return @sizeOf(@typeOf(f)); } |
| 3968 | , | 3687 | , &[_][]const u8{ |
| 3969 | "tmp.zig:2:12: error: unable to evaluate constant expression", | 3688 | "tmp.zig:2:12: error: unable to evaluate constant expression", |
| 3970 | ); | 3689 | }); |
| 3971 | | 3690 | |
| 3972 | cases.add( | 3691 | cases.add("@cImport with bogus include", |
| 3973 | "@cImport with bogus include", | | |
| 3974 | \\const c = @cImport(@cInclude("bogus.h")); | 3692 | \\const c = @cImport(@cInclude("bogus.h")); |
| 3975 | \\export fn entry() usize { return @sizeOf(@typeOf(c.bogo)); } | 3693 | \\export fn entry() usize { return @sizeOf(@typeOf(c.bogo)); } |
| 3976 | , | 3694 | , &[_][]const u8{ |
| 3977 | "tmp.zig:1:11: error: C import failed", | 3695 | "tmp.zig:1:11: error: C import failed", |
| 3978 | ".h:1:10: note: 'bogus.h' file not found", | 3696 | ".h:1:10: note: 'bogus.h' file not found", |
| 3979 | ); | 3697 | }); |
| 3980 | | 3698 | |
| 3981 | cases.add( | 3699 | cases.add("address of number literal", |
| 3982 | "address of number literal", | | |
| 3983 | \\const x = 3; | 3700 | \\const x = 3; |
| 3984 | \\const y = &x; | 3701 | \\const y = &x; |
| 3985 | \\fn foo() *const i32 { return y; } | 3702 | \\fn foo() *const i32 { return y; } |
| 3986 | \\export fn entry() usize { return @sizeOf(@typeOf(foo)); } | 3703 | \\export fn entry() usize { return @sizeOf(@typeOf(foo)); } |
| 3987 | , | 3704 | , &[_][]const u8{ |
| 3988 | "tmp.zig:3:30: error: expected type '*const i32', found '*const comptime_int'", | 3705 | "tmp.zig:3:30: error: expected type '*const i32', found '*const comptime_int'", |
| 3989 | ); | 3706 | }); |
| 3990 | | 3707 | |
| 3991 | cases.add( | 3708 | cases.add("integer overflow error", |
| 3992 | "integer overflow error", | | |
| 3993 | \\const x : u8 = 300; | 3709 | \\const x : u8 = 300; |
| 3994 | \\export fn entry() usize { return @sizeOf(@typeOf(x)); } | 3710 | \\export fn entry() usize { return @sizeOf(@typeOf(x)); } |
| 3995 | , | 3711 | , &[_][]const u8{ |
| 3996 | "tmp.zig:1:16: error: integer value 300 cannot be coerced to type 'u8'", | 3712 | "tmp.zig:1:16: error: integer value 300 cannot be coerced to type 'u8'", |
| 3997 | ); | 3713 | }); |
| 3998 | | 3714 | |
| 3999 | cases.add( | 3715 | cases.add("invalid shift amount error", |
| 4000 | "invalid shift amount error", | | |
| 4001 | \\const x : u8 = 2; | 3716 | \\const x : u8 = 2; |
| 4002 | \\fn f() u16 { | 3717 | \\fn f() u16 { |
| 4003 | \\ return x << 8; | 3718 | \\ return x << 8; |
| 4004 | \\} | 3719 | \\} |
| 4005 | \\export fn entry() u16 { return f(); } | 3720 | \\export fn entry() u16 { return f(); } |
| 4006 | , | 3721 | , &[_][]const u8{ |
| 4007 | "tmp.zig:3:14: error: RHS of shift is too large for LHS type", | 3722 | "tmp.zig:3:14: error: RHS of shift is too large for LHS type", |
| 4008 | "tmp.zig:3:17: note: value 8 cannot fit into type u3", | 3723 | "tmp.zig:3:17: note: value 8 cannot fit into type u3", |
| 4009 | ); | 3724 | }); |
| 4010 | | 3725 | |
| 4011 | cases.add( | 3726 | cases.add("missing function call param", |
| 4012 | "missing function call param", | | |
| 4013 | \\const Foo = struct { | 3727 | \\const Foo = struct { |
| 4014 | \\ a: i32, | 3728 | \\ a: i32, |
| 4015 | \\ b: i32, | 3729 | \\ b: i32, |
| ... | @@ -4033,60 +3747,54 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -4033,60 +3747,54 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4033 | \\} | 3747 | \\} |
| 4034 | \\ | 3748 | \\ |
| 4035 | \\export fn entry() usize { return @sizeOf(@typeOf(f)); } | 3749 | \\export fn entry() usize { return @sizeOf(@typeOf(f)); } |
| 4036 | , | 3750 | , &[_][]const u8{ |
| 4037 | "tmp.zig:20:34: error: expected 1 arguments, found 0", | 3751 | "tmp.zig:20:34: error: expected 1 arguments, found 0", |
| 4038 | ); | 3752 | }); |
| 4039 | | 3753 | |
| 4040 | cases.add( | 3754 | cases.add("missing function name", |
| 4041 | "missing function name", | | |
| 4042 | \\fn () void {} | 3755 | \\fn () void {} |
| 4043 | \\export fn entry() usize { return @sizeOf(@typeOf(f)); } | 3756 | \\export fn entry() usize { return @sizeOf(@typeOf(f)); } |
| 4044 | , | 3757 | , &[_][]const u8{ |
| 4045 | "tmp.zig:1:1: error: missing function name", | 3758 | "tmp.zig:1:1: error: missing function name", |
| 4046 | ); | 3759 | }); |
| 4047 | | 3760 | |
| 4048 | cases.add( | 3761 | cases.add("missing param name", |
| 4049 | "missing param name", | | |
| 4050 | \\fn f(i32) void {} | 3762 | \\fn f(i32) void {} |
| 4051 | \\export fn entry() usize { return @sizeOf(@typeOf(f)); } | 3763 | \\export fn entry() usize { return @sizeOf(@typeOf(f)); } |
| 4052 | , | 3764 | , &[_][]const u8{ |
| 4053 | "tmp.zig:1:6: error: missing parameter name", | 3765 | "tmp.zig:1:6: error: missing parameter name", |
| 4054 | ); | 3766 | }); |
| 4055 | | 3767 | |
| 4056 | cases.add( | 3768 | cases.add("wrong function type", |
| 4057 | "wrong function type", | | |
| 4058 | \\const fns = [_]fn() void { a, b, c }; | 3769 | \\const fns = [_]fn() void { a, b, c }; |
| 4059 | \\fn a() i32 {return 0;} | 3770 | \\fn a() i32 {return 0;} |
| 4060 | \\fn b() i32 {return 1;} | 3771 | \\fn b() i32 {return 1;} |
| 4061 | \\fn c() i32 {return 2;} | 3772 | \\fn c() i32 {return 2;} |
| 4062 | \\export fn entry() usize { return @sizeOf(@typeOf(fns)); } | 3773 | \\export fn entry() usize { return @sizeOf(@typeOf(fns)); } |
| 4063 | , | 3774 | , &[_][]const u8{ |
| 4064 | "tmp.zig:1:28: error: expected type 'fn() void', found 'fn() i32'", | 3775 | "tmp.zig:1:28: error: expected type 'fn() void', found 'fn() i32'", |
| 4065 | ); | 3776 | }); |
| 4066 | | 3777 | |
| 4067 | cases.add( | 3778 | cases.add("extern function pointer mismatch", |
| 4068 | "extern function pointer mismatch", | | |
| 4069 | \\const fns = [_](fn(i32)i32) { a, b, c }; | 3779 | \\const fns = [_](fn(i32)i32) { a, b, c }; |
| 4070 | \\pub fn a(x: i32) i32 {return x + 0;} | 3780 | \\pub fn a(x: i32) i32 {return x + 0;} |
| 4071 | \\pub fn b(x: i32) i32 {return x + 1;} | 3781 | \\pub fn b(x: i32) i32 {return x + 1;} |
| 4072 | \\export fn c(x: i32) i32 {return x + 2;} | 3782 | \\export fn c(x: i32) i32 {return x + 2;} |
| 4073 | \\ | 3783 | \\ |
| 4074 | \\export fn entry() usize { return @sizeOf(@typeOf(fns)); } | 3784 | \\export fn entry() usize { return @sizeOf(@typeOf(fns)); } |
| 4075 | , | 3785 | , &[_][]const u8{ |
| 4076 | "tmp.zig:1:37: error: expected type 'fn(i32) i32', found 'extern fn(i32) i32'", | 3786 | "tmp.zig:1:37: error: expected type 'fn(i32) i32', found 'extern fn(i32) i32'", |
| 4077 | ); | 3787 | }); |
| 4078 | | 3788 | |
| 4079 | cases.add( | 3789 | cases.add("colliding invalid top level functions", |
| 4080 | "colliding invalid top level functions", | | |
| 4081 | \\fn func() bogus {} | 3790 | \\fn func() bogus {} |
| 4082 | \\fn func() bogus {} | 3791 | \\fn func() bogus {} |
| 4083 | \\export fn entry() usize { return @sizeOf(@typeOf(func)); } | 3792 | \\export fn entry() usize { return @sizeOf(@typeOf(func)); } |
| 4084 | , | 3793 | , &[_][]const u8{ |
| 4085 | "tmp.zig:2:1: error: redefinition of 'func'", | 3794 | "tmp.zig:2:1: error: redefinition of 'func'", |
| 4086 | ); | 3795 | }); |
| 4087 | | 3796 | |
| 4088 | cases.add( | 3797 | cases.add("non constant expression in array size", |
| 4089 | "non constant expression in array size", | | |
| 4090 | \\const Foo = struct { | 3798 | \\const Foo = struct { |
| 4091 | \\ y: [get()]u8, | 3799 | \\ y: [get()]u8, |
| 4092 | \\}; | 3800 | \\}; |
| ... | @@ -4094,25 +3802,23 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -4094,25 +3802,23 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4094 | \\fn get() usize { return global_var; } | 3802 | \\fn get() usize { return global_var; } |
| 4095 | \\ | 3803 | \\ |
| 4096 | \\export fn entry() usize { return @sizeOf(@typeOf(Foo)); } | 3804 | \\export fn entry() usize { return @sizeOf(@typeOf(Foo)); } |
| 4097 | , | 3805 | , &[_][]const u8{ |
| 4098 | "tmp.zig:5:25: error: unable to evaluate constant expression", | 3806 | "tmp.zig:5:25: error: unable to evaluate constant expression", |
| 4099 | "tmp.zig:2:12: note: referenced here", | 3807 | "tmp.zig:2:12: note: referenced here", |
| 4100 | ); | 3808 | }); |
| 4101 | | 3809 | |
| 4102 | cases.add( | 3810 | cases.add("addition with non numbers", |
| 4103 | "addition with non numbers", | | |
| 4104 | \\const Foo = struct { | 3811 | \\const Foo = struct { |
| 4105 | \\ field: i32, | 3812 | \\ field: i32, |
| 4106 | \\}; | 3813 | \\}; |
| 4107 | \\const x = Foo {.field = 1} + Foo {.field = 2}; | 3814 | \\const x = Foo {.field = 1} + Foo {.field = 2}; |
| 4108 | \\ | 3815 | \\ |
| 4109 | \\export fn entry() usize { return @sizeOf(@typeOf(x)); } | 3816 | \\export fn entry() usize { return @sizeOf(@typeOf(x)); } |
| 4110 | , | 3817 | , &[_][]const u8{ |
| 4111 | "tmp.zig:4:28: error: invalid operands to binary expression: 'Foo' and 'Foo'", | 3818 | "tmp.zig:4:28: error: invalid operands to binary expression: 'Foo' and 'Foo'", |
| 4112 | ); | 3819 | }); |
| 4113 | | 3820 | |
| 4114 | cases.add( | 3821 | cases.add("division by zero", |
| 4115 | "division by zero", | | |
| 4116 | \\const lit_int_x = 1 / 0; | 3822 | \\const lit_int_x = 1 / 0; |
| 4117 | \\const lit_float_x = 1.0 / 0.0; | 3823 | \\const lit_float_x = 1.0 / 0.0; |
| 4118 | \\const int_x = @as(u32, 1) / @as(u32, 0); | 3824 | \\const int_x = @as(u32, 1) / @as(u32, 0); |
| ... | @@ -4122,522 +3828,471 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -4122,522 +3828,471 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4122 | \\export fn entry2() usize { return @sizeOf(@typeOf(lit_float_x)); } | 3828 | \\export fn entry2() usize { return @sizeOf(@typeOf(lit_float_x)); } |
| 4123 | \\export fn entry3() usize { return @sizeOf(@typeOf(int_x)); } | 3829 | \\export fn entry3() usize { return @sizeOf(@typeOf(int_x)); } |
| 4124 | \\export fn entry4() usize { return @sizeOf(@typeOf(float_x)); } | 3830 | \\export fn entry4() usize { return @sizeOf(@typeOf(float_x)); } |
| 4125 | , | 3831 | , &[_][]const u8{ |
| 4126 | "tmp.zig:1:21: error: division by zero", | 3832 | "tmp.zig:1:21: error: division by zero", |
| 4127 | "tmp.zig:2:25: error: division by zero", | 3833 | "tmp.zig:2:25: error: division by zero", |
| 4128 | "tmp.zig:3:27: error: division by zero", | 3834 | "tmp.zig:3:27: error: division by zero", |
| 4129 | "tmp.zig:4:31: error: division by zero", | 3835 | "tmp.zig:4:31: error: division by zero", |
| 4130 | ); | 3836 | }); |
| 4131 | | 3837 | |
| 4132 | cases.add( | 3838 | cases.add("normal string with newline", |
| 4133 | "normal string with newline", | | |
| 4134 | \\const foo = "a | 3839 | \\const foo = "a |
| 4135 | \\b"; | 3840 | \\b"; |
| 4136 | \\ | 3841 | \\ |
| 4137 | \\export fn entry() usize { return @sizeOf(@typeOf(foo)); } | 3842 | \\export fn entry() usize { return @sizeOf(@typeOf(foo)); } |
| 4138 | , | 3843 | , &[_][]const u8{ |
| 4139 | "tmp.zig:1:15: error: newline not allowed in string literal", | 3844 | "tmp.zig:1:15: error: newline not allowed in string literal", |
| 4140 | ); | 3845 | }); |
| 4141 | | 3846 | |
| 4142 | cases.add( | 3847 | cases.add("invalid comparison for function pointers", |
| 4143 | "invalid comparison for function pointers", | | |
| 4144 | \\fn foo() void {} | 3848 | \\fn foo() void {} |
| 4145 | \\const invalid = foo > foo; | 3849 | \\const invalid = foo > foo; |
| 4146 | \\ | 3850 | \\ |
| 4147 | \\export fn entry() usize { return @sizeOf(@typeOf(invalid)); } | 3851 | \\export fn entry() usize { return @sizeOf(@typeOf(invalid)); } |
| 4148 | , | 3852 | , &[_][]const u8{ |
| 4149 | "tmp.zig:2:21: error: operator not allowed for type 'fn() void'", | 3853 | "tmp.zig:2:21: error: operator not allowed for type 'fn() void'", |
| 4150 | ); | 3854 | }); |
| 4151 | | 3855 | |
| 4152 | cases.add( | 3856 | cases.add("generic function instance with non-constant expression", |
| 4153 | "generic function instance with non-constant expression", | | |
| 4154 | \\fn foo(comptime x: i32, y: i32) i32 { return x + y; } | 3857 | \\fn foo(comptime x: i32, y: i32) i32 { return x + y; } |
| 4155 | \\fn test1(a: i32, b: i32) i32 { | 3858 | \\fn test1(a: i32, b: i32) i32 { |
| 4156 | \\ return foo(a, b); | 3859 | \\ return foo(a, b); |
| 4157 | \\} | 3860 | \\} |
| 4158 | \\ | 3861 | \\ |
| 4159 | \\export fn entry() usize { return @sizeOf(@typeOf(test1)); } | 3862 | \\export fn entry() usize { return @sizeOf(@typeOf(test1)); } |
| 4160 | , | 3863 | , &[_][]const u8{ |
| 4161 | "tmp.zig:3:16: error: unable to evaluate constant expression", | 3864 | "tmp.zig:3:16: error: unable to evaluate constant expression", |
| 4162 | ); | 3865 | }); |
| 4163 | | 3866 | |
| 4164 | cases.add( | 3867 | cases.add("assign null to non-optional pointer", |
| 4165 | "assign null to non-optional pointer", | | |
| 4166 | \\const a: *u8 = null; | 3868 | \\const a: *u8 = null; |
| 4167 | \\ | 3869 | \\ |
| 4168 | \\export fn entry() usize { return @sizeOf(@typeOf(a)); } | 3870 | \\export fn entry() usize { return @sizeOf(@typeOf(a)); } |
| 4169 | , | 3871 | , &[_][]const u8{ |
| 4170 | "tmp.zig:1:16: error: expected type '*u8', found '(null)'", | 3872 | "tmp.zig:1:16: error: expected type '*u8', found '(null)'", |
| 4171 | ); | 3873 | }); |
| 4172 | | 3874 | |
| 4173 | cases.add( | 3875 | cases.add("indexing an array of size zero", |
| 4174 | "indexing an array of size zero", | | |
| 4175 | \\const array = [_]u8{}; | 3876 | \\const array = [_]u8{}; |
| 4176 | \\export fn foo() void { | 3877 | \\export fn foo() void { |
| 4177 | \\ const pointer = &array[0]; | 3878 | \\ const pointer = &array[0]; |
| 4178 | \\} | 3879 | \\} |
| 4179 | , | 3880 | , &[_][]const u8{ |
| 4180 | "tmp.zig:3:27: error: index 0 outside array of size 0", | 3881 | "tmp.zig:3:27: error: index 0 outside array of size 0", |
| 4181 | ); | 3882 | }); |
| 4182 | | 3883 | |
| 4183 | cases.add( | 3884 | cases.add("compile time division by zero", |
| 4184 | "compile time division by zero", | | |
| 4185 | \\const y = foo(0); | 3885 | \\const y = foo(0); |
| 4186 | \\fn foo(x: u32) u32 { | 3886 | \\fn foo(x: u32) u32 { |
| 4187 | \\ return 1 / x; | 3887 | \\ return 1 / x; |
| 4188 | \\} | 3888 | \\} |
| 4189 | \\ | 3889 | \\ |
| 4190 | \\export fn entry() usize { return @sizeOf(@typeOf(y)); } | 3890 | \\export fn entry() usize { return @sizeOf(@typeOf(y)); } |
| 4191 | , | 3891 | , &[_][]const u8{ |
| 4192 | "tmp.zig:3:14: error: division by zero", | 3892 | "tmp.zig:3:14: error: division by zero", |
| 4193 | "tmp.zig:1:14: note: referenced here", | 3893 | "tmp.zig:1:14: note: referenced here", |
| 4194 | ); | 3894 | }); |
| 4195 | | 3895 | |
| 4196 | cases.add( | 3896 | cases.add("branch on undefined value", |
| 4197 | "branch on undefined value", | | |
| 4198 | \\const x = if (undefined) true else false; | 3897 | \\const x = if (undefined) true else false; |
| 4199 | \\ | 3898 | \\ |
| 4200 | \\export fn entry() usize { return @sizeOf(@typeOf(x)); } | 3899 | \\export fn entry() usize { return @sizeOf(@typeOf(x)); } |
| 4201 | , | 3900 | , &[_][]const u8{ |
| 4202 | "tmp.zig:1:15: error: use of undefined value here causes undefined behavior", | 3901 | "tmp.zig:1:15: error: use of undefined value here causes undefined behavior", |
| 4203 | ); | 3902 | }); |
| 4204 | | 3903 | |
| 4205 | cases.add( | 3904 | cases.add("div on undefined value", |
| 4206 | "div on undefined value", | | |
| 4207 | \\comptime { | 3905 | \\comptime { |
| 4208 | \\ var a: i64 = undefined; | 3906 | \\ var a: i64 = undefined; |
| 4209 | \\ _ = a / a; | 3907 | \\ _ = a / a; |
| 4210 | \\} | 3908 | \\} |
| 4211 | , | 3909 | , &[_][]const u8{ |
| 4212 | "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", | 3910 | "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", |
| 4213 | ); | 3911 | }); |
| 4214 | | 3912 | |
| 4215 | cases.add( | 3913 | cases.add("div assign on undefined value", |
| 4216 | "div assign on undefined value", | | |
| 4217 | \\comptime { | 3914 | \\comptime { |
| 4218 | \\ var a: i64 = undefined; | 3915 | \\ var a: i64 = undefined; |
| 4219 | \\ a /= a; | 3916 | \\ a /= a; |
| 4220 | \\} | 3917 | \\} |
| 4221 | , | 3918 | , &[_][]const u8{ |
| 4222 | "tmp.zig:3:5: error: use of undefined value here causes undefined behavior", | 3919 | "tmp.zig:3:5: error: use of undefined value here causes undefined behavior", |
| 4223 | ); | 3920 | }); |
| 4224 | | 3921 | |
| 4225 | cases.add( | 3922 | cases.add("mod on undefined value", |
| 4226 | "mod on undefined value", | | |
| 4227 | \\comptime { | 3923 | \\comptime { |
| 4228 | \\ var a: i64 = undefined; | 3924 | \\ var a: i64 = undefined; |
| 4229 | \\ _ = a % a; | 3925 | \\ _ = a % a; |
| 4230 | \\} | 3926 | \\} |
| 4231 | , | 3927 | , &[_][]const u8{ |
| 4232 | "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", | 3928 | "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", |
| 4233 | ); | 3929 | }); |
| 4234 | | 3930 | |
| 4235 | cases.add( | 3931 | cases.add("mod assign on undefined value", |
| 4236 | "mod assign on undefined value", | | |
| 4237 | \\comptime { | 3932 | \\comptime { |
| 4238 | \\ var a: i64 = undefined; | 3933 | \\ var a: i64 = undefined; |
| 4239 | \\ a %= a; | 3934 | \\ a %= a; |
| 4240 | \\} | 3935 | \\} |
| 4241 | , | 3936 | , &[_][]const u8{ |
| 4242 | "tmp.zig:3:5: error: use of undefined value here causes undefined behavior", | 3937 | "tmp.zig:3:5: error: use of undefined value here causes undefined behavior", |
| 4243 | ); | 3938 | }); |
| 4244 | | 3939 | |
| 4245 | cases.add( | 3940 | cases.add("add on undefined value", |
| 4246 | "add on undefined value", | | |
| 4247 | \\comptime { | 3941 | \\comptime { |
| 4248 | \\ var a: i64 = undefined; | 3942 | \\ var a: i64 = undefined; |
| 4249 | \\ _ = a + a; | 3943 | \\ _ = a + a; |
| 4250 | \\} | 3944 | \\} |
| 4251 | , | 3945 | , &[_][]const u8{ |
| 4252 | "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", | 3946 | "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", |
| 4253 | ); | 3947 | }); |
| 4254 | | 3948 | |
| 4255 | cases.add( | 3949 | cases.add("add assign on undefined value", |
| 4256 | "add assign on undefined value", | | |
| 4257 | \\comptime { | 3950 | \\comptime { |
| 4258 | \\ var a: i64 = undefined; | 3951 | \\ var a: i64 = undefined; |
| 4259 | \\ a += a; | 3952 | \\ a += a; |
| 4260 | \\} | 3953 | \\} |
| 4261 | , | 3954 | , &[_][]const u8{ |
| 4262 | "tmp.zig:3:5: error: use of undefined value here causes undefined behavior", | 3955 | "tmp.zig:3:5: error: use of undefined value here causes undefined behavior", |
| 4263 | ); | 3956 | }); |
| 4264 | | 3957 | |
| 4265 | cases.add( | 3958 | cases.add("add wrap on undefined value", |
| 4266 | "add wrap on undefined value", | | |
| 4267 | \\comptime { | 3959 | \\comptime { |
| 4268 | \\ var a: i64 = undefined; | 3960 | \\ var a: i64 = undefined; |
| 4269 | \\ _ = a +% a; | 3961 | \\ _ = a +% a; |
| 4270 | \\} | 3962 | \\} |
| 4271 | , | 3963 | , &[_][]const u8{ |
| 4272 | "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", | 3964 | "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", |
| 4273 | ); | 3965 | }); |
| 4274 | | 3966 | |
| 4275 | cases.add( | 3967 | cases.add("add wrap assign on undefined value", |
| 4276 | "add wrap assign on undefined value", | | |
| 4277 | \\comptime { | 3968 | \\comptime { |
| 4278 | \\ var a: i64 = undefined; | 3969 | \\ var a: i64 = undefined; |
| 4279 | \\ a +%= a; | 3970 | \\ a +%= a; |
| 4280 | \\} | 3971 | \\} |
| 4281 | , | 3972 | , &[_][]const u8{ |
| 4282 | "tmp.zig:3:5: error: use of undefined value here causes undefined behavior", | 3973 | "tmp.zig:3:5: error: use of undefined value here causes undefined behavior", |
| 4283 | ); | 3974 | }); |
| 4284 | | 3975 | |
| 4285 | cases.add( | 3976 | cases.add("sub on undefined value", |
| 4286 | "sub on undefined value", | | |
| 4287 | \\comptime { | 3977 | \\comptime { |
| 4288 | \\ var a: i64 = undefined; | 3978 | \\ var a: i64 = undefined; |
| 4289 | \\ _ = a - a; | 3979 | \\ _ = a - a; |
| 4290 | \\} | 3980 | \\} |
| 4291 | , | 3981 | , &[_][]const u8{ |
| 4292 | "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", | 3982 | "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", |
| 4293 | ); | 3983 | }); |
| 4294 | | 3984 | |
| 4295 | cases.add( | 3985 | cases.add("sub assign on undefined value", |
| 4296 | "sub assign on undefined value", | | |
| 4297 | \\comptime { | 3986 | \\comptime { |
| 4298 | \\ var a: i64 = undefined; | 3987 | \\ var a: i64 = undefined; |
| 4299 | \\ a -= a; | 3988 | \\ a -= a; |
| 4300 | \\} | 3989 | \\} |
| 4301 | , | 3990 | , &[_][]const u8{ |
| 4302 | "tmp.zig:3:5: error: use of undefined value here causes undefined behavior", | 3991 | "tmp.zig:3:5: error: use of undefined value here causes undefined behavior", |
| 4303 | ); | 3992 | }); |
| 4304 | | 3993 | |
| 4305 | cases.add( | 3994 | cases.add("sub wrap on undefined value", |
| 4306 | "sub wrap on undefined value", | | |
| 4307 | \\comptime { | 3995 | \\comptime { |
| 4308 | \\ var a: i64 = undefined; | 3996 | \\ var a: i64 = undefined; |
| 4309 | \\ _ = a -% a; | 3997 | \\ _ = a -% a; |
| 4310 | \\} | 3998 | \\} |
| 4311 | , | 3999 | , &[_][]const u8{ |
| 4312 | "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", | 4000 | "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", |
| 4313 | ); | 4001 | }); |
| 4314 | | 4002 | |
| 4315 | cases.add( | 4003 | cases.add("sub wrap assign on undefined value", |
| 4316 | "sub wrap assign on undefined value", | | |
| 4317 | \\comptime { | 4004 | \\comptime { |
| 4318 | \\ var a: i64 = undefined; | 4005 | \\ var a: i64 = undefined; |
| 4319 | \\ a -%= a; | 4006 | \\ a -%= a; |
| 4320 | \\} | 4007 | \\} |
| 4321 | , | 4008 | , &[_][]const u8{ |
| 4322 | "tmp.zig:3:5: error: use of undefined value here causes undefined behavior", | 4009 | "tmp.zig:3:5: error: use of undefined value here causes undefined behavior", |
| 4323 | ); | 4010 | }); |
| 4324 | | 4011 | |
| 4325 | cases.add( | 4012 | cases.add("mult on undefined value", |
| 4326 | "mult on undefined value", | | |
| 4327 | \\comptime { | 4013 | \\comptime { |
| 4328 | \\ var a: i64 = undefined; | 4014 | \\ var a: i64 = undefined; |
| 4329 | \\ _ = a * a; | 4015 | \\ _ = a * a; |
| 4330 | \\} | 4016 | \\} |
| 4331 | , | 4017 | , &[_][]const u8{ |
| 4332 | "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", | 4018 | "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", |
| 4333 | ); | 4019 | }); |
| 4334 | | 4020 | |
| 4335 | cases.add( | 4021 | cases.add("mult assign on undefined value", |
| 4336 | "mult assign on undefined value", | | |
| 4337 | \\comptime { | 4022 | \\comptime { |
| 4338 | \\ var a: i64 = undefined; | 4023 | \\ var a: i64 = undefined; |
| 4339 | \\ a *= a; | 4024 | \\ a *= a; |
| 4340 | \\} | 4025 | \\} |
| 4341 | , | 4026 | , &[_][]const u8{ |
| 4342 | "tmp.zig:3:5: error: use of undefined value here causes undefined behavior", | 4027 | "tmp.zig:3:5: error: use of undefined value here causes undefined behavior", |
| 4343 | ); | 4028 | }); |
| 4344 | | 4029 | |
| 4345 | cases.add( | 4030 | cases.add("mult wrap on undefined value", |
| 4346 | "mult wrap on undefined value", | | |
| 4347 | \\comptime { | 4031 | \\comptime { |
| 4348 | \\ var a: i64 = undefined; | 4032 | \\ var a: i64 = undefined; |
| 4349 | \\ _ = a *% a; | 4033 | \\ _ = a *% a; |
| 4350 | \\} | 4034 | \\} |
| 4351 | , | 4035 | , &[_][]const u8{ |
| 4352 | "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", | 4036 | "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", |
| 4353 | ); | 4037 | }); |
| 4354 | | 4038 | |
| 4355 | cases.add( | 4039 | cases.add("mult wrap assign on undefined value", |
| 4356 | "mult wrap assign on undefined value", | | |
| 4357 | \\comptime { | 4040 | \\comptime { |
| 4358 | \\ var a: i64 = undefined; | 4041 | \\ var a: i64 = undefined; |
| 4359 | \\ a *%= a; | 4042 | \\ a *%= a; |
| 4360 | \\} | 4043 | \\} |
| 4361 | , | 4044 | , &[_][]const u8{ |
| 4362 | "tmp.zig:3:5: error: use of undefined value here causes undefined behavior", | 4045 | "tmp.zig:3:5: error: use of undefined value here causes undefined behavior", |
| 4363 | ); | 4046 | }); |
| 4364 | | 4047 | |
| 4365 | cases.add( | 4048 | cases.add("shift left on undefined value", |
| 4366 | "shift left on undefined value", | | |
| 4367 | \\comptime { | 4049 | \\comptime { |
| 4368 | \\ var a: i64 = undefined; | 4050 | \\ var a: i64 = undefined; |
| 4369 | \\ _ = a << 2; | 4051 | \\ _ = a << 2; |
| 4370 | \\} | 4052 | \\} |
| 4371 | , | 4053 | , &[_][]const u8{ |
| 4372 | "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", | 4054 | "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", |
| 4373 | ); | 4055 | }); |
| 4374 | | 4056 | |
| 4375 | cases.add( | 4057 | cases.add("shift left assign on undefined value", |
| 4376 | "shift left assign on undefined value", | | |
| 4377 | \\comptime { | 4058 | \\comptime { |
| 4378 | \\ var a: i64 = undefined; | 4059 | \\ var a: i64 = undefined; |
| 4379 | \\ a <<= 2; | 4060 | \\ a <<= 2; |
| 4380 | \\} | 4061 | \\} |
| 4381 | , | 4062 | , &[_][]const u8{ |
| 4382 | "tmp.zig:3:5: error: use of undefined value here causes undefined behavior", | 4063 | "tmp.zig:3:5: error: use of undefined value here causes undefined behavior", |
| 4383 | ); | 4064 | }); |
| 4384 | | 4065 | |
| 4385 | cases.add( | 4066 | cases.add("shift right on undefined value", |
| 4386 | "shift right on undefined value", | | |
| 4387 | \\comptime { | 4067 | \\comptime { |
| 4388 | \\ var a: i64 = undefined; | 4068 | \\ var a: i64 = undefined; |
| 4389 | \\ _ = a >> 2; | 4069 | \\ _ = a >> 2; |
| 4390 | \\} | 4070 | \\} |
| 4391 | , | 4071 | , &[_][]const u8{ |
| 4392 | "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", | 4072 | "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", |
| 4393 | ); | 4073 | }); |
| 4394 | | 4074 | |
| 4395 | cases.add( | 4075 | cases.add("shift left assign on undefined value", |
| 4396 | "shift left assign on undefined value", | | |
| 4397 | \\comptime { | 4076 | \\comptime { |
| 4398 | \\ var a: i64 = undefined; | 4077 | \\ var a: i64 = undefined; |
| 4399 | \\ a >>= 2; | 4078 | \\ a >>= 2; |
| 4400 | \\} | 4079 | \\} |
| 4401 | , | 4080 | , &[_][]const u8{ |
| 4402 | "tmp.zig:3:5: error: use of undefined value here causes undefined behavior", | 4081 | "tmp.zig:3:5: error: use of undefined value here causes undefined behavior", |
| 4403 | ); | 4082 | }); |
| 4404 | | 4083 | |
| 4405 | cases.add( | 4084 | cases.add("bin and on undefined value", |
| 4406 | "bin and on undefined value", | | |
| 4407 | \\comptime { | 4085 | \\comptime { |
| 4408 | \\ var a: i64 = undefined; | 4086 | \\ var a: i64 = undefined; |
| 4409 | \\ _ = a & a; | 4087 | \\ _ = a & a; |
| 4410 | \\} | 4088 | \\} |
| 4411 | , | 4089 | , &[_][]const u8{ |
| 4412 | "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", | 4090 | "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", |
| 4413 | ); | 4091 | }); |
| 4414 | | 4092 | |
| 4415 | cases.add( | 4093 | cases.add("bin and assign on undefined value", |
| 4416 | "bin and assign on undefined value", | | |
| 4417 | \\comptime { | 4094 | \\comptime { |
| 4418 | \\ var a: i64 = undefined; | 4095 | \\ var a: i64 = undefined; |
| 4419 | \\ a &= a; | 4096 | \\ a &= a; |
| 4420 | \\} | 4097 | \\} |
| 4421 | , | 4098 | , &[_][]const u8{ |
| 4422 | "tmp.zig:3:5: error: use of undefined value here causes undefined behavior", | 4099 | "tmp.zig:3:5: error: use of undefined value here causes undefined behavior", |
| 4423 | ); | 4100 | }); |
| 4424 | | 4101 | |
| 4425 | cases.add( | 4102 | cases.add("bin or on undefined value", |
| 4426 | "bin or on undefined value", | | |
| 4427 | \\comptime { | 4103 | \\comptime { |
| 4428 | \\ var a: i64 = undefined; | 4104 | \\ var a: i64 = undefined; |
| 4429 | \\ _ = a | a; | 4105 | \\ _ = a | a; |
| 4430 | \\} | 4106 | \\} |
| 4431 | , | 4107 | , &[_][]const u8{ |
| 4432 | "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", | 4108 | "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", |
| 4433 | ); | 4109 | }); |
| 4434 | | 4110 | |
| 4435 | cases.add( | 4111 | cases.add("bin or assign on undefined value", |
| 4436 | "bin or assign on undefined value", | | |
| 4437 | \\comptime { | 4112 | \\comptime { |
| 4438 | \\ var a: i64 = undefined; | 4113 | \\ var a: i64 = undefined; |
| 4439 | \\ a |= a; | 4114 | \\ a |= a; |
| 4440 | \\} | 4115 | \\} |
| 4441 | , | 4116 | , &[_][]const u8{ |
| 4442 | "tmp.zig:3:5: error: use of undefined value here causes undefined behavior", | 4117 | "tmp.zig:3:5: error: use of undefined value here causes undefined behavior", |
| 4443 | ); | 4118 | }); |
| 4444 | | 4119 | |
| 4445 | cases.add( | 4120 | cases.add("bin xor on undefined value", |
| 4446 | "bin xor on undefined value", | | |
| 4447 | \\comptime { | 4121 | \\comptime { |
| 4448 | \\ var a: i64 = undefined; | 4122 | \\ var a: i64 = undefined; |
| 4449 | \\ _ = a ^ a; | 4123 | \\ _ = a ^ a; |
| 4450 | \\} | 4124 | \\} |
| 4451 | , | 4125 | , &[_][]const u8{ |
| 4452 | "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", | 4126 | "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", |
| 4453 | ); | 4127 | }); |
| 4454 | | 4128 | |
| 4455 | cases.add( | 4129 | cases.add("bin xor assign on undefined value", |
| 4456 | "bin xor assign on undefined value", | | |
| 4457 | \\comptime { | 4130 | \\comptime { |
| 4458 | \\ var a: i64 = undefined; | 4131 | \\ var a: i64 = undefined; |
| 4459 | \\ a ^= a; | 4132 | \\ a ^= a; |
| 4460 | \\} | 4133 | \\} |
| 4461 | , | 4134 | , &[_][]const u8{ |
| 4462 | "tmp.zig:3:5: error: use of undefined value here causes undefined behavior", | 4135 | "tmp.zig:3:5: error: use of undefined value here causes undefined behavior", |
| 4463 | ); | 4136 | }); |
| 4464 | | 4137 | |
| 4465 | cases.add( | 4138 | cases.add("equal on undefined value", |
| 4466 | "equal on undefined value", | | |
| 4467 | \\comptime { | 4139 | \\comptime { |
| 4468 | \\ var a: i64 = undefined; | 4140 | \\ var a: i64 = undefined; |
| 4469 | \\ _ = a == a; | 4141 | \\ _ = a == a; |
| 4470 | \\} | 4142 | \\} |
| 4471 | , | 4143 | , &[_][]const u8{ |
| 4472 | "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", | 4144 | "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", |
| 4473 | ); | 4145 | }); |
| 4474 | | 4146 | |
| 4475 | cases.add( | 4147 | cases.add("not equal on undefined value", |
| 4476 | "not equal on undefined value", | | |
| 4477 | \\comptime { | 4148 | \\comptime { |
| 4478 | \\ var a: i64 = undefined; | 4149 | \\ var a: i64 = undefined; |
| 4479 | \\ _ = a != a; | 4150 | \\ _ = a != a; |
| 4480 | \\} | 4151 | \\} |
| 4481 | , | 4152 | , &[_][]const u8{ |
| 4482 | "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", | 4153 | "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", |
| 4483 | ); | 4154 | }); |
| 4484 | | 4155 | |
| 4485 | cases.add( | 4156 | cases.add("greater than on undefined value", |
| 4486 | "greater than on undefined value", | | |
| 4487 | \\comptime { | 4157 | \\comptime { |
| 4488 | \\ var a: i64 = undefined; | 4158 | \\ var a: i64 = undefined; |
| 4489 | \\ _ = a > a; | 4159 | \\ _ = a > a; |
| 4490 | \\} | 4160 | \\} |
| 4491 | , | 4161 | , &[_][]const u8{ |
| 4492 | "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", | 4162 | "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", |
| 4493 | ); | 4163 | }); |
| 4494 | | 4164 | |
| 4495 | cases.add( | 4165 | cases.add("greater than equal on undefined value", |
| 4496 | "greater than equal on undefined value", | | |
| 4497 | \\comptime { | 4166 | \\comptime { |
| 4498 | \\ var a: i64 = undefined; | 4167 | \\ var a: i64 = undefined; |
| 4499 | \\ _ = a >= a; | 4168 | \\ _ = a >= a; |
| 4500 | \\} | 4169 | \\} |
| 4501 | , | 4170 | , &[_][]const u8{ |
| 4502 | "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", | 4171 | "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", |
| 4503 | ); | 4172 | }); |
| 4504 | | 4173 | |
| 4505 | cases.add( | 4174 | cases.add("less than on undefined value", |
| 4506 | "less than on undefined value", | | |
| 4507 | \\comptime { | 4175 | \\comptime { |
| 4508 | \\ var a: i64 = undefined; | 4176 | \\ var a: i64 = undefined; |
| 4509 | \\ _ = a < a; | 4177 | \\ _ = a < a; |
| 4510 | \\} | 4178 | \\} |
| 4511 | , | 4179 | , &[_][]const u8{ |
| 4512 | "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", | 4180 | "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", |
| 4513 | ); | 4181 | }); |
| 4514 | | 4182 | |
| 4515 | cases.add( | 4183 | cases.add("less than equal on undefined value", |
| 4516 | "less than equal on undefined value", | | |
| 4517 | \\comptime { | 4184 | \\comptime { |
| 4518 | \\ var a: i64 = undefined; | 4185 | \\ var a: i64 = undefined; |
| 4519 | \\ _ = a <= a; | 4186 | \\ _ = a <= a; |
| 4520 | \\} | 4187 | \\} |
| 4521 | , | 4188 | , &[_][]const u8{ |
| 4522 | "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", | 4189 | "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", |
| 4523 | ); | 4190 | }); |
| 4524 | | 4191 | |
| 4525 | cases.add( | 4192 | cases.add("and on undefined value", |
| 4526 | "and on undefined value", | | |
| 4527 | \\comptime { | 4193 | \\comptime { |
| 4528 | \\ var a: bool = undefined; | 4194 | \\ var a: bool = undefined; |
| 4529 | \\ _ = a and a; | 4195 | \\ _ = a and a; |
| 4530 | \\} | 4196 | \\} |
| 4531 | , | 4197 | , &[_][]const u8{ |
| 4532 | "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", | 4198 | "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", |
| 4533 | ); | 4199 | }); |
| 4534 | | 4200 | |
| 4535 | cases.add( | 4201 | cases.add("or on undefined value", |
| 4536 | "or on undefined value", | | |
| 4537 | \\comptime { | 4202 | \\comptime { |
| 4538 | \\ var a: bool = undefined; | 4203 | \\ var a: bool = undefined; |
| 4539 | \\ _ = a or a; | 4204 | \\ _ = a or a; |
| 4540 | \\} | 4205 | \\} |
| 4541 | , | 4206 | , &[_][]const u8{ |
| 4542 | "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", | 4207 | "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", |
| 4543 | ); | 4208 | }); |
| 4544 | | 4209 | |
| 4545 | cases.add( | 4210 | cases.add("negate on undefined value", |
| 4546 | "negate on undefined value", | | |
| 4547 | \\comptime { | 4211 | \\comptime { |
| 4548 | \\ var a: i64 = undefined; | 4212 | \\ var a: i64 = undefined; |
| 4549 | \\ _ = -a; | 4213 | \\ _ = -a; |
| 4550 | \\} | 4214 | \\} |
| 4551 | , | 4215 | , &[_][]const u8{ |
| 4552 | "tmp.zig:3:10: error: use of undefined value here causes undefined behavior", | 4216 | "tmp.zig:3:10: error: use of undefined value here causes undefined behavior", |
| 4553 | ); | 4217 | }); |
| 4554 | | 4218 | |
| 4555 | cases.add( | 4219 | cases.add("negate wrap on undefined value", |
| 4556 | "negate wrap on undefined value", | | |
| 4557 | \\comptime { | 4220 | \\comptime { |
| 4558 | \\ var a: i64 = undefined; | 4221 | \\ var a: i64 = undefined; |
| 4559 | \\ _ = -%a; | 4222 | \\ _ = -%a; |
| 4560 | \\} | 4223 | \\} |
| 4561 | , | 4224 | , &[_][]const u8{ |
| 4562 | "tmp.zig:3:11: error: use of undefined value here causes undefined behavior", | 4225 | "tmp.zig:3:11: error: use of undefined value here causes undefined behavior", |
| 4563 | ); | 4226 | }); |
| 4564 | | 4227 | |
| 4565 | cases.add( | 4228 | cases.add("bin not on undefined value", |
| 4566 | "bin not on undefined value", | | |
| 4567 | \\comptime { | 4229 | \\comptime { |
| 4568 | \\ var a: i64 = undefined; | 4230 | \\ var a: i64 = undefined; |
| 4569 | \\ _ = ~a; | 4231 | \\ _ = ~a; |
| 4570 | \\} | 4232 | \\} |
| 4571 | , | 4233 | , &[_][]const u8{ |
| 4572 | "tmp.zig:3:10: error: use of undefined value here causes undefined behavior", | 4234 | "tmp.zig:3:10: error: use of undefined value here causes undefined behavior", |
| 4573 | ); | 4235 | }); |
| 4574 | | 4236 | |
| 4575 | cases.add( | 4237 | cases.add("bool not on undefined value", |
| 4576 | "bool not on undefined value", | | |
| 4577 | \\comptime { | 4238 | \\comptime { |
| 4578 | \\ var a: bool = undefined; | 4239 | \\ var a: bool = undefined; |
| 4579 | \\ _ = !a; | 4240 | \\ _ = !a; |
| 4580 | \\} | 4241 | \\} |
| 4581 | , | 4242 | , &[_][]const u8{ |
| 4582 | "tmp.zig:3:10: error: use of undefined value here causes undefined behavior", | 4243 | "tmp.zig:3:10: error: use of undefined value here causes undefined behavior", |
| 4583 | ); | 4244 | }); |
| 4584 | | 4245 | |
| 4585 | cases.add( | 4246 | cases.add("orelse on undefined value", |
| 4586 | "orelse on undefined value", | | |
| 4587 | \\comptime { | 4247 | \\comptime { |
| 4588 | \\ var a: ?bool = undefined; | 4248 | \\ var a: ?bool = undefined; |
| 4589 | \\ _ = a orelse false; | 4249 | \\ _ = a orelse false; |
| 4590 | \\} | 4250 | \\} |
| 4591 | , | 4251 | , &[_][]const u8{ |
| 4592 | "tmp.zig:3:11: error: use of undefined value here causes undefined behavior", | 4252 | "tmp.zig:3:11: error: use of undefined value here causes undefined behavior", |
| 4593 | ); | 4253 | }); |
| 4594 | | 4254 | |
| 4595 | cases.add( | 4255 | cases.add("catch on undefined value", |
| 4596 | "catch on undefined value", | | |
| 4597 | \\comptime { | 4256 | \\comptime { |
| 4598 | \\ var a: anyerror!bool = undefined; | 4257 | \\ var a: anyerror!bool = undefined; |
| 4599 | \\ _ = a catch |err| false; | 4258 | \\ _ = a catch |err| false; |
| 4600 | \\} | 4259 | \\} |
| 4601 | , | 4260 | , &[_][]const u8{ |
| 4602 | "tmp.zig:3:11: error: use of undefined value here causes undefined behavior", | 4261 | "tmp.zig:3:11: error: use of undefined value here causes undefined behavior", |
| 4603 | ); | 4262 | }); |
| 4604 | | 4263 | |
| 4605 | cases.add( | 4264 | cases.add("deref on undefined value", |
| 4606 | "deref on undefined value", | | |
| 4607 | \\comptime { | 4265 | \\comptime { |
| 4608 | \\ var a: *u8 = undefined; | 4266 | \\ var a: *u8 = undefined; |
| 4609 | \\ _ = a.*; | 4267 | \\ _ = a.*; |
| 4610 | \\} | 4268 | \\} |
| 4611 | , | 4269 | , &[_][]const u8{ |
| 4612 | "tmp.zig:3:9: error: attempt to dereference undefined value", | 4270 | "tmp.zig:3:9: error: attempt to dereference undefined value", |
| 4613 | ); | 4271 | }); |
| 4614 | | 4272 | |
| 4615 | cases.add( | 4273 | cases.add("endless loop in function evaluation", |
| 4616 | "endless loop in function evaluation", | | |
| 4617 | \\const seventh_fib_number = fibbonaci(7); | 4274 | \\const seventh_fib_number = fibbonaci(7); |
| 4618 | \\fn fibbonaci(x: i32) i32 { | 4275 | \\fn fibbonaci(x: i32) i32 { |
| 4619 | \\ return fibbonaci(x - 1) + fibbonaci(x - 2); | 4276 | \\ return fibbonaci(x - 1) + fibbonaci(x - 2); |
| 4620 | \\} | 4277 | \\} |
| 4621 | \\ | 4278 | \\ |
| 4622 | \\export fn entry() usize { return @sizeOf(@typeOf(seventh_fib_number)); } | 4279 | \\export fn entry() usize { return @sizeOf(@typeOf(seventh_fib_number)); } |
| 4623 | , | 4280 | , &[_][]const u8{ |
| 4624 | "tmp.zig:3:21: error: evaluation exceeded 1000 backwards branches", | 4281 | "tmp.zig:3:21: error: evaluation exceeded 1000 backwards branches", |
| 4625 | "tmp.zig:1:37: note: referenced here", | 4282 | "tmp.zig:1:37: note: referenced here", |
| 4626 | "tmp.zig:6:50: note: referenced here", | 4283 | "tmp.zig:6:50: note: referenced here", |
| 4627 | ); | 4284 | }); |
| 4628 | | 4285 | |
| 4629 | cases.add( | 4286 | cases.add("@embedFile with bogus file", |
| 4630 | "@embedFile with bogus file", | | |
| 4631 | \\const resource = @embedFile("bogus.txt",); | 4287 | \\const resource = @embedFile("bogus.txt",); |
| 4632 | \\ | 4288 | \\ |
| 4633 | \\export fn entry() usize { return @sizeOf(@typeOf(resource)); } | 4289 | \\export fn entry() usize { return @sizeOf(@typeOf(resource)); } |
| 4634 | , | 4290 | , &[_][]const u8{ |
| 4635 | "tmp.zig:1:29: error: unable to find '", | 4291 | "tmp.zig:1:29: error: unable to find '", |
| 4636 | "bogus.txt'", | 4292 | "bogus.txt'", |
| 4637 | ); | 4293 | }); |
| 4638 | | 4294 | |
| 4639 | cases.add( | 4295 | cases.add("non-const expression in struct literal outside function", |
| 4640 | "non-const expression in struct literal outside function", | | |
| 4641 | \\const Foo = struct { | 4296 | \\const Foo = struct { |
| 4642 | \\ x: i32, | 4297 | \\ x: i32, |
| 4643 | \\}; | 4298 | \\}; |
| ... | @@ -4645,12 +4300,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -4645,12 +4300,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4645 | \\extern fn get_it() i32; | 4300 | \\extern fn get_it() i32; |
| 4646 | \\ | 4301 | \\ |
| 4647 | \\export fn entry() usize { return @sizeOf(@typeOf(a)); } | 4302 | \\export fn entry() usize { return @sizeOf(@typeOf(a)); } |
| 4648 | , | 4303 | , &[_][]const u8{ |
| 4649 | "tmp.zig:4:21: error: unable to evaluate constant expression", | 4304 | "tmp.zig:4:21: error: unable to evaluate constant expression", |
| 4650 | ); | 4305 | }); |
| 4651 | | 4306 | |
| 4652 | cases.add( | 4307 | cases.add("non-const expression function call with struct return value outside function", |
| 4653 | "non-const expression function call with struct return value outside function", | | |
| 4654 | \\const Foo = struct { | 4308 | \\const Foo = struct { |
| 4655 | \\ x: i32, | 4309 | \\ x: i32, |
| 4656 | \\}; | 4310 | \\}; |
| ... | @@ -4662,25 +4316,23 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -4662,25 +4316,23 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4662 | \\var global_side_effect = false; | 4316 | \\var global_side_effect = false; |
| 4663 | \\ | 4317 | \\ |
| 4664 | \\export fn entry() usize { return @sizeOf(@typeOf(a)); } | 4318 | \\export fn entry() usize { return @sizeOf(@typeOf(a)); } |
| 4665 | , | 4319 | , &[_][]const u8{ |
| 4666 | "tmp.zig:6:26: error: unable to evaluate constant expression", | 4320 | "tmp.zig:6:26: error: unable to evaluate constant expression", |
| 4667 | "tmp.zig:4:17: note: referenced here", | 4321 | "tmp.zig:4:17: note: referenced here", |
| 4668 | ); | 4322 | }); |
| 4669 | | 4323 | |
| 4670 | cases.add( | 4324 | cases.add("undeclared identifier error should mark fn as impure", |
| 4671 | "undeclared identifier error should mark fn as impure", | | |
| 4672 | \\export fn foo() void { | 4325 | \\export fn foo() void { |
| 4673 | \\ test_a_thing(); | 4326 | \\ test_a_thing(); |
| 4674 | \\} | 4327 | \\} |
| 4675 | \\fn test_a_thing() void { | 4328 | \\fn test_a_thing() void { |
| 4676 | \\ bad_fn_call(); | 4329 | \\ bad_fn_call(); |
| 4677 | \\} | 4330 | \\} |
| 4678 | , | 4331 | , &[_][]const u8{ |
| 4679 | "tmp.zig:5:5: error: use of undeclared identifier 'bad_fn_call'", | 4332 | "tmp.zig:5:5: error: use of undeclared identifier 'bad_fn_call'", |
| 4680 | ); | 4333 | }); |
| 4681 | | 4334 | |
| 4682 | cases.add( | 4335 | cases.add("illegal comparison of types", |
| 4683 | "illegal comparison of types", | | |
| 4684 | \\fn bad_eql_1(a: []u8, b: []u8) bool { | 4336 | \\fn bad_eql_1(a: []u8, b: []u8) bool { |
| 4685 | \\ return a == b; | 4337 | \\ return a == b; |
| 4686 | \\} | 4338 | \\} |
| ... | @@ -4694,13 +4346,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -4694,13 +4346,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4694 | \\ | 4346 | \\ |
| 4695 | \\export fn entry1() usize { return @sizeOf(@typeOf(bad_eql_1)); } | 4347 | \\export fn entry1() usize { return @sizeOf(@typeOf(bad_eql_1)); } |
| 4696 | \\export fn entry2() usize { return @sizeOf(@typeOf(bad_eql_2)); } | 4348 | \\export fn entry2() usize { return @sizeOf(@typeOf(bad_eql_2)); } |
| 4697 | , | 4349 | , &[_][]const u8{ |
| 4698 | "tmp.zig:2:14: error: operator not allowed for type '[]u8'", | 4350 | "tmp.zig:2:14: error: operator not allowed for type '[]u8'", |
| 4699 | "tmp.zig:9:16: error: operator not allowed for type 'EnumWithData'", | 4351 | "tmp.zig:9:16: error: operator not allowed for type 'EnumWithData'", |
| 4700 | ); | 4352 | }); |
| 4701 | | 4353 | |
| 4702 | cases.add( | 4354 | cases.add("non-const switch number literal", |
| 4703 | "non-const switch number literal", | | |
| 4704 | \\export fn foo() void { | 4355 | \\export fn foo() void { |
| 4705 | \\ const x = switch (bar()) { | 4356 | \\ const x = switch (bar()) { |
| 4706 | \\ 1, 2 => 1, | 4357 | \\ 1, 2 => 1, |
| ... | @@ -4711,109 +4362,100 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -4711,109 +4362,100 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4711 | \\fn bar() i32 { | 4362 | \\fn bar() i32 { |
| 4712 | \\ return 2; | 4363 | \\ return 2; |
| 4713 | \\} | 4364 | \\} |
| 4714 | , | 4365 | , &[_][]const u8{ |
| 4715 | "tmp.zig:5:17: error: cannot store runtime value in type 'comptime_int'", | 4366 | "tmp.zig:5:17: error: cannot store runtime value in type 'comptime_int'", |
| 4716 | ); | 4367 | }); |
| 4717 | | 4368 | |
| 4718 | cases.add( | 4369 | cases.add("atomic orderings of cmpxchg - failure stricter than success", |
| 4719 | "atomic orderings of cmpxchg - failure stricter than success", | | |
| 4720 | \\const AtomicOrder = @import("builtin").AtomicOrder; | 4370 | \\const AtomicOrder = @import("builtin").AtomicOrder; |
| 4721 | \\export fn f() void { | 4371 | \\export fn f() void { |
| 4722 | \\ var x: i32 = 1234; | 4372 | \\ var x: i32 = 1234; |
| 4723 | \\ while (!@cmpxchgWeak(i32, &x, 1234, 5678, AtomicOrder.Monotonic, AtomicOrder.SeqCst)) {} | 4373 | \\ while (!@cmpxchgWeak(i32, &x, 1234, 5678, AtomicOrder.Monotonic, AtomicOrder.SeqCst)) {} |
| 4724 | \\} | 4374 | \\} |
| 4725 | , | 4375 | , &[_][]const u8{ |
| 4726 | "tmp.zig:4:81: error: failure atomic ordering must be no stricter than success", | 4376 | "tmp.zig:4:81: error: failure atomic ordering must be no stricter than success", |
| 4727 | ); | 4377 | }); |
| 4728 | | 4378 | |
| 4729 | cases.add( | 4379 | cases.add("atomic orderings of cmpxchg - success Monotonic or stricter", |
| 4730 | "atomic orderings of cmpxchg - success Monotonic or stricter", | | |
| 4731 | \\const AtomicOrder = @import("builtin").AtomicOrder; | 4380 | \\const AtomicOrder = @import("builtin").AtomicOrder; |
| 4732 | \\export fn f() void { | 4381 | \\export fn f() void { |
| 4733 | \\ var x: i32 = 1234; | 4382 | \\ var x: i32 = 1234; |
| 4734 | \\ while (!@cmpxchgWeak(i32, &x, 1234, 5678, AtomicOrder.Unordered, AtomicOrder.Unordered)) {} | 4383 | \\ while (!@cmpxchgWeak(i32, &x, 1234, 5678, AtomicOrder.Unordered, AtomicOrder.Unordered)) {} |
| 4735 | \\} | 4384 | \\} |
| 4736 | , | 4385 | , &[_][]const u8{ |
| 4737 | "tmp.zig:4:58: error: success atomic ordering must be Monotonic or stricter", | 4386 | "tmp.zig:4:58: error: success atomic ordering must be Monotonic or stricter", |
| 4738 | ); | 4387 | }); |
| 4739 | | 4388 | |
| 4740 | cases.add( | 4389 | cases.add("negation overflow in function evaluation", |
| 4741 | "negation overflow in function evaluation", | | |
| 4742 | \\const y = neg(-128); | 4390 | \\const y = neg(-128); |
| 4743 | \\fn neg(x: i8) i8 { | 4391 | \\fn neg(x: i8) i8 { |
| 4744 | \\ return -x; | 4392 | \\ return -x; |
| 4745 | \\} | 4393 | \\} |
| 4746 | \\ | 4394 | \\ |
| 4747 | \\export fn entry() usize { return @sizeOf(@typeOf(y)); } | 4395 | \\export fn entry() usize { return @sizeOf(@typeOf(y)); } |
| 4748 | , | 4396 | , &[_][]const u8{ |
| 4749 | "tmp.zig:3:12: error: negation caused overflow", | 4397 | "tmp.zig:3:12: error: negation caused overflow", |
| 4750 | "tmp.zig:1:14: note: referenced here", | 4398 | "tmp.zig:1:14: note: referenced here", |
| 4751 | ); | 4399 | }); |
| 4752 | | 4400 | |
| 4753 | cases.add( | 4401 | cases.add("add overflow in function evaluation", |
| 4754 | "add overflow in function evaluation", | | |
| 4755 | \\const y = add(65530, 10); | 4402 | \\const y = add(65530, 10); |
| 4756 | \\fn add(a: u16, b: u16) u16 { | 4403 | \\fn add(a: u16, b: u16) u16 { |
| 4757 | \\ return a + b; | 4404 | \\ return a + b; |
| 4758 | \\} | 4405 | \\} |
| 4759 | \\ | 4406 | \\ |
| 4760 | \\export fn entry() usize { return @sizeOf(@typeOf(y)); } | 4407 | \\export fn entry() usize { return @sizeOf(@typeOf(y)); } |
| 4761 | , | 4408 | , &[_][]const u8{ |
| 4762 | "tmp.zig:3:14: error: operation caused overflow", | 4409 | "tmp.zig:3:14: error: operation caused overflow", |
| 4763 | "tmp.zig:1:14: note: referenced here", | 4410 | "tmp.zig:1:14: note: referenced here", |
| 4764 | ); | 4411 | }); |
| 4765 | | 4412 | |
| 4766 | cases.add( | 4413 | cases.add("sub overflow in function evaluation", |
| 4767 | "sub overflow in function evaluation", | | |
| 4768 | \\const y = sub(10, 20); | 4414 | \\const y = sub(10, 20); |
| 4769 | \\fn sub(a: u16, b: u16) u16 { | 4415 | \\fn sub(a: u16, b: u16) u16 { |
| 4770 | \\ return a - b; | 4416 | \\ return a - b; |
| 4771 | \\} | 4417 | \\} |
| 4772 | \\ | 4418 | \\ |
| 4773 | \\export fn entry() usize { return @sizeOf(@typeOf(y)); } | 4419 | \\export fn entry() usize { return @sizeOf(@typeOf(y)); } |
| 4774 | , | 4420 | , &[_][]const u8{ |
| 4775 | "tmp.zig:3:14: error: operation caused overflow", | 4421 | "tmp.zig:3:14: error: operation caused overflow", |
| 4776 | "tmp.zig:1:14: note: referenced here", | 4422 | "tmp.zig:1:14: note: referenced here", |
| 4777 | ); | 4423 | }); |
| 4778 | | 4424 | |
| 4779 | cases.add( | 4425 | cases.add("mul overflow in function evaluation", |
| 4780 | "mul overflow in function evaluation", | | |
| 4781 | \\const y = mul(300, 6000); | 4426 | \\const y = mul(300, 6000); |
| 4782 | \\fn mul(a: u16, b: u16) u16 { | 4427 | \\fn mul(a: u16, b: u16) u16 { |
| 4783 | \\ return a * b; | 4428 | \\ return a * b; |
| 4784 | \\} | 4429 | \\} |
| 4785 | \\ | 4430 | \\ |
| 4786 | \\export fn entry() usize { return @sizeOf(@typeOf(y)); } | 4431 | \\export fn entry() usize { return @sizeOf(@typeOf(y)); } |
| 4787 | , | 4432 | , &[_][]const u8{ |
| 4788 | "tmp.zig:3:14: error: operation caused overflow", | 4433 | "tmp.zig:3:14: error: operation caused overflow", |
| 4789 | "tmp.zig:1:14: note: referenced here", | 4434 | "tmp.zig:1:14: note: referenced here", |
| 4790 | ); | 4435 | }); |
| 4791 | | 4436 | |
| 4792 | cases.add( | 4437 | cases.add("truncate sign mismatch", |
| 4793 | "truncate sign mismatch", | | |
| 4794 | \\fn f() i8 { | 4438 | \\fn f() i8 { |
| 4795 | \\ var x: u32 = 10; | 4439 | \\ var x: u32 = 10; |
| 4796 | \\ return @truncate(i8, x); | 4440 | \\ return @truncate(i8, x); |
| 4797 | \\} | 4441 | \\} |
| 4798 | \\ | 4442 | \\ |
| 4799 | \\export fn entry() usize { return @sizeOf(@typeOf(f)); } | 4443 | \\export fn entry() usize { return @sizeOf(@typeOf(f)); } |
| 4800 | , | 4444 | , &[_][]const u8{ |
| 4801 | "tmp.zig:3:26: error: expected signed integer type, found 'u32'", | 4445 | "tmp.zig:3:26: error: expected signed integer type, found 'u32'", |
| 4802 | ); | 4446 | }); |
| 4803 | | 4447 | |
| 4804 | cases.add( | 4448 | cases.add("try in function with non error return type", |
| 4805 | "try in function with non error return type", | | |
| 4806 | \\export fn f() void { | 4449 | \\export fn f() void { |
| 4807 | \\ try something(); | 4450 | \\ try something(); |
| 4808 | \\} | 4451 | \\} |
| 4809 | \\fn something() anyerror!void { } | 4452 | \\fn something() anyerror!void { } |
| 4810 | , | 4453 | , &[_][]const u8{ |
| 4811 | "tmp.zig:2:5: error: expected type 'void', found 'anyerror'", | 4454 | "tmp.zig:2:5: error: expected type 'void', found 'anyerror'", |
| 4812 | "tmp.zig:1:15: note: return type declared here", | 4455 | "tmp.zig:1:15: note: return type declared here", |
| 4813 | ); | 4456 | }); |
| 4814 | | 4457 | |
| 4815 | cases.add( | 4458 | cases.add("invalid pointer for var type", |
| 4816 | "invalid pointer for var type", | | |
| 4817 | \\extern fn ext() usize; | 4459 | \\extern fn ext() usize; |
| 4818 | \\var bytes: [ext()]u8 = undefined; | 4460 | \\var bytes: [ext()]u8 = undefined; |
| 4819 | \\export fn f() void { | 4461 | \\export fn f() void { |
| ... | @@ -4821,43 +4463,39 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -4821,43 +4463,39 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4821 | \\ b.* = @as(u8, i); | 4463 | \\ b.* = @as(u8, i); |
| 4822 | \\ } | 4464 | \\ } |
| 4823 | \\} | 4465 | \\} |
| 4824 | , | 4466 | , &[_][]const u8{ |
| 4825 | "tmp.zig:2:13: error: unable to evaluate constant expression", | 4467 | "tmp.zig:2:13: error: unable to evaluate constant expression", |
| 4826 | ); | 4468 | }); |
| 4827 | | 4469 | |
| 4828 | cases.add( | 4470 | cases.add("export function with comptime parameter", |
| 4829 | "export function with comptime parameter", | | |
| 4830 | \\export fn foo(comptime x: i32, y: i32) i32{ | 4471 | \\export fn foo(comptime x: i32, y: i32) i32{ |
| 4831 | \\ return x + y; | 4472 | \\ return x + y; |
| 4832 | \\} | 4473 | \\} |
| 4833 | , | 4474 | , &[_][]const u8{ |
| 4834 | "tmp.zig:1:15: error: comptime parameter not allowed in function with calling convention 'ccc'", | 4475 | "tmp.zig:1:15: error: comptime parameter not allowed in function with calling convention 'ccc'", |
| 4835 | ); | 4476 | }); |
| 4836 | | 4477 | |
| 4837 | cases.add( | 4478 | cases.add("extern function with comptime parameter", |
| 4838 | "extern function with comptime parameter", | | |
| 4839 | \\extern fn foo(comptime x: i32, y: i32) i32; | 4479 | \\extern fn foo(comptime x: i32, y: i32) i32; |
| 4840 | \\fn f() i32 { | 4480 | \\fn f() i32 { |
| 4841 | \\ return foo(1, 2); | 4481 | \\ return foo(1, 2); |
| 4842 | \\} | 4482 | \\} |
| 4843 | \\export fn entry() usize { return @sizeOf(@typeOf(f)); } | 4483 | \\export fn entry() usize { return @sizeOf(@typeOf(f)); } |
| 4844 | , | 4484 | , &[_][]const u8{ |
| 4845 | "tmp.zig:1:15: error: comptime parameter not allowed in function with calling convention 'ccc'", | 4485 | "tmp.zig:1:15: error: comptime parameter not allowed in function with calling convention 'ccc'", |
| 4846 | ); | 4486 | }); |
| 4847 | | 4487 | |
| 4848 | cases.add( | 4488 | cases.add("convert fixed size array to slice with invalid size", |
| 4849 | "convert fixed size array to slice with invalid size", | | |
| 4850 | \\export fn f() void { | 4489 | \\export fn f() void { |
| 4851 | \\ var array: [5]u8 = undefined; | 4490 | \\ var array: [5]u8 = undefined; |
| 4852 | \\ var foo = @bytesToSlice(u32, &array)[0]; | 4491 | \\ var foo = @bytesToSlice(u32, &array)[0]; |
| 4853 | \\} | 4492 | \\} |
| 4854 | , | 4493 | , &[_][]const u8{ |
| 4855 | "tmp.zig:3:15: error: unable to convert [5]u8 to []align(1) u32: size mismatch", | 4494 | "tmp.zig:3:15: error: unable to convert [5]u8 to []align(1) u32: size mismatch", |
| 4856 | "tmp.zig:3:29: note: u32 has size 4; remaining bytes: 1", | 4495 | "tmp.zig:3:29: note: u32 has size 4; remaining bytes: 1", |
| 4857 | ); | 4496 | }); |
| 4858 | | 4497 | |
| 4859 | cases.add( | 4498 | cases.add("non-pure function returns type", |
| 4860 | "non-pure function returns type", | | |
| 4861 | \\var a: u32 = 0; | 4499 | \\var a: u32 = 0; |
| 4862 | \\pub fn List(comptime T: type) type { | 4500 | \\pub fn List(comptime T: type) type { |
| 4863 | \\ a += 1; | 4501 | \\ a += 1; |
| ... | @@ -4876,24 +4514,22 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -4876,24 +4514,22 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4876 | \\ var list: List(i32) = undefined; | 4514 | \\ var list: List(i32) = undefined; |
| 4877 | \\ list.length = 10; | 4515 | \\ list.length = 10; |
| 4878 | \\} | 4516 | \\} |
| 4879 | , | 4517 | , &[_][]const u8{ |
| 4880 | "tmp.zig:3:7: error: unable to evaluate constant expression", | 4518 | "tmp.zig:3:7: error: unable to evaluate constant expression", |
| 4881 | "tmp.zig:16:19: note: referenced here", | 4519 | "tmp.zig:16:19: note: referenced here", |
| 4882 | ); | 4520 | }); |
| 4883 | | 4521 | |
| 4884 | cases.add( | 4522 | cases.add("bogus method call on slice", |
| 4885 | "bogus method call on slice", | | |
| 4886 | \\var self = "aoeu"; | 4523 | \\var self = "aoeu"; |
| 4887 | \\fn f(m: []const u8) void { | 4524 | \\fn f(m: []const u8) void { |
| 4888 | \\ m.copy(u8, self[0..], m); | 4525 | \\ m.copy(u8, self[0..], m); |
| 4889 | \\} | 4526 | \\} |
| 4890 | \\export fn entry() usize { return @sizeOf(@typeOf(f)); } | 4527 | \\export fn entry() usize { return @sizeOf(@typeOf(f)); } |
| 4891 | , | 4528 | , &[_][]const u8{ |
| 4892 | "tmp.zig:3:6: error: no member named 'copy' in '[]const u8'", | 4529 | "tmp.zig:3:6: error: no member named 'copy' in '[]const u8'", |
| 4893 | ); | 4530 | }); |
| 4894 | | 4531 | |
| 4895 | cases.add( | 4532 | cases.add("wrong number of arguments for method fn call", |
| 4896 | "wrong number of arguments for method fn call", | | |
| 4897 | \\const Foo = struct { | 4533 | \\const Foo = struct { |
| 4898 | \\ fn method(self: *const Foo, a: i32) void {} | 4534 | \\ fn method(self: *const Foo, a: i32) void {} |
| 4899 | \\}; | 4535 | \\}; |
| ... | @@ -4902,39 +4538,35 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -4902,39 +4538,35 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4902 | \\ foo.method(1, 2); | 4538 | \\ foo.method(1, 2); |
| 4903 | \\} | 4539 | \\} |
| 4904 | \\export fn entry() usize { return @sizeOf(@typeOf(f)); } | 4540 | \\export fn entry() usize { return @sizeOf(@typeOf(f)); } |
| 4905 | , | 4541 | , &[_][]const u8{ |
| 4906 | "tmp.zig:6:15: error: expected 2 arguments, found 3", | 4542 | "tmp.zig:6:15: error: expected 2 arguments, found 3", |
| 4907 | ); | 4543 | }); |
| 4908 | | 4544 | |
| 4909 | cases.add( | 4545 | cases.add("assign through constant pointer", |
| 4910 | "assign through constant pointer", | | |
| 4911 | \\export fn f() void { | 4546 | \\export fn f() void { |
| 4912 | \\ var cstr = "Hat"; | 4547 | \\ var cstr = "Hat"; |
| 4913 | \\ cstr[0] = 'W'; | 4548 | \\ cstr[0] = 'W'; |
| 4914 | \\} | 4549 | \\} |
| 4915 | , | 4550 | , &[_][]const u8{ |
| 4916 | "tmp.zig:3:13: error: cannot assign to constant", | 4551 | "tmp.zig:3:13: error: cannot assign to constant", |
| 4917 | ); | 4552 | }); |
| 4918 | | 4553 | |
| 4919 | cases.add( | 4554 | cases.add("assign through constant slice", |
| 4920 | "assign through constant slice", | | |
| 4921 | \\export fn f() void { | 4555 | \\export fn f() void { |
| 4922 | \\ var cstr: []const u8 = "Hat"; | 4556 | \\ var cstr: []const u8 = "Hat"; |
| 4923 | \\ cstr[0] = 'W'; | 4557 | \\ cstr[0] = 'W'; |
| 4924 | \\} | 4558 | \\} |
| 4925 | , | 4559 | , &[_][]const u8{ |
| 4926 | "tmp.zig:3:13: error: cannot assign to constant", | 4560 | "tmp.zig:3:13: error: cannot assign to constant", |
| 4927 | ); | 4561 | }); |
| 4928 | | 4562 | |
| 4929 | cases.add( | 4563 | cases.add("main function with bogus args type", |
| 4930 | "main function with bogus args type", | | |
| 4931 | \\pub fn main(args: [][]bogus) !void {} | 4564 | \\pub fn main(args: [][]bogus) !void {} |
| 4932 | , | 4565 | , &[_][]const u8{ |
| 4933 | "tmp.zig:1:23: error: use of undeclared identifier 'bogus'", | 4566 | "tmp.zig:1:23: error: use of undeclared identifier 'bogus'", |
| 4934 | ); | 4567 | }); |
| 4935 | | 4568 | |
| 4936 | cases.add( | 4569 | cases.add("misspelled type with pointer only reference", |
| 4937 | "misspelled type with pointer only reference", | | |
| 4938 | \\const JasonHM = u8; | 4570 | \\const JasonHM = u8; |
| 4939 | \\const JasonList = *JsonNode; | 4571 | \\const JasonList = *JsonNode; |
| 4940 | \\ | 4572 | \\ |
| ... | @@ -4965,12 +4597,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -4965,12 +4597,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4965 | \\} | 4597 | \\} |
| 4966 | \\ | 4598 | \\ |
| 4967 | \\export fn entry() usize { return @sizeOf(@typeOf(foo)); } | 4599 | \\export fn entry() usize { return @sizeOf(@typeOf(foo)); } |
| 4968 | , | 4600 | , &[_][]const u8{ |
| 4969 | "tmp.zig:5:16: error: use of undeclared identifier 'JsonList'", | 4601 | "tmp.zig:5:16: error: use of undeclared identifier 'JsonList'", |
| 4970 | ); | 4602 | }); |
| 4971 | | 4603 | |
| 4972 | cases.add( | 4604 | cases.add("method call with first arg type primitive", |
| 4973 | "method call with first arg type primitive", | | |
| 4974 | \\const Foo = struct { | 4605 | \\const Foo = struct { |
| 4975 | \\ x: i32, | 4606 | \\ x: i32, |
| 4976 | \\ | 4607 | \\ |
| ... | @@ -4986,12 +4617,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -4986,12 +4617,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4986 | \\ | 4617 | \\ |
| 4987 | \\ derp.init(); | 4618 | \\ derp.init(); |
| 4988 | \\} | 4619 | \\} |
| 4989 | , | 4620 | , &[_][]const u8{ |
| 4990 | "tmp.zig:14:5: error: expected type 'i32', found 'Foo'", | 4621 | "tmp.zig:14:5: error: expected type 'i32', found 'Foo'", |
| 4991 | ); | 4622 | }); |
| 4992 | | 4623 | |
| 4993 | cases.add( | 4624 | cases.add("method call with first arg type wrong container", |
| 4994 | "method call with first arg type wrong container", | | |
| 4995 | \\pub const List = struct { | 4625 | \\pub const List = struct { |
| 4996 | \\ len: usize, | 4626 | \\ len: usize, |
| 4997 | \\ allocator: *Allocator, | 4627 | \\ allocator: *Allocator, |
| ... | @@ -5016,33 +4646,31 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -5016,33 +4646,31 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5016 | \\ var x = List.init(&global_allocator); | 4646 | \\ var x = List.init(&global_allocator); |
| 5017 | \\ x.init(); | 4647 | \\ x.init(); |
| 5018 | \\} | 4648 | \\} |
| 5019 | , | 4649 | , &[_][]const u8{ |
| 5020 | "tmp.zig:23:5: error: expected type '*Allocator', found '*List'", | 4650 | "tmp.zig:23:5: error: expected type '*Allocator', found '*List'", |
| 5021 | ); | 4651 | }); |
| 5022 | | 4652 | |
| 5023 | cases.add( | 4653 | cases.add("binary not on number literal", |
| 5024 | "binary not on number literal", | | |
| 5025 | \\const TINY_QUANTUM_SHIFT = 4; | 4654 | \\const TINY_QUANTUM_SHIFT = 4; |
| 5026 | \\const TINY_QUANTUM_SIZE = 1 << TINY_QUANTUM_SHIFT; | 4655 | \\const TINY_QUANTUM_SIZE = 1 << TINY_QUANTUM_SHIFT; |
| 5027 | \\var block_aligned_stuff: usize = (4 + TINY_QUANTUM_SIZE) & ~(TINY_QUANTUM_SIZE - 1); | 4656 | \\var block_aligned_stuff: usize = (4 + TINY_QUANTUM_SIZE) & ~(TINY_QUANTUM_SIZE - 1); |
| 5028 | \\ | 4657 | \\ |
| 5029 | \\export fn entry() usize { return @sizeOf(@typeOf(block_aligned_stuff)); } | 4658 | \\export fn entry() usize { return @sizeOf(@typeOf(block_aligned_stuff)); } |
| 5030 | , | 4659 | , &[_][]const u8{ |
| 5031 | "tmp.zig:3:60: error: unable to perform binary not operation on type 'comptime_int'", | 4660 | "tmp.zig:3:60: error: unable to perform binary not operation on type 'comptime_int'", |
| 5032 | ); | 4661 | }); |
| 5033 | | 4662 | |
| 5034 | cases.addCase(x: { | 4663 | cases.addCase(x: { |
| 5035 | const tc = cases.create( | 4664 | const tc = cases.create("multiple files with private function error", |
| 5036 | "multiple files with private function error", | | |
| 5037 | \\const foo = @import("foo.zig",); | 4665 | \\const foo = @import("foo.zig",); |
| 5038 | \\ | 4666 | \\ |
| 5039 | \\export fn callPrivFunction() void { | 4667 | \\export fn callPrivFunction() void { |
| 5040 | \\ foo.privateFunction(); | 4668 | \\ foo.privateFunction(); |
| 5041 | \\} | 4669 | \\} |
| 5042 | , | 4670 | , &[_][]const u8{ |
| 5043 | "tmp.zig:4:8: error: 'privateFunction' is private", | 4671 | "tmp.zig:4:8: error: 'privateFunction' is private", |
| 5044 | "foo.zig:1:1: note: declared here", | 4672 | "foo.zig:1:1: note: declared here", |
| 5045 | ); | 4673 | }); |
| 5046 | | 4674 | |
| 5047 | tc.addSourceFile("foo.zig", | 4675 | tc.addSourceFile("foo.zig", |
| 5048 | \\fn privateFunction() void { } | 4676 | \\fn privateFunction() void { } |
| ... | @@ -5051,18 +4679,16 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -5051,18 +4679,16 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5051 | break :x tc; | 4679 | break :x tc; |
| 5052 | }); | 4680 | }); |
| 5053 | | 4681 | |
| 5054 | cases.add( | 4682 | cases.add("container init with non-type", |
| 5055 | "container init with non-type", | | |
| 5056 | \\const zero: i32 = 0; | 4683 | \\const zero: i32 = 0; |
| 5057 | \\const a = zero{1}; | 4684 | \\const a = zero{1}; |
| 5058 | \\ | 4685 | \\ |
| 5059 | \\export fn entry() usize { return @sizeOf(@typeOf(a)); } | 4686 | \\export fn entry() usize { return @sizeOf(@typeOf(a)); } |
| 5060 | , | 4687 | , &[_][]const u8{ |
| 5061 | "tmp.zig:2:11: error: expected type 'type', found 'i32'", | 4688 | "tmp.zig:2:11: error: expected type 'type', found 'i32'", |
| 5062 | ); | 4689 | }); |
| 5063 | | 4690 | |
| 5064 | cases.add( | 4691 | cases.add("assign to constant field", |
| 5065 | "assign to constant field", | | |
| 5066 | \\const Foo = struct { | 4692 | \\const Foo = struct { |
| 5067 | \\ field: i32, | 4693 | \\ field: i32, |
| 5068 | \\}; | 4694 | \\}; |
| ... | @@ -5070,12 +4696,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -5070,12 +4696,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5070 | \\ const f = Foo {.field = 1234,}; | 4696 | \\ const f = Foo {.field = 1234,}; |
| 5071 | \\ f.field = 0; | 4697 | \\ f.field = 0; |
| 5072 | \\} | 4698 | \\} |
| 5073 | , | 4699 | , &[_][]const u8{ |
| 5074 | "tmp.zig:6:15: error: cannot assign to constant", | 4700 | "tmp.zig:6:15: error: cannot assign to constant", |
| 5075 | ); | 4701 | }); |
| 5076 | | 4702 | |
| 5077 | cases.add( | 4703 | cases.add("return from defer expression", |
| 5078 | "return from defer expression", | | |
| 5079 | \\pub fn testTrickyDefer() !void { | 4704 | \\pub fn testTrickyDefer() !void { |
| 5080 | \\ defer canFail() catch {}; | 4705 | \\ defer canFail() catch {}; |
| 5081 | \\ | 4706 | \\ |
| ... | @@ -5091,72 +4716,33 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -5091,72 +4716,33 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5091 | \\} | 4716 | \\} |
| 5092 | \\ | 4717 | \\ |
| 5093 | \\export fn entry() usize { return @sizeOf(@typeOf(testTrickyDefer)); } | 4718 | \\export fn entry() usize { return @sizeOf(@typeOf(testTrickyDefer)); } |
| 5094 | , | 4719 | , &[_][]const u8{ |
| 5095 | "tmp.zig:4:11: error: cannot return from defer expression", | 4720 | "tmp.zig:4:11: error: cannot return from defer expression", |
| 5096 | ); | 4721 | }); |
| 5097 | | | |
| 5098 | cases.add( | | |
| 5099 | "attempt to access var args out of bounds", | | |
| 5100 | \\fn add(args: ...) i32 { | | |
| 5101 | \\ return args[0] + args[1]; | | |
| 5102 | \\} | | |
| 5103 | \\ | | |
| 5104 | \\fn foo() i32 { | | |
| 5105 | \\ return add(@as(i32, 1234)); | | |
| 5106 | \\} | | |
| 5107 | \\ | | |
| 5108 | \\export fn entry() usize { return @sizeOf(@typeOf(foo)); } | | |
| 5109 | , | | |
| 5110 | "tmp.zig:2:26: error: index 1 outside argument list of size 1", | | |
| 5111 | "tmp.zig:6:15: note: called from here", | | |
| 5112 | ); | | |
| 5113 | | | |
| 5114 | cases.add( | | |
| 5115 | "pass integer literal to var args", | | |
| 5116 | \\fn add(args: ...) i32 { | | |
| 5117 | \\ var sum = @as(i32, 0); | | |
| 5118 | \\ {comptime var i: usize = 0; inline while (i < args.len) : (i += 1) { | | |
| 5119 | \\ sum += args[i]; | | |
| 5120 | \\ }} | | |
| 5121 | \\ return sum; | | |
| 5122 | \\} | | |
| 5123 | \\ | | |
| 5124 | \\fn bar() i32 { | | |
| 5125 | \\ return add(1, 2, 3, 4); | | |
| 5126 | \\} | | |
| 5127 | \\ | | |
| 5128 | \\export fn entry() usize { return @sizeOf(@typeOf(bar)); } | | |
| 5129 | , | | |
| 5130 | "tmp.zig:10:16: error: compiler bug: integer and float literals in var args function must be casted", | | |
| 5131 | ); | | |
| 5132 | | 4722 | |
| 5133 | cases.add( | 4723 | cases.add("assign too big number to u16", |
| 5134 | "assign too big number to u16", | | |
| 5135 | \\export fn foo() void { | 4724 | \\export fn foo() void { |
| 5136 | \\ var vga_mem: u16 = 0xB8000; | 4725 | \\ var vga_mem: u16 = 0xB8000; |
| 5137 | \\} | 4726 | \\} |
| 5138 | , | 4727 | , &[_][]const u8{ |
| 5139 | "tmp.zig:2:24: error: integer value 753664 cannot be coerced to type 'u16'", | 4728 | "tmp.zig:2:24: error: integer value 753664 cannot be coerced to type 'u16'", |
| 5140 | ); | 4729 | }); |
| 5141 | | 4730 | |
| 5142 | cases.add( | 4731 | cases.add("global variable alignment non power of 2", |
| 5143 | "global variable alignment non power of 2", | | |
| 5144 | \\const some_data: [100]u8 align(3) = undefined; | 4732 | \\const some_data: [100]u8 align(3) = undefined; |
| 5145 | \\export fn entry() usize { return @sizeOf(@typeOf(some_data)); } | 4733 | \\export fn entry() usize { return @sizeOf(@typeOf(some_data)); } |
| 5146 | , | 4734 | , &[_][]const u8{ |
| 5147 | "tmp.zig:1:32: error: alignment value 3 is not a power of 2", | 4735 | "tmp.zig:1:32: error: alignment value 3 is not a power of 2", |
| 5148 | ); | 4736 | }); |
| 5149 | | 4737 | |
| 5150 | cases.add( | 4738 | cases.add("function alignment non power of 2", |
| 5151 | "function alignment non power of 2", | | |
| 5152 | \\extern fn foo() align(3) void; | 4739 | \\extern fn foo() align(3) void; |
| 5153 | \\export fn entry() void { return foo(); } | 4740 | \\export fn entry() void { return foo(); } |
| 5154 | , | 4741 | , &[_][]const u8{ |
| 5155 | "tmp.zig:1:23: error: alignment value 3 is not a power of 2", | 4742 | "tmp.zig:1:23: error: alignment value 3 is not a power of 2", |
| 5156 | ); | 4743 | }); |
| 5157 | | 4744 | |
| 5158 | cases.add( | 4745 | cases.add("compile log", |
| 5159 | "compile log", | | |
| 5160 | \\export fn foo() void { | 4746 | \\export fn foo() void { |
| 5161 | \\ comptime bar(12, "hi",); | 4747 | \\ comptime bar(12, "hi",); |
| 5162 | \\} | 4748 | \\} |
| ... | @@ -5165,14 +4751,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -5165,14 +4751,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5165 | \\ @compileLog("a", a, "b", b); | 4751 | \\ @compileLog("a", a, "b", b); |
| 5166 | \\ @compileLog("end",); | 4752 | \\ @compileLog("end",); |
| 5167 | \\} | 4753 | \\} |
| 5168 | , | 4754 | , &[_][]const u8{ |
| 5169 | "tmp.zig:5:5: error: found compile log statement", | 4755 | "tmp.zig:5:5: error: found compile log statement", |
| 5170 | "tmp.zig:6:5: error: found compile log statement", | 4756 | "tmp.zig:6:5: error: found compile log statement", |
| 5171 | "tmp.zig:7:5: error: found compile log statement", | 4757 | "tmp.zig:7:5: error: found compile log statement", |
| 5172 | ); | 4758 | }); |
| 5173 | | 4759 | |
| 5174 | cases.add( | 4760 | cases.add("casting bit offset pointer to regular pointer", |
| 5175 | "casting bit offset pointer to regular pointer", | | |
| 5176 | \\const BitField = packed struct { | 4761 | \\const BitField = packed struct { |
| 5177 | \\ a: u3, | 4762 | \\ a: u3, |
| 5178 | \\ b: u3, | 4763 | \\ b: u3, |
| ... | @@ -5188,12 +4773,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -5188,12 +4773,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5188 | \\} | 4773 | \\} |
| 5189 | \\ | 4774 | \\ |
| 5190 | \\export fn entry() usize { return @sizeOf(@typeOf(foo)); } | 4775 | \\export fn entry() usize { return @sizeOf(@typeOf(foo)); } |
| 5191 | , | 4776 | , &[_][]const u8{ |
| 5192 | "tmp.zig:8:26: error: expected type '*const u3', found '*align(:3:1) const u3'", | 4777 | "tmp.zig:8:26: error: expected type '*const u3', found '*align(:3:1) const u3'", |
| 5193 | ); | 4778 | }); |
| 5194 | | 4779 | |
| 5195 | cases.add( | 4780 | cases.add("referring to a struct that is invalid", |
| 5196 | "referring to a struct that is invalid", | | |
| 5197 | \\const UsbDeviceRequest = struct { | 4781 | \\const UsbDeviceRequest = struct { |
| 5198 | \\ Type: u8, | 4782 | \\ Type: u8, |
| 5199 | \\}; | 4783 | \\}; |
| ... | @@ -5205,13 +4789,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -5205,13 +4789,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5205 | \\fn assert(ok: bool) void { | 4789 | \\fn assert(ok: bool) void { |
| 5206 | \\ if (!ok) unreachable; | 4790 | \\ if (!ok) unreachable; |
| 5207 | \\} | 4791 | \\} |
| 5208 | , | 4792 | , &[_][]const u8{ |
| 5209 | "tmp.zig:10:14: error: unable to evaluate constant expression", | 4793 | "tmp.zig:10:14: error: unable to evaluate constant expression", |
| 5210 | "tmp.zig:6:20: note: referenced here", | 4794 | "tmp.zig:6:20: note: referenced here", |
| 5211 | ); | 4795 | }); |
| 5212 | | 4796 | |
| 5213 | cases.add( | 4797 | cases.add("control flow uses comptime var at runtime", |
| 5214 | "control flow uses comptime var at runtime", | | |
| 5215 | \\export fn foo() void { | 4798 | \\export fn foo() void { |
| 5216 | \\ comptime var i = 0; | 4799 | \\ comptime var i = 0; |
| 5217 | \\ while (i < 5) : (i += 1) { | 4800 | \\ while (i < 5) : (i += 1) { |
| ... | @@ -5220,79 +4803,71 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -5220,79 +4803,71 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5220 | \\} | 4803 | \\} |
| 5221 | \\ | 4804 | \\ |
| 5222 | \\fn bar() void { } | 4805 | \\fn bar() void { } |
| 5223 | , | 4806 | , &[_][]const u8{ |
| 5224 | "tmp.zig:3:5: error: control flow attempts to use compile-time variable at runtime", | 4807 | "tmp.zig:3:5: error: control flow attempts to use compile-time variable at runtime", |
| 5225 | "tmp.zig:3:24: note: compile-time variable assigned here", | 4808 | "tmp.zig:3:24: note: compile-time variable assigned here", |
| 5226 | ); | 4809 | }); |
| 5227 | | 4810 | |
| 5228 | cases.add( | 4811 | cases.add("ignored return value", |
| 5229 | "ignored return value", | | |
| 5230 | \\export fn foo() void { | 4812 | \\export fn foo() void { |
| 5231 | \\ bar(); | 4813 | \\ bar(); |
| 5232 | \\} | 4814 | \\} |
| 5233 | \\fn bar() i32 { return 0; } | 4815 | \\fn bar() i32 { return 0; } |
| 5234 | , | 4816 | , &[_][]const u8{ |
| 5235 | "tmp.zig:2:8: error: expression value is ignored", | 4817 | "tmp.zig:2:8: error: expression value is ignored", |
| 5236 | ); | 4818 | }); |
| 5237 | | 4819 | |
| 5238 | cases.add( | 4820 | cases.add("ignored assert-err-ok return value", |
| 5239 | "ignored assert-err-ok return value", | | |
| 5240 | \\export fn foo() void { | 4821 | \\export fn foo() void { |
| 5241 | \\ bar() catch unreachable; | 4822 | \\ bar() catch unreachable; |
| 5242 | \\} | 4823 | \\} |
| 5243 | \\fn bar() anyerror!i32 { return 0; } | 4824 | \\fn bar() anyerror!i32 { return 0; } |
| 5244 | , | 4825 | , &[_][]const u8{ |
| 5245 | "tmp.zig:2:11: error: expression value is ignored", | 4826 | "tmp.zig:2:11: error: expression value is ignored", |
| 5246 | ); | 4827 | }); |
| 5247 | | 4828 | |
| 5248 | cases.add( | 4829 | cases.add("ignored statement value", |
| 5249 | "ignored statement value", | | |
| 5250 | \\export fn foo() void { | 4830 | \\export fn foo() void { |
| 5251 | \\ 1; | 4831 | \\ 1; |
| 5252 | \\} | 4832 | \\} |
| 5253 | , | 4833 | , &[_][]const u8{ |
| 5254 | "tmp.zig:2:5: error: expression value is ignored", | 4834 | "tmp.zig:2:5: error: expression value is ignored", |
| 5255 | ); | 4835 | }); |
| 5256 | | 4836 | |
| 5257 | cases.add( | 4837 | cases.add("ignored comptime statement value", |
| 5258 | "ignored comptime statement value", | | |
| 5259 | \\export fn foo() void { | 4838 | \\export fn foo() void { |
| 5260 | \\ comptime {1;} | 4839 | \\ comptime {1;} |
| 5261 | \\} | 4840 | \\} |
| 5262 | , | 4841 | , &[_][]const u8{ |
| 5263 | "tmp.zig:2:15: error: expression value is ignored", | 4842 | "tmp.zig:2:15: error: expression value is ignored", |
| 5264 | ); | 4843 | }); |
| 5265 | | 4844 | |
| 5266 | cases.add( | 4845 | cases.add("ignored comptime value", |
| 5267 | "ignored comptime value", | | |
| 5268 | \\export fn foo() void { | 4846 | \\export fn foo() void { |
| 5269 | \\ comptime 1; | 4847 | \\ comptime 1; |
| 5270 | \\} | 4848 | \\} |
| 5271 | , | 4849 | , &[_][]const u8{ |
| 5272 | "tmp.zig:2:5: error: expression value is ignored", | 4850 | "tmp.zig:2:5: error: expression value is ignored", |
| 5273 | ); | 4851 | }); |
| 5274 | | 4852 | |
| 5275 | cases.add( | 4853 | cases.add("ignored defered statement value", |
| 5276 | "ignored defered statement value", | | |
| 5277 | \\export fn foo() void { | 4854 | \\export fn foo() void { |
| 5278 | \\ defer {1;} | 4855 | \\ defer {1;} |
| 5279 | \\} | 4856 | \\} |
| 5280 | , | 4857 | , &[_][]const u8{ |
| 5281 | "tmp.zig:2:12: error: expression value is ignored", | 4858 | "tmp.zig:2:12: error: expression value is ignored", |
| 5282 | ); | 4859 | }); |
| 5283 | | 4860 | |
| 5284 | cases.add( | 4861 | cases.add("ignored defered function call", |
| 5285 | "ignored defered function call", | | |
| 5286 | \\export fn foo() void { | 4862 | \\export fn foo() void { |
| 5287 | \\ defer bar(); | 4863 | \\ defer bar(); |
| 5288 | \\} | 4864 | \\} |
| 5289 | \\fn bar() anyerror!i32 { return 0; } | 4865 | \\fn bar() anyerror!i32 { return 0; } |
| 5290 | , | 4866 | , &[_][]const u8{ |
| 5291 | "tmp.zig:2:14: error: expression value is ignored", | 4867 | "tmp.zig:2:14: error: expression value is ignored", |
| 5292 | ); | 4868 | }); |
| 5293 | | 4869 | |
| 5294 | cases.add( | 4870 | cases.add("dereference an array", |
| 5295 | "dereference an array", | | |
| 5296 | \\var s_buffer: [10]u8 = undefined; | 4871 | \\var s_buffer: [10]u8 = undefined; |
| 5297 | \\pub fn pass(in: []u8) []u8 { | 4872 | \\pub fn pass(in: []u8) []u8 { |
| 5298 | \\ var out = &s_buffer; | 4873 | \\ var out = &s_buffer; |
| ... | @@ -5301,12 +4876,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -5301,12 +4876,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5301 | \\} | 4876 | \\} |
| 5302 | \\ | 4877 | \\ |
| 5303 | \\export fn entry() usize { return @sizeOf(@typeOf(pass)); } | 4878 | \\export fn entry() usize { return @sizeOf(@typeOf(pass)); } |
| 5304 | , | 4879 | , &[_][]const u8{ |
| 5305 | "tmp.zig:4:10: error: attempt to dereference non-pointer type '[10]u8'", | 4880 | "tmp.zig:4:10: error: attempt to dereference non-pointer type '[10]u8'", |
| 5306 | ); | 4881 | }); |
| 5307 | | 4882 | |
| 5308 | cases.add( | 4883 | cases.add("pass const ptr to mutable ptr fn", |
| 5309 | "pass const ptr to mutable ptr fn", | | |
| 5310 | \\fn foo() bool { | 4884 | \\fn foo() bool { |
| 5311 | \\ const a = @as([]const u8, "a",); | 4885 | \\ const a = @as([]const u8, "a",); |
| 5312 | \\ const b = &a; | 4886 | \\ const b = &a; |
| ... | @@ -5317,22 +4891,21 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -5317,22 +4891,21 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5317 | \\} | 4891 | \\} |
| 5318 | \\ | 4892 | \\ |
| 5319 | \\export fn entry() usize { return @sizeOf(@typeOf(foo)); } | 4893 | \\export fn entry() usize { return @sizeOf(@typeOf(foo)); } |
| 5320 | , | 4894 | , &[_][]const u8{ |
| 5321 | "tmp.zig:4:19: error: expected type '*[]const u8', found '*const []const u8'", | 4895 | "tmp.zig:4:19: error: expected type '*[]const u8', found '*const []const u8'", |
| 5322 | ); | 4896 | }); |
| 5323 | | 4897 | |
| 5324 | cases.addCase(x: { | 4898 | cases.addCase(x: { |
| 5325 | const tc = cases.create( | 4899 | const tc = cases.create("export collision", |
| 5326 | "export collision", | | |
| 5327 | \\const foo = @import("foo.zig",); | 4900 | \\const foo = @import("foo.zig",); |
| 5328 | \\ | 4901 | \\ |
| 5329 | \\export fn bar() usize { | 4902 | \\export fn bar() usize { |
| 5330 | \\ return foo.baz; | 4903 | \\ return foo.baz; |
| 5331 | \\} | 4904 | \\} |
| 5332 | , | 4905 | , &[_][]const u8{ |
| 5333 | "foo.zig:1:1: error: exported symbol collision: 'bar'", | 4906 | "foo.zig:1:1: error: exported symbol collision: 'bar'", |
| 5334 | "tmp.zig:3:1: note: other symbol here", | 4907 | "tmp.zig:3:1: note: other symbol here", |
| 5335 | ); | 4908 | }); |
| 5336 | | 4909 | |
| 5337 | tc.addSourceFile("foo.zig", | 4910 | tc.addSourceFile("foo.zig", |
| 5338 | \\export fn bar() void {} | 4911 | \\export fn bar() void {} |
| ... | @@ -5342,28 +4915,25 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -5342,28 +4915,25 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5342 | break :x tc; | 4915 | break :x tc; |
| 5343 | }); | 4916 | }); |
| 5344 | | 4917 | |
| 5345 | cases.add( | 4918 | cases.add("implicit cast from array to mutable slice", |
| 5346 | "implicit cast from array to mutable slice", | | |
| 5347 | \\var global_array: [10]i32 = undefined; | 4919 | \\var global_array: [10]i32 = undefined; |
| 5348 | \\fn foo(param: []i32) void {} | 4920 | \\fn foo(param: []i32) void {} |
| 5349 | \\export fn entry() void { | 4921 | \\export fn entry() void { |
| 5350 | \\ foo(global_array); | 4922 | \\ foo(global_array); |
| 5351 | \\} | 4923 | \\} |
| 5352 | , | 4924 | , &[_][]const u8{ |
| 5353 | "tmp.zig:4:9: error: expected type '[]i32', found '[10]i32'", | 4925 | "tmp.zig:4:9: error: expected type '[]i32', found '[10]i32'", |
| 5354 | ); | 4926 | }); |
| 5355 | | 4927 | |
| 5356 | cases.add( | 4928 | cases.add("ptrcast to non-pointer", |
| 5357 | "ptrcast to non-pointer", | | |
| 5358 | \\export fn entry(a: *i32) usize { | 4929 | \\export fn entry(a: *i32) usize { |
| 5359 | \\ return @ptrCast(usize, a); | 4930 | \\ return @ptrCast(usize, a); |
| 5360 | \\} | 4931 | \\} |
| 5361 | , | 4932 | , &[_][]const u8{ |
| 5362 | "tmp.zig:2:21: error: expected pointer, found 'usize'", | 4933 | "tmp.zig:2:21: error: expected pointer, found 'usize'", |
| 5363 | ); | 4934 | }); |
| 5364 | | 4935 | |
| 5365 | cases.add( | 4936 | cases.add("asm at compile time", |
| 5366 | "asm at compile time", | | |
| 5367 | \\comptime { | 4937 | \\comptime { |
| 5368 | \\ doSomeAsm(); | 4938 | \\ doSomeAsm(); |
| 5369 | \\} | 4939 | \\} |
| ... | @@ -5375,66 +4945,60 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -5375,66 +4945,60 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5375 | \\ \\.set aoeu, derp; | 4945 | \\ \\.set aoeu, derp; |
| 5376 | \\ ); | 4946 | \\ ); |
| 5377 | \\} | 4947 | \\} |
| 5378 | , | 4948 | , &[_][]const u8{ |
| 5379 | "tmp.zig:6:5: error: unable to evaluate constant expression", | 4949 | "tmp.zig:6:5: error: unable to evaluate constant expression", |
| 5380 | ); | 4950 | }); |
| 5381 | | 4951 | |
| 5382 | cases.add( | 4952 | cases.add("invalid member of builtin enum", |
| 5383 | "invalid member of builtin enum", | | |
| 5384 | \\const builtin = @import("builtin",); | 4953 | \\const builtin = @import("builtin",); |
| 5385 | \\export fn entry() void { | 4954 | \\export fn entry() void { |
| 5386 | \\ const foo = builtin.Arch.x86; | 4955 | \\ const foo = builtin.Arch.x86; |
| 5387 | \\} | 4956 | \\} |
| 5388 | , | 4957 | , &[_][]const u8{ |
| 5389 | "tmp.zig:3:29: error: container 'std.target.Arch' has no member called 'x86'", | 4958 | "tmp.zig:3:29: error: container 'std.target.Arch' has no member called 'x86'", |
| 5390 | ); | 4959 | }); |
| 5391 | | 4960 | |
| 5392 | cases.add( | 4961 | cases.add("int to ptr of 0 bits", |
| 5393 | "int to ptr of 0 bits", | | |
| 5394 | \\export fn foo() void { | 4962 | \\export fn foo() void { |
| 5395 | \\ var x: usize = 0x1000; | 4963 | \\ var x: usize = 0x1000; |
| 5396 | \\ var y: *void = @intToPtr(*void, x); | 4964 | \\ var y: *void = @intToPtr(*void, x); |
| 5397 | \\} | 4965 | \\} |
| 5398 | , | 4966 | , &[_][]const u8{ |
| 5399 | "tmp.zig:3:30: error: type '*void' has 0 bits and cannot store information", | 4967 | "tmp.zig:3:30: error: type '*void' has 0 bits and cannot store information", |
| 5400 | ); | 4968 | }); |
| 5401 | | 4969 | |
| 5402 | cases.add( | 4970 | cases.add("@fieldParentPtr - non struct", |
| 5403 | "@fieldParentPtr - non struct", | | |
| 5404 | \\const Foo = i32; | 4971 | \\const Foo = i32; |
| 5405 | \\export fn foo(a: *i32) *Foo { | 4972 | \\export fn foo(a: *i32) *Foo { |
| 5406 | \\ return @fieldParentPtr(Foo, "a", a); | 4973 | \\ return @fieldParentPtr(Foo, "a", a); |
| 5407 | \\} | 4974 | \\} |
| 5408 | , | 4975 | , &[_][]const u8{ |
| 5409 | "tmp.zig:3:28: error: expected struct type, found 'i32'", | 4976 | "tmp.zig:3:28: error: expected struct type, found 'i32'", |
| 5410 | ); | 4977 | }); |
| 5411 | | 4978 | |
| 5412 | cases.add( | 4979 | cases.add("@fieldParentPtr - bad field name", |
| 5413 | "@fieldParentPtr - bad field name", | | |
| 5414 | \\const Foo = extern struct { | 4980 | \\const Foo = extern struct { |
| 5415 | \\ derp: i32, | 4981 | \\ derp: i32, |
| 5416 | \\}; | 4982 | \\}; |
| 5417 | \\export fn foo(a: *i32) *Foo { | 4983 | \\export fn foo(a: *i32) *Foo { |
| 5418 | \\ return @fieldParentPtr(Foo, "a", a); | 4984 | \\ return @fieldParentPtr(Foo, "a", a); |
| 5419 | \\} | 4985 | \\} |
| 5420 | , | 4986 | , &[_][]const u8{ |
| 5421 | "tmp.zig:5:33: error: struct 'Foo' has no field 'a'", | 4987 | "tmp.zig:5:33: error: struct 'Foo' has no field 'a'", |
| 5422 | ); | 4988 | }); |
| 5423 | | 4989 | |
| 5424 | cases.add( | 4990 | cases.add("@fieldParentPtr - field pointer is not pointer", |
| 5425 | "@fieldParentPtr - field pointer is not pointer", | | |
| 5426 | \\const Foo = extern struct { | 4991 | \\const Foo = extern struct { |
| 5427 | \\ a: i32, | 4992 | \\ a: i32, |
| 5428 | \\}; | 4993 | \\}; |
| 5429 | \\export fn foo(a: i32) *Foo { | 4994 | \\export fn foo(a: i32) *Foo { |
| 5430 | \\ return @fieldParentPtr(Foo, "a", a); | 4995 | \\ return @fieldParentPtr(Foo, "a", a); |
| 5431 | \\} | 4996 | \\} |
| 5432 | , | 4997 | , &[_][]const u8{ |
| 5433 | "tmp.zig:5:38: error: expected pointer, found 'i32'", | 4998 | "tmp.zig:5:38: error: expected pointer, found 'i32'", |
| 5434 | ); | 4999 | }); |
| 5435 | | 5000 | |
| 5436 | cases.add( | 5001 | cases.add("@fieldParentPtr - comptime field ptr not based on struct", |
| 5437 | "@fieldParentPtr - comptime field ptr not based on struct", | | |
| 5438 | \\const Foo = struct { | 5002 | \\const Foo = struct { |
| 5439 | \\ a: i32, | 5003 | \\ a: i32, |
| 5440 | \\ b: i32, | 5004 | \\ b: i32, |
| ... | @@ -5445,12 +5009,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -5445,12 +5009,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5445 | \\ const field_ptr = @intToPtr(*i32, 0x1234); | 5009 | \\ const field_ptr = @intToPtr(*i32, 0x1234); |
| 5446 | \\ const another_foo_ptr = @fieldParentPtr(Foo, "b", field_ptr); | 5010 | \\ const another_foo_ptr = @fieldParentPtr(Foo, "b", field_ptr); |
| 5447 | \\} | 5011 | \\} |
| 5448 | , | 5012 | , &[_][]const u8{ |
| 5449 | "tmp.zig:9:55: error: pointer value not based on parent struct", | 5013 | "tmp.zig:9:55: error: pointer value not based on parent struct", |
| 5450 | ); | 5014 | }); |
| 5451 | | 5015 | |
| 5452 | cases.add( | 5016 | cases.add("@fieldParentPtr - comptime wrong field index", |
| 5453 | "@fieldParentPtr - comptime wrong field index", | | |
| 5454 | \\const Foo = struct { | 5017 | \\const Foo = struct { |
| 5455 | \\ a: i32, | 5018 | \\ a: i32, |
| 5456 | \\ b: i32, | 5019 | \\ b: i32, |
| ... | @@ -5460,80 +5023,72 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -5460,80 +5023,72 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5460 | \\comptime { | 5023 | \\comptime { |
| 5461 | \\ const another_foo_ptr = @fieldParentPtr(Foo, "b", &foo.a); | 5024 | \\ const another_foo_ptr = @fieldParentPtr(Foo, "b", &foo.a); |
| 5462 | \\} | 5025 | \\} |
| 5463 | , | 5026 | , &[_][]const u8{ |
| 5464 | "tmp.zig:8:29: error: field 'b' has index 1 but pointer value is index 0 of struct 'Foo'", | 5027 | "tmp.zig:8:29: error: field 'b' has index 1 but pointer value is index 0 of struct 'Foo'", |
| 5465 | ); | 5028 | }); |
| 5466 | | 5029 | |
| 5467 | cases.add( | 5030 | cases.add("@byteOffsetOf - non struct", |
| 5468 | "@byteOffsetOf - non struct", | | |
| 5469 | \\const Foo = i32; | 5031 | \\const Foo = i32; |
| 5470 | \\export fn foo() usize { | 5032 | \\export fn foo() usize { |
| 5471 | \\ return @byteOffsetOf(Foo, "a",); | 5033 | \\ return @byteOffsetOf(Foo, "a",); |
| 5472 | \\} | 5034 | \\} |
| 5473 | , | 5035 | , &[_][]const u8{ |
| 5474 | "tmp.zig:3:26: error: expected struct type, found 'i32'", | 5036 | "tmp.zig:3:26: error: expected struct type, found 'i32'", |
| 5475 | ); | 5037 | }); |
| 5476 | | 5038 | |
| 5477 | cases.add( | 5039 | cases.add("@byteOffsetOf - bad field name", |
| 5478 | "@byteOffsetOf - bad field name", | | |
| 5479 | \\const Foo = struct { | 5040 | \\const Foo = struct { |
| 5480 | \\ derp: i32, | 5041 | \\ derp: i32, |
| 5481 | \\}; | 5042 | \\}; |
| 5482 | \\export fn foo() usize { | 5043 | \\export fn foo() usize { |
| 5483 | \\ return @byteOffsetOf(Foo, "a",); | 5044 | \\ return @byteOffsetOf(Foo, "a",); |
| 5484 | \\} | 5045 | \\} |
| 5485 | , | 5046 | , &[_][]const u8{ |
| 5486 | "tmp.zig:5:31: error: struct 'Foo' has no field 'a'", | 5047 | "tmp.zig:5:31: error: struct 'Foo' has no field 'a'", |
| 5487 | ); | 5048 | }); |
| 5488 | | 5049 | |
| 5489 | cases.addExe( | 5050 | cases.addExe("missing main fn in executable", |
| 5490 | "missing main fn in executable", | | |
| 5491 | \\ | 5051 | \\ |
| 5492 | , | 5052 | , &[_][]const u8{ |
| 5493 | "error: root source file has no member called 'main'", | 5053 | "error: root source file has no member called 'main'", |
| 5494 | ); | 5054 | }); |
| 5495 | | 5055 | |
| 5496 | cases.addExe( | 5056 | cases.addExe("private main fn", |
| 5497 | "private main fn", | | |
| 5498 | \\fn main() void {} | 5057 | \\fn main() void {} |
| 5499 | , | 5058 | , &[_][]const u8{ |
| 5500 | "error: 'main' is private", | 5059 | "error: 'main' is private", |
| 5501 | "tmp.zig:1:1: note: declared here", | 5060 | "tmp.zig:1:1: note: declared here", |
| 5502 | ); | 5061 | }); |
| 5503 | | 5062 | |
| 5504 | cases.add( | 5063 | cases.add("setting a section on a local variable", |
| 5505 | "setting a section on a local variable", | | |
| 5506 | \\export fn entry() i32 { | 5064 | \\export fn entry() i32 { |
| 5507 | \\ var foo: i32 linksection(".text2") = 1234; | 5065 | \\ var foo: i32 linksection(".text2") = 1234; |
| 5508 | \\ return foo; | 5066 | \\ return foo; |
| 5509 | \\} | 5067 | \\} |
| 5510 | , | 5068 | , &[_][]const u8{ |
| 5511 | "tmp.zig:2:30: error: cannot set section of local variable 'foo'", | 5069 | "tmp.zig:2:30: error: cannot set section of local variable 'foo'", |
| 5512 | ); | 5070 | }); |
| 5513 | | 5071 | |
| 5514 | cases.add( | 5072 | cases.add("returning address of local variable - simple", |
| 5515 | "returning address of local variable - simple", | | |
| 5516 | \\export fn foo() *i32 { | 5073 | \\export fn foo() *i32 { |
| 5517 | \\ var a: i32 = undefined; | 5074 | \\ var a: i32 = undefined; |
| 5518 | \\ return &a; | 5075 | \\ return &a; |
| 5519 | \\} | 5076 | \\} |
| 5520 | , | 5077 | , &[_][]const u8{ |
| 5521 | "tmp.zig:3:13: error: function returns address of local variable", | 5078 | "tmp.zig:3:13: error: function returns address of local variable", |
| 5522 | ); | 5079 | }); |
| 5523 | | 5080 | |
| 5524 | cases.add( | 5081 | cases.add("returning address of local variable - phi", |
| 5525 | "returning address of local variable - phi", | | |
| 5526 | \\export fn foo(c: bool) *i32 { | 5082 | \\export fn foo(c: bool) *i32 { |
| 5527 | \\ var a: i32 = undefined; | 5083 | \\ var a: i32 = undefined; |
| 5528 | \\ var b: i32 = undefined; | 5084 | \\ var b: i32 = undefined; |
| 5529 | \\ return if (c) &a else &b; | 5085 | \\ return if (c) &a else &b; |
| 5530 | \\} | 5086 | \\} |
| 5531 | , | 5087 | , &[_][]const u8{ |
| 5532 | "tmp.zig:4:12: error: function returns address of local variable", | 5088 | "tmp.zig:4:12: error: function returns address of local variable", |
| 5533 | ); | 5089 | }); |
| 5534 | | 5090 | |
| 5535 | cases.add( | 5091 | cases.add("inner struct member shadowing outer struct member", |
| 5536 | "inner struct member shadowing outer struct member", | | |
| 5537 | \\fn A() type { | 5092 | \\fn A() type { |
| 5538 | \\ return struct { | 5093 | \\ return struct { |
| 5539 | \\ b: B(), | 5094 | \\ b: B(), |
| ... | @@ -5553,73 +5108,66 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -5553,73 +5108,66 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5553 | \\fn assert(ok: bool) void { | 5108 | \\fn assert(ok: bool) void { |
| 5554 | \\ if (!ok) unreachable; | 5109 | \\ if (!ok) unreachable; |
| 5555 | \\} | 5110 | \\} |
| 5556 | , | 5111 | , &[_][]const u8{ |
| 5557 | "tmp.zig:9:17: error: redefinition of 'Self'", | 5112 | "tmp.zig:9:17: error: redefinition of 'Self'", |
| 5558 | "tmp.zig:5:9: note: previous definition is here", | 5113 | "tmp.zig:5:9: note: previous definition is here", |
| 5559 | ); | 5114 | }); |
| 5560 | | 5115 | |
| 5561 | cases.add( | 5116 | cases.add("while expected bool, got optional", |
| 5562 | "while expected bool, got optional", | | |
| 5563 | \\export fn foo() void { | 5117 | \\export fn foo() void { |
| 5564 | \\ while (bar()) {} | 5118 | \\ while (bar()) {} |
| 5565 | \\} | 5119 | \\} |
| 5566 | \\fn bar() ?i32 { return 1; } | 5120 | \\fn bar() ?i32 { return 1; } |
| 5567 | , | 5121 | , &[_][]const u8{ |
| 5568 | "tmp.zig:2:15: error: expected type 'bool', found '?i32'", | 5122 | "tmp.zig:2:15: error: expected type 'bool', found '?i32'", |
| 5569 | ); | 5123 | }); |
| 5570 | | 5124 | |
| 5571 | cases.add( | 5125 | cases.add("while expected bool, got error union", |
| 5572 | "while expected bool, got error union", | | |
| 5573 | \\export fn foo() void { | 5126 | \\export fn foo() void { |
| 5574 | \\ while (bar()) {} | 5127 | \\ while (bar()) {} |
| 5575 | \\} | 5128 | \\} |
| 5576 | \\fn bar() anyerror!i32 { return 1; } | 5129 | \\fn bar() anyerror!i32 { return 1; } |
| 5577 | , | 5130 | , &[_][]const u8{ |
| 5578 | "tmp.zig:2:15: error: expected type 'bool', found 'anyerror!i32'", | 5131 | "tmp.zig:2:15: error: expected type 'bool', found 'anyerror!i32'", |
| 5579 | ); | 5132 | }); |
| 5580 | | 5133 | |
| 5581 | cases.add( | 5134 | cases.add("while expected optional, got bool", |
| 5582 | "while expected optional, got bool", | | |
| 5583 | \\export fn foo() void { | 5135 | \\export fn foo() void { |
| 5584 | \\ while (bar()) |x| {} | 5136 | \\ while (bar()) |x| {} |
| 5585 | \\} | 5137 | \\} |
| 5586 | \\fn bar() bool { return true; } | 5138 | \\fn bar() bool { return true; } |
| 5587 | , | 5139 | , &[_][]const u8{ |
| 5588 | "tmp.zig:2:15: error: expected optional type, found 'bool'", | 5140 | "tmp.zig:2:15: error: expected optional type, found 'bool'", |
| 5589 | ); | 5141 | }); |
| 5590 | | 5142 | |
| 5591 | cases.add( | 5143 | cases.add("while expected optional, got error union", |
| 5592 | "while expected optional, got error union", | | |
| 5593 | \\export fn foo() void { | 5144 | \\export fn foo() void { |
| 5594 | \\ while (bar()) |x| {} | 5145 | \\ while (bar()) |x| {} |
| 5595 | \\} | 5146 | \\} |
| 5596 | \\fn bar() anyerror!i32 { return 1; } | 5147 | \\fn bar() anyerror!i32 { return 1; } |
| 5597 | , | 5148 | , &[_][]const u8{ |
| 5598 | "tmp.zig:2:15: error: expected optional type, found 'anyerror!i32'", | 5149 | "tmp.zig:2:15: error: expected optional type, found 'anyerror!i32'", |
| 5599 | ); | 5150 | }); |
| 5600 | | 5151 | |
| 5601 | cases.add( | 5152 | cases.add("while expected error union, got bool", |
| 5602 | "while expected error union, got bool", | | |
| 5603 | \\export fn foo() void { | 5153 | \\export fn foo() void { |
| 5604 | \\ while (bar()) |x| {} else |err| {} | 5154 | \\ while (bar()) |x| {} else |err| {} |
| 5605 | \\} | 5155 | \\} |
| 5606 | \\fn bar() bool { return true; } | 5156 | \\fn bar() bool { return true; } |
| 5607 | , | 5157 | , &[_][]const u8{ |
| 5608 | "tmp.zig:2:15: error: expected error union type, found 'bool'", | 5158 | "tmp.zig:2:15: error: expected error union type, found 'bool'", |
| 5609 | ); | 5159 | }); |
| 5610 | | 5160 | |
| 5611 | cases.add( | 5161 | cases.add("while expected error union, got optional", |
| 5612 | "while expected error union, got optional", | | |
| 5613 | \\export fn foo() void { | 5162 | \\export fn foo() void { |
| 5614 | \\ while (bar()) |x| {} else |err| {} | 5163 | \\ while (bar()) |x| {} else |err| {} |
| 5615 | \\} | 5164 | \\} |
| 5616 | \\fn bar() ?i32 { return 1; } | 5165 | \\fn bar() ?i32 { return 1; } |
| 5617 | , | 5166 | , &[_][]const u8{ |
| 5618 | "tmp.zig:2:15: error: expected error union type, found '?i32'", | 5167 | "tmp.zig:2:15: error: expected error union type, found '?i32'", |
| 5619 | ); | 5168 | }); |
| 5620 | | 5169 | |
| 5621 | cases.add( | 5170 | cases.add("inline fn calls itself indirectly", |
| 5622 | "inline fn calls itself indirectly", | | |
| 5623 | \\export fn foo() void { | 5171 | \\export fn foo() void { |
| 5624 | \\ bar(); | 5172 | \\ bar(); |
| 5625 | \\} | 5173 | \\} |
| ... | @@ -5632,94 +5180,85 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -5632,94 +5180,85 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5632 | \\ quux(); | 5180 | \\ quux(); |
| 5633 | \\} | 5181 | \\} |
| 5634 | \\extern fn quux() void; | 5182 | \\extern fn quux() void; |
| 5635 | , | 5183 | , &[_][]const u8{ |
| 5636 | "tmp.zig:4:1: error: unable to inline function", | 5184 | "tmp.zig:4:1: error: unable to inline function", |
| 5637 | ); | 5185 | }); |
| 5638 | | 5186 | |
| 5639 | cases.add( | 5187 | cases.add("save reference to inline function", |
| 5640 | "save reference to inline function", | | |
| 5641 | \\export fn foo() void { | 5188 | \\export fn foo() void { |
| 5642 | \\ quux(@ptrToInt(bar)); | 5189 | \\ quux(@ptrToInt(bar)); |
| 5643 | \\} | 5190 | \\} |
| 5644 | \\inline fn bar() void { } | 5191 | \\inline fn bar() void { } |
| 5645 | \\extern fn quux(usize) void; | 5192 | \\extern fn quux(usize) void; |
| 5646 | , | 5193 | , &[_][]const u8{ |
| 5647 | "tmp.zig:4:1: error: unable to inline function", | 5194 | "tmp.zig:4:1: error: unable to inline function", |
| 5648 | ); | 5195 | }); |
| 5649 | | 5196 | |
| 5650 | cases.add( | 5197 | cases.add("signed integer division", |
| 5651 | "signed integer division", | | |
| 5652 | \\export fn foo(a: i32, b: i32) i32 { | 5198 | \\export fn foo(a: i32, b: i32) i32 { |
| 5653 | \\ return a / b; | 5199 | \\ return a / b; |
| 5654 | \\} | 5200 | \\} |
| 5655 | , | 5201 | , &[_][]const u8{ |
| 5656 | "tmp.zig:2:14: error: division with 'i32' and 'i32': signed integers must use @divTrunc, @divFloor, or @divExact", | 5202 | "tmp.zig:2:14: error: division with 'i32' and 'i32': signed integers must use @divTrunc, @divFloor, or @divExact", |
| 5657 | ); | 5203 | }); |
| 5658 | | 5204 | |
| 5659 | cases.add( | 5205 | cases.add("signed integer remainder division", |
| 5660 | "signed integer remainder division", | | |
| 5661 | \\export fn foo(a: i32, b: i32) i32 { | 5206 | \\export fn foo(a: i32, b: i32) i32 { |
| 5662 | \\ return a % b; | 5207 | \\ return a % b; |
| 5663 | \\} | 5208 | \\} |
| 5664 | , | 5209 | , &[_][]const u8{ |
| 5665 | "tmp.zig:2:14: error: remainder division with 'i32' and 'i32': signed integers and floats must use @rem or @mod", | 5210 | "tmp.zig:2:14: error: remainder division with 'i32' and 'i32': signed integers and floats must use @rem or @mod", |
| 5666 | ); | 5211 | }); |
| 5667 | | 5212 | |
| 5668 | cases.add( | 5213 | cases.add("compile-time division by zero", |
| 5669 | "compile-time division by zero", | | |
| 5670 | \\comptime { | 5214 | \\comptime { |
| 5671 | \\ const a: i32 = 1; | 5215 | \\ const a: i32 = 1; |
| 5672 | \\ const b: i32 = 0; | 5216 | \\ const b: i32 = 0; |
| 5673 | \\ const c = a / b; | 5217 | \\ const c = a / b; |
| 5674 | \\} | 5218 | \\} |
| 5675 | , | 5219 | , &[_][]const u8{ |
| 5676 | "tmp.zig:4:17: error: division by zero", | 5220 | "tmp.zig:4:17: error: division by zero", |
| 5677 | ); | 5221 | }); |
| 5678 | | 5222 | |
| 5679 | cases.add( | 5223 | cases.add("compile-time remainder division by zero", |
| 5680 | "compile-time remainder division by zero", | | |
| 5681 | \\comptime { | 5224 | \\comptime { |
| 5682 | \\ const a: i32 = 1; | 5225 | \\ const a: i32 = 1; |
| 5683 | \\ const b: i32 = 0; | 5226 | \\ const b: i32 = 0; |
| 5684 | \\ const c = a % b; | 5227 | \\ const c = a % b; |
| 5685 | \\} | 5228 | \\} |
| 5686 | , | 5229 | , &[_][]const u8{ |
| 5687 | "tmp.zig:4:17: error: division by zero", | 5230 | "tmp.zig:4:17: error: division by zero", |
| 5688 | ); | 5231 | }); |
| 5689 | | 5232 | |
| 5690 | cases.add( | 5233 | cases.add("@setRuntimeSafety twice for same scope", |
| 5691 | "@setRuntimeSafety twice for same scope", | | |
| 5692 | \\export fn foo() void { | 5234 | \\export fn foo() void { |
| 5693 | \\ @setRuntimeSafety(false); | 5235 | \\ @setRuntimeSafety(false); |
| 5694 | \\ @setRuntimeSafety(false); | 5236 | \\ @setRuntimeSafety(false); |
| 5695 | \\} | 5237 | \\} |
| 5696 | , | 5238 | , &[_][]const u8{ |
| 5697 | "tmp.zig:3:5: error: runtime safety set twice for same scope", | 5239 | "tmp.zig:3:5: error: runtime safety set twice for same scope", |
| 5698 | "tmp.zig:2:5: note: first set here", | 5240 | "tmp.zig:2:5: note: first set here", |
| 5699 | ); | 5241 | }); |
| 5700 | | 5242 | |
| 5701 | cases.add( | 5243 | cases.add("@setFloatMode twice for same scope", |
| 5702 | "@setFloatMode twice for same scope", | | |
| 5703 | \\export fn foo() void { | 5244 | \\export fn foo() void { |
| 5704 | \\ @setFloatMode(@import("builtin").FloatMode.Optimized); | 5245 | \\ @setFloatMode(@import("builtin").FloatMode.Optimized); |
| 5705 | \\ @setFloatMode(@import("builtin").FloatMode.Optimized); | 5246 | \\ @setFloatMode(@import("builtin").FloatMode.Optimized); |
| 5706 | \\} | 5247 | \\} |
| 5707 | , | 5248 | , &[_][]const u8{ |
| 5708 | "tmp.zig:3:5: error: float mode set twice for same scope", | 5249 | "tmp.zig:3:5: error: float mode set twice for same scope", |
| 5709 | "tmp.zig:2:5: note: first set here", | 5250 | "tmp.zig:2:5: note: first set here", |
| 5710 | ); | 5251 | }); |
| 5711 | | 5252 | |
| 5712 | cases.add( | 5253 | cases.add("array access of type", |
| 5713 | "array access of type", | | |
| 5714 | \\export fn foo() void { | 5254 | \\export fn foo() void { |
| 5715 | \\ var b: u8[40] = undefined; | 5255 | \\ var b: u8[40] = undefined; |
| 5716 | \\} | 5256 | \\} |
| 5717 | , | 5257 | , &[_][]const u8{ |
| 5718 | "tmp.zig:2:14: error: array access of non-array type 'type'", | 5258 | "tmp.zig:2:14: error: array access of non-array type 'type'", |
| 5719 | ); | 5259 | }); |
| 5720 | | 5260 | |
| 5721 | cases.add( | 5261 | cases.add("cannot break out of defer expression", |
| 5722 | "cannot break out of defer expression", | | |
| 5723 | \\export fn foo() void { | 5262 | \\export fn foo() void { |
| 5724 | \\ while (true) { | 5263 | \\ while (true) { |
| 5725 | \\ defer { | 5264 | \\ defer { |
| ... | @@ -5727,12 +5266,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -5727,12 +5266,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5727 | \\ } | 5266 | \\ } |
| 5728 | \\ } | 5267 | \\ } |
| 5729 | \\} | 5268 | \\} |
| 5730 | , | 5269 | , &[_][]const u8{ |
| 5731 | "tmp.zig:4:13: error: cannot break out of defer expression", | 5270 | "tmp.zig:4:13: error: cannot break out of defer expression", |
| 5732 | ); | 5271 | }); |
| 5733 | | 5272 | |
| 5734 | cases.add( | 5273 | cases.add("cannot continue out of defer expression", |
| 5735 | "cannot continue out of defer expression", | | |
| 5736 | \\export fn foo() void { | 5274 | \\export fn foo() void { |
| 5737 | \\ while (true) { | 5275 | \\ while (true) { |
| 5738 | \\ defer { | 5276 | \\ defer { |
| ... | @@ -5740,26 +5278,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -5740,26 +5278,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5740 | \\ } | 5278 | \\ } |
| 5741 | \\ } | 5279 | \\ } |
| 5742 | \\} | 5280 | \\} |
| 5743 | , | 5281 | , &[_][]const u8{ |
| 5744 | "tmp.zig:4:13: error: cannot continue out of defer expression", | 5282 | "tmp.zig:4:13: error: cannot continue out of defer expression", |
| 5745 | ); | 5283 | }); |
| 5746 | | | |
| 5747 | cases.add( | | |
| 5748 | "calling a var args function only known at runtime", | | |
| 5749 | \\var foos = [_]fn(...) void { foo1, foo2 }; | | |
| 5750 | \\ | | |
| 5751 | \\fn foo1(args: ...) void {} | | |
| 5752 | \\fn foo2(args: ...) void {} | | |
| 5753 | \\ | | |
| 5754 | \\pub fn main() !void { | | |
| 5755 | \\ foos[0](); | | |
| 5756 | \\} | | |
| 5757 | , | | |
| 5758 | "tmp.zig:7:9: error: calling a generic function requires compile-time known function value", | | |
| 5759 | ); | | |
| 5760 | | 5284 | |
| 5761 | cases.add( | 5285 | cases.add("calling a generic function only known at runtime", |
| 5762 | "calling a generic function only known at runtime", | | |
| 5763 | \\var foos = [_]fn(var) void { foo1, foo2 }; | 5286 | \\var foos = [_]fn(var) void { foo1, foo2 }; |
| 5764 | \\ | 5287 | \\ |
| 5765 | \\fn foo1(arg: var) void {} | 5288 | \\fn foo1(arg: var) void {} |
| ... | @@ -5768,12 +5291,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -5768,12 +5291,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5768 | \\pub fn main() !void { | 5291 | \\pub fn main() !void { |
| 5769 | \\ foos[0](true); | 5292 | \\ foos[0](true); |
| 5770 | \\} | 5293 | \\} |
| 5771 | , | 5294 | , &[_][]const u8{ |
| 5772 | "tmp.zig:7:9: error: calling a generic function requires compile-time known function value", | 5295 | "tmp.zig:7:9: error: calling a generic function requires compile-time known function value", |
| 5773 | ); | 5296 | }); |
| 5774 | | 5297 | |
| 5775 | cases.add( | 5298 | cases.add("@compileError shows traceback of references that caused it", |
| 5776 | "@compileError shows traceback of references that caused it", | | |
| 5777 | \\const foo = @compileError("aoeu",); | 5299 | \\const foo = @compileError("aoeu",); |
| 5778 | \\ | 5300 | \\ |
| 5779 | \\const bar = baz + foo; | 5301 | \\const bar = baz + foo; |
| ... | @@ -5782,96 +5304,86 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -5782,96 +5304,86 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5782 | \\export fn entry() i32 { | 5304 | \\export fn entry() i32 { |
| 5783 | \\ return bar; | 5305 | \\ return bar; |
| 5784 | \\} | 5306 | \\} |
| 5785 | , | 5307 | , &[_][]const u8{ |
| 5786 | "tmp.zig:1:13: error: aoeu", | 5308 | "tmp.zig:1:13: error: aoeu", |
| 5787 | "tmp.zig:3:19: note: referenced here", | 5309 | "tmp.zig:3:19: note: referenced here", |
| 5788 | "tmp.zig:7:12: note: referenced here", | 5310 | "tmp.zig:7:12: note: referenced here", |
| 5789 | ); | 5311 | }); |
| 5790 | | 5312 | |
| 5791 | cases.add( | 5313 | cases.add("float literal too large error", |
| 5792 | "float literal too large error", | | |
| 5793 | \\comptime { | 5314 | \\comptime { |
| 5794 | \\ const a = 0x1.0p18495; | 5315 | \\ const a = 0x1.0p18495; |
| 5795 | \\} | 5316 | \\} |
| 5796 | , | 5317 | , &[_][]const u8{ |
| 5797 | "tmp.zig:2:15: error: float literal out of range of any type", | 5318 | "tmp.zig:2:15: error: float literal out of range of any type", |
| 5798 | ); | 5319 | }); |
| 5799 | | 5320 | |
| 5800 | cases.add( | 5321 | cases.add("float literal too small error (denormal)", |
| 5801 | "float literal too small error (denormal)", | | |
| 5802 | \\comptime { | 5322 | \\comptime { |
| 5803 | \\ const a = 0x1.0p-19000; | 5323 | \\ const a = 0x1.0p-19000; |
| 5804 | \\} | 5324 | \\} |
| 5805 | , | 5325 | , &[_][]const u8{ |
| 5806 | "tmp.zig:2:15: error: float literal out of range of any type", | 5326 | "tmp.zig:2:15: error: float literal out of range of any type", |
| 5807 | ); | 5327 | }); |
| 5808 | | 5328 | |
| 5809 | cases.add( | 5329 | cases.add("explicit cast float literal to integer when there is a fraction component", |
| 5810 | "explicit cast float literal to integer when there is a fraction component", | | |
| 5811 | \\export fn entry() i32 { | 5330 | \\export fn entry() i32 { |
| 5812 | \\ return @as(i32, 12.34); | 5331 | \\ return @as(i32, 12.34); |
| 5813 | \\} | 5332 | \\} |
| 5814 | , | 5333 | , &[_][]const u8{ |
| 5815 | "tmp.zig:2:21: error: fractional component prevents float value 12.340000 from being casted to type 'i32'", | 5334 | "tmp.zig:2:21: error: fractional component prevents float value 12.340000 from being casted to type 'i32'", |
| 5816 | ); | 5335 | }); |
| 5817 | | 5336 | |
| 5818 | cases.add( | 5337 | cases.add("non pointer given to @ptrToInt", |
| 5819 | "non pointer given to @ptrToInt", | | |
| 5820 | \\export fn entry(x: i32) usize { | 5338 | \\export fn entry(x: i32) usize { |
| 5821 | \\ return @ptrToInt(x); | 5339 | \\ return @ptrToInt(x); |
| 5822 | \\} | 5340 | \\} |
| 5823 | , | 5341 | , &[_][]const u8{ |
| 5824 | "tmp.zig:2:22: error: expected pointer, found 'i32'", | 5342 | "tmp.zig:2:22: error: expected pointer, found 'i32'", |
| 5825 | ); | 5343 | }); |
| 5826 | | 5344 | |
| 5827 | cases.add( | 5345 | cases.add("@shlExact shifts out 1 bits", |
| 5828 | "@shlExact shifts out 1 bits", | | |
| 5829 | \\comptime { | 5346 | \\comptime { |
| 5830 | \\ const x = @shlExact(@as(u8, 0b01010101), 2); | 5347 | \\ const x = @shlExact(@as(u8, 0b01010101), 2); |
| 5831 | \\} | 5348 | \\} |
| 5832 | , | 5349 | , &[_][]const u8{ |
| 5833 | "tmp.zig:2:15: error: operation caused overflow", | 5350 | "tmp.zig:2:15: error: operation caused overflow", |
| 5834 | ); | 5351 | }); |
| 5835 | | 5352 | |
| 5836 | cases.add( | 5353 | cases.add("@shrExact shifts out 1 bits", |
| 5837 | "@shrExact shifts out 1 bits", | | |
| 5838 | \\comptime { | 5354 | \\comptime { |
| 5839 | \\ const x = @shrExact(@as(u8, 0b10101010), 2); | 5355 | \\ const x = @shrExact(@as(u8, 0b10101010), 2); |
| 5840 | \\} | 5356 | \\} |
| 5841 | , | 5357 | , &[_][]const u8{ |
| 5842 | "tmp.zig:2:15: error: exact shift shifted out 1 bits", | 5358 | "tmp.zig:2:15: error: exact shift shifted out 1 bits", |
| 5843 | ); | 5359 | }); |
| 5844 | | 5360 | |
| 5845 | cases.add( | 5361 | cases.add("shifting without int type or comptime known", |
| 5846 | "shifting without int type or comptime known", | | |
| 5847 | \\export fn entry(x: u8) u8 { | 5362 | \\export fn entry(x: u8) u8 { |
| 5848 | \\ return 0x11 << x; | 5363 | \\ return 0x11 << x; |
| 5849 | \\} | 5364 | \\} |
| 5850 | , | 5365 | , &[_][]const u8{ |
| 5851 | "tmp.zig:2:17: error: LHS of shift must be an integer type, or RHS must be compile-time known", | 5366 | "tmp.zig:2:17: error: LHS of shift must be an integer type, or RHS must be compile-time known", |
| 5852 | ); | 5367 | }); |
| 5853 | | 5368 | |
| 5854 | cases.add( | 5369 | cases.add("shifting RHS is log2 of LHS int bit width", |
| 5855 | "shifting RHS is log2 of LHS int bit width", | | |
| 5856 | \\export fn entry(x: u8, y: u8) u8 { | 5370 | \\export fn entry(x: u8, y: u8) u8 { |
| 5857 | \\ return x << y; | 5371 | \\ return x << y; |
| 5858 | \\} | 5372 | \\} |
| 5859 | , | 5373 | , &[_][]const u8{ |
| 5860 | "tmp.zig:2:17: error: expected type 'u3', found 'u8'", | 5374 | "tmp.zig:2:17: error: expected type 'u3', found 'u8'", |
| 5861 | ); | 5375 | }); |
| 5862 | | 5376 | |
| 5863 | cases.add( | 5377 | cases.add("globally shadowing a primitive type", |
| 5864 | "globally shadowing a primitive type", | | |
| 5865 | \\const u16 = @intType(false, 8); | 5378 | \\const u16 = @intType(false, 8); |
| 5866 | \\export fn entry() void { | 5379 | \\export fn entry() void { |
| 5867 | \\ const a: u16 = 300; | 5380 | \\ const a: u16 = 300; |
| 5868 | \\} | 5381 | \\} |
| 5869 | , | 5382 | , &[_][]const u8{ |
| 5870 | "tmp.zig:1:1: error: declaration shadows primitive type 'u16'", | 5383 | "tmp.zig:1:1: error: declaration shadows primitive type 'u16'", |
| 5871 | ); | 5384 | }); |
| 5872 | | 5385 | |
| 5873 | cases.add( | 5386 | cases.add("implicitly increasing pointer alignment", |
| 5874 | "implicitly increasing pointer alignment", | | |
| 5875 | \\const Foo = packed struct { | 5387 | \\const Foo = packed struct { |
| 5876 | \\ a: u8, | 5388 | \\ a: u8, |
| 5877 | \\ b: u32, | 5389 | \\ b: u32, |
| ... | @@ -5885,12 +5397,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -5885,12 +5397,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5885 | \\fn bar(x: *u32) void { | 5397 | \\fn bar(x: *u32) void { |
| 5886 | \\ x.* += 1; | 5398 | \\ x.* += 1; |
| 5887 | \\} | 5399 | \\} |
| 5888 | , | 5400 | , &[_][]const u8{ |
| 5889 | "tmp.zig:8:13: error: expected type '*u32', found '*align(1) u32'", | 5401 | "tmp.zig:8:13: error: expected type '*u32', found '*align(1) u32'", |
| 5890 | ); | 5402 | }); |
| 5891 | | 5403 | |
| 5892 | cases.add( | 5404 | cases.add("implicitly increasing slice alignment", |
| 5893 | "implicitly increasing slice alignment", | | |
| 5894 | \\const Foo = packed struct { | 5405 | \\const Foo = packed struct { |
| 5895 | \\ a: u8, | 5406 | \\ a: u8, |
| 5896 | \\ b: u32, | 5407 | \\ b: u32, |
| ... | @@ -5905,36 +5416,33 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -5905,36 +5416,33 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5905 | \\fn bar(x: []u32) void { | 5416 | \\fn bar(x: []u32) void { |
| 5906 | \\ x[0] += 1; | 5417 | \\ x[0] += 1; |
| 5907 | \\} | 5418 | \\} |
| 5908 | , | 5419 | , &[_][]const u8{ |
| 5909 | "tmp.zig:9:26: error: cast increases pointer alignment", | 5420 | "tmp.zig:9:26: error: cast increases pointer alignment", |
| 5910 | "tmp.zig:9:26: note: '*align(1) u32' has alignment 1", | 5421 | "tmp.zig:9:26: note: '*align(1) u32' has alignment 1", |
| 5911 | "tmp.zig:9:26: note: '*[1]u32' has alignment 4", | 5422 | "tmp.zig:9:26: note: '*[1]u32' has alignment 4", |
| 5912 | ); | 5423 | }); |
| 5913 | | 5424 | |
| 5914 | cases.add( | 5425 | cases.add("increase pointer alignment in @ptrCast", |
| 5915 | "increase pointer alignment in @ptrCast", | | |
| 5916 | \\export fn entry() u32 { | 5426 | \\export fn entry() u32 { |
| 5917 | \\ var bytes: [4]u8 = [_]u8{0x01, 0x02, 0x03, 0x04}; | 5427 | \\ var bytes: [4]u8 = [_]u8{0x01, 0x02, 0x03, 0x04}; |
| 5918 | \\ const ptr = @ptrCast(*u32, &bytes[0]); | 5428 | \\ const ptr = @ptrCast(*u32, &bytes[0]); |
| 5919 | \\ return ptr.*; | 5429 | \\ return ptr.*; |
| 5920 | \\} | 5430 | \\} |
| 5921 | , | 5431 | , &[_][]const u8{ |
| 5922 | "tmp.zig:3:17: error: cast increases pointer alignment", | 5432 | "tmp.zig:3:17: error: cast increases pointer alignment", |
| 5923 | "tmp.zig:3:38: note: '*u8' has alignment 1", | 5433 | "tmp.zig:3:38: note: '*u8' has alignment 1", |
| 5924 | "tmp.zig:3:26: note: '*u32' has alignment 4", | 5434 | "tmp.zig:3:26: note: '*u32' has alignment 4", |
| 5925 | ); | 5435 | }); |
| 5926 | | 5436 | |
| 5927 | cases.add( | 5437 | cases.add("@alignCast expects pointer or slice", |
| 5928 | "@alignCast expects pointer or slice", | | |
| 5929 | \\export fn entry() void { | 5438 | \\export fn entry() void { |
| 5930 | \\ @alignCast(4, @as(u32, 3)); | 5439 | \\ @alignCast(4, @as(u32, 3)); |
| 5931 | \\} | 5440 | \\} |
| 5932 | , | 5441 | , &[_][]const u8{ |
| 5933 | "tmp.zig:2:19: error: expected pointer or slice, found 'u32'", | 5442 | "tmp.zig:2:19: error: expected pointer or slice, found 'u32'", |
| 5934 | ); | 5443 | }); |
| 5935 | | 5444 | |
| 5936 | cases.add( | 5445 | cases.add("passing an under-aligned function pointer", |
| 5937 | "passing an under-aligned function pointer", | | |
| 5938 | \\export fn entry() void { | 5446 | \\export fn entry() void { |
| 5939 | \\ testImplicitlyDecreaseFnAlign(alignedSmall, 1234); | 5447 | \\ testImplicitlyDecreaseFnAlign(alignedSmall, 1234); |
| 5940 | \\} | 5448 | \\} |
| ... | @@ -5942,45 +5450,41 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -5942,45 +5450,41 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5942 | \\ if (ptr() != answer) unreachable; | 5450 | \\ if (ptr() != answer) unreachable; |
| 5943 | \\} | 5451 | \\} |
| 5944 | \\fn alignedSmall() align(4) i32 { return 1234; } | 5452 | \\fn alignedSmall() align(4) i32 { return 1234; } |
| 5945 | , | 5453 | , &[_][]const u8{ |
| 5946 | "tmp.zig:2:35: error: expected type 'fn() align(8) i32', found 'fn() align(4) i32'", | 5454 | "tmp.zig:2:35: error: expected type 'fn() align(8) i32', found 'fn() align(4) i32'", |
| 5947 | ); | 5455 | }); |
| 5948 | | 5456 | |
| 5949 | cases.add( | 5457 | cases.add("passing a not-aligned-enough pointer to cmpxchg", |
| 5950 | "passing a not-aligned-enough pointer to cmpxchg", | | |
| 5951 | \\const AtomicOrder = @import("builtin").AtomicOrder; | 5458 | \\const AtomicOrder = @import("builtin").AtomicOrder; |
| 5952 | \\export fn entry() bool { | 5459 | \\export fn entry() bool { |
| 5953 | \\ var x: i32 align(1) = 1234; | 5460 | \\ var x: i32 align(1) = 1234; |
| 5954 | \\ while (!@cmpxchgWeak(i32, &x, 1234, 5678, AtomicOrder.SeqCst, AtomicOrder.SeqCst)) {} | 5461 | \\ while (!@cmpxchgWeak(i32, &x, 1234, 5678, AtomicOrder.SeqCst, AtomicOrder.SeqCst)) {} |
| 5955 | \\ return x == 5678; | 5462 | \\ return x == 5678; |
| 5956 | \\} | 5463 | \\} |
| 5957 | , | 5464 | , &[_][]const u8{ |
| 5958 | "tmp.zig:4:32: error: expected type '*i32', found '*align(1) i32'", | 5465 | "tmp.zig:4:32: error: expected type '*i32', found '*align(1) i32'", |
| 5959 | ); | 5466 | }); |
| 5960 | | 5467 | |
| 5961 | cases.add( | 5468 | cases.add("wrong size to an array literal", |
| 5962 | "wrong size to an array literal", | | |
| 5963 | \\comptime { | 5469 | \\comptime { |
| 5964 | \\ const array = [2]u8{1, 2, 3}; | 5470 | \\ const array = [2]u8{1, 2, 3}; |
| 5965 | \\} | 5471 | \\} |
| 5966 | , | 5472 | , &[_][]const u8{ |
| 5967 | "tmp.zig:2:31: error: index 2 outside array of size 2", | 5473 | "tmp.zig:2:31: error: index 2 outside array of size 2", |
| 5968 | ); | 5474 | }); |
| 5969 | | 5475 | |
| 5970 | cases.add( | 5476 | cases.add("wrong pointer coerced to pointer to @OpaqueType()", |
| 5971 | "wrong pointer coerced to pointer to @OpaqueType()", | | |
| 5972 | \\const Derp = @OpaqueType(); | 5477 | \\const Derp = @OpaqueType(); |
| 5973 | \\extern fn bar(d: *Derp) void; | 5478 | \\extern fn bar(d: *Derp) void; |
| 5974 | \\export fn foo() void { | 5479 | \\export fn foo() void { |
| 5975 | \\ var x = @as(u8, 1); | 5480 | \\ var x = @as(u8, 1); |
| 5976 | \\ bar(@ptrCast(*c_void, &x)); | 5481 | \\ bar(@ptrCast(*c_void, &x)); |
| 5977 | \\} | 5482 | \\} |
| 5978 | , | 5483 | , &[_][]const u8{ |
| 5979 | "tmp.zig:5:9: error: expected type '*Derp', found '*c_void'", | 5484 | "tmp.zig:5:9: error: expected type '*Derp', found '*c_void'", |
| 5980 | ); | 5485 | }); |
| 5981 | | 5486 | |
| 5982 | cases.add( | 5487 | cases.add("non-const variables of things that require const variables", |
| 5983 | "non-const variables of things that require const variables", | | |
| 5984 | \\export fn entry1() void { | 5488 | \\export fn entry1() void { |
| 5985 | \\ var m2 = &2; | 5489 | \\ var m2 = &2; |
| 5986 | \\} | 5490 | \\} |
| ... | @@ -6012,7 +5516,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -6012,7 +5516,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6012 | \\const Foo = struct { | 5516 | \\const Foo = struct { |
| 6013 | \\ fn bar(self: *const Foo) void {} | 5517 | \\ fn bar(self: *const Foo) void {} |
| 6014 | \\}; | 5518 | \\}; |
| 6015 | , | 5519 | , &[_][]const u8{ |
| 6016 | "tmp.zig:2:4: error: variable of type '*comptime_int' must be const or comptime", | 5520 | "tmp.zig:2:4: error: variable of type '*comptime_int' must be const or comptime", |
| 6017 | "tmp.zig:5:4: error: variable of type '(undefined)' must be const or comptime", | 5521 | "tmp.zig:5:4: error: variable of type '(undefined)' must be const or comptime", |
| 6018 | "tmp.zig:8:4: error: variable of type 'comptime_int' must be const or comptime", | 5522 | "tmp.zig:8:4: error: variable of type 'comptime_int' must be const or comptime", |
| ... | @@ -6022,30 +5526,27 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -6022,30 +5526,27 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6022 | "tmp.zig:20:4: error: variable of type 'type' must be const or comptime", | 5526 | "tmp.zig:20:4: error: variable of type 'type' must be const or comptime", |
| 6023 | "tmp.zig:23:4: error: variable of type '(bound fn(*const Foo) void)' must be const or comptime", | 5527 | "tmp.zig:23:4: error: variable of type '(bound fn(*const Foo) void)' must be const or comptime", |
| 6024 | "tmp.zig:26:22: error: unreachable code", | 5528 | "tmp.zig:26:22: error: unreachable code", |
| 6025 | ); | 5529 | }); |
| 6026 | | 5530 | |
| 6027 | cases.add( | 5531 | cases.add("wrong types given to atomic order args in cmpxchg", |
| 6028 | "wrong types given to atomic order args in cmpxchg", | | |
| 6029 | \\export fn entry() void { | 5532 | \\export fn entry() void { |
| 6030 | \\ var x: i32 = 1234; | 5533 | \\ var x: i32 = 1234; |
| 6031 | \\ while (!@cmpxchgWeak(i32, &x, 1234, 5678, @as(u32, 1234), @as(u32, 1234))) {} | 5534 | \\ while (!@cmpxchgWeak(i32, &x, 1234, 5678, @as(u32, 1234), @as(u32, 1234))) {} |
| 6032 | \\} | 5535 | \\} |
| 6033 | , | 5536 | , &[_][]const u8{ |
| 6034 | "tmp.zig:3:47: error: expected type 'std.builtin.AtomicOrder', found 'u32'", | 5537 | "tmp.zig:3:47: error: expected type 'std.builtin.AtomicOrder', found 'u32'", |
| 6035 | ); | 5538 | }); |
| 6036 | | 5539 | |
| 6037 | cases.add( | 5540 | cases.add("wrong types given to @export", |
| 6038 | "wrong types given to @export", | | |
| 6039 | \\extern fn entry() void { } | 5541 | \\extern fn entry() void { } |
| 6040 | \\comptime { | 5542 | \\comptime { |
| 6041 | \\ @export("entry", entry, @as(u32, 1234)); | 5543 | \\ @export("entry", entry, @as(u32, 1234)); |
| 6042 | \\} | 5544 | \\} |
| 6043 | , | 5545 | , &[_][]const u8{ |
| 6044 | "tmp.zig:3:29: error: expected type 'std.builtin.GlobalLinkage', found 'u32'", | 5546 | "tmp.zig:3:29: error: expected type 'std.builtin.GlobalLinkage', found 'u32'", |
| 6045 | ); | 5547 | }); |
| 6046 | | 5548 | |
| 6047 | cases.add( | 5549 | cases.add("struct with invalid field", |
| 6048 | "struct with invalid field", | | |
| 6049 | \\const std = @import("std",); | 5550 | \\const std = @import("std",); |
| 6050 | \\const Allocator = std.mem.Allocator; | 5551 | \\const Allocator = std.mem.Allocator; |
| 6051 | \\const ArrayList = std.ArrayList; | 5552 | \\const ArrayList = std.ArrayList; |
| ... | @@ -6069,62 +5570,56 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -6069,62 +5570,56 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6069 | \\ .weight = HeaderWeight.H1, | 5570 | \\ .weight = HeaderWeight.H1, |
| 6070 | \\ }; | 5571 | \\ }; |
| 6071 | \\} | 5572 | \\} |
| 6072 | , | 5573 | , &[_][]const u8{ |
| 6073 | "tmp.zig:14:17: error: use of undeclared identifier 'HeaderValue'", | 5574 | "tmp.zig:14:17: error: use of undeclared identifier 'HeaderValue'", |
| 6074 | ); | 5575 | }); |
| 6075 | | 5576 | |
| 6076 | cases.add( | 5577 | cases.add("@setAlignStack outside function", |
| 6077 | "@setAlignStack outside function", | | |
| 6078 | \\comptime { | 5578 | \\comptime { |
| 6079 | \\ @setAlignStack(16); | 5579 | \\ @setAlignStack(16); |
| 6080 | \\} | 5580 | \\} |
| 6081 | , | 5581 | , &[_][]const u8{ |
| 6082 | "tmp.zig:2:5: error: @setAlignStack outside function", | 5582 | "tmp.zig:2:5: error: @setAlignStack outside function", |
| 6083 | ); | 5583 | }); |
| 6084 | | 5584 | |
| 6085 | cases.add( | 5585 | cases.add("@setAlignStack in naked function", |
| 6086 | "@setAlignStack in naked function", | | |
| 6087 | \\export nakedcc fn entry() void { | 5586 | \\export nakedcc fn entry() void { |
| 6088 | \\ @setAlignStack(16); | 5587 | \\ @setAlignStack(16); |
| 6089 | \\} | 5588 | \\} |
| 6090 | , | 5589 | , &[_][]const u8{ |
| 6091 | "tmp.zig:2:5: error: @setAlignStack in naked function", | 5590 | "tmp.zig:2:5: error: @setAlignStack in naked function", |
| 6092 | ); | 5591 | }); |
| 6093 | | 5592 | |
| 6094 | cases.add( | 5593 | cases.add("@setAlignStack in inline function", |
| 6095 | "@setAlignStack in inline function", | | |
| 6096 | \\export fn entry() void { | 5594 | \\export fn entry() void { |
| 6097 | \\ foo(); | 5595 | \\ foo(); |
| 6098 | \\} | 5596 | \\} |
| 6099 | \\inline fn foo() void { | 5597 | \\inline fn foo() void { |
| 6100 | \\ @setAlignStack(16); | 5598 | \\ @setAlignStack(16); |
| 6101 | \\} | 5599 | \\} |
| 6102 | , | 5600 | , &[_][]const u8{ |
| 6103 | "tmp.zig:5:5: error: @setAlignStack in inline function", | 5601 | "tmp.zig:5:5: error: @setAlignStack in inline function", |
| 6104 | ); | 5602 | }); |
| 6105 | | 5603 | |
| 6106 | cases.add( | 5604 | cases.add("@setAlignStack set twice", |
| 6107 | "@setAlignStack set twice", | | |
| 6108 | \\export fn entry() void { | 5605 | \\export fn entry() void { |
| 6109 | \\ @setAlignStack(16); | 5606 | \\ @setAlignStack(16); |
| 6110 | \\ @setAlignStack(16); | 5607 | \\ @setAlignStack(16); |
| 6111 | \\} | 5608 | \\} |
| 6112 | , | 5609 | , &[_][]const u8{ |
| 6113 | "tmp.zig:3:5: error: alignstack set twice", | 5610 | "tmp.zig:3:5: error: alignstack set twice", |
| 6114 | "tmp.zig:2:5: note: first set here", | 5611 | "tmp.zig:2:5: note: first set here", |
| 6115 | ); | 5612 | }); |
| 6116 | | 5613 | |
| 6117 | cases.add( | 5614 | cases.add("@setAlignStack too big", |
| 6118 | "@setAlignStack too big", | | |
| 6119 | \\export fn entry() void { | 5615 | \\export fn entry() void { |
| 6120 | \\ @setAlignStack(511 + 1); | 5616 | \\ @setAlignStack(511 + 1); |
| 6121 | \\} | 5617 | \\} |
| 6122 | , | 5618 | , &[_][]const u8{ |
| 6123 | "tmp.zig:2:5: error: attempt to @setAlignStack(512); maximum is 256", | 5619 | "tmp.zig:2:5: error: attempt to @setAlignStack(512); maximum is 256", |
| 6124 | ); | 5620 | }); |
| 6125 | | 5621 | |
| 6126 | cases.add( | 5622 | cases.add("storing runtime value in compile time variable then using it", |
| 6127 | "storing runtime value in compile time variable then using it", | | |
| 6128 | \\const Mode = @import("builtin").Mode; | 5623 | \\const Mode = @import("builtin").Mode; |
| 6129 | \\ | 5624 | \\ |
| 6130 | \\fn Free(comptime filename: []const u8) TestCase { | 5625 | \\fn Free(comptime filename: []const u8) TestCase { |
| ... | @@ -6166,12 +5661,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -6166,12 +5661,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6166 | \\ } | 5661 | \\ } |
| 6167 | \\ } | 5662 | \\ } |
| 6168 | \\} | 5663 | \\} |
| 6169 | , | 5664 | , &[_][]const u8{ |
| 6170 | "tmp.zig:37:29: error: cannot store runtime value in compile time variable", | 5665 | "tmp.zig:37:29: error: cannot store runtime value in compile time variable", |
| 6171 | ); | 5666 | }); |
| 6172 | | 5667 | |
| 6173 | cases.add( | 5668 | cases.add("field access of opaque type", |
| 6174 | "field access of opaque type", | | |
| 6175 | \\const MyType = @OpaqueType(); | 5669 | \\const MyType = @OpaqueType(); |
| 6176 | \\ | 5670 | \\ |
| 6177 | \\export fn entry() bool { | 5671 | \\export fn entry() bool { |
| ... | @@ -6182,163 +5676,143 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -6182,163 +5676,143 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6182 | \\fn bar(x: *MyType) bool { | 5676 | \\fn bar(x: *MyType) bool { |
| 6183 | \\ return x.blah; | 5677 | \\ return x.blah; |
| 6184 | \\} | 5678 | \\} |
| 6185 | , | 5679 | , &[_][]const u8{ |
| 6186 | "tmp.zig:9:13: error: type '*MyType' does not support field access", | 5680 | "tmp.zig:9:13: error: type '*MyType' does not support field access", |
| 6187 | ); | 5681 | }); |
| 6188 | | 5682 | |
| 6189 | cases.add( | 5683 | cases.add("carriage return special case", "fn test() bool {\r\n" ++ |
| 6190 | "carriage return special case", | 5684 | " true\r\n" ++ |
| 6191 | "fn test() bool {\r\n" ++ | 5685 | "}\r\n", &[_][]const u8{ |
| 6192 | " true\r\n" ++ | | |
| 6193 | "}\r\n", | | |
| 6194 | "tmp.zig:1:17: error: invalid carriage return, only '\\n' line endings are supported", | 5686 | "tmp.zig:1:17: error: invalid carriage return, only '\\n' line endings are supported", |
| 6195 | ); | 5687 | }); |
| 6196 | | 5688 | |
| 6197 | cases.add( | 5689 | cases.add("invalid legacy unicode escape", |
| 6198 | "invalid legacy unicode escape", | | |
| 6199 | \\export fn entry() void { | 5690 | \\export fn entry() void { |
| 6200 | \\ const a = '\U1234'; | 5691 | \\ const a = '\U1234'; |
| 6201 | \\} | 5692 | \\} |
| 6202 | , | 5693 | , &[_][]const u8{ |
| 6203 | "tmp.zig:2:17: error: invalid character: 'U'", | 5694 | "tmp.zig:2:17: error: invalid character: 'U'", |
| 6204 | ); | 5695 | }); |
| 6205 | | 5696 | |
| 6206 | cases.add( | 5697 | cases.add("invalid empty unicode escape", |
| 6207 | "invalid empty unicode escape", | | |
| 6208 | \\export fn entry() void { | 5698 | \\export fn entry() void { |
| 6209 | \\ const a = '\u{}'; | 5699 | \\ const a = '\u{}'; |
| 6210 | \\} | 5700 | \\} |
| 6211 | , | 5701 | , &[_][]const u8{ |
| 6212 | "tmp.zig:2:19: error: empty unicode escape sequence", | 5702 | "tmp.zig:2:19: error: empty unicode escape sequence", |
| 6213 | ); | 5703 | }); |
| 6214 | | 5704 | |
| 6215 | cases.add( | 5705 | cases.add("non-printable invalid character", "\xff\xfe" ++ |
| 6216 | "non-printable invalid character", | 5706 | \\fn test() bool {\r |
| 6217 | "\xff\xfe" ++ | 5707 | \\ true\r |
| 6218 | \\fn test() bool {\r | 5708 | \\} |
| 6219 | \\ true\r | 5709 | , &[_][]const u8{ |
| 6220 | \\} | | |
| 6221 | , | | |
| 6222 | "tmp.zig:1:1: error: invalid character: '\\xff'", | 5710 | "tmp.zig:1:1: error: invalid character: '\\xff'", |
| 6223 | ); | 5711 | }); |
| 6224 | | 5712 | |
| 6225 | cases.add( | 5713 | cases.add("non-printable invalid character with escape alternative", "fn test() bool {\n" ++ |
| 6226 | "non-printable invalid character with escape alternative", | 5714 | "\ttrue\n" ++ |
| 6227 | "fn test() bool {\n" ++ | 5715 | "}\n", &[_][]const u8{ |
| 6228 | "\ttrue\n" ++ | | |
| 6229 | "}\n", | | |
| 6230 | "tmp.zig:2:1: error: invalid character: '\\t'", | 5716 | "tmp.zig:2:1: error: invalid character: '\\t'", |
| 6231 | ); | 5717 | }); |
| 6232 | | 5718 | |
| 6233 | cases.add( | 5719 | cases.add("@ArgType given non function parameter", |
| 6234 | "@ArgType given non function parameter", | | |
| 6235 | \\comptime { | 5720 | \\comptime { |
| 6236 | \\ _ = @ArgType(i32, 3); | 5721 | \\ _ = @ArgType(i32, 3); |
| 6237 | \\} | 5722 | \\} |
| 6238 | , | 5723 | , &[_][]const u8{ |
| 6239 | "tmp.zig:2:18: error: expected function, found 'i32'", | 5724 | "tmp.zig:2:18: error: expected function, found 'i32'", |
| 6240 | ); | 5725 | }); |
| 6241 | | 5726 | |
| 6242 | cases.add( | 5727 | cases.add("@ArgType arg index out of bounds", |
| 6243 | "@ArgType arg index out of bounds", | | |
| 6244 | \\comptime { | 5728 | \\comptime { |
| 6245 | \\ _ = @ArgType(@typeOf(add), 2); | 5729 | \\ _ = @ArgType(@typeOf(add), 2); |
| 6246 | \\} | 5730 | \\} |
| 6247 | \\fn add(a: i32, b: i32) i32 { return a + b; } | 5731 | \\fn add(a: i32, b: i32) i32 { return a + b; } |
| 6248 | , | 5732 | , &[_][]const u8{ |
| 6249 | "tmp.zig:2:32: error: arg index 2 out of bounds; 'fn(i32, i32) i32' has 2 arguments", | 5733 | "tmp.zig:2:32: error: arg index 2 out of bounds; 'fn(i32, i32) i32' has 2 arguments", |
| 6250 | ); | 5734 | }); |
| 6251 | | 5735 | |
| 6252 | cases.add( | 5736 | cases.add("@memberType on unsupported type", |
| 6253 | "@memberType on unsupported type", | | |
| 6254 | \\comptime { | 5737 | \\comptime { |
| 6255 | \\ _ = @memberType(i32, 0); | 5738 | \\ _ = @memberType(i32, 0); |
| 6256 | \\} | 5739 | \\} |
| 6257 | , | 5740 | , &[_][]const u8{ |
| 6258 | "tmp.zig:2:21: error: type 'i32' does not support @memberType", | 5741 | "tmp.zig:2:21: error: type 'i32' does not support @memberType", |
| 6259 | ); | 5742 | }); |
| 6260 | | 5743 | |
| 6261 | cases.add( | 5744 | cases.add("@memberType on enum", |
| 6262 | "@memberType on enum", | | |
| 6263 | \\comptime { | 5745 | \\comptime { |
| 6264 | \\ _ = @memberType(Foo, 0); | 5746 | \\ _ = @memberType(Foo, 0); |
| 6265 | \\} | 5747 | \\} |
| 6266 | \\const Foo = enum {A,}; | 5748 | \\const Foo = enum {A,}; |
| 6267 | , | 5749 | , &[_][]const u8{ |
| 6268 | "tmp.zig:2:21: error: type 'Foo' does not support @memberType", | 5750 | "tmp.zig:2:21: error: type 'Foo' does not support @memberType", |
| 6269 | ); | 5751 | }); |
| 6270 | | 5752 | |
| 6271 | cases.add( | 5753 | cases.add("@memberType struct out of bounds", |
| 6272 | "@memberType struct out of bounds", | | |
| 6273 | \\comptime { | 5754 | \\comptime { |
| 6274 | \\ _ = @memberType(Foo, 0); | 5755 | \\ _ = @memberType(Foo, 0); |
| 6275 | \\} | 5756 | \\} |
| 6276 | \\const Foo = struct {}; | 5757 | \\const Foo = struct {}; |
| 6277 | , | 5758 | , &[_][]const u8{ |
| 6278 | "tmp.zig:2:26: error: member index 0 out of bounds; 'Foo' has 0 members", | 5759 | "tmp.zig:2:26: error: member index 0 out of bounds; 'Foo' has 0 members", |
| 6279 | ); | 5760 | }); |
| 6280 | | 5761 | |
| 6281 | cases.add( | 5762 | cases.add("@memberType union out of bounds", |
| 6282 | "@memberType union out of bounds", | | |
| 6283 | \\comptime { | 5763 | \\comptime { |
| 6284 | \\ _ = @memberType(Foo, 1); | 5764 | \\ _ = @memberType(Foo, 1); |
| 6285 | \\} | 5765 | \\} |
| 6286 | \\const Foo = union {A: void,}; | 5766 | \\const Foo = union {A: void,}; |
| 6287 | , | 5767 | , &[_][]const u8{ |
| 6288 | "tmp.zig:2:26: error: member index 1 out of bounds; 'Foo' has 1 members", | 5768 | "tmp.zig:2:26: error: member index 1 out of bounds; 'Foo' has 1 members", |
| 6289 | ); | 5769 | }); |
| 6290 | | 5770 | |
| 6291 | cases.add( | 5771 | cases.add("@memberName on unsupported type", |
| 6292 | "@memberName on unsupported type", | | |
| 6293 | \\comptime { | 5772 | \\comptime { |
| 6294 | \\ _ = @memberName(i32, 0); | 5773 | \\ _ = @memberName(i32, 0); |
| 6295 | \\} | 5774 | \\} |
| 6296 | , | 5775 | , &[_][]const u8{ |
| 6297 | "tmp.zig:2:21: error: type 'i32' does not support @memberName", | 5776 | "tmp.zig:2:21: error: type 'i32' does not support @memberName", |
| 6298 | ); | 5777 | }); |
| 6299 | | 5778 | |
| 6300 | cases.add( | 5779 | cases.add("@memberName struct out of bounds", |
| 6301 | "@memberName struct out of bounds", | | |
| 6302 | \\comptime { | 5780 | \\comptime { |
| 6303 | \\ _ = @memberName(Foo, 0); | 5781 | \\ _ = @memberName(Foo, 0); |
| 6304 | \\} | 5782 | \\} |
| 6305 | \\const Foo = struct {}; | 5783 | \\const Foo = struct {}; |
| 6306 | , | 5784 | , &[_][]const u8{ |
| 6307 | "tmp.zig:2:26: error: member index 0 out of bounds; 'Foo' has 0 members", | 5785 | "tmp.zig:2:26: error: member index 0 out of bounds; 'Foo' has 0 members", |
| 6308 | ); | 5786 | }); |
| 6309 | | 5787 | |
| 6310 | cases.add( | 5788 | cases.add("@memberName enum out of bounds", |
| 6311 | "@memberName enum out of bounds", | | |
| 6312 | \\comptime { | 5789 | \\comptime { |
| 6313 | \\ _ = @memberName(Foo, 1); | 5790 | \\ _ = @memberName(Foo, 1); |
| 6314 | \\} | 5791 | \\} |
| 6315 | \\const Foo = enum {A,}; | 5792 | \\const Foo = enum {A,}; |
| 6316 | , | 5793 | , &[_][]const u8{ |
| 6317 | "tmp.zig:2:26: error: member index 1 out of bounds; 'Foo' has 1 members", | 5794 | "tmp.zig:2:26: error: member index 1 out of bounds; 'Foo' has 1 members", |
| 6318 | ); | 5795 | }); |
| 6319 | | 5796 | |
| 6320 | cases.add( | 5797 | cases.add("@memberName union out of bounds", |
| 6321 | "@memberName union out of bounds", | | |
| 6322 | \\comptime { | 5798 | \\comptime { |
| 6323 | \\ _ = @memberName(Foo, 1); | 5799 | \\ _ = @memberName(Foo, 1); |
| 6324 | \\} | 5800 | \\} |
| 6325 | \\const Foo = union {A:i32,}; | 5801 | \\const Foo = union {A:i32,}; |
| 6326 | , | 5802 | , &[_][]const u8{ |
| 6327 | "tmp.zig:2:26: error: member index 1 out of bounds; 'Foo' has 1 members", | 5803 | "tmp.zig:2:26: error: member index 1 out of bounds; 'Foo' has 1 members", |
| 6328 | ); | 5804 | }); |
| 6329 | | 5805 | |
| 6330 | cases.add( | 5806 | cases.add("calling var args extern function, passing array instead of pointer", |
| 6331 | "calling var args extern function, passing array instead of pointer", | | |
| 6332 | \\export fn entry() void { | 5807 | \\export fn entry() void { |
| 6333 | \\ foo("hello".*,); | 5808 | \\ foo("hello".*,); |
| 6334 | \\} | 5809 | \\} |
| 6335 | \\pub extern fn foo(format: *const u8, ...) void; | 5810 | \\pub extern fn foo(format: *const u8, ...) void; |
| 6336 | , | 5811 | , &[_][]const u8{ |
| 6337 | "tmp.zig:2:16: error: expected type '*const u8', found '[5:0]u8'", | 5812 | "tmp.zig:2:16: error: expected type '*const u8', found '[5:0]u8'", |
| 6338 | ); | 5813 | }); |
| 6339 | | 5814 | |
| 6340 | cases.add( | 5815 | cases.add("constant inside comptime function has compile error", |
| 6341 | "constant inside comptime function has compile error", | | |
| 6342 | \\const ContextAllocator = MemoryPool(usize); | 5816 | \\const ContextAllocator = MemoryPool(usize); |
| 6343 | \\ | 5817 | \\ |
| 6344 | \\pub fn MemoryPool(comptime T: type) type { | 5818 | \\pub fn MemoryPool(comptime T: type) type { |
| ... | @@ -6352,11 +5826,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -6352,11 +5826,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6352 | \\export fn entry() void { | 5826 | \\export fn entry() void { |
| 6353 | \\ var allocator: ContextAllocator = undefined; | 5827 | \\ var allocator: ContextAllocator = undefined; |
| 6354 | \\} | 5828 | \\} |
| 6355 | , | 5829 | , &[_][]const u8{ |
| 6356 | "tmp.zig:4:25: error: aoeu", | 5830 | "tmp.zig:4:25: error: aoeu", |
| 6357 | "tmp.zig:1:36: note: referenced here", | 5831 | "tmp.zig:1:36: note: referenced here", |
| 6358 | "tmp.zig:12:20: note: referenced here", | 5832 | "tmp.zig:12:20: note: referenced here", |
| 6359 | ); | 5833 | }); |
| 6360 | | 5834 | |
| 6361 | cases.add("specify enum tag type that is too small", | 5835 | cases.add("specify enum tag type that is too small", |
| 6362 | \\const Small = enum (u2) { | 5836 | \\const Small = enum (u2) { |
| ... | @@ -6370,10 +5844,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -6370,10 +5844,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6370 | \\export fn entry() void { | 5844 | \\export fn entry() void { |
| 6371 | \\ var x = Small.One; | 5845 | \\ var x = Small.One; |
| 6372 | \\} | 5846 | \\} |
| 6373 | , "tmp.zig:6:5: error: enumeration value 4 too large for type 'u2'"); | 5847 | , &[_][]const u8{ |
| | 5848 | "tmp.zig:6:5: error: enumeration value 4 too large for type 'u2'", |
| | 5849 | }); |
| 6374 | | 5850 | |
| 6375 | cases.add( | 5851 | cases.add("specify non-integer enum tag type", |
| 6376 | "specify non-integer enum tag type", | | |
| 6377 | \\const Small = enum (f32) { | 5852 | \\const Small = enum (f32) { |
| 6378 | \\ One, | 5853 | \\ One, |
| 6379 | \\ Two, | 5854 | \\ Two, |
| ... | @@ -6383,12 +5858,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -6383,12 +5858,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6383 | \\export fn entry() void { | 5858 | \\export fn entry() void { |
| 6384 | \\ var x = Small.One; | 5859 | \\ var x = Small.One; |
| 6385 | \\} | 5860 | \\} |
| 6386 | , | 5861 | , &[_][]const u8{ |
| 6387 | "tmp.zig:1:21: error: expected integer, found 'f32'", | 5862 | "tmp.zig:1:21: error: expected integer, found 'f32'", |
| 6388 | ); | 5863 | }); |
| 6389 | | 5864 | |
| 6390 | cases.add( | 5865 | cases.add("implicitly casting enum to tag type", |
| 6391 | "implicitly casting enum to tag type", | | |
| 6392 | \\const Small = enum(u2) { | 5866 | \\const Small = enum(u2) { |
| 6393 | \\ One, | 5867 | \\ One, |
| 6394 | \\ Two, | 5868 | \\ Two, |
| ... | @@ -6399,12 +5873,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -6399,12 +5873,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6399 | \\export fn entry() void { | 5873 | \\export fn entry() void { |
| 6400 | \\ var x: u2 = Small.Two; | 5874 | \\ var x: u2 = Small.Two; |
| 6401 | \\} | 5875 | \\} |
| 6402 | , | 5876 | , &[_][]const u8{ |
| 6403 | "tmp.zig:9:22: error: expected type 'u2', found 'Small'", | 5877 | "tmp.zig:9:22: error: expected type 'u2', found 'Small'", |
| 6404 | ); | 5878 | }); |
| 6405 | | 5879 | |
| 6406 | cases.add( | 5880 | cases.add("explicitly casting non tag type to enum", |
| 6407 | "explicitly casting non tag type to enum", | | |
| 6408 | \\const Small = enum(u2) { | 5881 | \\const Small = enum(u2) { |
| 6409 | \\ One, | 5882 | \\ One, |
| 6410 | \\ Two, | 5883 | \\ Two, |
| ... | @@ -6416,45 +5889,41 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -6416,45 +5889,41 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6416 | \\ var y = @as(u3, 3); | 5889 | \\ var y = @as(u3, 3); |
| 6417 | \\ var x = @intToEnum(Small, y); | 5890 | \\ var x = @intToEnum(Small, y); |
| 6418 | \\} | 5891 | \\} |
| 6419 | , | 5892 | , &[_][]const u8{ |
| 6420 | "tmp.zig:10:31: error: expected type 'u2', found 'u3'", | 5893 | "tmp.zig:10:31: error: expected type 'u2', found 'u3'", |
| 6421 | ); | 5894 | }); |
| 6422 | | 5895 | |
| 6423 | cases.add( | 5896 | cases.add("union fields with value assignments", |
| 6424 | "union fields with value assignments", | | |
| 6425 | \\const MultipleChoice = union { | 5897 | \\const MultipleChoice = union { |
| 6426 | \\ A: i32 = 20, | 5898 | \\ A: i32 = 20, |
| 6427 | \\}; | 5899 | \\}; |
| 6428 | \\export fn entry() void { | 5900 | \\export fn entry() void { |
| 6429 | \\ var x: MultipleChoice = undefined; | 5901 | \\ var x: MultipleChoice = undefined; |
| 6430 | \\} | 5902 | \\} |
| 6431 | , | 5903 | , &[_][]const u8{ |
| 6432 | "tmp.zig:2:14: error: untagged union field assignment", | 5904 | "tmp.zig:2:14: error: untagged union field assignment", |
| 6433 | "tmp.zig:1:24: note: consider 'union(enum)' here", | 5905 | "tmp.zig:1:24: note: consider 'union(enum)' here", |
| 6434 | ); | 5906 | }); |
| 6435 | | 5907 | |
| 6436 | cases.add( | 5908 | cases.add("enum with 0 fields", |
| 6437 | "enum with 0 fields", | | |
| 6438 | \\const Foo = enum {}; | 5909 | \\const Foo = enum {}; |
| 6439 | \\export fn entry() usize { | 5910 | \\export fn entry() usize { |
| 6440 | \\ return @sizeOf(Foo); | 5911 | \\ return @sizeOf(Foo); |
| 6441 | \\} | 5912 | \\} |
| 6442 | , | 5913 | , &[_][]const u8{ |
| 6443 | "tmp.zig:1:13: error: enums must have 1 or more fields", | 5914 | "tmp.zig:1:13: error: enums must have 1 or more fields", |
| 6444 | ); | 5915 | }); |
| 6445 | | 5916 | |
| 6446 | cases.add( | 5917 | cases.add("union with 0 fields", |
| 6447 | "union with 0 fields", | | |
| 6448 | \\const Foo = union {}; | 5918 | \\const Foo = union {}; |
| 6449 | \\export fn entry() usize { | 5919 | \\export fn entry() usize { |
| 6450 | \\ return @sizeOf(Foo); | 5920 | \\ return @sizeOf(Foo); |
| 6451 | \\} | 5921 | \\} |
| 6452 | , | 5922 | , &[_][]const u8{ |
| 6453 | "tmp.zig:1:13: error: unions must have 1 or more fields", | 5923 | "tmp.zig:1:13: error: unions must have 1 or more fields", |
| 6454 | ); | 5924 | }); |
| 6455 | | 5925 | |
| 6456 | cases.add( | 5926 | cases.add("enum value already taken", |
| 6457 | "enum value already taken", | | |
| 6458 | \\const MultipleChoice = enum(u32) { | 5927 | \\const MultipleChoice = enum(u32) { |
| 6459 | \\ A = 20, | 5928 | \\ A = 20, |
| 6460 | \\ B = 40, | 5929 | \\ B = 40, |
| ... | @@ -6465,13 +5934,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -6465,13 +5934,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6465 | \\export fn entry() void { | 5934 | \\export fn entry() void { |
| 6466 | \\ var x = MultipleChoice.C; | 5935 | \\ var x = MultipleChoice.C; |
| 6467 | \\} | 5936 | \\} |
| 6468 | , | 5937 | , &[_][]const u8{ |
| 6469 | "tmp.zig:6:5: error: enum tag value 60 already taken", | 5938 | "tmp.zig:6:5: error: enum tag value 60 already taken", |
| 6470 | "tmp.zig:4:5: note: other occurrence here", | 5939 | "tmp.zig:4:5: note: other occurrence here", |
| 6471 | ); | 5940 | }); |
| 6472 | | 5941 | |
| 6473 | cases.add( | 5942 | cases.add("union with specified enum omits field", |
| 6474 | "union with specified enum omits field", | | |
| 6475 | \\const Letter = enum { | 5943 | \\const Letter = enum { |
| 6476 | \\ A, | 5944 | \\ A, |
| 6477 | \\ B, | 5945 | \\ B, |
| ... | @@ -6484,50 +5952,46 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -6484,50 +5952,46 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6484 | \\export fn entry() usize { | 5952 | \\export fn entry() usize { |
| 6485 | \\ return @sizeOf(Payload); | 5953 | \\ return @sizeOf(Payload); |
| 6486 | \\} | 5954 | \\} |
| 6487 | , | 5955 | , &[_][]const u8{ |
| 6488 | "tmp.zig:6:17: error: enum field missing: 'C'", | 5956 | "tmp.zig:6:17: error: enum field missing: 'C'", |
| 6489 | "tmp.zig:4:5: note: declared here", | 5957 | "tmp.zig:4:5: note: declared here", |
| 6490 | ); | 5958 | }); |
| 6491 | | 5959 | |
| 6492 | cases.add( | 5960 | cases.add("@TagType when union has no attached enum", |
| 6493 | "@TagType when union has no attached enum", | | |
| 6494 | \\const Foo = union { | 5961 | \\const Foo = union { |
| 6495 | \\ A: i32, | 5962 | \\ A: i32, |
| 6496 | \\}; | 5963 | \\}; |
| 6497 | \\export fn entry() void { | 5964 | \\export fn entry() void { |
| 6498 | \\ const x = @TagType(Foo); | 5965 | \\ const x = @TagType(Foo); |
| 6499 | \\} | 5966 | \\} |
| 6500 | , | 5967 | , &[_][]const u8{ |
| 6501 | "tmp.zig:5:24: error: union 'Foo' has no tag", | 5968 | "tmp.zig:5:24: error: union 'Foo' has no tag", |
| 6502 | "tmp.zig:1:13: note: consider 'union(enum)' here", | 5969 | "tmp.zig:1:13: note: consider 'union(enum)' here", |
| 6503 | ); | 5970 | }); |
| 6504 | | 5971 | |
| 6505 | cases.add( | 5972 | cases.add("non-integer tag type to automatic union enum", |
| 6506 | "non-integer tag type to automatic union enum", | | |
| 6507 | \\const Foo = union(enum(f32)) { | 5973 | \\const Foo = union(enum(f32)) { |
| 6508 | \\ A: i32, | 5974 | \\ A: i32, |
| 6509 | \\}; | 5975 | \\}; |
| 6510 | \\export fn entry() void { | 5976 | \\export fn entry() void { |
| 6511 | \\ const x = @TagType(Foo); | 5977 | \\ const x = @TagType(Foo); |
| 6512 | \\} | 5978 | \\} |
| 6513 | , | 5979 | , &[_][]const u8{ |
| 6514 | "tmp.zig:1:24: error: expected integer tag type, found 'f32'", | 5980 | "tmp.zig:1:24: error: expected integer tag type, found 'f32'", |
| 6515 | ); | 5981 | }); |
| 6516 | | 5982 | |
| 6517 | cases.add( | 5983 | cases.add("non-enum tag type passed to union", |
| 6518 | "non-enum tag type passed to union", | | |
| 6519 | \\const Foo = union(u32) { | 5984 | \\const Foo = union(u32) { |
| 6520 | \\ A: i32, | 5985 | \\ A: i32, |
| 6521 | \\}; | 5986 | \\}; |
| 6522 | \\export fn entry() void { | 5987 | \\export fn entry() void { |
| 6523 | \\ const x = @TagType(Foo); | 5988 | \\ const x = @TagType(Foo); |
| 6524 | \\} | 5989 | \\} |
| 6525 | , | 5990 | , &[_][]const u8{ |
| 6526 | "tmp.zig:1:19: error: expected enum tag type, found 'u32'", | 5991 | "tmp.zig:1:19: error: expected enum tag type, found 'u32'", |
| 6527 | ); | 5992 | }); |
| 6528 | | 5993 | |
| 6529 | cases.add( | 5994 | cases.add("union auto-enum value already taken", |
| 6530 | "union auto-enum value already taken", | | |
| 6531 | \\const MultipleChoice = union(enum(u32)) { | 5995 | \\const MultipleChoice = union(enum(u32)) { |
| 6532 | \\ A = 20, | 5996 | \\ A = 20, |
| 6533 | \\ B = 40, | 5997 | \\ B = 40, |
| ... | @@ -6538,13 +6002,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -6538,13 +6002,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6538 | \\export fn entry() void { | 6002 | \\export fn entry() void { |
| 6539 | \\ var x = MultipleChoice { .C = {} }; | 6003 | \\ var x = MultipleChoice { .C = {} }; |
| 6540 | \\} | 6004 | \\} |
| 6541 | , | 6005 | , &[_][]const u8{ |
| 6542 | "tmp.zig:6:9: error: enum tag value 60 already taken", | 6006 | "tmp.zig:6:9: error: enum tag value 60 already taken", |
| 6543 | "tmp.zig:4:9: note: other occurrence here", | 6007 | "tmp.zig:4:9: note: other occurrence here", |
| 6544 | ); | 6008 | }); |
| 6545 | | 6009 | |
| 6546 | cases.add( | 6010 | cases.add("union enum field does not match enum", |
| 6547 | "union enum field does not match enum", | | |
| 6548 | \\const Letter = enum { | 6011 | \\const Letter = enum { |
| 6549 | \\ A, | 6012 | \\ A, |
| 6550 | \\ B, | 6013 | \\ B, |
| ... | @@ -6559,13 +6022,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -6559,13 +6022,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6559 | \\export fn entry() void { | 6022 | \\export fn entry() void { |
| 6560 | \\ var a = Payload {.A = 1234}; | 6023 | \\ var a = Payload {.A = 1234}; |
| 6561 | \\} | 6024 | \\} |
| 6562 | , | 6025 | , &[_][]const u8{ |
| 6563 | "tmp.zig:10:5: error: enum field not found: 'D'", | 6026 | "tmp.zig:10:5: error: enum field not found: 'D'", |
| 6564 | "tmp.zig:1:16: note: enum declared here", | 6027 | "tmp.zig:1:16: note: enum declared here", |
| 6565 | ); | 6028 | }); |
| 6566 | | 6029 | |
| 6567 | cases.add( | 6030 | cases.add("field type supplied in an enum", |
| 6568 | "field type supplied in an enum", | | |
| 6569 | \\const Letter = enum { | 6031 | \\const Letter = enum { |
| 6570 | \\ A: void, | 6032 | \\ A: void, |
| 6571 | \\ B, | 6033 | \\ B, |
| ... | @@ -6574,37 +6036,34 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -6574,37 +6036,34 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6574 | \\export fn entry() void { | 6036 | \\export fn entry() void { |
| 6575 | \\ var b = Letter.B; | 6037 | \\ var b = Letter.B; |
| 6576 | \\} | 6038 | \\} |
| 6577 | , | 6039 | , &[_][]const u8{ |
| 6578 | "tmp.zig:2:8: error: structs and unions, not enums, support field types", | 6040 | "tmp.zig:2:8: error: structs and unions, not enums, support field types", |
| 6579 | "tmp.zig:1:16: note: consider 'union(enum)' here", | 6041 | "tmp.zig:1:16: note: consider 'union(enum)' here", |
| 6580 | ); | 6042 | }); |
| 6581 | | 6043 | |
| 6582 | cases.add( | 6044 | cases.add("struct field missing type", |
| 6583 | "struct field missing type", | | |
| 6584 | \\const Letter = struct { | 6045 | \\const Letter = struct { |
| 6585 | \\ A, | 6046 | \\ A, |
| 6586 | \\}; | 6047 | \\}; |
| 6587 | \\export fn entry() void { | 6048 | \\export fn entry() void { |
| 6588 | \\ var a = Letter { .A = {} }; | 6049 | \\ var a = Letter { .A = {} }; |
| 6589 | \\} | 6050 | \\} |
| 6590 | , | 6051 | , &[_][]const u8{ |
| 6591 | "tmp.zig:2:5: error: struct field missing type", | 6052 | "tmp.zig:2:5: error: struct field missing type", |
| 6592 | ); | 6053 | }); |
| 6593 | | 6054 | |
| 6594 | cases.add( | 6055 | cases.add("extern union field missing type", |
| 6595 | "extern union field missing type", | | |
| 6596 | \\const Letter = extern union { | 6056 | \\const Letter = extern union { |
| 6597 | \\ A, | 6057 | \\ A, |
| 6598 | \\}; | 6058 | \\}; |
| 6599 | \\export fn entry() void { | 6059 | \\export fn entry() void { |
| 6600 | \\ var a = Letter { .A = {} }; | 6060 | \\ var a = Letter { .A = {} }; |
| 6601 | \\} | 6061 | \\} |
| 6602 | , | 6062 | , &[_][]const u8{ |
| 6603 | "tmp.zig:2:5: error: union field missing type", | 6063 | "tmp.zig:2:5: error: union field missing type", |
| 6604 | ); | 6064 | }); |
| 6605 | | 6065 | |
| 6606 | cases.add( | 6066 | cases.add("extern union given enum tag type", |
| 6607 | "extern union given enum tag type", | | |
| 6608 | \\const Letter = enum { | 6067 | \\const Letter = enum { |
| 6609 | \\ A, | 6068 | \\ A, |
| 6610 | \\ B, | 6069 | \\ B, |
| ... | @@ -6618,12 +6077,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -6618,12 +6077,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6618 | \\export fn entry() void { | 6077 | \\export fn entry() void { |
| 6619 | \\ var a = Payload { .A = 1234 }; | 6078 | \\ var a = Payload { .A = 1234 }; |
| 6620 | \\} | 6079 | \\} |
| 6621 | , | 6080 | , &[_][]const u8{ |
| 6622 | "tmp.zig:6:30: error: extern union does not support enum tag type", | 6081 | "tmp.zig:6:30: error: extern union does not support enum tag type", |
| 6623 | ); | 6082 | }); |
| 6624 | | 6083 | |
| 6625 | cases.add( | 6084 | cases.add("packed union given enum tag type", |
| 6626 | "packed union given enum tag type", | | |
| 6627 | \\const Letter = enum { | 6085 | \\const Letter = enum { |
| 6628 | \\ A, | 6086 | \\ A, |
| 6629 | \\ B, | 6087 | \\ B, |
| ... | @@ -6637,12 +6095,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -6637,12 +6095,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6637 | \\export fn entry() void { | 6095 | \\export fn entry() void { |
| 6638 | \\ var a = Payload { .A = 1234 }; | 6096 | \\ var a = Payload { .A = 1234 }; |
| 6639 | \\} | 6097 | \\} |
| 6640 | , | 6098 | , &[_][]const u8{ |
| 6641 | "tmp.zig:6:30: error: packed union does not support enum tag type", | 6099 | "tmp.zig:6:30: error: packed union does not support enum tag type", |
| 6642 | ); | 6100 | }); |
| 6643 | | 6101 | |
| 6644 | cases.add( | 6102 | cases.add("packed union with automatic layout field", |
| 6645 | "packed union with automatic layout field", | | |
| 6646 | \\const Foo = struct { | 6103 | \\const Foo = struct { |
| 6647 | \\ a: u32, | 6104 | \\ a: u32, |
| 6648 | \\ b: f32, | 6105 | \\ b: f32, |
| ... | @@ -6654,12 +6111,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -6654,12 +6111,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6654 | \\export fn entry() void { | 6111 | \\export fn entry() void { |
| 6655 | \\ var a = Payload { .B = true }; | 6112 | \\ var a = Payload { .B = true }; |
| 6656 | \\} | 6113 | \\} |
| 6657 | , | 6114 | , &[_][]const u8{ |
| 6658 | "tmp.zig:6:5: error: non-packed, non-extern struct 'Foo' not allowed in packed union; no guaranteed in-memory representation", | 6115 | "tmp.zig:6:5: error: non-packed, non-extern struct 'Foo' not allowed in packed union; no guaranteed in-memory representation", |
| 6659 | ); | 6116 | }); |
| 6660 | | 6117 | |
| 6661 | cases.add( | 6118 | cases.add("switch on union with no attached enum", |
| 6662 | "switch on union with no attached enum", | | |
| 6663 | \\const Payload = union { | 6119 | \\const Payload = union { |
| 6664 | \\ A: i32, | 6120 | \\ A: i32, |
| 6665 | \\ B: f64, | 6121 | \\ B: f64, |
| ... | @@ -6675,13 +6131,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -6675,13 +6131,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6675 | \\ else => unreachable, | 6131 | \\ else => unreachable, |
| 6676 | \\ } | 6132 | \\ } |
| 6677 | \\} | 6133 | \\} |
| 6678 | , | 6134 | , &[_][]const u8{ |
| 6679 | "tmp.zig:11:14: error: switch on union which has no attached enum", | 6135 | "tmp.zig:11:14: error: switch on union which has no attached enum", |
| 6680 | "tmp.zig:1:17: note: consider 'union(enum)' here", | 6136 | "tmp.zig:1:17: note: consider 'union(enum)' here", |
| 6681 | ); | 6137 | }); |
| 6682 | | 6138 | |
| 6683 | cases.add( | 6139 | cases.add("enum in field count range but not matching tag", |
| 6684 | "enum in field count range but not matching tag", | | |
| 6685 | \\const Foo = enum(u32) { | 6140 | \\const Foo = enum(u32) { |
| 6686 | \\ A = 10, | 6141 | \\ A = 10, |
| 6687 | \\ B = 11, | 6142 | \\ B = 11, |
| ... | @@ -6689,13 +6144,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -6689,13 +6144,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6689 | \\export fn entry() void { | 6144 | \\export fn entry() void { |
| 6690 | \\ var x = @intToEnum(Foo, 0); | 6145 | \\ var x = @intToEnum(Foo, 0); |
| 6691 | \\} | 6146 | \\} |
| 6692 | , | 6147 | , &[_][]const u8{ |
| 6693 | "tmp.zig:6:13: error: enum 'Foo' has no tag matching integer value 0", | 6148 | "tmp.zig:6:13: error: enum 'Foo' has no tag matching integer value 0", |
| 6694 | "tmp.zig:1:13: note: 'Foo' declared here", | 6149 | "tmp.zig:1:13: note: 'Foo' declared here", |
| 6695 | ); | 6150 | }); |
| 6696 | | 6151 | |
| 6697 | cases.add( | 6152 | cases.add("comptime cast enum to union but field has payload", |
| 6698 | "comptime cast enum to union but field has payload", | | |
| 6699 | \\const Letter = enum { A, B, C }; | 6153 | \\const Letter = enum { A, B, C }; |
| 6700 | \\const Value = union(Letter) { | 6154 | \\const Value = union(Letter) { |
| 6701 | \\ A: i32, | 6155 | \\ A: i32, |
| ... | @@ -6705,13 +6159,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -6705,13 +6159,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6705 | \\export fn entry() void { | 6159 | \\export fn entry() void { |
| 6706 | \\ var x: Value = Letter.A; | 6160 | \\ var x: Value = Letter.A; |
| 6707 | \\} | 6161 | \\} |
| 6708 | , | 6162 | , &[_][]const u8{ |
| 6709 | "tmp.zig:8:26: error: cast to union 'Value' must initialize 'i32' field 'A'", | 6163 | "tmp.zig:8:26: error: cast to union 'Value' must initialize 'i32' field 'A'", |
| 6710 | "tmp.zig:3:5: note: field 'A' declared here", | 6164 | "tmp.zig:3:5: note: field 'A' declared here", |
| 6711 | ); | 6165 | }); |
| 6712 | | 6166 | |
| 6713 | cases.add( | 6167 | cases.add("runtime cast to union which has non-void fields", |
| 6714 | "runtime cast to union which has non-void fields", | | |
| 6715 | \\const Letter = enum { A, B, C }; | 6168 | \\const Letter = enum { A, B, C }; |
| 6716 | \\const Value = union(Letter) { | 6169 | \\const Value = union(Letter) { |
| 6717 | \\ A: i32, | 6170 | \\ A: i32, |
| ... | @@ -6724,37 +6177,34 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -6724,37 +6177,34 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6724 | \\fn foo(l: Letter) void { | 6177 | \\fn foo(l: Letter) void { |
| 6725 | \\ var x: Value = l; | 6178 | \\ var x: Value = l; |
| 6726 | \\} | 6179 | \\} |
| 6727 | , | 6180 | , &[_][]const u8{ |
| 6728 | "tmp.zig:11:20: error: runtime cast to union 'Value' which has non-void fields", | 6181 | "tmp.zig:11:20: error: runtime cast to union 'Value' which has non-void fields", |
| 6729 | "tmp.zig:3:5: note: field 'A' has type 'i32'", | 6182 | "tmp.zig:3:5: note: field 'A' has type 'i32'", |
| 6730 | ); | 6183 | }); |
| 6731 | | 6184 | |
| 6732 | cases.add( | 6185 | cases.add("taking byte offset of void field in struct", |
| 6733 | "taking byte offset of void field in struct", | | |
| 6734 | \\const Empty = struct { | 6186 | \\const Empty = struct { |
| 6735 | \\ val: void, | 6187 | \\ val: void, |
| 6736 | \\}; | 6188 | \\}; |
| 6737 | \\export fn foo() void { | 6189 | \\export fn foo() void { |
| 6738 | \\ const fieldOffset = @byteOffsetOf(Empty, "val",); | 6190 | \\ const fieldOffset = @byteOffsetOf(Empty, "val",); |
| 6739 | \\} | 6191 | \\} |
| 6740 | , | 6192 | , &[_][]const u8{ |
| 6741 | "tmp.zig:5:46: error: zero-bit field 'val' in struct 'Empty' has no offset", | 6193 | "tmp.zig:5:46: error: zero-bit field 'val' in struct 'Empty' has no offset", |
| 6742 | ); | 6194 | }); |
| 6743 | | 6195 | |
| 6744 | cases.add( | 6196 | cases.add("taking bit offset of void field in struct", |
| 6745 | "taking bit offset of void field in struct", | | |
| 6746 | \\const Empty = struct { | 6197 | \\const Empty = struct { |
| 6747 | \\ val: void, | 6198 | \\ val: void, |
| 6748 | \\}; | 6199 | \\}; |
| 6749 | \\export fn foo() void { | 6200 | \\export fn foo() void { |
| 6750 | \\ const fieldOffset = @bitOffsetOf(Empty, "val",); | 6201 | \\ const fieldOffset = @bitOffsetOf(Empty, "val",); |
| 6751 | \\} | 6202 | \\} |
| 6752 | , | 6203 | , &[_][]const u8{ |
| 6753 | "tmp.zig:5:45: error: zero-bit field 'val' in struct 'Empty' has no offset", | 6204 | "tmp.zig:5:45: error: zero-bit field 'val' in struct 'Empty' has no offset", |
| 6754 | ); | 6205 | }); |
| 6755 | | 6206 | |
| 6756 | cases.add( | 6207 | cases.add("invalid union field access in comptime", |
| 6757 | "invalid union field access in comptime", | | |
| 6758 | \\const Foo = union { | 6208 | \\const Foo = union { |
| 6759 | \\ Bar: u8, | 6209 | \\ Bar: u8, |
| 6760 | \\ Baz: void, | 6210 | \\ Baz: void, |
| ... | @@ -6763,60 +6213,54 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -6763,60 +6213,54 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6763 | \\ var foo = Foo {.Baz = {}}; | 6213 | \\ var foo = Foo {.Baz = {}}; |
| 6764 | \\ const bar_val = foo.Bar; | 6214 | \\ const bar_val = foo.Bar; |
| 6765 | \\} | 6215 | \\} |
| 6766 | , | 6216 | , &[_][]const u8{ |
| 6767 | "tmp.zig:7:24: error: accessing union field 'Bar' while field 'Baz' is set", | 6217 | "tmp.zig:7:24: error: accessing union field 'Bar' while field 'Baz' is set", |
| 6768 | ); | 6218 | }); |
| 6769 | | 6219 | |
| 6770 | cases.add( | 6220 | cases.add("getting return type of generic function", |
| 6771 | "getting return type of generic function", | | |
| 6772 | \\fn generic(a: var) void {} | 6221 | \\fn generic(a: var) void {} |
| 6773 | \\comptime { | 6222 | \\comptime { |
| 6774 | \\ _ = @typeOf(generic).ReturnType; | 6223 | \\ _ = @typeOf(generic).ReturnType; |
| 6775 | \\} | 6224 | \\} |
| 6776 | , | 6225 | , &[_][]const u8{ |
| 6777 | "tmp.zig:3:25: error: ReturnType has not been resolved because 'fn(var)var' is generic", | 6226 | "tmp.zig:3:25: error: ReturnType has not been resolved because 'fn(var)var' is generic", |
| 6778 | ); | 6227 | }); |
| 6779 | | 6228 | |
| 6780 | cases.add( | 6229 | cases.add("getting @ArgType of generic function", |
| 6781 | "getting @ArgType of generic function", | | |
| 6782 | \\fn generic(a: var) void {} | 6230 | \\fn generic(a: var) void {} |
| 6783 | \\comptime { | 6231 | \\comptime { |
| 6784 | \\ _ = @ArgType(@typeOf(generic), 0); | 6232 | \\ _ = @ArgType(@typeOf(generic), 0); |
| 6785 | \\} | 6233 | \\} |
| 6786 | , | 6234 | , &[_][]const u8{ |
| 6787 | "tmp.zig:3:36: error: @ArgType could not resolve the type of arg 0 because 'fn(var)var' is generic", | 6235 | "tmp.zig:3:36: error: @ArgType could not resolve the type of arg 0 because 'fn(var)var' is generic", |
| 6788 | ); | 6236 | }); |
| 6789 | | 6237 | |
| 6790 | cases.add( | 6238 | cases.add("unsupported modifier at start of asm output constraint", |
| 6791 | "unsupported modifier at start of asm output constraint", | | |
| 6792 | \\export fn foo() void { | 6239 | \\export fn foo() void { |
| 6793 | \\ var bar: u32 = 3; | 6240 | \\ var bar: u32 = 3; |
| 6794 | \\ asm volatile ("" : [baz]"+r"(bar) : : ""); | 6241 | \\ asm volatile ("" : [baz]"+r"(bar) : : ""); |
| 6795 | \\} | 6242 | \\} |
| 6796 | , | 6243 | , &[_][]const u8{ |
| 6797 | "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", | 6244 | "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", |
| 6798 | ); | 6245 | }); |
| 6799 | | 6246 | |
| 6800 | cases.add( | 6247 | cases.add("comptime_int in asm input", |
| 6801 | "comptime_int in asm input", | | |
| 6802 | \\export fn foo() void { | 6248 | \\export fn foo() void { |
| 6803 | \\ asm volatile ("" : : [bar]"r"(3) : ""); | 6249 | \\ asm volatile ("" : : [bar]"r"(3) : ""); |
| 6804 | \\} | 6250 | \\} |
| 6805 | , | 6251 | , &[_][]const u8{ |
| 6806 | "tmp.zig:2:35: error: expected sized integer or sized float, found comptime_int", | 6252 | "tmp.zig:2:35: error: expected sized integer or sized float, found comptime_int", |
| 6807 | ); | 6253 | }); |
| 6808 | | 6254 | |
| 6809 | cases.add( | 6255 | cases.add("comptime_float in asm input", |
| 6810 | "comptime_float in asm input", | | |
| 6811 | \\export fn foo() void { | 6256 | \\export fn foo() void { |
| 6812 | \\ asm volatile ("" : : [bar]"r"(3.17) : ""); | 6257 | \\ asm volatile ("" : : [bar]"r"(3.17) : ""); |
| 6813 | \\} | 6258 | \\} |
| 6814 | , | 6259 | , &[_][]const u8{ |
| 6815 | "tmp.zig:2:35: error: expected sized integer or sized float, found comptime_float", | 6260 | "tmp.zig:2:35: error: expected sized integer or sized float, found comptime_float", |
| 6816 | ); | 6261 | }); |
| 6817 | | 6262 | |
| 6818 | cases.add( | 6263 | cases.add("runtime assignment to comptime struct type", |
| 6819 | "runtime assignment to comptime struct type", | | |
| 6820 | \\const Foo = struct { | 6264 | \\const Foo = struct { |
| 6821 | \\ Bar: u8, | 6265 | \\ Bar: u8, |
| 6822 | \\ Baz: type, | 6266 | \\ Baz: type, |
| ... | @@ -6825,12 +6269,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -6825,12 +6269,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6825 | \\ var x: u8 = 0; | 6269 | \\ var x: u8 = 0; |
| 6826 | \\ const foo = Foo { .Bar = x, .Baz = u8 }; | 6270 | \\ const foo = Foo { .Bar = x, .Baz = u8 }; |
| 6827 | \\} | 6271 | \\} |
| 6828 | , | 6272 | , &[_][]const u8{ |
| 6829 | "tmp.zig:7:23: error: unable to evaluate constant expression", | 6273 | "tmp.zig:7:23: error: unable to evaluate constant expression", |
| 6830 | ); | 6274 | }); |
| 6831 | | 6275 | |
| 6832 | cases.add( | 6276 | cases.add("runtime assignment to comptime union type", |
| 6833 | "runtime assignment to comptime union type", | | |
| 6834 | \\const Foo = union { | 6277 | \\const Foo = union { |
| 6835 | \\ Bar: u8, | 6278 | \\ Bar: u8, |
| 6836 | \\ Baz: type, | 6279 | \\ Baz: type, |
| ... | @@ -6839,42 +6282,39 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -6839,42 +6282,39 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6839 | \\ var x: u8 = 0; | 6282 | \\ var x: u8 = 0; |
| 6840 | \\ const foo = Foo { .Bar = x }; | 6283 | \\ const foo = Foo { .Bar = x }; |
| 6841 | \\} | 6284 | \\} |
| 6842 | , | 6285 | , &[_][]const u8{ |
| 6843 | "tmp.zig:7:23: error: unable to evaluate constant expression", | 6286 | "tmp.zig:7:23: error: unable to evaluate constant expression", |
| 6844 | ); | 6287 | }); |
| 6845 | | 6288 | |
| 6846 | cases.addTest( | 6289 | cases.addTest("@shuffle with selected index past first vector length", |
| 6847 | "@shuffle with selected index past first vector length", | | |
| 6848 | \\export fn entry() void { | 6290 | \\export fn entry() void { |
| 6849 | \\ const v: @Vector(4, u32) = [4]u32{ 10, 11, 12, 13 }; | 6291 | \\ const v: @Vector(4, u32) = [4]u32{ 10, 11, 12, 13 }; |
| 6850 | \\ const x: @Vector(4, u32) = [4]u32{ 14, 15, 16, 17 }; | 6292 | \\ const x: @Vector(4, u32) = [4]u32{ 14, 15, 16, 17 }; |
| 6851 | \\ var z = @shuffle(u32, v, x, [8]i32{ 0, 1, 2, 3, 7, 6, 5, 4 }); | 6293 | \\ var z = @shuffle(u32, v, x, [8]i32{ 0, 1, 2, 3, 7, 6, 5, 4 }); |
| 6852 | \\} | 6294 | \\} |
| 6853 | , | 6295 | , &[_][]const u8{ |
| 6854 | "tmp.zig:4:39: error: mask index '4' has out-of-bounds selection", | 6296 | "tmp.zig:4:39: error: mask index '4' has out-of-bounds selection", |
| 6855 | "tmp.zig:4:27: note: selected index '7' out of bounds of @Vector(4, u32)", | 6297 | "tmp.zig:4:27: note: selected index '7' out of bounds of @Vector(4, u32)", |
| 6856 | "tmp.zig:4:30: note: selections from the second vector are specified with negative numbers", | 6298 | "tmp.zig:4:30: note: selections from the second vector are specified with negative numbers", |
| 6857 | ); | 6299 | }); |
| 6858 | | 6300 | |
| 6859 | cases.addTest( | 6301 | cases.addTest("nested vectors", |
| 6860 | "nested vectors", | | |
| 6861 | \\export fn entry() void { | 6302 | \\export fn entry() void { |
| 6862 | \\ const V = @Vector(4, @Vector(4, u8)); | 6303 | \\ const V = @Vector(4, @Vector(4, u8)); |
| 6863 | \\ var v: V = undefined; | 6304 | \\ var v: V = undefined; |
| 6864 | \\} | 6305 | \\} |
| 6865 | , | 6306 | , &[_][]const u8{ |
| 6866 | "tmp.zig:2:26: error: vector element type must be integer, float, bool, or pointer; '@Vector(4, u8)' is invalid", | 6307 | "tmp.zig:2:26: error: vector element type must be integer, float, bool, or pointer; '@Vector(4, u8)' is invalid", |
| 6867 | ); | 6308 | }); |
| 6868 | | 6309 | |
| 6869 | cases.addTest( | 6310 | cases.addTest("bad @splat type", |
| 6870 | "bad @splat type", | | |
| 6871 | \\export fn entry() void { | 6311 | \\export fn entry() void { |
| 6872 | \\ const c = 4; | 6312 | \\ const c = 4; |
| 6873 | \\ var v = @splat(4, c); | 6313 | \\ var v = @splat(4, c); |
| 6874 | \\} | 6314 | \\} |
| 6875 | , | 6315 | , &[_][]const u8{ |
| 6876 | "tmp.zig:3:23: error: vector element type must be integer, float, bool, or pointer; 'comptime_int' is invalid", | 6316 | "tmp.zig:3:23: error: vector element type must be integer, float, bool, or pointer; 'comptime_int' is invalid", |
| 6877 | ); | 6317 | }); |
| 6878 | | 6318 | |
| 6879 | cases.add("compileLog of tagged enum doesn't crash the compiler", | 6319 | cases.add("compileLog of tagged enum doesn't crash the compiler", |
| 6880 | \\const Bar = union(enum(u32)) { | 6320 | \\const Bar = union(enum(u32)) { |
| ... | @@ -6888,33 +6328,32 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -6888,33 +6328,32 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6888 | \\pub fn main () void { | 6328 | \\pub fn main () void { |
| 6889 | \\ comptime testCompileLog(Bar{.X = 123}); | 6329 | \\ comptime testCompileLog(Bar{.X = 123}); |
| 6890 | \\} | 6330 | \\} |
| 6891 | , "tmp.zig:6:5: error: found compile log statement"); | 6331 | , &[_][]const u8{ |
| | 6332 | "tmp.zig:6:5: error: found compile log statement", |
| | 6333 | }); |
| 6892 | | 6334 | |
| 6893 | cases.add( | 6335 | cases.add("attempted implicit cast from *const T to *[1]T", |
| 6894 | "attempted implicit cast from *const T to *[1]T", | | |
| 6895 | \\export fn entry(byte: u8) void { | 6336 | \\export fn entry(byte: u8) void { |
| 6896 | \\ const w: i32 = 1234; | 6337 | \\ const w: i32 = 1234; |
| 6897 | \\ var x: *const i32 = &w; | 6338 | \\ var x: *const i32 = &w; |
| 6898 | \\ var y: *[1]i32 = x; | 6339 | \\ var y: *[1]i32 = x; |
| 6899 | \\ y[0] += 1; | 6340 | \\ y[0] += 1; |
| 6900 | \\} | 6341 | \\} |
| 6901 | , | 6342 | , &[_][]const u8{ |
| 6902 | "tmp.zig:4:22: error: expected type '*[1]i32', found '*const i32'", | 6343 | "tmp.zig:4:22: error: expected type '*[1]i32', found '*const i32'", |
| 6903 | "tmp.zig:4:22: note: cast discards const qualifier", | 6344 | "tmp.zig:4:22: note: cast discards const qualifier", |
| 6904 | ); | 6345 | }); |
| 6905 | | 6346 | |
| 6906 | cases.add( | 6347 | cases.add("attempted implicit cast from *const T to []T", |
| 6907 | "attempted implicit cast from *const T to []T", | | |
| 6908 | \\export fn entry() void { | 6348 | \\export fn entry() void { |
| 6909 | \\ const u: u32 = 42; | 6349 | \\ const u: u32 = 42; |
| 6910 | \\ const x: []u32 = &u; | 6350 | \\ const x: []u32 = &u; |
| 6911 | \\} | 6351 | \\} |
| 6912 | , | 6352 | , &[_][]const u8{ |
| 6913 | "tmp.zig:3:23: error: expected type '[]u32', found '*const u32'", | 6353 | "tmp.zig:3:23: error: expected type '[]u32', found '*const u32'", |
| 6914 | ); | 6354 | }); |
| 6915 | | 6355 | |
| 6916 | cases.add( | 6356 | cases.add("for loop body expression ignored", |
| 6917 | "for loop body expression ignored", | | |
| 6918 | \\fn returns() usize { | 6357 | \\fn returns() usize { |
| 6919 | \\ return 2; | 6358 | \\ return 2; |
| 6920 | \\} | 6359 | \\} |
| ... | @@ -6925,37 +6364,35 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -6925,37 +6364,35 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6925 | \\ var x: anyerror!i32 = error.Bad; | 6364 | \\ var x: anyerror!i32 = error.Bad; |
| 6926 | \\ for ("hello") |_| returns() else unreachable; | 6365 | \\ for ("hello") |_| returns() else unreachable; |
| 6927 | \\} | 6366 | \\} |
| 6928 | , | 6367 | , &[_][]const u8{ |
| 6929 | "tmp.zig:5:30: error: expression value is ignored", | 6368 | "tmp.zig:5:30: error: expression value is ignored", |
| 6930 | "tmp.zig:9:30: error: expression value is ignored", | 6369 | "tmp.zig:9:30: error: expression value is ignored", |
| 6931 | ); | 6370 | }); |
| 6932 | | 6371 | |
| 6933 | cases.add( | 6372 | cases.add("aligned variable of zero-bit type", |
| 6934 | "aligned variable of zero-bit type", | | |
| 6935 | \\export fn f() void { | 6373 | \\export fn f() void { |
| 6936 | \\ var s: struct {} align(4) = undefined; | 6374 | \\ var s: struct {} align(4) = undefined; |
| 6937 | \\} | 6375 | \\} |
| 6938 | , | 6376 | , &[_][]const u8{ |
| 6939 | "tmp.zig:2:5: error: variable 's' of zero-bit type 'struct:2:12' has no in-memory representation, it cannot be aligned", | 6377 | "tmp.zig:2:5: error: variable 's' of zero-bit type 'struct:2:12' has no in-memory representation, it cannot be aligned", |
| 6940 | ); | 6378 | }); |
| 6941 | | 6379 | |
| 6942 | cases.add( | 6380 | cases.add("function returning opaque type", |
| 6943 | "function returning opaque type", | | |
| 6944 | \\const FooType = @OpaqueType(); | 6381 | \\const FooType = @OpaqueType(); |
| 6945 | \\export fn bar() !FooType { | 6382 | \\export fn bar() !FooType { |
| 6946 | \\ return error.InvalidValue; | 6383 | \\ return error.InvalidValue; |
| 6947 | \\} | 6384 | \\} |
| 6948 | , | 6385 | , &[_][]const u8{ |
| 6949 | "tmp.zig:2:18: error: opaque return type 'FooType' not allowed", | 6386 | "tmp.zig:2:18: error: opaque return type 'FooType' not allowed", |
| 6950 | "tmp.zig:1:1: note: declared here", | 6387 | "tmp.zig:1:1: note: declared here", |
| 6951 | ); | 6388 | }); |
| 6952 | | 6389 | |
| 6953 | cases.add( // fixed bug #2032 | 6390 | cases.add( // fixed bug #2032 |
| 6954 | "compile diagnostic string for top level decl type", | 6391 | "compile diagnostic string for top level decl type", |
| 6955 | \\export fn entry() void { | 6392 | \\export fn entry() void { |
| 6956 | \\ var foo: u32 = @This(){}; | 6393 | \\ var foo: u32 = @This(){}; |
| 6957 | \\} | 6394 | \\} |
| 6958 | , | 6395 | , &[_][]const u8{ |
| 6959 | "tmp.zig:2:27: error: type 'u32' does not support array initialization", | 6396 | "tmp.zig:2:27: error: type 'u32' does not support array initialization", |
| 6960 | ); | 6397 | }); |
| 6961 | } | 6398 | } |