From 7c546566c35ed682dcd1892d174071cde1014e46 Mon Sep 17 00:00:00 2001 From: David Crawshaw Date: Fri, 11 Mar 2016 17:49:07 -0500 Subject: [PATCH] cmd/compile: compute number of arguments correctly The outCount value includes a flag bit for dotdotdot. If we have this count incorrect, then the offset for the methodset *rtype are in the wrong place. Fixes #14783 Change-Id: If5acb16af08d4ffe36c8c9ee389c32f2712ce757 Reviewed-on: https://go-review.googlesource.com/20566 Reviewed-by: Ian Lance Taylor Run-TryBot: Ian Lance Taylor TryBot-Result: Gobot Gobot --- src/cmd/compile/internal/gc/reflect.go | 2 +- src/reflect/all_test.go | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/cmd/compile/internal/gc/reflect.go b/src/cmd/compile/internal/gc/reflect.go index cd39969258..5ca292c39e 100644 --- a/src/cmd/compile/internal/gc/reflect.go +++ b/src/cmd/compile/internal/gc/reflect.go @@ -1068,7 +1068,7 @@ ok: ot += 4 // align for *rtype } - dataAdd := (inCount + outCount) * Widthptr + dataAdd := (inCount + t.Outtuple) * Widthptr ot = dextratype(s, ot, t, dataAdd) // Array of rtype pointers follows funcType. diff --git a/src/reflect/all_test.go b/src/reflect/all_test.go index 352b2046e7..32dd782c3c 100644 --- a/src/reflect/all_test.go +++ b/src/reflect/all_test.go @@ -2410,6 +2410,17 @@ func TestEmbeddedMethods(t *testing.T) { } } +type FuncDDD func(...interface{}) error + +func (f FuncDDD) M() {} + +func TestNumMethodOnDDD(t *testing.T) { + rv := ValueOf((FuncDDD)(nil)) + if n := rv.NumMethod(); n != 1 { + t.Fatalf("NumMethod()=%d, want 1", n) + } +} + func TestPtrTo(t *testing.T) { var i int