Skip to content

Commit

Permalink
dart-lang#1398. Change testing members of Never
Browse files Browse the repository at this point in the history
  • Loading branch information
sgrekhov committed Sep 1, 2022
1 parent cd7f50a commit a6d8ea6
Show file tree
Hide file tree
Showing 8 changed files with 168 additions and 79 deletions.
15 changes: 7 additions & 8 deletions LanguageFeatures/nnbd/static_errors_A17_t01.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,13 @@
// Requirements=nnbd-strong

void test(var x) {
if (x is Never) {
x.toString();
x.runtimeType;
x.s = 1;
}
}
Never foo() => throw Exception();

main() {
test(null);
try {
foo().toString();
foo().runtimeType;
foo().x;
foo().s = 1;
} catch (_) {}
}
15 changes: 7 additions & 8 deletions LanguageFeatures/nnbd/static_errors_A17_t02.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,13 @@

typedef Neverland = Never;

void test(var x) {
if (x is Neverland) {
x.toString();
x.runtimeType;
x.s = 1;
}
}
Neverland foo() => throw Exception();

main() {
test(null);
try {
foo().toString();
foo().runtimeType;
foo().x;
foo().s = 1;
} catch (_) {}
}
47 changes: 35 additions & 12 deletions LanguageFeatures/nnbd/static_errors_A17_t03.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,47 @@
/// Implementations that provide feedback about dead or unreachable code are
/// encouraged to indicate that any arguments to the invocation are unreachable.
///
/// @description Check that it is not an error to call a method, setter, or
/// @description Check that it is a warning to call a method, setter, or
/// getter on a receiver of static type Never via a null aware operator.
/// @author sgrekhov@unipro.ru
/// @issue 39866
// Requirements=nnbd-strong

void test(var x) {
if (x is Never) {
x?.toString();
x?.runtimeType;
x?.s = 1;
x?..toString();
x?..runtimeType;
x?..s = 1;
}
}
Never foo() => throw Exception();

main() {
test(null);
try {
foo()?.toString();
// ^^
// [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
// ^
// [cfe] Operand of null-aware operation '?.' has type 'Never' which excludes null.
foo()?.runtimeType;
// ^^
// [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
// ^
// [cfe] Operand of null-aware operation '?.' has type 'Never' which excludes null.
foo()?.s = 1;
// ^^
// [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
// ^
// [cfe] Operand of null-aware operation '?.' has type 'Never' which excludes null.
foo()?..toString();
// ^^^
// [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
// ^
// [cfe] Operand of null-aware operation '?..' has type 'Never' which excludes null.
foo()?..runtimeType;
// ^^^
// [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
// ^
// [cfe] Operand of null-aware operation '?..' has type 'Never' which excludes null.
foo()?..s = 1;
// ^^^
// [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
// ^
// [cfe] Operand of null-aware operation '?..' has type 'Never' which excludes null.

} catch (_) {}
}
48 changes: 37 additions & 11 deletions LanguageFeatures/nnbd/static_errors_A17_t04.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,43 @@

typedef Neverland = Never;

void test(var x) {
if (x is Neverland) {
x?.toString();
x?.runtimeType;
x?.s = 1;
x?..toString();
x?..runtimeType;
x?..s = 1;
}
}
Neverland foo() => throw Exception();

main() {
test(null);
try {
foo()?.toString();
// ^^
// [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
// ^
// [cfe] Operand of null-aware operation '?.' has type 'Never' which excludes null.
foo()?.runtimeType;
// ^^
// [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
// ^
// [cfe] Operand of null-aware operation '?.' has type 'Never' which excludes null.
foo()?.s = 1;
// ^^
// [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
// ^
// [cfe] Operand of null-aware operation '?.' has type 'Never' which excludes null.
foo()
?..toString();
// ^^^
// [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
// ^
// [cfe] Operand of null-aware operation '?..' has type 'Never' which excludes null.
foo()
?..runtimeType;
// ^^^
// [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
// ^
// [cfe] Operand of null-aware operation '?..' has type 'Never' which excludes null.
foo()
?..s = 1;
// ^^^
// [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
// ^
// [cfe] Operand of null-aware operation '?..' has type 'Never' which excludes null.

} catch (_) {}
}
15 changes: 7 additions & 8 deletions LanguageFeatures/nnbd/weak/static_errors_A17_t01.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,13 @@
// Requirements=nnbd-weak

void test(var x) {
if (x is Never) {
x.toString();
x.runtimeType;
x.s = 1;
}
}
Never foo() => throw Exception();

main() {
test(null);
try {
foo().toString();
foo().runtimeType;
foo().x;
foo().s = 1;
} catch (_) {}
}
15 changes: 7 additions & 8 deletions LanguageFeatures/nnbd/weak/static_errors_A17_t02.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,13 @@

typedef Neverland = Never;

void test(var x) {
if (x is Neverland) {
x.toString();
x.runtimeType;
x.s = 1;
}
}
Neverland foo() => throw Exception();

main() {
test(null);
try {
foo().toString();
foo().runtimeType;
foo().x;
foo().s = 1;
} catch (_) {}
}
46 changes: 34 additions & 12 deletions LanguageFeatures/nnbd/weak/static_errors_A17_t03.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,46 @@
/// Implementations that provide feedback about dead or unreachable code are
/// encouraged to indicate that any arguments to the invocation are unreachable.
///
/// @description Check that it is not an error to call a method, setter, or
/// @description Check that it is a warning error to call a method, setter, or
/// getter on a receiver of static type [Never] via a null aware operator.
/// @author sgrekhov@unipro.ru
/// @issue 39866
// Requirements=nnbd-weak

void test(var x) {
if (x is Never) {
x?.toString();
x?.runtimeType;
x?.s = 1;
x?..toString();
x?..runtimeType;
x?..s = 1;
}
}
Never foo() => throw Exception();

main() {
test(null);
try {
foo()?.toString();
// ^^
// [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
// ^
// [cfe] Operand of null-aware operation '?.' has type 'Never' which excludes null.
foo()?.runtimeType;
// ^^
// [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
// ^
// [cfe] Operand of null-aware operation '?.' has type 'Never' which excludes null.
foo()?.s = 1;
// ^^
// [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
// ^
// [cfe] Operand of null-aware operation '?.' has type 'Never' which excludes null.
foo()?..toString();
// ^^^
// [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
// ^
// [cfe] Operand of null-aware operation '?..' has type 'Never' which excludes null.
foo()?..runtimeType;
// ^^^
// [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
// ^
// [cfe] Operand of null-aware operation '?..' has type 'Never' which excludes null.
foo()?..s = 1;
// ^^^
// [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
// ^
// [cfe] Operand of null-aware operation '?..' has type 'Never' which excludes null.
} catch (_) {}
}
46 changes: 34 additions & 12 deletions LanguageFeatures/nnbd/weak/static_errors_A17_t04.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
/// Implementations that provide feedback about dead or unreachable code are
/// encouraged to indicate that any arguments to the invocation are unreachable.
///
/// @description Check that it is not an error to call a method, setter, or
/// @description Check that it is a warning to call a method, setter, or
/// getter on a receiver of static type [Never] via a null aware operator. Test
/// type aliases
/// @author sgrekhov@unipro.ru
Expand All @@ -17,17 +17,39 @@

typedef Neverland = Never;

void test(var x) {
if (x is Neverland) {
x?.toString();
x?.runtimeType;
x?.s = 1;
x?..toString();
x?..runtimeType;
x?..s = 1;
}
}
Neverland foo() => throw Exception();

main() {
test(null);
try {
foo()?.toString();
// ^^
// [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
// ^
// [cfe] Operand of null-aware operation '?.' has type 'Never' which excludes null.
foo()?.runtimeType;
// ^^
// [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
// ^
// [cfe] Operand of null-aware operation '?.' has type 'Never' which excludes null.
foo()?.s = 1;
// ^^
// [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
// ^
// [cfe] Operand of null-aware operation '?.' has type 'Never' which excludes null.
foo()?..toString();
// ^^^
// [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
// ^
// [cfe] Operand of null-aware operation '?..' has type 'Never' which excludes null.
foo()?..runtimeType;
// ^^^
// [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
// ^
// [cfe] Operand of null-aware operation '?..' has type 'Never' which excludes null.
foo()?..s = 1;
// ^^^
// [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
// ^
// [cfe] Operand of null-aware operation '?..' has type 'Never' which excludes null.
} catch (_) {}
}

0 comments on commit a6d8ea6

Please sign in to comment.