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 "TrySingle" signature with honest nullable annotations #801

Merged
merged 1 commit into from
Mar 18, 2021

Conversation

atifaziz
Copy link
Member

There was a to-do comment pending since PR #582 that questioned whether we could be more honest with the signatures of TrySingle regarding T being null when cardinality isn't one. Starting with C# 9, it looks like we can finally address this with unconstrained type parameter annotations:

In C#8, ? annotations could only be applied to type parameters that were explicitly constrained to value types or reference types. In C#9, ? annotations can be applied to any type parameter, regardless of constraints.

This PR fixes the signatures to be more honest and removes the need for the use of the dammit (!) operator within the implementation body.

We still can't express that T isn't null when cardinality is one (e.g. through some of the helper attributes for the compiler) but the new annotations are far better than what was there before.

@atifaziz
Copy link
Member Author

@viceroypenguin Thanks for the review!

@atifaziz atifaziz merged commit dae1660 into morelinq:master Mar 18, 2021
@atifaziz atifaziz deleted the fix-TrySingle-nrt-annotations branch March 18, 2021 17:58
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

2 participants