You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I observed this issue printing a complex data structure with several structs containing interface fields which could be one of many conforming types. A number of those types might be empty structs, where the type is the only relevant information (the zero value is the only value).
If the outer struct with an interface field is printed, the nonzero function returns false because the concrete value of the interface field is zero. An example playground showing this can be found here: https://go.dev/play/p/HjxnCorTQtj
For interface fields, would it be possible to mark the field as nonzero if the field is non-nil, rather than the value of what the field is pointing at?
Thanks!
package main
import (
"fmt""github.com/kr/pretty"
)
funcmain() {
// This should print the zero value for Av:=&A{Err: nil}
pretty.Println(v)
// This will print &main.FormatError{...}v.Err=&FormatError{"foo.go", 12}
pretty.Println(v)
// This SHOULD print &main.A{Err: main.LogicError{}}, but prints the zero value for A instead.v.Err=LogicError{}
pretty.Println(v)
}
typeAstruct {
Errerror
}
typeFormatErrorstruct {
FilestringLineint
}
func (err*FormatError) Error() string {
returnfmt.Sprintf("format error: %s:%d", err.File, err.Line)
}
typeLogicErrorstruct{}
func (LogicError) Error() string {
return"logic error"
}
Hi there, thanks for making this package.
I observed this issue printing a complex data structure with several structs containing
interface
fields which could be one of many conforming types. A number of those types might be empty structs, where the type is the only relevant information (the zero value is the only value).If the outer struct with an
interface
field is printed, thenonzero
function returnsfalse
because the concrete value of the interface field is zero. An example playground showing this can be found here: https://go.dev/play/p/HjxnCorTQtjFor
interface
fields, would it be possible to mark the field as nonzero if the field is non-nil, rather than the value of what the field is pointing at?Thanks!
Output
Desired Output
The text was updated successfully, but these errors were encountered: