Closed dropwhile closed 10 months ago
Goverter currently doesn't check if the source type is assignable to an interface of an extend method.
In the error message the conversion error occurs for the types RefID -> string, you could define the extend method like this.
// goverter:converter
// goverter:matchIgnoreCase
// goverter:extend StringerToString
type Converter interface {
ConvertNotifications(source []*Notification) []*PbNotification
// goverter:ignoreUnexported
ConvertNotification(source *Notification) *PbNotification
}
func StringerToString(x RefID) string {
return x.String()
}
This should be generic enough for this use-case. I'm not 100% against supporting interface assignment checks for extend methods, but it needs a better use-case for me to consider integrating it into goverter.
Unfortunately RefID
in my example is one of many RefID "types" (used so static typing makes it harder to call methods with bad identifier types). I have a workaround for now, and I think my use case is probably a bit unusual or uncommon.
Thanks for the consideration though!
Describe the bug goverter:extend with Interface does not seem to work as expected.
To Reproduce
Note: extracted from a larger codebase, so this example isn't quite exact
output
Expected behavior I would have expected it to work.
Current work around I am using:
It works, but then I have to annotate all methods (there will be many more instances/uses of RefID).