Commit 8e515485 authored by Russ Cox's avatar Russ Cox

gc: remove funarg special case in structfield

This should make CL 5431046 a little simpler.

R=ken2
CC=golang-dev
https://golang.org/cl/5444048
parent c8d2544b
......@@ -771,7 +771,6 @@ structfield(Node *n)
break;
}
// tofunarg will undo this for _ arguments
if(n->left && n->left->op == ONAME) {
f->nname = n->left;
f->embedded = n->embedded;
......@@ -840,13 +839,6 @@ tofunargs(NodeList *l)
for(tp = &t->type; l; l=l->next) {
f = structfield(l->n);
// Unlink the name for _ arguments.
if(l->n->left && l->n->left->op == ONAME && isblank(l->n->left)) {
f->nname = nil;
f->sym = nil;
f->embedded = 0;
}
// esc.c needs to find f given a PPARAM to add the tag.
if(l->n->left && l->n->left->class == PPARAM)
l->n->left->paramfld = f;
......
......@@ -2226,13 +2226,12 @@ structargs(Type **tl, int mustname)
gen = 0;
for(t = structfirst(&savet, tl); t != T; t = structnext(&savet)) {
n = N;
if(t->sym)
n = newname(t->sym);
else if(mustname) {
// have to give it a name so we can refer to it in trampoline
if(mustname && (t->sym == nil || strcmp(t->sym->name, "_") == 0)) {
// invent a name so that we can refer to it in the trampoline
snprint(buf, sizeof buf, ".anon%d", gen++);
n = newname(lookup(buf));
}
} else if(t->sym)
n = newname(t->sym);
a = nod(ODCLFIELD, n, typenod(t->type));
a->isddd = t->isddd;
if(n != N)
......@@ -2274,7 +2273,7 @@ genwrapper(Type *rcvr, Type *method, Sym *newnam, int iface)
int isddd;
Val v;
if(0 && debug['r'])
if(debug['r'])
print("genwrapper rcvrtype=%T method=%T newnam=%S\n",
rcvr, method, newnam);
......
......@@ -2465,6 +2465,7 @@ static void
domethod(Node *n)
{
Node *nt;
Type *t;
nt = n->type->nname;
typecheck(&nt, Etype);
......@@ -2474,6 +2475,20 @@ domethod(Node *n)
n->type->nod = N;
return;
}
// If we have
// type I interface {
// M(_ int)
// }
// then even though I.M looks like it doesn't care about the
// value of its argument, a specific implementation of I may
// care. The _ would suppress the assignment to that argument
// while generating a call, so remove it.
for(t=getinargx(nt->type)->type; t; t=t->down) {
if(t->sym != nil && strcmp(t->sym->name, "_") == 0)
t->sym = nil;
}
*n->type = *nt->type;
n->type->nod = N;
checkwidth(n->type);
......
......@@ -101,6 +101,29 @@ func main() {
}
h(a, b)
m()
}
type I interface {
M(_ int, y int)
}
type TI struct{}
func (TI) M(x int, y int) {
if x != y {
println("invalid M call:", x, y)
panic("bad M")
}
}
func m() {
var i I
i = TI{}
i.M(1, 1)
i.M(2, 2)
}
// useless but legal
......@@ -120,3 +143,4 @@ func _() {
func ff() {
var _ int = 1
}
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