better detection of pointer receivers #979
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I did not attempt to fully grok the yaml marshaler implementation but it seems to me to be broken, in the sense that it does not correctly pick up Marshaler implementations that take pointer receivers when a non-pointer struct is marshaled. While at some point the yaml marshaler may want to treat pointers differently from non-pointers (e.g., to create anchors and references), this is not currently a feature so I think "casting" everything to a pointer before doing the type assertion is a valid way to go. time.Time doesn't need a custom marshaler since that type already implements TextMarshaler; and there seemed to be inconsistent handling of Duration and Time pointers vs non-pointers. This is cleaned up in the PR because the "cast" to a pointer folds. I saw other PRs that introduce the ability to set Time formatters etc but I think maybe a more general impl such as passing in a func() that gets called on all types that don't have a Marshaler so as to be able to override the default behavior ...