Bug 7481 – Compiler should 'soldier on' after template errors
Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2012-02-10T22:03:00Z
Last change time
2015-06-09T05:10:45Z
Assigned to
nobody
Creator
clugdbug
Comments
Comment #0 by clugdbug — 2012-02-10T22:03:55Z
At the start of TemplateInstance::semantic is this code:
if (global.errors)
{
//printf("not instantiating %s due to %d errors\n", toChars(), global.errors);
if (!global.gag)
{
/* Trying to soldier on rarely generates useful messages
* at this point.
*/
fatal();
}
It's a hack, really. This has the effect that after ANY error, any template instantiation will abort compilation completely. Back in the Bad Old Days, when the compiler soldiered on, it would spew reams of garbage and then crash. But now, with all of the ErrorExp improvements, soldiering on does in fact generate useful error messages.
If there have been errors in the template arguments, obviously it shouldn't instantiate it, but there's no need to abort compilation completely. More importantly, notice that it *does* continue if errors are gagged. Aborting compilation is hampering our ability to observe what it's doing.
Soldiering on will help make it more robust.
Simple example: this code should generate two errors, one for 'zoo' and one for 'roo'.
int foo(X)(X x) { return 6; }
void main()
{
foo!(zoo)(5);
foo!(double)(roo);
}
Comment #1 by bugzilla — 2012-02-10T23:35:18Z
The place I'd like to get is to continue compiling anything that does not depend on something that already failed. We're partway there with the way expressions are evaluated.
For templates, it should try to instantiate one only if its arguments are free of errors.
Comment #2 by clugdbug — 2012-02-11T00:20:31Z
(In reply to comment #1)
> The place I'd like to get is to continue compiling anything that does not
> depend on something that already failed. We're partway there with the way
> expressions are evaluated.
>
> For templates, it should try to instantiate one only if its arguments are free
> of errors.
That's basically what this patch does.