[Issue 5117] [CTFE] Member function call with rather complex this: side effects ignored
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Mon Oct 25 14:14:53 PDT 2010
http://d.puremagic.com/issues/show_bug.cgi?id=5117
Shin Fujishiro <rsinfu at gmail.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Summary|[CTFE] Member function call |[CTFE] Member function call
|with chained dots: side |with rather complex this:
|effects ignored |side effects ignored
--- Comment #1 from Shin Fujishiro <rsinfu at gmail.com> 2010-10-25 14:14:06 PDT ---
The problem lies in FuncDeclralation::interpret(), around line 223:
--------------------
// Don't restore the value of 'this' upon function return
if (needThis() && thisarg->op == TOKvar && istate)
{
VarDeclaration *thisvar = ((VarExp
*)(thisarg))->var->isVarDeclaration();
for (size_t i = 0; i < istate->vars.dim; i++)
{ VarDeclaration *v = (VarDeclaration *)istate->vars.data[i];
if (v == thisvar)
{ istate->vars.data[i] = NULL;
break;
}
}
}
--------------------
In the repro code in comment #1, thisarg is 'r.s' (TOKdotvar) and the local
variable 'r' is not removed from the "restore list" istate->vars. Then, the
interpretor wrongly restores 'r' to init.
Just dealing with TOKdotvar fixes the specific reported problem, but it's not a
general fix. Still the interpretor should deal with references. For example:
--------------------
enum dummy = test();
int test()
{
S s;
getRef(s).change();
assert(s.value == 1); // fails, value == 0
return 0;
}
ref S getRef(ref S s) { return s; }
struct S
{
int value;
void change() { value = 1; }
}
--------------------
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list