From 5e040a20f853891fa4587274179a1a2d4733b0a3 Mon Sep 17 00:00:00 2001 From: Sam Rawlins Date: Fri, 2 Apr 2021 02:43:48 +0000 Subject: [PATCH] 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 Reviewed-by: Konstantin Shcheglov Reviewed-by: Brian Wilkerson --- .../correction/dart/add_null_check.dart | 25 +++++- pkg/analyzer/lib/error/listener.dart | 5 +- .../assignment_expression_resolver.dart | 2 +- .../resolver/binary_expression_resolver.dart | 2 +- ...nction_expression_invocation_resolver.dart | 2 +- .../lib/src/dart/resolver/lexical_lookup.dart | 2 +- .../resolver/method_invocation_resolver.dart | 4 +- .../resolver/postfix_expression_resolver.dart | 2 +- .../resolver/prefix_expression_resolver.dart | 2 +- .../resolver/property_element_resolver.dart | 4 +- .../dart/resolver/type_property_resolver.dart | 20 +++-- pkg/analyzer/lib/src/error/codes.dart | 4 +- .../error/nullable_dereference_verifier.dart | 15 +++- .../lib/src/generated/element_resolver.dart | 4 +- .../resolution/method_invocation_test.dart | 12 +-- .../resolution/prefix_expression_test.dart | 4 +- .../dart/resolution/property_access_test.dart | 2 +- .../null_safety_read_write_test.dart | 12 +-- .../receiver_of_type_never_test.dart | 14 ++-- .../diagnostics/undefined_getter_test.dart | 2 +- .../use_of_nullable_value_test.dart | 78 +++++++++---------- .../test/src/lint/lint_rule_test.dart | 2 +- pkg/analyzer/tool/diagnostics/diagnostics.md | 4 +- ...xtension_this_not_promoted_error_test.dart | 2 +- ...subscript_produces_nullable_type_test.dart | 6 +- .../question_question_lub_test.dart | 6 +- ...ient_for_equals_null_check_error_test.dart | 8 +- .../prefix_not_shortening_test.dart | 6 +- ..._assignment_to_postfix_increment_test.dart | 4 +- .../super/conditional_operator_test.dart | 4 +- .../assignment_error_test.dart | 18 ++--- .../extension_property_error_test.dart | 14 ++-- .../why_not_promoted/field_error_test.dart | 16 ++-- .../nullable_expression_call_error_test.dart | 2 +- .../nullable_method_call_error_test.dart | 14 ++-- .../why_not_promoted/property_error_test.dart | 16 ++-- .../why_not_promoted/this_error_test.dart | 2 +- 37 files changed, 190 insertions(+), 151 deletions(-) diff --git a/pkg/analysis_server/lib/src/services/correction/dart/add_null_check.dart b/pkg/analysis_server/lib/src/services/correction/dart/add_null_check.dart index 891afc1b3a7..b7b4810da2e 100644 --- a/pkg/analysis_server/lib/src/services/correction/dart/add_null_check.dart +++ b/pkg/analysis_server/lib/src/services/correction/dart/add_null_check.dart @@ -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; } diff --git a/pkg/analyzer/lib/error/listener.dart b/pkg/analyzer/lib/error/listener.dart index e89e8b6de24..b37838a20ba 100644 --- a/pkg/analyzer/lib/error/listener.dart +++ b/pkg/analyzer/lib/error/listener.dart @@ -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? arguments]) { - reportErrorForOffset(errorCode, token.offset, token.length, arguments); + [List? arguments, List? messages]) { + reportErrorForOffset( + errorCode, token.offset, token.length, arguments, messages); } /// Report an error with the given [errorCode] and [message]. The location of diff --git a/pkg/analyzer/lib/src/dart/resolver/assignment_expression_resolver.dart b/pkg/analyzer/lib/src/dart/resolver/assignment_expression_resolver.dart index 4c0516457a3..aaaa1821017 100644 --- a/pkg/analyzer/lib/src/dart/resolver/assignment_expression_resolver.dart +++ b/pkg/analyzer/lib/src/dart/resolver/assignment_expression_resolver.dart @@ -185,7 +185,7 @@ class AssignmentExpressionResolver { receiver: left, receiverType: leftType, name: methodName, - receiverErrorNode: left, + propertyErrorEntity: operator, nameErrorEntity: operator, ); node.staticElement = result.getter as MethodElement?; diff --git a/pkg/analyzer/lib/src/dart/resolver/binary_expression_resolver.dart b/pkg/analyzer/lib/src/dart/resolver/binary_expression_resolver.dart index b6453e8edfa..e4b016a8ad5 100644 --- a/pkg/analyzer/lib/src/dart/resolver/binary_expression_resolver.dart +++ b/pkg/analyzer/lib/src/dart/resolver/binary_expression_resolver.dart @@ -322,7 +322,7 @@ class BinaryExpressionResolver { receiver: leftOperand, receiverType: leftType, name: methodName, - receiverErrorNode: leftOperand, + propertyErrorEntity: node.operator, nameErrorEntity: node, ); diff --git a/pkg/analyzer/lib/src/dart/resolver/function_expression_invocation_resolver.dart b/pkg/analyzer/lib/src/dart/resolver/function_expression_invocation_resolver.dart index 9a099ed1677..199ea71ad1b 100644 --- a/pkg/analyzer/lib/src/dart/resolver/function_expression_invocation_resolver.dart +++ b/pkg/analyzer/lib/src/dart/resolver/function_expression_invocation_resolver.dart @@ -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; diff --git a/pkg/analyzer/lib/src/dart/resolver/lexical_lookup.dart b/pkg/analyzer/lib/src/dart/resolver/lexical_lookup.dart index f9256eae4c6..63bc1cff126 100644 --- a/pkg/analyzer/lib/src/dart/resolver/lexical_lookup.dart +++ b/pkg/analyzer/lib/src/dart/resolver/lexical_lookup.dart @@ -56,7 +56,7 @@ class LexicalLookup { receiver: null, receiverType: thisType, name: id, - receiverErrorNode: node, + propertyErrorEntity: node, nameErrorEntity: node, ); diff --git a/pkg/analyzer/lib/src/dart/resolver/method_invocation_resolver.dart b/pkg/analyzer/lib/src/dart/resolver/method_invocation_resolver.dart index c585b072c5b..caff68307d9 100644 --- a/pkg/analyzer/lib/src/dart/resolver/method_invocation_resolver.dart +++ b/pkg/analyzer/lib/src/dart/resolver/method_invocation_resolver.dart @@ -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, ); diff --git a/pkg/analyzer/lib/src/dart/resolver/postfix_expression_resolver.dart b/pkg/analyzer/lib/src/dart/resolver/postfix_expression_resolver.dart index e8adbbb98c2..c09803d0166 100644 --- a/pkg/analyzer/lib/src/dart/resolver/postfix_expression_resolver.dart +++ b/pkg/analyzer/lib/src/dart/resolver/postfix_expression_resolver.dart @@ -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?; diff --git a/pkg/analyzer/lib/src/dart/resolver/prefix_expression_resolver.dart b/pkg/analyzer/lib/src/dart/resolver/prefix_expression_resolver.dart index 32016260a60..6e787e6cba1 100644 --- a/pkg/analyzer/lib/src/dart/resolver/prefix_expression_resolver.dart +++ b/pkg/analyzer/lib/src/dart/resolver/prefix_expression_resolver.dart @@ -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?; diff --git a/pkg/analyzer/lib/src/dart/resolver/property_element_resolver.dart b/pkg/analyzer/lib/src/dart/resolver/property_element_resolver.dart index 36abe1cac4a..8a6475857f0 100644 --- a/pkg/analyzer/lib/src/dart/resolver/property_element_resolver.dart +++ b/pkg/analyzer/lib/src/dart/resolver/property_element_resolver.dart @@ -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, ); diff --git a/pkg/analyzer/lib/src/dart/resolver/type_property_resolver.dart b/pkg/analyzer/lib/src/dart/resolver/type_property_resolver.dart index 5c6b1abccd6..cff8b7e4257 100644 --- a/pkg/analyzer/lib/src/dart/resolver/type_property_resolver.dart +++ b/pkg/analyzer/lib/src/dart/resolver/type_property_resolver.dart @@ -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; diff --git a/pkg/analyzer/lib/src/error/codes.dart b/pkg/analyzer/lib/src/error/codes.dart index dc70d3e90c6..58fcf578218 100644 --- a/pkg/analyzer/lib/src/error/codes.dart +++ b/pkg/analyzer/lib/src/error/codes.dart @@ -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) { // // ... // } // } diff --git a/pkg/analyzer/lib/src/error/nullable_dereference_verifier.dart b/pkg/analyzer/lib/src/error/nullable_dereference_verifier.dart index cc053b67e04..cf1f3b53e1b 100644 --- a/pkg/analyzer/lib/src/error/nullable_dereference_verifier.dart +++ b/pkg/analyzer/lib/src/error/nullable_dereference_verifier.dart @@ -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 arguments = const [], List? 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. diff --git a/pkg/analyzer/lib/src/generated/element_resolver.dart b/pkg/analyzer/lib/src/generated/element_resolver.dart index ed9e40fdf6f..1da17d490b0 100644 --- a/pkg/analyzer/lib/src/generated/element_resolver.dart +++ b/pkg/analyzer/lib/src/generated/element_resolver.dart @@ -665,7 +665,7 @@ class ElementResolver extends SimpleAstVisitor { 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 { receiver: null, receiverType: enclosingType, name: identifier.name, - receiverErrorNode: identifier, + propertyErrorEntity: identifier, nameErrorEntity: identifier, ); if (identifier.inSetterContext() || diff --git a/pkg/analyzer/test/src/dart/resolution/method_invocation_test.dart b/pkg/analyzer/test/src/dart/resolution/method_invocation_test.dart index 237b1d89ee0..28b1f8c5ea7 100644 --- a/pkg/analyzer/test/src/dart/resolution/method_invocation_test.dart +++ b/pkg/analyzer/test/src/dart/resolution/method_invocation_test.dart @@ -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( diff --git a/pkg/analyzer/test/src/dart/resolution/prefix_expression_test.dart b/pkg/analyzer/test/src/dart/resolution/prefix_expression_test.dart index eb49c3fca0f..c49b4a60fa8 100644 --- a/pkg/analyzer/test/src/dart/resolution/prefix_expression_test.dart +++ b/pkg/analyzer/test/src/dart/resolution/prefix_expression_test.dart @@ -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( diff --git a/pkg/analyzer/test/src/dart/resolution/property_access_test.dart b/pkg/analyzer/test/src/dart/resolution/property_access_test.dart index 9c22823e9f7..b95d6270b27 100644 --- a/pkg/analyzer/test/src/dart/resolution/property_access_test.dart +++ b/pkg/analyzer/test/src/dart/resolution/property_access_test.dart @@ -522,7 +522,7 @@ class C { assertErrorsInResult(expectedErrorsByNullability( nullable: [ error(CompileTimeErrorCode.UNCHECKED_PROPERTY_ACCESS_OF_NULLABLE_VALUE, - 33, 3), + 37, 3), ], legacy: [ error(CompileTimeErrorCode.UNDEFINED_GETTER, 37, 3), diff --git a/pkg/analyzer/test/src/diagnostics/null_safety_read_write_test.dart b/pkg/analyzer/test/src/diagnostics/null_safety_read_write_test.dart index 1d73a79be57..ef2d1d96050 100644 --- a/pkg/analyzer/test/src/diagnostics/null_safety_read_write_test.dart +++ b/pkg/analyzer/test/src/diagnostics/null_safety_read_write_test.dart @@ -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); } diff --git a/pkg/analyzer/test/src/diagnostics/receiver_of_type_never_test.dart b/pkg/analyzer/test/src/diagnostics/receiver_of_type_never_test.dart index 9a85f2f91cc..b65d7e47227 100644 --- a/pkg/analyzer/test/src/diagnostics/receiver_of_type_never_test.dart +++ b/pkg/analyzer/test/src/diagnostics/receiver_of_type_never_test.dart @@ -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( diff --git a/pkg/analyzer/test/src/diagnostics/undefined_getter_test.dart b/pkg/analyzer/test/src/diagnostics/undefined_getter_test.dart index e00bb5fecd8..193e74a598a 100644 --- a/pkg/analyzer/test/src/diagnostics/undefined_getter_test.dart +++ b/pkg/analyzer/test/src/diagnostics/undefined_getter_test.dart @@ -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), ])); diff --git a/pkg/analyzer/test/src/diagnostics/use_of_nullable_value_test.dart b/pkg/analyzer/test/src/diagnostics/use_of_nullable_value_test.dart index cd568690710..f76dd2b370a 100644 --- a/pkg/analyzer/test/src/diagnostics/use_of_nullable_value_test.dart +++ b/pkg/analyzer/test/src/diagnostics/use_of_nullable_value_test.dart @@ -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 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), ]); } diff --git a/pkg/analyzer/test/src/lint/lint_rule_test.dart b/pkg/analyzer/test/src/lint/lint_rule_test.dart index 5db743af981..9298033b7fd 100644 --- a/pkg/analyzer/test/src/lint/lint_rule_test.dart +++ b/pkg/analyzer/test/src/lint/lint_rule_test.dart @@ -87,7 +87,7 @@ class CollectingReporter extends ErrorReporter { @override void reportErrorForToken(ErrorCode errorCode, Token token, - [List? arguments]) { + [List? arguments, List? messages]) { code = errorCode; } } diff --git a/pkg/analyzer/tool/diagnostics/diagnostics.md b/pkg/analyzer/tool/diagnostics/diagnostics.md index 9c462d535f7..767c77a50bd 100644 --- a/pkg/analyzer/tool/diagnostics/diagnostics.md +++ b/pkg/analyzer/tool/diagnostics/diagnostics.md @@ -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) { // ... } } diff --git a/tests/language/extension_methods/static_extension_this_not_promoted_error_test.dart b/tests/language/extension_methods/static_extension_this_not_promoted_error_test.dart index 342ccca45f4..bedb6da9ab2 100644 --- a/tests/language/extension_methods/static_extension_this_not_promoted_error_test.dart +++ b/tests/language/extension_methods/static_extension_this_not_promoted_error_test.dart @@ -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. diff --git a/tests/language/nnbd/resolution/null_aware_subscript_produces_nullable_type_test.dart b/tests/language/nnbd/resolution/null_aware_subscript_produces_nullable_type_test.dart index e7bf5b2fdcf..c0bd3e23c84 100644 --- a/tests/language/nnbd/resolution/null_aware_subscript_produces_nullable_type_test.dart +++ b/tests/language/nnbd/resolution/null_aware_subscript_produces_nullable_type_test.dart @@ -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(Generic? x) { x?[0] + 1; -//^^^^^ +// ^ // [analyzer] COMPILE_TIME_ERROR.UNCHECKED_USE_OF_NULLABLE_VALUE // [cfe] unspecified } void f4(Generic x) { x[0] + 1; -//^^^^ +// ^ // [analyzer] COMPILE_TIME_ERROR.UNCHECKED_USE_OF_NULLABLE_VALUE // [cfe] unspecified } diff --git a/tests/language/nnbd/resolution/question_question_lub_test.dart b/tests/language/nnbd/resolution/question_question_lub_test.dart index 12bafaec8c5..0f586265095 100644 --- a/tests/language/nnbd/resolution/question_question_lub_test.dart +++ b/tests/language/nnbd/resolution/question_question_lub_test.dart @@ -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; // ^ diff --git a/tests/language/nnbd/type_promotion/null_type_insufficient_for_equals_null_check_error_test.dart b/tests/language/nnbd/type_promotion/null_type_insufficient_for_equals_null_check_error_test.dart index 55d529b9104..bc800dcd774 100644 --- a/tests/language/nnbd/type_promotion/null_type_insufficient_for_equals_null_check_error_test.dart +++ b/tests/language/nnbd/type_promotion/null_type_insufficient_for_equals_null_check_error_test.dart @@ -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. diff --git a/tests/language/null_aware/prefix_not_shortening_test.dart b/tests/language/null_aware/prefix_not_shortening_test.dart index 20ef1affea2..9a9e6cd8b38 100644 --- a/tests/language/null_aware/prefix_not_shortening_test.dart +++ b/tests/language/null_aware/prefix_not_shortening_test.dart @@ -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. } diff --git a/tests/language/operator/invalid_assignment_to_postfix_increment_test.dart b/tests/language/operator/invalid_assignment_to_postfix_increment_test.dart index 751c947f344..2c10bfc4d65 100644 --- a/tests/language/operator/invalid_assignment_to_postfix_increment_test.dart +++ b/tests/language/operator/invalid_assignment_to_postfix_increment_test.dart @@ -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. } diff --git a/tests/language/super/conditional_operator_test.dart b/tests/language/super/conditional_operator_test.dart index 5ae030d02a0..734f7fcc385 100644 --- a/tests/language/super/conditional_operator_test.dart +++ b/tests/language/super/conditional_operator_test.dart @@ -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 diff --git a/tests/language/why_not_promoted/assignment_error_test.dart b/tests/language/why_not_promoted/assignment_error_test.dart index 6f363d8edb9..86ba93dcd2f 100644 --- a/tests/language/why_not_promoted/assignment_error_test.dart +++ b/tests/language/why_not_promoted/assignment_error_test.dart @@ -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 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 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 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 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 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. diff --git a/tests/language/why_not_promoted/extension_property_error_test.dart b/tests/language/why_not_promoted/extension_property_error_test.dart index db7d3eebf17..7412c73056a 100644 --- a/tests/language/why_not_promoted/extension_property_error_test.dart +++ b/tests/language/why_not_promoted/extension_property_error_test.dart @@ -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. diff --git a/tests/language/why_not_promoted/field_error_test.dart b/tests/language/why_not_promoted/field_error_test.dart index b32683d04a5..81935780602 100644 --- a/tests/language/why_not_promoted/field_error_test.dart +++ b/tests/language/why_not_promoted/field_error_test.dart @@ -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. diff --git a/tests/language/why_not_promoted/nullable_expression_call_error_test.dart b/tests/language/why_not_promoted/nullable_expression_call_error_test.dart index 45c461faf9a..c12b0e504bd 100644 --- a/tests/language/why_not_promoted/nullable_expression_call_error_test.dart +++ b/tests/language/why_not_promoted/nullable_expression_call_error_test.dart @@ -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. diff --git a/tests/language/why_not_promoted/nullable_method_call_error_test.dart b/tests/language/why_not_promoted/nullable_method_call_error_test.dart index 986436b85d7..70e8bbe4a6d 100644 --- a/tests/language/why_not_promoted/nullable_method_call_error_test.dart +++ b/tests/language/why_not_promoted/nullable_method_call_error_test.dart @@ -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. diff --git a/tests/language/why_not_promoted/property_error_test.dart b/tests/language/why_not_promoted/property_error_test.dart index 87452be4026..330a21e124e 100644 --- a/tests/language/why_not_promoted/property_error_test.dart +++ b/tests/language/why_not_promoted/property_error_test.dart @@ -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. diff --git a/tests/language/why_not_promoted/this_error_test.dart b/tests/language/why_not_promoted/this_error_test.dart index b9a770b2eb1..9c2a1d4fc92 100644 --- a/tests/language/why_not_promoted/this_error_test.dart +++ b/tests/language/why_not_promoted/this_error_test.dart @@ -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.