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

Projects

Status

Backlog

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions