-
-
Save tarunon/ba3f3ae7dcf8b445479de51dd97881da to your computer and use it in GitHub Desktop.
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
protocol Foo { | |
func foo() -> String | |
} | |
protocol FooStandard {} | |
extension Foo where Self: FooStandard { | |
func foo() -> String { | |
return "hello" | |
} | |
} | |
protocol FooFatal{} | |
extension Foo where Self: FooStandard, Self: FooFatal { | |
func foo() -> String { | |
return "fatal" | |
} | |
} | |
class A: Foo, FooStandard {} | |
class B: A, FooFatal {} | |
A().foo() // hello | |
B().foo() // fatal | |
(A() as Foo).foo() // hello | |
(B() as Foo).foo() // hello | |
func callFoo<F: Foo>(_ f: F) -> String { | |
return f.foo() | |
} | |
callFoo(A()) // hello | |
callFoo(B()) // hello |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment