Issue 52130. Fix 'Inline Local' refactoring inside SwitchPatternCase.

Bug: https://github.com/dart-lang/sdk/issues/52130
Change-Id: Ic84e4781e12dece3775fc0462b727a6a9b9c9906
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/306125
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
This commit is contained in:
Konstantin Shcheglov 2023-05-26 19:38:48 +00:00 committed by Commit Queue
parent 4d21b9e5aa
commit faa16fc565
2 changed files with 25 additions and 26 deletions

View file

@ -203,7 +203,9 @@ class InlineLocalRefactoringImpl extends RefactoringImpl
var statement = declarationList.parent;
if (statement is VariableDeclarationStatement) {
var parent = statement.parent;
if (parent is Block || parent is SwitchCase) {
if (parent is Block ||
parent is SwitchCase ||
parent is SwitchPatternCase) {
return statement;
}
}

View file

@ -154,31 +154,6 @@ void f() {
''');
}
@FailingTest(issue: 'https://github.com/dart-lang/sdk/issues/49759')
Future<void> test_OK_inSwitchCase() async {
await indexTestUnit('''
void f(int p) {
switch (p) {
case 0:
int test = 42;
print(test);
break;
}
}
''');
_createRefactoring('test =');
// validate change
return assertSuccessfulRefactoring('''
void f(int p) {
switch (p) {
case 0:
print(42);
break;
}
}
''');
}
Future<void> test_OK_inSwitchCase_language219() async {
await indexTestUnit('''
// @dart=2.19
@ -205,6 +180,28 @@ void f(int p) {
''');
}
Future<void> test_OK_inSwitchPatternCase() async {
await indexTestUnit('''
void f(Object? x) {
switch (x) {
case _?:
var test = 42;
print(test);
}
}
''');
_createRefactoring('test =');
// validate change
return assertSuccessfulRefactoring('''
void f(Object? x) {
switch (x) {
case _?:
print(42);
}
}
''');
}
Future<void> test_OK_intoStringInterpolation_binaryExpression() async {
await indexTestUnit(r'''
void f() {