Skip to content

Commit

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

Closes #77
  • Loading branch information
AndyGerlicher authored Feb 16, 2017
1 parent 033999a commit e55ebc1
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 VerifyHybridDictionaryBaseIndexer()
{
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 e55ebc1

Please sign in to comment.