`[param: NotNull]` on property set accessor not respected for nullability analysis
- Dominant language
- C#
- Stars
- 20.7k
- Forks
- 4.3k
- PR merge metrics
- PR metrics pending
Description
**Version Used**:
.NET SDK 9.0.305
**Steps to Reproduce**:
https://lab.razor.fyi/#4zrAzMUVUJSfXpSYq5dcLLSRubQ4My9dIbiyuCQ115oLmafnkpmYnpdfXJKZXKznnJ-S6piXmFNZnFlszcWVnJNYXKwANYirmktBQUGhLD8zRSEktbjEUCM_KSs1ucReoUBTASIHAgEKtgoF1nAuRI1CPlhUQV_fOdjCzMAALF2Lap4RdvN8NQo0cRjHhTAFpjUASWd0QWJRYq6Vgl9-iV9pTk4sXKI4tQRJGQg4FqWX5qbmgdW5ViSnFpRk5ufphWQU5Zd7poEENcoSc0pTkRwCsRbJC74a0TCL4K7JR_YIYTvyoebXctVyebGlFhXlFxVHcXIcWXv63aY0AZYERgA
```csharp
using System;
using System.Diagnostics.CodeAnalysis;
class Program
{
void Test1(object? p) {
P = p;
object o = p; //CS8600
}
void Test2(object? p) {
M(p);
object o = p;
}
object? P {
[param: NotNull]
set {
ArgumentNullException.ThrowIfNull(value);
}
}
void M([NotNull] object? o) {
ArgumentNullException.ThrowIfNull(o);
}
}
```
**Diagnostic Id**:
```
Program.cs(8,20): warning CS8600: Converting null literal or possible null value to non-nullable type.
```
**Expected Behavior**:
`NotNull` on set accessor should be respected as [documented](https://learn.microsoft.com/en-us/dotnet/api/system.diagnostics.codeanalysis.notnullattribute?view=net-9.0):
>Specifies that an input argument was not `null` when the call returns.
The same way it happens for method parameter in `Test2`.
**Actual Behavior**:
Warning produced.
Contributor guide
Assessment
This issue has not been assessed yet.