ashanbrown / makezero

A linter to ensure that slices are not initialized with non-zero length
Other
71 stars 7 forks source link

Wrong Check when multiple declare in same line #8

Closed ivila closed 2 years ago

ivila commented 2 years ago
  1. makezero could make mistake in judge slice append when the slice declare in same line with other non-zero slice:
// will also report "append to slice `b` with non-zero initialized length at testing.go:7:9" while it shouldn't
package bar

func foo() {
    a, b := make([]int, 10), make([]int, 0)
    a = append(a, 10)
    b = append(b, 10)
}
  1. makezero failed to report in judge slice append when the slice declare in same line with other zero slice in front:
    
    // will report nothing while it should
    package bar

func foo() { a, b := make([]int, 0), make([]int, 10) a = append(a, 10) b = append(b, 10) }