Issue 48004. Report when null-aware operator is used on type.

Bug: https://github.com/dart-lang/sdk/issues/48004
Change-Id: I61c658f9974fdb2023aa999bf34ee873e348058a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/246301
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
This commit is contained in:
Konstantin Shcheglov
2022-05-29 19:03:15 +00:00
committed by Commit Bot
parent 264f5255db
commit 58ae856422
18 changed files with 395 additions and 42 deletions
@@ -4518,6 +4518,19 @@ class ErrorVerifier extends RecursiveAstVisitor<void>
return;
}
} else if (targetType == null) {
if (target is Identifier) {
final targetElement = target.staticElement;
if (targetElement is ClassElement ||
targetElement is ExtensionElement ||
targetElement is TypeAliasElement) {
errorReporter.reportErrorForOffset(
errorCode,
operator.offset,
endToken.end - operator.offset,
arguments,
);
}
}
return;
}
@@ -5053,16 +5053,20 @@ main() {
}
test_error_undefinedMethod_typeLiteral_conditional() async {
// When applied to a type literal, the conditional access operator '?.'
// cannot be used to access instance methods of Type.
await assertErrorsInCode(r'''
await assertErrorsInCode(
r'''
class A {}
main() {
A?.toString();
}
''', [
error(CompileTimeErrorCode.UNDEFINED_METHOD, 25, 8),
]);
''',
expectedErrorsByNullability(nullable: [
error(StaticWarningCode.INVALID_NULL_AWARE_OPERATOR, 23, 2),
error(CompileTimeErrorCode.UNDEFINED_METHOD, 25, 8),
], legacy: [
error(CompileTimeErrorCode.UNDEFINED_METHOD, 25, 8),
]),
);
}
test_error_undefinedSuperMethod() async {
@@ -171,7 +171,7 @@ void f(int? a, int b) {
}
test_getter_class() async {
await assertNoErrorsInCode('''
await assertErrorsInCode('''
class C {
static int x = 0;
}
@@ -179,11 +179,13 @@ class C {
f() {
C?.x;
}
''');
''', [
error(StaticWarningCode.INVALID_NULL_AWARE_OPERATOR, 42, 2),
]);
}
test_getter_extension() async {
await assertNoErrorsInCode('''
await assertErrorsInCode('''
extension E on int {
static int x = 0;
}
@@ -191,7 +193,9 @@ extension E on int {
f() {
E?.x;
}
''');
''', [
error(StaticWarningCode.INVALID_NULL_AWARE_OPERATOR, 53, 2),
]);
}
test_getter_legacy() async {
@@ -213,7 +217,7 @@ f() {
}
test_getter_mixin() async {
await assertNoErrorsInCode('''
await assertErrorsInCode('''
mixin M {
static int x = 0;
}
@@ -221,7 +225,9 @@ mixin M {
f() {
M?.x;
}
''');
''', [
error(StaticWarningCode.INVALID_NULL_AWARE_OPERATOR, 42, 2),
]);
}
test_getter_nonNullable() async {
@@ -303,7 +309,7 @@ f(List<int>? x) {
}
test_method_class() async {
await assertNoErrorsInCode('''
await assertErrorsInCode('''
class C {
static void foo() {}
}
@@ -311,11 +317,31 @@ class C {
f() {
C?.foo();
}
''', [
error(StaticWarningCode.INVALID_NULL_AWARE_OPERATOR, 45, 2),
]);
}
test_method_class_prefixed() async {
newFile('$testPackageLibPath/a.dart', r'''
class C {
static void foo() {}
}
''');
await assertErrorsInCode('''
import 'a.dart' as prefix;
void f() {
prefix.C?.foo();
}
''', [
error(StaticWarningCode.INVALID_NULL_AWARE_OPERATOR, 49, 2),
]);
}
test_method_extension() async {
await assertNoErrorsInCode('''
await assertErrorsInCode('''
extension E on int {
static void foo() {}
}
@@ -323,7 +349,27 @@ extension E on int {
f() {
E?.foo();
}
''', [
error(StaticWarningCode.INVALID_NULL_AWARE_OPERATOR, 56, 2),
]);
}
test_method_extension_prefixed() async {
newFile('$testPackageLibPath/a.dart', r'''
extension E on int {
static void foo() {}
}
''');
await assertErrorsInCode('''
import 'a.dart' as prefix;
f() {
prefix.E?.foo();
}
''', [
error(StaticWarningCode.INVALID_NULL_AWARE_OPERATOR, 44, 2),
]);
}
test_method_legacy() async {
@@ -345,7 +391,7 @@ f() {
}
test_method_mixin() async {
await assertNoErrorsInCode('''
await assertErrorsInCode('''
mixin M {
static void foo() {}
}
@@ -353,7 +399,27 @@ mixin M {
f() {
M?.foo();
}
''', [
error(StaticWarningCode.INVALID_NULL_AWARE_OPERATOR, 45, 2),
]);
}
test_method_mixin_prefixed() async {
newFile('$testPackageLibPath/a.dart', r'''
mixin M {
static void foo() {}
}
''');
await assertErrorsInCode('''
import 'a.dart' as prefix;
f() {
prefix.M?.foo();
}
''', [
error(StaticWarningCode.INVALID_NULL_AWARE_OPERATOR, 44, 2),
]);
}
test_method_nonNullable() async {
@@ -377,6 +443,22 @@ f(int? x) {
''');
}
test_method_typeAlias_class() async {
await assertErrorsInCode('''
class A {
static void foo() {}
}
typedef B = A;
f() {
B?.foo();
}
''', [
error(StaticWarningCode.INVALID_NULL_AWARE_OPERATOR, 62, 2),
]);
}
test_nonNullableSpread_nullableType() async {
await assertNoErrorsInCode('''
f(List<int> x) {
@@ -421,7 +503,7 @@ f(List<int>? x) {
}
test_setter_class() async {
await assertNoErrorsInCode('''
await assertErrorsInCode('''
class C {
static int x = 0;
}
@@ -429,11 +511,13 @@ class C {
f() {
C?.x = 0;
}
''');
''', [
error(StaticWarningCode.INVALID_NULL_AWARE_OPERATOR, 42, 2),
]);
}
test_setter_extension() async {
await assertNoErrorsInCode('''
await assertErrorsInCode('''
extension E on int {
static int x = 0;
}
@@ -441,11 +525,13 @@ extension E on int {
f() {
E?.x = 0;
}
''');
''', [
error(StaticWarningCode.INVALID_NULL_AWARE_OPERATOR, 53, 2),
]);
}
test_setter_mixin() async {
await assertNoErrorsInCode('''
await assertErrorsInCode('''
mixin M {
static int x = 0;
}
@@ -453,7 +539,9 @@ mixin M {
f() {
M?.x = 0;
}
''');
''', [
error(StaticWarningCode.INVALID_NULL_AWARE_OPERATOR, 42, 2),
]);
}
/// Here we test that analysis does not crash while checking whether to
@@ -479,15 +479,18 @@ main() {
]);
}
test_static_conditionalAcces_defined() async {
// The conditional access operator '?.' can be used to access static
// fields.
await assertNoErrorsInCode('''
test_static_conditionalAccess_defined() async {
await assertErrorsInCode(
'''
class A {
static var x;
}
var a = A?.x;
''');
''',
expectedErrorsByNullability(nullable: [
error(StaticWarningCode.INVALID_NULL_AWARE_OPERATOR, 37, 2),
], legacy: []),
);
}
test_static_definedInSuperclass() async {
@@ -527,14 +530,18 @@ main() {
}
test_typeLiteral_conditionalAccess() async {
// When applied to a type literal, the conditional access operator '?.'
// cannot be used to access instance getters of Type.
await assertErrorsInCode('''
await assertErrorsInCode(
'''
class A {}
f() => A?.hashCode;
''', [
error(CompileTimeErrorCode.UNDEFINED_GETTER, 21, 8),
]);
''',
expectedErrorsByNullability(nullable: [
error(StaticWarningCode.INVALID_NULL_AWARE_OPERATOR, 19, 2),
error(CompileTimeErrorCode.UNDEFINED_GETTER, 21, 8),
], legacy: [
error(CompileTimeErrorCode.UNDEFINED_GETTER, 21, 8),
]),
);
}
test_typeSubstitution_defined() async {
@@ -228,14 +228,14 @@ main() {
}
test_static_conditionalAccess_defined() async {
// The conditional access operator '?.' can be used to access static
// methods.
await assertNoErrorsInCode('''
await assertErrorsInCode('''
class A {
static void m() {}
}
f() { A?.m(); }
''');
''', [
error(StaticWarningCode.INVALID_NULL_AWARE_OPERATOR, 40, 2),
]);
}
test_static_mixinApplication_superConstructorIsFactory() async {
@@ -212,14 +212,17 @@ f(var a) {
}
test_static_conditionalAccess_defined() async {
// The conditional access operator '?.' can be used to access static
// fields.
await assertNoErrorsInCode('''
await assertErrorsInCode(
'''
class A {
static var x;
}
f() { A?.x = 1; }
''');
''',
expectedErrorsByNullability(nullable: [
error(StaticWarningCode.INVALID_NULL_AWARE_OPERATOR, 35, 2),
], legacy: []),
);
}
test_static_definedInSuperclass() async {
@@ -204,6 +204,9 @@ main() {
yGetValue = 1;
check(1, () => C?.x ??= y, ['C.x', 'y', 'C.x=1']);
// ^
// [cfe] The class 'C' cannot be null.
// ^^
// [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
}
@@ -206,4 +206,8 @@ main() {
yGetValue = 1;
check(1, () => h.C?.x ??= y, ['h.C.x', 'y', 'h.C.x=1']);
// ^
// [cfe] The class 'C' cannot be null.
// ^^
// [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
}
@@ -257,6 +257,8 @@ main() {
// C?.v ??= e2 is equivalent to C.v ??= e2.
C.xGetValue = 1;
check(1, () => C?.x ??= bad(), ['C.x']);
// ^^
// [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
// ^
// [cfe] The class 'C' cannot be null.
h.C.xgetValue = 1;
@@ -269,10 +271,14 @@ main() {
// [cfe] Undefined name 'c'.
yGetValue = 1;
check(1, () => C?.x ??= y, ['C.x', 'y', 'C.x=1']);
// ^^
// [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
// ^
// [cfe] The class 'C' cannot be null.
yGetValue = 1;
check(1, () => h.C?.x ??= y, ['h.C.x', 'y', 'h.C.x=1']);
// ^^
// [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
// ^
// [cfe] The class 'C' cannot be null.
}
@@ -227,7 +227,8 @@ int? ifNullAssignNullAwareField(C? c, int f()) {
}
int ifNullAssignNullAwareStatic(int f()) {
return C?.staticField ??= f(); // ignore: dead_null_aware_expression
// ignore: dead_null_aware_expression, invalid_null_aware_operator
return C?.staticField ??= f();
}
void unnecessaryNullAwareAccess(int f()) {
@@ -28,9 +28,17 @@ main() {
// C?.id is equivalent to C.id.
C.staticInt = 1;
Expect.equals(1, C?.staticInt);
// ^
// [cfe] The class 'C' cannot be null.
// ^^
// [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
h.C.staticInt = 1;
Expect.equals(1, h.C?.staticInt);
// ^
// [cfe] The class 'C' cannot be null.
// ^^
// [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
// The static type of e1?.id is the static type of e1.id.
{
@@ -41,12 +49,20 @@ main() {
{
C.staticInt = 1;
int? i = C?.staticInt;
// ^
// [cfe] The class 'C' cannot be null.
// ^^
// [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
Expect.equals(1, i);
}
{
h.C.staticInt = 1;
int? i = h.C?.staticInt;
// ^
// [cfe] The class 'C' cannot be null.
// ^^
// [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
Expect.equals(1, i);
}
}
@@ -35,6 +35,8 @@ main() {
{
C.staticInt = 1;
Expect.equals(1, C?.staticInt);
// ^^
// [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
// ^
// [cfe] The class 'C' cannot be null.
}
@@ -43,6 +45,8 @@ main() {
Expect.equals(1, h.C?.staticInt);
// ^
// [cfe] The class 'C' cannot be null.
// ^^
// [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
}
// The static type of e1?.d is the static type of e1.id.
@@ -70,6 +74,8 @@ main() {
int? i = C?.staticInt;
// ^
// [cfe] The class 'C' cannot be null.
// ^^
// [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
Expect.equals(1, i);
}
{
@@ -77,6 +83,8 @@ main() {
int? i = h.C?.staticInt;
// ^
// [cfe] The class 'C' cannot be null.
// ^^
// [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
Expect.equals(1, i);
}
{
@@ -87,6 +95,8 @@ main() {
// [cfe] The class 'C' cannot be null.
// ^
// [cfe] A value of type 'int?' can't be assigned to a variable of type 'String?'.
// ^^
// [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
Expect.equals(null, s);
}
{
@@ -94,6 +104,8 @@ main() {
String? s = h.C?.staticNullable;
// ^^^^^^^^^^^^^^^^^^^
// [analyzer] COMPILE_TIME_ERROR.INVALID_ASSIGNMENT
// ^^
// [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
// ^
// [cfe] The class 'C' cannot be null.
// ^
@@ -125,10 +137,14 @@ main() {
// Nor can it be used to access the hashCode getter on the class Type.
Expect.throwsNoSuchMethodError(() => C?.hashCode);
// ^^
// [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
// ^^^^^^^^
// [analyzer] COMPILE_TIME_ERROR.UNDEFINED_GETTER
// [cfe] Member not found: 'hashCode'.
Expect.throwsNoSuchMethodError(() => h.C?.hashCode);
// ^^
// [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
// ^^^^^^^^
// [analyzer] COMPILE_TIME_ERROR.UNDEFINED_GETTER
// [cfe] Member not found: 'hashCode'.
@@ -52,10 +52,18 @@ main() {
// C?.v = e2 is equivalent to C.v = e2.
C.staticInt = 1;
Expect.equals(2, C?.staticInt = 2);
// ^
// [cfe] The class 'C' cannot be null.
// ^^
// [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
Expect.equals(2, C.staticInt);
h.C.staticInt = 1;
Expect.equals(2, h.C?.staticInt = 2);
// ^
// [cfe] The class 'C' cannot be null.
// ^^
// [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
Expect.equals(2, h.C.staticInt);
// The static type of e1?.v = e2 is the static type of e2.
@@ -70,12 +78,20 @@ main() {
D.staticE = new E();
G g = new G();
F? f = (D?.staticE = g);
// ^
// [cfe] The class 'D' cannot be null.
// ^^
// [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
Expect.identical(f, g);
}
h.D.staticE = new h.E();
h.G g = new h.G();
h.F? f = (h.D?.staticE = g);
// ^
// [cfe] The class 'D' cannot be null.
// ^^
// [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
Expect.identical(f, g);
// Exactly the same errors that would be caused by e1.v = e2 are
@@ -92,7 +108,15 @@ main() {
// C?.v op= e2 is equivalent to C.v op= e2.
C.staticInt = 1;
Expect.equals(3, C?.staticInt += 2);
// ^
// [cfe] The class 'C' cannot be null.
// ^^
// [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
Expect.equals(3, C?.staticInt);
// ^
// [cfe] The class 'C' cannot be null.
// ^^
// [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
// The static type of e1?.v op= e2 is the static type of e1.v op e2.
{
@@ -104,12 +128,20 @@ main() {
{
D.staticE = new E();
F? f = (D?.staticE += 1);
// ^
// [cfe] The class 'D' cannot be null.
// ^^
// [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
Expect.identical(D.staticE, f);
}
{
h.D.staticE = new h.E();
h.F? f = (h.D?.staticE += 1);
// ^
// [cfe] The class 'D' cannot be null.
// ^^
// [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
Expect.identical(h.D.staticE, f);
}
}
@@ -64,6 +64,8 @@ main() {
Expect.equals(2, C?.staticInt = 2);
// ^
// [cfe] The class 'C' cannot be null.
// ^^
// [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
Expect.equals(2, C.staticInt);
}
{
@@ -71,6 +73,8 @@ main() {
Expect.equals(2, h.C?.staticInt = 2);
// ^
// [cfe] The class 'C' cannot be null.
// ^^
// [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
Expect.equals(2, h.C.staticInt);
}
@@ -95,6 +99,8 @@ main() {
F? f = (D?.staticE = g);
// ^
// [cfe] The class 'D' cannot be null.
// ^^
// [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
Expect.identical(f, g);
}
{
@@ -103,6 +109,8 @@ main() {
h.F? f = (h.D?.staticE = g);
// ^
// [cfe] The class 'D' cannot be null.
// ^^
// [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
Expect.identical(f, g);
}
{
@@ -112,6 +120,8 @@ main() {
// ^^^^^^^^^^^^^^
// [analyzer] COMPILE_TIME_ERROR.INVALID_ASSIGNMENT
// [cfe] The class 'D' cannot be null.
// ^^
// [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
// ^
// [cfe] A value of type 'E' can't be assigned to a variable of type 'F?'.
}
@@ -123,6 +133,8 @@ main() {
// [analyzer] COMPILE_TIME_ERROR.INVALID_ASSIGNMENT
// ^
// [cfe] The class 'D' cannot be null.
// ^^
// [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
// ^
// [cfe] A value of type 'E' can't be assigned to a variable of type 'F'.
}
@@ -163,9 +175,13 @@ main() {
Expect.equals(3, C?.staticInt += 2);
// ^
// [cfe] The class 'C' cannot be null.
// ^^
// [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
Expect.equals(3, C?.staticInt);
// ^
// [cfe] The class 'C' cannot be null.
// ^^
// [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
}
// The static type of e1?.v op= e2 is the static type of e1.v op e2.
@@ -183,6 +199,8 @@ main() {
F? f = (D?.staticE += 1);
// ^
// [cfe] The class 'D' cannot be null.
// ^^
// [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
Expect.identical(D.staticE, f);
}
{
@@ -190,6 +208,8 @@ main() {
h.F? f = (h.D?.staticE += 1);
// ^
// [cfe] The class 'D' cannot be null.
// ^^
// [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
Expect.identical(h.D.staticE, f);
}
@@ -239,6 +259,8 @@ main() {
F? f = (D?.staticE += nullC());
// ^
// [cfe] The class 'D' cannot be null.
// ^^
// [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
// ^^^^^^^
// [analyzer] COMPILE_TIME_ERROR.ARGUMENT_TYPE_NOT_ASSIGNABLE
// [cfe] A value of type 'C?' can't be assigned to a variable of type 'int'.
@@ -248,6 +270,8 @@ main() {
h.F? f = (h.D?.staticE += h.nullC());
// ^
// [cfe] The class 'D' cannot be null.
// ^^
// [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
// ^^^^^^^^^
// [analyzer] COMPILE_TIME_ERROR.ARGUMENT_TYPE_NOT_ASSIGNABLE
// ^
@@ -259,6 +283,8 @@ main() {
// ^^^^^^^^^^^^^^^
// [analyzer] COMPILE_TIME_ERROR.INVALID_ASSIGNMENT
// [cfe] The class 'D' cannot be null.
// ^^
// [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
// ^
// [cfe] A value of type 'G' can't be assigned to a variable of type 'H?'.
}
@@ -269,6 +295,8 @@ main() {
// [analyzer] COMPILE_TIME_ERROR.INVALID_ASSIGNMENT
// ^
// [cfe] The class 'D' cannot be null.
// ^^
// [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
// ^
// [cfe] A value of type 'G' can't be assigned to a variable of type 'H?'.
}
@@ -55,11 +55,19 @@ main() {
{
C.staticInt = 1;
Expect.equals(1, C?.staticInt++);
// ^
// [cfe] The class 'C' cannot be null.
// ^^
// [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
Expect.equals(2, C.staticInt);
}
{
h.C.staticInt = 1;
Expect.equals(1, h.C?.staticInt++);
// ^
// [cfe] The class 'C' cannot be null.
// ^^
// [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
Expect.equals(2, h.C.staticInt);
}
@@ -75,12 +83,20 @@ main() {
E e1 = new E();
D.staticE = e1;
E? e2 = D?.staticE++;
// ^
// [cfe] The class 'D' cannot be null.
// ^^
// [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
Expect.identical(e1, e2);
}
{
h.E e1 = new h.E();
h.D.staticE = e1;
h.E? e2 = h.D?.staticE++;
// ^
// [cfe] The class 'D' cannot be null.
// ^^
// [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
Expect.identical(e1, e2);
}
@@ -96,11 +112,19 @@ main() {
{
C.staticInt = 1;
Expect.equals(1, C?.staticInt--);
// ^
// [cfe] The class 'C' cannot be null.
// ^^
// [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
Expect.equals(0, C.staticInt);
}
{
h.C.staticInt = 1;
Expect.equals(1, h.C?.staticInt--);
// ^
// [cfe] The class 'C' cannot be null.
// ^^
// [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
Expect.equals(0, h.C.staticInt);
}
@@ -116,12 +140,20 @@ main() {
E e1 = new E();
D.staticE = e1;
E? e2 = D?.staticE--;
// ^
// [cfe] The class 'D' cannot be null.
// ^^
// [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
Expect.identical(e1, e2);
}
{
h.E e1 = new h.E();
h.D.staticE = e1;
h.E? e2 = h.D?.staticE--;
// ^
// [cfe] The class 'D' cannot be null.
// ^^
// [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
Expect.identical(e1, e2);
}
@@ -137,11 +169,19 @@ main() {
{
C.staticInt = 1;
Expect.equals(2, ++C?.staticInt);
// ^
// [cfe] The class 'C' cannot be null.
// ^^
// [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
Expect.equals(2, C.staticInt);
}
{
h.C.staticInt = 1;
Expect.equals(2, ++h.C?.staticInt);
// ^
// [cfe] The class 'C' cannot be null.
// ^^
// [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
Expect.equals(2, h.C.staticInt);
}
@@ -160,6 +200,10 @@ main() {
{
h.D.staticE = new h.E();
h.F? f = ++h.D?.staticE;
// ^
// [cfe] The class 'D' cannot be null.
// ^^
// [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
Expect.identical(h.D.staticE, f);
}
@@ -175,11 +219,19 @@ main() {
{
C.staticInt = 1;
Expect.equals(0, --C?.staticInt);
// ^
// [cfe] The class 'C' cannot be null.
// ^^
// [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
Expect.equals(0, C.staticInt);
}
{
h.C.staticInt = 1;
Expect.equals(0, --h.C?.staticInt);
// ^
// [cfe] The class 'C' cannot be null.
// ^^
// [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
Expect.equals(0, h.C.staticInt);
}
@@ -193,12 +245,20 @@ main() {
{
D.staticE = new E();
F? f = --D?.staticE;
// ^
// [cfe] The class 'D' cannot be null.
// ^^
// [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
Expect.identical(D.staticE, f);
}
{
h.D.staticE = new h.E();
h.F? f = --h.D?.staticE;
// ^
// [cfe] The class 'D' cannot be null.
// ^^
// [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
Expect.identical(h.D.staticE, f);
}
}
@@ -54,6 +54,8 @@ main() {
Expect.equals(1, C?.staticInt++);
// ^
// [cfe] The class 'C' cannot be null.
// ^^
// [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
Expect.equals(2, C.staticInt);
}
{
@@ -61,6 +63,8 @@ main() {
Expect.equals(1, h.C?.staticInt++);
// ^
// [cfe] The class 'C' cannot be null.
// ^^
// [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
Expect.equals(2, h.C.staticInt);
}
@@ -86,6 +90,8 @@ main() {
E? e2 = D?.staticE++;
// ^
// [cfe] The class 'D' cannot be null.
// ^^
// [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
Expect.identical(e1, e2);
}
{
@@ -94,6 +100,8 @@ main() {
h.E? e2 = h.D?.staticE++;
// ^
// [cfe] The class 'D' cannot be null.
// ^^
// [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
Expect.identical(e1, e2);
}
{
@@ -103,6 +111,8 @@ main() {
// ^^^^^^^^^^^^
// [analyzer] COMPILE_TIME_ERROR.INVALID_ASSIGNMENT
// [cfe] The class 'D' cannot be null.
// ^^
// [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
// ^
// [cfe] A value of type 'E' can't be assigned to a variable of type 'F?'.
Expect.identical(f, g);
@@ -115,6 +125,8 @@ main() {
// [analyzer] COMPILE_TIME_ERROR.INVALID_ASSIGNMENT
// ^
// [cfe] The class 'D' cannot be null.
// ^^
// [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
// ^
// [cfe] A value of type 'E' can't be assigned to a variable of type 'F?'.
Expect.identical(f, g);
@@ -134,6 +146,8 @@ main() {
Expect.equals(1, C?.staticInt--);
// ^
// [cfe] The class 'C' cannot be null.
// ^^
// [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
Expect.equals(0, C.staticInt);
}
{
@@ -141,6 +155,8 @@ main() {
Expect.equals(1, h.C?.staticInt--);
// ^
// [cfe] The class 'C' cannot be null.
// ^^
// [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
Expect.equals(0, h.C.staticInt);
}
@@ -166,6 +182,8 @@ main() {
E? e2 = D?.staticE--;
// ^
// [cfe] The class 'D' cannot be null.
// ^^
// [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
Expect.identical(e1, e2);
}
{
@@ -174,6 +192,8 @@ main() {
h.E? e2 = h.D?.staticE--;
// ^
// [cfe] The class 'D' cannot be null.
// ^^
// [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
Expect.identical(e1, e2);
}
{
@@ -183,6 +203,8 @@ main() {
// ^^^^^^^^^^^^
// [analyzer] COMPILE_TIME_ERROR.INVALID_ASSIGNMENT
// [cfe] The class 'D' cannot be null.
// ^^
// [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
// ^
// [cfe] A value of type 'E' can't be assigned to a variable of type 'F?'.
Expect.identical(f, g);
@@ -195,6 +217,8 @@ main() {
// [analyzer] COMPILE_TIME_ERROR.INVALID_ASSIGNMENT
// ^
// [cfe] The class 'D' cannot be null.
// ^^
// [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
// ^
// [cfe] A value of type 'E' can't be assigned to a variable of type 'F?'.
Expect.identical(f, g);
@@ -214,6 +238,8 @@ main() {
Expect.equals(2, ++C?.staticInt);
// ^
// [cfe] The class 'C' cannot be null.
// ^^
// [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
Expect.equals(2, C.staticInt);
}
{
@@ -221,6 +247,8 @@ main() {
Expect.equals(2, ++h.C?.staticInt);
// ^
// [cfe] The class 'C' cannot be null.
// ^^
// [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
Expect.equals(2, h.C.staticInt);
}
@@ -244,6 +272,8 @@ main() {
F? f = ++D?.staticE;
// ^
// [cfe] The class 'D' cannot be null.
// ^^
// [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
Expect.identical(D.staticE, f);
}
{
@@ -251,6 +281,8 @@ main() {
h.F? f = ++h.D?.staticE;
// ^
// [cfe] The class 'D' cannot be null.
// ^^
// [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
Expect.identical(h.D.staticE, f);
}
{
@@ -260,6 +292,8 @@ main() {
// [analyzer] COMPILE_TIME_ERROR.INVALID_ASSIGNMENT
// ^
// [cfe] The class 'D' cannot be null.
// ^^
// [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
// ^
// [cfe] A value of type 'G' can't be assigned to a variable of type 'H?'.
Expect.identical(D.staticE, h);
@@ -271,6 +305,8 @@ main() {
// [analyzer] COMPILE_TIME_ERROR.INVALID_ASSIGNMENT
// ^
// [cfe] The class 'D' cannot be null.
// ^^
// [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
// ^
// [cfe] A value of type 'G' can't be assigned to a variable of type 'H?'.
Expect.identical(h.D.staticE, hh);
@@ -290,6 +326,8 @@ main() {
Expect.equals(0, --C?.staticInt);
// ^
// [cfe] The class 'C' cannot be null.
// ^^
// [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
Expect.equals(0, C.staticInt);
}
{
@@ -297,6 +335,8 @@ main() {
Expect.equals(0, --h.C?.staticInt);
// ^
// [cfe] The class 'C' cannot be null.
// ^^
// [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
Expect.equals(0, h.C.staticInt);
}
@@ -320,6 +360,8 @@ main() {
F? f = --D?.staticE;
// ^
// [cfe] The class 'D' cannot be null.
// ^^
// [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
Expect.identical(D.staticE, f);
}
{
@@ -327,6 +369,8 @@ main() {
h.F? f = --h.D?.staticE;
// ^
// [cfe] The class 'D' cannot be null.
// ^^
// [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
Expect.identical(h.D.staticE, f);
}
{
@@ -336,6 +380,8 @@ main() {
// [analyzer] COMPILE_TIME_ERROR.INVALID_ASSIGNMENT
// ^
// [cfe] The class 'D' cannot be null.
// ^^
// [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
// ^
// [cfe] A value of type 'G' can't be assigned to a variable of type 'H?'.
Expect.identical(D.staticE, h);
@@ -347,6 +393,8 @@ main() {
// [analyzer] COMPILE_TIME_ERROR.INVALID_ASSIGNMENT
// ^
// [cfe] The class 'D' cannot be null.
// ^^
// [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
// ^
// [cfe] A value of type 'G' can't be assigned to a variable of type 'H?'.
Expect.identical(h.D.staticE, hh);
@@ -32,7 +32,11 @@ main() {
Expect.equals(1, c?.f(() => 1));
// C?.m(...) is equivalent to C.m(...).
Expect.equals(1, C?.staticF(() => 1));
// ^^
// [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
Expect.equals(1, h.C?.staticF(() => 1));
// ^^
// [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
// The static type of o?.m(...) is the same as the static type of
// o.m(...).
@@ -46,10 +50,14 @@ main() {
}
{
int? i = C?.staticG(() => 1);
// ^^
// [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
Expect.equals(1, i);
}
{
int? i = h.C?.staticG(() => 1);
// ^^
// [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
Expect.equals(1, i);
}
}
@@ -35,7 +35,11 @@ main() {
// C?.m(...) is equivalent to C.m(...).
Expect.equals(1, C?.staticF(() => 1));
// ^^
// [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
Expect.equals(1, h.C?.staticF(() => 1));
// ^^
// [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
// The static type of o?.m(...) is the same as the static type of
// o.m(...).
@@ -51,15 +55,23 @@ main() {
// ^
// [cfe] A value of type 'int?' can't be assigned to a variable of type 'String?'.
{ int? i = C?.staticG(() => 1); Expect.equals(1, i); }
// ^^
// [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
{ int? i = h.C?.staticG(() => 1); Expect.equals(1, i); }
// ^^
// [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
{ String? s = C?.staticG(() => null); Expect.equals(null, s); }
// ^^^^^^^^^^^^^^^^^^^^^^
// [analyzer] COMPILE_TIME_ERROR.INVALID_ASSIGNMENT
// ^^
// [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
// ^
// [cfe] A value of type 'int?' can't be assigned to a variable of type 'String?'.
{ String? s = h.C?.staticG(() => null); Expect.equals(null, s); }
// ^^^^^^^^^^^^^^^^^^^^^^^^
// [analyzer] COMPILE_TIME_ERROR.INVALID_ASSIGNMENT
// ^^
// [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
// ^
// [cfe] A value of type 'int?' can't be assigned to a variable of type 'String?'.
@@ -84,10 +96,14 @@ main() {
// Nor can it be used to access the toString method on the class Type.
Expect.throwsNoSuchMethodError(() => C?.toString());
// ^^
// [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
// ^^^^^^^^
// [analyzer] COMPILE_TIME_ERROR.UNDEFINED_METHOD
// [cfe] Method not found: 'C.toString'.
Expect.throwsNoSuchMethodError(() => h.C?.toString());
// ^^
// [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
// ^^^^^^^^
// [analyzer] COMPILE_TIME_ERROR.UNDEFINED_METHOD
// [cfe] Method not found: 'C.toString'.