]> Cypherpunks repositories - gostls13.git/commit
go/types, types2: quote user-supplied names in error messages
authorRobert Griesemer <gri@golang.org>
Wed, 13 Mar 2024 20:57:08 +0000 (13:57 -0700)
committerGopher Robot <gobot@golang.org>
Mon, 18 Mar 2024 18:59:40 +0000 (18:59 +0000)
commitdc6a5cfca18320ab41af7c5f64565ec2ba303843
tree007ba40652504e5da68f2bc4b21ffef91b47d4a2
parent2e8d84f148c69404b8eec86d9149785a3f4e3e92
go/types, types2: quote user-supplied names in error messages

Use `' quotes (as in `foo') to differentiate from Go quotes.
Quoting prevents confusion when user-supplied names alter
the meaning of the error message.

For instance, report

        duplicate method `wanted'

rather than

        duplicate method wanted

Exceptions:
- don't quote _:
        `_' is ugly and not necessary
- don't quote after a ":":
        undefined name: foo
- don't quote if the name is used correctly in a statement:
        goto L jumps over variable declaration

Quoting is done with a helper function and can be centrally adjusted
and fine-tuned as needed.

Adjusted some test cases to explicitly include the quoted names.

Fixes #65790.

Change-Id: Icce667215f303ab8685d3e5cb00d540a2fd372ca
Reviewed-on: https://go-review.googlesource.com/c/go/+/571396
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
Run-TryBot: Emmanuel Odeke <emmanuel@orijtech.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Robert Griesemer <gri@google.com>
33 files changed:
src/cmd/compile/internal/types2/builtins.go
src/cmd/compile/internal/types2/call.go
src/cmd/compile/internal/types2/check.go
src/cmd/compile/internal/types2/decl.go
src/cmd/compile/internal/types2/format.go
src/cmd/compile/internal/types2/issues_test.go
src/cmd/compile/internal/types2/labels.go
src/cmd/compile/internal/types2/stmt.go
src/cmd/compile/internal/types2/typeset.go
src/cmd/compile/internal/types2/typexpr.go
src/go/types/builtins.go
src/go/types/call.go
src/go/types/check.go
src/go/types/decl.go
src/go/types/format.go
src/go/types/issues_test.go
src/go/types/labels.go
src/go/types/stmt.go
src/go/types/typeset.go
src/go/types/typexpr.go
src/internal/types/testdata/check/builtins0.go
src/internal/types/testdata/check/decls0.go
src/internal/types/testdata/check/decls2/decls2a.go
src/internal/types/testdata/check/go1_13.go
src/internal/types/testdata/check/importdecl0/importdecl0a.go
src/internal/types/testdata/check/labels.go
src/internal/types/testdata/check/stmt0.go
src/internal/types/testdata/fixedbugs/issue50779.go
src/internal/types/testdata/fixedbugs/issue66285.go
test/fixedbugs/issue11361.go
test/fixedbugs/issue21317.go
test/fixedbugs/issue28268.go
test/fixedbugs/issue34329.go