-
Notifications
You must be signed in to change notification settings - Fork 90
Null-Coalescing Changes in V8 #737
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
Labels
meeting: priority
Review before meeting. Merge, merge with issues, or reject at the next TC49-TC2 meeting
Milestone
Comments
Based on some testing using unconstrained type parameters with
Can you wordsmith from here? |
Make sure it allows public class C {
public void M<T1, T2>(T1 a, ref T2 b) where T1 : T2 {
b ??= a;
}
} |
BillWagner
added a commit
to BillWagner/csharpstandard
that referenced
this issue
May 7, 2025
Fixes dotnet#737 Add the language to the null-coalescing operator so that `??` can be used with an unconstrained type parameter.
BillWagner
added a commit
that referenced
this issue
May 14, 2025
* Unconstrainted type parameters and `??` Fixes #737 Add the language to the null-coalescing operator so that `??` can be used with an unconstrained type parameter. * Revert "Unconstrainted type parameters and `??`" This reverts commit a958a37. * Do this the easy way. I think this can be done the easy way. After reverting the original change, this commit removes the phrase "or a reference type" from the first bullet. By doing that, an unconstrained type parameter `T` is allowed. It's not a reference type. I tested the case Nigel and Kalle described for using `??` with an unconstrained type parameter, and the existing rules produce the behavior they described. I ran a few other cases to validate, and those worked correctly as well. * Update standard/expressions.md Co-authored-by: Nigel-Ecma <[email protected]> * add exclusion on unmanaged types Respond to Nigel's question * respond to feedback Change "a non-nullable value type" to "known to be a non-nullable value type". Add an example to illustrate that `a ?? b` is `a` when the type of `a` is a non-nullable value type used as a type argument to an unconstrained type parameter. * Update standard/expressions.md Co-authored-by: Jon Skeet <[email protected]> * extend the bulleted list. * fix test harness issue * Update standard/expressions.md * Update standard/expressions.md --------- Co-authored-by: Nigel-Ecma <[email protected]> Co-authored-by: Jon Skeet <[email protected]>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
meeting: priority
Review before meeting. Merge, merge with issues, or reject at the next TC49-TC2 meeting
@BillWagner
This issue interacts with PR #609, “Add support for Null-coalescing assignment”.
Background
??
(§11.14 in V7); however, support for??=
was not included.??=
. Using the MS spec for this feature, Rex created Draft PR 609.??
and??=
. Here’s a simple example:Current Situation
More than a year after he wrote the PR 609 text, Rex recognized that PR and the unconstrained type parameters topic are related, and he is now trying to figure out what the spec should be for allowing unconstrained type parameters. His current thinking is:
??
and??=
.??=
and supporting unconstrained type parameters as separate features, it seems appropriate to combine them into one PR.??
operator section, and only if that impacts??=
should it be mentioned in the compound-assignment section as well.??=
went into the “Assignment operators” sections; there were no changes to the??
operator section itself. In hindsight, we should review the two sections to make sure they work together, and preserve the general notion that the compound-assignment operators be defined in terms of their non-assignment counterparts.Bottom line
Rex needs someone to
The text was updated successfully, but these errors were encountered: