Created
March 5, 2016 14:27
-
-
Save sinsoku/275acf2eb1dd4bab244c to your computer and use it in GitHub Desktop.
@niwatako さんのプロトコル拡張の問題の話
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
| protocol P { | |
| func say() | |
| } | |
| class A : P {} | |
| class B : A {} | |
| extension P { | |
| func say() { print("P") } | |
| } | |
| extension P where Self: A { | |
| func say() { print("A") } | |
| } | |
| extension P where Self: B { | |
| func say() { print("B") } | |
| } | |
| A().say() // A | |
| B().say() // B | |
| print("cast P") | |
| (A() as P).say() // A | |
| (B() as P).say() // A <- ??? | |
| print("cast!") | |
| ((A() as P) as! A).say() // A | |
| ((B() as P) as! B).say() // B |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment