Support reevaluation of initializer expressions
Example:
class A {
int y = 17;
int x = y + 1;
}
class B {
inherit A;
int y = 42;
}
int main()
{
werror("%O\n", (mapping)B());
}
In this case the requester expected an output of
([ /* 2 elements */
"x": 43,
"y": 42
])
but the actual output is
([ /* 2 elements */
"x": 18,
"y": 42
])
This is due to the implementation of __INIT()
:
void A::__INIT()
{
y = 17;
x = y + 1;
}
void B::__INIT()
{
A::__INIT();
y = 42;
}
Suggested approach:
int A::__INIT_y()
{
return 17;
}
int A::__INIT_x()
{
return y + 1;
}
void A::__INIT()
{
y = __INIT_y();
x = __INIT_x();
}
int B::__INIT_y()
{
return 42;
}
void B::__INIT()
{
A::__INIT();
y = __INIT_y(); // Redundant.
}
Note that due to the overloading of __INIT_y()
, y
will be set twice by B::__INIT()
(but both times to 42
).