Skip to content

Commit

Permalink
Merge pull request #971 from 9rnsr/fix8169
Browse files Browse the repository at this point in the history
Issue 8169 - Method loses its compile-time evaluability when used through alias this
  • Loading branch information
WalterBright committed May 31, 2012
2 parents 65c7bb6 + df51c6d commit bc7144d
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/expression.c
Original file line number Diff line number Diff line change
Expand Up @@ -7843,13 +7843,23 @@ Expression *CallExp::semantic(Scope *sc)
AggregateDeclaration *ad;
UnaExp *ue = (UnaExp *)(e1);

Expression *ue1 = ue->e1;
VarDeclaration *v;
if (ue1->op == TOKvar &&
(v = ((VarExp *)ue1)->var->isVarDeclaration()) != NULL &&
v->needThis())
{
ue->e1 = new TypeExp(ue1->loc, ue1->type);
ue1 = NULL;
}

if (e1->op == TOKdotvar)
{ // Do overload resolution
dve = (DotVarExp *)(e1);

f = dve->var->isFuncDeclaration();
assert(f);
f = f->overloadResolve(loc, ue->e1, arguments);
f = f->overloadResolve(loc, ue1, arguments);

ad = f->toParent()->isAggregateDeclaration();
}
Expand All @@ -7860,7 +7870,7 @@ Expression *CallExp::semantic(Scope *sc)
if (!arguments)
// Should fix deduceFunctionTemplate() so it works on NULL argument
arguments = new Expressions();
f = td->deduceFunctionTemplate(sc, loc, targsi, ue->e1, arguments);
f = td->deduceFunctionTemplate(sc, loc, targsi, ue1, arguments);
if (!f)
return new ErrorExp();
ad = td->toParent()->isAggregateDeclaration();
Expand Down
26 changes: 26 additions & 0 deletions test/runnable/aliasthis.d
Original file line number Diff line number Diff line change
Expand Up @@ -833,6 +833,31 @@ void test7992()
assert(arr.length == 2);
}

/***************************************************/
// 8169

void test8169()
{
static struct ValueImpl
{
static immutable(int) getValue()
{
return 42;
}
}

static struct ValueUser
{
ValueImpl m_valueImpl;
alias m_valueImpl this;
}

static assert(ValueImpl.getValue() == 42); // #0, OK
static assert(ValueUser.getValue() == 42); // #1, NG
static assert( ValueUser.m_valueImpl .getValue() == 42); // #2, NG
static assert(typeof(ValueUser.m_valueImpl).getValue() == 42); // #3, OK
}

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

int main()
Expand Down Expand Up @@ -866,6 +891,7 @@ int main()
test7808();
test7945();
test7992();
test8169();

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

0 comments on commit bc7144d

Please sign in to comment.