@@ -833,6 +833,10 @@ type IsTypeArgument struct {
833833// For example:
834834//
835835// args.Assert(t, IsType(""), IsType(0))
836+ //
837+ // Mock cannot match interface types because the contained type will be passed
838+ // to both IsType and Mock.Called, for the zero value of all interfaces this
839+ // will be <nil> type.
836840func IsType (t interface {}) * IsTypeArgument {
837841 return & IsTypeArgument {t : reflect .TypeOf (t )}
838842}
@@ -1034,7 +1038,7 @@ func (args Arguments) Diff(objects []interface{}) (string, int) {
10341038 if actualT != expected .t {
10351039 differences ++
10361040 outputRenderers = append (outputRenderers , func () string {
1037- return fmt .Sprintf ("\t %d: FAIL: type %s != type %s - %s\n " , i , expected .t . Name ( ), actualT . Name () , actualFmt ())
1041+ return fmt .Sprintf ("\t %d: FAIL: type %s != type %s - %s\n " , i , safeTypeName ( expected .t ), actualT , actualFmt ())
10381042 })
10391043 }
10401044 case * FunctionalOptionsArgument :
@@ -1179,6 +1183,15 @@ func (args Arguments) Bool(index int) bool {
11791183 return s
11801184}
11811185
1186+ // safeTypeName returns the reflect.Type's name without causing a panic.
1187+ // If the provided reflect.Type is nil, it returns the placeholder string "<nil>"
1188+ func safeTypeName (t reflect.Type ) string {
1189+ if t == nil {
1190+ return "<nil>"
1191+ }
1192+ return t .Name ()
1193+ }
1194+
11821195func typeAndKind (v interface {}) (reflect.Type , reflect.Kind ) {
11831196 t := reflect .TypeOf (v )
11841197 k := t .Kind ()
0 commit comments