Skip to content

Commit

Permalink
Check if parameter reference is inside expression tree (fix #902) (RC…
Browse files Browse the repository at this point in the history
…S1231)
  • Loading branch information
josefpihrt committed May 26, 2022
1 parent 54c9b66 commit e0c64de
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,8 @@ public override void VisitIdentifierName(IdentifierNameSyntax node)
&& SymbolEqualityComparer.Default.Equals(parameterSymbol, SemanticModel.GetSymbol(node, CancellationToken)))
{
if (_localFunctionDepth > 0
|| _anonymousFunctionDepth > 0)
|| _anonymousFunctionDepth > 0
|| node.IsInExpressionTree(SemanticModel, CancellationToken))
{
Parameters.Remove(name);
}
Expand Down
23 changes: 23 additions & 0 deletions src/Tests/Analyzers.Tests/RCS1231MakeParameterRefReadOnlyTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,29 @@ void M(bool value)
{
}
}
");
}

[Fact, Trait(Traits.Analyzer, DiagnosticIdentifiers.MakeParameterRefReadOnly)]
public async Task TestNoDiagnostic_ExpressionTree()
{
await VerifyNoDiagnosticAsync(@"
using System;
using System.Linq;
class C
{
public void M(DateTime dt)
{
var items = default(IQueryable<C>);
var x = from item in items
where item.P <= dt
select item;
}
public DateTime P { get; set; }
}
");
}
}
Expand Down

0 comments on commit e0c64de

Please sign in to comment.