Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

fix Issue 9338 - Compiler segfaults if try to CTFE member function wi…

…thout valid 'this'
  • Loading branch information...
commit 7982d16e224495cc28787dd93020db7ab01620b9 1 parent 685d943
@9rnsr 9rnsr authored
Showing with 31 additions and 19 deletions.
  1. +10 −19 src/interpret.c
  2. +21 −0 test/fail_compilation/ice9338.d
View
29 src/interpret.c
@@ -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;
View
21 test/fail_compilation/ice9338.d
@@ -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"];
+ }
+}
Please sign in to comment.
Something went wrong with that request. Please try again.