Skip to content

Commit 79181ab

Browse files
scheglovcommit-bot@chromium.org
authored andcommitted
Issue 46839. Stop using UNCHECKED_USE_OF_NULLABLE_VALUE.
Bug: #46839 Change-Id: Ia6a71438c265e54e83b148689e68e1e409d34cee Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/209500 Reviewed-by: Samuel Rawlins <[email protected]> Reviewed-by: Brian Wilkerson <[email protected]> Commit-Queue: Konstantin Shcheglov <[email protected]>
1 parent 3a2e4d9 commit 79181ab

8 files changed

+42
-33
lines changed

pkg/analyzer/lib/src/dart/resolver/for_resolver.dart

+4-3
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,10 @@ class ForResolver {
114114
iterable.accept(_resolver);
115115
iterable = forEachParts.iterable;
116116

117-
_resolver.nullableDereferenceVerifier.expression(iterable,
118-
errorCode:
119-
CompileTimeErrorCode.UNCHECKED_USE_OF_NULLABLE_VALUE_AS_ITERATOR);
117+
_resolver.nullableDereferenceVerifier.expression(
118+
CompileTimeErrorCode.UNCHECKED_USE_OF_NULLABLE_VALUE_AS_ITERATOR,
119+
iterable,
120+
);
120121

121122
loopVariable?.accept(_resolver);
122123
var elementType = _computeForEachElementType(iterable, isAsync);

pkg/analyzer/lib/src/dart/resolver/function_expression_invocation_resolver.dart

+5-3
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class FunctionExpressionInvocationResolver {
2424

2525
FunctionExpressionInvocationResolver({
2626
required ResolverVisitor resolver,
27-
}) : _resolver = resolver,
27+
}) : _resolver = resolver,
2828
_typePropertyResolver = resolver.typePropertyResolver,
2929
_inferenceHelper = resolver.inferenceHelper;
3030

@@ -60,8 +60,10 @@ class FunctionExpressionInvocationResolver {
6060
return;
6161
}
6262

63-
_nullableDereferenceVerifier.expression(function,
64-
errorCode: CompileTimeErrorCode.UNCHECKED_INVOCATION_OF_NULLABLE_VALUE);
63+
_nullableDereferenceVerifier.expression(
64+
CompileTimeErrorCode.UNCHECKED_INVOCATION_OF_NULLABLE_VALUE,
65+
function,
66+
);
6567

6668
if (receiverType is FunctionType) {
6769
_resolve(node, receiverType, whyNotPromotedList);

pkg/analyzer/lib/src/dart/resolver/method_invocation_resolver.dart

+5-3
Original file line numberDiff line numberDiff line change
@@ -495,9 +495,11 @@ class MethodInvocationResolver {
495495
);
496496
} else {
497497
_setDynamicResolution(node, whyNotPromotedList: whyNotPromotedList);
498-
_resolver.nullableDereferenceVerifier.report(methodName, receiverType,
499-
errorCode: CompileTimeErrorCode
500-
.UNCHECKED_METHOD_INVOCATION_OF_NULLABLE_VALUE);
498+
_resolver.nullableDereferenceVerifier.report(
499+
CompileTimeErrorCode.UNCHECKED_METHOD_INVOCATION_OF_NULLABLE_VALUE,
500+
methodName,
501+
receiverType,
502+
);
501503
}
502504
return;
503505
}

pkg/analyzer/lib/src/dart/resolver/type_property_resolver.dart

+2-2
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,8 @@ class TypePropertyResolver {
143143
}
144144
}
145145
_resolver.nullableDereferenceVerifier.report(
146-
propertyErrorEntity, receiverType,
147-
errorCode: errorCode, arguments: [name], messages: messages);
146+
errorCode, propertyErrorEntity, receiverType,
147+
arguments: [name], messages: messages);
148148
_reportedGetterError = true;
149149
_reportedSetterError = true;
150150

pkg/analyzer/lib/src/dart/resolver/yield_statement_resolver.dart

