Skip to content

Commit

Permalink
bugzilla 4003 The result changes only with the order of source files.
Browse files Browse the repository at this point in the history
  • Loading branch information
Walter Bright committed Jun 9, 2010
1 parent e06a86d commit b729847
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 9 deletions.
3 changes: 3 additions & 0 deletions src/declaration.c
Original file line number Diff line number Diff line change
Expand Up @@ -754,6 +754,9 @@ void VarDeclaration::semantic(Scope *sc)
else
type = init->inferType(sc);

//printf("test2: %s, %s, %s\n", toChars(), type->toChars(), type->deco);
// type = type->semantic(loc, sc);

inuse--;
inferred = 1;

Expand Down
30 changes: 25 additions & 5 deletions src/expression.c
Original file line number Diff line number Diff line change
Expand Up @@ -5277,8 +5277,8 @@ Expression *IsExp::semantic(Scope *sc)
* is(targ : tspec)
*/
tspec = tspec->semantic(loc, sc);
//printf("targ = %s\n", targ->toChars());
//printf("tspec = %s\n", tspec->toChars());
//printf("targ = %s, %s\n", targ->toChars(), targ->deco);
//printf("tspec = %s, %s\n", tspec->toChars(), tspec->deco);
if (tok == TOKcolon)
{ if (targ->implicitConvTo(tspec))
goto Lyes;
Expand All @@ -5303,11 +5303,11 @@ Expression *IsExp::semantic(Scope *sc)
if (sc->sd)
s->addMember(sc, sc->sd, 1);
}
//printf("Lyes\n");
//printf("Lyes\n");
return new IntegerExp(loc, 1, Type::tbool);

Lno:
//printf("Lno\n");
//printf("Lno\n");
return new IntegerExp(loc, 0, Type::tbool);

Lerr:
Expand Down Expand Up @@ -6429,7 +6429,27 @@ Expression *DotTemplateInstanceExp::semantic(Scope *sc)
Dsymbol *s = ti->inst->toAlias();
Declaration *v = s->isDeclaration();
if (v)
{ e = new DotVarExp(loc, eleft, v);
{
/* Fix for Bugzilla 4003
* The problem is a class template member function v returning a reference to the same
* type as the enclosing template instantiation. This results in a nested instantiation,
* which of course gets short circuited. The return type then gets set to
* the template instance type before instantiation, rather than after.
* We can detect this by the deco not being set. If so, go ahead and retry
* the return type semantic.
* The offending code is the return type from std.typecons.Tuple.slice:
* ref Tuple!(Types[from .. to]) slice(uint from, uint to)()
* {
* return *cast(typeof(return) *) &(field[from]);
* }
* and this line from the following unittest:
* auto s = a.slice!(1, 3);
* where s's type wound up not having semantic() run on it.
*/
if (v->type && !v->type->deco)
v->type = v->type->semantic(v->loc, sc);

e = new DotVarExp(loc, eleft, v);
e = e->semantic(sc);
return e;
}
Expand Down
6 changes: 4 additions & 2 deletions src/func.c
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,9 @@ void FuncDeclaration::semantic(Scope *sc)
if (semanticRun >= PASSsemanticdone)
{
if (!parent->isClassDeclaration())
{
return;
}
// need to re-run semantic() in order to set the class's vtbl[]
}
else
Expand Down Expand Up @@ -2314,12 +2316,12 @@ AggregateDeclaration *FuncDeclaration::isMember2()
//printf("\ts = '%s', parent = '%s', kind = %s\n", s->toChars(), s->parent->toChars(), s->parent->kind());
ad = s->isMember();
if (ad)
{ //printf("test4\n");
{
break;
}
if (!s->parent ||
(!s->parent->isTemplateInstance()))
{ //printf("test5\n");
{
break;
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/mtype.c
Original file line number Diff line number Diff line change
Expand Up @@ -7689,7 +7689,8 @@ Type *TypeSlice::semantic(Loc loc, Scope *sc)
args->push(arg);
}

return new TypeTuple(args);
Type *t = new TypeTuple(args)->semantic(loc, sc);
return t;
}

void TypeSlice::resolve(Loc loc, Scope *sc, Expression **pe, Type **pt, Dsymbol **ps)
Expand Down
2 changes: 1 addition & 1 deletion src/template.c
Original file line number Diff line number Diff line change
Expand Up @@ -3569,7 +3569,7 @@ void TemplateInstance::semantic(Scope *sc)

void TemplateInstance::semantic(Scope *sc, Expressions *fargs)
{
//printf("TemplateInstance::semantic('%s', this=%p)\n", toChars(), this);
//printf("TemplateInstance::semantic('%s', this=%p, gag = %d)\n", toChars(), this, global.gag);
if (global.errors && name != Id::AssociativeArray)
{
//printf("not instantiating %s due to %d errors\n", toChars(), global.errors);
Expand Down

0 comments on commit b729847

Please sign in to comment.