fix arity-checking bug; do not check arities in self-recursive function calls
This commit is contained in:
parent
524e3627fb
commit
8e03707f64
|
@ -370,18 +370,29 @@ Deferred until a later iteration of Ludus:
|
|||
# (set (args :tail-call) true))
|
||||
|
||||
(defn- check-arity [validator]
|
||||
(print "CHECKING ARITY")
|
||||
(def ast (validator :ast))
|
||||
# (when (ast :partial) (break validator))
|
||||
(def ctx (validator :ctx))
|
||||
(def data (ast :data))
|
||||
(def fn-word (first data))
|
||||
(pp fn-word)
|
||||
(def the-fn (resolve-name ctx (fn-word :data)))
|
||||
(print "the called function: " the-fn)
|
||||
(pp the-fn)
|
||||
(when (not the-fn) (break validator))
|
||||
(print "the function is not nil")
|
||||
(print "the function type is " (type the-fn))
|
||||
(when (= :function (type the-fn)) (break validator))
|
||||
(when (= :cfunction (type the-fn) (break validator)))
|
||||
(when (= :cfunction (type the-fn)) (break validator))
|
||||
(print "the function is not a janet fn")
|
||||
(print "fn type: " (the-fn :type))
|
||||
(when (not= :fn (the-fn :type)) (break validator))
|
||||
(print "fn name: " (the-fn :name))
|
||||
(def arities (the-fn :arities))
|
||||
# when there aren't arities yet, break, since that means we're making a recursive function call
|
||||
# TODO: enahnce this so that we can determine arities *before* all function bodies; this ensures arity-checking for self-recursive calls
|
||||
(when (not arities) (break validator))
|
||||
(print "arities: ")
|
||||
(pp arities)
|
||||
(def args (get data 1))
|
||||
|
@ -389,6 +400,9 @@ Deferred until a later iteration of Ludus:
|
|||
(print "called with #args " num-args)
|
||||
(pp (get (validator :ctx) "bar"))
|
||||
(when (has-key? arities num-args) (break validator))
|
||||
(print "arities: ")
|
||||
(pp arities)
|
||||
(when (not arities) (break validator))
|
||||
(def rest-arities (keys (arities :rest)))
|
||||
(when (empty? rest-arities)
|
||||
(array/push (validator :errors)
|
||||
|
@ -724,10 +738,11 @@ Deferred until a later iteration of Ludus:
|
|||
(do
|
||||
# (comment
|
||||
(def source `
|
||||
let foo = 1
|
||||
pkg Foo {foo}
|
||||
pkg Baz {Foo, foo}
|
||||
Baz :Foo :bar
|
||||
fn foo {
|
||||
() -> foo (:foo)
|
||||
}
|
||||
|
||||
foo ()
|
||||
`)
|
||||
(def scanned (s/scan source))
|
||||
(def parsed (p/parse scanned))
|
||||
|
|
Loading…
Reference in New Issue
Block a user