File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -673,13 +673,13 @@ fn translation_rules() -> Vec<Rule<SwiftContext>> {
673673 =>
674674 ( switch_case body: ( block stmt: { ..body} ) )
675675 ) ,
676- // if case let x = expr — the pattern is taken as-is (no Optional wrapping)
676+ // if case PATTERN = expr — preserve the pattern directly (no Optional wrapping)
677677 rule!(
678- ( if_let_binding "case" ( value_binding_pattern ) bound_identifier : @name _ @val)
678+ ( if_let_binding "case" pattern : @pat value : @val)
679679 =>
680680 ( pattern_guard_expr
681681 value: { val}
682- pattern: ( name_pattern identifier : ( identifier # { name } ) ) )
682+ pattern: { pat } )
683683 ) ,
684684 rule!(
685685 ( if_let_binding
Original file line number Diff line number Diff line change @@ -594,6 +594,83 @@ top_level
594594 name_expr
595595 identifier: identifier "x"
596596
597+ ===
598+ If-case-let with shadowing in condition value
599+ ===
600+
601+ if case let x = x + 10 {
602+ print(x)
603+ }
604+
605+ ---
606+
607+ source_file
608+ statement:
609+ if_statement
610+ body:
611+ block
612+ statement:
613+ call_expression
614+ function: simple_identifier "print"
615+ suffix:
616+ call_suffix
617+ arguments:
618+ value_arguments
619+ argument:
620+ value_argument
621+ value: simple_identifier "x"
622+ condition:
623+ if_condition
624+ kind:
625+ if_let_binding
626+ pattern:
627+ pattern
628+ kind:
629+ binding_pattern
630+ binding:
631+ value_binding_pattern
632+ mutability: let
633+ pattern:
634+ pattern
635+ bound_identifier: simple_identifier "x"
636+ value:
637+ additive_expression
638+ lhs: simple_identifier "x"
639+ op: +
640+ rhs: integer_literal "10"
641+
642+ ---
643+
644+ top_level
645+ body:
646+ block
647+ stmt:
648+ if_expr
649+ condition:
650+ pattern_guard_expr
651+ pattern:
652+ name_pattern
653+ identifier: identifier "x"
654+ value:
655+ binary_expr
656+ operator: infix_operator "+"
657+ left:
658+ name_expr
659+ identifier: identifier "x"
660+ right: int_literal "10"
661+ then:
662+ block
663+ stmt:
664+ call_expr
665+ argument:
666+ argument
667+ value:
668+ name_expr
669+ identifier: identifier "x"
670+ callee:
671+ name_expr
672+ identifier: identifier "print"
673+
597674===
598675Switch with binding pattern
599676===
You can’t perform that action at this time.
0 commit comments