winglang / wing

A programming language for the cloud ☁️ A unified programming model, combining infrastructure and runtime code into one language ⚡
https://winglang.io
Other
4.6k stars 180 forks source link

Cannot add statements before `super()` statement #6387

Open Chriscbr opened 2 weeks ago

Chriscbr commented 2 weeks ago

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