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) ...@@ -771,7 +771,6 @@ structfield(Node *n)
break; break;
} }
// tofunarg will undo this for _ arguments
if(n->left && n->left->op == ONAME) { if(n->left && n->left->op == ONAME) {
f->nname = n->left; f->nname = n->left;
f->embedded = n->embedded; f->embedded = n->embedded;
...@@ -840,13 +839,6 @@ tofunargs(NodeList *l) ...@@ -840,13 +839,6 @@ tofunargs(NodeList *l)
for(tp = &t->type; l; l=l->next) { for(tp = &t->type; l; l=l->next) {
f = structfield(l->n); 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. // esc.c needs to find f given a PPARAM to add the tag.
if(l->n->left && l->n->left->class == PPARAM) if(l->n->left && l->n->left->class == PPARAM)
l->n->left->paramfld = f; l->n->left->paramfld = f;
......
...@@ -2226,13 +2226,12 @@ structargs(Type **tl, int mustname) ...@@ -2226,13 +2226,12 @@ structargs(Type **tl, int mustname)
gen = 0; gen = 0;
for(t = structfirst(&savet, tl); t != T; t = structnext(&savet)) { for(t = structfirst(&savet, tl); t != T; t = structnext(&savet)) {
n = N; n = N;
if(t->sym) if(mustname && (t->sym == nil || strcmp(t->sym->name, "_") == 0)) {
n = newname(t->sym); // invent a name so that we can refer to it in the trampoline
else if(mustname) {
// have to give it a name so we can refer to it in trampoline
snprint(buf, sizeof buf, ".anon%d", gen++); snprint(buf, sizeof buf, ".anon%d", gen++);
n = newname(lookup(buf)); n = newname(lookup(buf));
} } else if(t->sym)
n = newname(t->sym);
a = nod(ODCLFIELD, n, typenod(t->type)); a = nod(ODCLFIELD, n, typenod(t->type));
a->isddd = t->isddd; a->isddd = t->isddd;
if(n != N) if(n != N)
...@@ -2274,7 +2273,7 @@ genwrapper(Type *rcvr, Type *method, Sym *newnam, int iface) ...@@ -2274,7 +2273,7 @@ genwrapper(Type *rcvr, Type *method, Sym *newnam, int iface)
int isddd; int isddd;
Val v; Val v;
if(0 && debug['r']) if(debug['r'])
print("genwrapper rcvrtype=%T method=%T newnam=%S\n", print("genwrapper rcvrtype=%T method=%T newnam=%S\n",
rcvr, method, newnam); rcvr, method, newnam);
......
...@@ -2465,6 +2465,7 @@ static void ...@@ -2465,6 +2465,7 @@ static void
domethod(Node *n) domethod(Node *n)
{ {
Node *nt; Node *nt;
Type *t;
nt = n->type->nname; nt = n->type->nname;
typecheck(&nt, Etype); typecheck(&nt, Etype);
...@@ -2474,6 +2475,20 @@ domethod(Node *n) ...@@ -2474,6 +2475,20 @@ domethod(Node *n)
n->type->nod = N; n->type->nod = N;
return; 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 = *nt->type;
n->type->nod = N; n->type->nod = N;
checkwidth(n->type); checkwidth(n->type);
......
...@@ -101,6 +101,29 @@ func main() { ...@@ -101,6 +101,29 @@ func main() {
} }
h(a, b) 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 // useless but legal
...@@ -120,3 +143,4 @@ func _() { ...@@ -120,3 +143,4 @@ func _() {
func ff() { func ff() {
var _ int = 1 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