Skip to content

Commit f9e102a

Browse files
committed
unified: Fix extraction bug
The special-cased labelExpr rules were simply unnecessary
1 parent 7d263ad commit f9e102a

3 files changed

Lines changed: 4 additions & 30 deletions

File tree

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

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -672,33 +672,7 @@ fn translation_rules() -> Vec<Rule<SwiftContext>> {
672672
tree!((call_expr callee: {callee} argument: {args}))
673673
}
674674
),
675-
// A call or enum-case pattern argument. Both use the shared `argument`
676-
// shape, preserving the optional label as `name` and the child as `value`.
677-
// The pattern-only shapes (`patternExpr`, `discardAssignmentExpr`) are
678-
// matched first; they never occur as ordinary call arguments.
679-
rule!(
680-
(labeledExpr
681-
label: _? @@lbl
682-
expression: (functionCallExpr
683-
calledExpression: @constructor
684-
arguments: _* @elements))
685-
=>
686-
argument {
687-
tree!((argument
688-
name_node: (identifier #{lbl})?
689-
value: (call_expr callee: {constructor} argument: {elements})))
690-
}
691-
),
692-
rule!(
693-
(labeledExpr label: _? @@lbl expression: (patternExpr pattern: @p))
694-
=>
695-
(argument name_node: (identifier #{lbl})? value: {p})
696-
),
697-
rule!(
698-
(labeledExpr label: _? @@lbl expression: (discardAssignmentExpr) @@wildcard)
699-
=>
700-
(argument name_node: (identifier #{lbl})? value: (identifier #{wildcard}))
701-
),
675+
// A call or enum-case pattern argument.
702676
rule!(
703677
(labeledExpr label: _? @@lbl expression: @val)
704678
=>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
| test.swift:2:9:2:9 | a | Unused local variable 'a' |
2-
| test.swift:12:9:12:9 | a | Unused local variable 'a' |
2+
| test.swift:16:13:16:13 | b | Unused local variable 'b' |

‎unified/ql/test/query-tests/unusedentities/test.swift‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ func t2() -> Int {
1010
return "df"
1111
}
1212
// Note: This currently fails because the trailing closure is not extracted correctly
13-
let a = 1 // $ SPURIOUS: Alert
13+
let a = 1
1414
print(foo() { _ in
1515
print(a)
16-
let b = 2 // $ MISSING: Alert[unified/unused-variable]
16+
let b = 2 // $ Alert[unified/unused-variable]
1717
})
1818
}

0 commit comments

Comments
 (0)