From 10d4783fcde057046d8e8239748233d9afb1074e Mon Sep 17 00:00:00 2001 From: Victorious3 Date: Wed, 10 Nov 2021 14:43:26 +0100 Subject: [PATCH] Fix varargs --- src/test/test_compiler.pr | 3 ++- src/test/test_runtime.pr | 10 +++++++++- src/test/test_typechecking.pr | 3 ++- src/typechecking.pr | 9 +++------ version | 2 +- 5 files changed, 17 insertions(+), 10 deletions(-) diff --git a/src/test/test_compiler.pr b/src/test/test_compiler.pr index ae860604..01184b82 100644 --- a/src/test/test_compiler.pr +++ b/src/test/test_compiler.pr @@ -11,6 +11,7 @@ import compiler import toolchain import builtins import preprocess +import errors import test::testsuite @@ -18,7 +19,7 @@ export var print_ll = false def compile(s: string) -> string { toolchain::outfolder = "./build" - toolchain::error_count = 0 + errors::error_count = 0 vector::push(toolchain::include_path, util::copy_string("src")) diff --git a/src/test/test_runtime.pr b/src/test/test_runtime.pr index 5e1c42c0..03efefe2 100644 --- a/src/test/test_runtime.pr +++ b/src/test/test_runtime.pr @@ -308,9 +308,17 @@ def sum(args: int...) -> int { return sum } +def my_print(args: string...) { + for var i in 0..args.size { + print(args[i], " ") + } + print("\n") +} + def test_varargs { tassert(sum(1, 2, 3) == 6) tassert(sum([1, 2, 3]) == 6) + my_print("foo", "bar", "baz") } def test_if_expression { @@ -386,7 +394,7 @@ export def run_tests { run_test("test_deref", *test_deref, "10 20\n", "") run_test("test_ucs", *test_ucs) run_test("test_anonymous", *test_anonymous, "20.500000\n", "") - run_test("test_varargs", *test_varargs) + run_test("test_varargs", *test_varargs, "foo bar baz \n", "") run_test("test_if_expression", *test_if_expression) run_test("test_default_parameters", *test_default_parameters, util::strip_margin("\ |0 some value diff --git a/src/test/test_typechecking.pr b/src/test/test_typechecking.pr index 76e1291c..b1715795 100644 --- a/src/test/test_typechecking.pr +++ b/src/test/test_typechecking.pr @@ -11,6 +11,7 @@ import debug import codegen import toolchain import preprocess +import errors import test::testsuite @@ -21,7 +22,7 @@ type Result = struct { def typecheck(s: string) -> Result { toolchain::outfolder = "./build" - toolchain::error_count = 0 + errors::error_count = 0 vector::push(toolchain::include_path, util::copy_string("src")) diff --git a/src/typechecking.pr b/src/typechecking.pr index 9a22552d..9c587192 100644 --- a/src/typechecking.pr +++ b/src/typechecking.pr @@ -519,8 +519,8 @@ export def overload_score(a: *Type, param_b: *vector::Vector, positional: bool) } var lvalue = left.tpe if i == vector::length(param_a) - 1 and - is_array(right.tpe) and - left.varargs and left.tpe { + left.varargs and left.tpe and + convert_type_score(array(left.tpe), right.tpe) != -1 { lvalue = array(left.tpe) } @@ -1505,10 +1505,7 @@ def walk_Call(node: *parser::Node, dry_run: bool, state: *State) -> bool { var left = (@node).value.func_call.left if not left { return false } if not dry_run { - let suppress_errors = errors::suppress_errors - errors::suppress_errors = true - walk(node, left, state) - errors::suppress_errors = suppress_errors + walk(node, left, state) } // We need to do this because member access overwrites the parent node left = node.value.func_call.left diff --git a/version b/version index b6df663e..10ad8ac2 100644 --- a/version +++ b/version @@ -1 +1 @@ -VERSION=0.1.10 \ No newline at end of file +VERSION=0.1.11 \ No newline at end of file