| 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 '../../../reflective_tests.dart'; | 7 import 'package:test_reflective_loader/test_reflective_loader.dart'; |
| 8 |
| 8 import 'strong_test_helper.dart'; | 9 import 'strong_test_helper.dart'; |
| 9 | 10 |
| 10 void main() { | 11 void main() { |
| 11 initStrongModeTests(); | 12 initStrongModeTests(); |
| 12 runReflectiveTests(CheckerTest); | 13 defineReflectiveTests(CheckerTest); |
| 13 } | 14 } |
| 14 | 15 |
| 15 @reflectiveTest | 16 @reflectiveTest |
| 16 class CheckerTest { | 17 class CheckerTest { |
| 17 void test_awaitForInCastsStreamElementToVariable() { | 18 void test_awaitForInCastsStreamElementToVariable() { |
| 18 checkFile(''' | 19 checkFile(''' |
| 19 import 'dart:async'; | 20 import 'dart:async'; |
| 20 main() async { | 21 main() async { |
| 21 // Don't choke if sequence is not stream. | 22 // Don't choke if sequence is not stream. |
| 22 await for (var i in /*error:FOR_IN_OF_INVALID_TYPE*/1234) {} | 23 await for (var i in /*error:FOR_IN_OF_INVALID_TYPE*/1234) {} |
| (...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 313 a[b] += d; | 314 a[b] += d; |
| 314 a[/*info:DYNAMIC_CAST*/c] += d; | 315 a[/*info:DYNAMIC_CAST*/c] += d; |
| 315 a[/*error:ARGUMENT_TYPE_NOT_ASSIGNABLE*/z] += d; | 316 a[/*error:ARGUMENT_TYPE_NOT_ASSIGNABLE*/z] += d; |
| 316 a[b] += /*info:DYNAMIC_CAST*/c; | 317 a[b] += /*info:DYNAMIC_CAST*/c; |
| 317 a[b] += /*error:ARGUMENT_TYPE_NOT_ASSIGNABLE*/z; | 318 a[b] += /*error:ARGUMENT_TYPE_NOT_ASSIGNABLE*/z; |
| 318 /*info:DYNAMIC_INVOKE,info:DYNAMIC_INVOKE*/c[b] += d; | 319 /*info:DYNAMIC_INVOKE,info:DYNAMIC_INVOKE*/c[b] += d; |
| 319 } | 320 } |
| 320 '''); | 321 '''); |
| 321 } | 322 } |
| 322 | 323 |
| 324 void test_constantGenericTypeArg_explict() { |
| 325 // Regression test for https://github.com/dart-lang/sdk/issues/26141 |
| 326 checkFile(''' |
| 327 abstract class Equality<R> {} |
| 328 abstract class EqualityBase<R> implements Equality<R> { |
| 329 final C<R> c = const C<R>(); |
| 330 const EqualityBase(); |
| 331 } |
| 332 class DefaultEquality<S> extends EqualityBase<S> { |
| 333 const DefaultEquality(); |
| 334 } |
| 335 class SetEquality<T> implements Equality<T> { |
| 336 final Equality<T> field = const DefaultEquality<T>(); |
| 337 const SetEquality([Equality<T> inner = const DefaultEquality<T>()]); |
| 338 } |
| 339 class C<Q> { |
| 340 final List<Q> list = const <Q>[]; |
| 341 final Map<Q, Iterable<Q>> m = const <Q, Iterable<Q>>{}; |
| 342 const C(); |
| 343 } |
| 344 main() { |
| 345 const SetEquality<String>(); |
| 346 } |
| 347 '''); |
| 348 } |
| 349 |
| 350 void test_constantGenericTypeArg_infer() { |
| 351 // Regression test for https://github.com/dart-lang/sdk/issues/26141 |
| 352 checkFile(''' |
| 353 abstract class Equality<Q> {} |
| 354 abstract class EqualityBase<R> implements Equality<R> { |
| 355 final C<R> c = /*info:INFERRED_TYPE_ALLOCATION*/const C(); |
| 356 const EqualityBase(); |
| 357 } |
| 358 class DefaultEquality<S> extends EqualityBase<S> { |
| 359 const DefaultEquality(); |
| 360 } |
| 361 class SetEquality<T> implements Equality<T> { |
| 362 final Equality<T> field = const DefaultEquality(); |
| 363 const SetEquality([Equality<T> inner = const DefaultEquality()]); |
| 364 } |
| 365 class C<Q> { |
| 366 final List<Q> list = /*info:INFERRED_TYPE_LITERAL*/const []; |
| 367 final Map<Q, Iterable<Q>> m = /*info:INFERRED_TYPE_LITERAL*/const {}; |
| 368 const C(); |
| 369 } |
| 370 main() { |
| 371 const SetEquality<String>(); |
| 372 } |
| 373 '''); |
| 374 } |
| 375 |
| 323 void test_constructorInvalid() { | 376 void test_constructorInvalid() { |
| 324 // Regression test for https://github.com/dart-lang/sdk/issues/26695 | 377 // Regression test for https://github.com/dart-lang/sdk/issues/26695 |
| 325 checkFile(''' | 378 checkFile(''' |
| 326 class A { | 379 class A { |
| 327 B({ /*error:FIELD_INITIALIZER_OUTSIDE_CONSTRUCTOR*/this.test: 1.0 }) {} | 380 B({ /*error:FIELD_INITIALIZER_OUTSIDE_CONSTRUCTOR*/this.test: 1.0 }) {} |
| 328 final double test = 0.0; | 381 final double test = 0.0; |
| 329 } | 382 } |
| 330 '''); | 383 '''); |
| 331 } | 384 } |
| 332 | 385 |
| (...skipping 1648 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1981 d = /*error:IMPLICIT_DYNAMIC_FUNCTION*/g(); | 2034 d = /*error:IMPLICIT_DYNAMIC_FUNCTION*/g(); |
| 1982 i = g(); | 2035 i = g(); |
| 1983 | 2036 |
| 1984 /*error:IMPLICIT_DYNAMIC_INVOKE*/(/*<T>*/(/*=T*/ t) => t)(d); | 2037 /*error:IMPLICIT_DYNAMIC_INVOKE*/(/*<T>*/(/*=T*/ t) => t)(d); |
| 1985 (/*<T>*/(/*=T*/ t) => t)(42); | 2038 (/*<T>*/(/*=T*/ t) => t)(42); |
| 1986 (/*<T>*/() => /*info:UNNECESSARY_CAST*/null as dynamic/*=T*/)/*<int>*/(); | 2039 (/*<T>*/() => /*info:UNNECESSARY_CAST*/null as dynamic/*=T*/)/*<int>*/(); |
| 1987 } | 2040 } |
| 1988 '''); | 2041 '''); |
| 1989 check(implicitDynamic: false); | 2042 check(implicitDynamic: false); |
| 1990 } | 2043 } |
| 2044 |
| 1991 void test_implicitDynamic_listLiteral() { | 2045 void test_implicitDynamic_listLiteral() { |
| 1992 addFile(r''' | 2046 addFile(r''' |
| 1993 | 2047 |
| 1994 var l0 = /*error:IMPLICIT_DYNAMIC_LIST_LITERAL*/[]; | 2048 var l0 = /*error:IMPLICIT_DYNAMIC_LIST_LITERAL*/[]; |
| 1995 List l1 = /*error:IMPLICIT_DYNAMIC_LIST_LITERAL*/[]; | 2049 List l1 = /*error:IMPLICIT_DYNAMIC_LIST_LITERAL*/[]; |
| 1996 List<dynamic> l2 = /*error:IMPLICIT_DYNAMIC_LIST_LITERAL*/[]; | 2050 List<dynamic> l2 = /*error:IMPLICIT_DYNAMIC_LIST_LITERAL*/[]; |
| 1997 dynamic d = 42; | 2051 dynamic d = 42; |
| 1998 var l3 = /*error:IMPLICIT_DYNAMIC_LIST_LITERAL*/[d, d]; | 2052 var l3 = /*error:IMPLICIT_DYNAMIC_LIST_LITERAL*/[d, d]; |
| 1999 | 2053 |
| 2000 var l4 = <dynamic>[]; | 2054 var l4 = <dynamic>[]; |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2161 var /*error:IMPLICIT_DYNAMIC_VARIABLE*/x1 = (<dynamic>[])[0]; | 2215 var /*error:IMPLICIT_DYNAMIC_VARIABLE*/x1 = (<dynamic>[])[0]; |
| 2162 var /*error:IMPLICIT_DYNAMIC_VARIABLE*/x2, | 2216 var /*error:IMPLICIT_DYNAMIC_VARIABLE*/x2, |
| 2163 x3 = 42, | 2217 x3 = 42, |
| 2164 /*error:IMPLICIT_DYNAMIC_VARIABLE*/x4; | 2218 /*error:IMPLICIT_DYNAMIC_VARIABLE*/x4; |
| 2165 dynamic y0; | 2219 dynamic y0; |
| 2166 dynamic y1 = (<dynamic>[])[0]; | 2220 dynamic y1 = (<dynamic>[])[0]; |
| 2167 '''); | 2221 '''); |
| 2168 check(implicitDynamic: false); | 2222 check(implicitDynamic: false); |
| 2169 } | 2223 } |
| 2170 | 2224 |
| 2171 void test_constantGenericTypeArg_infer() { | |
| 2172 // Regression test for https://github.com/dart-lang/sdk/issues/26141 | |
| 2173 checkFile(''' | |
| 2174 abstract class Equality<Q> {} | |
| 2175 abstract class EqualityBase<R> implements Equality<R> { | |
| 2176 final C<R> c = /*info:INFERRED_TYPE_ALLOCATION*/const C(); | |
| 2177 const EqualityBase(); | |
| 2178 } | |
| 2179 class DefaultEquality<S> extends EqualityBase<S> { | |
| 2180 const DefaultEquality(); | |
| 2181 } | |
| 2182 class SetEquality<T> implements Equality<T> { | |
| 2183 final Equality<T> field = const DefaultEquality(); | |
| 2184 const SetEquality([Equality<T> inner = const DefaultEquality()]); | |
| 2185 } | |
| 2186 class C<Q> { | |
| 2187 final List<Q> list = /*info:INFERRED_TYPE_LITERAL*/const []; | |
| 2188 final Map<Q, Iterable<Q>> m = /*info:INFERRED_TYPE_LITERAL*/const {}; | |
| 2189 const C(); | |
| 2190 } | |
| 2191 main() { | |
| 2192 const SetEquality<String>(); | |
| 2193 } | |
| 2194 '''); | |
| 2195 } | |
| 2196 | |
| 2197 void test_constantGenericTypeArg_explict() { | |
| 2198 // Regression test for https://github.com/dart-lang/sdk/issues/26141 | |
| 2199 checkFile(''' | |
| 2200 abstract class Equality<R> {} | |
| 2201 abstract class EqualityBase<R> implements Equality<R> { | |
| 2202 final C<R> c = const C<R>(); | |
| 2203 const EqualityBase(); | |
| 2204 } | |
| 2205 class DefaultEquality<S> extends EqualityBase<S> { | |
| 2206 const DefaultEquality(); | |
| 2207 } | |
| 2208 class SetEquality<T> implements Equality<T> { | |
| 2209 final Equality<T> field = const DefaultEquality<T>(); | |
| 2210 const SetEquality([Equality<T> inner = const DefaultEquality<T>()]); | |
| 2211 } | |
| 2212 class C<Q> { | |
| 2213 final List<Q> list = const <Q>[]; | |
| 2214 final Map<Q, Iterable<Q>> m = const <Q, Iterable<Q>>{}; | |
| 2215 const C(); | |
| 2216 } | |
| 2217 main() { | |
| 2218 const SetEquality<String>(); | |
| 2219 } | |
| 2220 '''); | |
| 2221 } | |
| 2222 | |
| 2223 void test_invalidOverrides_baseClassOverrideToChildInterface() { | 2225 void test_invalidOverrides_baseClassOverrideToChildInterface() { |
| 2224 checkFile(''' | 2226 checkFile(''' |
| 2225 class A {} | 2227 class A {} |
| 2226 class B {} | 2228 class B {} |
| 2227 | 2229 |
| 2228 abstract class I { | 2230 abstract class I { |
| 2229 m(A a); | 2231 m(A a); |
| 2230 } | 2232 } |
| 2231 | 2233 |
| 2232 class Base { | 2234 class Base { |
| (...skipping 1492 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3725 // Regression test for https://github.com/dart-lang/sdk/issues/25069 | 3727 // Regression test for https://github.com/dart-lang/sdk/issues/25069 |
| 3726 checkFile(''' | 3728 checkFile(''' |
| 3727 typedef int Foo(); | 3729 typedef int Foo(); |
| 3728 void foo() {} | 3730 void foo() {} |
| 3729 void main () { | 3731 void main () { |
| 3730 Foo x = /*error:INVALID_ASSIGNMENT,info:USE_OF_VOID_RESULT*/foo(); | 3732 Foo x = /*error:INVALID_ASSIGNMENT,info:USE_OF_VOID_RESULT*/foo(); |
| 3731 } | 3733 } |
| 3732 '''); | 3734 '''); |
| 3733 } | 3735 } |
| 3734 } | 3736 } |
| OLD | NEW |