lazy variables cannot be lvalues - why?

Adam Cigánek adam.ciganek at
Mon Nov 1 08:57:09 PDT 2010


why is the following code illegal?

  import std.stdio;

  void delegate() fun;

  void capture(lazy void f) {
    fun = &f;

  void main() {

It says "Error: lazy variables cannot be lvalues", pointing to the
"fun = &f" line.

It can be worked around by rewriting it like this:

void capture(lazy void f) {
  fun = delegate void() { f(); };

So it's not big deal, just a minor inconvenience. But still, why is it
illegal? According to the docs
(, lazy
expressions are implicitly converted to delegates, so it seems to me
that it should work.


More information about the Digitalmars-d-learn mailing list