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

False Colon Violation inside guard and ternary operator #2806

Closed
Lukasz2891 opened this issue Jul 9, 2019 · 5 comments · Fixed by #2836
Closed

False Colon Violation inside guard and ternary operator #2806

Lukasz2891 opened this issue Jul 9, 2019 · 5 comments · Fixed by #2836
Labels
bug Unexpected and reproducible misbehavior.

Comments

@Lukasz2891
Copy link

In 0.33.x

guard let requestData = try? JSONSerialization.data(withJSONObject: dictionary, options: .prettyPrinted),
            let storeURL = sandbox ? Self.sandboxStoreURL : Self.productionStoreURL else {
                return ...
        }

produces false Colon Violation (colon) inside the ternary ?: operator.

@Lukasz2891 Lukasz2891 changed the title False Colon Violation inside guard False Colon Violation inside guard and ternary operator Jul 9, 2019
@marcelofabri marcelofabri added the bug Unexpected and reproducible misbehavior. label Jul 9, 2019
@a-25
Copy link
Contributor

a-25 commented Jul 22, 2019

Hello, @Lukasz2891. Could you please post the whole method and all variables included? I could not understand what kind of variables sandboxStoreURL and productionStoreURL are.
I tried to check like below but it does not compile (Xcode 10.2.1).

class TestClass {
    public static var sandboxStoreURL: String? = "sandboxStoreURL"
    public static var productionStoreURL: String? = "productionStoreURL"
    public static var sandbox = false
}

class TestSubclass: TestClass {
    func test() -> String {
        let dict = ["dictKey":"dictValue"]
        guard let requestData = try? JSONSerialization.data(withJSONObject: dict, options: .prettyPrinted),
            let storeURL = sandbox ? Self.sandboxStoreURL : Self.productionStoreURL else {
                return "empty"
        }
        return "\(requestData)\(storeURL)"
    }
}

The essence of this bug it Self keyword. I tried 0.34 version, replaced Self with self and bug has gone.

@Lukasz2891
Copy link
Author

It’s a default extension to a protocol so big „Self” is needed as a not specified type.

See: https://stackoverflow.com/questions/42037852/why-do-self-and-self-sometimes-refer-to-different-types-in-static-functions

@a-25
Copy link
Contributor

a-25 commented Aug 14, 2019

Hello, @Lukasz2891.
Made a PR, did it fix your case?

@Lukasz2891
Copy link
Author

protocol Test {
    static var aaa: Any? { get }
    static var bbb: Any? { get }
}

extension Test {
    func foo() {
        let cond = false
        _ = cond ? Self.aaa : Self.bbb
    }
}

still produces colon :( in 0.34.0

@a-25
Copy link
Contributor

a-25 commented Aug 26, 2019

@Lukasz2891: fix is not released yet

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

Successfully merging a pull request may close this issue.

3 participants