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

x/tools/cmd/stringer: Gets confused with pointers to C.struct_xxx types. #13123

npat-efault opened this issue Nov 1, 2015 · 2 comments


Copy link

@npat-efault npat-efault commented Nov 1, 2015

Save this in foo.go and say:

stringer -type MyT foo.go

Stringer will fail with:

stringer: checking package: foo.go:22:2: invalid operation: pfoo (variable of type *invalid type) has no field or method i

Stringer works ok with this, though:

Another similar program that triggers the same behavior (stringer failure) is this:

Copy link

@dmitshur dmitshur commented Nov 1, 2015

Your program uses cgo. I wasn't sure if stringer officially supported use of cgo or not.

I looked at the source code and I didn't see any "TODO" or similar mentions regarding importing package "C", so it seems it might be supported. The .go files that import "C" are indeed processed (e.g., see here), but that's the only special thing being done.

I guess my point is that it should first be confirmed that the tool is meant to support cgo at this time. If so, this is likely a problem with it (since I imagine it's a situation that's less common and therefore more poorly tested).

@ianlancetaylor ianlancetaylor added this to the Unreleased milestone Nov 2, 2015
Copy link

@adonovan adonovan commented Nov 4, 2015

stringer doesn't support cgo. It makes the simplifying assumptions that the initial package consists only of Go source files and that dependencies can be loaded from compiler export data (e.g. $GOROOT/pkg/$GOOS_$GOARCH/fmt.a).


This issue is more or less a duplicate of "stringer: can't find packages" (#10249). Josh closed it and filed the broader issue "go/loader: importers should just work" (#10276). I closed that after some changes to go/loader; in passing, I created a CL to make stringer use go/loader ( but it was rejected by Rob "until go/loader is tidied up". go/loader could use more tidying up, though I won't be able to get to this for a while. In the meantime, stringer still has this bug.

@gopherbot gopherbot added the Tools label Sep 12, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
5 participants
You can’t perform that action at this time.