Fix #368: generate proper expression for null-coalescing operators on nullable types#369
Merged
metoule merged 1 commit intodynamicexpresso:masterfrom Oct 6, 2025
Merged
Conversation
Contributor
Author
|
Back to draft, so that I can see how to handle the other binary operators. |
Contributor
Author
|
After playing with sharplab, I discovered that for nullable types, the .NET compiler generates: int? a;
int b = a ?? 10; // int b = a.GetValueOrDefault(10);int? a;
bool b = a > 10; // bool b = (a.GetValueOrDefault() > 10) & a.HasValueI'll update the PR to match this. |
Contributor
Author
|
It's actually ready, the other binary operators are properly resolved (e.g. |
davideicardi
approved these changes
Oct 6, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The expression we generate for the null-coalescing operator doesn't work for nullable types, because there's no comparison operator between a nullable type and an object:
This PR changes the generated expression for nullable types from
expr == null ? exprRight : exprtoexpr.HasValue ? expr.Value : exprRightFix #368