Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3162 from 9rnsr/fix11447
[REG2.065a] Issue 11447 - Closure provide bogus values
- Loading branch information
Showing
3 changed files
with
86 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} |