S5034 does not take ternary operators into consideration.
Repro steps
class Test
{
static ValueTask<IEnumerable> MakeGeneric(ValueTask<IEnumerable<T>> task)
=> task.IsCompletedSuccessfully
// S5034: Refactor this 'ValueTask' usage to consume the result only if the operation has completed successfully.
? ValueTask.FromResult<IEnumerable>(task.Result)
: MakeGenericSlow(task);
static async ValueTask<IEnumerable> MakeGenericSlow(ValueTask<IEnumerable<T>> task)
=> await task;
}
Expected behavior
No warning.
Actual behavior
S5034: Refactor this 'ValueTask' usage to consume the result only if the operation has completed successfully.
Known workarounds
class Test
{
static ValueTask<IEnumerable> MakeGeneric(ValueTask<IEnumerable<T>> task)
{
if (task.IsCompletedSuccessfully)
return ValueTask.FromResult<IEnumerable>(task.Result); // No warning.
return MakeGenericSlow(task);
}
static async ValueTask<IEnumerable> MakeGenericSlow(ValueTask<IEnumerable<T>> task)
=> await task;
}
Related information
SonarLint for Visual Studio 2022, version 8.9.0.92083
Visual Studio Professional 2022 (64 bit), version 17.10.4
dotnet 8.0.303
MSBuild version 17.10.4+10fbfbf2e for .NET Framework, version 17.10.4.21802
Description
S5034 does not take ternary operators into consideration.
Repro steps
Expected behavior
No warning.
Actual behavior
Known workarounds
Related information