This repository was archived by the owner on Nov 20, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +34
-0
lines changed Expand file tree Collapse file tree 2 files changed +34
-0
lines changed Original file line number Diff line number Diff line change @@ -129,6 +129,27 @@ DartType? getExpectedType(PostfixExpression node) {
129
129
parent = parent.parent;
130
130
}
131
131
if (parent is ArgumentList && realNode is Expression ) {
132
+ var grandParent = parent.parent;
133
+ if (grandParent is InstanceCreationExpression ) {
134
+ var constructor = grandParent.constructorName.staticElement;
135
+ if (constructor != null ) {
136
+ if (constructor.returnType.isDartAsyncFuture &&
137
+ constructor.name == 'value' ) {
138
+ return null ;
139
+ }
140
+ }
141
+ } else if (grandParent is MethodInvocation ) {
142
+ var targetType = grandParent.realTarget? .staticType;
143
+ if (targetType is InterfaceType ) {
144
+ var targetClass = targetType.element;
145
+
146
+ if (targetClass.library.isDartAsync &&
147
+ targetClass.name == 'Completer' &&
148
+ grandParent.methodName.name == 'complete' ) {
149
+ return null ;
150
+ }
151
+ }
152
+ }
132
153
return realNode.staticParameterElement? .type;
133
154
}
134
155
return null ;
Original file line number Diff line number Diff line change @@ -17,6 +17,19 @@ class UnnecessaryNullChecksTest extends LintRuleTest {
17
17
@override
18
18
String get lintRule => 'unnecessary_null_checks' ;
19
19
20
+ test_completerComplete () async {
21
+ await assertNoDiagnostics (r'''
22
+ import 'dart:async';
23
+ void f(int? i) => Completer<int>().complete(i!);
24
+ ''' );
25
+ }
26
+
27
+ test_futureValue () async {
28
+ await assertNoDiagnostics (r'''
29
+ void f(int? i) => Future<int>.value(i!);
30
+ ''' );
31
+ }
32
+
20
33
test_undefinedFunction () async {
21
34
await assertDiagnostics (r'''
22
35
f6(int? p) {
You can’t perform that action at this time.
0 commit comments