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

Short-circuiting null check operator #2862

Closed
HosseinYousefi opened this issue Feb 24, 2023 · 3 comments
Closed

Short-circuiting null check operator #2862

HosseinYousefi opened this issue Feb 24, 2023 · 3 comments
Labels
feature Proposed language feature that solves one or more problems null-aware-expressions Issues proposing new expressions to manage null

Comments

@HosseinYousefi
Copy link
Member

Currently, instead of doing

a == null ? null : b

We can do

a ?? b

And instead of doing

a == null ? null : a.method()

We can do

a?.method()

However, we can't do this for other expressions, like function calls.

a == null ? null : f(a)

I propose a short-circuiting null check operator, so we can change the previous to this

f(??a)

Or convert this

a == null ? null : b == null ? null : a + b

into

??a + ??b

It can also be short-circuiting so in this example if f() is null then g won't be called:

??f() + ??g()

The operator itself doesn't have to be double question marks.

@HosseinYousefi HosseinYousefi added the feature Proposed language feature that solves one or more problems label Feb 24, 2023
@eernstg eernstg added the null-aware-expressions Issues proposing new expressions to manage null label Feb 24, 2023
@eernstg
Copy link
Member

eernstg commented Feb 24, 2023

Note that the following proposals touch upon a similar topic: null-aware-expressions Issues proposing new expressions to manage null .

@lrhn
Copy link
Member

lrhn commented Feb 24, 2023

Specifically issue #1592, which even tries to summarize all the other ideas.

@munificent
Copy link
Member

I'm going to go ahead and close this in favor of the other related issue and label.

@munificent munificent closed this as not planned Won't fix, can't repro, duplicate, stale Apr 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Proposed language feature that solves one or more problems null-aware-expressions Issues proposing new expressions to manage null
Projects
None yet
Development

No branches or pull requests

4 participants