Skip to content

Commit ae28833

Browse files
authored
Merge pull request github#9511 from MathiasVP/fix-completion-for-patterns
Swift: Fix completion for "naked" patterns
2 parents 32ef535 + 9d7afab commit ae28833

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)