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

redundant_optional_initialization rule bug #1159

Closed
Agarunov opened this issue Jan 11, 2017 · 5 comments
Closed

redundant_optional_initialization rule bug #1159

Agarunov opened this issue Jan 11, 2017 · 5 comments
Labels
bug Unexpected and reproducible misbehavior.

Comments

@Agarunov
Copy link

Agarunov commented Jan 11, 2017

class Foo: NSObject {
    let descr: String?
    let name: String?

    lazy private(set) var bazz: String = {
        if self.name != nil && self.name!.isEmpty == false {
            return self.name!
        } else {
            return ""
        }

    }()

   ...
}

this code (self.name != nil) cause redundant_optional_initialization violation

SwiftLint 0.16.0

@marcelofabri
Copy link
Collaborator

Are you using Swift 2.3?

@Agarunov
Copy link
Author

@marcelofabri Swift 3.0

@marcelofabri
Copy link
Collaborator

I couldn't reproduce it with Swift 3.0 and 0.16 😬

Are you sure this isolated example triggers?

@Agarunov
Copy link
Author

Agarunov commented Jan 11, 2017

@marcelofabri sorry for wrong example

Here is new code which repoduce bug

class Address: NSObject {
    
    let country: String?
    let city: String?
        
    lazy private(set) var fullAddress: String? = {
        var names = [String]()

        if self.country != nil && self.country!.isEmpty == false {
            names.append(self.country!)
        }
        
        if self.city != nil && self.city!.isEmpty == false {
            names.append(self.city!)
        }

        return names.joined(separator: ", ")
    }()
        
    init(country: String?, city: String?) {
        self.country = country
        self.city = city
    }
    
}

code self.name != nil cause redundant_optional_initialization violation

@marcelofabri
Copy link
Collaborator

OK, I was able to reproduce it now. Thanks!

@marcelofabri marcelofabri added the bug Unexpected and reproducible misbehavior. label Jan 11, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Unexpected and reproducible misbehavior.
Projects
None yet
Development

No branches or pull requests

2 participants