[Issue 11447] Closure provide bogus values
    d-bugmail at puremagic.com 
    d-bugmail at puremagic.com
       
    Sat Nov 16 12:10:09 PST 2013
    
    
  
https://d.puremagic.com/issues/show_bug.cgi?id=11447
--- Comment #2 from deadalnix <deadalnix at gmail.com> 2013-11-16 12:10:06 PST ---
OK, I've been able to spend some time making this report look better.
a.d :
class A {
}
import std.algorithm;
import std.array;
struct TemplateInstancier {
    auto instanciateFromResolvedArgs(A a) {
        auto bs = [B(a)];
        static A gladeulfeurah;
        gladeulfeurah = a;
        // XXX: have to put array once again to avoid multiple map.
        string id = bs.map!(
            b => b.apply!(
                function string() { assert(0); },
                delegate string(i) {
                    assert(a is gladeulfeurah, "tagazok");
                    return "";
                }
            )
        ).join;
    }
}
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);
    }
}
fail.d:
import a;
void main() {
    auto a = new A();
    TemplateInstancier().instanciateFromResolvedArgs(a);
}
Compile via:
dmd -c -offail.o fail.d -m64 -w -debug -gc
dmd -c -ofa.o a.d -m64 -w -debug -gc
gcc -o fail fail.o a.o -m64 -lphobos2 -export-dynamic -ldl
Run via:
./fail
The program assert fail with the message tagazok. The value of the variable a
in the closure is incorrect.
-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
    
    
More information about the Digitalmars-d-bugs
mailing list