]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: fix printing of array types in error messages
authorRobert Griesemer <gri@golang.org>
Tue, 5 Jun 2018 00:17:16 +0000 (17:17 -0700)
committerRobert Griesemer <gri@golang.org>
Tue, 5 Jun 2018 00:43:22 +0000 (00:43 +0000)
Fixes #23094.

Change-Id: I9aa36046488baa5f55cf2099e10cfb39ecd17b06
Reviewed-on: https://go-review.googlesource.com/116256
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
src/cmd/compile/internal/gc/fmt.go
test/fixedbugs/issue23094.go [new file with mode: 0644]

index 4e92f5421b0e5b04c28a13c0c1a811b751ef0d08..598930bf15de714b204dec70895c55a79580cb7e 100644 (file)
@@ -1268,7 +1268,7 @@ func (n *Node) exprfmt(s fmt.State, prec int, mode fmtMode) {
 
        case OTARRAY:
                if n.Left != nil {
-                       mode.Fprintf(s, "[]%v", n.Left)
+                       mode.Fprintf(s, "[%v]%v", n.Left, n.Right)
                        return
                }
                mode.Fprintf(s, "[]%v", n.Right) // happens before typecheck
diff --git a/test/fixedbugs/issue23094.go b/test/fixedbugs/issue23094.go
new file mode 100644 (file)
index 0000000..415556f
--- /dev/null
@@ -0,0 +1,11 @@
+// errorcheck
+
+// Copyright 2018 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.
+
+// Verify that the array is reported in correct notation.
+
+package p
+
+var a [len(a)]int // ERROR "\[len\(a\)\]int"