go vet panic: inconsistent import go vet 报错:导入不一致

huangapple go评论137阅读模式
英文:

go vet panic: inconsistent import

问题

当我运行go vet ./...时,我遇到了以下输出的 go vet 错误:

% go version
go version go1.6.2 darwin/amd64
% go vet ./...
% go version
go version go1.7beta1 darwin/amd64
% go vet ./...
panic: inconsistent import:
    var crypto/rand.Reader io.Reader previously imported as:
    var Reader io.Reader  [recovered]
    panic: inconsistent import:
    var crypto/rand.Reader io.Reader previously imported as:
    var Reader io.Reader


goroutine 1 [running]: panic(0x25f720, 0xc4203fc1f0)
    /usr/local/go/src/runtime/panic.go:500 +0x1a1 go/types.(*Checker).handleBailout(0xc4200b61c0, 0xc4200c78e8)
    /usr/local/go/src/go/types/check.go:213 +0xae panic(0x25f720, 0xc4203fc1f0)
    /usr/local/go/src/runtime/panic.go:458 +0x243 go/internal/gcimporter.(*importer).declare(0xc42008e000, 0x3d81c0, 0xc4203ea5f0)
    /usr/local/go/src/go/internal/gcimporter/bimport.go:173 +0x17c go/internal/gcimporter.(*importer).obj(0xc42008e000, 0xfffffffffffffffc)
    /usr/local/go/src/go/internal/gcimporter/bimport.go:193 +0x1af go/internal/gcimporter.BImportData(0xc42000af00, 0xc420334000, 0x703e, 0x7e00, 0xc420166a51, 0xb, 0x0, 0xb, 0xc4203f4ff0, 0xc4200c70c8)
    /usr/local/go/src/go/internal/gcimporter/bimport.go:86 +0x34c go/internal/gcimporter.Import(0xc42000af00, 0xc420166a51, 0xb, 0x7fff5fbff610, 0x8, 0xc420320190, 0x0, 0x0)
    /usr/local/go/src/go/internal/gcimporter/gcimporter.go:166 +0x551 go/importer.gcimports.ImportFrom(0xc42000af00, 0xc420166a51, 0xb, 0x7fff5fbff610, 0x8, 0x0, 0xc4202d55e0, 0x0, 0x0)
    /usr/local/go/src/go/importer/importer.go:70 +0x67 go/types.(*Checker).collectObjects(0xc4200b61c0)
    /usr/local/go/src/go/types/resolver.go:191 +0x81d go/types.(*Checker).checkFiles(0xc4200b61c0, 0xc42018b600, 0x2, 0x2, 0x0, 0x0)
    /usr/local/go/src/go/types/check.go:225 +0xaa go/types.(*Checker).Files(0xc4200b61c0, 0xc42018b600, 0x2, 0x2, 0xc420192a80, 0xc4200cb960)
    /usr/local/go/src/go/types/check.go:218 +0x49 go/types.(*Config).Check(0xc42018d9c0, 0xc420015817, 0x5, 0xc420013f00, 0xc42018b600, 0x2, 0x2, 0xc420187400, 0x45e000, 0x0, ...)
    /usr/local/go/src/go/types/api.go:344 +0x19f main.(*Package).check(0xc42001a8a0, 0xc420013f00, 0xc42018b600, 0x2, 0x2, 0xc42018b610, 0x1)
    /usr/local/go/src/cmd/vet/types.go:76 +0x36c main.doPackage(0x2b769c, 0x1, 0xc42000a220, 0x2, 0x2, 0x0)
    /usr/local/go/src/cmd/vet/main.go:333 +0x992 main.main()
    /usr/local/go/src/cmd/vet/main.go:241 +0x335 exit status 2 panic: inconsistent import:
    var time.UTC *time.Location previously imported as:
    var UTC *time.Location  [recovered]
    panic: inconsistent import:
    var time.UTC *time.Location previously imported as:
    var UTC *time.Location


goroutine 1 [running]: panic(0x25f720, 0xc420141b10)
    /usr/local/go/src/runtime/panic.go:500 +0x1a1 go/types.(*Checker).handleBailout(0xc4200ce1c0, 0xc42004b8d8)
    /usr/local/go/src/go/types/check.go:213 +0xae panic(0x25f720, 0xc420141b10)
    /usr/local/go/src/runtime/panic.go:458 +0x243 go/internal/gcimporter.(*importer).declare(0xc4200a2cc0, 0x3d81c0, 0xc4205f6d70)
    /usr/local/go/src/go/internal/gcimporter/bimport.go:173 +0x17c go/internal/gcimporter.(*importer).obj(0xc4200a2cc0, 0xfffffffffffffffc)
    /usr/local/go/src/go/internal/gcimporter/bimport.go:193 +0x1af go/internal/gcimporter.BImportData(0xc42007ae40, 0xc42035a000, 0x3a210, 0x3fe00, 0xc42007995b, 0x4, 0x0, 0x4, 0xc4201392f0, 0xc42004b0b8)
    /usr/local/go/src/go/internal/gcimporter/bimport.go:86 +0x34c go/internal/gcimporter.Import(0xc42007ae40, 0xc42007995b, 0x4, 0x7fff5fbff598, 0x7, 0xc4205b7040, 0x0, 0x0)
    /usr/local/go/src/go/internal/gcimporter/gcimporter.go:166 +0x551 go/importer.gcimports.ImportFrom(0xc42007ae40, 0xc42007995b, 0x4, 0x7fff5fbff598, 0x7, 0x0, 0xc42017ec80, 0x0, 0x0)
    /usr/local/go/src/go/importer/importer.go:70 +0x67 go/types.(*Checker).collectObjects(0xc4200ce1c0)
    /usr/local/go/src/go/types/resolver.go:191 +0x81d go/types.(*Checker).checkFiles(0xc4200ce1c0, 0xc42018b600, 0x8, 0x8, 0x0, 0x0)
    /usr/local/go/src/go/types/check.go:225 +0xaa go/types.(*Checker).Files(0xc4200ce1c0, 0xc42018b600, 0x8, 0x8, 0xc420199800, 0xc4200e3960)
    /usr/local/go/src/go/types/check.go:218 +0x49 go/types.(*Config).Check(0xc420193cc0, 0xc420079667, 0x7, 0xc420095c00, 0xc42018b600, 0x8, 0x8, 0xc420194b40, 0x45e4b0, 0x0, ...)
    /usr/local/go/src/go/types/api.go:344 +0x19f main.(*Package).check(0xc420076a80, 0xc420095c00, 0xc42018b600, 0x8, 0x8, 0x0, 0xc4200b9980)
    /usr/local/go/src/cmd/vet/types.go:76 +0x36c main.doPackage(0x2b769c, 0x1, 0xc420098010, 0x8, 0x8, 0x0)
    /usr/local/go/src/cmd/vet/main.go:333 +0x992 main.main()
    /usr/local/go/src/cmd/vet/main.go:241 +0x335 exit status 2 panic: inconsistent import:
    func errors.New(text string) error previously imported as:
    func errors.New(text string) error  [recovered]
    panic: inconsistent import:
    func errors.New(text string) error previously imported as:
    func errors.New(text string) error


