Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'for' expression initialization statements do not trigger value change events #15

Open
szabolcsmaj opened this issue Feb 15, 2017 · 1 comment

Comments

@szabolcsmaj
Copy link
Contributor

In the following example, the initialization assignment for 'i' never triggers a value change event.

int j = 7;
for (final int i = 17; j < i; ++j);

GhostWriter checks the 'step' part of the 'for' expression for mutations and adds value change event triggers to the body of the for loop. Thus we get an event at each iteration.

The problem with the 'initialization' part of the 'for' expression part is that there seems to be only one correct solution. The value change event triggering for the initialization needs to be put in the for loop body with as a conditional statement. Generating the conditional statement for the first iteration that covers all general use cases can be quite tricky.

int j = 7;
for (final int i = 17; j < i; ++j) {
   if (isFirstIteration) {
      GW.valueChange("i");
   }
   GW.valueChange("j");
}

One thing to keep in mind that it can happen that we execute the initialization part of the 'for' expression, but do not iterate, since the terminating condition is met at the start. In that case we still miss a value change event that happened.

In all cases, the solution to have the value change event triggered after the 'for' expression would work, however the down side is that the events come out of order, meaning the iteration step events come before the initialization event.

One possible "optimal" solution could be to extend GW API to support this use case, by having the valueChange API call return the traced value. So we would have something like this:

for (final int i = GW.valueChange(17); j < i; ++j);

Though this leads to a whole lot of things that need to be considered, supported (chaining, exceptions ... ).

@szabolcsmaj
Copy link
Contributor Author

Depends on #16

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant