1
0
mirror of https://github.com/golang/go synced 2024-11-18 11:04:42 -07:00

tools/cmd/stringer: fake import C.

Avoid error "could not import C (can't find import: C)"
Fixes golang/go#9169.

LGTM=adonovan, r
R=golang-codereviews, adonovan, r
CC=golang-codereviews
https://golang.org/cl/184730043
This commit is contained in:
Nathan John Youngman 2014-11-27 15:36:14 +11:00 committed by Rob Pike
parent 354b6ccbcc
commit 806f1dbf43
2 changed files with 33 additions and 1 deletions

View File

@ -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,
}

32
cmd/stringer/testdata/cgo.go vendored Normal file
View File

@ -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)
}
}