Skip to content

Commit

Permalink
fix typed func variadic
Browse files Browse the repository at this point in the history
  • Loading branch information
visualfc committed Jul 25, 2022
1 parent 45e4033 commit f3887d9
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 6 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.14
require (
github.com/goplus/gop v1.1.2
github.com/goplus/gox v1.11.12
github.com/goplus/reflectx v0.9.0
github.com/goplus/reflectx v0.9.3
github.com/peterh/liner v1.2.2
github.com/petermattis/goid v0.0.0-20220331194723-8ee3e6ded87a
github.com/visualfc/funcval v0.1.3
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ github.com/goplus/gox v1.11.12/go.mod h1:wRCRSNukie4cDqADF4w0Btc2Gk6V3p3V6hI5+rs
github.com/goplus/libc v0.3.10/go.mod h1:gSQ8dVF/iKdoBn1ABeQfAF/ybaYX0pij3iPtC72FtJc=
github.com/goplus/mod v0.9.12 h1:CjgBGQIYqUTPGl3MrAS5CICzJwxbIfSa4OlEb141Gs4=
github.com/goplus/mod v0.9.12/go.mod h1:YoPIowz71rnLLROA4YG0AC8bzDtPRyMaQwgTRLr8ri4=
github.com/goplus/reflectx v0.9.0 h1:T+TF/0Z6C5NEJkf1HaWQFoAzCLCftdsayFpNl6aYl6w=
github.com/goplus/reflectx v0.9.0/go.mod h1:XPDe5lYQ/8FN05bhqv6r1hhLxwmYIkZ5UvIkN1GNRYg=
github.com/goplus/reflectx v0.9.3 h1:qokF5QYma0SXpURkCLYJ8QxR+EtNX0BM1VEzzQlnAUk=
github.com/goplus/reflectx v0.9.3/go.mod h1:XPDe5lYQ/8FN05bhqv6r1hhLxwmYIkZ5UvIkN1GNRYg=
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
github.com/mattn/go-runewidth v0.0.3 h1:a+kO+98RDGEfo6asOGMmpodZq4FNtnGP54yps8BzLR4=
github.com/mattn/go-runewidth v0.0.3/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU=
Expand Down
17 changes: 17 additions & 0 deletions interp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2174,3 +2174,20 @@ func main() {
panic(all)
}
}

func TestVariadicFunc(t *testing.T) {
src := `package main
type Context struct{}
type ClientConn struct{}
type CallOption struct{}
type UnaryInvoker func(ctx Context, method string, req, reply interface{}, cc *ClientConn, opts ...CallOption) error
func main() {
}
`
_, err := igop.RunFile("main.go", src, nil, 0)
if err != nil {
t.Fatal(err)
}
}
14 changes: 11 additions & 3 deletions xtypes.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,21 @@ func toMockType(typ types.Type) reflect.Type {
}
ins := make([]reflect.Type, in, in)
outs := make([]reflect.Type, out, out)
for i := 0; i < in; i++ {
ins[i] = tyEmptyStruct
variadic := t.Variadic()
if variadic {
for i := 0; i < in-1; i++ {
ins[i] = tyEmptyStruct
}
ins[in-1] = tyEmptySlice
} else {
for i := 0; i < in; i++ {
ins[i] = tyEmptyStruct
}
}
for i := 0; i < out; i++ {
outs[i] = tyEmptyStruct
}
return reflect.FuncOf(ins, outs, t.Variadic())
return reflect.FuncOf(ins, outs, variadic)
default:
panic(fmt.Errorf("toEmptyType: unreachable %v", typ))
}
Expand Down

0 comments on commit f3887d9

Please sign in to comment.