expander: propagate srcloc on rename-transformer expansion

This commit is contained in:
Matthew Flatt 2018-02-28 13:59:13 -07:00
parent 3c69a1296a
commit de27be536d
3 changed files with 1022 additions and 980 deletions

View File

@ -2524,4 +2524,15 @@
;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(test #t
'rename-transformer-srcloc
;; make sure `cons` in the expansion gets the same source line as `1`
(let ([stx (expand #'(letrec-syntax ([kons (make-rename-transformer #'cons)])
(kons 1 2)))])
(syntax-case stx ()
[(_ () (_app cons one . _))
(equal? (syntax-line #'cons) (syntax-line #'one))])))
;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(report-errs)

View File

@ -292,7 +292,9 @@
[(expand-context-just-once? ctx) exp-s]
[else (expand exp-s re-ctx
#:alternate-id (and (rename-transformer? t)
(syntax-track-origin (rename-transformer-target-in-context t ctx)
(syntax-track-origin (transfer-srcloc
(rename-transformer-target-in-context t ctx)
id)
id
id))
#:skip-log? (or (expand-context-only-immediate? ctx)
@ -742,3 +744,12 @@
(when (rename-transformer? val)
(parameterize ([current-expand-context ctx])
(maybe-install-free=id! val id phase))))
;; Transfer the original ID's source location, if any, when expanding
;; a reference to a rename transformer
(define (transfer-srcloc new-s old-s)
(define srcloc (syntax-srcloc old-s))
(if srcloc
(struct-copy syntax new-s
[srcloc srcloc])
new-s))

File diff suppressed because it is too large Load Diff