Repository navigation
fix(common): nil safety in SortedSet methods and fix test format args - #28
Open
reginaldalfret wants to merge 1 commit into
Open
reginaldalfret wants to merge 1 commit into
reginaldalfret wants to merge 1 commit into
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
common/sorted_set/sorted_set.go, methodsLen(),Contains(), andSortedSlice()defensively check fors == nil. However,AddAll(other),Filter(), andClone()dereferenced receiver or argument btree pointers directly, causing panics if called on a nilSortedSetor with a nilotherset.common/sorted_set/sorted_set_test.go, fivet.Errorf("... wanted %v got %v")assertions omitted the(want, got)arguments, causing compilation errors duringgo vetandgo testwith modern Go toolchains.Solution
AddAll(other): return early ifs == nil,s.tree == nil,other == nil, orother.tree == nil.Filter(predicate): returnnilifs == nilors.tree == nil.Clone(): returnnilifs == nilors.tree == nil.want, gotarguments to all 5t.Errorfcalls inTestInsert.TestSortedSet_NilSafetytesting nil receivers and arguments acrossLen,Contains,SortedSlice,Clone,Filter, andAddAll.