Opened 5 years ago

Last modified 3 years ago

#1441 closed defect

Macro keywords unexpectedly match against imported identifiers — at Version 1

Reported by: sjamaan Owned by: sjamaan
Priority: major Milestone: 5.1
Component: expander Version: 4.13.0
Keywords: hygiene, syntax-rules, capture Cc:
Estimated difficulty: hard

Description (last modified by sjamaan)

As reported by Joerg Wittenberger, Al Petrofsky's "unhygienic extraction" of identifiers via syntax-rules keywords list fails when the identifier was imported from another module.

A simplified example:

(module break (break)
  (import scheme)
  (define break "elsewhere"))

(module unhygienic-loop (loop)
  (import scheme)

(define-syntax find-identifier
  (syntax-rules ()
    ((_ ident (x . y) sk fk)
     (find-identifier ident x sk (find-identifier ident y sk fk)))
    ((_ ident #(x ...) sk fk)
     (find-identifier ident (x ...) sk fk))
    ((_ ident form sk fk)
           (syntax-rules (ident)
             ((_ ident ident* (s-f . s-args) fk_) (s-f ident* . s-args))
             ((_ x y sk_ fk_) fk_))))
       (check form form sk fk)))))

(define-syntax loop
  (syntax-rules ()
    ((_ . exps)
         ((l (syntax-rules ()
               ((_ ident exps_)
                 (lambda (ident)
                   (let f ()
                     (begin 'prevent-empty-begin . exps_)
       (find-identifier break exps (l exps) (l bogus exps)))))))

(module foo ()

(import scheme break unhygienic-loop)

;; Uncomment these and comment the above to see the differing behaviour:
;; (import scheme unhygienic-loop)

;; This definition is not required
;; (define break "local")

(display (loop (break 'foo))))

This appears to be incorrect, at least when compared to Chibi on an equivalent set of R7RS modules, it behaves identically in the case where the identifier is defined locally, undefined, or defined by another module.

In CHICKEN 4.12 and earlier, this code behaves the same regardless of where the identifier came from.

Change History (1)

comment:1 Changed 5 years ago by sjamaan

Description: modified (diff)
Note: See TracTickets for help on using tickets.