Alternative to __traits(compiles)
bauss
jj_1337 at live.dk
Tue Oct 17 18:59:56 UTC 2017
Could we have an alternative version to __traits(compiles) that
will give you the compiler errors?
Something like:
enum compilerErrors = __traits(compilerErrors, mixin(code));
// compilerErrors should be null if there are no errors.
static if (compilerErrors)
{
pragma(msg, "Failed to compile code.");
pragma(msg, compilerErrors);
pragma(msg, code);
}
else
{
mixin(code);
}
The closest to the above is doing the following with
__traits(compiles):
mixin(code);
static if (!__traits(compiles, mixin(code))
{
pragma(msg, "Failed to compile code.");
pragma(msg, code);
}
But it just doesn't satisfy the order of message printing as the
compiler errors are printed after the pragma(msg) calls. That way
if you're compiling multiple pieces of long code it becomes kinda
hard trying to read your error messages, where the first approach
will let you print them in the order you need them.
It would be a really helpful thing in the combat of mixins vs
error messages.
What do you think?
More information about the Digitalmars-d
mailing list