Skip to content

Commit

Permalink
Merge pull request #3833 from 9rnsr/fix13220
Browse files Browse the repository at this point in the history
[REG2.066a] Issue 13220 - [ICE] 'global.gaggedErrors || global.errors' on line 750 in file 'statement.c'
  • Loading branch information
WalterBright authored and 9rnsr committed Jul 30, 2014
1 parent 01bab81 commit 7119ce5
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 76 deletions.
110 changes: 41 additions & 69 deletions src/expression.c
Expand Up @@ -381,11 +381,7 @@ Expression *resolvePropertiesX(Scope *sc, Expression *e1, Expression *e2 = NULL)
{
//assert(ti->needsTypeInference(sc));
if (!ti->semanticTiargs(sc))
{
ti->inst = ti;
ti->inst->errors = true;
goto Leprop;
}
tiargs = ti->tiargs;
tthis = NULL;
if ((os = ti->tempdecl->isOverloadSet()) != NULL)
Expand Down Expand Up @@ -3344,13 +3340,12 @@ Expression *DsymbolExp::semantic(Scope *sc)

if (TemplateInstance *ti = s->isTemplateInstance())
{
if (!ti->semanticRun)
ti->semantic(sc);
ti->semantic(sc);
if (!ti->inst || ti->errors)
return new ErrorExp();
s = ti->toAlias();
if (!s->isTemplateInstance())
goto Lagain;
if (ti->errors)
return new ErrorExp();
e = new ScopeExp(loc, ti);
e = e->semantic(sc);
return e;
Expand Down Expand Up @@ -4562,8 +4557,6 @@ Expression *ScopeExp::semantic(Scope *sc)
if (!ti->findTempDecl(sc, &withsym) ||
!ti->semanticTiargs(sc))
{
ti->inst = ti;
ti->inst->errors = true;
return new ErrorExp();
}
if (withsym && withsym->withstate->wthis)
Expand All @@ -4572,8 +4565,7 @@ Expression *ScopeExp::semantic(Scope *sc)
e = new DotTemplateInstanceExp(loc, e, ti);
return e->semantic(sc);
}
if (!ti->semanticRun &&
ti->needsTypeInference(sc))
if (ti->needsTypeInference(sc))
{
if (TemplateDeclaration *td = ti->tempdecl->isTemplateDeclaration())
{
Expand All @@ -4599,13 +4591,12 @@ Expression *ScopeExp::semantic(Scope *sc)
}
return this;
}
if (!ti->semanticRun)
ti->semantic(sc);
if (ti->inst)
ti->semantic(sc);
if (!ti->inst || ti->errors)
return new ErrorExp();

{
if (ti->inst->errors)
return new ErrorExp();
Dsymbol *s = ti->inst->toAlias();
Dsymbol *s = ti->toAlias();
ScopeDsymbol *sds2 = s->isScopeDsymbol();
if (!sds2)
{
Expand Down Expand Up @@ -7845,30 +7836,26 @@ Expression *DotTemplateInstanceExp::semanticY(Scope *sc, int flag)
}
else if (OverDeclaration *od = dve->var->isOverDeclaration())
{
e1 = dve->e1; // pull semantic() result
if (!findTempDecl(sc))
goto Lerr;
Expression *eleft = dve->e1;
if (ti->needsTypeInference(sc))
{
e1 = eleft;
return this;
}
else
ti->semantic(sc);
if (!ti->inst) // if template failed to expand
ti->semantic(sc);
if (!ti->inst || ti->errors) // if template failed to expand
return new ErrorExp();
Dsymbol *s = ti->inst->toAlias();
Dsymbol *s = ti->toAlias();
Declaration *v = s->isDeclaration();
if (v)
{
if (v->type && !v->type->deco)
v->type = v->type->semantic(v->loc, sc);
e = new DotVarExp(loc, eleft, v);
e = new DotVarExp(loc, e1, v);
e = e->semantic(sc);
return e;
}
e = new ScopeExp(loc, ti);
e = new DotExp(loc, eleft, e);
e = new DotExp(loc, e1, e);
e = e->semantic(sc);
return e;
}
Expand All @@ -7895,42 +7882,33 @@ Expression *DotTemplateInstanceExp::semanticY(Scope *sc, int flag)
}
if (e->op == TOKdottd)
{
if (ti->errors)
return new ErrorExp();
DotTemplateExp *dte = (DotTemplateExp *)e;
Expression *eleft = dte->e1;
e1 = dte->e1; // pull semantic() result

ti->tempdecl = dte->td;
if (!ti->semanticTiargs(sc))
{
ti->inst = ti;
ti->inst->errors = true;
return new ErrorExp();
}
if (ti->needsTypeInference(sc))
{
e1 = eleft; // save result of semantic()
return this;
}
else
ti->semantic(sc);
if (!ti->inst) // if template failed to expand
ti->semantic(sc);
if (!ti->inst || ti->errors) // if template failed to expand
return new ErrorExp();
Dsymbol *s = ti->inst->toAlias();
Dsymbol *s = ti->toAlias();
Declaration *v = s->isDeclaration();
if (v && (v->isFuncDeclaration() || v->isVarDeclaration()))
{
e = new DotVarExp(loc, eleft, v);
e = new DotVarExp(loc, e1, v);
e = e->semantic(sc);
return e;
}
if (eleft->op == TOKtype)
if (e1->op == TOKtype)
{
e = new DsymbolExp(loc, s);
e = e->semantic(sc);
return e;
}
e = new ScopeExp(loc, ti);
e = new DotExp(loc, eleft, e);
e = new DotExp(loc, e1, e);
e = e->semantic(sc);
return e;
}
Expand All @@ -7951,38 +7929,32 @@ Expression *DotTemplateInstanceExp::semanticY(Scope *sc, int flag)
else if (e->op == TOKdotexp)
{
DotExp *de = (DotExp *)e;
Expression *eleft = de->e1;
e1 = de->e1; // pull semantic() result

if (de->e2->op == TOKoverloadset)
{
if (!findTempDecl(sc) ||
!ti->semanticTiargs(sc))
{
ti->inst = ti;
ti->inst->errors = true;
return new ErrorExp();
}
if (ti->needsTypeInference(sc))
{
e1 = eleft;
return this;
}
else
ti->semantic(sc);
if (!ti->inst) // if template failed to expand
ti->semantic(sc);
if (!ti->inst || ti->errors) // if template failed to expand
return new ErrorExp();
Dsymbol *s = ti->inst->toAlias();
Dsymbol *s = ti->toAlias();
Declaration *v = s->isDeclaration();
if (v)
{
if (v->type && !v->type->deco)
v->type = v->type->semantic(v->loc, sc);
e = new DotVarExp(loc, eleft, v);
e = new DotVarExp(loc, e1, v);
e = e->semantic(sc);
return e;
}
e = new ScopeExp(loc, ti);
e = new DotExp(loc, eleft, e);
e = new DotExp(loc, e1, e);
e = e->semantic(sc);
return e;
}
Expand Down Expand Up @@ -8199,7 +8171,7 @@ Expression *CallExp::semantic(Scope *sc)
{
ScopeExp *se = (ScopeExp *)e1;
TemplateInstance *ti = se->sds->isTemplateInstance();
if (ti && !ti->semanticRun)
if (ti)
{
/* Attempt to instantiate ti. If that works, go with it.
* If not, go with partial explicit specialization.
Expand All @@ -8208,8 +8180,6 @@ Expression *CallExp::semantic(Scope *sc)
if (!ti->findTempDecl(sc, &withsym) ||
!ti->semanticTiargs(sc))
{
ti->inst = ti;
ti->inst->errors = true;
return new ErrorExp();
}
if (withsym && withsym->withstate->wthis)
Expand All @@ -8233,7 +8203,10 @@ Expression *CallExp::semantic(Scope *sc)
}
else
{
e1 = e1->semantic(sc);
Expression *e1x = e1->semantic(sc);
if (e1x->op == TOKerror)
return e1x;
e1 = e1x;
}
}
}
Expand All @@ -8246,16 +8219,13 @@ Expression *CallExp::semantic(Scope *sc)
{
DotTemplateInstanceExp *se = (DotTemplateInstanceExp *)e1;
TemplateInstance *ti = se->ti;
if (!ti->semanticRun)
{
/* Attempt to instantiate ti. If that works, go with it.
* If not, go with partial explicit specialization.
*/
if (!se->findTempDecl(sc) ||
!ti->semanticTiargs(sc))
{
ti->inst = ti;
ti->inst->errors = true;
return new ErrorExp();
}
if (ti->needsTypeInference(sc, 1))
Expand All @@ -8275,7 +8245,10 @@ Expression *CallExp::semantic(Scope *sc)
}
else
{
e1 = e1->semantic(sc);
Expression *e1x = e1->semantic(sc);
if (e1x->op == TOKerror)
return e1x;
e1 = e1x;
}
}
}
Expand Down Expand Up @@ -9103,13 +9076,12 @@ Expression *AddrExp::semantic(Scope *sc)
{
DotTemplateInstanceExp* dti = (DotTemplateInstanceExp *)e1;
TemplateInstance *ti = dti->ti;
if (!ti->semanticRun)
{
//assert(ti->needsTypeInference(sc));
ti->semantic(sc);
if (!ti->inst || ti->errors) // if template failed to expand
return new ErrorExp;
Dsymbol *s = ti->inst->toAlias();
Dsymbol *s = ti->toAlias();
FuncDeclaration *f = s->isFuncDeclaration();
if (f)
{
Expand All @@ -9121,13 +9093,13 @@ Expression *AddrExp::semantic(Scope *sc)
else if (e1->op == TOKimport)
{
TemplateInstance *ti = ((ScopeExp *)e1)->sds->isTemplateInstance();
if (ti && !ti->semanticRun)
if (ti)
{
//assert(ti->needsTypeInference(sc));
ti->semantic(sc);
if (!ti->inst || ti->errors) // if template failed to expand
return new ErrorExp;
Dsymbol *s = ti->inst->toAlias();
Dsymbol *s = ti->toAlias();
FuncDeclaration *f = s->isFuncDeclaration();
if (f)
{
Expand Down
25 changes: 18 additions & 7 deletions src/template.c
Expand Up @@ -6025,9 +6025,15 @@ void TemplateInstance::semantic(Scope *sc, Expressions *fargs)
!semanticTiargs(sc) ||
!findBestMatch(sc, fargs))
{
inst = this;
inst->errors = true;
return; // error recovery
if (global.gag)
{
// Bugzilla 13220: Rollback status for later semantic re-running.
semanticRun = PASSinit;
}
else
inst = this;
errors = true;
return;
}
TemplateDeclaration *tempdecl = this->tempdecl->isTemplateDeclaration();
assert(tempdecl);
Expand Down Expand Up @@ -7155,6 +7161,8 @@ bool TemplateInstance::findBestMatch(Scope *sc, Expressions *fargs)
bool TemplateInstance::needsTypeInference(Scope *sc, int flag)
{
//printf("TemplateInstance::needsTypeInference() %s\n", toChars());
if (semanticRun != PASSinit)
return false;

struct ParamNeedsInf
{
Expand Down Expand Up @@ -7279,9 +7287,12 @@ bool TemplateInstance::needsTypeInference(Scope *sc, int flag)
}
if (olderrs != global.errors)
{
errorSupplemental(loc, "while looking for match for %s", toChars());
semanticRun = PASSsemanticdone;
inst = this;
if (!global.gag)
{
errorSupplemental(loc, "while looking for match for %s", toChars());
semanticRun = PASSsemanticdone;
inst = this;
}
errors = true;
}
//printf("false\n");
Expand Down Expand Up @@ -8085,7 +8096,7 @@ void TemplateMixin::semantic(Scope *sc)
}

inst = this;
inst->errors = true;
errors = true;
return; // error recovery
}
TemplateDeclaration *tempdecl = this->tempdecl->isTemplateDeclaration();
Expand Down
23 changes: 23 additions & 0 deletions test/fail_compilation/ice13220.d
@@ -0,0 +1,23 @@
/*
TEST_OUTPUT:
---
fail_compilation/ice13220.d(22): Error: template instance test!0 does not match template declaration test(T)()
---
*/

struct Tuple(T...)
{
T field;
alias field this;
}

template test(T)
{
bool test() { return false; };
}

void main()
{
Tuple!bool t;
t[0] = test!0();
}

0 comments on commit 7119ce5

Please sign in to comment.