File tree Expand file tree Collapse file tree 2 files changed +30
-2
lines changed Expand file tree Collapse file tree 2 files changed +30
-2
lines changed Original file line number Diff line number Diff line change @@ -446,3 +446,29 @@ no-change-test: "list element variable definitions not refactorable when referen
446446 (define z (list-ref (first pt-list) 2 ))
447447 (+ x y z))
448448------------------------------
449+
450+
451+ test: "refactoring list element variable definitions to match-define doesn't reformat surroundings "
452+ ------------------------------
453+ (require racket/list)
454+ (define (f pt)
455+
456+ ( void )
457+
458+ (define x (list-ref pt 0 ))
459+ (define y (list-ref pt 1 ))
460+ (define z (list-ref pt 2 ))
461+
462+ ; comment
463+ ( + x y z ))
464+ ==============================
465+ (require racket/list)
466+ (define (f pt)
467+
468+ ( void )
469+
470+ (match-define (list x y z) pt)
471+
472+ ; comment
473+ ( + x y z ))
474+ ------------------------------
Original file line number Diff line number Diff line change 247247`match-define`. Note that the suggested replacement raises an error if the list contains more \
248248elements than expected. "
249249 #:literals (define )
250- (~seq body-before ... (define v:id ref-expr:list-ref-expr) ...+ body-after ... )
250+ (~seq body-before ... (~and definition ( define v:id ref-expr:list-ref-expr)) ...+ body-after ...+ )
251251 #:do [(define num-vars (length (attribute v)))]
252252 #:with first-list-id (first (attribute ref-expr.list-id))
253253 #:when (for/and ([list-id (in-list (rest (attribute ref-expr.list-id)))])
@@ -257,7 +257,9 @@ elements than expected."
257257 id:id
258258 #:when (free-identifier=? (attribute id) (attribute first-list-id))
259259 #:when (not (equal? (syntax-property (attribute id) 'usage-count ) num-vars))))
260- (body-before ... (match-define (list v ... ) first-list-id) body-after ... ))
260+ #:with match-definition
261+ #'(~replacement (match-define (list v ... ) first-list-id) #:original-splice (definition ... ))
262+ (body-before ... (~focus-replacement-on match-definition) body-after ... ))
261263
262264
263265(define-refactoring-suite match-shortcuts
You can’t perform that action at this time.
0 commit comments