| ... | ... | @@ -2,6 +2,15 @@ const tests = @import("tests.zig"); |
| 2 | 2 | const builtin = @import("builtin"); |
| 3 | 3 | |
| 4 | 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 | 14 | cases.add("comptime struct field, no init value", |
| 6 | 15 | \\const Foo = struct { |
| 7 | 16 | \\ comptime b: i32, |
| ... | ... | @@ -9,10 +18,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 9 | 18 | \\export fn entry() void { |
| 10 | 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( |
| 15 | | "bad usage of @call", |
| 25 | cases.add("bad usage of @call", |
| 16 | 26 | \\export fn entry1() void { |
| 17 | 27 | \\ @call(.{}, foo, {}); |
| 18 | 28 | \\} |
| ... | ... | @@ -33,24 +43,25 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 33 | 43 | \\inline fn bar() void {} |
| 34 | 44 | \\fn baz1() void {} |
| 35 | 45 | \\fn baz2() void {} |
| 36 | | , |
| 46 | , &[_][]const u8{ |
| 37 | 47 | "tmp.zig:2:21: error: expected tuple or struct, found 'void'", |
| 38 | 48 | "tmp.zig:5:14: error: unable to perform 'never_inline' call at compile-time", |
| 39 | 49 | "tmp.zig:8:14: error: unable to perform 'never_tail' call at compile-time", |
| 40 | 50 | "tmp.zig:11:5: error: no-inline call of inline function", |
| 41 | 51 | "tmp.zig:15:43: error: unable to evaluate constant expression", |
| 42 | | ); |
| 52 | }); |
| 43 | 53 | |
| 44 | 54 | cases.add("exported async function", |
| 45 | 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( |
| 49 | | "main missing name", |
| 60 | cases.addExe("main missing name", |
| 50 | 61 | \\pub fn (main) void {} |
| 51 | | , |
| 62 | , &[_][]const u8{ |
| 52 | 63 | "tmp.zig:1:5: error: missing function name", |
| 53 | | ); |
| 64 | }); |
| 54 | 65 | |
| 55 | 66 | cases.addCase(x: { |
| 56 | 67 | var tc = cases.create("call with new stack on unsupported target", |
| ... | ... | @@ -59,7 +70,9 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 59 | 70 | \\ @call(.{.stack = &buf}, foo, .{}); |
| 60 | 71 | \\} |
| 61 | 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 | 76 | tc.target = tests.Target{ |
| 64 | 77 | .Cross = tests.CrossTarget{ |
| 65 | 78 | .arch = .wasm32, |
| ... | ... | @@ -72,8 +85,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 72 | 85 | |
| 73 | 86 | // Note: One of the error messages here is backwards. It would be nice to fix, but that's not |
| 74 | 87 | // going to stop me from merging this branch which fixes a bunch of other stuff. |
| 75 | | cases.add( |
| 76 | | "incompatible sentinels", |
| 88 | cases.add("incompatible sentinels", |
| 77 | 89 | \\export fn entry1(ptr: [*:255]u8) [*:0]u8 { |
| 78 | 90 | \\ return ptr; |
| 79 | 91 | \\} |
| ... | ... | @@ -86,7 +98,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 86 | 98 | \\export fn entry4() void { |
| 87 | 99 | \\ var array: [2:0]u8 = [_]u8{1, 2}; |
| 88 | 100 | \\} |
| 89 | | , |
| 101 | , &[_][]const u8{ |
| 90 | 102 | "tmp.zig:2:12: error: expected type '[*:0]u8', found '[*:255]u8'", |
| 91 | 103 | "tmp.zig:2:12: note: destination pointer requires a terminating '0' sentinel, but source pointer has a terminating '255' sentinel", |
| 92 | 104 | "tmp.zig:5:12: error: expected type '[*:0]u8', found '[*]u8'", |
| ... | ... | @@ -96,20 +108,18 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 96 | 108 | "tmp.zig:8:35: note: destination array requires a terminating '255' sentinel, but source array has a terminating '0' sentinel", |
| 97 | 109 | "tmp.zig:11:31: error: expected type '[2:0]u8', found '[2]u8'", |
| 98 | 110 | "tmp.zig:11:31: note: destination array requires a terminating '0' sentinel", |
| 99 | | ); |
| 111 | }); |
| 100 | 112 | |
| 101 | | cases.add( |
| 102 | | "empty switch on an integer", |
| 113 | cases.add("empty switch on an integer", |
| 103 | 114 | \\export fn entry() void { |
| 104 | 115 | \\ var x: u32 = 0; |
| 105 | 116 | \\ switch(x) {} |
| 106 | 117 | \\} |
| 107 | | , |
| 118 | , &[_][]const u8{ |
| 108 | 119 | "tmp.zig:3:5: error: switch must handle all possibilities", |
| 109 | | ); |
| 120 | }); |
| 110 | 121 | |
| 111 | | cases.add( |
| 112 | | "incorrect return type", |
| 122 | cases.add("incorrect return type", |
| 113 | 123 | \\ pub export fn entry() void{ |
| 114 | 124 | \\ _ = foo(); |
| 115 | 125 | \\ } |
| ... | ... | @@ -125,12 +135,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 125 | 135 | \\ fn bar() B { |
| 126 | 136 | \\ unreachable; |
| 127 | 137 | \\ } |
| 128 | | , |
| 138 | , &[_][]const u8{ |
| 129 | 139 | "tmp.zig:8:16: error: expected type 'A', found 'B'", |
| 130 | | ); |
| 140 | }); |
| 131 | 141 | |
| 132 | | cases.add( |
| 133 | | "regression test #2980: base type u32 is not type checked properly when assigning a value within a struct", |
| 142 | cases.add("regression test #2980: base type u32 is not type checked properly when assigning a value within a struct", |
| 134 | 143 | \\const Foo = struct { |
| 135 | 144 | \\ ptr: ?*usize, |
| 136 | 145 | \\ uval: u32, |
| ... | ... | @@ -144,12 +153,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 144 | 153 | \\ .uval = get_uval(42), |
| 145 | 154 | \\ }; |
| 146 | 155 | \\} |
| 147 | | , |
| 156 | , &[_][]const u8{ |
| 148 | 157 | "tmp.zig:11:25: error: expected type 'u32', found '@typeOf(get_uval).ReturnType.ErrorSet!u32'", |
| 149 | | ); |
| 158 | }); |
| 150 | 159 | |
| 151 | | cases.add( |
| 152 | | "asigning to struct or union fields that are not optionals with a function that returns an optional", |
| 160 | cases.add("asigning to struct or union fields that are not optionals with a function that returns an optional", |
| 153 | 161 | \\fn maybe(is: bool) ?u8 { |
| 154 | 162 | \\ if (is) return @as(u8, 10) else return null; |
| 155 | 163 | \\} |
| ... | ... | @@ -163,24 +171,22 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 163 | 171 | \\ var u = U{ .Ye = maybe(false) }; |
| 164 | 172 | \\ var s = S{ .num = maybe(false) }; |
| 165 | 173 | \\} |
| 166 | | , |
| 174 | , &[_][]const u8{ |
| 167 | 175 | "tmp.zig:11:27: error: expected type 'u8', found '?u8'", |
| 168 | | ); |
| 176 | }); |
| 169 | 177 | |
| 170 | | cases.add( |
| 171 | | "missing result type for phi node", |
| 178 | cases.add("missing result type for phi node", |
| 172 | 179 | \\fn foo() !void { |
| 173 | 180 | \\ return anyerror.Foo; |
| 174 | 181 | \\} |
| 175 | 182 | \\export fn entry() void { |
| 176 | 183 | \\ foo() catch 0; |
| 177 | 184 | \\} |
| 178 | | , |
| 185 | , &[_][]const u8{ |
| 179 | 186 | "tmp.zig:5:17: error: integer value 0 cannot be coerced to type 'void'", |
| 180 | | ); |
| 187 | }); |
| 181 | 188 | |
| 182 | | cases.add( |
| 183 | | "atomicrmw with enum op not .Xchg", |
| 189 | cases.add("atomicrmw with enum op not .Xchg", |
| 184 | 190 | \\export fn entry() void { |
| 185 | 191 | \\ const E = enum(u8) { |
| 186 | 192 | \\ a, |
| ... | ... | @@ -191,34 +197,31 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 191 | 197 | \\ var x: E = .a; |
| 192 | 198 | \\ _ = @atomicRmw(E, &x, .Add, .b, .SeqCst); |
| 193 | 199 | \\} |
| 194 | | , |
| 200 | , &[_][]const u8{ |
| 195 | 201 | "tmp.zig:9:27: error: @atomicRmw on enum only works with .Xchg", |
| 196 | | ); |
| 202 | }); |
| 197 | 203 | |
| 198 | | cases.add( |
| 199 | | "disallow coercion from non-null-terminated pointer to null-terminated pointer", |
| 204 | cases.add("disallow coercion from non-null-terminated pointer to null-terminated pointer", |
| 200 | 205 | \\extern fn puts(s: [*:0]const u8) c_int; |
| 201 | 206 | \\pub fn main() void { |
| 202 | 207 | \\ const no_zero_array = [_]u8{'h', 'e', 'l', 'l', 'o'}; |
| 203 | 208 | \\ const no_zero_ptr: [*]const u8 = &no_zero_array; |
| 204 | 209 | \\ _ = puts(no_zero_ptr); |
| 205 | 210 | \\} |
| 206 | | , |
| 211 | , &[_][]const u8{ |
| 207 | 212 | "tmp.zig:5:14: error: expected type '[*:0]const u8', found '[*]const u8'", |
| 208 | | ); |
| 213 | }); |
| 209 | 214 | |
| 210 | | cases.add( |
| 211 | | "atomic orderings of atomicStore Acquire or AcqRel", |
| 215 | cases.add("atomic orderings of atomicStore Acquire or AcqRel", |
| 212 | 216 | \\export fn entry() void { |
| 213 | 217 | \\ var x: u32 = 0; |
| 214 | 218 | \\ @atomicStore(u32, &x, 1, .Acquire); |
| 215 | 219 | \\} |
| 216 | | , |
| 220 | , &[_][]const u8{ |
| 217 | 221 | "tmp.zig:3:30: error: @atomicStore atomic ordering must not be Acquire or AcqRel", |
| 218 | | ); |
| 222 | }); |
| 219 | 223 | |
| 220 | | cases.add( |
| 221 | | "missing const in slice with nested array type", |
| 224 | cases.add("missing const in slice with nested array type", |
| 222 | 225 | \\const Geo3DTex2D = struct { vertices: [][2]f32 }; |
| 223 | 226 | \\pub fn getGeo3DTex2D() Geo3DTex2D { |
| 224 | 227 | \\ return Geo3DTex2D{ |
| ... | ... | @@ -230,34 +233,31 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 230 | 233 | \\export fn entry() void { |
| 231 | 234 | \\ var geo_data = getGeo3DTex2D(); |
| 232 | 235 | \\} |
| 233 | | , |
| 236 | , &[_][]const u8{ |
| 234 | 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( |
| 238 | | "slicing of global undefined pointer", |
| 240 | cases.add("slicing of global undefined pointer", |
| 239 | 241 | \\var buf: *[1]u8 = undefined; |
| 240 | 242 | \\export fn entry() void { |
| 241 | 243 | \\ _ = buf[0..1]; |
| 242 | 244 | \\} |
| 243 | | , |
| 245 | , &[_][]const u8{ |
| 244 | 246 | "tmp.zig:3:12: error: non-zero length slice of undefined pointer", |
| 245 | | ); |
| 247 | }); |
| 246 | 248 | |
| 247 | | cases.add( |
| 248 | | "using invalid types in function call raises an error", |
| 249 | cases.add("using invalid types in function call raises an error", |
| 249 | 250 | \\const MenuEffect = enum {}; |
| 250 | 251 | \\fn func(effect: MenuEffect) void {} |
| 251 | 252 | \\export fn entry() void { |
| 252 | 253 | \\ func(MenuEffect.ThisDoesNotExist); |
| 253 | 254 | \\} |
| 254 | | , |
| 255 | , &[_][]const u8{ |
| 255 | 256 | "tmp.zig:1:20: error: enums must have 1 or more fields", |
| 256 | 257 | "tmp.zig:4:20: note: referenced here", |
| 257 | | ); |
| 258 | }); |
| 258 | 259 | |
| 259 | | cases.add( |
| 260 | | "store vector pointer with unknown runtime index", |
| 260 | cases.add("store vector pointer with unknown runtime index", |
| 261 | 261 | \\export fn entry() void { |
| 262 | 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 | 268 | \\fn storev(ptr: var, val: i32) void { |
| 269 | 269 | \\ ptr.* = val; |
| 270 | 270 | \\} |
| 271 | | , |
| 271 | , &[_][]const u8{ |
| 272 | 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( |
| 276 | | "load vector pointer with unknown runtime index", |
| 275 | cases.add("load vector pointer with unknown runtime index", |
| 277 | 276 | \\export fn entry() void { |
| 278 | 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 | 283 | \\fn loadv(ptr: var) i32 { |
| 285 | 284 | \\ return ptr.*; |
| 286 | 285 | \\} |
| 287 | | , |
| 286 | , &[_][]const u8{ |
| 288 | 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( |
| 292 | | "using an unknown len ptr type instead of array", |
| 290 | cases.add("using an unknown len ptr type instead of array", |
| 293 | 291 | \\const resolutions = [*][*]const u8{ |
| 294 | 292 | \\ "[320 240 ]", |
| 295 | 293 | \\ null, |
| ... | ... | @@ -297,22 +295,20 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 297 | 295 | \\comptime { |
| 298 | 296 | \\ _ = resolutions; |
| 299 | 297 | \\} |
| 300 | | , |
| 298 | , &[_][]const u8{ |
| 301 | 299 | "tmp.zig:1:21: error: expected array type or [_], found '[*][*]const u8'", |
| 302 | | ); |
| 300 | }); |
| 303 | 301 | |
| 304 | | cases.add( |
| 305 | | "comparison with error union and error value", |
| 302 | cases.add("comparison with error union and error value", |
| 306 | 303 | \\export fn entry() void { |
| 307 | 304 | \\ var number_or_error: anyerror!i32 = error.SomethingAwful; |
| 308 | 305 | \\ _ = number_or_error == error.SomethingAwful; |
| 309 | 306 | \\} |
| 310 | | , |
| 307 | , &[_][]const u8{ |
| 311 | 308 | "tmp.zig:3:25: error: operator not allowed for type 'anyerror!i32'", |
| 312 | | ); |
| 309 | }); |
| 313 | 310 | |
| 314 | | cases.add( |
| 315 | | "switch with overlapping case ranges", |
| 311 | cases.add("switch with overlapping case ranges", |
| 316 | 312 | \\export fn entry() void { |
| 317 | 313 | \\ var q: u8 = 0; |
| 318 | 314 | \\ switch (q) { |
| ... | ... | @@ -320,22 +316,20 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 320 | 316 | \\ 0...255 => {}, |
| 321 | 317 | \\ } |
| 322 | 318 | \\} |
| 323 | | , |
| 319 | , &[_][]const u8{ |
| 324 | 320 | "tmp.zig:5:9: error: duplicate switch value", |
| 325 | | ); |
| 321 | }); |
| 326 | 322 | |
| 327 | | cases.add( |
| 328 | | "invalid optional type in extern struct", |
| 323 | cases.add("invalid optional type in extern struct", |
| 329 | 324 | \\const stroo = extern struct { |
| 330 | 325 | \\ moo: ?[*c]u8, |
| 331 | 326 | \\}; |
| 332 | 327 | \\export fn testf(fluff: *stroo) void {} |
| 333 | | , |
| 328 | , &[_][]const u8{ |
| 334 | 329 | "tmp.zig:2:5: error: extern structs cannot contain fields of type '?[*c]u8'", |
| 335 | | ); |
| 330 | }); |
| 336 | 331 | |
| 337 | | cases.add( |
| 338 | | "attempt to negate a non-integer, non-float or non-vector type", |
| 332 | cases.add("attempt to negate a non-integer, non-float or non-vector type", |
| 339 | 333 | \\fn foo() anyerror!u32 { |
| 340 | 334 | \\ return 1; |
| 341 | 335 | \\} |
| ... | ... | @@ -343,42 +337,38 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 343 | 337 | \\export fn entry() void { |
| 344 | 338 | \\ const x = -foo(); |
| 345 | 339 | \\} |
| 346 | | , |
| 340 | , &[_][]const u8{ |
| 347 | 341 | "tmp.zig:6:15: error: negation of type 'anyerror!u32'", |
| 348 | | ); |
| 342 | }); |
| 349 | 343 | |
| 350 | | cases.add( |
| 351 | | "attempt to create 17 bit float type", |
| 344 | cases.add("attempt to create 17 bit float type", |
| 352 | 345 | \\const builtin = @import("builtin"); |
| 353 | 346 | \\comptime { |
| 354 | 347 | \\ _ = @Type(builtin.TypeInfo { .Float = builtin.TypeInfo.Float { .bits = 17 } }); |
| 355 | 348 | \\} |
| 356 | | , |
| 349 | , &[_][]const u8{ |
| 357 | 350 | "tmp.zig:3:32: error: 17-bit float unsupported", |
| 358 | | ); |
| 351 | }); |
| 359 | 352 | |
| 360 | | cases.add( |
| 361 | | "wrong type for @Type", |
| 353 | cases.add("wrong type for @Type", |
| 362 | 354 | \\export fn entry() void { |
| 363 | 355 | \\ _ = @Type(0); |
| 364 | 356 | \\} |
| 365 | | , |
| 357 | , &[_][]const u8{ |
| 366 | 358 | "tmp.zig:2:15: error: expected type 'std.builtin.TypeInfo', found 'comptime_int'", |
| 367 | | ); |
| 359 | }); |
| 368 | 360 | |
| 369 | | cases.add( |
| 370 | | "@Type with non-constant expression", |
| 361 | cases.add("@Type with non-constant expression", |
| 371 | 362 | \\const builtin = @import("builtin"); |
| 372 | 363 | \\var globalTypeInfo : builtin.TypeInfo = undefined; |
| 373 | 364 | \\export fn entry() void { |
| 374 | 365 | \\ _ = @Type(globalTypeInfo); |
| 375 | 366 | \\} |
| 376 | | , |
| 367 | , &[_][]const u8{ |
| 377 | 368 | "tmp.zig:4:15: error: unable to evaluate constant expression", |
| 378 | | ); |
| 369 | }); |
| 379 | 370 | |
| 380 | | cases.add( |
| 381 | | "@Type with TypeInfo.Int", |
| 371 | cases.add("@Type with TypeInfo.Int", |
| 382 | 372 | \\const builtin = @import("builtin"); |
| 383 | 373 | \\export fn entry() void { |
| 384 | 374 | \\ _ = @Type(builtin.TypeInfo.Int { |
| ... | ... | @@ -386,21 +376,19 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 386 | 376 | \\ .bits = 8, |
| 387 | 377 | \\ }); |
| 388 | 378 | \\} |
| 389 | | , |
| 379 | , &[_][]const u8{ |
| 390 | 380 | "tmp.zig:3:36: error: expected type 'std.builtin.TypeInfo', found 'std.builtin.Int'", |
| 391 | | ); |
| 381 | }); |
| 392 | 382 | |
| 393 | | cases.add( |
| 394 | | "Struct unavailable for @Type", |
| 383 | cases.add("Struct unavailable for @Type", |
| 395 | 384 | \\export fn entry() void { |
| 396 | 385 | \\ _ = @Type(@typeInfo(struct { })); |
| 397 | 386 | \\} |
| 398 | | , |
| 387 | , &[_][]const u8{ |
| 399 | 388 | "tmp.zig:2:15: error: @Type not availble for 'TypeInfo.Struct'", |
| 400 | | ); |
| 389 | }); |
| 401 | 390 | |
| 402 | | cases.add( |
| 403 | | "wrong type for result ptr to @asyncCall", |
| 391 | cases.add("wrong type for result ptr to @asyncCall", |
| 404 | 392 | \\export fn entry() void { |
| 405 | 393 | \\ _ = async amain(); |
| 406 | 394 | \\} |
| ... | ... | @@ -411,32 +399,29 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 411 | 399 | \\fn foo() i32 { |
| 412 | 400 | \\ return 1234; |
| 413 | 401 | \\} |
| 414 | | , |
| 402 | , &[_][]const u8{ |
| 415 | 403 | "tmp.zig:6:37: error: expected type '*i32', found 'bool'", |
| 416 | | ); |
| 404 | }); |
| 417 | 405 | |
| 418 | | cases.add( |
| 419 | | "shift amount has to be an integer type", |
| 406 | cases.add("shift amount has to be an integer type", |
| 420 | 407 | \\export fn entry() void { |
| 421 | 408 | \\ const x = 1 << &@as(u8, 10); |
| 422 | 409 | \\} |
| 423 | | , |
| 410 | , &[_][]const u8{ |
| 424 | 411 | "tmp.zig:2:21: error: shift amount has to be an integer type, but found '*u8'", |
| 425 | 412 | "tmp.zig:2:17: note: referenced here", |
| 426 | | ); |
| 413 | }); |
| 427 | 414 | |
| 428 | | cases.add( |
| 429 | | "bit shifting only works on integer types", |
| 415 | cases.add("bit shifting only works on integer types", |
| 430 | 416 | \\export fn entry() void { |
| 431 | 417 | \\ const x = &@as(u8, 1) << 10; |
| 432 | 418 | \\} |
| 433 | | , |
| 419 | , &[_][]const u8{ |
| 434 | 420 | "tmp.zig:2:16: error: bit shifting operation expected integer type, found '*u8'", |
| 435 | 421 | "tmp.zig:2:27: note: referenced here", |
| 436 | | ); |
| 422 | }); |
| 437 | 423 | |
| 438 | | cases.add( |
| 439 | | "struct depends on itself via optional field", |
| 424 | cases.add("struct depends on itself via optional field", |
| 440 | 425 | \\const LhsExpr = struct { |
| 441 | 426 | \\ rhsExpr: ?AstObject, |
| 442 | 427 | \\}; |
| ... | ... | @@ -447,14 +432,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 447 | 432 | \\ const lhsExpr = LhsExpr{ .rhsExpr = null }; |
| 448 | 433 | \\ const obj = AstObject{ .lhsExpr = lhsExpr }; |
| 449 | 434 | \\} |
| 450 | | , |
| 435 | , &[_][]const u8{ |
| 451 | 436 | "tmp.zig:1:17: error: struct 'LhsExpr' depends on itself", |
| 452 | 437 | "tmp.zig:5:5: note: while checking this field", |
| 453 | 438 | "tmp.zig:2:5: note: while checking this field", |
| 454 | | ); |
| 439 | }); |
| 455 | 440 | |
| 456 | | cases.add( |
| 457 | | "alignment of enum field specified", |
| 441 | cases.add("alignment of enum field specified", |
| 458 | 442 | \\const Number = enum { |
| 459 | 443 | \\ a, |
| 460 | 444 | \\ b align(i32), |
| ... | ... | @@ -462,23 +446,22 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 462 | 446 | \\export fn entry1() void { |
| 463 | 447 | \\ var x: Number = undefined; |
| 464 | 448 | \\} |
| 465 | | , |
| 449 | , &[_][]const u8{ |
| 466 | 450 | "tmp.zig:3:13: error: structs and unions, not enums, support field alignment", |
| 467 | 451 | "tmp.zig:1:16: note: consider 'union(enum)' here", |
| 468 | | ); |
| 452 | }); |
| 469 | 453 | |
| 470 | | cases.add( |
| 471 | | "bad alignment type", |
| 454 | cases.add("bad alignment type", |
| 472 | 455 | \\export fn entry1() void { |
| 473 | 456 | \\ var x: []align(true) i32 = undefined; |
| 474 | 457 | \\} |
| 475 | 458 | \\export fn entry2() void { |
| 476 | 459 | \\ var x: *align(@as(f64, 12.34)) i32 = undefined; |
| 477 | 460 | \\} |
| 478 | | , |
| 461 | , &[_][]const u8{ |
| 479 | 462 | "tmp.zig:2:20: error: expected type 'u29', found 'bool'", |
| 480 | 463 | "tmp.zig:5:19: error: fractional component prevents float value 12.340000 from being casted to type 'u29'", |
| 481 | | ); |
| 464 | }); |
| 482 | 465 | |
| 483 | 466 | cases.addCase(x: { |
| 484 | 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 | 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 | 477 | tc.target = tests.Target{ |
| 493 | 478 | .Cross = tests.CrossTarget{ |
| 494 | 479 | .arch = .x86_64, |
| ... | ... | @@ -499,8 +484,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 499 | 484 | break :x tc; |
| 500 | 485 | }); |
| 501 | 486 | |
| 502 | | cases.add( |
| 503 | | "indirect recursion of async functions detected", |
| 487 | cases.add("indirect recursion of async functions detected", |
| 504 | 488 | \\var frame: ?anyframe = null; |
| 505 | 489 | \\ |
| 506 | 490 | \\export fn a() void { |
| ... | ... | @@ -529,14 +513,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 529 | 513 | \\ var child = rangeSum(x - 1); |
| 530 | 514 | \\ return child + 1; |
| 531 | 515 | \\} |
| 532 | | , |
| 516 | , &[_][]const u8{ |
| 533 | 517 | "tmp.zig:8:1: error: '@Frame(rangeSum)' depends on itself", |
| 534 | 518 | "tmp.zig:15:33: note: when analyzing type '@Frame(rangeSum)' here", |
| 535 | 519 | "tmp.zig:26:25: note: when analyzing type '@Frame(rangeSumIndirect)' here", |
| 536 | | ); |
| 520 | }); |
| 537 | 521 | |
| 538 | | cases.add( |
| 539 | | "non-async function pointer eventually is inferred to become async", |
| 522 | cases.add("non-async function pointer eventually is inferred to become async", |
| 540 | 523 | \\export fn a() void { |
| 541 | 524 | \\ var non_async_fn: fn () void = undefined; |
| 542 | 525 | \\ non_async_fn = func; |
| ... | ... | @@ -544,45 +527,41 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 544 | 527 | \\fn func() void { |
| 545 | 528 | \\ suspend; |
| 546 | 529 | \\} |
| 547 | | , |
| 530 | , &[_][]const u8{ |
| 548 | 531 | "tmp.zig:5:1: error: 'func' cannot be async", |
| 549 | 532 | "tmp.zig:3:20: note: required to be non-async here", |
| 550 | 533 | "tmp.zig:6:5: note: suspends here", |
| 551 | | ); |
| 534 | }); |
| 552 | 535 | |
| 553 | | cases.add( |
| 554 | | "bad alignment in @asyncCall", |
| 536 | cases.add("bad alignment in @asyncCall", |
| 555 | 537 | \\export fn entry() void { |
| 556 | 538 | \\ var ptr: async fn () void = func; |
| 557 | 539 | \\ var bytes: [64]u8 = undefined; |
| 558 | 540 | \\ _ = @asyncCall(&bytes, {}, ptr); |
| 559 | 541 | \\} |
| 560 | 542 | \\async fn func() void {} |
| 561 | | , |
| 543 | , &[_][]const u8{ |
| 562 | 544 | "tmp.zig:4:21: error: expected type '[]align(16) u8', found '*[64]u8'", |
| 563 | | ); |
| 545 | }); |
| 564 | 546 | |
| 565 | | cases.add( |
| 566 | | "atomic orderings of fence Acquire or stricter", |
| 547 | cases.add("atomic orderings of fence Acquire or stricter", |
| 567 | 548 | \\export fn entry() void { |
| 568 | 549 | \\ @fence(.Monotonic); |
| 569 | 550 | \\} |
| 570 | | , |
| 551 | , &[_][]const u8{ |
| 571 | 552 | "tmp.zig:2:12: error: atomic ordering must be Acquire or stricter", |
| 572 | | ); |
| 553 | }); |
| 573 | 554 | |
| 574 | | cases.add( |
| 575 | | "bad alignment in implicit cast from array pointer to slice", |
| 555 | cases.add("bad alignment in implicit cast from array pointer to slice", |
| 576 | 556 | \\export fn a() void { |
| 577 | 557 | \\ var x: [10]u8 = undefined; |
| 578 | 558 | \\ var y: []align(16) u8 = &x; |
| 579 | 559 | \\} |
| 580 | | , |
| 560 | , &[_][]const u8{ |
| 581 | 561 | "tmp.zig:3:30: error: expected type '[]align(16) u8', found '*[10]u8'", |
| 582 | | ); |
| 562 | }); |
| 583 | 563 | |
| 584 | | cases.add( |
| 585 | | "result location incompatibility mismatching handle_is_ptr (generic call)", |
| 564 | cases.add("result location incompatibility mismatching handle_is_ptr (generic call)", |
| 586 | 565 | \\export fn entry() void { |
| 587 | 566 | \\ var damn = Container{ |
| 588 | 567 | \\ .not_optional = getOptional(i32), |
| ... | ... | @@ -594,12 +573,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 594 | 573 | \\pub const Container = struct { |
| 595 | 574 | \\ not_optional: i32, |
| 596 | 575 | \\}; |
| 597 | | , |
| 576 | , &[_][]const u8{ |
| 598 | 577 | "tmp.zig:3:36: error: expected type 'i32', found '?i32'", |
| 599 | | ); |
| 578 | }); |
| 600 | 579 | |
| 601 | | cases.add( |
| 602 | | "result location incompatibility mismatching handle_is_ptr", |
| 580 | cases.add("result location incompatibility mismatching handle_is_ptr", |
| 603 | 581 | \\export fn entry() void { |
| 604 | 582 | \\ var damn = Container{ |
| 605 | 583 | \\ .not_optional = getOptional(), |
| ... | ... | @@ -611,12 +589,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 611 | 589 | \\pub const Container = struct { |
| 612 | 590 | \\ not_optional: i32, |
| 613 | 591 | \\}; |
| 614 | | , |
| 592 | , &[_][]const u8{ |
| 615 | 593 | "tmp.zig:3:36: error: expected type 'i32', found '?i32'", |
| 616 | | ); |
| 594 | }); |
| 617 | 595 | |
| 618 | | cases.add( |
| 619 | | "const frame cast to anyframe", |
| 596 | cases.add("const frame cast to anyframe", |
| 620 | 597 | \\export fn a() void { |
| 621 | 598 | \\ const f = async func(); |
| 622 | 599 | \\ resume f; |
| ... | ... | @@ -628,13 +605,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 628 | 605 | \\fn func() void { |
| 629 | 606 | \\ suspend; |
| 630 | 607 | \\} |
| 631 | | , |
| 608 | , &[_][]const u8{ |
| 632 | 609 | "tmp.zig:3:12: error: expected type 'anyframe', found '*const @Frame(func)'", |
| 633 | 610 | "tmp.zig:7:24: error: expected type 'anyframe', found '*const @Frame(func)'", |
| 634 | | ); |
| 611 | }); |
| 635 | 612 | |
| 636 | | cases.add( |
| 637 | | "prevent bad implicit casting of anyframe types", |
| 613 | cases.add("prevent bad implicit casting of anyframe types", |
| 638 | 614 | \\export fn a() void { |
| 639 | 615 | \\ var x: anyframe = undefined; |
| 640 | 616 | \\ var y: anyframe->i32 = x; |
| ... | ... | @@ -648,14 +624,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 648 | 624 | \\ var y: anyframe->i32 = &x; |
| 649 | 625 | \\} |
| 650 | 626 | \\fn func() void {} |
| 651 | | , |
| 627 | , &[_][]const u8{ |
| 652 | 628 | "tmp.zig:3:28: error: expected type 'anyframe->i32', found 'anyframe'", |
| 653 | 629 | "tmp.zig:7:28: error: expected type 'anyframe->i32', found 'i32'", |
| 654 | 630 | "tmp.zig:11:29: error: expected type 'anyframe->i32', found '*@Frame(func)'", |
| 655 | | ); |
| 631 | }); |
| 656 | 632 | |
| 657 | | cases.add( |
| 658 | | "wrong frame type used for async call", |
| 633 | cases.add("wrong frame type used for async call", |
| 659 | 634 | \\export fn entry() void { |
| 660 | 635 | \\ var frame: @Frame(foo) = undefined; |
| 661 | 636 | \\ frame = async bar(); |
| ... | ... | @@ -666,37 +641,34 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 666 | 641 | \\fn bar() void { |
| 667 | 642 | \\ suspend; |
| 668 | 643 | \\} |
| 669 | | , |
| 644 | , &[_][]const u8{ |
| 670 | 645 | "tmp.zig:3:5: error: expected type '*@Frame(bar)', found '*@Frame(foo)'", |
| 671 | | ); |
| 646 | }); |
| 672 | 647 | |
| 673 | | cases.add( |
| 674 | | "@Frame() of generic function", |
| 648 | cases.add("@Frame() of generic function", |
| 675 | 649 | \\export fn entry() void { |
| 676 | 650 | \\ var frame: @Frame(func) = undefined; |
| 677 | 651 | \\} |
| 678 | 652 | \\fn func(comptime T: type) void { |
| 679 | 653 | \\ var x: T = undefined; |
| 680 | 654 | \\} |
| 681 | | , |
| 655 | , &[_][]const u8{ |
| 682 | 656 | "tmp.zig:2:16: error: @Frame() of generic function", |
| 683 | | ); |
| 657 | }); |
| 684 | 658 | |
| 685 | | cases.add( |
| 686 | | "@frame() causes function to be async", |
| 659 | cases.add("@frame() causes function to be async", |
| 687 | 660 | \\export fn entry() void { |
| 688 | 661 | \\ func(); |
| 689 | 662 | \\} |
| 690 | 663 | \\fn func() void { |
| 691 | 664 | \\ _ = @frame(); |
| 692 | 665 | \\} |
| 693 | | , |
| 666 | , &[_][]const u8{ |
| 694 | 667 | "tmp.zig:1:1: error: function with calling convention 'ccc' cannot be async", |
| 695 | 668 | "tmp.zig:5:9: note: @frame() causes function to be async", |
| 696 | | ); |
| 669 | }); |
| 697 | 670 | |
| 698 | | cases.add( |
| 699 | | "invalid suspend in exported function", |
| 671 | cases.add("invalid suspend in exported function", |
| 700 | 672 | \\export fn entry() void { |
| 701 | 673 | \\ var frame = async func(); |
| 702 | 674 | \\ var result = await frame; |
| ... | ... | @@ -704,13 +676,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 704 | 676 | \\fn func() void { |
| 705 | 677 | \\ suspend; |
| 706 | 678 | \\} |
| 707 | | , |
| 679 | , &[_][]const u8{ |
| 708 | 680 | "tmp.zig:1:1: error: function with calling convention 'ccc' cannot be async", |
| 709 | 681 | "tmp.zig:3:18: note: await here is a suspend point", |
| 710 | | ); |
| 682 | }); |
| 711 | 683 | |
| 712 | | cases.add( |
| 713 | | "async function indirectly depends on its own frame", |
| 684 | cases.add("async function indirectly depends on its own frame", |
| 714 | 685 | \\export fn entry() void { |
| 715 | 686 | \\ _ = async amain(); |
| 716 | 687 | \\} |
| ... | ... | @@ -720,39 +691,36 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 720 | 691 | \\fn other() void { |
| 721 | 692 | \\ var x: [@sizeOf(@Frame(amain))]u8 = undefined; |
| 722 | 693 | \\} |
| 723 | | , |
| 694 | , &[_][]const u8{ |
| 724 | 695 | "tmp.zig:4:1: error: unable to determine async function frame of 'amain'", |
| 725 | 696 | "tmp.zig:5:10: note: analysis of function 'other' depends on the frame", |
| 726 | 697 | "tmp.zig:8:13: note: referenced here", |
| 727 | | ); |
| 698 | }); |
| 728 | 699 | |
| 729 | | cases.add( |
| 730 | | "async function depends on its own frame", |
| 700 | cases.add("async function depends on its own frame", |
| 731 | 701 | \\export fn entry() void { |
| 732 | 702 | \\ _ = async amain(); |
| 733 | 703 | \\} |
| 734 | 704 | \\async fn amain() void { |
| 735 | 705 | \\ var x: [@sizeOf(@Frame(amain))]u8 = undefined; |
| 736 | 706 | \\} |
| 737 | | , |
| 707 | , &[_][]const u8{ |
| 738 | 708 | "tmp.zig:4:1: error: cannot resolve '@Frame(amain)': function not fully analyzed yet", |
| 739 | 709 | "tmp.zig:5:13: note: referenced here", |
| 740 | | ); |
| 710 | }); |
| 741 | 711 | |
| 742 | | cases.add( |
| 743 | | "non async function pointer passed to @asyncCall", |
| 712 | cases.add("non async function pointer passed to @asyncCall", |
| 744 | 713 | \\export fn entry() void { |
| 745 | 714 | \\ var ptr = afunc; |
| 746 | 715 | \\ var bytes: [100]u8 align(16) = undefined; |
| 747 | 716 | \\ _ = @asyncCall(&bytes, {}, ptr); |
| 748 | 717 | \\} |
| 749 | 718 | \\fn afunc() void { } |
| 750 | | , |
| 719 | , &[_][]const u8{ |
| 751 | 720 | "tmp.zig:4:32: error: expected async function, found 'fn() void'", |
| 752 | | ); |
| 721 | }); |
| 753 | 722 | |
| 754 | | cases.add( |
| 755 | | "runtime-known async function called", |
| 723 | cases.add("runtime-known async function called", |
| 756 | 724 | \\export fn entry() void { |
| 757 | 725 | \\ _ = async amain(); |
| 758 | 726 | \\} |
| ... | ... | @@ -761,24 +729,22 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 761 | 729 | \\ _ = ptr(); |
| 762 | 730 | \\} |
| 763 | 731 | \\async fn afunc() void {} |
| 764 | | , |
| 732 | , &[_][]const u8{ |
| 765 | 733 | "tmp.zig:6:12: error: function is not comptime-known; @asyncCall required", |
| 766 | | ); |
| 734 | }); |
| 767 | 735 | |
| 768 | | cases.add( |
| 769 | | "runtime-known function called with async keyword", |
| 736 | cases.add("runtime-known function called with async keyword", |
| 770 | 737 | \\export fn entry() void { |
| 771 | 738 | \\ var ptr = afunc; |
| 772 | 739 | \\ _ = async ptr(); |
| 773 | 740 | \\} |
| 774 | 741 | \\ |
| 775 | 742 | \\async fn afunc() void { } |
| 776 | | , |
| 743 | , &[_][]const u8{ |
| 777 | 744 | "tmp.zig:3:15: error: function is not comptime-known; @asyncCall required", |
| 778 | | ); |
| 745 | }); |
| 779 | 746 | |
| 780 | | cases.add( |
| 781 | | "function with ccc indirectly calling async function", |
| 747 | cases.add("function with ccc indirectly calling async function", |
| 782 | 748 | \\export fn entry() void { |
| 783 | 749 | \\ foo(); |
| 784 | 750 | \\} |
| ... | ... | @@ -788,15 +754,14 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 788 | 754 | \\fn bar() void { |
| 789 | 755 | \\ suspend; |
| 790 | 756 | \\} |
| 791 | | , |
| 757 | , &[_][]const u8{ |
| 792 | 758 | "tmp.zig:1:1: error: function with calling convention 'ccc' cannot be async", |
| 793 | 759 | "tmp.zig:2:8: note: async function call here", |
| 794 | 760 | "tmp.zig:5:8: note: async function call here", |
| 795 | 761 | "tmp.zig:8:5: note: suspends here", |
| 796 | | ); |
| 762 | }); |
| 797 | 763 | |
| 798 | | cases.add( |
| 799 | | "capture group on switch prong with incompatible payload types", |
| 764 | cases.add("capture group on switch prong with incompatible payload types", |
| 800 | 765 | \\const Union = union(enum) { |
| 801 | 766 | \\ A: usize, |
| 802 | 767 | \\ B: isize, |
| ... | ... | @@ -807,59 +772,53 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 807 | 772 | \\ .A, .B => |e| unreachable, |
| 808 | 773 | \\ } |
| 809 | 774 | \\} |
| 810 | | , |
| 775 | , &[_][]const u8{ |
| 811 | 776 | "tmp.zig:8:20: error: capture group with incompatible types", |
| 812 | 777 | "tmp.zig:8:9: note: type 'usize' here", |
| 813 | 778 | "tmp.zig:8:13: note: type 'isize' here", |
| 814 | | ); |
| 779 | }); |
| 815 | 780 | |
| 816 | | cases.add( |
| 817 | | "wrong type to @hasField", |
| 781 | cases.add("wrong type to @hasField", |
| 818 | 782 | \\export fn entry() bool { |
| 819 | 783 | \\ return @hasField(i32, "hi"); |
| 820 | 784 | \\} |
| 821 | | , |
| 785 | , &[_][]const u8{ |
| 822 | 786 | "tmp.zig:2:22: error: type 'i32' does not support @hasField", |
| 823 | | ); |
| 787 | }); |
| 824 | 788 | |
| 825 | | cases.add( |
| 826 | | "slice passed as array init type with elems", |
| 789 | cases.add("slice passed as array init type with elems", |
| 827 | 790 | \\export fn entry() void { |
| 828 | 791 | \\ const x = []u8{1, 2}; |
| 829 | 792 | \\} |
| 830 | | , |
| 793 | , &[_][]const u8{ |
| 831 | 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( |
| 835 | | "slice passed as array init type", |
| 797 | cases.add("slice passed as array init type", |
| 836 | 798 | \\export fn entry() void { |
| 837 | 799 | \\ const x = []u8{}; |
| 838 | 800 | \\} |
| 839 | | , |
| 801 | , &[_][]const u8{ |
| 840 | 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( |
| 844 | | "inferred array size invalid here", |
| 805 | cases.add("inferred array size invalid here", |
| 845 | 806 | \\export fn entry() void { |
| 846 | 807 | \\ const x = [_]u8; |
| 847 | 808 | \\} |
| 848 | | , |
| 809 | , &[_][]const u8{ |
| 849 | 810 | "tmp.zig:2:15: error: inferred array size invalid here", |
| 850 | | ); |
| 811 | }); |
| 851 | 812 | |
| 852 | | cases.add( |
| 853 | | "initializing array with struct syntax", |
| 813 | cases.add("initializing array with struct syntax", |
| 854 | 814 | \\export fn entry() void { |
| 855 | 815 | \\ const x = [_]u8{ .y = 2 }; |
| 856 | 816 | \\} |
| 857 | | , |
| 817 | , &[_][]const u8{ |
| 858 | 818 | "tmp.zig:2:15: error: initializing array with struct syntax", |
| 859 | | ); |
| 819 | }); |
| 860 | 820 | |
| 861 | | cases.add( |
| 862 | | "compile error in struct init expression", |
| 821 | cases.add("compile error in struct init expression", |
| 863 | 822 | \\const Foo = struct { |
| 864 | 823 | \\ a: i32 = crap, |
| 865 | 824 | \\ b: i32, |
| ... | ... | @@ -869,54 +828,49 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 869 | 828 | \\ .b = 5, |
| 870 | 829 | \\ }; |
| 871 | 830 | \\} |
| 872 | | , |
| 831 | , &[_][]const u8{ |
| 873 | 832 | "tmp.zig:2:14: error: use of undeclared identifier 'crap'", |
| 874 | | ); |
| 833 | }); |
| 875 | 834 | |
| 876 | | cases.add( |
| 877 | | "undefined as field type is rejected", |
| 835 | cases.add("undefined as field type is rejected", |
| 878 | 836 | \\const Foo = struct { |
| 879 | 837 | \\ a: undefined, |
| 880 | 838 | \\}; |
| 881 | 839 | \\export fn entry1() void { |
| 882 | 840 | \\ const foo: Foo = undefined; |
| 883 | 841 | \\} |
| 884 | | , |
| 842 | , &[_][]const u8{ |
| 885 | 843 | "tmp.zig:2:8: error: use of undefined value here causes undefined behavior", |
| 886 | | ); |
| 844 | }); |
| 887 | 845 | |
| 888 | | cases.add( |
| 889 | | "@hasDecl with non-container", |
| 846 | cases.add("@hasDecl with non-container", |
| 890 | 847 | \\export fn entry() void { |
| 891 | 848 | \\ _ = @hasDecl(i32, "hi"); |
| 892 | 849 | \\} |
| 893 | | , |
| 850 | , &[_][]const u8{ |
| 894 | 851 | "tmp.zig:2:18: error: expected struct, enum, or union; found 'i32'", |
| 895 | | ); |
| 852 | }); |
| 896 | 853 | |
| 897 | | cases.add( |
| 898 | | "field access of slices", |
| 854 | cases.add("field access of slices", |
| 899 | 855 | \\export fn entry() void { |
| 900 | 856 | \\ var slice: []i32 = undefined; |
| 901 | 857 | \\ const info = @typeOf(slice).unknown; |
| 902 | 858 | \\} |
| 903 | | , |
| 859 | , &[_][]const u8{ |
| 904 | 860 | "tmp.zig:3:32: error: type '[]i32' does not support field access", |
| 905 | | ); |
| 861 | }); |
| 906 | 862 | |
| 907 | | cases.add( |
| 908 | | "peer cast then implicit cast const pointer to mutable C pointer", |
| 863 | cases.add("peer cast then implicit cast const pointer to mutable C pointer", |
| 909 | 864 | \\export fn func() void { |
| 910 | 865 | \\ var strValue: [*c]u8 = undefined; |
| 911 | 866 | \\ strValue = strValue orelse ""; |
| 912 | 867 | \\} |
| 913 | | , |
| 868 | , &[_][]const u8{ |
| 914 | 869 | "tmp.zig:3:32: error: expected type '[*c]u8', found '*const [0:0]u8'", |
| 915 | 870 | "tmp.zig:3:32: note: cast discards const qualifier", |
| 916 | | ); |
| 871 | }); |
| 917 | 872 | |
| 918 | | cases.add( |
| 919 | | "overflow in enum value allocation", |
| 873 | cases.add("overflow in enum value allocation", |
| 920 | 874 | \\const Moo = enum(u8) { |
| 921 | 875 | \\ Last = 255, |
| 922 | 876 | \\ Over, |
| ... | ... | @@ -924,32 +878,29 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 924 | 878 | \\pub fn main() void { |
| 925 | 879 | \\ var y = Moo.Last; |
| 926 | 880 | \\} |
| 927 | | , |
| 881 | , &[_][]const u8{ |
| 928 | 882 | "tmp.zig:3:5: error: enumeration value 256 too large for type 'u8'", |
| 929 | | ); |
| 883 | }); |
| 930 | 884 | |
| 931 | | cases.add( |
| 932 | | "attempt to cast enum literal to error", |
| 885 | cases.add("attempt to cast enum literal to error", |
| 933 | 886 | \\export fn entry() void { |
| 934 | 887 | \\ switch (error.Hi) { |
| 935 | 888 | \\ .Hi => {}, |
| 936 | 889 | \\ } |
| 937 | 890 | \\} |
| 938 | | , |
| 891 | , &[_][]const u8{ |
| 939 | 892 | "tmp.zig:3:9: error: expected type 'error{Hi}', found '(enum literal)'", |
| 940 | | ); |
| 893 | }); |
| 941 | 894 | |
| 942 | | cases.add( |
| 943 | | "@sizeOf bad type", |
| 895 | cases.add("@sizeOf bad type", |
| 944 | 896 | \\export fn entry() usize { |
| 945 | 897 | \\ return @sizeOf(@typeOf(null)); |
| 946 | 898 | \\} |
| 947 | | , |
| 899 | , &[_][]const u8{ |
| 948 | 900 | "tmp.zig:2:20: error: no size available for type '(null)'", |
| 949 | | ); |
| 901 | }); |
| 950 | 902 | |
| 951 | | cases.add( |
| 952 | | "generic function where return type is self-referenced", |
| 903 | cases.add("generic function where return type is self-referenced", |
| 953 | 904 | \\fn Foo(comptime T: type) Foo(T) { |
| 954 | 905 | \\ return struct{ x: T }; |
| 955 | 906 | \\} |
| ... | ... | @@ -958,22 +909,20 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 958 | 909 | \\ .x = 1 |
| 959 | 910 | \\ }; |
| 960 | 911 | \\} |
| 961 | | , |
| 912 | , &[_][]const u8{ |
| 962 | 913 | "tmp.zig:1:29: error: evaluation exceeded 1000 backwards branches", |
| 963 | 914 | "tmp.zig:5:18: note: referenced here", |
| 964 | | ); |
| 915 | }); |
| 965 | 916 | |
| 966 | | cases.add( |
| 967 | | "@ptrToInt 0 to non optional pointer", |
| 917 | cases.add("@ptrToInt 0 to non optional pointer", |
| 968 | 918 | \\export fn entry() void { |
| 969 | 919 | \\ var b = @intToPtr(*i32, 0); |
| 970 | 920 | \\} |
| 971 | | , |
| 921 | , &[_][]const u8{ |
| 972 | 922 | "tmp.zig:2:13: error: pointer type '*i32' does not allow address zero", |
| 973 | | ); |
| 923 | }); |
| 974 | 924 | |
| 975 | | cases.add( |
| 976 | | "cast enum literal to enum but it doesn't match", |
| 925 | cases.add("cast enum literal to enum but it doesn't match", |
| 977 | 926 | \\const Foo = enum { |
| 978 | 927 | \\ a, |
| 979 | 928 | \\ b, |
| ... | ... | @@ -981,34 +930,31 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 981 | 930 | \\export fn entry() void { |
| 982 | 931 | \\ const x: Foo = .c; |
| 983 | 932 | \\} |
| 984 | | , |
| 933 | , &[_][]const u8{ |
| 985 | 934 | "tmp.zig:6:20: error: enum 'Foo' has no field named 'c'", |
| 986 | 935 | "tmp.zig:1:13: note: 'Foo' declared here", |
| 987 | | ); |
| 936 | }); |
| 988 | 937 | |
| 989 | | cases.add( |
| 990 | | "discarding error value", |
| 938 | cases.add("discarding error value", |
| 991 | 939 | \\export fn entry() void { |
| 992 | 940 | \\ _ = foo(); |
| 993 | 941 | \\} |
| 994 | 942 | \\fn foo() !void { |
| 995 | 943 | \\ return error.OutOfMemory; |
| 996 | 944 | \\} |
| 997 | | , |
| 945 | , &[_][]const u8{ |
| 998 | 946 | "tmp.zig:2:12: error: error is discarded", |
| 999 | | ); |
| 947 | }); |
| 1000 | 948 | |
| 1001 | | cases.add( |
| 1002 | | "volatile on global assembly", |
| 949 | cases.add("volatile on global assembly", |
| 1003 | 950 | \\comptime { |
| 1004 | 951 | \\ asm volatile (""); |
| 1005 | 952 | \\} |
| 1006 | | , |
| 953 | , &[_][]const u8{ |
| 1007 | 954 | "tmp.zig:2:9: error: volatile is meaningless on global assembly", |
| 1008 | | ); |
| 955 | }); |
| 1009 | 956 | |
| 1010 | | cases.add( |
| 1011 | | "invalid multiple dereferences", |
| 957 | cases.add("invalid multiple dereferences", |
| 1012 | 958 | \\export fn a() void { |
| 1013 | 959 | \\ var box = Box{ .field = 0 }; |
| 1014 | 960 | \\ box.*.field = 1; |
| ... | ... | @@ -1021,20 +967,18 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1021 | 967 | \\pub const Box = struct { |
| 1022 | 968 | \\ field: i32, |
| 1023 | 969 | \\}; |
| 1024 | | , |
| 970 | , &[_][]const u8{ |
| 1025 | 971 | "tmp.zig:3:8: error: attempt to dereference non-pointer type 'Box'", |
| 1026 | 972 | "tmp.zig:8:13: error: attempt to dereference non-pointer type 'Box'", |
| 1027 | | ); |
| 973 | }); |
| 1028 | 974 | |
| 1029 | | cases.add( |
| 1030 | | "usingnamespace with wrong type", |
| 975 | cases.add("usingnamespace with wrong type", |
| 1031 | 976 | \\usingnamespace void; |
| 1032 | | , |
| 977 | , &[_][]const u8{ |
| 1033 | 978 | "tmp.zig:1:1: error: expected struct, enum, or union; found 'void'", |
| 1034 | | ); |
| 979 | }); |
| 1035 | 980 | |
| 1036 | | cases.add( |
| 1037 | | "ignored expression in while continuation", |
| 981 | cases.add("ignored expression in while continuation", |
| 1038 | 982 | \\export fn a() void { |
| 1039 | 983 | \\ while (true) : (bad()) {} |
| 1040 | 984 | \\} |
| ... | ... | @@ -1049,96 +993,86 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1049 | 993 | \\fn bad() anyerror!void { |
| 1050 | 994 | \\ return error.Bad; |
| 1051 | 995 | \\} |
| 1052 | | , |
| 996 | , &[_][]const u8{ |
| 1053 | 997 | "tmp.zig:2:24: error: expression value is ignored", |
| 1054 | 998 | "tmp.zig:6:25: error: expression value is ignored", |
| 1055 | 999 | "tmp.zig:10:25: error: expression value is ignored", |
| 1056 | | ); |
| 1000 | }); |
| 1057 | 1001 | |
| 1058 | | cases.add( |
| 1059 | | "empty while loop body", |
| 1002 | cases.add("empty while loop body", |
| 1060 | 1003 | \\export fn a() void { |
| 1061 | 1004 | \\ while(true); |
| 1062 | 1005 | \\} |
| 1063 | | , |
| 1006 | , &[_][]const u8{ |
| 1064 | 1007 | "tmp.zig:2:16: error: expected loop body, found ';'", |
| 1065 | | ); |
| 1008 | }); |
| 1066 | 1009 | |
| 1067 | | cases.add( |
| 1068 | | "empty for loop body", |
| 1010 | cases.add("empty for loop body", |
| 1069 | 1011 | \\export fn a() void { |
| 1070 | 1012 | \\ for(undefined) |x|; |
| 1071 | 1013 | \\} |
| 1072 | | , |
| 1014 | , &[_][]const u8{ |
| 1073 | 1015 | "tmp.zig:2:23: error: expected loop body, found ';'", |
| 1074 | | ); |
| 1016 | }); |
| 1075 | 1017 | |
| 1076 | | cases.add( |
| 1077 | | "empty if body", |
| 1018 | cases.add("empty if body", |
| 1078 | 1019 | \\export fn a() void { |
| 1079 | 1020 | \\ if(true); |
| 1080 | 1021 | \\} |
| 1081 | | , |
| 1022 | , &[_][]const u8{ |
| 1082 | 1023 | "tmp.zig:2:13: error: expected if body, found ';'", |
| 1083 | | ); |
| 1024 | }); |
| 1084 | 1025 | |
| 1085 | | cases.add( |
| 1086 | | "import outside package path", |
| 1026 | cases.add("import outside package path", |
| 1087 | 1027 | \\comptime{ |
| 1088 | 1028 | \\ _ = @import("../a.zig"); |
| 1089 | 1029 | \\} |
| 1090 | | , |
| 1030 | , &[_][]const u8{ |
| 1091 | 1031 | "tmp.zig:2:9: error: import of file outside package path: '../a.zig'", |
| 1092 | | ); |
| 1032 | }); |
| 1093 | 1033 | |
| 1094 | | cases.add( |
| 1095 | | "bogus compile var", |
| 1034 | cases.add("bogus compile var", |
| 1096 | 1035 | \\const x = @import("builtin").bogus; |
| 1097 | 1036 | \\export fn entry() usize { return @sizeOf(@typeOf(x)); } |
| 1098 | | , |
| 1037 | , &[_][]const u8{ |
| 1099 | 1038 | "tmp.zig:1:29: error: container 'builtin' has no member called 'bogus'", |
| 1100 | | ); |
| 1039 | }); |
| 1101 | 1040 | |
| 1102 | | cases.add( |
| 1103 | | "wrong panic signature, runtime function", |
| 1041 | cases.add("wrong panic signature, runtime function", |
| 1104 | 1042 | \\test "" {} |
| 1105 | 1043 | \\ |
| 1106 | 1044 | \\pub fn panic() void {} |
| 1107 | 1045 | \\ |
| 1108 | | , |
| 1046 | , &[_][]const u8{ |
| 1109 | 1047 | "error: expected type 'fn([]const u8, ?*std.builtin.StackTrace) noreturn', found 'fn() void'", |
| 1110 | | ); |
| 1048 | }); |
| 1111 | 1049 | |
| 1112 | | cases.add( |
| 1113 | | "wrong panic signature, generic function", |
| 1050 | cases.add("wrong panic signature, generic function", |
| 1114 | 1051 | \\pub fn panic(comptime msg: []const u8, error_return_trace: ?*builtin.StackTrace) noreturn { |
| 1115 | 1052 | \\ while (true) {} |
| 1116 | 1053 | \\} |
| 1117 | | , |
| 1054 | , &[_][]const u8{ |
| 1118 | 1055 | "error: expected type 'fn([]const u8, ?*std.builtin.StackTrace) noreturn', found 'fn([]const u8,var)var'", |
| 1119 | 1056 | "note: only one of the functions is generic", |
| 1120 | | ); |
| 1057 | }); |
| 1121 | 1058 | |
| 1122 | | cases.add( |
| 1123 | | "direct struct loop", |
| 1059 | cases.add("direct struct loop", |
| 1124 | 1060 | \\const A = struct { a : A, }; |
| 1125 | 1061 | \\export fn entry() usize { return @sizeOf(A); } |
| 1126 | | , |
| 1062 | , &[_][]const u8{ |
| 1127 | 1063 | "tmp.zig:1:11: error: struct 'A' depends on itself", |
| 1128 | | ); |
| 1064 | }); |
| 1129 | 1065 | |
| 1130 | | cases.add( |
| 1131 | | "indirect struct loop", |
| 1066 | cases.add("indirect struct loop", |
| 1132 | 1067 | \\const A = struct { b : B, }; |
| 1133 | 1068 | \\const B = struct { c : C, }; |
| 1134 | 1069 | \\const C = struct { a : A, }; |
| 1135 | 1070 | \\export fn entry() usize { return @sizeOf(A); } |
| 1136 | | , |
| 1071 | , &[_][]const u8{ |
| 1137 | 1072 | "tmp.zig:1:11: error: struct 'A' depends on itself", |
| 1138 | | ); |
| 1073 | }); |
| 1139 | 1074 | |
| 1140 | | cases.add( |
| 1141 | | "instantiating an undefined value for an invalid struct that contains itself", |
| 1075 | cases.add("instantiating an undefined value for an invalid struct that contains itself", |
| 1142 | 1076 | \\const Foo = struct { |
| 1143 | 1077 | \\ x: Foo, |
| 1144 | 1078 | \\}; |
| ... | ... | @@ -1148,13 +1082,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1148 | 1082 | \\export fn entry() usize { |
| 1149 | 1083 | \\ return @sizeOf(@typeOf(foo.x)); |
| 1150 | 1084 | \\} |
| 1151 | | , |
| 1085 | , &[_][]const u8{ |
| 1152 | 1086 | "tmp.zig:1:13: error: struct 'Foo' depends on itself", |
| 1153 | 1087 | "tmp.zig:8:28: note: referenced here", |
| 1154 | | ); |
| 1088 | }); |
| 1155 | 1089 | |
| 1156 | | cases.add( |
| 1157 | | "@typeInfo causing depend on itself compile error", |
| 1090 | cases.add("@typeInfo causing depend on itself compile error", |
| 1158 | 1091 | \\const start = struct { |
| 1159 | 1092 | \\ fn crash() bug() { |
| 1160 | 1093 | \\ return bug; |
| ... | ... | @@ -1166,14 +1099,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1166 | 1099 | \\export fn entry() void { |
| 1167 | 1100 | \\ var boom = start.crash(); |
| 1168 | 1101 | \\} |
| 1169 | | , |
| 1102 | , &[_][]const u8{ |
| 1170 | 1103 | "tmp.zig:7:9: error: dependency loop detected", |
| 1171 | 1104 | "tmp.zig:2:19: note: referenced here", |
| 1172 | 1105 | "tmp.zig:10:21: note: referenced here", |
| 1173 | | ); |
| 1106 | }); |
| 1174 | 1107 | |
| 1175 | | cases.add( |
| 1176 | | "enum field value references enum", |
| 1108 | cases.add("enum field value references enum", |
| 1177 | 1109 | \\pub const Foo = extern enum { |
| 1178 | 1110 | \\ A = Foo.B, |
| 1179 | 1111 | \\ C = D, |
| ... | ... | @@ -1181,25 +1113,23 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1181 | 1113 | \\export fn entry() void { |
| 1182 | 1114 | \\ var s: Foo = Foo.E; |
| 1183 | 1115 | \\} |
| 1184 | | , |
| 1116 | , &[_][]const u8{ |
| 1185 | 1117 | "tmp.zig:1:17: error: enum 'Foo' depends on itself", |
| 1186 | | ); |
| 1118 | }); |
| 1187 | 1119 | |
| 1188 | | cases.add( |
| 1189 | | "top level decl dependency loop", |
| 1120 | cases.add("top level decl dependency loop", |
| 1190 | 1121 | \\const a : @typeOf(b) = 0; |
| 1191 | 1122 | \\const b : @typeOf(a) = 0; |
| 1192 | 1123 | \\export fn entry() void { |
| 1193 | 1124 | \\ const c = a + b; |
| 1194 | 1125 | \\} |
| 1195 | | , |
| 1126 | , &[_][]const u8{ |
| 1196 | 1127 | "tmp.zig:2:19: error: dependency loop detected", |
| 1197 | 1128 | "tmp.zig:1:19: note: referenced here", |
| 1198 | 1129 | "tmp.zig:4:15: note: referenced here", |
| 1199 | | ); |
| 1130 | }); |
| 1200 | 1131 | |
| 1201 | | cases.addTest( |
| 1202 | | "not an enum type", |
| 1132 | cases.addTest("not an enum type", |
| 1203 | 1133 | \\export fn entry() void { |
| 1204 | 1134 | \\ var self: Error = undefined; |
| 1205 | 1135 | \\ switch (self) { |
| ... | ... | @@ -1213,58 +1143,53 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1213 | 1143 | \\}; |
| 1214 | 1144 | \\const InvalidToken = struct {}; |
| 1215 | 1145 | \\const ExpectedVarDeclOrFn = struct {}; |
| 1216 | | , |
| 1146 | , &[_][]const u8{ |
| 1217 | 1147 | "tmp.zig:4:9: error: expected type '@TagType(Error)', found 'type'", |
| 1218 | | ); |
| 1148 | }); |
| 1219 | 1149 | |
| 1220 | | cases.addTest( |
| 1221 | | "binary OR operator on error sets", |
| 1150 | cases.addTest("binary OR operator on error sets", |
| 1222 | 1151 | \\pub const A = error.A; |
| 1223 | 1152 | \\pub const AB = A | error.B; |
| 1224 | 1153 | \\export fn entry() void { |
| 1225 | 1154 | \\ var x: AB = undefined; |
| 1226 | 1155 | \\} |
| 1227 | | , |
| 1156 | , &[_][]const u8{ |
| 1228 | 1157 | "tmp.zig:2:18: error: invalid operands to binary expression: 'error{A}' and 'error{B}'", |
| 1229 | | ); |
| 1158 | }); |
| 1230 | 1159 | |
| 1231 | 1160 | if (builtin.os == builtin.Os.linux) { |
| 1232 | | cases.addTest( |
| 1233 | | "implicit dependency on libc", |
| 1161 | cases.addTest("implicit dependency on libc", |
| 1234 | 1162 | \\extern "c" fn exit(u8) void; |
| 1235 | 1163 | \\export fn entry() void { |
| 1236 | 1164 | \\ exit(0); |
| 1237 | 1165 | \\} |
| 1238 | | , |
| 1166 | , &[_][]const u8{ |
| 1239 | 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( |
| 1243 | | "libc headers note", |
| 1170 | cases.addTest("libc headers note", |
| 1244 | 1171 | \\const c = @cImport(@cInclude("stdio.h")); |
| 1245 | 1172 | \\export fn entry() void { |
| 1246 | 1173 | \\ _ = c.printf("hello, world!\n"); |
| 1247 | 1174 | \\} |
| 1248 | | , |
| 1175 | , &[_][]const u8{ |
| 1249 | 1176 | "tmp.zig:1:11: error: C import failed", |
| 1250 | 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( |
| 1255 | | "comptime vector overflow shows the index", |
| 1181 | cases.addTest("comptime vector overflow shows the index", |
| 1256 | 1182 | \\comptime { |
| 1257 | 1183 | \\ var a: @Vector(4, u8) = [_]u8{ 1, 2, 255, 4 }; |
| 1258 | 1184 | \\ var b: @Vector(4, u8) = [_]u8{ 5, 6, 1, 8 }; |
| 1259 | 1185 | \\ var x = a + b; |
| 1260 | 1186 | \\} |
| 1261 | | , |
| 1187 | , &[_][]const u8{ |
| 1262 | 1188 | "tmp.zig:4:15: error: operation caused overflow", |
| 1263 | 1189 | "tmp.zig:4:15: note: when computing vector element at index 2", |
| 1264 | | ); |
| 1190 | }); |
| 1265 | 1191 | |
| 1266 | | cases.addTest( |
| 1267 | | "packed struct with fields of not allowed types", |
| 1192 | cases.addTest("packed struct with fields of not allowed types", |
| 1268 | 1193 | \\const A = packed struct { |
| 1269 | 1194 | \\ x: anyerror, |
| 1270 | 1195 | \\}; |
| ... | ... | @@ -1318,7 +1243,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1318 | 1243 | \\ A, |
| 1319 | 1244 | \\ B, |
| 1320 | 1245 | \\}; |
| 1321 | | , |
| 1246 | , &[_][]const u8{ |
| 1322 | 1247 | "tmp.zig:2:5: error: type 'anyerror' not allowed in packed struct; no guaranteed in-memory representation", |
| 1323 | 1248 | "tmp.zig:5:5: error: array of 'u24' not allowed in packed struct due to padding bits", |
| 1324 | 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 | 1252 | "tmp.zig:17:5: error: type '?anyerror' not allowed in packed struct; no guaranteed in-memory representation", |
| 1328 | 1253 | "tmp.zig:20:5: error: type 'Enum' not allowed in packed struct; no guaranteed in-memory representation", |
| 1329 | 1254 | "tmp.zig:50:14: note: enum declaration does not specify an integer tag type", |
| 1330 | | ); |
| 1255 | }); |
| 1331 | 1256 | |
| 1332 | 1257 | cases.addCase(x: { |
| 1333 | | var tc = cases.create( |
| 1334 | | "deduplicate undeclared identifier", |
| 1258 | var tc = cases.create("deduplicate undeclared identifier", |
| 1335 | 1259 | \\export fn a() void { |
| 1336 | 1260 | \\ x += 1; |
| 1337 | 1261 | \\} |
| 1338 | 1262 | \\export fn b() void { |
| 1339 | 1263 | \\ x += 1; |
| 1340 | 1264 | \\} |
| 1341 | | , |
| 1265 | , &[_][]const u8{ |
| 1342 | 1266 | "tmp.zig:2:5: error: use of undeclared identifier 'x'", |
| 1343 | | ); |
| 1267 | }); |
| 1344 | 1268 | tc.expect_exact = true; |
| 1345 | 1269 | break :x tc; |
| 1346 | 1270 | }); |
| 1347 | 1271 | |
| 1348 | | cases.add( |
| 1349 | | "export generic function", |
| 1272 | cases.add("export generic function", |
| 1350 | 1273 | \\export fn foo(num: var) i32 { |
| 1351 | 1274 | \\ return 0; |
| 1352 | 1275 | \\} |
| 1353 | | , |
| 1276 | , &[_][]const u8{ |
| 1354 | 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( |
| 1358 | | "C pointer to c_void", |
| 1280 | cases.add("C pointer to c_void", |
| 1359 | 1281 | \\export fn a() void { |
| 1360 | 1282 | \\ var x: *c_void = undefined; |
| 1361 | 1283 | \\ var y: [*c]c_void = x; |
| 1362 | 1284 | \\} |
| 1363 | | , |
| 1285 | , &[_][]const u8{ |
| 1364 | 1286 | "tmp.zig:3:16: error: C pointers cannot point opaque types", |
| 1365 | | ); |
| 1287 | }); |
| 1366 | 1288 | |
| 1367 | | cases.add( |
| 1368 | | "directly embedding opaque type in struct and union", |
| 1289 | cases.add("directly embedding opaque type in struct and union", |
| 1369 | 1290 | \\const O = @OpaqueType(); |
| 1370 | 1291 | \\const Foo = struct { |
| 1371 | 1292 | \\ o: O, |
| ... | ... | @@ -1380,13 +1301,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1380 | 1301 | \\export fn b() void { |
| 1381 | 1302 | \\ var bar: Bar = undefined; |
| 1382 | 1303 | \\} |
| 1383 | | , |
| 1304 | , &[_][]const u8{ |
| 1384 | 1305 | "tmp.zig:3:8: error: opaque types have unknown size and therefore cannot be directly embedded in structs", |
| 1385 | 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( |
| 1389 | | "implicit cast between C pointer and Zig pointer - bad const/align/child", |
| 1309 | cases.add("implicit cast between C pointer and Zig pointer - bad const/align/child", |
| 1390 | 1310 | \\export fn a() void { |
| 1391 | 1311 | \\ var x: [*c]u8 = undefined; |
| 1392 | 1312 | \\ var y: *align(4) u8 = x; |
| ... | ... | @@ -1411,7 +1331,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1411 | 1331 | \\ var y: *u8 = undefined; |
| 1412 | 1332 | \\ var x: [*c]u32 = y; |
| 1413 | 1333 | \\} |
| 1414 | | , |
| 1334 | , &[_][]const u8{ |
| 1415 | 1335 | "tmp.zig:3:27: error: cast increases pointer alignment", |
| 1416 | 1336 | "tmp.zig:7:18: error: cast discards const qualifier", |
| 1417 | 1337 | "tmp.zig:11:19: error: expected type '*u32', found '[*c]u8'", |
| ... | ... | @@ -1419,30 +1339,27 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1419 | 1339 | "tmp.zig:15:22: error: cast increases pointer alignment", |
| 1420 | 1340 | "tmp.zig:19:21: error: cast discards const qualifier", |
| 1421 | 1341 | "tmp.zig:23:22: error: expected type '[*c]u32', found '*u8'", |
| 1422 | | ); |
| 1342 | }); |
| 1423 | 1343 | |
| 1424 | | cases.add( |
| 1425 | | "implicit casting null c pointer to zig pointer", |
| 1344 | cases.add("implicit casting null c pointer to zig pointer", |
| 1426 | 1345 | \\comptime { |
| 1427 | 1346 | \\ var c_ptr: [*c]u8 = 0; |
| 1428 | 1347 | \\ var zig_ptr: *u8 = c_ptr; |
| 1429 | 1348 | \\} |
| 1430 | | , |
| 1349 | , &[_][]const u8{ |
| 1431 | 1350 | "tmp.zig:3:24: error: null pointer casted to type '*u8'", |
| 1432 | | ); |
| 1351 | }); |
| 1433 | 1352 | |
| 1434 | | cases.add( |
| 1435 | | "implicit casting undefined c pointer to zig pointer", |
| 1353 | cases.add("implicit casting undefined c pointer to zig pointer", |
| 1436 | 1354 | \\comptime { |
| 1437 | 1355 | \\ var c_ptr: [*c]u8 = undefined; |
| 1438 | 1356 | \\ var zig_ptr: *u8 = c_ptr; |
| 1439 | 1357 | \\} |
| 1440 | | , |
| 1358 | , &[_][]const u8{ |
| 1441 | 1359 | "tmp.zig:3:24: error: use of undefined value here causes undefined behavior", |
| 1442 | | ); |
| 1360 | }); |
| 1443 | 1361 | |
| 1444 | | cases.add( |
| 1445 | | "implicit casting C pointers which would mess up null semantics", |
| 1362 | cases.add("implicit casting C pointers which would mess up null semantics", |
| 1446 | 1363 | \\export fn entry() void { |
| 1447 | 1364 | \\ var slice: []const u8 = "aoeu"; |
| 1448 | 1365 | \\ const opt_many_ptr: [*]const u8 = slice.ptr; |
| ... | ... | @@ -1457,17 +1374,16 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1457 | 1374 | \\ var ptr_opt_many_ptr = &opt_many_ptr; |
| 1458 | 1375 | \\ var c_ptr: [*c][*c]const u8 = ptr_opt_many_ptr; |
| 1459 | 1376 | \\} |
| 1460 | | , |
| 1377 | , &[_][]const u8{ |
| 1461 | 1378 | "tmp.zig:6:24: error: expected type '*const [*]const u8', found '[*c]const [*c]const u8'", |
| 1462 | 1379 | "tmp.zig:6:24: note: pointer type child '[*c]const u8' cannot cast into pointer type child '[*]const u8'", |
| 1463 | 1380 | "tmp.zig:6:24: note: '[*c]const u8' could have null values which are illegal in type '[*]const u8'", |
| 1464 | 1381 | "tmp.zig:13:35: error: expected type '[*c][*c]const u8', found '*[*]u8'", |
| 1465 | 1382 | "tmp.zig:13:35: note: pointer type child '[*]u8' cannot cast into pointer type child '[*c]const u8'", |
| 1466 | 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( |
| 1470 | | "implicit casting too big integers to C pointers", |
| 1386 | cases.add("implicit casting too big integers to C pointers", |
| 1471 | 1387 | \\export fn a() void { |
| 1472 | 1388 | \\ var ptr: [*c]u8 = (1 << 64) + 1; |
| 1473 | 1389 | \\} |
| ... | ... | @@ -1475,25 +1391,23 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1475 | 1391 | \\ var x: @IntType(false, 65) = 0x1234; |
| 1476 | 1392 | \\ var ptr: [*c]u8 = x; |
| 1477 | 1393 | \\} |
| 1478 | | , |
| 1394 | , &[_][]const u8{ |
| 1479 | 1395 | "tmp.zig:2:33: error: integer value 18446744073709551617 cannot be coerced to type 'usize'", |
| 1480 | 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( |
| 1484 | | "C pointer pointing to non C ABI compatible type or has align attr", |
| 1399 | cases.add("C pointer pointing to non C ABI compatible type or has align attr", |
| 1485 | 1400 | \\const Foo = struct {}; |
| 1486 | 1401 | \\export fn a() void { |
| 1487 | 1402 | \\ const T = [*c]Foo; |
| 1488 | 1403 | \\ var t: T = undefined; |
| 1489 | 1404 | \\} |
| 1490 | | , |
| 1405 | , &[_][]const u8{ |
| 1491 | 1406 | "tmp.zig:3:19: error: C pointers cannot point to non-C-ABI-compatible type 'Foo'", |
| 1492 | | ); |
| 1407 | }); |
| 1493 | 1408 | |
| 1494 | 1409 | cases.addCase(x: { |
| 1495 | | var tc = cases.create( |
| 1496 | | "compile log statement warning deduplication in generic fn", |
| 1410 | var tc = cases.create("compile log statement warning deduplication in generic fn", |
| 1497 | 1411 | \\export fn entry() void { |
| 1498 | 1412 | \\ inner(1); |
| 1499 | 1413 | \\ inner(2); |
| ... | ... | @@ -1502,111 +1416,100 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1502 | 1416 | \\ comptime var i = 0; |
| 1503 | 1417 | \\ inline while (i < n) : (i += 1) { @compileLog("!@#$"); } |
| 1504 | 1418 | \\} |
| 1505 | | , |
| 1419 | , &[_][]const u8{ |
| 1506 | 1420 | "tmp.zig:7:39: error: found compile log statement", |
| 1507 | | ); |
| 1421 | }); |
| 1508 | 1422 | tc.expect_exact = true; |
| 1509 | 1423 | break :x tc; |
| 1510 | 1424 | }); |
| 1511 | 1425 | |
| 1512 | | cases.add( |
| 1513 | | "assign to invalid dereference", |
| 1426 | cases.add("assign to invalid dereference", |
| 1514 | 1427 | \\export fn entry() void { |
| 1515 | 1428 | \\ 'a'.* = 1; |
| 1516 | 1429 | \\} |
| 1517 | | , |
| 1430 | , &[_][]const u8{ |
| 1518 | 1431 | "tmp.zig:2:8: error: attempt to dereference non-pointer type 'comptime_int'", |
| 1519 | | ); |
| 1432 | }); |
| 1520 | 1433 | |
| 1521 | | cases.add( |
| 1522 | | "take slice of invalid dereference", |
| 1434 | cases.add("take slice of invalid dereference", |
| 1523 | 1435 | \\export fn entry() void { |
| 1524 | 1436 | \\ const x = 'a'.*[0..]; |
| 1525 | 1437 | \\} |
| 1526 | | , |
| 1438 | , &[_][]const u8{ |
| 1527 | 1439 | "tmp.zig:2:18: error: attempt to dereference non-pointer type 'comptime_int'", |
| 1528 | | ); |
| 1440 | }); |
| 1529 | 1441 | |
| 1530 | | cases.add( |
| 1531 | | "@truncate undefined value", |
| 1442 | cases.add("@truncate undefined value", |
| 1532 | 1443 | \\export fn entry() void { |
| 1533 | 1444 | \\ var z = @truncate(u8, @as(u16, undefined)); |
| 1534 | 1445 | \\} |
| 1535 | | , |
| 1446 | , &[_][]const u8{ |
| 1536 | 1447 | "tmp.zig:2:27: error: use of undefined value here causes undefined behavior", |
| 1537 | | ); |
| 1448 | }); |
| 1538 | 1449 | |
| 1539 | | cases.addTest( |
| 1540 | | "return invalid type from test", |
| 1450 | cases.addTest("return invalid type from test", |
| 1541 | 1451 | \\test "example" { return 1; } |
| 1542 | | , |
| 1452 | , &[_][]const u8{ |
| 1543 | 1453 | "tmp.zig:1:25: error: integer value 1 cannot be coerced to type 'void'", |
| 1544 | | ); |
| 1454 | }); |
| 1545 | 1455 | |
| 1546 | | cases.add( |
| 1547 | | "threadlocal qualifier on const", |
| 1456 | cases.add("threadlocal qualifier on const", |
| 1548 | 1457 | \\threadlocal const x: i32 = 1234; |
| 1549 | 1458 | \\export fn entry() i32 { |
| 1550 | 1459 | \\ return x; |
| 1551 | 1460 | \\} |
| 1552 | | , |
| 1461 | , &[_][]const u8{ |
| 1553 | 1462 | "tmp.zig:1:13: error: threadlocal variable cannot be constant", |
| 1554 | | ); |
| 1463 | }); |
| 1555 | 1464 | |
| 1556 | | cases.add( |
| 1557 | | "@bitCast same size but bit count mismatch", |
| 1465 | cases.add("@bitCast same size but bit count mismatch", |
| 1558 | 1466 | \\export fn entry(byte: u8) void { |
| 1559 | 1467 | \\ var oops = @bitCast(u7, byte); |
| 1560 | 1468 | \\} |
| 1561 | | , |
| 1469 | , &[_][]const u8{ |
| 1562 | 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( |
| 1566 | | "@bitCast with different sizes inside an expression", |
| 1473 | cases.add("@bitCast with different sizes inside an expression", |
| 1567 | 1474 | \\export fn entry() void { |
| 1568 | 1475 | \\ var foo = (@bitCast(u8, @as(f32, 1.0)) == 0xf); |
| 1569 | 1476 | \\} |
| 1570 | | , |
| 1477 | , &[_][]const u8{ |
| 1571 | 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( |
| 1575 | | "attempted `&&`", |
| 1481 | cases.add("attempted `&&`", |
| 1576 | 1482 | \\export fn entry(a: bool, b: bool) i32 { |
| 1577 | 1483 | \\ if (a && b) { |
| 1578 | 1484 | \\ return 1234; |
| 1579 | 1485 | \\ } |
| 1580 | 1486 | \\ return 5678; |
| 1581 | 1487 | \\} |
| 1582 | | , |
| 1488 | , &[_][]const u8{ |
| 1583 | 1489 | "tmp.zig:2:12: error: `&&` is invalid. Note that `and` is boolean AND", |
| 1584 | | ); |
| 1490 | }); |
| 1585 | 1491 | |
| 1586 | | cases.add( |
| 1587 | | "attempted `||` on boolean values", |
| 1492 | cases.add("attempted `||` on boolean values", |
| 1588 | 1493 | \\export fn entry(a: bool, b: bool) i32 { |
| 1589 | 1494 | \\ if (a || b) { |
| 1590 | 1495 | \\ return 1234; |
| 1591 | 1496 | \\ } |
| 1592 | 1497 | \\ return 5678; |
| 1593 | 1498 | \\} |
| 1594 | | , |
| 1499 | , &[_][]const u8{ |
| 1595 | 1500 | "tmp.zig:2:9: error: expected error set type, found 'bool'", |
| 1596 | 1501 | "tmp.zig:2:11: note: `||` merges error sets; `or` performs boolean OR", |
| 1597 | | ); |
| 1502 | }); |
| 1598 | 1503 | |
| 1599 | | cases.add( |
| 1600 | | "compile log a pointer to an opaque value", |
| 1504 | cases.add("compile log a pointer to an opaque value", |
| 1601 | 1505 | \\export fn entry() void { |
| 1602 | 1506 | \\ @compileLog(@ptrCast(*const c_void, &entry)); |
| 1603 | 1507 | \\} |
| 1604 | | , |
| 1508 | , &[_][]const u8{ |
| 1605 | 1509 | "tmp.zig:2:5: error: found compile log statement", |
| 1606 | | ); |
| 1510 | }); |
| 1607 | 1511 | |
| 1608 | | cases.add( |
| 1609 | | "duplicate boolean switch value", |
| 1512 | cases.add("duplicate boolean switch value", |
| 1610 | 1513 | \\comptime { |
| 1611 | 1514 | \\ const x = switch (true) { |
| 1612 | 1515 | \\ true => false, |
| ... | ... | @@ -1621,13 +1524,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1621 | 1524 | \\ false => true, |
| 1622 | 1525 | \\ }; |
| 1623 | 1526 | \\} |
| 1624 | | , |
| 1527 | , &[_][]const u8{ |
| 1625 | 1528 | "tmp.zig:5:9: error: duplicate switch value", |
| 1626 | 1529 | "tmp.zig:12:9: error: duplicate switch value", |
| 1627 | | ); |
| 1530 | }); |
| 1628 | 1531 | |
| 1629 | | cases.add( |
| 1630 | | "missing boolean switch value", |
| 1532 | cases.add("missing boolean switch value", |
| 1631 | 1533 | \\comptime { |
| 1632 | 1534 | \\ const x = switch (true) { |
| 1633 | 1535 | \\ true => false, |
| ... | ... | @@ -1638,37 +1540,34 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1638 | 1540 | \\ false => true, |
| 1639 | 1541 | \\ }; |
| 1640 | 1542 | \\} |
| 1641 | | , |
| 1543 | , &[_][]const u8{ |
| 1642 | 1544 | "tmp.zig:2:15: error: switch must handle all possibilities", |
| 1643 | 1545 | "tmp.zig:7:15: error: switch must handle all possibilities", |
| 1644 | | ); |
| 1546 | }); |
| 1645 | 1547 | |
| 1646 | | cases.add( |
| 1647 | | "reading past end of pointer casted array", |
| 1548 | cases.add("reading past end of pointer casted array", |
| 1648 | 1549 | \\comptime { |
| 1649 | 1550 | \\ const array: [4]u8 = "aoeu".*; |
| 1650 | 1551 | \\ const slice = array[1..]; |
| 1651 | 1552 | \\ const int_ptr = @ptrCast(*const u24, slice.ptr); |
| 1652 | 1553 | \\ const deref = int_ptr.*; |
| 1653 | 1554 | \\} |
| 1654 | | , |
| 1555 | , &[_][]const u8{ |
| 1655 | 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( |
| 1659 | | "error note for function parameter incompatibility", |
| 1559 | cases.add("error note for function parameter incompatibility", |
| 1660 | 1560 | \\fn do_the_thing(func: fn (arg: i32) void) void {} |
| 1661 | 1561 | \\fn bar(arg: bool) void {} |
| 1662 | 1562 | \\export fn entry() void { |
| 1663 | 1563 | \\ do_the_thing(bar); |
| 1664 | 1564 | \\} |
| 1665 | | , |
| 1565 | , &[_][]const u8{ |
| 1666 | 1566 | "tmp.zig:4:18: error: expected type 'fn(i32) void', found 'fn(bool) void", |
| 1667 | 1567 | "tmp.zig:4:18: note: parameter 0: 'bool' cannot cast into 'i32'", |
| 1668 | | ); |
| 1568 | }); |
| 1669 | 1569 | |
| 1670 | | cases.add( |
| 1671 | | "cast negative value to unsigned integer", |
| 1570 | cases.add("cast negative value to unsigned integer", |
| 1672 | 1571 | \\comptime { |
| 1673 | 1572 | \\ const value: i32 = -1; |
| 1674 | 1573 | \\ const unsigned = @intCast(u32, value); |
| ... | ... | @@ -1677,13 +1576,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1677 | 1576 | \\ const value: i32 = -1; |
| 1678 | 1577 | \\ const unsigned: u32 = value; |
| 1679 | 1578 | \\} |
| 1680 | | , |
| 1579 | , &[_][]const u8{ |
| 1681 | 1580 | "tmp.zig:3:36: error: cannot cast negative value -1 to unsigned integer type 'u32'", |
| 1682 | 1581 | "tmp.zig:7:27: error: cannot cast negative value -1 to unsigned integer type 'u32'", |
| 1683 | | ); |
| 1582 | }); |
| 1684 | 1583 | |
| 1685 | | cases.add( |
| 1686 | | "integer cast truncates bits", |
| 1584 | cases.add("integer cast truncates bits", |
| 1687 | 1585 | \\export fn entry1() void { |
| 1688 | 1586 | \\ const spartan_count: u16 = 300; |
| 1689 | 1587 | \\ const byte = @intCast(u8, spartan_count); |
| ... | ... | @@ -1700,50 +1598,46 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1700 | 1598 | \\ var signed: i8 = -1; |
| 1701 | 1599 | \\ var unsigned: u64 = signed; |
| 1702 | 1600 | \\} |
| 1703 | | , |
| 1601 | , &[_][]const u8{ |
| 1704 | 1602 | "tmp.zig:3:31: error: integer value 300 cannot be coerced to type 'u8'", |
| 1705 | 1603 | "tmp.zig:7:22: error: integer value 300 cannot be coerced to type 'u8'", |
| 1706 | 1604 | "tmp.zig:11:20: error: expected type 'u8', found 'u16'", |
| 1707 | 1605 | "tmp.zig:11:20: note: unsigned 8-bit int cannot represent all possible unsigned 16-bit values", |
| 1708 | 1606 | "tmp.zig:15:25: error: expected type 'u64', found 'i8'", |
| 1709 | 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( |
| 1713 | | "comptime implicit cast f64 to f32", |
| 1610 | cases.add("comptime implicit cast f64 to f32", |
| 1714 | 1611 | \\export fn entry() void { |
| 1715 | 1612 | \\ const x: f64 = 16777217; |
| 1716 | 1613 | \\ const y: f32 = x; |
| 1717 | 1614 | \\} |
| 1718 | | , |
| 1615 | , &[_][]const u8{ |
| 1719 | 1616 | "tmp.zig:3:20: error: cast of value 16777217.000000 to type 'f32' loses information", |
| 1720 | | ); |
| 1617 | }); |
| 1721 | 1618 | |
| 1722 | | cases.add( |
| 1723 | | "implicit cast from f64 to f32", |
| 1619 | cases.add("implicit cast from f64 to f32", |
| 1724 | 1620 | \\var x: f64 = 1.0; |
| 1725 | 1621 | \\var y: f32 = x; |
| 1726 | 1622 | \\ |
| 1727 | 1623 | \\export fn entry() usize { return @sizeOf(@typeOf(y)); } |
| 1728 | | , |
| 1624 | , &[_][]const u8{ |
| 1729 | 1625 | "tmp.zig:2:14: error: expected type 'f32', found 'f64'", |
| 1730 | | ); |
| 1626 | }); |
| 1731 | 1627 | |
| 1732 | | cases.add( |
| 1733 | | "exceeded maximum bit width of integer", |
| 1628 | cases.add("exceeded maximum bit width of integer", |
| 1734 | 1629 | \\export fn entry1() void { |
| 1735 | 1630 | \\ const T = @IntType(false, 65536); |
| 1736 | 1631 | \\} |
| 1737 | 1632 | \\export fn entry2() void { |
| 1738 | 1633 | \\ var x: i65536 = 1; |
| 1739 | 1634 | \\} |
| 1740 | | , |
| 1635 | , &[_][]const u8{ |
| 1741 | 1636 | "tmp.zig:2:31: error: integer value 65536 cannot be coerced to type 'u16'", |
| 1742 | 1637 | "tmp.zig:5:12: error: primitive integer type 'i65536' exceeds maximum bit width of 65535", |
| 1743 | | ); |
| 1638 | }); |
| 1744 | 1639 | |
| 1745 | | cases.add( |
| 1746 | | "compile error when evaluating return type of inferred error set", |
| 1640 | cases.add("compile error when evaluating return type of inferred error set", |
| 1747 | 1641 | \\const Car = struct { |
| 1748 | 1642 | \\ foo: *SymbolThatDoesNotExist, |
| 1749 | 1643 | \\ pub fn init() !Car {} |
| ... | ... | @@ -1751,24 +1645,22 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1751 | 1645 | \\export fn entry() void { |
| 1752 | 1646 | \\ const car = Car.init(); |
| 1753 | 1647 | \\} |
| 1754 | | , |
| 1648 | , &[_][]const u8{ |
| 1755 | 1649 | "tmp.zig:2:11: error: use of undeclared identifier 'SymbolThatDoesNotExist'", |
| 1756 | | ); |
| 1650 | }); |
| 1757 | 1651 | |
| 1758 | | cases.add( |
| 1759 | | "don't implicit cast double pointer to *c_void", |
| 1652 | cases.add("don't implicit cast double pointer to *c_void", |
| 1760 | 1653 | \\export fn entry() void { |
| 1761 | 1654 | \\ var a: u32 = 1; |
| 1762 | 1655 | \\ var ptr: *c_void = &a; |
| 1763 | 1656 | \\ var b: *u32 = @ptrCast(*u32, ptr); |
| 1764 | 1657 | \\ var ptr2: *c_void = &b; |
| 1765 | 1658 | \\} |
| 1766 | | , |
| 1659 | , &[_][]const u8{ |
| 1767 | 1660 | "tmp.zig:5:26: error: expected type '*c_void', found '**u32'", |
| 1768 | | ); |
| 1661 | }); |
| 1769 | 1662 | |
| 1770 | | cases.add( |
| 1771 | | "runtime index into comptime type slice", |
| 1663 | cases.add("runtime index into comptime type slice", |
| 1772 | 1664 | \\const Struct = struct { |
| 1773 | 1665 | \\ a: u32, |
| 1774 | 1666 | \\}; |
| ... | ... | @@ -1779,12 +1671,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1779 | 1671 | \\ const index = getIndex(); |
| 1780 | 1672 | \\ const field = @typeInfo(Struct).Struct.fields[index]; |
| 1781 | 1673 | \\} |
| 1782 | | , |
| 1674 | , &[_][]const u8{ |
| 1783 | 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( |
| 1787 | | "compile log statement inside function which must be comptime evaluated", |
| 1678 | cases.add("compile log statement inside function which must be comptime evaluated", |
| 1788 | 1679 | \\fn Foo(comptime T: type) type { |
| 1789 | 1680 | \\ @compileLog(@typeName(T)); |
| 1790 | 1681 | \\ return T; |
| ... | ... | @@ -1793,80 +1684,73 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1793 | 1684 | \\ _ = Foo(i32); |
| 1794 | 1685 | \\ _ = @typeName(Foo(i32)); |
| 1795 | 1686 | \\} |
| 1796 | | , |
| 1687 | , &[_][]const u8{ |
| 1797 | 1688 | "tmp.zig:2:5: error: found compile log statement", |
| 1798 | | ); |
| 1689 | }); |
| 1799 | 1690 | |
| 1800 | | cases.add( |
| 1801 | | "comptime slice of an undefined slice", |
| 1691 | cases.add("comptime slice of an undefined slice", |
| 1802 | 1692 | \\comptime { |
| 1803 | 1693 | \\ var a: []u8 = undefined; |
| 1804 | 1694 | \\ var b = a[0..10]; |
| 1805 | 1695 | \\} |
| 1806 | | , |
| 1696 | , &[_][]const u8{ |
| 1807 | 1697 | "tmp.zig:3:14: error: slice of undefined", |
| 1808 | | ); |
| 1698 | }); |
| 1809 | 1699 | |
| 1810 | | cases.add( |
| 1811 | | "implicit cast const array to mutable slice", |
| 1700 | cases.add("implicit cast const array to mutable slice", |
| 1812 | 1701 | \\export fn entry() void { |
| 1813 | 1702 | \\ const buffer: [1]u8 = [_]u8{8}; |
| 1814 | 1703 | \\ const sliceA: []u8 = &buffer; |
| 1815 | 1704 | \\} |
| 1816 | | , |
| 1705 | , &[_][]const u8{ |
| 1817 | 1706 | "tmp.zig:3:27: error: expected type '[]u8', found '*const [1]u8'", |
| 1818 | | ); |
| 1707 | }); |
| 1819 | 1708 | |
| 1820 | | cases.add( |
| 1821 | | "deref slice and get len field", |
| 1709 | cases.add("deref slice and get len field", |
| 1822 | 1710 | \\export fn entry() void { |
| 1823 | 1711 | \\ var a: []u8 = undefined; |
| 1824 | 1712 | \\ _ = a.*.len; |
| 1825 | 1713 | \\} |
| 1826 | | , |
| 1714 | , &[_][]const u8{ |
| 1827 | 1715 | "tmp.zig:3:10: error: attempt to dereference non-pointer type '[]u8'", |
| 1828 | | ); |
| 1716 | }); |
| 1829 | 1717 | |
| 1830 | | cases.add( |
| 1831 | | "@ptrCast a 0 bit type to a non- 0 bit type", |
| 1718 | cases.add("@ptrCast a 0 bit type to a non- 0 bit type", |
| 1832 | 1719 | \\export fn entry() bool { |
| 1833 | 1720 | \\ var x: u0 = 0; |
| 1834 | 1721 | \\ const p = @ptrCast(?*u0, &x); |
| 1835 | 1722 | \\ return p == null; |
| 1836 | 1723 | \\} |
| 1837 | | , |
| 1724 | , &[_][]const u8{ |
| 1838 | 1725 | "tmp.zig:3:15: error: '*u0' and '?*u0' do not have the same in-memory representation", |
| 1839 | 1726 | "tmp.zig:3:31: note: '*u0' has no in-memory bits", |
| 1840 | 1727 | "tmp.zig:3:24: note: '?*u0' has in-memory bits", |
| 1841 | | ); |
| 1728 | }); |
| 1842 | 1729 | |
| 1843 | | cases.add( |
| 1844 | | "comparing a non-optional pointer against null", |
| 1730 | cases.add("comparing a non-optional pointer against null", |
| 1845 | 1731 | \\export fn entry() void { |
| 1846 | 1732 | \\ var x: i32 = 1; |
| 1847 | 1733 | \\ _ = &x == null; |
| 1848 | 1734 | \\} |
| 1849 | | , |
| 1735 | , &[_][]const u8{ |
| 1850 | 1736 | "tmp.zig:3:12: error: comparison of '*i32' with null", |
| 1851 | | ); |
| 1737 | }); |
| 1852 | 1738 | |
| 1853 | | cases.add( |
| 1854 | | "non error sets used in merge error sets operator", |
| 1739 | cases.add("non error sets used in merge error sets operator", |
| 1855 | 1740 | \\export fn foo() void { |
| 1856 | 1741 | \\ const Errors = u8 || u16; |
| 1857 | 1742 | \\} |
| 1858 | 1743 | \\export fn bar() void { |
| 1859 | 1744 | \\ const Errors = error{} || u16; |
| 1860 | 1745 | \\} |
| 1861 | | , |
| 1746 | , &[_][]const u8{ |
| 1862 | 1747 | "tmp.zig:2:20: error: expected error set type, found type 'u8'", |
| 1863 | 1748 | "tmp.zig:2:23: note: `||` merges error sets; `or` performs boolean OR", |
| 1864 | 1749 | "tmp.zig:5:31: error: expected error set type, found type 'u16'", |
| 1865 | 1750 | "tmp.zig:5:28: note: `||` merges error sets; `or` performs boolean OR", |
| 1866 | | ); |
| 1751 | }); |
| 1867 | 1752 | |
| 1868 | | cases.add( |
| 1869 | | "variable initialization compile error then referenced", |
| 1753 | cases.add("variable initialization compile error then referenced", |
| 1870 | 1754 | \\fn Undeclared() type { |
| 1871 | 1755 | \\ return T; |
| 1872 | 1756 | \\} |
| ... | ... | @@ -1879,23 +1763,21 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1879 | 1763 | \\export fn entry() void { |
| 1880 | 1764 | \\ const S = Gen(); |
| 1881 | 1765 | \\} |
| 1882 | | , |
| 1766 | , &[_][]const u8{ |
| 1883 | 1767 | "tmp.zig:2:12: error: use of undeclared identifier 'T'", |
| 1884 | | ); |
| 1768 | }); |
| 1885 | 1769 | |
| 1886 | | cases.add( |
| 1887 | | "refer to the type of a generic function", |
| 1770 | cases.add("refer to the type of a generic function", |
| 1888 | 1771 | \\export fn entry() void { |
| 1889 | 1772 | \\ const Func = fn (type) void; |
| 1890 | 1773 | \\ const f: Func = undefined; |
| 1891 | 1774 | \\ f(i32); |
| 1892 | 1775 | \\} |
| 1893 | | , |
| 1776 | , &[_][]const u8{ |
| 1894 | 1777 | "tmp.zig:4:5: error: use of undefined value here causes undefined behavior", |
| 1895 | | ); |
| 1778 | }); |
| 1896 | 1779 | |
| 1897 | | cases.add( |
| 1898 | | "accessing runtime parameter from outer function", |
| 1780 | cases.add("accessing runtime parameter from outer function", |
| 1899 | 1781 | \\fn outer(y: u32) fn (u32) u32 { |
| 1900 | 1782 | \\ const st = struct { |
| 1901 | 1783 | \\ fn get(z: u32) u32 { |
| ... | ... | @@ -1908,53 +1790,48 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1908 | 1790 | \\ var func = outer(10); |
| 1909 | 1791 | \\ var x = func(3); |
| 1910 | 1792 | \\} |
| 1911 | | , |
| 1793 | , &[_][]const u8{ |
| 1912 | 1794 | "tmp.zig:4:24: error: 'y' not accessible from inner function", |
| 1913 | 1795 | "tmp.zig:3:28: note: crossed function definition here", |
| 1914 | 1796 | "tmp.zig:1:10: note: declared here", |
| 1915 | | ); |
| 1797 | }); |
| 1916 | 1798 | |
| 1917 | | cases.add( |
| 1918 | | "non int passed to @intToFloat", |
| 1799 | cases.add("non int passed to @intToFloat", |
| 1919 | 1800 | \\export fn entry() void { |
| 1920 | 1801 | \\ const x = @intToFloat(f32, 1.1); |
| 1921 | 1802 | \\} |
| 1922 | | , |
| 1803 | , &[_][]const u8{ |
| 1923 | 1804 | "tmp.zig:2:32: error: expected int type, found 'comptime_float'", |
| 1924 | | ); |
| 1805 | }); |
| 1925 | 1806 | |
| 1926 | | cases.add( |
| 1927 | | "non float passed to @floatToInt", |
| 1807 | cases.add("non float passed to @floatToInt", |
| 1928 | 1808 | \\export fn entry() void { |
| 1929 | 1809 | \\ const x = @floatToInt(i32, @as(i32, 54)); |
| 1930 | 1810 | \\} |
| 1931 | | , |
| 1811 | , &[_][]const u8{ |
| 1932 | 1812 | "tmp.zig:2:32: error: expected float type, found 'i32'", |
| 1933 | | ); |
| 1813 | }); |
| 1934 | 1814 | |
| 1935 | | cases.add( |
| 1936 | | "out of range comptime_int passed to @floatToInt", |
| 1815 | cases.add("out of range comptime_int passed to @floatToInt", |
| 1937 | 1816 | \\export fn entry() void { |
| 1938 | 1817 | \\ const x = @floatToInt(i8, 200); |
| 1939 | 1818 | \\} |
| 1940 | | , |
| 1819 | , &[_][]const u8{ |
| 1941 | 1820 | "tmp.zig:2:31: error: integer value 200 cannot be coerced to type 'i8'", |
| 1942 | | ); |
| 1821 | }); |
| 1943 | 1822 | |
| 1944 | | cases.add( |
| 1945 | | "load too many bytes from comptime reinterpreted pointer", |
| 1823 | cases.add("load too many bytes from comptime reinterpreted pointer", |
| 1946 | 1824 | \\export fn entry() void { |
| 1947 | 1825 | \\ const float: f32 = 5.99999999999994648725e-01; |
| 1948 | 1826 | \\ const float_ptr = &float; |
| 1949 | 1827 | \\ const int_ptr = @ptrCast(*const i64, float_ptr); |
| 1950 | 1828 | \\ const int_val = int_ptr.*; |
| 1951 | 1829 | \\} |
| 1952 | | , |
| 1830 | , &[_][]const u8{ |
| 1953 | 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( |
| 1957 | | "invalid type used in array type", |
| 1834 | cases.add("invalid type used in array type", |
| 1958 | 1835 | \\const Item = struct { |
| 1959 | 1836 | \\ field: SomeNonexistentType, |
| 1960 | 1837 | \\}; |
| ... | ... | @@ -1962,12 +1839,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1962 | 1839 | \\export fn entry() void { |
| 1963 | 1840 | \\ const a = items[0]; |
| 1964 | 1841 | \\} |
| 1965 | | , |
| 1842 | , &[_][]const u8{ |
| 1966 | 1843 | "tmp.zig:2:12: error: use of undeclared identifier 'SomeNonexistentType'", |
| 1967 | | ); |
| 1844 | }); |
| 1968 | 1845 | |
| 1969 | | cases.add( |
| 1970 | | "comptime continue inside runtime catch", |
| 1846 | cases.add("comptime continue inside runtime catch", |
| 1971 | 1847 | \\export fn entry(c: bool) void { |
| 1972 | 1848 | \\ const ints = [_]u8{ 1, 2 }; |
| 1973 | 1849 | \\ inline for (ints) |_| { |
| ... | ... | @@ -1977,13 +1853,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1977 | 1853 | \\fn bad() !void { |
| 1978 | 1854 | \\ return error.Bad; |
| 1979 | 1855 | \\} |
| 1980 | | , |
| 1856 | , &[_][]const u8{ |
| 1981 | 1857 | "tmp.zig:4:25: error: comptime control flow inside runtime block", |
| 1982 | 1858 | "tmp.zig:4:15: note: runtime block created here", |
| 1983 | | ); |
| 1859 | }); |
| 1984 | 1860 | |
| 1985 | | cases.add( |
| 1986 | | "comptime continue inside runtime switch", |
| 1861 | cases.add("comptime continue inside runtime switch", |
| 1987 | 1862 | \\export fn entry() void { |
| 1988 | 1863 | \\ var p: i32 = undefined; |
| 1989 | 1864 | \\ comptime var q = true; |
| ... | ... | @@ -1995,13 +1870,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1995 | 1870 | \\ q = false; |
| 1996 | 1871 | \\ } |
| 1997 | 1872 | \\} |
| 1998 | | , |
| 1873 | , &[_][]const u8{ |
| 1999 | 1874 | "tmp.zig:6:19: error: comptime control flow inside runtime block", |
| 2000 | 1875 | "tmp.zig:5:9: note: runtime block created here", |
| 2001 | | ); |
| 1876 | }); |
| 2002 | 1877 | |
| 2003 | | cases.add( |
| 2004 | | "comptime continue inside runtime while error", |
| 1878 | cases.add("comptime continue inside runtime while error", |
| 2005 | 1879 | \\export fn entry() void { |
| 2006 | 1880 | \\ var p: anyerror!usize = undefined; |
| 2007 | 1881 | \\ comptime var q = true; |
| ... | ... | @@ -2012,13 +1886,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2012 | 1886 | \\ q = false; |
| 2013 | 1887 | \\ } |
| 2014 | 1888 | \\} |
| 2015 | | , |
| 1889 | , &[_][]const u8{ |
| 2016 | 1890 | "tmp.zig:6:13: error: comptime control flow inside runtime block", |
| 2017 | 1891 | "tmp.zig:5:9: note: runtime block created here", |
| 2018 | | ); |
| 1892 | }); |
| 2019 | 1893 | |
| 2020 | | cases.add( |
| 2021 | | "comptime continue inside runtime while optional", |
| 1894 | cases.add("comptime continue inside runtime while optional", |
| 2022 | 1895 | \\export fn entry() void { |
| 2023 | 1896 | \\ var p: ?usize = undefined; |
| 2024 | 1897 | \\ comptime var q = true; |
| ... | ... | @@ -2027,13 +1900,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2027 | 1900 | \\ q = false; |
| 2028 | 1901 | \\ } |
| 2029 | 1902 | \\} |
| 2030 | | , |
| 1903 | , &[_][]const u8{ |
| 2031 | 1904 | "tmp.zig:5:23: error: comptime control flow inside runtime block", |
| 2032 | 1905 | "tmp.zig:5:9: note: runtime block created here", |
| 2033 | | ); |
| 1906 | }); |
| 2034 | 1907 | |
| 2035 | | cases.add( |
| 2036 | | "comptime continue inside runtime while bool", |
| 1908 | cases.add("comptime continue inside runtime while bool", |
| 2037 | 1909 | \\export fn entry() void { |
| 2038 | 1910 | \\ var p: usize = undefined; |
| 2039 | 1911 | \\ comptime var q = true; |
| ... | ... | @@ -2042,13 +1914,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2042 | 1914 | \\ q = false; |
| 2043 | 1915 | \\ } |
| 2044 | 1916 | \\} |
| 2045 | | , |
| 1917 | , &[_][]const u8{ |
| 2046 | 1918 | "tmp.zig:5:25: error: comptime control flow inside runtime block", |
| 2047 | 1919 | "tmp.zig:5:9: note: runtime block created here", |
| 2048 | | ); |
| 1920 | }); |
| 2049 | 1921 | |
| 2050 | | cases.add( |
| 2051 | | "comptime continue inside runtime if error", |
| 1922 | cases.add("comptime continue inside runtime if error", |
| 2052 | 1923 | \\export fn entry() void { |
| 2053 | 1924 | \\ var p: anyerror!i32 = undefined; |
| 2054 | 1925 | \\ comptime var q = true; |
| ... | ... | @@ -2057,13 +1928,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2057 | 1928 | \\ q = false; |
| 2058 | 1929 | \\ } |
| 2059 | 1930 | \\} |
| 2060 | | , |
| 1931 | , &[_][]const u8{ |
| 2061 | 1932 | "tmp.zig:5:20: error: comptime control flow inside runtime block", |
| 2062 | 1933 | "tmp.zig:5:9: note: runtime block created here", |
| 2063 | | ); |
| 1934 | }); |
| 2064 | 1935 | |
| 2065 | | cases.add( |
| 2066 | | "comptime continue inside runtime if optional", |
| 1936 | cases.add("comptime continue inside runtime if optional", |
| 2067 | 1937 | \\export fn entry() void { |
| 2068 | 1938 | \\ var p: ?i32 = undefined; |
| 2069 | 1939 | \\ comptime var q = true; |
| ... | ... | @@ -2072,13 +1942,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2072 | 1942 | \\ q = false; |
| 2073 | 1943 | \\ } |
| 2074 | 1944 | \\} |
| 2075 | | , |
| 1945 | , &[_][]const u8{ |
| 2076 | 1946 | "tmp.zig:5:20: error: comptime control flow inside runtime block", |
| 2077 | 1947 | "tmp.zig:5:9: note: runtime block created here", |
| 2078 | | ); |
| 1948 | }); |
| 2079 | 1949 | |
| 2080 | | cases.add( |
| 2081 | | "comptime continue inside runtime if bool", |
| 1950 | cases.add("comptime continue inside runtime if bool", |
| 2082 | 1951 | \\export fn entry() void { |
| 2083 | 1952 | \\ var p: usize = undefined; |
| 2084 | 1953 | \\ comptime var q = true; |
| ... | ... | @@ -2087,13 +1956,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2087 | 1956 | \\ q = false; |
| 2088 | 1957 | \\ } |
| 2089 | 1958 | \\} |
| 2090 | | , |
| 1959 | , &[_][]const u8{ |
| 2091 | 1960 | "tmp.zig:5:22: error: comptime control flow inside runtime block", |
| 2092 | 1961 | "tmp.zig:5:9: note: runtime block created here", |
| 2093 | | ); |
| 1962 | }); |
| 2094 | 1963 | |
| 2095 | | cases.add( |
| 2096 | | "switch with invalid expression parameter", |
| 1964 | cases.add("switch with invalid expression parameter", |
| 2097 | 1965 | \\export fn entry() void { |
| 2098 | 1966 | \\ Test(i32); |
| 2099 | 1967 | \\} |
| ... | ... | @@ -2104,43 +1972,39 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2104 | 1972 | \\ else => unreachable, |
| 2105 | 1973 | \\ }; |
| 2106 | 1974 | \\} |
| 2107 | | , |
| 1975 | , &[_][]const u8{ |
| 2108 | 1976 | "tmp.zig:7:17: error: switch on type 'type' provides no expression parameter", |
| 2109 | | ); |
| 1977 | }); |
| 2110 | 1978 | |
| 2111 | | cases.add( |
| 2112 | | "function protoype with no body", |
| 1979 | cases.add("function protoype with no body", |
| 2113 | 1980 | \\fn foo() void; |
| 2114 | 1981 | \\export fn entry() void { |
| 2115 | 1982 | \\ foo(); |
| 2116 | 1983 | \\} |
| 2117 | | , |
| 1984 | , &[_][]const u8{ |
| 2118 | 1985 | "tmp.zig:1:1: error: non-extern function has no body", |
| 2119 | | ); |
| 1986 | }); |
| 2120 | 1987 | |
| 2121 | | cases.add( |
| 2122 | | "@frame() called outside of function definition", |
| 1988 | cases.add("@frame() called outside of function definition", |
| 2123 | 1989 | \\var handle_undef: anyframe = undefined; |
| 2124 | 1990 | \\var handle_dummy: anyframe = @frame(); |
| 2125 | 1991 | \\export fn entry() bool { |
| 2126 | 1992 | \\ return handle_undef == handle_dummy; |
| 2127 | 1993 | \\} |
| 2128 | | , |
| 1994 | , &[_][]const u8{ |
| 2129 | 1995 | "tmp.zig:2:30: error: @frame() called outside of function definition", |
| 2130 | | ); |
| 1996 | }); |
| 2131 | 1997 | |
| 2132 | | cases.add( |
| 2133 | | "`_` is not a declarable symbol", |
| 1998 | cases.add("`_` is not a declarable symbol", |
| 2134 | 1999 | \\export fn f1() usize { |
| 2135 | 2000 | \\ var _: usize = 2; |
| 2136 | 2001 | \\ return _; |
| 2137 | 2002 | \\} |
| 2138 | | , |
| 2003 | , &[_][]const u8{ |
| 2139 | 2004 | "tmp.zig:2:5: error: `_` is not a declarable symbol", |
| 2140 | | ); |
| 2005 | }); |
| 2141 | 2006 | |
| 2142 | | cases.add( |
| 2143 | | "`_` should not be usable inside for", |
| 2007 | cases.add("`_` should not be usable inside for", |
| 2144 | 2008 | \\export fn returns() void { |
| 2145 | 2009 | \\ for ([_]void{}) |_, i| { |
| 2146 | 2010 | \\ for ([_]void{}) |_, j| { |
| ... | ... | @@ -2148,12 +2012,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2148 | 2012 | \\ } |
| 2149 | 2013 | \\ } |
| 2150 | 2014 | \\} |
| 2151 | | , |
| 2015 | , &[_][]const u8{ |
| 2152 | 2016 | "tmp.zig:4:20: error: `_` may only be used to assign things to", |
| 2153 | | ); |
| 2017 | }); |
| 2154 | 2018 | |
| 2155 | | cases.add( |
| 2156 | | "`_` should not be usable inside while", |
| 2019 | cases.add("`_` should not be usable inside while", |
| 2157 | 2020 | \\export fn returns() void { |
| 2158 | 2021 | \\ while (optionalReturn()) |_| { |
| 2159 | 2022 | \\ while (optionalReturn()) |_| { |
| ... | ... | @@ -2164,12 +2027,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2164 | 2027 | \\fn optionalReturn() ?u32 { |
| 2165 | 2028 | \\ return 1; |
| 2166 | 2029 | \\} |
| 2167 | | , |
| 2030 | , &[_][]const u8{ |
| 2168 | 2031 | "tmp.zig:4:20: error: `_` may only be used to assign things to", |
| 2169 | | ); |
| 2032 | }); |
| 2170 | 2033 | |
| 2171 | | cases.add( |
| 2172 | | "`_` should not be usable inside while else", |
| 2034 | cases.add("`_` should not be usable inside while else", |
| 2173 | 2035 | \\export fn returns() void { |
| 2174 | 2036 | \\ while (optionalReturnError()) |_| { |
| 2175 | 2037 | \\ while (optionalReturnError()) |_| { |
| ... | ... | @@ -2182,12 +2044,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2182 | 2044 | \\fn optionalReturnError() !?u32 { |
| 2183 | 2045 | \\ return error.optionalReturnError; |
| 2184 | 2046 | \\} |
| 2185 | | , |
| 2047 | , &[_][]const u8{ |
| 2186 | 2048 | "tmp.zig:6:17: error: `_` may only be used to assign things to", |
| 2187 | | ); |
| 2049 | }); |
| 2188 | 2050 | |
| 2189 | | cases.add( |
| 2190 | | "while loop body expression ignored", |
| 2051 | cases.add("while loop body expression ignored", |
| 2191 | 2052 | \\fn returns() usize { |
| 2192 | 2053 | \\ return 2; |
| 2193 | 2054 | \\} |
| ... | ... | @@ -2202,25 +2063,23 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2202 | 2063 | \\ var x: anyerror!i32 = error.Bad; |
| 2203 | 2064 | \\ while (x) |_| returns() else |_| unreachable; |
| 2204 | 2065 | \\} |
| 2205 | | , |
| 2066 | , &[_][]const u8{ |
| 2206 | 2067 | "tmp.zig:5:25: error: expression value is ignored", |
| 2207 | 2068 | "tmp.zig:9:26: error: expression value is ignored", |
| 2208 | 2069 | "tmp.zig:13:26: error: expression value is ignored", |
| 2209 | | ); |
| 2070 | }); |
| 2210 | 2071 | |
| 2211 | | cases.add( |
| 2212 | | "missing parameter name of generic function", |
| 2072 | cases.add("missing parameter name of generic function", |
| 2213 | 2073 | \\fn dump(var) void {} |
| 2214 | 2074 | \\export fn entry() void { |
| 2215 | 2075 | \\ var a: u8 = 9; |
| 2216 | 2076 | \\ dump(a); |
| 2217 | 2077 | \\} |
| 2218 | | , |
| 2078 | , &[_][]const u8{ |
| 2219 | 2079 | "tmp.zig:1:9: error: missing parameter name", |
| 2220 | | ); |
| 2080 | }); |
| 2221 | 2081 | |
| 2222 | | cases.add( |
| 2223 | | "non-inline for loop on a type that requires comptime", |
| 2082 | cases.add("non-inline for loop on a type that requires comptime", |
| 2224 | 2083 | \\const Foo = struct { |
| 2225 | 2084 | \\ name: []const u8, |
| 2226 | 2085 | \\ T: type, |
| ... | ... | @@ -2229,23 +2088,21 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2229 | 2088 | \\ const xx: [2]Foo = undefined; |
| 2230 | 2089 | \\ for (xx) |f| {} |
| 2231 | 2090 | \\} |
| 2232 | | , |
| 2091 | , &[_][]const u8{ |
| 2233 | 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( |
| 2237 | | "generic fn as parameter without comptime keyword", |
| 2095 | cases.add("generic fn as parameter without comptime keyword", |
| 2238 | 2096 | \\fn f(_: fn (var) void) void {} |
| 2239 | 2097 | \\fn g(_: var) void {} |
| 2240 | 2098 | \\export fn entry() void { |
| 2241 | 2099 | \\ f(g); |
| 2242 | 2100 | \\} |
| 2243 | | , |
| 2101 | , &[_][]const u8{ |
| 2244 | 2102 | "tmp.zig:1:9: error: parameter of type 'fn(var)var' must be declared comptime", |
| 2245 | | ); |
| 2103 | }); |
| 2246 | 2104 | |
| 2247 | | cases.add( |
| 2248 | | "optional pointer to void in extern struct", |
| 2105 | cases.add("optional pointer to void in extern struct", |
| 2249 | 2106 | \\const Foo = extern struct { |
| 2250 | 2107 | \\ x: ?*const void, |
| 2251 | 2108 | \\}; |
| ... | ... | @@ -2254,12 +2111,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2254 | 2111 | \\ y: i32, |
| 2255 | 2112 | \\}; |
| 2256 | 2113 | \\export fn entry(bar: *Bar) void {} |
| 2257 | | , |
| 2114 | , &[_][]const u8{ |
| 2258 | 2115 | "tmp.zig:2:5: error: extern structs cannot contain fields of type '?*const void'", |
| 2259 | | ); |
| 2116 | }); |
| 2260 | 2117 | |
| 2261 | | cases.add( |
| 2262 | | "use of comptime-known undefined function value", |
| 2118 | cases.add("use of comptime-known undefined function value", |
| 2263 | 2119 | \\const Cmd = struct { |
| 2264 | 2120 | \\ exec: fn () void, |
| 2265 | 2121 | \\}; |
| ... | ... | @@ -2267,12 +2123,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2267 | 2123 | \\ const command = Cmd{ .exec = undefined }; |
| 2268 | 2124 | \\ command.exec(); |
| 2269 | 2125 | \\} |
| 2270 | | , |
| 2126 | , &[_][]const u8{ |
| 2271 | 2127 | "tmp.zig:6:12: error: use of undefined value here causes undefined behavior", |
| 2272 | | ); |
| 2128 | }); |
| 2273 | 2129 | |
| 2274 | | cases.add( |
| 2275 | | "use of comptime-known undefined function value", |
| 2130 | cases.add("use of comptime-known undefined function value", |
| 2276 | 2131 | \\const Cmd = struct { |
| 2277 | 2132 | \\ exec: fn () void, |
| 2278 | 2133 | \\}; |
| ... | ... | @@ -2280,41 +2135,37 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2280 | 2135 | \\ const command = Cmd{ .exec = undefined }; |
| 2281 | 2136 | \\ command.exec(); |
| 2282 | 2137 | \\} |
| 2283 | | , |
| 2138 | , &[_][]const u8{ |
| 2284 | 2139 | "tmp.zig:6:12: error: use of undefined value here causes undefined behavior", |
| 2285 | | ); |
| 2140 | }); |
| 2286 | 2141 | |
| 2287 | | cases.add( |
| 2288 | | "bad @alignCast at comptime", |
| 2142 | cases.add("bad @alignCast at comptime", |
| 2289 | 2143 | \\comptime { |
| 2290 | 2144 | \\ const ptr = @intToPtr(*i32, 0x1); |
| 2291 | 2145 | \\ const aligned = @alignCast(4, ptr); |
| 2292 | 2146 | \\} |
| 2293 | | , |
| 2147 | , &[_][]const u8{ |
| 2294 | 2148 | "tmp.zig:3:35: error: pointer address 0x1 is not aligned to 4 bytes", |
| 2295 | | ); |
| 2149 | }); |
| 2296 | 2150 | |
| 2297 | | cases.add( |
| 2298 | | "@ptrToInt on *void", |
| 2151 | cases.add("@ptrToInt on *void", |
| 2299 | 2152 | \\export fn entry() bool { |
| 2300 | 2153 | \\ return @ptrToInt(&{}) == @ptrToInt(&{}); |
| 2301 | 2154 | \\} |
| 2302 | | , |
| 2155 | , &[_][]const u8{ |
| 2303 | 2156 | "tmp.zig:2:23: error: pointer to size 0 type has no address", |
| 2304 | | ); |
| 2157 | }); |
| 2305 | 2158 | |
| 2306 | | cases.add( |
| 2307 | | "@popCount - non-integer", |
| 2159 | cases.add("@popCount - non-integer", |
| 2308 | 2160 | \\export fn entry(x: f32) u32 { |
| 2309 | 2161 | \\ return @popCount(f32, x); |
| 2310 | 2162 | \\} |
| 2311 | | , |
| 2163 | , &[_][]const u8{ |
| 2312 | 2164 | "tmp.zig:2:22: error: expected integer type, found 'f32'", |
| 2313 | | ); |
| 2165 | }); |
| 2314 | 2166 | |
| 2315 | 2167 | cases.addCase(x: { |
| 2316 | | const tc = cases.create( |
| 2317 | | "wrong same named struct", |
| 2168 | const tc = cases.create("wrong same named struct", |
| 2318 | 2169 | \\const a = @import("a.zig"); |
| 2319 | 2170 | \\const b = @import("b.zig"); |
| 2320 | 2171 | \\ |
| ... | ... | @@ -2324,12 +2175,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2324 | 2175 | \\} |
| 2325 | 2176 | \\ |
| 2326 | 2177 | \\fn bar(x: *b.Foo) void {} |
| 2327 | | , |
| 2178 | , &[_][]const u8{ |
| 2328 | 2179 | "tmp.zig:6:10: error: expected type '*b.Foo', found '*a.Foo'", |
| 2329 | 2180 | "tmp.zig:6:10: note: pointer type child 'a.Foo' cannot cast into pointer type child 'b.Foo'", |
| 2330 | 2181 | "a.zig:1:17: note: a.Foo declared here", |
| 2331 | 2182 | "b.zig:1:17: note: b.Foo declared here", |
| 2332 | | ); |
| 2183 | }); |
| 2333 | 2184 | |
| 2334 | 2185 | tc.addSourceFile("a.zig", |
| 2335 | 2186 | \\pub const Foo = struct { |
| ... | ... | @@ -2346,8 +2197,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2346 | 2197 | break :x tc; |
| 2347 | 2198 | }); |
| 2348 | 2199 | |
| 2349 | | cases.add( |
| 2350 | | "@floatToInt comptime safety", |
| 2200 | cases.add("@floatToInt comptime safety", |
| 2351 | 2201 | \\comptime { |
| 2352 | 2202 | \\ _ = @floatToInt(i8, @as(f32, -129.1)); |
| 2353 | 2203 | \\} |
| ... | ... | @@ -2357,23 +2207,21 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2357 | 2207 | \\comptime { |
| 2358 | 2208 | \\ _ = @floatToInt(u8, @as(f32, 256.1)); |
| 2359 | 2209 | \\} |
| 2360 | | , |
| 2210 | , &[_][]const u8{ |
| 2361 | 2211 | "tmp.zig:2:9: error: integer value '-129' cannot be stored in type 'i8'", |
| 2362 | 2212 | "tmp.zig:5:9: error: integer value '-1' cannot be stored in type 'u8'", |
| 2363 | 2213 | "tmp.zig:8:9: error: integer value '256' cannot be stored in type 'u8'", |
| 2364 | | ); |
| 2214 | }); |
| 2365 | 2215 | |
| 2366 | | cases.add( |
| 2367 | | "use c_void as return type of fn ptr", |
| 2216 | cases.add("use c_void as return type of fn ptr", |
| 2368 | 2217 | \\export fn entry() void { |
| 2369 | 2218 | \\ const a: fn () c_void = undefined; |
| 2370 | 2219 | \\} |
| 2371 | | , |
| 2220 | , &[_][]const u8{ |
| 2372 | 2221 | "tmp.zig:2:20: error: return type cannot be opaque", |
| 2373 | | ); |
| 2222 | }); |
| 2374 | 2223 | |
| 2375 | | cases.add( |
| 2376 | | "use implicit casts to assign null to non-nullable pointer", |
| 2224 | cases.add("use implicit casts to assign null to non-nullable pointer", |
| 2377 | 2225 | \\export fn entry() void { |
| 2378 | 2226 | \\ var x: i32 = 1234; |
| 2379 | 2227 | \\ var p: *i32 = &x; |
| ... | ... | @@ -2381,30 +2229,27 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2381 | 2229 | \\ pp.* = null; |
| 2382 | 2230 | \\ var y = p.*; |
| 2383 | 2231 | \\} |
| 2384 | | , |
| 2232 | , &[_][]const u8{ |
| 2385 | 2233 | "tmp.zig:4:23: error: expected type '*?*i32', found '**i32'", |
| 2386 | | ); |
| 2234 | }); |
| 2387 | 2235 | |
| 2388 | | cases.add( |
| 2389 | | "attempted implicit cast from T to [*]const T", |
| 2236 | cases.add("attempted implicit cast from T to [*]const T", |
| 2390 | 2237 | \\export fn entry() void { |
| 2391 | 2238 | \\ const x: [*]const bool = true; |
| 2392 | 2239 | \\} |
| 2393 | | , |
| 2240 | , &[_][]const u8{ |
| 2394 | 2241 | "tmp.zig:2:30: error: expected type '[*]const bool', found 'bool'", |
| 2395 | | ); |
| 2242 | }); |
| 2396 | 2243 | |
| 2397 | | cases.add( |
| 2398 | | "dereference unknown length pointer", |
| 2244 | cases.add("dereference unknown length pointer", |
| 2399 | 2245 | \\export fn entry(x: [*]i32) i32 { |
| 2400 | 2246 | \\ return x.*; |
| 2401 | 2247 | \\} |
| 2402 | | , |
| 2248 | , &[_][]const u8{ |
| 2403 | 2249 | "tmp.zig:2:13: error: index syntax required for unknown-length pointer type '[*]i32'", |
| 2404 | | ); |
| 2250 | }); |
| 2405 | 2251 | |
| 2406 | | cases.add( |
| 2407 | | "field access of unknown length pointer", |
| 2252 | cases.add("field access of unknown length pointer", |
| 2408 | 2253 | \\const Foo = extern struct { |
| 2409 | 2254 | \\ a: i32, |
| 2410 | 2255 | \\}; |
| ... | ... | @@ -2412,19 +2257,17 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2412 | 2257 | \\export fn entry(foo: [*]Foo) void { |
| 2413 | 2258 | \\ foo.a += 1; |
| 2414 | 2259 | \\} |
| 2415 | | , |
| 2260 | , &[_][]const u8{ |
| 2416 | 2261 | "tmp.zig:6:8: error: type '[*]Foo' does not support field access", |
| 2417 | | ); |
| 2262 | }); |
| 2418 | 2263 | |
| 2419 | | cases.add( |
| 2420 | | "unknown length pointer to opaque", |
| 2264 | cases.add("unknown length pointer to opaque", |
| 2421 | 2265 | \\export const T = [*]@OpaqueType(); |
| 2422 | | , |
| 2266 | , &[_][]const u8{ |
| 2423 | 2267 | "tmp.zig:1:21: error: unknown-length pointer to opaque", |
| 2424 | | ); |
| 2268 | }); |
| 2425 | 2269 | |
| 2426 | | cases.add( |
| 2427 | | "error when evaluating return type", |
| 2270 | cases.add("error when evaluating return type", |
| 2428 | 2271 | \\const Foo = struct { |
| 2429 | 2272 | \\ map: @as(i32, i32), |
| 2430 | 2273 | \\ |
| ... | ... | @@ -2435,30 +2278,27 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2435 | 2278 | \\export fn entry() void { |
| 2436 | 2279 | \\ var rule_set = try Foo.init(); |
| 2437 | 2280 | \\} |
| 2438 | | , |
| 2281 | , &[_][]const u8{ |
| 2439 | 2282 | "tmp.zig:2:10: error: expected type 'i32', found 'type'", |
| 2440 | | ); |
| 2283 | }); |
| 2441 | 2284 | |
| 2442 | | cases.add( |
| 2443 | | "slicing single-item pointer", |
| 2285 | cases.add("slicing single-item pointer", |
| 2444 | 2286 | \\export fn entry(ptr: *i32) void { |
| 2445 | 2287 | \\ const slice = ptr[0..2]; |
| 2446 | 2288 | \\} |
| 2447 | | , |
| 2289 | , &[_][]const u8{ |
| 2448 | 2290 | "tmp.zig:2:22: error: slice of single-item pointer", |
| 2449 | | ); |
| 2291 | }); |
| 2450 | 2292 | |
| 2451 | | cases.add( |
| 2452 | | "indexing single-item pointer", |
| 2293 | cases.add("indexing single-item pointer", |
| 2453 | 2294 | \\export fn entry(ptr: *i32) i32 { |
| 2454 | 2295 | \\ return ptr[1]; |
| 2455 | 2296 | \\} |
| 2456 | | , |
| 2297 | , &[_][]const u8{ |
| 2457 | 2298 | "tmp.zig:2:15: error: index of single-item pointer", |
| 2458 | | ); |
| 2299 | }); |
| 2459 | 2300 | |
| 2460 | | cases.add( |
| 2461 | | "nested error set mismatch", |
| 2301 | cases.add("nested error set mismatch", |
| 2462 | 2302 | \\const NextError = error{NextError}; |
| 2463 | 2303 | \\const OtherError = error{OutOfMemory}; |
| 2464 | 2304 | \\ |
| ... | ... | @@ -2469,15 +2309,14 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2469 | 2309 | \\fn foo() ?OtherError!i32 { |
| 2470 | 2310 | \\ return null; |
| 2471 | 2311 | \\} |
| 2472 | | , |
| 2312 | , &[_][]const u8{ |
| 2473 | 2313 | "tmp.zig:5:34: error: expected type '?NextError!i32', found '?OtherError!i32'", |
| 2474 | 2314 | "tmp.zig:5:34: note: optional type child 'OtherError!i32' cannot cast into optional type child 'NextError!i32'", |
| 2475 | 2315 | "tmp.zig:5:34: note: error set 'OtherError' cannot cast into error set 'NextError'", |
| 2476 | 2316 | "tmp.zig:2:26: note: 'error.OutOfMemory' not a member of destination error set", |
| 2477 | | ); |
| 2317 | }); |
| 2478 | 2318 | |
| 2479 | | cases.add( |
| 2480 | | "invalid deref on switch target", |
| 2319 | cases.add("invalid deref on switch target", |
| 2481 | 2320 | \\comptime { |
| 2482 | 2321 | \\ var tile = Tile.Empty; |
| 2483 | 2322 | \\ switch (tile.*) { |
| ... | ... | @@ -2489,19 +2328,17 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2489 | 2328 | \\ Empty, |
| 2490 | 2329 | \\ Filled, |
| 2491 | 2330 | \\}; |
| 2492 | | , |
| 2331 | , &[_][]const u8{ |
| 2493 | 2332 | "tmp.zig:3:17: error: attempt to dereference non-pointer type 'Tile'", |
| 2494 | | ); |
| 2333 | }); |
| 2495 | 2334 | |
| 2496 | | cases.add( |
| 2497 | | "invalid field access in comptime", |
| 2335 | cases.add("invalid field access in comptime", |
| 2498 | 2336 | \\comptime { var x = doesnt_exist.whatever; } |
| 2499 | | , |
| 2337 | , &[_][]const u8{ |
| 2500 | 2338 | "tmp.zig:1:20: error: use of undeclared identifier 'doesnt_exist'", |
| 2501 | | ); |
| 2339 | }); |
| 2502 | 2340 | |
| 2503 | | cases.add( |
| 2504 | | "suspend inside suspend block", |
| 2341 | cases.add("suspend inside suspend block", |
| 2505 | 2342 | \\export fn entry() void { |
| 2506 | 2343 | \\ _ = async foo(); |
| 2507 | 2344 | \\} |
| ... | ... | @@ -2511,34 +2348,31 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2511 | 2348 | \\ } |
| 2512 | 2349 | \\ } |
| 2513 | 2350 | \\} |
| 2514 | | , |
| 2351 | , &[_][]const u8{ |
| 2515 | 2352 | "tmp.zig:6:9: error: cannot suspend inside suspend block", |
| 2516 | 2353 | "tmp.zig:5:5: note: other suspend block here", |
| 2517 | | ); |
| 2354 | }); |
| 2518 | 2355 | |
| 2519 | | cases.add( |
| 2520 | | "assign inline fn to non-comptime var", |
| 2356 | cases.add("assign inline fn to non-comptime var", |
| 2521 | 2357 | \\export fn entry() void { |
| 2522 | 2358 | \\ var a = b; |
| 2523 | 2359 | \\} |
| 2524 | 2360 | \\inline fn b() void { } |
| 2525 | | , |
| 2361 | , &[_][]const u8{ |
| 2526 | 2362 | "tmp.zig:2:5: error: functions marked inline must be stored in const or comptime var", |
| 2527 | 2363 | "tmp.zig:4:1: note: declared here", |
| 2528 | | ); |
| 2364 | }); |
| 2529 | 2365 | |
| 2530 | | cases.add( |
| 2531 | | "wrong type passed to @panic", |
| 2366 | cases.add("wrong type passed to @panic", |
| 2532 | 2367 | \\export fn entry() void { |
| 2533 | 2368 | \\ var e = error.Foo; |
| 2534 | 2369 | \\ @panic(e); |
| 2535 | 2370 | \\} |
| 2536 | | , |
| 2371 | , &[_][]const u8{ |
| 2537 | 2372 | "tmp.zig:3:12: error: expected type '[]const u8', found 'error{Foo}'", |
| 2538 | | ); |
| 2373 | }); |
| 2539 | 2374 | |
| 2540 | | cases.add( |
| 2541 | | "@tagName used on union with no associated enum tag", |
| 2375 | cases.add("@tagName used on union with no associated enum tag", |
| 2542 | 2376 | \\const FloatInt = extern union { |
| 2543 | 2377 | \\ Float: f32, |
| 2544 | 2378 | \\ Int: i32, |
| ... | ... | @@ -2547,54 +2381,49 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2547 | 2381 | \\ var fi = FloatInt{.Float = 123.45}; |
| 2548 | 2382 | \\ var tagName = @tagName(fi); |
| 2549 | 2383 | \\} |
| 2550 | | , |
| 2384 | , &[_][]const u8{ |
| 2551 | 2385 | "tmp.zig:7:19: error: union has no associated enum", |
| 2552 | 2386 | "tmp.zig:1:18: note: declared here", |
| 2553 | | ); |
| 2387 | }); |
| 2554 | 2388 | |
| 2555 | | cases.add( |
| 2556 | | "returning error from void async function", |
| 2389 | cases.add("returning error from void async function", |
| 2557 | 2390 | \\export fn entry() void { |
| 2558 | 2391 | \\ _ = async amain(); |
| 2559 | 2392 | \\} |
| 2560 | 2393 | \\async fn amain() void { |
| 2561 | 2394 | \\ return error.ShouldBeCompileError; |
| 2562 | 2395 | \\} |
| 2563 | | , |
| 2396 | , &[_][]const u8{ |
| 2564 | 2397 | "tmp.zig:5:17: error: expected type 'void', found 'error{ShouldBeCompileError}'", |
| 2565 | | ); |
| 2398 | }); |
| 2566 | 2399 | |
| 2567 | | cases.add( |
| 2568 | | "var makes structs required to be comptime known", |
| 2400 | cases.add("var makes structs required to be comptime known", |
| 2569 | 2401 | \\export fn entry() void { |
| 2570 | 2402 | \\ const S = struct{v: var}; |
| 2571 | 2403 | \\ var s = S{.v=@as(i32, 10)}; |
| 2572 | 2404 | \\} |
| 2573 | | , |
| 2405 | , &[_][]const u8{ |
| 2574 | 2406 | "tmp.zig:3:4: error: variable of type 'S' must be const or comptime", |
| 2575 | | ); |
| 2407 | }); |
| 2576 | 2408 | |
| 2577 | | cases.add( |
| 2578 | | "@ptrCast discards const qualifier", |
| 2409 | cases.add("@ptrCast discards const qualifier", |
| 2579 | 2410 | \\export fn entry() void { |
| 2580 | 2411 | \\ const x: i32 = 1234; |
| 2581 | 2412 | \\ const y = @ptrCast(*i32, &x); |
| 2582 | 2413 | \\} |
| 2583 | | , |
| 2414 | , &[_][]const u8{ |
| 2584 | 2415 | "tmp.zig:3:15: error: cast discards const qualifier", |
| 2585 | | ); |
| 2416 | }); |
| 2586 | 2417 | |
| 2587 | | cases.add( |
| 2588 | | "comptime slice of undefined pointer non-zero len", |
| 2418 | cases.add("comptime slice of undefined pointer non-zero len", |
| 2589 | 2419 | \\export fn entry() void { |
| 2590 | 2420 | \\ const slice = @as([*]i32, undefined)[0..1]; |
| 2591 | 2421 | \\} |
| 2592 | | , |
| 2422 | , &[_][]const u8{ |
| 2593 | 2423 | "tmp.zig:2:41: error: non-zero length slice of undefined pointer", |
| 2594 | | ); |
| 2424 | }); |
| 2595 | 2425 | |
| 2596 | | cases.add( |
| 2597 | | "type checking function pointers", |
| 2426 | cases.add("type checking function pointers", |
| 2598 | 2427 | \\fn a(b: fn (*const u8) void) void { |
| 2599 | 2428 | \\ b('a'); |
| 2600 | 2429 | \\} |
| ... | ... | @@ -2602,12 +2431,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2602 | 2431 | \\export fn entry() void { |
| 2603 | 2432 | \\ a(c); |
| 2604 | 2433 | \\} |
| 2605 | | , |
| 2434 | , &[_][]const u8{ |
| 2606 | 2435 | "tmp.zig:6:7: error: expected type 'fn(*const u8) void', found 'fn(u8) void'", |
| 2607 | | ); |
| 2436 | }); |
| 2608 | 2437 | |
| 2609 | | cases.add( |
| 2610 | | "no else prong on switch on global error set", |
| 2438 | cases.add("no else prong on switch on global error set", |
| 2611 | 2439 | \\export fn entry() void { |
| 2612 | 2440 | \\ foo(error.A); |
| 2613 | 2441 | \\} |
| ... | ... | @@ -2616,23 +2444,21 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2616 | 2444 | \\ error.A => {}, |
| 2617 | 2445 | \\ } |
| 2618 | 2446 | \\} |
| 2619 | | , |
| 2447 | , &[_][]const u8{ |
| 2620 | 2448 | "tmp.zig:5:5: error: else prong required when switching on type 'anyerror'", |
| 2621 | | ); |
| 2449 | }); |
| 2622 | 2450 | |
| 2623 | | cases.add( |
| 2624 | | "inferred error set with no returned error", |
| 2451 | cases.add("inferred error set with no returned error", |
| 2625 | 2452 | \\export fn entry() void { |
| 2626 | 2453 | \\ foo() catch unreachable; |
| 2627 | 2454 | \\} |
| 2628 | 2455 | \\fn foo() !void { |
| 2629 | 2456 | \\} |
| 2630 | | , |
| 2457 | , &[_][]const u8{ |
| 2631 | 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( |
| 2635 | | "error not handled in switch", |
| 2461 | cases.add("error not handled in switch", |
| 2636 | 2462 | \\export fn entry() void { |
| 2637 | 2463 | \\ foo(452) catch |err| switch (err) { |
| 2638 | 2464 | \\ error.Foo => {}, |
| ... | ... | @@ -2646,13 +2472,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2646 | 2472 | \\ else => {}, |
| 2647 | 2473 | \\ } |
| 2648 | 2474 | \\} |
| 2649 | | , |
| 2475 | , &[_][]const u8{ |
| 2650 | 2476 | "tmp.zig:2:26: error: error.Baz not handled in switch", |
| 2651 | 2477 | "tmp.zig:2:26: error: error.Bar not handled in switch", |
| 2652 | | ); |
| 2478 | }); |
| 2653 | 2479 | |
| 2654 | | cases.add( |
| 2655 | | "duplicate error in switch", |
| 2480 | cases.add("duplicate error in switch", |
| 2656 | 2481 | \\export fn entry() void { |
| 2657 | 2482 | \\ foo(452) catch |err| switch (err) { |
| 2658 | 2483 | \\ error.Foo => {}, |
| ... | ... | @@ -2668,10 +2493,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2668 | 2493 | \\ else => {}, |
| 2669 | 2494 | \\ } |
| 2670 | 2495 | \\} |
| 2671 | | , |
| 2496 | , &[_][]const u8{ |
| 2672 | 2497 | "tmp.zig:5:14: error: duplicate switch value: '@typeOf(foo).ReturnType.ErrorSet.Foo'", |
| 2673 | 2498 | "tmp.zig:3:14: note: other value is here", |
| 2674 | | ); |
| 2499 | }); |
| 2675 | 2500 | |
| 2676 | 2501 | cases.add("invalid cast from integral type to enum", |
| 2677 | 2502 | \\const E = enum(usize) { One, Two }; |
| ... | ... | @@ -2685,10 +2510,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2685 | 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( |
| 2691 | | "range operator in switch used on error set", |
| 2517 | cases.add("range operator in switch used on error set", |
| 2692 | 2518 | \\export fn entry() void { |
| 2693 | 2519 | \\ try foo(452) catch |err| switch (err) { |
| 2694 | 2520 | \\ error.A ... error.B => {}, |
| ... | ... | @@ -2702,41 +2528,37 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2702 | 2528 | \\ else => {}, |
| 2703 | 2529 | \\ } |
| 2704 | 2530 | \\} |
| 2705 | | , |
| 2531 | , &[_][]const u8{ |
| 2706 | 2532 | "tmp.zig:3:17: error: operator not allowed for errors", |
| 2707 | | ); |
| 2533 | }); |
| 2708 | 2534 | |
| 2709 | | cases.add( |
| 2710 | | "inferring error set of function pointer", |
| 2535 | cases.add("inferring error set of function pointer", |
| 2711 | 2536 | \\comptime { |
| 2712 | 2537 | \\ const z: ?fn()!void = null; |
| 2713 | 2538 | \\} |
| 2714 | | , |
| 2539 | , &[_][]const u8{ |
| 2715 | 2540 | "tmp.zig:2:15: error: inferring error set of return type valid only for function definitions", |
| 2716 | | ); |
| 2541 | }); |
| 2717 | 2542 | |
| 2718 | | cases.add( |
| 2719 | | "access non-existent member of error set", |
| 2543 | cases.add("access non-existent member of error set", |
| 2720 | 2544 | \\const Foo = error{A}; |
| 2721 | 2545 | \\comptime { |
| 2722 | 2546 | \\ const z = Foo.Bar; |
| 2723 | 2547 | \\} |
| 2724 | | , |
| 2548 | , &[_][]const u8{ |
| 2725 | 2549 | "tmp.zig:3:18: error: no error named 'Bar' in 'Foo'", |
| 2726 | | ); |
| 2550 | }); |
| 2727 | 2551 | |
| 2728 | | cases.add( |
| 2729 | | "error union operator with non error set LHS", |
| 2552 | cases.add("error union operator with non error set LHS", |
| 2730 | 2553 | \\comptime { |
| 2731 | 2554 | \\ const z = i32!i32; |
| 2732 | 2555 | \\ var x: z = undefined; |
| 2733 | 2556 | \\} |
| 2734 | | , |
| 2557 | , &[_][]const u8{ |
| 2735 | 2558 | "tmp.zig:2:15: error: expected error set type, found type 'i32'", |
| 2736 | | ); |
| 2559 | }); |
| 2737 | 2560 | |
| 2738 | | cases.add( |
| 2739 | | "error equality but sets have no common members", |
| 2561 | cases.add("error equality but sets have no common members", |
| 2740 | 2562 | \\const Set1 = error{A, C}; |
| 2741 | 2563 | \\const Set2 = error{B, D}; |
| 2742 | 2564 | \\export fn entry() void { |
| ... | ... | @@ -2747,33 +2569,30 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2747 | 2569 | \\ |
| 2748 | 2570 | \\ } |
| 2749 | 2571 | \\} |
| 2750 | | , |
| 2572 | , &[_][]const u8{ |
| 2751 | 2573 | "tmp.zig:7:11: error: error sets 'Set1' and 'Set2' have no common errors", |
| 2752 | | ); |
| 2574 | }); |
| 2753 | 2575 | |
| 2754 | | cases.add( |
| 2755 | | "only equality binary operator allowed for error sets", |
| 2576 | cases.add("only equality binary operator allowed for error sets", |
| 2756 | 2577 | \\comptime { |
| 2757 | 2578 | \\ const z = error.A > error.B; |
| 2758 | 2579 | \\} |
| 2759 | | , |
| 2580 | , &[_][]const u8{ |
| 2760 | 2581 | "tmp.zig:2:23: error: operator not allowed for errors", |
| 2761 | | ); |
| 2582 | }); |
| 2762 | 2583 | |
| 2763 | | cases.add( |
| 2764 | | "explicit error set cast known at comptime violates error sets", |
| 2584 | cases.add("explicit error set cast known at comptime violates error sets", |
| 2765 | 2585 | \\const Set1 = error {A, B}; |
| 2766 | 2586 | \\const Set2 = error {A, C}; |
| 2767 | 2587 | \\comptime { |
| 2768 | 2588 | \\ var x = Set1.B; |
| 2769 | 2589 | \\ var y = @errSetCast(Set2, x); |
| 2770 | 2590 | \\} |
| 2771 | | , |
| 2591 | , &[_][]const u8{ |
| 2772 | 2592 | "tmp.zig:5:13: error: error.B not a member of error set 'Set2'", |
| 2773 | | ); |
| 2593 | }); |
| 2774 | 2594 | |
| 2775 | | cases.add( |
| 2776 | | "cast error union of global error set to error union of smaller error set", |
| 2595 | cases.add("cast error union of global error set to error union of smaller error set", |
| 2777 | 2596 | \\const SmallErrorSet = error{A}; |
| 2778 | 2597 | \\export fn entry() void { |
| 2779 | 2598 | \\ var x: SmallErrorSet!i32 = foo(); |
| ... | ... | @@ -2781,14 +2600,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2781 | 2600 | \\fn foo() anyerror!i32 { |
| 2782 | 2601 | \\ return error.B; |
| 2783 | 2602 | \\} |
| 2784 | | , |
| 2603 | , &[_][]const u8{ |
| 2785 | 2604 | "tmp.zig:3:35: error: expected type 'SmallErrorSet!i32', found 'anyerror!i32'", |
| 2786 | 2605 | "tmp.zig:3:35: note: error set 'anyerror' cannot cast into error set 'SmallErrorSet'", |
| 2787 | 2606 | "tmp.zig:3:35: note: cannot cast global error set into smaller set", |
| 2788 | | ); |
| 2607 | }); |
| 2789 | 2608 | |
| 2790 | | cases.add( |
| 2791 | | "cast global error set to error set", |
| 2609 | cases.add("cast global error set to error set", |
| 2792 | 2610 | \\const SmallErrorSet = error{A}; |
| 2793 | 2611 | \\export fn entry() void { |
| 2794 | 2612 | \\ var x: SmallErrorSet = foo(); |
| ... | ... | @@ -2796,24 +2614,22 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2796 | 2614 | \\fn foo() anyerror { |
| 2797 | 2615 | \\ return error.B; |
| 2798 | 2616 | \\} |
| 2799 | | , |
| 2617 | , &[_][]const u8{ |
| 2800 | 2618 | "tmp.zig:3:31: error: expected type 'SmallErrorSet', found 'anyerror'", |
| 2801 | 2619 | "tmp.zig:3:31: note: cannot cast global error set into smaller set", |
| 2802 | | ); |
| 2803 | | cases.add( |
| 2804 | | "recursive inferred error set", |
| 2620 | }); |
| 2621 | cases.add("recursive inferred error set", |
| 2805 | 2622 | \\export fn entry() void { |
| 2806 | 2623 | \\ foo() catch unreachable; |
| 2807 | 2624 | \\} |
| 2808 | 2625 | \\fn foo() !void { |
| 2809 | 2626 | \\ try foo(); |
| 2810 | 2627 | \\} |
| 2811 | | , |
| 2628 | , &[_][]const u8{ |
| 2812 | 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( |
| 2816 | | "implicit cast of error set not a subset", |
| 2632 | cases.add("implicit cast of error set not a subset", |
| 2817 | 2633 | \\const Set1 = error{A, B}; |
| 2818 | 2634 | \\const Set2 = error{A, C}; |
| 2819 | 2635 | \\export fn entry() void { |
| ... | ... | @@ -2822,13 +2638,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2822 | 2638 | \\fn foo(set1: Set1) void { |
| 2823 | 2639 | \\ var x: Set2 = set1; |
| 2824 | 2640 | \\} |
| 2825 | | , |
| 2641 | , &[_][]const u8{ |
| 2826 | 2642 | "tmp.zig:7:19: error: expected type 'Set2', found 'Set1'", |
| 2827 | 2643 | "tmp.zig:1:23: note: 'error.B' not a member of destination error set", |
| 2828 | | ); |
| 2644 | }); |
| 2829 | 2645 | |
| 2830 | | cases.add( |
| 2831 | | "int to err global invalid number", |
| 2646 | cases.add("int to err global invalid number", |
| 2832 | 2647 | \\const Set1 = error{ |
| 2833 | 2648 | \\ A, |
| 2834 | 2649 | \\ B, |
| ... | ... | @@ -2837,12 +2652,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2837 | 2652 | \\ var x: u16 = 3; |
| 2838 | 2653 | \\ var y = @intToError(x); |
| 2839 | 2654 | \\} |
| 2840 | | , |
| 2655 | , &[_][]const u8{ |
| 2841 | 2656 | "tmp.zig:7:13: error: integer value 3 represents no error", |
| 2842 | | ); |
| 2657 | }); |
| 2843 | 2658 | |
| 2844 | | cases.add( |
| 2845 | | "int to err non global invalid number", |
| 2659 | cases.add("int to err non global invalid number", |
| 2846 | 2660 | \\const Set1 = error{ |
| 2847 | 2661 | \\ A, |
| 2848 | 2662 | \\ B, |
| ... | ... | @@ -2855,21 +2669,19 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2855 | 2669 | \\ var x = @errorToInt(Set1.B); |
| 2856 | 2670 | \\ var y = @errSetCast(Set2, @intToError(x)); |
| 2857 | 2671 | \\} |
| 2858 | | , |
| 2672 | , &[_][]const u8{ |
| 2859 | 2673 | "tmp.zig:11:13: error: error.B not a member of error set 'Set2'", |
| 2860 | | ); |
| 2674 | }); |
| 2861 | 2675 | |
| 2862 | | cases.add( |
| 2863 | | "@memberCount of error", |
| 2676 | cases.add("@memberCount of error", |
| 2864 | 2677 | \\comptime { |
| 2865 | 2678 | \\ _ = @memberCount(anyerror); |
| 2866 | 2679 | \\} |
| 2867 | | , |
| 2680 | , &[_][]const u8{ |
| 2868 | 2681 | "tmp.zig:2:9: error: global error set member count not available at comptime", |
| 2869 | | ); |
| 2682 | }); |
| 2870 | 2683 | |
| 2871 | | cases.add( |
| 2872 | | "duplicate error value in error set", |
| 2684 | cases.add("duplicate error value in error set", |
| 2873 | 2685 | \\const Foo = error { |
| 2874 | 2686 | \\ Bar, |
| 2875 | 2687 | \\ Bar, |
| ... | ... | @@ -2877,32 +2689,29 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2877 | 2689 | \\export fn entry() void { |
| 2878 | 2690 | \\ const a: Foo = undefined; |
| 2879 | 2691 | \\} |
| 2880 | | , |
| 2692 | , &[_][]const u8{ |
| 2881 | 2693 | "tmp.zig:3:5: error: duplicate error: 'Bar'", |
| 2882 | 2694 | "tmp.zig:2:5: note: other error here", |
| 2883 | | ); |
| 2695 | }); |
| 2884 | 2696 | |
| 2885 | | cases.add( |
| 2886 | | "cast negative integer literal to usize", |
| 2697 | cases.add("cast negative integer literal to usize", |
| 2887 | 2698 | \\export fn entry() void { |
| 2888 | 2699 | \\ const x = @as(usize, -10); |
| 2889 | 2700 | \\} |
| 2890 | | , |
| 2701 | , &[_][]const u8{ |
| 2891 | 2702 | "tmp.zig:2:26: error: cannot cast negative value -10 to unsigned integer type 'usize'", |
| 2892 | | ); |
| 2703 | }); |
| 2893 | 2704 | |
| 2894 | | cases.add( |
| 2895 | | "use invalid number literal as array index", |
| 2705 | cases.add("use invalid number literal as array index", |
| 2896 | 2706 | \\var v = 25; |
| 2897 | 2707 | \\export fn entry() void { |
| 2898 | 2708 | \\ var arr: [v]u8 = undefined; |
| 2899 | 2709 | \\} |
| 2900 | | , |
| 2710 | , &[_][]const u8{ |
| 2901 | 2711 | "tmp.zig:1:1: error: unable to infer variable type", |
| 2902 | | ); |
| 2712 | }); |
| 2903 | 2713 | |
| 2904 | | cases.add( |
| 2905 | | "duplicate struct field", |
| 2714 | cases.add("duplicate struct field", |
| 2906 | 2715 | \\const Foo = struct { |
| 2907 | 2716 | \\ Bar: i32, |
| 2908 | 2717 | \\ Bar: usize, |
| ... | ... | @@ -2910,13 +2719,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2910 | 2719 | \\export fn entry() void { |
| 2911 | 2720 | \\ const a: Foo = undefined; |
| 2912 | 2721 | \\} |
| 2913 | | , |
| 2722 | , &[_][]const u8{ |
| 2914 | 2723 | "tmp.zig:3:5: error: duplicate struct field: 'Bar'", |
| 2915 | 2724 | "tmp.zig:2:5: note: other field here", |
| 2916 | | ); |
| 2725 | }); |
| 2917 | 2726 | |
| 2918 | | cases.add( |
| 2919 | | "duplicate union field", |
| 2727 | cases.add("duplicate union field", |
| 2920 | 2728 | \\const Foo = union { |
| 2921 | 2729 | \\ Bar: i32, |
| 2922 | 2730 | \\ Bar: usize, |
| ... | ... | @@ -2924,13 +2732,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2924 | 2732 | \\export fn entry() void { |
| 2925 | 2733 | \\ const a: Foo = undefined; |
| 2926 | 2734 | \\} |
| 2927 | | , |
| 2735 | , &[_][]const u8{ |
| 2928 | 2736 | "tmp.zig:3:5: error: duplicate union field: 'Bar'", |
| 2929 | 2737 | "tmp.zig:2:5: note: other field here", |
| 2930 | | ); |
| 2738 | }); |
| 2931 | 2739 | |
| 2932 | | cases.add( |
| 2933 | | "duplicate enum field", |
| 2740 | cases.add("duplicate enum field", |
| 2934 | 2741 | \\const Foo = enum { |
| 2935 | 2742 | \\ Bar, |
| 2936 | 2743 | \\ Bar, |
| ... | ... | @@ -2939,110 +2746,99 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2939 | 2746 | \\export fn entry() void { |
| 2940 | 2747 | \\ const a: Foo = undefined; |
| 2941 | 2748 | \\} |
| 2942 | | , |
| 2749 | , &[_][]const u8{ |
| 2943 | 2750 | "tmp.zig:3:5: error: duplicate enum field: 'Bar'", |
| 2944 | 2751 | "tmp.zig:2:5: note: other field here", |
| 2945 | | ); |
| 2752 | }); |
| 2946 | 2753 | |
| 2947 | | cases.add( |
| 2948 | | "calling function with naked calling convention", |
| 2754 | cases.add("calling function with naked calling convention", |
| 2949 | 2755 | \\export fn entry() void { |
| 2950 | 2756 | \\ foo(); |
| 2951 | 2757 | \\} |
| 2952 | 2758 | \\nakedcc fn foo() void { } |
| 2953 | | , |
| 2759 | , &[_][]const u8{ |
| 2954 | 2760 | "tmp.zig:2:5: error: unable to call function with naked calling convention", |
| 2955 | 2761 | "tmp.zig:4:1: note: declared here", |
| 2956 | | ); |
| 2762 | }); |
| 2957 | 2763 | |
| 2958 | | cases.add( |
| 2959 | | "function with invalid return type", |
| 2764 | cases.add("function with invalid return type", |
| 2960 | 2765 | \\export fn foo() boid {} |
| 2961 | | , |
| 2766 | , &[_][]const u8{ |
| 2962 | 2767 | "tmp.zig:1:17: error: use of undeclared identifier 'boid'", |
| 2963 | | ); |
| 2768 | }); |
| 2964 | 2769 | |
| 2965 | | cases.add( |
| 2966 | | "function with non-extern non-packed enum parameter", |
| 2770 | cases.add("function with non-extern non-packed enum parameter", |
| 2967 | 2771 | \\const Foo = enum { A, B, C }; |
| 2968 | 2772 | \\export fn entry(foo: Foo) void { } |
| 2969 | | , |
| 2773 | , &[_][]const u8{ |
| 2970 | 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( |
| 2974 | | "function with non-extern non-packed struct parameter", |
| 2777 | cases.add("function with non-extern non-packed struct parameter", |
| 2975 | 2778 | \\const Foo = struct { |
| 2976 | 2779 | \\ A: i32, |
| 2977 | 2780 | \\ B: f32, |
| 2978 | 2781 | \\ C: bool, |
| 2979 | 2782 | \\}; |
| 2980 | 2783 | \\export fn entry(foo: Foo) void { } |
| 2981 | | , |
| 2784 | , &[_][]const u8{ |
| 2982 | 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( |
| 2986 | | "function with non-extern non-packed union parameter", |
| 2788 | cases.add("function with non-extern non-packed union parameter", |
| 2987 | 2789 | \\const Foo = union { |
| 2988 | 2790 | \\ A: i32, |
| 2989 | 2791 | \\ B: f32, |
| 2990 | 2792 | \\ C: bool, |
| 2991 | 2793 | \\}; |
| 2992 | 2794 | \\export fn entry(foo: Foo) void { } |
| 2993 | | , |
| 2795 | , &[_][]const u8{ |
| 2994 | 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( |
| 2998 | | "switch on enum with 1 field with no prongs", |
| 2799 | cases.add("switch on enum with 1 field with no prongs", |
| 2999 | 2800 | \\const Foo = enum { M }; |
| 3000 | 2801 | \\ |
| 3001 | 2802 | \\export fn entry() void { |
| 3002 | 2803 | \\ var f = Foo.M; |
| 3003 | 2804 | \\ switch (f) {} |
| 3004 | 2805 | \\} |
| 3005 | | , |
| 2806 | , &[_][]const u8{ |
| 3006 | 2807 | "tmp.zig:5:5: error: enumeration value 'Foo.M' not handled in switch", |
| 3007 | | ); |
| 2808 | }); |
| 3008 | 2809 | |
| 3009 | | cases.add( |
| 3010 | | "shift by negative comptime integer", |
| 2810 | cases.add("shift by negative comptime integer", |
| 3011 | 2811 | \\comptime { |
| 3012 | 2812 | \\ var a = 1 >> -1; |
| 3013 | 2813 | \\} |
| 3014 | | , |
| 2814 | , &[_][]const u8{ |
| 3015 | 2815 | "tmp.zig:2:18: error: shift by negative value -1", |
| 3016 | | ); |
| 2816 | }); |
| 3017 | 2817 | |
| 3018 | | cases.add( |
| 3019 | | "@panic called at compile time", |
| 2818 | cases.add("@panic called at compile time", |
| 3020 | 2819 | \\export fn entry() void { |
| 3021 | 2820 | \\ comptime { |
| 3022 | 2821 | \\ @panic("aoeu",); |
| 3023 | 2822 | \\ } |
| 3024 | 2823 | \\} |
| 3025 | | , |
| 2824 | , &[_][]const u8{ |
| 3026 | 2825 | "tmp.zig:3:9: error: encountered @panic at compile-time", |
| 3027 | | ); |
| 2826 | }); |
| 3028 | 2827 | |
| 3029 | | cases.add( |
| 3030 | | "wrong return type for main", |
| 2828 | cases.add("wrong return type for main", |
| 3031 | 2829 | \\pub fn main() f32 { } |
| 3032 | | , |
| 2830 | , &[_][]const u8{ |
| 3033 | 2831 | "error: expected return type of main to be 'void', '!void', 'noreturn', 'u8', or '!u8'", |
| 3034 | | ); |
| 2832 | }); |
| 3035 | 2833 | |
| 3036 | | cases.add( |
| 3037 | | "double ?? on main return value", |
| 2834 | cases.add("double ?? on main return value", |
| 3038 | 2835 | \\pub fn main() ??void { |
| 3039 | 2836 | \\} |
| 3040 | | , |
| 2837 | , &[_][]const u8{ |
| 3041 | 2838 | "error: expected return type of main to be 'void', '!void', 'noreturn', 'u8', or '!u8'", |
| 3042 | | ); |
| 2839 | }); |
| 3043 | 2840 | |
| 3044 | | cases.add( |
| 3045 | | "bad identifier in function with struct defined inside function which references local const", |
| 2841 | cases.add("bad identifier in function with struct defined inside function which references local const", |
| 3046 | 2842 | \\export fn entry() void { |
| 3047 | 2843 | \\ const BlockKind = u32; |
| 3048 | 2844 | \\ |
| ... | ... | @@ -3052,12 +2848,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3052 | 2848 | \\ |
| 3053 | 2849 | \\ bogus; |
| 3054 | 2850 | \\} |
| 3055 | | , |
| 2851 | , &[_][]const u8{ |
| 3056 | 2852 | "tmp.zig:8:5: error: use of undeclared identifier 'bogus'", |
| 3057 | | ); |
| 2853 | }); |
| 3058 | 2854 | |
| 3059 | | cases.add( |
| 3060 | | "labeled break not found", |
| 2855 | cases.add("labeled break not found", |
| 3061 | 2856 | \\export fn entry() void { |
| 3062 | 2857 | \\ blah: while (true) { |
| 3063 | 2858 | \\ while (true) { |
| ... | ... | @@ -3065,12 +2860,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3065 | 2860 | \\ } |
| 3066 | 2861 | \\ } |
| 3067 | 2862 | \\} |
| 3068 | | , |
| 2863 | , &[_][]const u8{ |
| 3069 | 2864 | "tmp.zig:4:13: error: label not found: 'outer'", |
| 3070 | | ); |
| 2865 | }); |
| 3071 | 2866 | |
| 3072 | | cases.add( |
| 3073 | | "labeled continue not found", |
| 2867 | cases.add("labeled continue not found", |
| 3074 | 2868 | \\export fn entry() void { |
| 3075 | 2869 | \\ var i: usize = 0; |
| 3076 | 2870 | \\ blah: while (i < 10) : (i += 1) { |
| ... | ... | @@ -3079,12 +2873,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3079 | 2873 | \\ } |
| 3080 | 2874 | \\ } |
| 3081 | 2875 | \\} |
| 3082 | | , |
| 2876 | , &[_][]const u8{ |
| 3083 | 2877 | "tmp.zig:5:13: error: labeled loop not found: 'outer'", |
| 3084 | | ); |
| 2878 | }); |
| 3085 | 2879 | |
| 3086 | | cases.add( |
| 3087 | | "attempt to use 0 bit type in extern fn", |
| 2880 | cases.add("attempt to use 0 bit type in extern fn", |
| 3088 | 2881 | \\extern fn foo(ptr: extern fn(*void) void) void; |
| 3089 | 2882 | \\ |
| 3090 | 2883 | \\export fn entry() void { |
| ... | ... | @@ -3095,476 +2888,431 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3095 | 2888 | \\export fn entry2() void { |
| 3096 | 2889 | \\ bar(&{}); |
| 3097 | 2890 | \\} |
| 3098 | | , |
| 2891 | , &[_][]const u8{ |
| 3099 | 2892 | "tmp.zig:1:30: error: parameter of type '*void' has 0 bits; not allowed in function with calling convention 'ccc'", |
| 3100 | 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( |
| 3104 | | "implicit semicolon - block statement", |
| 2896 | cases.add("implicit semicolon - block statement", |
| 3105 | 2897 | \\export fn entry() void { |
| 3106 | 2898 | \\ {} |
| 3107 | 2899 | \\ var good = {}; |
| 3108 | 2900 | \\ ({}) |
| 3109 | 2901 | \\ var bad = {}; |
| 3110 | 2902 | \\} |
| 3111 | | , |
| 2903 | , &[_][]const u8{ |
| 3112 | 2904 | "tmp.zig:5:5: error: expected token ';', found 'var'", |
| 3113 | | ); |
| 2905 | }); |
| 3114 | 2906 | |
| 3115 | | cases.add( |
| 3116 | | "implicit semicolon - block expr", |
| 2907 | cases.add("implicit semicolon - block expr", |
| 3117 | 2908 | \\export fn entry() void { |
| 3118 | 2909 | \\ _ = {}; |
| 3119 | 2910 | \\ var good = {}; |
| 3120 | 2911 | \\ _ = {} |
| 3121 | 2912 | \\ var bad = {}; |
| 3122 | 2913 | \\} |
| 3123 | | , |
| 2914 | , &[_][]const u8{ |
| 3124 | 2915 | "tmp.zig:5:5: error: expected token ';', found 'var'", |
| 3125 | | ); |
| 2916 | }); |
| 3126 | 2917 | |
| 3127 | | cases.add( |
| 3128 | | "implicit semicolon - comptime statement", |
| 2918 | cases.add("implicit semicolon - comptime statement", |
| 3129 | 2919 | \\export fn entry() void { |
| 3130 | 2920 | \\ comptime {} |
| 3131 | 2921 | \\ var good = {}; |
| 3132 | 2922 | \\ comptime ({}) |
| 3133 | 2923 | \\ var bad = {}; |
| 3134 | 2924 | \\} |
| 3135 | | , |
| 2925 | , &[_][]const u8{ |
| 3136 | 2926 | "tmp.zig:5:5: error: expected token ';', found 'var'", |
| 3137 | | ); |
| 2927 | }); |
| 3138 | 2928 | |
| 3139 | | cases.add( |
| 3140 | | "implicit semicolon - comptime expression", |
| 2929 | cases.add("implicit semicolon - comptime expression", |
| 3141 | 2930 | \\export fn entry() void { |
| 3142 | 2931 | \\ _ = comptime {}; |
| 3143 | 2932 | \\ var good = {}; |
| 3144 | 2933 | \\ _ = comptime {} |
| 3145 | 2934 | \\ var bad = {}; |
| 3146 | 2935 | \\} |
| 3147 | | , |
| 2936 | , &[_][]const u8{ |
| 3148 | 2937 | "tmp.zig:5:5: error: expected token ';', found 'var'", |
| 3149 | | ); |
| 2938 | }); |
| 3150 | 2939 | |
| 3151 | | cases.add( |
| 3152 | | "implicit semicolon - defer", |
| 2940 | cases.add("implicit semicolon - defer", |
| 3153 | 2941 | \\export fn entry() void { |
| 3154 | 2942 | \\ defer {} |
| 3155 | 2943 | \\ var good = {}; |
| 3156 | 2944 | \\ defer ({}) |
| 3157 | 2945 | \\ var bad = {}; |
| 3158 | 2946 | \\} |
| 3159 | | , |
| 2947 | , &[_][]const u8{ |
| 3160 | 2948 | "tmp.zig:5:5: error: expected token ';', found 'var'", |
| 3161 | | ); |
| 2949 | }); |
| 3162 | 2950 | |
| 3163 | | cases.add( |
| 3164 | | "implicit semicolon - if statement", |
| 2951 | cases.add("implicit semicolon - if statement", |
| 3165 | 2952 | \\export fn entry() void { |
| 3166 | 2953 | \\ if(true) {} |
| 3167 | 2954 | \\ var good = {}; |
| 3168 | 2955 | \\ if(true) ({}) |
| 3169 | 2956 | \\ var bad = {}; |
| 3170 | 2957 | \\} |
| 3171 | | , |
| 2958 | , &[_][]const u8{ |
| 3172 | 2959 | "tmp.zig:5:5: error: expected token ';', found 'var'", |
| 3173 | | ); |
| 2960 | }); |
| 3174 | 2961 | |
| 3175 | | cases.add( |
| 3176 | | "implicit semicolon - if expression", |
| 2962 | cases.add("implicit semicolon - if expression", |
| 3177 | 2963 | \\export fn entry() void { |
| 3178 | 2964 | \\ _ = if(true) {}; |
| 3179 | 2965 | \\ var good = {}; |
| 3180 | 2966 | \\ _ = if(true) {} |
| 3181 | 2967 | \\ var bad = {}; |
| 3182 | 2968 | \\} |
| 3183 | | , |
| 2969 | , &[_][]const u8{ |
| 3184 | 2970 | "tmp.zig:5:5: error: expected token ';', found 'var'", |
| 3185 | | ); |
| 2971 | }); |
| 3186 | 2972 | |
| 3187 | | cases.add( |
| 3188 | | "implicit semicolon - if-else statement", |
| 2973 | cases.add("implicit semicolon - if-else statement", |
| 3189 | 2974 | \\export fn entry() void { |
| 3190 | 2975 | \\ if(true) {} else {} |
| 3191 | 2976 | \\ var good = {}; |
| 3192 | 2977 | \\ if(true) ({}) else ({}) |
| 3193 | 2978 | \\ var bad = {}; |
| 3194 | 2979 | \\} |
| 3195 | | , |
| 2980 | , &[_][]const u8{ |
| 3196 | 2981 | "tmp.zig:5:5: error: expected token ';', found 'var'", |
| 3197 | | ); |
| 2982 | }); |
| 3198 | 2983 | |
| 3199 | | cases.add( |
| 3200 | | "implicit semicolon - if-else expression", |
| 2984 | cases.add("implicit semicolon - if-else expression", |
| 3201 | 2985 | \\export fn entry() void { |
| 3202 | 2986 | \\ _ = if(true) {} else {}; |
| 3203 | 2987 | \\ var good = {}; |
| 3204 | 2988 | \\ _ = if(true) {} else {} |
| 3205 | 2989 | \\ var bad = {}; |
| 3206 | 2990 | \\} |
| 3207 | | , |
| 2991 | , &[_][]const u8{ |
| 3208 | 2992 | "tmp.zig:5:5: error: expected token ';', found 'var'", |
| 3209 | | ); |
| 2993 | }); |
| 3210 | 2994 | |
| 3211 | | cases.add( |
| 3212 | | "implicit semicolon - if-else-if statement", |
| 2995 | cases.add("implicit semicolon - if-else-if statement", |
| 3213 | 2996 | \\export fn entry() void { |
| 3214 | 2997 | \\ if(true) {} else if(true) {} |
| 3215 | 2998 | \\ var good = {}; |
| 3216 | 2999 | \\ if(true) ({}) else if(true) ({}) |
| 3217 | 3000 | \\ var bad = {}; |
| 3218 | 3001 | \\} |
| 3219 | | , |
| 3002 | , &[_][]const u8{ |
| 3220 | 3003 | "tmp.zig:5:5: error: expected token ';', found 'var'", |
| 3221 | | ); |
| 3004 | }); |
| 3222 | 3005 | |
| 3223 | | cases.add( |
| 3224 | | "implicit semicolon - if-else-if expression", |
| 3006 | cases.add("implicit semicolon - if-else-if expression", |
| 3225 | 3007 | \\export fn entry() void { |
| 3226 | 3008 | \\ _ = if(true) {} else if(true) {}; |
| 3227 | 3009 | \\ var good = {}; |
| 3228 | 3010 | \\ _ = if(true) {} else if(true) {} |
| 3229 | 3011 | \\ var bad = {}; |
| 3230 | 3012 | \\} |
| 3231 | | , |
| 3013 | , &[_][]const u8{ |
| 3232 | 3014 | "tmp.zig:5:5: error: expected token ';', found 'var'", |
| 3233 | | ); |
| 3015 | }); |
| 3234 | 3016 | |
| 3235 | | cases.add( |
| 3236 | | "implicit semicolon - if-else-if-else statement", |
| 3017 | cases.add("implicit semicolon - if-else-if-else statement", |
| 3237 | 3018 | \\export fn entry() void { |
| 3238 | 3019 | \\ if(true) {} else if(true) {} else {} |
| 3239 | 3020 | \\ var good = {}; |
| 3240 | 3021 | \\ if(true) ({}) else if(true) ({}) else ({}) |
| 3241 | 3022 | \\ var bad = {}; |
| 3242 | 3023 | \\} |
| 3243 | | , |
| 3024 | , &[_][]const u8{ |
| 3244 | 3025 | "tmp.zig:5:5: error: expected token ';', found 'var'", |
| 3245 | | ); |
| 3026 | }); |
| 3246 | 3027 | |
| 3247 | | cases.add( |
| 3248 | | "implicit semicolon - if-else-if-else expression", |
| 3028 | cases.add("implicit semicolon - if-else-if-else expression", |
| 3249 | 3029 | \\export fn entry() void { |
| 3250 | 3030 | \\ _ = if(true) {} else if(true) {} else {}; |
| 3251 | 3031 | \\ var good = {}; |
| 3252 | 3032 | \\ _ = if(true) {} else if(true) {} else {} |
| 3253 | 3033 | \\ var bad = {}; |
| 3254 | 3034 | \\} |
| 3255 | | , |
| 3035 | , &[_][]const u8{ |
| 3256 | 3036 | "tmp.zig:5:5: error: expected token ';', found 'var'", |
| 3257 | | ); |
| 3037 | }); |
| 3258 | 3038 | |
| 3259 | | cases.add( |
| 3260 | | "implicit semicolon - test statement", |
| 3039 | cases.add("implicit semicolon - test statement", |
| 3261 | 3040 | \\export fn entry() void { |
| 3262 | 3041 | \\ if (foo()) |_| {} |
| 3263 | 3042 | \\ var good = {}; |
| 3264 | 3043 | \\ if (foo()) |_| ({}) |
| 3265 | 3044 | \\ var bad = {}; |
| 3266 | 3045 | \\} |
| 3267 | | , |
| 3046 | , &[_][]const u8{ |
| 3268 | 3047 | "tmp.zig:5:5: error: expected token ';', found 'var'", |
| 3269 | | ); |
| 3048 | }); |
| 3270 | 3049 | |
| 3271 | | cases.add( |
| 3272 | | "implicit semicolon - test expression", |
| 3050 | cases.add("implicit semicolon - test expression", |
| 3273 | 3051 | \\export fn entry() void { |
| 3274 | 3052 | \\ _ = if (foo()) |_| {}; |
| 3275 | 3053 | \\ var good = {}; |
| 3276 | 3054 | \\ _ = if (foo()) |_| {} |
| 3277 | 3055 | \\ var bad = {}; |
| 3278 | 3056 | \\} |
| 3279 | | , |
| 3057 | , &[_][]const u8{ |
| 3280 | 3058 | "tmp.zig:5:5: error: expected token ';', found 'var'", |
| 3281 | | ); |
| 3059 | }); |
| 3282 | 3060 | |
| 3283 | | cases.add( |
| 3284 | | "implicit semicolon - while statement", |
| 3061 | cases.add("implicit semicolon - while statement", |
| 3285 | 3062 | \\export fn entry() void { |
| 3286 | 3063 | \\ while(true) {} |
| 3287 | 3064 | \\ var good = {}; |
| 3288 | 3065 | \\ while(true) ({}) |
| 3289 | 3066 | \\ var bad = {}; |
| 3290 | 3067 | \\} |
| 3291 | | , |
| 3068 | , &[_][]const u8{ |
| 3292 | 3069 | "tmp.zig:5:5: error: expected token ';', found 'var'", |
| 3293 | | ); |
| 3070 | }); |
| 3294 | 3071 | |
| 3295 | | cases.add( |
| 3296 | | "implicit semicolon - while expression", |
| 3072 | cases.add("implicit semicolon - while expression", |
| 3297 | 3073 | \\export fn entry() void { |
| 3298 | 3074 | \\ _ = while(true) {}; |
| 3299 | 3075 | \\ var good = {}; |
| 3300 | 3076 | \\ _ = while(true) {} |
| 3301 | 3077 | \\ var bad = {}; |
| 3302 | 3078 | \\} |
| 3303 | | , |
| 3079 | , &[_][]const u8{ |
| 3304 | 3080 | "tmp.zig:5:5: error: expected token ';', found 'var'", |
| 3305 | | ); |
| 3081 | }); |
| 3306 | 3082 | |
| 3307 | | cases.add( |
| 3308 | | "implicit semicolon - while-continue statement", |
| 3083 | cases.add("implicit semicolon - while-continue statement", |
| 3309 | 3084 | \\export fn entry() void { |
| 3310 | 3085 | \\ while(true):({}) {} |
| 3311 | 3086 | \\ var good = {}; |
| 3312 | 3087 | \\ while(true):({}) ({}) |
| 3313 | 3088 | \\ var bad = {}; |
| 3314 | 3089 | \\} |
| 3315 | | , |
| 3090 | , &[_][]const u8{ |
| 3316 | 3091 | "tmp.zig:5:5: error: expected token ';', found 'var'", |
| 3317 | | ); |
| 3092 | }); |
| 3318 | 3093 | |
| 3319 | | cases.add( |
| 3320 | | "implicit semicolon - while-continue expression", |
| 3094 | cases.add("implicit semicolon - while-continue expression", |
| 3321 | 3095 | \\export fn entry() void { |
| 3322 | 3096 | \\ _ = while(true):({}) {}; |
| 3323 | 3097 | \\ var good = {}; |
| 3324 | 3098 | \\ _ = while(true):({}) {} |
| 3325 | 3099 | \\ var bad = {}; |
| 3326 | 3100 | \\} |
| 3327 | | , |
| 3101 | , &[_][]const u8{ |
| 3328 | 3102 | "tmp.zig:5:5: error: expected token ';', found 'var'", |
| 3329 | | ); |
| 3103 | }); |
| 3330 | 3104 | |
| 3331 | | cases.add( |
| 3332 | | "implicit semicolon - for statement", |
| 3105 | cases.add("implicit semicolon - for statement", |
| 3333 | 3106 | \\export fn entry() void { |
| 3334 | 3107 | \\ for(foo()) |_| {} |
| 3335 | 3108 | \\ var good = {}; |
| 3336 | 3109 | \\ for(foo()) |_| ({}) |
| 3337 | 3110 | \\ var bad = {}; |
| 3338 | 3111 | \\} |
| 3339 | | , |
| 3112 | , &[_][]const u8{ |
| 3340 | 3113 | "tmp.zig:5:5: error: expected token ';', found 'var'", |
| 3341 | | ); |
| 3114 | }); |
| 3342 | 3115 | |
| 3343 | | cases.add( |
| 3344 | | "implicit semicolon - for expression", |
| 3116 | cases.add("implicit semicolon - for expression", |
| 3345 | 3117 | \\export fn entry() void { |
| 3346 | 3118 | \\ _ = for(foo()) |_| {}; |
| 3347 | 3119 | \\ var good = {}; |
| 3348 | 3120 | \\ _ = for(foo()) |_| {} |
| 3349 | 3121 | \\ var bad = {}; |
| 3350 | 3122 | \\} |
| 3351 | | , |
| 3123 | , &[_][]const u8{ |
| 3352 | 3124 | "tmp.zig:5:5: error: expected token ';', found 'var'", |
| 3353 | | ); |
| 3125 | }); |
| 3354 | 3126 | |
| 3355 | | cases.add( |
| 3356 | | "multiple function definitions", |
| 3127 | cases.add("multiple function definitions", |
| 3357 | 3128 | \\fn a() void {} |
| 3358 | 3129 | \\fn a() void {} |
| 3359 | 3130 | \\export fn entry() void { a(); } |
| 3360 | | , |
| 3131 | , &[_][]const u8{ |
| 3361 | 3132 | "tmp.zig:2:1: error: redefinition of 'a'", |
| 3362 | | ); |
| 3133 | }); |
| 3363 | 3134 | |
| 3364 | | cases.add( |
| 3365 | | "unreachable with return", |
| 3135 | cases.add("unreachable with return", |
| 3366 | 3136 | \\fn a() noreturn {return;} |
| 3367 | 3137 | \\export fn entry() void { a(); } |
| 3368 | | , |
| 3138 | , &[_][]const u8{ |
| 3369 | 3139 | "tmp.zig:1:18: error: expected type 'noreturn', found 'void'", |
| 3370 | | ); |
| 3140 | }); |
| 3371 | 3141 | |
| 3372 | | cases.add( |
| 3373 | | "control reaches end of non-void function", |
| 3142 | cases.add("control reaches end of non-void function", |
| 3374 | 3143 | \\fn a() i32 {} |
| 3375 | 3144 | \\export fn entry() void { _ = a(); } |
| 3376 | | , |
| 3145 | , &[_][]const u8{ |
| 3377 | 3146 | "tmp.zig:1:12: error: expected type 'i32', found 'void'", |
| 3378 | | ); |
| 3147 | }); |
| 3379 | 3148 | |
| 3380 | | cases.add( |
| 3381 | | "undefined function call", |
| 3149 | cases.add("undefined function call", |
| 3382 | 3150 | \\export fn a() void { |
| 3383 | 3151 | \\ b(); |
| 3384 | 3152 | \\} |
| 3385 | | , |
| 3153 | , &[_][]const u8{ |
| 3386 | 3154 | "tmp.zig:2:5: error: use of undeclared identifier 'b'", |
| 3387 | | ); |
| 3155 | }); |
| 3388 | 3156 | |
| 3389 | | cases.add( |
| 3390 | | "wrong number of arguments", |
| 3157 | cases.add("wrong number of arguments", |
| 3391 | 3158 | \\export fn a() void { |
| 3392 | 3159 | \\ b(1); |
| 3393 | 3160 | \\} |
| 3394 | 3161 | \\fn b(a: i32, b: i32, c: i32) void { } |
| 3395 | | , |
| 3162 | , &[_][]const u8{ |
| 3396 | 3163 | "tmp.zig:2:6: error: expected 3 arguments, found 1", |
| 3397 | | ); |
| 3164 | }); |
| 3398 | 3165 | |
| 3399 | | cases.add( |
| 3400 | | "invalid type", |
| 3166 | cases.add("invalid type", |
| 3401 | 3167 | \\fn a() bogus {} |
| 3402 | 3168 | \\export fn entry() void { _ = a(); } |
| 3403 | | , |
| 3169 | , &[_][]const u8{ |
| 3404 | 3170 | "tmp.zig:1:8: error: use of undeclared identifier 'bogus'", |
| 3405 | | ); |
| 3171 | }); |
| 3406 | 3172 | |
| 3407 | | cases.add( |
| 3408 | | "pointer to noreturn", |
| 3173 | cases.add("pointer to noreturn", |
| 3409 | 3174 | \\fn a() *noreturn {} |
| 3410 | 3175 | \\export fn entry() void { _ = a(); } |
| 3411 | | , |
| 3176 | , &[_][]const u8{ |
| 3412 | 3177 | "tmp.zig:1:9: error: pointer to noreturn not allowed", |
| 3413 | | ); |
| 3178 | }); |
| 3414 | 3179 | |
| 3415 | | cases.add( |
| 3416 | | "unreachable code", |
| 3180 | cases.add("unreachable code", |
| 3417 | 3181 | \\export fn a() void { |
| 3418 | 3182 | \\ return; |
| 3419 | 3183 | \\ b(); |
| 3420 | 3184 | \\} |
| 3421 | 3185 | \\ |
| 3422 | 3186 | \\fn b() void {} |
| 3423 | | , |
| 3187 | , &[_][]const u8{ |
| 3424 | 3188 | "tmp.zig:3:6: error: unreachable code", |
| 3425 | | ); |
| 3189 | }); |
| 3426 | 3190 | |
| 3427 | | cases.add( |
| 3428 | | "bad import", |
| 3191 | cases.add("bad import", |
| 3429 | 3192 | \\const bogus = @import("bogus-does-not-exist.zig",); |
| 3430 | 3193 | \\export fn entry() void { bogus.bogo(); } |
| 3431 | | , |
| 3194 | , &[_][]const u8{ |
| 3432 | 3195 | "tmp.zig:1:15: error: unable to find 'bogus-does-not-exist.zig'", |
| 3433 | | ); |
| 3196 | }); |
| 3434 | 3197 | |
| 3435 | | cases.add( |
| 3436 | | "undeclared identifier", |
| 3198 | cases.add("undeclared identifier", |
| 3437 | 3199 | \\export fn a() void { |
| 3438 | 3200 | \\ return |
| 3439 | 3201 | \\ b + |
| 3440 | 3202 | \\ c; |
| 3441 | 3203 | \\} |
| 3442 | | , |
| 3204 | , &[_][]const u8{ |
| 3443 | 3205 | "tmp.zig:3:5: error: use of undeclared identifier 'b'", |
| 3444 | | ); |
| 3206 | }); |
| 3445 | 3207 | |
| 3446 | | cases.add( |
| 3447 | | "parameter redeclaration", |
| 3208 | cases.add("parameter redeclaration", |
| 3448 | 3209 | \\fn f(a : i32, a : i32) void { |
| 3449 | 3210 | \\} |
| 3450 | 3211 | \\export fn entry() void { f(1, 2); } |
| 3451 | | , |
| 3212 | , &[_][]const u8{ |
| 3452 | 3213 | "tmp.zig:1:15: error: redeclaration of variable 'a'", |
| 3453 | | ); |
| 3214 | }); |
| 3454 | 3215 | |
| 3455 | | cases.add( |
| 3456 | | "local variable redeclaration", |
| 3216 | cases.add("local variable redeclaration", |
| 3457 | 3217 | \\export fn f() void { |
| 3458 | 3218 | \\ const a : i32 = 0; |
| 3459 | 3219 | \\ const a = 0; |
| 3460 | 3220 | \\} |
| 3461 | | , |
| 3221 | , &[_][]const u8{ |
| 3462 | 3222 | "tmp.zig:3:5: error: redeclaration of variable 'a'", |
| 3463 | | ); |
| 3223 | }); |
| 3464 | 3224 | |
| 3465 | | cases.add( |
| 3466 | | "local variable redeclares parameter", |
| 3225 | cases.add("local variable redeclares parameter", |
| 3467 | 3226 | \\fn f(a : i32) void { |
| 3468 | 3227 | \\ const a = 0; |
| 3469 | 3228 | \\} |
| 3470 | 3229 | \\export fn entry() void { f(1); } |
| 3471 | | , |
| 3230 | , &[_][]const u8{ |
| 3472 | 3231 | "tmp.zig:2:5: error: redeclaration of variable 'a'", |
| 3473 | | ); |
| 3232 | }); |
| 3474 | 3233 | |
| 3475 | | cases.add( |
| 3476 | | "variable has wrong type", |
| 3234 | cases.add("variable has wrong type", |
| 3477 | 3235 | \\export fn f() i32 { |
| 3478 | 3236 | \\ const a = "a"; |
| 3479 | 3237 | \\ return a; |
| 3480 | 3238 | \\} |
| 3481 | | , |
| 3239 | , &[_][]const u8{ |
| 3482 | 3240 | "tmp.zig:3:12: error: expected type 'i32', found '*const [1:0]u8'", |
| 3483 | | ); |
| 3241 | }); |
| 3484 | 3242 | |
| 3485 | | cases.add( |
| 3486 | | "if condition is bool, not int", |
| 3243 | cases.add("if condition is bool, not int", |
| 3487 | 3244 | \\export fn f() void { |
| 3488 | 3245 | \\ if (0) {} |
| 3489 | 3246 | \\} |
| 3490 | | , |
| 3247 | , &[_][]const u8{ |
| 3491 | 3248 | "tmp.zig:2:9: error: expected type 'bool', found 'comptime_int'", |
| 3492 | | ); |
| 3249 | }); |
| 3493 | 3250 | |
| 3494 | | cases.add( |
| 3495 | | "assign unreachable", |
| 3251 | cases.add("assign unreachable", |
| 3496 | 3252 | \\export fn f() void { |
| 3497 | 3253 | \\ const a = return; |
| 3498 | 3254 | \\} |
| 3499 | | , |
| 3255 | , &[_][]const u8{ |
| 3500 | 3256 | "tmp.zig:2:5: error: unreachable code", |
| 3501 | | ); |
| 3257 | }); |
| 3502 | 3258 | |
| 3503 | | cases.add( |
| 3504 | | "unreachable variable", |
| 3259 | cases.add("unreachable variable", |
| 3505 | 3260 | \\export fn f() void { |
| 3506 | 3261 | \\ const a: noreturn = {}; |
| 3507 | 3262 | \\} |
| 3508 | | , |
| 3263 | , &[_][]const u8{ |
| 3509 | 3264 | "tmp.zig:2:25: error: expected type 'noreturn', found 'void'", |
| 3510 | | ); |
| 3265 | }); |
| 3511 | 3266 | |
| 3512 | | cases.add( |
| 3513 | | "unreachable parameter", |
| 3267 | cases.add("unreachable parameter", |
| 3514 | 3268 | \\fn f(a: noreturn) void {} |
| 3515 | 3269 | \\export fn entry() void { f(); } |
| 3516 | | , |
| 3270 | , &[_][]const u8{ |
| 3517 | 3271 | "tmp.zig:1:9: error: parameter of type 'noreturn' not allowed", |
| 3518 | | ); |
| 3272 | }); |
| 3519 | 3273 | |
| 3520 | | cases.add( |
| 3521 | | "bad assignment target", |
| 3274 | cases.add("bad assignment target", |
| 3522 | 3275 | \\export fn f() void { |
| 3523 | 3276 | \\ 3 = 3; |
| 3524 | 3277 | \\} |
| 3525 | | , |
| 3278 | , &[_][]const u8{ |
| 3526 | 3279 | "tmp.zig:2:9: error: cannot assign to constant", |
| 3527 | | ); |
| 3280 | }); |
| 3528 | 3281 | |
| 3529 | | cases.add( |
| 3530 | | "assign to constant variable", |
| 3282 | cases.add("assign to constant variable", |
| 3531 | 3283 | \\export fn f() void { |
| 3532 | 3284 | \\ const a = 3; |
| 3533 | 3285 | \\ a = 4; |
| 3534 | 3286 | \\} |
| 3535 | | , |
| 3287 | , &[_][]const u8{ |
| 3536 | 3288 | "tmp.zig:3:9: error: cannot assign to constant", |
| 3537 | | ); |
| 3289 | }); |
| 3538 | 3290 | |
| 3539 | | cases.add( |
| 3540 | | "use of undeclared identifier", |
| 3291 | cases.add("use of undeclared identifier", |
| 3541 | 3292 | \\export fn f() void { |
| 3542 | 3293 | \\ b = 3; |
| 3543 | 3294 | \\} |
| 3544 | | , |
| 3295 | , &[_][]const u8{ |
| 3545 | 3296 | "tmp.zig:2:5: error: use of undeclared identifier 'b'", |
| 3546 | | ); |
| 3297 | }); |
| 3547 | 3298 | |
| 3548 | | cases.add( |
| 3549 | | "const is a statement, not an expression", |
| 3299 | cases.add("const is a statement, not an expression", |
| 3550 | 3300 | \\export fn f() void { |
| 3551 | 3301 | \\ (const a = 0); |
| 3552 | 3302 | \\} |
| 3553 | | , |
| 3303 | , &[_][]const u8{ |
| 3554 | 3304 | "tmp.zig:2:6: error: invalid token: 'const'", |
| 3555 | | ); |
| 3305 | }); |
| 3556 | 3306 | |
| 3557 | | cases.add( |
| 3558 | | "array access of undeclared identifier", |
| 3307 | cases.add("array access of undeclared identifier", |
| 3559 | 3308 | \\export fn f() void { |
| 3560 | 3309 | \\ i[i] = i[i]; |
| 3561 | 3310 | \\} |
| 3562 | | , |
| 3311 | , &[_][]const u8{ |
| 3563 | 3312 | "tmp.zig:2:5: error: use of undeclared identifier 'i'", |
| 3564 | | ); |
| 3313 | }); |
| 3565 | 3314 | |
| 3566 | | cases.add( |
| 3567 | | "array access of non array", |
| 3315 | cases.add("array access of non array", |
| 3568 | 3316 | \\export fn f() void { |
| 3569 | 3317 | \\ var bad : bool = undefined; |
| 3570 | 3318 | \\ bad[bad] = bad[bad]; |
| ... | ... | @@ -3573,13 +3321,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3573 | 3321 | \\ var bad : bool = undefined; |
| 3574 | 3322 | \\ _ = bad[bad]; |
| 3575 | 3323 | \\} |
| 3576 | | , |
| 3324 | , &[_][]const u8{ |
| 3577 | 3325 | "tmp.zig:3:8: error: array access of non-array type 'bool'", |
| 3578 | 3326 | "tmp.zig:7:12: error: array access of non-array type 'bool'", |
| 3579 | | ); |
| 3327 | }); |
| 3580 | 3328 | |
| 3581 | | cases.add( |
| 3582 | | "array access with non integer index", |
| 3329 | cases.add("array access with non integer index", |
| 3583 | 3330 | \\export fn f() void { |
| 3584 | 3331 | \\ var array = "aoeu"; |
| 3585 | 3332 | \\ var bad = false; |
| ... | ... | @@ -3590,24 +3337,22 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3590 | 3337 | \\ var bad = false; |
| 3591 | 3338 | \\ _ = array[bad]; |
| 3592 | 3339 | \\} |
| 3593 | | , |
| 3340 | , &[_][]const u8{ |
| 3594 | 3341 | "tmp.zig:4:11: error: expected type 'usize', found 'bool'", |
| 3595 | 3342 | "tmp.zig:9:15: error: expected type 'usize', found 'bool'", |
| 3596 | | ); |
| 3343 | }); |
| 3597 | 3344 | |
| 3598 | | cases.add( |
| 3599 | | "write to const global variable", |
| 3345 | cases.add("write to const global variable", |
| 3600 | 3346 | \\const x : i32 = 99; |
| 3601 | 3347 | \\fn f() void { |
| 3602 | 3348 | \\ x = 1; |
| 3603 | 3349 | \\} |
| 3604 | 3350 | \\export fn entry() void { f(); } |
| 3605 | | , |
| 3351 | , &[_][]const u8{ |
| 3606 | 3352 | "tmp.zig:3:9: error: cannot assign to constant", |
| 3607 | | ); |
| 3353 | }); |
| 3608 | 3354 | |
| 3609 | | cases.add( |
| 3610 | | "missing else clause", |
| 3355 | cases.add("missing else clause", |
| 3611 | 3356 | \\fn f(b: bool) void { |
| 3612 | 3357 | \\ const x : i32 = if (b) h: { break :h 1; }; |
| 3613 | 3358 | \\} |
| ... | ... | @@ -3615,13 +3360,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3615 | 3360 | \\ const y = if (b) h: { break :h @as(i32, 1); }; |
| 3616 | 3361 | \\} |
| 3617 | 3362 | \\export fn entry() void { f(true); g(true); } |
| 3618 | | , |
| 3363 | , &[_][]const u8{ |
| 3619 | 3364 | "tmp.zig:2:21: error: expected type 'i32', found 'void'", |
| 3620 | 3365 | "tmp.zig:5:15: error: incompatible types: 'i32' and 'void'", |
| 3621 | | ); |
| 3366 | }); |
| 3622 | 3367 | |
| 3623 | | cases.add( |
| 3624 | | "invalid struct field", |
| 3368 | cases.add("invalid struct field", |
| 3625 | 3369 | \\const A = struct { x : i32, }; |
| 3626 | 3370 | \\export fn f() void { |
| 3627 | 3371 | \\ var a : A = undefined; |
| ... | ... | @@ -3632,38 +3376,34 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3632 | 3376 | \\ var a : A = undefined; |
| 3633 | 3377 | \\ const y = a.bar; |
| 3634 | 3378 | \\} |
| 3635 | | , |
| 3379 | , &[_][]const u8{ |
| 3636 | 3380 | "tmp.zig:4:6: error: no member named 'foo' in struct 'A'", |
| 3637 | 3381 | "tmp.zig:9:16: error: no member named 'bar' in struct 'A'", |
| 3638 | | ); |
| 3382 | }); |
| 3639 | 3383 | |
| 3640 | | cases.add( |
| 3641 | | "redefinition of struct", |
| 3384 | cases.add("redefinition of struct", |
| 3642 | 3385 | \\const A = struct { x : i32, }; |
| 3643 | 3386 | \\const A = struct { y : i32, }; |
| 3644 | | , |
| 3387 | , &[_][]const u8{ |
| 3645 | 3388 | "tmp.zig:2:1: error: redefinition of 'A'", |
| 3646 | | ); |
| 3389 | }); |
| 3647 | 3390 | |
| 3648 | | cases.add( |
| 3649 | | "redefinition of enums", |
| 3391 | cases.add("redefinition of enums", |
| 3650 | 3392 | \\const A = enum {}; |
| 3651 | 3393 | \\const A = enum {}; |
| 3652 | | , |
| 3394 | , &[_][]const u8{ |
| 3653 | 3395 | "tmp.zig:2:1: error: redefinition of 'A'", |
| 3654 | | ); |
| 3396 | }); |
| 3655 | 3397 | |
| 3656 | | cases.add( |
| 3657 | | "redefinition of global variables", |
| 3398 | cases.add("redefinition of global variables", |
| 3658 | 3399 | \\var a : i32 = 1; |
| 3659 | 3400 | \\var a : i32 = 2; |
| 3660 | | , |
| 3401 | , &[_][]const u8{ |
| 3661 | 3402 | "tmp.zig:2:1: error: redefinition of 'a'", |
| 3662 | 3403 | "tmp.zig:1:1: note: previous definition is here", |
| 3663 | | ); |
| 3404 | }); |
| 3664 | 3405 | |
| 3665 | | cases.add( |
| 3666 | | "duplicate field in struct value expression", |
| 3406 | cases.add("duplicate field in struct value expression", |
| 3667 | 3407 | \\const A = struct { |
| 3668 | 3408 | \\ x : i32, |
| 3669 | 3409 | \\ y : i32, |
| ... | ... | @@ -3677,12 +3417,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3677 | 3417 | \\ .z = 4, |
| 3678 | 3418 | \\ }; |
| 3679 | 3419 | \\} |
| 3680 | | , |
| 3420 | , &[_][]const u8{ |
| 3681 | 3421 | "tmp.zig:11:9: error: duplicate field", |
| 3682 | | ); |
| 3422 | }); |
| 3683 | 3423 | |
| 3684 | | cases.add( |
| 3685 | | "missing field in struct value expression", |
| 3424 | cases.add("missing field in struct value expression", |
| 3686 | 3425 | \\const A = struct { |
| 3687 | 3426 | \\ x : i32, |
| 3688 | 3427 | \\ y : i32, |
| ... | ... | @@ -3696,12 +3435,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3696 | 3435 | \\ .y = 2, |
| 3697 | 3436 | \\ }; |
| 3698 | 3437 | \\} |
| 3699 | | , |
| 3438 | , &[_][]const u8{ |
| 3700 | 3439 | "tmp.zig:9:17: error: missing field: 'x'", |
| 3701 | | ); |
| 3440 | }); |
| 3702 | 3441 | |
| 3703 | | cases.add( |
| 3704 | | "invalid field in struct value expression", |
| 3442 | cases.add("invalid field in struct value expression", |
| 3705 | 3443 | \\const A = struct { |
| 3706 | 3444 | \\ x : i32, |
| 3707 | 3445 | \\ y : i32, |
| ... | ... | @@ -3714,86 +3452,77 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3714 | 3452 | \\ .foo = 42, |
| 3715 | 3453 | \\ }; |
| 3716 | 3454 | \\} |
| 3717 | | , |
| 3455 | , &[_][]const u8{ |
| 3718 | 3456 | "tmp.zig:10:9: error: no member named 'foo' in struct 'A'", |
| 3719 | | ); |
| 3457 | }); |
| 3720 | 3458 | |
| 3721 | | cases.add( |
| 3722 | | "invalid break expression", |
| 3459 | cases.add("invalid break expression", |
| 3723 | 3460 | \\export fn f() void { |
| 3724 | 3461 | \\ break; |
| 3725 | 3462 | \\} |
| 3726 | | , |
| 3463 | , &[_][]const u8{ |
| 3727 | 3464 | "tmp.zig:2:5: error: break expression outside loop", |
| 3728 | | ); |
| 3465 | }); |
| 3729 | 3466 | |
| 3730 | | cases.add( |
| 3731 | | "invalid continue expression", |
| 3467 | cases.add("invalid continue expression", |
| 3732 | 3468 | \\export fn f() void { |
| 3733 | 3469 | \\ continue; |
| 3734 | 3470 | \\} |
| 3735 | | , |
| 3471 | , &[_][]const u8{ |
| 3736 | 3472 | "tmp.zig:2:5: error: continue expression outside loop", |
| 3737 | | ); |
| 3473 | }); |
| 3738 | 3474 | |
| 3739 | | cases.add( |
| 3740 | | "invalid maybe type", |
| 3475 | cases.add("invalid maybe type", |
| 3741 | 3476 | \\export fn f() void { |
| 3742 | 3477 | \\ if (true) |x| { } |
| 3743 | 3478 | \\} |
| 3744 | | , |
| 3479 | , &[_][]const u8{ |
| 3745 | 3480 | "tmp.zig:2:9: error: expected optional type, found 'bool'", |
| 3746 | | ); |
| 3481 | }); |
| 3747 | 3482 | |
| 3748 | | cases.add( |
| 3749 | | "cast unreachable", |
| 3483 | cases.add("cast unreachable", |
| 3750 | 3484 | \\fn f() i32 { |
| 3751 | 3485 | \\ return @as(i32, return 1); |
| 3752 | 3486 | \\} |
| 3753 | 3487 | \\export fn entry() void { _ = f(); } |
| 3754 | | , |
| 3488 | , &[_][]const u8{ |
| 3755 | 3489 | "tmp.zig:2:12: error: unreachable code", |
| 3756 | | ); |
| 3490 | }); |
| 3757 | 3491 | |
| 3758 | | cases.add( |
| 3759 | | "invalid builtin fn", |
| 3492 | cases.add("invalid builtin fn", |
| 3760 | 3493 | \\fn f() @bogus(foo) { |
| 3761 | 3494 | \\} |
| 3762 | 3495 | \\export fn entry() void { _ = f(); } |
| 3763 | | , |
| 3496 | , &[_][]const u8{ |
| 3764 | 3497 | "tmp.zig:1:8: error: invalid builtin function: 'bogus'", |
| 3765 | | ); |
| 3498 | }); |
| 3766 | 3499 | |
| 3767 | | cases.add( |
| 3768 | | "noalias on non pointer param", |
| 3500 | cases.add("noalias on non pointer param", |
| 3769 | 3501 | \\fn f(noalias x: i32) void {} |
| 3770 | 3502 | \\export fn entry() void { f(1234); } |
| 3771 | | , |
| 3503 | , &[_][]const u8{ |
| 3772 | 3504 | "tmp.zig:1:6: error: noalias on non-pointer parameter", |
| 3773 | | ); |
| 3505 | }); |
| 3774 | 3506 | |
| 3775 | | cases.add( |
| 3776 | | "struct init syntax for array", |
| 3507 | cases.add("struct init syntax for array", |
| 3777 | 3508 | \\const foo = [3]u16{ .x = 1024 }; |
| 3778 | 3509 | \\comptime { |
| 3779 | 3510 | \\ _ = foo; |
| 3780 | 3511 | \\} |
| 3781 | | , |
| 3512 | , &[_][]const u8{ |
| 3782 | 3513 | "tmp.zig:1:21: error: type '[3]u16' does not support struct initialization syntax", |
| 3783 | | ); |
| 3514 | }); |
| 3784 | 3515 | |
| 3785 | | cases.add( |
| 3786 | | "type variables must be constant", |
| 3516 | cases.add("type variables must be constant", |
| 3787 | 3517 | \\var foo = u8; |
| 3788 | 3518 | \\export fn entry() foo { |
| 3789 | 3519 | \\ return 1; |
| 3790 | 3520 | \\} |
| 3791 | | , |
| 3521 | , &[_][]const u8{ |
| 3792 | 3522 | "tmp.zig:1:1: error: variable of type 'type' must be constant", |
| 3793 | | ); |
| 3523 | }); |
| 3794 | 3524 | |
| 3795 | | cases.add( |
| 3796 | | "variables shadowing types", |
| 3525 | cases.add("variables shadowing types", |
| 3797 | 3526 | \\const Foo = struct {}; |
| 3798 | 3527 | \\const Bar = struct {}; |
| 3799 | 3528 | \\ |
| ... | ... | @@ -3804,15 +3533,14 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3804 | 3533 | \\export fn entry() void { |
| 3805 | 3534 | \\ f(1234); |
| 3806 | 3535 | \\} |
| 3807 | | , |
| 3536 | , &[_][]const u8{ |
| 3808 | 3537 | "tmp.zig:4:6: error: redefinition of 'Foo'", |
| 3809 | 3538 | "tmp.zig:1:1: note: previous definition is here", |
| 3810 | 3539 | "tmp.zig:5:5: error: redefinition of 'Bar'", |
| 3811 | 3540 | "tmp.zig:2:1: note: previous definition is here", |
| 3812 | | ); |
| 3541 | }); |
| 3813 | 3542 | |
| 3814 | | cases.add( |
| 3815 | | "switch expression - missing enumeration prong", |
| 3543 | cases.add("switch expression - missing enumeration prong", |
| 3816 | 3544 | \\const Number = enum { |
| 3817 | 3545 | \\ One, |
| 3818 | 3546 | \\ Two, |
| ... | ... | @@ -3828,12 +3556,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3828 | 3556 | \\} |
| 3829 | 3557 | \\ |
| 3830 | 3558 | \\export fn entry() usize { return @sizeOf(@typeOf(f)); } |
| 3831 | | , |
| 3559 | , &[_][]const u8{ |
| 3832 | 3560 | "tmp.zig:8:5: error: enumeration value 'Number.Four' not handled in switch", |
| 3833 | | ); |
| 3561 | }); |
| 3834 | 3562 | |
| 3835 | | cases.add( |
| 3836 | | "switch expression - duplicate enumeration prong", |
| 3563 | cases.add("switch expression - duplicate enumeration prong", |
| 3837 | 3564 | \\const Number = enum { |
| 3838 | 3565 | \\ One, |
| 3839 | 3566 | \\ Two, |
| ... | ... | @@ -3851,13 +3578,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3851 | 3578 | \\} |
| 3852 | 3579 | \\ |
| 3853 | 3580 | \\export fn entry() usize { return @sizeOf(@typeOf(f)); } |
| 3854 | | , |
| 3581 | , &[_][]const u8{ |
| 3855 | 3582 | "tmp.zig:13:15: error: duplicate switch value", |
| 3856 | 3583 | "tmp.zig:10:15: note: other value is here", |
| 3857 | | ); |
| 3584 | }); |
| 3858 | 3585 | |
| 3859 | | cases.add( |
| 3860 | | "switch expression - duplicate enumeration prong when else present", |
| 3586 | cases.add("switch expression - duplicate enumeration prong when else present", |
| 3861 | 3587 | \\const Number = enum { |
| 3862 | 3588 | \\ One, |
| 3863 | 3589 | \\ Two, |
| ... | ... | @@ -3876,13 +3602,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3876 | 3602 | \\} |
| 3877 | 3603 | \\ |
| 3878 | 3604 | \\export fn entry() usize { return @sizeOf(@typeOf(f)); } |
| 3879 | | , |
| 3605 | , &[_][]const u8{ |
| 3880 | 3606 | "tmp.zig:13:15: error: duplicate switch value", |
| 3881 | 3607 | "tmp.zig:10:15: note: other value is here", |
| 3882 | | ); |
| 3608 | }); |
| 3883 | 3609 | |
| 3884 | | cases.add( |
| 3885 | | "switch expression - multiple else prongs", |
| 3610 | cases.add("switch expression - multiple else prongs", |
| 3886 | 3611 | \\fn f(x: u32) void { |
| 3887 | 3612 | \\ const value: bool = switch (x) { |
| 3888 | 3613 | \\ 1234 => false, |
| ... | ... | @@ -3893,24 +3618,22 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3893 | 3618 | \\export fn entry() void { |
| 3894 | 3619 | \\ f(1234); |
| 3895 | 3620 | \\} |
| 3896 | | , |
| 3621 | , &[_][]const u8{ |
| 3897 | 3622 | "tmp.zig:5:9: error: multiple else prongs in switch expression", |
| 3898 | | ); |
| 3623 | }); |
| 3899 | 3624 | |
| 3900 | | cases.add( |
| 3901 | | "switch expression - non exhaustive integer prongs", |
| 3625 | cases.add("switch expression - non exhaustive integer prongs", |
| 3902 | 3626 | \\fn foo(x: u8) void { |
| 3903 | 3627 | \\ switch (x) { |
| 3904 | 3628 | \\ 0 => {}, |
| 3905 | 3629 | \\ } |
| 3906 | 3630 | \\} |
| 3907 | 3631 | \\export fn entry() usize { return @sizeOf(@typeOf(foo)); } |
| 3908 | | , |
| 3632 | , &[_][]const u8{ |
| 3909 | 3633 | "tmp.zig:2:5: error: switch must handle all possibilities", |
| 3910 | | ); |
| 3634 | }); |
| 3911 | 3635 | |
| 3912 | | cases.add( |
| 3913 | | "switch expression - duplicate or overlapping integer value", |
| 3636 | cases.add("switch expression - duplicate or overlapping integer value", |
| 3914 | 3637 | \\fn foo(x: u8) u8 { |
| 3915 | 3638 | \\ return switch (x) { |
| 3916 | 3639 | \\ 0 ... 100 => @as(u8, 0), |
| ... | ... | @@ -3920,13 +3643,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3920 | 3643 | \\ }; |
| 3921 | 3644 | \\} |
| 3922 | 3645 | \\export fn entry() usize { return @sizeOf(@typeOf(foo)); } |
| 3923 | | , |
| 3646 | , &[_][]const u8{ |
| 3924 | 3647 | "tmp.zig:6:9: error: duplicate switch value", |
| 3925 | 3648 | "tmp.zig:5:14: note: previous value is here", |
| 3926 | | ); |
| 3649 | }); |
| 3927 | 3650 | |
| 3928 | | cases.add( |
| 3929 | | "switch expression - switch on pointer type with no else", |
| 3651 | cases.add("switch expression - switch on pointer type with no else", |
| 3930 | 3652 | \\fn foo(x: *u8) void { |
| 3931 | 3653 | \\ switch (x) { |
| 3932 | 3654 | \\ &y => {}, |
| ... | ... | @@ -3934,82 +3656,74 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3934 | 3656 | \\} |
| 3935 | 3657 | \\const y: u8 = 100; |
| 3936 | 3658 | \\export fn entry() usize { return @sizeOf(@typeOf(foo)); } |
| 3937 | | , |
| 3659 | , &[_][]const u8{ |
| 3938 | 3660 | "tmp.zig:2:5: error: else prong required when switching on type '*u8'", |
| 3939 | | ); |
| 3661 | }); |
| 3940 | 3662 | |
| 3941 | | cases.add( |
| 3942 | | "global variable initializer must be constant expression", |
| 3663 | cases.add("global variable initializer must be constant expression", |
| 3943 | 3664 | \\extern fn foo() i32; |
| 3944 | 3665 | \\const x = foo(); |
| 3945 | 3666 | \\export fn entry() i32 { return x; } |
| 3946 | | , |
| 3667 | , &[_][]const u8{ |
| 3947 | 3668 | "tmp.zig:2:11: error: unable to evaluate constant expression", |
| 3948 | | ); |
| 3669 | }); |
| 3949 | 3670 | |
| 3950 | | cases.add( |
| 3951 | | "array concatenation with wrong type", |
| 3671 | cases.add("array concatenation with wrong type", |
| 3952 | 3672 | \\const src = "aoeu"; |
| 3953 | 3673 | \\const derp: usize = 1234; |
| 3954 | 3674 | \\const a = derp ++ "foo"; |
| 3955 | 3675 | \\ |
| 3956 | 3676 | \\export fn entry() usize { return @sizeOf(@typeOf(a)); } |
| 3957 | | , |
| 3677 | , &[_][]const u8{ |
| 3958 | 3678 | "tmp.zig:3:11: error: expected array, found 'usize'", |
| 3959 | | ); |
| 3679 | }); |
| 3960 | 3680 | |
| 3961 | | cases.add( |
| 3962 | | "non compile time array concatenation", |
| 3681 | cases.add("non compile time array concatenation", |
| 3963 | 3682 | \\fn f() []u8 { |
| 3964 | 3683 | \\ return s ++ "foo"; |
| 3965 | 3684 | \\} |
| 3966 | 3685 | \\var s: [10]u8 = undefined; |
| 3967 | 3686 | \\export fn entry() usize { return @sizeOf(@typeOf(f)); } |
| 3968 | | , |
| 3687 | , &[_][]const u8{ |
| 3969 | 3688 | "tmp.zig:2:12: error: unable to evaluate constant expression", |
| 3970 | | ); |
| 3689 | }); |
| 3971 | 3690 | |
| 3972 | | cases.add( |
| 3973 | | "@cImport with bogus include", |
| 3691 | cases.add("@cImport with bogus include", |
| 3974 | 3692 | \\const c = @cImport(@cInclude("bogus.h")); |
| 3975 | 3693 | \\export fn entry() usize { return @sizeOf(@typeOf(c.bogo)); } |
| 3976 | | , |
| 3694 | , &[_][]const u8{ |
| 3977 | 3695 | "tmp.zig:1:11: error: C import failed", |
| 3978 | 3696 | ".h:1:10: note: 'bogus.h' file not found", |
| 3979 | | ); |
| 3697 | }); |
| 3980 | 3698 | |
| 3981 | | cases.add( |
| 3982 | | "address of number literal", |
| 3699 | cases.add("address of number literal", |
| 3983 | 3700 | \\const x = 3; |
| 3984 | 3701 | \\const y = &x; |
| 3985 | 3702 | \\fn foo() *const i32 { return y; } |
| 3986 | 3703 | \\export fn entry() usize { return @sizeOf(@typeOf(foo)); } |
| 3987 | | , |
| 3704 | , &[_][]const u8{ |
| 3988 | 3705 | "tmp.zig:3:30: error: expected type '*const i32', found '*const comptime_int'", |
| 3989 | | ); |
| 3706 | }); |
| 3990 | 3707 | |
| 3991 | | cases.add( |
| 3992 | | "integer overflow error", |
| 3708 | cases.add("integer overflow error", |
| 3993 | 3709 | \\const x : u8 = 300; |
| 3994 | 3710 | \\export fn entry() usize { return @sizeOf(@typeOf(x)); } |
| 3995 | | , |
| 3711 | , &[_][]const u8{ |
| 3996 | 3712 | "tmp.zig:1:16: error: integer value 300 cannot be coerced to type 'u8'", |
| 3997 | | ); |
| 3713 | }); |
| 3998 | 3714 | |
| 3999 | | cases.add( |
| 4000 | | "invalid shift amount error", |
| 3715 | cases.add("invalid shift amount error", |
| 4001 | 3716 | \\const x : u8 = 2; |
| 4002 | 3717 | \\fn f() u16 { |
| 4003 | 3718 | \\ return x << 8; |
| 4004 | 3719 | \\} |
| 4005 | 3720 | \\export fn entry() u16 { return f(); } |
| 4006 | | , |
| 3721 | , &[_][]const u8{ |
| 4007 | 3722 | "tmp.zig:3:14: error: RHS of shift is too large for LHS type", |
| 4008 | 3723 | "tmp.zig:3:17: note: value 8 cannot fit into type u3", |
| 4009 | | ); |
| 3724 | }); |
| 4010 | 3725 | |
| 4011 | | cases.add( |
| 4012 | | "missing function call param", |
| 3726 | cases.add("missing function call param", |
| 4013 | 3727 | \\const Foo = struct { |
| 4014 | 3728 | \\ a: i32, |
| 4015 | 3729 | \\ b: i32, |
| ... | ... | @@ -4033,60 +3747,54 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4033 | 3747 | \\} |
| 4034 | 3748 | \\ |
| 4035 | 3749 | \\export fn entry() usize { return @sizeOf(@typeOf(f)); } |
| 4036 | | , |
| 3750 | , &[_][]const u8{ |
| 4037 | 3751 | "tmp.zig:20:34: error: expected 1 arguments, found 0", |
| 4038 | | ); |
| 3752 | }); |
| 4039 | 3753 | |
| 4040 | | cases.add( |
| 4041 | | "missing function name", |
| 3754 | cases.add("missing function name", |
| 4042 | 3755 | \\fn () void {} |
| 4043 | 3756 | \\export fn entry() usize { return @sizeOf(@typeOf(f)); } |
| 4044 | | , |
| 3757 | , &[_][]const u8{ |
| 4045 | 3758 | "tmp.zig:1:1: error: missing function name", |
| 4046 | | ); |
| 3759 | }); |
| 4047 | 3760 | |
| 4048 | | cases.add( |
| 4049 | | "missing param name", |
| 3761 | cases.add("missing param name", |
| 4050 | 3762 | \\fn f(i32) void {} |
| 4051 | 3763 | \\export fn entry() usize { return @sizeOf(@typeOf(f)); } |
| 4052 | | , |
| 3764 | , &[_][]const u8{ |
| 4053 | 3765 | "tmp.zig:1:6: error: missing parameter name", |
| 4054 | | ); |
| 3766 | }); |
| 4055 | 3767 | |
| 4056 | | cases.add( |
| 4057 | | "wrong function type", |
| 3768 | cases.add("wrong function type", |
| 4058 | 3769 | \\const fns = [_]fn() void { a, b, c }; |
| 4059 | 3770 | \\fn a() i32 {return 0;} |
| 4060 | 3771 | \\fn b() i32 {return 1;} |
| 4061 | 3772 | \\fn c() i32 {return 2;} |
| 4062 | 3773 | \\export fn entry() usize { return @sizeOf(@typeOf(fns)); } |
| 4063 | | , |
| 3774 | , &[_][]const u8{ |
| 4064 | 3775 | "tmp.zig:1:28: error: expected type 'fn() void', found 'fn() i32'", |
| 4065 | | ); |
| 3776 | }); |
| 4066 | 3777 | |
| 4067 | | cases.add( |
| 4068 | | "extern function pointer mismatch", |
| 3778 | cases.add("extern function pointer mismatch", |
| 4069 | 3779 | \\const fns = [_](fn(i32)i32) { a, b, c }; |
| 4070 | 3780 | \\pub fn a(x: i32) i32 {return x + 0;} |
| 4071 | 3781 | \\pub fn b(x: i32) i32 {return x + 1;} |
| 4072 | 3782 | \\export fn c(x: i32) i32 {return x + 2;} |
| 4073 | 3783 | \\ |
| 4074 | 3784 | \\export fn entry() usize { return @sizeOf(@typeOf(fns)); } |
| 4075 | | , |
| 3785 | , &[_][]const u8{ |
| 4076 | 3786 | "tmp.zig:1:37: error: expected type 'fn(i32) i32', found 'extern fn(i32) i32'", |
| 4077 | | ); |
| 3787 | }); |
| 4078 | 3788 | |
| 4079 | | cases.add( |
| 4080 | | "colliding invalid top level functions", |
| 3789 | cases.add("colliding invalid top level functions", |
| 4081 | 3790 | \\fn func() bogus {} |
| 4082 | 3791 | \\fn func() bogus {} |
| 4083 | 3792 | \\export fn entry() usize { return @sizeOf(@typeOf(func)); } |
| 4084 | | , |
| 3793 | , &[_][]const u8{ |
| 4085 | 3794 | "tmp.zig:2:1: error: redefinition of 'func'", |
| 4086 | | ); |
| 3795 | }); |
| 4087 | 3796 | |
| 4088 | | cases.add( |
| 4089 | | "non constant expression in array size", |
| 3797 | cases.add("non constant expression in array size", |
| 4090 | 3798 | \\const Foo = struct { |
| 4091 | 3799 | \\ y: [get()]u8, |
| 4092 | 3800 | \\}; |
| ... | ... | @@ -4094,25 +3802,23 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4094 | 3802 | \\fn get() usize { return global_var; } |
| 4095 | 3803 | \\ |
| 4096 | 3804 | \\export fn entry() usize { return @sizeOf(@typeOf(Foo)); } |
| 4097 | | , |
| 3805 | , &[_][]const u8{ |
| 4098 | 3806 | "tmp.zig:5:25: error: unable to evaluate constant expression", |
| 4099 | 3807 | "tmp.zig:2:12: note: referenced here", |
| 4100 | | ); |
| 3808 | }); |
| 4101 | 3809 | |
| 4102 | | cases.add( |
| 4103 | | "addition with non numbers", |
| 3810 | cases.add("addition with non numbers", |
| 4104 | 3811 | \\const Foo = struct { |
| 4105 | 3812 | \\ field: i32, |
| 4106 | 3813 | \\}; |
| 4107 | 3814 | \\const x = Foo {.field = 1} + Foo {.field = 2}; |
| 4108 | 3815 | \\ |
| 4109 | 3816 | \\export fn entry() usize { return @sizeOf(@typeOf(x)); } |
| 4110 | | , |
| 3817 | , &[_][]const u8{ |
| 4111 | 3818 | "tmp.zig:4:28: error: invalid operands to binary expression: 'Foo' and 'Foo'", |
| 4112 | | ); |
| 3819 | }); |
| 4113 | 3820 | |
| 4114 | | cases.add( |
| 4115 | | "division by zero", |
| 3821 | cases.add("division by zero", |
| 4116 | 3822 | \\const lit_int_x = 1 / 0; |
| 4117 | 3823 | \\const lit_float_x = 1.0 / 0.0; |
| 4118 | 3824 | \\const int_x = @as(u32, 1) / @as(u32, 0); |
| ... | ... | @@ -4122,522 +3828,471 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4122 | 3828 | \\export fn entry2() usize { return @sizeOf(@typeOf(lit_float_x)); } |
| 4123 | 3829 | \\export fn entry3() usize { return @sizeOf(@typeOf(int_x)); } |
| 4124 | 3830 | \\export fn entry4() usize { return @sizeOf(@typeOf(float_x)); } |
| 4125 | | , |
| 3831 | , &[_][]const u8{ |
| 4126 | 3832 | "tmp.zig:1:21: error: division by zero", |
| 4127 | 3833 | "tmp.zig:2:25: error: division by zero", |
| 4128 | 3834 | "tmp.zig:3:27: error: division by zero", |
| 4129 | 3835 | "tmp.zig:4:31: error: division by zero", |
| 4130 | | ); |
| 3836 | }); |
| 4131 | 3837 | |
| 4132 | | cases.add( |
| 4133 | | "normal string with newline", |
| 3838 | cases.add("normal string with newline", |
| 4134 | 3839 | \\const foo = "a |
| 4135 | 3840 | \\b"; |
| 4136 | 3841 | \\ |
| 4137 | 3842 | \\export fn entry() usize { return @sizeOf(@typeOf(foo)); } |
| 4138 | | , |
| 3843 | , &[_][]const u8{ |
| 4139 | 3844 | "tmp.zig:1:15: error: newline not allowed in string literal", |
| 4140 | | ); |
| 3845 | }); |
| 4141 | 3846 | |
| 4142 | | cases.add( |
| 4143 | | "invalid comparison for function pointers", |
| 3847 | cases.add("invalid comparison for function pointers", |
| 4144 | 3848 | \\fn foo() void {} |
| 4145 | 3849 | \\const invalid = foo > foo; |
| 4146 | 3850 | \\ |
| 4147 | 3851 | \\export fn entry() usize { return @sizeOf(@typeOf(invalid)); } |
| 4148 | | , |
| 3852 | , &[_][]const u8{ |
| 4149 | 3853 | "tmp.zig:2:21: error: operator not allowed for type 'fn() void'", |
| 4150 | | ); |
| 3854 | }); |
| 4151 | 3855 | |
| 4152 | | cases.add( |
| 4153 | | "generic function instance with non-constant expression", |
| 3856 | cases.add("generic function instance with non-constant expression", |
| 4154 | 3857 | \\fn foo(comptime x: i32, y: i32) i32 { return x + y; } |
| 4155 | 3858 | \\fn test1(a: i32, b: i32) i32 { |
| 4156 | 3859 | \\ return foo(a, b); |
| 4157 | 3860 | \\} |
| 4158 | 3861 | \\ |
| 4159 | 3862 | \\export fn entry() usize { return @sizeOf(@typeOf(test1)); } |
| 4160 | | , |
| 3863 | , &[_][]const u8{ |
| 4161 | 3864 | "tmp.zig:3:16: error: unable to evaluate constant expression", |
| 4162 | | ); |
| 3865 | }); |
| 4163 | 3866 | |
| 4164 | | cases.add( |
| 4165 | | "assign null to non-optional pointer", |
| 3867 | cases.add("assign null to non-optional pointer", |
| 4166 | 3868 | \\const a: *u8 = null; |
| 4167 | 3869 | \\ |
| 4168 | 3870 | \\export fn entry() usize { return @sizeOf(@typeOf(a)); } |
| 4169 | | , |
| 3871 | , &[_][]const u8{ |
| 4170 | 3872 | "tmp.zig:1:16: error: expected type '*u8', found '(null)'", |
| 4171 | | ); |
| 3873 | }); |
| 4172 | 3874 | |
| 4173 | | cases.add( |
| 4174 | | "indexing an array of size zero", |
| 3875 | cases.add("indexing an array of size zero", |
| 4175 | 3876 | \\const array = [_]u8{}; |
| 4176 | 3877 | \\export fn foo() void { |
| 4177 | 3878 | \\ const pointer = &array[0]; |
| 4178 | 3879 | \\} |
| 4179 | | , |
| 3880 | , &[_][]const u8{ |
| 4180 | 3881 | "tmp.zig:3:27: error: index 0 outside array of size 0", |
| 4181 | | ); |
| 3882 | }); |
| 4182 | 3883 | |
| 4183 | | cases.add( |
| 4184 | | "compile time division by zero", |
| 3884 | cases.add("compile time division by zero", |
| 4185 | 3885 | \\const y = foo(0); |
| 4186 | 3886 | \\fn foo(x: u32) u32 { |
| 4187 | 3887 | \\ return 1 / x; |
| 4188 | 3888 | \\} |
| 4189 | 3889 | \\ |
| 4190 | 3890 | \\export fn entry() usize { return @sizeOf(@typeOf(y)); } |
| 4191 | | , |
| 3891 | , &[_][]const u8{ |
| 4192 | 3892 | "tmp.zig:3:14: error: division by zero", |
| 4193 | 3893 | "tmp.zig:1:14: note: referenced here", |
| 4194 | | ); |
| 3894 | }); |
| 4195 | 3895 | |
| 4196 | | cases.add( |
| 4197 | | "branch on undefined value", |
| 3896 | cases.add("branch on undefined value", |
| 4198 | 3897 | \\const x = if (undefined) true else false; |
| 4199 | 3898 | \\ |
| 4200 | 3899 | \\export fn entry() usize { return @sizeOf(@typeOf(x)); } |
| 4201 | | , |
| 3900 | , &[_][]const u8{ |
| 4202 | 3901 | "tmp.zig:1:15: error: use of undefined value here causes undefined behavior", |
| 4203 | | ); |
| 3902 | }); |
| 4204 | 3903 | |
| 4205 | | cases.add( |
| 4206 | | "div on undefined value", |
| 3904 | cases.add("div on undefined value", |
| 4207 | 3905 | \\comptime { |
| 4208 | 3906 | \\ var a: i64 = undefined; |
| 4209 | 3907 | \\ _ = a / a; |
| 4210 | 3908 | \\} |
| 4211 | | , |
| 3909 | , &[_][]const u8{ |
| 4212 | 3910 | "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", |
| 4213 | | ); |
| 3911 | }); |
| 4214 | 3912 | |
| 4215 | | cases.add( |
| 4216 | | "div assign on undefined value", |
| 3913 | cases.add("div assign on undefined value", |
| 4217 | 3914 | \\comptime { |
| 4218 | 3915 | \\ var a: i64 = undefined; |
| 4219 | 3916 | \\ a /= a; |
| 4220 | 3917 | \\} |
| 4221 | | , |
| 3918 | , &[_][]const u8{ |
| 4222 | 3919 | "tmp.zig:3:5: error: use of undefined value here causes undefined behavior", |
| 4223 | | ); |
| 3920 | }); |
| 4224 | 3921 | |
| 4225 | | cases.add( |
| 4226 | | "mod on undefined value", |
| 3922 | cases.add("mod on undefined value", |
| 4227 | 3923 | \\comptime { |
| 4228 | 3924 | \\ var a: i64 = undefined; |
| 4229 | 3925 | \\ _ = a % a; |
| 4230 | 3926 | \\} |
| 4231 | | , |
| 3927 | , &[_][]const u8{ |
| 4232 | 3928 | "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", |
| 4233 | | ); |
| 3929 | }); |
| 4234 | 3930 | |
| 4235 | | cases.add( |
| 4236 | | "mod assign on undefined value", |
| 3931 | cases.add("mod assign on undefined value", |
| 4237 | 3932 | \\comptime { |
| 4238 | 3933 | \\ var a: i64 = undefined; |
| 4239 | 3934 | \\ a %= a; |
| 4240 | 3935 | \\} |
| 4241 | | , |
| 3936 | , &[_][]const u8{ |
| 4242 | 3937 | "tmp.zig:3:5: error: use of undefined value here causes undefined behavior", |
| 4243 | | ); |
| 3938 | }); |
| 4244 | 3939 | |
| 4245 | | cases.add( |
| 4246 | | "add on undefined value", |
| 3940 | cases.add("add on undefined value", |
| 4247 | 3941 | \\comptime { |
| 4248 | 3942 | \\ var a: i64 = undefined; |
| 4249 | 3943 | \\ _ = a + a; |
| 4250 | 3944 | \\} |
| 4251 | | , |
| 3945 | , &[_][]const u8{ |
| 4252 | 3946 | "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", |
| 4253 | | ); |
| 3947 | }); |
| 4254 | 3948 | |
| 4255 | | cases.add( |
| 4256 | | "add assign on undefined value", |
| 3949 | cases.add("add assign on undefined value", |
| 4257 | 3950 | \\comptime { |
| 4258 | 3951 | \\ var a: i64 = undefined; |
| 4259 | 3952 | \\ a += a; |
| 4260 | 3953 | \\} |
| 4261 | | , |
| 3954 | , &[_][]const u8{ |
| 4262 | 3955 | "tmp.zig:3:5: error: use of undefined value here causes undefined behavior", |
| 4263 | | ); |
| 3956 | }); |
| 4264 | 3957 | |
| 4265 | | cases.add( |
| 4266 | | "add wrap on undefined value", |
| 3958 | cases.add("add wrap on undefined value", |
| 4267 | 3959 | \\comptime { |
| 4268 | 3960 | \\ var a: i64 = undefined; |
| 4269 | 3961 | \\ _ = a +% a; |
| 4270 | 3962 | \\} |
| 4271 | | , |
| 3963 | , &[_][]const u8{ |
| 4272 | 3964 | "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", |
| 4273 | | ); |
| 3965 | }); |
| 4274 | 3966 | |
| 4275 | | cases.add( |
| 4276 | | "add wrap assign on undefined value", |
| 3967 | cases.add("add wrap assign on undefined value", |
| 4277 | 3968 | \\comptime { |
| 4278 | 3969 | \\ var a: i64 = undefined; |
| 4279 | 3970 | \\ a +%= a; |
| 4280 | 3971 | \\} |
| 4281 | | , |
| 3972 | , &[_][]const u8{ |
| 4282 | 3973 | "tmp.zig:3:5: error: use of undefined value here causes undefined behavior", |
| 4283 | | ); |
| 3974 | }); |
| 4284 | 3975 | |
| 4285 | | cases.add( |
| 4286 | | "sub on undefined value", |
| 3976 | cases.add("sub on undefined value", |
| 4287 | 3977 | \\comptime { |
| 4288 | 3978 | \\ var a: i64 = undefined; |
| 4289 | 3979 | \\ _ = a - a; |
| 4290 | 3980 | \\} |
| 4291 | | , |
| 3981 | , &[_][]const u8{ |
| 4292 | 3982 | "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", |
| 4293 | | ); |
| 3983 | }); |
| 4294 | 3984 | |
| 4295 | | cases.add( |
| 4296 | | "sub assign on undefined value", |
| 3985 | cases.add("sub assign on undefined value", |
| 4297 | 3986 | \\comptime { |
| 4298 | 3987 | \\ var a: i64 = undefined; |
| 4299 | 3988 | \\ a -= a; |
| 4300 | 3989 | \\} |
| 4301 | | , |
| 3990 | , &[_][]const u8{ |
| 4302 | 3991 | "tmp.zig:3:5: error: use of undefined value here causes undefined behavior", |
| 4303 | | ); |
| 3992 | }); |
| 4304 | 3993 | |
| 4305 | | cases.add( |
| 4306 | | "sub wrap on undefined value", |
| 3994 | cases.add("sub wrap on undefined value", |
| 4307 | 3995 | \\comptime { |
| 4308 | 3996 | \\ var a: i64 = undefined; |
| 4309 | 3997 | \\ _ = a -% a; |
| 4310 | 3998 | \\} |
| 4311 | | , |
| 3999 | , &[_][]const u8{ |
| 4312 | 4000 | "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", |
| 4313 | | ); |
| 4001 | }); |
| 4314 | 4002 | |
| 4315 | | cases.add( |
| 4316 | | "sub wrap assign on undefined value", |
| 4003 | cases.add("sub wrap assign on undefined value", |
| 4317 | 4004 | \\comptime { |
| 4318 | 4005 | \\ var a: i64 = undefined; |
| 4319 | 4006 | \\ a -%= a; |
| 4320 | 4007 | \\} |
| 4321 | | , |
| 4008 | , &[_][]const u8{ |
| 4322 | 4009 | "tmp.zig:3:5: error: use of undefined value here causes undefined behavior", |
| 4323 | | ); |
| 4010 | }); |
| 4324 | 4011 | |
| 4325 | | cases.add( |
| 4326 | | "mult on undefined value", |
| 4012 | cases.add("mult on undefined value", |
| 4327 | 4013 | \\comptime { |
| 4328 | 4014 | \\ var a: i64 = undefined; |
| 4329 | 4015 | \\ _ = a * a; |
| 4330 | 4016 | \\} |
| 4331 | | , |
| 4017 | , &[_][]const u8{ |
| 4332 | 4018 | "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", |
| 4333 | | ); |
| 4019 | }); |
| 4334 | 4020 | |
| 4335 | | cases.add( |
| 4336 | | "mult assign on undefined value", |
| 4021 | cases.add("mult assign on undefined value", |
| 4337 | 4022 | \\comptime { |
| 4338 | 4023 | \\ var a: i64 = undefined; |
| 4339 | 4024 | \\ a *= a; |
| 4340 | 4025 | \\} |
| 4341 | | , |
| 4026 | , &[_][]const u8{ |
| 4342 | 4027 | "tmp.zig:3:5: error: use of undefined value here causes undefined behavior", |
| 4343 | | ); |
| 4028 | }); |
| 4344 | 4029 | |
| 4345 | | cases.add( |
| 4346 | | "mult wrap on undefined value", |
| 4030 | cases.add("mult wrap on undefined value", |
| 4347 | 4031 | \\comptime { |
| 4348 | 4032 | \\ var a: i64 = undefined; |
| 4349 | 4033 | \\ _ = a *% a; |
| 4350 | 4034 | \\} |
| 4351 | | , |
| 4035 | , &[_][]const u8{ |
| 4352 | 4036 | "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", |
| 4353 | | ); |
| 4037 | }); |
| 4354 | 4038 | |
| 4355 | | cases.add( |
| 4356 | | "mult wrap assign on undefined value", |
| 4039 | cases.add("mult wrap assign on undefined value", |
| 4357 | 4040 | \\comptime { |
| 4358 | 4041 | \\ var a: i64 = undefined; |
| 4359 | 4042 | \\ a *%= a; |
| 4360 | 4043 | \\} |
| 4361 | | , |
| 4044 | , &[_][]const u8{ |
| 4362 | 4045 | "tmp.zig:3:5: error: use of undefined value here causes undefined behavior", |
| 4363 | | ); |
| 4046 | }); |
| 4364 | 4047 | |
| 4365 | | cases.add( |
| 4366 | | "shift left on undefined value", |
| 4048 | cases.add("shift left on undefined value", |
| 4367 | 4049 | \\comptime { |
| 4368 | 4050 | \\ var a: i64 = undefined; |
| 4369 | 4051 | \\ _ = a << 2; |
| 4370 | 4052 | \\} |
| 4371 | | , |
| 4053 | , &[_][]const u8{ |
| 4372 | 4054 | "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", |
| 4373 | | ); |
| 4055 | }); |
| 4374 | 4056 | |
| 4375 | | cases.add( |
| 4376 | | "shift left assign on undefined value", |
| 4057 | cases.add("shift left assign on undefined value", |
| 4377 | 4058 | \\comptime { |
| 4378 | 4059 | \\ var a: i64 = undefined; |
| 4379 | 4060 | \\ a <<= 2; |
| 4380 | 4061 | \\} |
| 4381 | | , |
| 4062 | , &[_][]const u8{ |
| 4382 | 4063 | "tmp.zig:3:5: error: use of undefined value here causes undefined behavior", |
| 4383 | | ); |
| 4064 | }); |
| 4384 | 4065 | |
| 4385 | | cases.add( |
| 4386 | | "shift right on undefined value", |
| 4066 | cases.add("shift right on undefined value", |
| 4387 | 4067 | \\comptime { |
| 4388 | 4068 | \\ var a: i64 = undefined; |
| 4389 | 4069 | \\ _ = a >> 2; |
| 4390 | 4070 | \\} |
| 4391 | | , |
| 4071 | , &[_][]const u8{ |
| 4392 | 4072 | "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", |
| 4393 | | ); |
| 4073 | }); |
| 4394 | 4074 | |
| 4395 | | cases.add( |
| 4396 | | "shift left assign on undefined value", |
| 4075 | cases.add("shift left assign on undefined value", |
| 4397 | 4076 | \\comptime { |
| 4398 | 4077 | \\ var a: i64 = undefined; |
| 4399 | 4078 | \\ a >>= 2; |
| 4400 | 4079 | \\} |
| 4401 | | , |
| 4080 | , &[_][]const u8{ |
| 4402 | 4081 | "tmp.zig:3:5: error: use of undefined value here causes undefined behavior", |
| 4403 | | ); |
| 4082 | }); |
| 4404 | 4083 | |
| 4405 | | cases.add( |
| 4406 | | "bin and on undefined value", |
| 4084 | cases.add("bin and on undefined value", |
| 4407 | 4085 | \\comptime { |
| 4408 | 4086 | \\ var a: i64 = undefined; |
| 4409 | 4087 | \\ _ = a & a; |
| 4410 | 4088 | \\} |
| 4411 | | , |
| 4089 | , &[_][]const u8{ |
| 4412 | 4090 | "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", |
| 4413 | | ); |
| 4091 | }); |
| 4414 | 4092 | |
| 4415 | | cases.add( |
| 4416 | | "bin and assign on undefined value", |
| 4093 | cases.add("bin and assign on undefined value", |
| 4417 | 4094 | \\comptime { |
| 4418 | 4095 | \\ var a: i64 = undefined; |
| 4419 | 4096 | \\ a &= a; |
| 4420 | 4097 | \\} |
| 4421 | | , |
| 4098 | , &[_][]const u8{ |
| 4422 | 4099 | "tmp.zig:3:5: error: use of undefined value here causes undefined behavior", |
| 4423 | | ); |
| 4100 | }); |
| 4424 | 4101 | |
| 4425 | | cases.add( |
| 4426 | | "bin or on undefined value", |
| 4102 | cases.add("bin or on undefined value", |
| 4427 | 4103 | \\comptime { |
| 4428 | 4104 | \\ var a: i64 = undefined; |
| 4429 | 4105 | \\ _ = a | a; |
| 4430 | 4106 | \\} |
| 4431 | | , |
| 4107 | , &[_][]const u8{ |
| 4432 | 4108 | "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", |
| 4433 | | ); |
| 4109 | }); |
| 4434 | 4110 | |
| 4435 | | cases.add( |
| 4436 | | "bin or assign on undefined value", |
| 4111 | cases.add("bin or assign on undefined value", |
| 4437 | 4112 | \\comptime { |
| 4438 | 4113 | \\ var a: i64 = undefined; |
| 4439 | 4114 | \\ a |= a; |
| 4440 | 4115 | \\} |
| 4441 | | , |
| 4116 | , &[_][]const u8{ |
| 4442 | 4117 | "tmp.zig:3:5: error: use of undefined value here causes undefined behavior", |
| 4443 | | ); |
| 4118 | }); |
| 4444 | 4119 | |
| 4445 | | cases.add( |
| 4446 | | "bin xor on undefined value", |
| 4120 | cases.add("bin xor on undefined value", |
| 4447 | 4121 | \\comptime { |
| 4448 | 4122 | \\ var a: i64 = undefined; |
| 4449 | 4123 | \\ _ = a ^ a; |
| 4450 | 4124 | \\} |
| 4451 | | , |
| 4125 | , &[_][]const u8{ |
| 4452 | 4126 | "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", |
| 4453 | | ); |
| 4127 | }); |
| 4454 | 4128 | |
| 4455 | | cases.add( |
| 4456 | | "bin xor assign on undefined value", |
| 4129 | cases.add("bin xor assign on undefined value", |
| 4457 | 4130 | \\comptime { |
| 4458 | 4131 | \\ var a: i64 = undefined; |
| 4459 | 4132 | \\ a ^= a; |
| 4460 | 4133 | \\} |
| 4461 | | , |
| 4134 | , &[_][]const u8{ |
| 4462 | 4135 | "tmp.zig:3:5: error: use of undefined value here causes undefined behavior", |
| 4463 | | ); |
| 4136 | }); |
| 4464 | 4137 | |
| 4465 | | cases.add( |
| 4466 | | "equal on undefined value", |
| 4138 | cases.add("equal on undefined value", |
| 4467 | 4139 | \\comptime { |
| 4468 | 4140 | \\ var a: i64 = undefined; |
| 4469 | 4141 | \\ _ = a == a; |
| 4470 | 4142 | \\} |
| 4471 | | , |
| 4143 | , &[_][]const u8{ |
| 4472 | 4144 | "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", |
| 4473 | | ); |
| 4145 | }); |
| 4474 | 4146 | |
| 4475 | | cases.add( |
| 4476 | | "not equal on undefined value", |
| 4147 | cases.add("not equal on undefined value", |
| 4477 | 4148 | \\comptime { |
| 4478 | 4149 | \\ var a: i64 = undefined; |
| 4479 | 4150 | \\ _ = a != a; |
| 4480 | 4151 | \\} |
| 4481 | | , |
| 4152 | , &[_][]const u8{ |
| 4482 | 4153 | "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", |
| 4483 | | ); |
| 4154 | }); |
| 4484 | 4155 | |
| 4485 | | cases.add( |
| 4486 | | "greater than on undefined value", |
| 4156 | cases.add("greater than on undefined value", |
| 4487 | 4157 | \\comptime { |
| 4488 | 4158 | \\ var a: i64 = undefined; |
| 4489 | 4159 | \\ _ = a > a; |
| 4490 | 4160 | \\} |
| 4491 | | , |
| 4161 | , &[_][]const u8{ |
| 4492 | 4162 | "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", |
| 4493 | | ); |
| 4163 | }); |
| 4494 | 4164 | |
| 4495 | | cases.add( |
| 4496 | | "greater than equal on undefined value", |
| 4165 | cases.add("greater than equal on undefined value", |
| 4497 | 4166 | \\comptime { |
| 4498 | 4167 | \\ var a: i64 = undefined; |
| 4499 | 4168 | \\ _ = a >= a; |
| 4500 | 4169 | \\} |
| 4501 | | , |
| 4170 | , &[_][]const u8{ |
| 4502 | 4171 | "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", |
| 4503 | | ); |
| 4172 | }); |
| 4504 | 4173 | |
| 4505 | | cases.add( |
| 4506 | | "less than on undefined value", |
| 4174 | cases.add("less than on undefined value", |
| 4507 | 4175 | \\comptime { |
| 4508 | 4176 | \\ var a: i64 = undefined; |
| 4509 | 4177 | \\ _ = a < a; |
| 4510 | 4178 | \\} |
| 4511 | | , |
| 4179 | , &[_][]const u8{ |
| 4512 | 4180 | "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", |
| 4513 | | ); |
| 4181 | }); |
| 4514 | 4182 | |
| 4515 | | cases.add( |
| 4516 | | "less than equal on undefined value", |
| 4183 | cases.add("less than equal on undefined value", |
| 4517 | 4184 | \\comptime { |
| 4518 | 4185 | \\ var a: i64 = undefined; |
| 4519 | 4186 | \\ _ = a <= a; |
| 4520 | 4187 | \\} |
| 4521 | | , |
| 4188 | , &[_][]const u8{ |
| 4522 | 4189 | "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", |
| 4523 | | ); |
| 4190 | }); |
| 4524 | 4191 | |
| 4525 | | cases.add( |
| 4526 | | "and on undefined value", |
| 4192 | cases.add("and on undefined value", |
| 4527 | 4193 | \\comptime { |
| 4528 | 4194 | \\ var a: bool = undefined; |
| 4529 | 4195 | \\ _ = a and a; |
| 4530 | 4196 | \\} |
| 4531 | | , |
| 4197 | , &[_][]const u8{ |
| 4532 | 4198 | "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", |
| 4533 | | ); |
| 4199 | }); |
| 4534 | 4200 | |
| 4535 | | cases.add( |
| 4536 | | "or on undefined value", |
| 4201 | cases.add("or on undefined value", |
| 4537 | 4202 | \\comptime { |
| 4538 | 4203 | \\ var a: bool = undefined; |
| 4539 | 4204 | \\ _ = a or a; |
| 4540 | 4205 | \\} |
| 4541 | | , |
| 4206 | , &[_][]const u8{ |
| 4542 | 4207 | "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", |
| 4543 | | ); |
| 4208 | }); |
| 4544 | 4209 | |
| 4545 | | cases.add( |
| 4546 | | "negate on undefined value", |
| 4210 | cases.add("negate on undefined value", |
| 4547 | 4211 | \\comptime { |
| 4548 | 4212 | \\ var a: i64 = undefined; |
| 4549 | 4213 | \\ _ = -a; |
| 4550 | 4214 | \\} |
| 4551 | | , |
| 4215 | , &[_][]const u8{ |
| 4552 | 4216 | "tmp.zig:3:10: error: use of undefined value here causes undefined behavior", |
| 4553 | | ); |
| 4217 | }); |
| 4554 | 4218 | |
| 4555 | | cases.add( |
| 4556 | | "negate wrap on undefined value", |
| 4219 | cases.add("negate wrap on undefined value", |
| 4557 | 4220 | \\comptime { |
| 4558 | 4221 | \\ var a: i64 = undefined; |
| 4559 | 4222 | \\ _ = -%a; |
| 4560 | 4223 | \\} |
| 4561 | | , |
| 4224 | , &[_][]const u8{ |
| 4562 | 4225 | "tmp.zig:3:11: error: use of undefined value here causes undefined behavior", |
| 4563 | | ); |
| 4226 | }); |
| 4564 | 4227 | |
| 4565 | | cases.add( |
| 4566 | | "bin not on undefined value", |
| 4228 | cases.add("bin not on undefined value", |
| 4567 | 4229 | \\comptime { |
| 4568 | 4230 | \\ var a: i64 = undefined; |
| 4569 | 4231 | \\ _ = ~a; |
| 4570 | 4232 | \\} |
| 4571 | | , |
| 4233 | , &[_][]const u8{ |
| 4572 | 4234 | "tmp.zig:3:10: error: use of undefined value here causes undefined behavior", |
| 4573 | | ); |
| 4235 | }); |
| 4574 | 4236 | |
| 4575 | | cases.add( |
| 4576 | | "bool not on undefined value", |
| 4237 | cases.add("bool not on undefined value", |
| 4577 | 4238 | \\comptime { |
| 4578 | 4239 | \\ var a: bool = undefined; |
| 4579 | 4240 | \\ _ = !a; |
| 4580 | 4241 | \\} |
| 4581 | | , |
| 4242 | , &[_][]const u8{ |
| 4582 | 4243 | "tmp.zig:3:10: error: use of undefined value here causes undefined behavior", |
| 4583 | | ); |
| 4244 | }); |
| 4584 | 4245 | |
| 4585 | | cases.add( |
| 4586 | | "orelse on undefined value", |
| 4246 | cases.add("orelse on undefined value", |
| 4587 | 4247 | \\comptime { |
| 4588 | 4248 | \\ var a: ?bool = undefined; |
| 4589 | 4249 | \\ _ = a orelse false; |
| 4590 | 4250 | \\} |
| 4591 | | , |
| 4251 | , &[_][]const u8{ |
| 4592 | 4252 | "tmp.zig:3:11: error: use of undefined value here causes undefined behavior", |
| 4593 | | ); |
| 4253 | }); |
| 4594 | 4254 | |
| 4595 | | cases.add( |
| 4596 | | "catch on undefined value", |
| 4255 | cases.add("catch on undefined value", |
| 4597 | 4256 | \\comptime { |
| 4598 | 4257 | \\ var a: anyerror!bool = undefined; |
| 4599 | 4258 | \\ _ = a catch |err| false; |
| 4600 | 4259 | \\} |
| 4601 | | , |
| 4260 | , &[_][]const u8{ |
| 4602 | 4261 | "tmp.zig:3:11: error: use of undefined value here causes undefined behavior", |
| 4603 | | ); |
| 4262 | }); |
| 4604 | 4263 | |
| 4605 | | cases.add( |
| 4606 | | "deref on undefined value", |
| 4264 | cases.add("deref on undefined value", |
| 4607 | 4265 | \\comptime { |
| 4608 | 4266 | \\ var a: *u8 = undefined; |
| 4609 | 4267 | \\ _ = a.*; |
| 4610 | 4268 | \\} |
| 4611 | | , |
| 4269 | , &[_][]const u8{ |
| 4612 | 4270 | "tmp.zig:3:9: error: attempt to dereference undefined value", |
| 4613 | | ); |
| 4271 | }); |
| 4614 | 4272 | |
| 4615 | | cases.add( |
| 4616 | | "endless loop in function evaluation", |
| 4273 | cases.add("endless loop in function evaluation", |
| 4617 | 4274 | \\const seventh_fib_number = fibbonaci(7); |
| 4618 | 4275 | \\fn fibbonaci(x: i32) i32 { |
| 4619 | 4276 | \\ return fibbonaci(x - 1) + fibbonaci(x - 2); |
| 4620 | 4277 | \\} |
| 4621 | 4278 | \\ |
| 4622 | 4279 | \\export fn entry() usize { return @sizeOf(@typeOf(seventh_fib_number)); } |
| 4623 | | , |
| 4280 | , &[_][]const u8{ |
| 4624 | 4281 | "tmp.zig:3:21: error: evaluation exceeded 1000 backwards branches", |
| 4625 | 4282 | "tmp.zig:1:37: note: referenced here", |
| 4626 | 4283 | "tmp.zig:6:50: note: referenced here", |
| 4627 | | ); |
| 4284 | }); |
| 4628 | 4285 | |
| 4629 | | cases.add( |
| 4630 | | "@embedFile with bogus file", |
| 4286 | cases.add("@embedFile with bogus file", |
| 4631 | 4287 | \\const resource = @embedFile("bogus.txt",); |
| 4632 | 4288 | \\ |
| 4633 | 4289 | \\export fn entry() usize { return @sizeOf(@typeOf(resource)); } |
| 4634 | | , |
| 4290 | , &[_][]const u8{ |
| 4635 | 4291 | "tmp.zig:1:29: error: unable to find '", |
| 4636 | 4292 | "bogus.txt'", |
| 4637 | | ); |
| 4293 | }); |
| 4638 | 4294 | |
| 4639 | | cases.add( |
| 4640 | | "non-const expression in struct literal outside function", |
| 4295 | cases.add("non-const expression in struct literal outside function", |
| 4641 | 4296 | \\const Foo = struct { |
| 4642 | 4297 | \\ x: i32, |
| 4643 | 4298 | \\}; |
| ... | ... | @@ -4645,12 +4300,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4645 | 4300 | \\extern fn get_it() i32; |
| 4646 | 4301 | \\ |
| 4647 | 4302 | \\export fn entry() usize { return @sizeOf(@typeOf(a)); } |
| 4648 | | , |
| 4303 | , &[_][]const u8{ |
| 4649 | 4304 | "tmp.zig:4:21: error: unable to evaluate constant expression", |
| 4650 | | ); |
| 4305 | }); |
| 4651 | 4306 | |
| 4652 | | cases.add( |
| 4653 | | "non-const expression function call with struct return value outside function", |
| 4307 | cases.add("non-const expression function call with struct return value outside function", |
| 4654 | 4308 | \\const Foo = struct { |
| 4655 | 4309 | \\ x: i32, |
| 4656 | 4310 | \\}; |
| ... | ... | @@ -4662,25 +4316,23 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4662 | 4316 | \\var global_side_effect = false; |
| 4663 | 4317 | \\ |
| 4664 | 4318 | \\export fn entry() usize { return @sizeOf(@typeOf(a)); } |
| 4665 | | , |
| 4319 | , &[_][]const u8{ |
| 4666 | 4320 | "tmp.zig:6:26: error: unable to evaluate constant expression", |
| 4667 | 4321 | "tmp.zig:4:17: note: referenced here", |
| 4668 | | ); |
| 4322 | }); |
| 4669 | 4323 | |
| 4670 | | cases.add( |
| 4671 | | "undeclared identifier error should mark fn as impure", |
| 4324 | cases.add("undeclared identifier error should mark fn as impure", |
| 4672 | 4325 | \\export fn foo() void { |
| 4673 | 4326 | \\ test_a_thing(); |
| 4674 | 4327 | \\} |
| 4675 | 4328 | \\fn test_a_thing() void { |
| 4676 | 4329 | \\ bad_fn_call(); |
| 4677 | 4330 | \\} |
| 4678 | | , |
| 4331 | , &[_][]const u8{ |
| 4679 | 4332 | "tmp.zig:5:5: error: use of undeclared identifier 'bad_fn_call'", |
| 4680 | | ); |
| 4333 | }); |
| 4681 | 4334 | |
| 4682 | | cases.add( |
| 4683 | | "illegal comparison of types", |
| 4335 | cases.add("illegal comparison of types", |
| 4684 | 4336 | \\fn bad_eql_1(a: []u8, b: []u8) bool { |
| 4685 | 4337 | \\ return a == b; |
| 4686 | 4338 | \\} |
| ... | ... | @@ -4694,13 +4346,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4694 | 4346 | \\ |
| 4695 | 4347 | \\export fn entry1() usize { return @sizeOf(@typeOf(bad_eql_1)); } |
| 4696 | 4348 | \\export fn entry2() usize { return @sizeOf(@typeOf(bad_eql_2)); } |
| 4697 | | , |
| 4349 | , &[_][]const u8{ |
| 4698 | 4350 | "tmp.zig:2:14: error: operator not allowed for type '[]u8'", |
| 4699 | 4351 | "tmp.zig:9:16: error: operator not allowed for type 'EnumWithData'", |
| 4700 | | ); |
| 4352 | }); |
| 4701 | 4353 | |
| 4702 | | cases.add( |
| 4703 | | "non-const switch number literal", |
| 4354 | cases.add("non-const switch number literal", |
| 4704 | 4355 | \\export fn foo() void { |
| 4705 | 4356 | \\ const x = switch (bar()) { |
| 4706 | 4357 | \\ 1, 2 => 1, |
| ... | ... | @@ -4711,109 +4362,100 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4711 | 4362 | \\fn bar() i32 { |
| 4712 | 4363 | \\ return 2; |
| 4713 | 4364 | \\} |
| 4714 | | , |
| 4365 | , &[_][]const u8{ |
| 4715 | 4366 | "tmp.zig:5:17: error: cannot store runtime value in type 'comptime_int'", |
| 4716 | | ); |
| 4367 | }); |
| 4717 | 4368 | |
| 4718 | | cases.add( |
| 4719 | | "atomic orderings of cmpxchg - failure stricter than success", |
| 4369 | cases.add("atomic orderings of cmpxchg - failure stricter than success", |
| 4720 | 4370 | \\const AtomicOrder = @import("builtin").AtomicOrder; |
| 4721 | 4371 | \\export fn f() void { |
| 4722 | 4372 | \\ var x: i32 = 1234; |
| 4723 | 4373 | \\ while (!@cmpxchgWeak(i32, &x, 1234, 5678, AtomicOrder.Monotonic, AtomicOrder.SeqCst)) {} |
| 4724 | 4374 | \\} |
| 4725 | | , |
| 4375 | , &[_][]const u8{ |
| 4726 | 4376 | "tmp.zig:4:81: error: failure atomic ordering must be no stricter than success", |
| 4727 | | ); |
| 4377 | }); |
| 4728 | 4378 | |
| 4729 | | cases.add( |
| 4730 | | "atomic orderings of cmpxchg - success Monotonic or stricter", |
| 4379 | cases.add("atomic orderings of cmpxchg - success Monotonic or stricter", |
| 4731 | 4380 | \\const AtomicOrder = @import("builtin").AtomicOrder; |
| 4732 | 4381 | \\export fn f() void { |
| 4733 | 4382 | \\ var x: i32 = 1234; |
| 4734 | 4383 | \\ while (!@cmpxchgWeak(i32, &x, 1234, 5678, AtomicOrder.Unordered, AtomicOrder.Unordered)) {} |
| 4735 | 4384 | \\} |
| 4736 | | , |
| 4385 | , &[_][]const u8{ |
| 4737 | 4386 | "tmp.zig:4:58: error: success atomic ordering must be Monotonic or stricter", |
| 4738 | | ); |
| 4387 | }); |
| 4739 | 4388 | |
| 4740 | | cases.add( |
| 4741 | | "negation overflow in function evaluation", |
| 4389 | cases.add("negation overflow in function evaluation", |
| 4742 | 4390 | \\const y = neg(-128); |
| 4743 | 4391 | \\fn neg(x: i8) i8 { |
| 4744 | 4392 | \\ return -x; |
| 4745 | 4393 | \\} |
| 4746 | 4394 | \\ |
| 4747 | 4395 | \\export fn entry() usize { return @sizeOf(@typeOf(y)); } |
| 4748 | | , |
| 4396 | , &[_][]const u8{ |
| 4749 | 4397 | "tmp.zig:3:12: error: negation caused overflow", |
| 4750 | 4398 | "tmp.zig:1:14: note: referenced here", |
| 4751 | | ); |
| 4399 | }); |
| 4752 | 4400 | |
| 4753 | | cases.add( |
| 4754 | | "add overflow in function evaluation", |
| 4401 | cases.add("add overflow in function evaluation", |
| 4755 | 4402 | \\const y = add(65530, 10); |
| 4756 | 4403 | \\fn add(a: u16, b: u16) u16 { |
| 4757 | 4404 | \\ return a + b; |
| 4758 | 4405 | \\} |
| 4759 | 4406 | \\ |
| 4760 | 4407 | \\export fn entry() usize { return @sizeOf(@typeOf(y)); } |
| 4761 | | , |
| 4408 | , &[_][]const u8{ |
| 4762 | 4409 | "tmp.zig:3:14: error: operation caused overflow", |
| 4763 | 4410 | "tmp.zig:1:14: note: referenced here", |
| 4764 | | ); |
| 4411 | }); |
| 4765 | 4412 | |
| 4766 | | cases.add( |
| 4767 | | "sub overflow in function evaluation", |
| 4413 | cases.add("sub overflow in function evaluation", |
| 4768 | 4414 | \\const y = sub(10, 20); |
| 4769 | 4415 | \\fn sub(a: u16, b: u16) u16 { |
| 4770 | 4416 | \\ return a - b; |
| 4771 | 4417 | \\} |
| 4772 | 4418 | \\ |
| 4773 | 4419 | \\export fn entry() usize { return @sizeOf(@typeOf(y)); } |
| 4774 | | , |
| 4420 | , &[_][]const u8{ |
| 4775 | 4421 | "tmp.zig:3:14: error: operation caused overflow", |
| 4776 | 4422 | "tmp.zig:1:14: note: referenced here", |
| 4777 | | ); |
| 4423 | }); |
| 4778 | 4424 | |
| 4779 | | cases.add( |
| 4780 | | "mul overflow in function evaluation", |
| 4425 | cases.add("mul overflow in function evaluation", |
| 4781 | 4426 | \\const y = mul(300, 6000); |
| 4782 | 4427 | \\fn mul(a: u16, b: u16) u16 { |
| 4783 | 4428 | \\ return a * b; |
| 4784 | 4429 | \\} |
| 4785 | 4430 | \\ |
| 4786 | 4431 | \\export fn entry() usize { return @sizeOf(@typeOf(y)); } |
| 4787 | | , |
| 4432 | , &[_][]const u8{ |
| 4788 | 4433 | "tmp.zig:3:14: error: operation caused overflow", |
| 4789 | 4434 | "tmp.zig:1:14: note: referenced here", |
| 4790 | | ); |
| 4435 | }); |
| 4791 | 4436 | |
| 4792 | | cases.add( |
| 4793 | | "truncate sign mismatch", |
| 4437 | cases.add("truncate sign mismatch", |
| 4794 | 4438 | \\fn f() i8 { |
| 4795 | 4439 | \\ var x: u32 = 10; |
| 4796 | 4440 | \\ return @truncate(i8, x); |
| 4797 | 4441 | \\} |
| 4798 | 4442 | \\ |
| 4799 | 4443 | \\export fn entry() usize { return @sizeOf(@typeOf(f)); } |
| 4800 | | , |
| 4444 | , &[_][]const u8{ |
| 4801 | 4445 | "tmp.zig:3:26: error: expected signed integer type, found 'u32'", |
| 4802 | | ); |
| 4446 | }); |
| 4803 | 4447 | |
| 4804 | | cases.add( |
| 4805 | | "try in function with non error return type", |
| 4448 | cases.add("try in function with non error return type", |
| 4806 | 4449 | \\export fn f() void { |
| 4807 | 4450 | \\ try something(); |
| 4808 | 4451 | \\} |
| 4809 | 4452 | \\fn something() anyerror!void { } |
| 4810 | | , |
| 4453 | , &[_][]const u8{ |
| 4811 | 4454 | "tmp.zig:2:5: error: expected type 'void', found 'anyerror'", |
| 4812 | 4455 | "tmp.zig:1:15: note: return type declared here", |
| 4813 | | ); |
| 4456 | }); |
| 4814 | 4457 | |
| 4815 | | cases.add( |
| 4816 | | "invalid pointer for var type", |
| 4458 | cases.add("invalid pointer for var type", |
| 4817 | 4459 | \\extern fn ext() usize; |
| 4818 | 4460 | \\var bytes: [ext()]u8 = undefined; |
| 4819 | 4461 | \\export fn f() void { |
| ... | ... | @@ -4821,43 +4463,39 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4821 | 4463 | \\ b.* = @as(u8, i); |
| 4822 | 4464 | \\ } |
| 4823 | 4465 | \\} |
| 4824 | | , |
| 4466 | , &[_][]const u8{ |
| 4825 | 4467 | "tmp.zig:2:13: error: unable to evaluate constant expression", |
| 4826 | | ); |
| 4468 | }); |
| 4827 | 4469 | |
| 4828 | | cases.add( |
| 4829 | | "export function with comptime parameter", |
| 4470 | cases.add("export function with comptime parameter", |
| 4830 | 4471 | \\export fn foo(comptime x: i32, y: i32) i32{ |
| 4831 | 4472 | \\ return x + y; |
| 4832 | 4473 | \\} |
| 4833 | | , |
| 4474 | , &[_][]const u8{ |
| 4834 | 4475 | "tmp.zig:1:15: error: comptime parameter not allowed in function with calling convention 'ccc'", |
| 4835 | | ); |
| 4476 | }); |
| 4836 | 4477 | |
| 4837 | | cases.add( |
| 4838 | | "extern function with comptime parameter", |
| 4478 | cases.add("extern function with comptime parameter", |
| 4839 | 4479 | \\extern fn foo(comptime x: i32, y: i32) i32; |
| 4840 | 4480 | \\fn f() i32 { |
| 4841 | 4481 | \\ return foo(1, 2); |
| 4842 | 4482 | \\} |
| 4843 | 4483 | \\export fn entry() usize { return @sizeOf(@typeOf(f)); } |
| 4844 | | , |
| 4484 | , &[_][]const u8{ |
| 4845 | 4485 | "tmp.zig:1:15: error: comptime parameter not allowed in function with calling convention 'ccc'", |
| 4846 | | ); |
| 4486 | }); |
| 4847 | 4487 | |
| 4848 | | cases.add( |
| 4849 | | "convert fixed size array to slice with invalid size", |
| 4488 | cases.add("convert fixed size array to slice with invalid size", |
| 4850 | 4489 | \\export fn f() void { |
| 4851 | 4490 | \\ var array: [5]u8 = undefined; |
| 4852 | 4491 | \\ var foo = @bytesToSlice(u32, &array)[0]; |
| 4853 | 4492 | \\} |
| 4854 | | , |
| 4493 | , &[_][]const u8{ |
| 4855 | 4494 | "tmp.zig:3:15: error: unable to convert [5]u8 to []align(1) u32: size mismatch", |
| 4856 | 4495 | "tmp.zig:3:29: note: u32 has size 4; remaining bytes: 1", |
| 4857 | | ); |
| 4496 | }); |
| 4858 | 4497 | |
| 4859 | | cases.add( |
| 4860 | | "non-pure function returns type", |
| 4498 | cases.add("non-pure function returns type", |
| 4861 | 4499 | \\var a: u32 = 0; |
| 4862 | 4500 | \\pub fn List(comptime T: type) type { |
| 4863 | 4501 | \\ a += 1; |
| ... | ... | @@ -4876,24 +4514,22 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4876 | 4514 | \\ var list: List(i32) = undefined; |
| 4877 | 4515 | \\ list.length = 10; |
| 4878 | 4516 | \\} |
| 4879 | | , |
| 4517 | , &[_][]const u8{ |
| 4880 | 4518 | "tmp.zig:3:7: error: unable to evaluate constant expression", |
| 4881 | 4519 | "tmp.zig:16:19: note: referenced here", |
| 4882 | | ); |
| 4520 | }); |
| 4883 | 4521 | |
| 4884 | | cases.add( |
| 4885 | | "bogus method call on slice", |
| 4522 | cases.add("bogus method call on slice", |
| 4886 | 4523 | \\var self = "aoeu"; |
| 4887 | 4524 | \\fn f(m: []const u8) void { |
| 4888 | 4525 | \\ m.copy(u8, self[0..], m); |
| 4889 | 4526 | \\} |
| 4890 | 4527 | \\export fn entry() usize { return @sizeOf(@typeOf(f)); } |
| 4891 | | , |
| 4528 | , &[_][]const u8{ |
| 4892 | 4529 | "tmp.zig:3:6: error: no member named 'copy' in '[]const u8'", |
| 4893 | | ); |
| 4530 | }); |
| 4894 | 4531 | |
| 4895 | | cases.add( |
| 4896 | | "wrong number of arguments for method fn call", |
| 4532 | cases.add("wrong number of arguments for method fn call", |
| 4897 | 4533 | \\const Foo = struct { |
| 4898 | 4534 | \\ fn method(self: *const Foo, a: i32) void {} |
| 4899 | 4535 | \\}; |
| ... | ... | @@ -4902,39 +4538,35 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4902 | 4538 | \\ foo.method(1, 2); |
| 4903 | 4539 | \\} |
| 4904 | 4540 | \\export fn entry() usize { return @sizeOf(@typeOf(f)); } |
| 4905 | | , |
| 4541 | , &[_][]const u8{ |
| 4906 | 4542 | "tmp.zig:6:15: error: expected 2 arguments, found 3", |
| 4907 | | ); |
| 4543 | }); |
| 4908 | 4544 | |
| 4909 | | cases.add( |
| 4910 | | "assign through constant pointer", |
| 4545 | cases.add("assign through constant pointer", |
| 4911 | 4546 | \\export fn f() void { |
| 4912 | 4547 | \\ var cstr = "Hat"; |
| 4913 | 4548 | \\ cstr[0] = 'W'; |
| 4914 | 4549 | \\} |
| 4915 | | , |
| 4550 | , &[_][]const u8{ |
| 4916 | 4551 | "tmp.zig:3:13: error: cannot assign to constant", |
| 4917 | | ); |
| 4552 | }); |
| 4918 | 4553 | |
| 4919 | | cases.add( |
| 4920 | | "assign through constant slice", |
| 4554 | cases.add("assign through constant slice", |
| 4921 | 4555 | \\export fn f() void { |
| 4922 | 4556 | \\ var cstr: []const u8 = "Hat"; |
| 4923 | 4557 | \\ cstr[0] = 'W'; |
| 4924 | 4558 | \\} |
| 4925 | | , |
| 4559 | , &[_][]const u8{ |
| 4926 | 4560 | "tmp.zig:3:13: error: cannot assign to constant", |
| 4927 | | ); |
| 4561 | }); |
| 4928 | 4562 | |
| 4929 | | cases.add( |
| 4930 | | "main function with bogus args type", |
| 4563 | cases.add("main function with bogus args type", |
| 4931 | 4564 | \\pub fn main(args: [][]bogus) !void {} |
| 4932 | | , |
| 4565 | , &[_][]const u8{ |
| 4933 | 4566 | "tmp.zig:1:23: error: use of undeclared identifier 'bogus'", |
| 4934 | | ); |
| 4567 | }); |
| 4935 | 4568 | |
| 4936 | | cases.add( |
| 4937 | | "misspelled type with pointer only reference", |
| 4569 | cases.add("misspelled type with pointer only reference", |
| 4938 | 4570 | \\const JasonHM = u8; |
| 4939 | 4571 | \\const JasonList = *JsonNode; |
| 4940 | 4572 | \\ |
| ... | ... | @@ -4965,12 +4597,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4965 | 4597 | \\} |
| 4966 | 4598 | \\ |
| 4967 | 4599 | \\export fn entry() usize { return @sizeOf(@typeOf(foo)); } |
| 4968 | | , |
| 4600 | , &[_][]const u8{ |
| 4969 | 4601 | "tmp.zig:5:16: error: use of undeclared identifier 'JsonList'", |
| 4970 | | ); |
| 4602 | }); |
| 4971 | 4603 | |
| 4972 | | cases.add( |
| 4973 | | "method call with first arg type primitive", |
| 4604 | cases.add("method call with first arg type primitive", |
| 4974 | 4605 | \\const Foo = struct { |
| 4975 | 4606 | \\ x: i32, |
| 4976 | 4607 | \\ |
| ... | ... | @@ -4986,12 +4617,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4986 | 4617 | \\ |
| 4987 | 4618 | \\ derp.init(); |
| 4988 | 4619 | \\} |
| 4989 | | , |
| 4620 | , &[_][]const u8{ |
| 4990 | 4621 | "tmp.zig:14:5: error: expected type 'i32', found 'Foo'", |
| 4991 | | ); |
| 4622 | }); |
| 4992 | 4623 | |
| 4993 | | cases.add( |
| 4994 | | "method call with first arg type wrong container", |
| 4624 | cases.add("method call with first arg type wrong container", |
| 4995 | 4625 | \\pub const List = struct { |
| 4996 | 4626 | \\ len: usize, |
| 4997 | 4627 | \\ allocator: *Allocator, |
| ... | ... | @@ -5016,33 +4646,31 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5016 | 4646 | \\ var x = List.init(&global_allocator); |
| 5017 | 4647 | \\ x.init(); |
| 5018 | 4648 | \\} |
| 5019 | | , |
| 4649 | , &[_][]const u8{ |
| 5020 | 4650 | "tmp.zig:23:5: error: expected type '*Allocator', found '*List'", |
| 5021 | | ); |
| 4651 | }); |
| 5022 | 4652 | |
| 5023 | | cases.add( |
| 5024 | | "binary not on number literal", |
| 4653 | cases.add("binary not on number literal", |
| 5025 | 4654 | \\const TINY_QUANTUM_SHIFT = 4; |
| 5026 | 4655 | \\const TINY_QUANTUM_SIZE = 1 << TINY_QUANTUM_SHIFT; |
| 5027 | 4656 | \\var block_aligned_stuff: usize = (4 + TINY_QUANTUM_SIZE) & ~(TINY_QUANTUM_SIZE - 1); |
| 5028 | 4657 | \\ |
| 5029 | 4658 | \\export fn entry() usize { return @sizeOf(@typeOf(block_aligned_stuff)); } |
| 5030 | | , |
| 4659 | , &[_][]const u8{ |
| 5031 | 4660 | "tmp.zig:3:60: error: unable to perform binary not operation on type 'comptime_int'", |
| 5032 | | ); |
| 4661 | }); |
| 5033 | 4662 | |
| 5034 | 4663 | cases.addCase(x: { |
| 5035 | | const tc = cases.create( |
| 5036 | | "multiple files with private function error", |
| 4664 | const tc = cases.create("multiple files with private function error", |
| 5037 | 4665 | \\const foo = @import("foo.zig",); |
| 5038 | 4666 | \\ |
| 5039 | 4667 | \\export fn callPrivFunction() void { |
| 5040 | 4668 | \\ foo.privateFunction(); |
| 5041 | 4669 | \\} |
| 5042 | | , |
| 4670 | , &[_][]const u8{ |
| 5043 | 4671 | "tmp.zig:4:8: error: 'privateFunction' is private", |
| 5044 | 4672 | "foo.zig:1:1: note: declared here", |
| 5045 | | ); |
| 4673 | }); |
| 5046 | 4674 | |
| 5047 | 4675 | tc.addSourceFile("foo.zig", |
| 5048 | 4676 | \\fn privateFunction() void { } |
| ... | ... | @@ -5051,18 +4679,16 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5051 | 4679 | break :x tc; |
| 5052 | 4680 | }); |
| 5053 | 4681 | |
| 5054 | | cases.add( |
| 5055 | | "container init with non-type", |
| 4682 | cases.add("container init with non-type", |
| 5056 | 4683 | \\const zero: i32 = 0; |
| 5057 | 4684 | \\const a = zero{1}; |
| 5058 | 4685 | \\ |
| 5059 | 4686 | \\export fn entry() usize { return @sizeOf(@typeOf(a)); } |
| 5060 | | , |
| 4687 | , &[_][]const u8{ |
| 5061 | 4688 | "tmp.zig:2:11: error: expected type 'type', found 'i32'", |
| 5062 | | ); |
| 4689 | }); |
| 5063 | 4690 | |
| 5064 | | cases.add( |
| 5065 | | "assign to constant field", |
| 4691 | cases.add("assign to constant field", |
| 5066 | 4692 | \\const Foo = struct { |
| 5067 | 4693 | \\ field: i32, |
| 5068 | 4694 | \\}; |
| ... | ... | @@ -5070,12 +4696,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5070 | 4696 | \\ const f = Foo {.field = 1234,}; |
| 5071 | 4697 | \\ f.field = 0; |
| 5072 | 4698 | \\} |
| 5073 | | , |
| 4699 | , &[_][]const u8{ |
| 5074 | 4700 | "tmp.zig:6:15: error: cannot assign to constant", |
| 5075 | | ); |
| 4701 | }); |
| 5076 | 4702 | |
| 5077 | | cases.add( |
| 5078 | | "return from defer expression", |
| 4703 | cases.add("return from defer expression", |
| 5079 | 4704 | \\pub fn testTrickyDefer() !void { |
| 5080 | 4705 | \\ defer canFail() catch {}; |
| 5081 | 4706 | \\ |
| ... | ... | @@ -5091,72 +4716,33 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5091 | 4716 | \\} |
| 5092 | 4717 | \\ |
| 5093 | 4718 | \\export fn entry() usize { return @sizeOf(@typeOf(testTrickyDefer)); } |
| 5094 | | , |
| 4719 | , &[_][]const u8{ |
| 5095 | 4720 | "tmp.zig:4:11: error: cannot return from defer expression", |
| 5096 | | ); |
| 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 | | ); |
| 4721 | }); |
| 5132 | 4722 | |
| 5133 | | cases.add( |
| 5134 | | "assign too big number to u16", |
| 4723 | cases.add("assign too big number to u16", |
| 5135 | 4724 | \\export fn foo() void { |
| 5136 | 4725 | \\ var vga_mem: u16 = 0xB8000; |
| 5137 | 4726 | \\} |
| 5138 | | , |
| 4727 | , &[_][]const u8{ |
| 5139 | 4728 | "tmp.zig:2:24: error: integer value 753664 cannot be coerced to type 'u16'", |
| 5140 | | ); |
| 4729 | }); |
| 5141 | 4730 | |
| 5142 | | cases.add( |
| 5143 | | "global variable alignment non power of 2", |
| 4731 | cases.add("global variable alignment non power of 2", |
| 5144 | 4732 | \\const some_data: [100]u8 align(3) = undefined; |
| 5145 | 4733 | \\export fn entry() usize { return @sizeOf(@typeOf(some_data)); } |
| 5146 | | , |
| 4734 | , &[_][]const u8{ |
| 5147 | 4735 | "tmp.zig:1:32: error: alignment value 3 is not a power of 2", |
| 5148 | | ); |
| 4736 | }); |
| 5149 | 4737 | |
| 5150 | | cases.add( |
| 5151 | | "function alignment non power of 2", |
| 4738 | cases.add("function alignment non power of 2", |
| 5152 | 4739 | \\extern fn foo() align(3) void; |
| 5153 | 4740 | \\export fn entry() void { return foo(); } |
| 5154 | | , |
| 4741 | , &[_][]const u8{ |
| 5155 | 4742 | "tmp.zig:1:23: error: alignment value 3 is not a power of 2", |
| 5156 | | ); |
| 4743 | }); |
| 5157 | 4744 | |
| 5158 | | cases.add( |
| 5159 | | "compile log", |
| 4745 | cases.add("compile log", |
| 5160 | 4746 | \\export fn foo() void { |
| 5161 | 4747 | \\ comptime bar(12, "hi",); |
| 5162 | 4748 | \\} |
| ... | ... | @@ -5165,14 +4751,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5165 | 4751 | \\ @compileLog("a", a, "b", b); |
| 5166 | 4752 | \\ @compileLog("end",); |
| 5167 | 4753 | \\} |
| 5168 | | , |
| 4754 | , &[_][]const u8{ |
| 5169 | 4755 | "tmp.zig:5:5: error: found compile log statement", |
| 5170 | 4756 | "tmp.zig:6:5: error: found compile log statement", |
| 5171 | 4757 | "tmp.zig:7:5: error: found compile log statement", |
| 5172 | | ); |
| 4758 | }); |
| 5173 | 4759 | |
| 5174 | | cases.add( |
| 5175 | | "casting bit offset pointer to regular pointer", |
| 4760 | cases.add("casting bit offset pointer to regular pointer", |
| 5176 | 4761 | \\const BitField = packed struct { |
| 5177 | 4762 | \\ a: u3, |
| 5178 | 4763 | \\ b: u3, |
| ... | ... | @@ -5188,12 +4773,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5188 | 4773 | \\} |
| 5189 | 4774 | \\ |
| 5190 | 4775 | \\export fn entry() usize { return @sizeOf(@typeOf(foo)); } |
| 5191 | | , |
| 4776 | , &[_][]const u8{ |
| 5192 | 4777 | "tmp.zig:8:26: error: expected type '*const u3', found '*align(:3:1) const u3'", |
| 5193 | | ); |
| 4778 | }); |
| 5194 | 4779 | |
| 5195 | | cases.add( |
| 5196 | | "referring to a struct that is invalid", |
| 4780 | cases.add("referring to a struct that is invalid", |
| 5197 | 4781 | \\const UsbDeviceRequest = struct { |
| 5198 | 4782 | \\ Type: u8, |
| 5199 | 4783 | \\}; |
| ... | ... | @@ -5205,13 +4789,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5205 | 4789 | \\fn assert(ok: bool) void { |
| 5206 | 4790 | \\ if (!ok) unreachable; |
| 5207 | 4791 | \\} |
| 5208 | | , |
| 4792 | , &[_][]const u8{ |
| 5209 | 4793 | "tmp.zig:10:14: error: unable to evaluate constant expression", |
| 5210 | 4794 | "tmp.zig:6:20: note: referenced here", |
| 5211 | | ); |
| 4795 | }); |
| 5212 | 4796 | |
| 5213 | | cases.add( |
| 5214 | | "control flow uses comptime var at runtime", |
| 4797 | cases.add("control flow uses comptime var at runtime", |
| 5215 | 4798 | \\export fn foo() void { |
| 5216 | 4799 | \\ comptime var i = 0; |
| 5217 | 4800 | \\ while (i < 5) : (i += 1) { |
| ... | ... | @@ -5220,79 +4803,71 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5220 | 4803 | \\} |
| 5221 | 4804 | \\ |
| 5222 | 4805 | \\fn bar() void { } |
| 5223 | | , |
| 4806 | , &[_][]const u8{ |
| 5224 | 4807 | "tmp.zig:3:5: error: control flow attempts to use compile-time variable at runtime", |
| 5225 | 4808 | "tmp.zig:3:24: note: compile-time variable assigned here", |
| 5226 | | ); |
| 4809 | }); |
| 5227 | 4810 | |
| 5228 | | cases.add( |
| 5229 | | "ignored return value", |
| 4811 | cases.add("ignored return value", |
| 5230 | 4812 | \\export fn foo() void { |
| 5231 | 4813 | \\ bar(); |
| 5232 | 4814 | \\} |
| 5233 | 4815 | \\fn bar() i32 { return 0; } |
| 5234 | | , |
| 4816 | , &[_][]const u8{ |
| 5235 | 4817 | "tmp.zig:2:8: error: expression value is ignored", |
| 5236 | | ); |
| 4818 | }); |
| 5237 | 4819 | |
| 5238 | | cases.add( |
| 5239 | | "ignored assert-err-ok return value", |
| 4820 | cases.add("ignored assert-err-ok return value", |
| 5240 | 4821 | \\export fn foo() void { |
| 5241 | 4822 | \\ bar() catch unreachable; |
| 5242 | 4823 | \\} |
| 5243 | 4824 | \\fn bar() anyerror!i32 { return 0; } |
| 5244 | | , |
| 4825 | , &[_][]const u8{ |
| 5245 | 4826 | "tmp.zig:2:11: error: expression value is ignored", |
| 5246 | | ); |
| 4827 | }); |
| 5247 | 4828 | |
| 5248 | | cases.add( |
| 5249 | | "ignored statement value", |
| 4829 | cases.add("ignored statement value", |
| 5250 | 4830 | \\export fn foo() void { |
| 5251 | 4831 | \\ 1; |
| 5252 | 4832 | \\} |
| 5253 | | , |
| 4833 | , &[_][]const u8{ |
| 5254 | 4834 | "tmp.zig:2:5: error: expression value is ignored", |
| 5255 | | ); |
| 4835 | }); |
| 5256 | 4836 | |
| 5257 | | cases.add( |
| 5258 | | "ignored comptime statement value", |
| 4837 | cases.add("ignored comptime statement value", |
| 5259 | 4838 | \\export fn foo() void { |
| 5260 | 4839 | \\ comptime {1;} |
| 5261 | 4840 | \\} |
| 5262 | | , |
| 4841 | , &[_][]const u8{ |
| 5263 | 4842 | "tmp.zig:2:15: error: expression value is ignored", |
| 5264 | | ); |
| 4843 | }); |
| 5265 | 4844 | |
| 5266 | | cases.add( |
| 5267 | | "ignored comptime value", |
| 4845 | cases.add("ignored comptime value", |
| 5268 | 4846 | \\export fn foo() void { |
| 5269 | 4847 | \\ comptime 1; |
| 5270 | 4848 | \\} |
| 5271 | | , |
| 4849 | , &[_][]const u8{ |
| 5272 | 4850 | "tmp.zig:2:5: error: expression value is ignored", |
| 5273 | | ); |
| 4851 | }); |
| 5274 | 4852 | |
| 5275 | | cases.add( |
| 5276 | | "ignored defered statement value", |
| 4853 | cases.add("ignored defered statement value", |
| 5277 | 4854 | \\export fn foo() void { |
| 5278 | 4855 | \\ defer {1;} |
| 5279 | 4856 | \\} |
| 5280 | | , |
| 4857 | , &[_][]const u8{ |
| 5281 | 4858 | "tmp.zig:2:12: error: expression value is ignored", |
| 5282 | | ); |
| 4859 | }); |
| 5283 | 4860 | |
| 5284 | | cases.add( |
| 5285 | | "ignored defered function call", |
| 4861 | cases.add("ignored defered function call", |
| 5286 | 4862 | \\export fn foo() void { |
| 5287 | 4863 | \\ defer bar(); |
| 5288 | 4864 | \\} |
| 5289 | 4865 | \\fn bar() anyerror!i32 { return 0; } |
| 5290 | | , |
| 4866 | , &[_][]const u8{ |
| 5291 | 4867 | "tmp.zig:2:14: error: expression value is ignored", |
| 5292 | | ); |
| 4868 | }); |
| 5293 | 4869 | |
| 5294 | | cases.add( |
| 5295 | | "dereference an array", |
| 4870 | cases.add("dereference an array", |
| 5296 | 4871 | \\var s_buffer: [10]u8 = undefined; |
| 5297 | 4872 | \\pub fn pass(in: []u8) []u8 { |
| 5298 | 4873 | \\ var out = &s_buffer; |
| ... | ... | @@ -5301,12 +4876,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5301 | 4876 | \\} |
| 5302 | 4877 | \\ |
| 5303 | 4878 | \\export fn entry() usize { return @sizeOf(@typeOf(pass)); } |
| 5304 | | , |
| 4879 | , &[_][]const u8{ |
| 5305 | 4880 | "tmp.zig:4:10: error: attempt to dereference non-pointer type '[10]u8'", |
| 5306 | | ); |
| 4881 | }); |
| 5307 | 4882 | |
| 5308 | | cases.add( |
| 5309 | | "pass const ptr to mutable ptr fn", |
| 4883 | cases.add("pass const ptr to mutable ptr fn", |
| 5310 | 4884 | \\fn foo() bool { |
| 5311 | 4885 | \\ const a = @as([]const u8, "a",); |
| 5312 | 4886 | \\ const b = &a; |
| ... | ... | @@ -5317,22 +4891,21 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5317 | 4891 | \\} |
| 5318 | 4892 | \\ |
| 5319 | 4893 | \\export fn entry() usize { return @sizeOf(@typeOf(foo)); } |
| 5320 | | , |
| 4894 | , &[_][]const u8{ |
| 5321 | 4895 | "tmp.zig:4:19: error: expected type '*[]const u8', found '*const []const u8'", |
| 5322 | | ); |
| 4896 | }); |
| 5323 | 4897 | |
| 5324 | 4898 | cases.addCase(x: { |
| 5325 | | const tc = cases.create( |
| 5326 | | "export collision", |
| 4899 | const tc = cases.create("export collision", |
| 5327 | 4900 | \\const foo = @import("foo.zig",); |
| 5328 | 4901 | \\ |
| 5329 | 4902 | \\export fn bar() usize { |
| 5330 | 4903 | \\ return foo.baz; |
| 5331 | 4904 | \\} |
| 5332 | | , |
| 4905 | , &[_][]const u8{ |
| 5333 | 4906 | "foo.zig:1:1: error: exported symbol collision: 'bar'", |
| 5334 | 4907 | "tmp.zig:3:1: note: other symbol here", |
| 5335 | | ); |
| 4908 | }); |
| 5336 | 4909 | |
| 5337 | 4910 | tc.addSourceFile("foo.zig", |
| 5338 | 4911 | \\export fn bar() void {} |
| ... | ... | @@ -5342,28 +4915,25 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5342 | 4915 | break :x tc; |
| 5343 | 4916 | }); |
| 5344 | 4917 | |
| 5345 | | cases.add( |
| 5346 | | "implicit cast from array to mutable slice", |
| 4918 | cases.add("implicit cast from array to mutable slice", |
| 5347 | 4919 | \\var global_array: [10]i32 = undefined; |
| 5348 | 4920 | \\fn foo(param: []i32) void {} |
| 5349 | 4921 | \\export fn entry() void { |
| 5350 | 4922 | \\ foo(global_array); |
| 5351 | 4923 | \\} |
| 5352 | | , |
| 4924 | , &[_][]const u8{ |
| 5353 | 4925 | "tmp.zig:4:9: error: expected type '[]i32', found '[10]i32'", |
| 5354 | | ); |
| 4926 | }); |
| 5355 | 4927 | |
| 5356 | | cases.add( |
| 5357 | | "ptrcast to non-pointer", |
| 4928 | cases.add("ptrcast to non-pointer", |
| 5358 | 4929 | \\export fn entry(a: *i32) usize { |
| 5359 | 4930 | \\ return @ptrCast(usize, a); |
| 5360 | 4931 | \\} |
| 5361 | | , |
| 4932 | , &[_][]const u8{ |
| 5362 | 4933 | "tmp.zig:2:21: error: expected pointer, found 'usize'", |
| 5363 | | ); |
| 4934 | }); |
| 5364 | 4935 | |
| 5365 | | cases.add( |
| 5366 | | "asm at compile time", |
| 4936 | cases.add("asm at compile time", |
| 5367 | 4937 | \\comptime { |
| 5368 | 4938 | \\ doSomeAsm(); |
| 5369 | 4939 | \\} |
| ... | ... | @@ -5375,66 +4945,60 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5375 | 4945 | \\ \\.set aoeu, derp; |
| 5376 | 4946 | \\ ); |
| 5377 | 4947 | \\} |
| 5378 | | , |
| 4948 | , &[_][]const u8{ |
| 5379 | 4949 | "tmp.zig:6:5: error: unable to evaluate constant expression", |
| 5380 | | ); |
| 4950 | }); |
| 5381 | 4951 | |
| 5382 | | cases.add( |
| 5383 | | "invalid member of builtin enum", |
| 4952 | cases.add("invalid member of builtin enum", |
| 5384 | 4953 | \\const builtin = @import("builtin",); |
| 5385 | 4954 | \\export fn entry() void { |
| 5386 | 4955 | \\ const foo = builtin.Arch.x86; |
| 5387 | 4956 | \\} |
| 5388 | | , |
| 4957 | , &[_][]const u8{ |
| 5389 | 4958 | "tmp.zig:3:29: error: container 'std.target.Arch' has no member called 'x86'", |
| 5390 | | ); |
| 4959 | }); |
| 5391 | 4960 | |
| 5392 | | cases.add( |
| 5393 | | "int to ptr of 0 bits", |
| 4961 | cases.add("int to ptr of 0 bits", |
| 5394 | 4962 | \\export fn foo() void { |
| 5395 | 4963 | \\ var x: usize = 0x1000; |
| 5396 | 4964 | \\ var y: *void = @intToPtr(*void, x); |
| 5397 | 4965 | \\} |
| 5398 | | , |
| 4966 | , &[_][]const u8{ |
| 5399 | 4967 | "tmp.zig:3:30: error: type '*void' has 0 bits and cannot store information", |
| 5400 | | ); |
| 4968 | }); |
| 5401 | 4969 | |
| 5402 | | cases.add( |
| 5403 | | "@fieldParentPtr - non struct", |
| 4970 | cases.add("@fieldParentPtr - non struct", |
| 5404 | 4971 | \\const Foo = i32; |
| 5405 | 4972 | \\export fn foo(a: *i32) *Foo { |
| 5406 | 4973 | \\ return @fieldParentPtr(Foo, "a", a); |
| 5407 | 4974 | \\} |
| 5408 | | , |
| 4975 | , &[_][]const u8{ |
| 5409 | 4976 | "tmp.zig:3:28: error: expected struct type, found 'i32'", |
| 5410 | | ); |
| 4977 | }); |
| 5411 | 4978 | |
| 5412 | | cases.add( |
| 5413 | | "@fieldParentPtr - bad field name", |
| 4979 | cases.add("@fieldParentPtr - bad field name", |
| 5414 | 4980 | \\const Foo = extern struct { |
| 5415 | 4981 | \\ derp: i32, |
| 5416 | 4982 | \\}; |
| 5417 | 4983 | \\export fn foo(a: *i32) *Foo { |
| 5418 | 4984 | \\ return @fieldParentPtr(Foo, "a", a); |
| 5419 | 4985 | \\} |
| 5420 | | , |
| 4986 | , &[_][]const u8{ |
| 5421 | 4987 | "tmp.zig:5:33: error: struct 'Foo' has no field 'a'", |
| 5422 | | ); |
| 4988 | }); |
| 5423 | 4989 | |
| 5424 | | cases.add( |
| 5425 | | "@fieldParentPtr - field pointer is not pointer", |
| 4990 | cases.add("@fieldParentPtr - field pointer is not pointer", |
| 5426 | 4991 | \\const Foo = extern struct { |
| 5427 | 4992 | \\ a: i32, |
| 5428 | 4993 | \\}; |
| 5429 | 4994 | \\export fn foo(a: i32) *Foo { |
| 5430 | 4995 | \\ return @fieldParentPtr(Foo, "a", a); |
| 5431 | 4996 | \\} |
| 5432 | | , |
| 4997 | , &[_][]const u8{ |
| 5433 | 4998 | "tmp.zig:5:38: error: expected pointer, found 'i32'", |
| 5434 | | ); |
| 4999 | }); |
| 5435 | 5000 | |
| 5436 | | cases.add( |
| 5437 | | "@fieldParentPtr - comptime field ptr not based on struct", |
| 5001 | cases.add("@fieldParentPtr - comptime field ptr not based on struct", |
| 5438 | 5002 | \\const Foo = struct { |
| 5439 | 5003 | \\ a: i32, |
| 5440 | 5004 | \\ b: i32, |
| ... | ... | @@ -5445,12 +5009,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5445 | 5009 | \\ const field_ptr = @intToPtr(*i32, 0x1234); |
| 5446 | 5010 | \\ const another_foo_ptr = @fieldParentPtr(Foo, "b", field_ptr); |
| 5447 | 5011 | \\} |
| 5448 | | , |
| 5012 | , &[_][]const u8{ |
| 5449 | 5013 | "tmp.zig:9:55: error: pointer value not based on parent struct", |
| 5450 | | ); |
| 5014 | }); |
| 5451 | 5015 | |
| 5452 | | cases.add( |
| 5453 | | "@fieldParentPtr - comptime wrong field index", |
| 5016 | cases.add("@fieldParentPtr - comptime wrong field index", |
| 5454 | 5017 | \\const Foo = struct { |
| 5455 | 5018 | \\ a: i32, |
| 5456 | 5019 | \\ b: i32, |
| ... | ... | @@ -5460,80 +5023,72 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5460 | 5023 | \\comptime { |
| 5461 | 5024 | \\ const another_foo_ptr = @fieldParentPtr(Foo, "b", &foo.a); |
| 5462 | 5025 | \\} |
| 5463 | | , |
| 5026 | , &[_][]const u8{ |
| 5464 | 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( |
| 5468 | | "@byteOffsetOf - non struct", |
| 5030 | cases.add("@byteOffsetOf - non struct", |
| 5469 | 5031 | \\const Foo = i32; |
| 5470 | 5032 | \\export fn foo() usize { |
| 5471 | 5033 | \\ return @byteOffsetOf(Foo, "a",); |
| 5472 | 5034 | \\} |
| 5473 | | , |
| 5035 | , &[_][]const u8{ |
| 5474 | 5036 | "tmp.zig:3:26: error: expected struct type, found 'i32'", |
| 5475 | | ); |
| 5037 | }); |
| 5476 | 5038 | |
| 5477 | | cases.add( |
| 5478 | | "@byteOffsetOf - bad field name", |
| 5039 | cases.add("@byteOffsetOf - bad field name", |
| 5479 | 5040 | \\const Foo = struct { |
| 5480 | 5041 | \\ derp: i32, |
| 5481 | 5042 | \\}; |
| 5482 | 5043 | \\export fn foo() usize { |
| 5483 | 5044 | \\ return @byteOffsetOf(Foo, "a",); |
| 5484 | 5045 | \\} |
| 5485 | | , |
| 5046 | , &[_][]const u8{ |
| 5486 | 5047 | "tmp.zig:5:31: error: struct 'Foo' has no field 'a'", |
| 5487 | | ); |
| 5048 | }); |
| 5488 | 5049 | |
| 5489 | | cases.addExe( |
| 5490 | | "missing main fn in executable", |
| 5050 | cases.addExe("missing main fn in executable", |
| 5491 | 5051 | \\ |
| 5492 | | , |
| 5052 | , &[_][]const u8{ |
| 5493 | 5053 | "error: root source file has no member called 'main'", |
| 5494 | | ); |
| 5054 | }); |
| 5495 | 5055 | |
| 5496 | | cases.addExe( |
| 5497 | | "private main fn", |
| 5056 | cases.addExe("private main fn", |
| 5498 | 5057 | \\fn main() void {} |
| 5499 | | , |
| 5058 | , &[_][]const u8{ |
| 5500 | 5059 | "error: 'main' is private", |
| 5501 | 5060 | "tmp.zig:1:1: note: declared here", |
| 5502 | | ); |
| 5061 | }); |
| 5503 | 5062 | |
| 5504 | | cases.add( |
| 5505 | | "setting a section on a local variable", |
| 5063 | cases.add("setting a section on a local variable", |
| 5506 | 5064 | \\export fn entry() i32 { |
| 5507 | 5065 | \\ var foo: i32 linksection(".text2") = 1234; |
| 5508 | 5066 | \\ return foo; |
| 5509 | 5067 | \\} |
| 5510 | | , |
| 5068 | , &[_][]const u8{ |
| 5511 | 5069 | "tmp.zig:2:30: error: cannot set section of local variable 'foo'", |
| 5512 | | ); |
| 5070 | }); |
| 5513 | 5071 | |
| 5514 | | cases.add( |
| 5515 | | "returning address of local variable - simple", |
| 5072 | cases.add("returning address of local variable - simple", |
| 5516 | 5073 | \\export fn foo() *i32 { |
| 5517 | 5074 | \\ var a: i32 = undefined; |
| 5518 | 5075 | \\ return &a; |
| 5519 | 5076 | \\} |
| 5520 | | , |
| 5077 | , &[_][]const u8{ |
| 5521 | 5078 | "tmp.zig:3:13: error: function returns address of local variable", |
| 5522 | | ); |
| 5079 | }); |
| 5523 | 5080 | |
| 5524 | | cases.add( |
| 5525 | | "returning address of local variable - phi", |
| 5081 | cases.add("returning address of local variable - phi", |
| 5526 | 5082 | \\export fn foo(c: bool) *i32 { |
| 5527 | 5083 | \\ var a: i32 = undefined; |
| 5528 | 5084 | \\ var b: i32 = undefined; |
| 5529 | 5085 | \\ return if (c) &a else &b; |
| 5530 | 5086 | \\} |
| 5531 | | , |
| 5087 | , &[_][]const u8{ |
| 5532 | 5088 | "tmp.zig:4:12: error: function returns address of local variable", |
| 5533 | | ); |
| 5089 | }); |
| 5534 | 5090 | |
| 5535 | | cases.add( |
| 5536 | | "inner struct member shadowing outer struct member", |
| 5091 | cases.add("inner struct member shadowing outer struct member", |
| 5537 | 5092 | \\fn A() type { |
| 5538 | 5093 | \\ return struct { |
| 5539 | 5094 | \\ b: B(), |
| ... | ... | @@ -5553,73 +5108,66 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5553 | 5108 | \\fn assert(ok: bool) void { |
| 5554 | 5109 | \\ if (!ok) unreachable; |
| 5555 | 5110 | \\} |
| 5556 | | , |
| 5111 | , &[_][]const u8{ |
| 5557 | 5112 | "tmp.zig:9:17: error: redefinition of 'Self'", |
| 5558 | 5113 | "tmp.zig:5:9: note: previous definition is here", |
| 5559 | | ); |
| 5114 | }); |
| 5560 | 5115 | |
| 5561 | | cases.add( |
| 5562 | | "while expected bool, got optional", |
| 5116 | cases.add("while expected bool, got optional", |
| 5563 | 5117 | \\export fn foo() void { |
| 5564 | 5118 | \\ while (bar()) {} |
| 5565 | 5119 | \\} |
| 5566 | 5120 | \\fn bar() ?i32 { return 1; } |
| 5567 | | , |
| 5121 | , &[_][]const u8{ |
| 5568 | 5122 | "tmp.zig:2:15: error: expected type 'bool', found '?i32'", |
| 5569 | | ); |
| 5123 | }); |
| 5570 | 5124 | |
| 5571 | | cases.add( |
| 5572 | | "while expected bool, got error union", |
| 5125 | cases.add("while expected bool, got error union", |
| 5573 | 5126 | \\export fn foo() void { |
| 5574 | 5127 | \\ while (bar()) {} |
| 5575 | 5128 | \\} |
| 5576 | 5129 | \\fn bar() anyerror!i32 { return 1; } |
| 5577 | | , |
| 5130 | , &[_][]const u8{ |
| 5578 | 5131 | "tmp.zig:2:15: error: expected type 'bool', found 'anyerror!i32'", |
| 5579 | | ); |
| 5132 | }); |
| 5580 | 5133 | |
| 5581 | | cases.add( |
| 5582 | | "while expected optional, got bool", |
| 5134 | cases.add("while expected optional, got bool", |
| 5583 | 5135 | \\export fn foo() void { |
| 5584 | 5136 | \\ while (bar()) |x| {} |
| 5585 | 5137 | \\} |
| 5586 | 5138 | \\fn bar() bool { return true; } |
| 5587 | | , |
| 5139 | , &[_][]const u8{ |
| 5588 | 5140 | "tmp.zig:2:15: error: expected optional type, found 'bool'", |
| 5589 | | ); |
| 5141 | }); |
| 5590 | 5142 | |
| 5591 | | cases.add( |
| 5592 | | "while expected optional, got error union", |
| 5143 | cases.add("while expected optional, got error union", |
| 5593 | 5144 | \\export fn foo() void { |
| 5594 | 5145 | \\ while (bar()) |x| {} |
| 5595 | 5146 | \\} |
| 5596 | 5147 | \\fn bar() anyerror!i32 { return 1; } |
| 5597 | | , |
| 5148 | , &[_][]const u8{ |
| 5598 | 5149 | "tmp.zig:2:15: error: expected optional type, found 'anyerror!i32'", |
| 5599 | | ); |
| 5150 | }); |
| 5600 | 5151 | |
| 5601 | | cases.add( |
| 5602 | | "while expected error union, got bool", |
| 5152 | cases.add("while expected error union, got bool", |
| 5603 | 5153 | \\export fn foo() void { |
| 5604 | 5154 | \\ while (bar()) |x| {} else |err| {} |
| 5605 | 5155 | \\} |
| 5606 | 5156 | \\fn bar() bool { return true; } |
| 5607 | | , |
| 5157 | , &[_][]const u8{ |
| 5608 | 5158 | "tmp.zig:2:15: error: expected error union type, found 'bool'", |
| 5609 | | ); |
| 5159 | }); |
| 5610 | 5160 | |
| 5611 | | cases.add( |
| 5612 | | "while expected error union, got optional", |
| 5161 | cases.add("while expected error union, got optional", |
| 5613 | 5162 | \\export fn foo() void { |
| 5614 | 5163 | \\ while (bar()) |x| {} else |err| {} |
| 5615 | 5164 | \\} |
| 5616 | 5165 | \\fn bar() ?i32 { return 1; } |
| 5617 | | , |
| 5166 | , &[_][]const u8{ |
| 5618 | 5167 | "tmp.zig:2:15: error: expected error union type, found '?i32'", |
| 5619 | | ); |
| 5168 | }); |
| 5620 | 5169 | |
| 5621 | | cases.add( |
| 5622 | | "inline fn calls itself indirectly", |
| 5170 | cases.add("inline fn calls itself indirectly", |
| 5623 | 5171 | \\export fn foo() void { |
| 5624 | 5172 | \\ bar(); |
| 5625 | 5173 | \\} |
| ... | ... | @@ -5632,94 +5180,85 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5632 | 5180 | \\ quux(); |
| 5633 | 5181 | \\} |
| 5634 | 5182 | \\extern fn quux() void; |
| 5635 | | , |
| 5183 | , &[_][]const u8{ |
| 5636 | 5184 | "tmp.zig:4:1: error: unable to inline function", |
| 5637 | | ); |
| 5185 | }); |
| 5638 | 5186 | |
| 5639 | | cases.add( |
| 5640 | | "save reference to inline function", |
| 5187 | cases.add("save reference to inline function", |
| 5641 | 5188 | \\export fn foo() void { |
| 5642 | 5189 | \\ quux(@ptrToInt(bar)); |
| 5643 | 5190 | \\} |
| 5644 | 5191 | \\inline fn bar() void { } |
| 5645 | 5192 | \\extern fn quux(usize) void; |
| 5646 | | , |
| 5193 | , &[_][]const u8{ |
| 5647 | 5194 | "tmp.zig:4:1: error: unable to inline function", |
| 5648 | | ); |
| 5195 | }); |
| 5649 | 5196 | |
| 5650 | | cases.add( |
| 5651 | | "signed integer division", |
| 5197 | cases.add("signed integer division", |
| 5652 | 5198 | \\export fn foo(a: i32, b: i32) i32 { |
| 5653 | 5199 | \\ return a / b; |
| 5654 | 5200 | \\} |
| 5655 | | , |
| 5201 | , &[_][]const u8{ |
| 5656 | 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( |
| 5660 | | "signed integer remainder division", |
| 5205 | cases.add("signed integer remainder division", |
| 5661 | 5206 | \\export fn foo(a: i32, b: i32) i32 { |
| 5662 | 5207 | \\ return a % b; |
| 5663 | 5208 | \\} |
| 5664 | | , |
| 5209 | , &[_][]const u8{ |
| 5665 | 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( |
| 5669 | | "compile-time division by zero", |
| 5213 | cases.add("compile-time division by zero", |
| 5670 | 5214 | \\comptime { |
| 5671 | 5215 | \\ const a: i32 = 1; |
| 5672 | 5216 | \\ const b: i32 = 0; |
| 5673 | 5217 | \\ const c = a / b; |
| 5674 | 5218 | \\} |
| 5675 | | , |
| 5219 | , &[_][]const u8{ |
| 5676 | 5220 | "tmp.zig:4:17: error: division by zero", |
| 5677 | | ); |
| 5221 | }); |
| 5678 | 5222 | |
| 5679 | | cases.add( |
| 5680 | | "compile-time remainder division by zero", |
| 5223 | cases.add("compile-time remainder division by zero", |
| 5681 | 5224 | \\comptime { |
| 5682 | 5225 | \\ const a: i32 = 1; |
| 5683 | 5226 | \\ const b: i32 = 0; |
| 5684 | 5227 | \\ const c = a % b; |
| 5685 | 5228 | \\} |
| 5686 | | , |
| 5229 | , &[_][]const u8{ |
| 5687 | 5230 | "tmp.zig:4:17: error: division by zero", |
| 5688 | | ); |
| 5231 | }); |
| 5689 | 5232 | |
| 5690 | | cases.add( |
| 5691 | | "@setRuntimeSafety twice for same scope", |
| 5233 | cases.add("@setRuntimeSafety twice for same scope", |
| 5692 | 5234 | \\export fn foo() void { |
| 5693 | 5235 | \\ @setRuntimeSafety(false); |
| 5694 | 5236 | \\ @setRuntimeSafety(false); |
| 5695 | 5237 | \\} |
| 5696 | | , |
| 5238 | , &[_][]const u8{ |
| 5697 | 5239 | "tmp.zig:3:5: error: runtime safety set twice for same scope", |
| 5698 | 5240 | "tmp.zig:2:5: note: first set here", |
| 5699 | | ); |
| 5241 | }); |
| 5700 | 5242 | |
| 5701 | | cases.add( |
| 5702 | | "@setFloatMode twice for same scope", |
| 5243 | cases.add("@setFloatMode twice for same scope", |
| 5703 | 5244 | \\export fn foo() void { |
| 5704 | 5245 | \\ @setFloatMode(@import("builtin").FloatMode.Optimized); |
| 5705 | 5246 | \\ @setFloatMode(@import("builtin").FloatMode.Optimized); |
| 5706 | 5247 | \\} |
| 5707 | | , |
| 5248 | , &[_][]const u8{ |
| 5708 | 5249 | "tmp.zig:3:5: error: float mode set twice for same scope", |
| 5709 | 5250 | "tmp.zig:2:5: note: first set here", |
| 5710 | | ); |
| 5251 | }); |
| 5711 | 5252 | |
| 5712 | | cases.add( |
| 5713 | | "array access of type", |
| 5253 | cases.add("array access of type", |
| 5714 | 5254 | \\export fn foo() void { |
| 5715 | 5255 | \\ var b: u8[40] = undefined; |
| 5716 | 5256 | \\} |
| 5717 | | , |
| 5257 | , &[_][]const u8{ |
| 5718 | 5258 | "tmp.zig:2:14: error: array access of non-array type 'type'", |
| 5719 | | ); |
| 5259 | }); |
| 5720 | 5260 | |
| 5721 | | cases.add( |
| 5722 | | "cannot break out of defer expression", |
| 5261 | cases.add("cannot break out of defer expression", |
| 5723 | 5262 | \\export fn foo() void { |
| 5724 | 5263 | \\ while (true) { |
| 5725 | 5264 | \\ defer { |
| ... | ... | @@ -5727,12 +5266,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5727 | 5266 | \\ } |
| 5728 | 5267 | \\ } |
| 5729 | 5268 | \\} |
| 5730 | | , |
| 5269 | , &[_][]const u8{ |
| 5731 | 5270 | "tmp.zig:4:13: error: cannot break out of defer expression", |
| 5732 | | ); |
| 5271 | }); |
| 5733 | 5272 | |
| 5734 | | cases.add( |
| 5735 | | "cannot continue out of defer expression", |
| 5273 | cases.add("cannot continue out of defer expression", |
| 5736 | 5274 | \\export fn foo() void { |
| 5737 | 5275 | \\ while (true) { |
| 5738 | 5276 | \\ defer { |
| ... | ... | @@ -5740,26 +5278,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5740 | 5278 | \\ } |
| 5741 | 5279 | \\ } |
| 5742 | 5280 | \\} |
| 5743 | | , |
| 5281 | , &[_][]const u8{ |
| 5744 | 5282 | "tmp.zig:4:13: error: cannot continue out of defer expression", |
| 5745 | | ); |
| 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 | | ); |
| 5283 | }); |
| 5760 | 5284 | |
| 5761 | | cases.add( |
| 5762 | | "calling a generic function only known at runtime", |
| 5285 | cases.add("calling a generic function only known at runtime", |
| 5763 | 5286 | \\var foos = [_]fn(var) void { foo1, foo2 }; |
| 5764 | 5287 | \\ |
| 5765 | 5288 | \\fn foo1(arg: var) void {} |
| ... | ... | @@ -5768,12 +5291,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5768 | 5291 | \\pub fn main() !void { |
| 5769 | 5292 | \\ foos[0](true); |
| 5770 | 5293 | \\} |
| 5771 | | , |
| 5294 | , &[_][]const u8{ |
| 5772 | 5295 | "tmp.zig:7:9: error: calling a generic function requires compile-time known function value", |
| 5773 | | ); |
| 5296 | }); |
| 5774 | 5297 | |
| 5775 | | cases.add( |
| 5776 | | "@compileError shows traceback of references that caused it", |
| 5298 | cases.add("@compileError shows traceback of references that caused it", |
| 5777 | 5299 | \\const foo = @compileError("aoeu",); |
| 5778 | 5300 | \\ |
| 5779 | 5301 | \\const bar = baz + foo; |
| ... | ... | @@ -5782,96 +5304,86 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5782 | 5304 | \\export fn entry() i32 { |
| 5783 | 5305 | \\ return bar; |
| 5784 | 5306 | \\} |
| 5785 | | , |
| 5307 | , &[_][]const u8{ |
| 5786 | 5308 | "tmp.zig:1:13: error: aoeu", |
| 5787 | 5309 | "tmp.zig:3:19: note: referenced here", |
| 5788 | 5310 | "tmp.zig:7:12: note: referenced here", |
| 5789 | | ); |
| 5311 | }); |
| 5790 | 5312 | |
| 5791 | | cases.add( |
| 5792 | | "float literal too large error", |
| 5313 | cases.add("float literal too large error", |
| 5793 | 5314 | \\comptime { |
| 5794 | 5315 | \\ const a = 0x1.0p18495; |
| 5795 | 5316 | \\} |
| 5796 | | , |
| 5317 | , &[_][]const u8{ |
| 5797 | 5318 | "tmp.zig:2:15: error: float literal out of range of any type", |
| 5798 | | ); |
| 5319 | }); |
| 5799 | 5320 | |
| 5800 | | cases.add( |
| 5801 | | "float literal too small error (denormal)", |
| 5321 | cases.add("float literal too small error (denormal)", |
| 5802 | 5322 | \\comptime { |
| 5803 | 5323 | \\ const a = 0x1.0p-19000; |
| 5804 | 5324 | \\} |
| 5805 | | , |
| 5325 | , &[_][]const u8{ |
| 5806 | 5326 | "tmp.zig:2:15: error: float literal out of range of any type", |
| 5807 | | ); |
| 5327 | }); |
| 5808 | 5328 | |
| 5809 | | cases.add( |
| 5810 | | "explicit cast float literal to integer when there is a fraction component", |
| 5329 | cases.add("explicit cast float literal to integer when there is a fraction component", |
| 5811 | 5330 | \\export fn entry() i32 { |
| 5812 | 5331 | \\ return @as(i32, 12.34); |
| 5813 | 5332 | \\} |
| 5814 | | , |
| 5333 | , &[_][]const u8{ |
| 5815 | 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( |
| 5819 | | "non pointer given to @ptrToInt", |
| 5337 | cases.add("non pointer given to @ptrToInt", |
| 5820 | 5338 | \\export fn entry(x: i32) usize { |
| 5821 | 5339 | \\ return @ptrToInt(x); |
| 5822 | 5340 | \\} |
| 5823 | | , |
| 5341 | , &[_][]const u8{ |
| 5824 | 5342 | "tmp.zig:2:22: error: expected pointer, found 'i32'", |
| 5825 | | ); |
| 5343 | }); |
| 5826 | 5344 | |
| 5827 | | cases.add( |
| 5828 | | "@shlExact shifts out 1 bits", |
| 5345 | cases.add("@shlExact shifts out 1 bits", |
| 5829 | 5346 | \\comptime { |
| 5830 | 5347 | \\ const x = @shlExact(@as(u8, 0b01010101), 2); |
| 5831 | 5348 | \\} |
| 5832 | | , |
| 5349 | , &[_][]const u8{ |
| 5833 | 5350 | "tmp.zig:2:15: error: operation caused overflow", |
| 5834 | | ); |
| 5351 | }); |
| 5835 | 5352 | |
| 5836 | | cases.add( |
| 5837 | | "@shrExact shifts out 1 bits", |
| 5353 | cases.add("@shrExact shifts out 1 bits", |
| 5838 | 5354 | \\comptime { |
| 5839 | 5355 | \\ const x = @shrExact(@as(u8, 0b10101010), 2); |
| 5840 | 5356 | \\} |
| 5841 | | , |
| 5357 | , &[_][]const u8{ |
| 5842 | 5358 | "tmp.zig:2:15: error: exact shift shifted out 1 bits", |
| 5843 | | ); |
| 5359 | }); |
| 5844 | 5360 | |
| 5845 | | cases.add( |
| 5846 | | "shifting without int type or comptime known", |
| 5361 | cases.add("shifting without int type or comptime known", |
| 5847 | 5362 | \\export fn entry(x: u8) u8 { |
| 5848 | 5363 | \\ return 0x11 << x; |
| 5849 | 5364 | \\} |
| 5850 | | , |
| 5365 | , &[_][]const u8{ |
| 5851 | 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( |
| 5855 | | "shifting RHS is log2 of LHS int bit width", |
| 5369 | cases.add("shifting RHS is log2 of LHS int bit width", |
| 5856 | 5370 | \\export fn entry(x: u8, y: u8) u8 { |
| 5857 | 5371 | \\ return x << y; |
| 5858 | 5372 | \\} |
| 5859 | | , |
| 5373 | , &[_][]const u8{ |
| 5860 | 5374 | "tmp.zig:2:17: error: expected type 'u3', found 'u8'", |
| 5861 | | ); |
| 5375 | }); |
| 5862 | 5376 | |
| 5863 | | cases.add( |
| 5864 | | "globally shadowing a primitive type", |
| 5377 | cases.add("globally shadowing a primitive type", |
| 5865 | 5378 | \\const u16 = @intType(false, 8); |
| 5866 | 5379 | \\export fn entry() void { |
| 5867 | 5380 | \\ const a: u16 = 300; |
| 5868 | 5381 | \\} |
| 5869 | | , |
| 5382 | , &[_][]const u8{ |
| 5870 | 5383 | "tmp.zig:1:1: error: declaration shadows primitive type 'u16'", |
| 5871 | | ); |
| 5384 | }); |
| 5872 | 5385 | |
| 5873 | | cases.add( |
| 5874 | | "implicitly increasing pointer alignment", |
| 5386 | cases.add("implicitly increasing pointer alignment", |
| 5875 | 5387 | \\const Foo = packed struct { |
| 5876 | 5388 | \\ a: u8, |
| 5877 | 5389 | \\ b: u32, |
| ... | ... | @@ -5885,12 +5397,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5885 | 5397 | \\fn bar(x: *u32) void { |
| 5886 | 5398 | \\ x.* += 1; |
| 5887 | 5399 | \\} |
| 5888 | | , |
| 5400 | , &[_][]const u8{ |
| 5889 | 5401 | "tmp.zig:8:13: error: expected type '*u32', found '*align(1) u32'", |
| 5890 | | ); |
| 5402 | }); |
| 5891 | 5403 | |
| 5892 | | cases.add( |
| 5893 | | "implicitly increasing slice alignment", |
| 5404 | cases.add("implicitly increasing slice alignment", |
| 5894 | 5405 | \\const Foo = packed struct { |
| 5895 | 5406 | \\ a: u8, |
| 5896 | 5407 | \\ b: u32, |
| ... | ... | @@ -5905,36 +5416,33 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5905 | 5416 | \\fn bar(x: []u32) void { |
| 5906 | 5417 | \\ x[0] += 1; |
| 5907 | 5418 | \\} |
| 5908 | | , |
| 5419 | , &[_][]const u8{ |
| 5909 | 5420 | "tmp.zig:9:26: error: cast increases pointer alignment", |
| 5910 | 5421 | "tmp.zig:9:26: note: '*align(1) u32' has alignment 1", |
| 5911 | 5422 | "tmp.zig:9:26: note: '*[1]u32' has alignment 4", |
| 5912 | | ); |
| 5423 | }); |
| 5913 | 5424 | |
| 5914 | | cases.add( |
| 5915 | | "increase pointer alignment in @ptrCast", |
| 5425 | cases.add("increase pointer alignment in @ptrCast", |
| 5916 | 5426 | \\export fn entry() u32 { |
| 5917 | 5427 | \\ var bytes: [4]u8 = [_]u8{0x01, 0x02, 0x03, 0x04}; |
| 5918 | 5428 | \\ const ptr = @ptrCast(*u32, &bytes[0]); |
| 5919 | 5429 | \\ return ptr.*; |
| 5920 | 5430 | \\} |
| 5921 | | , |
| 5431 | , &[_][]const u8{ |
| 5922 | 5432 | "tmp.zig:3:17: error: cast increases pointer alignment", |
| 5923 | 5433 | "tmp.zig:3:38: note: '*u8' has alignment 1", |
| 5924 | 5434 | "tmp.zig:3:26: note: '*u32' has alignment 4", |
| 5925 | | ); |
| 5435 | }); |
| 5926 | 5436 | |
| 5927 | | cases.add( |
| 5928 | | "@alignCast expects pointer or slice", |
| 5437 | cases.add("@alignCast expects pointer or slice", |
| 5929 | 5438 | \\export fn entry() void { |
| 5930 | 5439 | \\ @alignCast(4, @as(u32, 3)); |
| 5931 | 5440 | \\} |
| 5932 | | , |
| 5441 | , &[_][]const u8{ |
| 5933 | 5442 | "tmp.zig:2:19: error: expected pointer or slice, found 'u32'", |
| 5934 | | ); |
| 5443 | }); |
| 5935 | 5444 | |
| 5936 | | cases.add( |
| 5937 | | "passing an under-aligned function pointer", |
| 5445 | cases.add("passing an under-aligned function pointer", |
| 5938 | 5446 | \\export fn entry() void { |
| 5939 | 5447 | \\ testImplicitlyDecreaseFnAlign(alignedSmall, 1234); |
| 5940 | 5448 | \\} |
| ... | ... | @@ -5942,45 +5450,41 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5942 | 5450 | \\ if (ptr() != answer) unreachable; |
| 5943 | 5451 | \\} |
| 5944 | 5452 | \\fn alignedSmall() align(4) i32 { return 1234; } |
| 5945 | | , |
| 5453 | , &[_][]const u8{ |
| 5946 | 5454 | "tmp.zig:2:35: error: expected type 'fn() align(8) i32', found 'fn() align(4) i32'", |
| 5947 | | ); |
| 5455 | }); |
| 5948 | 5456 | |
| 5949 | | cases.add( |
| 5950 | | "passing a not-aligned-enough pointer to cmpxchg", |
| 5457 | cases.add("passing a not-aligned-enough pointer to cmpxchg", |
| 5951 | 5458 | \\const AtomicOrder = @import("builtin").AtomicOrder; |
| 5952 | 5459 | \\export fn entry() bool { |
| 5953 | 5460 | \\ var x: i32 align(1) = 1234; |
| 5954 | 5461 | \\ while (!@cmpxchgWeak(i32, &x, 1234, 5678, AtomicOrder.SeqCst, AtomicOrder.SeqCst)) {} |
| 5955 | 5462 | \\ return x == 5678; |
| 5956 | 5463 | \\} |
| 5957 | | , |
| 5464 | , &[_][]const u8{ |
| 5958 | 5465 | "tmp.zig:4:32: error: expected type '*i32', found '*align(1) i32'", |
| 5959 | | ); |
| 5466 | }); |
| 5960 | 5467 | |
| 5961 | | cases.add( |
| 5962 | | "wrong size to an array literal", |
| 5468 | cases.add("wrong size to an array literal", |
| 5963 | 5469 | \\comptime { |
| 5964 | 5470 | \\ const array = [2]u8{1, 2, 3}; |
| 5965 | 5471 | \\} |
| 5966 | | , |
| 5472 | , &[_][]const u8{ |
| 5967 | 5473 | "tmp.zig:2:31: error: index 2 outside array of size 2", |
| 5968 | | ); |
| 5474 | }); |
| 5969 | 5475 | |
| 5970 | | cases.add( |
| 5971 | | "wrong pointer coerced to pointer to @OpaqueType()", |
| 5476 | cases.add("wrong pointer coerced to pointer to @OpaqueType()", |
| 5972 | 5477 | \\const Derp = @OpaqueType(); |
| 5973 | 5478 | \\extern fn bar(d: *Derp) void; |
| 5974 | 5479 | \\export fn foo() void { |
| 5975 | 5480 | \\ var x = @as(u8, 1); |
| 5976 | 5481 | \\ bar(@ptrCast(*c_void, &x)); |
| 5977 | 5482 | \\} |
| 5978 | | , |
| 5483 | , &[_][]const u8{ |
| 5979 | 5484 | "tmp.zig:5:9: error: expected type '*Derp', found '*c_void'", |
| 5980 | | ); |
| 5485 | }); |
| 5981 | 5486 | |
| 5982 | | cases.add( |
| 5983 | | "non-const variables of things that require const variables", |
| 5487 | cases.add("non-const variables of things that require const variables", |
| 5984 | 5488 | \\export fn entry1() void { |
| 5985 | 5489 | \\ var m2 = &2; |
| 5986 | 5490 | \\} |
| ... | ... | @@ -6012,7 +5516,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6012 | 5516 | \\const Foo = struct { |
| 6013 | 5517 | \\ fn bar(self: *const Foo) void {} |
| 6014 | 5518 | \\}; |
| 6015 | | , |
| 5519 | , &[_][]const u8{ |
| 6016 | 5520 | "tmp.zig:2:4: error: variable of type '*comptime_int' must be const or comptime", |
| 6017 | 5521 | "tmp.zig:5:4: error: variable of type '(undefined)' must be const or comptime", |
| 6018 | 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 | 5526 | "tmp.zig:20:4: error: variable of type 'type' must be const or comptime", |
| 6023 | 5527 | "tmp.zig:23:4: error: variable of type '(bound fn(*const Foo) void)' must be const or comptime", |
| 6024 | 5528 | "tmp.zig:26:22: error: unreachable code", |
| 6025 | | ); |
| 5529 | }); |
| 6026 | 5530 | |
| 6027 | | cases.add( |
| 6028 | | "wrong types given to atomic order args in cmpxchg", |
| 5531 | cases.add("wrong types given to atomic order args in cmpxchg", |
| 6029 | 5532 | \\export fn entry() void { |
| 6030 | 5533 | \\ var x: i32 = 1234; |
| 6031 | 5534 | \\ while (!@cmpxchgWeak(i32, &x, 1234, 5678, @as(u32, 1234), @as(u32, 1234))) {} |
| 6032 | 5535 | \\} |
| 6033 | | , |
| 5536 | , &[_][]const u8{ |
| 6034 | 5537 | "tmp.zig:3:47: error: expected type 'std.builtin.AtomicOrder', found 'u32'", |
| 6035 | | ); |
| 5538 | }); |
| 6036 | 5539 | |
| 6037 | | cases.add( |
| 6038 | | "wrong types given to @export", |
| 5540 | cases.add("wrong types given to @export", |
| 6039 | 5541 | \\extern fn entry() void { } |
| 6040 | 5542 | \\comptime { |
| 6041 | 5543 | \\ @export("entry", entry, @as(u32, 1234)); |
| 6042 | 5544 | \\} |
| 6043 | | , |
| 5545 | , &[_][]const u8{ |
| 6044 | 5546 | "tmp.zig:3:29: error: expected type 'std.builtin.GlobalLinkage', found 'u32'", |
| 6045 | | ); |
| 5547 | }); |
| 6046 | 5548 | |
| 6047 | | cases.add( |
| 6048 | | "struct with invalid field", |
| 5549 | cases.add("struct with invalid field", |
| 6049 | 5550 | \\const std = @import("std",); |
| 6050 | 5551 | \\const Allocator = std.mem.Allocator; |
| 6051 | 5552 | \\const ArrayList = std.ArrayList; |
| ... | ... | @@ -6069,62 +5570,56 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6069 | 5570 | \\ .weight = HeaderWeight.H1, |
| 6070 | 5571 | \\ }; |
| 6071 | 5572 | \\} |
| 6072 | | , |
| 5573 | , &[_][]const u8{ |
| 6073 | 5574 | "tmp.zig:14:17: error: use of undeclared identifier 'HeaderValue'", |
| 6074 | | ); |
| 5575 | }); |
| 6075 | 5576 | |
| 6076 | | cases.add( |
| 6077 | | "@setAlignStack outside function", |
| 5577 | cases.add("@setAlignStack outside function", |
| 6078 | 5578 | \\comptime { |
| 6079 | 5579 | \\ @setAlignStack(16); |
| 6080 | 5580 | \\} |
| 6081 | | , |
| 5581 | , &[_][]const u8{ |
| 6082 | 5582 | "tmp.zig:2:5: error: @setAlignStack outside function", |
| 6083 | | ); |
| 5583 | }); |
| 6084 | 5584 | |
| 6085 | | cases.add( |
| 6086 | | "@setAlignStack in naked function", |
| 5585 | cases.add("@setAlignStack in naked function", |
| 6087 | 5586 | \\export nakedcc fn entry() void { |
| 6088 | 5587 | \\ @setAlignStack(16); |
| 6089 | 5588 | \\} |
| 6090 | | , |
| 5589 | , &[_][]const u8{ |
| 6091 | 5590 | "tmp.zig:2:5: error: @setAlignStack in naked function", |
| 6092 | | ); |
| 5591 | }); |
| 6093 | 5592 | |
| 6094 | | cases.add( |
| 6095 | | "@setAlignStack in inline function", |
| 5593 | cases.add("@setAlignStack in inline function", |
| 6096 | 5594 | \\export fn entry() void { |
| 6097 | 5595 | \\ foo(); |
| 6098 | 5596 | \\} |
| 6099 | 5597 | \\inline fn foo() void { |
| 6100 | 5598 | \\ @setAlignStack(16); |
| 6101 | 5599 | \\} |
| 6102 | | , |
| 5600 | , &[_][]const u8{ |
| 6103 | 5601 | "tmp.zig:5:5: error: @setAlignStack in inline function", |
| 6104 | | ); |
| 5602 | }); |
| 6105 | 5603 | |
| 6106 | | cases.add( |
| 6107 | | "@setAlignStack set twice", |
| 5604 | cases.add("@setAlignStack set twice", |
| 6108 | 5605 | \\export fn entry() void { |
| 6109 | 5606 | \\ @setAlignStack(16); |
| 6110 | 5607 | \\ @setAlignStack(16); |
| 6111 | 5608 | \\} |
| 6112 | | , |
| 5609 | , &[_][]const u8{ |
| 6113 | 5610 | "tmp.zig:3:5: error: alignstack set twice", |
| 6114 | 5611 | "tmp.zig:2:5: note: first set here", |
| 6115 | | ); |
| 5612 | }); |
| 6116 | 5613 | |
| 6117 | | cases.add( |
| 6118 | | "@setAlignStack too big", |
| 5614 | cases.add("@setAlignStack too big", |
| 6119 | 5615 | \\export fn entry() void { |
| 6120 | 5616 | \\ @setAlignStack(511 + 1); |
| 6121 | 5617 | \\} |
| 6122 | | , |
| 5618 | , &[_][]const u8{ |
| 6123 | 5619 | "tmp.zig:2:5: error: attempt to @setAlignStack(512); maximum is 256", |
| 6124 | | ); |
| 5620 | }); |
| 6125 | 5621 | |
| 6126 | | cases.add( |
| 6127 | | "storing runtime value in compile time variable then using it", |
| 5622 | cases.add("storing runtime value in compile time variable then using it", |
| 6128 | 5623 | \\const Mode = @import("builtin").Mode; |
| 6129 | 5624 | \\ |
| 6130 | 5625 | \\fn Free(comptime filename: []const u8) TestCase { |
| ... | ... | @@ -6166,12 +5661,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6166 | 5661 | \\ } |
| 6167 | 5662 | \\ } |
| 6168 | 5663 | \\} |
| 6169 | | , |
| 5664 | , &[_][]const u8{ |
| 6170 | 5665 | "tmp.zig:37:29: error: cannot store runtime value in compile time variable", |
| 6171 | | ); |
| 5666 | }); |
| 6172 | 5667 | |
| 6173 | | cases.add( |
| 6174 | | "field access of opaque type", |
| 5668 | cases.add("field access of opaque type", |
| 6175 | 5669 | \\const MyType = @OpaqueType(); |
| 6176 | 5670 | \\ |
| 6177 | 5671 | \\export fn entry() bool { |
| ... | ... | @@ -6182,163 +5676,143 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6182 | 5676 | \\fn bar(x: *MyType) bool { |
| 6183 | 5677 | \\ return x.blah; |
| 6184 | 5678 | \\} |
| 6185 | | , |
| 5679 | , &[_][]const u8{ |
| 6186 | 5680 | "tmp.zig:9:13: error: type '*MyType' does not support field access", |
| 6187 | | ); |
| 5681 | }); |
| 6188 | 5682 | |
| 6189 | | cases.add( |
| 6190 | | "carriage return special case", |
| 6191 | | "fn test() bool {\r\n" ++ |
| 6192 | | " true\r\n" ++ |
| 6193 | | "}\r\n", |
| 5683 | cases.add("carriage return special case", "fn test() bool {\r\n" ++ |
| 5684 | " true\r\n" ++ |
| 5685 | "}\r\n", &[_][]const u8{ |
| 6194 | 5686 | "tmp.zig:1:17: error: invalid carriage return, only '\\n' line endings are supported", |
| 6195 | | ); |
| 5687 | }); |
| 6196 | 5688 | |
| 6197 | | cases.add( |
| 6198 | | "invalid legacy unicode escape", |
| 5689 | cases.add("invalid legacy unicode escape", |
| 6199 | 5690 | \\export fn entry() void { |
| 6200 | 5691 | \\ const a = '\U1234'; |
| 6201 | 5692 | \\} |
| 6202 | | , |
| 5693 | , &[_][]const u8{ |
| 6203 | 5694 | "tmp.zig:2:17: error: invalid character: 'U'", |
| 6204 | | ); |
| 5695 | }); |
| 6205 | 5696 | |
| 6206 | | cases.add( |
| 6207 | | "invalid empty unicode escape", |
| 5697 | cases.add("invalid empty unicode escape", |
| 6208 | 5698 | \\export fn entry() void { |
| 6209 | 5699 | \\ const a = '\u{}'; |
| 6210 | 5700 | \\} |
| 6211 | | , |
| 5701 | , &[_][]const u8{ |
| 6212 | 5702 | "tmp.zig:2:19: error: empty unicode escape sequence", |
| 6213 | | ); |
| 5703 | }); |
| 6214 | 5704 | |
| 6215 | | cases.add( |
| 6216 | | "non-printable invalid character", |
| 6217 | | "\xff\xfe" ++ |
| 6218 | | \\fn test() bool {\r |
| 6219 | | \\ true\r |
| 6220 | | \\} |
| 6221 | | , |
| 5705 | cases.add("non-printable invalid character", "\xff\xfe" ++ |
| 5706 | \\fn test() bool {\r |
| 5707 | \\ true\r |
| 5708 | \\} |
| 5709 | , &[_][]const u8{ |
| 6222 | 5710 | "tmp.zig:1:1: error: invalid character: '\\xff'", |
| 6223 | | ); |
| 5711 | }); |
| 6224 | 5712 | |
| 6225 | | cases.add( |
| 6226 | | "non-printable invalid character with escape alternative", |
| 6227 | | "fn test() bool {\n" ++ |
| 6228 | | "\ttrue\n" ++ |
| 6229 | | "}\n", |
| 5713 | cases.add("non-printable invalid character with escape alternative", "fn test() bool {\n" ++ |
| 5714 | "\ttrue\n" ++ |
| 5715 | "}\n", &[_][]const u8{ |
| 6230 | 5716 | "tmp.zig:2:1: error: invalid character: '\\t'", |
| 6231 | | ); |
| 5717 | }); |
| 6232 | 5718 | |
| 6233 | | cases.add( |
| 6234 | | "@ArgType given non function parameter", |
| 5719 | cases.add("@ArgType given non function parameter", |
| 6235 | 5720 | \\comptime { |
| 6236 | 5721 | \\ _ = @ArgType(i32, 3); |
| 6237 | 5722 | \\} |
| 6238 | | , |
| 5723 | , &[_][]const u8{ |
| 6239 | 5724 | "tmp.zig:2:18: error: expected function, found 'i32'", |
| 6240 | | ); |
| 5725 | }); |
| 6241 | 5726 | |
| 6242 | | cases.add( |
| 6243 | | "@ArgType arg index out of bounds", |
| 5727 | cases.add("@ArgType arg index out of bounds", |
| 6244 | 5728 | \\comptime { |
| 6245 | 5729 | \\ _ = @ArgType(@typeOf(add), 2); |
| 6246 | 5730 | \\} |
| 6247 | 5731 | \\fn add(a: i32, b: i32) i32 { return a + b; } |
| 6248 | | , |
| 5732 | , &[_][]const u8{ |
| 6249 | 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( |
| 6253 | | "@memberType on unsupported type", |
| 5736 | cases.add("@memberType on unsupported type", |
| 6254 | 5737 | \\comptime { |
| 6255 | 5738 | \\ _ = @memberType(i32, 0); |
| 6256 | 5739 | \\} |
| 6257 | | , |
| 5740 | , &[_][]const u8{ |
| 6258 | 5741 | "tmp.zig:2:21: error: type 'i32' does not support @memberType", |
| 6259 | | ); |
| 5742 | }); |
| 6260 | 5743 | |
| 6261 | | cases.add( |
| 6262 | | "@memberType on enum", |
| 5744 | cases.add("@memberType on enum", |
| 6263 | 5745 | \\comptime { |
| 6264 | 5746 | \\ _ = @memberType(Foo, 0); |
| 6265 | 5747 | \\} |
| 6266 | 5748 | \\const Foo = enum {A,}; |
| 6267 | | , |
| 5749 | , &[_][]const u8{ |
| 6268 | 5750 | "tmp.zig:2:21: error: type 'Foo' does not support @memberType", |
| 6269 | | ); |
| 5751 | }); |
| 6270 | 5752 | |
| 6271 | | cases.add( |
| 6272 | | "@memberType struct out of bounds", |
| 5753 | cases.add("@memberType struct out of bounds", |
| 6273 | 5754 | \\comptime { |
| 6274 | 5755 | \\ _ = @memberType(Foo, 0); |
| 6275 | 5756 | \\} |
| 6276 | 5757 | \\const Foo = struct {}; |
| 6277 | | , |
| 5758 | , &[_][]const u8{ |
| 6278 | 5759 | "tmp.zig:2:26: error: member index 0 out of bounds; 'Foo' has 0 members", |
| 6279 | | ); |
| 5760 | }); |
| 6280 | 5761 | |
| 6281 | | cases.add( |
| 6282 | | "@memberType union out of bounds", |
| 5762 | cases.add("@memberType union out of bounds", |
| 6283 | 5763 | \\comptime { |
| 6284 | 5764 | \\ _ = @memberType(Foo, 1); |
| 6285 | 5765 | \\} |
| 6286 | 5766 | \\const Foo = union {A: void,}; |
| 6287 | | , |
| 5767 | , &[_][]const u8{ |
| 6288 | 5768 | "tmp.zig:2:26: error: member index 1 out of bounds; 'Foo' has 1 members", |
| 6289 | | ); |
| 5769 | }); |
| 6290 | 5770 | |
| 6291 | | cases.add( |
| 6292 | | "@memberName on unsupported type", |
| 5771 | cases.add("@memberName on unsupported type", |
| 6293 | 5772 | \\comptime { |
| 6294 | 5773 | \\ _ = @memberName(i32, 0); |
| 6295 | 5774 | \\} |
| 6296 | | , |
| 5775 | , &[_][]const u8{ |
| 6297 | 5776 | "tmp.zig:2:21: error: type 'i32' does not support @memberName", |
| 6298 | | ); |
| 5777 | }); |
| 6299 | 5778 | |
| 6300 | | cases.add( |
| 6301 | | "@memberName struct out of bounds", |
| 5779 | cases.add("@memberName struct out of bounds", |
| 6302 | 5780 | \\comptime { |
| 6303 | 5781 | \\ _ = @memberName(Foo, 0); |
| 6304 | 5782 | \\} |
| 6305 | 5783 | \\const Foo = struct {}; |
| 6306 | | , |
| 5784 | , &[_][]const u8{ |
| 6307 | 5785 | "tmp.zig:2:26: error: member index 0 out of bounds; 'Foo' has 0 members", |
| 6308 | | ); |
| 5786 | }); |
| 6309 | 5787 | |
| 6310 | | cases.add( |
| 6311 | | "@memberName enum out of bounds", |
| 5788 | cases.add("@memberName enum out of bounds", |
| 6312 | 5789 | \\comptime { |
| 6313 | 5790 | \\ _ = @memberName(Foo, 1); |
| 6314 | 5791 | \\} |
| 6315 | 5792 | \\const Foo = enum {A,}; |
| 6316 | | , |
| 5793 | , &[_][]const u8{ |
| 6317 | 5794 | "tmp.zig:2:26: error: member index 1 out of bounds; 'Foo' has 1 members", |
| 6318 | | ); |
| 5795 | }); |
| 6319 | 5796 | |
| 6320 | | cases.add( |
| 6321 | | "@memberName union out of bounds", |
| 5797 | cases.add("@memberName union out of bounds", |
| 6322 | 5798 | \\comptime { |
| 6323 | 5799 | \\ _ = @memberName(Foo, 1); |
| 6324 | 5800 | \\} |
| 6325 | 5801 | \\const Foo = union {A:i32,}; |
| 6326 | | , |
| 5802 | , &[_][]const u8{ |
| 6327 | 5803 | "tmp.zig:2:26: error: member index 1 out of bounds; 'Foo' has 1 members", |
| 6328 | | ); |
| 5804 | }); |
| 6329 | 5805 | |
| 6330 | | cases.add( |
| 6331 | | "calling var args extern function, passing array instead of pointer", |
| 5806 | cases.add("calling var args extern function, passing array instead of pointer", |
| 6332 | 5807 | \\export fn entry() void { |
| 6333 | 5808 | \\ foo("hello".*,); |
| 6334 | 5809 | \\} |
| 6335 | 5810 | \\pub extern fn foo(format: *const u8, ...) void; |
| 6336 | | , |
| 5811 | , &[_][]const u8{ |
| 6337 | 5812 | "tmp.zig:2:16: error: expected type '*const u8', found '[5:0]u8'", |
| 6338 | | ); |
| 5813 | }); |
| 6339 | 5814 | |
| 6340 | | cases.add( |
| 6341 | | "constant inside comptime function has compile error", |
| 5815 | cases.add("constant inside comptime function has compile error", |
| 6342 | 5816 | \\const ContextAllocator = MemoryPool(usize); |
| 6343 | 5817 | \\ |
| 6344 | 5818 | \\pub fn MemoryPool(comptime T: type) type { |
| ... | ... | @@ -6352,11 +5826,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6352 | 5826 | \\export fn entry() void { |
| 6353 | 5827 | \\ var allocator: ContextAllocator = undefined; |
| 6354 | 5828 | \\} |
| 6355 | | , |
| 5829 | , &[_][]const u8{ |
| 6356 | 5830 | "tmp.zig:4:25: error: aoeu", |
| 6357 | 5831 | "tmp.zig:1:36: note: referenced here", |
| 6358 | 5832 | "tmp.zig:12:20: note: referenced here", |
| 6359 | | ); |
| 5833 | }); |
| 6360 | 5834 | |
| 6361 | 5835 | cases.add("specify enum tag type that is too small", |
| 6362 | 5836 | \\const Small = enum (u2) { |
| ... | ... | @@ -6370,10 +5844,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6370 | 5844 | \\export fn entry() void { |
| 6371 | 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( |
| 6376 | | "specify non-integer enum tag type", |
| 5851 | cases.add("specify non-integer enum tag type", |
| 6377 | 5852 | \\const Small = enum (f32) { |
| 6378 | 5853 | \\ One, |
| 6379 | 5854 | \\ Two, |
| ... | ... | @@ -6383,12 +5858,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6383 | 5858 | \\export fn entry() void { |
| 6384 | 5859 | \\ var x = Small.One; |
| 6385 | 5860 | \\} |
| 6386 | | , |
| 5861 | , &[_][]const u8{ |
| 6387 | 5862 | "tmp.zig:1:21: error: expected integer, found 'f32'", |
| 6388 | | ); |
| 5863 | }); |
| 6389 | 5864 | |
| 6390 | | cases.add( |
| 6391 | | "implicitly casting enum to tag type", |
| 5865 | cases.add("implicitly casting enum to tag type", |
| 6392 | 5866 | \\const Small = enum(u2) { |
| 6393 | 5867 | \\ One, |
| 6394 | 5868 | \\ Two, |
| ... | ... | @@ -6399,12 +5873,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6399 | 5873 | \\export fn entry() void { |
| 6400 | 5874 | \\ var x: u2 = Small.Two; |
| 6401 | 5875 | \\} |
| 6402 | | , |
| 5876 | , &[_][]const u8{ |
| 6403 | 5877 | "tmp.zig:9:22: error: expected type 'u2', found 'Small'", |
| 6404 | | ); |
| 5878 | }); |
| 6405 | 5879 | |
| 6406 | | cases.add( |
| 6407 | | "explicitly casting non tag type to enum", |
| 5880 | cases.add("explicitly casting non tag type to enum", |
| 6408 | 5881 | \\const Small = enum(u2) { |
| 6409 | 5882 | \\ One, |
| 6410 | 5883 | \\ Two, |
| ... | ... | @@ -6416,45 +5889,41 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6416 | 5889 | \\ var y = @as(u3, 3); |
| 6417 | 5890 | \\ var x = @intToEnum(Small, y); |
| 6418 | 5891 | \\} |
| 6419 | | , |
| 5892 | , &[_][]const u8{ |
| 6420 | 5893 | "tmp.zig:10:31: error: expected type 'u2', found 'u3'", |
| 6421 | | ); |
| 5894 | }); |
| 6422 | 5895 | |
| 6423 | | cases.add( |
| 6424 | | "union fields with value assignments", |
| 5896 | cases.add("union fields with value assignments", |
| 6425 | 5897 | \\const MultipleChoice = union { |
| 6426 | 5898 | \\ A: i32 = 20, |
| 6427 | 5899 | \\}; |
| 6428 | 5900 | \\export fn entry() void { |
| 6429 | 5901 | \\ var x: MultipleChoice = undefined; |
| 6430 | 5902 | \\} |
| 6431 | | , |
| 5903 | , &[_][]const u8{ |
| 6432 | 5904 | "tmp.zig:2:14: error: untagged union field assignment", |
| 6433 | 5905 | "tmp.zig:1:24: note: consider 'union(enum)' here", |
| 6434 | | ); |
| 5906 | }); |
| 6435 | 5907 | |
| 6436 | | cases.add( |
| 6437 | | "enum with 0 fields", |
| 5908 | cases.add("enum with 0 fields", |
| 6438 | 5909 | \\const Foo = enum {}; |
| 6439 | 5910 | \\export fn entry() usize { |
| 6440 | 5911 | \\ return @sizeOf(Foo); |
| 6441 | 5912 | \\} |
| 6442 | | , |
| 5913 | , &[_][]const u8{ |
| 6443 | 5914 | "tmp.zig:1:13: error: enums must have 1 or more fields", |
| 6444 | | ); |
| 5915 | }); |
| 6445 | 5916 | |
| 6446 | | cases.add( |
| 6447 | | "union with 0 fields", |
| 5917 | cases.add("union with 0 fields", |
| 6448 | 5918 | \\const Foo = union {}; |
| 6449 | 5919 | \\export fn entry() usize { |
| 6450 | 5920 | \\ return @sizeOf(Foo); |
| 6451 | 5921 | \\} |
| 6452 | | , |
| 5922 | , &[_][]const u8{ |
| 6453 | 5923 | "tmp.zig:1:13: error: unions must have 1 or more fields", |
| 6454 | | ); |
| 5924 | }); |
| 6455 | 5925 | |
| 6456 | | cases.add( |
| 6457 | | "enum value already taken", |
| 5926 | cases.add("enum value already taken", |
| 6458 | 5927 | \\const MultipleChoice = enum(u32) { |
| 6459 | 5928 | \\ A = 20, |
| 6460 | 5929 | \\ B = 40, |
| ... | ... | @@ -6465,13 +5934,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6465 | 5934 | \\export fn entry() void { |
| 6466 | 5935 | \\ var x = MultipleChoice.C; |
| 6467 | 5936 | \\} |
| 6468 | | , |
| 5937 | , &[_][]const u8{ |
| 6469 | 5938 | "tmp.zig:6:5: error: enum tag value 60 already taken", |
| 6470 | 5939 | "tmp.zig:4:5: note: other occurrence here", |
| 6471 | | ); |
| 5940 | }); |
| 6472 | 5941 | |
| 6473 | | cases.add( |
| 6474 | | "union with specified enum omits field", |
| 5942 | cases.add("union with specified enum omits field", |
| 6475 | 5943 | \\const Letter = enum { |
| 6476 | 5944 | \\ A, |
| 6477 | 5945 | \\ B, |
| ... | ... | @@ -6484,50 +5952,46 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6484 | 5952 | \\export fn entry() usize { |
| 6485 | 5953 | \\ return @sizeOf(Payload); |
| 6486 | 5954 | \\} |
| 6487 | | , |
| 5955 | , &[_][]const u8{ |
| 6488 | 5956 | "tmp.zig:6:17: error: enum field missing: 'C'", |
| 6489 | 5957 | "tmp.zig:4:5: note: declared here", |
| 6490 | | ); |
| 5958 | }); |
| 6491 | 5959 | |
| 6492 | | cases.add( |
| 6493 | | "@TagType when union has no attached enum", |
| 5960 | cases.add("@TagType when union has no attached enum", |
| 6494 | 5961 | \\const Foo = union { |
| 6495 | 5962 | \\ A: i32, |
| 6496 | 5963 | \\}; |
| 6497 | 5964 | \\export fn entry() void { |
| 6498 | 5965 | \\ const x = @TagType(Foo); |
| 6499 | 5966 | \\} |
| 6500 | | , |
| 5967 | , &[_][]const u8{ |
| 6501 | 5968 | "tmp.zig:5:24: error: union 'Foo' has no tag", |
| 6502 | 5969 | "tmp.zig:1:13: note: consider 'union(enum)' here", |
| 6503 | | ); |
| 5970 | }); |
| 6504 | 5971 | |
| 6505 | | cases.add( |
| 6506 | | "non-integer tag type to automatic union enum", |
| 5972 | cases.add("non-integer tag type to automatic union enum", |
| 6507 | 5973 | \\const Foo = union(enum(f32)) { |
| 6508 | 5974 | \\ A: i32, |
| 6509 | 5975 | \\}; |
| 6510 | 5976 | \\export fn entry() void { |
| 6511 | 5977 | \\ const x = @TagType(Foo); |
| 6512 | 5978 | \\} |
| 6513 | | , |
| 5979 | , &[_][]const u8{ |
| 6514 | 5980 | "tmp.zig:1:24: error: expected integer tag type, found 'f32'", |
| 6515 | | ); |
| 5981 | }); |
| 6516 | 5982 | |
| 6517 | | cases.add( |
| 6518 | | "non-enum tag type passed to union", |
| 5983 | cases.add("non-enum tag type passed to union", |
| 6519 | 5984 | \\const Foo = union(u32) { |
| 6520 | 5985 | \\ A: i32, |
| 6521 | 5986 | \\}; |
| 6522 | 5987 | \\export fn entry() void { |
| 6523 | 5988 | \\ const x = @TagType(Foo); |
| 6524 | 5989 | \\} |
| 6525 | | , |
| 5990 | , &[_][]const u8{ |
| 6526 | 5991 | "tmp.zig:1:19: error: expected enum tag type, found 'u32'", |
| 6527 | | ); |
| 5992 | }); |
| 6528 | 5993 | |
| 6529 | | cases.add( |
| 6530 | | "union auto-enum value already taken", |
| 5994 | cases.add("union auto-enum value already taken", |
| 6531 | 5995 | \\const MultipleChoice = union(enum(u32)) { |
| 6532 | 5996 | \\ A = 20, |
| 6533 | 5997 | \\ B = 40, |
| ... | ... | @@ -6538,13 +6002,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6538 | 6002 | \\export fn entry() void { |
| 6539 | 6003 | \\ var x = MultipleChoice { .C = {} }; |
| 6540 | 6004 | \\} |
| 6541 | | , |
| 6005 | , &[_][]const u8{ |
| 6542 | 6006 | "tmp.zig:6:9: error: enum tag value 60 already taken", |
| 6543 | 6007 | "tmp.zig:4:9: note: other occurrence here", |
| 6544 | | ); |
| 6008 | }); |
| 6545 | 6009 | |
| 6546 | | cases.add( |
| 6547 | | "union enum field does not match enum", |
| 6010 | cases.add("union enum field does not match enum", |
| 6548 | 6011 | \\const Letter = enum { |
| 6549 | 6012 | \\ A, |
| 6550 | 6013 | \\ B, |
| ... | ... | @@ -6559,13 +6022,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6559 | 6022 | \\export fn entry() void { |
| 6560 | 6023 | \\ var a = Payload {.A = 1234}; |
| 6561 | 6024 | \\} |
| 6562 | | , |
| 6025 | , &[_][]const u8{ |
| 6563 | 6026 | "tmp.zig:10:5: error: enum field not found: 'D'", |
| 6564 | 6027 | "tmp.zig:1:16: note: enum declared here", |
| 6565 | | ); |
| 6028 | }); |
| 6566 | 6029 | |
| 6567 | | cases.add( |
| 6568 | | "field type supplied in an enum", |
| 6030 | cases.add("field type supplied in an enum", |
| 6569 | 6031 | \\const Letter = enum { |
| 6570 | 6032 | \\ A: void, |
| 6571 | 6033 | \\ B, |
| ... | ... | @@ -6574,37 +6036,34 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6574 | 6036 | \\export fn entry() void { |
| 6575 | 6037 | \\ var b = Letter.B; |
| 6576 | 6038 | \\} |
| 6577 | | , |
| 6039 | , &[_][]const u8{ |
| 6578 | 6040 | "tmp.zig:2:8: error: structs and unions, not enums, support field types", |
| 6579 | 6041 | "tmp.zig:1:16: note: consider 'union(enum)' here", |
| 6580 | | ); |
| 6042 | }); |
| 6581 | 6043 | |
| 6582 | | cases.add( |
| 6583 | | "struct field missing type", |
| 6044 | cases.add("struct field missing type", |
| 6584 | 6045 | \\const Letter = struct { |
| 6585 | 6046 | \\ A, |
| 6586 | 6047 | \\}; |
| 6587 | 6048 | \\export fn entry() void { |
| 6588 | 6049 | \\ var a = Letter { .A = {} }; |
| 6589 | 6050 | \\} |
| 6590 | | , |
| 6051 | , &[_][]const u8{ |
| 6591 | 6052 | "tmp.zig:2:5: error: struct field missing type", |
| 6592 | | ); |
| 6053 | }); |
| 6593 | 6054 | |
| 6594 | | cases.add( |
| 6595 | | "extern union field missing type", |
| 6055 | cases.add("extern union field missing type", |
| 6596 | 6056 | \\const Letter = extern union { |
| 6597 | 6057 | \\ A, |
| 6598 | 6058 | \\}; |
| 6599 | 6059 | \\export fn entry() void { |
| 6600 | 6060 | \\ var a = Letter { .A = {} }; |
| 6601 | 6061 | \\} |
| 6602 | | , |
| 6062 | , &[_][]const u8{ |
| 6603 | 6063 | "tmp.zig:2:5: error: union field missing type", |
| 6604 | | ); |
| 6064 | }); |
| 6605 | 6065 | |
| 6606 | | cases.add( |
| 6607 | | "extern union given enum tag type", |
| 6066 | cases.add("extern union given enum tag type", |
| 6608 | 6067 | \\const Letter = enum { |
| 6609 | 6068 | \\ A, |
| 6610 | 6069 | \\ B, |
| ... | ... | @@ -6618,12 +6077,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6618 | 6077 | \\export fn entry() void { |
| 6619 | 6078 | \\ var a = Payload { .A = 1234 }; |
| 6620 | 6079 | \\} |
| 6621 | | , |
| 6080 | , &[_][]const u8{ |
| 6622 | 6081 | "tmp.zig:6:30: error: extern union does not support enum tag type", |
| 6623 | | ); |
| 6082 | }); |
| 6624 | 6083 | |
| 6625 | | cases.add( |
| 6626 | | "packed union given enum tag type", |
| 6084 | cases.add("packed union given enum tag type", |
| 6627 | 6085 | \\const Letter = enum { |
| 6628 | 6086 | \\ A, |
| 6629 | 6087 | \\ B, |
| ... | ... | @@ -6637,12 +6095,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6637 | 6095 | \\export fn entry() void { |
| 6638 | 6096 | \\ var a = Payload { .A = 1234 }; |
| 6639 | 6097 | \\} |
| 6640 | | , |
| 6098 | , &[_][]const u8{ |
| 6641 | 6099 | "tmp.zig:6:30: error: packed union does not support enum tag type", |
| 6642 | | ); |
| 6100 | }); |
| 6643 | 6101 | |
| 6644 | | cases.add( |
| 6645 | | "packed union with automatic layout field", |
| 6102 | cases.add("packed union with automatic layout field", |
| 6646 | 6103 | \\const Foo = struct { |
| 6647 | 6104 | \\ a: u32, |
| 6648 | 6105 | \\ b: f32, |
| ... | ... | @@ -6654,12 +6111,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6654 | 6111 | \\export fn entry() void { |
| 6655 | 6112 | \\ var a = Payload { .B = true }; |
| 6656 | 6113 | \\} |
| 6657 | | , |
| 6114 | , &[_][]const u8{ |
| 6658 | 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( |
| 6662 | | "switch on union with no attached enum", |
| 6118 | cases.add("switch on union with no attached enum", |
| 6663 | 6119 | \\const Payload = union { |
| 6664 | 6120 | \\ A: i32, |
| 6665 | 6121 | \\ B: f64, |
| ... | ... | @@ -6675,13 +6131,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6675 | 6131 | \\ else => unreachable, |
| 6676 | 6132 | \\ } |
| 6677 | 6133 | \\} |
| 6678 | | , |
| 6134 | , &[_][]const u8{ |
| 6679 | 6135 | "tmp.zig:11:14: error: switch on union which has no attached enum", |
| 6680 | 6136 | "tmp.zig:1:17: note: consider 'union(enum)' here", |
| 6681 | | ); |
| 6137 | }); |
| 6682 | 6138 | |
| 6683 | | cases.add( |
| 6684 | | "enum in field count range but not matching tag", |
| 6139 | cases.add("enum in field count range but not matching tag", |
| 6685 | 6140 | \\const Foo = enum(u32) { |
| 6686 | 6141 | \\ A = 10, |
| 6687 | 6142 | \\ B = 11, |
| ... | ... | @@ -6689,13 +6144,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6689 | 6144 | \\export fn entry() void { |
| 6690 | 6145 | \\ var x = @intToEnum(Foo, 0); |
| 6691 | 6146 | \\} |
| 6692 | | , |
| 6147 | , &[_][]const u8{ |
| 6693 | 6148 | "tmp.zig:6:13: error: enum 'Foo' has no tag matching integer value 0", |
| 6694 | 6149 | "tmp.zig:1:13: note: 'Foo' declared here", |
| 6695 | | ); |
| 6150 | }); |
| 6696 | 6151 | |
| 6697 | | cases.add( |
| 6698 | | "comptime cast enum to union but field has payload", |
| 6152 | cases.add("comptime cast enum to union but field has payload", |
| 6699 | 6153 | \\const Letter = enum { A, B, C }; |
| 6700 | 6154 | \\const Value = union(Letter) { |
| 6701 | 6155 | \\ A: i32, |
| ... | ... | @@ -6705,13 +6159,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6705 | 6159 | \\export fn entry() void { |
| 6706 | 6160 | \\ var x: Value = Letter.A; |
| 6707 | 6161 | \\} |
| 6708 | | , |
| 6162 | , &[_][]const u8{ |
| 6709 | 6163 | "tmp.zig:8:26: error: cast to union 'Value' must initialize 'i32' field 'A'", |
| 6710 | 6164 | "tmp.zig:3:5: note: field 'A' declared here", |
| 6711 | | ); |
| 6165 | }); |
| 6712 | 6166 | |
| 6713 | | cases.add( |
| 6714 | | "runtime cast to union which has non-void fields", |
| 6167 | cases.add("runtime cast to union which has non-void fields", |
| 6715 | 6168 | \\const Letter = enum { A, B, C }; |
| 6716 | 6169 | \\const Value = union(Letter) { |
| 6717 | 6170 | \\ A: i32, |
| ... | ... | @@ -6724,37 +6177,34 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6724 | 6177 | \\fn foo(l: Letter) void { |
| 6725 | 6178 | \\ var x: Value = l; |
| 6726 | 6179 | \\} |
| 6727 | | , |
| 6180 | , &[_][]const u8{ |
| 6728 | 6181 | "tmp.zig:11:20: error: runtime cast to union 'Value' which has non-void fields", |
| 6729 | 6182 | "tmp.zig:3:5: note: field 'A' has type 'i32'", |
| 6730 | | ); |
| 6183 | }); |
| 6731 | 6184 | |
| 6732 | | cases.add( |
| 6733 | | "taking byte offset of void field in struct", |
| 6185 | cases.add("taking byte offset of void field in struct", |
| 6734 | 6186 | \\const Empty = struct { |
| 6735 | 6187 | \\ val: void, |
| 6736 | 6188 | \\}; |
| 6737 | 6189 | \\export fn foo() void { |
| 6738 | 6190 | \\ const fieldOffset = @byteOffsetOf(Empty, "val",); |
| 6739 | 6191 | \\} |
| 6740 | | , |
| 6192 | , &[_][]const u8{ |
| 6741 | 6193 | "tmp.zig:5:46: error: zero-bit field 'val' in struct 'Empty' has no offset", |
| 6742 | | ); |
| 6194 | }); |
| 6743 | 6195 | |
| 6744 | | cases.add( |
| 6745 | | "taking bit offset of void field in struct", |
| 6196 | cases.add("taking bit offset of void field in struct", |
| 6746 | 6197 | \\const Empty = struct { |
| 6747 | 6198 | \\ val: void, |
| 6748 | 6199 | \\}; |
| 6749 | 6200 | \\export fn foo() void { |
| 6750 | 6201 | \\ const fieldOffset = @bitOffsetOf(Empty, "val",); |
| 6751 | 6202 | \\} |
| 6752 | | , |
| 6203 | , &[_][]const u8{ |
| 6753 | 6204 | "tmp.zig:5:45: error: zero-bit field 'val' in struct 'Empty' has no offset", |
| 6754 | | ); |
| 6205 | }); |
| 6755 | 6206 | |
| 6756 | | cases.add( |
| 6757 | | "invalid union field access in comptime", |
| 6207 | cases.add("invalid union field access in comptime", |
| 6758 | 6208 | \\const Foo = union { |
| 6759 | 6209 | \\ Bar: u8, |
| 6760 | 6210 | \\ Baz: void, |
| ... | ... | @@ -6763,60 +6213,54 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6763 | 6213 | \\ var foo = Foo {.Baz = {}}; |
| 6764 | 6214 | \\ const bar_val = foo.Bar; |
| 6765 | 6215 | \\} |
| 6766 | | , |
| 6216 | , &[_][]const u8{ |
| 6767 | 6217 | "tmp.zig:7:24: error: accessing union field 'Bar' while field 'Baz' is set", |
| 6768 | | ); |
| 6218 | }); |
| 6769 | 6219 | |
| 6770 | | cases.add( |
| 6771 | | "getting return type of generic function", |
| 6220 | cases.add("getting return type of generic function", |
| 6772 | 6221 | \\fn generic(a: var) void {} |
| 6773 | 6222 | \\comptime { |
| 6774 | 6223 | \\ _ = @typeOf(generic).ReturnType; |
| 6775 | 6224 | \\} |
| 6776 | | , |
| 6225 | , &[_][]const u8{ |
| 6777 | 6226 | "tmp.zig:3:25: error: ReturnType has not been resolved because 'fn(var)var' is generic", |
| 6778 | | ); |
| 6227 | }); |
| 6779 | 6228 | |
| 6780 | | cases.add( |
| 6781 | | "getting @ArgType of generic function", |
| 6229 | cases.add("getting @ArgType of generic function", |
| 6782 | 6230 | \\fn generic(a: var) void {} |
| 6783 | 6231 | \\comptime { |
| 6784 | 6232 | \\ _ = @ArgType(@typeOf(generic), 0); |
| 6785 | 6233 | \\} |
| 6786 | | , |
| 6234 | , &[_][]const u8{ |
| 6787 | 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( |
| 6791 | | "unsupported modifier at start of asm output constraint", |
| 6238 | cases.add("unsupported modifier at start of asm output constraint", |
| 6792 | 6239 | \\export fn foo() void { |
| 6793 | 6240 | \\ var bar: u32 = 3; |
| 6794 | 6241 | \\ asm volatile ("" : [baz]"+r"(bar) : : ""); |
| 6795 | 6242 | \\} |
| 6796 | | , |
| 6243 | , &[_][]const u8{ |
| 6797 | 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( |
| 6801 | | "comptime_int in asm input", |
| 6247 | cases.add("comptime_int in asm input", |
| 6802 | 6248 | \\export fn foo() void { |
| 6803 | 6249 | \\ asm volatile ("" : : [bar]"r"(3) : ""); |
| 6804 | 6250 | \\} |
| 6805 | | , |
| 6251 | , &[_][]const u8{ |
| 6806 | 6252 | "tmp.zig:2:35: error: expected sized integer or sized float, found comptime_int", |
| 6807 | | ); |
| 6253 | }); |
| 6808 | 6254 | |
| 6809 | | cases.add( |
| 6810 | | "comptime_float in asm input", |
| 6255 | cases.add("comptime_float in asm input", |
| 6811 | 6256 | \\export fn foo() void { |
| 6812 | 6257 | \\ asm volatile ("" : : [bar]"r"(3.17) : ""); |
| 6813 | 6258 | \\} |
| 6814 | | , |
| 6259 | , &[_][]const u8{ |
| 6815 | 6260 | "tmp.zig:2:35: error: expected sized integer or sized float, found comptime_float", |
| 6816 | | ); |
| 6261 | }); |
| 6817 | 6262 | |
| 6818 | | cases.add( |
| 6819 | | "runtime assignment to comptime struct type", |
| 6263 | cases.add("runtime assignment to comptime struct type", |
| 6820 | 6264 | \\const Foo = struct { |
| 6821 | 6265 | \\ Bar: u8, |
| 6822 | 6266 | \\ Baz: type, |
| ... | ... | @@ -6825,12 +6269,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6825 | 6269 | \\ var x: u8 = 0; |
| 6826 | 6270 | \\ const foo = Foo { .Bar = x, .Baz = u8 }; |
| 6827 | 6271 | \\} |
| 6828 | | , |
| 6272 | , &[_][]const u8{ |
| 6829 | 6273 | "tmp.zig:7:23: error: unable to evaluate constant expression", |
| 6830 | | ); |
| 6274 | }); |
| 6831 | 6275 | |
| 6832 | | cases.add( |
| 6833 | | "runtime assignment to comptime union type", |
| 6276 | cases.add("runtime assignment to comptime union type", |
| 6834 | 6277 | \\const Foo = union { |
| 6835 | 6278 | \\ Bar: u8, |
| 6836 | 6279 | \\ Baz: type, |
| ... | ... | @@ -6839,42 +6282,39 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6839 | 6282 | \\ var x: u8 = 0; |
| 6840 | 6283 | \\ const foo = Foo { .Bar = x }; |
| 6841 | 6284 | \\} |
| 6842 | | , |
| 6285 | , &[_][]const u8{ |
| 6843 | 6286 | "tmp.zig:7:23: error: unable to evaluate constant expression", |
| 6844 | | ); |
| 6287 | }); |
| 6845 | 6288 | |
| 6846 | | cases.addTest( |
| 6847 | | "@shuffle with selected index past first vector length", |
| 6289 | cases.addTest("@shuffle with selected index past first vector length", |
| 6848 | 6290 | \\export fn entry() void { |
| 6849 | 6291 | \\ const v: @Vector(4, u32) = [4]u32{ 10, 11, 12, 13 }; |
| 6850 | 6292 | \\ const x: @Vector(4, u32) = [4]u32{ 14, 15, 16, 17 }; |
| 6851 | 6293 | \\ var z = @shuffle(u32, v, x, [8]i32{ 0, 1, 2, 3, 7, 6, 5, 4 }); |
| 6852 | 6294 | \\} |
| 6853 | | , |
| 6295 | , &[_][]const u8{ |
| 6854 | 6296 | "tmp.zig:4:39: error: mask index '4' has out-of-bounds selection", |
| 6855 | 6297 | "tmp.zig:4:27: note: selected index '7' out of bounds of @Vector(4, u32)", |
| 6856 | 6298 | "tmp.zig:4:30: note: selections from the second vector are specified with negative numbers", |
| 6857 | | ); |
| 6299 | }); |
| 6858 | 6300 | |
| 6859 | | cases.addTest( |
| 6860 | | "nested vectors", |
| 6301 | cases.addTest("nested vectors", |
| 6861 | 6302 | \\export fn entry() void { |
| 6862 | 6303 | \\ const V = @Vector(4, @Vector(4, u8)); |
| 6863 | 6304 | \\ var v: V = undefined; |
| 6864 | 6305 | \\} |
| 6865 | | , |
| 6306 | , &[_][]const u8{ |
| 6866 | 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( |
| 6870 | | "bad @splat type", |
| 6310 | cases.addTest("bad @splat type", |
| 6871 | 6311 | \\export fn entry() void { |
| 6872 | 6312 | \\ const c = 4; |
| 6873 | 6313 | \\ var v = @splat(4, c); |
| 6874 | 6314 | \\} |
| 6875 | | , |
| 6315 | , &[_][]const u8{ |
| 6876 | 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 | 6319 | cases.add("compileLog of tagged enum doesn't crash the compiler", |
| 6880 | 6320 | \\const Bar = union(enum(u32)) { |
| ... | ... | @@ -6888,33 +6328,32 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6888 | 6328 | \\pub fn main () void { |
| 6889 | 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( |
| 6894 | | "attempted implicit cast from *const T to *[1]T", |
| 6335 | cases.add("attempted implicit cast from *const T to *[1]T", |
| 6895 | 6336 | \\export fn entry(byte: u8) void { |
| 6896 | 6337 | \\ const w: i32 = 1234; |
| 6897 | 6338 | \\ var x: *const i32 = &w; |
| 6898 | 6339 | \\ var y: *[1]i32 = x; |
| 6899 | 6340 | \\ y[0] += 1; |
| 6900 | 6341 | \\} |
| 6901 | | , |
| 6342 | , &[_][]const u8{ |
| 6902 | 6343 | "tmp.zig:4:22: error: expected type '*[1]i32', found '*const i32'", |
| 6903 | 6344 | "tmp.zig:4:22: note: cast discards const qualifier", |
| 6904 | | ); |
| 6345 | }); |
| 6905 | 6346 | |
| 6906 | | cases.add( |
| 6907 | | "attempted implicit cast from *const T to []T", |
| 6347 | cases.add("attempted implicit cast from *const T to []T", |
| 6908 | 6348 | \\export fn entry() void { |
| 6909 | 6349 | \\ const u: u32 = 42; |
| 6910 | 6350 | \\ const x: []u32 = &u; |
| 6911 | 6351 | \\} |
| 6912 | | , |
| 6352 | , &[_][]const u8{ |
| 6913 | 6353 | "tmp.zig:3:23: error: expected type '[]u32', found '*const u32'", |
| 6914 | | ); |
| 6354 | }); |
| 6915 | 6355 | |
| 6916 | | cases.add( |
| 6917 | | "for loop body expression ignored", |
| 6356 | cases.add("for loop body expression ignored", |
| 6918 | 6357 | \\fn returns() usize { |
| 6919 | 6358 | \\ return 2; |
| 6920 | 6359 | \\} |
| ... | ... | @@ -6925,37 +6364,35 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6925 | 6364 | \\ var x: anyerror!i32 = error.Bad; |
| 6926 | 6365 | \\ for ("hello") |_| returns() else unreachable; |
| 6927 | 6366 | \\} |
| 6928 | | , |
| 6367 | , &[_][]const u8{ |
| 6929 | 6368 | "tmp.zig:5:30: error: expression value is ignored", |
| 6930 | 6369 | "tmp.zig:9:30: error: expression value is ignored", |
| 6931 | | ); |
| 6370 | }); |
| 6932 | 6371 | |
| 6933 | | cases.add( |
| 6934 | | "aligned variable of zero-bit type", |
| 6372 | cases.add("aligned variable of zero-bit type", |
| 6935 | 6373 | \\export fn f() void { |
| 6936 | 6374 | \\ var s: struct {} align(4) = undefined; |
| 6937 | 6375 | \\} |
| 6938 | | , |
| 6376 | , &[_][]const u8{ |
| 6939 | 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( |
| 6943 | | "function returning opaque type", |
| 6380 | cases.add("function returning opaque type", |
| 6944 | 6381 | \\const FooType = @OpaqueType(); |
| 6945 | 6382 | \\export fn bar() !FooType { |
| 6946 | 6383 | \\ return error.InvalidValue; |
| 6947 | 6384 | \\} |
| 6948 | | , |
| 6385 | , &[_][]const u8{ |
| 6949 | 6386 | "tmp.zig:2:18: error: opaque return type 'FooType' not allowed", |
| 6950 | 6387 | "tmp.zig:1:1: note: declared here", |
| 6951 | | ); |
| 6388 | }); |
| 6952 | 6389 | |
| 6953 | 6390 | cases.add( // fixed bug #2032 |
| 6954 | 6391 | "compile diagnostic string for top level decl type", |
| 6955 | 6392 | \\export fn entry() void { |
| 6956 | 6393 | \\ var foo: u32 = @This(){}; |
| 6957 | 6394 | \\} |
| 6958 | | , |
| 6395 | , &[_][]const u8{ |
| 6959 | 6396 | "tmp.zig:2:27: error: type 'u32' does not support array initialization", |
| 6960 | | ); |
| 6397 | }); |
| 6961 | 6398 | } |