Last active
August 3, 2018 17:26
-
-
Save grigorye/2c491047ce04cf8002b2b3775a162a2e 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 P { | |
func foo() | |
} | |
extension P { | |
func foo() { print("P") } | |
} | |
class A: P {} | |
class B: A { | |
func foo() { print("B") } // <- Does not work. | |
} | |
class C: P { | |
func foo() { print("C") } | |
} | |
class D: C { | |
override func foo() { print("D") } | |
} | |
let instances: [P] = [A(), B(), C(), D()] | |
instances.forEach { $0.foo() } | |
/* Actual output: | |
P | |
P | |
C | |
D | |
*/ | |
/* Desired output: | |
P | |
B | |
C | |
D | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment