diff options
author | Robert Griesemer <gri@golang.org> | 2024-03-13 13:57:08 -0700 |
---|---|---|
committer | Gopher Robot <gobot@golang.org> | 2024-03-18 18:59:40 +0000 |
commit | dc6a5cfca18320ab41af7c5f64565ec2ba303843 (patch) | |
tree | 007ba40652504e5da68f2bc4b21ffef91b47d4a2 /test | |
parent | 2e8d84f148c69404b8eec86d9149785a3f4e3e92 (diff) | |
download | go-dc6a5cfca18320ab41af7c5f64565ec2ba303843.tar.gz go-dc6a5cfca18320ab41af7c5f64565ec2ba303843.zip |
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>
Diffstat (limited to 'test')
-rw-r--r-- | test/fixedbugs/issue11361.go | 2 | ||||
-rw-r--r-- | test/fixedbugs/issue21317.go | 4 | ||||
-rw-r--r-- | test/fixedbugs/issue28268.go | 4 | ||||
-rw-r--r-- | test/fixedbugs/issue34329.go | 2 |
4 files changed, 6 insertions, 6 deletions
diff --git a/test/fixedbugs/issue11361.go b/test/fixedbugs/issue11361.go index 1ef8735a52..84e71c73e6 100644 --- a/test/fixedbugs/issue11361.go +++ b/test/fixedbugs/issue11361.go @@ -8,4 +8,4 @@ package a import "fmt" // GC_ERROR "imported and not used" -const n = fmt // ERROR "fmt without selector|unexpected reference to package|use of package fmt not in selector" +const n = fmt // ERROR "fmt without selector|unexpected reference to package|use of package `fmt' not in selector" diff --git a/test/fixedbugs/issue21317.go b/test/fixedbugs/issue21317.go index cebfc0f52d..d525f12a58 100644 --- a/test/fixedbugs/issue21317.go +++ b/test/fixedbugs/issue21317.go @@ -45,8 +45,8 @@ func main() { log.Fatalf("expected cmd/compile to fail") } wantErrs := []string{ - "7:9: n declared and not used", - "7:12: err declared and not used", + "7:9: `n' declared and not used", + "7:12: `err' declared and not used", } outStr := string(out) for _, want := range wantErrs { diff --git a/test/fixedbugs/issue28268.go b/test/fixedbugs/issue28268.go index 263b2d1b42..b04e42555f 100644 --- a/test/fixedbugs/issue28268.go +++ b/test/fixedbugs/issue28268.go @@ -16,8 +16,8 @@ type T struct { type E struct{} -func (T) b() {} // ERROR "field and method named b|redeclares struct field name|field and method with the same name b" -func (*T) E() {} // ERROR "field and method named E|redeclares struct field name|field and method with the same name E" +func (T) b() {} // ERROR "field and method named b|redeclares struct field name|field and method with the same name `b'" +func (*T) E() {} // ERROR "field and method named E|redeclares struct field name|field and method with the same name `E'" func _() { var x T diff --git a/test/fixedbugs/issue34329.go b/test/fixedbugs/issue34329.go index 790686e3dd..585770d87a 100644 --- a/test/fixedbugs/issue34329.go +++ b/test/fixedbugs/issue34329.go @@ -10,5 +10,5 @@ type I interface { M() } type _ interface { I - I // ERROR "duplicate method M" + I // ERROR "duplicate method `M'" } |