Commit 7df9ff55 authored by Luuk van Dijk's avatar Luuk van Dijk

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
parent bd43eac3
......@@ -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);
}
}
......
// 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()
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment