digitalmars.D.learn - Delegate type inferred as pure
- cal (13/13) Jan 27 2013 This fails:
- qznc (3/16) Jan 28 2013 Do you really need the type? You could just use "auto".
- cal (3/7) Jan 28 2013 Yeah this is reduced from something I'd like to use typeof for,
- Kenji Hara (3/16) Jan 28 2013 Filed:
This fails: void main() { int z; typeof((int a){return z;}) dg; dg = (int a) {return z;}; } Error: cannot implicitly convert expression (__lambda2) of type int delegate(int a) nothrow safe to int delegate(int a) pure nothrow safe But I can't make the delegate pure: dg = (int a) pure {return z;}; because it references z. Is the 'typeof((int a){return z;})' getting it wrong here?
Jan 27 2013
On Monday, 28 January 2013 at 03:16:24 UTC, cal wrote:This fails: void main() { int z; typeof((int a){return z;}) dg; dg = (int a) {return z;}; } Error: cannot implicitly convert expression (__lambda2) of type int delegate(int a) nothrow safe to int delegate(int a) pure nothrow safe But I can't make the delegate pure: dg = (int a) pure {return z;}; because it references z. Is the 'typeof((int a){return z;})' getting it wrong here?Do you really need the type? You could just use "auto". auto dg = (int a) {return z;};
Jan 28 2013
On Monday, 28 January 2013 at 10:44:22 UTC, qznc wrote:On Monday, 28 January 2013 at 03:16:24 UTC, cal wrote:Yeah this is reduced from something I'd like to use typeof for, usually auto would be fine like you say.Is the 'typeof((int a){return z;})' getting it wrong here?Do you really need the type? You could just use "auto". auto dg = (int a) {return z;};
Jan 28 2013
On Monday, 28 January 2013 at 03:16:24 UTC, cal wrote:This fails: void main() { int z; typeof((int a){return z;}) dg; dg = (int a) {return z;}; } Error: cannot implicitly convert expression (__lambda2) of type int delegate(int a) nothrow safe to int delegate(int a) pure nothrow safe But I can't make the delegate pure: dg = (int a) pure {return z;}; because it references z. Is the 'typeof((int a){return z;})' getting it wrong here?Filed: http://d.puremagic.com/issues/show_bug.cgi?id=9415
Jan 28 2013