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

Comments

@Lukasz2891
Copy link

commented Jul 9, 2019

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 label Jul 9, 2019

@a-25

This comment has been minimized.

Copy link
Contributor

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

This comment has been minimized.

Copy link
Author

commented Jul 22, 2019

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

This comment has been minimized.

Copy link
Contributor

commented Aug 14, 2019

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

@jpsim jpsim closed this in #2836 Aug 14, 2019

@Lukasz2891

This comment has been minimized.

Copy link
Author

commented Aug 26, 2019

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

This comment has been minimized.

Copy link
Contributor

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
Projects
None yet
3 participants
You can’t perform that action at this time.