Skip to content

Commit 2e6dd67

Browse files
DanTupcommit-bot@chromium.org
authored andcommitted
Prevent NPE when trying to compute AddDiagnosticPropertyReference assist inside a mixin
Bug: dart-lang/sdk#42749 Change-Id: I2772f0c0f4f21409730713c1ed8a871725080a2f Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/154883 Reviewed-by: Brian Wilkerson <[email protected]> Commit-Queue: Danny Tuppeny <[email protected]>
1 parent ad3be0a commit 2e6dd67

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,9 @@ class AddDiagnosticPropertyReference extends CorrectionProducer {
9999
}
100100

101101
final classDeclaration = parent.thisOrAncestorOfType<ClassDeclaration>();
102+
if (classDeclaration == null) {
103+
return;
104+
}
102105
final debugFillProperties =
103106
classDeclaration.getMethod('debugFillProperties');
104107
if (debugFillProperties == null) {

pkg/analysis_server/test/src/services/correction/assist/add_diagnostic_property_reference_test.dart

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,14 @@ class W extends Widget {
4242
}
4343
''');
4444
}
45+
46+
Future<void> test_notAvailable_mixin() async {
47+
verifyNoTestUnitErrors = false;
48+
await resolveTestUnit('''
49+
mixin MyMixin {
50+
String get foo/*caret*/() {}
51+
}
52+
''');
53+
await assertNoAssist();
54+
}
4555
}

0 commit comments

Comments
 (0)