diff --git a/ast/ArgumentTuple.lua b/ast/ArgumentTuple.lua index da60e3b..eff9dac 100644 --- a/ast/ArgumentTuple.lua +++ b/ast/ArgumentTuple.lua @@ -150,8 +150,8 @@ ArgumentTuple = ast.abstract.Node { end -- not found if not arg then return false, ("missing parameter %s"):format(param.identifier:format(state)) end - -- type check - if param.type_check then + -- type check (assume ok for default values) + if param.type_check and arg ~= param.default then local r = param.type_check:call(state, ArgumentTuple:new(arg)) if not r:truthy() then return false, ("type check failure for parameter %s in function %s"):format(param.identifier:format(state), params:format(state)) end if Number:is(r) then diff --git a/test/results/function type dispatch with default.ans b/test/results/function type dispatch with default.ans new file mode 100644 index 0000000..8088f5f --- /dev/null +++ b/test/results/function type dispatch with default.ans @@ -0,0 +1,20 @@ +--# run #-- +--- text --- +| {}"a"| +--- text --- +| {}"x"| +--- text --- +| {}"a"| +--- text --- +| {}"" {}"gs" {}""| +| {}"" {}"gn" {}""| +| {}"" {}"gs" {}""| +| {}"" {}"gn" {}""| +| {}"" {}"gs" {}""| +| {}"" {}"gn" {}""| +| {}"" {}"gs" {}""| +| {}"" {}"gn" {}""| +--- return --- +() +--# saved #-- +{} \ No newline at end of file diff --git a/test/tests/function type dispatch with default.ans b/test/tests/function type dispatch with default.ans new file mode 100644 index 0000000..b36e04f --- /dev/null +++ b/test/tests/function type dispatch with default.ans @@ -0,0 +1,26 @@ +:$ fn(x::number) + |x + +:$ fn(a::string="o") + |a + +fn("s") + +fn(5) + +fn() + +:$ g(n="s", a::number=5) + @"gn" + +:$ g(n="s", a::string="lol") + @"gs" + +|{g(n="k", a="l")} +|{g(n="k", a=1)} +|{g(n="k", "l")} +|{g(n="k", 1)} +|{g("k", "l")} +|{g("k", 1)} +|{g("k", a="l")} +|{g("k", a=1)}