analyzer: Improve span of use_of_nullable_value errors

This changes the span reported from the _receiver_ to
the _use_ (method name, property name, operator token).

I think this change is overall an improvement.
Specifically, its a great improvement for cmdline
output, where the receiver and the "use" are on
different lines.

One possibly weird change is that if the operator is `[]`,
then I only highlight the `[` character. I don't know if
there is a better place, and I think this is fine.

Fixes https://github.com/dart-lang/sdk/issues/43708

Change-Id: Ie66ddf04b4904a367575193106385dd63ee39985
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/188680
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
This commit is contained in:
Sam Rawlins 2021-04-02 02:43:48 +00:00 committed by commit-bot@chromium.org
parent fdba4e3a65
commit 5e040a20f8
37 changed files with 190 additions and 151 deletions

View file

@ -24,8 +24,31 @@ class AddNullCheck extends CorrectionProducer {
return;
}
Expression target;
if (coveredNode is Expression) {
var coveredNodeParent = coveredNode.parent;
if (coveredNode is SimpleIdentifier) {
if (coveredNodeParent is MethodInvocation) {
target = coveredNodeParent.realTarget;
} else if (coveredNodeParent is PrefixedIdentifier) {
target = coveredNodeParent.prefix;
} else if (coveredNodeParent is PropertyAccess) {
target = coveredNodeParent.realTarget;
} else if (coveredNodeParent is BinaryExpression) {
target = coveredNodeParent.rightOperand;
} else {
target = coveredNode;
}
} else if (coveredNode is IndexExpression) {
target = (coveredNode as IndexExpression).realTarget;
} else if (coveredNodeParent is FunctionExpressionInvocation) {
target = coveredNode;
} else if (coveredNodeParent is AssignmentExpression) {
target = coveredNodeParent.rightHandSide;
} else if (coveredNode is PostfixExpression) {
target = (coveredNode as PostfixExpression).operand;
} else if (coveredNode is PrefixExpression) {
target = (coveredNode as PrefixExpression).operand;
} else if (coveredNode is BinaryExpression) {
target = (coveredNode as BinaryExpression).leftOperand;
} else {
return;
}

View file

@ -120,8 +120,9 @@ class ErrorReporter {
/// Report an error with the given [errorCode] and [arguments]. The [token] is
/// used to compute the location of the error.
void reportErrorForToken(ErrorCode errorCode, Token token,
[List<Object?>? arguments]) {
reportErrorForOffset(errorCode, token.offset, token.length, arguments);
[List<Object?>? arguments, List<DiagnosticMessage>? messages]) {
reportErrorForOffset(
errorCode, token.offset, token.length, arguments, messages);
}
/// Report an error with the given [errorCode] and [message]. The location of

View file

@ -185,7 +185,7 @@ class AssignmentExpressionResolver {
receiver: left,
receiverType: leftType,
name: methodName,
receiverErrorNode: left,
propertyErrorEntity: operator,
nameErrorEntity: operator,
);
node.staticElement = result.getter as MethodElement?;

View file

@ -322,7 +322,7 @@ class BinaryExpressionResolver {
receiver: leftOperand,
receiverType: leftType,
name: methodName,
receiverErrorNode: leftOperand,
propertyErrorEntity: node.operator,
nameErrorEntity: node,
);

View file

@ -165,7 +165,7 @@ class FunctionExpressionInvocationResolver {
receiver: function,
receiverType: receiverType,
name: FunctionElement.CALL_METHOD_NAME,
receiverErrorNode: function,
propertyErrorEntity: function,
nameErrorEntity: function,
);
var callElement = result.getter;

View file

@ -56,7 +56,7 @@ class LexicalLookup {
receiver: null,
receiverType: thisType,
name: id,
receiverErrorNode: node,
propertyErrorEntity: node,
nameErrorEntity: node,
);

View file

@ -492,7 +492,7 @@ class MethodInvocationResolver {
);
} else {
_setDynamicResolution(node, whyNotPromotedList: whyNotPromotedList);
_resolver.nullableDereferenceVerifier.report(receiver, receiverType,
_resolver.nullableDereferenceVerifier.report(methodName, receiverType,
errorCode: CompileTimeErrorCode
.UNCHECKED_METHOD_INVOCATION_OF_NULLABLE_VALUE);
}
@ -693,7 +693,7 @@ class MethodInvocationResolver {
receiver: receiver,
receiverType: receiverType,
name: name,
receiverErrorNode: receiverErrorNode,
propertyErrorEntity: nameNode,
nameErrorEntity: nameNode,
);

View file

@ -134,7 +134,7 @@ class PostfixExpressionResolver {
receiver: operand,
receiverType: receiverType,
name: methodName,
receiverErrorNode: operand,
propertyErrorEntity: node.operator,
nameErrorEntity: operand,
);
node.staticElement = result.getter as MethodElement?;

View file

@ -168,7 +168,7 @@ class PrefixExpressionResolver {
receiver: operand,
receiverType: readType,
name: methodName,
receiverErrorNode: operand,
propertyErrorEntity: node.operator,
nameErrorEntity: operand,
);
node.staticElement = result.getter as MethodElement?;

View file

@ -95,7 +95,7 @@ class PropertyElementResolver {
receiver: target,
receiverType: targetType,
name: '[]',
receiverErrorNode: target,
propertyErrorEntity: node.leftBracket,
nameErrorEntity: target,
);
@ -369,7 +369,7 @@ class PropertyElementResolver {
receiver: target,
receiverType: targetType,
name: propertyName.name,
receiverErrorNode: target,
propertyErrorEntity: propertyName,
nameErrorEntity: propertyName,
);

View file

@ -54,15 +54,15 @@ class TypePropertyResolver {
///
/// The [receiver] might be `null`, used to identify `super`.
///
/// The [receiverErrorNode] is the node to report nullable dereference,
/// The [propertyErrorNode] is the node to report nullable dereference,
/// if the [receiverType] is potentially nullable.
///
/// The [nameErrorEntity] is used to report the ambiguous extension issue.
/// The [nameErrorEntity] is used to report an ambiguous extension issue.
ResolutionResult resolve({
required Expression? receiver,
required DartType receiverType,
required String name,
required AstNode receiverErrorNode,
required SyntacticEntity propertyErrorEntity,
required SyntacticEntity nameErrorEntity,
}) {
_receiver = receiver;
@ -91,7 +91,17 @@ class TypePropertyResolver {
return _toResult();
}
var parentExpression = (receiver ?? receiverErrorNode).parent;
AstNode? parentExpression;
if (receiver != null) {
parentExpression = receiver.parent;
} else if (propertyErrorEntity is AstNode) {
parentExpression = propertyErrorEntity.parent;
} else {
throw StateError('Either `receiver` must be non-null or'
'`propertyErrorEntity` must be an AstNode to report an unchecked '
'invocation of a nullable value.');
}
CompileTimeErrorCode errorCode;
if (parentExpression == null) {
errorCode = CompileTimeErrorCode.UNCHECKED_INVOCATION_OF_NULLABLE_VALUE;
@ -130,7 +140,7 @@ class TypePropertyResolver {
}
}
_resolver.nullableDereferenceVerifier.report(
receiverErrorNode, receiverType,
propertyErrorEntity, receiverType,
errorCode: errorCode, arguments: [name], messages: messages);
_reportedGetterError = true;
_reportedSetterError = true;

View file

@ -6854,7 +6854,7 @@ class CompileTimeErrorCode extends AnalyzerErrorCode {
// #### Description
//
// The analyzer produces this diagnostic when an expression whose value will
// always be `null` is dererenced.
// always be `null` is dereferenced.
//
// #### Example
//
@ -11897,7 +11897,7 @@ class CompileTimeErrorCode extends AnalyzerErrorCode {
//
// ```dart
// void f(String? s) {
// if ([!s!].length > 3) {
// if (s.[!length!] > 3) {
// // ...
// }
// }

View file

@ -3,6 +3,8 @@
// BSD-style license that can be found in the LICENSE file.
import 'package:analyzer/dart/ast/ast.dart';
import 'package:analyzer/dart/ast/syntactic_entity.dart';
import 'package:analyzer/dart/ast/token.dart';
import 'package:analyzer/dart/element/type.dart';
import 'package:analyzer/diagnostic/diagnostic.dart';
import 'package:analyzer/error/error.dart';
@ -39,7 +41,7 @@ class NullableDereferenceVerifier {
return _check(expression, type, errorCode: errorCode);
}
void report(AstNode errorNode, DartType receiverType,
void report(SyntacticEntity errorEntity, DartType receiverType,
{ErrorCode? errorCode,
List<String> arguments = const <String>[],
List<DiagnosticMessage>? messages}) {
@ -48,8 +50,15 @@ class NullableDereferenceVerifier {
} else {
errorCode ??= CompileTimeErrorCode.UNCHECKED_USE_OF_NULLABLE_VALUE;
}
_errorReporter.reportErrorForNode(
errorCode, errorNode, arguments, messages);
if (errorEntity is AstNode) {
_errorReporter.reportErrorForNode(
errorCode, errorEntity, arguments, messages);
} else if (errorEntity is Token) {
_errorReporter.reportErrorForToken(
errorCode, errorEntity, arguments, messages);
} else {
throw StateError('Syntactic entity must be AstNode or Token to report.');
}
}
/// If the [receiverType] is potentially nullable, report it.

View file

@ -665,7 +665,7 @@ class ElementResolver extends SimpleAstVisitor<void> {
receiver: null,
receiverType: enclosingClass.thisType,
name: identifier.name,
receiverErrorNode: identifier,
propertyErrorEntity: identifier,
nameErrorEntity: identifier,
);
setter = result.setter;
@ -706,7 +706,7 @@ class ElementResolver extends SimpleAstVisitor<void> {
receiver: null,
receiverType: enclosingType,
name: identifier.name,
receiverErrorNode: identifier,
propertyErrorEntity: identifier,
nameErrorEntity: identifier,
);
if (identifier.inSetterContext() ||

View file

@ -1000,7 +1000,7 @@ main() {
}
''', [
if (typeToStringWithNullability)
error(CompileTimeErrorCode.INVALID_USE_OF_NULL_VALUE, 11, 4)
error(CompileTimeErrorCode.INVALID_USE_OF_NULL_VALUE, 16, 3)
else
error(CompileTimeErrorCode.UNDEFINED_METHOD, 16, 3),
]);
@ -2486,7 +2486,7 @@ void f(Function? foo) {
}
''', [
error(CompileTimeErrorCode.UNCHECKED_METHOD_INVOCATION_OF_NULLABLE_VALUE,
26, 3),
30, 4),
]);
assertMethodInvocation2(
@ -2538,7 +2538,7 @@ void f(A? a) {
}
''', [
error(CompileTimeErrorCode.UNCHECKED_METHOD_INVOCATION_OF_NULLABLE_VALUE,
46, 1),
48, 3),
]);
assertMethodInvocation2(
@ -2565,7 +2565,7 @@ void f(A? a) {
}
''', [
error(CompileTimeErrorCode.UNCHECKED_METHOD_INVOCATION_OF_NULLABLE_VALUE,
84, 1),
86, 3),
]);
assertMethodInvocation2(
@ -2633,7 +2633,7 @@ void f(A? a) {
}
''', [
error(CompileTimeErrorCode.UNCHECKED_METHOD_INVOCATION_OF_NULLABLE_VALUE,
29, 1),
31, 3),
]);
assertMethodInvocation2(
@ -2658,7 +2658,7 @@ void f(A? a) {
}
''', [
error(CompileTimeErrorCode.UNCHECKED_METHOD_INVOCATION_OF_NULLABLE_VALUE,
67, 1),
69, 3),
]);
assertMethodInvocation2(

View file

@ -675,7 +675,7 @@ void f(A? a) {
}
''', [
error(CompileTimeErrorCode.UNCHECKED_METHOD_INVOCATION_OF_NULLABLE_VALUE,
51, 6),
50, 1),
]);
assertPrefixExpression(
@ -750,7 +750,7 @@ void f(A? a) {
}
''', [
error(CompileTimeErrorCode.UNCHECKED_METHOD_INVOCATION_OF_NULLABLE_VALUE,
51, 6),
50, 1),
]);
assertPrefixExpression(

View file

@ -522,7 +522,7 @@ class C<T> {
assertErrorsInResult(expectedErrorsByNullability(
nullable: [
error(CompileTimeErrorCode.UNCHECKED_PROPERTY_ACCESS_OF_NULLABLE_VALUE,
33, 3),
37, 3),
],
legacy: [
error(CompileTimeErrorCode.UNDEFINED_GETTER, 37, 3),

View file

@ -514,7 +514,7 @@ void f() {
error(CompileTimeErrorCode.DEFINITELY_UNASSIGNED_LATE_LOCAL_VARIABLE, 68,
1),
error(CompileTimeErrorCode.UNCHECKED_METHOD_INVOCATION_OF_NULLABLE_VALUE,
68, 1),
70, 2),
]);
_assertAssigned('x +=', assigned: false, unassigned: true);
}
@ -530,7 +530,7 @@ void f() {
error(CompileTimeErrorCode.DEFINITELY_UNASSIGNED_LATE_LOCAL_VARIABLE, 68,
1),
error(CompileTimeErrorCode.UNCHECKED_METHOD_INVOCATION_OF_NULLABLE_VALUE,
68, 1),
69, 2),
]);
_assertAssigned('x++', assigned: false, unassigned: true);
}
@ -546,7 +546,7 @@ void f() {
error(CompileTimeErrorCode.DEFINITELY_UNASSIGNED_LATE_LOCAL_VARIABLE, 70,
1),
error(CompileTimeErrorCode.UNCHECKED_METHOD_INVOCATION_OF_NULLABLE_VALUE,
70, 1),
68, 2),
]);
_assertAssigned('x; // 0', assigned: false, unassigned: true);
}
@ -583,7 +583,7 @@ void f(bool b) {
}
''', [
error(CompileTimeErrorCode.UNCHECKED_METHOD_INVOCATION_OF_NULLABLE_VALUE,
90, 1),
92, 2),
]);
_assertAssigned('x +=', assigned: false, unassigned: false);
}
@ -598,7 +598,7 @@ void f(bool b) {
}
''', [
error(CompileTimeErrorCode.UNCHECKED_METHOD_INVOCATION_OF_NULLABLE_VALUE,
90, 1),
91, 2),
]);
_assertAssigned('x++', assigned: false, unassigned: false);
}
@ -613,7 +613,7 @@ void f(bool b) {
}
''', [
error(CompileTimeErrorCode.UNCHECKED_METHOD_INVOCATION_OF_NULLABLE_VALUE,
92, 1),
90, 2),
]);
_assertAssigned('x; // 0', assigned: false, unassigned: false);
}

View file

@ -78,7 +78,7 @@ void f(Never? x) {
''', [
error(
CompileTimeErrorCode.UNCHECKED_OPERATOR_INVOCATION_OF_NULLABLE_VALUE,
21,
23,
1),
]);
@ -204,7 +204,7 @@ void f(Never? x) {
}
''', [
error(CompileTimeErrorCode.UNCHECKED_METHOD_INVOCATION_OF_NULLABLE_VALUE,
21, 1),
22, 1),
]);
assertIndexExpression(
@ -222,7 +222,7 @@ void f(Never? x) {
}
''', [
error(CompileTimeErrorCode.UNCHECKED_METHOD_INVOCATION_OF_NULLABLE_VALUE,
21, 1),
22, 1),
]);
assertAssignment(
@ -254,7 +254,7 @@ void f(Never? x) {
}
''', [
error(CompileTimeErrorCode.UNCHECKED_METHOD_INVOCATION_OF_NULLABLE_VALUE,
21, 1),
22, 1),
]);
assertIndexExpression(
@ -364,7 +364,7 @@ void f(Never? x) {
}
''', [
error(CompileTimeErrorCode.UNCHECKED_METHOD_INVOCATION_OF_NULLABLE_VALUE,
21, 1),
22, 2),
]);
assertPostfixExpression(
@ -406,7 +406,7 @@ void f(Never? x) {
}
''', [
error(CompileTimeErrorCode.UNCHECKED_METHOD_INVOCATION_OF_NULLABLE_VALUE,
23, 1),
21, 2),
]);
assertPrefixExpression(
@ -517,7 +517,7 @@ void f(Never? x) {
}
''', [
error(CompileTimeErrorCode.UNCHECKED_PROPERTY_ACCESS_OF_NULLABLE_VALUE,
21, 1),
23, 3),
]);
assertSimpleIdentifier(

View file

@ -247,7 +247,7 @@ m() {
}
''',
expectedErrorsByNullability(nullable: [
error(CompileTimeErrorCode.INVALID_USE_OF_NULL_VALUE, 22, 5),
error(CompileTimeErrorCode.INVALID_USE_OF_NULL_VALUE, 28, 3),
], legacy: [
error(CompileTimeErrorCode.UNDEFINED_GETTER, 28, 3),
]));

View file

@ -161,9 +161,9 @@ extension E on A? {
}
''', [
error(CompileTimeErrorCode.UNCHECKED_METHOD_INVOCATION_OF_NULLABLE_VALUE,
126, 4),
130, 1),
error(CompileTimeErrorCode.UNCHECKED_METHOD_INVOCATION_OF_NULLABLE_VALUE,
154, 4),
158, 1),
]);
}
@ -206,7 +206,7 @@ extension E on A? {
error(CompileTimeErrorCode.UNCHECKED_METHOD_INVOCATION_OF_NULLABLE_VALUE,
68, 3),
error(CompileTimeErrorCode.UNCHECKED_METHOD_INVOCATION_OF_NULLABLE_VALUE,
79, 4),
84, 3),
]);
}
@ -237,7 +237,7 @@ extension E on A? {
}
''', [
error(CompileTimeErrorCode.UNCHECKED_METHOD_INVOCATION_OF_NULLABLE_VALUE,
78, 4),
77, 1),
]);
}
@ -284,7 +284,7 @@ extension E on A? {
error(CompileTimeErrorCode.UNCHECKED_PROPERTY_ACCESS_OF_NULLABLE_VALUE,
93, 3),
error(CompileTimeErrorCode.UNCHECKED_PROPERTY_ACCESS_OF_NULLABLE_VALUE,
102, 4),
107, 3),
]);
}
@ -331,7 +331,7 @@ extension E on A? {
error(CompileTimeErrorCode.UNCHECKED_METHOD_INVOCATION_OF_NULLABLE_VALUE,
93, 3),
error(CompileTimeErrorCode.UNCHECKED_PROPERTY_ACCESS_OF_NULLABLE_VALUE,
106, 4),
111, 3),
]);
}
}
@ -407,7 +407,7 @@ m(B b) {
}
''', [
error(CompileTimeErrorCode.UNCHECKED_PROPERTY_ACCESS_OF_NULLABLE_VALUE,
100, 3,
104, 1,
contextMessages: [message('/home/test/lib/test.dart', 56, 1)]),
]);
@ -494,7 +494,7 @@ m(B b) {
}
''', [
error(CompileTimeErrorCode.UNCHECKED_METHOD_INVOCATION_OF_NULLABLE_VALUE,
109, 5),
115, 2),
]);
assertAssignment(
@ -549,7 +549,7 @@ m(B b) {
}
''', [
error(CompileTimeErrorCode.UNCHECKED_PROPERTY_ACCESS_OF_NULLABLE_VALUE,
101, 3,
105, 1,
contextMessages: [message('/home/test/lib/test.dart', 56, 1)]),
]);
@ -595,7 +595,7 @@ m(int x, int? y) {
}
''', [
error(CompileTimeErrorCode.UNCHECKED_METHOD_INVOCATION_OF_NULLABLE_VALUE,
31, 1),
33, 2),
]);
var assignment1 = findNode.assignment('x +=');
var assignment2 = findNode.assignment('y +=');
@ -667,7 +667,7 @@ m() {
}
''', [
error(CompileTimeErrorCode.UNCHECKED_METHOD_INVOCATION_OF_NULLABLE_VALUE,
24, 1),
27, 1),
]);
}
@ -688,7 +688,7 @@ m() {
}
''', [
error(CompileTimeErrorCode.UNCHECKED_METHOD_INVOCATION_OF_NULLABLE_VALUE,
18, 1),
21, 3),
]);
}
@ -709,7 +709,7 @@ m() {
}
''', [
error(CompileTimeErrorCode.UNCHECKED_PROPERTY_ACCESS_OF_NULLABLE_VALUE,
18, 1),
21, 6),
]);
}
@ -766,7 +766,7 @@ m(int? x) {
}
''', [
error(CompileTimeErrorCode.UNCHECKED_PROPERTY_ACCESS_OF_NULLABLE_VALUE,
58, 1),
60, 3),
]);
}
@ -808,7 +808,7 @@ m() {
}
''', [
error(CompileTimeErrorCode.UNCHECKED_METHOD_INVOCATION_OF_NULLABLE_VALUE,
19, 1),
20, 1),
]);
}
@ -916,7 +916,7 @@ m() {
}
''', [
error(CompileTimeErrorCode.UNCHECKED_PROPERTY_ACCESS_OF_NULLABLE_VALUE,
18, 1),
20, 6),
]);
assertSimpleIdentifier(
findNode.simple('isEven'),
@ -942,7 +942,7 @@ m() {
}
''', [
error(CompileTimeErrorCode.UNCHECKED_PROPERTY_ACCESS_OF_NULLABLE_VALUE,
18, 3),
22, 6),
]);
}
@ -962,7 +962,7 @@ m<T extends int?>(T x) {
}
''', [
error(CompileTimeErrorCode.UNCHECKED_PROPERTY_ACCESS_OF_NULLABLE_VALUE,
27, 1),
29, 6),
]);
}
@ -1019,7 +1019,7 @@ m() {
}
''', [
error(CompileTimeErrorCode.UNCHECKED_METHOD_INVOCATION_OF_NULLABLE_VALUE,
18, 1),
20, 5),
]);
}
@ -1034,7 +1034,7 @@ m(int? x) {
}
''', [
error(CompileTimeErrorCode.UNCHECKED_METHOD_INVOCATION_OF_NULLABLE_VALUE,
54, 1),
56, 3),
]);
}
@ -1070,7 +1070,7 @@ m(Function? x) {
}
''', [
error(CompileTimeErrorCode.UNCHECKED_METHOD_INVOCATION_OF_NULLABLE_VALUE,
19, 1),
21, 4),
]);
}
@ -1094,7 +1094,7 @@ m() {
''', [
error(HintCode.UNUSED_LOCAL_VARIABLE, 13, 1),
error(CompileTimeErrorCode.UNCHECKED_METHOD_INVOCATION_OF_NULLABLE_VALUE,
18, 1),
20, 2),
]);
}
@ -1176,7 +1176,7 @@ m() {
''', [
error(
CompileTimeErrorCode.UNCHECKED_OPERATOR_INVOCATION_OF_NULLABLE_VALUE,
18,
20,
1),
]);
}
@ -1199,7 +1199,7 @@ m() {
''', [
error(
CompileTimeErrorCode.UNCHECKED_OPERATOR_INVOCATION_OF_NULLABLE_VALUE,
18,
20,
1),
]);
}
@ -1224,7 +1224,7 @@ m() {
''', [
error(HintCode.UNUSED_LOCAL_VARIABLE, 13, 1),
error(CompileTimeErrorCode.UNCHECKED_METHOD_INVOCATION_OF_NULLABLE_VALUE,
18, 1),
19, 2),
]);
}
@ -1243,7 +1243,7 @@ m(int? x) {
}
''', [
error(CompileTimeErrorCode.UNCHECKED_METHOD_INVOCATION_OF_NULLABLE_VALUE,
14, 1),
15, 2),
]);
}
@ -1260,7 +1260,7 @@ m(A? x) {
}
''', [
error(CompileTimeErrorCode.UNCHECKED_METHOD_INVOCATION_OF_NULLABLE_VALUE,
77, 1),
78, 2),
]);
}
@ -1284,7 +1284,7 @@ m() {
''', [
error(HintCode.UNUSED_LOCAL_VARIABLE, 13, 1),
error(CompileTimeErrorCode.UNCHECKED_METHOD_INVOCATION_OF_NULLABLE_VALUE,
20, 1),
18, 2),
]);
}
@ -1303,7 +1303,7 @@ m(int? x) {
}
''', [
error(CompileTimeErrorCode.UNCHECKED_METHOD_INVOCATION_OF_NULLABLE_VALUE,
16, 1),
14, 2),
]);
}
@ -1327,7 +1327,7 @@ m() {
''', [
error(HintCode.UNUSED_LOCAL_VARIABLE, 13, 1),
error(CompileTimeErrorCode.UNCHECKED_METHOD_INVOCATION_OF_NULLABLE_VALUE,
19, 1),
18, 1),
]);
}
@ -1344,7 +1344,7 @@ m(A? x) {
}
''', [
error(CompileTimeErrorCode.UNCHECKED_METHOD_INVOCATION_OF_NULLABLE_VALUE,
73, 1),
72, 1),
]);
}
@ -1386,7 +1386,7 @@ m(int? x) {
}
''', [
error(CompileTimeErrorCode.UNCHECKED_METHOD_INVOCATION_OF_NULLABLE_VALUE,
14, 1),
16, 2),
]);
}
@ -1403,7 +1403,7 @@ m(A? a) {
}
''', [
error(CompileTimeErrorCode.UNCHECKED_PROPERTY_ACCESS_OF_NULLABLE_VALUE,
66, 1),
68, 1),
]);
var propertyAccess1 = findNode.propertyAccess('a?.x; // 1');
var propertyAccess2 = findNode.prefixed('a.x; // 2');
@ -1435,7 +1435,7 @@ m(B b) {
}
''', [
error(CompileTimeErrorCode.UNCHECKED_PROPERTY_ACCESS_OF_NULLABLE_VALUE,
101, 3,
105, 1,
contextMessages: [message('/home/test/lib/test.dart', 56, 1)]),
]);
var propertyAccess1 = findNode.propertyAccess('b.a?.x; // 1');
@ -1468,7 +1468,7 @@ m(B? b) {
}
''', [
error(CompileTimeErrorCode.UNCHECKED_PROPERTY_ACCESS_OF_NULLABLE_VALUE,
101, 1),
103, 1),
]);
var propertyAccess1 = findNode.propertyAccess('x; // 1');
var propertyAccess2 = findNode.propertyAccess('x; // 2');
@ -1505,7 +1505,7 @@ m(C c) {
}
''', [
error(CompileTimeErrorCode.UNCHECKED_PROPERTY_ACCESS_OF_NULLABLE_VALUE,
142, 5,
148, 1,
contextMessages: [message('/home/test/lib/test.dart', 56, 1)]),
]);
var propertyAccess1 = findNode.propertyAccess('x; // 1');
@ -1543,7 +1543,7 @@ m(C c) {
}
''', [
error(CompileTimeErrorCode.UNCHECKED_PROPERTY_ACCESS_OF_NULLABLE_VALUE,
148, 3,
152, 1,
contextMessages: [message('/home/test/lib/test.dart', 101, 1)]),
]);
var propertyAccess1 = findNode.propertyAccess('x; // 1');
@ -1630,8 +1630,8 @@ m(String? s) {
''', [
error(
CompileTimeErrorCode.UNCHECKED_OPERATOR_INVOCATION_OF_NULLABLE_VALUE,
17,
9),
27,
3),
]);
}

View file

@ -87,7 +87,7 @@ class CollectingReporter extends ErrorReporter {
@override
void reportErrorForToken(ErrorCode errorCode, Token token,
[List<Object?>? arguments]) {
[List<Object?>? arguments, List<DiagnosticMessage>? messages]) {
code = errorCode;
}
}

View file

@ -6400,7 +6400,7 @@ _An expression whose value is always 'null' can't be dereferenced._
#### Description
The analyzer produces this diagnostic when an expression whose value will
always be `null` is dererenced.
always be `null` is dereferenced.
#### Example
@ -11101,7 +11101,7 @@ the point where it's referenced:
{% prettify dart tag=pre+code %}
void f(String? s) {
if ([!s!].length > 3) {
if (s.[!length!] > 3) {
// ...
}
}

View file

@ -15,7 +15,7 @@ extension on C? {
void testCQuestion() {
if (this != null) {
f(this.cProp);
//^^^^
// ^^^^^
// [analyzer] COMPILE_TIME_ERROR.UNCHECKED_USE_OF_NULLABLE_VALUE
// ^
// [cfe] Property 'cProp' cannot be accessed on 'C?' because it is potentially null.

View file

@ -18,7 +18,7 @@ void f1(NotGeneric x) {
void f2(NotGeneric? x) {
x?[0] + 1;
//^^^^^
// ^
// [analyzer] COMPILE_TIME_ERROR.UNCHECKED_USE_OF_NULLABLE_VALUE
// [cfe] unspecified
x?[0] = 1;
@ -45,14 +45,14 @@ void f2(NotGeneric? x) {
void f3<T extends num>(Generic<T>? x) {
x?[0] + 1;
//^^^^^
// ^
// [analyzer] COMPILE_TIME_ERROR.UNCHECKED_USE_OF_NULLABLE_VALUE
// [cfe] unspecified
}
void f4<T extends num>(Generic<T?> x) {
x[0] + 1;
//^^^^
// ^
// [analyzer] COMPILE_TIME_ERROR.UNCHECKED_USE_OF_NULLABLE_VALUE
// [cfe] unspecified
}

View file

@ -14,18 +14,16 @@ void f1(
) {
(nullableInt ?? nonNullInt) + 1;
(nullableInt ?? nullableInt) + 1;
//^^^^^^^^^^^^^^^^^^^^^^^^^^^^
// [analyzer] COMPILE_TIME_ERROR.UNCHECKED_USE_OF_NULLABLE_VALUE
// ^
// [analyzer] COMPILE_TIME_ERROR.UNCHECKED_USE_OF_NULLABLE_VALUE
// [cfe] Operator '+' cannot be called on 'int?' because it is potentially null.
(nonNullInt ?? nullableInt) + 1;
//^^^^^^^^^^^^^^^^^^^^^^^^^^^
// [analyzer] COMPILE_TIME_ERROR.UNCHECKED_USE_OF_NULLABLE_VALUE
// ^
// [cfe] Operand of null-aware operation '??' has type 'int' which excludes null.
// ^^^^^^^^^^^
// [analyzer] STATIC_WARNING.DEAD_NULL_AWARE_EXPRESSION
// ^
// [analyzer] COMPILE_TIME_ERROR.UNCHECKED_USE_OF_NULLABLE_VALUE
// [cfe] Operator '+' cannot be called on 'int?' because it is potentially null.
(nonNullInt ?? nonNullInt) + 1;
// ^

View file

@ -12,7 +12,7 @@
void assignNullRhs(int? x) {
if (x != (x = null)) {
x.isEven;
// ^
// ^^^^^^
// [analyzer] COMPILE_TIME_ERROR.UNCHECKED_USE_OF_NULLABLE_VALUE
//^
// [cfe] Property 'isEven' cannot be accessed on 'int?' because it is potentially null.
@ -25,7 +25,7 @@ void assignNullLhs(int? x) {
// promote in order to be consistent with the `assignNullRhs` case.
if ((x = null) != x) {
x.isEven;
// ^
// ^^^^^^
// [analyzer] COMPILE_TIME_ERROR.UNCHECKED_USE_OF_NULLABLE_VALUE
//^
// [cfe] Property 'isEven' cannot be accessed on 'int?' because it is potentially null.
@ -35,7 +35,7 @@ void assignNullLhs(int? x) {
void unrelatedVarRhs(int? x, Null n) {
if (x != n) {
x.isEven;
// ^
// ^^^^^^
// [analyzer] COMPILE_TIME_ERROR.UNCHECKED_USE_OF_NULLABLE_VALUE
//^
// [cfe] Property 'isEven' cannot be accessed on 'int?' because it is potentially null.
@ -45,7 +45,7 @@ void unrelatedVarRhs(int? x, Null n) {
void unrelatedVarLhs(int? x, Null n) {
if (n != x) {
x.isEven;
// ^
// ^^^^^^
// [analyzer] COMPILE_TIME_ERROR.UNCHECKED_USE_OF_NULLABLE_VALUE
//^
// [cfe] Property 'isEven' cannot be accessed on 'int?' because it is potentially null.

View file

@ -11,14 +11,12 @@ class C {
void main() {
final C? c = new C();
/**/ -c?.e();
// ^^^^^^
// [analyzer] COMPILE_TIME_ERROR.UNCHECKED_USE_OF_NULLABLE_VALUE
// ^
// [analyzer] COMPILE_TIME_ERROR.UNCHECKED_USE_OF_NULLABLE_VALUE
// [cfe] Operator 'unary-' cannot be called on 'C?' because it is potentially null.
/**/ ~c?.e();
// ^^^^^^
// [analyzer] COMPILE_TIME_ERROR.UNCHECKED_USE_OF_NULLABLE_VALUE
// ^
// [analyzer] COMPILE_TIME_ERROR.UNCHECKED_USE_OF_NULLABLE_VALUE
// [cfe] Operator '~' cannot be called on 'C?' because it is potentially null.
}

View file

@ -18,12 +18,12 @@ void f(int x, int y, int? z) {
// ^
// [cfe] Illegal assignment to non-assignable expression.
z++ ??= y;
//^
// [analyzer] COMPILE_TIME_ERROR.UNCHECKED_USE_OF_NULLABLE_VALUE
//^^^
// [analyzer] SYNTACTIC_ERROR.ILLEGAL_ASSIGNMENT_TO_NON_ASSIGNABLE
//^^^
// [analyzer] SYNTACTIC_ERROR.MISSING_ASSIGNABLE_SELECTOR
// ^^
// [analyzer] COMPILE_TIME_ERROR.UNCHECKED_USE_OF_NULLABLE_VALUE
// ^
// [cfe] Illegal assignment to non-assignable expression.
}

View file

@ -49,13 +49,13 @@ class C extends B {
// [analyzer] SYNTACTIC_ERROR.INVALID_OPERATOR_QUESTIONMARK_PERIOD_FOR_SUPER
// [cfe] The operator '?.' cannot be used with 'super' because 'super' cannot be null.
-super?.field;
// ^^^^^^^^^^^^
// ^
// [analyzer] COMPILE_TIME_ERROR.UNCHECKED_USE_OF_NULLABLE_VALUE
// ^^
// [analyzer] SYNTACTIC_ERROR.INVALID_OPERATOR_QUESTIONMARK_PERIOD_FOR_SUPER
// [cfe] The operator '?.' cannot be used with 'super' because 'super' cannot be null.
~super?.field;
// ^^^^^^^^^^^^
// ^
// [analyzer] COMPILE_TIME_ERROR.UNCHECKED_USE_OF_NULLABLE_VALUE
// ^^
// [analyzer] SYNTACTIC_ERROR.INVALID_OPERATOR_QUESTIONMARK_PERIOD_FOR_SUPER

View file

@ -13,7 +13,7 @@ direct_assignment(int? i, int? j) {
//^
// [context 1] Variable 'i' could be null due to an intervening write.
i.isEven;
//^
// ^^^^^^
// [analyzer] COMPILE_TIME_ERROR.UNCHECKED_USE_OF_NULLABLE_VALUE
//^
// [cfe 1] Property 'isEven' cannot be accessed on 'int?' because it is potentially null.
@ -25,7 +25,7 @@ compound_assignment(C? c, int i) {
//^
// [context 2] Variable 'c' could be null due to an intervening write.
c.cProperty;
//^
// ^^^^^^^^^
// [analyzer] COMPILE_TIME_ERROR.UNCHECKED_USE_OF_NULLABLE_VALUE
//^
// [cfe 2] Property 'cProperty' cannot be accessed on 'C?' because it is potentially null.
@ -37,7 +37,7 @@ via_postfix_op(C? c) {
//^
// [context 3] Variable 'c' could be null due to an intervening write.
c.cProperty;
//^
// ^^^^^^^^^
// [analyzer] COMPILE_TIME_ERROR.UNCHECKED_USE_OF_NULLABLE_VALUE
//^
// [cfe 3] Property 'cProperty' cannot be accessed on 'C?' because it is potentially null.
@ -49,7 +49,7 @@ via_prefix_op(C? c) {
//^
// [context 4] Variable 'c' could be null due to an intervening write.
c.cProperty;
//^
// ^^^^^^^^^
// [analyzer] COMPILE_TIME_ERROR.UNCHECKED_USE_OF_NULLABLE_VALUE
//^
// [cfe 4] Property 'cProperty' cannot be accessed on 'C?' because it is potentially null.
@ -61,7 +61,7 @@ via_for_each_statement(int? i, List<int?> list) {
// ^
// [context 5] Variable 'i' could be null due to an intervening write.
i.isEven;
// ^
// ^^^^^^
// [analyzer] COMPILE_TIME_ERROR.UNCHECKED_USE_OF_NULLABLE_VALUE
//^
// [cfe 5] Property 'isEven' cannot be accessed on 'int?' because it is potentially null.
@ -73,7 +73,7 @@ via_for_each_list_element(int? i, List<int?> list) {
[for (i in list) i.isEven];
// ^
// [context 6] Variable 'i' could be null due to an intervening write.
// ^
// ^^^^^^
// [analyzer] COMPILE_TIME_ERROR.UNCHECKED_USE_OF_NULLABLE_VALUE
// ^
// [cfe 6] Property 'isEven' cannot be accessed on 'int?' because it is potentially null.
@ -84,7 +84,7 @@ via_for_each_set_element(int? i, List<int?> list) {
({for (i in list) i.isEven});
// ^
// [context 7] Variable 'i' could be null due to an intervening write.
// ^
// ^^^^^^
// [analyzer] COMPILE_TIME_ERROR.UNCHECKED_USE_OF_NULLABLE_VALUE
// ^
// [cfe 7] Property 'isEven' cannot be accessed on 'int?' because it is potentially null.
@ -95,7 +95,7 @@ via_for_each_map_key(int? i, List<int?> list) {
({for (i in list) i.isEven: null});
// ^
// [context 8] Variable 'i' could be null due to an intervening write.
// ^
// ^^^^^^
// [analyzer] COMPILE_TIME_ERROR.UNCHECKED_USE_OF_NULLABLE_VALUE
// ^
// [cfe 8] Property 'isEven' cannot be accessed on 'int?' because it is potentially null.
@ -106,7 +106,7 @@ via_for_each_map_value(int? i, List<int?> list) {
({for (i in list) null: i.isEven});
// ^
// [context 9] Variable 'i' could be null due to an intervening write.
// ^
// ^^^^^^
// [analyzer] COMPILE_TIME_ERROR.UNCHECKED_USE_OF_NULLABLE_VALUE
// ^
// [cfe 9] Property 'isEven' cannot be accessed on 'int?' because it is potentially null.

View file

@ -6,7 +6,7 @@ class C {
get_property_via_explicit_this() {
if (this.i == null) return;
this.i.isEven;
// ^^^^^^
// ^^^^^^
// [analyzer] COMPILE_TIME_ERROR.UNCHECKED_USE_OF_NULLABLE_VALUE
// ^
// [cfe 1] Property 'isEven' cannot be accessed on 'int?' because it is potentially null.
@ -15,7 +15,7 @@ class C {
get_property_via_explicit_this_parenthesized() {
if ((this).i == null) return;
(this).i.isEven;
// ^^^^^^^^
// ^^^^^^
// [analyzer] COMPILE_TIME_ERROR.UNCHECKED_USE_OF_NULLABLE_VALUE
// ^
// [cfe 2] Property 'isEven' cannot be accessed on 'int?' because it is potentially null.
@ -24,7 +24,7 @@ class C {
get_property_by_implicit_this() {
if (i == null) return;
i.isEven;
// ^
// ^^^^^^
// [analyzer] COMPILE_TIME_ERROR.UNCHECKED_USE_OF_NULLABLE_VALUE
// ^
// [cfe 3] Property 'isEven' cannot be accessed on 'int?' because it is potentially null.
@ -46,7 +46,7 @@ class D extends C {
get_property_by_implicit_super() {
if (i == null) return;
i.isEven;
// ^
// ^^^^^^
// [analyzer] COMPILE_TIME_ERROR.UNCHECKED_USE_OF_NULLABLE_VALUE
// ^
// [cfe 4] Property 'isEven' cannot be accessed on 'int?' because it is potentially null.
@ -56,7 +56,7 @@ class D extends C {
get_property_via_prefixed_identifier(C c) {
if (c.i == null) return;
c.i.isEven;
//^^^
// ^^^^^^
// [analyzer] COMPILE_TIME_ERROR.UNCHECKED_USE_OF_NULLABLE_VALUE
// ^
// [cfe 5] Property 'isEven' cannot be accessed on 'int?' because it is potentially null.
@ -67,7 +67,7 @@ get_property_via_prefixed_identifier_mismatched_target(C c1, C c2) {
// to promote is on c1, but the property the user is accessing is on c2.
if (c1.i == null) return;
c2.i.isEven;
//^^^^
// ^^^^^^
// [analyzer] COMPILE_TIME_ERROR.UNCHECKED_USE_OF_NULLABLE_VALUE
// ^
// [cfe] Property 'isEven' cannot be accessed on 'int?' because it is potentially null.
@ -78,7 +78,7 @@ get_property_via_prefixed_identifier_mismatched_property(C c) {
// to promote is C.i, but the property the user is accessing is C.j.
if (c.i == null) return;
c.j.isEven;
//^^^
// ^^^^^^
// [analyzer] COMPILE_TIME_ERROR.UNCHECKED_USE_OF_NULLABLE_VALUE
// ^
// [cfe] Property 'isEven' cannot be accessed on 'int?' because it is potentially null.

View file

@ -16,7 +16,7 @@ class C {
get_field_via_explicit_this() {
if (this.i == null) return;
this.i.isEven;
// ^^^^^^
// ^^^^^^
// [analyzer] COMPILE_TIME_ERROR.UNCHECKED_USE_OF_NULLABLE_VALUE
// ^
// [cfe 1] Property 'isEven' cannot be accessed on 'int?' because it is potentially null.
@ -25,7 +25,7 @@ class C {
get_field_via_explicit_this_parenthesized() {
if ((this).i == null) return;
(this).i.isEven;
// ^^^^^^^^
// ^^^^^^
// [analyzer] COMPILE_TIME_ERROR.UNCHECKED_USE_OF_NULLABLE_VALUE
// ^
// [cfe 2] Property 'isEven' cannot be accessed on 'int?' because it is potentially null.
@ -34,7 +34,7 @@ class C {
get_field_by_implicit_this() {
if (i == null) return;
i.isEven;
// ^
// ^^^^^^
// [analyzer] COMPILE_TIME_ERROR.UNCHECKED_USE_OF_NULLABLE_VALUE
// ^
// [cfe 3] Property 'isEven' cannot be accessed on 'int?' because it is potentially null.
@ -45,7 +45,7 @@ class D extends C {
get_field_via_explicit_super() {
if (super.i == null) return;
super.i.isEven;
// ^^^^^^^
// ^^^^^^
// [analyzer] COMPILE_TIME_ERROR.UNCHECKED_USE_OF_NULLABLE_VALUE
// ^
// [cfe 4] Property 'isEven' cannot be accessed on 'int?' because it is potentially null.
@ -54,7 +54,7 @@ class D extends C {
get_field_by_implicit_super() {
if (i == null) return;
i.isEven;
// ^
// ^^^^^^
// [analyzer] COMPILE_TIME_ERROR.UNCHECKED_USE_OF_NULLABLE_VALUE
// ^
// [cfe 5] Property 'isEven' cannot be accessed on 'int?' because it is potentially null.
@ -64,7 +64,7 @@ class D extends C {
get_field_via_prefixed_identifier(C c) {
if (c.i == null) return;
c.i.isEven;
//^^^
// ^^^^^^
// [analyzer] COMPILE_TIME_ERROR.UNCHECKED_USE_OF_NULLABLE_VALUE
// ^
// [cfe 6] Property 'isEven' cannot be accessed on 'int?' because it is potentially null.
@ -75,7 +75,7 @@ get_field_via_prefixed_identifier_mismatched_target(C c1, C c2) {
// to promote is on c1, but the property the user is accessing is on c2.
if (c1.i == null) return;
c2.i.isEven;
//^^^^
// ^^^^^^
// [analyzer] COMPILE_TIME_ERROR.UNCHECKED_USE_OF_NULLABLE_VALUE
// ^
// [cfe] Property 'isEven' cannot be accessed on 'int?' because it is potentially null.
@ -86,7 +86,7 @@ get_field_via_prefixed_identifier_mismatched_property(C c) {
// to promote is C.i, but the property the user is accessing is C.j.
if (c.i == null) return;
c.j.isEven;
//^^^
// ^^^^^^
// [analyzer] COMPILE_TIME_ERROR.UNCHECKED_USE_OF_NULLABLE_VALUE
// ^
// [cfe] Property 'isEven' cannot be accessed on 'int?' because it is potentially null.

View file

@ -140,7 +140,7 @@ instance_field_invocation(C12 c) {
// Note: the CFE error message is misleading here. See
// https://github.com/dart-lang/sdk/issues/45552
c.bad.foo();
//^^^^^
// ^^^
// [analyzer] COMPILE_TIME_ERROR.UNCHECKED_USE_OF_NULLABLE_VALUE
// ^
// [cfe 6] Can't use an expression of type 'C13?' as a function because it's potentially null.

View file

@ -34,7 +34,7 @@ property_get_of_variable(int? i, int? j) {
//^
// [context 1] Variable 'i' could be null due to an intervening write.
i.isEven;
//^
// ^^^^^^
// [analyzer] COMPILE_TIME_ERROR.UNCHECKED_USE_OF_NULLABLE_VALUE
// ^
// [cfe 1] Property 'isEven' cannot be accessed on 'int?' because it is potentially null.
@ -47,7 +47,7 @@ extension_property_get_of_variable(int? i, int? j) {
// [context 2] Variable 'i' could be null due to an intervening write.
i.propertyOnNullableInt;
i.propertyOnNonNullInt;
//^
// ^^^^^^^^^^^^^^^^^^^^
// [analyzer] COMPILE_TIME_ERROR.UNCHECKED_USE_OF_NULLABLE_VALUE
// ^
// [cfe 2] Property 'propertyOnNonNullInt' cannot be accessed on 'int?' because it is potentially null.
@ -56,7 +56,7 @@ extension_property_get_of_variable(int? i, int? j) {
property_get_of_expression(C c) {
if (c.i == null) return;
c.i.isEven;
//^^^
// ^^^^^^
// [analyzer] COMPILE_TIME_ERROR.UNCHECKED_USE_OF_NULLABLE_VALUE
// ^
// [cfe 3] Property 'isEven' cannot be accessed on 'int?' because it is potentially null.
@ -66,7 +66,7 @@ extension_property_get_of_expression(C c) {
if (c.i == null) return;
c.i.propertyOnNullableInt;
c.i.propertyOnNonNullInt;
//^^^
// ^^^^^^^^^^^^^^^^^^^^
// [analyzer] COMPILE_TIME_ERROR.UNCHECKED_USE_OF_NULLABLE_VALUE
// ^
// [cfe 4] Property 'propertyOnNonNullInt' cannot be accessed on 'int?' because it is potentially null.
@ -75,7 +75,7 @@ extension_property_get_of_expression(C c) {
method_invocation(C c) {
if (c.i == null) return;
c.i.abs();
//^^^
// ^^^
// [analyzer] COMPILE_TIME_ERROR.UNCHECKED_USE_OF_NULLABLE_VALUE
// ^
// [cfe 5] Method 'abs' cannot be called on 'int?' because it is potentially null.
@ -85,7 +85,7 @@ extension_method_invocation(C c) {
if (c.i == null) return;
c.i.methodOnNullableInt();
c.i.methodOnNonNullInt();
//^^^
// ^^^^^^^^^^^^^^^^^^
// [analyzer] COMPILE_TIME_ERROR.UNCHECKED_USE_OF_NULLABLE_VALUE
// ^
// [cfe 6] Method 'methodOnNonNullInt' cannot be called on 'int?' because it is potentially null.
@ -94,7 +94,7 @@ extension_method_invocation(C c) {
call_invocation(C c) {
if (c.f == null) return;
c.f.call();
//^^^
// ^^^^
// [analyzer] COMPILE_TIME_ERROR.UNCHECKED_USE_OF_NULLABLE_VALUE
// ^
// [cfe 7] Method 'call' cannot be called on 'void Function()?' because it is potentially null.

View file

@ -16,7 +16,7 @@ class C {
get_property_via_explicit_this() {
if (this.i == null) return;
this.i.isEven;
// ^^^^^^
// ^^^^^^
// [analyzer] COMPILE_TIME_ERROR.UNCHECKED_USE_OF_NULLABLE_VALUE
// ^
// [cfe 1] Property 'isEven' cannot be accessed on 'int?' because it is potentially null.
@ -25,7 +25,7 @@ class C {
get_property_via_explicit_this_parenthesized() {
if ((this).i == null) return;
(this).i.isEven;
// ^^^^^^^^
// ^^^^^^
// [analyzer] COMPILE_TIME_ERROR.UNCHECKED_USE_OF_NULLABLE_VALUE
// ^
// [cfe 2] Property 'isEven' cannot be accessed on 'int?' because it is potentially null.
@ -34,7 +34,7 @@ class C {
get_property_by_implicit_this() {
if (i == null) return;
i.isEven;
// ^
// ^^^^^^
// [analyzer] COMPILE_TIME_ERROR.UNCHECKED_USE_OF_NULLABLE_VALUE
// ^
// [cfe 3] Property 'isEven' cannot be accessed on 'int?' because it is potentially null.
@ -45,7 +45,7 @@ class D extends C {
get_property_via_explicit_super() {
if (super.i == null) return;
super.i.isEven;
// ^^^^^^^
// ^^^^^^
// [analyzer] COMPILE_TIME_ERROR.UNCHECKED_USE_OF_NULLABLE_VALUE
// ^
// [cfe 4] Property 'isEven' cannot be accessed on 'int?' because it is potentially null.
@ -54,7 +54,7 @@ class D extends C {
get_property_by_implicit_super() {
if (i == null) return;
i.isEven;
// ^
// ^^^^^^
// [analyzer] COMPILE_TIME_ERROR.UNCHECKED_USE_OF_NULLABLE_VALUE
// ^
// [cfe 5] Property 'isEven' cannot be accessed on 'int?' because it is potentially null.
@ -64,7 +64,7 @@ class D extends C {
get_property_via_prefixed_identifier(C c) {
if (c.i == null) return;
c.i.isEven;
//^^^
// ^^^^^^
// [analyzer] COMPILE_TIME_ERROR.UNCHECKED_USE_OF_NULLABLE_VALUE
// ^
// [cfe 6] Property 'isEven' cannot be accessed on 'int?' because it is potentially null.
@ -75,7 +75,7 @@ get_property_via_prefixed_identifier_mismatched_target(C c1, C c2) {
// to promote is on c1, but the property the user is accessing is on c2.
if (c1.i == null) return;
c2.i.isEven;
//^^^^
// ^^^^^^
// [analyzer] COMPILE_TIME_ERROR.UNCHECKED_USE_OF_NULLABLE_VALUE
// ^
// [cfe] Property 'isEven' cannot be accessed on 'int?' because it is potentially null.
@ -86,7 +86,7 @@ get_property_via_prefixed_identifier_mismatched_property(C c) {
// to promote is C.i, but the property the user is accessing is C.j.
if (c.i == null) return;
c.j.isEven;
//^^^
// ^^^^^^
// [analyzer] COMPILE_TIME_ERROR.UNCHECKED_USE_OF_NULLABLE_VALUE
// ^
// [cfe] Property 'isEven' cannot be accessed on 'int?' because it is potentially null.

View file

@ -14,7 +14,7 @@ extension on int? {
// TODO(paulberry): get this to work with the CFE.
if (this == null) return;
this.isEven;
// ^^^^
// ^^^^^^
// [analyzer] COMPILE_TIME_ERROR.UNCHECKED_USE_OF_NULLABLE_VALUE
// ^
// [cfe] Property 'isEven' cannot be accessed on 'int?' because it is potentially null.