[SR-6417] Check if super is called when required. #48967
Labels
compiler
The Swift compiler itself
feature
A feature request or implementation
good first issue
Good for newcomers
improvement
swift evolution proposal needed
Flag → feature: A feature that warrants a Swift evolution proposal
type checker
Area → compiler: Semantic analysis
Additional Detail from JIRA
md5: 8ca04a71f5feba734a5bda3679466acc
Issue Description:
When creating a subclass of NSObject, you get an error when you 'forget' to call super in the init() function.
When creating a subclass of UIViewController, and you forget to call super in viewDidLoad, viewWillAppear, etc, you will not get an error or warning.
When creating a subclass of UIView, and you forget to call super in your implementation of awakeFromNib, you will not get an error or warning.
When creating a subclass of UITableViewCell or UICollectionViewCell, and you forget to call super in your implementation of prepareForReuse, you will not get an error or warning.
And there are probably more places where it is required, but not guarded that you call super.
As a freelancer, I produce and see lots of code and this is one of the issues that I often see (and fix). Forgetting to call super in these functions results in unexpected behaviour, even crashes and it can be pretty hard to find the problem.
It would be very helpful if one could declare that an overriding function has to call super. For instance with an attribute in the same manner as @discardableResult:
This attribute should be valid for all subclasses that override this function, even subclasses of subclasses.
And then Apple should use this in their declaration of the aforementioned functions.
The text was updated successfully, but these errors were encountered: