Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion src/semantic/closure-mutation-checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,11 @@ class ClosureMutationChecker {
// Simple-name reassignment after capture is the error we're looking for.
// Member-access assignments (obj.x = y) don't reassign the binding itself.
if (capturedNames.indexOf(assign.name) !== -1) {
this.reportError(assign.name, assign.loc);
// NOTE: `assign.loc` is intentionally not passed here. No AssignmentStatement
// creation site in parser-ts/parser-native sets `loc`, so reading `assign.loc`
// in the native self-hosted compiler GEPs past the struct and segfaults.
// See the PR that introduced this comment for the full root cause.
this.reportError(assign.name, undefined);
}
this.scanExprForCaptures(assign.value, scopeVarNames, capturedNames);
} else if (stype === "if") {
Expand Down
10 changes: 10 additions & 0 deletions tests/fixtures/closures/closure-mutation-inside-arrow-body.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// @test-compile-error: variable 'x' is captured by a closure but reassigned after capture
// @test-description: closure mutation detected when assignment is inside the arrow body itself
function outer() {
let x = 0;
const g = () => {
x = 1;
};
g();
}
outer();
9 changes: 9 additions & 0 deletions tests/fixtures/closures/closure-mutation-inside-function.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// @test-compile-error: variable 'x' is captured by a closure but reassigned after capture
// @test-description: closure mutation detected inside a function body (not just top-level)
function outer() {
let x = 0;
const g = () => x;
x = 1;
g();
}
outer();
Loading