Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Bug with CC0009 when using the created object in the initialization #525

@AdrianoRNascimento

Description

@AdrianoRNascimento

When the variable declaration does not have an initializer, and it is assigned, CC0009 is incorrectly triggered. This should not raise a diagnostic for CC0009:

class Foo
{
    public Foo F { get; set; }
    static void Baz()
    {
        Foo foo;
        foo = new Foo();
        foo.F = foo;
    }
}

We should check for that specific scenario.

This should still raise a diagnostic:

class Foo
{
    public Foo F { get; set; }
    static void Baz()
    {
        Foo foo;
        foo = Whatever();
        foo = new Foo();
        foo.F = foo;
    }
}

When there is a prior assignment between the variable declaration and it's assignment (or the variable being passed as ref or out to a method) CC0009 should still be raised.

This is a bug on the analyzer, not on the code fix provider.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions