title: Swift: dynamic dispatch with protocol and subclass
body: <p>Please consider the following Swift 5 code:</p>
  <pre><code>protocol P: class {
      func call_foo()
      func foo()
      func call_bar()
      func bar()
  }
  
  extension P {
      func call_foo() { foo() }
      func foo() { print(&quot;P.foo&quot;) }
      func call_bar() { bar() }
      func bar() { print(&quot;P.bar&quot;) }
  }
  
  class C1: P {
      func foo() { print(&quot;C1.foo&quot;) }
  }
  
  class C2: C1 {
      func bar() { print(&quot;C2.bar&quot;) }
  }
  
  let c = C2()
  c.call_foo()    //  C1.foo
  c.foo()         //  C1.foo
  c.call_bar()    //  P.bar
  c.bar()         //  C2.bar
  </code></pre>
  <p>If the <code>foo()</code> call in <code>P.call_foo()</code> gets dynamically dispatched to <code>C1.foo()</code>, then why the <code>bar()</code> call in <code>P.call_bar()</code> does not get dynamically dispatched to <code>C2.bar()</code>?</p>
  <p>The only difference is that <code>foo()</code> is overridden directly in the class that conforms to <code>P</code>, and <code>bar()</code> is only overridden in a subclass. Why does that make a difference?</p>
  <p>Given that <code>bar()</code> is a protocol requirement, shouldn't all calls to it always get dynamically dispatched?</p>