It's very annoying to get a compiler message that consists of nothing but:
" error: ATemplateFunction: int does not have a .length property"
Where ATemplateFunction is something like
void ATemplateFunction(ArrayT)(ArrayT x) {
auto n = x.length;
....
}
Great so I know that *somewhere* in all my source code I called ATemplateFunction with the wrong kind of argument. The compiler knows where it was that I made the call, but it just doesn't care to enlighten me. Very
frustrating.
I seem to recall a discussion at one point where Walter said that template instantiation backtraces make template errors look too complicated. And I can see the reasoning in that, but omitting them entirely is like chopping off the developer's legs just because his toes are cold.
So I have a couple of suggestions:
1) Only print the backtrace when compiling with -v. That way most of the time you don't have to see it. Only when you're really stuck will you pull out the -v guns to figure out what the issue is.
2) Just print out an abbreviated backtrace that consists of only file names and line numbers.
3) Do some combination of 1 and 2.
Comment #1 by kamm-removethis — 2008-12-13T02:18:04Z
Created attachment 281
add basic template instantiation traces
We've added this to LDC a while back and I've attached the original diff. It doesn't cover all cases, but should at least provide a trace for a significant number of in-template errors.
In order to not spam users, we only print long traces completely when -v is given. Otherwise only the first and last three steps in the chain are shown.
Comment #2 by fvbommel — 2009-04-26T15:04:27Z
*** Bug 2902 has been marked as a duplicate of this bug. ***
Comment #3 by smjg — 2009-09-26T11:59:25Z
You have the same typo in three different places:
fprintf(stdmsg," instantiatied in %s: %s\n", cur->loc.toChars(), cur->toChars());
instantiatied -> instantiated
And
while(cur = cur->tinst)
probably ought to be written
while((cur = cur->tinst) != NULL)
to avoid triggering a "possibly incorrect assignment" warning in some compilers.
But I like the idea of defaulting to showing the three instantiation levels at each end of the chain.
Comment #4 by clugdbug — 2010-01-13T08:44:08Z
I think this was fixed in the last release, as part of the 'static assert' patch. Please confirm.