Skip to content

Commit

Permalink
Merge pull request #1506 from 9rnsr/fix9338
Browse files Browse the repository at this point in the history
Issue 9338 - Compiler segfaults if try to CTFE member function without valid 'this'
  • Loading branch information
Don Clugston committed Jan 18, 2013
2 parents 685d943 + 7982d16 commit f7e5659
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 19 deletions.
29 changes: 10 additions & 19 deletions src/interpret.c
Original file line number Diff line number Diff line change
Expand Up @@ -3983,25 +3983,16 @@ Expression *CallExp::interpret(InterState *istate, CtfeGoal goal)
}
if (pthis)
{ // Member function call
Expression *oldpthis;
if (pthis->op == TOKthis)
{
pthis = istate ? istate->localThis : NULL;
oldpthis = pthis;
}
else
{
if (pthis->op == TOKcomma)
pthis = pthis->interpret(istate);
if (exceptionOrCantInterpret(pthis))
return pthis;
// Evaluate 'this'
oldpthis = pthis;
if (pthis->op != TOKvar)
pthis = pthis->interpret(istate, ctfeNeedLvalue);
if (exceptionOrCantInterpret(pthis))
return pthis;
}
if (pthis->op == TOKcomma)
pthis = pthis->interpret(istate);
if (exceptionOrCantInterpret(pthis))
return pthis;
// Evaluate 'this'
Expression *oldpthis = pthis;
if (pthis->op != TOKvar)
pthis = pthis->interpret(istate, ctfeNeedLvalue);
if (exceptionOrCantInterpret(pthis))
return pthis;
if (fd->isVirtual())
{ // Make a virtual function call.
Expression *thisval = pthis;
Expand Down
21 changes: 21 additions & 0 deletions test/fail_compilation/ice9338.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
TEST_OUTPUT:
---
fail_compilation/ice9338.d(13): Error: value of 'this' is not known at compile time
fail_compilation/ice9338.d(14): Error: value of 'this' is not known at compile time
---
*/

class Foo
{
void test()
{
enum members1 = makeArray();
enum members2 = this.makeArray();
}

string[] makeArray()
{
return ["a"];
}
}

0 comments on commit f7e5659

Please sign in to comment.