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

[SR-13821] Variables never mutated in lazy properties should generate a warning #56219

Open
swift-ci opened this issue Nov 3, 2020 · 3 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself

Comments

@swift-ci
Copy link
Collaborator

swift-ci commented Nov 3, 2020

Previous ID SR-13821
Radar rdar://problem/71041013
Original Reporter TheCD (JIRA User)
Type Bug
Environment

OS: macOS 10.15.7

Xcode: 12.1 (12A7403)

SDK: iOS 14.1

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug
Assignee maustinstar (JIRA)
Priority Medium

md5: a76f43f6511ceb0126fc0e579f8fd3ba

relates to:

  • SR-11992 Unused variables in lazy properties should generate a warning

Issue Description:

In the code below, var x = 42 appropriately gives us an 'x' was never mutated warning. However, the var z = 42 does not.

class Foo {
    lazy var y: Int = {
        var z = 42
        return z
    }()

    func run() {
        var x = 42 // Variable 'x' was never mutated; consider changing to 'let' constant
        print("\(x)")
    }
}

Variables never mutated in lazy properties should produce the never mutated variable warning.

@typesanitizer
Copy link

This doesn't seem to be related to lazy properties specifically.

struct S {
  var x: Int = {
    var y = 42
    return y
  }()
} 

Also does not show any warning.

@typesanitizer
Copy link

@swift-ci create

@swift-ci
Copy link
Collaborator Author

swift-ci commented Nov 6, 2020

Comment by Michael Verges (JIRA)

See my PR: #34617

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
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. compiler The Swift compiler in itself
Projects
None yet
Development

No branches or pull requests

2 participants