Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 73193f0

Browse files
fix: diagnose not implement when assign value to closure variable (#2750)
Fixes: #2749
1 parent 927b7cd commit 73193f0

File tree

4 files changed

+28
-6
lines changed

4 files changed

+28
-6
lines changed

‎src/compiler.ts‎

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5596,13 +5596,21 @@ export class Compiler extends DiagnosticEmitter {
55965596
// to compile just the value, we need to know the target's type
55975597
let targetType: Type;
55985598
switch (target.kind) {
5599-
case ElementKind.Global: {
5600-
if (!this.compileGlobalLazy(<Global>target, expression)) {
5599+
case ElementKind.Global:
5600+
case ElementKind.Local: {
5601+
if (target.kind == ElementKind.Global) {
5602+
if (!this.compileGlobalLazy(<Global>target, expression)) {
5603+
return this.module.unreachable();
5604+
}
5605+
} else if (!(<Local>target).declaredByFlow(flow)) {
5606+
// TODO: closures
5607+
this.error(
5608+
DiagnosticCode.Not_implemented_0,
5609+
expression.range,
5610+
"Closures"
5611+
);
56015612
return this.module.unreachable();
56025613
}
5603-
// fall-through
5604-
}
5605-
case ElementKind.Local: {
56065614
if (this.pendingElements.has(target)) {
56075615
this.error(
56085616
DiagnosticCode.Variable_0_used_before_its_declaration,
@@ -7371,7 +7379,7 @@ export class Compiler extends DiagnosticEmitter {
73717379
this.currentType = localType;
73727380
}
73737381

7374-
if (target.parent!=flow.targetFunction) {
7382+
if (!local.declaredByFlow(flow)) {
73757383
// TODO: closures
73767384
this.error(
73777385
DiagnosticCode.Not_implemented_0,

‎src/program.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3639,6 +3639,10 @@ export class Local extends VariableLikeElement {
36393639
assert(type != Type.void);
36403640
this.setType(type);
36413641
}
3642+
3643+
declaredByFlow(flow: Flow): bool {
3644+
return this.parent == flow.targetFunction;
3645+
}
36423646
}
36433647

36443648
/** A yet unresolved function prototype. */

‎tests/compiler/closure.json‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
"$local0; // closure 3",
1111
"AS100: Not implemented: Closures",
1212
"$local0(123); // closure 4",
13+
"AS100: Not implemented: Closures",
14+
"$local0 = 10; // closure 5",
1315
"EOF"
1416
]
1517
}

‎tests/compiler/closure.ts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,12 @@ function testFuncParam($local0: (x: i32) => void): () => void {
2828
}
2929
testFuncParam((x: i32) => {});
3030

31+
function testAssign(): (value: i32) => void {
32+
let $local0 = 0;
33+
return function inner(value: i32): void {
34+
$local0 = 10; // closure 5
35+
};
36+
}
37+
testAssign();
38+
3139
ERROR("EOF");

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /