Indexer usage missing parentheses
Opened this issue · 0 comments
sharwell commented
The following Java code:
if (visited.put(current.getParent(i), current.getParent(i)) == null) {
workList.push(current.getParent(i));
}
Is currently producing the following C# code:
if (visited[current.GetParent(i)] = current.GetParent(i) == null)
{
workList.Push(current.GetParent(i));
}
This is incorrect for two reasons:
- Parentheses are needed around the indexer usage.
- The return value of the
put
method is the old value stored in the map. The result of the assignment expression is the new value stored in the map. The semantics change results in a major logic error in code like is posted above.