@@ -42,7 +42,6 @@ class VoidChecks extends LintRule implements NodeLintRule {
42
42
void registerNodeProcessors (
43
43
NodeLintRegistry registry, LinterContext context) {
44
44
final visitor = _Visitor (this , context);
45
- registry.addCompilationUnit (this , visitor);
46
45
registry.addMethodInvocation (this , visitor);
47
46
registry.addInstanceCreationExpression (this , visitor);
48
47
registry.addAssignmentExpression (this , visitor);
@@ -56,34 +55,38 @@ class _Visitor extends SimpleAstVisitor<void> {
56
55
final LinterContext context;
57
56
final TypeSystem typeSystem;
58
57
59
- InterfaceType _futureDynamicType;
60
-
61
58
_Visitor (this .rule, this .context) : typeSystem = context.typeSystem;
62
59
63
60
bool isTypeAcceptableWhenExpectingVoid (DartType type) {
64
61
if (type.isVoid) return true ;
65
62
if (type.isDartCoreNull) return true ;
66
63
if (type.isDartAsyncFuture &&
67
64
type is InterfaceType &&
68
- (type.typeArguments.first.isVoid ||
69
- type.typeArguments.first.isDartCoreNull)) {
65
+ isTypeAcceptableWhenExpectingVoid (type.typeArguments.first)) {
70
66
return true ;
71
67
}
72
68
return false ;
73
69
}
74
70
71
+ bool isTypeAcceptableWhenExpectingFutureOrVoid (DartType type) {
72
+ if (type.isDynamic) return true ;
73
+ if (isTypeAcceptableWhenExpectingVoid (type)) return true ;
74
+ if (type.isDartAsyncFutureOr &&
75
+ type is InterfaceType &&
76
+ isTypeAcceptableWhenExpectingFutureOrVoid (type.typeArguments.first)) {
77
+ return true ;
78
+ }
79
+
80
+ return false ;
81
+ }
82
+
75
83
@override
76
84
void visitAssignmentExpression (AssignmentExpression node) {
77
85
final type = node.writeType;
78
86
_check (type, node.rightHandSide? .staticType, node,
79
87
checkedNode: node.rightHandSide);
80
88
}
81
89
82
- @override
83
- void visitCompilationUnit (CompilationUnit node) {
84
- _futureDynamicType = context.typeProvider.futureDynamicType;
85
- }
86
-
87
90
@override
88
91
void visitInstanceCreationExpression (InstanceCreationExpression node) {
89
92
final args = node.argumentList.arguments;
@@ -131,11 +134,12 @@ class _Visitor extends SimpleAstVisitor<void> {
131
134
checkedNode ?? = node;
132
135
if (expectedType == null || type == null ) {
133
136
return ;
134
- } else if (expectedType.isVoid &&
135
- ! isTypeAcceptableWhenExpectingVoid (type) ||
136
- expectedType.isDartAsyncFutureOr &&
137
- (expectedType as InterfaceType ).typeArguments.first.isVoid &&
138
- ! typeSystem.isAssignableTo (type, _futureDynamicType)) {
137
+ }
138
+ if (expectedType.isVoid && ! isTypeAcceptableWhenExpectingVoid (type)) {
139
+ rule.reportLint (node);
140
+ } else if (expectedType.isDartAsyncFutureOr &&
141
+ (expectedType as InterfaceType ).typeArguments.first.isVoid &&
142
+ ! isTypeAcceptableWhenExpectingFutureOrVoid (type)) {
139
143
rule.reportLint (node);
140
144
} else if (checkedNode is FunctionExpression &&
141
145
checkedNode.body is ! ExpressionFunctionBody &&
0 commit comments