You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If you have a loop that sets a variable living outside the scope of the loop without reading the variable, it results in faulty rewritten code. I have produced a minimal sample that demonstrates the problem.
The file "Program.cs" contains this code:
using System;
using System.Linq;
namespace RoslynLinqRewriteError
{
public static class Program
{
public static void Main()
{
var values = new int[] { 1, 2, 3 };
var result = 0;
foreach (var value in values.Where(x => (x % 2) == 0))
{
result = value;
}
Console.WriteLine(result);
}
}
}
Could not compile rewritten method. Consider applying a [Shaman.Runtime.NoLinqRewrite] attribute.
(18,9): error CS0103: The name 'result' does not exist in the current context
If you change result = value to result = result + value it compiles without problem because the variable is also read inside of the loop.
The text was updated successfully, but these errors were encountered:
If you have a loop that sets a variable living outside the scope of the loop without reading the variable, it results in faulty rewritten code. I have produced a minimal sample that demonstrates the problem.
The file "Program.cs" contains this code:
Compile it with this command:
This will result in the following error:
If you change
result = value
toresult = result + value
it compiles without problem because the variable is also read inside of the loop.The text was updated successfully, but these errors were encountered: