"Error: `TypeInfo` cannot be used with -betterC" on a CTFE function

Liam McGillivray yoshi.pit.link.mario at gmail.com
Wed Apr 10 02:50:15 UTC 2024


On Tuesday, 9 April 2024 at 23:50:36 UTC, Richard (Rikki) Andrew 
Cattermole wrote:
> The string mixin triggers CTFE, if ``EnumPrefixes`` wasn't 
> templated, that would cause codegen and hence error. If you 
> called it in a context that wasn't CTFE only, it would codegen 
> even with template and would error.
>
> For quite a long time we emitted -betterC errors during 
> semantic, we learned that this was all around a bad idea and 
> moved (hopefully all but I doubt it) into the glue code. So 
> only if it codegens will it error.

Well then, perhaps this is a bug (though a useful bug in my case).

If you want to investigate, you can download [this 
commit](https://github.com/LiamM32/raylib-d/blob/49a8f2a2e4285fc85b9db54ae9a49cafe8b1a5ed) of Raylib-D. The DUB package in the `rayguiexample` directory has `betterC` as a build option, yet doesn't have this error. This is despite the inclusion of a CTFE function with string appending.

It's in 
[`source/raylib/package.d`](https://github.com/LiamM32/raylib-d/blob/49a8f2a2e4285fc85b9db54ae9a49cafe8b1a5ed/source/raylib/package.d) where `mixin(EnumPrefixes!Key("KeyboardKey", "KEY_"));` appears. The definition of `EnumPrefixes` is in [`source/templates.d`](https://github.com/LiamM32/raylib-d/blob/49a8f2a2e4285fc85b9db54ae9a49cafe8b1a5ed/source/templates.d).


More information about the Digitalmars-d-learn mailing list