@@ -608,14 +608,22 @@ func (t *rawType) String() string {
608608 s += " }"
609609 return s
610610 case Func :
611+ isVariadic := t .IsVariadic ()
611612
612613 f := "func("
613614 for i := 0 ; i < t .NumIn (); i ++ {
614615 if i > 0 {
615616 f += ", "
616617 }
617- f += t .In (i ).String ()
618+
619+ input := t .In (i ).String ()
620+ if isVariadic && i == t .NumIn ()- 1 {
621+ f += "..."
622+ input = input [2 :]
623+ }
624+ f += input
618625 }
626+
619627 f += ") "
620628
621629 var rets string
@@ -1069,21 +1077,36 @@ func (t *rawType) ConvertibleTo(u Type) bool {
10691077}
10701078
10711079func (t * rawType ) IsVariadic () bool {
1072- // need to test if bool mapped to int set by compiler
1080+ if t .isNamed () {
1081+ named := (* namedType )(unsafe .Pointer (t ))
1082+ t = named .elem
1083+ }
1084+
10731085 if t .Kind () != Func {
10741086 panic ("reflect: IsVariadic of non-func type" )
10751087 }
1088+
10761089 return (* funcType )(unsafe .Pointer (t )).variadic
10771090}
10781091
10791092func (t * rawType ) NumIn () int {
1093+ if t .isNamed () {
1094+ named := (* namedType )(unsafe .Pointer (t ))
1095+ return int ((* funcType )(unsafe .Pointer (named .elem )).inCount )
1096+ }
1097+
10801098 if t .Kind () != Func {
10811099 panic ("reflect: NumIn of non-func type" )
10821100 }
10831101 return int ((* funcType )(unsafe .Pointer (t )).inCount )
10841102}
10851103
10861104func (t * rawType ) NumOut () int {
1105+ if t .isNamed () {
1106+ named := (* namedType )(unsafe .Pointer (t ))
1107+ return int ((* funcType )(unsafe .Pointer (named .elem )).outCount )
1108+ }
1109+
10871110 if t .Kind () != Func {
10881111 panic ("reflect: NumOut of non-func type" )
10891112 }
@@ -1163,33 +1186,43 @@ func addChecked(p unsafe.Pointer, x uintptr, whySafe string) unsafe.Pointer {
11631186}
11641187
11651188func (t * rawType ) In (i int ) Type {
1189+ if t .isNamed () {
1190+ named := (* namedType )(unsafe .Pointer (t ))
1191+ t = named .elem
1192+ }
1193+
11661194 if t .Kind () != Func {
11671195 panic (errTypeField )
11681196 }
1169- descriptor := (* funcType )(unsafe .Pointer (t . underlying () ))
1170- if uint (i ) >= uint (descriptor .inCount ) {
1197+ fType := (* funcType )(unsafe .Pointer (t ))
1198+ if uint (i ) >= uint (fType .inCount ) {
11711199 panic ("reflect: field index out of range" )
11721200 }
11731201
1174- pointer := (unsafe .Add (unsafe .Pointer (& descriptor .fields [0 ]), uintptr (i )* unsafe .Sizeof (unsafe .Pointer (nil ))))
1175- return (* rawType )( * (* * rawType )(pointer ))
1202+ pointer := (unsafe .Add (unsafe .Pointer (& fType .fields [0 ]), uintptr (i )* unsafe .Sizeof (unsafe .Pointer (nil ))))
1203+ return (* (* * rawType )(pointer ))
11761204}
11771205
11781206func (t * rawType ) Out (i int ) Type {
1207+ if t .isNamed () {
1208+ named := (* namedType )(unsafe .Pointer (t ))
1209+ t = named .elem
1210+ }
1211+
11791212 if t .Kind () != Func {
11801213 panic (errTypeField )
11811214 }
11821215
1183- descriptor := (* funcType )(unsafe .Pointer (t .underlying ()))
1184- if uint (i ) >= uint (descriptor .outCount ) {
1216+ fType := (* funcType )(unsafe .Pointer (t ))
1217+
1218+ if uint (i ) >= uint (fType .outCount ) {
11851219 panic ("reflect: field index out of range" )
11861220 }
11871221
11881222 // Shift the index by the number of input parameters.
1189- i = i + int ((* funcType )(unsafe .Pointer (t )).inCount )
1190-
1191- pointer := (unsafe .Add (unsafe .Pointer (& descriptor .fields [0 ]), uintptr (i )* unsafe .Sizeof (unsafe .Pointer (nil ))))
1192- return (* rawType )(* (* * rawType )(pointer ))
1223+ i = i + int (fType .inCount )
1224+ pointer := (unsafe .Add (unsafe .Pointer (& fType .fields [0 ]), uintptr (i )* unsafe .Sizeof (unsafe .Pointer (nil ))))
1225+ return (* (* * rawType )(pointer ))
11931226}
11941227
11951228// OverflowComplex reports whether the complex128 x cannot be represented by type t.
0 commit comments