dotnet / dotnet/roslyn

Enhance `await` usage warnings with null coalescing operator

Open
#75,010 0 comments 1 reaction 0 assignees View on GitHub
Area-Compilers Concept-Diagnostic Clarity Feature - Warning Waves Feature Request
Dominant language
C#
Stars
20.7k
Forks
4.3k
PR merge metrics
PR metrics pending

Description

**Brief description:**

When using the null coalescing operator on an async delegate there is no warning that `await` is missing. Example:

![image](https://github.com/user-attachments/assets/139595aa-e975-441c-acba-9d2c587d9beb)

First, we can see that `initialize()` triggers a warning, but not `initialize?.Invoke()`.
Besides, another warning could be displayed if someone simply adds `await` while using the operator as the result could be `null`.

**Languages applicable:**

I am not sure.

**Code example that the analyzer should report:**

1. `initialize?.Invoke()` -> missing await
2. `await initialize?.Invoke()` -> don't use await with coalescing operator

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.