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:
		
							parent
							
								
									5d386107a0
								
							
						
					
					
						commit
						ff84d756df
					
				| 
						 | 
				
			
			@ -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
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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 */ {}
 | 
			
		||||
}
 | 
			
		||||
		Loading…
	
		Reference in New Issue