[Issue 18058] @nogc and forwarding lazy argument, particularly with scope

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon Dec 11 16:58:41 UTC 2017


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

Maksim Fomin <mxfm at protonmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |mxfm at protonmail.com

--- Comment #1 from Maksim Fomin <mxfm at 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- at 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.

--


More information about the Digitalmars-d-bugs mailing list