Skip to content
This repository has been archived by the owner on Mar 9, 2021. It is now read-only.

Indexer usage missing parentheses #74

Open
sharwell opened this issue Jun 8, 2016 · 0 comments
Open

Indexer usage missing parentheses #74

sharwell opened this issue Jun 8, 2016 · 0 comments

Comments

@sharwell
Copy link
Contributor

sharwell commented Jun 8, 2016

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.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant