Created
February 7, 2020 14:58
-
-
Save JensAyton/624d74861f06fb65abc3ba6e7138631e to your computer and use it in GitHub Desktop.
Surprising init resolution in Swift (5.1 and 5.2)
This file contains hidden or 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
struct Test {} | |
extension Test: LosslessStringConvertible { | |
init?(_ description: String) { | |
print("unlabelled init") | |
} | |
var description: String { "Test" } | |
} | |
extension Test: ExpressibleByStringLiteral { | |
init(stringLiteral value: String) { | |
print("stringliteral init") | |
} | |
} | |
let test = Test("Hello") | |
// Prints "stringliteral init" | |
// This happens if init(_:) is non-failable too |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment