Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(170)

Side by Side Diff: pkg/analyzer/test/generated/static_type_warning_code_test.dart

Issue 1771153002: Type check for-in statements. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Update to latest on master. Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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.generated.static_type_warning_code_test; 5 library analyzer.test.generated.static_type_warning_code_test;
6 6
7 import 'package:analyzer/src/generated/engine.dart'; 7 import 'package:analyzer/src/generated/engine.dart';
8 import 'package:analyzer/src/generated/error.dart'; 8 import 'package:analyzer/src/generated/error.dart';
9 import 'package:analyzer/src/generated/java_core.dart' show formatList; 9 import 'package:analyzer/src/generated/java_core.dart' show formatList;
10 import 'package:analyzer/src/generated/source_io.dart'; 10 import 'package:analyzer/src/generated/source_io.dart';
(...skipping 2021 matching lines...) Expand 10 before | Expand all | Expand 10 after
2032 class C<E> {} 2032 class C<E> {}
2033 f(p) { 2033 f(p) {
2034 return p is C<A, A>; 2034 return p is C<A, A>;
2035 }'''); 2035 }''');
2036 computeLibrarySourceErrors(source); 2036 computeLibrarySourceErrors(source);
2037 assertErrors( 2037 assertErrors(
2038 source, [StaticTypeWarningCode.WRONG_NUMBER_OF_TYPE_ARGUMENTS]); 2038 source, [StaticTypeWarningCode.WRONG_NUMBER_OF_TYPE_ARGUMENTS]);
2039 verify([source]); 2039 verify([source]);
2040 } 2040 }
2041 2041
2042 void test_forIn_notIterable() {
2043 assertErrorsInCode('''
2044 f() {
2045 for (var i in true) {}
2046 }
2047 ''', [StaticTypeWarningCode.FOR_IN_OF_INVALID_TYPE]);
2048 }
2049
2050 void test_forIn_declaredVariableWrongType() {
2051 assertErrorsInCode('''
2052 f() {
2053 for (int i in <String>[]) {}
2054 }
2055 ''', [StaticTypeWarningCode.FOR_IN_OF_INVALID_ELEMENT_TYPE]);
2056 }
2057
2058 void test_forIn_existingVariableWrongType() {
2059 assertErrorsInCode('''
2060 f() {
2061 int i;
2062 for (i in <String>[]) {}
2063 }
2064 ''', [StaticTypeWarningCode.FOR_IN_OF_INVALID_ELEMENT_TYPE]);
2065 }
2066
2067 void test_forIn_declaredVariableRightType() {
2068 assertNoErrorsInCode('''
2069 f() {
2070 for (int i in <int>[]) {}
2071 }
2072 ''');
2073 }
2074
2075 void test_forIn_existingVariableRightType() {
2076 assertNoErrorsInCode('''
2077 f() {
2078 int i;
2079 for (i in <int>[]) {}
2080 }
2081 ''');
2082 }
2083
2084 void test_forIn_dynamicVariable() {
2085 assertNoErrorsInCode('''
2086 f() {
2087 for (var i in <int>[]) {}
2088 }
2089 ''');
2090 }
2091
2092 void test_forIn_iterableOfDynamic() {
2093 assertNoErrorsInCode('''
2094 f() {
2095 for (int i in []) {}
2096 }
2097 ''');
2098 }
2099
2100 void test_forIn_dynamicIterable() {
2101 assertNoErrorsInCode('''
2102 f() {
2103 dynamic iterable;
2104 for (int i in iterable) {}
2105 }
2106 ''');
2107 }
2108
2109 void test_forIn_upcast() {
2110 assertNoErrorsInCode('''
2111 f() {
2112 for (num i in <int>[]) {}
2113 }
2114 ''');
2115 }
2116
2117 void test_forIn_downcast() {
Brian Wilkerson 2016/03/08 01:12:12 Should any of these tests have different behavior
Bob Nystrom 2016/03/08 19:00:50 Right now, I think you'll just get duplicate error
2118 assertNoErrorsInCode('''
2119 f() {
2120 for (int i in <num>[]) {}
2121 }
2122 ''');
2123 }
2124
2125 void test_forIn_typeBoundBad() {
2126 assertErrorsInCode('''
2127 class Foo<T extends Iterable<int>> {
2128 void method(T iterable) {
2129 for (String i in iterable) {}
2130 }
2131 }
2132 ''', [StaticTypeWarningCode.FOR_IN_OF_INVALID_ELEMENT_TYPE]);
2133 }
2134
2135 void test_forIn_typeBoundGood() {
2136 assertNoErrorsInCode('''
2137 class Foo<T extends Iterable<int>> {
2138 void method(T iterable) {
2139 for (var i in iterable) {}
2140 }
2141 }
2142 ''');
2143 }
2144
2145 void test_awaitForIn_notStream() {
2146 assertErrorsInCode('''
2147 f() async {
2148 await for (var i in true) {}
2149 }
2150 ''', [StaticTypeWarningCode.FOR_IN_OF_INVALID_TYPE]);
2151 }
2152
2153 void test_awaitForIn_declaredVariableWrongType() {
2154 assertErrorsInCode('''
2155 import 'dart:async';
2156 f() async {
2157 Stream<String> stream;
2158 await for (int i in stream) {}
2159 }
2160 ''', [StaticTypeWarningCode.FOR_IN_OF_INVALID_ELEMENT_TYPE]);
2161 }
2162
2163 void test_awaitForIn_existingVariableWrongType() {
2164 assertErrorsInCode('''
2165 import 'dart:async';
2166 f() async {
2167 Stream<String> stream;
2168 int i;
2169 await for (i in stream) {}
2170 }
2171 ''', [StaticTypeWarningCode.FOR_IN_OF_INVALID_ELEMENT_TYPE]);
2172 }
2173
2174 void test_awaitForIn_declaredVariableRightType() {
2175 assertNoErrorsInCode('''
2176 import 'dart:async';
2177 f() async {
2178 Stream<int> stream;
2179 await for (int i in stream) {}
2180 }
2181 ''');
2182 }
2183
2184 void test_awaitForIn_existingVariableRightType() {
2185 assertNoErrorsInCode('''
2186 import 'dart:async';
2187 f() async {
2188 Stream<int> stream;
2189 int i;
2190 await for (i in stream) {}
2191 }
2192 ''');
2193 }
2194
2195 void test_awaitForIn_dynamicVariable() {
2196 assertNoErrorsInCode('''
2197 import 'dart:async';
2198 f() async {
2199 Stream<int> stream;
2200 await for (var i in stream) {}
2201 }
2202 ''');
2203 }
2204
2205 void test_awaitForIn_streamOfDynamic() {
2206 assertNoErrorsInCode('''
2207 import 'dart:async';
2208 f() async {
2209 Stream stream;
2210 await for (int i in stream) {}
2211 }
2212 ''');
2213 }
2214
2215 void test_awaitForIn_dynamicStream() {
2216 assertNoErrorsInCode('''
2217 f() async {
2218 dynamic stream;
2219 await for (int i in stream) {}
2220 }
2221 ''');
2222 }
2223
2224 void test_awaitForIn_upcast() {
2225 assertNoErrorsInCode('''
2226 import 'dart:async';
2227 f() async {
2228 Stream<int> stream;
2229 await for (num i in stream) {}
2230 }
2231 ''');
2232 }
2233
2234 void test_awaitForIn_downcast() {
2235 assertNoErrorsInCode('''
2236 import 'dart:async';
2237 f() async {
2238 Stream<num> stream;
2239 await for (int i in stream) {}
2240 }
2241 ''');
2242 }
2243
2042 void test_yield_async_to_basic_type() { 2244 void test_yield_async_to_basic_type() {
2043 Source source = addSource(''' 2245 Source source = addSource('''
2044 int f() async* { 2246 int f() async* {
2045 yield 3; 2247 yield 3;
2046 } 2248 }
2047 '''); 2249 ''');
2048 computeLibrarySourceErrors(source); 2250 computeLibrarySourceErrors(source);
2049 assertErrors(source, [ 2251 assertErrors(source, [
2050 StaticTypeWarningCode.YIELD_OF_INVALID_TYPE, 2252 StaticTypeWarningCode.YIELD_OF_INVALID_TYPE,
2051 StaticTypeWarningCode.ILLEGAL_ASYNC_GENERATOR_RETURN_TYPE 2253 StaticTypeWarningCode.ILLEGAL_ASYNC_GENERATOR_RETURN_TYPE
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
2189 for (AnalysisError error in analysisContext2.computeErrors(source)) { 2391 for (AnalysisError error in analysisContext2.computeErrors(source)) {
2190 if (error.errorCode == 2392 if (error.errorCode ==
2191 StaticTypeWarningCode.WRONG_NUMBER_OF_TYPE_ARGUMENTS) { 2393 StaticTypeWarningCode.WRONG_NUMBER_OF_TYPE_ARGUMENTS) {
2192 expect(error.message, 2394 expect(error.message,
2193 formatList(error.errorCode.message, ['() → dynamic', 0, 1])); 2395 formatList(error.errorCode.message, ['() → dynamic', 0, 1]));
2194 } 2396 }
2195 } 2397 }
2196 verify([source]); 2398 verify([source]);
2197 } 2399 }
2198 } 2400 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698