From ff84d756df91f94289bef164765142632922a6bc Mon Sep 17 00:00:00 2001 From: Robert Griesemer Date: Tue, 3 Dec 2013 17:51:54 -0800 Subject: [PATCH] go.tools/go/types: avoid spurious error in a common case R=adonovan CC=golang-dev https://golang.org/cl/36900043 --- go/types/expr.go | 2 +- go/types/testdata/errors.src | 11 ++++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/go/types/expr.go b/go/types/expr.go index 20f64b15..6dd67543 100644 --- a/go/types/expr.go +++ b/go/types/expr.go @@ -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 } diff --git a/go/types/testdata/errors.src b/go/types/testdata/errors.src index 11380078..f8acc0c7 100644 --- a/go/types/testdata/errors.src +++ b/go/types/testdata/errors.src @@ -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 */ {} +} \ No newline at end of file