[swift-evolution] [Discussion] Enforcing Calling Super

Haravikk swift-evolution at haravikk.me
Tue Feb 23 03:02:16 CST 2016


> On 23 Feb 2016, at 00:51, Kyle Sherman via swift-evolution <swift-evolution at swift.org> wrote:
> 
> @haravikk: I still don’t see a reason to have a parameter for saying that it is required, since as we both agreed, it makes sense that only when the attribute is defined, is it required. Having the attribute declared but not have required would basically be invalid. I think baking it into the name like I originally suggested is probably best, as @super by itself is probably not explicit enough. The naming of these attributes and casing are being debated in a different thread, so I think I will just submit my suggestion with the idea that it can be corrected to fit what they decide in the other thread.

My reasoning was that it may make sense to have a distinction between required and other restriction types, for example:

optional: super call can be included if desired (this is the default, but IMO before/after should default to being requirements, so this would be useful for changing that).
required: super call *must* be included or an error is produced
warn: downgrades errors to warnings, implies required by default (i.e- super call *should* be included or a warning is produced)
replace: super call should not be included or an error is produced (i.e- the requirement is that overriding methods must be a total replacement)

While the proposal doesn’t have to push for these up front, I think that they still make sense as possible extensions of the feature, and adding @warnSuper, @optionalSuper etc. would make things more unwieldy. But the added flexibility would be very useful, for example:

	@super(optional, before)	// super call isn’t required, but if it is included it must come first.
	@super(replace, warn)		// downgrades replace to a warning, so a developer can still use the super call if they like, but should be very sure they know what they’re doing.

Personally I think @super is clear enough, though @includeSuper or such may be more-so. I just think that @requireSuper is too specific, especially if the default for the proposal is to generate a warning, since as mentioned we may want to push an error if we know that our parent class will break horribly if its method(s) aren’t called.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160223/29bfc316/attachment.html>


More information about the swift-evolution mailing list