Skip to content

LABELS local function fails to shadow top-level function under some circumstances #591

Open
@slburson

Description

@slburson

To see this, in a fresh ABCL 1.9.1, do:

(ql:quickload "fset")
(in-package :fset-user)
(defun foo (x)
  (labels ((bar (x)
             (cond ((null x) nil)
                   ((eq (car x) '&rest) (tail (cadr x)))
                   (t (cons (car x) (bar (cdr x))))))
           (tail (x)
             (list 'local-tail x)))
    (bar x)))
(compile 'foo)
(foo '(a &rest b))

Expected: (A LOCAL-TAIL B)

Actual: 
The value B is not of type LIST.
   [Condition of type TYPE-ERROR]

What seems to be going on there is that fset:tail, which is imported, is defined thus:

(defun tail (list)
  "Another name for the `cdr' operation on lists."
  (cdr list))

(declaim (inline tail))

My guess is that the inline declaration is somehow confusing matters so that the local function tail doesn't get called from bar. But oddly, I have not been able to produce a simple example, without using FSet, that fails. Evidently, there's some other condition required, that I haven't identified, for the bug to bite. It's easy to see that the name matters, though; just rename the local function:

(defun foo (x)
           (labels ((bar (x)
                      (cond ((null x) nil)
                            ((eq (car x) '&rest) (tailx (cadr x)))
                            (t (cons (car x) (bar (cdr x))))))
                    (tailx (x)
                      (list 'local-tail x)))
             (bar x)))

This works as expected.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions