1a2f01efa6
Update the Go library to the 1.10beta1 release. Requires a few changes to the compiler for modifications to the map runtime code, and to handle some nowritebarrier cases in the runtime. Reviewed-on: https://go-review.googlesource.com/86455 gotools/: * Makefile.am (go_cmd_vet_files): New variable. (go_cmd_buildid_files, go_cmd_test2json_files): New variables. (s-zdefaultcc): Change from constants to functions. (noinst_PROGRAMS): Add vet, buildid, and test2json. (cgo$(EXEEXT)): Link against $(LIBGOTOOL). (vet$(EXEEXT)): New target. (buildid$(EXEEXT)): New target. (test2json$(EXEEXT)): New target. (install-exec-local): Install all $(noinst_PROGRAMS). (uninstall-local): Uninstasll all $(noinst_PROGRAMS). (check-go-tool): Depend on $(noinst_PROGRAMS). Copy down objabi.go. (check-runtime): Depend on $(noinst_PROGRAMS). (check-cgo-test, check-carchive-test): Likewise. (check-vet): New target. (check): Depend on check-vet. Look at cmd_vet-testlog. (.PHONY): Add check-vet. * Makefile.in: Rebuild. From-SVN: r256365
104 lines
1.9 KiB
Go
104 lines
1.9 KiB
Go
// Copyright 2012 The Go Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
// This file contains the test for untagged struct literals.
|
|
|
|
package testdata
|
|
|
|
import (
|
|
"flag"
|
|
"go/scanner"
|
|
"image"
|
|
"unicode"
|
|
|
|
"path/to/unknownpkg"
|
|
)
|
|
|
|
var Okay1 = []string{
|
|
"Name",
|
|
"Usage",
|
|
"DefValue",
|
|
}
|
|
|
|
var Okay2 = map[string]bool{
|
|
"Name": true,
|
|
"Usage": true,
|
|
"DefValue": true,
|
|
}
|
|
|
|
var Okay3 = struct {
|
|
X string
|
|
Y string
|
|
Z string
|
|
}{
|
|
"Name",
|
|
"Usage",
|
|
"DefValue",
|
|
}
|
|
|
|
var Okay4 = []struct {
|
|
A int
|
|
B int
|
|
}{
|
|
{1, 2},
|
|
{3, 4},
|
|
}
|
|
|
|
type MyStruct struct {
|
|
X string
|
|
Y string
|
|
Z string
|
|
}
|
|
|
|
var Okay5 = &MyStruct{
|
|
"Name",
|
|
"Usage",
|
|
"DefValue",
|
|
}
|
|
|
|
var Okay6 = []MyStruct{
|
|
{"foo", "bar", "baz"},
|
|
{"aa", "bb", "cc"},
|
|
}
|
|
|
|
// Testing is awkward because we need to reference things from a separate package
|
|
// to trigger the warnings.
|
|
|
|
var goodStructLiteral = flag.Flag{
|
|
Name: "Name",
|
|
Usage: "Usage",
|
|
}
|
|
var badStructLiteral = flag.Flag{ // ERROR "unkeyed fields"
|
|
"Name",
|
|
"Usage",
|
|
nil, // Value
|
|
"DefValue",
|
|
}
|
|
|
|
// SpecialCase is a named slice of CaseRange to test issue 9171.
|
|
var goodNamedSliceLiteral = unicode.SpecialCase{
|
|
{Lo: 1, Hi: 2},
|
|
unicode.CaseRange{Lo: 1, Hi: 2},
|
|
}
|
|
var badNamedSliceLiteral = unicode.SpecialCase{
|
|
{1, 2}, // ERROR "unkeyed fields"
|
|
unicode.CaseRange{1, 2}, // ERROR "unkeyed fields"
|
|
}
|
|
|
|
// ErrorList is a named slice, so no warnings should be emitted.
|
|
var goodScannerErrorList = scanner.ErrorList{
|
|
&scanner.Error{Msg: "foobar"},
|
|
}
|
|
var badScannerErrorList = scanner.ErrorList{
|
|
&scanner.Error{"foobar"}, // ERROR "unkeyed fields"
|
|
}
|
|
|
|
// Check whitelisted structs: if vet is run with --compositewhitelist=false,
|
|
// this line triggers an error.
|
|
var whitelistedPoint = image.Point{1, 2}
|
|
|
|
// Do not check type from unknown package.
|
|
// See issue 15408.
|
|
var unknownPkgVar = unknownpkg.Foobar{"foo", "bar"}
|