View difference between Paste ID: UCrAdCgd and 580sQ2uh
SHOW: | | - or go back to the newest paste.
1
protocol P {
2
    func foo()
3
}
4
5
extension P {
6
    func foo() { print("P") }
7
}
8
9
class A: P {}
10
class B: A {
11
    func foo() { print("B") } // <- Does not work.
12
}
13
class C: P {
14
    func foo() { print("C") }
15
}
16
class D: C {
17
    override func foo() { print("D") }
18
}
19
let instances: [P] = [A(), B(), C(), D()]
20
instances.forEach { $0.foo() }
21
22
/* Actual output:
23
 P
24
 P
25
 C
26
 D
27
 */
28
29
/* Desired output:
30
 P
31
 B
32
 C
33
 D
34
 */