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

SwitchStatement with When breaks even with body of switch #387

Closed
belav opened this issue Aug 3, 2021 · 2 comments · Fixed by #393
Closed

SwitchStatement with When breaks even with body of switch #387

belav opened this issue Aug 3, 2021 · 2 comments · Fixed by #393
Assignees
Milestone

Comments

@belav
Copy link
Owner

belav commented Aug 3, 2021

This is a side effect of #384 I found while testing the changes on https://github.com/belav/aspnetcore

With a regular switch statement, when the when breaks, it ends up inline with the body of the case statement

        switch (expression.Body)
        {
            case var body when body == expression.Parameters[0]:
                return CompileFromIdentityFunc(expression);
            case MemberExpression memberExpression
                when memberExpression.Expression is ConstantExpression constantExpression:
                return CompileCapturedConstant(memberExpression, constantExpression);
            default:
                return null;
        }

Here are a bunch of ideas I came up with for how to deal with it.

Use align 2 on the when

        switch (expression.Body)
        {
            case var body when body == expression.Parameters[0]:
                return CompileFromIdentityFunc(expression);
            case MemberExpression memberExpression
              when memberExpression.Expression is ConstantExpression constantExpression:
                return CompileCapturedConstant(memberExpression, constantExpression);
            default:
                return null;
        }

Use align 2 on the body of the case

        switch (expression.Body)
        {
            case var body when body == expression.Parameters[0]:
              return CompileFromIdentityFunc(expression);
            case MemberExpression memberExpression
                when memberExpression.Expression is ConstantExpression constantExpression:
              return CompileCapturedConstant(memberExpression, constantExpression);
            default:
              return null;
        }

Line up the when with the case

        switch (expression.Body)
        {
            case var body when body == expression.Parameters[0]:
                return CompileFromIdentityFunc(expression);
            case MemberExpression memberExpression
            when memberExpression.Expression is ConstantExpression constantExpression:
                return CompileCapturedConstant(memberExpression, constantExpression);
            default:
                return null;
        }

Indent and align 2 the when

        switch (expression.Body)
        {
            case var body when body == expression.Parameters[0]:
                return CompileFromIdentityFunc(expression);
            case MemberExpression memberExpression
                  when memberExpression.Expression is ConstantExpression constantExpression:
                return CompileCapturedConstant(memberExpression, constantExpression);
            default:
                return null;
        }

I think I lean towards Line up, or Indent + Align2

@pmccloghrylaing and @shocklateboy92, what do you think?

@shocklateboy92
Copy link
Collaborator

What would it look like if you double indent the when?

@belav
Copy link
Owner Author

belav commented Aug 3, 2021

Looks similar to Ident + Align2, I think I might like it a little better

        switch (expression.Body)
        {
            case var body when body == expression.Parameters[0]:
                return CompileFromIdentityFunc(expression);
            case MemberExpression memberExpression
                    when memberExpression.Expression is ConstantExpression constantExpression:
                return CompileCapturedConstant(memberExpression, constantExpression);
            default:
                return null;
        }

@belav belav self-assigned this Aug 8, 2021
@belav belav added this to the 0.9.9 milestone Aug 8, 2021
shocklateboy92 pushed a commit that referenced this issue Aug 9, 2021
…ody (#393)

closes #387
I went with Align 6
Double indent seemed a bit much, and lining up didn't look good in the case below
```c#
    case "D______________________________________________________________________"
    when D == 50:
    default:
    {
        break;
    }
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants