Skip to content

Simplify member access (IDE0002) code style rule suggestion generates broken code #56882

@RichardVesely

Description

@RichardVesely

Version Used:
Visual Studio 16.11.3

Steps to Reproduce:

using Qux = Foo.Bar;

public class Foo
{
    public enum Bar
    {
        Baz
    }

    public int Qux { get; set; }

    // Okay, but suggests IDE0002: Simplify member access, see Method2.
    public void Method1(Qux qux = Foo.Bar.Baz)
    {
    }

    // CS1061: 'int' does not contain a definition for 'Baz' and no accessible extension method 'Baz' accepting a first argument of type 'int' could be found (are you missing a using directive or an assembly reference?).
    public void Method2(Qux qux = Qux.Baz)
    {
    }
}

Expected Behavior:
Either a valid code that generates no errors or no suggestion.

Actual Behavior:
Code that worked before applying rule suggestion generates CS1061 error after. Either way, compiler should not confuse optional argument default value with property access.

Metadata

Metadata

Assignees

Labels

Area-IDEBughelp wantedThe issue is "up for grabs" - add a comment if you are interested in working on it

Type

No type
No fields configured for issues without a type.

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions