Skip to content

Commit 9d7afab

Browse files
committed
Swift: Fix completion for patterns that occur outside 'CaseLabelItems'. Previously we'd add an unnecessary 'no-match' completion to these patterns even though they were always matching. This caused some confusing output in the graph tests in particular.
1 parent e1c7de9 commit 9d7afab

File tree

2 files changed

+71
-65
lines changed

2 files changed

+71
-65
lines changed

swift/ql/lib/codeql/swift/controlflow/internal/Completion.qll

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,11 +265,22 @@ private predicate isIrrefutableMatch(Pattern p) {
265265
isIrrefutableMatch(p.getResolveStep())
266266
}
267267

268+
/**
269+
* Holds if the ast node `ast` is a (possibly top-level) pattern that constantly matches (`value = true`) or
270+
* constantly non-matches (`value = false`).
271+
*/
272+
private predicate isMatchingConstant(AstNode ast, boolean value) {
273+
isMatchingConstantItem(ast, value)
274+
or
275+
isIrrefutableMatch(ast) and
276+
value = true
277+
}
278+
268279
/**
269280
* Holds if the top-level pattern `cli` constantly matches (`value = true`) or
270281
* constantly non-matches (`value = false`).
271282
*/
272-
private predicate isMatchingConstant(CaseLabelItem cli, boolean value) {
283+
private predicate isMatchingConstantItem(CaseLabelItem cli, boolean value) {
273284
// If the pattern always matches
274285
isIrrefutableMatch(cli.getPattern()) and
275286
(

0 commit comments

Comments
 (0)