]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: only print one error for bad-type literal in assignment
authorAlberto Donizetti <alb.donizetti@gmail.com>
Thu, 13 Apr 2017 08:42:16 +0000 (10:42 +0200)
committerRobert Griesemer <gri@golang.org>
Thu, 20 Apr 2017 22:21:55 +0000 (22:21 +0000)
Fixes #8438

Change-Id: Ib43cdcdc962a8d9e14faf984bc859a92ba1eb517
Reviewed-on: https://go-review.googlesource.com/40531
Reviewed-by: Robert Griesemer <gri@golang.org>
src/cmd/compile/internal/gc/subr.go
test/fixedbugs/issue8438.go [new file with mode: 0644]
test/interface/explicit.go

index ff2d88614b1e61e74936d52e3a8085d875ed77a2..b52b4e4e69df6f2d2e87c0052ad20ad53aad44d8 100644 (file)
@@ -982,7 +982,9 @@ func assignconvfn(n *Node, t *types.Type, context func() string) *Node {
        var why string
        op := assignop(n.Type, t, &why)
        if op == 0 {
-               yyerror("cannot use %L as type %v in %s%s", n, t, context(), why)
+               if !old.Diag() {
+                       yyerror("cannot use %L as type %v in %s%s", n, t, context(), why)
+               }
                op = OCONV
        }
 
diff --git a/test/fixedbugs/issue8438.go b/test/fixedbugs/issue8438.go
new file mode 100644 (file)
index 0000000..b28025c
--- /dev/null
@@ -0,0 +1,17 @@
+// errorcheck
+
+// Copyright 2017 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.
+
+// Check that we don't print duplicate errors for string ->
+// array-literal conversion
+
+package main
+
+func main() {
+       _ = []byte{"foo"}   // ERROR "cannot convert"
+       _ = []int{"foo"}    // ERROR "cannot convert"
+       _ = []rune{"foo"}   // ERROR "cannot convert"
+       _ = []string{"foo"} // OK
+}
index b10d02f2485adb66c1411351ce4909661325ef6d..3c449b13ada192821dd86a2260151d3190bb6f1c 100644 (file)
@@ -53,7 +53,7 @@ func main() {
        i2 = I2(i) // ERROR "invalid|missing N method"
 
        e = E(t) // ok
-       t = T(e) // ERROR "need explicit|need type assertion|incompatible" "as type [*]T"
+       t = T(e) // ERROR "need explicit|need type assertion|incompatible"
 }
 
 type M interface {
@@ -81,7 +81,6 @@ var m2 M = jj // ERROR "incompatible|wrong type for M method"
 var m3 = M(ii) // ERROR "invalid|missing"
 var m4 = M(jj) // ERROR "invalid|wrong type for M method"
 
-
 type B1 interface {
        _() // ERROR "methods must have a unique non-blank name"
 }