Skip to content

Commit 61f0793

Browse files
committed
Look for keywords in inactive #if regions when checking for variable uses
Fixes issue #79555
1 parent db761dc commit 61f0793

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

lib/ASTGen/Sources/ASTGen/CompilerBuildConfiguration.swift

+7-3
Original file line numberDiff line numberDiff line change
@@ -359,11 +359,15 @@ private enum InactiveCodeChecker {
359359
// match.
360360
switch self {
361361
case .name(let name):
362-
guard let identifier = token.identifier, identifier.name == name else {
363-
continue
362+
if let identifier = token.identifier, identifier.name == name {
363+
break
364364
}
365365

366-
break
366+
if case .keyword = token.tokenKind, token.text == name {
367+
break
368+
}
369+
370+
continue
367371

368372
case .tryOrThrow:
369373
guard let keywordKind = token.keywordKind,

test/decl/var/usage.swift

+13
Original file line numberDiff line numberDiff line change
@@ -571,3 +571,16 @@ func testEnumeratedForLoop(a: [Int]) {
571571
let _ = c
572572
}
573573
}
574+
575+
// https://github.com/swiftlang/swift/issues/79555
576+
final class A {
577+
var x: () -> Void {
578+
{ [weak self] in // Used to warn: variable 'self' was written to, but never read
579+
#if NOT_PROCESSED
580+
self?.f()
581+
#endif
582+
}
583+
}
584+
585+
func f() {}
586+
}

0 commit comments

Comments
 (0)