diff --git a/anselme/state/ScopeStack.lua b/anselme/state/ScopeStack.lua index bee26cd..d209f1f 100644 --- a/anselme/state/ScopeStack.lua +++ b/anselme/state/ScopeStack.lua @@ -65,7 +65,7 @@ local ScopeStack = class { end end self:define_overloadable(sym, LuaFunction:new(parameters, func):eval(self.state)) - elseif Node:is(value) then + elseif Node:issub(value) then self:define(sym, value) else self:define(sym, to_anselme(value)) diff --git a/test/results/function custom type dispatch error.ans b/test/results/function custom type dispatch error.ans new file mode 100644 index 0000000..0f10730 --- /dev/null +++ b/test/results/function custom type dispatch error.ans @@ -0,0 +1,13 @@ +--# run #-- +--- text --- +| {}"" {}"pierre" {}" is french" | +--- text --- +| {}"" {}"idk" {}" is esperanto" | +--- error --- +can't call overload overload<($(name::($(x) type(x) == t)) _), ($(name::($(x) type(x) == t)) _)>: no function match (type("nope", 5)), possible functions were: + • (name::($(x) type(x) == t)): type check failure for parameter name in function (name::($(x) type(x) == t)) + • (name::($(x) type(x) == t)): type check failure for parameter name in function (name::($(x) type(x) == t)) + ↳ from test/tests/function custom type dispatch error.ans:14:2 in call: a(type(5, "nope")) + ↳ from ? in block: :french name = "french name"… +--# saved #-- +{} \ No newline at end of file diff --git a/test/results/function custom type dispatch.ans b/test/results/function custom type dispatch.ans new file mode 100644 index 0000000..3a4a570 --- /dev/null +++ b/test/results/function custom type dispatch.ans @@ -0,0 +1,11 @@ +--# run #-- +--- text --- +| {}"" {}"bob" {}" is english or generic" | +--- text --- +| {}"" {}"pierre" {}" is french" | +--- text --- +| {}"" {}"idk" {}" is english or generic" | +--- return --- +() +--# saved #-- +{} \ No newline at end of file diff --git a/test/results/litterals.ans b/test/results/litterals.ans new file mode 100644 index 0000000..3742c16 --- /dev/null +++ b/test/results/litterals.ans @@ -0,0 +1,42 @@ +--# run #-- +--- text --- +| {}"numbers:" | +| {}"" {}"0" {}"" | +| {}"" {}"12" {}"" | +| {}"" {}"0.87" {}"" | +| {}"" {}"39.12" {}"" | +--- text --- +| {}"strings:" | +| {}"" {}"foo" {}"" | +--- text --- +| {}"tuple:" | +| {}"" {}"[4, 8, 9]" {}"" | +--- text --- +| {}"struct:" | +| {}"" {}"{1:9, 2:8, 7:4}" {}"" | +--- text --- +| {}"symbols:" | +| {}"" {}":ab" {}"" | +--- text --- +| {}"anchor:" | +| {}"" {}"#jdfe" {}"" | +| {}"" {}"#foo bar" {}"" | +--- text --- +| {}"boolean:" | +| {}"" {}"false" {}"" | +| {}"" {}"true" {}"" | +--- text --- +| {}"nil:" | +| {}"" {}"()" {}"" | +--- text --- +| {}"pair:" | +| {}"" {}"6:8" {}"" | +| {}"" {}"\"d\":[]" {}"" | +--- text --- +| {}"function:" | +| {}"" {}"($() 12)" {}"" | +| {}"" {}"($(x) x)" {}"" | +--- return --- +() +--# saved #-- +{} \ No newline at end of file diff --git a/test/tests/function custom type dispatch error.ans b/test/tests/function custom type dispatch error.ans new file mode 100644 index 0000000..b7a764b --- /dev/null +++ b/test/tests/function custom type dispatch error.ans @@ -0,0 +1,14 @@ +:french name="french name" +:esperanto name="esperanto name" + +:$ a(name::is(esperanto name)) + |{name!value} is esperanto + +:$ a(name::is(french name)) + |{name!value} is french + +a("pierre"!type(french name)) + +a("idk"!type(esperanto name)) + +a(5!type("nope")) diff --git a/test/tests/function custom type dispatch.ans b/test/tests/function custom type dispatch.ans new file mode 100644 index 0000000..af8029c --- /dev/null +++ b/test/tests/function custom type dispatch.ans @@ -0,0 +1,14 @@ +:french name="french name" +:esperanto name="esperanto name" + +:$ a(name) + |{name!value} is english or generic + +:$ a(name::is(french name)) + |{name!value} is french + +a("bob") + +a("pierre"!type(french name)) + +a("idk"!type(esperanto name)) diff --git a/test/tests/litterals.ans b/test/tests/litterals.ans new file mode 100644 index 0000000..90efb5f --- /dev/null +++ b/test/tests/litterals.ans @@ -0,0 +1,36 @@ +| numbers: +| {0} +| {12} +| {.87} +| {39.12} + +| strings: +| {"foo"} + +| tuple: +| {[4,8,9]} + +| struct: +| {{7:4,2:8,1:9}} + +| symbols: +| {:ab} + +| anchor: +| {#jdfe} +| {#foo bar} + +| boolean: +| {false} +| {true} + +| nil: +| {()} + +| pair: +| {6:8} +| {("d"):([])} + +| function: +| {$12} +| {$(x)x}