Skip to content

MinimumSwitchCases does not redeclare variables in new blocks #687

@arthurvl

Description

@arthurvl

Suppose we have a switch case:

switch (someInt) {
    case 1:
            String data = getSomeString();
            doThingOneWith(data);
            break;
    case 2:
            data = getSomeOtherString();
            doThingTwoWith(data);
            break;
}

That will currently be rewritten by MinimumSwitchCases to

if (someInt == 1) {
        String data = getSomeString();
        doThingOneWith(data);
} else if (someInt == 2) {
        data = getSomeOtherString();
        doThingTwoWith(data);
}

which does not compile due to data not being declared in the else block's scope.

Metadata

Metadata

Assignees

Labels

Type

No type
No fields configured for issues without a type.

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions