Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Emit an error on not implemented closure #955

Merged
merged 1 commit into from
Nov 14, 2019
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
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");