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

'Convert switch statement to expression' breaks code. #36876

Closed
CyrusNajmabadi opened this issue Jun 28, 2019 · 2 comments · Fixed by #38007
Closed

'Convert switch statement to expression' breaks code. #36876

CyrusNajmabadi opened this issue Jun 28, 2019 · 2 comments · Fixed by #38007
Labels
Area-IDE Bug Resolution-Fixed The bug has been fixed and/or the requested behavior has been implemented
Milestone

Comments

@CyrusNajmabadi
Copy link
Member

Conversion on:

                long target;
                try
                {
                    switch (origin)
                    {
                        case SeekOrigin.Begin:
                            target = offset;
                            break;

                        case SeekOrigin.Current:
                            target = checked(offset + position);
                            break;

                        case SeekOrigin.End:
                            target = checked(offset + length);
                            break;

                        default:
                            throw new ArgumentOutOfRangeException(nameof(origin));
                    }
                }
                catch (OverflowException)
                {
                    throw new ArgumentOutOfRangeException(nameof(offset));
                }

                if (target < 0)
                {
                    throw new ArgumentOutOfRangeException(nameof(offset));
                }

Produced:

                try
                {
                    var target = origin switch
                    {
                        SeekOrigin.Begin => offset,

                        SeekOrigin.Current => checked(offset + position),

                        SeekOrigin.End => checked(offset + length),

                        _ => throw new ArgumentOutOfRangeException(nameof(origin)),
                    };
                }
                catch (OverflowException)
                {
                    throw new ArgumentOutOfRangeException(nameof(offset));
                }

                if (target < 0)
                {
                    throw new ArgumentOutOfRangeException(nameof(offset));
                }
@jinujoseph jinujoseph added the Bug label Jul 2, 2019
@jinujoseph jinujoseph added this to the 16.3 milestone Jul 2, 2019
@jinujoseph
Copy link
Contributor

@jasonmalinowski Is this a Duplicate of #36608

@alrz
Copy link
Contributor

alrz commented Jul 2, 2019

I think not. this is about the use after switch (should not move decl). #36608 is about the common/target type.

@jinujoseph jinujoseph modified the milestones: 16.3, Backlog Aug 9, 2019
ryzngard added a commit that referenced this issue Oct 3, 2019
Bugfixes for ConvertSwitchStatementToExpression

Fixes #37949 (leave open for offering the fix instead of bail out)
Fixes #37950 (will be resolved on the compiler side)
Fixes #36876
Fixes #37873
Fixes #37872
Fixes #37907
Fixes #37947
Closes #36877 (duplicate of #37873)
@jinujoseph jinujoseph modified the milestones: Backlog, 16.4.P3 Oct 3, 2019
@jinujoseph jinujoseph added the Resolution-Fixed The bug has been fixed and/or the requested behavior has been implemented label Oct 3, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-IDE Bug Resolution-Fixed The bug has been fixed and/or the requested behavior has been implemented
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants