I am using Go 1.12.1.
cmd/vet does not report any warning for example code below:
package main
type noCopy struct{}
func (*noCopy) Lock() {}
func (*noCopy) Unlock() {}
func (*noCopy) MuteUnusedWarning() {}
func returnNCP() *noCopy {
var nc noCopy
return &nc
}
func main() {
var nc noCopy
nc = *returnNCP()
nc.MuteUnusedWarning()
}
I read code of the analyzer copylock.go:
func lockPathRhs(pass *analysis.Pass, x ast.Expr) typePath {
224 if _, ok := x.(*ast.CompositeLit); ok {
225 return nil
226 }
227 if _, ok := x.(*ast.CallExpr); ok {
228 // A call may return a zero value.
229 return nil
230 }
231 if star, ok := x.(*ast.StarExpr); ok {
232 if _, ok := star.X.(*ast.CallExpr); ok {
233 // A call may return a pointer to a zero value.
234 return nil
235 }
my confusion is why line 234 just return nil without check the return type of the function (BTW, in my example code, "return &nc" will pass the "checkCopyLocksReturnStmt" check, b/c the return type is a pointer). All this result to the mute of cmd/vet.
Could this case be caught by cmd/vet in future?
I am using Go 1.12.1.
cmd/vet does not report any warning for example code below:
I read code of the analyzer copylock.go:
my confusion is why line 234 just return nil without check the return type of the function (BTW, in my example code, "return &nc" will pass the "checkCopyLocksReturnStmt" check, b/c the return type is a pointer). All this result to the mute of cmd/vet.
Could this case be caught by cmd/vet in future?