Skip to content

Commit

Permalink
Added a comment describing the need to use "!" operator
Browse files Browse the repository at this point in the history
  • Loading branch information
iliar-turdushev committed Sep 26, 2024
1 parent 864e2eb commit 1392bec
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/Polly.Core/ResilienceProperties.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ public bool TryGetValue<TValue>(ResiliencePropertyKey<TValue> key, [MaybeNullWhe
}
else if (val is null)
{
// We have to use null-forgiving operator "!" here to suppress a null-state analysis warning.
// The reason is the following. The output type "TValue" doesn't have any type constraints as
// "notnull", "class" or "struct", therefore the analyzer considers "TValue" as non-nullable
// and warns us that we're assigning "null" to it. But that's not correct, because "TValue"
// could be a nullable type, e.g. "string?", and assigning "null" to it is correct. Therefore
// it is reasonable to use "!" here to suppress the warning.
value = default!;
return true;
}
Expand Down

0 comments on commit 1392bec

Please sign in to comment.