Fix #36956, report undefined getter for uses on Null.
Bug: 36956 Change-Id: I5b8f40f5c1f7fd9304b02054e3d8d7d607c12af1 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/106021 Commit-Queue: Mike Fairhurst <mfairhurst@google.com> Reviewed-by: Paul Berry <paulberry@google.com>
This commit is contained in:
committed by
commit-bot@chromium.org
parent
f56df4a251
commit
c246fa1f2b
@@ -1743,14 +1743,10 @@ class ElementResolver extends SimpleAstVisitor<void> {
|
||||
|
||||
/**
|
||||
* 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
|
||||
|
||||
@@ -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<void> _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),
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
@@ -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<X extends num, Y extends X>(Y y) {
|
||||
|
||||
@@ -4,10 +4,10 @@
|
||||
|
||||
import "package:expect/expect.dart";
|
||||
|
||||
var array = <dynamic>[1];
|
||||
|
||||
main() {
|
||||
Expect.throwsNoSuchMethodError(() => -null);
|
||||
Expect.throwsNoSuchMethodError(() => -(null as dynamic));
|
||||
// Make sure we have an untyped call to operator-.
|
||||
print(-array[0]);
|
||||
}
|
||||
|
||||
var array = <dynamic>[1];
|
||||
|
||||
Reference in New Issue
Block a user