| 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 // TODO(jmesserly): this file needs to be refactored, it's a port from | 5 // TODO(jmesserly): this file needs to be refactored, it's a port from |
| 6 // package:dev_compiler's tests | 6 // package:dev_compiler's tests |
| 7 /// General type checking tests | 7 /// General type checking tests |
| 8 library analyzer.test.src.task.strong.checker_test; | 8 library analyzer.test.src.task.strong.checker_test; |
| 9 | 9 |
| 10 import 'package:unittest/unittest.dart'; | 10 import 'package:unittest/unittest.dart'; |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 do {} while (/*warning:NON_BOOL_CONDITION*/i); | 80 do {} while (/*warning:NON_BOOL_CONDITION*/i); |
| 81 | 81 |
| 82 for (;b;) {} | 82 for (;b;) {} |
| 83 for (;/*info:DYNAMIC_CAST*/dyn;) {} | 83 for (;/*info:DYNAMIC_CAST*/dyn;) {} |
| 84 for (;/*info:DOWN_CAST_IMPLICIT*/obj;) {} | 84 for (;/*info:DOWN_CAST_IMPLICIT*/obj;) {} |
| 85 for (;/*warning:NON_BOOL_CONDITION*/i;) {} | 85 for (;/*warning:NON_BOOL_CONDITION*/i;) {} |
| 86 } | 86 } |
| 87 '''); | 87 '''); |
| 88 }); | 88 }); |
| 89 | 89 |
| 90 test('for-in casts supertype sequence to iterable', () { |
| 91 checkFile(''' |
| 92 main() { |
| 93 dynamic d; |
| 94 for (var i in /*info:DYNAMIC_CAST*/d) {} |
| 95 |
| 96 Object o; |
| 97 for (var i in /*info:DOWN_CAST_IMPLICIT*/o) {} |
| 98 } |
| 99 '''); |
| 100 }); |
| 101 |
| 102 test('await for-in casts supertype sequence to stream', () { |
| 103 checkFile(''' |
| 104 main() async { |
| 105 dynamic d; |
| 106 await for (var i in /*info:DYNAMIC_CAST*/d) {} |
| 107 |
| 108 Object o; |
| 109 await for (var i in /*info:DOWN_CAST_IMPLICIT*/o) {} |
| 110 } |
| 111 '''); |
| 112 }); |
| 113 |
| 114 test('for-in casts iterable element to variable', () { |
| 115 checkFile(''' |
| 116 main() { |
| 117 // Don't choke if sequence is not iterable. |
| 118 for (var i in /*warning:FOR_IN_OF_INVALID_TYPE*/1234) {} |
| 119 |
| 120 // Dynamic cast. |
| 121 for (String /*info:DYNAMIC_CAST*/s in <dynamic>[]) {} |
| 122 |
| 123 // Identity cast. |
| 124 for (String s in <String>[]) {} |
| 125 |
| 126 // Untyped. |
| 127 for (var s in <String>[]) {} |
| 128 |
| 129 // Downcast. |
| 130 for (int /*info:DOWN_CAST_IMPLICIT*/i in <num>[]) {} |
| 131 } |
| 132 '''); |
| 133 }); |
| 134 |
| 135 test('await for-in casts stream element to variable', () { |
| 136 checkFile(''' |
| 137 import 'dart:async'; |
| 138 main() async { |
| 139 // Don't choke if sequence is not stream. |
| 140 await for (var i in /*warning:FOR_IN_OF_INVALID_TYPE*/1234) {} |
| 141 |
| 142 // Dynamic cast. |
| 143 await for (String /*info:DYNAMIC_CAST*/s in new Stream<dynamic>()) {} |
| 144 |
| 145 // Identity cast. |
| 146 await for (String s in new Stream<String>()) {} |
| 147 |
| 148 // Untyped. |
| 149 await for (var s in new Stream<String>()) {} |
| 150 |
| 151 // Downcast. |
| 152 await for (int /*info:DOWN_CAST_IMPLICIT*/i in new Stream<num>()) {} |
| 153 } |
| 154 '''); |
| 155 }); |
| 156 |
| 90 test('dynamic invocation', () { | 157 test('dynamic invocation', () { |
| 91 checkFile(''' | 158 checkFile(''' |
| 92 class A { | 159 class A { |
| 93 dynamic call(dynamic x) => x; | 160 dynamic call(dynamic x) => x; |
| 94 } | 161 } |
| 95 class B extends A { | 162 class B extends A { |
| 96 int call(int x) => x; | 163 int call(int x) => x; |
| 97 double col(double x) => x; | 164 double col(double x) => x; |
| 98 } | 165 } |
| 99 void main() { | 166 void main() { |
| (...skipping 2806 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2906 | 2973 |
| 2907 baz1() sync* { yield* /*info:DYNAMIC_CAST*/x; } | 2974 baz1() sync* { yield* /*info:DYNAMIC_CAST*/x; } |
| 2908 Iterable baz2() sync* { yield* /*info:DYNAMIC_CAST*/x; } | 2975 Iterable baz2() sync* { yield* /*info:DYNAMIC_CAST*/x; } |
| 2909 Iterable<int> baz3() sync* { yield* /*warning:DOWN_CAST_COMPOSITE*/x; } | 2976 Iterable<int> baz3() sync* { yield* /*warning:DOWN_CAST_COMPOSITE*/x; } |
| 2910 Iterable<int> baz4() sync* { yield* bar3(); } | 2977 Iterable<int> baz4() sync* { yield* bar3(); } |
| 2911 Iterable<int> baz5() sync* { yield* /*info:INFERRED_TYPE_ALLOCATION*/new
List(); } | 2978 Iterable<int> baz5() sync* { yield* /*info:INFERRED_TYPE_ALLOCATION*/new
List(); } |
| 2912 '''); | 2979 '''); |
| 2913 }); | 2980 }); |
| 2914 }); | 2981 }); |
| 2915 } | 2982 } |
| OLD | NEW |