Skip to content

Instantly share code, notes, and snippets.

@takasek
Created April 17, 2018 08:16
Show Gist options
  • Save takasek/feff2b4a515e6fe8cfb6081abc54426b to your computer and use it in GitHub Desktop.
Save takasek/feff2b4a515e6fe8cfb6081abc54426b to your computer and use it in GitHub Desktop.
ここらへんのジェネリクスのネストの挙動の理解、だいぶ昔のまま止まってたかも #CodePiece
struct A<T> {
let t: T
struct S1 {
let t: T
}
struct S2<T> {
let t: T
}
func xxx() -> S1 {
return S1(t: t)
}
func xxx<T>(t: T) -> S2<T> {
return S2(t: t)
}
}
let a = A(t: 1)
a.xxx() // A<Int>.S1
a.xxx(t: "aaa") // A<Int>.S2<String>
A.S1(t: true) // A<Bool>.S1
A<Any>.S2(t: true) // A<Any>.S2<Bool>
A.S2(t: true) // error: Generic parameter 'T' could not be inferred
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment