keyword to force calling the super on any method
Today I faced the following code ```ts class A { // silly warning comment: if you override this, don't forget to call the super method to avoid memory leaks onExit() { // do some important cleaning stuff } } class B extends A { onExit() { super.onExit(); // good } } class C extends A { onExit() { // forgot to call to super.onExit = memory leaks } } ``` The problem is that, unlike a constructor, there is no way to force a method overriding another one to call the parent "super" function. I wished we had a "concrete"* keyword to let the user know he must call the super method. ```ts class A { concrete onExit() { // do some cleaning stuff } } class B extends A { onExit() { super.onExit(); // no error } } class C extends A { // error: Declaration of derived method must contain a 'super' call onExit() { } } ``` In another language, I could have used the ```final``` keyword to prevent overriding the method but then… no overriding allowed neither. * "concrete" In opposition to "abstract" (for lack of a better name), other ideas: "important" or "mandatory"
Posted by Xample on Jan 24, 2018, 12:24 PM
Tags
Related issues
- struct's lifetime requirements can be bypassed via covariant field assignment
- Proposal to Reorganize the Moderation Team and Review Moderation Policies
- Progressive FPS degradation appears to be related to dota2.com — blocking the domain prevents the performance loss
- proposal: container/...: generic collection types
- Better Custom Endpoint BYOK
- A concrete policy for backward compatibility until Godot 5.0
Raise real-world problems, find people facing the same issue, and discuss solutions.4,500 issues0 comments
github (Other)
struct's lifetime requirements can be bypassed via covariant field assignment
Proposal to Reorganize the Moderation Team and Review Moderation Policies
Progressive FPS degradation appears to be related to dota2.com — blocking the domain prevents the performance loss
proposal: container/...: generic collection types
Better Custom Endpoint BYOK
A concrete policy for backward compatibility until Godot 5.0
New MTP models not supported
Tracking: 429 / Capacity Issues
keyword to force calling the super on any method
Today I faced the following code ```ts class A { // silly warning comment: if you override this, don't forget to call the super method to avoid memory leaks onExit() { // do some important cleaning stuff } } class B extends A { onExit() { super.onExit(); // good } } class C extends A { onExit() { // forgot to call to super.onExit = memory leaks } } ``` The problem is that, unlike a constructor, there is no way to force a method overriding another one to call the parent "super" function. I wished we had a "concrete"* keyword to let the user know he must call the super method. ```ts class A { concrete onExit() { // do some cleaning stuff } } class B extends A { onExit() { super.onExit(); // no error } } class C extends A { // error: Declaration of derived method must contain a 'super' call onExit() { } } ``` In another language, I could have used the ```final``` keyword to prevent overriding the method but then… no overriding allowed neither. * "concrete" In opposition to "abstract" (for lack of a better name), other ideas: "important" or "mandatory"
Comments (0)
No comments yet. Start the discussion.