Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support calling super methods #2986

Closed
hasanaburayyan opened this issue Jun 20, 2023 · 4 comments · Fixed by #3468
Closed

Support calling super methods #2986

hasanaburayyan opened this issue Jun 20, 2023 · 4 comments · Fixed by #3468
Assignees
Labels
🛠️ compiler Compiler ✨ enhancement New feature or request 📜 lang-spec-impl Appears in the language spec roadmap

Comments

@hasanaburayyan
Copy link
Contributor

Feature Spec

Wing now supports calling methods from inherited classes within derived classes with super.

class Student {
  name: str;
  major: str;
  init(name: str, major: str) {
    this.name = name;
    this.major = major;
  }
  
  toString(): str {
    return "Name: ${this.name}, Major: ${this.major}";
  }
}

class PaidStudent {
  hrlyWage: num;
  
  init(name: str, major: str, hrlyWage: num) {
    super(name, major);
    this.hrlyWage = hrlyWage;
  }

  // Overridden method that calls method on super
  toString(): str {
    return "${super.toString()}, hrlyWage: ${this.hrlyWage}";  
  }
}

Use Cases

Allows calling of inherited methods

Implementation Notes

No response

Component

No response

Community Notes

  • Please vote by adding a 👍 reaction to the issue to help us prioritize.
  • If you are interested to work on this issue, please leave a comment.
@hasanaburayyan hasanaburayyan added ✨ enhancement New feature or request 🛠️ compiler Compiler labels Jun 20, 2023
@staycoolcall911 staycoolcall911 added the 📜 lang-spec-impl Appears in the language spec roadmap label Jun 20, 2023
@eladb
Copy link
Contributor

eladb commented Jun 27, 2023

@staycoolcall911 this needs to be p1. We can't really extend anything without this.

@hasanaburayyan
Copy link
Contributor Author

hasanaburayyan commented Jun 27, 2023

@eladb I think it might fall into p1 territory as well. Right now you can still access methods on the super class with this.someMethod() but this is troublesome and just hacky for overriding methods. It would require you to do something like

class A {
	init() {}
	toString(): str {
		return "parent";
     }
}

class B extends A {
   init() { super() }

  toStringNotOverriden() {
    return this.toString() + " child";
   }
}

@staycoolcall911
Copy link
Contributor

Changed to p1
@eladb , @hasanaburayyan

@yoav-steinberg yoav-steinberg self-assigned this Jul 7, 2023
@yoav-steinberg yoav-steinberg linked a pull request Jul 16, 2023 that will close this issue
5 tasks
@mergify mergify bot closed this as completed in #3468 Jul 21, 2023
mergify bot pushed a commit that referenced this issue Jul 21, 2023
see #2986
This adds the ability to call the superclass's overridden methods from an extended class
```wing
class A { do() {}  }
class B extends A { 
  do() { 
    super.do(); // call A's "do" 
  }
}
```
Note that this currently doesn't support calling a super method from within an inflight closure (the complexity of capturing the parent's `super` after the closure is transformed into a class was too much.. see #3474).

- [x] Title matches [Winglang's style guide](https://www.winglang.io/contributing/start-here/pull_requests#how-are-pull-request-titles-formatted)
- [x] Description explains motivation and solution
- [x] Tests added (always)
- [ ] Docs updated (only required for features)
- [ ] Added `pr/e2e-full` label if this feature requires end-to-end testing

*By submitting this pull request, I confirm that my contribution is made under the terms of the [Monada Contribution License](https://www.winglang.io/terms-and-policies/contribution-license.html)*.
@monadabot
Copy link
Contributor

Congrats! 🚀 This was released in Wing 0.24.41.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🛠️ compiler Compiler ✨ enhancement New feature or request 📜 lang-spec-impl Appears in the language spec roadmap
Projects
Archived in project
5 participants