Skip to content

Commit

Permalink
Merge pull request #3103 from 9rnsr/fix10133
Browse files Browse the repository at this point in the history
Issue 10133 - ICE for templated static conditional lambda
  • Loading branch information
WalterBright authored and AndrewEdwards committed Jan 28, 2014
1 parent 3ba2df6 commit e928078
Show file tree
Hide file tree
Showing 24 changed files with 502 additions and 535 deletions.
2 changes: 1 addition & 1 deletion src/attrib.c
Expand Up @@ -1061,7 +1061,7 @@ void PragmaDeclaration::semantic(Scope *sc)
if (global.params.moduleDeps && !global.params.moduleDepsFile)
{
OutBuffer *ob = global.params.moduleDeps;
Module* imod = sc->instantiatingModule ? sc->instantiatingModule : sc->module;
Module *imod = sc->instantiatingModule();
ob->writestring("depsLib ");
ob->writestring(imod->toPrettyChars());
ob->writestring(" (");
Expand Down
2 changes: 0 additions & 2 deletions src/clone.c
Expand Up @@ -76,7 +76,6 @@ FuncDeclaration *AggregateDeclaration::hasIdentityOpAssign(Scope *sc)
unsigned oldspec = global.speculativeGag; // template opAssign fbody makes it.
global.speculativeGag = global.gag;
sc = sc->push();
sc->tinst = NULL;
sc->speculative = true;

for (size_t i = 0; i < 2; i++)
Expand Down Expand Up @@ -416,7 +415,6 @@ FuncDeclaration *AggregateDeclaration::hasIdentityOpEquals(Scope *sc)
unsigned oldspec = global.speculativeGag; // template opAssign fbody makes it.
global.speculativeGag = global.gag;
sc = sc->push();
sc->tinst = NULL;
sc->speculative = true;

for (size_t j = 0; j < 2; j++)
Expand Down
2 changes: 1 addition & 1 deletion src/cond.c
Expand Up @@ -90,7 +90,7 @@ void printDepsConditional(Scope *sc, DVCondition* condition, const char* depType
if (!global.params.moduleDeps || global.params.moduleDepsFile)
return;
OutBuffer *ob = global.params.moduleDeps;
Module* imod = sc ? (sc->instantiatingModule ? sc->instantiatingModule : sc->module) : condition->mod;
Module* imod = sc ? sc->instantiatingModule() : condition->mod;
if (!imod)
return;
ob->writestring(depType);
Expand Down
6 changes: 3 additions & 3 deletions src/ctfeexpr.c
Expand Up @@ -546,9 +546,9 @@ TypeAArray *toBuiltinAAType(Type *t)
assert(t->ty == Tstruct);
StructDeclaration *sym = ((TypeStruct *)t)->sym;
assert(sym->ident == Id::AssociativeArray);
TemplateInstance *tinst = sym->parent->isTemplateInstance();
assert(tinst);
return new TypeAArray((Type *)(*tinst->tiargs)[1], (Type *)(*tinst->tiargs)[0]);
TemplateInstance *ti = sym->parent->isTemplateInstance();
assert(ti);
return new TypeAArray((Type *)(*ti->tiargs)[1], (Type *)(*ti->tiargs)[0]);
#else
assert(0);
return NULL;
Expand Down
31 changes: 13 additions & 18 deletions src/expression.c
Expand Up @@ -159,15 +159,6 @@ FuncDeclaration *hasThis(Scope *sc)
FuncDeclaration *fdthis = p ? p->isFuncDeclaration() : NULL;
//printf("fdthis = %p, '%s'\n", fdthis, fdthis ? fdthis->toChars() : "");

/* Special case for inside template constraint
*/
if (fdthis && (sc->flags & SCOPEstaticif) && fdthis->parent->isTemplateDeclaration())
{
//TemplateDeclaration *td = fdthis->parent->isTemplateDeclaration();
//printf("[%s] td = %s, fdthis->vthis = %p\n", td->loc.toChars(), td->toChars(), fdthis->vthis);
return fdthis->vthis ? fdthis : NULL;
}

// Go upwards until we find the enclosing member function
FuncDeclaration *fd = fdthis;
while (1)
Expand Down Expand Up @@ -234,11 +225,6 @@ bool isNeedThisScope(Scope *sc, Declaration *d)
continue;
if (f->isMember2())
break;
if (TemplateDeclaration *td = f->parent->isTemplateDeclaration())
{
if ((td->scope->stc & STCstatic) && td->isMember())
break; // no valid 'this'
}
}
}
return true;
Expand Down Expand Up @@ -3674,6 +3660,11 @@ Expression *ThisExp::semantic(Scope *sc)
var = fd->vthis;
assert(var->parent);
type = var->type;
if (TemplateInstance *ti = fd->parent->isTemplateInstance())
{
if (ti->members == NULL)
type = type->mutableOf();
}
var->isVarDeclaration()->checkNestedReference(sc, loc);
if (!sc->intypeof)
sc->callSuper |= CSXthis;
Expand Down Expand Up @@ -3765,9 +3756,8 @@ Expression *SuperExp::semantic(Scope *sc)
if (!fd)
goto Lerr;

