Browse Source

[CodeIssues] ConstantConditionIssue: check if condition is compile time constant to avoid fake warnings

newNRvisualizers
Mansheng Yang 14 years ago
parent
commit
a27b0518ce
  1. 2
      ICSharpCode.NRefactory.CSharp/Refactoring/CodeIssues/ConstantConditionIssue.cs
  2. 3
      ICSharpCode.NRefactory.Tests/CSharp/CodeIssues/ConstantConditionIssueTests.cs

2
ICSharpCode.NRefactory.CSharp/Refactoring/CodeIssues/ConstantConditionIssue.cs

@ -88,7 +88,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -88,7 +88,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
return;
var resolveResult = ctx.Resolve (condition);
if (!(resolveResult.ConstantValue is bool))
if (!(resolveResult.IsCompileTimeConstant && resolveResult.ConstantValue is bool))
return;
var value = (bool)resolveResult.ConstantValue;

3
ICSharpCode.NRefactory.Tests/CSharp/CodeIssues/ConstantConditionIssueTests.cs

@ -172,10 +172,11 @@ class TestClass @@ -172,10 +172,11 @@ class TestClass
var input = @"
class TestClass
{
void TestMethod ()
void TestMethod (int x = true)
{
while (true) ;
if (false) ;
if (x) ;
}
}";
Test<ConstantConditionIssue> (input, 0);

Loading…
Cancel
Save