Skip to content

Commit

Permalink
Merge pull request #3162 from 9rnsr/fix11447
Browse files Browse the repository at this point in the history
[REG2.065a] Issue 11447 - Closure provide bogus values
  • Loading branch information
WalterBright committed Jan 27, 2014
2 parents 5c68e57 + 0cfb7aa commit b7590ed
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/func.c
Expand Up @@ -3796,8 +3796,15 @@ bool FuncDeclaration::needsCodegen()
{
assert(semanticRun == PASSsemantic3done);

if (!isInstantiated() && inNonRoot())
return false;
for (FuncDeclaration *fd = this; fd; )
{
if (!fd->isInstantiated() && fd->inNonRoot())
return false;
if (fd->isNested())
fd = fd->toParent2()->isFuncDeclaration();
else
break;
}

if (global.params.useUnitTests ||
global.params.allInst ||
Expand Down
66 changes: 66 additions & 0 deletions test/runnable/imports/c11447.d
@@ -0,0 +1,66 @@
template map(fun...)
{
auto map(Range)(Range r)
{
return MapResult!(fun, Range)(r);
}
}
private struct MapResult(alias fun, R)
{
R _input;
this(R input) { _input = input; }
@property bool empty() { return _input.length == 0; }
@property auto ref front() { return fun(_input[0]); }
void popFront() { _input = _input[1..$]; }
}

class A {}

struct TemplateInstancier
{
auto instanciateFromResolvedArgs(A a)
{
auto bs = [B(a)];

static A gladeulfeurah;
gladeulfeurah = a;

auto r = bs.map!(
b => b.apply!(
function string() { assert(0); },
delegate string(i) {
assert(a is gladeulfeurah, "tagazok");
return "";
}
)
);

foreach (e; r) {}
}
}

enum Tag { Undefined, A, }

struct B
{
A a;
Tag tag;

this(A a)
{
tag = Tag.A;
this.a = a;
}
}

auto apply(alias undefinedHandler, alias handler)(B b)
{
final switch(b.tag) with(Tag)
{
case Undefined :
return undefinedHandler();

case A :
return handler(b.a);
}
}
11 changes: 11 additions & 0 deletions test/runnable/test11447c.d
@@ -0,0 +1,11 @@
// COMPILE_SEPARATELY
// EXTRA_SOURCES: imports/c11447.d
// PERMUTE_ARGS: -allinst -w -debug -gc

import imports.c11447;

void main()
{
auto a = new A();
TemplateInstancier().instanciateFromResolvedArgs(a);
}

0 comments on commit b7590ed

Please sign in to comment.