Skip to content

Commit 6fbc639

Browse files
authored
Emit an error on not implemented closure (#955)
1 parent 98f2986 commit 6fbc639

File tree

4 files changed

+20
-23
lines changed

4 files changed

+20
-23
lines changed

Diff for: src/compiler.ts

+9
Original file line numberDiff line numberDiff line change
@@ -7251,6 +7251,15 @@ export class Compiler extends DiagnosticEmitter {
72517251
switch (target.kind) {
72527252
case ElementKind.LOCAL: {
72537253
let type = (<Local>target).type;
7254+
if (target.parent != flow.parentFunction) {
7255+
// Closures are not yet supported
7256+
this.error(
7257+
DiagnosticCode.Not_implemented,
7258+
expression.range
7259+
);
7260+
this.currentType = type;
7261+
return module.unreachable();
7262+
}
72547263
assert(type != Type.void);
72557264
if ((<Local>target).is(CommonFlags.INLINED)) {
72567265
return this.compileInlineConstant(<Local>target, contextualType, constraints);

Diff for: tests/compiler/closure.json

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
{
22
"asc_flags": [
33
"--runtime none"
4+
],
5+
"stderr": [
6+
"AS100: Not implemented.",
7+
"EOF"
48
]
59
}

Diff for: tests/compiler/closure.optimized.wat

-8
This file was deleted.

Diff for: tests/compiler/closure.ts

+7-15
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,8 @@
1-
// TODO
1+
function test($local0: i32, $local1: i32): (value: i32) => i32 {
2+
return function inner(value: i32) {
3+
return $local1; // closure
4+
};
5+
}
26

3-
// export function outer(): () => () => i32 {
4-
// var inner: i32 = 42; // should become a global right away
5-
// return function a(): () => i32 {
6-
// return function b(): i32 {
7-
// return inner++;
8-
// };
9-
// };
10-
// }
11-
12-
// var fnA = outer();
13-
// var fnB = fnA();
14-
15-
// assert(fnB() == 42);
16-
// assert(fnB() == 43);
7+
test(1, 2);
8+
ERROR("EOF");

0 commit comments

Comments
 (0)