makezero icon indicating copy to clipboard operation
makezero copied to clipboard

False positive: slice does not have non-zero initial length (makezero) incorrectly reported when slice length is explicitly set.

Open Shubham-iron opened this issue 2 months ago • 0 comments

The linter reports the warning:

slice 'result' does not have non-zero initial length (makezero)

even when the slice is explicitly created with a non-zero length.

func initUserScores(users []string, defaultScore int) map[string][]int {
	result := make(map[string][]int, len(users))
	template := []int{defaultScore, defaultScore}

	for _, u := range users {
		// Pre-allocate exact slice length
		result[u] = make([]int, len(template))
		copy(result[u], template)
	}

	return result
}

Can we handle these type of cases where function like copy are immediately next to declaration.

Shubham-iron avatar Nov 24 '25 09:11 Shubham-iron