diff --git a/pkg/analyzer/lib/src/error/best_practices_verifier.dart b/pkg/analyzer/lib/src/error/best_practices_verifier.dart index 0e76c6184f8..5ee814de87d 100644 --- a/pkg/analyzer/lib/src/error/best_practices_verifier.dart +++ b/pkg/analyzer/lib/src/error/best_practices_verifier.dart @@ -613,7 +613,8 @@ class BestPracticesVerifier extends RecursiveAstVisitor { @override void visitPostfixExpression(PostfixExpression node) { _deprecatedVerifier.postfixExpression(node); - if (node.operand.staticType?.isDartCoreNull ?? false) { + if (node.operator.type == TokenType.BANG && + node.operand.staticType.isDartCoreNull) { _errorReporter.reportErrorForNode(HintCode.NULL_CHECK_ALWAYS_FAILS, node); } super.visitPostfixExpression(node); diff --git a/pkg/analyzer/test/src/diagnostics/null_check_always_fails_test.dart b/pkg/analyzer/test/src/diagnostics/null_check_always_fails_test.dart index e21d37c0e62..ce1298ba56c 100644 --- a/pkg/analyzer/test/src/diagnostics/null_check_always_fails_test.dart +++ b/pkg/analyzer/test/src/diagnostics/null_check_always_fails_test.dart @@ -37,10 +37,10 @@ void f() { test_nullLiteral_parenthesized() async { await assertErrorsInCode(r''' void f() { - null!; + (null)!; } ''', [ - error(HintCode.NULL_CHECK_ALWAYS_FAILS, 13, 5), + error(HintCode.NULL_CHECK_ALWAYS_FAILS, 13, 7), ]); }