diff --git a/helper/schema/set.go b/helper/schema/set.go index 965ad6f8b8..a10c2b8d95 100644 --- a/helper/schema/set.go +++ b/helper/schema/set.go @@ -123,6 +123,9 @@ func (s *Set) add(item interface{}) int { s.once.Do(s.init) code := s.F(item) + if code < 0 { + code *= -1 + } if _, ok := s.m[code]; !ok { s.m[code] = item } diff --git a/helper/schema/set_test.go b/helper/schema/set_test.go index 8ae4be479f..9688c5f715 100644 --- a/helper/schema/set_test.go +++ b/helper/schema/set_test.go @@ -18,6 +18,20 @@ func TestSetAdd(t *testing.T) { } } +func TestSetAdd_negative(t *testing.T) { + // Since we don't allow negative hashes, this should just hash to the + // same thing... + s := &Set{F: testSetInt} + s.Add(-1) + s.Add(1) + + expected := []interface{}{-1} + actual := s.List() + if !reflect.DeepEqual(actual, expected) { + t.Fatalf("bad: %#v", actual) + } +} + func TestSetContains(t *testing.T) { s := &Set{F: testSetInt} s.Add(5)