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

Cannot add statements before super() statement #6387

Open
Chriscbr opened this issue Apr 30, 2024 · 0 comments
Open

Cannot add statements before super() statement #6387

Chriscbr opened this issue Apr 30, 2024 · 0 comments
Labels
🐛 bug Something isn't working 🛠️ compiler Compiler

Comments

@Chriscbr
Copy link
Contributor

Chriscbr commented Apr 30, 2024

I tried this:

class A {
  new(x: num) {}
}

class B extends A {
  new() {
    let x = 3 + 5;
    super(x);
  }
}

This happened:

error: Call to super constructor must be first statement in constructor
  --> wing/main.w:8:5
  |
8 |     super(x);
  |     ^^^^^^^^^ Call to super constructor must be first statement in constructor

I expected this:

I expected the example to compile. This kind of code is supported in TypeScript:

class A {
  constructor(foo: number) {}
}

class B extends A {
  constructor() {
    let x = Math.random();
    super(x);
  }
}

Is there a workaround?

No response

Anything else?

No response

Wing Version

0.73.13

Node.js Version

20.11.1

Platform(s)

MacOS

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 bug Something isn't working 🛠️ compiler Compiler
Projects
Status: 🤝 Backlog - handoff to owners
Development

No branches or pull requests

1 participant