summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorK. "pestophagous" Heller <pestophagous@gmail.com>2019-08-20 23:13:25 -0700
committerRobert Griesemer <gri@golang.org>2019-09-06 18:03:49 +0000
commit2da9c3e0f99b72cf8f3bdca01b57e7a68a546c5b (patch)
tree2f22aad40bf68c877c98b7550a64af4d3dead12f /src
parenta3ceb57fb4bfeb1af3558ff9999687b97fd08bc9 (diff)
downloadgo-git-2da9c3e0f99b72cf8f3bdca01b57e7a68a546c5b.tar.gz
cmd/compile: improve errors for invalid conversions of consts
Follow-up to Change-Id: If6e52c59eab438599d641ecf6f110ebafca740a9 This addresses the remaining tech debt on issue 21979. The aforementioned previous CL silenced one of two mostly redundant compiler errors. However, the silenced error was the more expressive error. This CL now imbues the surviving error with the same level of expressiveness as the old semi-redundant error. Fixes #21979 Change-Id: I3273d48c88bbab073fabe53421d801df621ce321 Reviewed-on: https://go-review.googlesource.com/c/go/+/191079 Run-TryBot: Robert Griesemer <gri@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
Diffstat (limited to 'src')
-rw-r--r--src/cmd/compile/internal/gc/const.go10
1 files changed, 7 insertions, 3 deletions
diff --git a/src/cmd/compile/internal/gc/const.go b/src/cmd/compile/internal/gc/const.go
index c5b8d816c6..569cab4390 100644
--- a/src/cmd/compile/internal/gc/const.go
+++ b/src/cmd/compile/internal/gc/const.go
@@ -413,16 +413,20 @@ func convlit1(n *Node, t *types.Type, explicit bool, reuse canReuseNode) *Node {
return n
bad:
+ reportErr := false
if !n.Diag() {
- if !t.Broke() {
- yyerror("cannot convert %L to type %v", n, t)
- }
+ reportErr = !t.Broke()
n.SetDiag(true)
}
if n.Type.IsUntyped() {
n = defaultlitreuse(n, nil, reuse)
}
+
+ if reportErr {
+ yyerror("cannot convert %L to type %v", n, t)
+ }
+
return n
}