Skip to content

Commit d3d5929

Browse files
committed
internal/impl: Extend fieldInfoForScalar() with ProtoStringer
1 parent a5c2af8 commit d3d5929

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

internal/impl/message_reflect_field.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,8 +292,18 @@ func fieldInfoForScalar(fd protoreflect.FieldDescriptor, fs reflect.StructField,
292292
return rv.Float() != 0 || math.Signbit(rv.Float())
293293
case reflect.String, reflect.Slice:
294294
return rv.Len() > 0
295+
case reflect.Ptr:
296+
if _, ok := rv.Interface().(protoreflect.ProtoStringer); ok {
297+
return !rv.IsNil()
298+
}
299+
fallthrough
300+
case reflect.Struct:
301+
if _, ok := rv.Interface().(protoreflect.ProtoStringer); ok {
302+
return !rv.IsNil()
303+
}
304+
fallthrough
295305
default:
296-
panic(fmt.Sprintf("field %v has invalid type: %v", fd.FullName(), rv.Type())) // should never happen
306+
panic(fmt.Sprintf("field %v has invalid type: %v %s", fd.FullName(), rv.Type(), rv.Kind())) // should never happen
297307
}
298308
},
299309
clear: func(p pointer) {

0 commit comments

Comments
 (0)