Incorrect inferred nullability for slice pattern
- Dominant language
- C#
- Stars
- 20.7k
- Forks
- 4.3k
- PR merge metrics
- PR metrics pending
Description
It looks like that was intentional (`SetState(ref this.State, outputSlot, NullableFlowState.NotNull); // Slice value is assumed to be never null`) but the assumption is not necessarily correct.
```cs
#nullable enable
object? o1 = null;
if (Infer(o1) is [var x])
{
x.ToString(); // warning CS8602: Dereference of a possibly null reference.
}
object? o2 = null;
if (Infer(o2) is [.. var y])
{
y.ToString(); // missing warning
}
object? o3 = new object();
if (Infer(o3) is [var z1])
{
z1.ToString();
}
if (Infer(o3) is [.. var z2])
{
z2.ToString();
}
C Infer(T t) => throw null!;
class C
{
public int Length => 0;
public T this[int i] => throw null!;
public T Slice(int i, int j) => throw null!;
}
```
Contributor guide
Assessment
This issue has not been assessed yet.