1
0
mirror of https://github.com/golang/go synced 2024-11-18 18:44:42 -07:00

go.tools/go/types: avoid spurious error in a common case

R=adonovan
CC=golang-dev
https://golang.org/cl/36900043
This commit is contained in:
Robert Griesemer 2013-12-03 17:51:54 -08:00
parent 5d386107a0
commit ff84d756df
2 changed files with 9 additions and 4 deletions

View File

@ -464,7 +464,7 @@ func (check *checker) updateExprType(x ast.Expr, typ Type, final bool) {
// convertUntyped attempts to set the type of an untyped value to the target type.
func (check *checker) convertUntyped(x *operand, target Type) {
if x.mode == invalid || isTyped(x.typ) {
if x.mode == invalid || isTyped(x.typ) || target == Typ[Invalid] {
return
}

View File

@ -2,11 +2,10 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// testing precise operand formatting in error messages
// (matching messages are regular expressions, hence the \'s)
package errors
// Testing precise operand formatting in error messages
// (matching messages are regular expressions, hence the \'s).
func f(x int, m map[string]int) {
// no values
_ = f /* ERROR "f\(0, m\) \(no value\) used as value" */ (0, m)
@ -44,3 +43,9 @@ func _() {
0 // ERROR "0 .* is not used"
0 // ERROR 0 .* is not used
}
// Don't report spurious errors as a consequence of earlier errors.
// Add more tests as needed.
func _() {
if err := foo /* ERROR undeclared */ (); err != nil /* no error here */ {}
}