Skip to content

Static initializers may refer to later static methods #15010

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

Merged

Conversation

sandersn
Copy link
Member

@sandersn sandersn commented Apr 4, 2017

Static methods are created before static property initializers run, so static property initializers may refer to static methods. This was not allowed previously.

Fixes #14312

sandersn added 2 commits April 4, 2017 14:49
Static methods are created before static property initializers run, so
static property initializers may refer to static methods. This was not
allowed previously.
@@ -0,0 +1,14 @@
class X {
Copy link
Contributor

Choose a reason for hiding this comment

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

The bug can also be observed on non-statics:

class Y {
  a = "" + this.b;
  b = "";
}

I'm not sure if your fix handles this case as well.

Copy link
Member Author

Choose a reason for hiding this comment

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

this.b is undefined in the expression "" + this.b, even though its initial value is supposed to be "". I think we want to error in this case.

@sandersn sandersn merged commit c62cc3f into master Apr 4, 2017
@sandersn sandersn deleted the static-initialisers-can-refer-to-later-static-methods branch April 4, 2017 22:30
@microsoft microsoft locked and limited conversation to collaborators Jun 21, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants