Created
July 3, 2015 22:05
-
-
Save natecook1000/c1657cb94d53598be2a1 to your computer and use it in GitHub Desktop.
Ambiguous inits
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 Foo { | |
| init(a: String) { | |
| print("init(a: String)") | |
| } | |
| init(b: String) { | |
| print("init(b: String)") | |
| } | |
| init(a: Int) { | |
| print("init(a: Int)") | |
| } | |
| init<T>(a: T) { | |
| print("init<T>(a: T)") | |
| } | |
| init<T>(_ a: T) { | |
| print("init<T>(_ a: T)") | |
| } | |
| } | |
| let numbers = [1, 2, 3] | |
| let strings = ["1", "2", "3"] | |
| let w = numbers.map(Foo.init) | |
| let x = w.map(Foo.init) // error here, no init optimized for Foo | |
| let y = strings.map(Foo.init) // error here, two inits optimized for String |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment