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
71197119 return ira->codegen->builtin_types.entry_invalid;
71207120 } else if (err == ErrorOverflow) {
71217121 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"));
71237123 return ira->codegen->builtin_types.entry_invalid;
71247124 }
71257125 return ira->codegen->builtin_types.entry_invalid;
test/run_tests.cpp+53-66
......@@ -1178,7 +1178,7 @@ fn f(n: Number) -> i32 {
11781178fn f() {
11791179 const std = @import("std");
11801180}
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
11841184 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; }
11961196fn test1(a: i32, b: i32) -> i32 {
11971197 return foo(a, b);
11981198}
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
12011201 add_compile_fail_case("goto jumping into block", R"SOURCE(
12021202fn f() {
......@@ -1205,9 +1205,7 @@ a_label:
12051205 }
12061206 goto a_label;
12071207}
1208 )SOURCE", 2,
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'");
1208 )SOURCE", 1, ".tmp_source.zig:6:5: error: no label in scope named 'a_label'");
12111209
12121210 add_compile_fail_case("goto jumping past a defer", R"SOURCE(
12131211fn f(b: bool) {
......@@ -1216,9 +1214,7 @@ fn f(b: bool) {
12161214label:
12171215}
12181216fn derp(){}
1219 )SOURCE", 2,
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");
1217 )SOURCE", 1, ".tmp_source.zig:3:12: error: no label in scope named 'label'");
12221218
12231219 add_compile_fail_case("assign null to non-nullable pointer", R"SOURCE(
12241220const a: &u8 = null;
......@@ -1229,21 +1225,20 @@ const array = []u8{};
12291225fn foo() {
12301226 const pointer = &array[0];
12311227}
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
12341230 add_compile_fail_case("compile time division by zero", R"SOURCE(
1235const x = foo(0);
1231const y = foo(0);
12361232fn foo(x: i32) -> i32 {
12371233 1 / x
12381234}
1239 )SOURCE", 3,
1240 ".tmp_source.zig:3:1: error: function evaluation caused division by zero",
1241 ".tmp_source.zig:2:14: note: called from here",
1242 ".tmp_source.zig:4:7: note: division by zero here");
1235 )SOURCE", 2,
1236 ".tmp_source.zig:4:7: error: division by zero is undefined",
1237 ".tmp_source.zig:2:14: note: called from here");
12431238
12441239 add_compile_fail_case("branch on undefined value", R"SOURCE(
12451240const 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
12491244 add_compile_fail_case("endless loop in function evaluation", R"SOURCE(
......@@ -1251,26 +1246,25 @@ const seventh_fib_number = fibbonaci(7);
12511246fn fibbonaci(x: i32) -> i32 {
12521247 return fibbonaci(x - 1) + fibbonaci(x - 2);
12531248}
1254 )SOURCE", 3,
1255 ".tmp_source.zig:3:1: error: function evaluation exceeded 1000 branches",
1256 ".tmp_source.zig:2:37: note: called from here",
1257 ".tmp_source.zig:4:40: note: quota exceeded here");
1249 )SOURCE", 2,
1250 ".tmp_source.zig:4:21: error: evaluation exceeded 1000 backwards branches",
1251 ".tmp_source.zig:4:21: note: called from here");
12581252
12591253 add_compile_fail_case("@embedFile with bogus file", R"SOURCE(
12601254const 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
12641258 add_compile_fail_case("non-const expression in struct literal outside function", R"SOURCE(
1265const Foo = {
1259const Foo = struct {
12661260 x: i32,
12671261};
12681262const a = Foo {.x = get_it()};
12691263extern 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
12721266 add_compile_fail_case("non-const expression function call with struct return value outside function", R"SOURCE(
1273const Foo = {
1267const Foo = struct {
12741268 x: i32,
12751269};
12761270const a = get_it();
......@@ -1320,76 +1314,68 @@ fn bar() -> i32 {
13201314
13211315 )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(
13241318fn f() {
13251319 var x: i32 = 1234;
13261320 while (!@cmpxchg(&x, 1234, 5678, AtomicOrder.Monotonic, AtomicOrder.SeqCst)) {}
1327 while (!@cmpxchg(&x, 1234, 5678, AtomicOrder.Unordered, AtomicOrder.Unordered)) {}
13281321}
1329 )SOURCE", 2,
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");
1322 )SOURCE", 1, ".tmp_source.zig:4:72: error: failure atomic ordering must be no stricter than success");
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(
13341325fn f() {
1335 const x = neg(-128);
1326 var x: i32 = 1234;
1327 while (!@cmpxchg(&x, 1234, 5678, AtomicOrder.Unordered, AtomicOrder.Unordered)) {}
13361328}
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);
13371333fn neg(x: i8) -> i8 {
13381334 -x
13391335}
1340 )SOURCE", 3,
1341 ".tmp_source.zig:5:1: error: function evaluation caused overflow",
1342 ".tmp_source.zig:3:18: note: called from here",
1343 ".tmp_source.zig:6:5: note: overflow occurred here");
1336 )SOURCE", 2,
1337 ".tmp_source.zig:4:5: error: negation caused overflow",
1338 ".tmp_source.zig:2:14: note: called from here");
13441339
13451340 add_compile_fail_case("add overflow in function evaluation", R"SOURCE(
1346fn f() {
1347 const x = add(65530, 10);
1348}
1341const y = add(65530, 10);
13491342fn add(a: u16, b: u16) -> u16 {
13501343 a + b
13511344}
1352 )SOURCE", 3,
1353 ".tmp_source.zig:5:1: error: function evaluation caused overflow",
1354 ".tmp_source.zig:3:18: note: called from here",
1355 ".tmp_source.zig:6:7: note: overflow occurred here");
1345 )SOURCE", 2,
1346 ".tmp_source.zig:4:7: error: operation caused overflow",
1347 ".tmp_source.zig:2:14: note: called from here");
13561348
13571349
13581350 add_compile_fail_case("sub overflow in function evaluation", R"SOURCE(
1359fn f() {
1360 const x = sub(10, 20);
1361}
1351const y = sub(10, 20);
13621352fn sub(a: u16, b: u16) -> u16 {
13631353 a - b
13641354}
1365 )SOURCE", 3,
1366 ".tmp_source.zig:5:1: error: function evaluation caused overflow",
1367 ".tmp_source.zig:3:18: note: called from here",
1368 ".tmp_source.zig:6:7: note: overflow occurred here");
1355 )SOURCE", 2,
1356 ".tmp_source.zig:4:7: error: operation caused overflow",
1357 ".tmp_source.zig:2:14: note: called from here");
13691358
13701359 add_compile_fail_case("mul overflow in function evaluation", R"SOURCE(
1371fn f() {
1372 const x = mul(300, 6000);
1373}
1360const y = mul(300, 6000);
13741361fn mul(a: u16, b: u16) -> u16 {
13751362 a * b
13761363}
1377 )SOURCE", 3,
1378 ".tmp_source.zig:5:1: error: function evaluation caused overflow",
1379 ".tmp_source.zig:3:18: note: called from here",
1380 ".tmp_source.zig:6:7: note: overflow occurred here");
1364 )SOURCE", 2,
1365 ".tmp_source.zig:4:7: error: operation caused overflow",
1366 ".tmp_source.zig:2:14: note: called from here");
13811367
13821368 add_compile_fail_case("truncate sign mismatch", R"SOURCE(
1383fn f() {
1369fn f() -> i8 {
13841370 const x: u32 = 10;
1385 @truncate(i8, x);
1371 @truncate(i8, x)
13861372}
13871373 )SOURCE", 1, ".tmp_source.zig:4:19: error: expected signed integer type, found 'u32'");
13881374
13891375 add_compile_fail_case("truncate same bit count", R"SOURCE(
1390fn f() {
1376fn f() -> i8 {
13911377 const x: i8 = 10;
1392 @truncate(i8, x);
1378 @truncate(i8, x)
13931379}
13941380 )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() {
13981384 %return something();
13991385}
14001386fn something() -> %void { }
1401 )SOURCE", 2,
1402 ".tmp_source.zig:3:5: error: %return statement in function with return type 'void'",
1403 ".tmp_source.zig:2:8: note: function return type here");
1387 )SOURCE", 1,
1388 ".tmp_source.zig:3:5: error: expected type 'void', found 'error'");
14041389
14051390 add_compile_fail_case("wrong return type for main", R"SOURCE(
14061391pub fn main(args: [][]u8) { }
......@@ -1444,10 +1429,12 @@ pub fn List(inline T: type) -> type {
14441429 SmallList(T, 8)
14451430}
14461431
1447pub struct SmallList(inline T: type, inline STATIC_SIZE: usize) {
1448 items: []T,
1449 length: usize,
1450 prealloc_items: [STATIC_SIZE]T,
1432pub fn SmallList(inline T: type, inline STATIC_SIZE: usize) -> type {
1433 struct {
1434 items: []T,
1435 length: usize,
1436 prealloc_items: [STATIC_SIZE]T,
1437 }
14511438}
14521439
14531440fn function_with_return_type_type() {