Last active
June 15, 2017 16:52
-
-
Save pcantrell/52162c7ad6c6f44a8475c14acb7ed3aa to your computer and use it in GitHub Desktop.
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 A { | |
func foo() | |
} | |
extension A { | |
default func foo() { … } // Dynamically dispatched b/c it’s in the protocol | |
func bar() { … } // Statically dispatched b/c it’s not in the protocol | |
} | |
// Dynamic shadows static | |
protocol B: A { | |
func bar() | |
} | |
extension B { | |
func foo() { … } // Shouldn’t warn, but should this also require `default`? or maybe `override`? | |
default func bar() { … } // Should warn about shadowing A.bar() | |
} | |
// Static shadows static | |
protocol C: A { | |
} | |
extension C { | |
func foo() { … } // Should warn about shadowing A.foo() | |
} | |
// Static can’t shadow dynamic: anything that implements B will use dynamic dispatch for bar(), | |
// and any type that tries to separately conform to both B and something else with a static | |
// extension impl for bar() already gives a compile error: | |
protocol D { | |
} | |
extension D { | |
func foo() { } | |
} | |
class E: B, D { // Already gives a compiler error about conflicting foo() impls | |
} | |
// Type implementation shadowing/overriding extensions | |
class F: A { | |
func foo() { … } // Legit; shouldn’t warn. Should this require `override`? | |
func bar() { … } // Should warn about collision with B.bar() | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment