@@ -82,40 +82,8 @@ private extension VariableShadowingRule {
8282 return super. visit ( node)
8383 }
8484
85- override func visit( _ node: CodeBlockItemListSyntax ) -> SyntaxVisitorContinueKind {
86- guard let parent = node. parent else {
87- return super. visit ( node)
88- }
89-
90- // Call super first so the base visitor opens the child scope and collects identifiers
91- let kind = super. visit ( node)
92-
93- // Check conditions if this is an if/while body AFTER identifiers from conditions were collected
94- if let ifStmt = parent. as ( IfExprSyntax . self) {
95- checkForShadowingInConditions ( ifStmt. conditions)
96- } else if let whileStmt = parent. as ( WhileStmtSyntax . self) {
97- checkForShadowingInConditions ( whileStmt. conditions)
98- }
99-
100- return kind
101- }
102-
103- override func visitPost( _ node: GuardStmtSyntax ) {
104- // Let the base visitor collect identifiers first (it does so in its visitPost)
105- super. visitPost ( node)
106- // Check for shadowing in guard conditions after collection
107- checkForShadowingInConditions ( node. conditions)
108- }
109-
110- private func checkForShadowingInConditions( _ conditions: ConditionElementListSyntax ) {
111- for element in conditions {
112- if let binding = element. condition. as ( OptionalBindingConditionSyntax . self) {
113- checkForShadowing ( in: binding. pattern)
114- }
115- }
116- }
117-
11885 private func checkForShadowing( in pattern: PatternSyntax ) {
86+ // Handle direct identifier patterns
11987 if let identifier = pattern. as ( IdentifierPatternSyntax . self) {
12088 let identifierText = identifier. identifier. text
12189 if isShadowingOuterScope ( identifierText) {
@@ -124,13 +92,20 @@ private extension VariableShadowingRule {
12492 return
12593 }
12694
95+ // Recurse into tuple patterns: e.g., (a, b)
12796 if let tuple = pattern. as ( TuplePatternSyntax . self) {
12897 tuple. elements. forEach { element in
12998 checkForShadowing ( in: element. pattern)
13099 }
131100 return
132101 }
133102
103+ // Recurse into value binding patterns: e.g., `let a`, `var (a, b)`
104+ if let valueBinding = pattern. as ( ValueBindingPatternSyntax . self) {
105+ checkForShadowing ( in: valueBinding. pattern)
106+ return
107+ }
108+
134109 // Other pattern kinds are not relevant for shadowing checks here; no action needed.
135110 }
136111
0 commit comments