Skip to content
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

Assigning a variable to itself doesn't yield a warning/error inside a closure #80047

Open
layoutSubviews opened this issue Mar 16, 2025 · 0 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. triage needed This issue needs more specific labels

Comments

@layoutSubviews
Copy link

Description

The logic that checks whether a variable is (mistakingly) assigned to itself is not working when the assignment is in a closure.

This currently happens with Xcode 16.3 beta 2.

Reproduction

let _ = {
    var b = false
    b = b // No warning or error
}

var a = false
a = a // Error: Assigning a variable to itself

Expected behavior

b = b should yield a warning and/or error as this code is illogical.

Environment

swift-driver version: 1.120.5 Apple Swift version 6.1 (swiftlang-6.1.0.109.103 clang-1700.0.13.2)

Additional information

This looks like a silly bug, but this prevented the compiler from catching a fairly nasty bug that was hitting many customers in our apps. A functional warning would have prevented this bug from shipping in the first place.

@layoutSubviews layoutSubviews added bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. triage needed This issue needs more specific labels labels Mar 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. triage needed This issue needs more specific labels
Projects
None yet
Development

No branches or pull requests

1 participant