SonarSource/sonar-dotnet

Make `ProgramState.SetOperationValueCore` set the value for a tracked symbol as well

Opened this issue · 0 comments

If the operation passed to ProgramState.SetOperationValueCore has a tracked symbol (operation.TrackedSymbol(state) is { } symbol) the method should also set the symbolic value for the symbol.

When implemented naively, multiple UTs start failing. The reasons for this need to be investigated, and the problems evaluated to see if they can be solved.

Why?
The following and similar patterns are repeated multiple times in our solution:

state = state.SetOperationValue(operation, value);
if (operation.TrackedSymbol(state) is { } symbol)
{
    state = state.SetSymbolValue(symbol, value);
}

This is unnecessary. Changing the behavior of SetOperationValueCore lets us simplify the code to

state = state.SetOperationValue(operation, value);