goroutine 1 [running]: panic(0x25f720, 0xc4203f73c0)
    /usr/local/go/src/runtime/panic.go:500 +0x1a1 go/types.(*Checker).handleBailout(0xc4200b61c0, 0xc4200c98e8)
    /usr/local/go/src/go/types/check.go:213 +0xae panic(0x25f720, 0xc4203f73c0)
    /usr/local/go/src/runtime/panic.go:458 +0x243 go/internal/gcimporter.(*importer).declare(0xc4204b60c0, 0x3d7ea0, 0xc4203fe460)
    /usr/local/go/src/go/internal/gcimporter/bimport.go:173 +0x17c go/internal/gcimporter.(*importer).obj(0xc4204b60c0, 0xfffffffffffffffb)
    /usr/local/go/src/go/internal/gcimporter/bimport.go:201 +0x49d go/internal/gcimporter.BImportData(0xc420014ea0, 0xc420406000, 0xb62, 0xe00, 0xc420169771, 0x6, 0x0, 0x6, 0x10, 0x10)
    /usr/local/go/src/go/internal/gcimporter/bimport.go:86 +0x34c go/internal/gcimporter.Import(0xc420014ea0, 0xc420169771, 0x6, 0x7fff5fbff5f0, 0x5, 0xc420430f00, 0x0, 0x0)
    /usr/local/go/src/go/internal/gcimporter/gcimporter.go:166 +0x551 go/importer.gcimports.ImportFrom(0xc420014ea0, 0xc420169771, 0x6, 0x7fff5fbff5f0, 0x5, 0x0, 0x1, 0x2, 0x0)
    /usr/local/go/src/go/importer/importer.go:70 +0x67 go/types.(*Checker).collectObjects(0xc4200b61c0)
    /usr/local/go/src/go/types/resolver.go:191 +0x81d go/types.(*Checker).checkFiles(0xc4200b61c0, 0xc42017df00, 0x4, 0x4, 0x0, 0x0)
    /usr/local/go/src/go/types/check.go:225 +0xaa go/types.(*Checker).Files(0xc4200b61c0, 0xc42017df00, 0x4, 0x4, 0xc420192360, 0xc4200c9960)
    /usr/local/go/src/go/types/check.go:218 +0x49 go/types.(*Config).Check(0xc42018b700, 0xc420017837, 0x5, 0xc420013e80, 0xc42017df00, 0x4, 0x4, 0xc42017fdb0, 0x45e000, 0x0, ...)
    /usr/local/go/src/go/types/api.go:344 +0x19f main.(*Package).check(0xc42001a960, 0xc420013e80, 0xc42017df00, 0x4, 0x4, 0x0, 0xc420011880)
    /usr/local/go/src/cmd/vet/types.go:76 +0x36c main.doPackage(0x2b769c, 0x1, 0xc42000a1a0, 0x4, 0x4, 0x0)
    /usr/local/go/src/cmd/vet/main.go:333 +0x992 main.main()
    /usr/local/go/src/cmd/vet/main.go:241 +0x335 exit status 2

请帮我翻译这段内容。

英文:

When I run go vet ./..., I am go vet is panicking with following output:

% go version 
go version go1.6.2 darwin/amd64 
% go vet ./... 
% go version 
go version go1.7beta1 darwin/amd64 
% go vet ./... panic: inconsistent import:
    var crypto/rand.Reader io.Reader previously imported as:
    var Reader io.Reader  [recovered]
    panic: inconsistent import:
    var crypto/rand.Reader io.Reader previously imported as:
    var Reader io.Reader


goroutine 1 [running]: panic(0x25f720, 0xc4203fc1f0)
    /usr/local/go/src/runtime/panic.go:500 +0x1a1 go/types.(*Checker).handleBailout(0xc4200b61c0, 0xc4200c78e8)
    /usr/local/go/src/go/types/check.go:213 +0xae panic(0x25f720, 0xc4203fc1f0)
    /usr/local/go/src/runtime/panic.go:458 +0x243 go/internal/gcimporter.(*importer).declare(0xc42008e000, 0x3d81c0, 0xc4203ea5f0)
    /usr/local/go/src/go/internal/gcimporter/bimport.go:173 +0x17c go/internal/gcimporter.(*importer).obj(0xc42008e000, 0xfffffffffffffffc)
    /usr/local/go/src/go/internal/gcimporter/bimport.go:193 +0x1af go/internal/gcimporter.BImportData(0xc42000af00, 0xc420334000, 0x703e, 0x7e00, 0xc420166a51, 0xb, 0x0, 0xb, 0xc4203f4ff0, 0xc4200c70c8)
    /usr/local/go/src/go/internal/gcimporter/bimport.go:86 +0x34c go/internal/gcimporter.Import(0xc42000af00, 0xc420166a51, 0xb, 0x7fff5fbff610, 0x8, 0xc420320190, 0x0, 0x0)
    /usr/local/go/src/go/internal/gcimporter/gcimporter.go:166 +0x551 go/importer.gcimports.ImportFrom(0xc42000af00, 0xc420166a51, 0xb, 0x7fff5fbff610, 0x8, 0x0, 0xc4202d55e0, 0x0, 0x0)
    /usr/local/go/src/go/importer/importer.go:70 +0x67 go/types.(*Checker).collectObjects(0xc4200b61c0)
    /usr/local/go/src/go/types/resolver.go:191 +0x81d go/types.(*Checker).checkFiles(0xc4200b61c0, 0xc42018b600, 0x2, 0x2, 0x0, 0x0)
    /usr/local/go/src/go/types/check.go:225 +0xaa go/types.(*Checker).Files(0xc4200b61c0, 0xc42018b600, 0x2, 0x2, 0xc420192a80, 0xc4200cb960)
    /usr/local/go/src/go/types/check.go:218 +0x49 go/types.(*Config).Check(0xc42018d9c0, 0xc420015817, 0x5, 0xc420013f00, 0xc42018b600, 0x2, 0x2, 0xc420187400, 0x45e000, 0x0, ...)
    /usr/local/go/src/go/types/api.go:344 +0x19f main.(*Package).check(0xc42001a8a0, 0xc420013f00, 0xc42018b600, 0x2, 0x2, 0xc42018b610, 0x1)
    /usr/local/go/src/cmd/vet/types.go:76 +0x36c main.doPackage(0x2b769c, 0x1, 0xc42000a220, 0x2, 0x2, 0x0)
    /usr/local/go/src/cmd/vet/main.go:333 +0x992 main.main()
    /usr/local/go/src/cmd/vet/main.go:241 +0x335 exit status 2 panic: inconsistent import:
    var time.UTC *time.Location previously imported as:
    var UTC *time.Location  [recovered]
    panic: inconsistent import:
    var time.UTC *time.Location previously imported as:
    var UTC *time.Location


goroutine 1 [running]: panic(0x25f720, 0xc420141b10)
    /usr/local/go/src/runtime/panic.go:500 +0x1a1 go/types.(*Checker).handleBailout(0xc4200ce1c0, 0xc42004b8d8)
    /usr/local/go/src/go/types/check.go:213 +0xae panic(0x25f720, 0xc420141b10)
    /usr/local/go/src/runtime/panic.go:458 +0x243 go/internal/gcimporter.(*importer).declare(0xc4200a2cc0, 0x3d81c0, 0xc4205f6d70)
    /usr/local/go/src/go/internal/gcimporter/bimport.go:173 +0x17c go/internal/gcimporter.(*importer).obj(0xc4200a2cc0, 0xfffffffffffffffc)
    /usr/local/go/src/go/internal/gcimporter/bimport.go:193 +0x1af go/internal/gcimporter.BImportData(0xc42007ae40, 0xc42035a000, 0x3a210, 0x3fe00, 0xc42007995b, 0x4, 0x0, 0x4, 0xc4201392f0, 0xc42004b0b8)
    /usr/local/go/src/go/internal/gcimporter/bimport.go:86 +0x34c go/internal/gcimporter.Import(0xc42007ae40, 0xc42007995b, 0x4, 0x7fff5fbff598, 0x7, 0xc4205b7040, 0x0, 0x0)
    /usr/local/go/src/go/internal/gcimporter/gcimporter.go:166 +0x551 go/importer.gcimports.ImportFrom(0xc42007ae40, 0xc42007995b, 0x4, 0x7fff5fbff598, 0x7, 0x0, 0xc42017ec80, 0x0, 0x0)
    /usr/local/go/src/go/importer/importer.go:70 +0x67 go/types.(*Checker).collectObjects(0xc4200ce1c0)
    /usr/local/go/src/go/types/resolver.go:191 +0x81d go/types.(*Checker).checkFiles(0xc4200ce1c0, 0xc42018b600, 0x8, 0x8, 0x0, 0x0)
    /usr/local/go/src/go/types/check.go:225 +0xaa go/types.(*Checker).Files(0xc4200ce1c0, 0xc42018b600, 0x8, 0x8, 0xc420199800, 0xc4200e3960)
    /usr/local/go/src/go/types/check.go:218 +0x49 go/types.(*Config).Check(0xc420193cc0, 0xc420079667, 0x7, 0xc420095c00, 0xc42018b600, 0x8, 0x8, 0xc420194b40, 0x45e4b0, 0x0, ...)
    /usr/local/go/src/go/types/api.go:344 +0x19f main.(*Package).check(0xc420076a80, 0xc420095c00, 0xc42018b600, 0x8, 0x8, 0x0, 0xc4200b9980)
    /usr/local/go/src/cmd/vet/types.go:76 +0x36c main.doPackage(0x2b769c, 0x1, 0xc420098010, 0x8, 0x8, 0x0)
    /usr/local/go/src/cmd/vet/main.go:333 +0x992 main.main()
    /usr/local/go/src/cmd/vet/main.go:241 +0x335 exit status 2 panic: inconsistent import:
    func errors.New(text string) error previously imported as:
    func errors.New(text string) error  [recovered]
    panic: inconsistent import:
    func errors.New(text string) error previously imported as:
    func errors.New(text string) error


goroutine 1 [running]: panic(0x25f720, 0xc4203f73c0)
    /usr/local/go/src/runtime/panic.go:500 +0x1a1 go/types.(*Checker).handleBailout(0xc4200b61c0, 0xc4200c98e8)
    /usr/local/go/src/go/types/check.go:213 +0xae panic(0x25f720, 0xc4203f73c0)
    /usr/local/go/src/runtime/panic.go:458 +0x243 go/internal/gcimporter.(*importer).declare(0xc4204b60c0, 0x3d7ea0, 0xc4203fe460)
    /usr/local/go/src/go/internal/gcimporter/bimport.go:173 +0x17c go/internal/gcimporter.(*importer).obj(0xc4204b60c0, 0xfffffffffffffffb)
    /usr/local/go/src/go/internal/gcimporter/bimport.go:201 +0x49d go/internal/gcimporter.BImportData(0xc420014ea0, 0xc420406000, 0xb62, 0xe00, 0xc420169771, 0x6, 0x0, 0x6, 0x10, 0x10)
    /usr/local/go/src/go/internal/gcimporter/bimport.go:86 +0x34c go/internal/gcimporter.Import(0xc420014ea0, 0xc420169771, 0x6, 0x7fff5fbff5f0, 0x5, 0xc420430f00, 0x0, 0x0)
    /usr/local/go/src/go/internal/gcimporter/gcimporter.go:166 +0x551 go/importer.gcimports.ImportFrom(0xc420014ea0, 0xc420169771, 0x6, 0x7fff5fbff5f0, 0x5, 0x0, 0x1, 0x2, 0x0)
    /usr/local/go/src/go/importer/importer.go:70 +0x67 go/types.(*Checker).collectObjects(0xc4200b61c0)
    /usr/local/go/src/go/types/resolver.go:191 +0x81d go/types.(*Checker).checkFiles(0xc4200b61c0, 0xc42017df00, 0x4, 0x4, 0x0, 0x0)
    /usr/local/go/src/go/types/check.go:225 +0xaa go/types.(*Checker).Files(0xc4200b61c0, 0xc42017df00, 0x4, 0x4, 0xc420192360, 0xc4200c9960)
    /usr/local/go/src/go/types/check.go:218 +0x49 go/types.(*Config).Check(0xc42018b700, 0xc420017837, 0x5, 0xc420013e80, 0xc42017df00, 0x4, 0x4, 0xc42017fdb0, 0x45e000, 0x0, ...)
    /usr/local/go/src/go/types/api.go:344 +0x19f main.(*Package).check(0xc42001a960, 0xc420013e80, 0xc42017df00, 0x4, 0x4, 0x0, 0xc420011880)
    /usr/local/go/src/cmd/vet/types.go:76 +0x36c main.doPackage(0x2b769c, 0x1, 0xc42000a1a0, 0x4, 0x4, 0x0)
    /usr/local/go/src/cmd/vet/main.go:333 +0x992 main.main()
    /usr/local/go/src/cmd/vet/main.go:241 +0x335 exit status 2

答案1

得分: 3

当升级Go版本后,在$GOPATH/pkg中存在任何不兼容的文件时,就会出现这种情况。清理你的GOPATH/pkg并重新构建可以解决这个问题。

rm -rf $GOPATH/pkg/
go build
go vet ./...
英文:

This happens when there is any incompatible file in the $GOPATH/pkg after upgrading the go version. Clean your GOPATH/pkg and build again to resolve this problem.

rm -rf $GOPATH/pkg/
go build
go vet ./...

huangapple
  • 本文由 发表于 2016年9月6日 13:54:11
  • 转载请务必保留本文链接:https://go.coder-hub.com/39341513.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定