Skip to content

Commit

Permalink
[DAS] Fixes ambiguous extension access fix for method
Browse files Browse the repository at this point in the history
[email protected]

Fixes #59543

Change-Id: I84c73c6315c401bc5f8d925f190d395354329102
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/396741
Reviewed-by: Samuel Rawlins <[email protected]>
Reviewed-by: Phil Quitslund <[email protected]>
Commit-Queue: Phil Quitslund <[email protected]>
Auto-Submit: Felipe Morschel <[email protected]>
  • Loading branch information
FMorschel authored and Commit Queue committed Nov 21, 2024
1 parent b9e7cb6 commit b02a116
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,14 @@ class AddExtensionOverride extends MultiCorrectionProducer {
var node = this.node;
if (node is! SimpleIdentifier) return const [];
var parent = node.parent;
if (parent is! PropertyAccess) return const [];
var target = parent.target;
Expression? target;
if (parent is MethodInvocation) {
target = parent.target;
} else if (parent is PropertyAccess) {
target = parent.target;
} else {
return const [];
}
if (target == null) return const [];
var dartFixContext = context.dartFixContext;
if (dartFixContext == null) return const [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,39 @@ class AddExtensionOverrideTest extends FixProcessorTest {
@override
FixKind get kind => DartFixKind.ADD_EXTENSION_OVERRIDE;

Future<void> test_method() async {
await resolveTestCode('''
extension E on int {
void foo() {}
}
extension E2 on int {
void foo() {}
}
f() {
0.foo();
}
''');
await assertHasFix('''
extension E on int {
void foo() {}
}
extension E2 on int {
void foo() {}
}
f() {
E(0).foo();
}
''', matchFixMessage: "Add an extension override for 'E'");

await assertHasFixesWithoutApplying(
expectedNumberOfFixesForKind: 2,
matchFixMessages: [
"Add an extension override for 'E'",
"Add an extension override for 'E2'",
],
);
}

Future<void> test_no_name() async {
await resolveTestCode('''
extension E on int {
Expand Down

0 comments on commit b02a116

Please sign in to comment.