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/printer: hmac gofix mishandles comments #2750

Closed
rsc opened this issue Jan 20, 2012 · 7 comments
Closed

go/printer: hmac gofix mishandles comments #2750

rsc opened this issue Jan 20, 2012 · 7 comments
Milestone

Comments

@rsc
Copy link
Contributor

rsc commented Jan 20, 2012

$ cat x.go
package main

import "crypto/hmac"

func main() {
    hmac.NewMD5(nil)  // foo
}
$ gofix x.go
x.go:9:2: expected 1 expression
x.go:10:7: expected statement, found ')'
$ 

Don't know whether it is specific to the hmac fix
or a bug in the printer.  Probably the latter, sigh.
@Luit
Copy link

Luit commented Jan 20, 2012

Comment 1:

Weird... Is the way it's rewriting the CallExpr.Args field wrong?

@Luit
Copy link

Luit commented Jan 20, 2012

Comment 2:

Hold on, the comment triggers this? How? I'm not touching that with a 10-foot pole...

@Luit
Copy link

Luit commented Jan 20, 2012

Comment 3:

Is token location information somehow not invalidated or ignored? This is interesting
output too by the way: 
$ cat x.go 
package main
import "crypto/hmac"
func main() {
    go hmac.NewMD5(nil)  // foo
}
$ gofix x.go 
x.go:9:22: expected ')', found newline
x.go:10:2: expected ';', found ','
Note the "go". I'm completely in the dark on this one... I wrote that gofix, but I have
only very basic understanding of AST and it's parser/printer.

@rsc
Copy link
Contributor Author

rsc commented Jan 20, 2012

Comment 4:

The way to debug this would be to add the test case to
the gofix tests and then put some prints in
src/cmd/gofix/main_test.go's parseFixPrint to
see what the intermediate printing output is.
It will have put the // in the wrong place.
I believe Robert is working on getting //'s into
only right places, so this issue will probably
resolve when that gets fixed.

@rsc
Copy link
Contributor Author

rsc commented Jan 24, 2012

Comment 6:

Labels changed: added priority-go1, removed priority-asap.

@griesemer
Copy link
Contributor

Comment 7:

go/printer incorrectly reformats the gofix-ed program (the comment has incorrect
position information) and the rewritten program looks like:
package main
import (
    "crypto/hmac"
    "crypto/md5"
)
func main() {
    hmac.New(md5.New // foo
    , nil)
}
which is clearly incorrect:
x.go:9:2: expected 1 expression
x.go:10:7: expected statement, found ')'
This is a duplicate of issue #1505.

@griesemer
Copy link
Contributor

Comment 8:

Owner changed to @griesemer.

Status changed to Duplicate.

Merged into issue #1505.

@rsc rsc added this to the Go1 milestone Apr 10, 2015
@rsc rsc removed the priority-go1 label Apr 10, 2015
@golang golang locked and limited conversation to collaborators Jun 24, 2016
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants