Skip to content

Commit

Permalink
QuickFix. Issue 55804. Don't suggest creating local vriable when it i…
Browse files Browse the repository at this point in the history
…s a name of property.

Bug: #55804
Change-Id: Ib61c025855464e1b7f01116234624d936ee9bc89
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/368701
Reviewed-by: Phil Quitslund <pquitslund@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
  • Loading branch information
scheglov authored and Commit Queue committed May 29, 2024
1 parent 04d7213 commit 28da71b
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,17 @@ class CreateLocalVariable extends ResolvedCorrectionProducer {
return;
}
}

// In `foo.bar`, `bar` is not a local variable.
// It also does not seem useful to suggest `foo`.
// So, always skip with these parents.
var parent = nameNode.parent;
switch (parent) {
case PrefixedIdentifier():
case PropertyAccess():
return;
}

// prepare target Statement
var target = node.thisOrAncestorOfType<Statement>();
if (target == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,33 @@ void f() {
''');
}

@failingTest
Future<void> test_propertyAccess() async {
// We should not offer to define a local variable named 'g'.
Future<void> test_read_prefixedIdentifier_identifier() async {
await resolveTestCode('''
void f(String s) {
s.g;
void f(C c) {
c.test;
}
class C {}
''');
await assertNoFix();
}

Future<void> test_read_prefixedIdentifier_prefix() async {
await resolveTestCode('''
void f() {
test.foo;
}
''');
await assertNoFix();
}

Future<void> test_read_propertyAccess_propertyName() async {
await resolveTestCode('''
void f(C c) {
(c).test;
}
class C {}
''');
await assertNoFix();
}
Expand Down Expand Up @@ -287,4 +307,35 @@ void f() {
}
''');
}

Future<void> test_write_prefixedIdentifier_identifier() async {
await resolveTestCode('''
void f(C c) {
c.test = 0;
}
class C {}
''');
await assertNoFix();
}

Future<void> test_write_prefixedIdentifier_prefix() async {
await resolveTestCode('''
void f() {
test.foo = 0;
}
''');
await assertNoFix();
}

Future<void> test_write_propertyAccess_propertyName() async {
await resolveTestCode('''
void f(C c) {
(c).test = 0;
}
class C {}
''');
await assertNoFix();
}
}

0 comments on commit 28da71b

Please sign in to comment.