Skip to content

Commit

Permalink
Fixes dart-lang#1398. Fix tests that use unreachable code after Never
Browse files Browse the repository at this point in the history
  • Loading branch information
sgrekhov committed Aug 22, 2022
1 parent 08c8887 commit cd7f50a
Show file tree
Hide file tree
Showing 12 changed files with 47 additions and 117 deletions.
10 changes: 8 additions & 2 deletions LanguageFeatures/nnbd/expression_typing_A02_t01.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
/// type Never.
///
/// @description Checks that calling a method (including an operator) or getter
/// on a receiver of static type Never is treated by static analysis as producing
/// a result of type Never
/// on a receiver of static type [Never] is treated by static analysis as
/// producing a result of type [Never] (except members of [Object])
/// @issue 41273
/// @author sgrekhov@unipro.ru
Expand All @@ -17,7 +17,13 @@
void test(var x) {
if (x is Never) {
Never n1 = x.toString();
// ^^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
Never n2 = x.runtimeType;
// ^^^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
Never n3 = x.someGetter;
Never n4 = x.someMethod();
Never n5 = x + x;
Expand Down
9 changes: 6 additions & 3 deletions LanguageFeatures/nnbd/expression_typing_A03_t01.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

/// @assertion Tearing off a method from a receiver of static type Never produces
/// a value of type Never.
/// @assertion Tearing off a method from a receiver of static type[ Never]
/// produces a value of type [Never].
///
/// @description Checks that tearing off a method from a receiver of static type
/// Never produces a value of type Never.
/// [Never] produces a value of type [Never] (except members of [Object]).
/// @issue 41273
/// @author sgrekhov@unipro.ru
Expand All @@ -15,6 +15,9 @@
void test(var x) {
if (x is Never) {
Never n1 = x.toString;
// ^^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
Never n2 = x.someMethod;
}
}
Expand Down
1 change: 1 addition & 0 deletions LanguageFeatures/nnbd/static_errors_A17_t01.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
/// @issue 39866
// Requirements=nnbd-strong

void test(var x) {
if (x is Never) {
x.toString();
Expand Down
5 changes: 3 additions & 2 deletions LanguageFeatures/nnbd/static_errors_A17_t02.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@
/// 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 an error to call a method, setter, or getter on
/// a receiver of static type Never. Test type aliases
/// @description Check that it is not an error to call a method, setter, or
/// getter on a receiver of static type Never. Test type aliases
/// @author sgrekhov@unipro.ru
/// @issue 39866
// Requirements=nnbd-strong

typedef Neverland = Never;

void test(var x) {
Expand Down
27 changes: 2 additions & 25 deletions LanguageFeatures/nnbd/static_errors_A17_t03.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,44 +7,21 @@
/// 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 a warning to call a method, setter, or
/// @description Check that it is not an 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-strong

void test(var x) {
if (x is Never) {
x?.toString();
// ^^
// [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
// ^
// [cfe] Operand of null-aware operation '?.' has type 'Never' which excludes null.
x?.runtimeType;
// ^^
// [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
// ^
// [cfe] Operand of null-aware operation '?.' has type 'Never' which excludes null.
x?.s = 1;
// ^^
// [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
// ^
// [cfe] Operand of null-aware operation '?.' has type 'Never' which excludes null.
x?..toString();
// ^^^
// [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
// ^
// [cfe] Operand of null-aware operation '?..' has type 'Never' which excludes null.
x?..runtimeType;
// ^^^
// [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
// ^
// [cfe] Operand of null-aware operation '?..' has type 'Never' which excludes null.
x?..s = 1;
// ^^^
// [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
// ^
// [cfe] Operand of null-aware operation '?..' has type 'Never' which excludes null.
}
}

Expand Down
27 changes: 2 additions & 25 deletions LanguageFeatures/nnbd/static_errors_A17_t04.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,47 +7,24 @@
/// 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 a warning to call a method, setter, or
/// @description Check that it is not an error 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
/// @issue 39866
// Requirements=nnbd-strong

typedef Neverland = Never;

void test(var x) {
if (x is Neverland) {
x?.toString();
// ^^
// [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
// ^
// [cfe] Operand of null-aware operation '?.' has type 'Never' which excludes null.
x?.runtimeType;
// ^^
// [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
// ^
// [cfe] Operand of null-aware operation '?.' has type 'Never' which excludes null.
x?.s = 1;
// ^^
// [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
// ^
// [cfe] Operand of null-aware operation '?.' has type 'Never' which excludes null.
x?..toString();
// ^^^
// [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
// ^
// [cfe] Operand of null-aware operation '?..' has type 'Never' which excludes null.
x?..runtimeType;
// ^^^
// [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
// ^
// [cfe] Operand of null-aware operation '?..' has type 'Never' which excludes null.
x?..s = 1;
// ^^^
// [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
// ^
// [cfe] Operand of null-aware operation '?..' has type 'Never' which excludes null.
}
}

Expand Down
10 changes: 8 additions & 2 deletions LanguageFeatures/nnbd/weak/expression_typing_A02_t01.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
/// type Never.
///
/// @description Checks that calling a method (including an operator) or getter
/// on a receiver of static type Never is treated by static analysis as producing
/// a result of type Never
/// on a receiver of static type [Never] is treated by static analysis as
/// producing a result of type [Never] (except members of [Object]).
/// @issue 41273
/// @author sgrekhov@unipro.ru
Expand All @@ -17,7 +17,13 @@
void test(var x) {
if (x is Never) {
Never n1 = x.toString();
// ^^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
Never n2 = x.runtimeType;
// ^^^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
Never n3 = x.someGetter;
Never n4 = x.someMethod();
Never n5 = x + x;
Expand Down
9 changes: 6 additions & 3 deletions LanguageFeatures/nnbd/weak/expression_typing_A03_t01.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

/// @assertion Tearing off a method from a receiver of static type Never produces
/// a value of type Never.
/// @assertion Tearing off a method from a receiver of static type [Never]
/// produces a value of type [Never].
///
/// @description Checks that tearing off a method from a receiver of static type
/// Never produces a value of type Never.
/// [Never] produces a value of type [Never] (except members of [Object]).
/// @issue 41273
/// @author sgrekhov@unipro.ru
Expand All @@ -15,6 +15,9 @@
void test(var x) {
if (x is Never) {
Never n1 = x.toString;
// ^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
Never n2 = x.someMethod;
}
}
Expand Down
3 changes: 2 additions & 1 deletion LanguageFeatures/nnbd/weak/static_errors_A17_t01.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@
/// 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
/// getter on a receiver of static type Never.
/// getter on a receiver of static type [Never].
/// @author sgrekhov@unipro.ru
/// @issue 39866
// Requirements=nnbd-weak

void test(var x) {
if (x is Never) {
x.toString();
Expand Down
5 changes: 3 additions & 2 deletions LanguageFeatures/nnbd/weak/static_errors_A17_t02.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@
/// 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 an error to call a method, setter, or getter on
/// a receiver of static type Never. Test type aliases
/// @description Check that it is not an error to call a method, setter, or
/// getter on a receiver of static type [Never]. Test type aliases
/// @author sgrekhov@unipro.ru
/// @issue 39866
// Requirements=nnbd-weak

typedef Neverland = Never;

void test(var x) {
Expand Down
29 changes: 3 additions & 26 deletions LanguageFeatures/nnbd/weak/static_errors_A17_t03.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,44 +7,21 @@
/// 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 a warning to call a method, setter, or
/// getter on a receiver of static type Never via a null aware operator.
/// @description Check that it is not an 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();
// ^^
// [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
// ^
// [cfe] Operand of null-aware operation '?.' has type 'Never' which excludes null.
x?.runtimeType;
// ^^
// [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
// ^
// [cfe] Operand of null-aware operation '?.' has type 'Never' which excludes null.
x?.s = 1;
// ^^
// [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
// ^
// [cfe] Operand of null-aware operation '?.' has type 'Never' which excludes null.
x?..toString();
// ^^^
// [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
// ^
// [cfe] Operand of null-aware operation '?..' has type 'Never' which excludes null.
x?..runtimeType;
// ^^^
// [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
// ^
// [cfe] Operand of null-aware operation '?..' has type 'Never' which excludes null.
x?..s = 1;
// ^^^
// [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
// ^
// [cfe] Operand of null-aware operation '?..' has type 'Never' which excludes null.
}
}

Expand Down
29 changes: 3 additions & 26 deletions LanguageFeatures/nnbd/weak/static_errors_A17_t04.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,47 +7,24 @@
/// 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 a warning to call a method, setter, or
/// getter on a receiver of static type Never via a null aware operator. Test
/// @description Check that it is not an error 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
/// @issue 39866
// Requirements=nnbd-weak

typedef Neverland = Never;

void test(var x) {
if (x is Neverland) {
x?.toString();
// ^^
// [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
// ^
// [cfe] Operand of null-aware operation '?.' has type 'Never' which excludes null.
x?.runtimeType;
// ^^
// [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
// ^
// [cfe] Operand of null-aware operation '?.' has type 'Never' which excludes null.
x?.s = 1;
// ^^
// [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
// ^
// [cfe] Operand of null-aware operation '?.' has type 'Never' which excludes null.
x?..toString();
// ^^^
// [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
// ^
// [cfe] Operand of null-aware operation '?..' has type 'Never' which excludes null.
x?..runtimeType;
// ^^^
// [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
// ^
// [cfe] Operand of null-aware operation '?..' has type 'Never' which excludes null.
x?..s = 1;
// ^^^
// [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
// ^
// [cfe] Operand of null-aware operation '?..' has type 'Never' which excludes null.
}
}

Expand Down

0 comments on commit cd7f50a

Please sign in to comment.