Skip to content

Commit 24792b1

Browse files
committed
fix: rest parameter crash resolver
1 parent 321ed3d commit 24792b1

File tree

5 files changed

+30
-1
lines changed

5 files changed

+30
-1
lines changed

src/resolver.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ export class Resolver extends DiagnosticEmitter {
392392
break;
393393
}
394394
case ParameterKind.Rest: {
395-
assert(i == numParameters);
395+
assert(i == numParameters - 1);
396396
hasRest = true;
397397
break;
398398
}

tests/compiler/issues/2707.debug.wat

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
(module
2+
(type $i32_=>_i32 (func (param i32) (result i32)))
3+
(global $issues/2707/func (mut i32) (i32.const 32))
4+
(global $~lib/memory/__data_end i32 (i32.const 44))
5+
(global $~lib/memory/__stack_pointer (mut i32) (i32.const 32812))
6+
(global $~lib/memory/__heap_base i32 (i32.const 32812))
7+
(memory $0 1)
8+
(data $0 (i32.const 12) "\1c\00\00\00\00\00\00\00\00\00\00\00\05\00\00\00\08\00\00\00\01\00\00\00\00\00\00\00\00\00\00\00")
9+
(table $0 2 2 funcref)
10+
(elem $0 (i32.const 1) $start:issues/2707~anonymous|0)
11+
(export "memory" (memory $0))
12+
(func $start:issues/2707~anonymous|0 (param $args i32) (result i32)
13+
i32.const 1
14+
return
15+
)
16+
)

tests/compiler/issues/2707.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"asc_flags": []
3+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
(module
2+
(memory $0 1)
3+
(data $0 (i32.const 1036) "\1c")
4+
(data $0.1 (i32.const 1048) "\05\00\00\00\08\00\00\00\01")
5+
(export "memory" (memory $0))
6+
)

tests/compiler/issues/2707.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// should not crash
2+
let func: (...args: i32[]) => i32 = (...args: i32[]) => {
3+
return 1;
4+
};

0 commit comments

Comments
 (0)