diff --git a/src/compiler.ts b/src/compiler.ts index 4341992c34..821d7445c8 100644 --- a/src/compiler.ts +++ b/src/compiler.ts @@ -6106,6 +6106,15 @@ export class Compiler extends DiagnosticEmitter { let local = target; signature = local.type.signatureReference; if (signature) { + if (local.parent != flow.parentFunction) { + // TODO: closures + this.error( + DiagnosticCode.Not_implemented_0, + expression.range, + "Closures" + ); + return module.unreachable(); + } if (local.is(CommonFlags.INLINED)) { let inlinedValue = local.constantIntegerValue; if (this.options.isWasm64) { diff --git a/tests/compiler/closure.json b/tests/compiler/closure.json index 75907cebe4..60af5f4ab5 100644 --- a/tests/compiler/closure.json +++ b/tests/compiler/closure.json @@ -8,6 +8,8 @@ "$local0; // closure 2", "AS100: Not implemented: Closures", "$local0; // closure 3", + "AS100: Not implemented: Closures", + "$local0(123); // closure 4", "EOF" ] } diff --git a/tests/compiler/closure.ts b/tests/compiler/closure.ts index fc23ecbf89..8d83cc791c 100644 --- a/tests/compiler/closure.ts +++ b/tests/compiler/closure.ts @@ -21,4 +21,11 @@ function testLet(): (value: i32) => i32 { } testLet(); +function testFuncParam($local0: (x: i32) => void): () => void { + return () => { + $local0(123); // closure 4 + }; +} +testFuncParam((x: i32) => {}); + ERROR("EOF");