There are four different treatments location metadata can receive in the convert.FromTyped method.
Location metadata is retained for maps, structs and slices if the value is not nil
Location metadata is lost for maps, structs and slices if the value is is nil
Location metadata is retained if a scalar type (eg. bool, string etc) does not change.
Location metadata is lost if the value for a scalar type changes.
This PR ensures that location metadata is not lost in any case; that is, it's always preserved.
For (2), this serves as a bug fix so that location information is not lost on conversion to and from typed for nil values of complex types (struct, slices, and maps).
For (4) this is a change in semantics. For primitive values modified in a typed mutator, any references to .Location() for computed primitive fields will now return associated YAML location metadata (if any) instead of an empty location.
While arguable, these semantics are OK since:
Situations like these will be rare.
Knowing the YAML location (if any) is better than not knowing the location at all. These locations are typically visible to the user in errors and warnings.
Changes
There are four different treatments location metadata can receive in the
convert.FromTyped
method.This PR ensures that location metadata is not lost in any case; that is, it's always preserved.
For (2), this serves as a bug fix so that location information is not lost on conversion to and from typed for nil values of complex types (struct, slices, and maps).
For (4) this is a change in semantics. For primitive values modified in a
typed
mutator, any references to.Location()
for computed primitive fields will now return associated YAML location metadata (if any) instead of an empty location.While arguable, these semantics are OK since:
Tests
Unit tests