Skip to content

Commit

Permalink
Issue 15172 - ICE(interpret.c ctfeCompile) Assertion `!fd->semantic3E…
Browse files Browse the repository at this point in the history
…rrors' failed.
  • Loading branch information
ibuclaw committed Jul 23, 2017
1 parent 5ab26bb commit dca9baa
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 13 deletions.
22 changes: 17 additions & 5 deletions src/func.c
Expand Up @@ -2141,10 +2141,15 @@ void FuncDeclaration::semantic3(Scope *sc)
//fflush(stdout);
}

/****************************************************
* Resolve forward reference of function signature -
* parameter types, return type, and attributes.
* Returns false if any errors exist in the signature.
*/
bool FuncDeclaration::functionSemantic()
{
if (!_scope)
return true;
return !errors;

if (!originalType) // semantic not yet run
{
Expand All @@ -2162,6 +2167,9 @@ bool FuncDeclaration::functionSemantic()
}

// if inferring return type, sematic3 needs to be run
// - When the function body contains any errors, we cannot assume
// the inferred return type is valid.
// So, the body errors should become the function signature error.
if (inferRetType && type && !type->nextOf())
return functionSemantic3();

Expand All @@ -2179,15 +2187,19 @@ bool FuncDeclaration::functionSemantic()
//ad->sizeok = SIZEOKfwd;
}
else
return functionSemantic3();
return functionSemantic3() || !errors;
}

if (storage_class & STCinference)
return functionSemantic3();
return functionSemantic3() || !errors;

return true;
return !errors;
}

/****************************************************
* Resolve forward reference of function body.
* Returns false if any errors exist in the body.
*/
bool FuncDeclaration::functionSemantic3()
{
if (semanticRun < PASSsemantic3 && _scope)
Expand All @@ -2212,7 +2224,7 @@ bool FuncDeclaration::functionSemantic3()
return false;
}

return true;
return !errors && !semantic3Errors;
}

VarDeclaration *FuncDeclaration::declareThis(Scope *sc, AggregateDeclaration *ad)
Expand Down
13 changes: 6 additions & 7 deletions src/interpret.c
Expand Up @@ -720,9 +720,13 @@ void ctfeCompile(FuncDeclaration *fd)
}

/*************************************
*
* Entry point for CTFE.
* A compile-time result is required. Give an error if not possible
* A compile-time result is required. Give an error if not possible.
*
* `e` must be semantically valid expression. In other words, it should not
* contain any `ErrorExp`s in it. But, CTFE interpretation will cross over
* functions and may invoke a function that contains `ErrorStatement` in its body.
* If that, the "CTFE failed because of previous errors" error is raised.
*/
Expression *ctfeInterpret(Expression *e)
{
Expand All @@ -733,8 +737,6 @@ Expression *ctfeInterpret(Expression *e)
if (e->type->ty == Terror)
return new ErrorExp();

unsigned olderrors = global.errors;

// This code is outside a function, but still needs to be compiled
// (there are compiler-generated temporary variables such as __dollar).
// However, this will only be run once and can then be discarded.
Expand All @@ -746,10 +748,7 @@ Expression *ctfeInterpret(Expression *e)
if (!CTFEExp::isCantExp(result))
result = scrubReturnValue(e->loc, result);
if (CTFEExp::isCantExp(result))
{
assert(global.errors != olderrors);
result = new ErrorExp();
}
return result;
}

Expand Down
7 changes: 6 additions & 1 deletion src/template.c
Expand Up @@ -2422,7 +2422,12 @@ void functionResolve(Match *m, Dsymbol *dstart, Loc loc, Scope *sc,
return 0;

if (fd->type->ty != Tfunction)
goto Lerror;
{
m->lastf = fd; // to propagate "error match"
m->count = 1;
m->last = MATCHnomatch;
return 1;
}

Type *tthis_fd = fd->needThis() && !fd->isCtorDeclaration() ? tthis : NULL;

Expand Down

0 comments on commit dca9baa

Please sign in to comment.