Skip to content

Look for keywords in inactive #if regions when checking for variable uses #79597

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions lib/ASTGen/Sources/ASTGen/CompilerBuildConfiguration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -359,11 +359,15 @@ private enum InactiveCodeChecker {
// match.
switch self {
case .name(let name):
guard let identifier = token.identifier, identifier.name == name else {
continue
if let identifier = token.identifier, identifier.name == name {
break
}

break
if case .keyword = token.tokenKind, token.text == name {
break
}

continue

case .tryOrThrow:
guard let keywordKind = token.keywordKind,
Expand Down
13 changes: 13 additions & 0 deletions test/decl/var/usage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -571,3 +571,16 @@ func testEnumeratedForLoop(a: [Int]) {
let _ = c
}
}

// https://github.com/swiftlang/swift/issues/79555
final class A {
var x: () -> Void {
{ [weak self] in // Used to warn: variable 'self' was written to, but never read
#if NOT_PROCESSED
self?.f()
#endif
}
}

func f() {}
}