Skip to content

Commit

Permalink
Merge pull request #2548 from 9rnsr/fix10666
Browse files Browse the repository at this point in the history
Partial fix for Issue 10666 - Appender does not work with a RefCounted type
  • Loading branch information
WalterBright committed Sep 15, 2013
2 parents c3cc007 + 59af1d0 commit aea5806
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 6 deletions.
19 changes: 13 additions & 6 deletions src/expression.c
Expand Up @@ -8385,10 +8385,10 @@ Expression *CallExp::semantic(Scope *sc)
#endif

if (e1->op == TOKcomma)
{ /* Rewrite (a,b)(args) as (a,(b(args)))
{
/* Rewrite (a,b)(args) as (a,(b(args)))
*/
CommaExp *ce = (CommaExp *)e1;

e1 = ce->e2;
e1->type = ce->type;
ce->e2 = this;
Expand All @@ -8397,15 +8397,15 @@ Expression *CallExp::semantic(Scope *sc)
}

if (e1->op == TOKdelegate)
{ DelegateExp *de = (DelegateExp *)e1;

{
DelegateExp *de = (DelegateExp *)e1;
e1 = new DotVarExp(de->loc, de->e1, de->func);
return semantic(sc);
}

if (e1->op == TOKfunction)
{ FuncExp *fe = (FuncExp *)e1;

{
FuncExp *fe = (FuncExp *)e1;
arguments = arrayExpressionSemantic(arguments, sc);
preFunctionParameters(loc, sc, arguments);
e1 = fe->semantic(sc, arguments);
Expand Down Expand Up @@ -9160,6 +9160,13 @@ Expression *CallExp::semantic(Scope *sc)
}
}

// Handle the case of a direct lambda call
if (f && f->isFuncLiteralDeclaration() &&
sc->func && !sc->intypeof)
{
f->tookAddressOf = 0;
}

return this;
}

Expand Down
22 changes: 22 additions & 0 deletions test/fail_compilation/fail10666.d
@@ -0,0 +1,22 @@
// REQUIRED_ARGS: -c
/*
TEST_OUTPUT:
---
fail_compilation/fail10666.d(16): Error: variable fail10666.foo10666.s1 has scoped destruction, cannot build closure
---
*/


struct S10666
{
int val;
~this() {}
}

void foo10666(S10666 s1)
{
auto f1 = (){ return () => s1.val; }(); // NG

S10666 s2;
auto f2 = (){ return () => s2.val; }(); // (should be NG)
}
20 changes: 20 additions & 0 deletions test/runnable/funclit.d
Expand Up @@ -822,6 +822,26 @@ void test10288() @safe pure nothrow
static assert(!__traits(compiles, baz10288(10)));
}

/***************************************************/
// 10666

struct S10666
{
int val;
~this() {}
}

void foo10666(S10666 s1)
{
S10666 s2;

/* Even if closureVars(s1 and s2) are accessed by directly called lambdas,
* they won't escape the scope of this function.
*/
auto x1 = (){ return s1.val; }(); // OK
auto x2 = (){ return s2.val; }(); // OK
}

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

int main()
Expand Down

0 comments on commit aea5806

Please sign in to comment.