Skip to content

Commit b02a116

Browse files
FMorschelCommit Queue
authored andcommitted
[DAS] Fixes ambiguous extension access fix for method
[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]>
1 parent b9e7cb6 commit b02a116

File tree

2 files changed

+41
-2
lines changed

2 files changed

+41
-2
lines changed

pkg/analysis_server/lib/src/services/correction/dart/add_extension_override.dart

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,14 @@ class AddExtensionOverride extends MultiCorrectionProducer {
1818
var node = this.node;
1919
if (node is! SimpleIdentifier) return const [];
2020
var parent = node.parent;
21-
if (parent is! PropertyAccess) return const [];
22-
var target = parent.target;
21+
Expression? target;
22+
if (parent is MethodInvocation) {
23+
target = parent.target;
24+
} else if (parent is PropertyAccess) {
25+
target = parent.target;
26+
} else {
27+
return const [];
28+
}
2329
if (target == null) return const [];
2430
var dartFixContext = context.dartFixContext;
2531
if (dartFixContext == null) return const [];

pkg/analysis_server/test/src/services/correction/fix/add_extension_override_test.dart

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,39 @@ class AddExtensionOverrideTest extends FixProcessorTest {
2020
@override
2121
FixKind get kind => DartFixKind.ADD_EXTENSION_OVERRIDE;
2222

23+
Future<void> test_method() async {
24+
await resolveTestCode('''
25+
extension E on int {
26+
void foo() {}
27+
}
28+
extension E2 on int {
29+
void foo() {}
30+
}
31+
f() {
32+
0.foo();
33+
}
34+
''');
35+
await assertHasFix('''
36+
extension E on int {
37+
void foo() {}
38+
}
39+
extension E2 on int {
40+
void foo() {}
41+
}
42+
f() {
43+
E(0).foo();
44+
}
45+
''', matchFixMessage: "Add an extension override for 'E'");
46+
47+
await assertHasFixesWithoutApplying(
48+
expectedNumberOfFixesForKind: 2,
49+
matchFixMessages: [
50+
"Add an extension override for 'E'",
51+
"Add an extension override for 'E2'",
52+
],
53+
);
54+
}
55+
2356
Future<void> test_no_name() async {
2457
await resolveTestCode('''
2558
extension E on int {

0 commit comments

Comments
 (0)