Skip to content

Commit 88b99aa

Browse files
myitcvflimzy
authored andcommitted
compiler: fix variadic args not being nil when zero length.
Fixes #806.
1 parent ec9572f commit 88b99aa

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

compiler/utils.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,10 @@ func (fc *funcContext) translateArgs(sig *types.Signature, argExprs []ast.Expr,
115115

116116
sigTypes := signatureTypes{Sig: sig}
117117

118+
if sig.Variadic() && len(argExprs) == 0 {
119+
return []string{fmt.Sprintf("%s.nil", c.typeName(varargType))}
120+
}
121+
118122
preserveOrder := false
119123
for i := 1; i < len(argExprs); i++ {
120124
preserveOrder = preserveOrder || fc.Blocking[argExprs[i]]

tests/compiler_test.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// +build js
2+
3+
package tests
4+
5+
import (
6+
"testing"
7+
)
8+
9+
func TestVariadicNil(t *testing.T) {
10+
printVari := func(strs ...string) []string {
11+
return strs
12+
}
13+
14+
if v := printVari(); v != nil {
15+
t.Errorf("expected printVari() to be %v; got: %v", nil, v)
16+
}
17+
}

0 commit comments

Comments
 (0)