Skip to content

Commit

Permalink
Remove check for 0-length make.
Browse files Browse the repository at this point in the history
While a 0-length make is sometimes done when a user should
have used "var s []int", the current lint check is reported to
cause too many false positives on legitimate uses of 0-length make.
This occurs because there is a semantic difference between
"make([]int, 0)" and "var s []int".

Fixes golang#234
  • Loading branch information
dsnet committed Oct 4, 2016
1 parent 64229b8 commit 4e7ffd8
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 49 deletions.
30 changes: 0 additions & 30 deletions lint.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,6 @@ func (f *file) lint() {
f.lintErrorStrings()
f.lintReceiverNames()
f.lintIncDec()
f.lintMake()
f.lintErrorReturn()
f.lintUnexportedReturn()
f.lintTimeNames()
Expand Down Expand Up @@ -1273,35 +1272,6 @@ func (f *file) lintIncDec() {
})
}

// lintMake examines statements that declare and initialize a variable with make.
// It complains if they are constructing a zero element slice.
func (f *file) lintMake() {
f.walk(func(n ast.Node) bool {
as, ok := n.(*ast.AssignStmt)
if !ok {
return true
}
// Only want single var := assignment statements.
if len(as.Lhs) != 1 || as.Tok != token.DEFINE {
return true
}
ce, ok := as.Rhs[0].(*ast.CallExpr)
if !ok {
return true
}
// Check if ce is make([]T, 0).
if !isIdent(ce.Fun, "make") || len(ce.Args) != 2 || !isZero(ce.Args[1]) {
return true
}
at, ok := ce.Args[0].(*ast.ArrayType)
if !ok || at.Len != nil {
return true
}
f.errorf(as, 0.8, category("slice"), `can probably use "var %s %s" instead`, f.render(as.Lhs[0]), f.render(at))
return true
})
}

// lintErrorReturn examines function declarations that return an error.
// It complains if the error isn't the last parameter.
func (f *file) lintErrorReturn() {
Expand Down
19 changes: 0 additions & 19 deletions testdata/make.go

This file was deleted.

0 comments on commit 4e7ffd8

Please sign in to comment.