www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 12664] New: nogc for lazy arguments too

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

          Issue ID: 12664
           Summary:  nogc for lazy arguments too
           Product: D
           Version: D2
          Hardware: x86
                OS: Windows
            Status: NEW
          Keywords: rejects-valid
          Severity: normal
          Priority: P1
         Component: DMD
          Assignee: nobody puremagic.com
          Reporter: bearophile_hugs eml.cc

(Issue understood with a little help from Dicebot.)

This compiles:


void foo(int delegate()  nogc x)  nogc {
    auto r = x();
}
void main() {
    foo(() => 1);
}



This too compiles, performing inference:

void foo(Deleg)(Deleg x)  nogc {
    auto r = x();
}
void main() {
    foo(() => 1);
}


But this code:


void foo(lazy int x)  nogc {
    auto r = x(); // Error
}
void main() {
    foo(1);
}


Gives with DMD 2.066alpha:

test.d(2,15): Error:  nogc function 'test.foo' cannot call non- nogc delegate
'x'


I think the third program should compile.

--
Apr 27 2014