OLD | NEW |
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 library analyzer.test.src.task.strong.checker_test; | 5 library analyzer.test.src.task.strong.checker_test; |
6 | 6 |
7 import 'package:test_reflective_loader/test_reflective_loader.dart'; | 7 import 'package:test_reflective_loader/test_reflective_loader.dart'; |
8 | 8 |
9 import 'strong_test_helper.dart'; | 9 import 'strong_test_helper.dart'; |
10 | 10 |
(...skipping 903 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
914 | 914 |
915 test_functionModifiers_async() async { | 915 test_functionModifiers_async() async { |
916 await checkFile(''' | 916 await checkFile(''' |
917 import 'dart:async'; | 917 import 'dart:async'; |
918 import 'dart:math' show Random; | 918 import 'dart:math' show Random; |
919 | 919 |
920 dynamic x; | 920 dynamic x; |
921 | 921 |
922 foo1() async => x; | 922 foo1() async => x; |
923 Future foo2() async => x; | 923 Future foo2() async => x; |
924 Future<int> foo3() async => x; | 924 Future<int> foo3() async => /*info:DYNAMIC_CAST*/x; |
925 Future<int> foo4() async => new Future<int>.value(x); | 925 Future<int> foo4() async => new Future<int>.value(x); |
926 Future<int> foo5() async => | 926 Future<int> foo5() async => |
927 /*error:RETURN_OF_INVALID_TYPE*/new Future<String>.value(x); | 927 /*error:RETURN_OF_INVALID_TYPE*/new Future<String>.value(x); |
928 | 928 |
929 bar1() async { return x; } | 929 bar1() async { return x; } |
930 Future bar2() async { return x; } | 930 Future bar2() async { return x; } |
931 Future<int> bar3() async { return x; } | 931 Future<int> bar3() async { return /*info:DYNAMIC_CAST*/x; } |
932 Future<int> bar4() async { return new Future<int>.value(x); } | 932 Future<int> bar4() async { return new Future<int>.value(x); } |
933 Future<int> bar5() async { | 933 Future<int> bar5() async { |
934 return /*error:RETURN_OF_INVALID_TYPE*/new Future<String>.value(x); | 934 return /*error:RETURN_OF_INVALID_TYPE*/new Future<String>.value(x); |
935 } | 935 } |
936 | 936 |
937 int y; | 937 int y; |
938 Future<int> z; | 938 Future<int> z; |
939 | 939 |
940 baz() async { | 940 baz() async { |
941 int a = /*info:DYNAMIC_CAST*/await x; | 941 int a = /*info:DYNAMIC_CAST*/await x; |
942 int b = await y; | 942 int b = await y; |
943 int c = await z; | 943 int c = await z; |
944 String d = /*error:INVALID_ASSIGNMENT*/await z; | 944 String d = /*error:INVALID_ASSIGNMENT*/await z; |
945 } | 945 } |
946 | 946 |
947 Future<bool> get issue_ddc_264 async { | 947 Future<bool> get issue_ddc_264 async { |
948 await 42; | 948 await 42; |
949 if (new Random().nextBool()) { | 949 if (new Random().nextBool()) { |
950 return true; | 950 return true; |
951 } else { | 951 } else { |
952 return new Future<bool>.value(false); | 952 return new Future<bool>.value(false); |
953 } | 953 } |
954 } | 954 } |
955 | 955 |
956 | 956 |
957 Future<String> issue_sdk_26404() async { | 957 Future<String> issue_sdk_26404() async { |
958 return (1 > 0) ? new Future<String>.value('hello') : "world"; | 958 return (/*info:DOWN_CAST_COMPOSITE*/(1 > 0) ? new Future<String>.value('hello'
) : "world"); |
959 } | 959 } |
960 '''); | 960 '''); |
961 } | 961 } |
962 | 962 |
963 test_functionModifiers_asyncStar() async { | 963 test_functionModifiers_asyncStar() async { |
964 await checkFile(''' | 964 await checkFile(''' |
965 import 'dart:async'; | 965 import 'dart:async'; |
966 | 966 |
967 dynamic x; | 967 dynamic x; |
968 | 968 |
(...skipping 1221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2190 for (;/*info:DYNAMIC_CAST*/dyn;) {} | 2190 for (;/*info:DYNAMIC_CAST*/dyn;) {} |
2191 for (;/*info:DOWN_CAST_IMPLICIT*/obj;) {} | 2191 for (;/*info:DOWN_CAST_IMPLICIT*/obj;) {} |
2192 for (;/*error:NON_BOOL_CONDITION*/i;) {} | 2192 for (;/*error:NON_BOOL_CONDITION*/i;) {} |
2193 } | 2193 } |
2194 '''); | 2194 '''); |
2195 } | 2195 } |
2196 | 2196 |
2197 test_implicitCasts() async { | 2197 test_implicitCasts() async { |
2198 addFile('num n; int i = /*info:ASSIGNMENT_CAST*/n;'); | 2198 addFile('num n; int i = /*info:ASSIGNMENT_CAST*/n;'); |
2199 await check(); | 2199 await check(); |
2200 // TODO(jmesserly): should not be emitting the hint as well as the error. | 2200 addFile('num n; int i = /*error:INVALID_ASSIGNMENT*/n;'); |
2201 // It is a "strong mode hint" however, so it will not be user visible. | |
2202 addFile( | |
2203 'num n; int i = /*info:ASSIGNMENT_CAST,error:INVALID_ASSIGNMENT*/n;'); | |
2204 await check(implicitCasts: false); | 2201 await check(implicitCasts: false); |
2205 } | 2202 } |
2206 | 2203 |
| 2204 test_implicitCasts_return() async { |
| 2205 addFile(r''' |
| 2206 import 'dart:async'; |
| 2207 |
| 2208 Future<List<String>> foo() async { |
| 2209 List<Object> x = <Object>["hello", "world"]; |
| 2210 return /*info:DOWN_CAST_IMPLICIT*/x; |
| 2211 } |
| 2212 '''); |
| 2213 await check(); |
| 2214 } |
| 2215 |
2207 test_implicitCasts_genericMethods() async { | 2216 test_implicitCasts_genericMethods() async { |
2208 addFile(''' | 2217 addFile(''' |
2209 var x = <String>[].map<String>((x) => ""); | 2218 var x = <String>[].map<String>((x) => ""); |
2210 '''); | 2219 '''); |
2211 await check(implicitCasts: false); | 2220 await check(implicitCasts: false); |
2212 } | 2221 } |
2213 | 2222 |
2214 test_implicitCasts_numericOps() async { | 2223 test_implicitCasts_numericOps() async { |
2215 // Regression test for https://github.com/dart-lang/sdk/issues/26912 | 2224 // Regression test for https://github.com/dart-lang/sdk/issues/26912 |
2216 addFile(r''' | 2225 addFile(r''' |
(...skipping 1925 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4142 class CheckerTest_Driver extends CheckerTest { | 4151 class CheckerTest_Driver extends CheckerTest { |
4143 @override | 4152 @override |
4144 bool get enableNewAnalysisDriver => true; | 4153 bool get enableNewAnalysisDriver => true; |
4145 | 4154 |
4146 @failingTest | 4155 @failingTest |
4147 @override | 4156 @override |
4148 test_covariantOverride_fields() async { | 4157 test_covariantOverride_fields() async { |
4149 await super.test_covariantOverride_fields(); | 4158 await super.test_covariantOverride_fields(); |
4150 } | 4159 } |
4151 } | 4160 } |
OLD | NEW |