We can trust that untyped composite literals are part of a slice literal
and not emit a vet warning for those.
Fixes #9171
Change-Id: Ia7c081e543b850f8be1fd1f9e711520061e70bed
Reviewed-on: https://go-review.googlesource.com/22000
Run-TryBot: Rob Pike <r@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rob Pike <r@golang.org>
allKeyValue := true
for _, e := range c.Elts {
if _, ok := e.(*ast.KeyValueExpr); !ok {
- allKeyValue = false
- break
+ if cl, ok := e.(*ast.CompositeLit); !ok || cl.Type != nil {
+ allKeyValue = false
+ break
+ }
}
}
if allKeyValue {
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
-// This file contains tests for the untagged struct literal checker.
-
// This file contains the test for untagged struct literals.
package testdata
import (
"flag"
"go/scanner"
+ "unicode"
)
var Okay1 = []string{
"DefValue",
}
+// SpecialCase is an (aptly named) slice of CaseRange to test issue 9171.
+var GoodNamedSliceLiteralUsedInTests = unicode.SpecialCase{
+ {Lo: 1, Hi: 2},
+}
+
// Used to test the check for slices and arrays: If that test is disabled and
// vet is run with --compositewhitelist=false, this line triggers an error.
// Clumsy but sufficient.