Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
1 change: 1 addition & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Fix analyzer [RCS1265](https://josefpihrt.github.io/docs/roslynator/analyzers/RCS1265) to not report catch clauses with a `when` filter ([PR](https://github.com/dotnet/roslynator/pull/1789))
- Fix analyzer [RCS0034](https://josefpihrt.github.io/docs/roslynator/analyzers/RCS0034) for types with a primary constructor and multiple constraint clauses ([PR](https://github.com/dotnet/roslynator/pull/1791))
- [CLI] Fix GitLab output format to use relative paths, forward slashes, and 1-based line numbers ([PR](https://github.com/dotnet/roslynator/pull/1792))
- Fix analyzer [RCS1231](https://josefpihrt.github.io/docs/roslynator/analyzers/RCS1231) to not report `CancellationToken` in sync methods returning `Task` ([PR](https://github.com/dotnet/roslynator/pull/1802))

## [4.16.0] - 2026-08-08

Expand Down
10 changes: 10 additions & 0 deletions src/Analyzers/CSharp/Analysis/RefReadOnlyParameterAnalyzer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ private static void AnalyzeMethodDeclaration(SyntaxNodeAnalysisContext context)
if (methodDeclaration.Modifiers.ContainsAny(SyntaxKind.AsyncKeyword, SyntaxKind.OverrideKeyword))
return;

IMethodSymbol methodSymbol = context.SemanticModel.GetDeclaredSymbol(methodDeclaration, context.CancellationToken);
Comment thread
josefpihrt marked this conversation as resolved.
Resolved

if (methodSymbol?.ReturnType.IsWellKnownTaskType() == true)
return;
Comment thread
josefpihrt marked this conversation as resolved.
Resolved

Analyze(context, methodDeclaration, methodDeclaration.ParameterList, methodDeclaration.BodyOrExpressionBody());
}

Expand Down Expand Up @@ -90,6 +95,11 @@ private static void AnalyzeLocalFunction(SyntaxNodeAnalysisContext context)
if (localFunction.Modifiers.Contains(SyntaxKind.AsyncKeyword))
return;

IMethodSymbol methodSymbol = context.SemanticModel.GetDeclaredSymbol(localFunction, context.CancellationToken);

if (methodSymbol?.ReturnType.IsWellKnownTaskType() == true)
return;

Analyze(context, localFunction, localFunction.ParameterList, localFunction.BodyOrExpressionBody());
}

Expand Down
17 changes: 17 additions & 0 deletions src/Tests/Analyzers.Tests/RCS1231MakeParameterRefReadOnlyTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,23 @@ public void M(DateTime dt)

public DateTime P { get; set; }
}
");
}

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

class C
{
public Task DoThatWay(CancellationToken cancellationToken)
{
return Task.FromCanceled(cancellationToken);
}
}
");
}
}
Loading