| ... | @@ -1178,7 +1178,7 @@ fn f(n: Number) -> i32 { | ... | @@ -1178,7 +1178,7 @@ fn f(n: Number) -> i32 { |
| 1178 | fn f() { | 1178 | fn f() { |
| 1179 | const std = @import("std"); | 1179 | const std = @import("std"); |
| 1180 | } | 1180 | } |
| 1181 | )SOURCE", 1, ".tmp_source.zig:3:17: error: @import invalid inside function bodies"); | 1181 | )SOURCE", 1, ".tmp_source.zig:3:17: error: import valid only at global scope"); |
| 1182 | | 1182 | |
| 1183 | | 1183 | |
| 1184 | add_compile_fail_case("normal string with newline", R"SOURCE( | 1184 | add_compile_fail_case("normal string with newline", R"SOURCE( |
| ... | @@ -1196,7 +1196,7 @@ fn foo(inline x: i32, y: i32) -> i32 { return x + y; } | ... | @@ -1196,7 +1196,7 @@ fn foo(inline x: i32, y: i32) -> i32 { return x + y; } |
| 1196 | fn test1(a: i32, b: i32) -> i32 { | 1196 | fn test1(a: i32, b: i32) -> i32 { |
| 1197 | return foo(a, b); | 1197 | return foo(a, b); |
| 1198 | } | 1198 | } |
| 1199 | )SOURCE", 1, ".tmp_source.zig:4:16: error: unable to evaluate constant expression for inline parameter"); | 1199 | )SOURCE", 1, ".tmp_source.zig:4:16: error: unable to evaluate constant expression"); |
| 1200 | | 1200 | |
| 1201 | add_compile_fail_case("goto jumping into block", R"SOURCE( | 1201 | add_compile_fail_case("goto jumping into block", R"SOURCE( |
| 1202 | fn f() { | 1202 | fn f() { |
| ... | @@ -1205,9 +1205,7 @@ a_label: | ... | @@ -1205,9 +1205,7 @@ a_label: |
| 1205 | } | 1205 | } |
| 1206 | goto a_label; | 1206 | goto a_label; |
| 1207 | } | 1207 | } |
| 1208 | )SOURCE", 2, | 1208 | )SOURCE", 1, ".tmp_source.zig:6:5: error: no label in scope named 'a_label'"); |
| 1209 | ".tmp_source.zig:4:1: error: label 'a_label' defined but not used", | | |
| 1210 | ".tmp_source.zig:6:5: error: no label in scope named 'a_label'"); | | |
| 1211 | | 1209 | |
| 1212 | add_compile_fail_case("goto jumping past a defer", R"SOURCE( | 1210 | add_compile_fail_case("goto jumping past a defer", R"SOURCE( |
| 1213 | fn f(b: bool) { | 1211 | fn f(b: bool) { |
| ... | @@ -1216,9 +1214,7 @@ fn f(b: bool) { | ... | @@ -1216,9 +1214,7 @@ fn f(b: bool) { |
| 1216 | label: | 1214 | label: |
| 1217 | } | 1215 | } |
| 1218 | fn derp(){} | 1216 | fn derp(){} |
| 1219 | )SOURCE", 2, | 1217 | )SOURCE", 1, ".tmp_source.zig:3:12: error: no label in scope named 'label'"); |
| 1220 | ".tmp_source.zig:3:12: error: no label in scope named 'label'", | | |
| 1221 | ".tmp_source.zig:5:1: error: label 'label' defined but not used"); | | |
| 1222 | | 1218 | |
| 1223 | add_compile_fail_case("assign null to non-nullable pointer", R"SOURCE( | 1219 | add_compile_fail_case("assign null to non-nullable pointer", R"SOURCE( |
| 1224 | const a: &u8 = null; | 1220 | const a: &u8 = null; |
| ... | @@ -1229,21 +1225,20 @@ const array = []u8{}; | ... | @@ -1229,21 +1225,20 @@ const array = []u8{}; |
| 1229 | fn foo() { | 1225 | fn foo() { |
| 1230 | const pointer = &array[0]; | 1226 | const pointer = &array[0]; |
| 1231 | } | 1227 | } |
| 1232 | )SOURCE", 1, ".tmp_source.zig:4:27: error: out of bounds array access"); | 1228 | )SOURCE", 1, ".tmp_source.zig:4:27: error: index 0 outside array of size 0"); |
| 1233 | | 1229 | |
| 1234 | add_compile_fail_case("compile time division by zero", R"SOURCE( | 1230 | add_compile_fail_case("compile time division by zero", R"SOURCE( |
| 1235 | const x = foo(0); | 1231 | const y = foo(0); |
| 1236 | fn foo(x: i32) -> i32 { | 1232 | fn foo(x: i32) -> i32 { |
| 1237 | 1 / x | 1233 | 1 / x |
| 1238 | } | 1234 | } |
| 1239 | )SOURCE", 3, | 1235 | )SOURCE", 2, |
| 1240 | ".tmp_source.zig:3:1: error: function evaluation caused division by zero", | 1236 | ".tmp_source.zig:4:7: error: division by zero is undefined", |
| 1241 | ".tmp_source.zig:2:14: note: called from here", | 1237 | ".tmp_source.zig:2:14: note: called from here"); |
| 1242 | ".tmp_source.zig:4:7: note: division by zero here"); | | |
| 1243 | | 1238 | |
| 1244 | add_compile_fail_case("branch on undefined value", R"SOURCE( | 1239 | add_compile_fail_case("branch on undefined value", R"SOURCE( |
| 1245 | const x = if (undefined) true else false; | 1240 | const x = if (undefined) true else false; |
| 1246 | )SOURCE", 1, ".tmp_source.zig:2:15: error: branch on undefined value"); | 1241 | )SOURCE", 1, ".tmp_source.zig:2:15: error: use of undefined value"); |
| 1247 | | 1242 | |
| 1248 | | 1243 | |
| 1249 | add_compile_fail_case("endless loop in function evaluation", R"SOURCE( | 1244 | add_compile_fail_case("endless loop in function evaluation", R"SOURCE( |
| ... | @@ -1251,26 +1246,25 @@ const seventh_fib_number = fibbonaci(7); | ... | @@ -1251,26 +1246,25 @@ const seventh_fib_number = fibbonaci(7); |
| 1251 | fn fibbonaci(x: i32) -> i32 { | 1246 | fn fibbonaci(x: i32) -> i32 { |
| 1252 | return fibbonaci(x - 1) + fibbonaci(x - 2); | 1247 | return fibbonaci(x - 1) + fibbonaci(x - 2); |
| 1253 | } | 1248 | } |
| 1254 | )SOURCE", 3, | 1249 | )SOURCE", 2, |
| 1255 | ".tmp_source.zig:3:1: error: function evaluation exceeded 1000 branches", | 1250 | ".tmp_source.zig:4:21: error: evaluation exceeded 1000 backwards branches", |
| 1256 | ".tmp_source.zig:2:37: note: called from here", | 1251 | ".tmp_source.zig:4:21: note: called from here"); |
| 1257 | ".tmp_source.zig:4:40: note: quota exceeded here"); | | |
| 1258 | | 1252 | |
| 1259 | add_compile_fail_case("@embedFile with bogus file", R"SOURCE( | 1253 | add_compile_fail_case("@embedFile with bogus file", R"SOURCE( |
| 1260 | const resource = @embedFile("bogus.txt"); | 1254 | const resource = @embedFile("bogus.txt"); |
| 1261 | )SOURCE", 1, ".tmp_source.zig:2:18: error: unable to find './bogus.txt'"); | 1255 | )SOURCE", 1, ".tmp_source.zig:2:29: error: unable to find './bogus.txt'"); |
| 1262 | | 1256 | |
| 1263 | | 1257 | |
| 1264 | add_compile_fail_case("non-const expression in struct literal outside function", R"SOURCE( | 1258 | add_compile_fail_case("non-const expression in struct literal outside function", R"SOURCE( |
| 1265 | const Foo = { | 1259 | const Foo = struct { |
| 1266 | x: i32, | 1260 | x: i32, |
| 1267 | }; | 1261 | }; |
| 1268 | const a = Foo {.x = get_it()}; | 1262 | const a = Foo {.x = get_it()}; |
| 1269 | extern fn get_it() -> i32; | 1263 | extern fn get_it() -> i32; |
| 1270 | )SOURCE", 1, ".tmp_source.zig:5:27: error: unable to evaluate constant expression"); | 1264 | )SOURCE", 1, ".tmp_source.zig:5:21: error: unable to evaluate constant expression"); |
| 1271 | | 1265 | |
| 1272 | add_compile_fail_case("non-const expression function call with struct return value outside function", R"SOURCE( | 1266 | add_compile_fail_case("non-const expression function call with struct return value outside function", R"SOURCE( |
| 1273 | const Foo = { | 1267 | const Foo = struct { |
| 1274 | x: i32, | 1268 | x: i32, |
| 1275 | }; | 1269 | }; |
| 1276 | const a = get_it(); | 1270 | const a = get_it(); |
| ... | @@ -1320,76 +1314,68 @@ fn bar() -> i32 { | ... | @@ -1320,76 +1314,68 @@ fn bar() -> i32 { |
| 1320 | | 1314 | |
| 1321 | )SOURCE", 1, ".tmp_source.zig:3:15: error: unable to infer expression type"); | 1315 | )SOURCE", 1, ".tmp_source.zig:3:15: error: unable to infer expression type"); |
| 1322 | | 1316 | |
| 1323 | add_compile_fail_case("atomic orderings of cmpxchg", R"SOURCE( | 1317 | add_compile_fail_case("atomic orderings of cmpxchg - failure stricter than success", R"SOURCE( |
| 1324 | fn f() { | 1318 | fn f() { |
| 1325 | var x: i32 = 1234; | 1319 | var x: i32 = 1234; |
| 1326 | while (!@cmpxchg(&x, 1234, 5678, AtomicOrder.Monotonic, AtomicOrder.SeqCst)) {} | 1320 | while (!@cmpxchg(&x, 1234, 5678, AtomicOrder.Monotonic, AtomicOrder.SeqCst)) {} |
| 1327 | while (!@cmpxchg(&x, 1234, 5678, AtomicOrder.Unordered, AtomicOrder.Unordered)) {} | | |
| 1328 | } | 1321 | } |
| 1329 | )SOURCE", 2, | 1322 | )SOURCE", 1, ".tmp_source.zig:4:72: error: failure atomic ordering must be no stricter than success"); |
| 1330 | ".tmp_source.zig:4:72: error: failure atomic ordering must be no stricter than success", | | |
| 1331 | ".tmp_source.zig:5:49: error: success atomic ordering must be Monotonic or stricter"); | | |
| 1332 | | 1323 | |
| 1333 | add_compile_fail_case("negation overflow in function evaluation", R"SOURCE( | 1324 | add_compile_fail_case("atomic orderings of cmpxchg - success Monotonic or stricter", R"SOURCE( |
| 1334 | fn f() { | 1325 | fn f() { |
| 1335 | const x = neg(-128); | 1326 | var x: i32 = 1234; |
| | 1327 | while (!@cmpxchg(&x, 1234, 5678, AtomicOrder.Unordered, AtomicOrder.Unordered)) {} |
| 1336 | } | 1328 | } |
| | 1329 | )SOURCE", 1, ".tmp_source.zig:4:49: error: success atomic ordering must be Monotonic or stricter"); |
| | 1330 | |
| | 1331 | add_compile_fail_case("negation overflow in function evaluation", R"SOURCE( |
| | 1332 | const y = neg(-128); |
| 1337 | fn neg(x: i8) -> i8 { | 1333 | fn neg(x: i8) -> i8 { |
| 1338 | -x | 1334 | -x |
| 1339 | } | 1335 | } |
| 1340 | )SOURCE", 3, | 1336 | )SOURCE", 2, |
| 1341 | ".tmp_source.zig:5:1: error: function evaluation caused overflow", | 1337 | ".tmp_source.zig:4:5: error: negation caused overflow", |
| 1342 | ".tmp_source.zig:3:18: note: called from here", | 1338 | ".tmp_source.zig:2:14: note: called from here"); |
| 1343 | ".tmp_source.zig:6:5: note: overflow occurred here"); | | |
| 1344 | | 1339 | |
| 1345 | add_compile_fail_case("add overflow in function evaluation", R"SOURCE( | 1340 | add_compile_fail_case("add overflow in function evaluation", R"SOURCE( |
| 1346 | fn f() { | 1341 | const y = add(65530, 10); |
| 1347 | const x = add(65530, 10); | | |
| 1348 | } | | |
| 1349 | fn add(a: u16, b: u16) -> u16 { | 1342 | fn add(a: u16, b: u16) -> u16 { |
| 1350 | a + b | 1343 | a + b |
| 1351 | } | 1344 | } |
| 1352 | )SOURCE", 3, | 1345 | )SOURCE", 2, |
| 1353 | ".tmp_source.zig:5:1: error: function evaluation caused overflow", | 1346 | ".tmp_source.zig:4:7: error: operation caused overflow", |
| 1354 | ".tmp_source.zig:3:18: note: called from here", | 1347 | ".tmp_source.zig:2:14: note: called from here"); |
| 1355 | ".tmp_source.zig:6:7: note: overflow occurred here"); | | |
| 1356 | | 1348 | |
| 1357 | | 1349 | |
| 1358 | add_compile_fail_case("sub overflow in function evaluation", R"SOURCE( | 1350 | add_compile_fail_case("sub overflow in function evaluation", R"SOURCE( |
| 1359 | fn f() { | 1351 | const y = sub(10, 20); |
| 1360 | const x = sub(10, 20); | | |
| 1361 | } | | |
| 1362 | fn sub(a: u16, b: u16) -> u16 { | 1352 | fn sub(a: u16, b: u16) -> u16 { |
| 1363 | a - b | 1353 | a - b |
| 1364 | } | 1354 | } |
| 1365 | )SOURCE", 3, | 1355 | )SOURCE", 2, |
| 1366 | ".tmp_source.zig:5:1: error: function evaluation caused overflow", | 1356 | ".tmp_source.zig:4:7: error: operation caused overflow", |
| 1367 | ".tmp_source.zig:3:18: note: called from here", | 1357 | ".tmp_source.zig:2:14: note: called from here"); |
| 1368 | ".tmp_source.zig:6:7: note: overflow occurred here"); | | |
| 1369 | | 1358 | |
| 1370 | add_compile_fail_case("mul overflow in function evaluation", R"SOURCE( | 1359 | add_compile_fail_case("mul overflow in function evaluation", R"SOURCE( |
| 1371 | fn f() { | 1360 | const y = mul(300, 6000); |
| 1372 | const x = mul(300, 6000); | | |
| 1373 | } | | |
| 1374 | fn mul(a: u16, b: u16) -> u16 { | 1361 | fn mul(a: u16, b: u16) -> u16 { |
| 1375 | a * b | 1362 | a * b |
| 1376 | } | 1363 | } |
| 1377 | )SOURCE", 3, | 1364 | )SOURCE", 2, |
| 1378 | ".tmp_source.zig:5:1: error: function evaluation caused overflow", | 1365 | ".tmp_source.zig:4:7: error: operation caused overflow", |
| 1379 | ".tmp_source.zig:3:18: note: called from here", | 1366 | ".tmp_source.zig:2:14: note: called from here"); |
| 1380 | ".tmp_source.zig:6:7: note: overflow occurred here"); | | |
| 1381 | | 1367 | |
| 1382 | add_compile_fail_case("truncate sign mismatch", R"SOURCE( | 1368 | add_compile_fail_case("truncate sign mismatch", R"SOURCE( |
| 1383 | fn f() { | 1369 | fn f() -> i8 { |
| 1384 | const x: u32 = 10; | 1370 | const x: u32 = 10; |
| 1385 | @truncate(i8, x); | 1371 | @truncate(i8, x) |
| 1386 | } | 1372 | } |
| 1387 | )SOURCE", 1, ".tmp_source.zig:4:19: error: expected signed integer type, found 'u32'"); | 1373 | )SOURCE", 1, ".tmp_source.zig:4:19: error: expected signed integer type, found 'u32'"); |
| 1388 | | 1374 | |
| 1389 | add_compile_fail_case("truncate same bit count", R"SOURCE( | 1375 | add_compile_fail_case("truncate same bit count", R"SOURCE( |
| 1390 | fn f() { | 1376 | fn f() -> i8 { |
| 1391 | const x: i8 = 10; | 1377 | const x: i8 = 10; |
| 1392 | @truncate(i8, x); | 1378 | @truncate(i8, x) |
| 1393 | } | 1379 | } |
| 1394 | )SOURCE", 1, ".tmp_source.zig:4:19: error: type 'i8' has same or fewer bits than destination type 'i8'"); | 1380 | )SOURCE", 1, ".tmp_source.zig:4:19: error: type 'i8' has same or fewer bits than destination type 'i8'"); |
| 1395 | | 1381 | |
| ... | @@ -1398,9 +1384,8 @@ fn f() { | ... | @@ -1398,9 +1384,8 @@ fn f() { |
| 1398 | %return something(); | 1384 | %return something(); |
| 1399 | } | 1385 | } |
| 1400 | fn something() -> %void { } | 1386 | fn something() -> %void { } |
| 1401 | )SOURCE", 2, | 1387 | )SOURCE", 1, |
| 1402 | ".tmp_source.zig:3:5: error: %return statement in function with return type 'void'", | 1388 | ".tmp_source.zig:3:5: error: expected type 'void', found 'error'"); |
| 1403 | ".tmp_source.zig:2:8: note: function return type here"); | | |
| 1404 | | 1389 | |
| 1405 | add_compile_fail_case("wrong return type for main", R"SOURCE( | 1390 | add_compile_fail_case("wrong return type for main", R"SOURCE( |
| 1406 | pub fn main(args: [][]u8) { } | 1391 | pub fn main(args: [][]u8) { } |
| ... | @@ -1444,10 +1429,12 @@ pub fn List(inline T: type) -> type { | ... | @@ -1444,10 +1429,12 @@ pub fn List(inline T: type) -> type { |
| 1444 | SmallList(T, 8) | 1429 | SmallList(T, 8) |
| 1445 | } | 1430 | } |
| 1446 | | 1431 | |
| 1447 | pub struct SmallList(inline T: type, inline STATIC_SIZE: usize) { | 1432 | pub fn SmallList(inline T: type, inline STATIC_SIZE: usize) -> type { |
| 1448 | items: []T, | 1433 | struct { |
| 1449 | length: usize, | 1434 | items: []T, |
| 1450 | prealloc_items: [STATIC_SIZE]T, | 1435 | length: usize, |
| | 1436 | prealloc_items: [STATIC_SIZE]T, |
| | 1437 | } |
| 1451 | } | 1438 | } |
| 1452 | | 1439 | |
| 1453 | fn function_with_return_type_type() { | 1440 | fn function_with_return_type_type() { |