strage heisenbug (has scoped destruction, cannot build closure)

anonymous via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Mar 3 06:02:51 PST 2015


On Tuesday, 3 March 2015 at 07:26:13 UTC, ketmar wrote:
> hi.
>
> the following (manually "dustmited" ;-)) code gives the error 
> from subj
> on git HEAD:
>
> === ztest.d ===
>   module ztest;
>
>   auto streamAsRange(STP) (STP st) {
>     static struct StreamRange(ST) {
>     private:
>       ST strm;
>     public:
>       void put (const(ubyte)[] data) { strm.rawWrite(data); }
>     }
>     return StreamRange!STP();
>   }
>
>   void zcompress(RO) (RO ro) {
>     ubyte[1] obuf;
>
>     void writeOBuf () {
>       static if (is(typeof(() {
>         ubyte[2] b;
>         ro.put(b);
>       }))) {
>         ro.put(obuf);
>       }
>     }
>
>     writeOBuf();
>   }
>
>   void test () {
>     import std.stdio;
>     auto fo = File();
>     zcompress(streamAsRange(fo));
>   }
>
>   void main () {
>   }
> ======

Reduced further:

----
module ztest;

struct StreamRange {
   ~this() {}
   void put() {}
}

void zcompress(StreamRange ro) {
   void writeOBuf() {
     enum e = is(typeof({ro.put();}));
     ro.put();
   }
   writeOBuf();
}

void main() {
   zcompress(StreamRange());
}
----

Looks like a compiler bug to me.


More information about the Digitalmars-d-learn mailing list