Skip to content

Fix find_var_htab to skip entries with scope_level != 0#1471

Open
jiang1997 wants to merge 2 commits into
quickjs-ng:masterfrom
jiang1997:fix/find-var-htab-scope-level
Open

Fix find_var_htab to skip entries with scope_level != 0#1471
jiang1997 wants to merge 2 commits into
quickjs-ng:masterfrom
jiang1997:fix/find-var-htab-scope-level

Conversation

@jiang1997
Copy link
Copy Markdown
Contributor

When a var shadows a block-scoped let of the same name, find_var_htab returned the block-scoped entry. find_var rejected it (scope_level != 0) and fell through to an O(n) linear scan.

Add scope_level == 0 check to the htab probe loop so non-scope-0 entries are skipped. This lets find_var treat htab miss as definitive.

@jiang1997 jiang1997 marked this pull request as ready for review May 16, 2026 14:25
When a `var` shadows a block-scoped `let` of the same name,
find_var_htab returned the block-scoped entry. find_var rejected it
(scope_level != 0) and fell through to an O(n) linear scan.

Add scope_level == 0 check to the htab probe loop so non-scope-0
entries are skipped. This lets find_var treat htab miss as definitive.
@jiang1997 jiang1997 force-pushed the fix/find-var-htab-scope-level branch from ffadecc to 6bec763 Compare May 16, 2026 14:27
@jiang1997 jiang1997 changed the title find_var_htab: skip entries with scope_level != 0 Fix find_var_htab to skip entries with scope_level != 0 May 16, 2026
@saghul
Copy link
Copy Markdown
Contributor

saghul commented May 16, 2026

Can you add a test for this?

@jiang1997 jiang1997 force-pushed the fix/find-var-htab-scope-level branch from b27f19b to bf52efb Compare May 16, 2026 23:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants