Skip to content

Commit

Permalink
Fixes #1398. Fix tests that use unreachable code after Never (#1402)
Browse files Browse the repository at this point in the history
Authored by @sgrekhov.

Fix tests that use unreachable code after `Never`. Change testing members of Never.
  • Loading branch information
sgrekhov committed Sep 1, 2022
1 parent 10f2a33 commit efd1d26
Show file tree
Hide file tree
Showing 12 changed files with 144 additions and 125 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
16 changes: 8 additions & 8 deletions LanguageFeatures/nnbd/static_errors_A17_t01.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@
/// @issue 39866
// 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 (_) {}
}
20 changes: 10 additions & 10 deletions LanguageFeatures/nnbd/static_errors_A17_t02.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,22 @@
/// 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) {
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 (_) {}
}
36 changes: 18 additions & 18 deletions LanguageFeatures/nnbd/static_errors_A17_t03.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,41 +13,41 @@
/// @issue 39866
// Requirements=nnbd-strong
void test(var x) {
if (x is Never) {
x?.toString();
// ^^

Never foo() => throw Exception();

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

main() {
test(null);
} catch (_) {}
}
41 changes: 22 additions & 19 deletions LanguageFeatures/nnbd/static_errors_A17_t04.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,50 +7,53 @@
/// 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();
// ^^
Neverland foo() => throw Exception();

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

main() {
test(null);
} catch (_) {}
}
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
18 changes: 9 additions & 9 deletions LanguageFeatures/nnbd/weak/static_errors_A17_t01.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@
/// 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();
x.runtimeType;
x.s = 1;
}
}

Never foo() => throw Exception();

main() {
test(null);
try {
foo().toString();
foo().runtimeType;
foo().x;
foo().s = 1;
} catch (_) {}
}
20 changes: 10 additions & 10 deletions LanguageFeatures/nnbd/weak/static_errors_A17_t02.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,22 @@
/// 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) {
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 (_) {}
}

0 comments on commit efd1d26

Please sign in to comment.