>> This code behaves as it does because protocol extensions are compile-time constructs.The problem with this is that it doesn't seem to be viable, as a compiler behavior:1. In the case of a class type conforming to the protocol(s) involved, the existing semantics of inheritance say that it doesn't matter (to instances of a subclass) whether a method is implemented in the subclass or a base class (when it's only implemented in one place, I mean, I'm not talking about overrides). If that weren't true, then it wouldn't be safe to factor behavior out of subclasses into base classes.2. In your 'extension Foo' example, the issue isn't whether the doFoo method is a compile-time construct, but the fact that 'self' already means something in terms of method lookup — it means to start with the class of the instance that's executing the code**. Unfortunately, in the current Swift, it means something else, apparently to start with a class chosen at compile time. Whatever that is, it isn't what 'self' mean
Topic:
Programming Languages
SubTopic:
Swift
Tags: