Surprising identifier binding ambiguity error with nested splicing-local (possible bug)

I encountered a surprising identifier binding ambiguity error when using splicing-local within the body of another splicing-local. Am I misusing splicing-local, or is this a bug?

Here's a small reproduction of the problem:

;;; splicing-bug.rkt
#lang racket/base
(require racket/splicing)

;; This one works.
;(splicing-local
;  ((define one 0)
;   (define (two) one))
;  3)

;; This one produces an error:
(splicing-local
  ()
  (splicing-local
    ((define one 0)
     (define (two) one))
    3))
;> racket splicing-bug.rkt
;splicing-bug.rkt:16:19: one: identifier's binding is ambiguous
;  in: one
;  context...:
;   #(536 intdef-outside) #(537 intdef) #(538 intdef-outside)
;   #(539 intdef) #(735 intdef-outside) #(736 intdef) #(747 local)
;   #(748 intdef) [common scopes]
;  matching binding...:
;   #(one.1 #<module-path-index='splicing-bug[253]> 0)
;   #(735 intdef-outside) #(736 intdef) [common scopes]
;  matching binding...:
;   local
;   #(536 intdef-outside) #(537 intdef) #(538 intdef-outside)
;   #(539 intdef) [common scopes]
;  common scopes...:
;   #(9 module) #(467 module splicing-bug) #(612 intdef)
;  location...:
;   splicing-bug.rkt:16:19
1 Like

A further oddity is that it works fine in an expression context:

#lang racket/base
(require racket/splicing)

(#%expression
 (splicing-local []
   (splicing-local [(define one 0)
                    (define (two) one)]
     3)))

Yes, this definitely seems like a bug. I’ll open an issue and look into this at some point.

1 Like