Earlier quoted context omitted.
I guess fundamentally, this is the question I have about this situation: would you ever, in real code, want dispatch to go straight back to the default implementation when you have in hand a value with a custom implementation? I may be having a failure of imagination; but I certainly haven't ever seen a case where I'd want that.
I’d imagine the issue lies in Swift classes utilizing only static dispatch. The protocol conformance creates a witness table populated by the methods of the class in question, but as Swift classes have no vtables except in ObjC compatability mode (right?) there’s no way to pass down the invocation from the protocol witness to a specific subclass as the method can not be resolved at runtime. This is the difference bet…
Swift: When Unused Code Is a Bug
71–77 of 77 posts
Re: Swift: When Unused Code Is a Bug
#72Earlier quoted context omitted.
I’m curious to know why... Looks like typical mixin pattern, no?
An interface declaration is not the right place for implementation. If you want a default implementation, use a base class and inherit, overriding if you don't want the default. This bug is now another good reason not to use default implementations on interfaces.
Re: Swift: When Unused Code Is a Bug
#73Earlier quoted context omitted.
> That means that greeter and greeter1 are just two references to the exact same underlying object They are two references that differ in type . It is a feature in Swift (and any strongly-typed language) that references are typed and when types differ, behaviors can differ. I understand you disagree with this design principle but it is an inherent property of strong type systems that have reference semantics. > two d…
> There isn’t any such thing as a “value type instance” Hmm.. "An instance of a class is traditionally known as an object. However, Swift structures and classes are much closer in functionality than in other languages, and much of this chapter describes functionality that applies to instances of either a class or a structure type. Because of this, the more general term instance is used." and "Structure and Class Inst…
I’m not “confusing” them; I’m prioritizing the former over the latter, whereas you are prioritizing the latter over the former. This is the classic strong/weak typing debate.
If you want a language in which the dynamic type overrides the static type, there are several (including Swift if you are explicit about the override, and sometimes even if you are not explicit).
> A static type system is there to ensure that the type of the variable matches the type in its contents
A strong type system is there to apply strict type rules. one of Swift’s type rules is that Greeter.greet() calls that function or an override, not an unrelated function that could only be inferred at runtime.
Re: Swift: When Unused Code Is a Bug
#74Re: Swift: When Unused Code Is a Bug
#75Earlier quoted context omitted.
> There isn’t any such thing as a “value type instance” Hmm.. "An instance of a class is traditionally known as an object. However, Swift structures and classes are much closer in functionality than in other languages, and much of this chapter describes functionality that applies to instances of either a class or a structure type. Because of this, the more general term instance is used." and "Structure and Class Inst…
> You are confusing the type of the variable with the type of the object/value contained in the variable. I’m not “confusing” them; I’m prioritizing the former over the latter, whereas you are prioritizing the latter over the former. This is the classic strong/weak typing debate. If you want a language in which the dynamic type overrides the static type, there are several (including Swift if you are explicit about th…
Re: Swift: When Unused Code Is a Bug
#76Earlier quoted context omitted.
Oh, that's definitely weird then. Is there an RFC to have that fixed in some way?
I don't think there is. I think the code is functioning as expected — it's just written in a super confusing way. What should probably happen is that the compiler should throw an error about redefining a function in a super classes extension. I'm not a compiler engineer but a check for that seems like it would be intensive unless that information is codified in the AST somehow.
Re: Swift: When Unused Code Is a Bug
#77Earlier quoted context omitted.
I’m curious to know why... Looks like typical mixin pattern, no?
An interface declaration is not the right place for implementation. If you want a default implementation, use a base class and inherit, overriding if you don't want the default. This bug is now another good reason not to use default implementations on interfaces.