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

cmd/go: go generate confounded by errors in generated code #16307

Closed
monotrememan42 opened this issue Jul 8, 2016 · 10 comments
Closed

cmd/go: go generate confounded by errors in generated code #16307

monotrememan42 opened this issue Jul 8, 2016 · 10 comments
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@monotrememan42
Copy link

Please answer these questions before submitting your issue. Thanks!

  1. What version of Go are you using (go version)?
    go version go1.6.2 darwin/amd64
  2. What operating system and processor architecture are you using (go env)?
    GOARCH="amd64"
    GOBIN=""
    GOEXE=""
    GOHOSTARCH="amd64"
    GOHOSTOS="darwin"
    GOOS="darwin"
    GOPATH="/Users/andrew/code/myriad"
    GORACE=""
    GOROOT="/usr/local/go"
    GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
    GO15VENDOREXPERIMENT="1"
    CC="clang"
    GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fno-common"
    CXX="clang++"
    CGO_ENABLED="1"
  3. What did you do?
    Unfortunately, this error requires multiple files to reproduce. the description should suffice, tho.

i use yacc and nex as part of a package. the generated code lives in another package
(so that generated code is not mixed in with source-controlled code).
occasionally, a mistake is made in my parse.y so that the generated parse.go causes an import cycle.
at this point, i can't simply correct parse.y (to not have the import cycle), because go generate
won't run the generate commands because (apparently) it processes the import directives first.

i observe that "go generate --help" says, in part,
Note that go generate does not parse the file, so lines that look
like directives in comments or multiline strings will be treated
as directives.

  1. What did you expect to see?
    i would expect go generate to run the command and not worry about an import cycle.
  2. What did you see instead?
    go generate determines (correctly but irrelevantly) that there is an import cycle and does not run the generate commands.
@ianlancetaylor ianlancetaylor changed the title go generate confounded by errors in generated code cmd/go: go generate confounded by errors in generated code Jul 9, 2016
@ianlancetaylor
Copy link
Contributor

What is the exact command that you run? What is the exact error that you see?

@ianlancetaylor ianlancetaylor added this to the Go1.8 milestone Jul 9, 2016
@ianlancetaylor
Copy link
Contributor

Note that we are likely to need a small test case in order to fix this. Unfortunate experience shows that it is very hard to recreate a specific problem from a text description.

@cznic
Copy link
Contributor

cznic commented Jul 9, 2016

@monotrememan42 go generate does not seem to parse go source files.

Do your go generate lines (the magic comments) invoke, for example, stringer or any other tool that needs the package to be compiled?

Sometimes it might help to "reset" the parser.go file before doing other things, like

//go:generate echo "package foo" > parser.go
//...
//go:generate go tool yacc -o parser.go parser.y

or

// Start with the last known good parser.go
//go:generate git checkout -f parser.go
//...
//go:generate go tool yacc -o parser.go parser.y

@monotrememan42
Copy link
Author

the first few lines of the source file are

//go:generate nex -p Parse -e -o ../../gen/rivegen/lexer.go lexer.nex
//go:generate go tool yacc -p Parse -o ../../gen/rivegen/parse.go parse.y
//go:generate mv y.output ../../gen/rivegen

package rive

i am working on getting a small reproducible example for you; i think i can do it in 2-3 files.
i’ll send a zipped tar file. when i do.

On Jul 9, 2016, at 6:29 AM, cznic notifications@github.com wrote:

@monotrememan42 https://github.com/monotrememan42 go generate does not seem https://github.com/golang/go/blob/57e459e02b4b01567f92542f92cd9afde209e193/src/cmd/go/generate.go to parse go source files.

Do your go generate lines (the magic comments) invoke, for example, stringer or any other tool that needs the package to be compiled?

Sometimes it might help to "reset" the parser.go file before doing other things, like

//go:generate echo "package foo" > parser.go
//...
//go:generate go tool yacc -o parser.go parser.y
or

// Start with the last known good parser.go
//go:generate git checkout -f parser.go
//...
//go:generate go tool yacc -o parser.go parser.y

You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub #16307 (comment), or mute the thread https://github.com/notifications/unsubscribe/AJ8JQKZFTffF4NsrUhW4I2eRgwdOImRGks5qT6IsgaJpZM4JId2b.

@monotrememan42
Copy link
Author

attached is a small tar file that contains a reproducible example.
there is a script.out file that shows the bug.
sorry i did not include this originally.

andrew

On Jul 8, 2016, at 6:36 PM, Ian Lance Taylor notifications@github.com wrote:

Note that we are likely to need a small test case in order to fix this. Unfortunate experience shows that it is very hard to recreate a specific problem from a text description.


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub #16307 (comment), or mute the thread https://github.com/notifications/unsubscribe/AJ8JQGaHjT2gexzinDdo2BxDoYP1b9-Aks5qTvsAgaJpZM4JId2b.

@monotrememan42
Copy link
Author

did the attached tar file make it? i don't see it here. i'll attach it again just in case.
ohhh, stupid system doesn't support tar but doesn't tell you (when submitting by email).
lovely. here is the same stuff in a zip file.
go16307.zip

@monotrememan42
Copy link
Author

i added the test case to reproduce

On Jul 8, 2016, at 6:36 PM, Ian Lance Taylor notifications@github.com wrote:

Note that we are likely to need a small test case in order to fix this. Unfortunate experience shows that it is very hard to recreate a specific problem from a text description.


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub #16307 (comment), or mute the thread https://github.com/notifications/unsubscribe/AJ8JQGaHjT2gexzinDdo2BxDoYP1b9-Aks5qTvsAgaJpZM4JId2b.

@monotrememan42
Copy link
Author

i'm not trying to annoy anyone, but i wanted to ensure someone had gotten the test cases etc. can someone please speak to that? thanks.

@cznic
Copy link
Contributor

cznic commented Jul 22, 2016

With some modifications I was able to reproduce the problem. I didn't investigate more. I'd look for go/types interfering when go generate is invoked, shooting in the dark, of course.

@quentinmit quentinmit added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Oct 6, 2016
@gopherbot
Copy link

CL https://golang.org/cl/31659 mentions this issue.

@golang golang locked and limited conversation to collaborators Oct 24, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge 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