Closed
Description
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
Projects
Milestone
Relationships
Development
No branches or pull requests
Activity
gafter commentedon Feb 5, 2015
this
should never appear in AlwaysAssigned because - except in a struct constructor - it is never (always) assigned within the region of code in question.this
should be treated just like any other value parameter in a class, ref parameter in a struct, and out parameter in a struct constructor.JoshVarty commentedon Feb 6, 2015
That makes sense, thanks!