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/compile: method expressions are misprinted #43428

Open
mdempsky opened this issue Dec 30, 2020 · 4 comments
Open

cmd/compile: method expressions are misprinted #43428

mdempsky opened this issue Dec 30, 2020 · 4 comments
Labels
Milestone

Comments

@mdempsky
Copy link
Member

@mdempsky mdempsky commented Dec 30, 2020

On the dev.regabi branch, the error message for this source file:

package p

import "bytes"

var x int = (*bytes.Buffer).Len

mentions *bytes.Buffer.Len. That's incorrect: it should be (*bytes.Buffer).Len, as it appears in the source.

(I suspect this is related to the ir/fmt.go changes in 4629f6a. Though it turns out we're printing it incorrectly even on master, where it prints as bytes.(*Buffer).Len.)

/cc @cuonglm

@mdempsky mdempsky added the NeedsFix label Dec 30, 2020
@mdempsky mdempsky added this to the Go1.17 milestone Dec 30, 2020
@ianlancetaylor
Copy link
Contributor

@ianlancetaylor ianlancetaylor commented Dec 30, 2020

We've printed the bytes.(*Buffer).Len version since at least Go 1.1.

@mdempsky
Copy link
Member Author

@mdempsky mdempsky commented Dec 30, 2020

@ianlancetaylor Thanks, that sounds believable. You aren't suggesting cmd/compile should continue printing it incorrectly though, are you?

In case it wasn't clear, the linker symbols used for pointer-receiver methods (including as they appear in runtime stack traces) are unchanged on dev.regabi; and while I believe the parentheses are superfluous there, I don't intend to remove them either. This issue is only about how method expressions are printed in Go-syntax compiler diagnostics, like error messages and -m output.

go/types correctly prints (*bytes.Buffer).Len in its diagnostics.

@gopherbot
Copy link

@gopherbot gopherbot commented Dec 30, 2020

Change https://golang.org/cl/280735 mentions this issue: cmd/compile: increase prec for StarExpr in SelectorExpr

@gopherbot
Copy link

@gopherbot gopherbot commented Dec 31, 2020

Change https://golang.org/cl/280873 mentions this issue: [dev.regabi] cmd/compile: fix printing of method expressions

gopherbot pushed a commit that referenced this issue Dec 31, 2020
OTYPE and OMETHEXPR were missing from OpPrec. So add them with the
same precedences as OT{ARRAY,MAP,STRUCT,etc} and
ODOT{,METH,INTER,etc}, respectively. However, ODEREF (which is also
used for pointer types *T) has a lower precedence than other types, so
pointer types need to be specially handled to assign them their
correct, lower precedence.

Incidentally, this also improves the error messages in issue15055.go,
where we were adding unnecessary parentheses around the types in
conversion expressions.

Thanks to Cuong Manh Le for writing the test cases for #43428.

Fixes #43428.

Change-Id: I57e7979babe3ed9ef8a8b5a2a3745e3737dd785f
Reviewed-on: https://go-review.googlesource.com/c/go/+/280873
Trust: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

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