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

bug(semantic): Incorrect ScopeId for IIFEs #4452

Closed
DonIsaac opened this issue Jul 25, 2024 · 4 comments
Closed

bug(semantic): Incorrect ScopeId for IIFEs #4452

DonIsaac opened this issue Jul 25, 2024 · 4 comments
Labels
A-semantic Area - Semantic C-bug Category - Bug

Comments

@DonIsaac
Copy link
Collaborator

DonIsaac commented Jul 25, 2024

See this test case for a reproduction

function foo()

In this following scope ids are equal:

  • the root scope id
  • AstNode::scope_id(), when called on foo's declaration node
  • SymbolTable::get_scope_id(), when called with foo's SymbolId

Now, consider this snippet:

(function foo() {})()

Here, the following scope ids are equal

  • the root scope id
  • AstNode::scope_id(), when called on foo's declaration node
    However, the symbol id obtained from SymbolTable::get_scope_id() is not the same as the other two.

I'm not certain what expected behavior here is, whether foo should be considered in the root scope or not, but the scope id for its AstNode and for the Symbol should definitely be the same.

@Dunqing
Copy link
Member

Dunqing commented Jul 25, 2024

This is expected behavior. The main difference here is between FunctionDeclaration and FunctionExpression. I explained in #4240 (comment)

@DonIsaac
Copy link
Collaborator Author

Oh boy that's confusing haha

Any chance we could write that down somewhere?

@Dunqing
Copy link
Member

Dunqing commented Jul 25, 2024

Oh boy that's confusing haha

Any chance we could write that down somewhere?

Maybe we should write down what the ScopeFlags are for each of the different SymbolFlags?

@overlookmotel
Copy link
Collaborator

As mentioned in #4240 (comment), I feel we should have separate types FunctionDeclaration and FunctionExpression. I think this would make it less confusing.

@DonIsaac DonIsaac closed this as not planned Won't fix, can't repro, duplicate, stale Jul 29, 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

No branches or pull requests

3 participants