The following workflow contains the steps needed to reproduce the error:
;; Byte-compile the function.
(byte-compile '(defun flatten (x)
(cl-labels ((rec (x acc)
(cond ((null x) acc)
((atom x) (cons x acc))
(t (rec (car x) (rec (cdr x) acc))))))
(rec x nil))))
;; `pp-eval-last-sexp` output.
(byte-code "\300\301\302\"\207"
[defalias flatten
#[(x)
"\302\303\211 \302\")\207"
[--cl-rec-- x nil
#[(x acc)
"\306 \n\211\204\0\306\202'\0\f:\204\0\fB\306\202'\0\f@
\fA\"\307*\204\0)\207"
[retval x acc acc x --cl-rec-- nil :recurse]
4]]
4]]
3)
;; Taking out the actual bytecode so as to eval the expression.
(#[(x)
"\302\303\211 \302\")\207"
[--cl-rec-- x nil
#[(x acc)
"\306 \n\211\204\0\306\202'\0\f:\204\0\fB\306\202'\0\f@
\fA\"\307*\204\0)\207"
[retval x acc acc x --cl-rec-- nil :recurse]
4]]
4] '(1 2 3))
As shown, I byte-compile a function and try to eval it with the argument '(1 2 3)
. It throws the following error and I don't know why:
Debugger entered--Lisp error: (wrong-type-argument listp 1)
#f(compiled-function (x acc) #<bytecode 0x4c32e213416e008>)((1 2 3) nil)
#f(compiled-function (x) #<bytecode -0x1a3b6ef3b20a60c7>)((1 2 3))
eval((#f(compiled-function (x) #<bytecode -0x1a3b6ef3b20a60c7>) '(1 2 3)) nil)
...
...
...
I've pinpointed that perhaps (cl-labels ((rec (x acc)
has something to do with this.