Invoke String/Error methods on addressable vals.

If a type implements a Stringer or error interface with a pointer receiver
and the value being formatted is addressable, the interface should be
invoked even when the DisablePointerMethods option is set.
DisablePointerMethods is only intended to prevent the potentially unsafe
action of stepping around type-safety restriction to invoke a Stringer or
error interface with a pointer to an unaddressable value.
This commit is contained in:
Dave Collins 2013-01-20 17:37:24 -06:00
parent 0cd00fd3ae
commit 6024e0c79e
1 changed files with 3 additions and 0 deletions

View File

@ -140,6 +140,9 @@ func handleMethods(cs *ConfigState, w io.Writer, v reflect.Value) (handled bool)
}
viface = v.Addr().Interface()
} else {
if v.CanAddr() {
v = v.Addr()
}
viface = v.Interface()
}