Skip to content

Commit

Permalink
repair for for expansion
Browse files Browse the repository at this point in the history
  • Loading branch information
mflatt committed Jul 26, 2023
1 parent a023513 commit b13e917
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
23 changes: 23 additions & 0 deletions pkgs/racket-test-core/tests/racket/for.rktl
Original file line number Diff line number Diff line change
Expand Up @@ -1458,6 +1458,29 @@
(test '(1)
eval-syntax #`(for/list ([(k v) (quote #,(datum->syntax #f #hash((1 . 0))))]) k))

;; ----------------------------------------
;; regression test for a missing "outer edge" scope

(let ()
(define-sequence-syntax in-digits
(lambda () #'values)
(lambda (stx)
(syntax-case stx ()
[[(d) (_ nat)]
#'[(d)
(:do-in
([(n) nat])
values
([i n])
(not (zero? i))
([(j d) (quotient/remainder i 10)])
#t
#t
[(- i 1)])]] ; <- regression would make this `i` ambigious
[_ #f])))

(for ([i (in-digits 12)]) i))

;; ----------------------------------------

(report-errs)
10 changes: 9 additions & 1 deletion racket/collects/racket/private/for.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -1775,7 +1775,15 @@
orig-stx
stx)])))

(define ((make for*? right?) stx)
(define ((make for*? right?) stx-in)
;; Add a fresh scope that acts the "outer edge" scope of `let`, so
;; that as we expand clause transformers, we don't end up with
;; ambiguities between things that started out in the form and that
;; were introduced by expansion. This is necessary due to the way
;; `for` performs its own expansion of clauses.
(define stx (internal-definition-context-add-scopes
(syntax-local-make-definition-context)
stx-in))
(syntax-case stx ()
[(_ orig-stx bindings+options . rest)
(let ()
Expand Down

0 comments on commit b13e917

Please sign in to comment.