Closed ewhauser closed 3 months ago
Currently useUnderlyingTypeMethods
has precedent over enum matching or actually any other type matching in Goverter. I'm not sure it's that clear-cut that enum matching should take precedent over useUnderlyingTypeMethods
and vice-versa.
extend
methods in the namespace shouldn't be used when converting enums.
I'm not sure about that. If the extend method matches the enums directly, it should always be used. E.g.
func ConvertEnum(input.SqlColor) output.Color {
// ...
}
Given that, it's consistent that useUnderlyingTypeMethods
also taken precedent over the enum matching but I can see that it's not obvious.
useUnderlyingTypeMethods
was initially implemented as an alternative for the enum use-case. So I'd say both settings conflict with each other. What do you think about letting goverter error if an extend method was found via useUnderlyingTypeMethods
and the conversion also qualifies for enum conversion?
The conflict can then be resolved by disabling enum for the method:
// goverter:converter
// goverter:extend ConvertUnderlying
// goverter:useUnderlyingTypeMethods
type Converter interface {
// goverter:enum no
Convert(input.SqlColor) output.Color
}
or disabling useUnderlyingTypeMethods:
// goverter:converter
// goverter:extend ConvertUnderlying
// goverter:useUnderlyingTypeMethods
type Converter interface {
// goverter:useUnderlyingTypeMethods no
Convert(input.SqlColor) output.Color
}
@jmattheis I think you're right in that the real problem here is that the settings conflict with each other. The new enum
functionality is a much better way to handle these conversions. An error seems reasonable but also don't feel like you need to address just for me.
Thank you!
Adding the error should be fairly simple, so I think it's worth to implement it.
Describe the bug When goverter tries to do an enum to enum conversion, it shouldn't use an matching underlying type methods in the conversion
To Reproduce Include the input file that goverter has problems with, and describe the steps you took to trigger the bug
Take the following scenario:
Expected behavior A clear and concise description of what you expected to happen.
extend
methods in the namespace shouldn't be used when converting enums.