https://issues.dlang.org/show_bug.cgi?id=18058

Maksim Fomin <m...@protonmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |m...@protonmail.com

--- Comment #1 from Maksim Fomin <m...@protonmail.com> ---
Since scope and lazy are poorly specified, it is not surprising that sometime
they behave unexpectedly (and in my experience scope and lazy features are
those which are mostly overlooked). Worse, because of underspecification it is
often unclear whether issue is bug or not.

Compiler seems to fail here:
https://github.com/dlang/dmd/blob/6f99996ba80ad51b37401552be4b3ace7f8e710b/src/ddmd/expressionsem.d#L3481

if (!tf.isnogc && sc.func.setGC())
{
   exp.error("@nogc %s '%s' cannot call non-@nogc %s '%s'",
      sc.func.kind(), sc.func.toPrettyChars(), p, exp.e1.toChars());
   err = true;
}

i.e. because 'func2' formally requires gc.

P.S. Unfortunatelly d developers put almost all efforts to fixing regressions
plus some bugs and leave documentation as it is. The situation has not improved
for many years. 

> This is wrong. Since "msg" is never evaluated, the fact that it is not 
> @nogc should not matter.

Why? Accordging to the spec closure must be always allocated regarless of scope
(of course, this can be proposed as an improvement). 

> The second problem is that the lowering is overly complicated. Instead
> of lowering to:

Again, currently compiler behaves according to the spec (in my understanding).
If you prefer option 1 you can write it explicitly.

--

Reply via email to