strage heisenbug (has scoped destruction, cannot build closure)

ketmar via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon Mar 2 23:26:13 PST 2015


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 () {
  }
======

the strange thing is that this is heisenbug. if i comment out `static if` 
the module successfully compiles. i.e. changing `zcompress()` to this 
allows me to compile the code:

===
  void zcompress(RO) (RO ro) {
    ubyte[1] obuf;

    void writeOBuf () {
      ro.put(obuf);
    }

    writeOBuf();
  }
===

so the offending line is `ro.put(b);` (comment it out, and everything is 
working again).

am i doing something very wrong here, or this is really a compiler bug?
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: not available
URL: <http://lists.puremagic.com/pipermail/digitalmars-d-learn/attachments/20150303/a402550f/attachment-0001.sig>


More information about the Digitalmars-d-learn mailing list