Commit c7e1453e authored by Chris Manghane's avatar Chris Manghane

cmd/internal/gc: do not show computed value in type error

Fixes #9076.

Change-Id: Ib41a452fa9aa9fecf19f65c36d13715923548041
Reviewed-on: https://go-review.googlesource.com/1250Reviewed-by: 's avatarMinux Ma <minux@golang.org>
Reviewed-by: 's avatarRuss Cox <rsc@golang.org>
Run-TryBot: Chris Manghane <cmang@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
parent b59dd94f
...@@ -1261,14 +1261,14 @@ func exprfmt(n *Node, prec int) string { ...@@ -1261,14 +1261,14 @@ func exprfmt(n *Node, prec int) string {
return f return f
case OLITERAL: // this is a bit of a mess case OLITERAL: // this is a bit of a mess
if fmtmode == FErr && n.Sym != nil { if n.Orig != nil && n.Orig != n {
var f string var f string
f += fmt.Sprintf("%v", Sconv(n.Sym, 0)) f += exprfmt(n.Orig, prec)
return f return f
} }
if n.Val.Ctype == CTNIL && n.Orig != nil && n.Orig != n { if fmtmode == FErr && n.Sym != nil {
var f string var f string
f += exprfmt(n.Orig, prec) f += fmt.Sprintf("%v", Sconv(n.Sym, 0))
return f return f
} }
if n.Type != nil && n.Type != Types[n.Type.Etype] && n.Type != idealbool && n.Type != idealstring { if n.Type != nil && n.Type != Types[n.Type.Etype] && n.Type != idealbool && n.Type != idealstring {
......
...@@ -7,5 +7,5 @@ ...@@ -7,5 +7,5 @@
package main package main
func main() { func main() {
_ = string(-4 + 2i + 2) // ERROR "-4\+2i" _ = string(-4 + 2i + 2) // ERROR "-4 \+ 2i"
} }
// errorcheck
// Copyright 2014 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.
// Issue 9076: cmd/gc shows computed values in error messages instead of original expression.
package main
import "unsafe"
const Hundred = 100
var _ int32 = 100/unsafe.Sizeof(int(0)) + 1 // GC_ERROR "100 \/ unsafe.Sizeof\(int\(0\)\) \+ 1"
var _ int32 = Hundred/unsafe.Sizeof(int(0)) + 1 // GC_ERROR "Hundred \/ unsafe.Sizeof\(int\(0\)\) \+ 1"
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment