-
Notifications
You must be signed in to change notification settings - Fork 63
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
null-conditional for boolean operation should be typed to nullable #624
Comments
@jrmoreno1 If ids?.Any() Then
Console.WriteLine(ids.First)
End If Or directly:
|
@VBAndCs : I know how to make it work, I am saying that how it works is wrong. Any returns a Boolean, ?.Any returns a nullable Boolean, nullable booleans should not require parentheses in order to work. |
@jrmoreno1
|
Hey @jrmoreno1, I'm pretty sure I was the language PM when this feature was implemented (or soon thereafter). The behavior you're describing is confusing and the behavior you want makes perfect sense in the exact scenario you're describing. I can't change it but perhaps I can provide some context as to why it behaves as it does by design. First, it's important to point out the the way Second, as to how it is designed--we had a very heated debate when implementing this feature in both VB and C# as to whether the feature would be left-associative or right-associative, i.e. whether Your original post appears to be requesting that for Boolean functions specifically, Given the expression Interestingly enough, the members of Now for value types this isn't that bad because the members if So back to your specific exception: Boolean functions. Booleans tend to be terminal in member access chains--if All of that being said, I agree your situation sucks. I think the reason is that most of what we consider a person will do with nullable result of a That's a lot of words to say, the team almost certainly can't (and won't) do what you're asking. I tried to provide some context of how we got here. Now all I can do is try to think of ways to help you and others that fall into this unfortunate ditch on the side of the road (in my next comment). |
OK, so:
I personally like Option 3 as a compromise. Not sure if the IDE would accept a PR doing this, and no one has volunteered to do the work, and I also don't know if you find it acceptable. I find a lot of language/tooling decisions I think about lately to fall into a "don't want to have to say it" vs "don't want to have to see it" dichotomy. My solution addressing having to say the parentheses though your original post suggests you don't want to see them either and there just isn't anything to be done about that at this point :( Warmest regards, -ADG |
@AnthonyDGreen : I used Boolean, simply because that was where I was encountering it, and it seems especially egregious. Thanks for the explanation, it does make sense, and a primitive could have a ToString after it…so even they wouldn’t necessarily be the end of the chain. I generally find If(a,b) at least as good as ??, but this is definitely an exception. I have done some analyzers / code fixes but not for a while and not much. I’ll have to check to see if just parentheses does what I want…. |
The Null Conditional operator when used in conjunction with a boolean function should result in a nullable value and not require parentheses around it before checking GetValueOrDefault or HasValue
vs
The text was updated successfully, but these errors were encountered: