]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/gc: do not display ~b identifiers in error messages
authorDidier Spezia <didier.06@gmail.com>
Sat, 9 May 2015 17:21:42 +0000 (17:21 +0000)
committerIan Lance Taylor <iant@golang.org>
Mon, 11 May 2015 17:44:31 +0000 (17:44 +0000)
Instead of errors like:

./blank2.go:15: cannot use ~b1 (type []int) as type int in assignment

we now have:

./blank2.go:15: cannot use _ (type []int) as type int in assignment

Less confusing for users.

Fixes #9521

Change-Id: Ieab9859040e8e0df95deeaee7eeb408d3be61c0f
Reviewed-on: https://go-review.googlesource.com/9902
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
src/cmd/internal/gc/fmt.go
test/fixedbugs/issue9521.go [new file with mode: 0644]

index 1a991a0a65434be1a2b2e6e449fc2004a390ac1c..4e3045a92967a1e4ae7db6beb122880673fd93d9 100644 (file)
@@ -1127,7 +1127,7 @@ func exprfmt(n *Node, prec int) string {
                // Special case: name used as local variable in export.
        // _ becomes ~b%d internally; print as _ for export
        case ONAME:
-               if fmtmode == FExp && n.Sym != nil && n.Sym.Name[0] == '~' && n.Sym.Name[1] == 'b' {
+               if (fmtmode == FExp || fmtmode == FErr) && n.Sym != nil && n.Sym.Name[0] == '~' && n.Sym.Name[1] == 'b' {
                        return "_"
                }
                if fmtmode == FExp && n.Sym != nil && !isblank(n) && n.Vargen > 0 {
diff --git a/test/fixedbugs/issue9521.go b/test/fixedbugs/issue9521.go
new file mode 100644 (file)
index 0000000..51b5204
--- /dev/null
@@ -0,0 +1,16 @@
+// errorcheck
+
+// Copyright 2015 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// Test that an incorrect use of the blank identifer is caught.
+// Does not compile.
+
+package main
+
+func f() (_, _ []int) { return }
+
+func main() {
+       _ = append(f()) // ERROR "cannot use _"
+}