Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Fixed

- Fix analyzer [RCS1229](https://josefpihrt.github.io/docs/roslynator/analyzers/RCS1229) ([PR](https://github.com/dotnet/roslynator/pull/1618))

### Added

- Add analyzer "Put expression body on its own line" [RCS0062](https://josefpihrt.github.io/docs/roslynator/analyzers/RCS0062) ([PR](https://github.com/dotnet/roslynator/pull/1593) by @cbersch)
Expand Down
10 changes: 5 additions & 5 deletions src/Analyzers/CSharp/Analysis/UseAsyncAwaitAnalyzer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ private bool IsCompletedTask(ExpressionSyntax expression)

return string.Equals(simpleMemberAccess.Name.Identifier.ValueText, "CompletedTask", StringComparison.Ordinal)
&& SemanticModel.GetSymbol(expression, CancellationToken) is IPropertySymbol propertySymbol
&& IsTaskOrTaskOrT(propertySymbol.ContainingType);
&& IsTaskOrTaskOfT(propertySymbol.ContainingType);
}
else
{
Expand All @@ -293,7 +293,7 @@ private bool IsCompletedTask(ExpressionSyntax expression)
if (SemanticModel.GetSymbol(expression, CancellationToken) is IMethodSymbol methodSymbol
&& (methodSymbol.Arity == 0 || methodSymbol.Arity == 1)
&& methodSymbol.Parameters.Length == 1
&& IsTaskOrTaskOrT(methodSymbol.ContainingType))
&& IsTaskOrTaskOfT(methodSymbol.ContainingType))
{
return true;
}
Expand All @@ -307,10 +307,10 @@ private bool IsCompletedTask(ExpressionSyntax expression)
return false;
}

private static bool IsTaskOrTaskOrT(INamedTypeSymbol typeSymbol)
private static bool IsTaskOrTaskOfT(INamedTypeSymbol typeSymbol)
{
return typeSymbol.HasMetadataName(MetadataNames.System_Threading_Tasks_Task)
|| typeSymbol.HasMetadataName(MetadataNames.System_Threading_Tasks_Task_T);
return typeSymbol.ContainingNamespace.HasMetadataName(MetadataNames.System_Threading_Tasks)
&& typeSymbol.MetadataName is "Task" or "Task`1" or "ValueTask" or "ValueTask`1";
}

public override void VisitLocalFunctionStatement(LocalFunctionStatementSyntax node)
Expand Down
20 changes: 20 additions & 0 deletions src/Tests/Analyzers.Tests/RCS1229UseAsyncAwaitTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -809,6 +809,26 @@ NonAwaitableTaskType<int> M2()
class NonAwaitableTaskType { }
[AsyncMethodBuilder(null)]
class NonAwaitableTaskType<T> { }
");
}

[Fact, Trait(Traits.Analyzer, DiagnosticIdentifiers.UseAsyncAwait)]
public async Task TestNoDiagnostic_ValueTask()
{
await VerifyNoDiagnosticAsync(@"
using System;
using System.IO;
using System.Threading.Tasks;

class C
{
ValueTask M()
{
using var memoryStream = new MemoryStream();

return ValueTask.CompletedTask;
}
}
");
}
}
Loading