From: Rob Pike Date: Tue, 22 Feb 2011 17:21:50 +0000 (-0800) Subject: reflect: add a secret method to ArrayOrSliceType. X-Git-Tag: weekly.2011-02-24~46 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=795ff00df0f2e2eae44b50f33e2b63c23ec1a862;p=gostls13.git reflect: add a secret method to ArrayOrSliceType. It was observed that the interface was generic enough that several other types implemented it too. Fixes #1530. R=rsc CC=golang-dev https://golang.org/cl/4169063 --- diff --git a/src/pkg/reflect/type.go b/src/pkg/reflect/type.go index 6ee9c127a4..9ccee3ae9d 100644 --- a/src/pkg/reflect/type.go +++ b/src/pkg/reflect/type.go @@ -163,6 +163,10 @@ type SliceType struct { elem *runtime.Type } +// arrayOrSliceType is an unexported method that guarantees only +// arrays and slices implement ArrayOrSliceType. +func (*SliceType) arrayOrSliceType() {} + // Struct field type structField struct { name *string @@ -397,6 +401,10 @@ func (t *ArrayType) Len() int { return int(t.len) } // Elem returns the type of the array's elements. func (t *ArrayType) Elem() Type { return toType(*t.elem) } +// arrayOrSliceType is an unexported method that guarantees only +// arrays and slices implement ArrayOrSliceType. +func (*ArrayType) arrayOrSliceType() {} + // Dir returns the channel direction. func (t *ChanType) Dir() ChanDir { return ChanDir(t.dir) } @@ -675,6 +683,7 @@ func toType(i interface{}) Type { type ArrayOrSliceType interface { Type Elem() Type + arrayOrSliceType() // Guarantees only Array and Slice implement this interface. } // Typeof returns the reflection Type of the value in the interface{}.