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

CC0019: switch suggested even when a break statement is present #1016

Open
GGG-KILLER opened this issue Dec 20, 2018 · 0 comments
Open

CC0019: switch suggested even when a break statement is present #1016

GGG-KILLER opened this issue Dec 20, 2018 · 0 comments

Comments

@GGG-KILLER
Copy link

Summary

CC0019 (Convert to switch) suggests the code transformation even for if statements that have a break statement in the body of one of the clauses.

Example

var str = "aaaaa";
for(var i = 0; i < 5; i++ )
{
    var c = str[i];
    if ( c == 'a' )
        Console.WriteLine ( "It's an A." );
    else if ( c == 'b' )
        break;
    else if ( c == 'c' )
        Console.WriteLine ( "It's a B." );
    else
        Console.WriteLine ( "It's not an A nor B." );
}

Current output after fix applied

var str = "aaaaa";
for(var i = 0; i < 5; i++ )
{
    var c = str[i];
    switch ( c )
    {
        case 'a':
            Console.WriteLine ( "It's an A." );
            break;
        case 'b':
            // The break statement's behavior cannot be preserved
            // when the if statement is converted to a switch statement.
            break;
            break;
        case 'c':
            Console.WriteLine ( "It's a B." );
            break;
        default:
            Console.WriteLine ( "It's not an A nor B." );
            break;
    }
}

Expected behavior

CC0019 is not raised.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants