Summary
Keys() and Values() return nil for an empty map (because append onto a nil slice stays nil). Map() returns an empty non-nil map. That asymmetry is observable (keys == nil is true for Keys but the same check on Map's return is false) and not documented.
Scope
Either:
A. Make Keys/Values return non-nil empty slices (make([]K, 0)) — consistent with Map's non-nil contract. Probably the right call since #TBD also pre-allocates.
B. Keep current behaviour but document explicitly.
Acceptance criteria
TestKeys_Empty and TestValues_Empty assert non-nil slice (or explicitly nil — whichever is chosen).
- Godoc on all three methods consistent about nil-vs-empty return.
Source: code-reviewer + security-reviewer.
Summary
Keys()andValues()returnnilfor an empty map (becauseappendonto a nil slice stays nil).Map()returns an empty non-nil map. That asymmetry is observable (keys == nilis true for Keys but the same check on Map's return is false) and not documented.Scope
Either:
A. Make Keys/Values return non-nil empty slices (
make([]K, 0)) — consistent with Map's non-nil contract. Probably the right call since #TBD also pre-allocates.B. Keep current behaviour but document explicitly.
Acceptance criteria
TestKeys_EmptyandTestValues_Emptyassert non-nil slice (or explicitly nil — whichever is chosen).Source: code-reviewer + security-reviewer.