diff --git a/pkg/analyzer/lib/src/generated/element_resolver.dart b/pkg/analyzer/lib/src/generated/element_resolver.dart index 0ab26fe98af..22baf4dcae7 100644 --- a/pkg/analyzer/lib/src/generated/element_resolver.dart +++ b/pkg/analyzer/lib/src/generated/element_resolver.dart @@ -1743,14 +1743,10 @@ class ElementResolver extends SimpleAstVisitor { /** * Return `true` if we should report an error for a [member] lookup that found - * no match on the given [type], or accessing a [member] on a nullable type. + * no match on the given [type]. */ - bool _shouldReportInvalidMember(DartType type, Element member) { - return type != null && - member == null && - !type.isDynamic && - !type.isDartCoreNull; - } + bool _shouldReportInvalidMember(DartType type, Element member) => + type != null && member == null && !type.isDynamic; /** * Checks whether the given [expression] is a reference to a class. If it is diff --git a/pkg/analyzer/test/generated/compile_time_error_code.dart b/pkg/analyzer/test/generated/compile_time_error_code.dart index e1db296a0e9..181575f182a 100644 --- a/pkg/analyzer/test/generated/compile_time_error_code.dart +++ b/pkg/analyzer/test/generated/compile_time_error_code.dart @@ -648,25 +648,28 @@ var x = const C(2); test_constEvalThrowsException_unaryBitNot_null() async { await assertErrorsInCode(''' -const C = ~null; +const dynamic D = null; +const C = ~D; ''', [ - error(CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION, 10, 5), + error(CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION, 34, 2), ]); } test_constEvalThrowsException_unaryNegated_null() async { await assertErrorsInCode(''' -const C = -null; +const dynamic D = null; +const C = -D; ''', [ - error(CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION, 10, 5), + error(CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION, 34, 2), ]); } test_constEvalThrowsException_unaryNot_null() async { await assertErrorsInCode(''' -const C = !null; +const dynamic D = null; +const C = !D; ''', [ - error(CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION, 10, 5), + error(CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION, 34, 2), ]); } @@ -5547,9 +5550,10 @@ f() { Future _check_constEvalThrowsException_binary_null( String expr, bool resolved) async { await assertErrorsInCode(''' -const C = $expr; +const dynamic D = null; +const C = ${expr.replaceAll('null', 'D')}; ''', [ - error(CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION, 10, 8), + error(CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION, 34, 5), ]); } diff --git a/pkg/analyzer/test/src/diagnostics/undefined_getter_test.dart b/pkg/analyzer/test/src/diagnostics/undefined_getter_test.dart index 6feaae55822..3958e8562c1 100644 --- a/pkg/analyzer/test/src/diagnostics/undefined_getter_test.dart +++ b/pkg/analyzer/test/src/diagnostics/undefined_getter_test.dart @@ -91,6 +91,15 @@ f(Object x) { '''); } + test_nullMember_undefined() async { + await assertErrorCodesInCode(r''' +m() { + Null _null; + _null.foo; +} +''', [StaticTypeWarningCode.UNDEFINED_GETTER]); + } + test_promotedTypeParameter_regress35305() async { await assertErrorsInCode(r''' void f(Y y) { diff --git a/tests/language_2/null_no_such_method_test.dart b/tests/language_2/null_no_such_method_test.dart index 600c6bb7d73..299ba2d662e 100644 --- a/tests/language_2/null_no_such_method_test.dart +++ b/tests/language_2/null_no_such_method_test.dart @@ -4,10 +4,10 @@ import "package:expect/expect.dart"; -var array = [1]; - main() { - Expect.throwsNoSuchMethodError(() => -null); + Expect.throwsNoSuchMethodError(() => -(null as dynamic)); // Make sure we have an untyped call to operator-. print(-array[0]); } + +var array = [1];