mono/sharpen

Indexer usage missing parentheses

Opened this issue · 0 comments

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:

  1. Parentheses are needed around the indexer usage.
  2. 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.