assert(fd->vthis);
var = fd->vthis;
assert(var->parent);
assert(var && var->parent);

s = fd->toParent();
while (s && s->isTemplateInstance())
Expand All @@ -3782,13 +3772,18 @@ Expression *SuperExp::semantic(Scope *sc)
if (!cd->baseClass)
{
error("no base class for %s", cd->toChars());
type = fd->vthis->type;
type = var->type;
}
else
{
type = cd->baseClass->type;
type = type->castMod(var->type->mod);
}
if (TemplateInstance *ti = fd->parent->isTemplateInstance())
{
if (ti->members == NULL)
type = type->mutableOf();
}

var->isVarDeclaration()->checkNestedReference(sc, loc);

Expand Down Expand Up @@ -7276,7 +7271,7 @@ Expression *FileExp::semantic(Scope *sc)
if (global.params.moduleDeps != NULL)
{
OutBuffer *ob = global.params.moduleDeps;
Module* imod = sc->instantiatingModule ? sc->instantiatingModule : sc->module;
Module* imod = sc->instantiatingModule();

if (!global.params.moduleDepsFile)
ob->writestring("depsFile ");
Expand Down
22 changes: 6 additions & 16 deletions src/func.c
Expand Up @@ -2876,26 +2876,16 @@ FuncDeclaration *resolveFuncCall(Loc loc, Scope *sc, Dsymbol *s,
}
else if (m.nextf)
{
/* CAUTION: m.lastf and m.nextf might be incompletely instantiated functions
* (created by doHeaderInstantiation), so call toPrettyChars will segfault.
*/
assert(m.lastf);
TypeFunction *t1 = (TypeFunction *)m.lastf->type;
TypeFunction *t2 = (TypeFunction *)m.nextf->type;
TemplateInstance *lastti = m.lastf->parent->isTemplateInstance();
TemplateInstance *nextti = m.nextf->parent->isTemplateInstance();
if (lastti && lastti->name != m.lastf->ident) lastti = NULL;
if (nextti && nextti->name != m.nextf->ident) nextti = NULL;
Dsymbol *lasts = lastti ? (Dsymbol *)lastti->tempdecl : (Dsymbol *)m.lastf;
Dsymbol *nexts = nextti ? (Dsymbol *)nextti->tempdecl : (Dsymbol *)m.nextf;
const char *lastprms = lastti ? "" : Parameter::argsTypesToChars(t1->parameters, t1->varargs);
const char *nextprms = nextti ? "" : Parameter::argsTypesToChars(t2->parameters, t2->varargs);
TypeFunction *tf1 = (TypeFunction *)m.lastf->type;
TypeFunction *tf2 = (TypeFunction *)m.nextf->type;
const char *lastprms = Parameter::argsTypesToChars(tf1->parameters, tf1->varargs);
const char *nextprms = Parameter::argsTypesToChars(tf2->parameters, tf2->varargs);
::error(loc, "%s.%s called with argument types %s matches both:\n"
"\t%s(%d): %s%s\nand:\n\t%s(%d): %s%s",
s->parent->toPrettyChars(), s->ident->toChars(),
fargsBuf.toChars(),
lasts->loc.filename, lasts->loc.linnum, lasts->toChars(), lastprms,
nexts->loc.filename, nexts->loc.linnum, nexts->toChars(), nextprms);
m.lastf->loc.filename, m.lastf->loc.linnum, m.lastf->toPrettyChars(), lastprms,
m.nextf->loc.filename, m.nextf->loc.linnum, m.nextf->toPrettyChars(), nextprms);
}
return NULL;
}
Expand Down
3 changes: 3 additions & 0 deletions src/glue.c
Expand Up @@ -567,6 +567,9 @@ void FuncDeclaration::toObjFile(int multiobj)
if (semanticRun >= PASSobj) // if toObjFile() already run
return;

if (type && type->ty == Tfunction && ((TypeFunction *)type)->next == NULL)
return;

// If errors occurred compiling it, such as bugzilla 6118
if (type && type->ty == Tfunction && ((TypeFunction *)type)->next->ty == Terror)
return;
Expand Down
2 changes: 1 addition & 1 deletion src/import.c
Expand Up @@ -291,7 +291,7 @@ void Import::semantic(Scope *sc)
*/

OutBuffer *ob = global.params.moduleDeps;
Module* imod = sc->instantiatingModule ? sc->instantiatingModule : sc->module;
Module* imod = sc->instantiatingModule();
if (!global.params.moduleDepsFile)
ob->writestring("depsImport ");
ob->writestring(imod->toPrettyChars());
Expand Down
2 changes: 2 additions & 0 deletions src/mars.c
Expand Up @@ -280,6 +280,8 @@ void verror(Loc loc, const char *format, va_list ap,
}
else
{
//fprintf(stderr, "(gag:%d) ", global.gag);
//verrorPrint(loc, header, format, ap, p1, p2);
global.gaggedErrors++;
}
global.errors++;
Expand Down
7 changes: 5 additions & 2 deletions src/mtype.c
Expand Up @@ -4909,8 +4909,11 @@ StructDeclaration *TypeAArray::getImpl()
TemplateInstance *ti = dti->ti;
#endif
// Instantiate on the root module of import dependency graph.
Scope *scx = sc->push(sc->module->importedFrom);
scx->instantiatingModule = sc->module->importedFrom;
Module *mi = sc->module->importedFrom;
Scope *scx = sc->push(mi);
scx->module = mi;
scx->tinst = NULL;
assert(scx->instantiatingModule() == mi);
ti->semantic(scx);
ti->semantic2(scx);
ti->semantic3(scx);
Expand Down
2 changes: 1 addition & 1 deletion src/opover.c
Expand Up @@ -1569,7 +1569,7 @@ void inferApplyArgTypesZ(TemplateDeclaration *tstart, Parameters *arguments)
error("forward reference to template %s", td->toChars());
return;
}
if (!td->onemember || !td->onemember->toAlias()->isFuncDeclaration())
if (!td->onemember || !td->onemember->isFuncDeclaration())
{
error("is not a function template");
return;
Expand Down
13 changes: 10 additions & 3 deletions src/scope.c
Expand Up @@ -26,6 +26,7 @@
#include "module.h"
#include "id.h"
#include "lexer.h"
#include "template.h"

Scope *Scope::freelist = NULL;

Expand All @@ -47,11 +48,11 @@ void *Scope::operator new(size_t size)
}

Scope::Scope()
{ // Create root scope
{
// Create root scope

//printf("Scope::Scope() %p\n", this);
this->module = NULL;
this->instantiatingModule = NULL;
this->scopesym = NULL;
this->sd = NULL;
this->enclosing = NULL;
Expand Down Expand Up @@ -93,7 +94,6 @@ Scope::Scope(Scope *enclosing)
//printf("Scope::Scope(enclosing = %p) %p\n", enclosing, this);
assert(!(enclosing->flags & SCOPEfree));
this->module = enclosing->module;
this->instantiatingModule = enclosing->instantiatingModule;
this->func = enclosing->func;
this->parent = enclosing->parent;
this->scopesym = NULL;
Expand Down Expand Up @@ -398,6 +398,13 @@ void Scope::mergeFieldInit(Loc loc, unsigned *fies)
}
}

Module *Scope::instantiatingModule()
{
if (tinst && tinst->instantiatingModule)
return tinst->instantiatingModule;
return module;
}

Dsymbol *Scope::search(Loc loc, Identifier *ident, Dsymbol **pscopesym)
{ Dsymbol *s;
Scope *sc;
Expand Down
3 changes: 2 additions & 1 deletion src/scope.h
Expand Up @@ -66,7 +66,6 @@ struct Scope
Scope *enclosing; // enclosing Scope

Module *module; // Root module
Module *instantiatingModule; // top level module that started a chain of template instantiations
ScopeDsymbol *scopesym; // current symbol
ScopeDsymbol *sd; // if in static if, and declaring new symbols,
// sd gets the addMember()
Expand Down Expand Up @@ -132,6 +131,8 @@ struct Scope
unsigned *saveFieldInit();
void mergeFieldInit(Loc loc, unsigned *cses);

Module *instantiatingModule();

Dsymbol *search(Loc loc, Identifier *ident, Dsymbol **pscopesym);
Dsymbol *search_correct(Identifier *ident);
Dsymbol *insert(Dsymbol *s);
Expand Down
2 changes: 1 addition & 1 deletion src/struct.c
Expand Up @@ -169,7 +169,7 @@ void AggregateDeclaration::semantic3(Scope *sc)
Expression *e = new DsymbolExp(Loc(), s, 0);

Scope *sc2 = ti->tempdecl->scope->startCTFE();
sc2->instantiatingModule = sc->instantiatingModule ? sc->instantiatingModule : sc->module;
sc2->tinst = sc->tinst;
e = e->semantic(sc2);
sc2->endCTFE();

Expand Down

0 comments on commit e928078

Please sign in to comment.