Skip to content

Commit

Permalink
fix Issue 12023 - template mixin fails within template class
Browse files Browse the repository at this point in the history
  • Loading branch information
9rnsr committed Jan 29, 2014
1 parent a4d86a6 commit 244c5ac
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/expression.c
Expand Up @@ -3408,6 +3408,17 @@ Expression *DsymbolExp::semantic(Scope *sc)
if (s != olds && !s->isFuncDeclaration())
checkDeprecated(sc, s);

if (VarDeclaration *v = s->isVarDeclaration())
{
/* Bugzilla 12023: forward reference should be resolved
* before 's->needThis()' is called.
*/
if ((!v->type || !v->type->deco) && v->scope)
{
v->semantic(v->scope);
s = v->toAlias(); // Need this if 'v' is a tuple variable
}
}
if (s->needThis() && hasThis(sc))
{
// For functions, this should happen after overload resolution
Expand All @@ -3429,8 +3440,6 @@ Expression *DsymbolExp::semantic(Scope *sc)
//printf("Identifier '%s' is a variable, type '%s'\n", toChars(), v->type->toChars());
if (!type)
{
if ((!v->type || !v->type->deco) && v->scope)
v->semantic(v->scope);
type = v->type;
if (!v->type)
{
Expand Down
44 changes: 44 additions & 0 deletions test/runnable/mixin1.d
Expand Up @@ -3,6 +3,8 @@ module mixin1;

import std.stdio;

alias TypeTuple(T...) = T;

/*******************************************/

mixin template Foo(T)
Expand Down Expand Up @@ -1259,6 +1261,47 @@ void test11767()
static assert(!__traits(compiles, S11767));
}

/*******************************************/
// 12023

void Delete12023(Object obj) {}

template MessageCode12023()
{
alias typeof(this) C;

struct MessageDeinitHelper
{
C m_outer;

~this()
{
m_outer.DoDeinitMessaging();
}
}

CToClient toClient = null;
TypeTuple!(CToClient) toClients;

class CToClient {}

void DoDeinitMessaging()
{
Delete12023(toClient);
Delete12023(toClients);
}
}

class TurretCannon12023(ProjectileClass)
{
mixin MessageCode12023;
}

void test12023()
{
auto tc = new TurretCannon12023!Object();
}

/*******************************************/

int main()
Expand Down Expand Up @@ -1309,6 +1352,7 @@ int main()
test42();
test9417();
test11767();
test12023();

printf("Success\n");
return 0;
Expand Down

0 comments on commit 244c5ac

Please sign in to comment.