ch-ch-changes
Nick Sabalausky
a at a.a
Wed Jan 28 23:41:00 PST 2009
"Daniel Keep" <daniel.keep.lists at gmail.com> wrote in message
news:glrlgi$2bu4$1 at digitalmars.com...
>
>
> Nick Sabalausky wrote:
>> "Daniel Keep" <daniel.keep.lists at gmail.com> wrote in message
>> news:glqu65$15pi$1 at digitalmars.com...
>>>
>>> Christopher Wright wrote:
>>>> Don wrote:
>>>>> [snip]
>>>>>
>>>>> Then we get:
>>>>> static assert(__traits(mixincompiles, comp), "Predicate: " ~ comp ~ "
>>>>> does not compile");
>>>>>
>>>>> mxin(comp);
>>>> That's certainly prettier.
>>> Still doesn't give the user a reason for WHY their predicate didn't
>>> compile...
>>>
>>> It's a pity we can't do this (or something similar):
>>>
>>> template Something(string comp)
>>> {
>>> static assert( __traits(mixincompiles, comp),
>>> "Predicate q{"~comp~"} does not compile, because:\n"
>>> ~__traits(mixinerrors, comp,
>>> Something.instantiationFile,
>>> Something.instantiationLine) );
>>> }
>>>
>>> -- Daniel
>>
>> I'd much rather see errors and static asserts inside of a template cause
>> the
>> compiler to automatically output a template instantiation "stack trace"
>> (for
>> lack of a better term). Ie, list files/lines starting with the deepest
>> file/line, and then the file/line that instantiated that template, and if
>> that was also inside a template, then the file/line that instantiated
>> that,
>> etc.
>
> I'd certainly like to see better error reporting for template errors,
> but I think the ultimate goal should be to be able to write template
> that, when they do something wrong, can tell the user SPECIFICALLY what
> they did wrong.
>
I would think those two things would compliment each other nicely. To modify
your examples:
template Something(string comp)
{
static assert( __traits(mixincompiles, comp),
"Predicate q{"~comp~"} does not compile, because:\n"
~__traits(mixinerrors, comp) );
}
Result:
Predicate blah does not compile, because: blah
file/line of static assert
file/line where Something was actually instantiated
My main original point is just that the writer of the meaningful diagnostic
message shouldn't have to manually deal with the file/line that attempted
the failed instatiation. It should just simply get shown by the compiler
saying "Error or static asset failure inside a template? I'd better spit out
*both* relevant files/lines along with the error/assert message". The
programmer shouldn't have to do that manually.
More information about the Digitalmars-d
mailing list