diff --git a/scripts/small.toy b/scripts/small.toy index a2a7134..9259392 100644 --- a/scripts/small.toy +++ b/scripts/small.toy @@ -1,50 +1,6 @@ -//test the standard library, under a number of different circumstances - -//test basic import -{ - import standard; - - //this depends on external factors, so only check the length - assert clock().length() == 24, "import library failed"; -} +import compound; +var arr: [int] = [1, 2, 3]; +fn f(_, v: int): int { return v + 1; } +print arr.map(f); -//test import within a function -{ - fn f() { - import standard; - - assert clock != null, "import library within function failed"; - - return clock; - } - - //invoke - assert f()().length() == 24, "import library within function and return failed"; -} - - -//test closing over standard library element -{ - import standard; - - fn f() { - assert clock != null, "import library outside function failed"; - - return clock; - } - - //invoke - assert f()().length() == 24, "import library outside function and return failed"; -} - - -//test importing as an alias -{ - import standard as std; - - assert std["clock"]().length() == 24, "import library as alias failed"; -} - - -print "All good"; diff --git a/source/toy_parser.c b/source/toy_parser.c index 94f2bf8..1bf4d1f 100644 --- a/source/toy_parser.c +++ b/source/toy_parser.c @@ -1220,7 +1220,7 @@ static void parsePrecedence(Toy_Parser* parser, Toy_ASTNode** nodeHandle, Preced Toy_emitASTNodeBinary(nodeHandle, rhsNode, opcode); //optimise away the constants - if (!calcStaticBinaryArithmetic(parser, nodeHandle)) { + if (!parser->panic && !calcStaticBinaryArithmetic(parser, nodeHandle)) { return; } } diff --git a/test/scripts/mustfail/arithmetic-without-operand.toy b/test/scripts/mustfail/arithmetic-without-operand.toy new file mode 100644 index 0000000..c62e800 --- /dev/null +++ b/test/scripts/mustfail/arithmetic-without-operand.toy @@ -0,0 +1 @@ +print "foo" + + "bar"; diff --git a/test/test_mustfail.c b/test/test_mustfail.c index d71e8c9..8a0a68d 100644 --- a/test/test_mustfail.c +++ b/test/test_mustfail.c @@ -96,6 +96,7 @@ int main() { //run each file in tests/scripts/ char* filenames[] = { "access-parent-directory.toy", + "arithmetic-without-operand.toy", "bad-function-identifier.toy", "declare-types-array.toy", "declare-types-dictionary-key.toy",