1
0
mirror of https://github.com/golang/go synced 2024-11-24 22:57:57 -07:00

gc: use inferred type rather than original one when reporting non-assignability.

Fixes #2451

R=rsc, bradfitz
CC=golang-dev
https://golang.org/cl/5372105
This commit is contained in:
Luuk van Dijk 2011-12-14 17:34:35 +01:00
parent d842acd57e
commit e14d1d7e41
4 changed files with 22 additions and 8 deletions

View File

@ -1278,13 +1278,17 @@ exprfmt(Fmt *f, Node *n, int prec)
static int static int
nodefmt(Fmt *f, Node *n) nodefmt(Fmt *f, Node *n)
{ {
Type *t;
if(f->flags&FmtLong && n->type != T) { t = n->type;
if(n->type->etype == TNIL) if(n->orig != N)
n = n->orig;
if(f->flags&FmtLong && t != T) {
if(t->etype == TNIL)
return fmtprint(f, "nil"); return fmtprint(f, "nil");
else else
return fmtprint(f, "%N (type %T)", n, n->type); return fmtprint(f, "%N (type %T)", n, t);
} }
// TODO inlining produces expressions with ninits. we can't print these yet. // TODO inlining produces expressions with ninits. we can't print these yet.
@ -1479,8 +1483,6 @@ Nconv(Fmt *fp)
switch(fmtmode) { switch(fmtmode) {
case FErr: case FErr:
case FExp: case FExp:
if(n->orig != N)
n = n->orig;
r = nodefmt(fp, n); r = nodefmt(fp, n);
break; break;
case FDbg: case FDbg:

View File

@ -15,7 +15,7 @@ var (
_ = sum() _ = sum()
_ = sum(1.0, 2.0) _ = sum(1.0, 2.0)
_ = sum(1.5) // ERROR "integer" _ = sum(1.5) // ERROR "integer"
_ = sum("hello") // ERROR ".hello. .type ideal string. as type int|incompatible" _ = sum("hello") // ERROR ".hello. .type string. as type int|incompatible"
_ = sum([]int{1}) // ERROR "\[\]int literal.*as type int|incompatible" _ = sum([]int{1}) // ERROR "\[\]int literal.*as type int|incompatible"
) )

12
test/fixedbugs/bug386.go Normal file
View File

@ -0,0 +1,12 @@
// errchk $G $D/$F.go
// Copyright 2011 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.
// Issue 2451, 2452
package foo
func f() error { return 0 } // ERROR "cannot use 0 .type int."
func g() error { return -1 } // ERROR "cannot use -1 .type int."

View File

@ -37,7 +37,7 @@ func main() {
asBool(true) asBool(true)
asBool(*&b) asBool(*&b)
asBool(Bool(true)) asBool(Bool(true))
asBool(1 != 2) // ERROR "cannot use.*type ideal bool.*as type Bool" asBool(1 != 2) // ERROR "cannot use.*type bool.*as type Bool"
asBool(i < j) // ERROR "cannot use.*type bool.*as type Bool" asBool(i < j) // ERROR "cannot use.*type bool.*as type Bool"
_, b = m[2] // ERROR "cannot .* bool.*type Bool" _, b = m[2] // ERROR "cannot .* bool.*type Bool"