Got a false CS8602 warnning when use Null-conditional operator and Null-coalescing opreator in expression
- Dominant language
- C#
- Stars
- 20.7k
- Forks
- 4.3k
- PR merge metrics
- PR metrics pending
Description
**Version Used**:
- csc.dll: `4.13.0-3.25155.17+398aa319196d4684c751a3d7c75c847e519a393c`
- .NET SDK: `9.0.203-dc7acfa194`
**Steps to Reproduce**:
1. Compile follow code
2. Got a false `CS8602` warnning
[Sharplab](https://sharplab.io/#v2:D4AQTAjAsAULCCA7A9gFwBYFMBOAVTAzqgMIA2AhgQQPwAE5KGO+RZlBtAvLYgK6mkA3LACWAM1oAKAIQM0WPIRIUq1AHQBJArmy9MtanTHlSBTAEpYAb1i07tEBACckuU0WsVBTdt2Zb9oF0AETEDADGmALkqCLIiLTYmACOekSYACbBAYF2AFy0oRFRFLHxPGiJKWmomcHmwjAAvrCOLsEsqLQAtpgYyBm0mIgZdQ2wrWC0SPLMSmxU1jkOAMy0AEbIyKS0Wjp6XLTGppiNTUA)
```csharp
using System;
AnotherTestClass? anotherTestClass = null;
if (!anotherTestClass?.IsTrue ?? false)
{
// CS8602 at `anotherTestClass`
Console.WriteLine(anotherTestClass.IsTrue
? "Cancellation requested"
: "Cancellation not requested");
}
Console.WriteLine("Test method ended");
class AnotherTestClass
{
public bool IsTrue = false;
}
```
**Diagnostic Id**:
`CS8602: Dereference of a possibly null reference.`
**Expected Behavior**:
No warnning
**Actual Behavior**:
Got a false`CS8602` warnning
Contributor guide
Assessment
This issue has not been assessed yet.