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

Closed
mdempsky opened this issue Dec 30, 2020 · 5 comments
Closed

cmd/compile: method expressions are misprinted #43428

mdempsky opened this issue Dec 30, 2020 · 5 comments
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@mdempsky
Copy link
Member

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 The path to resolution is known, but the work has not been done. label Dec 30, 2020
@mdempsky mdempsky added this to the Go1.17 milestone Dec 30, 2020
@ianlancetaylor
Copy link
Contributor

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

@mdempsky
Copy link
Member Author

@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

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

@gopherbot
Copy link

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>
@mdempsky
Copy link
Member Author

cmd/compile now prints diagnostics using Go syntax for method expressions on dev.regabi.

@golang golang locked and limited conversation to collaborators Jan 18, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

3 participants