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

Indexer usage missing parentheses #74

@sharwell

Description

@sharwell

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions