Skip to content

#2979. Fix CFE failures in nnbd weak-mode tests #2988

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions LanguageFeatures/nnbd/static_errors_A33_t09.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ void foo() {}
main() {
FutureOr<Function> f = foo;
f!;
//^
// [cfe] Operand of null-aware operation '!' has type 'FutureOr<Function>' which excludes null.
// ^
// [analyzer] STATIC_WARNING.UNNECESSARY_NON_NULL_ASSERTION
}
13 changes: 3 additions & 10 deletions LanguageFeatures/nnbd/weak/null_aware_operator_A13_t13.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
/// @issue 40557

// Requirements=nnbd-weak

import "../../../Utils/expect.dart";

class C {
Expand All @@ -38,18 +39,10 @@ class C {
}

void testShort(C? x, int index, dynamic value) {
var actual = x?[index] ??= value;
// ^^^^^
// [analyzer] STATIC_WARNING.DEAD_NULL_AWARE_EXPRESSION
// ^
// [cfe] Operand of null-aware operation '??=' has type 'int' which excludes null.
var actual = x?[index] ??= value; // ignore: dead_null_aware_expression
var n0 = x;
x?.init();
var expected = n0 == null ? null : n0[index] ??= value;
// ^^^^^
// [analyzer] STATIC_WARNING.DEAD_NULL_AWARE_EXPRESSION
// ^
// [cfe] Operand of null-aware operation '??=' has type 'int' which excludes null.
var expected = n0 == null ? null : n0[index] ??= value; // ignore: dead_null_aware_expression
Expect.equals(expected, actual);
}

Expand Down
55 changes: 10 additions & 45 deletions LanguageFeatures/nnbd/weak/null_aware_operator_A17_t01.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
/// @issue 40959

// Requirements=nnbd-weak

import "../../../Utils/expect.dart";

class C {
Expand All @@ -35,29 +36,17 @@ class C {

main() {
C c1 = new C();
var actual1 = c1 ?.. test1;
// ^^^
// [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
// ^
// [cfe] Operand of null-aware operation '?..' has type 'C' which excludes null.
var actual1 = c1 ?.. test1; // ignore: invalid_null_aware_operator
var expected = c1;
Expect.equals(expected, actual1);
Expect.equals("test1 called 1 times, test2() called 0 times", c1.log);

var actual2 = c1 ?.. test2();
// ^^^
// [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
// ^
// [cfe] Operand of null-aware operation '?..' has type 'C' which excludes null.
var actual2 = c1 ?.. test2(); // ignore: invalid_null_aware_operator
Expect.equals(expected, actual2);
Expect.equals("test1 called 1 times, test2() called 1 times", c1.log);

var actual3 = c1
// ^
// [cfe] Operand of null-aware operation '?..' has type 'C' which excludes null.
?.. test1
// ^^^
// [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
?.. test1 // ignore: invalid_null_aware_operator
.. test2();
Expect.equals(expected, actual3);
Expect.equals("test1 called 2 times, test2() called 2 times", c1.log);
Expand All @@ -75,42 +64,18 @@ main() {
Expect.isNull(actual6);

c2 = new C();
var actual7 = c2 ?.. test1;
// ^^^
// [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
// ^
// [cfe] Operand of null-aware operation '?..' has type 'C' which excludes null.
var actual7 = c2 ?.. test1; // ignore: invalid_null_aware_operator
var expected2 = c2;
Expect.equals(expected2, actual7);
Expect.equals("test1 called 1 times, test2() called 0 times", c2?.log);
// ^^
// [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
// ^
// [cfe] Operand of null-aware operation '?.' has type 'C' which excludes null.
Expect.equals("test1 called 1 times, test2() called 0 times", c2?.log); // ignore: invalid_null_aware_operator

var actual8 = c2 ?.. test2();
// ^^^
// [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
// ^
// [cfe] Operand of null-aware operation '?..' has type 'C' which excludes null.
var actual8 = c2 ?.. test2(); // ignore: invalid_null_aware_operator
Expect.equals(expected2, actual8);
Expect.equals("test1 called 1 times, test2() called 1 times", c2?.log);
// ^^
// [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
// ^
// [cfe] Operand of null-aware operation '?.' has type 'C' which excludes null.
Expect.equals("test1 called 1 times, test2() called 1 times", c2?.log); // ignore: invalid_null_aware_operator

var actual9 = c2
// ^
// [cfe] Operand of null-aware operation '?..' has type 'C' which excludes null.
?.. test1
// ^^^
// [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
?.. test1 // ignore: invalid_null_aware_operator
.. test2();
Expect.equals(expected2, actual9);
Expect.equals("test1 called 2 times, test2() called 2 times", c2?.log);
// ^^
// [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
// ^
// [cfe] Operand of null-aware operation '?.' has type 'C' which excludes null.
Expect.equals("test1 called 2 times, test2() called 2 times", c2?.log); // ignore: invalid_null_aware_operator
}
117 changes: 21 additions & 96 deletions LanguageFeatures/nnbd/weak/null_aware_operator_A17_t02.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
/// @issue 39141

// Requirements=nnbd-weak

import '../../../Utils/expect.dart';

class C {
Expand All @@ -38,31 +39,17 @@ typedef CAlias2 = C?;

main() {
CAlias1 c1 = new C();
var actual1 = c1 ?.. test1;
// ^^^
// [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
// ^
// [cfe] Operand of null-aware operation '?..' has type 'C' which excludes null.

var actual1 = c1 ?.. test1; // ignore: invalid_null_aware_operator
var expected = c1;
Expect.equals(expected, actual1);
Expect.equals("test1 called 1 times, test2() called 0 times", c1.log);

var actual2 = c1 ?.. test2();
// ^^^
// [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
// ^
// [cfe] Operand of null-aware operation '?..' has type 'C' which excludes null.

var actual2 = c1 ?.. test2(); // ignore: invalid_null_aware_operator
Expect.equals(expected, actual2);
Expect.equals("test1 called 1 times, test2() called 1 times", c1.log);

var actual3 = c1
// ^
// [cfe] Operand of null-aware operation '?..' has type 'C' which excludes null.
?.. test1
// ^^^
// [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
?.. test1 // ignore: invalid_null_aware_operator
.. test2();
Expect.equals(expected, actual3);
Expect.equals("test1 called 2 times, test2() called 2 times", c1.log);
Expand All @@ -80,74 +67,37 @@ main() {
Expect.isNull(actual6);

c2 = new C();
var actual7 = c2 ?.. test1;
// ^^^
// [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
// ^
// [cfe] Operand of null-aware operation '?..' has type 'C' which excludes null.
var actual7 = c2 ?.. test1; // ignore: invalid_null_aware_operator
var expected2 = c2;
Expect.equals(expected2, actual7);
Expect.equals("test1 called 1 times, test2() called 0 times", c2?.log);
// ^^
// [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
// ^
// [cfe] Operand of null-aware operation '?.' has type 'C' which excludes null.

var actual8 = c2 ?.. test2();
// ^^^
// [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
// ^
// [cfe] Operand of null-aware operation '?..' has type 'C' which excludes null.
Expect.equals("test1 called 1 times, test2() called 0 times", c2?.log); // ignore: invalid_null_aware_operator

var actual8 = c2 ?.. test2(); // ignore: invalid_null_aware_operator
Expect.equals(expected2, actual8);
Expect.equals("test1 called 1 times, test2() called 1 times", c2?.log);
// ^^
// [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
// ^
// [cfe] Operand of null-aware operation '?.' has type 'C' which excludes null.
Expect.equals("test1 called 1 times, test2() called 1 times", c2?.log); // ignore: invalid_null_aware_operator

var actual9 = c2
// ^
// [cfe] Operand of null-aware operation '?..' has type 'C' which excludes null.
?.. test1
// ^^^
// [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
?.. test1 // ignore: invalid_null_aware_operator
.. test2();
Expect.equals(expected2, actual9);
Expect.equals("test1 called 2 times, test2() called 2 times", c2?.log);
// ^^
// [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
// ^
// [cfe] Operand of null-aware operation '?.' has type 'C' which excludes null.
Expect.equals("test1 called 2 times, test2() called 2 times", c2?.log); // ignore: invalid_null_aware_operator

CAlias2 c3 = new C();
var actual10 = c3 ?.. test1;
// ^^^
// [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
// ^
// [cfe] Operand of null-aware operation '?..' has type 'C' which excludes null.
var actual10 = c3 ?.. test1; // ignore: invalid_null_aware_operator
var expected3 = c3;
Expect.equals(expected3, actual10);
if (c3 != null) {
Expect.equals("test1 called 1 times, test2() called 0 times", c3.log);
}

var actual11 = c3 ?.. test2();
// ^^^
// [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
// ^
// [cfe] Operand of null-aware operation '?..' has type 'C' which excludes null.

var actual11 = c3 ?.. test2(); // ignore: invalid_null_aware_operator
Expect.equals(expected3, actual11);
if (c3 != null) {
Expect.equals("test1 called 1 times, test2() called 1 times", c3.log);
}

var actual12 = c3
// ^
// [cfe] Operand of null-aware operation '?..' has type 'C' which excludes null.
?.. test1
// ^^^
// [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR

?.. test1 // ignore: invalid_null_aware_operator
.. test2();
Expect.equals(expected3, actual12);
if (c3 != null) {
Expand All @@ -167,44 +117,19 @@ main() {
Expect.isNull(actual15);

c4 = new C();
var actual16 = c4 ?.. test1;
// ^^^
// [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
// ^
// [cfe] Operand of null-aware operation '?..' has type 'C' which excludes null.
var actual16 = c4 ?.. test1; // ignore: invalid_null_aware_operator

var expected4 = c4;
Expect.equals(expected4, actual16);
Expect.equals("test1 called 1 times, test2() called 0 times", c4?.log);
// ^^
// [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
// ^
// [cfe] Operand of null-aware operation '?.' has type 'C' which excludes null.

var actual17 = c4 ?.. test2();
// ^^^
// [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
// ^
// [cfe] Operand of null-aware operation '?..' has type 'C' which excludes null.
Expect.equals("test1 called 1 times, test2() called 0 times", c4?.log); // ignore: invalid_null_aware_operator

var actual17 = c4 ?.. test2(); // ignore: invalid_null_aware_operator
Expect.equals(expected4, actual17);
Expect.equals("test1 called 1 times, test2() called 1 times", c4?.log);
// ^^
// [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
// ^
// [cfe] Operand of null-aware operation '?.' has type 'C' which excludes null.
Expect.equals("test1 called 1 times, test2() called 1 times", c4?.log); // ignore: invalid_null_aware_operator

var actual18 = c4
// ^
// [cfe] Operand of null-aware operation '?..' has type 'C' which excludes null.
?.. test1
// ^^^
// [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
?.. test1 // ignore: invalid_null_aware_operator
.. test2();
Expect.equals(expected4, actual18);
Expect.equals("test1 called 2 times, test2() called 2 times", c4?.log);
// ^^
// [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
// ^
// [cfe] Operand of null-aware operation '?.' has type 'C' which excludes null.
Expect.equals("test1 called 2 times, test2() called 2 times", c4?.log); // ignore: invalid_null_aware_operator
}
Loading