Skip to content

Compiler should throw error when constructor called without super() #461

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

Closed
MaxGraey opened this issue Feb 5, 2019 · 4 comments
Closed

Comments

@MaxGraey
Copy link
Member

MaxGraey commented Feb 5, 2019

Basically this works correctly even in runtime. But this should produce error during compilation:

class A {
  a: i32;
  constructor() {
    this.a = 1;
  }
}

export class B extends A {
  constructor(b: i32) {
    // super();
    this.a = b;
  }
}

export function test(): i32 {
  var b = new B(2);
  return b.a;
}
@MaxGraey
Copy link
Member Author

MaxGraey commented Feb 6, 2019

Also related to #245

@dcodeIO
Copy link
Member

dcodeIO commented Feb 6, 2019

After #463 this emits:

ERROR TS2377: Constructors for derived classes must contain a 'super' call.

   export class B extends A {
    constructor(b: i32) {
      // super();
      this.a = b;
    }

   in empty.ts(8,26)

@MaxGraey
Copy link
Member Author

MaxGraey commented Feb 6, 2019

Great!

@dcodeIO
Copy link
Member

dcodeIO commented Feb 7, 2019

This should have been fixed meanwhile, emitting

ERROR TS2377: Constructors for derived classes must contain a 'super' call.

@dcodeIO dcodeIO closed this as completed Feb 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants