Skip to content

Commit

Permalink
Fix dictionary bug when null key has null value
Browse files Browse the repository at this point in the history
  • Loading branch information
atifaziz committed Mar 17, 2021
1 parent 9b9be9c commit 9d71dae
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
15 changes: 15 additions & 0 deletions MoreLinq.Test/ScanByTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,21 @@ public void ScanByWithSomeNullKeys()
KeyValuePair.Create("foo" , 1));
}

[Test]
public void ScanByWithNullSeed()
{
var nil = (object)null;
var source = new[] { "foo", null, "bar", null, "baz" };
var result = source.ScanBy(c => c, k => nil, (i, k, e) => nil);

result.AssertSequenceEqual(
KeyValuePair.Create("foo" , nil),
KeyValuePair.Create((string)null, nil),
KeyValuePair.Create("bar" , nil),
KeyValuePair.Create((string)null, nil),
KeyValuePair.Create("baz" , nil));
}

[Test]
public void ScanByDoesNotIterateUnnecessaryElements()
{
Expand Down
2 changes: 1 addition & 1 deletion MoreLinq/Collections/Dictionary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public bool TryGetValue(TKey key, [MaybeNullWhen(false)] out TValue value)
{
switch (_null)
{
case (true, {} v):
case (true, var v):
value = v;
return true;
case (false, _):
Expand Down

0 comments on commit 9d71dae

Please sign in to comment.