Last active
April 25, 2016 14:20
-
-
Save eliperkins/3c102bb804e7afa053a699a42cbc72dd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protocol Able { | |
init?(foo: String) | |
} | |
protocol Ible { | |
init(bar: Int) throws | |
} | |
extension Able where Self: Ible { | |
init?(foo: String) { | |
// The bug can still be reproduced without the contents of this method | |
// by just `return nil`. | |
guard let value = Int(foo) else { return nil } | |
guard let object = try? Self(bar: value) else { | |
return nil | |
} | |
self = object | |
} | |
} | |
struct Baz { | |
let buzz: Int | |
} | |
extension Baz: Able { } | |
extension Baz: Ible { | |
init(bar: Int) throws { | |
self.buzz = bar | |
} | |
} | |
let x = Baz(foo: "1") // Errors with: '(foo: String) -> Baz' is not convertible to '(foo: String) -> Baz?' | |
let y = Baz.init(foo: "1") // Works! |
Author
eliperkins
commented
Apr 21, 2016
Hm .. Baz implements Able and Ible. Seems like Baz(foo: "1") takes the init of Able which is init?
And I guess when you call Baz.init(foo: "1") it is explicit
You have a very strange construct there :)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment