Index: pkg/analyzer/test/src/task/strong/checker_test.dart |
diff --git a/pkg/analyzer/test/src/task/strong/checker_test.dart b/pkg/analyzer/test/src/task/strong/checker_test.dart |
index 2819766276cd08b015b0f8dcb115ae12739202b8..396748cd99fa607e72801dc3f1e4a97874e8dada 100644 |
--- a/pkg/analyzer/test/src/task/strong/checker_test.dart |
+++ b/pkg/analyzer/test/src/task/strong/checker_test.dart |
@@ -2196,11 +2196,96 @@ main() { |
'''); |
} |
- test_implicitCasts() async { |
- addFile('num n; int i = /*info:ASSIGNMENT_CAST*/n;'); |
+ test_implicitCasts_assignment() async { |
+ addFile( |
+ 'num n; int i; void main() { i = /*info:DOWN_CAST_IMPLICIT*/n;}//yy'); |
await check(); |
- addFile('num n; int i = /*error:INVALID_ASSIGNMENT*/n;'); |
- await check(implicitCasts: false); |
+ addFile( |
+ 'num n; int i; void main() { i = /*error:INVALID_ASSIGNMENT*/n;}//ny'); |
+ await check(implicitCasts: false, declarationCasts: true); |
+ addFile( |
+ 'num n; int i; void main() { i = /*info:DOWN_CAST_IMPLICIT*/n;}//yn'); |
+ await check(implicitCasts: true, declarationCasts: false); |
+ addFile( |
+ 'num n; int i; void main() { i = /*error:INVALID_ASSIGNMENT*/n;}//nn'); |
+ await check(implicitCasts: false, declarationCasts: false); |
+ } |
+ |
+ test_implicitCasts_compoundAssignment() async { |
+ addFile('''f(num n, int i) { |
+ /*info:DOWN_CAST_IMPLICIT_ASSIGN*/i += n;}//yy'''); |
+ await check(); |
+ addFile('''f(num n, int i) { |
+ i += /*error:INVALID_ASSIGNMENT*/n;}//ny'''); |
+ await check(implicitCasts: false, declarationCasts: true); |
+ addFile('''f(num n, int i) { |
+ /*info:DOWN_CAST_IMPLICIT_ASSIGN*/i += n;}//yn'''); |
+ await check(implicitCasts: true, declarationCasts: false); |
+ addFile('''f(num n, int i) { |
+ i += /*error:INVALID_ASSIGNMENT*/n;}//nn'''); |
+ await check(implicitCasts: false, declarationCasts: false); |
+ } |
+ |
+ test_implicitCasts_constructorInitializer() async { |
+ addFile( |
+ 'class A { int i; A(num n) : i = /*info:DOWN_CAST_IMPLICIT*/n;}//yy'); |
+ await check(); |
+ addFile( |
+ 'class A { int i; A(num n) : i = /*error:FIELD_INITIALIZER_NOT_ASSIGNABLE*/n;}//ny'); |
+ await check(implicitCasts: false, declarationCasts: true); |
+ addFile( |
+ 'class A { int i; A(num n) : i = /*info:DOWN_CAST_IMPLICIT*/n;}//yn'); |
+ await check(implicitCasts: true, declarationCasts: false); |
+ addFile( |
+ 'class A { int i; A(num n) : i = /*error:FIELD_INITIALIZER_NOT_ASSIGNABLE*/n;}//nn'); |
+ await check(implicitCasts: false, declarationCasts: false); |
+ } |
+ |
+ test_implicitCasts_defaultValue() async { |
+ addFile('''const num n = 0; |
+ f({int i = /*info:DOWN_CAST_IMPLICIT*/n}) => i;//yy'''); |
+ await check(); |
+ addFile('''const num n = 0; |
+ f({int i = /*error:INVALID_ASSIGNMENT*/n}) => i;//ny'''); |
+ await check(implicitCasts: false, declarationCasts: true); |
+ addFile('''const num n = 0; |
+ f({int i = /*info:DOWN_CAST_IMPLICIT*/n}) => i;//yn'''); |
+ await check(implicitCasts: true, declarationCasts: false); |
+ addFile('''const num n = 0; |
+ f({int i = /*error:INVALID_ASSIGNMENT*/n}) => i;//nn'''); |
+ await check(implicitCasts: false, declarationCasts: false); |
+ } |
+ |
+ test_implicitCasts_fieldInitializer() async { |
+ addFile('class A { static num n; int i = /*info:ASSIGNMENT_CAST*/n;}//yy'); |
+ await check(); |
+ addFile('class A { static num n; int i = /*info:ASSIGNMENT_CAST*/n;}//ny'); |
+ await check(implicitCasts: false, declarationCasts: true); |
+ addFile( |
+ 'class A { static num n; int i = /*error:INVALID_ASSIGNMENT*/n;}//yn'); |
+ await check(implicitCasts: true, declarationCasts: false); |
+ addFile( |
+ 'class A { static num n; int i = /*error:INVALID_ASSIGNMENT*/n;}//nn'); |
+ await check(implicitCasts: false, declarationCasts: false); |
+ } |
+ |
+ test_implicitCasts_functionCall() async { |
+ addFile('''num n; |
+ f(int i) => i; |
+ var i = f(/*info:DOWN_CAST_IMPLICIT*/n);//yy'''); |
+ await check(); |
+ addFile('''num n; |
+ f(int i) => i; |
+ var i = f(/*error:ARGUMENT_TYPE_NOT_ASSIGNABLE*/n);//ny'''); |
+ await check(implicitCasts: false, declarationCasts: true); |
+ addFile('''num n; |
+ f(int i) => i; |
+ var i = f(/*info:DOWN_CAST_IMPLICIT*/n);//yn'''); |
+ await check(implicitCasts: true, declarationCasts: false); |
+ addFile('''num n; |
+ f(int i) => i; |
+ var i = f(/*error:ARGUMENT_TYPE_NOT_ASSIGNABLE*/n);//nn'''); |
+ await check(implicitCasts: false, declarationCasts: false); |
} |
test_implicitCasts_genericMethods() async { |
@@ -2210,6 +2295,17 @@ var x = <String>[].map<String>((x) => ""); |
await check(implicitCasts: false); |
} |
+ test_implicitCasts_initializer() async { |
+ addFile('num n; int i = /*info:ASSIGNMENT_CAST*/n;//yy'); |
+ await check(); |
+ addFile('num n; int i = /*info:ASSIGNMENT_CAST*/n;//ny'); |
+ await check(implicitCasts: false, declarationCasts: true); |
+ addFile('num n; int i = /*error:INVALID_ASSIGNMENT*/n;//yn'); |
+ await check(implicitCasts: true, declarationCasts: false); |
+ addFile('num n; int i = /*error:INVALID_ASSIGNMENT*/n;//nn'); |
+ await check(implicitCasts: false, declarationCasts: false); |
+ } |
+ |
test_implicitCasts_numericOps() async { |
// Regression test for https://github.com/dart-lang/sdk/issues/26912 |
addFile(r''' |
@@ -2222,7 +2318,37 @@ void f() { |
await check(implicitCasts: false); |
} |
+ test_implicitCasts_operator() async { |
+ addFile('''num n; |
+ int i; |
+ var r = i & /*info:DOWN_CAST_IMPLICIT*/n;//yy'''); |
+ await check(); |
+ addFile('''num n; |
+ int i; |
+ var r = i & /*error:ARGUMENT_TYPE_NOT_ASSIGNABLE*/n;//ny'''); |
+ await check(implicitCasts: false, declarationCasts: true); |
+ addFile('''num n; |
+ int i; |
+ var r = i & /*info:DOWN_CAST_IMPLICIT*/n;//yn'''); |
+ await check(implicitCasts: true, declarationCasts: false); |
+ addFile('''num n; |
+ int i; |
+ var r = i & /*error:ARGUMENT_TYPE_NOT_ASSIGNABLE*/n;//nn'''); |
+ await check(implicitCasts: false, declarationCasts: false); |
+ } |
+ |
test_implicitCasts_return() async { |
+ addFile('int f(num n) => /*info:DOWN_CAST_IMPLICIT*/n;//yy'); |
+ await check(); |
+ addFile('int f(num n) => /*error:RETURN_OF_INVALID_TYPE*/n;//ny'); |
+ await check(implicitCasts: false, declarationCasts: true); |
+ addFile('int f(num n) => /*info:DOWN_CAST_IMPLICIT*/n;//yn'); |
+ await check(implicitCasts: true, declarationCasts: false); |
+ addFile('int f(num n) => /*error:RETURN_OF_INVALID_TYPE*/n;//nn'); |
+ await check(implicitCasts: false, declarationCasts: false); |
+ } |
+ |
+ test_implicitCasts_return_async() async { |
addFile(r''' |
import 'dart:async'; |