December 14, 2014 [Issue 13845] Error using alias of typeof(null) as unnamed lambda parameter | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=13845 Peter Alexander <peter.alexander.au@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |peter.alexander.au@gmail.co | |m Component|Phobos |DMD Summary|std.variant.Algebraic |Error using alias of |"__lambda2 is not a |typeof(null) as unnamed |function or delegate" when |lambda parameter |using alias vs. bare type | OS|Windows |All --- Comment #1 from Peter Alexander <peter.alexander.au@gmail.com> --- Reduced: alias Null = typeof(null); auto a = (int) => 0; // ok auto b = (typeof(null)) => 0; // ok auto c = (Null x) => 0; // ok auto d = (Null) => 0; // error Error: variable bug.d type void is inferred from initializer (Null) => 0, and variables cannot be of type void -- |
December 15, 2014 [Issue 13845] Error using alias of typeof(null) as unnamed lambda parameter | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=13845 Kenji Hara <k.hara.pg@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |RESOLVED Resolution|--- |INVALID --- Comment #2 from Kenji Hara <k.hara.pg@gmail.com> --- (In reply to Peter Alexander from comment #1) > alias Null = typeof(null); > auto a = (int) => 0; // ok > auto b = (typeof(null)) => 0; // ok `int` and `typeof(null)` are definitely parsed as types. > auto c = (Null x) => 0; // ok `Null x` is parsed as a parameter, typed Null and parameter name is `x`. > auto d = (Null) => 0; // error > > Error: variable bug.d type void is inferred from initializer (Null) => 0, and variables cannot be of type void If a lambda parameter is an identifier, it's treated as the "parameter name". Therefore it is equivalent with: auto d = (x) => 0; and compiler cannot infer the lambda parameter type so there's no "target" type. -- |
Copyright © 1999-2021 by the D Language Foundation