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

Proposal: null-conditional call #261

Closed
dmitriyse opened this issue Mar 13, 2017 · 13 comments
Closed

Proposal: null-conditional call #261

dmitriyse opened this issue Mar 13, 2017 · 13 comments

Comments

@dmitriyse
Copy link

Func<int, string> myFunc = null;
if (myFunc?(10) == null)
{
    Console.WriteLine("Every body happy now");
}
@HaloFour
Copy link
Contributor

Func<int, string> myFunc = null;
if (myFunc?.Invoke(10) == null)
{
    Console.WriteLine("Every body happy now");
}

@dmitriyse
Copy link
Author

dmitriyse commented Mar 13, 2017

Probably I need some sleep. :)
This proposal gives too few benefits, and we can close it. But if it have low cost, then it can be part of #35 improvement.

@alrz
Copy link
Contributor

alrz commented Mar 13, 2017

@dmitriyse

AFAIK This was considered in the design of C# 6.0 and discarded because of ambiguities with ternary.

@dmitriyse
Copy link
Author

Then closing it.

@dmitriyse
Copy link
Author

@alrz Please provide some case, where it gives ambiguity. If you remember.

@dmitriyse
Copy link
Author

Probably it was declined due to cost/scheduling more than ambiguity?

@jnm2
Copy link
Contributor

jnm2 commented Mar 13, 2017

I remember the ambiguity too. Plus, writing out .Invoke makes the code easier to read imo.

@ufcpp
Copy link

ufcpp commented Mar 13, 2017

@dmitriyse
It was due to ambiguity between null-conditional call f?(10) and conditional operator f ? (10) : 20.

@dmitriyse
Copy link
Author

Good example, thanks.

@Mardoxx
Copy link

Mardoxx commented Nov 10, 2017

@ufcpp what ambiguity? f?(10) has no colon after it.


I see what you mean now...

Actually no, I don't see how this is reason for it to be rejected?

Unless this proposal would make `?` a unary operator, taking precedence over ternary, so the `f ? (10) : 20` would be interpreted as `x?(10) : 20` which is nonsense?

@CyrusNajmabadi
Copy link
Member

The problem is that whne you see the ?( you don't have enough information to make the determination. The part that follows the ?( may be arbitrarily complex. This means you'd have to do an enormous complex scan (or an expensive speculative parse) to figure out what was going on. For example, if you had:

f?(a, b).ToString()

What is? Well, you still can't tell. Maybe it's your new nullable-call, or maybe it's a ternary that has a tuple on the 'true' side.

Given that you have full expression facilities available to you (i.e. 'a' and 'b' can be arbitrarily large), it's quite difficult to make a determination about what's going on.

Remember that resolving ambiguities doesn't mean just handling the simple case. It means handling all the cases :)

@Mardoxx
Copy link

Mardoxx commented Nov 10, 2017 via email

@CyrusNajmabadi
Copy link
Member

You're welcome :)

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

No branches or pull requests

7 participants