Skip to content

Commit

Permalink
Merge pull request #5523 from 9rnsr/fix15794
Browse files Browse the repository at this point in the history
Issue 15794 - Lambda cannot get a chance to run its codegen
  • Loading branch information
WalterBright committed Mar 15, 2016
2 parents 558a0f2 + 23c957a commit e9073a7
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 9 deletions.
3 changes: 3 additions & 0 deletions src/declaration.h
Expand Up @@ -695,6 +695,9 @@ class FuncLiteralDeclaration : public FuncDeclaration
TOK tok; // TOKfunction or TOKdelegate
Type *treq; // target of return type inference

// backend
bool deferToObj;

FuncLiteralDeclaration(Loc loc, Loc endloc, Type *type, TOK tok,
ForeachStatement *fes, Identifier *id = NULL);
Dsymbol *syntaxCopy(Dsymbol *);
Expand Down
29 changes: 20 additions & 9 deletions src/e2ir.c
Expand Up @@ -978,6 +978,11 @@ elem *toElem(Expression *e, IRState *irs)
fld->tok = TOKfunction;
fld->vthis = NULL;
}
if (!fld->deferToObj)
{
fld->deferToObj = true;
irs->deferToObj->push(fld);
}
}

Symbol *s = toSymbol(se->var);
Expand Down Expand Up @@ -1159,22 +1164,28 @@ elem *toElem(Expression *e, IRState *irs)
void visit(FuncExp *fe)
{
//printf("FuncExp::toElem() %s\n", fe->toChars());
if (fe->fd->tok == TOKreserved && fe->type->ty == Tpointer)
FuncLiteralDeclaration *fld = fe->fd;

if (fld->tok == TOKreserved && fe->type->ty == Tpointer)
{
// change to non-nested
fe->fd->tok = TOKfunction;
fe->fd->vthis = NULL;
fld->tok = TOKfunction;
fld->vthis = NULL;
}
Symbol *s = toSymbol(fe->fd);
if (!fld->deferToObj)
{
fld->deferToObj = true;
irs->deferToObj->push(fld);
}

Symbol *s = toSymbol(fld);
elem *e = el_ptr(s);
if (fe->fd->isNested())
if (fld->isNested())
{
elem *ethis = getEthis(fe->loc, irs, fe->fd);
elem *ethis = getEthis(fe->loc, irs, fld);
e = el_pair(TYdelegate, ethis, e);
}

irs->deferToObj->push(fe->fd);
el_setLoc(e,fe->loc);
el_setLoc(e, fe->loc);
result = e;
}

Expand Down
3 changes: 3 additions & 0 deletions src/func.d
Expand Up @@ -4411,6 +4411,9 @@ public:
TOK tok; // TOKfunction or TOKdelegate
Type treq; // target of return type inference

// backend
bool deferToObj;

extern (D) this(Loc loc, Loc endloc, Type type, TOK tok, ForeachStatement fes, Identifier id = null)
{
super(loc, endloc, null, STCundefined, type);
Expand Down
27 changes: 27 additions & 0 deletions test/runnable/funclit.d
Expand Up @@ -1199,6 +1199,32 @@ void test14745()
static assert(is(typeof(dg2) : typeof(&foo2)));
}

/***************************************************/
// 15794

struct Foo15794
{
static void fun(Holder)()
{
int i = Holder.fn();
}
}

struct Holder15794(alias Fn)
{
alias fn = Fn;
}

void gun15794(alias fn, U...)()
{
Foo15794.fun!(Holder15794!fn)();
}

void test15794()
{
gun15794!(() => 0)(); // Line 26
}

/***************************************************/

int main()
Expand Down Expand Up @@ -1256,6 +1282,7 @@ int main()
test12508();
test13879();
test14745();
test15794();

printf("Success\n");
return 0;
Expand Down

0 comments on commit e9073a7

Please sign in to comment.