Why does the following code print "BaseP" at #2?
protocol BaseP { func foo() }
extension BaseP { func foo() { print("BaseP") } }
protocol SubP: BaseP {}
extension SubP { func foo() { print("SubP") } }
class C: SubP {}
let subP1: SubP = C()
subP1.foo() // #1 prints "SubP", fine.
class BaseC: BaseP {}
class SubC: BaseC, SubP {}
let subP2: SubP = SubC()
subP2.foo() // #2 prints "BaseP". why?
In both cases we call foo() on a reference with a static type of SubP,
referencing an object with a dynamic type that is a class conforming to SubP.
Even if it was a static dispatch, I'd think that it should still call SubP.foo().
Why does the base protocol implementation get called at #2?
Also, why does inheriting from BaseC make a difference
(if in the class SubC line I remove BaseC or replace it with BaseP,
then it suddenly prints "SubP")?