Better HN
topnewbestaskshowjobs
Log inSign up

anon180719

3 karma · joined Jul 19, 2018 (8y ago) · 4 submissions

Submissions

comment 8y ago · link · parent

hmph. I agree, the compiler should probably not let you compile in that case. Funny enough this reminds me of "responder chain politics" in dynamically typed languages with duck typing.

comment 8y ago · link · parent

Oh, that's definitely weird then. Is there an RFC to have that fixed in some way?

comment 8y ago · link · parent

It appears the correct action would have been to use <code>override func greet() { print("sup") }</code>.

To be fair, I was primed to really think about the code execution given he'd indicated there was a trap in there somewhere, so it certainly would not have been immediately obvious on first glance. But I think, generally developers understand that <code>override</code> is necessary to override code from a parent class.

Typically XCode helps out with this sort of thing – adding <code>override</code> where it seems like it should be added – but perhaps not when a parent class is using a default protocol implementation.

But again, in this scenario where a class is inheriting from another class, it's typically known you need to override the function in order to use your own implementation, so this does seem a bit contrived.