Request for Comment assert(__ctfe)

Timon Gehr timon.gehr at gmx.ch
Mon Apr 6 01:28:19 UTC 2020


On 06.04.20 00:12, Stefan Koch wrote:
> On Sunday, 5 April 2020 at 20:54:03 UTC, Meta wrote:
>> On Sunday, 5 April 2020 at 20:31:15 UTC, Timon Gehr wrote:
>>> On 05.04.20 14:11, Stefan Koch wrote:
>>>> [...]
>>>
>>> Make sure it works with `in` contracts:
>>>
>>> string generateMixin(string[] params)in{
>>>     assert(__ctfe);
>>> }do{
>>>     .... more code ....
>>> }
>>>
>>> (The plain assertion slightly hurts my eyes, because if it fails, 
>>> that failure would be attributable to the GenerateMixin function, 
>>> whereas with the `in` contract it is clear that the caller is at fault.)
>>
>> We likely get the shorthand version for free as well:
>> string generateMixin(...)
>> in(__ctfe)
>> {
>>    ...
>> }
> 
> No. the in contract was already a pain in the butt.

I don't understand how you would implement it in a way where the above 
does not work. Have you tested it? I am literally rewriting `in(__ctfe)` 
to `in{ assert(__ctfe); }` in the parser:

https://github.com/dlang/dmd/blob/master/src/dmd/parse.d#L5060


More information about the Digitalmars-d mailing list