fakethis(void)
{
Node *n;
- Type *t;
n = nod(ODCLFIELD, N, N);
- t = dostruct(N, TSTRUCT);
- t = ptrto(t);
- n->type = t;
+ n->type = ptrto(typ(TSTRUCT));
return n;
}
+/*
+ * Is this field a method on an interface?
+ * Those methods have an anonymous
+ * *struct{} as the receiver.
+ * (See fakethis above.)
+ */
+int
+isifacemethod(Type *f)
+{
+ Type *rcvr;
+ Type *t;
+
+ rcvr = getthisx(f->type)->type;
+ if(rcvr->sym != S)
+ return 0;
+ t = rcvr->type;
+ if(!isptr[t->etype])
+ return 0;
+ t = t->type;
+ if(t->sym != S || t->etype != TSTRUCT || t->type != T)
+ return 0;
+ return 1;
+}
+
/*
* this generates a new name that is
* pushed down on the declaration list.
void addtyp(Type*, int);
void addconst(Node*, Node*, int);
Node* fakethis(void);
+int isifacemethod(Type*);
Node* newname(Sym*);
Node* oldname(Sym*);
Type* newtype(Sym*);
// get receiver type for this particular method.
this = getthisx(f->type)->type->type;
- if(f->embedded != 2 && isptr[this->etype] && !isptr[progt->etype]) {
+ if(f->embedded != 2 && isptr[this->etype] && !isptr[progt->etype] && !isifacemethod(f)) {
// pointer receiver method but value method set.
// ignore.
if(debug['r'])
// but we can generate more efficient code
// using genembedtramp if all that is necessary
// is a pointer adjustment and a JMP.
- if(f->embedded && isptr[ifacet->etype])
+ if(f->embedded && isptr[ifacet->etype] && !isifacemethod(f))
genembedtramp(ifacet, a);
else
genwrapper(ifacet, f, a->sym);
u = u->type;
}
+ if(u->etype == TINTER) {
+ for(f=u->type; f!=T; f=f->down) {
+ if(!exportname(f->sym->name) && strcmp(f->sym->opackage, package) != 0)
+ continue;
+ if(f->sym->uniq)
+ continue;
+ f->sym->uniq = 1;
+ sl = mal(sizeof(*sl));
+ sl->field = f;
+ sl->link = slist;
+ sl->followptr = followptr;
+ slist = sl;
+ }
+ return;
+ }
+
u = methtype(t);
if(u != T) {
for(f=u->method; f!=T; f=f->down) {
// if pointer receiver in method,
// the method does not exist for value types.
rcvr = getthisx(tm->type)->type->type;
- if(isptr[rcvr->etype] && !isptr[t0->etype] && !followptr) {
+ if(isptr[rcvr->etype] && !isptr[t0->etype] && !followptr && !isifacemethod(tm)) {
if(debug['r'])
yyerror("interface pointer mismatch");
*m = im;
case TMAP:
case TSTRING:
case TARRAY:
+ case TINTER:
break;
default:
return;
n->right = f1->nname; // substitute real name
n->xoffset = f1->width;
n->type = f1->type;
- if(t->etype == TINTER)
+ if(t->etype == TINTER) {
+ implicitstar(&n->left);
n->op = ODOTINTER;
+ }
return 1;
}
if(l != N || r != T)
yyerror("assignment count mismatch: %d = %d",
listcount(*nl), structcount(*nr));
-
+
return rev(nn);
}