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

semantic: failed to produce syntax error for undeclared private field access #7582

Closed
overlookmotel opened this issue Dec 2, 2024 · 2 comments · Fixed by #7635
Closed

semantic: failed to produce syntax error for undeclared private field access #7582

overlookmotel opened this issue Dec 2, 2024 · 2 comments · Fixed by #7635
Assignees
Labels
A-semantic Area - Semantic C-bug Category - Bug

Comments

@overlookmotel
Copy link
Contributor

This does not produce a syntax error, but it should because there is no #x property.

class C {
  x = 1;
  method() {
    obj.#x;
  }
}

It seems syntax checker is confusing public property x with private property #x. If you rename the public property, it works as expected.

Oxc playground

@overlookmotel overlookmotel added C-bug Category - Bug A-semantic Area - Semantic labels Dec 2, 2024
@camc314
Copy link
Contributor

camc314 commented Dec 2, 2024

question: surely this is ok because you are accessing #x on obj not on this?

TS doesn't report a syntax error in this case:

var obj: any;

class C {
  x = 1;
  method() {
    obj.#x;
  }
}

instead you get "Property #x does not exist on type 'any'"

@overlookmotel
Copy link
Contributor Author

Private properties are lexically scoped. It's always a syntax error to use #x, unless that code is inside a class which defines a property #x. Try running the example above in NodeJS.

The fact that obj may not be an instance of a class which defines a private property #x is a separate problem - but that's a runtime error, not a syntax error. TypeScript makes it a type error too, but that's a TS-specific thing, and again a separate issue.

I'll admit, none of this is obvious! Everything around private properties is fiendishly complicated. Hence why I've been working on the class properties transform for weeks, and it's still not complete...

@Boshen Boshen self-assigned this Dec 2, 2024
@Boshen Boshen changed the title Semantic syntax checker confuses public and private fields semantic: failed to produce syntax error for undeclared private field access Dec 4, 2024
@Boshen Boshen closed this as completed Dec 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-semantic Area - Semantic C-bug Category - Bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants