Skip to content

Commit 2470c13

Browse files
committed
Fix: preserve switch case patterns in desugared output
The switch_entry rule was capturing switch_pattern wrapper nodes instead of drilling into them to extract the actual pattern nodes. This caused patterns from switch cases to be lost during desugaring. Changed the pattern match from: (switch_entry pattern: (switch_pattern)* @pats ...) to: (switch_entry pattern: (switch_pattern pattern: @pats)* ...) This now correctly extracts the pattern field from each switch_pattern node, ensuring that patterns from cases like 'case 1:' and 'case .circle(let r):' are preserved in the switch_case AST nodes. Updated control-flow.txt corpus outputs to reflect the new behavior.
1 parent fa98557 commit 2470c13

2 files changed

Lines changed: 7 additions & 3 deletions

File tree

unified/extractor/src/languages/swift/swift.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,7 @@ fn translation_rules() -> Vec<yeast::Rule> {
481481
),
482482
// Switch entry with patterns and body
483483
rule!(
484-
(switch_entry pattern: (switch_pattern)* @pats statement: _* @body)
484+
(switch_entry pattern: (switch_pattern pattern: @pats)* statement: _* @body)
485485
=>
486486
(switch_case pattern: {..pats} body: (block stmt: {..body}))
487487
),
@@ -491,8 +491,6 @@ fn translation_rules() -> Vec<yeast::Rule> {
491491
=>
492492
(switch_case body: (block stmt: {..body}))
493493
),
494-
// Switch pattern — unwrap to inner pattern
495-
rule!((switch_pattern (pattern)* @inner) => {..inner}),
496494
// if case let x = expr — the pattern is taken as-is (no Optional wrapping)
497495
rule!(
498496
(if_let_binding "case" (value_binding_pattern) bound_identifier: @name _ @val)

unified/extractor/tests/corpus/swift/control-flow.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -558,6 +558,7 @@ top_level
558558
callee:
559559
name_expr
560560
identifier: identifier "print"
561+
pattern: tuple_pattern "1"
561562
switch_case
562563
body:
563564
block
@@ -569,6 +570,9 @@ top_level
569570
callee:
570571
name_expr
571572
identifier: identifier "print"
573+
pattern:
574+
tuple_pattern "2"
575+
tuple_pattern "3"
572576
switch_case
573577
body:
574578
block
@@ -688,6 +692,7 @@ top_level
688692
callee:
689693
name_expr
690694
identifier: identifier "print"
695+
pattern: tuple_pattern ".circle(let r)"
691696
switch_case
692697
body:
693698
block
@@ -701,6 +706,7 @@ top_level
701706
callee:
702707
name_expr
703708
identifier: identifier "print"
709+
pattern: tuple_pattern ".square(let s)"
704710
value:
705711
name_expr
706712
identifier: identifier "shape"

0 commit comments

Comments
 (0)