Skip to content

Commit

Permalink
Emit an error on not implemented closure (#955)
Browse files Browse the repository at this point in the history
  • Loading branch information
dcodeIO authored Nov 14, 2019
1 parent 98f2986 commit 6fbc639
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 23 deletions.
9 changes: 9 additions & 0 deletions src/compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7251,6 +7251,15 @@ export class Compiler extends DiagnosticEmitter {
switch (target.kind) {
case ElementKind.LOCAL: {
let type = (<Local>target).type;
if (target.parent != flow.parentFunction) {
// Closures are not yet supported
this.error(
DiagnosticCode.Not_implemented,
expression.range
);
this.currentType = type;
return module.unreachable();
}
assert(type != Type.void);
if ((<Local>target).is(CommonFlags.INLINED)) {
return this.compileInlineConstant(<Local>target, contextualType, constraints);
Expand Down
4 changes: 4 additions & 0 deletions tests/compiler/closure.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
{
"asc_flags": [
"--runtime none"
],
"stderr": [
"AS100: Not implemented.",
"EOF"
]
}
8 changes: 0 additions & 8 deletions tests/compiler/closure.optimized.wat

This file was deleted.

22 changes: 7 additions & 15 deletions tests/compiler/closure.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,8 @@
// TODO
function test($local0: i32, $local1: i32): (value: i32) => i32 {
return function inner(value: i32) {
return $local1; // closure
};
}

// export function outer(): () => () => i32 {
// var inner: i32 = 42; // should become a global right away
// return function a(): () => i32 {
// return function b(): i32 {
// return inner++;
// };
// };
// }

// var fnA = outer();
// var fnB = fnA();

// assert(fnB() == 42);
// assert(fnB() == 43);
test(1, 2);
ERROR("EOF");

0 comments on commit 6fbc639

Please sign in to comment.