+4-3
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,10 @@ class YieldStatementResolver {
126126
node.expression.accept(_resolver);
127127

128128
if (node.star != null) {
129-
_resolver.nullableDereferenceVerifier.expression(node.expression,
130-
errorCode: CompileTimeErrorCode
131-
.UNCHECKED_USE_OF_NULLABLE_VALUE_IN_YIELD_EACH);
129+
_resolver.nullableDereferenceVerifier.expression(
130+
CompileTimeErrorCode.UNCHECKED_USE_OF_NULLABLE_VALUE_IN_YIELD_EACH,
131+
node.expression,
132+
);
132133
}
133134

134135
bodyContext.addYield(node);

pkg/analyzer/lib/src/error/bool_expression_verifier.dart

+5-4
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class BoolExpressionVerifier {
2525
required ResolverVisitor resolver,
2626
required ErrorReporter errorReporter,
2727
required NullableDereferenceVerifier nullableDereferenceVerifier,
28-
}) : _resolver = resolver,
28+
}) : _resolver = resolver,
2929
_errorReporter = errorReporter,
3030
_nullableDereferenceVerifier = nullableDereferenceVerifier,
3131
_boolType = resolver.typeSystem.typeProvider.boolType;
@@ -53,9 +53,10 @@ class BoolExpressionVerifier {
5353
if (!_checkForUseOfVoidResult(expression) &&
5454
!_resolver.typeSystem.isAssignableTo(type, _boolType)) {
5555
if (type.isDartCoreBool) {
56-
_nullableDereferenceVerifier.report(expression, type,
57-
errorCode: CompileTimeErrorCode
58-
.UNCHECKED_USE_OF_NULLABLE_VALUE_AS_CONDITION,
56+
_nullableDereferenceVerifier.report(
57+
CompileTimeErrorCode.UNCHECKED_USE_OF_NULLABLE_VALUE_AS_CONDITION,
58+
expression,
59+
type,
5960
messages: _resolver.computeWhyNotPromotedMessages(
6061
expression, whyNotPromoted?.call()));
6162
} else {

pkg/analyzer/lib/src/error/nullable_dereference_verifier.dart

+13-12
Original file line numberDiff line numberDiff line change
@@ -27,28 +27,26 @@ class NullableDereferenceVerifier {
2727
required TypeSystemImpl typeSystem,
2828
required ErrorReporter errorReporter,
2929
required ResolverVisitor resolver,
30-
}) : _typeSystem = typeSystem,
30+
}) : _typeSystem = typeSystem,
3131
_errorReporter = errorReporter,
3232
_resolver = resolver;
3333

34-
bool expression(Expression expression,
35-
{DartType? type, ErrorCode? errorCode}) {
34+
bool expression(ErrorCode errorCode, Expression expression,
35+
{DartType? type}) {
3636
if (!_typeSystem.isNonNullableByDefault) {
3737
return false;
3838
}
3939

4040
type ??= expression.typeOrThrow;
41-
return _check(expression, type, errorCode: errorCode);
41+
return _check(errorCode, expression, type);
4242
}
4343

44-
void report(SyntacticEntity errorEntity, DartType receiverType,
45-
{ErrorCode? errorCode,
46-
List<String> arguments = const <String>[],
44+
void report(
45+
ErrorCode errorCode, SyntacticEntity errorEntity, DartType receiverType,
46+
{List<String> arguments = const <String>[],
4747
List<DiagnosticMessage>? messages}) {
4848
if (receiverType == _typeSystem.typeProvider.nullType) {
4949
errorCode = CompileTimeErrorCode.INVALID_USE_OF_NULL_VALUE;
50-
} else {
51-
errorCode ??= CompileTimeErrorCode.UNCHECKED_USE_OF_NULLABLE_VALUE;
5250
}
5351
if (errorEntity is AstNode) {
5452
_errorReporter.reportErrorForNode(
@@ -67,8 +65,11 @@ class NullableDereferenceVerifier {
6765
/// receiver is the implicit `this`, the name of the invocation.
6866
///
6967
/// Returns whether [receiverType] was reported.
70-
bool _check(AstNode errorNode, DartType receiverType,
71-
{ErrorCode? errorCode}) {
68+
bool _check(
69+
ErrorCode errorCode,
70+
AstNode errorNode,
71+
DartType receiverType,
72+
) {
7273
if (identical(receiverType, DynamicTypeImpl.instance) ||
7374
!_typeSystem.isPotentiallyNullable(receiverType)) {
7475
return false;
@@ -79,7 +80,7 @@ class NullableDereferenceVerifier {
7980
messages = _resolver.computeWhyNotPromotedMessages(
8081
errorNode, _resolver.flowAnalysis?.flow?.whyNotPromoted(errorNode)());
8182
}
82-
report(errorNode, receiverType, errorCode: errorCode, messages: messages);
83+
report(errorCode, errorNode, receiverType, messages: messages);
8384
return true;
8485
}
8586
}

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

+4-3
Original file line numberDiff line numberDiff line change
@@ -1896,9 +1896,10 @@ class ResolverVisitor extends ScopedVisitor with ErrorDetectionHelpers {
18961896
super.visitSpreadElement(node);
18971897

18981898
if (!node.isNullAware) {
1899-
nullableDereferenceVerifier.expression(node.expression,
1900-
errorCode:
1901-
CompileTimeErrorCode.UNCHECKED_USE_OF_NULLABLE_VALUE_IN_SPREAD);
1899+
nullableDereferenceVerifier.expression(
1900+
CompileTimeErrorCode.UNCHECKED_USE_OF_NULLABLE_VALUE_IN_SPREAD,
1901+
node.expression,
1902+
);
19021903
}
19031904
}
19041905

0 commit comments

Comments
 (0)