BUG Convert to Linq-expression does incorrect transform

Initial code:


          var count=0;
          for(var i=0; i<5; i++) {
            foreach(var q in new[] { "aaa", "bbb", "ccc", "ddd" }) {
              count+=(i.ToString() + q).Length;
            }
          }
          Console.WriteLine("count is "+count);



Click anywhere inside the "foreach" word.
When the lightbulb popup appears, select "Convert to Linq-expression"

Result code:


          var count=0;
          for(var i=0; i<5; i++) {
            count=new[] {"aaa", "bbb", "ccc", "ddd"}.Sum(q => (i.ToString()+q).Length);
          }
          Console.WriteLine("count is "+count);


The new code replaces the value of count in each for-loop iteration rather than accumulating across iterations.

I've confirmed the bug in Resharper 5.0.1659.36 on Visual Studio 10.0.30319.1.



Thanks

1 comment
Comment actions Permalink

Hello Naju,

Thank you very much for reporting! This bug will be fixed in the upcoming
ReSharper 6.0. You can already get the nightly builds at http://confluence.jetbrains.net/display/ReSharper/ReSharper6.0Nightly+Builds.

Andrey Serebryansky
Senior Support Engineer
JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"

var count=0;
for(var i=0; i<5; i++) {
foreach(var q in new[] { "aaa", "bbb", "ccc", "ddd" }) {
count+=(i.ToString() + q).Length;
}
}
Console.WriteLine("count is "+count);



0

Please sign in to leave a comment.