Skip to content

Instantly share code, notes, and snippets.

@natecook1000
Created July 3, 2015 22:05
Show Gist options
  • Select an option

  • Save natecook1000/c1657cb94d53598be2a1 to your computer and use it in GitHub Desktop.

Select an option

Save natecook1000/c1657cb94d53598be2a1 to your computer and use it in GitHub Desktop.
Ambiguous inits
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