Skip to content

DataFlowAnalysis.WrittenOutside returning this #277

@JoshVarty

Description

@JoshVarty

The documentation on DataFlowAnalysis.WrittenOutside reads

The set of local variables that are written outside a region.

However, when I perform data flow analysis, I'm noticing that this is being returned as a parameter symbol within WrittenOutside.

Is this the intended behavior? Is this considered a local variable in this context? If so, should it not also be contained within AlwaysAssigned as this must always be assigned?

Here is the code I'm running:

var tree = CSharpSyntaxTree.ParseText(@"
public class Sample
{
   public void Foo()
   {
        int[] lcolSample = new int[10] { 0, 1, 2, 3, 4, 0, 1, 2, 3, 4};
        for (int lintCount1 = 0; lintCount1 < 10; lintCount1++)
        {
             Prog1(lintCount1);
             int[] lcolSample1 = new int[10] { 0, 1, 2, 3, 4, 0, 1, 2, 3, 4 };
             lintCount3 = lintCount3 + 100;
             lintCount1 = lintCount1 + 2;
             lcolSample1[lintCount1 - 1] = lcolSample[lintCount1] + 100;
        }
   }
}");

var Mscorlib = PortableExecutableReference.CreateFromAssembly(typeof(object).Assembly);
var compilation = CSharpCompilation.Create("MyCompilation",
    syntaxTrees: new[] { tree }, references: new[] { Mscorlib });
var model = compilation.GetSemanticModel(tree);

var forStatement = tree.GetRoot().DescendantNodes().OfType<ForStatementSyntax>().Single();
DataFlowAnalysis result = model.AnalyzeDataFlow(forStatement);

//Contains two symbols: this and lcolSample
var writtenOutside = result.WrittenOutside;

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions