Why is the error message coming by the end of the compilation?

Simen Kjærås simen.kjaras at gmail.com
Sun Apr 15 10:14:56 UTC 2018


On Saturday, 14 April 2018 at 08:20:51 UTC, bauss wrote:
> The problem is I can't pragma(msg) the code I want to mixin 
> manually since all mixins are dynamically generated. That's why 
> my only way is to do it within that static foreach.

Wat.

So the compiler is able to generate the string you want to mixin, 
but not print it?

If you try this:

     static foreach (viewResult; generateViewsResult)
     {
         pragma(msg, "Compiling: " ~ viewResult.name);
         pragma(msg, viewResult.source);
         pragma(msg, "Compiled: " ~ viewResult.name);
     }

Does it blow up? Does it print gibberish? Does it complain in any 
way?


> I initially tried to just use __traits(compiles) but it fails 
> even on the valid generated D code.

This also sounds weird. Are you missing brackets around the 
generated code? If the generated code consists of more than one 
expression, you generally have to check __traits(compiles, { 
mixin(foo()); }).

 From reading your messages here it seems the mixin simply 
contains a class. This test shows the difference:

enum s = "class A {}";

// Global scope:
static assert(!__traits(compiles, mixin(s)));
static assert(__traits(compiles, { mixin(s); }));

unittest {
     // Function scope:
     static assert(!__traits(compiles, mixin(s)));
     static assert(__traits(compiles, { mixin(s); }));
}

As we can see, the version with extra brackets compiles, the 
other does not.


> I wish there was a way to give a mixin some kind of identity 
> like:
> 
> mixin("mymixin", "somecode");
> 
> Where an error message would print something like:
> 
> Error in mixin("mymixin"): ...

That seems like a very good idea. Posted it in D.general:
https://forum.dlang.org/post/epqmzhjoyqcdqrqksuvf@forum.dlang.org

--
   Simen


More information about the Digitalmars-d-learn mailing list