-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Closed as not planned
Description
- Proposal addedDiscussed in LDMDecision in LDMFinalized (rejected)Spec'edTo pick up a draggable item, press the space bar. While dragging, use the arrow keys to move the item. Press space again to drop the item in its new position, or press escape to cancel.
Specification: https://github.com/dotnet/csharplang/blob/main/proposals/param-nullchecking.md
In short though this allows for standard null validation on parameters to be simplified using a small annotation on parameters:
// Before
void Insert(string s) {
if (s is null)
throw new ArgumentNullException(nameof(s));
...
}
// After
void Insert(string s!!) {
...
}LDM history:
- https://github.com/dotnet/csharplang/blob/master/meetings/2019/LDM-2019-01-14.md
- https://github.com/dotnet/csharplang/blob/master/meetings/2019/LDM-2019-07-10.md#param
- https://github.com/dotnet/csharplang/blob/main/meetings/2022/LDM-2022-04-06.md#parameter-null-checking
- https://github.com/dotnet/csharplang/blob/main/meetings/2022/LDM-2022-04-13.md#parameter-null-checking
yaakov-h, orthoxerox, qrli, DavidArno, Unknown6656 and 277 moreLiminiens, tupieurods, MrJul, Neme12, alrz and 104 moreHalidCisse, ruxo, TheFanatr, weitzhandler, bonesoul and 4 moreDavidArno, Unknown6656, GrabYourPitchforks, jrusbatch, DamienFlury and 23 moremaxkatz6, gatsbys, readonlyden, CCRcmcpe, joshuapassos and 22 morewhoisj, TheUnlocked, DamienFlury, napernik, alizahid4004 and 63 moresrkischa, jack9ye, alaatm, HalidCisse, TheFanatr and 10 morepaulomorgado, 0xced, HalidCisse, krlosmederos, TheFanatr and 10 more
Metadata
Metadata
Assignees
Type
Projects
Milestone
Relationships
Development
Select code repository
Activity
Thaina commentedon Jan 15, 2019
Shouldn't this be
string!?And also doesn't C# will always warning on nullable reference type from now on?
jaredpar commentedon Jan 15, 2019
@Thaina
No. This feature is for runtime value checking only. It does not affect the type system in any way. Hence the syntax annotation is on the value identifier, not the type.
Nullable reference type checking is an opt-in feature. Also it is designed to warn on potential null references in the code base but it doesn't affect the execution semantics of it.
qrli commentedon Jan 15, 2019
Maybe over simple, though ๐
And it looks like a declaration rather than implementation
DavidArno commentedon Jan 15, 2019
Great to see this proposal has resurfaced, and has been championed. I think it an excellent idea but thought it had been lost amongst all the other work going on around NRTs. Thanks, @jaredpar. ๐
Joe4evr commentedon Jan 15, 2019
You say that, but the original idea does put it on the type.
GeirGrusom commentedon Jan 15, 2019
It's the dammit operator placed on the argument. It makes sense that it is applied to the value rather than the type.
alrz commentedon Jan 15, 2019
that logic works only for parameters not property setters (that's why we'd need to invent syntax like
set!). to me, this is more of a very specific code generation problem (what if I just want to Assert?), IMO the functionality should be a part of method contracts, or alternatively, some special attribute (which could be extended to other validation logics as well).Thaina commentedon Jan 15, 2019
@Joe4evr If I understand it right (from the jaredpar's comment after mine) this is actually newer feature unrelated to nullable reference type. It just a syntactic sugar to throw exception while nullable reference type is compile time warning
Logerfo commentedon Jan 15, 2019
is this feature supposed to ship with 8.0 as well?
DavidArno commentedon Jan 15, 2019
@Logerfo, my money is on "unlikely, but not impossible". Seems a candidate for 8.1+ to me. But I could be wrong...
bbarry commentedon Jan 16, 2019
In isolation I think this is great but I'd much rather see a more comprehensive contract annotation system with a potential way to expand it for pattern matching validations and potentially even arbitrary code validation as well as return value validations, even if those advancements don't come as part of a first version of this.
In short I worry that this:
means something like this will never happen:
Joe4evr commentedon Jan 16, 2019
You're not wrong in that this feature could be achieved without NRTs, but the initial idea of having the compiler generate null checks for parameters (which is an extremely common scenario) came up during discussions of the NRT design. (Or rather, that was the moment the LDT would take it seriously. Theoretically, we could've had a syntax for generated null-checks ages ago.)
And while it's true that the check is about the value and not the type, applying the
!to the type 1) makes it more symmetrical, and 2) would probably make a lot of edge cases moot. (Granted, the reverse index syntax shows how much they care about symmetry. ยฏ\_(ใ)_/ยฏ)784 remaining items
Thaina commentedon Apr 19, 2022
I don't think they was just cancel it, it just being removed from C#11 because it not ready yet. It might come back later, but not now
AraHaan commentedon Apr 19, 2022
Honestly the only form of param null checking I can think of are:
%at the end instead.[NotNull]attribute which then implicitly gets executed (with compiler inserted code to do so on it's parameters) that then calls theThrowIfNull()function for us (but expose the attribute as a keyword where the compiler can transform it to the attribute and insert the code to "run the attribute's code inside").AraHaan commentedon Apr 20, 2022
@jaredpar why not keep this open for further discussion into possibly having this refined for future C# versions instead of closing it so that way more ideas for refinement can flow in?
Also just thought of this option as well:
Where the existing keywords could be used by the compiler to insert an
ThrowIfNull()call for each param marked withnot nullfrom pattern matching (but reused for this feature).CyrusNajmabadi commentedon Apr 20, 2022
This is an issue, which tracked an actual championed proposa/implementation. For a discussion, there should be an actual github discussion for it (which could link to this for example).
kimsey0 commentedon Apr 20, 2022
For context, here are the minutes from the two Language Design meetings that lead to the feature being removed:
https://github.com/dotnet/csharplang/blob/main/meetings/2022/LDM-2022-04-06.md#parameter-null-checking
https://github.com/dotnet/csharplang/blob/main/meetings/2022/LDM-2022-04-13.md#parameter-null-checking
CyrusNajmabadi commentedon Apr 20, 2022
@AraHaan we considered that syntax but didn't like it. See the notes in: https://github.com/dotnet/csharplang/blob/main/meetings/2022/LDM-2022-04-13.md#parameter-null-checking
sungaila commentedon Apr 20, 2022
I love that idea! Microsoft Research had these .NET code contracts for testing 14 years ago. Having pre-/postconditions, invariants and parameter null checking with first class language and compiler support would be awesome.
This would be one of the biggest and best C# releases yet!
AraHaan commentedon Apr 20, 2022
While the LDM members might not like it, the community might. Same for using contracts to check for nulls. I think having all 3 of them as an option but as an
.editorconfigoption to select their personal preference on what they want to be used for param null checking.There are devs who would prefer these for null checking:
!!(the current syntax)not null(reuse these pattern matching keywords so devs new to C# can get the general idea that the function will throw if they pass in null (the!!for dummies as some people say).where s1, b1 is not null;for using contracts to check multiple parameters at one time without having to mark each one with!!but do the same thing.!!can be exhausting depending on how many of such functions they have in their code.CyrusNajmabadi commentedon Apr 20, 2022
We will not do that. We're not going to add multiple redundant syntaxes because there are lots of different opinions on what people personally prefer for each of these areas.
TahirAhmadov commentedon Jul 15, 2022
Is there an issue/discussion and/or a champion for
!!in expressions?HaloFour commentedon Jul 15, 2022
@TahirAhmadov
Discussion, yes: #6034
Champion, no.
julealgon commentedon May 23, 2024
@jaredpar Shouldn't this issue be removed from the
Working Setmilestone, and also be "Closed as Not Planned" instead of "Closed as Completed"?Right now, it gives the impression that this is implemented and coming again in C# 13.
jaredpar commentedon May 23, 2024
@julealgon changed to not planned but generally we don't remove the milestones when closing.