Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No suggestions in switch expression arm when dotting on an enum type in a Color Color case #75350

Open
Rekkonnect opened this issue Oct 2, 2024 · 3 comments · May be fixed by #75373
Open

No suggestions in switch expression arm when dotting on an enum type in a Color Color case #75350

Rekkonnect opened this issue Oct 2, 2024 · 3 comments · May be fixed by #75373
Labels
Area-IDE Bug help wanted The issue is "up for grabs" - add a comment if you are interested in working on it
Milestone

Comments

@Rekkonnect
Copy link
Contributor

Version Used

VS 2022 Version 17.11.4
Roslyn 4.11.0 (5649376)

Project info
C# 12.0
.NET 8.0

Steps to Reproduce

Paste the following snippet and place the cursor at the position of $$:

public sealed record OrderModel(int Id, Status Status)
{
    public string StatusDisplay
    {
        get
        {
            return Status switch
            {
                Status.$$
            }
        }
    }
}

public enum Status
{
    Undisclosed,
    Open,
    Closed,
}

In SharpLab

In the above example, the auto complete will not show any suggestions. Note that this also works in a regular class, not binding to the primary constructor parameter, and also when the current context is a static method.

Expected Behavior

I get all the suggestions for the enum field values of Status that I can use.

Actual Behavior

No suggestions appear.

@dotnet-issue-labeler dotnet-issue-labeler bot added Area-Compilers untriaged Issues and PRs which have not yet been triaged by a lead labels Oct 2, 2024
@CyrusNajmabadi CyrusNajmabadi added Bug help wanted The issue is "up for grabs" - add a comment if you are interested in working on it Area-IDE and removed Area-Compilers untriaged Issues and PRs which have not yet been triaged by a lead labels Oct 2, 2024
@CyrusNajmabadi CyrusNajmabadi added this to the Backlog milestone Oct 2, 2024
@Rekkonnect
Copy link
Contributor Author

Can I take this up?

@CyrusNajmabadi
Copy link
Member

Yes :)

@Rekkonnect
Copy link
Contributor Author

This also hides an actual bug of a very unusual Color Color case shown below:

public sealed record OrderModel(int Id, Outer.Status Status)
{
    public string Outer { get; }
    public string Inner { get; }

    public string StatusDisplay
    {
        get
        {
            return this switch
            {
                { Inner: Outer.Status.A } => "",
                { Inner: Outer } => "",
            };
        }
    }
}

public static class Outer
{
    public enum Status { A, B, C }
}

Outer binds to the property Outer, despite being directly inside a ConstantPattern, because it is a SimpleMemberAccess. When binding, SimpleMemberAccess is evaluated to always resolve Color Color cases, regardless of the context, assuming that the convention was to use SimpleMemberAccess when there is the probability of binding to a member or a type, and QualifiedName when we will always expect a type.

This same bug can also be observed in parenthesized constant patterns:

public sealed record OrderModel(int Id, Status Status)
{
    public string StatusDisplay
    {
        get
        {
            if (Status is (Status.$$))
                ;
        }
    }
}

public enum Status
{
    Undisclosed,
    Open,
    Closed,
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-IDE Bug help wanted The issue is "up for grabs" - add a comment if you are interested in working on it
Projects
Status: InQueue
Development

Successfully merging a pull request may close this issue.

2 participants