Skip to content

Commit

Permalink
cmd/gc: do not display ~b identifiers in error messages
Browse files Browse the repository at this point in the history
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 golang#9521

Change-Id: Ieab9859040e8e0df95deeaee7eeb408d3be61c0f
Reviewed-on: https://go-review.googlesource.com/9902
Reviewed-by: Josh Bleecher Snyder <[email protected]>
Reviewed-by: Ian Lance Taylor <[email protected]>
  • Loading branch information
dspezia authored and ianlancetaylor committed May 11, 2015
1 parent 3475ec7 commit 7c0db1b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/cmd/internal/gc/fmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
16 changes: 16 additions & 0 deletions test/fixedbugs/issue9521.go
Original file line number Diff line number Diff line change
@@ -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 _"
}

0 comments on commit 7c0db1b

Please sign in to comment.