Description
Calling a super method is (with the below restrictions) as safe as calling regular methods.
Since doing so is a common requirement, e.g. in initializers, or when subclassing e.g. NSView
, we should find a way so that the user can easily do so.
Requirements that I know of so far:
- Only safe when declaring a new subclass.
- Only direct super methods (e.g. calling
NSResponder
's methods from a subclass ofNSView
could potentially lead to UB, ifNSView
was implemented in a certain way. - Super method calls can only access methods on the superclass, not on the declared class.
- Initializer methods only from inside other initializer methods.
The main problem with this is that it effectively doubles the amount of methods that we have to generate, the codegen is different for each. Though maybe with #448, that will be less of a problem?
If we had inherent traits, or something like it, then it would perhaps be easier, since we could make the implementation on a trait instead.
Related: Internally, we can consider getting rid of send_message_super
, by providing a struct Super<T: MessageReceiver> { obj: T, cls: &'static Class }
that implements MessageReceiver::send_message
by calling objc_msgSendSuper
instead.
Related: