Fear of Compiler Magic
Quirin Schroll
qs.il.paperinik at gmail.com
Mon Aug 5 11:05:21 UTC 2024
On Friday, 2 August 2024 at 08:34:39 UTC, Timon Gehr wrote:
> On 8/2/24 05:22, IchorDev wrote:
>> I hear people complain about compiler magic a lot.
>
> Probably this is partially inspired from here:
> https://dconf.org/2018/talks/alexandrescu.html
>
>> Yes, being able to do everything in-language is nice, but
>> compiler magic is inevitable and also can be very useful.
>> `assert` is my favourite example.
>
> int foo(){ enforce(0); } // error
> int foo(){ assert(0); } // ok
>
> "No compiler magic" would e.g. mean: `enforce` can similarly
> influence definite return analysis. It's not inevitable that
> this is impossible.
This specific case could be solved with Enum Parameters:
`enforce` could detect `0` (or `false`) specifically and return
type `noreturn`.
More information about the Digitalmars-d
mailing list