flyingmutant / rapid

Rapid is a modern Go property-based testing library
https://pkg.go.dev/pgregory.net/rapid
Mozilla Public License 2.0
588 stars 25 forks source link

Make sure we return nil slices as empty slices sometimes #15

Closed flyingmutant closed 2 years ago

flyingmutant commented 4 years ago

As there is code that can work with a := []int{}, but fail with var a []int.

Can we treat empty slices as having something like len = -1 during generation?

wfscheper commented 4 years ago

The only time I can think of where go will handle those differently is in comparison to nil. For example, the following will only print "a is nil" once:

var a []int
if a == nil {
    fmt.Println("a is nil")  // this will print
}
a = []int{}
if a == nil {
    fmt.Println("a is nil")  // this won't
}
flyingmutant commented 2 years ago

Closing as it looks like there is not a lot of value in this.