mirror of
https://github.com/golang/go
synced 2024-09-05 16:04:50 +00:00
cmd/compile: only print one error for bad-type literal in assignment
Fixes #8438 Change-Id: Ib43cdcdc962a8d9e14faf984bc859a92ba1eb517 Reviewed-on: https://go-review.googlesource.com/40531 Reviewed-by: Robert Griesemer <gri@golang.org>
This commit is contained in:
parent
405a280d01
commit
3218b1aa6f
|
@ -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
|
||||
}
|
||||
|
||||
|
|
17
test/fixedbugs/issue8438.go
Normal file
17
test/fixedbugs/issue8438.go
Normal file
|
@ -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
|
||||
}
|
|
@ -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"
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue