Skip to content

Commit

Permalink
Double-check that neighbors have neighboring srclocs
Browse files Browse the repository at this point in the history
With code like `(a b c . -> . d)`, which uses racket's infix `.` notation, the "are these syntax objects neighbors?" check goes a little sideways. This fix seems to mostly deal with the issue. Maybe.
  • Loading branch information
jackfirth committed Sep 1, 2024
1 parent dc50be0 commit 5f1945c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
10 changes: 4 additions & 6 deletions default-recommendations/contract-shortcuts.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,13 @@
(define-refactoring-rule arrow-contract-with-rest-to-arrow-contract-with-ellipses
#:description "This `->*` contract can be rewritten using `->` with ellipses."
#:literals (->* listof)
[((~and arrow-id ->*)
(~and args (arg-contract ...))
[(->*
(arg-contract ...)
(~optional ())
(~and rest-kw #:rest) (~and rest-list (listof rest-contract))
#:rest (~and rest-list (listof rest-contract))
result-contract)
(-> (ORIGINAL-GAP arrow-id args)
arg-contract ...
(-> arg-contract ...
rest-contract (... ...)
(ORIGINAL-GAP rest-list result-contract)
result-contract)])


Expand Down
7 changes: 5 additions & 2 deletions private/syntax-neighbors.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,12 @@
(for/list ([leading (in-list leading-neighbors)]
[trailing (in-list trailing-neighbors)]
[subform-stx (in-list (attribute subform))])
(define leading-pos (and leading (syntax-position leading)))
(define trailing-pos (and trailing (syntax-position trailing)))
(define subform-pos (syntax-position subform-stx))
(mark-neighbors (syntax-mark-original-neighbors subform-stx)
#:leading-neighbor leading
#:trailing-neighbor trailing)))
#:leading-neighbor (and leading (< leading-pos subform-pos) leading)
#:trailing-neighbor (and trailing (< subform-pos trailing-pos) trailing))))
(datum->syntax stx results stx stx)]
[_ stx]))

Expand Down

0 comments on commit 5f1945c

Please sign in to comment.