Skip to content

fix(common): nil safety in SortedSet methods and fix test format args - #28

Open
reginaldalfret wants to merge 1 commit into
spotify:mainfrom
reginaldalfret:fix/sorted-set-nil-safety-and-test-formatting
Open

reginaldalfret wants to merge 1 commit into
spotify:mainfrom
reginaldalfret:fix/sorted-set-nil-safety-and-test-formatting

Conversation

@reginaldalfret

Copy link
Copy Markdown

Problem

  1. In common/sorted_set/sorted_set.go, methods Len(), Contains(), and SortedSlice() defensively check for s == nil. However, AddAll(other), Filter(), and Clone() dereferenced receiver or argument btree pointers directly, causing panics if called on a nil SortedSet or with a nil other set.
  2. In common/sorted_set/sorted_set_test.go, five t.Errorf("... wanted %v got %v") assertions omitted the (want, got) arguments, causing compilation errors during go vet and go test with modern Go toolchains.

Solution

  1. Added nil checks in:
    • AddAll(other): return early if s == nil, s.tree == nil, other == nil, or other.tree == nil.
    • Filter(predicate): return nil if s == nil or s.tree == nil.
    • Clone(): return nil if s == nil or s.tree == nil.
  2. Passed want, got arguments to all 5 t.Errorf calls in TestInsert.
  3. Added TestSortedSet_NilSafety testing nil receivers and arguments across Len, Contains, SortedSlice, Clone, Filter, and AddAll.

This commit:
- Adds nil receiver and nil argument guards to SortedSet.AddAll, Filter, and Clone to match existing nil safety in Len, Contains, and SortedSlice.
- Fixes 5 occurrences in sorted_set_test.go where t.Errorf format string %v was called without the (want, got) arguments, which caused compilation failures under Go vet.
- Adds TestSortedSet_NilSafety exercising nil receiver and nil argument handling.

Signed-off-by: Reginald Alfret <reginaldalfret@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant