Describe the bug
update:ignoreZeroValueField can generate Go code that does not compile when the source field is a struct containing a non-comparable field, such as a slice, map, or function.
The generated code compares the source field against its zero value using !=, but Go only allows struct comparison when all struct fields are comparable.
To Reproduce
Given a nullable-style wrapper type and a converter using update mode with zero-value skipping:
type NullUUIDs struct {
UUIDs []uuid.UUID
Valid bool
}
// goverter:converter
type Converter interface {
// goverter:update target
// goverter:update:ignoreZeroValueField yes
Convert(source *Source, target *Target)
}
type Source struct {
UUIDs NullUUIDs
}
type Target struct {
UUIDs []uuid.UUID
}
This lead to goverter generates code that cannot be compiled:
// invalid operation: source.UUIDs != (NullUUIDs{}) (struct containing []uuid.UUID cannot be compared)
if source.UUIDs != (NullUUIDs{}) {
target.UUIDs = convertNullUUIDs(source.UUIDs)
}
Expected behavior
Goverter should avoid generating != comparisons for non-comparable struct types.
Possible approaches:
- Detect whether a struct type is comparable before emitting != zero and Fall back to reflect.Value.IsZero or an equivalent helper for non-comparable structs.
- Provide a directive/hook to customize zero-value detection for a specific source field/type.
- Provide some generic post-processing hook, so we can ignore these fields with
// goverter:ignore and then convert them with an extra-hook.
Describe the bug
update:ignoreZeroValueFieldcan generate Go code that does not compile when the source field is a struct containing a non-comparable field, such as a slice, map, or function.The generated code compares the source field against its zero value using
!=, but Go only allows struct comparison when all struct fields are comparable.To Reproduce
Given a nullable-style wrapper type and a converter using update mode with zero-value skipping:
This lead to goverter generates code that cannot be compiled:
Expected behavior
Goverter should avoid generating != comparisons for non-comparable struct types.
Possible approaches:
// goverter:ignoreand then convert them with an extra-hook.