1
0
mirror of https://github.com/golang/go synced 2024-11-23 00:50:05 -07:00

new interface error messages

package main
	func main() {
		var i interface { } = 1;
		a := i.(*[]byte);
	}

interface { } is int, not *[]uint8
throw: interface conversion

	package main
	func main() {
		var i interface { };
		a := i.(*[]byte);
	}

interface is nil, not *[]uint8
throw: interface conversion

	package main
	func main() {
		i := sys.unreflect(0, "*bogus");
		a := i.(*[]byte);
	}

interface { } is *bogus, not *[]uint8
throw: interface conversion

R=r
DELTA=30  (24 added, 2 deleted, 4 changed)
OCL=18548
CL=18565
This commit is contained in:
Russ Cox 2008-11-05 13:05:01 -08:00
parent 5a1cbe8b64
commit 6f07ec721a

View File

@ -122,9 +122,17 @@ hashmap(Sigi *si, Sigt *st, int32 canfail)
for(m=hash[h]; m!=nil; m=m->link) { for(m=hash[h]; m!=nil; m=m->link) {
if(m->sigi == si && m->sigt == st) { if(m->sigi == si && m->sigt == st) {
if(m->bad) { if(m->bad) {
if(!canfail)
throw("bad hashmap");
m = nil; m = nil;
if(!canfail) {
// this can only happen if the conversion
// was already done once using the , ok form
// and we have a cached negative result.
// the cached result doesn't record which
// interface function was missing, so jump
// down to the interface check, which will
// give a better error.
goto throw;
}
} }
// prints("old hashmap\n"); // prints("old hashmap\n");
return m; return m;
@ -136,6 +144,7 @@ hashmap(Sigi *si, Sigt *st, int32 canfail)
m->sigi = si; m->sigi = si;
m->sigt = st; m->sigt = st;
throw:
nt = 1; nt = 1;
for(ni=1;; ni++) { // ni=1: skip first word for(ni=1;; ni++) { // ni=1: skip first word
iname = si[ni].name; iname = si[ni].name;
@ -222,10 +231,23 @@ sys·ifaceI2T(Sigt *st, Map *im, void *it, void *ret)
prints("\n"); prints("\n");
} }
if(im == nil) if(im == nil) {
throw("ifaceI2T: nil map"); prints("interface is nil, not ");
if(im->sigt != st) prints((int8*)st[0].name);
throw("ifaceI2T: wrong type"); prints("\n");
throw("interface conversion");
}
if(im->sigt != st) {
prints((int8*)im->sigi[0].name);
prints(" is ");
prints((int8*)im->sigt[0].name);
prints(", not ");
prints((int8*)st[0].name);
prints("\n");
throw("interface conversion");
}
ret = it; ret = it;
if(debug) { if(debug) {
prints("I2T ret="); prints("I2T ret=");