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

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

Issue 1266923004: More fixes for failures on the Windows bot (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 5 years, 4 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 engine.static_warning_code_test; 5 library engine.static_warning_code_test;
6 6
7 import 'package:analyzer/src/generated/error.dart'; 7 import 'package:analyzer/src/generated/error.dart';
8 import 'package:analyzer/src/generated/source_io.dart'; 8 import 'package:analyzer/src/generated/source_io.dart';
9 import 'package:unittest/unittest.dart'; 9 import 'package:unittest/unittest.dart';
10 10
11 import '../reflective_tests.dart'; 11 import '../reflective_tests.dart';
12 import '../utils.dart';
12 import 'resolver_test.dart'; 13 import 'resolver_test.dart';
13 14
14 main() { 15 main() {
15 groupSep = ' | '; 16 initializeTestEnvironment();
16 runReflectiveTests(StaticWarningCodeTest); 17 runReflectiveTests(StaticWarningCodeTest);
17 } 18 }
18 19
19 @reflectiveTest 20 @reflectiveTest
20 class StaticWarningCodeTest extends ResolverTestCase { 21 class StaticWarningCodeTest extends ResolverTestCase {
21 void fail_undefinedGetter() { 22 void fail_undefinedGetter() {
22 Source source = addSource(r''' 23 Source source = addSource(r'''
23 '''); 24 ''');
24 computeLibrarySourceErrors(source); 25 computeLibrarySourceErrors(source);
25 assertErrors(source, [StaticWarningCode.UNDEFINED_GETTER]); 26 assertErrors(source, [StaticWarningCode.UNDEFINED_GETTER]);
(...skipping 21 matching lines...) Expand all
47 computeLibrarySourceErrors(source); 48 computeLibrarySourceErrors(source);
48 assertErrors(source, [StaticWarningCode.UNDEFINED_SETTER]); 49 assertErrors(source, [StaticWarningCode.UNDEFINED_SETTER]);
49 verify([source]); 50 verify([source]);
50 } 51 }
51 52
52 void test_ambiguousImport_as() { 53 void test_ambiguousImport_as() {
53 Source source = addSource(r''' 54 Source source = addSource(r'''
54 import 'lib1.dart'; 55 import 'lib1.dart';
55 import 'lib2.dart'; 56 import 'lib2.dart';
56 f(p) {p as N;}'''); 57 f(p) {p as N;}''');
57 addNamedSource("/lib1.dart", r''' 58 addNamedSource(
59 "/lib1.dart",
60 r'''
58 library lib1; 61 library lib1;
59 class N {}'''); 62 class N {}''');
60 addNamedSource("/lib2.dart", r''' 63 addNamedSource(
64 "/lib2.dart",
65 r'''
61 library lib2; 66 library lib2;
62 class N {}'''); 67 class N {}''');
63 computeLibrarySourceErrors(source); 68 computeLibrarySourceErrors(source);
64 assertErrors(source, [StaticWarningCode.AMBIGUOUS_IMPORT]); 69 assertErrors(source, [StaticWarningCode.AMBIGUOUS_IMPORT]);
65 } 70 }
66 71
67 void test_ambiguousImport_extends() { 72 void test_ambiguousImport_extends() {
68 Source source = addSource(r''' 73 Source source = addSource(r'''
69 import 'lib1.dart'; 74 import 'lib1.dart';
70 import 'lib2.dart'; 75 import 'lib2.dart';
71 class A extends N {}'''); 76 class A extends N {}''');
72 addNamedSource("/lib1.dart", r''' 77 addNamedSource(
78 "/lib1.dart",
79 r'''
73 library lib1; 80 library lib1;
74 class N {}'''); 81 class N {}''');
75 addNamedSource("/lib2.dart", r''' 82 addNamedSource(
83 "/lib2.dart",
84 r'''
76 library lib2; 85 library lib2;
77 class N {}'''); 86 class N {}''');
78 computeLibrarySourceErrors(source); 87 computeLibrarySourceErrors(source);
79 assertErrors(source, [ 88 assertErrors(source, [
80 StaticWarningCode.AMBIGUOUS_IMPORT, 89 StaticWarningCode.AMBIGUOUS_IMPORT,
81 CompileTimeErrorCode.EXTENDS_NON_CLASS 90 CompileTimeErrorCode.EXTENDS_NON_CLASS
82 ]); 91 ]);
83 } 92 }
84 93
85 void test_ambiguousImport_implements() { 94 void test_ambiguousImport_implements() {
86 Source source = addSource(r''' 95 Source source = addSource(r'''
87 import 'lib1.dart'; 96 import 'lib1.dart';
88 import 'lib2.dart'; 97 import 'lib2.dart';
89 class A implements N {}'''); 98 class A implements N {}''');
90 addNamedSource("/lib1.dart", r''' 99 addNamedSource(
100 "/lib1.dart",
101 r'''
91 library lib1; 102 library lib1;
92 class N {}'''); 103 class N {}''');
93 addNamedSource("/lib2.dart", r''' 104 addNamedSource(
105 "/lib2.dart",
106 r'''
94 library lib2; 107 library lib2;
95 class N {}'''); 108 class N {}''');
96 computeLibrarySourceErrors(source); 109 computeLibrarySourceErrors(source);
97 assertErrors(source, [ 110 assertErrors(source, [
98 StaticWarningCode.AMBIGUOUS_IMPORT, 111 StaticWarningCode.AMBIGUOUS_IMPORT,
99 CompileTimeErrorCode.IMPLEMENTS_NON_CLASS 112 CompileTimeErrorCode.IMPLEMENTS_NON_CLASS
100 ]); 113 ]);
101 } 114 }
102 115
103 void test_ambiguousImport_inPart() { 116 void test_ambiguousImport_inPart() {
104 Source source = addSource(r''' 117 Source source = addSource(r'''
105 library lib; 118 library lib;
106 import 'lib1.dart'; 119 import 'lib1.dart';
107 import 'lib2.dart'; 120 import 'lib2.dart';
108 part 'part.dart';'''); 121 part 'part.dart';''');
109 addNamedSource("/lib1.dart", r''' 122 addNamedSource(
123 "/lib1.dart",
124 r'''
110 library lib1; 125 library lib1;
111 class N {}'''); 126 class N {}''');
112 addNamedSource("/lib2.dart", r''' 127 addNamedSource(
128 "/lib2.dart",
129 r'''
113 library lib2; 130 library lib2;
114 class N {}'''); 131 class N {}''');
115 Source partSource = addNamedSource("/part.dart", r''' 132 Source partSource = addNamedSource(
133 "/part.dart",
134 r'''
116 part of lib; 135 part of lib;
117 class A extends N {}'''); 136 class A extends N {}''');
118 computeLibrarySourceErrors(source); 137 computeLibrarySourceErrors(source);
119 assertErrors(partSource, [ 138 assertErrors(partSource, [
120 StaticWarningCode.AMBIGUOUS_IMPORT, 139 StaticWarningCode.AMBIGUOUS_IMPORT,
121 CompileTimeErrorCode.EXTENDS_NON_CLASS 140 CompileTimeErrorCode.EXTENDS_NON_CLASS
122 ]); 141 ]);
123 } 142 }
124 143
125 void test_ambiguousImport_instanceCreation() { 144 void test_ambiguousImport_instanceCreation() {
126 Source source = addSource(r''' 145 Source source = addSource(r'''
127 library L; 146 library L;
128 import 'lib1.dart'; 147 import 'lib1.dart';
129 import 'lib2.dart'; 148 import 'lib2.dart';
130 f() {new N();}'''); 149 f() {new N();}''');
131 addNamedSource("/lib1.dart", r''' 150 addNamedSource(
151 "/lib1.dart",
152 r'''
132 library lib1; 153 library lib1;
133 class N {}'''); 154 class N {}''');
134 addNamedSource("/lib2.dart", r''' 155 addNamedSource(
156 "/lib2.dart",
157 r'''
135 library lib2; 158 library lib2;
136 class N {}'''); 159 class N {}''');
137 computeLibrarySourceErrors(source); 160 computeLibrarySourceErrors(source);
138 assertErrors(source, [StaticWarningCode.AMBIGUOUS_IMPORT]); 161 assertErrors(source, [StaticWarningCode.AMBIGUOUS_IMPORT]);
139 } 162 }
140 163
141 void test_ambiguousImport_is() { 164 void test_ambiguousImport_is() {
142 Source source = addSource(r''' 165 Source source = addSource(r'''
143 import 'lib1.dart'; 166 import 'lib1.dart';
144 import 'lib2.dart'; 167 import 'lib2.dart';
145 f(p) {p is N;}'''); 168 f(p) {p is N;}''');
146 addNamedSource("/lib1.dart", r''' 169 addNamedSource(
170 "/lib1.dart",
171 r'''
147 library lib1; 172 library lib1;
148 class N {}'''); 173 class N {}''');
149 addNamedSource("/lib2.dart", r''' 174 addNamedSource(
175 "/lib2.dart",
176 r'''
150 library lib2; 177 library lib2;
151 class N {}'''); 178 class N {}''');
152 computeLibrarySourceErrors(source); 179 computeLibrarySourceErrors(source);
153 assertErrors(source, [StaticWarningCode.AMBIGUOUS_IMPORT]); 180 assertErrors(source, [StaticWarningCode.AMBIGUOUS_IMPORT]);
154 } 181 }
155 182
156 void test_ambiguousImport_qualifier() { 183 void test_ambiguousImport_qualifier() {
157 Source source = addSource(r''' 184 Source source = addSource(r'''
158 import 'lib1.dart'; 185 import 'lib1.dart';
159 import 'lib2.dart'; 186 import 'lib2.dart';
160 g() { N.FOO; }'''); 187 g() { N.FOO; }''');
161 addNamedSource("/lib1.dart", r''' 188 addNamedSource(
189 "/lib1.dart",
190 r'''
162 library lib1; 191 library lib1;
163 class N {}'''); 192 class N {}''');
164 addNamedSource("/lib2.dart", r''' 193 addNamedSource(
194 "/lib2.dart",
195 r'''
165 library lib2; 196 library lib2;
166 class N {}'''); 197 class N {}''');
167 computeLibrarySourceErrors(source); 198 computeLibrarySourceErrors(source);
168 assertErrors(source, [StaticWarningCode.AMBIGUOUS_IMPORT]); 199 assertErrors(source, [StaticWarningCode.AMBIGUOUS_IMPORT]);
169 } 200 }
170 201
171 void test_ambiguousImport_typeAnnotation() { 202 void test_ambiguousImport_typeAnnotation() {
172 Source source = addSource(r''' 203 Source source = addSource(r'''
173 import 'lib1.dart'; 204 import 'lib1.dart';
174 import 'lib2.dart'; 205 import 'lib2.dart';
175 typedef N FT(N p); 206 typedef N FT(N p);
176 N f(N p) { 207 N f(N p) {
177 N v; 208 N v;
178 return null; 209 return null;
179 } 210 }
180 class A { 211 class A {
181 N m() { return null; } 212 N m() { return null; }
182 } 213 }
183 class B<T extends N> {}'''); 214 class B<T extends N> {}''');
184 addNamedSource("/lib1.dart", r''' 215 addNamedSource(
216 "/lib1.dart",
217 r'''
185 library lib1; 218 library lib1;
186 class N {}'''); 219 class N {}''');
187 addNamedSource("/lib2.dart", r''' 220 addNamedSource(
221 "/lib2.dart",
222 r'''
188 library lib2; 223 library lib2;
189 class N {}'''); 224 class N {}''');
190 computeLibrarySourceErrors(source); 225 computeLibrarySourceErrors(source);
191 assertErrors(source, [ 226 assertErrors(source, [
192 StaticWarningCode.AMBIGUOUS_IMPORT, 227 StaticWarningCode.AMBIGUOUS_IMPORT,
193 StaticWarningCode.AMBIGUOUS_IMPORT, 228 StaticWarningCode.AMBIGUOUS_IMPORT,
194 StaticWarningCode.AMBIGUOUS_IMPORT, 229 StaticWarningCode.AMBIGUOUS_IMPORT,
195 StaticWarningCode.AMBIGUOUS_IMPORT, 230 StaticWarningCode.AMBIGUOUS_IMPORT,
196 StaticWarningCode.AMBIGUOUS_IMPORT, 231 StaticWarningCode.AMBIGUOUS_IMPORT,
197 StaticWarningCode.AMBIGUOUS_IMPORT, 232 StaticWarningCode.AMBIGUOUS_IMPORT,
198 StaticWarningCode.AMBIGUOUS_IMPORT 233 StaticWarningCode.AMBIGUOUS_IMPORT
199 ]); 234 ]);
200 } 235 }
201 236
202 void test_ambiguousImport_typeArgument_annotation() { 237 void test_ambiguousImport_typeArgument_annotation() {
203 Source source = addSource(r''' 238 Source source = addSource(r'''
204 import 'lib1.dart'; 239 import 'lib1.dart';
205 import 'lib2.dart'; 240 import 'lib2.dart';
206 class A<T> {} 241 class A<T> {}
207 A<N> f() { return null; }'''); 242 A<N> f() { return null; }''');
208 addNamedSource("/lib1.dart", r''' 243 addNamedSource(
244 "/lib1.dart",
245 r'''
209 library lib1; 246 library lib1;
210 class N {}'''); 247 class N {}''');
211 addNamedSource("/lib2.dart", r''' 248 addNamedSource(
249 "/lib2.dart",
250 r'''
212 library lib2; 251 library lib2;
213 class N {}'''); 252 class N {}''');
214 computeLibrarySourceErrors(source); 253 computeLibrarySourceErrors(source);
215 assertErrors(source, [StaticWarningCode.AMBIGUOUS_IMPORT]); 254 assertErrors(source, [StaticWarningCode.AMBIGUOUS_IMPORT]);
216 } 255 }
217 256
218 void test_ambiguousImport_typeArgument_instanceCreation() { 257 void test_ambiguousImport_typeArgument_instanceCreation() {
219 Source source = addSource(r''' 258 Source source = addSource(r'''
220 import 'lib1.dart'; 259 import 'lib1.dart';
221 import 'lib2.dart'; 260 import 'lib2.dart';
222 class A<T> {} 261 class A<T> {}
223 f() {new A<N>();}'''); 262 f() {new A<N>();}''');
224 addNamedSource("/lib1.dart", r''' 263 addNamedSource(
264 "/lib1.dart",
265 r'''
225 library lib1; 266 library lib1;
226 class N {}'''); 267 class N {}''');
227 addNamedSource("/lib2.dart", r''' 268 addNamedSource(
269 "/lib2.dart",
270 r'''
228 library lib2; 271 library lib2;
229 class N {}'''); 272 class N {}''');
230 computeLibrarySourceErrors(source); 273 computeLibrarySourceErrors(source);
231 assertErrors(source, [StaticWarningCode.AMBIGUOUS_IMPORT]); 274 assertErrors(source, [StaticWarningCode.AMBIGUOUS_IMPORT]);
232 } 275 }
233 276
234 void test_ambiguousImport_varRead() { 277 void test_ambiguousImport_varRead() {
235 Source source = addSource(r''' 278 Source source = addSource(r'''
236 import 'lib1.dart'; 279 import 'lib1.dart';
237 import 'lib2.dart'; 280 import 'lib2.dart';
238 f() { g(v); } 281 f() { g(v); }
239 g(p) {}'''); 282 g(p) {}''');
240 addNamedSource("/lib1.dart", r''' 283 addNamedSource(
284 "/lib1.dart",
285 r'''
241 library lib1; 286 library lib1;
242 var v;'''); 287 var v;''');
243 addNamedSource("/lib2.dart", r''' 288 addNamedSource(
289 "/lib2.dart",
290 r'''
244 library lib2; 291 library lib2;
245 var v;'''); 292 var v;''');
246 computeLibrarySourceErrors(source); 293 computeLibrarySourceErrors(source);
247 assertErrors(source, [StaticWarningCode.AMBIGUOUS_IMPORT]); 294 assertErrors(source, [StaticWarningCode.AMBIGUOUS_IMPORT]);
248 } 295 }
249 296
250 void test_ambiguousImport_varWrite() { 297 void test_ambiguousImport_varWrite() {
251 Source source = addSource(r''' 298 Source source = addSource(r'''
252 import 'lib1.dart'; 299 import 'lib1.dart';
253 import 'lib2.dart'; 300 import 'lib2.dart';
254 f() { v = 0; }'''); 301 f() { v = 0; }''');
255 addNamedSource("/lib1.dart", r''' 302 addNamedSource(
303 "/lib1.dart",
304 r'''
256 library lib1; 305 library lib1;
257 var v;'''); 306 var v;''');
258 addNamedSource("/lib2.dart", r''' 307 addNamedSource(
308 "/lib2.dart",
309 r'''
259 library lib2; 310 library lib2;
260 var v;'''); 311 var v;''');
261 computeLibrarySourceErrors(source); 312 computeLibrarySourceErrors(source);
262 assertErrors(source, [StaticWarningCode.AMBIGUOUS_IMPORT]); 313 assertErrors(source, [StaticWarningCode.AMBIGUOUS_IMPORT]);
263 } 314 }
264 315
265 void test_ambiguousImport_withPrefix() { 316 void test_ambiguousImport_withPrefix() {
266 Source source = addSource(r''' 317 Source source = addSource(r'''
267 library test; 318 library test;
268 import 'lib1.dart' as p; 319 import 'lib1.dart' as p;
269 import 'lib2.dart' as p; 320 import 'lib2.dart' as p;
270 main() { 321 main() {
271 p.f(); 322 p.f();
272 }'''); 323 }''');
273 addNamedSource("/lib1.dart", r''' 324 addNamedSource(
325 "/lib1.dart",
326 r'''
274 library lib1; 327 library lib1;
275 f() {}'''); 328 f() {}''');
276 addNamedSource("/lib2.dart", r''' 329 addNamedSource(
330 "/lib2.dart",
331 r'''
277 library lib2; 332 library lib2;
278 f() {}'''); 333 f() {}''');
279 computeLibrarySourceErrors(source); 334 computeLibrarySourceErrors(source);
280 assertErrors(source, [StaticWarningCode.AMBIGUOUS_IMPORT]); 335 assertErrors(source, [StaticWarningCode.AMBIGUOUS_IMPORT]);
281 } 336 }
282 337
283 void test_argumentTypeNotAssignable_ambiguousClassName() { 338 void test_argumentTypeNotAssignable_ambiguousClassName() {
284 // See dartbug.com/19624 339 // See dartbug.com/19624
285 Source source = addNamedSource("/lib1.dart", r''' 340 Source source = addNamedSource(
341 "/lib1.dart",
342 r'''
286 library lib1; 343 library lib1;
287 import 'lib2.dart'; 344 import 'lib2.dart';
288 class _A {} 345 class _A {}
289 f() { 346 f() {
290 g((_A a) {}); 347 g((_A a) {});
291 }'''); 348 }''');
292 addNamedSource("/lib2.dart", r''' 349 addNamedSource(
350 "/lib2.dart",
351 r'''
293 library lib2; 352 library lib2;
294 class _A {} 353 class _A {}
295 g(h(_A a)) {}'''); 354 g(h(_A a)) {}''');
296 computeLibrarySourceErrors(source); 355 computeLibrarySourceErrors(source);
297 // The name _A is private to the library it's defined in, so this is a type 356 // The name _A is private to the library it's defined in, so this is a type
298 // mismatch. Furthermore, the error message should mention both _A and the 357 // mismatch. Furthermore, the error message should mention both _A and the
299 // filenames so the user can figure out what's going on. 358 // filenames so the user can figure out what's going on.
300 List<AnalysisError> errors = analysisContext2.computeErrors(source); 359 List<AnalysisError> errors = analysisContext2.computeErrors(source);
301 expect(errors, hasLength(1)); 360 expect(errors, hasLength(1));
302 AnalysisError error = errors[0]; 361 AnalysisError error = errors[0];
(...skipping 601 matching lines...) Expand 10 before | Expand all | Expand 10 after
904 source, [StaticWarningCode.CONCRETE_CLASS_WITH_ABSTRACT_MEMBER]); 963 source, [StaticWarningCode.CONCRETE_CLASS_WITH_ABSTRACT_MEMBER]);
905 verify([source]); 964 verify([source]);
906 } 965 }
907 966
908 void test_conflictingDartImport() { 967 void test_conflictingDartImport() {
909 Source source = addSource(r''' 968 Source source = addSource(r'''
910 import 'lib.dart'; 969 import 'lib.dart';
911 import 'dart:async'; 970 import 'dart:async';
912 Future f = null; 971 Future f = null;
913 Stream s;'''); 972 Stream s;''');
914 addNamedSource("/lib.dart", r''' 973 addNamedSource(
974 "/lib.dart",
975 r'''
915 library lib; 976 library lib;
916 class Future {}'''); 977 class Future {}''');
917 computeLibrarySourceErrors(source); 978 computeLibrarySourceErrors(source);
918 assertErrors(source, [StaticWarningCode.CONFLICTING_DART_IMPORT]); 979 assertErrors(source, [StaticWarningCode.CONFLICTING_DART_IMPORT]);
919 } 980 }
920 981
921 void test_conflictingInstanceGetterAndSuperclassMember_declField_direct_setter () { 982 void test_conflictingInstanceGetterAndSuperclassMember_declField_direct_setter () {
922 Source source = addSource(r''' 983 Source source = addSource(r'''
923 class A { 984 class A {
924 static set v(x) {} 985 static set v(x) {}
(...skipping 520 matching lines...) Expand 10 before | Expand all | Expand 10 after
1445 1506
1446 void test_importOfNonLibrary() { 1507 void test_importOfNonLibrary() {
1447 resolveWithErrors(<String>[ 1508 resolveWithErrors(<String>[
1448 r''' 1509 r'''
1449 part of lib; 1510 part of lib;
1450 class A {}''', 1511 class A {}''',
1451 r''' 1512 r'''
1452 library lib; 1513 library lib;
1453 import 'lib1.dart' deferred as p; 1514 import 'lib1.dart' deferred as p;
1454 var a = new p.A();''' 1515 var a = new p.A();'''
1455 ], <ErrorCode>[StaticWarningCode.IMPORT_OF_NON_LIBRARY]); 1516 ], <ErrorCode>[
1517 StaticWarningCode.IMPORT_OF_NON_LIBRARY
1518 ]);
1456 } 1519 }
1457 1520
1458 void test_inconsistentMethodInheritanceGetterAndMethod() { 1521 void test_inconsistentMethodInheritanceGetterAndMethod() {
1459 Source source = addSource(r''' 1522 Source source = addSource(r'''
1460 abstract class A { 1523 abstract class A {
1461 int x(); 1524 int x();
1462 } 1525 }
1463 abstract class B { 1526 abstract class B {
1464 int get x; 1527 int get x;
1465 } 1528 }
(...skipping 907 matching lines...) Expand 10 before | Expand all | Expand 10 after
2373 var A = 0; 2436 var A = 0;
2374 void f() { 2437 void f() {
2375 var a = new A(); 2438 var a = new A();
2376 }'''); 2439 }''');
2377 computeLibrarySourceErrors(source); 2440 computeLibrarySourceErrors(source);
2378 assertErrors(source, [StaticWarningCode.NEW_WITH_NON_TYPE]); 2441 assertErrors(source, [StaticWarningCode.NEW_WITH_NON_TYPE]);
2379 verify([source]); 2442 verify([source]);
2380 } 2443 }
2381 2444
2382 void test_newWithNonType_fromLibrary() { 2445 void test_newWithNonType_fromLibrary() {
2383 Source source1 = addNamedSource("lib.dart", "class B {}"); 2446 Source source1 = addNamedSource("/lib.dart", "class B {}");
2384 Source source2 = addNamedSource("lib2.dart", r''' 2447 Source source2 = addNamedSource(
2448 "/lib2.dart",
2449 r'''
2385 import 'lib.dart' as lib; 2450 import 'lib.dart' as lib;
2386 void f() { 2451 void f() {
2387 var a = new lib.A(); 2452 var a = new lib.A();
2388 } 2453 }
2389 lib.B b;'''); 2454 lib.B b;''');
2390 computeLibrarySourceErrors(source1); 2455 computeLibrarySourceErrors(source1);
2391 computeLibrarySourceErrors(source2); 2456 computeLibrarySourceErrors(source2);
2392 assertErrors(source2, [StaticWarningCode.NEW_WITH_NON_TYPE]); 2457 assertErrors(source2, [StaticWarningCode.NEW_WITH_NON_TYPE]);
2393 verify([source1]); 2458 verify([source1]);
2394 } 2459 }
(...skipping 665 matching lines...) Expand 10 before | Expand all | Expand 10 after
3060 resolveWithErrors(<String>[ 3125 resolveWithErrors(<String>[
3061 r''' 3126 r'''
3062 library lib1; 3127 library lib1;
3063 class A {}''', 3128 class A {}''',
3064 r''' 3129 r'''
3065 library root; 3130 library root;
3066 import 'lib1.dart' deferred as a; 3131 import 'lib1.dart' deferred as a;
3067 f(var v) { 3132 f(var v) {
3068 v as a.A; 3133 v as a.A;
3069 }''' 3134 }'''
3070 ], <ErrorCode>[StaticWarningCode.TYPE_ANNOTATION_DEFERRED_CLASS]); 3135 ], <ErrorCode>[
3136 StaticWarningCode.TYPE_ANNOTATION_DEFERRED_CLASS
3137 ]);
3071 } 3138 }
3072 3139
3073 void test_typeAnnotationDeferredClass_catchClause() { 3140 void test_typeAnnotationDeferredClass_catchClause() {
3074 resolveWithErrors(<String>[ 3141 resolveWithErrors(<String>[
3075 r''' 3142 r'''
3076 library lib1; 3143 library lib1;
3077 class A {}''', 3144 class A {}''',
3078 r''' 3145 r'''
3079 library root; 3146 library root;
3080 import 'lib1.dart' deferred as a; 3147 import 'lib1.dart' deferred as a;
3081 f(var v) { 3148 f(var v) {
3082 try { 3149 try {
3083 } on a.A { 3150 } on a.A {
3084 } 3151 }
3085 }''' 3152 }'''
3086 ], <ErrorCode>[StaticWarningCode.TYPE_ANNOTATION_DEFERRED_CLASS]); 3153 ], <ErrorCode>[
3154 StaticWarningCode.TYPE_ANNOTATION_DEFERRED_CLASS
3155 ]);
3087 } 3156 }
3088 3157
3089 void test_typeAnnotationDeferredClass_fieldFormalParameter() { 3158 void test_typeAnnotationDeferredClass_fieldFormalParameter() {
3090 resolveWithErrors(<String>[ 3159 resolveWithErrors(<String>[
3091 r''' 3160 r'''
3092 library lib1; 3161 library lib1;
3093 class A {}''', 3162 class A {}''',
3094 r''' 3163 r'''
3095 library root; 3164 library root;
3096 import 'lib1.dart' deferred as a; 3165 import 'lib1.dart' deferred as a;
3097 class C { 3166 class C {
3098 var v; 3167 var v;
3099 C(a.A this.v); 3168 C(a.A this.v);
3100 }''' 3169 }'''
3101 ], <ErrorCode>[StaticWarningCode.TYPE_ANNOTATION_DEFERRED_CLASS]); 3170 ], <ErrorCode>[
3171 StaticWarningCode.TYPE_ANNOTATION_DEFERRED_CLASS
3172 ]);
3102 } 3173 }
3103 3174
3104 void test_typeAnnotationDeferredClass_functionDeclaration_returnType() { 3175 void test_typeAnnotationDeferredClass_functionDeclaration_returnType() {
3105 resolveWithErrors(<String>[ 3176 resolveWithErrors(<String>[
3106 r''' 3177 r'''
3107 library lib1; 3178 library lib1;
3108 class A {}''', 3179 class A {}''',
3109 r''' 3180 r'''
3110 library root; 3181 library root;
3111 import 'lib1.dart' deferred as a; 3182 import 'lib1.dart' deferred as a;
3112 a.A f() { return null; }''' 3183 a.A f() { return null; }'''
3113 ], <ErrorCode>[StaticWarningCode.TYPE_ANNOTATION_DEFERRED_CLASS]); 3184 ], <ErrorCode>[
3185 StaticWarningCode.TYPE_ANNOTATION_DEFERRED_CLASS
3186 ]);
3114 } 3187 }
3115 3188
3116 void test_typeAnnotationDeferredClass_functionTypedFormalParameter_returnType( ) { 3189 void test_typeAnnotationDeferredClass_functionTypedFormalParameter_returnType( ) {
3117 resolveWithErrors(<String>[ 3190 resolveWithErrors(<String>[
3118 r''' 3191 r'''
3119 library lib1; 3192 library lib1;
3120 class A {}''', 3193 class A {}''',
3121 r''' 3194 r'''
3122 library root; 3195 library root;
3123 import 'lib1.dart' deferred as a; 3196 import 'lib1.dart' deferred as a;
3124 f(a.A g()) {}''' 3197 f(a.A g()) {}'''
3125 ], <ErrorCode>[StaticWarningCode.TYPE_ANNOTATION_DEFERRED_CLASS]); 3198 ], <ErrorCode>[
3199 StaticWarningCode.TYPE_ANNOTATION_DEFERRED_CLASS
3200 ]);
3126 } 3201 }
3127 3202
3128 void test_typeAnnotationDeferredClass_isExpression() { 3203 void test_typeAnnotationDeferredClass_isExpression() {
3129 resolveWithErrors(<String>[ 3204 resolveWithErrors(<String>[
3130 r''' 3205 r'''
3131 library lib1; 3206 library lib1;
3132 class A {}''', 3207 class A {}''',
3133 r''' 3208 r'''
3134 library root; 3209 library root;
3135 import 'lib1.dart' deferred as a; 3210 import 'lib1.dart' deferred as a;
3136 f(var v) { 3211 f(var v) {
3137 bool b = v is a.A; 3212 bool b = v is a.A;
3138 }''' 3213 }'''
3139 ], <ErrorCode>[StaticWarningCode.TYPE_ANNOTATION_DEFERRED_CLASS]); 3214 ], <ErrorCode>[
3215 StaticWarningCode.TYPE_ANNOTATION_DEFERRED_CLASS
3216 ]);
3140 } 3217 }
3141 3218
3142 void test_typeAnnotationDeferredClass_methodDeclaration_returnType() { 3219 void test_typeAnnotationDeferredClass_methodDeclaration_returnType() {
3143 resolveWithErrors(<String>[ 3220 resolveWithErrors(<String>[
3144 r''' 3221 r'''
3145 library lib1; 3222 library lib1;
3146 class A {}''', 3223 class A {}''',
3147 r''' 3224 r'''
3148 library root; 3225 library root;
3149 import 'lib1.dart' deferred as a; 3226 import 'lib1.dart' deferred as a;
3150 class C { 3227 class C {
3151 a.A m() { return null; } 3228 a.A m() { return null; }
3152 }''' 3229 }'''
3153 ], <ErrorCode>[StaticWarningCode.TYPE_ANNOTATION_DEFERRED_CLASS]); 3230 ], <ErrorCode>[
3231 StaticWarningCode.TYPE_ANNOTATION_DEFERRED_CLASS
3232 ]);
3154 } 3233 }
3155 3234
3156 void test_typeAnnotationDeferredClass_simpleFormalParameter() { 3235 void test_typeAnnotationDeferredClass_simpleFormalParameter() {
3157 resolveWithErrors(<String>[ 3236 resolveWithErrors(<String>[
3158 r''' 3237 r'''
3159 library lib1; 3238 library lib1;
3160 class A {}''', 3239 class A {}''',
3161 r''' 3240 r'''
3162 library root; 3241 library root;
3163 import 'lib1.dart' deferred as a; 3242 import 'lib1.dart' deferred as a;
3164 f(a.A v) {}''' 3243 f(a.A v) {}'''
3165 ], <ErrorCode>[StaticWarningCode.TYPE_ANNOTATION_DEFERRED_CLASS]); 3244 ], <ErrorCode>[
3245 StaticWarningCode.TYPE_ANNOTATION_DEFERRED_CLASS
3246 ]);
3166 } 3247 }
3167 3248
3168 void test_typeAnnotationDeferredClass_typeArgumentList() { 3249 void test_typeAnnotationDeferredClass_typeArgumentList() {
3169 resolveWithErrors(<String>[ 3250 resolveWithErrors(<String>[
3170 r''' 3251 r'''
3171 library lib1; 3252 library lib1;
3172 class A {}''', 3253 class A {}''',
3173 r''' 3254 r'''
3174 library root; 3255 library root;
3175 import 'lib1.dart' deferred as a; 3256 import 'lib1.dart' deferred as a;
3176 class C<E> {} 3257 class C<E> {}
3177 C<a.A> c;''' 3258 C<a.A> c;'''
3178 ], <ErrorCode>[StaticWarningCode.TYPE_ANNOTATION_DEFERRED_CLASS]); 3259 ], <ErrorCode>[
3260 StaticWarningCode.TYPE_ANNOTATION_DEFERRED_CLASS
3261 ]);
3179 } 3262 }
3180 3263
3181 void test_typeAnnotationDeferredClass_typeArgumentList2() { 3264 void test_typeAnnotationDeferredClass_typeArgumentList2() {
3182 resolveWithErrors(<String>[ 3265 resolveWithErrors(<String>[
3183 r''' 3266 r'''
3184 library lib1; 3267 library lib1;
3185 class A {}''', 3268 class A {}''',
3186 r''' 3269 r'''
3187 library root; 3270 library root;
3188 import 'lib1.dart' deferred as a; 3271 import 'lib1.dart' deferred as a;
3189 class C<E, F> {} 3272 class C<E, F> {}
3190 C<a.A, a.A> c;''' 3273 C<a.A, a.A> c;'''
3191 ], <ErrorCode>[ 3274 ], <ErrorCode>[
3192 StaticWarningCode.TYPE_ANNOTATION_DEFERRED_CLASS, 3275 StaticWarningCode.TYPE_ANNOTATION_DEFERRED_CLASS,
3193 StaticWarningCode.TYPE_ANNOTATION_DEFERRED_CLASS 3276 StaticWarningCode.TYPE_ANNOTATION_DEFERRED_CLASS
3194 ]); 3277 ]);
3195 } 3278 }
3196 3279
3197 void test_typeAnnotationDeferredClass_typeParameter_bound() { 3280 void test_typeAnnotationDeferredClass_typeParameter_bound() {
3198 resolveWithErrors(<String>[ 3281 resolveWithErrors(<String>[
3199 r''' 3282 r'''
3200 library lib1; 3283 library lib1;
3201 class A {}''', 3284 class A {}''',
3202 r''' 3285 r'''
3203 library root; 3286 library root;
3204 import 'lib1.dart' deferred as a; 3287 import 'lib1.dart' deferred as a;
3205 class C<E extends a.A> {}''' 3288 class C<E extends a.A> {}'''
3206 ], <ErrorCode>[StaticWarningCode.TYPE_ANNOTATION_DEFERRED_CLASS]); 3289 ], <ErrorCode>[
3290 StaticWarningCode.TYPE_ANNOTATION_DEFERRED_CLASS
3291 ]);
3207 } 3292 }
3208 3293
3209 void test_typeAnnotationDeferredClass_variableDeclarationList() { 3294 void test_typeAnnotationDeferredClass_variableDeclarationList() {
3210 resolveWithErrors(<String>[ 3295 resolveWithErrors(<String>[
3211 r''' 3296 r'''
3212 library lib1; 3297 library lib1;
3213 class A {}''', 3298 class A {}''',
3214 r''' 3299 r'''
3215 library root; 3300 library root;
3216 import 'lib1.dart' deferred as a; 3301 import 'lib1.dart' deferred as a;
3217 a.A v;''' 3302 a.A v;'''
3218 ], <ErrorCode>[StaticWarningCode.TYPE_ANNOTATION_DEFERRED_CLASS]); 3303 ], <ErrorCode>[
3304 StaticWarningCode.TYPE_ANNOTATION_DEFERRED_CLASS
3305 ]);
3219 } 3306 }
3220 3307
3221 void test_typeParameterReferencedByStatic_field() { 3308 void test_typeParameterReferencedByStatic_field() {
3222 Source source = addSource(r''' 3309 Source source = addSource(r'''
3223 class A<K> { 3310 class A<K> {
3224 static K k; 3311 static K k;
3225 }'''); 3312 }''');
3226 computeLibrarySourceErrors(source); 3313 computeLibrarySourceErrors(source);
3227 assertErrors( 3314 assertErrors(
3228 source, [StaticWarningCode.TYPE_PARAMETER_REFERENCED_BY_STATIC]); 3315 source, [StaticWarningCode.TYPE_PARAMETER_REFERENCED_BY_STATIC]);
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
3336 assertErrors(source, [StaticWarningCode.UNDEFINED_CLASS]); 3423 assertErrors(source, [StaticWarningCode.UNDEFINED_CLASS]);
3337 } 3424 }
3338 3425
3339 void test_undefinedClassBoolean_variableDeclaration() { 3426 void test_undefinedClassBoolean_variableDeclaration() {
3340 Source source = addSource("f() { boolean v; }"); 3427 Source source = addSource("f() { boolean v; }");
3341 computeLibrarySourceErrors(source); 3428 computeLibrarySourceErrors(source);
3342 assertErrors(source, [StaticWarningCode.UNDEFINED_CLASS_BOOLEAN]); 3429 assertErrors(source, [StaticWarningCode.UNDEFINED_CLASS_BOOLEAN]);
3343 } 3430 }
3344 3431
3345 void test_undefinedGetter_fromLibrary() { 3432 void test_undefinedGetter_fromLibrary() {
3346 Source source1 = addNamedSource("lib.dart", ""); 3433 Source source1 = addNamedSource("/lib.dart", "");
3347 Source source2 = addNamedSource("lib2.dart", r''' 3434 Source source2 = addNamedSource(
3435 "/lib2.dart",
3436 r'''
3348 import 'lib.dart' as lib; 3437 import 'lib.dart' as lib;
3349 void f() { 3438 void f() {
3350 var g = lib.gg; 3439 var g = lib.gg;
3351 }'''); 3440 }''');
3352 computeLibrarySourceErrors(source1); 3441 computeLibrarySourceErrors(source1);
3353 computeLibrarySourceErrors(source2); 3442 computeLibrarySourceErrors(source2);
3354 assertErrors(source2, [StaticWarningCode.UNDEFINED_GETTER]); 3443 assertErrors(source2, [StaticWarningCode.UNDEFINED_GETTER]);
3355 verify([source1]); 3444 verify([source1]);
3356 } 3445 }
3357 3446
(...skipping 30 matching lines...) Expand all
3388 assertErrors(source, [StaticWarningCode.UNDEFINED_IDENTIFIER]); 3477 assertErrors(source, [StaticWarningCode.UNDEFINED_IDENTIFIER]);
3389 } 3478 }
3390 3479
3391 void test_undefinedIdentifier_methodInvocation() { 3480 void test_undefinedIdentifier_methodInvocation() {
3392 Source source = addSource("f() { C.m(); }"); 3481 Source source = addSource("f() { C.m(); }");
3393 computeLibrarySourceErrors(source); 3482 computeLibrarySourceErrors(source);
3394 assertErrors(source, [StaticWarningCode.UNDEFINED_IDENTIFIER]); 3483 assertErrors(source, [StaticWarningCode.UNDEFINED_IDENTIFIER]);
3395 } 3484 }
3396 3485
3397 void test_undefinedIdentifier_private_getter() { 3486 void test_undefinedIdentifier_private_getter() {
3398 addNamedSource("/lib.dart", r''' 3487 addNamedSource(
3488 "/lib.dart",
3489 r'''
3399 library lib; 3490 library lib;
3400 class A { 3491 class A {
3401 var _foo; 3492 var _foo;
3402 }'''); 3493 }''');
3403 Source source = addSource(r''' 3494 Source source = addSource(r'''
3404 import 'lib.dart'; 3495 import 'lib.dart';
3405 class B extends A { 3496 class B extends A {
3406 test() { 3497 test() {
3407 var v = _foo; 3498 var v = _foo;
3408 } 3499 }
3409 }'''); 3500 }''');
3410 computeLibrarySourceErrors(source); 3501 computeLibrarySourceErrors(source);
3411 assertErrors(source, [StaticWarningCode.UNDEFINED_IDENTIFIER]); 3502 assertErrors(source, [StaticWarningCode.UNDEFINED_IDENTIFIER]);
3412 } 3503 }
3413 3504
3414 void test_undefinedIdentifier_private_setter() { 3505 void test_undefinedIdentifier_private_setter() {
3415 addNamedSource("/lib.dart", r''' 3506 addNamedSource(
3507 "/lib.dart",
3508 r'''
3416 library lib; 3509 library lib;
3417 class A { 3510 class A {
3418 var _foo; 3511 var _foo;
3419 }'''); 3512 }''');
3420 Source source = addSource(r''' 3513 Source source = addSource(r'''
3421 import 'lib.dart'; 3514 import 'lib.dart';
3422 class B extends A { 3515 class B extends A {
3423 test() { 3516 test() {
3424 _foo = 42; 3517 _foo = 42;
3425 } 3518 }
3426 }'''); 3519 }''');
3427 computeLibrarySourceErrors(source); 3520 computeLibrarySourceErrors(source);
3428 assertErrors(source, [StaticWarningCode.UNDEFINED_IDENTIFIER]); 3521 assertErrors(source, [StaticWarningCode.UNDEFINED_IDENTIFIER]);
3429 } 3522 }
3430 3523
3431 void test_undefinedNamedParameter() { 3524 void test_undefinedNamedParameter() {
3432 Source source = addSource(r''' 3525 Source source = addSource(r'''
3433 f({a, b}) {} 3526 f({a, b}) {}
3434 main() { 3527 main() {
3435 f(c: 1); 3528 f(c: 1);
3436 }'''); 3529 }''');
3437 computeLibrarySourceErrors(source); 3530 computeLibrarySourceErrors(source);
3438 assertErrors(source, [StaticWarningCode.UNDEFINED_NAMED_PARAMETER]); 3531 assertErrors(source, [StaticWarningCode.UNDEFINED_NAMED_PARAMETER]);
3439 // no verify(), 'c' is not resolved 3532 // no verify(), 'c' is not resolved
3440 } 3533 }
3441 3534
3442 void test_undefinedSetter() { 3535 void test_undefinedSetter() {
3443 Source source1 = addNamedSource("lib.dart", ""); 3536 Source source1 = addNamedSource("/lib.dart", "");
3444 Source source2 = addNamedSource("lib2.dart", r''' 3537 Source source2 = addNamedSource(
3538 "/lib2.dart",
3539 r'''
3445 import 'lib.dart' as lib; 3540 import 'lib.dart' as lib;
3446 void f() { 3541 void f() {
3447 lib.gg = null; 3542 lib.gg = null;
3448 }'''); 3543 }''');
3449 computeLibrarySourceErrors(source1); 3544 computeLibrarySourceErrors(source1);
3450 computeLibrarySourceErrors(source2); 3545 computeLibrarySourceErrors(source2);
3451 assertErrors(source2, [StaticWarningCode.UNDEFINED_SETTER]); 3546 assertErrors(source2, [StaticWarningCode.UNDEFINED_SETTER]);
3452 } 3547 }
3453 3548
3454 void test_undefinedStaticMethodOrGetter_getter() { 3549 void test_undefinedStaticMethodOrGetter_getter() {
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
3512 3607
3513 void test_voidReturnForGetter() { 3608 void test_voidReturnForGetter() {
3514 Source source = addSource(r''' 3609 Source source = addSource(r'''
3515 class S { 3610 class S {
3516 void get value {} 3611 void get value {}
3517 }'''); 3612 }''');
3518 computeLibrarySourceErrors(source); 3613 computeLibrarySourceErrors(source);
3519 assertErrors(source, [StaticWarningCode.VOID_RETURN_FOR_GETTER]); 3614 assertErrors(source, [StaticWarningCode.VOID_RETURN_FOR_GETTER]);
3520 } 3615 }
3521 } 3616 }
OLDNEW
« no previous file with comments | « pkg/analyzer/test/generated/static_type_warning_code_test.dart ('k') | pkg/analyzer/test/generated/test_all.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698