6

Playing with the new extension protocols in Swift 2.0 come by this example:

protocol A {
  func foo()
}

protocol B {
  func foo()
}

extension A {
    func foo() { print("A") }
}

extension B {
    func foo() { print("B") }
}

class C: A, B {

}

Is something like a "multiple inheritance" , that some languages like Python and C++ can handle as multiple inheritance of course. What really surprise me was the two compile errors that Xcode 7.0 Beta 4 gave me:

Type 'C' does not conform to protocol 'A'


Type 'C' does not conform to protocol 'B'

But this error not make any sense because the error must reflect that exist conflict or ambiguity between protocol A and B regarding the use of the foo function, or something like that.

If you put below of the above code the following line :

C().foo()

This launches exactly the error type I talking about:

Ambiguous use of 'foo'

My question here is :

With the new addition of extension protocols in Swift 2.0 has Apple considered any treatment to this kind of "multiple inheritance"(something like the way of C++ treatment) or just is not allowed at all?

Victor Sigler
  • 23,243
  • 14
  • 88
  • 105
  • @MartinR Is very much the same problem except for my question, I saw your answer and you're right ,but my question is different from the another question. – Victor Sigler Aug 07 '15 at 19:05
  • Then the answer is probably "it is just not allowed". What would you expect that `C().foo()` does? – Martin R Aug 07 '15 at 19:08
  • Nothing, my question is posted because with the new addition of protocol extensions in the book of Swift , Apple has no mention at all about this topic and I would expect some clarification about the treatment it has for the Swift compiler, is for that my mention to C++ and Python, nothing more just curiosity. – Victor Sigler Aug 07 '15 at 19:16
  • Then I don't see why this is not a duplicate. That may be my fault, but perhaps you can clarify in your question what makes it different from the linked-to thread. – Martin R Aug 07 '15 at 19:19
  • @MartinR it could be a duplicate , I think you're right after reading your answer once again. – Victor Sigler Aug 07 '15 at 19:26

0 Answers0