Browse Source

Fixed bug in redundant assignment issue.

pull/32/merge
Mike Krüger 13 years ago
parent
commit
ba13e28750
  1. 4
      ICSharpCode.NRefactory.CSharp/Refactoring/CodeIssues/RedundantAssignmentIssue.cs
  2. 32
      ICSharpCode.NRefactory.Tests/CSharp/CodeIssues/RedundantAssignmentIssueTests.cs

4
ICSharpCode.NRefactory.CSharp/Refactoring/CodeIssues/RedundantAssignmentIssue.cs

@ -106,7 +106,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -106,7 +106,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
continue;
var parent = node.Parent;
while (!(parent == null || parent is Statement || parent is LambdaExpression))
while (!(parent == null || parent is Statement || parent is LambdaExpression || parent is QueryExpression))
parent = parent.Parent;
if (parent == null)
continue;
@ -118,7 +118,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -118,7 +118,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
}
while (parent != null && parent != rootStatement) {
if (parent is LambdaExpression || parent is AnonymousMethodExpression) {
if (parent is LambdaExpression || parent is AnonymousMethodExpression || parent is QueryExpression) {
usedInLambda = true;
break;
}

32
ICSharpCode.NRefactory.Tests/CSharp/CodeIssues/RedundantAssignmentIssueTests.cs

@ -461,5 +461,37 @@ class TestClass @@ -461,5 +461,37 @@ class TestClass
}";
Test<RedundantAssignmentIssue>(input, 2, output, 0);
}
/// <summary>
/// Bug 11795 - Use of regex in linq statement not being recognized.
/// </summary>
[Test]
public void TestBug11795 ()
{
TestWrongContext<RedundantAssignmentIssue>(@"
using System;
using System.Text.RegularExpressions;
using System.IO;
using System.Linq;
public class Test
{
public void Demo ()
{
Regex pattern = new Regex (@""^.*\.(jpg|png)$"", RegexOptions.IgnoreCase);
string path = Path.Combine (""/"", ""speakers"");
Console.WriteLine (
from file in Directory.GetFiles (path)
where pattern.IsMatch (file)
select file
);
}
}");
}
}
}
Loading…
Cancel
Save