diff --git a/cmd/stringer/stringer.go b/cmd/stringer/stringer.go index 33343def..f7039aa2 100644 --- a/cmd/stringer/stringer.go +++ b/cmd/stringer/stringer.go @@ -261,7 +261,7 @@ func (g *Generator) parsePackage(directory string, names []string, text interfac // check type-checks the package. The package must be OK to proceed. func (pkg *Package) check(fs *token.FileSet, astFiles []*ast.File) { pkg.defs = make(map[*ast.Ident]types.Object) - var config types.Config + config := types.Config{FakeImportC: true} info := &types.Info{ Defs: pkg.defs, } diff --git a/cmd/stringer/testdata/cgo.go b/cmd/stringer/testdata/cgo.go new file mode 100644 index 00000000..ef38f959 --- /dev/null +++ b/cmd/stringer/testdata/cgo.go @@ -0,0 +1,32 @@ +// Copyright 2014 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. + +// Import "C" shouldn't be imported. + +package main + +/* +#define HELLO 1 +*/ +import "C" + +import "fmt" + +type Cgo uint32 + +const ( + // MustScanSubDirs indicates that events were coalesced hierarchically. + MustScanSubDirs Cgo = 1 << iota +) + +func main() { + _ = C.HELLO + ck(MustScanSubDirs, "MustScanSubDirs") +} + +func ck(day Cgo, str string) { + if fmt.Sprint(day) != str { + panic("cgo.go: " + str) + } +}