Created
April 17, 2018 08:16
-
-
Save takasek/feff2b4a515e6fe8cfb6081abc54426b to your computer and use it in GitHub Desktop.
ここらへんのジェネリクスのネストの挙動の理解、だいぶ昔のまま止まってたかも #CodePiece
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
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