mirror of
https://github.com/golang/go
synced 2024-11-25 09:17:57 -07:00
gc: helpful message instead of internal error on method call on pointer to pointer.
Fixes #2343. R=rsc CC=golang-dev https://golang.org/cl/5332048
This commit is contained in:
parent
bd43eac303
commit
7df9ff5594
@ -1595,6 +1595,14 @@ looktypedot(Node *n, Type *t, int dostrcmp)
|
||||
return 1;
|
||||
}
|
||||
|
||||
static Type*
|
||||
derefall(Type* t)
|
||||
{
|
||||
while(t && t->etype == tptr)
|
||||
t = t->type;
|
||||
return t;
|
||||
}
|
||||
|
||||
static int
|
||||
lookdot(Node *n, Type *t, int dostrcmp)
|
||||
{
|
||||
@ -1652,8 +1660,15 @@ lookdot(Node *n, Type *t, int dostrcmp)
|
||||
n->left = nod(OIND, n->left, N);
|
||||
n->left->implicit = 1;
|
||||
typecheck(&n->left, Etype|Erv);
|
||||
} else if(tt->etype == tptr && tt->type->etype == tptr && eqtype(derefall(tt), rcvr)) {
|
||||
yyerror("calling method %N with receiver %lN requires explicit dereference", n->right, n->left);
|
||||
while(tt->etype == tptr) {
|
||||
n->left = nod(OIND, n->left, N);
|
||||
n->left->implicit = 1;
|
||||
typecheck(&n->left, Etype|Erv);
|
||||
tt = tt->type;
|
||||
}
|
||||
} else {
|
||||
// method is attached to wrong type?
|
||||
fatal("method mismatch: %T for %T", rcvr, tt);
|
||||
}
|
||||
}
|
||||
|
24
test/fixedbugs/bug371.go
Normal file
24
test/fixedbugs/bug371.go
Normal file
@ -0,0 +1,24 @@
|
||||
// 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 2343
|
||||
|
||||
package main
|
||||
|
||||
type T struct {}
|
||||
|
||||
func (t *T) pm() {}
|
||||
func (t T) m() {}
|
||||
|
||||
func main() {
|
||||
p := &T{}
|
||||
p.pm()
|
||||
p.m()
|
||||
|
||||
q := &p
|
||||
q.m() // ERROR "requires explicit dereference"
|
||||
q.pm()
|
||||
}
|
Loading…
Reference in New Issue
Block a user