Skip to content

Commit a2c1c97

Browse files
authored
Ensure function locals are not in closures (#2533)
1 parent ee6a165 commit a2c1c97

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

Diff for: src/compiler.ts

+9
Original file line numberDiff line numberDiff line change
@@ -6106,6 +6106,15 @@ export class Compiler extends DiagnosticEmitter {
61066106
let local = <Local>target;
61076107
signature = local.type.signatureReference;
61086108
if (signature) {
6109+
if (local.parent != flow.parentFunction) {
6110+
// TODO: closures
6111+
this.error(
6112+
DiagnosticCode.Not_implemented_0,
6113+
expression.range,
6114+
"Closures"
6115+
);
6116+
return module.unreachable();
6117+
}
61096118
if (local.is(CommonFlags.INLINED)) {
61106119
let inlinedValue = local.constantIntegerValue;
61116120
if (this.options.isWasm64) {

Diff for: tests/compiler/closure.json

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
"$local0; // closure 2",
99
"AS100: Not implemented: Closures",
1010
"$local0; // closure 3",
11+
"AS100: Not implemented: Closures",
12+
"$local0(123); // closure 4",
1113
"EOF"
1214
]
1315
}

Diff for: tests/compiler/closure.ts

+7
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,11 @@ function testLet(): (value: i32) => i32 {
2121
}
2222
testLet();
2323

24+
function testFuncParam($local0: (x: i32) => void): () => void {
25+
return () => {
26+
$local0(123); // closure 4
27+
};
28+
}
29+
testFuncParam((x: i32) => {});
30+
2431
ERROR("EOF");

0 commit comments

Comments
 (0)