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 NullReferenceException when passing null to a nullable argument but trying to match it with a non-nullable IsAny. #160

Merged
merged 1 commit into from
Mar 10, 2015
Merged

Fix NullReferenceException when passing null to a nullable argument but trying to match it with a non-nullable IsAny. #160

merged 1 commit into from
Mar 10, 2015

Conversation

benjamin-hodgson
Copy link

This fixes issue #90.

The problem was that Matches() has to cast its input to the type parameter T in order to call the Condition function.
Since T is not a reference type, it does not accept nulls and throws a NullReferenceException at the site of the cast.

We get around this by treating value types as a special case inside Matches. If T is a value type and the input is null, it clearly doesn't match (since value types are not nullable).

…ut trying to match it with a non-nullable IsAny.

This fixes issue #90.

The problem was that Matches() has to cast its input to the type parameter T in order to call the Condition function.
Since T is a reference type, it does not accept nulls and throws a NullReferenceException at the site of the cast.

We get around this by treating value types as a special case. If T is a value type and the input is null, it clearly doesn't match (since value types are not nullable).
kzu added a commit that referenced this pull request Mar 10, 2015
…ptionFromIsAny

Fix NullReferenceException when passing null to a nullable argument but trying to match it with a non-nullable IsAny.
@kzu kzu merged commit 8bc9b11 into devlooped:master Mar 10, 2015
@benjamin-hodgson benjamin-hodgson deleted the 90_fixNullReferenceExceptionFromIsAny branch March 10, 2015 23:34
@anonymous112233
Copy link

This seem to back as of latest v. 4.2.1506.2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants