Skip to content

Commit

Permalink
Fix invalid indexer in HybridDictionary
Browse files Browse the repository at this point in the history
Indexer (defined in interface) implemented that recursively calls
itself. Nothing called this code, but if it did it would be wrong
(stack overflow).

Closes dotnet#77
  • Loading branch information
AndyGerlicher committed Feb 15, 2017
1 parent 487db4a commit 416a0c1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Shared/HybridDictionary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -349,8 +349,8 @@ public TValue this[TKey key]
/// </summary>
public object this[object key]
{
get { return (Object)this[key]; }
set { this[key] = value; }
get { return ((IDictionary<TKey, TValue>)this)[(TKey)key]; }
set { ((IDictionary<TKey, TValue>)this)[(TKey)key] = (TValue)value; }
}

/// <summary>
Expand Down
11 changes: 11 additions & 0 deletions src/Shared/UnitTests/HybridDictionary_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,17 @@ public void Medley()
}
}

[Fact]
private void VerifyHybridDictionaryAccessor()
{
var dict = new HybridDictionary<string, string>();
dict[(object) "key"] = "value";

Assert.Equal("value", dict["key"]);
Assert.Equal("value", dict[(object)"key"]);
Assert.Equal("key", dict.Keys.First());
}

/// <summary>
/// Performs both actions supplied and asserts either both or neither threw
/// </summary>
Expand Down

0 comments on commit 416a0c1

Please sign in to comment.