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(60617): abstract modifier cannot be used with private a identifier #60627

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

a-tarasyuk
Copy link
Contributor

Fixes #60617

@typescript-bot typescript-bot added the For Backlog Bug PRs that fix a backlog bug label Nov 27, 2024
Copy link
Contributor

Choose a reason for hiding this comment

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

It would be great to add those 2 tests to check that the abstractness of those is still working OK:

abstract class A1 {
  abstract #x: number;

  getX() {
    return this.#x;
  }

  static B = class B extends A1 {
    #x = 5;
  };
}

abstract class A2 {
  abstract #x: number;

  getX() {
    return this.#x;
  }

  static B = class B extends A2 {
    // x stays not implemented
  };
}

@whzx5byb
Copy link

abstract class A {
    abstract #x: number;
    getX() {
        return this.#x;
    }
}

will be compiled to

class A {
    getX() {
        return this.#x;
    }
}

and throw a runtime error because an abstract member will be erased.

@a-tarasyuk a-tarasyuk marked this pull request as draft November 27, 2024 17:19
Copy link
Member

@RyanCavanaugh RyanCavanaugh left a comment

Choose a reason for hiding this comment

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

This needs the corresponding emit change (and test) to preserve #x; when we're seeing abstract #x;

@whzx5byb
Copy link

@RyanCavanaugh I don't think it's a good idea. Even if we preserve #x, the private property is still not "implementable", for example this code:

abstract class A {
  abstract #x: number;

  getX() {
    return this.#x;
  }

  static B = class B extends A {
    #x = 5;
  };
}

will be compiled to (if we preseve #x):

class A {
  #x;

  getX() {
    return this.#x;
  }

  static B = class B extends A {
    #x = 5;
  };
}

and if you call new A.B().getX() you will only get undefined, which is not the desired value.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
For Backlog Bug PRs that fix a backlog bug
Projects
Status: Waiting on author
Development

Successfully merging this pull request may close these issues.

abstract modifier cannot be used with private a identifier
5 participants