diff --git a/eval/eval.go b/eval/eval.go index 34fc504..6948df9 100644 --- a/eval/eval.go +++ b/eval/eval.go @@ -344,7 +344,14 @@ func (ev *Eval) eval(exp primitive.Primitive, e *env.Environment, expandMacro bo // // Now we're only dealing with lists // - listExp := exp.(primitive.List) + listExp, listOk := exp.(primitive.List) + + // + // But just in case we're not .. + // + if !listOk { + return primitive.Error(fmt.Sprintf("argument not a list for a function call: %v", exp)) + } // // Is this an empty list? Then just return it diff --git a/eval/eval_test.go b/eval/eval_test.go index ae056ba..c13475d 100644 --- a/eval/eval_test.go +++ b/eval/eval_test.go @@ -390,6 +390,10 @@ a {input: "(define blah (lambda (a:number) (print a))) (blah '(3))", output: "ERROR{TypeError - argument a to blah was supposed to be number, got list}"}, {input: "(define blah (lambda (a:function) (print a))) (blah '(3))", output: "ERROR{TypeError - argument a to blah was supposed to be function, got list}"}, {input: "(define blah (lambda (a:any) (print a))) (blah '(3))", output: "(3)"}, + + // fuzz errors + {input: "(defmacro! unless(fn*()`(~!)))(unless )", output: "ERROR{argument '(lambda (x) (if x #f #t))' not a function}"}, + {input: "(ord 0)", output: "ERROR{argument not a character/string, got number}"}, } for _, test := range tests { diff --git a/fuzz_test.go b/fuzz_test.go index b90be2d..a3e4f15 100644 --- a/fuzz_test.go +++ b/fuzz_test.go @@ -126,6 +126,7 @@ func FuzzYAL(f *testing.F) { "invalid character literal", "is not a symbol", "must have even length", + "not a character", "not a function", "not a hash", "not a list", diff --git a/testdata/fuzz/FuzzYAL/ba0fcef6ab521763179f52a1f2ef9fed78574074e826d61f9c362bd4ca07f62e b/testdata/fuzz/FuzzYAL/ba0fcef6ab521763179f52a1f2ef9fed78574074e826d61f9c362bd4ca07f62e new file mode 100644 index 0000000..8c7e9f4 --- /dev/null +++ b/testdata/fuzz/FuzzYAL/ba0fcef6ab521763179f52a1f2ef9fed78574074e826d61f9c362bd4ca07f62e @@ -0,0 +1,2 @@ +go test fuzz v1 +[]byte("(defmacro! unless(fn*()`(~!)))(unless )")