File tree Expand file tree Collapse file tree 4 files changed +28
-6
lines changed Expand file tree Collapse file tree 4 files changed +28
-6
lines changed Original file line number Diff line number Diff line change @@ -5596,13 +5596,21 @@ export class Compiler extends DiagnosticEmitter {
5596
5596
// to compile just the value, we need to know the target's type
5597
5597
let targetType : Type ;
5598
5598
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
+ ) ;
5601
5612
return this . module . unreachable ( ) ;
5602
5613
}
5603
- // fall-through
5604
- }
5605
- case ElementKind . Local : {
5606
5614
if ( this . pendingElements . has ( target ) ) {
5607
5615
this . error (
5608
5616
DiagnosticCode . Variable_0_used_before_its_declaration ,
@@ -7371,7 +7379,7 @@ export class Compiler extends DiagnosticEmitter {
7371
7379
this . currentType = localType ;
7372
7380
}
7373
7381
7374
- if ( target . parent != flow . targetFunction ) {
7382
+ if ( ! local . declaredByFlow ( flow ) ) {
7375
7383
// TODO: closures
7376
7384
this . error (
7377
7385
DiagnosticCode . Not_implemented_0 ,
Original file line number Diff line number Diff line change @@ -3639,6 +3639,10 @@ export class Local extends VariableLikeElement {
3639
3639
assert ( type != Type . void ) ;
3640
3640
this . setType ( type ) ;
3641
3641
}
3642
+
3643
+ declaredByFlow ( flow : Flow ) : bool {
3644
+ return this . parent == flow . targetFunction ;
3645
+ }
3642
3646
}
3643
3647
3644
3648
/** A yet unresolved function prototype. */
Original file line number Diff line number Diff line change 10
10
" $local0; // closure 3" ,
11
11
" AS100: Not implemented: Closures" ,
12
12
" $local0(123); // closure 4" ,
13
+ " AS100: Not implemented: Closures" ,
14
+ " $local0 = 10; // closure 5" ,
13
15
" EOF"
14
16
]
15
17
}
Original file line number Diff line number Diff line change @@ -28,4 +28,12 @@ function testFuncParam($local0: (x: i32) => void): () => void {
28
28
}
29
29
testFuncParam ( ( x : i32 ) => { } ) ;
30
30
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
+
31
39
ERROR ( "EOF" ) ;
You can’t perform that action at this time.
0 commit comments