authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-01-11 00:38:24-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-01-11 00:38:24-05:00
log7493af59538fc59f6180c83a188e1b28bdf33eb4
tree1e0151d958cbc92d4cea9652113e3ff3e81ceacc
parentfde276a3bf3d20da5346bd302a736101ce440362

fix a few tests


2 files changed, 54 insertions(+), 67 deletions(-)

src/ir.cpp+1-1
...@@ -7119,7 +7119,7 @@ static TypeTableEntry *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp...@@ -7119,7 +7119,7 @@ static TypeTableEntry *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp
7119 return ira->codegen->builtin_types.entry_invalid;7119 return ira->codegen->builtin_types.entry_invalid;
7120 } else if (err == ErrorOverflow) {7120 } else if (err == ErrorOverflow) {
7121 ir_add_error_node(ira, bin_op_instruction->base.source_node,7121 ir_add_error_node(ira, bin_op_instruction->base.source_node,
7122 buf_sprintf("value cannot be represented in any integer type"));7122 buf_sprintf("operation caused overflow"));
7123 return ira->codegen->builtin_types.entry_invalid;7123 return ira->codegen->builtin_types.entry_invalid;
7124 }7124 }
7125 return ira->codegen->builtin_types.entry_invalid;7125 return ira->codegen->builtin_types.entry_invalid;
test/run_tests.cpp+53-66
...@@ -1178,7 +1178,7 @@ fn f(n: Number) -> i32 {...@@ -1178,7 +1178,7 @@ fn f(n: Number) -> i32 {
1178fn f() {1178fn 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");
11821182
11831183
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; }
1196fn test1(a: i32, b: i32) -> i32 {1196fn 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");
12001200
1201 add_compile_fail_case("goto jumping into block", R"SOURCE(1201 add_compile_fail_case("goto jumping into block", R"SOURCE(
1202fn f() {1202fn 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'");
12111209
1212 add_compile_fail_case("goto jumping past a defer", R"SOURCE(1210 add_compile_fail_case("goto jumping past a defer", R"SOURCE(
1213fn f(b: bool) {1211fn f(b: bool) {
...@@ -1216,9 +1214,7 @@ fn f(b: bool) {...@@ -1216,9 +1214,7 @@ fn f(b: bool) {
1216label:1214label:
1217}1215}
1218fn derp(){}1216fn 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");
12221218
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(
1224const a: &u8 = null;1220const a: &u8 = null;
...@@ -1229,21 +1225,20 @@ const array = []u8{};...@@ -1229,21 +1225,20 @@ const array = []u8{};
1229fn foo() {1225fn 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");
12331229
1234 add_compile_fail_case("compile time division by zero", R"SOURCE(1230 add_compile_fail_case("compile time division by zero", R"SOURCE(
1235const x = foo(0);1231const y = foo(0);
1236fn foo(x: i32) -> i32 {1232fn foo(x: i32) -> i32 {
1237 1 / x1233 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");
12431238
1244 add_compile_fail_case("branch on undefined value", R"SOURCE(1239 add_compile_fail_case("branch on undefined value", R"SOURCE(
1245const x = if (undefined) true else false;1240const 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");
12471242
12481243
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);
1251fn fibbonaci(x: i32) -> i32 {1246fn 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");
12581252
1259 add_compile_fail_case("@embedFile with bogus file", R"SOURCE(1253 add_compile_fail_case("@embedFile with bogus file", R"SOURCE(
1260const resource = @embedFile("bogus.txt");1254const 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'");
12621256
12631257
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(
1265const Foo = {1259const Foo = struct {
1266 x: i32,1260 x: i32,
1267};1261};
1268const a = Foo {.x = get_it()};1262const a = Foo {.x = get_it()};
1269extern fn get_it() -> i32;1263extern 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");
12711265
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(
1273const Foo = {1267const Foo = struct {
1274 x: i32,1268 x: i32,
1275};1269};
1276const a = get_it();1270const a = get_it();
...@@ -1320,76 +1314,68 @@ fn bar() -> i32 {...@@ -1320,76 +1314,68 @@ fn bar() -> i32 {
13201314
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");
13221316
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(
1324fn f() {1318fn 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");
13321323
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(
1334fn f() {1325fn 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(
1332const y = neg(-128);
1337fn neg(x: i8) -> i8 {1333fn neg(x: i8) -> i8 {
1338 -x1334 -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");
13441339
1345 add_compile_fail_case("add overflow in function evaluation", R"SOURCE(1340 add_compile_fail_case("add overflow in function evaluation", R"SOURCE(
1346fn f() {1341const y = add(65530, 10);
1347 const x = add(65530, 10);
1348}
1349fn add(a: u16, b: u16) -> u16 {1342fn add(a: u16, b: u16) -> u16 {
1350 a + b1343 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");
13561348
13571349
1358 add_compile_fail_case("sub overflow in function evaluation", R"SOURCE(1350 add_compile_fail_case("sub overflow in function evaluation", R"SOURCE(
1359fn f() {1351const y = sub(10, 20);
1360 const x = sub(10, 20);
1361}
1362fn sub(a: u16, b: u16) -> u16 {1352fn sub(a: u16, b: u16) -> u16 {
1363 a - b1353 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");
13691358
1370 add_compile_fail_case("mul overflow in function evaluation", R"SOURCE(1359 add_compile_fail_case("mul overflow in function evaluation", R"SOURCE(
1371fn f() {1360const y = mul(300, 6000);
1372 const x = mul(300, 6000);
1373}
1374fn mul(a: u16, b: u16) -> u16 {1361fn mul(a: u16, b: u16) -> u16 {
1375 a * b1362 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");
13811367
1382 add_compile_fail_case("truncate sign mismatch", R"SOURCE(1368 add_compile_fail_case("truncate sign mismatch", R"SOURCE(
1383fn f() {1369fn 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'");
13881374
1389 add_compile_fail_case("truncate same bit count", R"SOURCE(1375 add_compile_fail_case("truncate same bit count", R"SOURCE(
1390fn f() {1376fn 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'");
13951381
...@@ -1398,9 +1384,8 @@ fn f() {...@@ -1398,9 +1384,8 @@ fn f() {
1398 %return something();1384 %return something();
1399}1385}
1400fn something() -> %void { }1386fn 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");
14041389
1405 add_compile_fail_case("wrong return type for main", R"SOURCE(1390 add_compile_fail_case("wrong return type for main", R"SOURCE(
1406pub fn main(args: [][]u8) { }1391pub 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}
14461431
1447pub struct SmallList(inline T: type, inline STATIC_SIZE: usize) {1432pub 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}
14521439
1453fn function_with_return_type_type() {1440fn function_with_return_type_type() {