Is there any hope for "lazy" and @nogc?
Steven Schveighoffer
schveiguy at gmail.com
Tue Jul 31 15:14:46 UTC 2018
On 7/31/18 3:17 AM, Shachar Shemesh wrote:
> I'm trying to figure out what's the signature of the built-in assert. It
> does not seem that I can define a similar function myself.
>
> First attempt:
> void myAssert(bool cond, string msg) @nogc nothrow;
>
> No, because msg gets evaluated unconditionally.
>
> void myAssert(bool cond, lazy string msg) @nogc nothrow;
>
> test.d(8): Error: @nogc function test.myAssert cannot call non- at nogc
> delegate msg
Hm... I would say compiler should be smart enough to know that lazy
string messages that are not @nogc shouldn't be able to be passed in here.
e.g.:
myAssert(a == b, "a and b should be equal); // ok
myAssert(a == b, a.name ~ " and " ~ b.name ~ " should be equal"); // error
It appears that lazy is not inferring anything, it's strictly
transformed into a normal delegate. I'd say at least the template
solution should be made to work.
-Steve
More information about the Digitalmars-d
mailing list