Hello!

I've been rewriting one of my projects to SBCL and have encountered a strange type error during compilation bug, which can be narrowed to the following code.

bug.lisp file contents:

(declaim (inline curry))

(defun curry (function &rest args)
  (lambda (&rest more-args)
    (apply function (append args more-args))))

(declaim (inline concat))

(defun concat (&rest strings)
  (apply (curry #'concatenate 'string) strings))

(let ((sum (multiple-value-bind (x y)
               (values 3 4)
             (+ x y))))
  (defun dummy (x y)
    (list sum
          (concat x y))))

It appears, that both inline declarations are needed to reproduce the bug.

SBCL 1.0.5 Linux/x86 gives (1.0.4 exhibits this behaviour too):

* (compile-file "bug.lisp")

; compiling file "bug.lisp" (written 24 MAY 2007 06:00:39 AM):
; compiling (DECLAIM (INLINE CURRY))
; compiling (DEFUN CURRY ...)
; compiling (DECLAIM (INLINE CONCAT))
; compiling (DEFUN CONCAT ...)
; compiling (LET (#) ...)unhandled TYPE-ERROR in thread #<SB-THREAD:THREAD "initial thread" {B2A0131}>:
  The value NIL is not of type SB-C::PHYSENV.

0: (BACKTRACE 128 #<SYNONYM-STREAM :SYMBOL SB-SYS:*STDERR* {90B5849}>)
1: (SB-DEBUG::DEBUGGER-DISABLED-HOOK
    #<TYPE-ERROR {AD30079}>
    #<unavailable argument>)
2: (INVOKE-DEBUGGER #<TYPE-ERROR {AD30079}>)
3: (INVOKE-DEBUGGER #<TYPE-ERROR {AD30079}>)
4: (ERROR TYPE-ERROR)
5: (SB-KERNEL::OBJECT-NOT-TYPE-ERROR-HANDLER
    #<unavailable argument>
    #.(SB-SYS:INT-SAP #XB79EF5E4)
    #<SB-ALIEN-INTERNALS:ALIEN-VALUE :SAP #XB79EF2CC :TYPE (*
                                                            (STRUCT
                                                             SB-VM::OS-CONTEXT-T-STRUCT))>
    (14 78))
6: (SB-KERNEL::OBJECT-NOT-TYPE-ERROR-HANDLER
    #<unavailable argument>
    #.(SB-SYS:INT-SAP #XB79EF5E4)
    #<SB-ALIEN-INTERNALS:ALIEN-VALUE :SAP #XB79EF2CC :TYPE (*
                                                            (STRUCT
                                                             SB-VM::OS-CONTEXT-T-STRUCT))>
    (14 78))
7: (SB-KERNEL:INTERNAL-ERROR
    #.(SB-SYS:INT-SAP #XB79EF2CC)
    #<unavailable argument>)
8: ("foreign function: call_into_lisp")
9: ("foreign function: funcall2")
10: ("foreign function: interrupt_internal_error")
11: ("foreign function: handle_trap")
12: (SB-C::MERGE-LETS
     #<SB-C::CLAMBDA
       :%SOURCE-NAME SB-C::.ANONYMOUS.
       :%DEBUG-NAME (SB-C::VARARGS-ENTRY (LAMBDA (&REST MORE-ARGS)))
       :KIND NIL
       :TYPE #<SB-KERNEL:BUILT-IN-CLASSOID FUNCTION (read-only)>
       :WHERE-FROM :DEFINED
       :VARS (MORE-ARGS) {AD13C01}>
     #<SB-C::COMBINATION
       :FUN #<SB-C::REF
              :LEAF #<SB-C::CLAMBDA
                      :%SOURCE-NAME SB-C::.ANONYMOUS.
                      :%DEBUG-NAME (SB-C::VARARGS-ENTRY
                                    (LAMBDA (&REST MORE-ARGS)))
                      :KIND NIL
                      :TYPE #<SB-KERNEL:BUILT-IN-CLASSOID FUNCTION (read-only)>
                      :WHERE-FROM :DEFINED
                      :VARS (MORE-ARGS) {AD13C01}> {AD2C8D1}>
       :ARGS (#<SB-C::COMBINATION
                :FUN #<SB-C::REF
                       :LEAF #<SB-C::GLOBAL-VAR
                               :%SOURCE-NAME LIST
                               :TYPE #<SB-KERNEL:FUN-TYPE (FUNCTION *
                                                           (VALUES LIST
                                                                   &OPTIONAL))>
                               :WHERE-FROM :DECLARED
                               :KIND :GLOBAL-FUNCTION {AD11B61}> {AD2CA71}>
                :ARGS (#<SB-C::REF
                         :LEAF #<SB-C::LAMBDA-VAR
                                 :%SOURCE-NAME #:G69 {AD2C441}> {AD2CB51}>
                       #<SB-C::REF
                         :LEAF #<SB-C::LAMBDA-VAR
                                 :%SOURCE-NAME #:G70 {AD2C499}> {AD2CBF9}>) {AD2CAA9}>) {AD2C909}>)
13: (SB-C::LET-CONVERT
     #<SB-C::CLAMBDA
       :%SOURCE-NAME SB-C::.ANONYMOUS.
       :%DEBUG-NAME (SB-C::VARARGS-ENTRY (LAMBDA (&REST MORE-ARGS)))
       :KIND NIL
       :TYPE #<SB-KERNEL:BUILT-IN-CLASSOID FUNCTION (read-only)>
       :WHERE-FROM :DEFINED
       :VARS (MORE-ARGS) {AD13C01}>
     #<SB-C::COMBINATION
       :FUN #<SB-C::REF
              :LEAF #<SB-C::CLAMBDA
                      :%SOURCE-NAME SB-C::.ANONYMOUS.
                      :%DEBUG-NAME (SB-C::VARARGS-ENTRY
                                    (LAMBDA (&REST MORE-ARGS)))
                      :KIND NIL
                      :TYPE #<SB-KERNEL:BUILT-IN-CLASSOID FUNCTION (read-only)>
                      :WHERE-FROM :DEFINED
                      :VARS (MORE-ARGS) {AD13C01}> {AD2C8D1}>
       :ARGS (#<SB-C::COMBINATION
                :FUN #<SB-C::REF
                       :LEAF #<SB-C::GLOBAL-VAR
                               :%SOURCE-NAME LIST
                               :TYPE #<SB-KERNEL:FUN-TYPE (FUNCTION *
                                                           (VALUES LIST
                                                                   &OPTIONAL))>
                               :WHERE-FROM :DECLARED
                               :KIND :GLOBAL-FUNCTION {AD11B61}> {AD2CA71}>
                :ARGS (#<SB-C::REF
                         :LEAF #<SB-C::LAMBDA-VAR
                                 :%SOURCE-NAME #:G69 {AD2C441}> {AD2CB51}>
                       #<SB-C::REF
                         :LEAF #<SB-C::LAMBDA-VAR
                                 :%SOURCE-NAME #:G70 {AD2C499}> {AD2CBF9}>) {AD2CAA9}>) {AD2C909}>)
14: (SB-C::MAYBE-LET-CONVERT
     #<SB-C::CLAMBDA
       :%SOURCE-NAME SB-C::.ANONYMOUS.
       :%DEBUG-NAME (SB-C::VARARGS-ENTRY (LAMBDA (&REST MORE-ARGS)))
       :KIND NIL
       :TYPE #<SB-KERNEL:BUILT-IN-CLASSOID FUNCTION (read-only)>
       :WHERE-FROM :DEFINED
       :VARS (MORE-ARGS) {AD13C01}>)
15: (SB-C::DELETE-REF
     #<SB-C::REF
       :LEAF #<SB-C::CLAMBDA
               :%SOURCE-NAME SB-C::.ANONYMOUS.
               :%DEBUG-NAME (SB-C::VARARGS-ENTRY (LAMBDA (&REST MORE-ARGS)))
               :KIND NIL
               :TYPE #<SB-KERNEL:BUILT-IN-CLASSOID FUNCTION (read-only)>
               :WHERE-FROM :DEFINED
               :VARS (MORE-ARGS) {AD13C01}> {AD15959}>)
16: (SB-C::DELETE-BLOCK #<SB-C::CBLOCK 4 :START c1 {AD157D9}> NIL)
17: (SB-C::CLEAN-COMPONENT
     #<SB-C:COMPONENT :NAME "DEFUN DUMMY" :REANALYZE T {AD23CF9}>
     #<unavailable argument>)
18: (SB-C::IR1-OPTIMIZE
     #<SB-C:COMPONENT :NAME "DEFUN DUMMY" :REANALYZE T {AD23CF9}>
     NIL)
19: (SB-C::IR1-OPTIMIZE-UNTIL-DONE
     #<SB-C:COMPONENT :NAME "DEFUN DUMMY" :REANALYZE T {AD23CF9}>)
20: (SB-C::IR1-PHASES
     #<SB-C:COMPONENT :NAME "DEFUN DUMMY" :REANALYZE T {AD23CF9}>)
21: (SB-C::COMPILE-COMPONENT
     #<SB-C:COMPONENT :NAME "DEFUN DUMMY" :REANALYZE T {AD23CF9}>)
22: (SB-C::COMPILE-TOPLEVEL
     (#<SB-C::CLAMBDA
        :%SOURCE-NAME SB-C::.ANONYMOUS.
        :%DEBUG-NAME (SB-C::TOP-LEVEL-FORM
                      (LET ((SUM "#<...>" . "#<...>"))
                        (DEFUN "#<...>" . "#<...>")))
        :KIND :TOPLEVEL
        :TYPE #<SB-KERNEL:BUILT-IN-CLASSOID FUNCTION (read-only)>
        :WHERE-FROM :DEFINED
        :VARS NIL {AD0DEA1}>)
     NIL)
23: (SB-C::CONVERT-AND-MAYBE-COMPILE
     (LET ((SUM (MULTIPLE-VALUE-BIND (X Y) (VALUES 3 4) (+ X Y))))
       (DEFUN DUMMY (X Y) (LIST SUM (CONCAT X Y))))
     (SB-C::ORIGINAL-SOURCE-START 0 4))
24: ((FLET SB-C::DEFAULT-PROCESSOR)
     (LET ((SUM (MULTIPLE-VALUE-BIND (X Y) (VALUES 3 4) (+ X Y))))
       (DEFUN DUMMY (X Y) (LIST SUM (CONCAT X Y)))))
25: (SB-C::PROCESS-TOPLEVEL-FORM
     (LET ((SUM (MULTIPLE-VALUE-BIND (X Y) (VALUES 3 4) (+ X Y))))
       (DEFUN DUMMY (X Y) (LIST SUM (CONCAT X Y))))
     (SB-C::ORIGINAL-SOURCE-START 0 4)
     NIL)
26: (SB-C::SUB-SUB-COMPILE-FILE #<SB-C::SOURCE-INFO >)
27: ((LAMBDA ()))
28: (SB-C::%WITH-COMPILATION-UNIT #<CLOSURE (LAMBDA #) {ACB9F65}>)
29: (SB-C::SUB-COMPILE-FILE #<SB-C::SOURCE-INFO >)
30: (COMPILE-FILE "/home/ondrej/lisp/proxy-downloader/bug.lisp")
31: (SB-INT:SIMPLE-EVAL-IN-LEXENV
     (COMPILE-FILE "/home/ondrej/lisp/proxy-downloader/bug.lisp")
     #<NULL-LEXENV>)
32: (INTERACTIVE-EVAL
     (COMPILE-FILE "/home/ondrej/lisp/proxy-downloader/bug.lisp"))
33: (SB-IMPL::REPL-FUN NIL)
34: (SB-IMPL::REPL-FUN NIL)
35: ((LAMBDA ()))
36: ((LAMBDA ()))
37: (SB-IMPL::%WITH-REBOUND-IO-SYNTAX #<CLOSURE (LAMBDA #) {ACA6535}>)
38: (SB-IMPL::TOPLEVEL-REPL NIL)
39: (SB-IMPL::TOPLEVEL-INIT)
40: ((LABELS SB-IMPL::RESTART-LISP))

unhandled condition in --disable-debugger mode, quitting
;
; compilation unit aborted
;   caught 1 fatal ERROR condition

; compilation aborted after 0:00:00

Best regards,

Ondrej Svitek