Skip to content

macroexpand-1 handling of shadowing in lexical environment #1556

@fb08af68

Description

@fb08af68

Describe the bug

In a local lexical environment, functions defined by flet shadow macros introduced both by macrolet and defmacro. Normal execution implements this, but macroexpand-1 doesn't seem to.

Expected behavior

(macroexpand-1 '(f) env) returns (f) when f is in env as a function introduced by flet, regardless of presence of global macros defined by defmacro or lexically-scoped macros defined by macrolet.

Actual behavior

A macro is expanded. An older version failed to shadow both local and global ones, a fresh version shadows the local ones but the global macros are still not shadowed.

Code at issue

(defmacro g () 3)
(macrolet ((g () 1) 
                   (e (x &environment env) 
                   `',(macroexpand-1 x env)))
  (flet ((g () 2)) 
    (e (g))))

Expected: (g)
Actual on 2.2.0 from Nixpkgs: 1
Actual on 2.5.0 on Debian Bookworm from thirdlaw.tech repo: 3

If (e (g)) is replaced with (progn (g)), both expected an actual behaviour is to return 2.

Context

  • Versions or commit hashes of Clasp on which you observed the problem (if you have built from up to date source, saying so is fine, you don't need to dig around for hashes)

2.5.0-85-gd23de8b43

  • If relevant, your operating system and other aspects of your computing environment

Freshly installed Debian Bookworm VM

  • If you believe the compiler may be at fault, relevant declarations, including optimize settings (use (clasp-cltl2:declaration-information 'optimize))

Not changed; everything equal to 1

  • Any other context about the problem

Hopefully irrelevant, but https://gitlab.common-lisp.net/mraskin/agnostic-lizard/-/issues/6 (trying to check if examples.lisp failures are my fault or bugs in Clasp)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions