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

Rule request: newValue ignored on var set #1136

Closed
fpg1503 opened this Issue Jan 9, 2017 · 7 comments

Comments

Projects
None yet
4 participants
@fpg1503
Copy link

fpg1503 commented Jan 9, 2017

I've seen a lot of times people using the variable name instead of newValue which leads to bugs:

var aValue: String {
    get {
        return Persister.shared.aValue
    }
    set {
        Perister.shared.aValue = aValue //should be newValue
    }
}
@marcelofabri

This comment has been minimized.

Copy link
Collaborator

marcelofabri commented Jan 9, 2017

A small detail here is that you can use another name for the parameter. For example:

// shouldn't trigger
var aValue: String {
    get {
        return Persister.shared.aValue
    }
    set(persistedValue) {
        Perister.shared.aValue = persistedValue
    }
}
@marcelofabri

This comment has been minimized.

Copy link
Collaborator

marcelofabri commented May 2, 2017

There's an open ticket on Swift JIRA for this as well: SR-964

@marcelofabri

This comment has been minimized.

Copy link
Collaborator

marcelofabri commented Sep 27, 2017

Closing this as apple/swift#11465 was merged and it'll be a compiler warning in future Swift versions 🎉

@ZevEisenberg

This comment has been minimized.

Copy link

ZevEisenberg commented Aug 3, 2018

Note that a case was missed in the resolution to SR-964, and the PR for the fix never ended up getting merged, so SwiftLint could still provide a band-aid (or anyone who's interested could pick up that PR and port it to Swift 4.2 or 5.0).

@marcelofabri

This comment has been minimized.

Copy link
Collaborator

marcelofabri commented Jan 18, 2019

Going to revive this because we're just bitten by it, so I guess the compiler warning never really shipped on 4.2

@jgavris

This comment has been minimized.

Copy link

jgavris commented Jan 25, 2019

Would it be possible to ignore properties that are marked as unavailable? This is a bit unfortunate.

screen shot 2019-01-25 at 2 23 31 pm

@marcelofabri

This comment has been minimized.

Copy link
Collaborator

marcelofabri commented Jan 25, 2019

@jgavris please open a new issue to track this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment