Skip to content

Commit

Permalink
Fix varargs
Browse files Browse the repository at this point in the history
  • Loading branch information
Victorious3 committed Nov 10, 2021
1 parent f6496b0 commit 10d4783
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 10 deletions.
3 changes: 2 additions & 1 deletion src/test/test_compiler.pr
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@ import compiler
import toolchain
import builtins
import preprocess
import errors

import test::testsuite

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"))

Expand Down
10 changes: 9 additions & 1 deletion src/test/test_runtime.pr
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion src/test/test_typechecking.pr
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import debug
import codegen
import toolchain
import preprocess
import errors

import test::testsuite

Expand All @@ -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"))

Expand Down
9 changes: 3 additions & 6 deletions src/typechecking.pr
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
VERSION=0.1.10
VERSION=0.1.11

0 comments on commit 10d4783

Please sign in to comment.