Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix dictionary bug when null key has null value #800

Merged
merged 1 commit into from
Mar 18, 2021

Conversation

atifaziz
Copy link
Member

This PR fixes a bug introduced by PR #582 in our dictionary implementation that accepts null keys. The bug can be observed via ScanBy:

var nil = (object)null;
var source = new[] { "foo", null, "bar", null, "baz" };
var result = source.ScanBy(c => c, k => nil, (i, k, e) => nil);
foreach (var item in result)
    Console.WriteLine(item);

It prints the following:

[foo, ]
[, ]
[bar, ]

before throwing an ArgumentNullException:

System.ArgumentNullException: Value cannot be null. (Parameter 'key')
   at System.Collections.Generic.Dictionary`2.FindValue(TKey key)
   at System.Collections.Generic.Dictionary`2.TryGetValue(TKey key, TValue& value)
   at MoreLinq.Collections.Dictionary`2.TryGetValue(TKey key, TValue& value) in C:\projects\morelinq\MoreLinq\Collections\Dictionary.cs:line 69
   at MoreLinq.MoreEnumerable.<>c__DisplayClass226_0`3.<<ScanBy>g___|0>d.MoveNext() in C:\projects\morelinq\MoreLinq\ScanBy.cs:line 100

@atifaziz atifaziz added the bug label Mar 17, 2021
@atifaziz
Copy link
Member Author

@viceroypenguin Thanks for the review!

@atifaziz atifaziz merged commit 9d71dae into morelinq:master Mar 18, 2021
@atifaziz atifaziz deleted the fix-dict-null-key branch March 18, 2021 12:41
@atifaziz atifaziz added this to the 3.4.0 milestone Mar 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants