go/types:不理解在cgo代码中定义的常量

p8ekf7hl  于 6个月前  发布在  Go
关注(0)|答案(6)|浏览(47)

Please answer these questions before submitting your issue. Thanks!

What version of Go are you using ( go version )?

go version go1.9 linux/amd64

Does this issue reproduce with the latest release?

Yes, fails with git tip as well.

What operating system and processor architecture are you using ( go env )?

GOARCH="amd64"

GOBIN=""

GOEXE=""

GOHOSTARCH="amd64"

GOHOSTOS="linux"

GOOS="linux"

GOPATH="/home/travis/gopath"

GORACE=""

GOROOT="/home/travis/.gimme/versions/go1.9.linux.amd64"

GOTOOLDIR="/home/travis/.gimme/versions/go1.9.linux.amd64/pkg/tool/linux_amd64"

GCCGO="gccgo"

CC="gcc"

GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build036482233=/tmp/go-build -gno-record-gcc-switches"

CXX="g++"

CGO_ENABLED="1"

CGO_CFLAGS="-g -O2"

CGO_CPPFLAGS=""

CGO_CXXFLAGS="-g -O2"

CGO_FFLAGS="-g -O2"

CGO_LDFLAGS="-g -O2"

PKG_CONFIG="pkg-config"

What did you do?

100% reproducible. Travis link:
https://travis-ci.org/purpleidea/mgmt/jobs/270103895#L969
(errors are on the subsequent lines)

What did you expect to see?

No failures or a clear reason about what's wrong.

What did you see instead?

gotype fails where it didn't fail in golang 1.8
it would be great to report this as a false positive or to understand what changed between 1.8 and 1.9 that this is an issue.
Thanks!
James

gzszwxb4

gzszwxb41#

关于上游问题的顺便提一下:libvirt/libvirt-go#22

ia2d9nvy

ia2d9nvy2#

@purpleidea,感谢你的报告!很遗憾Go1.9版本已经发布(如果能早点报告就好了),但如果在周期内容易修复的话,这可能是Go1.9.1的一个候选版本。另外,如果你能提取一个可复现的代码片段并粘贴在这里,它可能会有助于更轻松地诊断和修复问题。
/cc @griesemer。

oyjwcjzk

oyjwcjzk3#

它100%容易复现,只需在libvirt包上运行gotype :)如我在travis示例中所见。至于1.9.1版本,那没问题,好主意!

On Thu, Aug 31, 2017 at 3:50 AM, Emmanuel T Odeke ***@***.***> wrote: @purpleidea < [https://github.com/purpleidea](https://github.com/purpleidea) >,感谢你的报告!不幸的是Go1.9已经下水(如果能早点报告这个问题就好了),但也许这可以成为Go1.9.1的一个候选版本,如果在这个周期内很容易修复的话。另外,如果你能提取一个可复现的代码片段并粘贴在这里,可能会有助于更轻松地诊断和修复问题。/cc @griesemer < [https://github.com/griesemer](https://github.com/griesemer) >。—你收到这个邮件是因为有人提到了你。直接回复此邮件,查看GitHub上的#21712(评论)或静音线程< [https://github.com/notifications/unsubscribe-auth/AAIPsyVmxBz7vXtlc5d0XohnoNkCboGEks5sdmXSgaJpZM4PIVh-](https://github.com/notifications/unsubscribe-auth/AAIPsyVmxBz7vXtlc5d0XohnoNkCboGEks5sdmXSgaJpZM4PIVh-) >。
zlhcx6iw

zlhcx6iw4#

1.9版本的主要变化是gotype现在使用了源导入器。您可以尝试使用标志-c=gc运行gotype,看看问题是否得到解决?

92dk7w1h

92dk7w1h5#

这个示例在没有指定 -c=gc 的情况下会失败,并显示以下消息:

main.go:6:22: cannot use sdl.GETEVENT (constant unknown with invalid type) as github.com/veandco/go-sdl2/sdl.EventAction value in argument to sdl.PeepEvents
main.go:6:36: cannot use sdl.FIRSTEVENT (constant unknown with invalid type) as uint32 value in argument to sdl.PeepEvents
main.go:6:52: cannot use sdl.LASTEVENT (constant unknown with invalid type) as uint32 value in argument to sdl.PeepEvents
s1ag04yj

s1ag04yj6#

这里使用go/types与cgo代码的问题。这些天它应该能正常工作吗?
我可以用

> go get -d github.com/veandco/go-sdl2/sdl
> go run ~/go/src/go/types/gotype.go -- foo.go

重现这个问题,其中foo.go是上面提到的文件。它会打印出

foo.go:6:22: cannot use sdl.GETEVENT (constant unknown with invalid type) as github.com/veandco/go-sdl2/sdl.EventAction value in argument to sdl.PeepEvents
foo.go:6:36: cannot use sdl.FIRSTEVENT (constant unknown with invalid type) as uint32 value in argument to sdl.PeepEvents
foo.go:6:52: cannot use sdl.LASTEVENT (constant unknown with invalid type) as uint32 value in argument to sdl.PeepEvents
exit status 2

。常量都是用cgo代码定义的,如下所示:

const (
	GETEVENT  = C.SDL_GETEVENT
)

相关问题