mirror of
https://github.com/golang/go
synced 2024-09-05 07:54:46 +00:00
complain when trying to put T into an interface
if T has pointer methods. this is just a heuristic but it catches the problem robert ran into and lets me put the larger interface issues aside for now. found one bug in pretty. R=ken OCL=26141 CL=26141
This commit is contained in:
parent
40e204b9eb
commit
4eb7ceba58
|
@ -2805,12 +2805,23 @@ ifacelookdot(Sym *s, Type *t)
|
||||||
// check whether non-interface type t
|
// check whether non-interface type t
|
||||||
// satisifes inteface type iface.
|
// satisifes inteface type iface.
|
||||||
int
|
int
|
||||||
ifaceokT2I(Type *t, Type *iface, Type **m)
|
ifaceokT2I(Type *t0, Type *iface, Type **m)
|
||||||
{
|
{
|
||||||
Type *im, *tm;
|
Type *t, *im, *tm;
|
||||||
int imhash;
|
int imhash;
|
||||||
|
|
||||||
t = methtype(t);
|
t = methtype(t0);
|
||||||
|
|
||||||
|
// stopgap: check for
|
||||||
|
// non-pointer type in T2I, methods want pointers.
|
||||||
|
// supposed to do something better eventually
|
||||||
|
// but this will catch errors while we decide the
|
||||||
|
// details of the "better" solution.
|
||||||
|
if(t == t0 && t->methptr == 2) {
|
||||||
|
yyerror("probably wanted *%T not %T", t, t);
|
||||||
|
*m = iface->type;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
// if this is too slow,
|
// if this is too slow,
|
||||||
// could sort these first
|
// could sort these first
|
||||||
|
|
|
@ -64,10 +64,6 @@ Faulting address: 0x0
|
||||||
pc: xxx
|
pc: xxx
|
||||||
|
|
||||||
|
|
||||||
=========== ./interface6.go
|
|
||||||
failure in f4 i
|
|
||||||
BUG interface6
|
|
||||||
|
|
||||||
=========== ./peano.go
|
=========== ./peano.go
|
||||||
0! = 1
|
0! = 1
|
||||||
1! = 1
|
1! = 1
|
||||||
|
|
|
@ -35,11 +35,11 @@ func ptrs() {
|
||||||
var smallptr SmallPtr = SmallPtr{ 12345 };
|
var smallptr SmallPtr = SmallPtr{ 12345 };
|
||||||
var intptr IntPtr = 12345;
|
var intptr IntPtr = 12345;
|
||||||
|
|
||||||
test("bigptr", bigptr);
|
// test("bigptr", bigptr);
|
||||||
test("&bigptr", &bigptr);
|
test("&bigptr", &bigptr);
|
||||||
test("smallptr", smallptr);
|
// test("smallptr", smallptr);
|
||||||
test("&smallptr", &smallptr);
|
test("&smallptr", &smallptr);
|
||||||
test("intptr", intptr);
|
// test("intptr", intptr);
|
||||||
test("&intptr", &intptr);
|
test("&intptr", &intptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -49,13 +49,13 @@ type S2 struct { i int }
|
||||||
func (p *S2) Get() int { return p.i }
|
func (p *S2) Get() int { return p.i }
|
||||||
func (p *S2) Put(i int) { p.i = i }
|
func (p *S2) Put(i int) { p.i = i }
|
||||||
|
|
||||||
func f4() {
|
// func f4() {
|
||||||
s := S2{1};
|
// s := S2{1};
|
||||||
var i I1 = s;
|
// var i I1 = s;
|
||||||
i.Put(2);
|
// i.Put(2);
|
||||||
check(i.Get() == 2, "f4 i");
|
// check(i.Get() == 2, "f4 i");
|
||||||
check(s.i == 1, "f4 s");
|
// check(s.i == 1, "f4 s");
|
||||||
}
|
// }
|
||||||
|
|
||||||
func f5() {
|
func f5() {
|
||||||
s := S2{1};
|
s := S2{1};
|
||||||
|
@ -107,13 +107,13 @@ type S4 struct { i, j, k, l int64 }
|
||||||
func (p *S4) Get() int64 { return p.l }
|
func (p *S4) Get() int64 { return p.l }
|
||||||
func (p *S4) Put(i int64) { p.l = i }
|
func (p *S4) Put(i int64) { p.l = i }
|
||||||
|
|
||||||
func f10() {
|
// func f10() {
|
||||||
s := S4{1, 2, 3, 4};
|
// s := S4{1, 2, 3, 4};
|
||||||
var i I2 = s;
|
// var i I2 = s;
|
||||||
i.Put(5);
|
// i.Put(5);
|
||||||
check(i.Get() == 5, "f10 i");
|
// check(i.Get() == 5, "f10 i");
|
||||||
check(s.l == 4, "f10 s");
|
// check(s.l == 4, "f10 s");
|
||||||
}
|
// }
|
||||||
|
|
||||||
func f11() {
|
func f11() {
|
||||||
s := S4{1, 2, 3, 4};
|
s := S4{1, 2, 3, 4};
|
||||||
|
@ -135,13 +135,13 @@ func main() {
|
||||||
f1();
|
f1();
|
||||||
f2();
|
f2();
|
||||||
f3();
|
f3();
|
||||||
f4();
|
// f4();
|
||||||
f5();
|
f5();
|
||||||
f6();
|
f6();
|
||||||
f7();
|
f7();
|
||||||
f8();
|
f8();
|
||||||
f9();
|
f9();
|
||||||
f10();
|
// f10();
|
||||||
f11();
|
f11();
|
||||||
f12();
|
f12();
|
||||||
if fail > 0 {
|
if fail > 0 {
|
||||||
|
|
|
@ -642,7 +642,7 @@ func (P *Parser) parseStructType() ast.Expr {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return ast.StructType{loc, fields, end};
|
return &ast.StructType{loc, fields, end};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue