Skip to content

Commit 9de49b5

Browse files
bwilkersoncommit-bot@chromium.org
authored andcommitted
Fix an NPE in invalid-null-aware-operator-after-short-circuit
Change-Id: I91ebe5b4c511d74be566ce1f01ae0dba07313057 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/154720 Reviewed-by: Konstantin Shcheglov <[email protected]> Commit-Queue: Brian Wilkerson <[email protected]>
1 parent 2e05e6c commit 9de49b5

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

pkg/analyzer/lib/src/generated/error_verifier.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4225,7 +4225,7 @@ class ErrorVerifier extends RecursiveAstVisitor<void> {
42254225
}
42264226
} else if (target is MethodInvocation) {
42274227
var operator = target.operator;
4228-
var type = operator.type;
4228+
var type = operator?.type;
42294229
if (type == TokenType.QUESTION_PERIOD) {
42304230
var realTarget = target.realTarget;
42314231
if (_isExpressionWithType(realTarget)) {

pkg/analyzer/test/src/diagnostics/invalid_null_aware_operator_test.dart

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,22 @@ void f(String? s) {
5050
]);
5151
}
5252

53+
Future<void> test_methodInvocation_noTarget() async {
54+
await assertErrorsInCode('''
55+
class C {
56+
C? m1() => this;
57+
C m2() => this;
58+
void m3() {
59+
m1()?.m2()?.m2();
60+
}
61+
}
62+
''', [
63+
error(StaticWarningCode.INVALID_NULL_AWARE_OPERATOR_AFTER_SHORT_CIRCUIT,
64+
75, 2,
65+
contextMessages: [message('/test/lib/test.dart', 69, 2)]),
66+
]);
67+
}
68+
5369
Future<void> test_methodInvocation_previousTarget() async {
5470
await assertErrorsInCode('''
5571
void f(String? s) {

0 commit comments

Comments
 (0)