Skip to content

DataFlowAnalysis.WrittenOutside returning this #277

Closed
@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;

Activity

self-assigned this
on Feb 5, 2015
added
Concept-APIThis issue involves adding, removing, clarification, or modification of an API.
and removed
Concept-APIThis issue involves adding, removing, clarification, or modification of an API.
on Feb 5, 2015
gafter

gafter commented on Feb 5, 2015

@gafter
Member

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.

added
Resolution-By DesignThe behavior reported in the issue matches the current design
4 - In ReviewA fix for the issue is submitted for review.
and removed on Feb 5, 2015
JoshVarty

JoshVarty commented on Feb 6, 2015

@JoshVarty
ContributorAuthor

That makes sense, thanks!

removed
4 - In ReviewA fix for the issue is submitted for review.
on Feb 9, 2015
assigned and unassigned on Feb 10, 2015
assigned and unassigned on May 5, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

    Development

    No branches or pull requests

      Participants

      @jaredpar@JoshVarty@gafter@theoy

      Issue actions

        DataFlowAnalysis.WrittenOutside returning this · Issue #277 · dotnet/roslyn