Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

go/types: doesn't understands constants defined in cgo code #21712

Open
purpleidea opened this issue Aug 31, 2017 · 6 comments
Open

go/types: doesn't understands constants defined in cgo code #21712

purpleidea opened this issue Aug 31, 2017 · 6 comments
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@purpleidea
Copy link

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

@purpleidea
Copy link
Author

Upstream issue btw: libvirt/libvirt-go#22

@odeke-em
Copy link
Member

@purpleidea, thanks for the report! Unfortunately the Go1.9 ship has sailed(it would have been nice to report this earlier) but perhaps this could be a candidate for Go1.9.1 if easily fixable within the cycle. Also it might help with easier diagnosis and fixing if you could extract a reproducible code snippet then paste it here.

/cc @griesemer.

@purpleidea
Copy link
Author

purpleidea commented Aug 31, 2017 via email

@griesemer
Copy link
Contributor

The major thing that changed for 1.9 is that gotype now uses a source importer. Can you try to run gotype with the flag -c=gc and see if the problem goes away?

@orivej
Copy link

orivej commented Sep 7, 2017

This example fails the check unless -c=gc is specified:

package main

import "github.com/veandco/go-sdl2/sdl"

func main() {
	sdl.PeepEvents(nil, sdl.GETEVENT, sdl.FIRSTEVENT, sdl.LASTEVENT)
}

with the message

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

@ianlancetaylor
Copy link
Contributor

The problem here is using go/types with cgo code. Is that supposed to work these days?

I can recreate the problem with

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

where foo.go is the file mentioned above. That prints

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

The constants are all defined with cgo code like:

const (
	GETEVENT  = C.SDL_GETEVENT
)

@ianlancetaylor ianlancetaylor added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Mar 29, 2018
@ianlancetaylor ianlancetaylor added this to the Unplanned milestone Mar 29, 2018
@ianlancetaylor ianlancetaylor changed the title Gotype lint error in 1.9 (worked in 1.8) go/types: doesn't understands constants defined in cgo code Mar 29, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

5 participants