]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: remove quoting in favor of clearer prose in error messages
authorRobert Griesemer <gri@golang.org>
Wed, 29 May 2024 21:19:14 +0000 (14:19 -0700)
committerGopher Robot <gobot@golang.org>
Thu, 30 May 2024 19:19:55 +0000 (19:19 +0000)
In an attempt to address issue #65790 (confusing error messages),
quoting of names was introduced for some (but not all) names used
in error messages.

That CL solved the issue at hand at the cost of extra punctuation
(the quotes) plus some inconsistency (not all names were quoted).

This CL removes the quoting again in favor or adding a qualifying noun
(such as "name", "label", "package", "built-in" etc.) before a user-
specified name where needed.

For instance, instead of

        invalid argument to `max'

we now say

        invalid argument to built-in max

There's still a chance for confusion. For instance, before an error
might have been

        `sadly' not exported by package X

and now it would be

        name sadly not exported by package X

but adverbs (such as "sadly") seem unlikely names in programs.

This change touches a lot of files but only affects error messages.

Fixes #67685.

Change-Id: I95435b388f92cade316e2844d59ecf6953b178bc
Reviewed-on: https://go-review.googlesource.com/c/go/+/589118
Auto-Submit: Robert Griesemer <gri@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Robert Findley <rfindley@google.com>
Reviewed-by: Robert Griesemer <gri@google.com>
42 files changed:
src/cmd/compile/internal/syntax/parser.go
src/cmd/compile/internal/syntax/testdata/issue20789.go
src/cmd/compile/internal/syntax/testdata/issue47704.go
src/cmd/compile/internal/syntax/testdata/issue49205.go
src/cmd/compile/internal/syntax/testdata/issue52391.go
src/cmd/compile/internal/syntax/testdata/issue65790.go
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/issue20789.go
test/fixedbugs/issue21317.go
test/fixedbugs/issue23664.go
test/fixedbugs/issue28268.go
test/fixedbugs/issue29870b.go
test/fixedbugs/issue34329.go

index f75f86587a658d42af3e96a6085e44304a19549a..66570fe92a823bb2993c4a786cca2be7cb3e97f2 100644 (file)
@@ -268,7 +268,7 @@ func (p *parser) syntaxErrorAt(pos Pos, msg string) {
        var tok string
        switch p.tok {
        case _Name:
-               tok = "`" + p.lit + "'"
+               tok = "name " + p.lit
        case _Semi:
                tok = p.lit
        case _Literal:
index 8a6db6d2ee0b81a08f11c85c64f5c31ef7e9a8c4..846da836946fca3275607f33480970ef8309617b 100644 (file)
@@ -6,4 +6,4 @@
 // Line 9 must end in EOF for this test (no newline).
 
 package e
-func([<-chan<-[func /* ERROR unexpected `u' */ u){go
\ No newline at end of file
+func([<-chan<-[func /* ERROR unexpected name u */ u){go
\ No newline at end of file
index aab37905607c40aae3e6dc3cdc5a960c7d33568a..e490130db0b516943282a27ad2419bed361df5e9 100644 (file)
@@ -7,7 +7,7 @@ package p
 func _() {
        _ = m[] // ERROR expected operand
        _ = m[x,]
-       _ = m[x /* ERROR unexpected `a' */ a b c d]
+       _ = m[x /* ERROR unexpected name a */ a b c d]
 }
 
 // test case from the issue
index 9b6c76970380c0f8aa2871256075ac852c0f6282..891a6eeb8313ff723daccdbc3add145ecfd975c2 100644 (file)
@@ -7,7 +7,7 @@ package p
 // test case from issue
 
 type _ interface{
-       m /* ERROR unexpected `int' in interface type; possibly missing semicolon or newline or } */ int
+       m /* ERROR unexpected name int in interface type; possibly missing semicolon or newline or } */ int
 }
 
 // other cases where the fix for this issue affects the error message
@@ -16,12 +16,12 @@ const (
        x int = 10 /* ERROR unexpected literal "foo" in grouped declaration; possibly missing semicolon or newline or \) */ "foo"
 )
 
-var _ = []int{1, 2, 3 /* ERROR unexpected `int' in composite literal; possibly missing comma or } */ int }
+var _ = []int{1, 2, 3 /* ERROR unexpected name int in composite literal; possibly missing comma or } */ int }
 
 type _ struct {
        x y /* ERROR syntax error: unexpected comma in struct type; possibly missing semicolon or newline or } */ ,
 }
 
-func f(a, b c /* ERROR unexpected `d' in parameter list; possibly missing comma or \) */ d) {
-       f(a, b, c /* ERROR unexpected `d' in argument list; possibly missing comma or \) */ d)
+func f(a, b c /* ERROR unexpected name d in parameter list; possibly missing comma or \) */ d) {
+       f(a, b, c /* ERROR unexpected name d in argument list; possibly missing comma or \) */ d)
 }
index 42b71cc83a315a9bc02c31711fad968b42a0affa..85c080c9e6cef67513e1e32311f4268d3d0c9327 100644 (file)
@@ -13,5 +13,5 @@ type _ interface {
        (int) | (string)
        (int) | ~(string)
        (/* ERROR unexpected ~ */ ~int)
-       (int /* ERROR unexpected \| */ | /* ERROR unexpected `string' */ string /* ERROR unexpected \) */ )
+       (int /* ERROR unexpected \| */ | /* ERROR unexpected name string */ string /* ERROR unexpected \) */ )
 }
index 07ffd1267849be4570f69b33b3a73f3c0802416c..9e079423ab6bf2101c062ff6653b3e1f9160b7df 100644 (file)
@@ -9,6 +9,6 @@ import (
 )
 
 func f() {
-       int status // ERROR syntax error: unexpected `status' at end of statement
+       int status // ERROR syntax error: unexpected name status at end of statement
        fmt.Println(status)
 }
index d176cf0967c9f6cbca51c92f8027a66fa7e3dfc3..808d39fd2422f92204a0042e1aadf27808e38b3e 100644 (file)
@@ -25,7 +25,7 @@ func (check *Checker) builtin(x *operand, call *syntax.CallExpr, id builtinId) (
        if hasDots(call) && id != _Append {
                check.errorf(dddErrPos(call),
                        InvalidDotDotDot,
-                       invalidOp+"invalid use of ... with built-in %s", quote(bin.name))
+                       invalidOp+"invalid use of ... with built-in %s", bin.name)
                check.use(argList...)
                return
        }
@@ -210,7 +210,7 @@ func (check *Checker) builtin(x *operand, call *syntax.CallExpr, id builtinId) (
                                if id == _Len {
                                        code = InvalidLen
                                }
-                               check.errorf(x, code, invalidArg+"%s for %s", x, quote(bin.name))
+                               check.errorf(x, code, invalidArg+"%s for built-in %s", x, bin.name)
                        }
                        return
                }
@@ -533,7 +533,7 @@ func (check *Checker) builtin(x *operand, call *syntax.CallExpr, id builtinId) (
        case _Max, _Min:
                // max(x, ...)
                // min(x, ...)
-               check.verifyVersionf(call.Fun, go1_21, "%s", quote(bin.name))
+               check.verifyVersionf(call.Fun, go1_21, "built-in %s", bin.name)
 
                op := token.LSS
                if id == _Max {
@@ -576,7 +576,7 @@ func (check *Checker) builtin(x *operand, call *syntax.CallExpr, id builtinId) (
                if x.mode != constant_ {
                        x.mode = value
                        // A value must not be untyped.
-                       check.assignment(x, &emptyInterface, "argument to "+quote(bin.name))
+                       check.assignment(x, &emptyInterface, "argument to built-in "+bin.name)
                        if x.mode == invalid {
                                return
                        }
@@ -641,7 +641,7 @@ func (check *Checker) builtin(x *operand, call *syntax.CallExpr, id builtinId) (
                if nargs > 0 {
                        params = make([]Type, nargs)
                        for i, a := range args {
-                               check.assignment(a, nil, "argument to "+quote(predeclaredFuncs[id].name))
+                               check.assignment(a, nil, "argument to built-in"+predeclaredFuncs[id].name)
                                if a.mode == invalid {
                                        return
                                }
@@ -992,7 +992,7 @@ func (check *Checker) applyTypeFunc(f func(Type) Type, x *operand, id builtinId)
                default:
                        panic("unreachable")
                }
-               check.softErrorf(x, code, "%s not supported as argument to %s for go1.18 (see go.dev/issue/50937)", x, quote(predeclaredFuncs[id].name))
+               check.softErrorf(x, code, "%s not supported as argument to built-in %s for go1.18 (see go.dev/issue/50937)", x, predeclaredFuncs[id].name)
 
                // Construct a suitable new type parameter for the result type.
                // The type parameter is placed in the current package so export/import
index ca9772ff41df93669e29dac30086365c4bd248c1..7df4e8250e4dcd8c60812693cba3debd339ca663 100644 (file)
@@ -719,7 +719,7 @@ func (check *Checker) selector(x *operand, e *syntax.SelectorExpr, def *TypeName
                                        goto Error
                                }
                                if !exp.Exported() {
-                                       check.errorf(e.Sel, UnexportedName, "%s not exported by package %s", quote(sel), quote(pkg.name))
+                                       check.errorf(e.Sel, UnexportedName, "name %s not exported by package %s", sel, pkg.name)
                                        // ok to continue
                                }
                        }
index 3bb28b46b4e78a7773ed8b326fa920524120f9c5..91ad474e9df3158b5dc9f2b538b6dff595afa2d0 100644 (file)
@@ -310,7 +310,7 @@ func (check *Checker) initFiles(files []*syntax.File) {
                        check.files = append(check.files, file)
 
                default:
-                       check.errorf(file, MismatchedPkgName, "package %s; expected %s", quote(name), quote(pkg.name))
+                       check.errorf(file, MismatchedPkgName, "package %s; expected package %s", name, pkg.name)
                        // ignore this file
                }
        }
index 08c186ed0aba6931fce2075cb74f03d2ec381de9..6a266de7fd99ab357577e4fa5bff9499ca49be95 100644 (file)
@@ -743,7 +743,7 @@ func (check *Checker) checkFieldUniqueness(base *Named) {
                                        // For historical consistency, we report the primary error on the
                                        // method, and the alt decl on the field.
                                        err := check.newError(DuplicateFieldAndMethod)
-                                       err.addf(alt, "field and method with the same name %s", quote(fld.name))
+                                       err.addf(alt, "field and method with the same name %s", fld.name)
                                        err.addAltDecl(fld)
                                        err.report()
                                }
index 1b9cf606b7771ce53bc42af2df945f863eb528c5..442d219d1afa5793eaac77d745e9991495b0de34 100644 (file)
@@ -14,39 +14,6 @@ import (
        "strings"
 )
 
-// quote encloses s in `' quotes, as in `foo', except for _,
-// which is left alone.
-//
-// Use to prevent confusion when user supplied names alter the
-// meaning of an 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 ":" as there's no need for it:
-//     undefined name: foo
-//   - don't quote if the name is used correctly in a statement:
-//     goto L jumps over variable declaration
-//
-// quote encloses s in `' quotes, as in `foo',
-// except for _ which is left alone.
-func quote(s string) string {
-       if s == "_" {
-               // `_' is ugly and not necessary
-               return s
-       }
-       return "`" + s + "'"
-}
-
 func sprintf(qf Qualifier, tpSubscripts bool, format string, args ...any) string {
        for i, arg := range args {
                switch a := arg.(type) {
index 3d500811d4a67a0b51fa72296cb7296a6c25700b..b4da3c0b915befae020440c5250d9cb23c9d859e 100644 (file)
@@ -258,11 +258,11 @@ func TestIssue22525(t *testing.T) {
        conf := Config{Error: func(err error) { got += err.Error() + "\n" }}
        typecheck(src, &conf, nil) // do not crash
        want := "\n" +
-               "p:1:27: `a' declared and not used\n" +
-               "p:1:30: `b' declared and not used\n" +
-               "p:1:33: `c' declared and not used\n" +
-               "p:1:36: `d' declared and not used\n" +
-               "p:1:39: `e' declared and not used\n"
+               "p:1:27: declared and not used: a\n" +
+               "p:1:30: declared and not used: b\n" +
+               "p:1:33: declared and not used: c\n" +
+               "p:1:36: declared and not used: d\n" +
+               "p:1:39: declared and not used: e\n"
        if got != want {
                t.Errorf("got: %swant: %s", got, want)
        }
index 61b3ca7511e9a1b4da7d45d4cfa8896af95ceff4..548df7925b101d5a7b2d719bb5e9225a93ec6cae 100644 (file)
@@ -26,13 +26,11 @@ func (check *Checker) labels(body *syntax.BlockStmt) {
                name := jmp.Label.Value
                if alt := all.Lookup(name); alt != nil {
                        msg = "goto %s jumps into block"
-                       alt.(*Label).used = true // avoid another error
                        code = JumpIntoBlock
-                       // don't quote name here because "goto L" matches the code
+                       alt.(*Label).used = true // avoid another error
                } else {
                        msg = "label %s not declared"
                        code = UndeclaredLabel
-                       name = quote(name)
                }
                check.errorf(jmp.Label, code, msg, name)
        }
@@ -41,7 +39,7 @@ func (check *Checker) labels(body *syntax.BlockStmt) {
        for name, obj := range all.elems {
                obj = resolve(name, obj)
                if lbl := obj.(*Label); !lbl.used {
-                       check.softErrorf(lbl.pos, UnusedLabel, "label %s declared and not used", quote(lbl.name))
+                       check.softErrorf(lbl.pos, UnusedLabel, "label %s declared and not used", lbl.name)
                }
        }
 }
@@ -137,7 +135,7 @@ func (check *Checker) blockBranches(all *Scope, parent *block, lstmt *syntax.Lab
                                if alt := all.Insert(lbl); alt != nil {
                                        err := check.newError(DuplicateLabel)
                                        err.soft = true
-                                       err.addf(lbl.pos, "label %s already declared", quote(name))
+                                       err.addf(lbl.pos, "label %s already declared", name)
                                        err.addAltDecl(alt)
                                        err.report()
                                        // ok to continue
@@ -193,7 +191,7 @@ func (check *Checker) blockBranches(all *Scope, parent *block, lstmt *syntax.Lab
                                        }
                                }
                                if !valid {
-                                       check.errorf(s.Label, MisplacedLabel, "invalid break label %s", quote(name))
+                                       check.errorf(s.Label, MisplacedLabel, "invalid break label %s", name)
                                        return
                                }
 
@@ -208,7 +206,7 @@ func (check *Checker) blockBranches(all *Scope, parent *block, lstmt *syntax.Lab
                                        }
                                }
                                if !valid {
-                                       check.errorf(s.Label, MisplacedLabel, "invalid continue label %s", quote(name))
+                                       check.errorf(s.Label, MisplacedLabel, "invalid continue label %s", name)
                                        return
                                }
 
index 655d072171cb49e365d16c90ff404977dd7d1ebc..656f0e2eb2bc2868a6cca562a9839e3c0bf1b2fc 100644 (file)
@@ -64,7 +64,7 @@ func (check *Checker) usage(scope *Scope) {
                return cmpPos(unused[i].pos, unused[j].pos) < 0
        })
        for _, v := range unused {
-               check.softErrorf(v.pos, UnusedVar, "%s declared and not used", quote(v.name))
+               check.softErrorf(v.pos, UnusedVar, "declared and not used: %s", v.name)
        }
 
        for _, scope := range scope.children {
@@ -496,7 +496,7 @@ func (check *Checker) stmt(ctxt stmtContext, s syntax.Stmt) {
                        for _, obj := range res.vars {
                                if alt := check.lookup(obj.name); alt != nil && alt != obj {
                                        err := check.newError(OutOfScopeResult)
-                                       err.addf(s, "result parameter %s not in scope at return", quote(obj.name))
+                                       err.addf(s, "result parameter %s not in scope at return", obj.name)
                                        err.addf(alt, "inner declaration of %s", obj)
                                        err.report()
                                        // ok to continue
index 2ce586e7a7eca62b99ac5b6fb47f09bd2571540f..0457502e393942f313465603d408ef28da126650 100644 (file)
@@ -226,8 +226,8 @@ func computeInterfaceTypeSet(check *Checker, pos syntax.Pos, ityp *Interface) *_
                case explicit:
                        if check != nil {
                                err := check.newError(DuplicateDecl)
-                               err.addf(atPos(pos), "duplicate method %s", quote(m.name))
-                               err.addf(atPos(mpos[other.(*Func)]), "other declaration of %s", quote(m.name))
+                               err.addf(atPos(pos), "duplicate method %s", m.name)
+                               err.addf(atPos(mpos[other.(*Func)]), "other declaration of method %s", m.name)
                                err.report()
                        }
                default:
@@ -240,8 +240,8 @@ func computeInterfaceTypeSet(check *Checker, pos syntax.Pos, ityp *Interface) *_
                                check.later(func() {
                                        if pos.IsKnown() && !check.allowVersion(atPos(pos), go1_14) || !Identical(m.typ, other.Type()) {
                                                err := check.newError(DuplicateDecl)
-                                               err.addf(atPos(pos), "duplicate method %s", quote(m.name))
-                                               err.addf(atPos(mpos[other.(*Func)]), "other declaration of %s", quote(m.name))
+                                               err.addf(atPos(pos), "duplicate method %s", m.name)
+                                               err.addf(atPos(mpos[other.(*Func)]), "other declaration of method %s", m.name)
                                                err.report()
                                        }
                                }).describef(atPos(pos), "duplicate method check for %s", m.name)
index eca60ada7b792419cc209c110de16beb4fa99fe0..6c121ae05459595e820f6baaeb33770c8f4cad02 100644 (file)
@@ -95,7 +95,7 @@ func (check *Checker) ident(x *operand, e *syntax.Name, def *TypeName, wantType
 
        switch obj := obj.(type) {
        case *PkgName:
-               check.errorf(e, InvalidPkgUse, "use of package %s not in selector", quote(obj.name))
+               check.errorf(e, InvalidPkgUse, "use of package %s not in selector", obj.name)
                return
 
        case *Const:
@@ -117,7 +117,7 @@ func (check *Checker) ident(x *operand, e *syntax.Name, def *TypeName, wantType
 
        case *TypeName:
                if !check.conf.EnableAlias && check.isBrokenAlias(obj) {
-                       check.errorf(e, InvalidDeclCycle, "invalid use of type alias %s in recursive type (see go.dev/issue/50729)", quote(obj.name))
+                       check.errorf(e, InvalidDeclCycle, "invalid use of type alias %s in recursive type (see go.dev/issue/50729)", obj.name)
                        return
                }
                x.mode = typexpr
index 4761fbd6ef4bd79777eef3f024553d8412b4380a..d92a4279f86c97372d7e19222089a42779c4ddbc 100644 (file)
@@ -28,7 +28,7 @@ func (check *Checker) builtin(x *operand, call *ast.CallExpr, id builtinId) (_ b
        if hasDots(call) && id != _Append {
                check.errorf(dddErrPos(call),
                        InvalidDotDotDot,
-                       invalidOp+"invalid use of ... with built-in %s", quote(bin.name))
+                       invalidOp+"invalid use of ... with built-in %s", bin.name)
                check.use(argList...)
                return
        }
@@ -213,7 +213,7 @@ func (check *Checker) builtin(x *operand, call *ast.CallExpr, id builtinId) (_ b
                                if id == _Len {
                                        code = InvalidLen
                                }
-                               check.errorf(x, code, invalidArg+"%s for %s", x, quote(bin.name))
+                               check.errorf(x, code, invalidArg+"%s for built-in %s", x, bin.name)
                        }
                        return
                }
@@ -536,7 +536,7 @@ func (check *Checker) builtin(x *operand, call *ast.CallExpr, id builtinId) (_ b
        case _Max, _Min:
                // max(x, ...)
                // min(x, ...)
-               check.verifyVersionf(call.Fun, go1_21, "%s", quote(bin.name))
+               check.verifyVersionf(call.Fun, go1_21, "built-in %s", bin.name)
 
                op := token.LSS
                if id == _Max {
@@ -579,7 +579,7 @@ func (check *Checker) builtin(x *operand, call *ast.CallExpr, id builtinId) (_ b
                if x.mode != constant_ {
                        x.mode = value
                        // A value must not be untyped.
-                       check.assignment(x, &emptyInterface, "argument to "+quote(bin.name))
+                       check.assignment(x, &emptyInterface, "argument to built-in "+bin.name)
                        if x.mode == invalid {
                                return
                        }
@@ -644,7 +644,7 @@ func (check *Checker) builtin(x *operand, call *ast.CallExpr, id builtinId) (_ b
                if nargs > 0 {
                        params = make([]Type, nargs)
                        for i, a := range args {
-                               check.assignment(a, nil, "argument to "+quote(predeclaredFuncs[id].name))
+                               check.assignment(a, nil, "argument to built-in"+predeclaredFuncs[id].name)
                                if a.mode == invalid {
                                        return
                                }
@@ -995,7 +995,7 @@ func (check *Checker) applyTypeFunc(f func(Type) Type, x *operand, id builtinId)
                default:
                        panic("unreachable")
                }
-               check.softErrorf(x, code, "%s not supported as argument to %s for go1.18 (see go.dev/issue/50937)", x, quote(predeclaredFuncs[id].name))
+               check.softErrorf(x, code, "%s not supported as argument to built-in %s for go1.18 (see go.dev/issue/50937)", x, predeclaredFuncs[id].name)
 
                // Construct a suitable new type parameter for the result type.
                // The type parameter is placed in the current package so export/import
index bee97a182b31acd5f5c0d9706e5bbb22849d4daa..8f02ffc39729a3488dff5e8b5883fdc0f49e070d 100644 (file)
@@ -722,7 +722,7 @@ func (check *Checker) selector(x *operand, e *ast.SelectorExpr, def *TypeName, w
                                        goto Error
                                }
                                if !exp.Exported() {
-                                       check.errorf(e.Sel, UnexportedName, "%s not exported by package %s", quote(sel), quote(pkg.name))
+                                       check.errorf(e.Sel, UnexportedName, "name %s not exported by package %s", sel, pkg.name)
                                        // ok to continue
                                }
                        }
index 789c130e1ce1aef769046a3d6a74fa88dea77fb6..1a5a41a3bb4b9923310de3f8c2dccbdd7f00e9b9 100644 (file)
@@ -332,7 +332,7 @@ func (check *Checker) initFiles(files []*ast.File) {
                        check.files = append(check.files, file)
 
                default:
-                       check.errorf(atPos(file.Package), MismatchedPkgName, "package %s; expected %s", quote(name), quote(pkg.name))
+                       check.errorf(atPos(file.Package), MismatchedPkgName, "package %s; expected package %s", name, pkg.name)
                        // ignore this file
                }
        }
index 17dd1d41549824909438cfe8484c17626ea43f49..e9bf802cb8b1df11998c4e06f2db984af40144d6 100644 (file)
@@ -842,7 +842,7 @@ func (check *Checker) checkFieldUniqueness(base *Named) {
                                        // For historical consistency, we report the primary error on the
                                        // method, and the alt decl on the field.
                                        err := check.newError(DuplicateFieldAndMethod)
-                                       err.addf(alt, "field and method with the same name %s", quote(fld.name))
+                                       err.addf(alt, "field and method with the same name %s", fld.name)
                                        err.addAltDecl(fld)
                                        err.report()
                                }
index f5edb0144978aebc8186783feb29013bc63d8472..09e599c3c336afaacae72b5ee725a603b7a06ffa 100644 (file)
@@ -15,39 +15,6 @@ import (
        "strings"
 )
 
-// quote encloses s in `' quotes, as in `foo', except for _,
-// which is left alone.
-//
-// Use to prevent confusion when user supplied names alter the
-// meaning of an 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 ":" as there's no need for it:
-//     undefined name: foo
-//   - don't quote if the name is used correctly in a statement:
-//     goto L jumps over variable declaration
-//
-// quote encloses s in `' quotes, as in `foo',
-// except for _ which is left alone.
-func quote(s string) string {
-       if s == "_" {
-               // `_' is ugly and not necessary
-               return s
-       }
-       return "`" + s + "'"
-}
-
 func sprintf(fset *token.FileSet, qf Qualifier, tpSubscripts bool, format string, args ...any) string {
        for i, arg := range args {
                switch a := arg.(type) {
index 3b01478723095d5b5793dad14aba415cb219449c..c99c9a9550da24e6d938751ddd96a1cff303315c 100644 (file)
@@ -266,11 +266,11 @@ func TestIssue22525(t *testing.T) {
        conf := Config{Error: func(err error) { got += err.Error() + "\n" }}
        typecheck(src, &conf, nil) // do not crash
        want := "\n" +
-               "p:1:27: `a' declared and not used\n" +
-               "p:1:30: `b' declared and not used\n" +
-               "p:1:33: `c' declared and not used\n" +
-               "p:1:36: `d' declared and not used\n" +
-               "p:1:39: `e' declared and not used\n"
+               "p:1:27: declared and not used: a\n" +
+               "p:1:30: declared and not used: b\n" +
+               "p:1:33: declared and not used: c\n" +
+               "p:1:36: declared and not used: d\n" +
+               "p:1:39: declared and not used: e\n"
        if got != want {
                t.Errorf("got: %swant: %s", got, want)
        }
index c3fd437c14d12646d609191a3684ad434301c05e..2f7f7bd20c0501fdb9ed63bcad2b836af889921e 100644 (file)
@@ -27,13 +27,11 @@ func (check *Checker) labels(body *ast.BlockStmt) {
                name := jmp.Label.Name
                if alt := all.Lookup(name); alt != nil {
                        msg = "goto %s jumps into block"
-                       alt.(*Label).used = true // avoid another error
                        code = JumpIntoBlock
-                       // don't quote name here because "goto L" matches the code
+                       alt.(*Label).used = true // avoid another error
                } else {
                        msg = "label %s not declared"
                        code = UndeclaredLabel
-                       name = quote(name)
                }
                check.errorf(jmp.Label, code, msg, name)
        }
@@ -42,7 +40,7 @@ func (check *Checker) labels(body *ast.BlockStmt) {
        for name, obj := range all.elems {
                obj = resolve(name, obj)
                if lbl := obj.(*Label); !lbl.used {
-                       check.softErrorf(lbl, UnusedLabel, "label %s declared and not used", quote(lbl.name))
+                       check.softErrorf(lbl, UnusedLabel, "label %s declared and not used", lbl.name)
                }
        }
 }
@@ -142,7 +140,7 @@ func (check *Checker) blockBranches(all *Scope, parent *block, lstmt *ast.Labele
                                if alt := all.Insert(lbl); alt != nil {
                                        err := check.newError(DuplicateLabel)
                                        err.soft = true
-                                       err.addf(lbl, "label %s already declared", quote(name))
+                                       err.addf(lbl, "label %s already declared", name)
                                        err.addAltDecl(alt)
                                        err.report()
                                        // ok to continue
@@ -198,7 +196,7 @@ func (check *Checker) blockBranches(all *Scope, parent *block, lstmt *ast.Labele
                                        }
                                }
                                if !valid {
-                                       check.errorf(s.Label, MisplacedLabel, "invalid break label %s", quote(name))
+                                       check.errorf(s.Label, MisplacedLabel, "invalid break label %s", name)
                                        return
                                }
 
@@ -213,7 +211,7 @@ func (check *Checker) blockBranches(all *Scope, parent *block, lstmt *ast.Labele
                                        }
                                }
                                if !valid {
-                                       check.errorf(s.Label, MisplacedLabel, "invalid continue label %s", quote(name))
+                                       check.errorf(s.Label, MisplacedLabel, "invalid continue label %s", name)
                                        return
                                }
 
index 258ad1d32759e9b55941a38907b35193eab77e4c..f9a733fc3a3cb15bfaadd4bc3254126c75eb9640 100644 (file)
@@ -65,7 +65,7 @@ func (check *Checker) usage(scope *Scope) {
                return cmpPos(unused[i].pos, unused[j].pos) < 0
        })
        for _, v := range unused {
-               check.softErrorf(v, UnusedVar, "%s declared and not used", quote(v.name))
+               check.softErrorf(v, UnusedVar, "declared and not used: %s", v.name)
        }
 
        for _, scope := range scope.children {
@@ -515,7 +515,7 @@ func (check *Checker) stmt(ctxt stmtContext, s ast.Stmt) {
                        for _, obj := range res.vars {
                                if alt := check.lookup(obj.name); alt != nil && alt != obj {
                                        err := check.newError(OutOfScopeResult)
-                                       err.addf(s, "result parameter %s not in scope at return", quote(obj.name))
+                                       err.addf(s, "result parameter %s not in scope at return", obj.name)
                                        err.addf(alt, "inner declaration of %s", obj)
                                        err.report()
                                        // ok to continue
index eb37de849ab10fbc2ecde4cf4bdd09b813dfb79b..d280bf2f5ff5cf5ac7d8b18cf8f9980da8dfc82e 100644 (file)
@@ -229,8 +229,8 @@ func computeInterfaceTypeSet(check *Checker, pos token.Pos, ityp *Interface) *_T
                case explicit:
                        if check != nil {
                                err := check.newError(DuplicateDecl)
-                               err.addf(atPos(pos), "duplicate method %s", quote(m.name))
-                               err.addf(atPos(mpos[other.(*Func)]), "other declaration of %s", quote(m.name))
+                               err.addf(atPos(pos), "duplicate method %s", m.name)
+                               err.addf(atPos(mpos[other.(*Func)]), "other declaration of method %s", m.name)
                                err.report()
                        }
                default:
@@ -243,8 +243,8 @@ func computeInterfaceTypeSet(check *Checker, pos token.Pos, ityp *Interface) *_T
                                check.later(func() {
                                        if pos.IsValid() && !check.allowVersion(atPos(pos), go1_14) || !Identical(m.typ, other.Type()) {
                                                err := check.newError(DuplicateDecl)
-                                               err.addf(atPos(pos), "duplicate method %s", quote(m.name))
-                                               err.addf(atPos(mpos[other.(*Func)]), "other declaration of %s", quote(m.name))
+                                               err.addf(atPos(pos), "duplicate method %s", m.name)
+                                               err.addf(atPos(mpos[other.(*Func)]), "other declaration of method %s", m.name)
                                                err.report()
                                        }
                                }).describef(atPos(pos), "duplicate method check for %s", m.name)
index dea6d3199753c1a2d97e6ce4bce25a1ccf1ce834..b6b6881089de66e9ddc31b6d842867bdba40a100 100644 (file)
@@ -95,7 +95,7 @@ func (check *Checker) ident(x *operand, e *ast.Ident, def *TypeName, wantType bo
 
        switch obj := obj.(type) {
        case *PkgName:
-               check.errorf(e, InvalidPkgUse, "use of package %s not in selector", quote(obj.name))
+               check.errorf(e, InvalidPkgUse, "use of package %s not in selector", obj.name)
                return
 
        case *Const:
@@ -117,7 +117,7 @@ func (check *Checker) ident(x *operand, e *ast.Ident, def *TypeName, wantType bo
 
        case *TypeName:
                if !check.conf._EnableAlias && check.isBrokenAlias(obj) {
-                       check.errorf(e, InvalidDeclCycle, "invalid use of type alias %s in recursive type (see go.dev/issue/50729)", quote(obj.name))
+                       check.errorf(e, InvalidDeclCycle, "invalid use of type alias %s in recursive type (see go.dev/issue/50729)", obj.name)
                        return
                }
                x.mode = typexpr
index 2bfece824eaa46f267eb62b998ca8d477a24b5b0..1c0e69200eba84737927a6e02698a11ed1ac6232 100644 (file)
@@ -100,10 +100,10 @@ func cap1() {
 
        var s [][]byte
        _ = cap(s)
-       _ = cap(s... /* ERROR "invalid use of ... with built-in `cap'" */ )
+       _ = cap(s... /* ERROR "invalid use of ... with built-in cap" */ )
 
        var x int
-       _ = cap(x /* ERROR "invalid argument: x (variable of type int) for `cap'" */ )
+       _ = cap(x /* ERROR "invalid argument: x (variable of type int) for built-in cap" */ )
 }
 
 func cap2() {
index bec2b17ada9c8b1d6718025d176b656a013bb49b..f9b0849dad7744db38c7a7db3298ff049a1bde9b 100644 (file)
@@ -137,7 +137,7 @@ type (
        }
        I3 interface {
                m1()
-               m1 /* ERROR "duplicate method `m1'" */ ()
+               m1 /* ERROR "duplicate method m1" */ ()
        }
        I4 interface {
                m1(x, y, x /* ERROR "redeclared" */ float32)
index f14b709dcf21fc93ff319879aa1049e25b7cf9ad..2362bb96ff190b976ae3c2d92a20c554c7006d56 100644 (file)
@@ -16,7 +16,7 @@ type T1 struct{
 
 func (T1) m() {}
 func (T1) m /* ERROR "already declared" */ () {}
-func (x *T1) f /* ERROR "field and method with the same name `f'" */ () {}
+func (x *T1) f /* ERROR "field and method with the same name f" */ () {}
 
 // Conflict between embedded field and method name,
 // with the embedded field being a basic type.
@@ -30,7 +30,7 @@ type T1c struct {
        time.Time
 }
 
-func (T1c) Time /* ERROR "field and method with the same name `Time'" */ () int { return 0 }
+func (T1c) Time /* ERROR "field and method with the same name Time" */ () int { return 0 }
 
 // Disabled for now: LookupFieldOrMethod will find Pointer even though
 // it's double-declared (it would cost extra in the common case to verify
index 3340124cfaa3d5d366951205890e3a85da7bb980..cc7861d616100222ffddabec24b6cc75d2e4dadc 100644 (file)
@@ -14,10 +14,10 @@ type I interface { m() }
 
 type _ interface {
        m()
-       I // ERROR "duplicate method `m'"
+       I // ERROR "duplicate method m"
 }
 
 type _ interface {
        I
-       I // ERROR "duplicate method `m'"
+       I // ERROR "duplicate method m"
 }
index b255c193753ed5e6cf62d7a1dde7e2de3ae88a91..4bfb61e5b4e43e6cd4af7347fb808ca4305ab012 100644 (file)
@@ -32,7 +32,7 @@ import f2 "fmt"
 
 // reflect.flag must not be visible in this package
 type flag int
-type _ reflect.flag /* ERROR "`flag' not exported by package `reflect'" */
+type _ reflect.flag /* ERROR "name flag not exported by package reflect" */
 
 // imported package name may conflict with local objects
 type reflect /* ERROR "reflect already declared" */ int
index 0a59e9e2dc9462f493353c6573f1fbe94b6e47b7..5948952fbe53398ab0806c15eaeef83814d86323 100644 (file)
@@ -10,23 +10,23 @@ package labels
 var x int
 
 func f0() {
-L1 /* ERROR "label `L1' declared and not used" */ :
+L1 /* ERROR "label L1 declared and not used" */ :
        for {
        }
-L2 /* ERROR "label `L2' declared and not used" */ :
+L2 /* ERROR "label L2 declared and not used" */ :
        select {
        }
-L3 /* ERROR "label `L3' declared and not used" */ :
+L3 /* ERROR "label L3 declared and not used" */ :
        switch {
        }
-L4 /* ERROR "label `L4' declared and not used" */ :
+L4 /* ERROR "label L4 declared and not used" */ :
        if true {
        }
-L5 /* ERROR "label `L5' declared and not used" */ :
+L5 /* ERROR "label L5 declared and not used" */ :
        f0()
 L6:
        f0()
-L6 /* ERROR "label `L6' already declared" */ :
+L6 /* ERROR "label L6 already declared" */ :
        f0()
        if x == 20 {
                goto L6
@@ -35,7 +35,7 @@ L6 /* ERROR "label `L6' already declared" */ :
 L7:
        for {
                break L7
-               break L8 /* ERROR "invalid break label `L8'" */
+               break L8 /* ERROR "invalid break label L8" */
        }
 
 // A label must be directly associated with a switch, select, or
@@ -43,8 +43,8 @@ L7:
 
 L7a /* ERROR "declared and not used" */ : L7b:
        for {
-               break L7a /* ERROR "invalid break label `L7a'" */
-               continue L7a /* ERROR "invalid continue label `L7a'" */
+               break L7a /* ERROR "invalid break label L7a" */
+               continue L7a /* ERROR "invalid continue label L7a" */
                continue L7b
        }
 
@@ -52,7 +52,7 @@ L8:
        for {
                if x == 21 {
                        continue L8
-                       continue L7 /* ERROR "invalid continue label `L7'" */
+                       continue L7 /* ERROR "invalid continue label L7" */
                }
        }
 
@@ -60,23 +60,23 @@ L9:
        switch {
        case true:
                break L9
-       defalt /* ERROR "label `defalt' declared and not used" */ :
+       defalt /* ERROR "label defalt declared and not used" */ :
        }
 
 L10:
        select {
        default:
                break L10
-               break L9 /* ERROR "invalid break label `L9'" */
+               break L9 /* ERROR "invalid break label L9" */
        }
 
        goto L10a
 L10a: L10b:
        select {
        default:
-               break L10a /* ERROR "invalid break label `L10a'" */
+               break L10a /* ERROR "invalid break label L10a" */
                break L10b
-               continue L10b /* ERROR "invalid continue label `L10b'" */
+               continue L10b /* ERROR "invalid continue label L10b" */
        }
 }
 
@@ -99,7 +99,7 @@ L2:
                        break L2
                }
                if x == 1 {
-                       continue L2 /* ERROR "invalid continue label `L2'" */
+                       continue L2 /* ERROR "invalid continue label L2" */
                }
                goto L2
        }
@@ -111,7 +111,7 @@ L3:
                        break L3
                }
                if x == 12 {
-                       continue L3 /* ERROR "invalid continue label `L3'" */
+                       continue L3 /* ERROR "invalid continue label L3" */
                }
                goto L3
        }
@@ -119,10 +119,10 @@ L3:
 L4:
        if true {
                if x == 13 {
-                       break L4 /* ERROR "invalid break label `L4'" */
+                       break L4 /* ERROR "invalid break label L4" */
                }
                if x == 14 {
-                       continue L4 /* ERROR "invalid continue label `L4'" */
+                       continue L4 /* ERROR "invalid continue label L4" */
                }
                if x == 15 {
                        goto L4
@@ -132,10 +132,10 @@ L4:
 L5:
        f1()
        if x == 16 {
-               break L5 /* ERROR "invalid break label `L5'" */
+               break L5 /* ERROR "invalid break label L5" */
        }
        if x == 17 {
-               continue L5 /* ERROR "invalid continue label `L5'" */
+               continue L5 /* ERROR "invalid continue label L5" */
        }
        if x == 18 {
                goto L5
@@ -143,10 +143,10 @@ L5:
 
        for {
                if x == 19 {
-                       break L1 /* ERROR "invalid break label `L1'" */
+                       break L1 /* ERROR "invalid break label L1" */
                }
                if x == 20 {
-                       continue L1 /* ERROR "invalid continue label `L1'" */
+                       continue L1 /* ERROR "invalid continue label L1" */
                }
                if x == 21 {
                        goto L1
@@ -157,10 +157,10 @@ L5:
 // Additional tests not in the original files.
 
 func f2() {
-L1 /* ERROR "label `L1' declared and not used" */ :
+L1 /* ERROR "label L1 declared and not used" */ :
        if x == 0 {
                for {
-                       continue L1 /* ERROR "invalid continue label `L1'" */
+                       continue L1 /* ERROR "invalid continue label L1" */
                }
        }
 }
@@ -170,11 +170,11 @@ L1:
 L2:
 L3:
        for {
-               break L1 /* ERROR "invalid break label `L1'" */
-               break L2 /* ERROR "invalid break label `L2'" */
+               break L1 /* ERROR "invalid break label L1" */
+               break L2 /* ERROR "invalid break label L2" */
                break L3
-               continue L1 /* ERROR "invalid continue label `L1'" */
-               continue L2 /* ERROR "invalid continue label `L2'" */
+               continue L1 /* ERROR "invalid continue label L1" */
+               continue L2 /* ERROR "invalid continue label L2" */
                continue L3
                goto L1
                goto L2
index ea161279c65cf7937f4be41333811bafe54b3197..e17dd650cdae627777b5a9fb169b75dcda07fc66 100644 (file)
@@ -222,7 +222,7 @@ func selects() {
        ch2 := make(chan int)
        select {
        case <-ch1:
-               var ch2 /* ERROR "`ch2' declared and not used" */ chan bool
+               var ch2 /* ERROR "declared and not used: ch2" */ chan bool
        case i := <-ch2:
                print(i + 1)
        }
@@ -394,7 +394,7 @@ func returns2() (a, b int) {
        {
                type a int
                return 1, 2
-               return /* ERROR "`a' not in scope at return" */
+               return /* ERROR "result parameter a not in scope at return" */
        }
 }
 
index a0a126dff017c8536d4ae269bfee35f09532428e..59c0f2d6a015750eb73237450dcf459c06374c27 100644 (file)
@@ -17,7 +17,7 @@ type R[S any, P any] struct{}
 type SR = R[SS, ST]
 
 type SS interface {
-       NSR(any) *SR // ERROR "invalid use of type alias `SR' in recursive type"
+       NSR(any) *SR // ERROR "invalid use of type alias SR in recursive type"
 }
 
 type C interface {
index 2e8bb59508f4d51a897eecc9bc71c9e793304f7c..9811fec3f35549aaeb0ce670de453b0d1b1ad8fc 100644 (file)
@@ -19,7 +19,7 @@ import "io"
 
 type _ interface {
        Reader
-       Reader // ERROR "duplicate method `Read'"
+       Reader // ERROR "duplicate method Read"
 }
 
 type Reader interface {
@@ -28,10 +28,10 @@ type Reader interface {
 
 type _ interface {
        io.Reader
-       Reader // ERROR "duplicate method `Read'"
+       Reader // ERROR "duplicate method Read"
 }
 
 type _ interface {
        io.Reader
-       io /* ERROR "duplicate method `Read'" */ .Reader
+       io /* ERROR "duplicate method Read" */ .Reader
 }
index 84e71c73e60991b8f1a73813ef8256de6772a158..1ef8735a525a40366b4f22809a3f3fe9ac2fe895 100644 (file)
@@ -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"
index cba129095773ca27cc8b5339b59a2b0f8f4ba01f..6a0b7961f374f5a4e76a198e5d22b1593610cf24 100644 (file)
@@ -10,4 +10,4 @@
 // there yet, so put it here for now. See also #20800.)
 
 package e
-func([<-chan<-[func u){go // ERROR "unexpected `u'"
\ No newline at end of file
+func([<-chan<-[func u){go // ERROR "unexpected name u"
\ No newline at end of file
index d525f12a58af1a5194452b8863da80e107a03045..8162548151a3d1b055f85b57a4d49462a2c4b1b6 100644 (file)
@@ -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: declared and not used: n",
+               "7:12: declared and not used: err",
        }
        outStr := string(out)
        for _, want := range wantErrs {
index fe171c27d0497ea4d70fd6a74f8182c6ee0bfeed..3b54f3cf1e9ae9e27107e7b4b9b40ab8ba4c3ee3 100644 (file)
@@ -9,9 +9,9 @@
 package p
 
 func f() {
-       if f() true { // ERROR "unexpected `true', expected {"
+       if f() true { // ERROR "unexpected name true, expected {"
        }
-       
-       switch f() true { // ERROR "unexpected `true', expected {"
+
+       switch f() true { // ERROR "unexpected name true, expected {"
        }
 }
index b04e42555fecb41ecca6c0775c17447559b3c677..263b2d1b425b7df9d3476350d81fbe5a3da9df12 100644 (file)
@@ -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
index c7cdd8c8c77d74bb5e8e177d4de6fa5d2cd7b4bb..df50b0522d62aed1a66868ceda7d1cd0956ce3b6 100644 (file)
@@ -10,5 +10,5 @@
 package main
 
 func _() {
-       x := 7 // ERROR ".*x.* declared and not used"
+       x := 7 // ERROR "declared and not used"
 }
index 585770d87a4d8d8ceda722dc8318aab740f0dd33..21f952cefdb13c904698a5b7ef0ce28b94cd6953 100644 (file)
@@ -6,9 +6,9 @@
 
 package p
 
-type I interface { M() }
+type I interface{ M() }
 
 type _ interface {
        I
-       I // ERROR "duplicate method `M'"
+       I // ERROR "duplicate method M"
 }