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

fix(compiler): enforce super constructor call in derived class constructors #5354

Conversation

fynnfluegge
Copy link
Collaborator

Closes #4277

This PR adds an error to compilation if super() was not called in a derived class constructor.
One last point is questionable. If you take a look at __snapshots__/invalid.ts.snap the error is also thrown if super() is not the first statement in a constructor. This is tricky to solve.
Screenshot 2023-12-28 at 01 10 12

Further I got a weird change in test_corpus/valid/optionals.test.w_compile_tf-aws.md after I added the now required super() calls to optionals.test.w. This is not related to my changes in parser.rs but I am wondering though.

Checklist

  • Title matches Winglang's style guide
  • Description explains motivation and solution
  • 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 Wing Cloud Contribution License.

@fynnfluegge fynnfluegge requested a review from a team as a code owner December 28, 2023 00:16
@monadabot monadabot added the ⚠️ pr/review-mutation PR has been mutated and will not auto-merge. Clear this label if the changes look good! label Dec 28, 2023
Copy link
Contributor

@eladb eladb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice job. I'll let someone from the compiler team to finalize the review.

@@ -98,7 +99,7 @@ class $Root extends $stdlib.std.Resource {
}
class Derived extends Base {
constructor($scope, $id, ) {
super($scope, $id);
super($scope, $id, );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this be avoided? Not critical if it's a hassle

Copy link
Collaborator Author

@fynnfluegge fynnfluegge Dec 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was wondering about his change, it was generated after I added super() to the inflight constructor and I ran e2e tests. I don't know if this is critical, but seems suspicious to me, so I pushed it to see if somebody knows whats going on 🙂
Screenshot 2023-12-28 at 11 16 45

Copy link

Hi,

This PR has not seen activity in 20 days. Therefore, we are marking the PR as stale for now. It will be closed after 7 days.
If you need help with the PR, do not hesitate to reach out in the winglang community slack at winglang.slack.com.
Feel free to re-open this PR when it is still relevant and ready to be worked on again.
Thanks!

@github-actions github-actions bot added the Stale label Jan 18, 2024
@github-actions github-actions bot closed this Jan 26, 2024
@@ -480,6 +482,84 @@ impl<'s> Parser<'s> {
}
}

fn report_missing_super_call(&self, node: &Node, scope: &Scope) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd change this logic. Instead of re-scanning the entire tree I'd just modify build_class_statement. There you can look at the returned value from build_scope when creating the scope for the initializer. If the first statement (or actually any statement) is a StmtKind::SuperConstructor and we have a defined parent for the class then you're good to go.

Copy link

Hi,

This PR has not seen activity in 20 days. Therefore, we are marking the PR as stale for now. It will be closed after 7 days.
If you need help with the PR, do not hesitate to reach out in the winglang community slack at winglang.slack.com.
Feel free to re-open this PR when it is still relevant and ready to be worked on again.
Thanks!

@github-actions github-actions bot added the Stale label Mar 20, 2024
@github-actions github-actions bot closed this Mar 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
⚠️ pr/review-mutation PR has been mutated and will not auto-merge. Clear this label if the changes look good! Stale
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Missing error when derived class does not call super in initializer
4 participants