Skip to content

Commit 4a2bec9

Browse files
committed
cmd/compile: fix printing of array types in error messages
Fixes #23094. Change-Id: I9aa36046488baa5f55cf2099e10cfb39ecd17b06 Reviewed-on: https://go-review.googlesource.com/116256 Run-TryBot: Robert Griesemer <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]>
1 parent 75c1aed commit 4a2bec9

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

src/cmd/compile/internal/gc/fmt.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1268,7 +1268,7 @@ func (n *Node) exprfmt(s fmt.State, prec int, mode fmtMode) {
12681268

12691269
case OTARRAY:
12701270
if n.Left != nil {
1271-
mode.Fprintf(s, "[]%v", n.Left)
1271+
mode.Fprintf(s, "[%v]%v", n.Left, n.Right)
12721272
return
12731273
}
12741274
mode.Fprintf(s, "[]%v", n.Right) // happens before typecheck

test/fixedbugs/issue23094.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// errorcheck
2+
3+
// Copyright 2018 The Go Authors. All rights reserved.
4+
// Use of this source code is governed by a BSD-style
5+
// license that can be found in the LICENSE file.
6+
7+
// Verify that the array is reported in correct notation.
8+
9+
package p
10+
11+
var a [len(a)]int // ERROR "\[len\(a\)\]int"

0 commit comments

Comments
 (0)