OLD | NEW |
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.compile_time_error_code_test; | 5 library engine.compile_time_error_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/parser.dart' show ParserErrorCode; | 8 import 'package:analyzer/src/generated/parser.dart' show ParserErrorCode; |
9 import 'package:analyzer/src/generated/source_io.dart'; | 9 import 'package:analyzer/src/generated/source_io.dart'; |
10 import 'package:unittest/unittest.dart' as _ut; | 10 import 'package:unittest/unittest.dart' as _ut; |
11 | 11 |
12 import '../reflective_tests.dart'; | 12 import '../reflective_tests.dart'; |
13 import 'resolver_test.dart'; | 13 import 'resolver_test.dart'; |
14 | 14 |
15 main() { | 15 main() { |
16 _ut.groupSep = ' | '; | 16 _ut.groupSep = ' | '; |
17 runReflectiveTests(CompileTimeErrorCodeTest); | 17 runReflectiveTests(CompileTimeErrorCodeTest); |
18 } | 18 } |
19 | 19 |
20 @reflectiveTest | 20 @reflectiveTest |
21 class CompileTimeErrorCodeTest extends ResolverTestCase { | 21 class CompileTimeErrorCodeTest extends ResolverTestCase { |
| 22 /** |
| 23 * Computes errors for the given [librarySource]. |
| 24 * This assumes that the given [librarySource] and its parts have already |
| 25 * been added to the content provider using the method [addNamedSource]. |
| 26 */ |
| 27 void computeLibrarySourceErrors(Source librarySource) { |
| 28 analysisContext.computeErrors(librarySource); |
| 29 } |
| 30 |
22 void fail_awaitInWrongContext_sync() { | 31 void fail_awaitInWrongContext_sync() { |
23 // This test requires better error recovery than we currently have. In | 32 // This test requires better error recovery than we currently have. In |
24 // particular, we need to be able to distinguish between an await expression | 33 // particular, we need to be able to distinguish between an await expression |
25 // in the wrong context, and the use of 'await' as an identifier. | 34 // in the wrong context, and the use of 'await' as an identifier. |
26 Source source = addSource(r''' | 35 Source source = addSource(r''' |
27 f(x) { | 36 f(x) { |
28 return await x; | 37 return await x; |
29 }'''); | 38 }'''); |
30 resolve(source); | 39 computeLibrarySourceErrors(source); |
31 assertErrors(source, [CompileTimeErrorCode.AWAIT_IN_WRONG_CONTEXT]); | 40 assertErrors(source, [CompileTimeErrorCode.AWAIT_IN_WRONG_CONTEXT]); |
32 verify([source]); | 41 verify([source]); |
33 } | 42 } |
34 | 43 |
35 void fail_awaitInWrongContext_syncStar() { | 44 void fail_awaitInWrongContext_syncStar() { |
36 // This test requires better error recovery than we currently have. In | 45 // This test requires better error recovery than we currently have. In |
37 // particular, we need to be able to distinguish between an await expression | 46 // particular, we need to be able to distinguish between an await expression |
38 // in the wrong context, and the use of 'await' as an identifier. | 47 // in the wrong context, and the use of 'await' as an identifier. |
39 Source source = addSource(r''' | 48 Source source = addSource(r''' |
40 f(x) sync* { | 49 f(x) sync* { |
41 yield await x; | 50 yield await x; |
42 }'''); | 51 }'''); |
43 resolve(source); | 52 computeLibrarySourceErrors(source); |
44 assertErrors(source, [CompileTimeErrorCode.AWAIT_IN_WRONG_CONTEXT]); | 53 assertErrors(source, [CompileTimeErrorCode.AWAIT_IN_WRONG_CONTEXT]); |
45 verify([source]); | 54 verify([source]); |
46 } | 55 } |
47 | 56 |
48 void fail_compileTimeConstantRaisesException() { | 57 void fail_compileTimeConstantRaisesException() { |
49 Source source = addSource(r''' | 58 Source source = addSource(r''' |
50 '''); | 59 '''); |
51 resolve(source); | 60 computeLibrarySourceErrors(source); |
52 assertErrors( | 61 assertErrors( |
53 source, [CompileTimeErrorCode.COMPILE_TIME_CONSTANT_RAISES_EXCEPTION]); | 62 source, [CompileTimeErrorCode.COMPILE_TIME_CONSTANT_RAISES_EXCEPTION]); |
54 verify([source]); | 63 verify([source]); |
55 } | 64 } |
56 | 65 |
57 void fail_constEvalThrowsException() { | 66 void fail_constEvalThrowsException() { |
58 Source source = addSource(r''' | 67 Source source = addSource(r''' |
59 class C { | 68 class C { |
60 const C(); | 69 const C(); |
61 } | 70 } |
62 f() { return const C(); }'''); | 71 f() { return const C(); }'''); |
63 resolve(source); | 72 computeLibrarySourceErrors(source); |
64 assertErrors( | 73 assertErrors( |
65 source, [CompileTimeErrorCode.CONST_CONSTRUCTOR_THROWS_EXCEPTION]); | 74 source, [CompileTimeErrorCode.CONST_CONSTRUCTOR_THROWS_EXCEPTION]); |
66 verify([source]); | 75 verify([source]); |
67 } | 76 } |
68 | 77 |
69 void fail_invalidIdentifierInAsync_async() { | 78 void fail_invalidIdentifierInAsync_async() { |
70 // TODO(brianwilkerson) Report this error. | 79 // TODO(brianwilkerson) Report this error. |
71 Source source = addSource(r''' | 80 Source source = addSource(r''' |
72 class A { | 81 class A { |
73 m() async { | 82 m() async { |
74 int async; | 83 int async; |
75 } | 84 } |
76 }'''); | 85 }'''); |
77 resolve(source); | 86 computeLibrarySourceErrors(source); |
78 assertErrors(source, [CompileTimeErrorCode.INVALID_IDENTIFIER_IN_ASYNC]); | 87 assertErrors(source, [CompileTimeErrorCode.INVALID_IDENTIFIER_IN_ASYNC]); |
79 verify([source]); | 88 verify([source]); |
80 } | 89 } |
81 | 90 |
82 void fail_invalidIdentifierInAsync_await() { | 91 void fail_invalidIdentifierInAsync_await() { |
83 // TODO(brianwilkerson) Report this error. | 92 // TODO(brianwilkerson) Report this error. |
84 Source source = addSource(r''' | 93 Source source = addSource(r''' |
85 class A { | 94 class A { |
86 m() async { | 95 m() async { |
87 int await; | 96 int await; |
88 } | 97 } |
89 }'''); | 98 }'''); |
90 resolve(source); | 99 computeLibrarySourceErrors(source); |
91 assertErrors(source, [CompileTimeErrorCode.INVALID_IDENTIFIER_IN_ASYNC]); | 100 assertErrors(source, [CompileTimeErrorCode.INVALID_IDENTIFIER_IN_ASYNC]); |
92 verify([source]); | 101 verify([source]); |
93 } | 102 } |
94 | 103 |
95 void fail_invalidIdentifierInAsync_yield() { | 104 void fail_invalidIdentifierInAsync_yield() { |
96 // TODO(brianwilkerson) Report this error. | 105 // TODO(brianwilkerson) Report this error. |
97 Source source = addSource(r''' | 106 Source source = addSource(r''' |
98 class A { | 107 class A { |
99 m() async { | 108 m() async { |
100 int yield; | 109 int yield; |
101 } | 110 } |
102 }'''); | 111 }'''); |
103 resolve(source); | 112 computeLibrarySourceErrors(source); |
104 assertErrors(source, [CompileTimeErrorCode.INVALID_IDENTIFIER_IN_ASYNC]); | 113 assertErrors(source, [CompileTimeErrorCode.INVALID_IDENTIFIER_IN_ASYNC]); |
105 verify([source]); | 114 verify([source]); |
106 } | 115 } |
107 | 116 |
108 void fail_mixinDeclaresConstructor() { | 117 void fail_mixinDeclaresConstructor() { |
109 Source source = addSource(r''' | 118 Source source = addSource(r''' |
110 class A { | 119 class A { |
111 A() {} | 120 A() {} |
112 } | 121 } |
113 class B extends Object mixin A {}'''); | 122 class B extends Object mixin A {}'''); |
114 resolve(source); | 123 computeLibrarySourceErrors(source); |
115 assertErrors(source, [CompileTimeErrorCode.MIXIN_DECLARES_CONSTRUCTOR]); | 124 assertErrors(source, [CompileTimeErrorCode.MIXIN_DECLARES_CONSTRUCTOR]); |
116 verify([source]); | 125 verify([source]); |
117 } | 126 } |
118 | 127 |
119 void fail_mixinOfNonClass() { | 128 void fail_mixinOfNonClass() { |
120 // TODO(brianwilkerson) Compare with MIXIN_WITH_NON_CLASS_SUPERCLASS. | 129 // TODO(brianwilkerson) Compare with MIXIN_WITH_NON_CLASS_SUPERCLASS. |
121 Source source = addSource(r''' | 130 Source source = addSource(r''' |
122 var A; | 131 var A; |
123 class B extends Object mixin A {}'''); | 132 class B extends Object mixin A {}'''); |
124 resolve(source); | 133 computeLibrarySourceErrors(source); |
125 assertErrors(source, [CompileTimeErrorCode.MIXIN_OF_NON_CLASS]); | 134 assertErrors(source, [CompileTimeErrorCode.MIXIN_OF_NON_CLASS]); |
126 verify([source]); | 135 verify([source]); |
127 } | 136 } |
128 | 137 |
129 void fail_objectCannotExtendAnotherClass() { | 138 void fail_objectCannotExtendAnotherClass() { |
130 Source source = addSource(r''' | 139 Source source = addSource(r''' |
131 '''); | 140 '''); |
132 resolve(source); | 141 computeLibrarySourceErrors(source); |
133 assertErrors( | 142 assertErrors( |
134 source, [CompileTimeErrorCode.OBJECT_CANNOT_EXTEND_ANOTHER_CLASS]); | 143 source, [CompileTimeErrorCode.OBJECT_CANNOT_EXTEND_ANOTHER_CLASS]); |
135 verify([source]); | 144 verify([source]); |
136 } | 145 } |
137 | 146 |
138 void fail_superInitializerInObject() { | 147 void fail_superInitializerInObject() { |
139 Source source = addSource(r''' | 148 Source source = addSource(r''' |
140 '''); | 149 '''); |
141 resolve(source); | 150 computeLibrarySourceErrors(source); |
142 assertErrors(source, [CompileTimeErrorCode.SUPER_INITIALIZER_IN_OBJECT]); | 151 assertErrors(source, [CompileTimeErrorCode.SUPER_INITIALIZER_IN_OBJECT]); |
143 verify([source]); | 152 verify([source]); |
144 } | 153 } |
145 | 154 |
146 void fail_yieldEachInNonGenerator_async() { | 155 void fail_yieldEachInNonGenerator_async() { |
147 // TODO(brianwilkerson) We are currently parsing the yield statement as a | 156 // TODO(brianwilkerson) We are currently parsing the yield statement as a |
148 // binary expression. | 157 // binary expression. |
149 Source source = addSource(r''' | 158 Source source = addSource(r''' |
150 f() async { | 159 f() async { |
151 yield* 0; | 160 yield* 0; |
152 }'''); | 161 }'''); |
153 resolve(source); | 162 computeLibrarySourceErrors(source); |
154 assertErrors(source, [CompileTimeErrorCode.YIELD_EACH_IN_NON_GENERATOR]); | 163 assertErrors(source, [CompileTimeErrorCode.YIELD_EACH_IN_NON_GENERATOR]); |
155 verify([source]); | 164 verify([source]); |
156 } | 165 } |
157 | 166 |
158 void fail_yieldEachInNonGenerator_sync() { | 167 void fail_yieldEachInNonGenerator_sync() { |
159 // TODO(brianwilkerson) We are currently parsing the yield statement as a | 168 // TODO(brianwilkerson) We are currently parsing the yield statement as a |
160 // binary expression. | 169 // binary expression. |
161 Source source = addSource(r''' | 170 Source source = addSource(r''' |
162 f() { | 171 f() { |
163 yield* 0; | 172 yield* 0; |
164 }'''); | 173 }'''); |
165 resolve(source); | 174 computeLibrarySourceErrors(source); |
166 assertErrors(source, [CompileTimeErrorCode.YIELD_IN_NON_GENERATOR]); | 175 assertErrors(source, [CompileTimeErrorCode.YIELD_IN_NON_GENERATOR]); |
167 verify([source]); | 176 verify([source]); |
168 } | 177 } |
169 | 178 |
170 void fail_yieldInNonGenerator_async() { | 179 void fail_yieldInNonGenerator_async() { |
171 // TODO(brianwilkerson) We are currently trying to parse the yield statement | 180 // TODO(brianwilkerson) We are currently trying to parse the yield statement |
172 // as a binary expression. | 181 // as a binary expression. |
173 Source source = addSource(r''' | 182 Source source = addSource(r''' |
174 f() async { | 183 f() async { |
175 yield 0; | 184 yield 0; |
176 }'''); | 185 }'''); |
177 resolve(source); | 186 computeLibrarySourceErrors(source); |
178 assertErrors(source, [CompileTimeErrorCode.YIELD_IN_NON_GENERATOR]); | 187 assertErrors(source, [CompileTimeErrorCode.YIELD_IN_NON_GENERATOR]); |
179 verify([source]); | 188 verify([source]); |
180 } | 189 } |
181 | 190 |
182 void fail_yieldInNonGenerator_sync() { | 191 void fail_yieldInNonGenerator_sync() { |
183 // TODO(brianwilkerson) We are currently trying to parse the yield statement | 192 // TODO(brianwilkerson) We are currently trying to parse the yield statement |
184 // as a binary expression. | 193 // as a binary expression. |
185 Source source = addSource(r''' | 194 Source source = addSource(r''' |
186 f() { | 195 f() { |
187 yield 0; | 196 yield 0; |
188 }'''); | 197 }'''); |
189 resolve(source); | 198 computeLibrarySourceErrors(source); |
190 assertErrors(source, [CompileTimeErrorCode.YIELD_EACH_IN_NON_GENERATOR]); | 199 assertErrors(source, [CompileTimeErrorCode.YIELD_EACH_IN_NON_GENERATOR]); |
191 verify([source]); | 200 verify([source]); |
192 } | 201 } |
193 | 202 |
194 void test_accessPrivateEnumField() { | 203 void test_accessPrivateEnumField() { |
195 Source source = addSource(r''' | 204 Source source = addSource(r''' |
196 enum E { ONE } | 205 enum E { ONE } |
197 String name(E e) { | 206 String name(E e) { |
198 return e._name; | 207 return e._name; |
199 }'''); | 208 }'''); |
200 resolve(source); | 209 computeLibrarySourceErrors(source); |
201 assertErrors(source, [CompileTimeErrorCode.ACCESS_PRIVATE_ENUM_FIELD]); | 210 assertErrors(source, [CompileTimeErrorCode.ACCESS_PRIVATE_ENUM_FIELD]); |
202 // Cannot verify because "_name" cannot be resolved. | 211 // Cannot verify because "_name" cannot be resolved. |
203 } | 212 } |
204 | 213 |
205 void test_ambiguousExport() { | 214 void test_ambiguousExport() { |
206 Source source = addSource(r''' | 215 Source source = addSource(r''' |
207 library L; | 216 library L; |
208 export 'lib1.dart'; | 217 export 'lib1.dart'; |
209 export 'lib2.dart';'''); | 218 export 'lib2.dart';'''); |
210 addNamedSource("/lib1.dart", r''' | 219 addNamedSource("/lib1.dart", r''' |
211 library lib1; | 220 library lib1; |
212 class N {}'''); | 221 class N {}'''); |
213 addNamedSource("/lib2.dart", r''' | 222 addNamedSource("/lib2.dart", r''' |
214 library lib2; | 223 library lib2; |
215 class N {}'''); | 224 class N {}'''); |
216 resolve(source); | 225 computeLibrarySourceErrors(source); |
217 assertErrors(source, [CompileTimeErrorCode.AMBIGUOUS_EXPORT]); | 226 assertErrors(source, [CompileTimeErrorCode.AMBIGUOUS_EXPORT]); |
218 verify([source]); | 227 verify([source]); |
219 } | 228 } |
220 | 229 |
221 void test_async_used_as_identifier_in_annotation() { | 230 void test_async_used_as_identifier_in_annotation() { |
222 Source source = addSource(''' | 231 Source source = addSource(''' |
223 const int async = 0; | 232 const int async = 0; |
224 f() async { | 233 f() async { |
225 g(@async x) {} | 234 g(@async x) {} |
226 g(0); | 235 g(0); |
227 } | 236 } |
228 '''); | 237 '''); |
229 resolve(source); | 238 computeLibrarySourceErrors(source); |
230 assertErrors(source, [ParserErrorCode.ASYNC_KEYWORD_USED_AS_IDENTIFIER]); | 239 assertErrors(source, [ParserErrorCode.ASYNC_KEYWORD_USED_AS_IDENTIFIER]); |
231 verify([source]); | 240 verify([source]); |
232 } | 241 } |
233 | 242 |
234 void test_async_used_as_identifier_in_argument_label() { | 243 void test_async_used_as_identifier_in_argument_label() { |
235 Source source = addSource(''' | 244 Source source = addSource(''' |
236 @proxy | 245 @proxy |
237 class C {} | 246 class C {} |
238 f() async { | 247 f() async { |
239 new C().g(async: 0); | 248 new C().g(async: 0); |
240 } | 249 } |
241 '''); | 250 '''); |
242 resolve(source); | 251 computeLibrarySourceErrors(source); |
243 assertErrors(source, [ParserErrorCode.ASYNC_KEYWORD_USED_AS_IDENTIFIER]); | 252 assertErrors(source, [ParserErrorCode.ASYNC_KEYWORD_USED_AS_IDENTIFIER]); |
244 // Note: we don't call verify([source]) because verify() doesn't understand | 253 // Note: we don't call verify([source]) because verify() doesn't understand |
245 // about @proxy. | 254 // about @proxy. |
246 } | 255 } |
247 | 256 |
248 void test_async_used_as_identifier_in_async_method() { | 257 void test_async_used_as_identifier_in_async_method() { |
249 Source source = addSource(''' | 258 Source source = addSource(''' |
250 f() async { | 259 f() async { |
251 var async = 1; | 260 var async = 1; |
252 } | 261 } |
253 '''); | 262 '''); |
254 resolve(source); | 263 computeLibrarySourceErrors(source); |
255 assertErrors(source, [ParserErrorCode.ASYNC_KEYWORD_USED_AS_IDENTIFIER]); | 264 assertErrors(source, [ParserErrorCode.ASYNC_KEYWORD_USED_AS_IDENTIFIER]); |
256 verify([source]); | 265 verify([source]); |
257 } | 266 } |
258 | 267 |
259 void test_async_used_as_identifier_in_async_star_method() { | 268 void test_async_used_as_identifier_in_async_star_method() { |
260 Source source = addSource(''' | 269 Source source = addSource(''' |
261 f() async* { | 270 f() async* { |
262 var async = 1; | 271 var async = 1; |
263 } | 272 } |
264 '''); | 273 '''); |
265 resolve(source); | 274 computeLibrarySourceErrors(source); |
266 assertErrors(source, [ParserErrorCode.ASYNC_KEYWORD_USED_AS_IDENTIFIER]); | 275 assertErrors(source, [ParserErrorCode.ASYNC_KEYWORD_USED_AS_IDENTIFIER]); |
267 verify([source]); | 276 verify([source]); |
268 } | 277 } |
269 | 278 |
270 void test_async_used_as_identifier_in_break_statement() { | 279 void test_async_used_as_identifier_in_break_statement() { |
271 Source source = addSource(''' | 280 Source source = addSource(''' |
272 f() async { | 281 f() async { |
273 while (true) { | 282 while (true) { |
274 break async; | 283 break async; |
275 } | 284 } |
276 } | 285 } |
277 '''); | 286 '''); |
278 resolve(source); | 287 computeLibrarySourceErrors(source); |
279 assertErrors(source, [ | 288 assertErrors(source, [ |
280 ParserErrorCode.ASYNC_KEYWORD_USED_AS_IDENTIFIER, | 289 ParserErrorCode.ASYNC_KEYWORD_USED_AS_IDENTIFIER, |
281 CompileTimeErrorCode.LABEL_UNDEFINED | 290 CompileTimeErrorCode.LABEL_UNDEFINED |
282 ]); | 291 ]); |
283 // Note: we don't call verify([source]) because the reference to the | 292 // Note: we don't call verify([source]) because the reference to the |
284 // "async" label is unresolved. | 293 // "async" label is unresolved. |
285 } | 294 } |
286 | 295 |
287 void test_async_used_as_identifier_in_cascaded_invocation() { | 296 void test_async_used_as_identifier_in_cascaded_invocation() { |
288 Source source = addSource(''' | 297 Source source = addSource(''' |
289 class C { | 298 class C { |
290 int async() => 1; | 299 int async() => 1; |
291 } | 300 } |
292 f() async { | 301 f() async { |
293 return new C()..async(); | 302 return new C()..async(); |
294 } | 303 } |
295 '''); | 304 '''); |
296 resolve(source); | 305 computeLibrarySourceErrors(source); |
297 assertErrors(source, [ParserErrorCode.ASYNC_KEYWORD_USED_AS_IDENTIFIER]); | 306 assertErrors(source, [ParserErrorCode.ASYNC_KEYWORD_USED_AS_IDENTIFIER]); |
298 verify([source]); | 307 verify([source]); |
299 } | 308 } |
300 | 309 |
301 void test_async_used_as_identifier_in_cascaded_setter_invocation() { | 310 void test_async_used_as_identifier_in_cascaded_setter_invocation() { |
302 Source source = addSource(''' | 311 Source source = addSource(''' |
303 class C { | 312 class C { |
304 void set async(int i) {} | 313 void set async(int i) {} |
305 } | 314 } |
306 f() async { | 315 f() async { |
307 return new C()..async = 1; | 316 return new C()..async = 1; |
308 } | 317 } |
309 '''); | 318 '''); |
310 resolve(source); | 319 computeLibrarySourceErrors(source); |
311 assertErrors(source, [ParserErrorCode.ASYNC_KEYWORD_USED_AS_IDENTIFIER]); | 320 assertErrors(source, [ParserErrorCode.ASYNC_KEYWORD_USED_AS_IDENTIFIER]); |
312 verify([source]); | 321 verify([source]); |
313 } | 322 } |
314 | 323 |
315 void test_async_used_as_identifier_in_catch_exception_argument() { | 324 void test_async_used_as_identifier_in_catch_exception_argument() { |
316 Source source = addSource(''' | 325 Source source = addSource(''' |
317 g() {} | 326 g() {} |
318 f() async { | 327 f() async { |
319 try { | 328 try { |
320 g(); | 329 g(); |
321 } catch (async) { } | 330 } catch (async) { } |
322 } | 331 } |
323 '''); | 332 '''); |
324 resolve(source); | 333 computeLibrarySourceErrors(source); |
325 assertErrors(source, [ParserErrorCode.ASYNC_KEYWORD_USED_AS_IDENTIFIER]); | 334 assertErrors(source, [ParserErrorCode.ASYNC_KEYWORD_USED_AS_IDENTIFIER]); |
326 verify([source]); | 335 verify([source]); |
327 } | 336 } |
328 | 337 |
329 void test_async_used_as_identifier_in_catch_stacktrace_argument() { | 338 void test_async_used_as_identifier_in_catch_stacktrace_argument() { |
330 Source source = addSource(''' | 339 Source source = addSource(''' |
331 g() {} | 340 g() {} |
332 f() async { | 341 f() async { |
333 try { | 342 try { |
334 g(); | 343 g(); |
335 } catch (e, async) { } | 344 } catch (e, async) { } |
336 } | 345 } |
337 '''); | 346 '''); |
338 resolve(source); | 347 computeLibrarySourceErrors(source); |
339 assertErrors(source, [ParserErrorCode.ASYNC_KEYWORD_USED_AS_IDENTIFIER]); | 348 assertErrors(source, [ParserErrorCode.ASYNC_KEYWORD_USED_AS_IDENTIFIER]); |
340 verify([source]); | 349 verify([source]); |
341 } | 350 } |
342 | 351 |
343 void test_async_used_as_identifier_in_continue_statement() { | 352 void test_async_used_as_identifier_in_continue_statement() { |
344 Source source = addSource(''' | 353 Source source = addSource(''' |
345 f() async { | 354 f() async { |
346 while (true) { | 355 while (true) { |
347 continue async; | 356 continue async; |
348 } | 357 } |
349 } | 358 } |
350 '''); | 359 '''); |
351 resolve(source); | 360 computeLibrarySourceErrors(source); |
352 assertErrors(source, [ | 361 assertErrors(source, [ |
353 ParserErrorCode.ASYNC_KEYWORD_USED_AS_IDENTIFIER, | 362 ParserErrorCode.ASYNC_KEYWORD_USED_AS_IDENTIFIER, |
354 CompileTimeErrorCode.LABEL_UNDEFINED | 363 CompileTimeErrorCode.LABEL_UNDEFINED |
355 ]); | 364 ]); |
356 // Note: we don't call verify([source]) because the reference to the | 365 // Note: we don't call verify([source]) because the reference to the |
357 // "async" label is unresolved. | 366 // "async" label is unresolved. |
358 } | 367 } |
359 | 368 |
360 void test_async_used_as_identifier_in_for_statement() { | 369 void test_async_used_as_identifier_in_for_statement() { |
361 Source source = addSource(''' | 370 Source source = addSource(''' |
362 var async; | 371 var async; |
363 f() async { | 372 f() async { |
364 for (async in []) {} | 373 for (async in []) {} |
365 } | 374 } |
366 '''); | 375 '''); |
367 resolve(source); | 376 computeLibrarySourceErrors(source); |
368 assertErrors(source, [ParserErrorCode.ASYNC_KEYWORD_USED_AS_IDENTIFIER]); | 377 assertErrors(source, [ParserErrorCode.ASYNC_KEYWORD_USED_AS_IDENTIFIER]); |
369 verify([source]); | 378 verify([source]); |
370 } | 379 } |
371 | 380 |
372 void test_async_used_as_identifier_in_formal_parameter_name() { | 381 void test_async_used_as_identifier_in_formal_parameter_name() { |
373 Source source = addSource(''' | 382 Source source = addSource(''' |
374 f() async { | 383 f() async { |
375 g(int async) {} | 384 g(int async) {} |
376 g(0); | 385 g(0); |
377 } | 386 } |
378 '''); | 387 '''); |
379 resolve(source); | 388 computeLibrarySourceErrors(source); |
380 assertErrors(source, [ParserErrorCode.ASYNC_KEYWORD_USED_AS_IDENTIFIER]); | 389 assertErrors(source, [ParserErrorCode.ASYNC_KEYWORD_USED_AS_IDENTIFIER]); |
381 verify([source]); | 390 verify([source]); |
382 } | 391 } |
383 | 392 |
384 void test_async_used_as_identifier_in_getter_name() { | 393 void test_async_used_as_identifier_in_getter_name() { |
385 Source source = addSource(''' | 394 Source source = addSource(''' |
386 class C { | 395 class C { |
387 int get async => 1; | 396 int get async => 1; |
388 } | 397 } |
389 f() async { | 398 f() async { |
390 return new C().async; | 399 return new C().async; |
391 } | 400 } |
392 '''); | 401 '''); |
393 resolve(source); | 402 computeLibrarySourceErrors(source); |
394 assertErrors(source, [ParserErrorCode.ASYNC_KEYWORD_USED_AS_IDENTIFIER]); | 403 assertErrors(source, [ParserErrorCode.ASYNC_KEYWORD_USED_AS_IDENTIFIER]); |
395 verify([source]); | 404 verify([source]); |
396 } | 405 } |
397 | 406 |
398 void test_async_used_as_identifier_in_invocation() { | 407 void test_async_used_as_identifier_in_invocation() { |
399 Source source = addSource(''' | 408 Source source = addSource(''' |
400 class C { | 409 class C { |
401 int async() => 1; | 410 int async() => 1; |
402 } | 411 } |
403 f() async { | 412 f() async { |
404 return new C().async(); | 413 return new C().async(); |
405 } | 414 } |
406 '''); | 415 '''); |
407 resolve(source); | 416 computeLibrarySourceErrors(source); |
408 assertErrors(source, [ParserErrorCode.ASYNC_KEYWORD_USED_AS_IDENTIFIER]); | 417 assertErrors(source, [ParserErrorCode.ASYNC_KEYWORD_USED_AS_IDENTIFIER]); |
409 verify([source]); | 418 verify([source]); |
410 } | 419 } |
411 | 420 |
412 void test_async_used_as_identifier_in_local_function_name() { | 421 void test_async_used_as_identifier_in_local_function_name() { |
413 Source source = addSource(''' | 422 Source source = addSource(''' |
414 f() async { | 423 f() async { |
415 int async() => null; | 424 int async() => null; |
416 } | 425 } |
417 '''); | 426 '''); |
418 resolve(source); | 427 computeLibrarySourceErrors(source); |
419 assertErrors(source, [ParserErrorCode.ASYNC_KEYWORD_USED_AS_IDENTIFIER]); | 428 assertErrors(source, [ParserErrorCode.ASYNC_KEYWORD_USED_AS_IDENTIFIER]); |
420 verify([source]); | 429 verify([source]); |
421 } | 430 } |
422 | 431 |
423 void test_async_used_as_identifier_in_prefix() { | 432 void test_async_used_as_identifier_in_prefix() { |
424 Source source = addSource(''' | 433 Source source = addSource(''' |
425 import 'dart:async' as async; | 434 import 'dart:async' as async; |
426 f() async { | 435 f() async { |
427 return new async.Future.value(0); | 436 return new async.Future.value(0); |
428 } | 437 } |
429 '''); | 438 '''); |
430 resolve(source); | 439 computeLibrarySourceErrors(source); |
431 assertErrors(source, [ParserErrorCode.ASYNC_KEYWORD_USED_AS_IDENTIFIER]); | 440 assertErrors(source, [ParserErrorCode.ASYNC_KEYWORD_USED_AS_IDENTIFIER]); |
432 verify([source]); | 441 verify([source]); |
433 } | 442 } |
434 | 443 |
435 void test_async_used_as_identifier_in_setter_name() { | 444 void test_async_used_as_identifier_in_setter_name() { |
436 Source source = addSource(''' | 445 Source source = addSource(''' |
437 class C { | 446 class C { |
438 void set async(int i) {} | 447 void set async(int i) {} |
439 } | 448 } |
440 f() async { | 449 f() async { |
441 new C().async = 1; | 450 new C().async = 1; |
442 } | 451 } |
443 '''); | 452 '''); |
444 resolve(source); | 453 computeLibrarySourceErrors(source); |
445 assertErrors(source, [ParserErrorCode.ASYNC_KEYWORD_USED_AS_IDENTIFIER]); | 454 assertErrors(source, [ParserErrorCode.ASYNC_KEYWORD_USED_AS_IDENTIFIER]); |
446 verify([source]); | 455 verify([source]); |
447 } | 456 } |
448 | 457 |
449 void test_async_used_as_identifier_in_statement_label() { | 458 void test_async_used_as_identifier_in_statement_label() { |
450 Source source = addSource(''' | 459 Source source = addSource(''' |
451 f() async { | 460 f() async { |
452 async: g(); | 461 async: g(); |
453 } | 462 } |
454 g() {} | 463 g() {} |
455 '''); | 464 '''); |
456 resolve(source); | 465 computeLibrarySourceErrors(source); |
457 assertErrors(source, [ParserErrorCode.ASYNC_KEYWORD_USED_AS_IDENTIFIER]); | 466 assertErrors(source, [ParserErrorCode.ASYNC_KEYWORD_USED_AS_IDENTIFIER]); |
458 verify([source]); | 467 verify([source]); |
459 } | 468 } |
460 | 469 |
461 void test_async_used_as_identifier_in_string_interpolation() { | 470 void test_async_used_as_identifier_in_string_interpolation() { |
462 Source source = addSource(r''' | 471 Source source = addSource(r''' |
463 int async = 1; | 472 int async = 1; |
464 f() async { | 473 f() async { |
465 return "$async"; | 474 return "$async"; |
466 } | 475 } |
467 '''); | 476 '''); |
468 resolve(source); | 477 computeLibrarySourceErrors(source); |
469 assertErrors(source, [ParserErrorCode.ASYNC_KEYWORD_USED_AS_IDENTIFIER]); | 478 assertErrors(source, [ParserErrorCode.ASYNC_KEYWORD_USED_AS_IDENTIFIER]); |
470 verify([source]); | 479 verify([source]); |
471 } | 480 } |
472 | 481 |
473 void test_async_used_as_identifier_in_suffix() { | 482 void test_async_used_as_identifier_in_suffix() { |
474 addNamedSource("/lib1.dart", r''' | 483 addNamedSource("/lib1.dart", r''' |
475 library lib1; | 484 library lib1; |
476 int async; | 485 int async; |
477 '''); | 486 '''); |
478 Source source = addSource(''' | 487 Source source = addSource(''' |
479 import 'lib1.dart' as l; | 488 import 'lib1.dart' as l; |
480 f() async { | 489 f() async { |
481 return l.async; | 490 return l.async; |
482 } | 491 } |
483 '''); | 492 '''); |
484 resolve(source); | 493 computeLibrarySourceErrors(source); |
485 assertErrors(source, [ParserErrorCode.ASYNC_KEYWORD_USED_AS_IDENTIFIER]); | 494 assertErrors(source, [ParserErrorCode.ASYNC_KEYWORD_USED_AS_IDENTIFIER]); |
486 verify([source]); | 495 verify([source]); |
487 } | 496 } |
488 | 497 |
489 void test_async_used_as_identifier_in_switch_label() { | 498 void test_async_used_as_identifier_in_switch_label() { |
490 Source source = addSource(''' | 499 Source source = addSource(''' |
491 f() async { | 500 f() async { |
492 switch (0) { | 501 switch (0) { |
493 async: case 0: break; | 502 async: case 0: break; |
494 } | 503 } |
495 } | 504 } |
496 '''); | 505 '''); |
497 resolve(source); | 506 computeLibrarySourceErrors(source); |
498 assertErrors(source, [ParserErrorCode.ASYNC_KEYWORD_USED_AS_IDENTIFIER]); | 507 assertErrors(source, [ParserErrorCode.ASYNC_KEYWORD_USED_AS_IDENTIFIER]); |
499 verify([source]); | 508 verify([source]); |
500 } | 509 } |
501 | 510 |
502 void test_async_used_as_identifier_in_sync_star_method() { | 511 void test_async_used_as_identifier_in_sync_star_method() { |
503 Source source = addSource(''' | 512 Source source = addSource(''' |
504 f() sync* { | 513 f() sync* { |
505 var async = 1; | 514 var async = 1; |
506 } | 515 } |
507 '''); | 516 '''); |
508 resolve(source); | 517 computeLibrarySourceErrors(source); |
509 assertErrors(source, [ParserErrorCode.ASYNC_KEYWORD_USED_AS_IDENTIFIER]); | 518 assertErrors(source, [ParserErrorCode.ASYNC_KEYWORD_USED_AS_IDENTIFIER]); |
510 verify([source]); | 519 verify([source]); |
511 } | 520 } |
512 | 521 |
513 void test_asyncForInWrongContext() { | 522 void test_asyncForInWrongContext() { |
514 Source source = addSource(r''' | 523 Source source = addSource(r''' |
515 f(list) { | 524 f(list) { |
516 await for (var e in list) { | 525 await for (var e in list) { |
517 } | 526 } |
518 }'''); | 527 }'''); |
519 resolve(source); | 528 computeLibrarySourceErrors(source); |
520 assertErrors(source, [CompileTimeErrorCode.ASYNC_FOR_IN_WRONG_CONTEXT]); | 529 assertErrors(source, [CompileTimeErrorCode.ASYNC_FOR_IN_WRONG_CONTEXT]); |
521 verify([source]); | 530 verify([source]); |
522 } | 531 } |
523 | 532 |
524 void test_await_used_as_identifier_in_async_method() { | 533 void test_await_used_as_identifier_in_async_method() { |
525 Source source = addSource(''' | 534 Source source = addSource(''' |
526 f() async { | 535 f() async { |
527 var await = 1; | 536 var await = 1; |
528 } | 537 } |
529 '''); | 538 '''); |
530 resolve(source); | 539 computeLibrarySourceErrors(source); |
531 assertErrors(source, [ParserErrorCode.ASYNC_KEYWORD_USED_AS_IDENTIFIER]); | 540 assertErrors(source, [ParserErrorCode.ASYNC_KEYWORD_USED_AS_IDENTIFIER]); |
532 verify([source]); | 541 verify([source]); |
533 } | 542 } |
534 | 543 |
535 void test_await_used_as_identifier_in_async_star_method() { | 544 void test_await_used_as_identifier_in_async_star_method() { |
536 Source source = addSource(''' | 545 Source source = addSource(''' |
537 f() async* { | 546 f() async* { |
538 var await = 1; | 547 var await = 1; |
539 } | 548 } |
540 '''); | 549 '''); |
541 resolve(source); | 550 computeLibrarySourceErrors(source); |
542 assertErrors(source, [ParserErrorCode.ASYNC_KEYWORD_USED_AS_IDENTIFIER]); | 551 assertErrors(source, [ParserErrorCode.ASYNC_KEYWORD_USED_AS_IDENTIFIER]); |
543 verify([source]); | 552 verify([source]); |
544 } | 553 } |
545 | 554 |
546 void test_await_used_as_identifier_in_sync_star_method() { | 555 void test_await_used_as_identifier_in_sync_star_method() { |
547 Source source = addSource(''' | 556 Source source = addSource(''' |
548 f() sync* { | 557 f() sync* { |
549 var await = 1; | 558 var await = 1; |
550 } | 559 } |
551 '''); | 560 '''); |
552 resolve(source); | 561 computeLibrarySourceErrors(source); |
553 assertErrors(source, [ParserErrorCode.ASYNC_KEYWORD_USED_AS_IDENTIFIER]); | 562 assertErrors(source, [ParserErrorCode.ASYNC_KEYWORD_USED_AS_IDENTIFIER]); |
554 verify([source]); | 563 verify([source]); |
555 } | 564 } |
556 | 565 |
557 void test_bug_23176() { | 566 void test_bug_23176() { |
558 Source source = addSource(''' | 567 Source source = addSource(''' |
559 class A { | 568 class A { |
560 const A([x]); | 569 const A([x]); |
561 } | 570 } |
562 class B { | 571 class B { |
563 dynamic @A(const A()) x; | 572 dynamic @A(const A()) x; |
564 } | 573 } |
565 '''); | 574 '''); |
566 resolve(source); | 575 computeLibrarySourceErrors(source); |
567 assertErrors(source, [ | 576 assertErrors(source, [ |
568 ParserErrorCode.EXPECTED_CLASS_MEMBER, | 577 ParserErrorCode.EXPECTED_CLASS_MEMBER, |
569 ParserErrorCode.MISSING_CONST_FINAL_VAR_OR_TYPE | 578 ParserErrorCode.MISSING_CONST_FINAL_VAR_OR_TYPE |
570 ]); | 579 ]); |
571 verify([source]); | 580 verify([source]); |
572 } | 581 } |
573 | 582 |
574 void test_builtInIdentifierAsMixinName_classTypeAlias() { | 583 void test_builtInIdentifierAsMixinName_classTypeAlias() { |
575 Source source = addSource(r''' | 584 Source source = addSource(r''' |
576 class A {} | 585 class A {} |
577 class B {} | 586 class B {} |
578 class as = A with B;'''); | 587 class as = A with B;'''); |
579 resolve(source); | 588 computeLibrarySourceErrors(source); |
580 assertErrors( | 589 assertErrors( |
581 source, [CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_TYPEDEF_NAME]); | 590 source, [CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_TYPEDEF_NAME]); |
582 verify([source]); | 591 verify([source]); |
583 } | 592 } |
584 | 593 |
585 void test_builtInIdentifierAsType_formalParameter_field() { | 594 void test_builtInIdentifierAsType_formalParameter_field() { |
586 Source source = addSource(r''' | 595 Source source = addSource(r''' |
587 class A { | 596 class A { |
588 var x; | 597 var x; |
589 A(static this.x); | 598 A(static this.x); |
590 }'''); | 599 }'''); |
591 resolve(source); | 600 computeLibrarySourceErrors(source); |
592 assertErrors(source, [CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_TYPE]); | 601 assertErrors(source, [CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_TYPE]); |
593 verify([source]); | 602 verify([source]); |
594 } | 603 } |
595 | 604 |
596 void test_builtInIdentifierAsType_formalParameter_simple() { | 605 void test_builtInIdentifierAsType_formalParameter_simple() { |
597 Source source = addSource(r''' | 606 Source source = addSource(r''' |
598 f(static x) { | 607 f(static x) { |
599 }'''); | 608 }'''); |
600 resolve(source); | 609 computeLibrarySourceErrors(source); |
601 assertErrors(source, [CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_TYPE]); | 610 assertErrors(source, [CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_TYPE]); |
602 verify([source]); | 611 verify([source]); |
603 } | 612 } |
604 | 613 |
605 void test_builtInIdentifierAsType_variableDeclaration() { | 614 void test_builtInIdentifierAsType_variableDeclaration() { |
606 Source source = addSource(r''' | 615 Source source = addSource(r''' |
607 f() { | 616 f() { |
608 typedef x; | 617 typedef x; |
609 }'''); | 618 }'''); |
610 resolve(source); | 619 computeLibrarySourceErrors(source); |
611 assertErrors(source, [CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_TYPE]); | 620 assertErrors(source, [CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_TYPE]); |
612 verify([source]); | 621 verify([source]); |
613 } | 622 } |
614 | 623 |
615 void test_builtInIdentifierAsTypedefName_functionTypeAlias() { | 624 void test_builtInIdentifierAsTypedefName_functionTypeAlias() { |
616 Source source = addSource("typedef bool as();"); | 625 Source source = addSource("typedef bool as();"); |
617 resolve(source); | 626 computeLibrarySourceErrors(source); |
618 assertErrors( | 627 assertErrors( |
619 source, [CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_TYPEDEF_NAME]); | 628 source, [CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_TYPEDEF_NAME]); |
620 verify([source]); | 629 verify([source]); |
621 } | 630 } |
622 | 631 |
623 void test_builtInIdentifierAsTypeName() { | 632 void test_builtInIdentifierAsTypeName() { |
624 Source source = addSource("class as {}"); | 633 Source source = addSource("class as {}"); |
625 resolve(source); | 634 computeLibrarySourceErrors(source); |
626 assertErrors( | 635 assertErrors( |
627 source, [CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_TYPE_NAME]); | 636 source, [CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_TYPE_NAME]); |
628 verify([source]); | 637 verify([source]); |
629 } | 638 } |
630 | 639 |
631 void test_builtInIdentifierAsTypeParameterName() { | 640 void test_builtInIdentifierAsTypeParameterName() { |
632 Source source = addSource("class A<as> {}"); | 641 Source source = addSource("class A<as> {}"); |
633 resolve(source); | 642 computeLibrarySourceErrors(source); |
634 assertErrors(source, | 643 assertErrors(source, |
635 [CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_TYPE_PARAMETER_NAME]); | 644 [CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_TYPE_PARAMETER_NAME]); |
636 verify([source]); | 645 verify([source]); |
637 } | 646 } |
638 | 647 |
639 void test_caseExpressionTypeImplementsEquals() { | 648 void test_caseExpressionTypeImplementsEquals() { |
640 Source source = addSource(r''' | 649 Source source = addSource(r''' |
641 class IntWrapper { | 650 class IntWrapper { |
642 final int value; | 651 final int value; |
643 const IntWrapper(this.value); | 652 const IntWrapper(this.value); |
644 bool operator ==(IntWrapper x) { | 653 bool operator ==(IntWrapper x) { |
645 return value == x.value; | 654 return value == x.value; |
646 } | 655 } |
647 get hashCode => value; | 656 get hashCode => value; |
648 } | 657 } |
649 | 658 |
650 f(var a) { | 659 f(var a) { |
651 switch(a) { | 660 switch(a) { |
652 case(const IntWrapper(1)) : return 1; | 661 case(const IntWrapper(1)) : return 1; |
653 default: return 0; | 662 default: return 0; |
654 } | 663 } |
655 }'''); | 664 }'''); |
656 resolve(source); | 665 computeLibrarySourceErrors(source); |
657 assertErrors( | 666 assertErrors( |
658 source, [CompileTimeErrorCode.CASE_EXPRESSION_TYPE_IMPLEMENTS_EQUALS]); | 667 source, [CompileTimeErrorCode.CASE_EXPRESSION_TYPE_IMPLEMENTS_EQUALS]); |
659 verify([source]); | 668 verify([source]); |
660 } | 669 } |
661 | 670 |
662 void test_conflictingConstructorNameAndMember_field() { | 671 void test_conflictingConstructorNameAndMember_field() { |
663 Source source = addSource(r''' | 672 Source source = addSource(r''' |
664 class A { | 673 class A { |
665 int x; | 674 int x; |
666 A.x() {} | 675 A.x() {} |
667 }'''); | 676 }'''); |
668 resolve(source); | 677 computeLibrarySourceErrors(source); |
669 assertErrors( | 678 assertErrors( |
670 source, [CompileTimeErrorCode.CONFLICTING_CONSTRUCTOR_NAME_AND_FIELD]); | 679 source, [CompileTimeErrorCode.CONFLICTING_CONSTRUCTOR_NAME_AND_FIELD]); |
671 verify([source]); | 680 verify([source]); |
672 } | 681 } |
673 | 682 |
674 void test_conflictingConstructorNameAndMember_method() { | 683 void test_conflictingConstructorNameAndMember_method() { |
675 Source source = addSource(r''' | 684 Source source = addSource(r''' |
676 class A { | 685 class A { |
677 const A.x(); | 686 const A.x(); |
678 void x() {} | 687 void x() {} |
679 }'''); | 688 }'''); |
680 resolve(source); | 689 computeLibrarySourceErrors(source); |
681 assertErrors( | 690 assertErrors( |
682 source, [CompileTimeErrorCode.CONFLICTING_CONSTRUCTOR_NAME_AND_METHOD]); | 691 source, [CompileTimeErrorCode.CONFLICTING_CONSTRUCTOR_NAME_AND_METHOD]); |
683 verify([source]); | 692 verify([source]); |
684 } | 693 } |
685 | 694 |
686 void test_conflictingGetterAndMethod_field_method() { | 695 void test_conflictingGetterAndMethod_field_method() { |
687 Source source = addSource(r''' | 696 Source source = addSource(r''' |
688 class A { | 697 class A { |
689 final int m = 0; | 698 final int m = 0; |
690 } | 699 } |
691 class B extends A { | 700 class B extends A { |
692 m() {} | 701 m() {} |
693 }'''); | 702 }'''); |
694 resolve(source); | 703 computeLibrarySourceErrors(source); |
695 assertErrors(source, [CompileTimeErrorCode.CONFLICTING_GETTER_AND_METHOD]); | 704 assertErrors(source, [CompileTimeErrorCode.CONFLICTING_GETTER_AND_METHOD]); |
696 verify([source]); | 705 verify([source]); |
697 } | 706 } |
698 | 707 |
699 void test_conflictingGetterAndMethod_getter_method() { | 708 void test_conflictingGetterAndMethod_getter_method() { |
700 Source source = addSource(r''' | 709 Source source = addSource(r''' |
701 class A { | 710 class A { |
702 get m => 0; | 711 get m => 0; |
703 } | 712 } |
704 class B extends A { | 713 class B extends A { |
705 m() {} | 714 m() {} |
706 }'''); | 715 }'''); |
707 resolve(source); | 716 computeLibrarySourceErrors(source); |
708 assertErrors(source, [CompileTimeErrorCode.CONFLICTING_GETTER_AND_METHOD]); | 717 assertErrors(source, [CompileTimeErrorCode.CONFLICTING_GETTER_AND_METHOD]); |
709 verify([source]); | 718 verify([source]); |
710 } | 719 } |
711 | 720 |
712 void test_conflictingGetterAndMethod_method_field() { | 721 void test_conflictingGetterAndMethod_method_field() { |
713 Source source = addSource(r''' | 722 Source source = addSource(r''' |
714 class A { | 723 class A { |
715 m() {} | 724 m() {} |
716 } | 725 } |
717 class B extends A { | 726 class B extends A { |
718 int m; | 727 int m; |
719 }'''); | 728 }'''); |
720 resolve(source); | 729 computeLibrarySourceErrors(source); |
721 assertErrors(source, [CompileTimeErrorCode.CONFLICTING_METHOD_AND_GETTER]); | 730 assertErrors(source, [CompileTimeErrorCode.CONFLICTING_METHOD_AND_GETTER]); |
722 verify([source]); | 731 verify([source]); |
723 } | 732 } |
724 | 733 |
725 void test_conflictingGetterAndMethod_method_getter() { | 734 void test_conflictingGetterAndMethod_method_getter() { |
726 Source source = addSource(r''' | 735 Source source = addSource(r''' |
727 class A { | 736 class A { |
728 m() {} | 737 m() {} |
729 } | 738 } |
730 class B extends A { | 739 class B extends A { |
731 get m => 0; | 740 get m => 0; |
732 }'''); | 741 }'''); |
733 resolve(source); | 742 computeLibrarySourceErrors(source); |
734 assertErrors(source, [CompileTimeErrorCode.CONFLICTING_METHOD_AND_GETTER]); | 743 assertErrors(source, [CompileTimeErrorCode.CONFLICTING_METHOD_AND_GETTER]); |
735 verify([source]); | 744 verify([source]); |
736 } | 745 } |
737 | 746 |
738 void test_conflictingTypeVariableAndClass() { | 747 void test_conflictingTypeVariableAndClass() { |
739 Source source = addSource(r''' | 748 Source source = addSource(r''' |
740 class T<T> { | 749 class T<T> { |
741 }'''); | 750 }'''); |
742 resolve(source); | 751 computeLibrarySourceErrors(source); |
743 assertErrors( | 752 assertErrors( |
744 source, [CompileTimeErrorCode.CONFLICTING_TYPE_VARIABLE_AND_CLASS]); | 753 source, [CompileTimeErrorCode.CONFLICTING_TYPE_VARIABLE_AND_CLASS]); |
745 verify([source]); | 754 verify([source]); |
746 } | 755 } |
747 | 756 |
748 void test_conflictingTypeVariableAndMember_field() { | 757 void test_conflictingTypeVariableAndMember_field() { |
749 Source source = addSource(r''' | 758 Source source = addSource(r''' |
750 class A<T> { | 759 class A<T> { |
751 var T; | 760 var T; |
752 }'''); | 761 }'''); |
753 resolve(source); | 762 computeLibrarySourceErrors(source); |
754 assertErrors( | 763 assertErrors( |
755 source, [CompileTimeErrorCode.CONFLICTING_TYPE_VARIABLE_AND_MEMBER]); | 764 source, [CompileTimeErrorCode.CONFLICTING_TYPE_VARIABLE_AND_MEMBER]); |
756 verify([source]); | 765 verify([source]); |
757 } | 766 } |
758 | 767 |
759 void test_conflictingTypeVariableAndMember_getter() { | 768 void test_conflictingTypeVariableAndMember_getter() { |
760 Source source = addSource(r''' | 769 Source source = addSource(r''' |
761 class A<T> { | 770 class A<T> { |
762 get T => null; | 771 get T => null; |
763 }'''); | 772 }'''); |
764 resolve(source); | 773 computeLibrarySourceErrors(source); |
765 assertErrors( | 774 assertErrors( |
766 source, [CompileTimeErrorCode.CONFLICTING_TYPE_VARIABLE_AND_MEMBER]); | 775 source, [CompileTimeErrorCode.CONFLICTING_TYPE_VARIABLE_AND_MEMBER]); |
767 verify([source]); | 776 verify([source]); |
768 } | 777 } |
769 | 778 |
770 void test_conflictingTypeVariableAndMember_method() { | 779 void test_conflictingTypeVariableAndMember_method() { |
771 Source source = addSource(r''' | 780 Source source = addSource(r''' |
772 class A<T> { | 781 class A<T> { |
773 T() {} | 782 T() {} |
774 }'''); | 783 }'''); |
775 resolve(source); | 784 computeLibrarySourceErrors(source); |
776 assertErrors( | 785 assertErrors( |
777 source, [CompileTimeErrorCode.CONFLICTING_TYPE_VARIABLE_AND_MEMBER]); | 786 source, [CompileTimeErrorCode.CONFLICTING_TYPE_VARIABLE_AND_MEMBER]); |
778 verify([source]); | 787 verify([source]); |
779 } | 788 } |
780 | 789 |
781 void test_conflictingTypeVariableAndMember_method_static() { | 790 void test_conflictingTypeVariableAndMember_method_static() { |
782 Source source = addSource(r''' | 791 Source source = addSource(r''' |
783 class A<T> { | 792 class A<T> { |
784 static T() {} | 793 static T() {} |
785 }'''); | 794 }'''); |
786 resolve(source); | 795 computeLibrarySourceErrors(source); |
787 assertErrors( | 796 assertErrors( |
788 source, [CompileTimeErrorCode.CONFLICTING_TYPE_VARIABLE_AND_MEMBER]); | 797 source, [CompileTimeErrorCode.CONFLICTING_TYPE_VARIABLE_AND_MEMBER]); |
789 verify([source]); | 798 verify([source]); |
790 } | 799 } |
791 | 800 |
792 void test_conflictingTypeVariableAndMember_setter() { | 801 void test_conflictingTypeVariableAndMember_setter() { |
793 Source source = addSource(r''' | 802 Source source = addSource(r''' |
794 class A<T> { | 803 class A<T> { |
795 set T(x) {} | 804 set T(x) {} |
796 }'''); | 805 }'''); |
797 resolve(source); | 806 computeLibrarySourceErrors(source); |
798 assertErrors( | 807 assertErrors( |
799 source, [CompileTimeErrorCode.CONFLICTING_TYPE_VARIABLE_AND_MEMBER]); | 808 source, [CompileTimeErrorCode.CONFLICTING_TYPE_VARIABLE_AND_MEMBER]); |
800 verify([source]); | 809 verify([source]); |
801 } | 810 } |
802 | 811 |
803 void test_consistentCaseExpressionTypes_dynamic() { | 812 void test_consistentCaseExpressionTypes_dynamic() { |
804 // Even though A.S and S have a static type of "dynamic", we should see | 813 // Even though A.S and S have a static type of "dynamic", we should see |
805 // that they match 'abc', because they are constant strings. | 814 // that they match 'abc', because they are constant strings. |
806 Source source = addSource(r''' | 815 Source source = addSource(r''' |
807 class A { | 816 class A { |
808 static const S = 'A.S'; | 817 static const S = 'A.S'; |
809 } | 818 } |
810 | 819 |
811 const S = 'S'; | 820 const S = 'S'; |
812 | 821 |
813 foo(var p) { | 822 foo(var p) { |
814 switch (p) { | 823 switch (p) { |
815 case S: | 824 case S: |
816 break; | 825 break; |
817 case A.S: | 826 case A.S: |
818 break; | 827 break; |
819 case 'abc': | 828 case 'abc': |
820 break; | 829 break; |
821 } | 830 } |
822 }'''); | 831 }'''); |
823 resolve(source); | 832 computeLibrarySourceErrors(source); |
824 assertNoErrors(source); | 833 assertNoErrors(source); |
825 verify([source]); | 834 verify([source]); |
826 } | 835 } |
827 | 836 |
828 void test_constConstructorWithFieldInitializedByNonConst() { | 837 void test_constConstructorWithFieldInitializedByNonConst() { |
829 Source source = addSource(r''' | 838 Source source = addSource(r''' |
830 class A { | 839 class A { |
831 final int i = f(); | 840 final int i = f(); |
832 const A(); | 841 const A(); |
833 } | 842 } |
834 int f() { | 843 int f() { |
835 return 3; | 844 return 3; |
836 }'''); | 845 }'''); |
837 resolve(source); | 846 computeLibrarySourceErrors(source); |
838 // TODO(paulberry): the error CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE is | 847 // TODO(paulberry): the error CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE is |
839 // redundant and ought to be suppressed. | 848 // redundant and ought to be suppressed. |
840 assertErrors(source, [ | 849 assertErrors(source, [ |
841 CompileTimeErrorCode.CONST_CONSTRUCTOR_WITH_FIELD_INITIALIZED_BY_NON_CONST
, | 850 CompileTimeErrorCode.CONST_CONSTRUCTOR_WITH_FIELD_INITIALIZED_BY_NON_CONST
, |
842 CompileTimeErrorCode.CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE | 851 CompileTimeErrorCode.CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE |
843 ]); | 852 ]); |
844 verify([source]); | 853 verify([source]); |
845 } | 854 } |
846 | 855 |
847 void test_constConstructorWithFieldInitializedByNonConst_static() { | 856 void test_constConstructorWithFieldInitializedByNonConst_static() { |
848 Source source = addSource(r''' | 857 Source source = addSource(r''' |
849 class A { | 858 class A { |
850 static final int i = f(); | 859 static final int i = f(); |
851 const A(); | 860 const A(); |
852 } | 861 } |
853 int f() { | 862 int f() { |
854 return 3; | 863 return 3; |
855 }'''); | 864 }'''); |
856 resolve(source); | 865 computeLibrarySourceErrors(source); |
857 assertNoErrors(source); | 866 assertNoErrors(source); |
858 verify([source]); | 867 verify([source]); |
859 } | 868 } |
860 | 869 |
861 void test_constConstructorWithMixin() { | 870 void test_constConstructorWithMixin() { |
862 Source source = addSource(r''' | 871 Source source = addSource(r''' |
863 class M { | 872 class M { |
864 } | 873 } |
865 class A extends Object with M { | 874 class A extends Object with M { |
866 const A(); | 875 const A(); |
867 }'''); | 876 }'''); |
868 resolve(source); | 877 computeLibrarySourceErrors(source); |
869 assertErrors(source, [CompileTimeErrorCode.CONST_CONSTRUCTOR_WITH_MIXIN]); | 878 assertErrors(source, [CompileTimeErrorCode.CONST_CONSTRUCTOR_WITH_MIXIN]); |
870 verify([source]); | 879 verify([source]); |
871 } | 880 } |
872 | 881 |
873 void test_constConstructorWithNonConstSuper_explicit() { | 882 void test_constConstructorWithNonConstSuper_explicit() { |
874 Source source = addSource(r''' | 883 Source source = addSource(r''' |
875 class A { | 884 class A { |
876 A(); | 885 A(); |
877 } | 886 } |
878 class B extends A { | 887 class B extends A { |
879 const B(): super(); | 888 const B(): super(); |
880 }'''); | 889 }'''); |
881 resolve(source); | 890 computeLibrarySourceErrors(source); |
882 assertErrors( | 891 assertErrors( |
883 source, [CompileTimeErrorCode.CONST_CONSTRUCTOR_WITH_NON_CONST_SUPER]); | 892 source, [CompileTimeErrorCode.CONST_CONSTRUCTOR_WITH_NON_CONST_SUPER]); |
884 verify([source]); | 893 verify([source]); |
885 } | 894 } |
886 | 895 |
887 void test_constConstructorWithNonConstSuper_implicit() { | 896 void test_constConstructorWithNonConstSuper_implicit() { |
888 Source source = addSource(r''' | 897 Source source = addSource(r''' |
889 class A { | 898 class A { |
890 A(); | 899 A(); |
891 } | 900 } |
892 class B extends A { | 901 class B extends A { |
893 const B(); | 902 const B(); |
894 }'''); | 903 }'''); |
895 resolve(source); | 904 computeLibrarySourceErrors(source); |
896 assertErrors( | 905 assertErrors( |
897 source, [CompileTimeErrorCode.CONST_CONSTRUCTOR_WITH_NON_CONST_SUPER]); | 906 source, [CompileTimeErrorCode.CONST_CONSTRUCTOR_WITH_NON_CONST_SUPER]); |
898 verify([source]); | 907 verify([source]); |
899 } | 908 } |
900 | 909 |
901 void test_constConstructorWithNonFinalField_mixin() { | 910 void test_constConstructorWithNonFinalField_mixin() { |
902 Source source = addSource(r''' | 911 Source source = addSource(r''' |
903 class A { | 912 class A { |
904 var a; | 913 var a; |
905 } | 914 } |
906 class B extends Object with A { | 915 class B extends Object with A { |
907 const B(); | 916 const B(); |
908 }'''); | 917 }'''); |
909 resolve(source); | 918 computeLibrarySourceErrors(source); |
910 assertErrors(source, [ | 919 assertErrors(source, [ |
911 CompileTimeErrorCode.CONST_CONSTRUCTOR_WITH_MIXIN, | 920 CompileTimeErrorCode.CONST_CONSTRUCTOR_WITH_MIXIN, |
912 CompileTimeErrorCode.CONST_CONSTRUCTOR_WITH_NON_FINAL_FIELD | 921 CompileTimeErrorCode.CONST_CONSTRUCTOR_WITH_NON_FINAL_FIELD |
913 ]); | 922 ]); |
914 verify([source]); | 923 verify([source]); |
915 } | 924 } |
916 | 925 |
917 void test_constConstructorWithNonFinalField_super() { | 926 void test_constConstructorWithNonFinalField_super() { |
918 Source source = addSource(r''' | 927 Source source = addSource(r''' |
919 class A { | 928 class A { |
920 var a; | 929 var a; |
921 } | 930 } |
922 class B extends A { | 931 class B extends A { |
923 const B(); | 932 const B(); |
924 }'''); | 933 }'''); |
925 resolve(source); | 934 computeLibrarySourceErrors(source); |
926 assertErrors(source, [ | 935 assertErrors(source, [ |
927 CompileTimeErrorCode.CONST_CONSTRUCTOR_WITH_NON_FINAL_FIELD, | 936 CompileTimeErrorCode.CONST_CONSTRUCTOR_WITH_NON_FINAL_FIELD, |
928 CompileTimeErrorCode.CONST_CONSTRUCTOR_WITH_NON_CONST_SUPER | 937 CompileTimeErrorCode.CONST_CONSTRUCTOR_WITH_NON_CONST_SUPER |
929 ]); | 938 ]); |
930 verify([source]); | 939 verify([source]); |
931 } | 940 } |
932 | 941 |
933 void test_constConstructorWithNonFinalField_this() { | 942 void test_constConstructorWithNonFinalField_this() { |
934 Source source = addSource(r''' | 943 Source source = addSource(r''' |
935 class A { | 944 class A { |
936 int x; | 945 int x; |
937 const A(); | 946 const A(); |
938 }'''); | 947 }'''); |
939 resolve(source); | 948 computeLibrarySourceErrors(source); |
940 assertErrors( | 949 assertErrors( |
941 source, [CompileTimeErrorCode.CONST_CONSTRUCTOR_WITH_NON_FINAL_FIELD]); | 950 source, [CompileTimeErrorCode.CONST_CONSTRUCTOR_WITH_NON_FINAL_FIELD]); |
942 verify([source]); | 951 verify([source]); |
943 } | 952 } |
944 | 953 |
945 void test_constDeferredClass() { | 954 void test_constDeferredClass() { |
946 resolveWithErrors(<String>[ | 955 resolveWithErrors(<String>[ |
947 r''' | 956 r''' |
948 library lib1; | 957 library lib1; |
949 class A { | 958 class A { |
(...skipping 23 matching lines...) Expand all Loading... |
973 }''' | 982 }''' |
974 ], <ErrorCode>[CompileTimeErrorCode.CONST_DEFERRED_CLASS]); | 983 ], <ErrorCode>[CompileTimeErrorCode.CONST_DEFERRED_CLASS]); |
975 } | 984 } |
976 | 985 |
977 void test_constEval_newInstance_constConstructor() { | 986 void test_constEval_newInstance_constConstructor() { |
978 Source source = addSource(r''' | 987 Source source = addSource(r''' |
979 class A { | 988 class A { |
980 const A(); | 989 const A(); |
981 } | 990 } |
982 const a = new A();'''); | 991 const a = new A();'''); |
983 resolve(source); | 992 computeLibrarySourceErrors(source); |
984 assertErrors(source, | 993 assertErrors(source, |
985 [CompileTimeErrorCode.CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE]); | 994 [CompileTimeErrorCode.CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE]); |
986 verify([source]); | 995 verify([source]); |
987 } | 996 } |
988 | 997 |
989 void test_constEval_newInstance_externalFactoryConstConstructor() { | 998 void test_constEval_newInstance_externalFactoryConstConstructor() { |
990 // We can't evaluate "const A()" because its constructor is external. But | 999 // We can't evaluate "const A()" because its constructor is external. But |
991 // the code is correct--we shouldn't report an error. | 1000 // the code is correct--we shouldn't report an error. |
992 Source source = addSource(r''' | 1001 Source source = addSource(r''' |
993 class A { | 1002 class A { |
994 external factory const A(); | 1003 external factory const A(); |
995 } | 1004 } |
996 const x = const A();'''); | 1005 const x = const A();'''); |
997 resolve(source); | 1006 computeLibrarySourceErrors(source); |
998 assertNoErrors(source); | 1007 assertNoErrors(source); |
999 verify([source]); | 1008 verify([source]); |
1000 } | 1009 } |
1001 | 1010 |
1002 void test_constEval_propertyExtraction_targetNotConst() { | 1011 void test_constEval_propertyExtraction_targetNotConst() { |
1003 Source source = addSource(r''' | 1012 Source source = addSource(r''' |
1004 class A { | 1013 class A { |
1005 const A(); | 1014 const A(); |
1006 m() {} | 1015 m() {} |
1007 } | 1016 } |
1008 final a = const A(); | 1017 final a = const A(); |
1009 const C = a.m;'''); | 1018 const C = a.m;'''); |
1010 resolve(source); | 1019 computeLibrarySourceErrors(source); |
1011 assertErrors(source, | 1020 assertErrors(source, |
1012 [CompileTimeErrorCode.CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE]); | 1021 [CompileTimeErrorCode.CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE]); |
1013 verify([source]); | 1022 verify([source]); |
1014 } | 1023 } |
1015 | 1024 |
1016 void test_constEvalThrowsException_binaryMinus_null() { | 1025 void test_constEvalThrowsException_binaryMinus_null() { |
1017 _check_constEvalThrowsException_binary_null("null - 5", false); | 1026 _check_constEvalThrowsException_binary_null("null - 5", false); |
1018 _check_constEvalThrowsException_binary_null("5 - null", true); | 1027 _check_constEvalThrowsException_binary_null("5 - null", true); |
1019 } | 1028 } |
1020 | 1029 |
1021 void test_constEvalThrowsException_binaryPlus_null() { | 1030 void test_constEvalThrowsException_binaryPlus_null() { |
1022 _check_constEvalThrowsException_binary_null("null + 5", false); | 1031 _check_constEvalThrowsException_binary_null("null + 5", false); |
1023 _check_constEvalThrowsException_binary_null("5 + null", true); | 1032 _check_constEvalThrowsException_binary_null("5 + null", true); |
1024 } | 1033 } |
1025 | 1034 |
1026 void test_constEvalThrowsException_divisionByZero() { | 1035 void test_constEvalThrowsException_divisionByZero() { |
1027 Source source = addSource("const C = 1 ~/ 0;"); | 1036 Source source = addSource("const C = 1 ~/ 0;"); |
1028 resolve(source); | 1037 computeLibrarySourceErrors(source); |
1029 assertErrors(source, [CompileTimeErrorCode.CONST_EVAL_THROWS_IDBZE]); | 1038 assertErrors(source, [CompileTimeErrorCode.CONST_EVAL_THROWS_IDBZE]); |
1030 verify([source]); | 1039 verify([source]); |
1031 } | 1040 } |
1032 | 1041 |
1033 void test_constEvalThrowsException_unaryBitNot_null() { | 1042 void test_constEvalThrowsException_unaryBitNot_null() { |
1034 Source source = addSource("const C = ~null;"); | 1043 Source source = addSource("const C = ~null;"); |
1035 resolve(source); | 1044 computeLibrarySourceErrors(source); |
1036 assertErrors(source, [CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION]); | 1045 assertErrors(source, [CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION]); |
1037 // no verify(), '~null' is not resolved | 1046 // no verify(), '~null' is not resolved |
1038 } | 1047 } |
1039 | 1048 |
1040 void test_constEvalThrowsException_unaryNegated_null() { | 1049 void test_constEvalThrowsException_unaryNegated_null() { |
1041 Source source = addSource("const C = -null;"); | 1050 Source source = addSource("const C = -null;"); |
1042 resolve(source); | 1051 computeLibrarySourceErrors(source); |
1043 assertErrors(source, [CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION]); | 1052 assertErrors(source, [CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION]); |
1044 // no verify(), '-null' is not resolved | 1053 // no verify(), '-null' is not resolved |
1045 } | 1054 } |
1046 | 1055 |
1047 void test_constEvalThrowsException_unaryNot_null() { | 1056 void test_constEvalThrowsException_unaryNot_null() { |
1048 Source source = addSource("const C = !null;"); | 1057 Source source = addSource("const C = !null;"); |
1049 resolve(source); | 1058 computeLibrarySourceErrors(source); |
1050 assertErrors(source, [CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION]); | 1059 assertErrors(source, [CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION]); |
1051 verify([source]); | 1060 verify([source]); |
1052 } | 1061 } |
1053 | 1062 |
1054 void test_constEvalTypeBool_binary() { | 1063 void test_constEvalTypeBool_binary() { |
1055 _check_constEvalTypeBool_withParameter_binary("p && ''"); | 1064 _check_constEvalTypeBool_withParameter_binary("p && ''"); |
1056 _check_constEvalTypeBool_withParameter_binary("p || ''"); | 1065 _check_constEvalTypeBool_withParameter_binary("p || ''"); |
1057 } | 1066 } |
1058 | 1067 |
1059 void test_constEvalTypeBool_binary_leftTrue() { | 1068 void test_constEvalTypeBool_binary_leftTrue() { |
1060 Source source = addSource("const C = (true || 0);"); | 1069 Source source = addSource("const C = (true || 0);"); |
1061 resolve(source); | 1070 computeLibrarySourceErrors(source); |
1062 assertErrors(source, [ | 1071 assertErrors(source, [ |
1063 CompileTimeErrorCode.CONST_EVAL_TYPE_BOOL, | 1072 CompileTimeErrorCode.CONST_EVAL_TYPE_BOOL, |
1064 StaticTypeWarningCode.NON_BOOL_OPERAND, | 1073 StaticTypeWarningCode.NON_BOOL_OPERAND, |
1065 HintCode.DEAD_CODE | 1074 HintCode.DEAD_CODE |
1066 ]); | 1075 ]); |
1067 verify([source]); | 1076 verify([source]); |
1068 } | 1077 } |
1069 | 1078 |
1070 void test_constEvalTypeBoolNumString_equal() { | 1079 void test_constEvalTypeBoolNumString_equal() { |
1071 Source source = addSource(r''' | 1080 Source source = addSource(r''' |
1072 class A { | 1081 class A { |
1073 const A(); | 1082 const A(); |
1074 } | 1083 } |
1075 class B { | 1084 class B { |
1076 final a; | 1085 final a; |
1077 const B(num p) : a = p == const A(); | 1086 const B(num p) : a = p == const A(); |
1078 }'''); | 1087 }'''); |
1079 resolve(source); | 1088 computeLibrarySourceErrors(source); |
1080 assertErrors( | 1089 assertErrors( |
1081 source, [CompileTimeErrorCode.CONST_EVAL_TYPE_BOOL_NUM_STRING]); | 1090 source, [CompileTimeErrorCode.CONST_EVAL_TYPE_BOOL_NUM_STRING]); |
1082 verify([source]); | 1091 verify([source]); |
1083 } | 1092 } |
1084 | 1093 |
1085 void test_constEvalTypeBoolNumString_notEqual() { | 1094 void test_constEvalTypeBoolNumString_notEqual() { |
1086 Source source = addSource(r''' | 1095 Source source = addSource(r''' |
1087 class A { | 1096 class A { |
1088 const A(); | 1097 const A(); |
1089 } | 1098 } |
1090 class B { | 1099 class B { |
1091 final a; | 1100 final a; |
1092 const B(String p) : a = p != const A(); | 1101 const B(String p) : a = p != const A(); |
1093 }'''); | 1102 }'''); |
1094 resolve(source); | 1103 computeLibrarySourceErrors(source); |
1095 assertErrors( | 1104 assertErrors( |
1096 source, [CompileTimeErrorCode.CONST_EVAL_TYPE_BOOL_NUM_STRING]); | 1105 source, [CompileTimeErrorCode.CONST_EVAL_TYPE_BOOL_NUM_STRING]); |
1097 verify([source]); | 1106 verify([source]); |
1098 } | 1107 } |
1099 | 1108 |
1100 void test_constEvalTypeInt_binary() { | 1109 void test_constEvalTypeInt_binary() { |
1101 _check_constEvalTypeInt_withParameter_binary("p ^ ''"); | 1110 _check_constEvalTypeInt_withParameter_binary("p ^ ''"); |
1102 _check_constEvalTypeInt_withParameter_binary("p & ''"); | 1111 _check_constEvalTypeInt_withParameter_binary("p & ''"); |
1103 _check_constEvalTypeInt_withParameter_binary("p | ''"); | 1112 _check_constEvalTypeInt_withParameter_binary("p | ''"); |
1104 _check_constEvalTypeInt_withParameter_binary("p >> ''"); | 1113 _check_constEvalTypeInt_withParameter_binary("p >> ''"); |
(...skipping 12 matching lines...) Expand all Loading... |
1117 _check_constEvalTypeNum_withParameter_binary("p <= ''"); | 1126 _check_constEvalTypeNum_withParameter_binary("p <= ''"); |
1118 _check_constEvalTypeNum_withParameter_binary("p % ''"); | 1127 _check_constEvalTypeNum_withParameter_binary("p % ''"); |
1119 } | 1128 } |
1120 | 1129 |
1121 void test_constFormalParameter_fieldFormalParameter() { | 1130 void test_constFormalParameter_fieldFormalParameter() { |
1122 Source source = addSource(r''' | 1131 Source source = addSource(r''' |
1123 class A { | 1132 class A { |
1124 var x; | 1133 var x; |
1125 A(const this.x) {} | 1134 A(const this.x) {} |
1126 }'''); | 1135 }'''); |
1127 resolve(source); | 1136 computeLibrarySourceErrors(source); |
1128 assertErrors(source, [CompileTimeErrorCode.CONST_FORMAL_PARAMETER]); | 1137 assertErrors(source, [CompileTimeErrorCode.CONST_FORMAL_PARAMETER]); |
1129 verify([source]); | 1138 verify([source]); |
1130 } | 1139 } |
1131 | 1140 |
1132 void test_constFormalParameter_simpleFormalParameter() { | 1141 void test_constFormalParameter_simpleFormalParameter() { |
1133 Source source = addSource("f(const x) {}"); | 1142 Source source = addSource("f(const x) {}"); |
1134 resolve(source); | 1143 computeLibrarySourceErrors(source); |
1135 assertErrors(source, [CompileTimeErrorCode.CONST_FORMAL_PARAMETER]); | 1144 assertErrors(source, [CompileTimeErrorCode.CONST_FORMAL_PARAMETER]); |
1136 verify([source]); | 1145 verify([source]); |
1137 } | 1146 } |
1138 | 1147 |
1139 void test_constInitializedWithNonConstValue() { | 1148 void test_constInitializedWithNonConstValue() { |
1140 Source source = addSource(r''' | 1149 Source source = addSource(r''' |
1141 f(p) { | 1150 f(p) { |
1142 const C = p; | 1151 const C = p; |
1143 }'''); | 1152 }'''); |
1144 resolve(source); | 1153 computeLibrarySourceErrors(source); |
1145 assertErrors(source, | 1154 assertErrors(source, |
1146 [CompileTimeErrorCode.CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE]); | 1155 [CompileTimeErrorCode.CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE]); |
1147 verify([source]); | 1156 verify([source]); |
1148 } | 1157 } |
1149 | 1158 |
1150 void test_constInitializedWithNonConstValue_missingConstInListLiteral() { | 1159 void test_constInitializedWithNonConstValue_missingConstInListLiteral() { |
1151 Source source = addSource("const List L = [0];"); | 1160 Source source = addSource("const List L = [0];"); |
1152 resolve(source); | 1161 computeLibrarySourceErrors(source); |
1153 assertErrors(source, | 1162 assertErrors(source, |
1154 [CompileTimeErrorCode.CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE]); | 1163 [CompileTimeErrorCode.CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE]); |
1155 verify([source]); | 1164 verify([source]); |
1156 } | 1165 } |
1157 | 1166 |
1158 void test_constInitializedWithNonConstValue_missingConstInMapLiteral() { | 1167 void test_constInitializedWithNonConstValue_missingConstInMapLiteral() { |
1159 Source source = addSource("const Map M = {'a' : 0};"); | 1168 Source source = addSource("const Map M = {'a' : 0};"); |
1160 resolve(source); | 1169 computeLibrarySourceErrors(source); |
1161 assertErrors(source, | 1170 assertErrors(source, |
1162 [CompileTimeErrorCode.CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE]); | 1171 [CompileTimeErrorCode.CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE]); |
1163 verify([source]); | 1172 verify([source]); |
1164 } | 1173 } |
1165 | 1174 |
1166 void test_constInitializedWithNonConstValueFromDeferredClass() { | 1175 void test_constInitializedWithNonConstValueFromDeferredClass() { |
1167 resolveWithErrors(<String>[ | 1176 resolveWithErrors(<String>[ |
1168 r''' | 1177 r''' |
1169 library lib1; | 1178 library lib1; |
1170 const V = 1;''', | 1179 const V = 1;''', |
(...skipping 18 matching lines...) Expand all Loading... |
1189 ], <ErrorCode>[ | 1198 ], <ErrorCode>[ |
1190 CompileTimeErrorCode.CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE_FROM_DEFERR
ED_LIBRARY | 1199 CompileTimeErrorCode.CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE_FROM_DEFERR
ED_LIBRARY |
1191 ]); | 1200 ]); |
1192 } | 1201 } |
1193 | 1202 |
1194 void test_constInstanceField() { | 1203 void test_constInstanceField() { |
1195 Source source = addSource(r''' | 1204 Source source = addSource(r''' |
1196 class C { | 1205 class C { |
1197 const int f = 0; | 1206 const int f = 0; |
1198 }'''); | 1207 }'''); |
1199 resolve(source); | 1208 computeLibrarySourceErrors(source); |
1200 assertErrors(source, [CompileTimeErrorCode.CONST_INSTANCE_FIELD]); | 1209 assertErrors(source, [CompileTimeErrorCode.CONST_INSTANCE_FIELD]); |
1201 verify([source]); | 1210 verify([source]); |
1202 } | 1211 } |
1203 | 1212 |
1204 void test_constMapKeyTypeImplementsEquals_direct() { | 1213 void test_constMapKeyTypeImplementsEquals_direct() { |
1205 Source source = addSource(r''' | 1214 Source source = addSource(r''' |
1206 class A { | 1215 class A { |
1207 const A(); | 1216 const A(); |
1208 operator ==(other) => false; | 1217 operator ==(other) => false; |
1209 } | 1218 } |
1210 main() { | 1219 main() { |
1211 const {const A() : 0}; | 1220 const {const A() : 0}; |
1212 }'''); | 1221 }'''); |
1213 resolve(source); | 1222 computeLibrarySourceErrors(source); |
1214 assertErrors(source, | 1223 assertErrors(source, |
1215 [CompileTimeErrorCode.CONST_MAP_KEY_EXPRESSION_TYPE_IMPLEMENTS_EQUALS]); | 1224 [CompileTimeErrorCode.CONST_MAP_KEY_EXPRESSION_TYPE_IMPLEMENTS_EQUALS]); |
1216 verify([source]); | 1225 verify([source]); |
1217 } | 1226 } |
1218 | 1227 |
1219 void test_constMapKeyTypeImplementsEquals_dynamic() { | 1228 void test_constMapKeyTypeImplementsEquals_dynamic() { |
1220 // Note: static type of B.a is "dynamic", but actual type of the const | 1229 // Note: static type of B.a is "dynamic", but actual type of the const |
1221 // object is A. We need to make sure we examine the actual type when | 1230 // object is A. We need to make sure we examine the actual type when |
1222 // deciding whether there is a problem with operator==. | 1231 // deciding whether there is a problem with operator==. |
1223 Source source = addSource(r''' | 1232 Source source = addSource(r''' |
1224 class A { | 1233 class A { |
1225 const A(); | 1234 const A(); |
1226 operator ==(other) => false; | 1235 operator ==(other) => false; |
1227 } | 1236 } |
1228 class B { | 1237 class B { |
1229 static const a = const A(); | 1238 static const a = const A(); |
1230 } | 1239 } |
1231 main() { | 1240 main() { |
1232 const {B.a : 0}; | 1241 const {B.a : 0}; |
1233 }'''); | 1242 }'''); |
1234 resolve(source); | 1243 computeLibrarySourceErrors(source); |
1235 assertErrors(source, | 1244 assertErrors(source, |
1236 [CompileTimeErrorCode.CONST_MAP_KEY_EXPRESSION_TYPE_IMPLEMENTS_EQUALS]); | 1245 [CompileTimeErrorCode.CONST_MAP_KEY_EXPRESSION_TYPE_IMPLEMENTS_EQUALS]); |
1237 verify([source]); | 1246 verify([source]); |
1238 } | 1247 } |
1239 | 1248 |
1240 void test_constMapKeyTypeImplementsEquals_factory() { | 1249 void test_constMapKeyTypeImplementsEquals_factory() { |
1241 Source source = addSource(r''' | 1250 Source source = addSource(r''' |
1242 class A { const factory A() = B; } | 1251 class A { const factory A() = B; } |
1243 | 1252 |
1244 class B implements A { | 1253 class B implements A { |
1245 const B(); | 1254 const B(); |
1246 | 1255 |
1247 operator ==(o) => true; | 1256 operator ==(o) => true; |
1248 } | 1257 } |
1249 | 1258 |
1250 main() { | 1259 main() { |
1251 var m = const { const A(): 42 }; | 1260 var m = const { const A(): 42 }; |
1252 }'''); | 1261 }'''); |
1253 resolve(source); | 1262 computeLibrarySourceErrors(source); |
1254 assertErrors(source, | 1263 assertErrors(source, |
1255 [CompileTimeErrorCode.CONST_MAP_KEY_EXPRESSION_TYPE_IMPLEMENTS_EQUALS]); | 1264 [CompileTimeErrorCode.CONST_MAP_KEY_EXPRESSION_TYPE_IMPLEMENTS_EQUALS]); |
1256 verify([source]); | 1265 verify([source]); |
1257 } | 1266 } |
1258 | 1267 |
1259 void test_constMapKeyTypeImplementsEquals_super() { | 1268 void test_constMapKeyTypeImplementsEquals_super() { |
1260 Source source = addSource(r''' | 1269 Source source = addSource(r''' |
1261 class A { | 1270 class A { |
1262 const A(); | 1271 const A(); |
1263 operator ==(other) => false; | 1272 operator ==(other) => false; |
1264 } | 1273 } |
1265 class B extends A { | 1274 class B extends A { |
1266 const B(); | 1275 const B(); |
1267 } | 1276 } |
1268 main() { | 1277 main() { |
1269 const {const B() : 0}; | 1278 const {const B() : 0}; |
1270 }'''); | 1279 }'''); |
1271 resolve(source); | 1280 computeLibrarySourceErrors(source); |
1272 assertErrors(source, | 1281 assertErrors(source, |
1273 [CompileTimeErrorCode.CONST_MAP_KEY_EXPRESSION_TYPE_IMPLEMENTS_EQUALS]); | 1282 [CompileTimeErrorCode.CONST_MAP_KEY_EXPRESSION_TYPE_IMPLEMENTS_EQUALS]); |
1274 verify([source]); | 1283 verify([source]); |
1275 } | 1284 } |
1276 | 1285 |
1277 void test_constWithInvalidTypeParameters() { | 1286 void test_constWithInvalidTypeParameters() { |
1278 Source source = addSource(r''' | 1287 Source source = addSource(r''' |
1279 class A { | 1288 class A { |
1280 const A(); | 1289 const A(); |
1281 } | 1290 } |
1282 f() { return const A<A>(); }'''); | 1291 f() { return const A<A>(); }'''); |
1283 resolve(source); | 1292 computeLibrarySourceErrors(source); |
1284 assertErrors( | 1293 assertErrors( |
1285 source, [CompileTimeErrorCode.CONST_WITH_INVALID_TYPE_PARAMETERS]); | 1294 source, [CompileTimeErrorCode.CONST_WITH_INVALID_TYPE_PARAMETERS]); |
1286 verify([source]); | 1295 verify([source]); |
1287 } | 1296 } |
1288 | 1297 |
1289 void test_constWithInvalidTypeParameters_tooFew() { | 1298 void test_constWithInvalidTypeParameters_tooFew() { |
1290 Source source = addSource(r''' | 1299 Source source = addSource(r''' |
1291 class A {} | 1300 class A {} |
1292 class C<K, V> { | 1301 class C<K, V> { |
1293 const C(); | 1302 const C(); |
1294 } | 1303 } |
1295 f(p) { | 1304 f(p) { |
1296 return const C<A>(); | 1305 return const C<A>(); |
1297 }'''); | 1306 }'''); |
1298 resolve(source); | 1307 computeLibrarySourceErrors(source); |
1299 assertErrors( | 1308 assertErrors( |
1300 source, [CompileTimeErrorCode.CONST_WITH_INVALID_TYPE_PARAMETERS]); | 1309 source, [CompileTimeErrorCode.CONST_WITH_INVALID_TYPE_PARAMETERS]); |
1301 verify([source]); | 1310 verify([source]); |
1302 } | 1311 } |
1303 | 1312 |
1304 void test_constWithInvalidTypeParameters_tooMany() { | 1313 void test_constWithInvalidTypeParameters_tooMany() { |
1305 Source source = addSource(r''' | 1314 Source source = addSource(r''' |
1306 class A {} | 1315 class A {} |
1307 class C<E> { | 1316 class C<E> { |
1308 const C(); | 1317 const C(); |
1309 } | 1318 } |
1310 f(p) { | 1319 f(p) { |
1311 return const C<A, A>(); | 1320 return const C<A, A>(); |
1312 }'''); | 1321 }'''); |
1313 resolve(source); | 1322 computeLibrarySourceErrors(source); |
1314 assertErrors( | 1323 assertErrors( |
1315 source, [CompileTimeErrorCode.CONST_WITH_INVALID_TYPE_PARAMETERS]); | 1324 source, [CompileTimeErrorCode.CONST_WITH_INVALID_TYPE_PARAMETERS]); |
1316 verify([source]); | 1325 verify([source]); |
1317 } | 1326 } |
1318 | 1327 |
1319 void test_constWithNonConst() { | 1328 void test_constWithNonConst() { |
1320 Source source = addSource(r''' | 1329 Source source = addSource(r''' |
1321 class T { | 1330 class T { |
1322 T(a, b, {c, d}) {} | 1331 T(a, b, {c, d}) {} |
1323 } | 1332 } |
1324 f() { return const T(0, 1, c: 2, d: 3); }'''); | 1333 f() { return const T(0, 1, c: 2, d: 3); }'''); |
1325 resolve(source); | 1334 computeLibrarySourceErrors(source); |
1326 assertErrors(source, [CompileTimeErrorCode.CONST_WITH_NON_CONST]); | 1335 assertErrors(source, [CompileTimeErrorCode.CONST_WITH_NON_CONST]); |
1327 verify([source]); | 1336 verify([source]); |
1328 } | 1337 } |
1329 | 1338 |
1330 void test_constWithNonConstantArgument_annotation() { | 1339 void test_constWithNonConstantArgument_annotation() { |
1331 Source source = addSource(r''' | 1340 Source source = addSource(r''' |
1332 class A { | 1341 class A { |
1333 const A(int p); | 1342 const A(int p); |
1334 } | 1343 } |
1335 var v = 42; | 1344 var v = 42; |
1336 @A(v) | 1345 @A(v) |
1337 main() { | 1346 main() { |
1338 }'''); | 1347 }'''); |
1339 resolve(source); | 1348 computeLibrarySourceErrors(source); |
1340 assertErrors( | 1349 assertErrors( |
1341 source, [CompileTimeErrorCode.CONST_WITH_NON_CONSTANT_ARGUMENT]); | 1350 source, [CompileTimeErrorCode.CONST_WITH_NON_CONSTANT_ARGUMENT]); |
1342 verify([source]); | 1351 verify([source]); |
1343 } | 1352 } |
1344 | 1353 |
1345 void test_constWithNonConstantArgument_instanceCreation() { | 1354 void test_constWithNonConstantArgument_instanceCreation() { |
1346 Source source = addSource(r''' | 1355 Source source = addSource(r''' |
1347 class A { | 1356 class A { |
1348 const A(a); | 1357 const A(a); |
1349 } | 1358 } |
1350 f(p) { return const A(p); }'''); | 1359 f(p) { return const A(p); }'''); |
1351 resolve(source); | 1360 computeLibrarySourceErrors(source); |
1352 // TODO(paulberry): the error INVALID_CONSTAT is redundant and ought to be | 1361 // TODO(paulberry): the error INVALID_CONSTAT is redundant and ought to be |
1353 // suppressed. | 1362 // suppressed. |
1354 assertErrors(source, [ | 1363 assertErrors(source, [ |
1355 CompileTimeErrorCode.CONST_WITH_NON_CONSTANT_ARGUMENT, | 1364 CompileTimeErrorCode.CONST_WITH_NON_CONSTANT_ARGUMENT, |
1356 CompileTimeErrorCode.INVALID_CONSTANT | 1365 CompileTimeErrorCode.INVALID_CONSTANT |
1357 ]); | 1366 ]); |
1358 verify([source]); | 1367 verify([source]); |
1359 } | 1368 } |
1360 | 1369 |
1361 void test_constWithNonType() { | 1370 void test_constWithNonType() { |
1362 Source source = addSource(r''' | 1371 Source source = addSource(r''' |
1363 int A; | 1372 int A; |
1364 f() { | 1373 f() { |
1365 return const A(); | 1374 return const A(); |
1366 }'''); | 1375 }'''); |
1367 resolve(source); | 1376 computeLibrarySourceErrors(source); |
1368 assertErrors(source, [CompileTimeErrorCode.CONST_WITH_NON_TYPE]); | 1377 assertErrors(source, [CompileTimeErrorCode.CONST_WITH_NON_TYPE]); |
1369 verify([source]); | 1378 verify([source]); |
1370 } | 1379 } |
1371 | 1380 |
1372 void test_constWithNonType_fromLibrary() { | 1381 void test_constWithNonType_fromLibrary() { |
1373 Source source1 = addNamedSource("lib.dart", ""); | 1382 Source source1 = addNamedSource("lib.dart", ""); |
1374 Source source2 = addNamedSource("lib2.dart", r''' | 1383 Source source2 = addNamedSource("lib2.dart", r''' |
1375 import 'lib.dart' as lib; | 1384 import 'lib.dart' as lib; |
1376 void f() { | 1385 void f() { |
1377 const lib.A(); | 1386 const lib.A(); |
1378 }'''); | 1387 }'''); |
1379 resolve(source1); | 1388 computeLibrarySourceErrors(source1); |
1380 resolve(source2); | 1389 computeLibrarySourceErrors(source2); |
1381 assertErrors(source2, [CompileTimeErrorCode.CONST_WITH_NON_TYPE]); | 1390 assertErrors(source2, [CompileTimeErrorCode.CONST_WITH_NON_TYPE]); |
1382 verify([source1]); | 1391 verify([source1]); |
1383 } | 1392 } |
1384 | 1393 |
1385 void test_constWithTypeParameters_direct() { | 1394 void test_constWithTypeParameters_direct() { |
1386 Source source = addSource(r''' | 1395 Source source = addSource(r''' |
1387 class A<T> { | 1396 class A<T> { |
1388 static const V = const A<T>(); | 1397 static const V = const A<T>(); |
1389 const A(); | 1398 const A(); |
1390 }'''); | 1399 }'''); |
1391 resolve(source); | 1400 computeLibrarySourceErrors(source); |
1392 assertErrors(source, [ | 1401 assertErrors(source, [ |
1393 CompileTimeErrorCode.CONST_WITH_TYPE_PARAMETERS, | 1402 CompileTimeErrorCode.CONST_WITH_TYPE_PARAMETERS, |
1394 StaticWarningCode.TYPE_PARAMETER_REFERENCED_BY_STATIC | 1403 StaticWarningCode.TYPE_PARAMETER_REFERENCED_BY_STATIC |
1395 ]); | 1404 ]); |
1396 verify([source]); | 1405 verify([source]); |
1397 } | 1406 } |
1398 | 1407 |
1399 void test_constWithTypeParameters_indirect() { | 1408 void test_constWithTypeParameters_indirect() { |
1400 Source source = addSource(r''' | 1409 Source source = addSource(r''' |
1401 class A<T> { | 1410 class A<T> { |
1402 static const V = const A<List<T>>(); | 1411 static const V = const A<List<T>>(); |
1403 const A(); | 1412 const A(); |
1404 }'''); | 1413 }'''); |
1405 resolve(source); | 1414 computeLibrarySourceErrors(source); |
1406 assertErrors(source, [ | 1415 assertErrors(source, [ |
1407 CompileTimeErrorCode.CONST_WITH_TYPE_PARAMETERS, | 1416 CompileTimeErrorCode.CONST_WITH_TYPE_PARAMETERS, |
1408 StaticWarningCode.TYPE_PARAMETER_REFERENCED_BY_STATIC | 1417 StaticWarningCode.TYPE_PARAMETER_REFERENCED_BY_STATIC |
1409 ]); | 1418 ]); |
1410 verify([source]); | 1419 verify([source]); |
1411 } | 1420 } |
1412 | 1421 |
1413 void test_constWithUndefinedConstructor() { | 1422 void test_constWithUndefinedConstructor() { |
1414 Source source = addSource(r''' | 1423 Source source = addSource(r''' |
1415 class A { | 1424 class A { |
1416 const A(); | 1425 const A(); |
1417 } | 1426 } |
1418 f() { | 1427 f() { |
1419 return const A.noSuchConstructor(); | 1428 return const A.noSuchConstructor(); |
1420 }'''); | 1429 }'''); |
1421 resolve(source); | 1430 computeLibrarySourceErrors(source); |
1422 assertErrors( | 1431 assertErrors( |
1423 source, [CompileTimeErrorCode.CONST_WITH_UNDEFINED_CONSTRUCTOR]); | 1432 source, [CompileTimeErrorCode.CONST_WITH_UNDEFINED_CONSTRUCTOR]); |
1424 // no verify(), 'noSuchConstructor' is not resolved | 1433 // no verify(), 'noSuchConstructor' is not resolved |
1425 } | 1434 } |
1426 | 1435 |
1427 void test_constWithUndefinedConstructorDefault() { | 1436 void test_constWithUndefinedConstructorDefault() { |
1428 Source source = addSource(r''' | 1437 Source source = addSource(r''' |
1429 class A { | 1438 class A { |
1430 const A.name(); | 1439 const A.name(); |
1431 } | 1440 } |
1432 f() { | 1441 f() { |
1433 return const A(); | 1442 return const A(); |
1434 }'''); | 1443 }'''); |
1435 resolve(source); | 1444 computeLibrarySourceErrors(source); |
1436 assertErrors(source, | 1445 assertErrors(source, |
1437 [CompileTimeErrorCode.CONST_WITH_UNDEFINED_CONSTRUCTOR_DEFAULT]); | 1446 [CompileTimeErrorCode.CONST_WITH_UNDEFINED_CONSTRUCTOR_DEFAULT]); |
1438 verify([source]); | 1447 verify([source]); |
1439 } | 1448 } |
1440 | 1449 |
1441 void test_defaultValueInFunctionTypeAlias() { | 1450 void test_defaultValueInFunctionTypeAlias() { |
1442 Source source = addSource("typedef F([x = 0]);"); | 1451 Source source = addSource("typedef F([x = 0]);"); |
1443 resolve(source); | 1452 computeLibrarySourceErrors(source); |
1444 assertErrors( | 1453 assertErrors( |
1445 source, [CompileTimeErrorCode.DEFAULT_VALUE_IN_FUNCTION_TYPE_ALIAS]); | 1454 source, [CompileTimeErrorCode.DEFAULT_VALUE_IN_FUNCTION_TYPE_ALIAS]); |
1446 verify([source]); | 1455 verify([source]); |
1447 } | 1456 } |
1448 | 1457 |
1449 void test_defaultValueInFunctionTypedParameter_named() { | 1458 void test_defaultValueInFunctionTypedParameter_named() { |
1450 Source source = addSource("f(g({p: null})) {}"); | 1459 Source source = addSource("f(g({p: null})) {}"); |
1451 resolve(source); | 1460 computeLibrarySourceErrors(source); |
1452 assertErrors(source, | 1461 assertErrors(source, |
1453 [CompileTimeErrorCode.DEFAULT_VALUE_IN_FUNCTION_TYPED_PARAMETER]); | 1462 [CompileTimeErrorCode.DEFAULT_VALUE_IN_FUNCTION_TYPED_PARAMETER]); |
1454 verify([source]); | 1463 verify([source]); |
1455 } | 1464 } |
1456 | 1465 |
1457 void test_defaultValueInFunctionTypedParameter_optional() { | 1466 void test_defaultValueInFunctionTypedParameter_optional() { |
1458 Source source = addSource("f(g([p = null])) {}"); | 1467 Source source = addSource("f(g([p = null])) {}"); |
1459 resolve(source); | 1468 computeLibrarySourceErrors(source); |
1460 assertErrors(source, | 1469 assertErrors(source, |
1461 [CompileTimeErrorCode.DEFAULT_VALUE_IN_FUNCTION_TYPED_PARAMETER]); | 1470 [CompileTimeErrorCode.DEFAULT_VALUE_IN_FUNCTION_TYPED_PARAMETER]); |
1462 verify([source]); | 1471 verify([source]); |
1463 } | 1472 } |
1464 | 1473 |
1465 void test_defaultValueInRedirectingFactoryConstructor() { | 1474 void test_defaultValueInRedirectingFactoryConstructor() { |
1466 Source source = addSource(r''' | 1475 Source source = addSource(r''' |
1467 class A { | 1476 class A { |
1468 factory A([int x = 0]) = B; | 1477 factory A([int x = 0]) = B; |
1469 } | 1478 } |
1470 | 1479 |
1471 class B implements A { | 1480 class B implements A { |
1472 B([int x = 1]) {} | 1481 B([int x = 1]) {} |
1473 }'''); | 1482 }'''); |
1474 resolve(source); | 1483 computeLibrarySourceErrors(source); |
1475 assertErrors(source, [ | 1484 assertErrors(source, [ |
1476 CompileTimeErrorCode.DEFAULT_VALUE_IN_REDIRECTING_FACTORY_CONSTRUCTOR | 1485 CompileTimeErrorCode.DEFAULT_VALUE_IN_REDIRECTING_FACTORY_CONSTRUCTOR |
1477 ]); | 1486 ]); |
1478 verify([source]); | 1487 verify([source]); |
1479 } | 1488 } |
1480 | 1489 |
1481 void test_duplicateConstructorName_named() { | 1490 void test_duplicateConstructorName_named() { |
1482 Source source = addSource(r''' | 1491 Source source = addSource(r''' |
1483 class A { | 1492 class A { |
1484 A.a() {} | 1493 A.a() {} |
1485 A.a() {} | 1494 A.a() {} |
1486 }'''); | 1495 }'''); |
1487 resolve(source); | 1496 computeLibrarySourceErrors(source); |
1488 assertErrors(source, [ | 1497 assertErrors(source, [ |
1489 CompileTimeErrorCode.DUPLICATE_CONSTRUCTOR_NAME, | 1498 CompileTimeErrorCode.DUPLICATE_CONSTRUCTOR_NAME, |
1490 CompileTimeErrorCode.DUPLICATE_CONSTRUCTOR_NAME | 1499 CompileTimeErrorCode.DUPLICATE_CONSTRUCTOR_NAME |
1491 ]); | 1500 ]); |
1492 verify([source]); | 1501 verify([source]); |
1493 } | 1502 } |
1494 | 1503 |
1495 void test_duplicateConstructorName_unnamed() { | 1504 void test_duplicateConstructorName_unnamed() { |
1496 Source source = addSource(r''' | 1505 Source source = addSource(r''' |
1497 class A { | 1506 class A { |
1498 A() {} | 1507 A() {} |
1499 A() {} | 1508 A() {} |
1500 }'''); | 1509 }'''); |
1501 resolve(source); | 1510 computeLibrarySourceErrors(source); |
1502 assertErrors(source, [ | 1511 assertErrors(source, [ |
1503 CompileTimeErrorCode.DUPLICATE_CONSTRUCTOR_DEFAULT, | 1512 CompileTimeErrorCode.DUPLICATE_CONSTRUCTOR_DEFAULT, |
1504 CompileTimeErrorCode.DUPLICATE_CONSTRUCTOR_DEFAULT | 1513 CompileTimeErrorCode.DUPLICATE_CONSTRUCTOR_DEFAULT |
1505 ]); | 1514 ]); |
1506 verify([source]); | 1515 verify([source]); |
1507 } | 1516 } |
1508 | 1517 |
1509 void test_duplicateDefinition() { | |
1510 Source source = addSource(r''' | |
1511 f() { | |
1512 int m = 0; | |
1513 m(a) {} | |
1514 }'''); | |
1515 resolve(source); | |
1516 assertErrors(source, [CompileTimeErrorCode.DUPLICATE_DEFINITION]); | |
1517 verify([source]); | |
1518 } | |
1519 | |
1520 void test_duplicateDefinition_acrossLibraries() { | 1518 void test_duplicateDefinition_acrossLibraries() { |
1521 Source librarySource = addNamedSource("/lib.dart", r''' | 1519 Source librarySource = addNamedSource("/lib.dart", r''' |
1522 library lib; | 1520 library lib; |
1523 | 1521 |
1524 part 'a.dart'; | 1522 part 'a.dart'; |
1525 part 'b.dart';'''); | 1523 part 'b.dart';'''); |
1526 Source sourceA = addNamedSource("/a.dart", r''' | 1524 Source sourceA = addNamedSource("/a.dart", r''' |
1527 part of lib; | 1525 part of lib; |
1528 | 1526 |
1529 class A {}'''); | 1527 class A {}'''); |
1530 Source sourceB = addNamedSource("/b.dart", r''' | 1528 Source sourceB = addNamedSource("/b.dart", r''' |
1531 part of lib; | 1529 part of lib; |
1532 | 1530 |
1533 class A {}'''); | 1531 class A {}'''); |
1534 resolve(librarySource); | 1532 computeLibrarySourceErrors(librarySource); |
1535 assertErrors(sourceB, [CompileTimeErrorCode.DUPLICATE_DEFINITION]); | 1533 assertErrors(sourceB, [CompileTimeErrorCode.DUPLICATE_DEFINITION]); |
1536 verify([librarySource, sourceA, sourceB]); | 1534 verify([librarySource, sourceA, sourceB]); |
1537 } | 1535 } |
1538 | 1536 |
| 1537 void test_duplicateDefinition_catch() { |
| 1538 Source source = addSource(r''' |
| 1539 main() { |
| 1540 try {} catch (e, e) {} |
| 1541 }'''); |
| 1542 computeLibrarySourceErrors(source); |
| 1543 assertErrors(source, [CompileTimeErrorCode.DUPLICATE_DEFINITION]); |
| 1544 verify([source]); |
| 1545 } |
| 1546 |
1539 void test_duplicateDefinition_classMembers_fields() { | 1547 void test_duplicateDefinition_classMembers_fields() { |
1540 Source source = addSource(r''' | 1548 Source source = addSource(r''' |
1541 class A { | 1549 class A { |
1542 int a; | 1550 int a; |
1543 int a; | 1551 int a; |
1544 }'''); | 1552 }'''); |
1545 resolve(source); | 1553 computeLibrarySourceErrors(source); |
1546 assertErrors(source, [CompileTimeErrorCode.DUPLICATE_DEFINITION]); | 1554 assertErrors(source, [CompileTimeErrorCode.DUPLICATE_DEFINITION]); |
1547 verify([source]); | 1555 verify([source]); |
1548 } | 1556 } |
1549 | 1557 |
1550 void test_duplicateDefinition_classMembers_fields_oneStatic() { | 1558 void test_duplicateDefinition_classMembers_fields_oneStatic() { |
1551 Source source = addSource(r''' | 1559 Source source = addSource(r''' |
1552 class A { | 1560 class A { |
1553 int x; | 1561 int x; |
1554 static int x; | 1562 static int x; |
1555 }'''); | 1563 }'''); |
1556 resolve(source); | 1564 computeLibrarySourceErrors(source); |
1557 assertErrors(source, [CompileTimeErrorCode.DUPLICATE_DEFINITION]); | 1565 assertErrors(source, [CompileTimeErrorCode.DUPLICATE_DEFINITION]); |
1558 verify([source]); | 1566 verify([source]); |
1559 } | 1567 } |
1560 | 1568 |
1561 void test_duplicateDefinition_classMembers_methods() { | 1569 void test_duplicateDefinition_classMembers_methods() { |
1562 Source source = addSource(r''' | 1570 Source source = addSource(r''' |
1563 class A { | 1571 class A { |
1564 m() {} | 1572 m() {} |
1565 m() {} | 1573 m() {} |
1566 }'''); | 1574 }'''); |
1567 resolve(source); | 1575 computeLibrarySourceErrors(source); |
1568 assertErrors(source, [CompileTimeErrorCode.DUPLICATE_DEFINITION]); | 1576 assertErrors(source, [CompileTimeErrorCode.DUPLICATE_DEFINITION]); |
1569 verify([source]); | 1577 verify([source]); |
1570 } | 1578 } |
1571 | 1579 |
1572 void test_duplicateDefinition_localFields() { | 1580 void test_duplicateDefinition_locals_inCase() { |
| 1581 Source source = addSource(r''' |
| 1582 main() { |
| 1583 switch(1) { |
| 1584 case 1: |
| 1585 var a; |
| 1586 var a; |
| 1587 } |
| 1588 }'''); |
| 1589 computeLibrarySourceErrors(source); |
| 1590 assertErrors(source, [CompileTimeErrorCode.DUPLICATE_DEFINITION]); |
| 1591 verify([source]); |
| 1592 } |
| 1593 |
| 1594 void test_duplicateDefinition_locals_inFunctionBlock() { |
| 1595 Source source = addSource(r''' |
| 1596 main() { |
| 1597 int m = 0; |
| 1598 m(a) {} |
| 1599 }'''); |
| 1600 computeLibrarySourceErrors(source); |
| 1601 assertErrors(source, [CompileTimeErrorCode.DUPLICATE_DEFINITION]); |
| 1602 verify([source]); |
| 1603 } |
| 1604 |
| 1605 void test_duplicateDefinition_locals_inIf() { |
| 1606 Source source = addSource(r''' |
| 1607 main(int p) { |
| 1608 if (p != 0) { |
| 1609 var a; |
| 1610 var a; |
| 1611 } |
| 1612 }'''); |
| 1613 computeLibrarySourceErrors(source); |
| 1614 assertErrors(source, [CompileTimeErrorCode.DUPLICATE_DEFINITION]); |
| 1615 verify([source]); |
| 1616 } |
| 1617 |
| 1618 void test_duplicateDefinition_locals_inMethodBlock() { |
1573 Source source = addSource(r''' | 1619 Source source = addSource(r''' |
1574 class A { | 1620 class A { |
1575 m() { | 1621 m() { |
1576 int a; | 1622 int a; |
1577 int a; | 1623 int a; |
1578 } | 1624 } |
1579 }'''); | 1625 }'''); |
1580 resolve(source); | 1626 computeLibrarySourceErrors(source); |
1581 assertErrors(source, [CompileTimeErrorCode.DUPLICATE_DEFINITION]); | 1627 assertErrors(source, [CompileTimeErrorCode.DUPLICATE_DEFINITION]); |
1582 verify([source]); | 1628 verify([source]); |
1583 } | 1629 } |
| 1630 |
| 1631 void test_duplicateDefinition_parameters_inFunctionTypeAlias() { |
| 1632 Source source = addSource(r''' |
| 1633 typedef F(int a, double a); |
| 1634 '''); |
| 1635 computeLibrarySourceErrors(source); |
| 1636 assertErrors(source, [CompileTimeErrorCode.DUPLICATE_DEFINITION]); |
| 1637 verify([source]); |
| 1638 } |
| 1639 |
| 1640 void test_duplicateDefinition_parameters_inLocalFunction() { |
| 1641 Source source = addSource(r''' |
| 1642 main() { |
| 1643 f(int a, double a) { |
| 1644 }; |
| 1645 }'''); |
| 1646 computeLibrarySourceErrors(source); |
| 1647 assertErrors(source, [CompileTimeErrorCode.DUPLICATE_DEFINITION]); |
| 1648 verify([source]); |
| 1649 } |
| 1650 |
| 1651 void test_duplicateDefinition_parameters_inMethod() { |
| 1652 Source source = addSource(r''' |
| 1653 class A { |
| 1654 m(int a, double a) { |
| 1655 } |
| 1656 }'''); |
| 1657 computeLibrarySourceErrors(source); |
| 1658 assertErrors(source, [CompileTimeErrorCode.DUPLICATE_DEFINITION]); |
| 1659 verify([source]); |
| 1660 } |
| 1661 |
| 1662 void test_duplicateDefinition_parameters_inTopLevelFunction() { |
| 1663 Source source = addSource(r''' |
| 1664 f(int a, double a) { |
| 1665 }'''); |
| 1666 computeLibrarySourceErrors(source); |
| 1667 assertErrors(source, [CompileTimeErrorCode.DUPLICATE_DEFINITION]); |
| 1668 verify([source]); |
| 1669 } |
| 1670 |
| 1671 void test_duplicateDefinition_typeParameters() { |
| 1672 Source source = addSource(r''' |
| 1673 class A<T, T> { |
| 1674 }'''); |
| 1675 computeLibrarySourceErrors(source); |
| 1676 assertErrors(source, [CompileTimeErrorCode.DUPLICATE_DEFINITION]); |
| 1677 verify([source]); |
| 1678 } |
1584 | 1679 |
1585 void test_duplicateDefinitionInheritance_instanceGetter_staticGetter() { | 1680 void test_duplicateDefinitionInheritance_instanceGetter_staticGetter() { |
1586 Source source = addSource(r''' | 1681 Source source = addSource(r''' |
1587 class A { | 1682 class A { |
1588 int get x => 0; | 1683 int get x => 0; |
1589 } | 1684 } |
1590 class B extends A { | 1685 class B extends A { |
1591 static int get x => 0; | 1686 static int get x => 0; |
1592 }'''); | 1687 }'''); |
1593 resolve(source); | 1688 computeLibrarySourceErrors(source); |
1594 assertErrors( | 1689 assertErrors( |
1595 source, [CompileTimeErrorCode.DUPLICATE_DEFINITION_INHERITANCE]); | 1690 source, [CompileTimeErrorCode.DUPLICATE_DEFINITION_INHERITANCE]); |
1596 verify([source]); | 1691 verify([source]); |
1597 } | 1692 } |
1598 | 1693 |
1599 void test_duplicateDefinitionInheritance_instanceGetterAbstract_staticGetter()
{ | 1694 void test_duplicateDefinitionInheritance_instanceGetterAbstract_staticGetter()
{ |
1600 Source source = addSource(r''' | 1695 Source source = addSource(r''' |
1601 abstract class A { | 1696 abstract class A { |
1602 int get x; | 1697 int get x; |
1603 } | 1698 } |
1604 class B extends A { | 1699 class B extends A { |
1605 static int get x => 0; | 1700 static int get x => 0; |
1606 }'''); | 1701 }'''); |
1607 resolve(source); | 1702 computeLibrarySourceErrors(source); |
1608 assertErrors( | 1703 assertErrors( |
1609 source, [CompileTimeErrorCode.DUPLICATE_DEFINITION_INHERITANCE]); | 1704 source, [CompileTimeErrorCode.DUPLICATE_DEFINITION_INHERITANCE]); |
1610 verify([source]); | 1705 verify([source]); |
1611 } | 1706 } |
1612 | 1707 |
1613 void test_duplicateDefinitionInheritance_instanceMethod_staticMethod() { | 1708 void test_duplicateDefinitionInheritance_instanceMethod_staticMethod() { |
1614 Source source = addSource(r''' | 1709 Source source = addSource(r''' |
1615 class A { | 1710 class A { |
1616 x() {} | 1711 x() {} |
1617 } | 1712 } |
1618 class B extends A { | 1713 class B extends A { |
1619 static x() {} | 1714 static x() {} |
1620 }'''); | 1715 }'''); |
1621 resolve(source); | 1716 computeLibrarySourceErrors(source); |
1622 assertErrors( | 1717 assertErrors( |
1623 source, [CompileTimeErrorCode.DUPLICATE_DEFINITION_INHERITANCE]); | 1718 source, [CompileTimeErrorCode.DUPLICATE_DEFINITION_INHERITANCE]); |
1624 verify([source]); | 1719 verify([source]); |
1625 } | 1720 } |
1626 | 1721 |
1627 void test_duplicateDefinitionInheritance_instanceMethodAbstract_staticMethod()
{ | 1722 void test_duplicateDefinitionInheritance_instanceMethodAbstract_staticMethod()
{ |
1628 Source source = addSource(r''' | 1723 Source source = addSource(r''' |
1629 abstract class A { | 1724 abstract class A { |
1630 x(); | 1725 x(); |
1631 } | 1726 } |
1632 abstract class B extends A { | 1727 abstract class B extends A { |
1633 static x() {} | 1728 static x() {} |
1634 }'''); | 1729 }'''); |
1635 resolve(source); | 1730 computeLibrarySourceErrors(source); |
1636 assertErrors( | 1731 assertErrors( |
1637 source, [CompileTimeErrorCode.DUPLICATE_DEFINITION_INHERITANCE]); | 1732 source, [CompileTimeErrorCode.DUPLICATE_DEFINITION_INHERITANCE]); |
1638 verify([source]); | 1733 verify([source]); |
1639 } | 1734 } |
1640 | 1735 |
1641 void test_duplicateDefinitionInheritance_instanceSetter_staticSetter() { | 1736 void test_duplicateDefinitionInheritance_instanceSetter_staticSetter() { |
1642 Source source = addSource(r''' | 1737 Source source = addSource(r''' |
1643 class A { | 1738 class A { |
1644 set x(value) {} | 1739 set x(value) {} |
1645 } | 1740 } |
1646 class B extends A { | 1741 class B extends A { |
1647 static set x(value) {} | 1742 static set x(value) {} |
1648 }'''); | 1743 }'''); |
1649 resolve(source); | 1744 computeLibrarySourceErrors(source); |
1650 assertErrors( | 1745 assertErrors( |
1651 source, [CompileTimeErrorCode.DUPLICATE_DEFINITION_INHERITANCE]); | 1746 source, [CompileTimeErrorCode.DUPLICATE_DEFINITION_INHERITANCE]); |
1652 verify([source]); | 1747 verify([source]); |
1653 } | 1748 } |
1654 | 1749 |
1655 void test_duplicateDefinitionInheritance_instanceSetterAbstract_staticSetter()
{ | 1750 void test_duplicateDefinitionInheritance_instanceSetterAbstract_staticSetter()
{ |
1656 Source source = addSource(r''' | 1751 Source source = addSource(r''' |
1657 abstract class A { | 1752 abstract class A { |
1658 set x(value); | 1753 set x(value); |
1659 } | 1754 } |
1660 class B extends A { | 1755 class B extends A { |
1661 static set x(value) {} | 1756 static set x(value) {} |
1662 }'''); | 1757 }'''); |
1663 resolve(source); | 1758 computeLibrarySourceErrors(source); |
1664 assertErrors( | 1759 assertErrors( |
1665 source, [CompileTimeErrorCode.DUPLICATE_DEFINITION_INHERITANCE]); | 1760 source, [CompileTimeErrorCode.DUPLICATE_DEFINITION_INHERITANCE]); |
1666 verify([source]); | 1761 verify([source]); |
1667 } | 1762 } |
1668 | 1763 |
1669 void test_duplicateNamedArgument() { | 1764 void test_duplicateNamedArgument() { |
1670 Source source = addSource(r''' | 1765 Source source = addSource(r''' |
1671 f({a, b}) {} | 1766 f({a, b}) {} |
1672 main() { | 1767 main() { |
1673 f(a: 1, a: 2); | 1768 f(a: 1, a: 2); |
1674 }'''); | 1769 }'''); |
1675 resolve(source); | 1770 computeLibrarySourceErrors(source); |
1676 assertErrors(source, [CompileTimeErrorCode.DUPLICATE_NAMED_ARGUMENT]); | 1771 assertErrors(source, [CompileTimeErrorCode.DUPLICATE_NAMED_ARGUMENT]); |
1677 verify([source]); | 1772 verify([source]); |
1678 } | 1773 } |
1679 | 1774 |
1680 void test_exportInternalLibrary() { | 1775 void test_exportInternalLibrary() { |
1681 Source source = addSource("export 'dart:_interceptors';"); | 1776 Source source = addSource("export 'dart:_interceptors';"); |
1682 resolve(source); | 1777 computeLibrarySourceErrors(source); |
1683 assertErrors(source, [CompileTimeErrorCode.EXPORT_INTERNAL_LIBRARY]); | 1778 assertErrors(source, [CompileTimeErrorCode.EXPORT_INTERNAL_LIBRARY]); |
1684 verify([source]); | 1779 verify([source]); |
1685 } | 1780 } |
1686 | 1781 |
1687 void test_exportOfNonLibrary() { | 1782 void test_exportOfNonLibrary() { |
1688 Source source = addSource(r''' | 1783 Source source = addSource(r''' |
1689 library L; | 1784 library L; |
1690 export 'lib1.dart';'''); | 1785 export 'lib1.dart';'''); |
1691 addNamedSource("/lib1.dart", "part of lib;"); | 1786 addNamedSource("/lib1.dart", "part of lib;"); |
1692 resolve(source); | 1787 computeLibrarySourceErrors(source); |
1693 assertErrors(source, [CompileTimeErrorCode.EXPORT_OF_NON_LIBRARY]); | 1788 assertErrors(source, [CompileTimeErrorCode.EXPORT_OF_NON_LIBRARY]); |
1694 verify([source]); | 1789 verify([source]); |
1695 } | 1790 } |
1696 | 1791 |
1697 void test_extendsDeferredClass() { | 1792 void test_extendsDeferredClass() { |
1698 resolveWithErrors(<String>[ | 1793 resolveWithErrors(<String>[ |
1699 r''' | 1794 r''' |
1700 library lib1; | 1795 library lib1; |
1701 class A {}''', | 1796 class A {}''', |
1702 r''' | 1797 r''' |
(...skipping 11 matching lines...) Expand all Loading... |
1714 r''' | 1809 r''' |
1715 library root; | 1810 library root; |
1716 import 'lib1.dart' deferred as a; | 1811 import 'lib1.dart' deferred as a; |
1717 class M {} | 1812 class M {} |
1718 class C = a.A with M;''' | 1813 class C = a.A with M;''' |
1719 ], <ErrorCode>[CompileTimeErrorCode.EXTENDS_DEFERRED_CLASS]); | 1814 ], <ErrorCode>[CompileTimeErrorCode.EXTENDS_DEFERRED_CLASS]); |
1720 } | 1815 } |
1721 | 1816 |
1722 void test_extendsDisallowedClass_class_bool() { | 1817 void test_extendsDisallowedClass_class_bool() { |
1723 Source source = addSource("class A extends bool {}"); | 1818 Source source = addSource("class A extends bool {}"); |
1724 resolve(source); | 1819 computeLibrarySourceErrors(source); |
1725 assertErrors(source, [ | 1820 assertErrors(source, [ |
1726 CompileTimeErrorCode.EXTENDS_DISALLOWED_CLASS, | 1821 CompileTimeErrorCode.EXTENDS_DISALLOWED_CLASS, |
1727 CompileTimeErrorCode.NO_DEFAULT_SUPER_CONSTRUCTOR_IMPLICIT | 1822 CompileTimeErrorCode.NO_DEFAULT_SUPER_CONSTRUCTOR_IMPLICIT |
1728 ]); | 1823 ]); |
1729 verify([source]); | 1824 verify([source]); |
1730 } | 1825 } |
1731 | 1826 |
1732 void test_extendsDisallowedClass_class_double() { | 1827 void test_extendsDisallowedClass_class_double() { |
1733 Source source = addSource("class A extends double {}"); | 1828 Source source = addSource("class A extends double {}"); |
1734 resolve(source); | 1829 computeLibrarySourceErrors(source); |
1735 assertErrors(source, [ | 1830 assertErrors(source, [ |
1736 CompileTimeErrorCode.EXTENDS_DISALLOWED_CLASS, | 1831 CompileTimeErrorCode.EXTENDS_DISALLOWED_CLASS, |
1737 CompileTimeErrorCode.NO_DEFAULT_SUPER_CONSTRUCTOR_IMPLICIT | 1832 CompileTimeErrorCode.NO_DEFAULT_SUPER_CONSTRUCTOR_IMPLICIT |
1738 ]); | 1833 ]); |
1739 verify([source]); | 1834 verify([source]); |
1740 } | 1835 } |
1741 | 1836 |
1742 void test_extendsDisallowedClass_class_int() { | 1837 void test_extendsDisallowedClass_class_int() { |
1743 Source source = addSource("class A extends int {}"); | 1838 Source source = addSource("class A extends int {}"); |
1744 resolve(source); | 1839 computeLibrarySourceErrors(source); |
1745 assertErrors(source, [ | 1840 assertErrors(source, [ |
1746 CompileTimeErrorCode.EXTENDS_DISALLOWED_CLASS, | 1841 CompileTimeErrorCode.EXTENDS_DISALLOWED_CLASS, |
1747 CompileTimeErrorCode.NO_DEFAULT_SUPER_CONSTRUCTOR_IMPLICIT | 1842 CompileTimeErrorCode.NO_DEFAULT_SUPER_CONSTRUCTOR_IMPLICIT |
1748 ]); | 1843 ]); |
1749 verify([source]); | 1844 verify([source]); |
1750 } | 1845 } |
1751 | 1846 |
1752 void test_extendsDisallowedClass_class_Null() { | 1847 void test_extendsDisallowedClass_class_Null() { |
1753 Source source = addSource("class A extends Null {}"); | 1848 Source source = addSource("class A extends Null {}"); |
1754 resolve(source); | 1849 computeLibrarySourceErrors(source); |
1755 assertErrors(source, [ | 1850 assertErrors(source, [ |
1756 CompileTimeErrorCode.EXTENDS_DISALLOWED_CLASS, | 1851 CompileTimeErrorCode.EXTENDS_DISALLOWED_CLASS, |
1757 CompileTimeErrorCode.NO_DEFAULT_SUPER_CONSTRUCTOR_IMPLICIT | 1852 CompileTimeErrorCode.NO_DEFAULT_SUPER_CONSTRUCTOR_IMPLICIT |
1758 ]); | 1853 ]); |
1759 verify([source]); | 1854 verify([source]); |
1760 } | 1855 } |
1761 | 1856 |
1762 void test_extendsDisallowedClass_class_num() { | 1857 void test_extendsDisallowedClass_class_num() { |
1763 Source source = addSource("class A extends num {}"); | 1858 Source source = addSource("class A extends num {}"); |
1764 resolve(source); | 1859 computeLibrarySourceErrors(source); |
1765 assertErrors(source, [ | 1860 assertErrors(source, [ |
1766 CompileTimeErrorCode.EXTENDS_DISALLOWED_CLASS, | 1861 CompileTimeErrorCode.EXTENDS_DISALLOWED_CLASS, |
1767 CompileTimeErrorCode.NO_DEFAULT_SUPER_CONSTRUCTOR_IMPLICIT | 1862 CompileTimeErrorCode.NO_DEFAULT_SUPER_CONSTRUCTOR_IMPLICIT |
1768 ]); | 1863 ]); |
1769 verify([source]); | 1864 verify([source]); |
1770 } | 1865 } |
1771 | 1866 |
1772 void test_extendsDisallowedClass_class_String() { | 1867 void test_extendsDisallowedClass_class_String() { |
1773 Source source = addSource("class A extends String {}"); | 1868 Source source = addSource("class A extends String {}"); |
1774 resolve(source); | 1869 computeLibrarySourceErrors(source); |
1775 assertErrors(source, [ | 1870 assertErrors(source, [ |
1776 CompileTimeErrorCode.EXTENDS_DISALLOWED_CLASS, | 1871 CompileTimeErrorCode.EXTENDS_DISALLOWED_CLASS, |
1777 CompileTimeErrorCode.NO_DEFAULT_SUPER_CONSTRUCTOR_IMPLICIT | 1872 CompileTimeErrorCode.NO_DEFAULT_SUPER_CONSTRUCTOR_IMPLICIT |
1778 ]); | 1873 ]); |
1779 verify([source]); | 1874 verify([source]); |
1780 } | 1875 } |
1781 | 1876 |
1782 void test_extendsDisallowedClass_classTypeAlias_bool() { | 1877 void test_extendsDisallowedClass_classTypeAlias_bool() { |
1783 Source source = addSource(r''' | 1878 Source source = addSource(r''' |
1784 class M {} | 1879 class M {} |
1785 class C = bool with M;'''); | 1880 class C = bool with M;'''); |
1786 resolve(source); | 1881 computeLibrarySourceErrors(source); |
1787 assertErrors(source, [ | 1882 assertErrors(source, [ |
1788 CompileTimeErrorCode.EXTENDS_DISALLOWED_CLASS, | 1883 CompileTimeErrorCode.EXTENDS_DISALLOWED_CLASS, |
1789 CompileTimeErrorCode.MIXIN_HAS_NO_CONSTRUCTORS | 1884 CompileTimeErrorCode.MIXIN_HAS_NO_CONSTRUCTORS |
1790 ]); | 1885 ]); |
1791 verify([source]); | 1886 verify([source]); |
1792 } | 1887 } |
1793 | 1888 |
1794 void test_extendsDisallowedClass_classTypeAlias_double() { | 1889 void test_extendsDisallowedClass_classTypeAlias_double() { |
1795 Source source = addSource(r''' | 1890 Source source = addSource(r''' |
1796 class M {} | 1891 class M {} |
1797 class C = double with M;'''); | 1892 class C = double with M;'''); |
1798 resolve(source); | 1893 computeLibrarySourceErrors(source); |
1799 assertErrors(source, [CompileTimeErrorCode.EXTENDS_DISALLOWED_CLASS]); | 1894 assertErrors(source, [CompileTimeErrorCode.EXTENDS_DISALLOWED_CLASS]); |
1800 verify([source]); | 1895 verify([source]); |
1801 } | 1896 } |
1802 | 1897 |
1803 void test_extendsDisallowedClass_classTypeAlias_int() { | 1898 void test_extendsDisallowedClass_classTypeAlias_int() { |
1804 Source source = addSource(r''' | 1899 Source source = addSource(r''' |
1805 class M {} | 1900 class M {} |
1806 class C = int with M;'''); | 1901 class C = int with M;'''); |
1807 resolve(source); | 1902 computeLibrarySourceErrors(source); |
1808 assertErrors(source, [ | 1903 assertErrors(source, [ |
1809 CompileTimeErrorCode.EXTENDS_DISALLOWED_CLASS, | 1904 CompileTimeErrorCode.EXTENDS_DISALLOWED_CLASS, |
1810 CompileTimeErrorCode.MIXIN_HAS_NO_CONSTRUCTORS | 1905 CompileTimeErrorCode.MIXIN_HAS_NO_CONSTRUCTORS |
1811 ]); | 1906 ]); |
1812 verify([source]); | 1907 verify([source]); |
1813 } | 1908 } |
1814 | 1909 |
1815 void test_extendsDisallowedClass_classTypeAlias_Null() { | 1910 void test_extendsDisallowedClass_classTypeAlias_Null() { |
1816 Source source = addSource(r''' | 1911 Source source = addSource(r''' |
1817 class M {} | 1912 class M {} |
1818 class C = Null with M;'''); | 1913 class C = Null with M;'''); |
1819 resolve(source); | 1914 computeLibrarySourceErrors(source); |
1820 assertErrors(source, [CompileTimeErrorCode.EXTENDS_DISALLOWED_CLASS]); | 1915 assertErrors(source, [CompileTimeErrorCode.EXTENDS_DISALLOWED_CLASS]); |
1821 verify([source]); | 1916 verify([source]); |
1822 } | 1917 } |
1823 | 1918 |
1824 void test_extendsDisallowedClass_classTypeAlias_num() { | 1919 void test_extendsDisallowedClass_classTypeAlias_num() { |
1825 Source source = addSource(r''' | 1920 Source source = addSource(r''' |
1826 class M {} | 1921 class M {} |
1827 class C = num with M;'''); | 1922 class C = num with M;'''); |
1828 resolve(source); | 1923 computeLibrarySourceErrors(source); |
1829 assertErrors(source, [CompileTimeErrorCode.EXTENDS_DISALLOWED_CLASS]); | 1924 assertErrors(source, [CompileTimeErrorCode.EXTENDS_DISALLOWED_CLASS]); |
1830 verify([source]); | 1925 verify([source]); |
1831 } | 1926 } |
1832 | 1927 |
1833 void test_extendsDisallowedClass_classTypeAlias_String() { | 1928 void test_extendsDisallowedClass_classTypeAlias_String() { |
1834 Source source = addSource(r''' | 1929 Source source = addSource(r''' |
1835 class M {} | 1930 class M {} |
1836 class C = String with M;'''); | 1931 class C = String with M;'''); |
1837 resolve(source); | 1932 computeLibrarySourceErrors(source); |
1838 assertErrors(source, [ | 1933 assertErrors(source, [ |
1839 CompileTimeErrorCode.EXTENDS_DISALLOWED_CLASS, | 1934 CompileTimeErrorCode.EXTENDS_DISALLOWED_CLASS, |
1840 CompileTimeErrorCode.MIXIN_HAS_NO_CONSTRUCTORS | 1935 CompileTimeErrorCode.MIXIN_HAS_NO_CONSTRUCTORS |
1841 ]); | 1936 ]); |
1842 verify([source]); | 1937 verify([source]); |
1843 } | 1938 } |
1844 | 1939 |
1845 void test_extendsEnum() { | 1940 void test_extendsEnum() { |
1846 Source source = addSource(r''' | 1941 Source source = addSource(r''' |
1847 enum E { ONE } | 1942 enum E { ONE } |
1848 class A extends E {}'''); | 1943 class A extends E {}'''); |
1849 resolve(source); | 1944 computeLibrarySourceErrors(source); |
1850 assertErrors(source, [CompileTimeErrorCode.EXTENDS_ENUM]); | 1945 assertErrors(source, [CompileTimeErrorCode.EXTENDS_ENUM]); |
1851 verify([source]); | 1946 verify([source]); |
1852 } | 1947 } |
1853 | 1948 |
1854 void test_extendsNonClass_class() { | 1949 void test_extendsNonClass_class() { |
1855 Source source = addSource(r''' | 1950 Source source = addSource(r''' |
1856 int A; | 1951 int A; |
1857 class B extends A {}'''); | 1952 class B extends A {}'''); |
1858 resolve(source); | 1953 computeLibrarySourceErrors(source); |
1859 assertErrors(source, [CompileTimeErrorCode.EXTENDS_NON_CLASS]); | 1954 assertErrors(source, [CompileTimeErrorCode.EXTENDS_NON_CLASS]); |
1860 verify([source]); | 1955 verify([source]); |
1861 } | 1956 } |
1862 | 1957 |
1863 void test_extendsNonClass_dynamic() { | 1958 void test_extendsNonClass_dynamic() { |
1864 Source source = addSource("class B extends dynamic {}"); | 1959 Source source = addSource("class B extends dynamic {}"); |
1865 resolve(source); | 1960 computeLibrarySourceErrors(source); |
1866 assertErrors(source, [CompileTimeErrorCode.EXTENDS_NON_CLASS]); | 1961 assertErrors(source, [CompileTimeErrorCode.EXTENDS_NON_CLASS]); |
1867 verify([source]); | 1962 verify([source]); |
1868 } | 1963 } |
1869 | 1964 |
1870 void test_extraPositionalArguments_const() { | 1965 void test_extraPositionalArguments_const() { |
1871 Source source = addSource(r''' | 1966 Source source = addSource(r''' |
1872 class A { | 1967 class A { |
1873 const A(); | 1968 const A(); |
1874 } | 1969 } |
1875 main() { | 1970 main() { |
1876 const A(0); | 1971 const A(0); |
1877 }'''); | 1972 }'''); |
1878 resolve(source); | 1973 computeLibrarySourceErrors(source); |
1879 assertErrors(source, [CompileTimeErrorCode.EXTRA_POSITIONAL_ARGUMENTS]); | 1974 assertErrors(source, [CompileTimeErrorCode.EXTRA_POSITIONAL_ARGUMENTS]); |
1880 verify([source]); | 1975 verify([source]); |
1881 } | 1976 } |
1882 | 1977 |
1883 void test_extraPositionalArguments_const_super() { | 1978 void test_extraPositionalArguments_const_super() { |
1884 Source source = addSource(r''' | 1979 Source source = addSource(r''' |
1885 class A { | 1980 class A { |
1886 const A(); | 1981 const A(); |
1887 } | 1982 } |
1888 class B extends A { | 1983 class B extends A { |
1889 const B() : super(0); | 1984 const B() : super(0); |
1890 }'''); | 1985 }'''); |
1891 resolve(source); | 1986 computeLibrarySourceErrors(source); |
1892 assertErrors(source, [CompileTimeErrorCode.EXTRA_POSITIONAL_ARGUMENTS]); | 1987 assertErrors(source, [CompileTimeErrorCode.EXTRA_POSITIONAL_ARGUMENTS]); |
1893 verify([source]); | 1988 verify([source]); |
1894 } | 1989 } |
1895 | 1990 |
1896 void test_fieldInitializedByMultipleInitializers() { | 1991 void test_fieldInitializedByMultipleInitializers() { |
1897 Source source = addSource(r''' | 1992 Source source = addSource(r''' |
1898 class A { | 1993 class A { |
1899 int x; | 1994 int x; |
1900 A() : x = 0, x = 1 {} | 1995 A() : x = 0, x = 1 {} |
1901 }'''); | 1996 }'''); |
1902 resolve(source); | 1997 computeLibrarySourceErrors(source); |
1903 assertErrors(source, | 1998 assertErrors(source, |
1904 [CompileTimeErrorCode.FIELD_INITIALIZED_BY_MULTIPLE_INITIALIZERS]); | 1999 [CompileTimeErrorCode.FIELD_INITIALIZED_BY_MULTIPLE_INITIALIZERS]); |
1905 verify([source]); | 2000 verify([source]); |
1906 } | 2001 } |
1907 | 2002 |
1908 void test_fieldInitializedByMultipleInitializers_multipleInits() { | 2003 void test_fieldInitializedByMultipleInitializers_multipleInits() { |
1909 Source source = addSource(r''' | 2004 Source source = addSource(r''' |
1910 class A { | 2005 class A { |
1911 int x; | 2006 int x; |
1912 A() : x = 0, x = 1, x = 2 {} | 2007 A() : x = 0, x = 1, x = 2 {} |
1913 }'''); | 2008 }'''); |
1914 resolve(source); | 2009 computeLibrarySourceErrors(source); |
1915 assertErrors(source, [ | 2010 assertErrors(source, [ |
1916 CompileTimeErrorCode.FIELD_INITIALIZED_BY_MULTIPLE_INITIALIZERS, | 2011 CompileTimeErrorCode.FIELD_INITIALIZED_BY_MULTIPLE_INITIALIZERS, |
1917 CompileTimeErrorCode.FIELD_INITIALIZED_BY_MULTIPLE_INITIALIZERS | 2012 CompileTimeErrorCode.FIELD_INITIALIZED_BY_MULTIPLE_INITIALIZERS |
1918 ]); | 2013 ]); |
1919 verify([source]); | 2014 verify([source]); |
1920 } | 2015 } |
1921 | 2016 |
1922 void test_fieldInitializedByMultipleInitializers_multipleNames() { | 2017 void test_fieldInitializedByMultipleInitializers_multipleNames() { |
1923 Source source = addSource(r''' | 2018 Source source = addSource(r''' |
1924 class A { | 2019 class A { |
1925 int x; | 2020 int x; |
1926 int y; | 2021 int y; |
1927 A() : x = 0, x = 1, y = 0, y = 1 {} | 2022 A() : x = 0, x = 1, y = 0, y = 1 {} |
1928 }'''); | 2023 }'''); |
1929 resolve(source); | 2024 computeLibrarySourceErrors(source); |
1930 assertErrors(source, [ | 2025 assertErrors(source, [ |
1931 CompileTimeErrorCode.FIELD_INITIALIZED_BY_MULTIPLE_INITIALIZERS, | 2026 CompileTimeErrorCode.FIELD_INITIALIZED_BY_MULTIPLE_INITIALIZERS, |
1932 CompileTimeErrorCode.FIELD_INITIALIZED_BY_MULTIPLE_INITIALIZERS | 2027 CompileTimeErrorCode.FIELD_INITIALIZED_BY_MULTIPLE_INITIALIZERS |
1933 ]); | 2028 ]); |
1934 verify([source]); | 2029 verify([source]); |
1935 } | 2030 } |
1936 | 2031 |
1937 void test_fieldInitializedInParameterAndInitializer() { | 2032 void test_fieldInitializedInParameterAndInitializer() { |
1938 Source source = addSource(r''' | 2033 Source source = addSource(r''' |
1939 class A { | 2034 class A { |
1940 int x; | 2035 int x; |
1941 A(this.x) : x = 1 {} | 2036 A(this.x) : x = 1 {} |
1942 }'''); | 2037 }'''); |
1943 resolve(source); | 2038 computeLibrarySourceErrors(source); |
1944 assertErrors(source, | 2039 assertErrors(source, |
1945 [CompileTimeErrorCode.FIELD_INITIALIZED_IN_PARAMETER_AND_INITIALIZER]); | 2040 [CompileTimeErrorCode.FIELD_INITIALIZED_IN_PARAMETER_AND_INITIALIZER]); |
1946 verify([source]); | 2041 verify([source]); |
1947 } | 2042 } |
1948 | 2043 |
1949 void test_fieldInitializerFactoryConstructor() { | 2044 void test_fieldInitializerFactoryConstructor() { |
1950 Source source = addSource(r''' | 2045 Source source = addSource(r''' |
1951 class A { | 2046 class A { |
1952 int x; | 2047 int x; |
1953 factory A(this.x) {} | 2048 factory A(this.x) {} |
1954 }'''); | 2049 }'''); |
1955 resolve(source); | 2050 computeLibrarySourceErrors(source); |
1956 assertErrors( | 2051 assertErrors( |
1957 source, [CompileTimeErrorCode.FIELD_INITIALIZER_FACTORY_CONSTRUCTOR]); | 2052 source, [CompileTimeErrorCode.FIELD_INITIALIZER_FACTORY_CONSTRUCTOR]); |
1958 verify([source]); | 2053 verify([source]); |
1959 } | 2054 } |
1960 | 2055 |
1961 void test_fieldInitializerOutsideConstructor() { | 2056 void test_fieldInitializerOutsideConstructor() { |
1962 // TODO(brianwilkerson) Fix the duplicate error messages. | 2057 // TODO(brianwilkerson) Fix the duplicate error messages. |
1963 Source source = addSource(r''' | 2058 Source source = addSource(r''' |
1964 class A { | 2059 class A { |
1965 int x; | 2060 int x; |
1966 m(this.x) {} | 2061 m(this.x) {} |
1967 }'''); | 2062 }'''); |
1968 resolve(source); | 2063 computeLibrarySourceErrors(source); |
1969 assertErrors(source, [ | 2064 assertErrors(source, [ |
1970 ParserErrorCode.FIELD_INITIALIZER_OUTSIDE_CONSTRUCTOR, | 2065 ParserErrorCode.FIELD_INITIALIZER_OUTSIDE_CONSTRUCTOR, |
1971 CompileTimeErrorCode.FIELD_INITIALIZER_OUTSIDE_CONSTRUCTOR | 2066 CompileTimeErrorCode.FIELD_INITIALIZER_OUTSIDE_CONSTRUCTOR |
1972 ]); | 2067 ]); |
1973 verify([source]); | 2068 verify([source]); |
1974 } | 2069 } |
1975 | 2070 |
1976 void test_fieldInitializerOutsideConstructor_defaultParameter() { | 2071 void test_fieldInitializerOutsideConstructor_defaultParameter() { |
1977 Source source = addSource(r''' | 2072 Source source = addSource(r''' |
1978 class A { | 2073 class A { |
1979 int x; | 2074 int x; |
1980 m([this.x]) {} | 2075 m([this.x]) {} |
1981 }'''); | 2076 }'''); |
1982 resolve(source); | 2077 computeLibrarySourceErrors(source); |
1983 assertErrors( | 2078 assertErrors( |
1984 source, [CompileTimeErrorCode.FIELD_INITIALIZER_OUTSIDE_CONSTRUCTOR]); | 2079 source, [CompileTimeErrorCode.FIELD_INITIALIZER_OUTSIDE_CONSTRUCTOR]); |
1985 verify([source]); | 2080 verify([source]); |
1986 } | 2081 } |
1987 | 2082 |
1988 void test_fieldInitializerRedirectingConstructor_afterRedirection() { | 2083 void test_fieldInitializerRedirectingConstructor_afterRedirection() { |
1989 Source source = addSource(r''' | 2084 Source source = addSource(r''' |
1990 class A { | 2085 class A { |
1991 int x; | 2086 int x; |
1992 A.named() {} | 2087 A.named() {} |
1993 A() : this.named(), x = 42; | 2088 A() : this.named(), x = 42; |
1994 }'''); | 2089 }'''); |
1995 resolve(source); | 2090 computeLibrarySourceErrors(source); |
1996 assertErrors(source, | 2091 assertErrors(source, |
1997 [CompileTimeErrorCode.FIELD_INITIALIZER_REDIRECTING_CONSTRUCTOR]); | 2092 [CompileTimeErrorCode.FIELD_INITIALIZER_REDIRECTING_CONSTRUCTOR]); |
1998 verify([source]); | 2093 verify([source]); |
1999 } | 2094 } |
2000 | 2095 |
2001 void test_fieldInitializerRedirectingConstructor_beforeRedirection() { | 2096 void test_fieldInitializerRedirectingConstructor_beforeRedirection() { |
2002 Source source = addSource(r''' | 2097 Source source = addSource(r''' |
2003 class A { | 2098 class A { |
2004 int x; | 2099 int x; |
2005 A.named() {} | 2100 A.named() {} |
2006 A() : x = 42, this.named(); | 2101 A() : x = 42, this.named(); |
2007 }'''); | 2102 }'''); |
2008 resolve(source); | 2103 computeLibrarySourceErrors(source); |
2009 assertErrors(source, | 2104 assertErrors(source, |
2010 [CompileTimeErrorCode.FIELD_INITIALIZER_REDIRECTING_CONSTRUCTOR]); | 2105 [CompileTimeErrorCode.FIELD_INITIALIZER_REDIRECTING_CONSTRUCTOR]); |
2011 verify([source]); | 2106 verify([source]); |
2012 } | 2107 } |
2013 | 2108 |
2014 void test_fieldInitializingFormalRedirectingConstructor() { | 2109 void test_fieldInitializingFormalRedirectingConstructor() { |
2015 Source source = addSource(r''' | 2110 Source source = addSource(r''' |
2016 class A { | 2111 class A { |
2017 int x; | 2112 int x; |
2018 A.named() {} | 2113 A.named() {} |
2019 A(this.x) : this.named(); | 2114 A(this.x) : this.named(); |
2020 }'''); | 2115 }'''); |
2021 resolve(source); | 2116 computeLibrarySourceErrors(source); |
2022 assertErrors(source, | 2117 assertErrors(source, |
2023 [CompileTimeErrorCode.FIELD_INITIALIZER_REDIRECTING_CONSTRUCTOR]); | 2118 [CompileTimeErrorCode.FIELD_INITIALIZER_REDIRECTING_CONSTRUCTOR]); |
2024 verify([source]); | 2119 verify([source]); |
2025 } | 2120 } |
2026 | 2121 |
2027 void test_finalInitializedMultipleTimes_initializers() { | 2122 void test_finalInitializedMultipleTimes_initializers() { |
2028 Source source = addSource(r''' | 2123 Source source = addSource(r''' |
2029 class A { | 2124 class A { |
2030 final x; | 2125 final x; |
2031 A() : x = 0, x = 0 {} | 2126 A() : x = 0, x = 0 {} |
2032 }'''); | 2127 }'''); |
2033 resolve(source); | 2128 computeLibrarySourceErrors(source); |
2034 assertErrors(source, | 2129 assertErrors(source, |
2035 [CompileTimeErrorCode.FIELD_INITIALIZED_BY_MULTIPLE_INITIALIZERS]); | 2130 [CompileTimeErrorCode.FIELD_INITIALIZED_BY_MULTIPLE_INITIALIZERS]); |
2036 verify([source]); | 2131 verify([source]); |
2037 } | 2132 } |
2038 | 2133 |
2039 /** | 2134 /** |
2040 * This test doesn't test the FINAL_INITIALIZED_MULTIPLE_TIMES code, but tests
the | 2135 * This test doesn't test the FINAL_INITIALIZED_MULTIPLE_TIMES code, but tests
the |
2041 * FIELD_INITIALIZED_IN_PARAMETER_AND_INITIALIZER code instead. It is provided
here to show | 2136 * FIELD_INITIALIZED_IN_PARAMETER_AND_INITIALIZER code instead. It is provided
here to show |
2042 * coverage over all of the permutations of initializers in constructor declar
ations. | 2137 * coverage over all of the permutations of initializers in constructor declar
ations. |
2043 * | 2138 * |
2044 * Note: FIELD_INITIALIZED_IN_PARAMETER_AND_INITIALIZER covers a subset of | 2139 * Note: FIELD_INITIALIZED_IN_PARAMETER_AND_INITIALIZER covers a subset of |
2045 * FINAL_INITIALIZED_MULTIPLE_TIMES, since it more specific, we use it instead
of the broader code | 2140 * FINAL_INITIALIZED_MULTIPLE_TIMES, since it more specific, we use it instead
of the broader code |
2046 */ | 2141 */ |
2047 void test_finalInitializedMultipleTimes_initializingFormal_initializer() { | 2142 void test_finalInitializedMultipleTimes_initializingFormal_initializer() { |
2048 Source source = addSource(r''' | 2143 Source source = addSource(r''' |
2049 class A { | 2144 class A { |
2050 final x; | 2145 final x; |
2051 A(this.x) : x = 0 {} | 2146 A(this.x) : x = 0 {} |
2052 }'''); | 2147 }'''); |
2053 resolve(source); | 2148 computeLibrarySourceErrors(source); |
2054 assertErrors(source, | 2149 assertErrors(source, |
2055 [CompileTimeErrorCode.FIELD_INITIALIZED_IN_PARAMETER_AND_INITIALIZER]); | 2150 [CompileTimeErrorCode.FIELD_INITIALIZED_IN_PARAMETER_AND_INITIALIZER]); |
2056 verify([source]); | 2151 verify([source]); |
2057 } | 2152 } |
2058 | 2153 |
2059 void test_finalInitializedMultipleTimes_initializingFormals() { | 2154 void test_finalInitializedMultipleTimes_initializingFormals() { |
2060 Source source = addSource(r''' | 2155 Source source = addSource(r''' |
2061 class A { | 2156 class A { |
2062 final x; | 2157 final x; |
2063 A(this.x, this.x) {} | 2158 A(this.x, this.x) {} |
2064 }'''); | 2159 }'''); |
2065 resolve(source); | 2160 computeLibrarySourceErrors(source); |
2066 assertErrors( | 2161 assertErrors( |
2067 source, [CompileTimeErrorCode.FINAL_INITIALIZED_MULTIPLE_TIMES]); | 2162 source, [CompileTimeErrorCode.FINAL_INITIALIZED_MULTIPLE_TIMES]); |
2068 verify([source]); | 2163 verify([source]); |
2069 } | 2164 } |
2070 | 2165 |
2071 void test_finalNotInitialized_instanceField_const_static() { | 2166 void test_finalNotInitialized_instanceField_const_static() { |
2072 Source source = addSource(r''' | 2167 Source source = addSource(r''' |
2073 class A { | 2168 class A { |
2074 static const F; | 2169 static const F; |
2075 }'''); | 2170 }'''); |
2076 resolve(source); | 2171 computeLibrarySourceErrors(source); |
2077 assertErrors(source, [CompileTimeErrorCode.CONST_NOT_INITIALIZED]); | 2172 assertErrors(source, [CompileTimeErrorCode.CONST_NOT_INITIALIZED]); |
2078 verify([source]); | 2173 verify([source]); |
2079 } | 2174 } |
2080 | 2175 |
2081 void test_finalNotInitialized_library_const() { | 2176 void test_finalNotInitialized_library_const() { |
2082 Source source = addSource("const F;"); | 2177 Source source = addSource("const F;"); |
2083 resolve(source); | 2178 computeLibrarySourceErrors(source); |
2084 assertErrors(source, [CompileTimeErrorCode.CONST_NOT_INITIALIZED]); | 2179 assertErrors(source, [CompileTimeErrorCode.CONST_NOT_INITIALIZED]); |
2085 verify([source]); | 2180 verify([source]); |
2086 } | 2181 } |
2087 | 2182 |
2088 void test_finalNotInitialized_local_const() { | 2183 void test_finalNotInitialized_local_const() { |
2089 Source source = addSource(r''' | 2184 Source source = addSource(r''' |
2090 f() { | 2185 f() { |
2091 const int x; | 2186 const int x; |
2092 }'''); | 2187 }'''); |
2093 resolve(source); | 2188 computeLibrarySourceErrors(source); |
2094 assertErrors(source, [CompileTimeErrorCode.CONST_NOT_INITIALIZED]); | 2189 assertErrors(source, [CompileTimeErrorCode.CONST_NOT_INITIALIZED]); |
2095 verify([source]); | 2190 verify([source]); |
2096 } | 2191 } |
2097 | 2192 |
2098 void test_fromEnvironment_bool_badArgs() { | 2193 void test_fromEnvironment_bool_badArgs() { |
2099 Source source = addSource(r''' | 2194 Source source = addSource(r''' |
2100 var b1 = const bool.fromEnvironment(1); | 2195 var b1 = const bool.fromEnvironment(1); |
2101 var b2 = const bool.fromEnvironment('x', defaultValue: 1);'''); | 2196 var b2 = const bool.fromEnvironment('x', defaultValue: 1);'''); |
2102 resolve(source); | 2197 computeLibrarySourceErrors(source); |
2103 assertErrors(source, [ | 2198 assertErrors(source, [ |
2104 CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION, | 2199 CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION, |
2105 StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE, | 2200 StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE, |
2106 CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION, | 2201 CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION, |
2107 StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE | 2202 StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE |
2108 ]); | 2203 ]); |
2109 verify([source]); | 2204 verify([source]); |
2110 } | 2205 } |
2111 | 2206 |
2112 void test_fromEnvironment_bool_badDefault_whenDefined() { | 2207 void test_fromEnvironment_bool_badDefault_whenDefined() { |
2113 // The type of the defaultValue needs to be correct even when the default | 2208 // The type of the defaultValue needs to be correct even when the default |
2114 // value isn't used (because the variable is defined in the environment). | 2209 // value isn't used (because the variable is defined in the environment). |
2115 analysisContext2.declaredVariables.define("x", "true"); | 2210 analysisContext2.declaredVariables.define("x", "true"); |
2116 Source source = | 2211 Source source = |
2117 addSource("var b = const bool.fromEnvironment('x', defaultValue: 1);"); | 2212 addSource("var b = const bool.fromEnvironment('x', defaultValue: 1);"); |
2118 resolve(source); | 2213 computeLibrarySourceErrors(source); |
2119 assertErrors(source, [ | 2214 assertErrors(source, [ |
2120 CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION, | 2215 CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION, |
2121 StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE | 2216 StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE |
2122 ]); | 2217 ]); |
2123 verify([source]); | 2218 verify([source]); |
2124 } | 2219 } |
2125 | 2220 |
2126 void test_getterAndMethodWithSameName() { | 2221 void test_getterAndMethodWithSameName() { |
2127 Source source = addSource(r''' | 2222 Source source = addSource(r''' |
2128 class A { | 2223 class A { |
2129 x(y) {} | 2224 x(y) {} |
2130 get x => 0; | 2225 get x => 0; |
2131 }'''); | 2226 }'''); |
2132 resolve(source); | 2227 computeLibrarySourceErrors(source); |
2133 assertErrors( | 2228 assertErrors( |
2134 source, [CompileTimeErrorCode.GETTER_AND_METHOD_WITH_SAME_NAME]); | 2229 source, [CompileTimeErrorCode.GETTER_AND_METHOD_WITH_SAME_NAME]); |
2135 verify([source]); | 2230 verify([source]); |
2136 } | 2231 } |
2137 | 2232 |
2138 void test_implementsDeferredClass() { | 2233 void test_implementsDeferredClass() { |
2139 resolveWithErrors(<String>[ | 2234 resolveWithErrors(<String>[ |
2140 r''' | 2235 r''' |
2141 library lib1; | 2236 library lib1; |
2142 class A {}''', | 2237 class A {}''', |
(...skipping 13 matching lines...) Expand all Loading... |
2156 library root; | 2251 library root; |
2157 import 'lib1.dart' deferred as a; | 2252 import 'lib1.dart' deferred as a; |
2158 class B {} | 2253 class B {} |
2159 class M {} | 2254 class M {} |
2160 class C = B with M implements a.A;''' | 2255 class C = B with M implements a.A;''' |
2161 ], <ErrorCode>[CompileTimeErrorCode.IMPLEMENTS_DEFERRED_CLASS]); | 2256 ], <ErrorCode>[CompileTimeErrorCode.IMPLEMENTS_DEFERRED_CLASS]); |
2162 } | 2257 } |
2163 | 2258 |
2164 void test_implementsDisallowedClass_class_bool() { | 2259 void test_implementsDisallowedClass_class_bool() { |
2165 Source source = addSource("class A implements bool {}"); | 2260 Source source = addSource("class A implements bool {}"); |
2166 resolve(source); | 2261 computeLibrarySourceErrors(source); |
2167 assertErrors(source, [CompileTimeErrorCode.IMPLEMENTS_DISALLOWED_CLASS]); | 2262 assertErrors(source, [CompileTimeErrorCode.IMPLEMENTS_DISALLOWED_CLASS]); |
2168 verify([source]); | 2263 verify([source]); |
2169 } | 2264 } |
2170 | 2265 |
2171 void test_implementsDisallowedClass_class_double() { | 2266 void test_implementsDisallowedClass_class_double() { |
2172 Source source = addSource("class A implements double {}"); | 2267 Source source = addSource("class A implements double {}"); |
2173 resolve(source); | 2268 computeLibrarySourceErrors(source); |
2174 assertErrors(source, [CompileTimeErrorCode.IMPLEMENTS_DISALLOWED_CLASS]); | 2269 assertErrors(source, [CompileTimeErrorCode.IMPLEMENTS_DISALLOWED_CLASS]); |
2175 verify([source]); | 2270 verify([source]); |
2176 } | 2271 } |
2177 | 2272 |
2178 void test_implementsDisallowedClass_class_int() { | 2273 void test_implementsDisallowedClass_class_int() { |
2179 Source source = addSource("class A implements int {}"); | 2274 Source source = addSource("class A implements int {}"); |
2180 resolve(source); | 2275 computeLibrarySourceErrors(source); |
2181 assertErrors(source, [CompileTimeErrorCode.IMPLEMENTS_DISALLOWED_CLASS]); | 2276 assertErrors(source, [CompileTimeErrorCode.IMPLEMENTS_DISALLOWED_CLASS]); |
2182 verify([source]); | 2277 verify([source]); |
2183 } | 2278 } |
2184 | 2279 |
2185 void test_implementsDisallowedClass_class_Null() { | 2280 void test_implementsDisallowedClass_class_Null() { |
2186 Source source = addSource("class A implements Null {}"); | 2281 Source source = addSource("class A implements Null {}"); |
2187 resolve(source); | 2282 computeLibrarySourceErrors(source); |
2188 assertErrors(source, [CompileTimeErrorCode.IMPLEMENTS_DISALLOWED_CLASS]); | 2283 assertErrors(source, [CompileTimeErrorCode.IMPLEMENTS_DISALLOWED_CLASS]); |
2189 verify([source]); | 2284 verify([source]); |
2190 } | 2285 } |
2191 | 2286 |
2192 void test_implementsDisallowedClass_class_num() { | 2287 void test_implementsDisallowedClass_class_num() { |
2193 Source source = addSource("class A implements num {}"); | 2288 Source source = addSource("class A implements num {}"); |
2194 resolve(source); | 2289 computeLibrarySourceErrors(source); |
2195 assertErrors(source, [CompileTimeErrorCode.IMPLEMENTS_DISALLOWED_CLASS]); | 2290 assertErrors(source, [CompileTimeErrorCode.IMPLEMENTS_DISALLOWED_CLASS]); |
2196 verify([source]); | 2291 verify([source]); |
2197 } | 2292 } |
2198 | 2293 |
2199 void test_implementsDisallowedClass_class_String() { | 2294 void test_implementsDisallowedClass_class_String() { |
2200 Source source = addSource("class A implements String {}"); | 2295 Source source = addSource("class A implements String {}"); |
2201 resolve(source); | 2296 computeLibrarySourceErrors(source); |
2202 assertErrors(source, [CompileTimeErrorCode.IMPLEMENTS_DISALLOWED_CLASS]); | 2297 assertErrors(source, [CompileTimeErrorCode.IMPLEMENTS_DISALLOWED_CLASS]); |
2203 verify([source]); | 2298 verify([source]); |
2204 } | 2299 } |
2205 | 2300 |
2206 void test_implementsDisallowedClass_class_String_num() { | 2301 void test_implementsDisallowedClass_class_String_num() { |
2207 Source source = addSource("class A implements String, num {}"); | 2302 Source source = addSource("class A implements String, num {}"); |
2208 resolve(source); | 2303 computeLibrarySourceErrors(source); |
2209 assertErrors(source, [ | 2304 assertErrors(source, [ |
2210 CompileTimeErrorCode.IMPLEMENTS_DISALLOWED_CLASS, | 2305 CompileTimeErrorCode.IMPLEMENTS_DISALLOWED_CLASS, |
2211 CompileTimeErrorCode.IMPLEMENTS_DISALLOWED_CLASS | 2306 CompileTimeErrorCode.IMPLEMENTS_DISALLOWED_CLASS |
2212 ]); | 2307 ]); |
2213 verify([source]); | 2308 verify([source]); |
2214 } | 2309 } |
2215 | 2310 |
2216 void test_implementsDisallowedClass_classTypeAlias_bool() { | 2311 void test_implementsDisallowedClass_classTypeAlias_bool() { |
2217 Source source = addSource(r''' | 2312 Source source = addSource(r''' |
2218 class A {} | 2313 class A {} |
2219 class M {} | 2314 class M {} |
2220 class C = A with M implements bool;'''); | 2315 class C = A with M implements bool;'''); |
2221 resolve(source); | 2316 computeLibrarySourceErrors(source); |
2222 assertErrors(source, [CompileTimeErrorCode.IMPLEMENTS_DISALLOWED_CLASS]); | 2317 assertErrors(source, [CompileTimeErrorCode.IMPLEMENTS_DISALLOWED_CLASS]); |
2223 verify([source]); | 2318 verify([source]); |
2224 } | 2319 } |
2225 | 2320 |
2226 void test_implementsDisallowedClass_classTypeAlias_double() { | 2321 void test_implementsDisallowedClass_classTypeAlias_double() { |
2227 Source source = addSource(r''' | 2322 Source source = addSource(r''' |
2228 class A {} | 2323 class A {} |
2229 class M {} | 2324 class M {} |
2230 class C = A with M implements double;'''); | 2325 class C = A with M implements double;'''); |
2231 resolve(source); | 2326 computeLibrarySourceErrors(source); |
2232 assertErrors(source, [CompileTimeErrorCode.IMPLEMENTS_DISALLOWED_CLASS]); | 2327 assertErrors(source, [CompileTimeErrorCode.IMPLEMENTS_DISALLOWED_CLASS]); |
2233 verify([source]); | 2328 verify([source]); |
2234 } | 2329 } |
2235 | 2330 |
2236 void test_implementsDisallowedClass_classTypeAlias_int() { | 2331 void test_implementsDisallowedClass_classTypeAlias_int() { |
2237 Source source = addSource(r''' | 2332 Source source = addSource(r''' |
2238 class A {} | 2333 class A {} |
2239 class M {} | 2334 class M {} |
2240 class C = A with M implements int;'''); | 2335 class C = A with M implements int;'''); |
2241 resolve(source); | 2336 computeLibrarySourceErrors(source); |
2242 assertErrors(source, [CompileTimeErrorCode.IMPLEMENTS_DISALLOWED_CLASS]); | 2337 assertErrors(source, [CompileTimeErrorCode.IMPLEMENTS_DISALLOWED_CLASS]); |
2243 verify([source]); | 2338 verify([source]); |
2244 } | 2339 } |
2245 | 2340 |
2246 void test_implementsDisallowedClass_classTypeAlias_Null() { | 2341 void test_implementsDisallowedClass_classTypeAlias_Null() { |
2247 Source source = addSource(r''' | 2342 Source source = addSource(r''' |
2248 class A {} | 2343 class A {} |
2249 class M {} | 2344 class M {} |
2250 class C = A with M implements Null;'''); | 2345 class C = A with M implements Null;'''); |
2251 resolve(source); | 2346 computeLibrarySourceErrors(source); |
2252 assertErrors(source, [CompileTimeErrorCode.IMPLEMENTS_DISALLOWED_CLASS]); | 2347 assertErrors(source, [CompileTimeErrorCode.IMPLEMENTS_DISALLOWED_CLASS]); |
2253 verify([source]); | 2348 verify([source]); |
2254 } | 2349 } |
2255 | 2350 |
2256 void test_implementsDisallowedClass_classTypeAlias_num() { | 2351 void test_implementsDisallowedClass_classTypeAlias_num() { |
2257 Source source = addSource(r''' | 2352 Source source = addSource(r''' |
2258 class A {} | 2353 class A {} |
2259 class M {} | 2354 class M {} |
2260 class C = A with M implements num;'''); | 2355 class C = A with M implements num;'''); |
2261 resolve(source); | 2356 computeLibrarySourceErrors(source); |
2262 assertErrors(source, [CompileTimeErrorCode.IMPLEMENTS_DISALLOWED_CLASS]); | 2357 assertErrors(source, [CompileTimeErrorCode.IMPLEMENTS_DISALLOWED_CLASS]); |
2263 verify([source]); | 2358 verify([source]); |
2264 } | 2359 } |
2265 | 2360 |
2266 void test_implementsDisallowedClass_classTypeAlias_String() { | 2361 void test_implementsDisallowedClass_classTypeAlias_String() { |
2267 Source source = addSource(r''' | 2362 Source source = addSource(r''' |
2268 class A {} | 2363 class A {} |
2269 class M {} | 2364 class M {} |
2270 class C = A with M implements String;'''); | 2365 class C = A with M implements String;'''); |
2271 resolve(source); | 2366 computeLibrarySourceErrors(source); |
2272 assertErrors(source, [CompileTimeErrorCode.IMPLEMENTS_DISALLOWED_CLASS]); | 2367 assertErrors(source, [CompileTimeErrorCode.IMPLEMENTS_DISALLOWED_CLASS]); |
2273 verify([source]); | 2368 verify([source]); |
2274 } | 2369 } |
2275 | 2370 |
2276 void test_implementsDisallowedClass_classTypeAlias_String_num() { | 2371 void test_implementsDisallowedClass_classTypeAlias_String_num() { |
2277 Source source = addSource(r''' | 2372 Source source = addSource(r''' |
2278 class A {} | 2373 class A {} |
2279 class M {} | 2374 class M {} |
2280 class C = A with M implements String, num;'''); | 2375 class C = A with M implements String, num;'''); |
2281 resolve(source); | 2376 computeLibrarySourceErrors(source); |
2282 assertErrors(source, [ | 2377 assertErrors(source, [ |
2283 CompileTimeErrorCode.IMPLEMENTS_DISALLOWED_CLASS, | 2378 CompileTimeErrorCode.IMPLEMENTS_DISALLOWED_CLASS, |
2284 CompileTimeErrorCode.IMPLEMENTS_DISALLOWED_CLASS | 2379 CompileTimeErrorCode.IMPLEMENTS_DISALLOWED_CLASS |
2285 ]); | 2380 ]); |
2286 verify([source]); | 2381 verify([source]); |
2287 } | 2382 } |
2288 | 2383 |
2289 void test_implementsDynamic() { | 2384 void test_implementsDynamic() { |
2290 Source source = addSource("class A implements dynamic {}"); | 2385 Source source = addSource("class A implements dynamic {}"); |
2291 resolve(source); | 2386 computeLibrarySourceErrors(source); |
2292 assertErrors(source, [CompileTimeErrorCode.IMPLEMENTS_DYNAMIC]); | 2387 assertErrors(source, [CompileTimeErrorCode.IMPLEMENTS_DYNAMIC]); |
2293 verify([source]); | 2388 verify([source]); |
2294 } | 2389 } |
2295 | 2390 |
2296 void test_implementsEnum() { | 2391 void test_implementsEnum() { |
2297 Source source = addSource(r''' | 2392 Source source = addSource(r''' |
2298 enum E { ONE } | 2393 enum E { ONE } |
2299 class A implements E {}'''); | 2394 class A implements E {}'''); |
2300 resolve(source); | 2395 computeLibrarySourceErrors(source); |
2301 assertErrors(source, [CompileTimeErrorCode.IMPLEMENTS_ENUM]); | 2396 assertErrors(source, [CompileTimeErrorCode.IMPLEMENTS_ENUM]); |
2302 verify([source]); | 2397 verify([source]); |
2303 } | 2398 } |
2304 | 2399 |
2305 void test_implementsNonClass_class() { | 2400 void test_implementsNonClass_class() { |
2306 Source source = addSource(r''' | 2401 Source source = addSource(r''' |
2307 int A; | 2402 int A; |
2308 class B implements A {}'''); | 2403 class B implements A {}'''); |
2309 resolve(source); | 2404 computeLibrarySourceErrors(source); |
2310 assertErrors(source, [CompileTimeErrorCode.IMPLEMENTS_NON_CLASS]); | 2405 assertErrors(source, [CompileTimeErrorCode.IMPLEMENTS_NON_CLASS]); |
2311 verify([source]); | 2406 verify([source]); |
2312 } | 2407 } |
2313 | 2408 |
2314 void test_implementsNonClass_typeAlias() { | 2409 void test_implementsNonClass_typeAlias() { |
2315 Source source = addSource(r''' | 2410 Source source = addSource(r''' |
2316 class A {} | 2411 class A {} |
2317 class M {} | 2412 class M {} |
2318 int B; | 2413 int B; |
2319 class C = A with M implements B;'''); | 2414 class C = A with M implements B;'''); |
2320 resolve(source); | 2415 computeLibrarySourceErrors(source); |
2321 assertErrors(source, [CompileTimeErrorCode.IMPLEMENTS_NON_CLASS]); | 2416 assertErrors(source, [CompileTimeErrorCode.IMPLEMENTS_NON_CLASS]); |
2322 verify([source]); | 2417 verify([source]); |
2323 } | 2418 } |
2324 | 2419 |
2325 void test_implementsRepeated() { | 2420 void test_implementsRepeated() { |
2326 Source source = addSource(r''' | 2421 Source source = addSource(r''' |
2327 class A {} | 2422 class A {} |
2328 class B implements A, A {}'''); | 2423 class B implements A, A {}'''); |
2329 resolve(source); | 2424 computeLibrarySourceErrors(source); |
2330 assertErrors(source, [CompileTimeErrorCode.IMPLEMENTS_REPEATED]); | 2425 assertErrors(source, [CompileTimeErrorCode.IMPLEMENTS_REPEATED]); |
2331 verify([source]); | 2426 verify([source]); |
2332 } | 2427 } |
2333 | 2428 |
2334 void test_implementsRepeated_3times() { | 2429 void test_implementsRepeated_3times() { |
2335 Source source = addSource(r''' | 2430 Source source = addSource(r''' |
2336 class A {} class C{} | 2431 class A {} class C{} |
2337 class B implements A, A, A, A {}'''); | 2432 class B implements A, A, A, A {}'''); |
2338 resolve(source); | 2433 computeLibrarySourceErrors(source); |
2339 assertErrors(source, [ | 2434 assertErrors(source, [ |
2340 CompileTimeErrorCode.IMPLEMENTS_REPEATED, | 2435 CompileTimeErrorCode.IMPLEMENTS_REPEATED, |
2341 CompileTimeErrorCode.IMPLEMENTS_REPEATED, | 2436 CompileTimeErrorCode.IMPLEMENTS_REPEATED, |
2342 CompileTimeErrorCode.IMPLEMENTS_REPEATED | 2437 CompileTimeErrorCode.IMPLEMENTS_REPEATED |
2343 ]); | 2438 ]); |
2344 verify([source]); | 2439 verify([source]); |
2345 } | 2440 } |
2346 | 2441 |
2347 void test_implementsSuperClass() { | 2442 void test_implementsSuperClass() { |
2348 Source source = addSource(r''' | 2443 Source source = addSource(r''' |
2349 class A {} | 2444 class A {} |
2350 class B extends A implements A {}'''); | 2445 class B extends A implements A {}'''); |
2351 resolve(source); | 2446 computeLibrarySourceErrors(source); |
2352 assertErrors(source, [CompileTimeErrorCode.IMPLEMENTS_SUPER_CLASS]); | 2447 assertErrors(source, [CompileTimeErrorCode.IMPLEMENTS_SUPER_CLASS]); |
2353 verify([source]); | 2448 verify([source]); |
2354 } | 2449 } |
2355 | 2450 |
2356 void test_implementsSuperClass_Object() { | 2451 void test_implementsSuperClass_Object() { |
2357 Source source = addSource("class A implements Object {}"); | 2452 Source source = addSource("class A implements Object {}"); |
2358 resolve(source); | 2453 computeLibrarySourceErrors(source); |
2359 assertErrors(source, [CompileTimeErrorCode.IMPLEMENTS_SUPER_CLASS]); | 2454 assertErrors(source, [CompileTimeErrorCode.IMPLEMENTS_SUPER_CLASS]); |
2360 verify([source]); | 2455 verify([source]); |
2361 } | 2456 } |
2362 | 2457 |
2363 void test_implicitThisReferenceInInitializer_field() { | 2458 void test_implicitThisReferenceInInitializer_field() { |
2364 Source source = addSource(r''' | 2459 Source source = addSource(r''' |
2365 class A { | 2460 class A { |
2366 var v; | 2461 var v; |
2367 A() : v = f; | 2462 A() : v = f; |
2368 var f; | 2463 var f; |
2369 }'''); | 2464 }'''); |
2370 resolve(source); | 2465 computeLibrarySourceErrors(source); |
2371 assertErrors( | 2466 assertErrors( |
2372 source, [CompileTimeErrorCode.IMPLICIT_THIS_REFERENCE_IN_INITIALIZER]); | 2467 source, [CompileTimeErrorCode.IMPLICIT_THIS_REFERENCE_IN_INITIALIZER]); |
2373 verify([source]); | 2468 verify([source]); |
2374 } | 2469 } |
2375 | 2470 |
2376 void test_implicitThisReferenceInInitializer_field2() { | 2471 void test_implicitThisReferenceInInitializer_field2() { |
2377 Source source = addSource(r''' | 2472 Source source = addSource(r''' |
2378 class A { | 2473 class A { |
2379 final x = 0; | 2474 final x = 0; |
2380 final y = x; | 2475 final y = x; |
2381 }'''); | 2476 }'''); |
2382 resolve(source); | 2477 computeLibrarySourceErrors(source); |
2383 assertErrors( | 2478 assertErrors( |
2384 source, [CompileTimeErrorCode.IMPLICIT_THIS_REFERENCE_IN_INITIALIZER]); | 2479 source, [CompileTimeErrorCode.IMPLICIT_THIS_REFERENCE_IN_INITIALIZER]); |
2385 verify([source]); | 2480 verify([source]); |
2386 } | 2481 } |
2387 | 2482 |
2388 void test_implicitThisReferenceInInitializer_invocation() { | 2483 void test_implicitThisReferenceInInitializer_invocation() { |
2389 Source source = addSource(r''' | 2484 Source source = addSource(r''' |
2390 class A { | 2485 class A { |
2391 var v; | 2486 var v; |
2392 A() : v = f(); | 2487 A() : v = f(); |
2393 f() {} | 2488 f() {} |
2394 }'''); | 2489 }'''); |
2395 resolve(source); | 2490 computeLibrarySourceErrors(source); |
2396 assertErrors( | 2491 assertErrors( |
2397 source, [CompileTimeErrorCode.IMPLICIT_THIS_REFERENCE_IN_INITIALIZER]); | 2492 source, [CompileTimeErrorCode.IMPLICIT_THIS_REFERENCE_IN_INITIALIZER]); |
2398 verify([source]); | 2493 verify([source]); |
2399 } | 2494 } |
2400 | 2495 |
2401 void test_implicitThisReferenceInInitializer_invocationInStatic() { | 2496 void test_implicitThisReferenceInInitializer_invocationInStatic() { |
2402 Source source = addSource(r''' | 2497 Source source = addSource(r''' |
2403 class A { | 2498 class A { |
2404 static var F = m(); | 2499 static var F = m(); |
2405 m() {} | 2500 m() {} |
2406 }'''); | 2501 }'''); |
2407 resolve(source); | 2502 computeLibrarySourceErrors(source); |
2408 assertErrors( | 2503 assertErrors( |
2409 source, [CompileTimeErrorCode.IMPLICIT_THIS_REFERENCE_IN_INITIALIZER]); | 2504 source, [CompileTimeErrorCode.IMPLICIT_THIS_REFERENCE_IN_INITIALIZER]); |
2410 verify([source]); | 2505 verify([source]); |
2411 } | 2506 } |
2412 | 2507 |
2413 void test_implicitThisReferenceInInitializer_redirectingConstructorInvocation(
) { | 2508 void test_implicitThisReferenceInInitializer_redirectingConstructorInvocation(
) { |
2414 Source source = addSource(r''' | 2509 Source source = addSource(r''' |
2415 class A { | 2510 class A { |
2416 A(p) {} | 2511 A(p) {} |
2417 A.named() : this(f); | 2512 A.named() : this(f); |
2418 var f; | 2513 var f; |
2419 }'''); | 2514 }'''); |
2420 resolve(source); | 2515 computeLibrarySourceErrors(source); |
2421 assertErrors( | 2516 assertErrors( |
2422 source, [CompileTimeErrorCode.IMPLICIT_THIS_REFERENCE_IN_INITIALIZER]); | 2517 source, [CompileTimeErrorCode.IMPLICIT_THIS_REFERENCE_IN_INITIALIZER]); |
2423 verify([source]); | 2518 verify([source]); |
2424 } | 2519 } |
2425 | 2520 |
2426 void test_implicitThisReferenceInInitializer_superConstructorInvocation() { | 2521 void test_implicitThisReferenceInInitializer_superConstructorInvocation() { |
2427 Source source = addSource(r''' | 2522 Source source = addSource(r''' |
2428 class A { | 2523 class A { |
2429 A(p) {} | 2524 A(p) {} |
2430 } | 2525 } |
2431 class B extends A { | 2526 class B extends A { |
2432 B() : super(f); | 2527 B() : super(f); |
2433 var f; | 2528 var f; |
2434 }'''); | 2529 }'''); |
2435 resolve(source); | 2530 computeLibrarySourceErrors(source); |
2436 assertErrors( | 2531 assertErrors( |
2437 source, [CompileTimeErrorCode.IMPLICIT_THIS_REFERENCE_IN_INITIALIZER]); | 2532 source, [CompileTimeErrorCode.IMPLICIT_THIS_REFERENCE_IN_INITIALIZER]); |
2438 verify([source]); | 2533 verify([source]); |
2439 } | 2534 } |
2440 | 2535 |
2441 void test_importInternalLibrary() { | 2536 void test_importInternalLibrary() { |
2442 Source source = addSource("import 'dart:_interceptors';"); | 2537 Source source = addSource("import 'dart:_interceptors';"); |
2443 resolve(source); | 2538 computeLibrarySourceErrors(source); |
2444 // Note, in these error cases we may generate an UNUSED_IMPORT hint, while | 2539 // Note, in these error cases we may generate an UNUSED_IMPORT hint, while |
2445 // we could prevent the hint from being generated by testing the import | 2540 // we could prevent the hint from being generated by testing the import |
2446 // directive for the error, this is such a minor corner case that we don't | 2541 // directive for the error, this is such a minor corner case that we don't |
2447 // think we should add the additional computation time to figure out such | 2542 // think we should add the additional computation time to figure out such |
2448 // cases. | 2543 // cases. |
2449 assertErrors(source, [ | 2544 assertErrors(source, [ |
2450 CompileTimeErrorCode.IMPORT_INTERNAL_LIBRARY, | 2545 CompileTimeErrorCode.IMPORT_INTERNAL_LIBRARY, |
2451 HintCode.UNUSED_IMPORT | 2546 HintCode.UNUSED_IMPORT |
2452 ]); | 2547 ]); |
2453 verify([source]); | 2548 verify([source]); |
2454 } | 2549 } |
2455 | 2550 |
2456 void test_importInternalLibrary_js_helper() { | 2551 void test_importInternalLibrary_js_helper() { |
2457 Source source = addSource("import 'dart:_js_helper';"); | 2552 Source source = addSource("import 'dart:_js_helper';"); |
2458 resolve(source); | 2553 computeLibrarySourceErrors(source); |
2459 // Note, in these error cases we may generate an UNUSED_IMPORT hint, while | 2554 // Note, in these error cases we may generate an UNUSED_IMPORT hint, while |
2460 // we could prevent the hint from being generated by testing the import | 2555 // we could prevent the hint from being generated by testing the import |
2461 // directive for the error, this is such a minor corner case that we don't | 2556 // directive for the error, this is such a minor corner case that we don't |
2462 // think we should add the additional computation time to figure out such | 2557 // think we should add the additional computation time to figure out such |
2463 // cases. | 2558 // cases. |
2464 assertErrors(source, [ | 2559 assertErrors(source, [ |
2465 CompileTimeErrorCode.IMPORT_INTERNAL_LIBRARY, | 2560 CompileTimeErrorCode.IMPORT_INTERNAL_LIBRARY, |
2466 HintCode.UNUSED_IMPORT | 2561 HintCode.UNUSED_IMPORT |
2467 ]); | 2562 ]); |
2468 verify([source]); | 2563 verify([source]); |
2469 } | 2564 } |
2470 | 2565 |
2471 void test_importOfNonLibrary() { | 2566 void test_importOfNonLibrary() { |
2472 Source source = addSource(r''' | 2567 Source source = addSource(r''' |
2473 library lib; | 2568 library lib; |
2474 import 'part.dart'; | 2569 import 'part.dart'; |
2475 A a;'''); | 2570 A a;'''); |
2476 addNamedSource("/part.dart", r''' | 2571 addNamedSource("/part.dart", r''' |
2477 part of lib; | 2572 part of lib; |
2478 class A{}'''); | 2573 class A{}'''); |
2479 resolve(source); | 2574 computeLibrarySourceErrors(source); |
2480 assertErrors(source, [CompileTimeErrorCode.IMPORT_OF_NON_LIBRARY]); | 2575 assertErrors(source, [CompileTimeErrorCode.IMPORT_OF_NON_LIBRARY]); |
2481 verify([source]); | 2576 verify([source]); |
2482 } | 2577 } |
2483 | 2578 |
2484 void test_inconsistentCaseExpressionTypes() { | 2579 void test_inconsistentCaseExpressionTypes() { |
2485 Source source = addSource(r''' | 2580 Source source = addSource(r''' |
2486 f(var p) { | 2581 f(var p) { |
2487 switch (p) { | 2582 switch (p) { |
2488 case 1: | 2583 case 1: |
2489 break; | 2584 break; |
2490 case 'a': | 2585 case 'a': |
2491 break; | 2586 break; |
2492 } | 2587 } |
2493 }'''); | 2588 }'''); |
2494 resolve(source); | 2589 computeLibrarySourceErrors(source); |
2495 assertErrors( | 2590 assertErrors( |
2496 source, [CompileTimeErrorCode.INCONSISTENT_CASE_EXPRESSION_TYPES]); | 2591 source, [CompileTimeErrorCode.INCONSISTENT_CASE_EXPRESSION_TYPES]); |
2497 verify([source]); | 2592 verify([source]); |
2498 } | 2593 } |
2499 | 2594 |
2500 void test_inconsistentCaseExpressionTypes_dynamic() { | 2595 void test_inconsistentCaseExpressionTypes_dynamic() { |
2501 // Even though A.S and S have a static type of "dynamic", we should see | 2596 // Even though A.S and S have a static type of "dynamic", we should see |
2502 // that they fail to match 3, because they are constant strings. | 2597 // that they fail to match 3, because they are constant strings. |
2503 Source source = addSource(r''' | 2598 Source source = addSource(r''' |
2504 class A { | 2599 class A { |
2505 static const S = 'A.S'; | 2600 static const S = 'A.S'; |
2506 } | 2601 } |
2507 | 2602 |
2508 const S = 'S'; | 2603 const S = 'S'; |
2509 | 2604 |
2510 foo(var p) { | 2605 foo(var p) { |
2511 switch (p) { | 2606 switch (p) { |
2512 case 3: | 2607 case 3: |
2513 break; | 2608 break; |
2514 case S: | 2609 case S: |
2515 break; | 2610 break; |
2516 case A.S: | 2611 case A.S: |
2517 break; | 2612 break; |
2518 } | 2613 } |
2519 }'''); | 2614 }'''); |
2520 resolve(source); | 2615 computeLibrarySourceErrors(source); |
2521 assertErrors(source, [ | 2616 assertErrors(source, [ |
2522 CompileTimeErrorCode.INCONSISTENT_CASE_EXPRESSION_TYPES, | 2617 CompileTimeErrorCode.INCONSISTENT_CASE_EXPRESSION_TYPES, |
2523 CompileTimeErrorCode.INCONSISTENT_CASE_EXPRESSION_TYPES | 2618 CompileTimeErrorCode.INCONSISTENT_CASE_EXPRESSION_TYPES |
2524 ]); | 2619 ]); |
2525 verify([source]); | 2620 verify([source]); |
2526 } | 2621 } |
2527 | 2622 |
2528 void test_inconsistentCaseExpressionTypes_repeated() { | 2623 void test_inconsistentCaseExpressionTypes_repeated() { |
2529 Source source = addSource(r''' | 2624 Source source = addSource(r''' |
2530 f(var p) { | 2625 f(var p) { |
2531 switch (p) { | 2626 switch (p) { |
2532 case 1: | 2627 case 1: |
2533 break; | 2628 break; |
2534 case 'a': | 2629 case 'a': |
2535 break; | 2630 break; |
2536 case 'b': | 2631 case 'b': |
2537 break; | 2632 break; |
2538 } | 2633 } |
2539 }'''); | 2634 }'''); |
2540 resolve(source); | 2635 computeLibrarySourceErrors(source); |
2541 assertErrors(source, [ | 2636 assertErrors(source, [ |
2542 CompileTimeErrorCode.INCONSISTENT_CASE_EXPRESSION_TYPES, | 2637 CompileTimeErrorCode.INCONSISTENT_CASE_EXPRESSION_TYPES, |
2543 CompileTimeErrorCode.INCONSISTENT_CASE_EXPRESSION_TYPES | 2638 CompileTimeErrorCode.INCONSISTENT_CASE_EXPRESSION_TYPES |
2544 ]); | 2639 ]); |
2545 verify([source]); | 2640 verify([source]); |
2546 } | 2641 } |
2547 | 2642 |
2548 void test_initializerForNonExistent_const() { | 2643 void test_initializerForNonExistent_const() { |
2549 // Check that the absence of a matching field doesn't cause a | 2644 // Check that the absence of a matching field doesn't cause a |
2550 // crash during constant evaluation. | 2645 // crash during constant evaluation. |
2551 Source source = addSource(r''' | 2646 Source source = addSource(r''' |
2552 class A { | 2647 class A { |
2553 const A() : x = 'foo'; | 2648 const A() : x = 'foo'; |
2554 } | 2649 } |
2555 A a = const A();'''); | 2650 A a = const A();'''); |
2556 resolve(source); | 2651 computeLibrarySourceErrors(source); |
2557 assertErrors( | 2652 assertErrors( |
2558 source, [CompileTimeErrorCode.INITIALIZER_FOR_NON_EXISTENT_FIELD]); | 2653 source, [CompileTimeErrorCode.INITIALIZER_FOR_NON_EXISTENT_FIELD]); |
2559 } | 2654 } |
2560 | 2655 |
2561 void test_initializerForNonExistent_initializer() { | 2656 void test_initializerForNonExistent_initializer() { |
2562 Source source = addSource(r''' | 2657 Source source = addSource(r''' |
2563 class A { | 2658 class A { |
2564 A() : x = 0 {} | 2659 A() : x = 0 {} |
2565 }'''); | 2660 }'''); |
2566 resolve(source); | 2661 computeLibrarySourceErrors(source); |
2567 assertErrors( | 2662 assertErrors( |
2568 source, [CompileTimeErrorCode.INITIALIZER_FOR_NON_EXISTENT_FIELD]); | 2663 source, [CompileTimeErrorCode.INITIALIZER_FOR_NON_EXISTENT_FIELD]); |
2569 } | 2664 } |
2570 | 2665 |
2571 void test_initializerForStaticField() { | 2666 void test_initializerForStaticField() { |
2572 Source source = addSource(r''' | 2667 Source source = addSource(r''' |
2573 class A { | 2668 class A { |
2574 static int x; | 2669 static int x; |
2575 A() : x = 0 {} | 2670 A() : x = 0 {} |
2576 }'''); | 2671 }'''); |
2577 resolve(source); | 2672 computeLibrarySourceErrors(source); |
2578 assertErrors(source, [CompileTimeErrorCode.INITIALIZER_FOR_STATIC_FIELD]); | 2673 assertErrors(source, [CompileTimeErrorCode.INITIALIZER_FOR_STATIC_FIELD]); |
2579 verify([source]); | 2674 verify([source]); |
2580 } | 2675 } |
2581 | 2676 |
2582 void test_initializingFormalForNonExistentField() { | 2677 void test_initializingFormalForNonExistentField() { |
2583 Source source = addSource(r''' | 2678 Source source = addSource(r''' |
2584 class A { | 2679 class A { |
2585 A(this.x) {} | 2680 A(this.x) {} |
2586 }'''); | 2681 }'''); |
2587 resolve(source); | 2682 computeLibrarySourceErrors(source); |
2588 assertErrors(source, | 2683 assertErrors(source, |
2589 [CompileTimeErrorCode.INITIALIZING_FORMAL_FOR_NON_EXISTENT_FIELD]); | 2684 [CompileTimeErrorCode.INITIALIZING_FORMAL_FOR_NON_EXISTENT_FIELD]); |
2590 verify([source]); | 2685 verify([source]); |
2591 } | 2686 } |
2592 | 2687 |
2593 void test_initializingFormalForNonExistentField_notInEnclosingClass() { | 2688 void test_initializingFormalForNonExistentField_notInEnclosingClass() { |
2594 Source source = addSource(r''' | 2689 Source source = addSource(r''' |
2595 class A { | 2690 class A { |
2596 int x; | 2691 int x; |
2597 } | 2692 } |
2598 class B extends A { | 2693 class B extends A { |
2599 B(this.x) {} | 2694 B(this.x) {} |
2600 }'''); | 2695 }'''); |
2601 resolve(source); | 2696 computeLibrarySourceErrors(source); |
2602 assertErrors(source, | 2697 assertErrors(source, |
2603 [CompileTimeErrorCode.INITIALIZING_FORMAL_FOR_NON_EXISTENT_FIELD]); | 2698 [CompileTimeErrorCode.INITIALIZING_FORMAL_FOR_NON_EXISTENT_FIELD]); |
2604 verify([source]); | 2699 verify([source]); |
2605 } | 2700 } |
2606 | 2701 |
2607 void test_initializingFormalForNonExistentField_optional() { | 2702 void test_initializingFormalForNonExistentField_optional() { |
2608 Source source = addSource(r''' | 2703 Source source = addSource(r''' |
2609 class A { | 2704 class A { |
2610 A([this.x]) {} | 2705 A([this.x]) {} |
2611 }'''); | 2706 }'''); |
2612 resolve(source); | 2707 computeLibrarySourceErrors(source); |
2613 assertErrors(source, | 2708 assertErrors(source, |
2614 [CompileTimeErrorCode.INITIALIZING_FORMAL_FOR_NON_EXISTENT_FIELD]); | 2709 [CompileTimeErrorCode.INITIALIZING_FORMAL_FOR_NON_EXISTENT_FIELD]); |
2615 verify([source]); | 2710 verify([source]); |
2616 } | 2711 } |
2617 | 2712 |
2618 void test_initializingFormalForNonExistentField_synthetic() { | 2713 void test_initializingFormalForNonExistentField_synthetic() { |
2619 Source source = addSource(r''' | 2714 Source source = addSource(r''' |
2620 class A { | 2715 class A { |
2621 int get x => 1; | 2716 int get x => 1; |
2622 A(this.x) {} | 2717 A(this.x) {} |
2623 }'''); | 2718 }'''); |
2624 resolve(source); | 2719 computeLibrarySourceErrors(source); |
2625 assertErrors(source, | 2720 assertErrors(source, |
2626 [CompileTimeErrorCode.INITIALIZING_FORMAL_FOR_NON_EXISTENT_FIELD]); | 2721 [CompileTimeErrorCode.INITIALIZING_FORMAL_FOR_NON_EXISTENT_FIELD]); |
2627 verify([source]); | 2722 verify([source]); |
2628 } | 2723 } |
2629 | 2724 |
2630 void test_initializingFormalForStaticField() { | 2725 void test_initializingFormalForStaticField() { |
2631 Source source = addSource(r''' | 2726 Source source = addSource(r''' |
2632 class A { | 2727 class A { |
2633 static int x; | 2728 static int x; |
2634 A([this.x]) {} | 2729 A([this.x]) {} |
2635 }'''); | 2730 }'''); |
2636 resolve(source); | 2731 computeLibrarySourceErrors(source); |
2637 assertErrors( | 2732 assertErrors( |
2638 source, [CompileTimeErrorCode.INITIALIZING_FORMAL_FOR_STATIC_FIELD]); | 2733 source, [CompileTimeErrorCode.INITIALIZING_FORMAL_FOR_STATIC_FIELD]); |
2639 verify([source]); | 2734 verify([source]); |
2640 } | 2735 } |
2641 | 2736 |
2642 void test_instanceMemberAccessFromFactory_named() { | 2737 void test_instanceMemberAccessFromFactory_named() { |
2643 Source source = addSource(r''' | 2738 Source source = addSource(r''' |
2644 class A { | 2739 class A { |
2645 m() {} | 2740 m() {} |
2646 A(); | 2741 A(); |
2647 factory A.make() { | 2742 factory A.make() { |
2648 m(); | 2743 m(); |
2649 return new A(); | 2744 return new A(); |
2650 } | 2745 } |
2651 }'''); | 2746 }'''); |
2652 resolve(source); | 2747 computeLibrarySourceErrors(source); |
2653 assertErrors( | 2748 assertErrors( |
2654 source, [CompileTimeErrorCode.INSTANCE_MEMBER_ACCESS_FROM_FACTORY]); | 2749 source, [CompileTimeErrorCode.INSTANCE_MEMBER_ACCESS_FROM_FACTORY]); |
2655 verify([source]); | 2750 verify([source]); |
2656 } | 2751 } |
2657 | 2752 |
2658 void test_instanceMemberAccessFromFactory_unnamed() { | 2753 void test_instanceMemberAccessFromFactory_unnamed() { |
2659 Source source = addSource(r''' | 2754 Source source = addSource(r''' |
2660 class A { | 2755 class A { |
2661 m() {} | 2756 m() {} |
2662 A._(); | 2757 A._(); |
2663 factory A() { | 2758 factory A() { |
2664 m(); | 2759 m(); |
2665 return new A._(); | 2760 return new A._(); |
2666 } | 2761 } |
2667 }'''); | 2762 }'''); |
2668 resolve(source); | 2763 computeLibrarySourceErrors(source); |
2669 assertErrors( | 2764 assertErrors( |
2670 source, [CompileTimeErrorCode.INSTANCE_MEMBER_ACCESS_FROM_FACTORY]); | 2765 source, [CompileTimeErrorCode.INSTANCE_MEMBER_ACCESS_FROM_FACTORY]); |
2671 verify([source]); | 2766 verify([source]); |
2672 } | 2767 } |
2673 | 2768 |
2674 void test_instanceMemberAccessFromStatic_field() { | 2769 void test_instanceMemberAccessFromStatic_field() { |
2675 Source source = addSource(r''' | 2770 Source source = addSource(r''' |
2676 class A { | 2771 class A { |
2677 int f; | 2772 int f; |
2678 static foo() { | 2773 static foo() { |
2679 f; | 2774 f; |
2680 } | 2775 } |
2681 }'''); | 2776 }'''); |
2682 resolve(source); | 2777 computeLibrarySourceErrors(source); |
2683 assertErrors( | 2778 assertErrors( |
2684 source, [CompileTimeErrorCode.INSTANCE_MEMBER_ACCESS_FROM_STATIC]); | 2779 source, [CompileTimeErrorCode.INSTANCE_MEMBER_ACCESS_FROM_STATIC]); |
2685 verify([source]); | 2780 verify([source]); |
2686 } | 2781 } |
2687 | 2782 |
2688 void test_instanceMemberAccessFromStatic_getter() { | 2783 void test_instanceMemberAccessFromStatic_getter() { |
2689 Source source = addSource(r''' | 2784 Source source = addSource(r''' |
2690 class A { | 2785 class A { |
2691 get g => null; | 2786 get g => null; |
2692 static foo() { | 2787 static foo() { |
2693 g; | 2788 g; |
2694 } | 2789 } |
2695 }'''); | 2790 }'''); |
2696 resolve(source); | 2791 computeLibrarySourceErrors(source); |
2697 assertErrors( | 2792 assertErrors( |
2698 source, [CompileTimeErrorCode.INSTANCE_MEMBER_ACCESS_FROM_STATIC]); | 2793 source, [CompileTimeErrorCode.INSTANCE_MEMBER_ACCESS_FROM_STATIC]); |
2699 verify([source]); | 2794 verify([source]); |
2700 } | 2795 } |
2701 | 2796 |
2702 void test_instanceMemberAccessFromStatic_method() { | 2797 void test_instanceMemberAccessFromStatic_method() { |
2703 Source source = addSource(r''' | 2798 Source source = addSource(r''' |
2704 class A { | 2799 class A { |
2705 m() {} | 2800 m() {} |
2706 static foo() { | 2801 static foo() { |
2707 m(); | 2802 m(); |
2708 } | 2803 } |
2709 }'''); | 2804 }'''); |
2710 resolve(source); | 2805 computeLibrarySourceErrors(source); |
2711 assertErrors( | 2806 assertErrors( |
2712 source, [CompileTimeErrorCode.INSTANCE_MEMBER_ACCESS_FROM_STATIC]); | 2807 source, [CompileTimeErrorCode.INSTANCE_MEMBER_ACCESS_FROM_STATIC]); |
2713 verify([source]); | 2808 verify([source]); |
2714 } | 2809 } |
2715 | 2810 |
2716 void test_instantiateEnum_const() { | 2811 void test_instantiateEnum_const() { |
2717 Source source = addSource(r''' | 2812 Source source = addSource(r''' |
2718 enum E { ONE } | 2813 enum E { ONE } |
2719 E e(String name) { | 2814 E e(String name) { |
2720 return const E(); | 2815 return const E(); |
2721 }'''); | 2816 }'''); |
2722 resolve(source); | 2817 computeLibrarySourceErrors(source); |
2723 assertErrors(source, [CompileTimeErrorCode.INSTANTIATE_ENUM]); | 2818 assertErrors(source, [CompileTimeErrorCode.INSTANTIATE_ENUM]); |
2724 verify([source]); | 2819 verify([source]); |
2725 } | 2820 } |
2726 | 2821 |
2727 void test_instantiateEnum_new() { | 2822 void test_instantiateEnum_new() { |
2728 Source source = addSource(r''' | 2823 Source source = addSource(r''' |
2729 enum E { ONE } | 2824 enum E { ONE } |
2730 E e(String name) { | 2825 E e(String name) { |
2731 return new E(); | 2826 return new E(); |
2732 }'''); | 2827 }'''); |
2733 resolve(source); | 2828 computeLibrarySourceErrors(source); |
2734 assertErrors(source, [CompileTimeErrorCode.INSTANTIATE_ENUM]); | 2829 assertErrors(source, [CompileTimeErrorCode.INSTANTIATE_ENUM]); |
2735 verify([source]); | 2830 verify([source]); |
2736 } | 2831 } |
2737 | 2832 |
2738 void test_invalidAnnotation_getter() { | 2833 void test_invalidAnnotation_getter() { |
2739 Source source = addSource(r''' | 2834 Source source = addSource(r''' |
2740 get V => 0; | 2835 get V => 0; |
2741 @V | 2836 @V |
2742 main() { | 2837 main() { |
2743 }'''); | 2838 }'''); |
2744 resolve(source); | 2839 computeLibrarySourceErrors(source); |
2745 assertErrors(source, [CompileTimeErrorCode.INVALID_ANNOTATION]); | 2840 assertErrors(source, [CompileTimeErrorCode.INVALID_ANNOTATION]); |
2746 verify([source]); | 2841 verify([source]); |
2747 } | 2842 } |
2748 | 2843 |
2749 void test_invalidAnnotation_importWithPrefix_getter() { | 2844 void test_invalidAnnotation_importWithPrefix_getter() { |
2750 addNamedSource("/lib.dart", r''' | 2845 addNamedSource("/lib.dart", r''' |
2751 library lib; | 2846 library lib; |
2752 get V => 0;'''); | 2847 get V => 0;'''); |
2753 Source source = addSource(r''' | 2848 Source source = addSource(r''' |
2754 import 'lib.dart' as p; | 2849 import 'lib.dart' as p; |
2755 @p.V | 2850 @p.V |
2756 main() { | 2851 main() { |
2757 }'''); | 2852 }'''); |
2758 resolve(source); | 2853 computeLibrarySourceErrors(source); |
2759 assertErrors(source, [CompileTimeErrorCode.INVALID_ANNOTATION]); | 2854 assertErrors(source, [CompileTimeErrorCode.INVALID_ANNOTATION]); |
2760 verify([source]); | 2855 verify([source]); |
2761 } | 2856 } |
2762 | 2857 |
2763 void test_invalidAnnotation_importWithPrefix_notConstantVariable() { | 2858 void test_invalidAnnotation_importWithPrefix_notConstantVariable() { |
2764 addNamedSource("/lib.dart", r''' | 2859 addNamedSource("/lib.dart", r''' |
2765 library lib; | 2860 library lib; |
2766 final V = 0;'''); | 2861 final V = 0;'''); |
2767 Source source = addSource(r''' | 2862 Source source = addSource(r''' |
2768 import 'lib.dart' as p; | 2863 import 'lib.dart' as p; |
2769 @p.V | 2864 @p.V |
2770 main() { | 2865 main() { |
2771 }'''); | 2866 }'''); |
2772 resolve(source); | 2867 computeLibrarySourceErrors(source); |
2773 assertErrors(source, [CompileTimeErrorCode.INVALID_ANNOTATION]); | 2868 assertErrors(source, [CompileTimeErrorCode.INVALID_ANNOTATION]); |
2774 verify([source]); | 2869 verify([source]); |
2775 } | 2870 } |
2776 | 2871 |
2777 void test_invalidAnnotation_importWithPrefix_notVariableOrConstructorInvocatio
n() { | 2872 void test_invalidAnnotation_importWithPrefix_notVariableOrConstructorInvocatio
n() { |
2778 addNamedSource("/lib.dart", r''' | 2873 addNamedSource("/lib.dart", r''' |
2779 library lib; | 2874 library lib; |
2780 typedef V();'''); | 2875 typedef V();'''); |
2781 Source source = addSource(r''' | 2876 Source source = addSource(r''' |
2782 import 'lib.dart' as p; | 2877 import 'lib.dart' as p; |
2783 @p.V | 2878 @p.V |
2784 main() { | 2879 main() { |
2785 }'''); | 2880 }'''); |
2786 resolve(source); | 2881 computeLibrarySourceErrors(source); |
2787 assertErrors(source, [CompileTimeErrorCode.INVALID_ANNOTATION]); | 2882 assertErrors(source, [CompileTimeErrorCode.INVALID_ANNOTATION]); |
2788 verify([source]); | 2883 verify([source]); |
2789 } | 2884 } |
2790 | 2885 |
2791 void test_invalidAnnotation_notConstantVariable() { | 2886 void test_invalidAnnotation_notConstantVariable() { |
2792 Source source = addSource(r''' | 2887 Source source = addSource(r''' |
2793 final V = 0; | 2888 final V = 0; |
2794 @V | 2889 @V |
2795 main() { | 2890 main() { |
2796 }'''); | 2891 }'''); |
2797 resolve(source); | 2892 computeLibrarySourceErrors(source); |
2798 assertErrors(source, [CompileTimeErrorCode.INVALID_ANNOTATION]); | 2893 assertErrors(source, [CompileTimeErrorCode.INVALID_ANNOTATION]); |
2799 verify([source]); | 2894 verify([source]); |
2800 } | 2895 } |
2801 | 2896 |
2802 void test_invalidAnnotation_notVariableOrConstructorInvocation() { | 2897 void test_invalidAnnotation_notVariableOrConstructorInvocation() { |
2803 Source source = addSource(r''' | 2898 Source source = addSource(r''' |
2804 typedef V(); | 2899 typedef V(); |
2805 @V | 2900 @V |
2806 main() { | 2901 main() { |
2807 }'''); | 2902 }'''); |
2808 resolve(source); | 2903 computeLibrarySourceErrors(source); |
2809 assertErrors(source, [CompileTimeErrorCode.INVALID_ANNOTATION]); | 2904 assertErrors(source, [CompileTimeErrorCode.INVALID_ANNOTATION]); |
2810 verify([source]); | 2905 verify([source]); |
2811 } | 2906 } |
2812 | 2907 |
2813 void test_invalidAnnotation_staticMethodReference() { | 2908 void test_invalidAnnotation_staticMethodReference() { |
2814 Source source = addSource(r''' | 2909 Source source = addSource(r''' |
2815 class A { | 2910 class A { |
2816 static f() {} | 2911 static f() {} |
2817 } | 2912 } |
2818 @A.f | 2913 @A.f |
2819 main() { | 2914 main() { |
2820 }'''); | 2915 }'''); |
2821 resolve(source); | 2916 computeLibrarySourceErrors(source); |
2822 assertErrors(source, [CompileTimeErrorCode.INVALID_ANNOTATION]); | 2917 assertErrors(source, [CompileTimeErrorCode.INVALID_ANNOTATION]); |
2823 verify([source]); | 2918 verify([source]); |
2824 } | 2919 } |
2825 | 2920 |
2826 void test_invalidAnnotation_unresolved_identifier() { | 2921 void test_invalidAnnotation_unresolved_identifier() { |
2827 Source source = addSource(r''' | 2922 Source source = addSource(r''' |
2828 @unresolved | 2923 @unresolved |
2829 main() { | 2924 main() { |
2830 }'''); | 2925 }'''); |
2831 resolve(source); | 2926 computeLibrarySourceErrors(source); |
2832 assertErrors(source, [CompileTimeErrorCode.INVALID_ANNOTATION]); | 2927 assertErrors(source, [CompileTimeErrorCode.INVALID_ANNOTATION]); |
2833 } | 2928 } |
2834 | 2929 |
2835 void test_invalidAnnotation_unresolved_invocation() { | 2930 void test_invalidAnnotation_unresolved_invocation() { |
2836 Source source = addSource(r''' | 2931 Source source = addSource(r''' |
2837 @Unresolved() | 2932 @Unresolved() |
2838 main() { | 2933 main() { |
2839 }'''); | 2934 }'''); |
2840 resolve(source); | 2935 computeLibrarySourceErrors(source); |
2841 assertErrors(source, [CompileTimeErrorCode.INVALID_ANNOTATION]); | 2936 assertErrors(source, [CompileTimeErrorCode.INVALID_ANNOTATION]); |
2842 } | 2937 } |
2843 | 2938 |
2844 void test_invalidAnnotation_unresolved_prefixedIdentifier() { | 2939 void test_invalidAnnotation_unresolved_prefixedIdentifier() { |
2845 Source source = addSource(r''' | 2940 Source source = addSource(r''' |
2846 import 'dart:math' as p; | 2941 import 'dart:math' as p; |
2847 @p.unresolved | 2942 @p.unresolved |
2848 main() { | 2943 main() { |
2849 }'''); | 2944 }'''); |
2850 resolve(source); | 2945 computeLibrarySourceErrors(source); |
2851 assertErrors(source, [CompileTimeErrorCode.INVALID_ANNOTATION]); | 2946 assertErrors(source, [CompileTimeErrorCode.INVALID_ANNOTATION]); |
2852 } | 2947 } |
2853 | 2948 |
2854 void test_invalidAnnotation_useLibraryScope() { | 2949 void test_invalidAnnotation_useLibraryScope() { |
2855 Source source = addSource(r''' | 2950 Source source = addSource(r''' |
2856 @foo | 2951 @foo |
2857 class A { | 2952 class A { |
2858 static const foo = null; | 2953 static const foo = null; |
2859 }'''); | 2954 }'''); |
2860 resolve(source); | 2955 computeLibrarySourceErrors(source); |
2861 assertErrors(source, [CompileTimeErrorCode.INVALID_ANNOTATION]); | 2956 assertErrors(source, [CompileTimeErrorCode.INVALID_ANNOTATION]); |
2862 } | 2957 } |
2863 | 2958 |
2864 void test_invalidAnnotationFromDeferredLibrary() { | 2959 void test_invalidAnnotationFromDeferredLibrary() { |
2865 // See test_invalidAnnotation_notConstantVariable | 2960 // See test_invalidAnnotation_notConstantVariable |
2866 resolveWithErrors(<String>[ | 2961 resolveWithErrors(<String>[ |
2867 r''' | 2962 r''' |
2868 library lib1; | 2963 library lib1; |
2869 class V { const V(); } | 2964 class V { const V(); } |
2870 const v = const V();''', | 2965 const v = const V();''', |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2906 CompileTimeErrorCode.INVALID_ANNOTATION_FROM_DEFERRED_LIBRARY | 3001 CompileTimeErrorCode.INVALID_ANNOTATION_FROM_DEFERRED_LIBRARY |
2907 ]); | 3002 ]); |
2908 } | 3003 } |
2909 | 3004 |
2910 void test_invalidConstructorName_notEnclosingClassName_defined() { | 3005 void test_invalidConstructorName_notEnclosingClassName_defined() { |
2911 Source source = addSource(r''' | 3006 Source source = addSource(r''' |
2912 class A { | 3007 class A { |
2913 B() : super(); | 3008 B() : super(); |
2914 } | 3009 } |
2915 class B {}'''); | 3010 class B {}'''); |
2916 resolve(source); | 3011 computeLibrarySourceErrors(source); |
2917 assertErrors(source, [CompileTimeErrorCode.INVALID_CONSTRUCTOR_NAME]); | 3012 assertErrors(source, [CompileTimeErrorCode.INVALID_CONSTRUCTOR_NAME]); |
2918 // no verify() call, "B" is not resolved | 3013 // no verify() call, "B" is not resolved |
2919 } | 3014 } |
2920 | 3015 |
2921 void test_invalidConstructorName_notEnclosingClassName_undefined() { | 3016 void test_invalidConstructorName_notEnclosingClassName_undefined() { |
2922 Source source = addSource(r''' | 3017 Source source = addSource(r''' |
2923 class A { | 3018 class A { |
2924 B() : super(); | 3019 B() : super(); |
2925 }'''); | 3020 }'''); |
2926 resolve(source); | 3021 computeLibrarySourceErrors(source); |
2927 assertErrors(source, [CompileTimeErrorCode.INVALID_CONSTRUCTOR_NAME]); | 3022 assertErrors(source, [CompileTimeErrorCode.INVALID_CONSTRUCTOR_NAME]); |
2928 // no verify() call, "B" is not resolved | 3023 // no verify() call, "B" is not resolved |
2929 } | 3024 } |
2930 | 3025 |
2931 void test_invalidFactoryNameNotAClass_notClassName() { | 3026 void test_invalidFactoryNameNotAClass_notClassName() { |
2932 Source source = addSource(r''' | 3027 Source source = addSource(r''' |
2933 int B; | 3028 int B; |
2934 class A { | 3029 class A { |
2935 factory B() {} | 3030 factory B() {} |
2936 }'''); | 3031 }'''); |
2937 resolve(source); | 3032 computeLibrarySourceErrors(source); |
2938 assertErrors( | 3033 assertErrors( |
2939 source, [CompileTimeErrorCode.INVALID_FACTORY_NAME_NOT_A_CLASS]); | 3034 source, [CompileTimeErrorCode.INVALID_FACTORY_NAME_NOT_A_CLASS]); |
2940 verify([source]); | 3035 verify([source]); |
2941 } | 3036 } |
2942 | 3037 |
2943 void test_invalidFactoryNameNotAClass_notEnclosingClassName() { | 3038 void test_invalidFactoryNameNotAClass_notEnclosingClassName() { |
2944 Source source = addSource(r''' | 3039 Source source = addSource(r''' |
2945 class A { | 3040 class A { |
2946 factory B() {} | 3041 factory B() {} |
2947 }'''); | 3042 }'''); |
2948 resolve(source); | 3043 computeLibrarySourceErrors(source); |
2949 assertErrors( | 3044 assertErrors( |
2950 source, [CompileTimeErrorCode.INVALID_FACTORY_NAME_NOT_A_CLASS]); | 3045 source, [CompileTimeErrorCode.INVALID_FACTORY_NAME_NOT_A_CLASS]); |
2951 // no verify() call, "B" is not resolved | 3046 // no verify() call, "B" is not resolved |
2952 } | 3047 } |
2953 | 3048 |
2954 void test_invalidModifierOnConstructor_async() { | 3049 void test_invalidModifierOnConstructor_async() { |
2955 Source source = addSource(r''' | 3050 Source source = addSource(r''' |
2956 class A { | 3051 class A { |
2957 A() async {} | 3052 A() async {} |
2958 }'''); | 3053 }'''); |
2959 resolve(source); | 3054 computeLibrarySourceErrors(source); |
2960 assertErrors( | 3055 assertErrors( |
2961 source, [CompileTimeErrorCode.INVALID_MODIFIER_ON_CONSTRUCTOR]); | 3056 source, [CompileTimeErrorCode.INVALID_MODIFIER_ON_CONSTRUCTOR]); |
2962 verify([source]); | 3057 verify([source]); |
2963 } | 3058 } |
2964 | 3059 |
2965 void test_invalidModifierOnConstructor_asyncStar() { | 3060 void test_invalidModifierOnConstructor_asyncStar() { |
2966 Source source = addSource(r''' | 3061 Source source = addSource(r''' |
2967 class A { | 3062 class A { |
2968 A() async* {} | 3063 A() async* {} |
2969 }'''); | 3064 }'''); |
2970 resolve(source); | 3065 computeLibrarySourceErrors(source); |
2971 assertErrors( | 3066 assertErrors( |
2972 source, [CompileTimeErrorCode.INVALID_MODIFIER_ON_CONSTRUCTOR]); | 3067 source, [CompileTimeErrorCode.INVALID_MODIFIER_ON_CONSTRUCTOR]); |
2973 verify([source]); | 3068 verify([source]); |
2974 } | 3069 } |
2975 | 3070 |
2976 void test_invalidModifierOnConstructor_syncStar() { | 3071 void test_invalidModifierOnConstructor_syncStar() { |
2977 Source source = addSource(r''' | 3072 Source source = addSource(r''' |
2978 class A { | 3073 class A { |
2979 A() sync* {} | 3074 A() sync* {} |
2980 }'''); | 3075 }'''); |
2981 resolve(source); | 3076 computeLibrarySourceErrors(source); |
2982 assertErrors( | 3077 assertErrors( |
2983 source, [CompileTimeErrorCode.INVALID_MODIFIER_ON_CONSTRUCTOR]); | 3078 source, [CompileTimeErrorCode.INVALID_MODIFIER_ON_CONSTRUCTOR]); |
2984 verify([source]); | 3079 verify([source]); |
2985 } | 3080 } |
2986 | 3081 |
2987 void test_invalidModifierOnSetter_member_async() { | 3082 void test_invalidModifierOnSetter_member_async() { |
2988 Source source = addSource(r''' | 3083 Source source = addSource(r''' |
2989 class A { | 3084 class A { |
2990 set x(v) async {} | 3085 set x(v) async {} |
2991 }'''); | 3086 }'''); |
2992 resolve(source); | 3087 computeLibrarySourceErrors(source); |
2993 assertErrors(source, [CompileTimeErrorCode.INVALID_MODIFIER_ON_SETTER]); | 3088 assertErrors(source, [CompileTimeErrorCode.INVALID_MODIFIER_ON_SETTER]); |
2994 verify([source]); | 3089 verify([source]); |
2995 } | 3090 } |
2996 | 3091 |
2997 void test_invalidModifierOnSetter_member_asyncStar() { | 3092 void test_invalidModifierOnSetter_member_asyncStar() { |
2998 Source source = addSource(r''' | 3093 Source source = addSource(r''' |
2999 class A { | 3094 class A { |
3000 set x(v) async* {} | 3095 set x(v) async* {} |
3001 }'''); | 3096 }'''); |
3002 resolve(source); | 3097 computeLibrarySourceErrors(source); |
3003 assertErrors(source, [CompileTimeErrorCode.INVALID_MODIFIER_ON_SETTER]); | 3098 assertErrors(source, [CompileTimeErrorCode.INVALID_MODIFIER_ON_SETTER]); |
3004 verify([source]); | 3099 verify([source]); |
3005 } | 3100 } |
3006 | 3101 |
3007 void test_invalidModifierOnSetter_member_syncStar() { | 3102 void test_invalidModifierOnSetter_member_syncStar() { |
3008 Source source = addSource(r''' | 3103 Source source = addSource(r''' |
3009 class A { | 3104 class A { |
3010 set x(v) sync* {} | 3105 set x(v) sync* {} |
3011 }'''); | 3106 }'''); |
3012 resolve(source); | 3107 computeLibrarySourceErrors(source); |
3013 assertErrors(source, [CompileTimeErrorCode.INVALID_MODIFIER_ON_SETTER]); | 3108 assertErrors(source, [CompileTimeErrorCode.INVALID_MODIFIER_ON_SETTER]); |
3014 verify([source]); | 3109 verify([source]); |
3015 } | 3110 } |
3016 | 3111 |
3017 void test_invalidModifierOnSetter_topLevel_async() { | 3112 void test_invalidModifierOnSetter_topLevel_async() { |
3018 Source source = addSource("set x(v) async {}"); | 3113 Source source = addSource("set x(v) async {}"); |
3019 resolve(source); | 3114 computeLibrarySourceErrors(source); |
3020 assertErrors(source, [CompileTimeErrorCode.INVALID_MODIFIER_ON_SETTER]); | 3115 assertErrors(source, [CompileTimeErrorCode.INVALID_MODIFIER_ON_SETTER]); |
3021 verify([source]); | 3116 verify([source]); |
3022 } | 3117 } |
3023 | 3118 |
3024 void test_invalidModifierOnSetter_topLevel_asyncStar() { | 3119 void test_invalidModifierOnSetter_topLevel_asyncStar() { |
3025 Source source = addSource("set x(v) async* {}"); | 3120 Source source = addSource("set x(v) async* {}"); |
3026 resolve(source); | 3121 computeLibrarySourceErrors(source); |
3027 assertErrors(source, [CompileTimeErrorCode.INVALID_MODIFIER_ON_SETTER]); | 3122 assertErrors(source, [CompileTimeErrorCode.INVALID_MODIFIER_ON_SETTER]); |
3028 verify([source]); | 3123 verify([source]); |
3029 } | 3124 } |
3030 | 3125 |
3031 void test_invalidModifierOnSetter_topLevel_syncStar() { | 3126 void test_invalidModifierOnSetter_topLevel_syncStar() { |
3032 Source source = addSource("set x(v) sync* {}"); | 3127 Source source = addSource("set x(v) sync* {}"); |
3033 resolve(source); | 3128 computeLibrarySourceErrors(source); |
3034 assertErrors(source, [CompileTimeErrorCode.INVALID_MODIFIER_ON_SETTER]); | 3129 assertErrors(source, [CompileTimeErrorCode.INVALID_MODIFIER_ON_SETTER]); |
3035 verify([source]); | 3130 verify([source]); |
3036 } | 3131 } |
3037 | 3132 |
3038 void test_invalidReferenceToThis_factoryConstructor() { | 3133 void test_invalidReferenceToThis_factoryConstructor() { |
3039 Source source = addSource(r''' | 3134 Source source = addSource(r''' |
3040 class A { | 3135 class A { |
3041 factory A() { return this; } | 3136 factory A() { return this; } |
3042 }'''); | 3137 }'''); |
3043 resolve(source); | 3138 computeLibrarySourceErrors(source); |
3044 assertErrors(source, [CompileTimeErrorCode.INVALID_REFERENCE_TO_THIS]); | 3139 assertErrors(source, [CompileTimeErrorCode.INVALID_REFERENCE_TO_THIS]); |
3045 verify([source]); | 3140 verify([source]); |
3046 } | 3141 } |
3047 | 3142 |
3048 void test_invalidReferenceToThis_instanceVariableInitializer_inConstructor() { | 3143 void test_invalidReferenceToThis_instanceVariableInitializer_inConstructor() { |
3049 Source source = addSource(r''' | 3144 Source source = addSource(r''' |
3050 class A { | 3145 class A { |
3051 var f; | 3146 var f; |
3052 A() : f = this; | 3147 A() : f = this; |
3053 }'''); | 3148 }'''); |
3054 resolve(source); | 3149 computeLibrarySourceErrors(source); |
3055 assertErrors(source, [CompileTimeErrorCode.INVALID_REFERENCE_TO_THIS]); | 3150 assertErrors(source, [CompileTimeErrorCode.INVALID_REFERENCE_TO_THIS]); |
3056 verify([source]); | 3151 verify([source]); |
3057 } | 3152 } |
3058 | 3153 |
3059 void test_invalidReferenceToThis_instanceVariableInitializer_inDeclaration() { | 3154 void test_invalidReferenceToThis_instanceVariableInitializer_inDeclaration() { |
3060 Source source = addSource(r''' | 3155 Source source = addSource(r''' |
3061 class A { | 3156 class A { |
3062 var f = this; | 3157 var f = this; |
3063 }'''); | 3158 }'''); |
3064 resolve(source); | 3159 computeLibrarySourceErrors(source); |
3065 assertErrors(source, [CompileTimeErrorCode.INVALID_REFERENCE_TO_THIS]); | 3160 assertErrors(source, [CompileTimeErrorCode.INVALID_REFERENCE_TO_THIS]); |
3066 verify([source]); | 3161 verify([source]); |
3067 } | 3162 } |
3068 | 3163 |
3069 void test_invalidReferenceToThis_staticMethod() { | 3164 void test_invalidReferenceToThis_staticMethod() { |
3070 Source source = addSource(r''' | 3165 Source source = addSource(r''' |
3071 class A { | 3166 class A { |
3072 static m() { return this; } | 3167 static m() { return this; } |
3073 }'''); | 3168 }'''); |
3074 resolve(source); | 3169 computeLibrarySourceErrors(source); |
3075 assertErrors(source, [CompileTimeErrorCode.INVALID_REFERENCE_TO_THIS]); | 3170 assertErrors(source, [CompileTimeErrorCode.INVALID_REFERENCE_TO_THIS]); |
3076 verify([source]); | 3171 verify([source]); |
3077 } | 3172 } |
3078 | 3173 |
3079 void test_invalidReferenceToThis_staticVariableInitializer() { | 3174 void test_invalidReferenceToThis_staticVariableInitializer() { |
3080 Source source = addSource(r''' | 3175 Source source = addSource(r''' |
3081 class A { | 3176 class A { |
3082 static A f = this; | 3177 static A f = this; |
3083 }'''); | 3178 }'''); |
3084 resolve(source); | 3179 computeLibrarySourceErrors(source); |
3085 assertErrors(source, [CompileTimeErrorCode.INVALID_REFERENCE_TO_THIS]); | 3180 assertErrors(source, [CompileTimeErrorCode.INVALID_REFERENCE_TO_THIS]); |
3086 verify([source]); | 3181 verify([source]); |
3087 } | 3182 } |
3088 | 3183 |
3089 void test_invalidReferenceToThis_superInitializer() { | 3184 void test_invalidReferenceToThis_superInitializer() { |
3090 Source source = addSource(r''' | 3185 Source source = addSource(r''' |
3091 class A { | 3186 class A { |
3092 A(var x) {} | 3187 A(var x) {} |
3093 } | 3188 } |
3094 class B extends A { | 3189 class B extends A { |
3095 B() : super(this); | 3190 B() : super(this); |
3096 }'''); | 3191 }'''); |
3097 resolve(source); | 3192 computeLibrarySourceErrors(source); |
3098 assertErrors(source, [CompileTimeErrorCode.INVALID_REFERENCE_TO_THIS]); | 3193 assertErrors(source, [CompileTimeErrorCode.INVALID_REFERENCE_TO_THIS]); |
3099 verify([source]); | 3194 verify([source]); |
3100 } | 3195 } |
3101 | 3196 |
3102 void test_invalidReferenceToThis_topLevelFunction() { | 3197 void test_invalidReferenceToThis_topLevelFunction() { |
3103 Source source = addSource("f() { return this; }"); | 3198 Source source = addSource("f() { return this; }"); |
3104 resolve(source); | 3199 computeLibrarySourceErrors(source); |
3105 assertErrors(source, [CompileTimeErrorCode.INVALID_REFERENCE_TO_THIS]); | 3200 assertErrors(source, [CompileTimeErrorCode.INVALID_REFERENCE_TO_THIS]); |
3106 verify([source]); | 3201 verify([source]); |
3107 } | 3202 } |
3108 | 3203 |
3109 void test_invalidReferenceToThis_variableInitializer() { | 3204 void test_invalidReferenceToThis_variableInitializer() { |
3110 Source source = addSource("int x = this;"); | 3205 Source source = addSource("int x = this;"); |
3111 resolve(source); | 3206 computeLibrarySourceErrors(source); |
3112 assertErrors(source, [CompileTimeErrorCode.INVALID_REFERENCE_TO_THIS]); | 3207 assertErrors(source, [CompileTimeErrorCode.INVALID_REFERENCE_TO_THIS]); |
3113 verify([source]); | 3208 verify([source]); |
3114 } | 3209 } |
3115 | 3210 |
3116 void test_invalidTypeArgumentInConstList() { | 3211 void test_invalidTypeArgumentInConstList() { |
3117 Source source = addSource(r''' | 3212 Source source = addSource(r''' |
3118 class A<E> { | 3213 class A<E> { |
3119 m() { | 3214 m() { |
3120 return const <E>[]; | 3215 return const <E>[]; |
3121 } | 3216 } |
3122 }'''); | 3217 }'''); |
3123 resolve(source); | 3218 computeLibrarySourceErrors(source); |
3124 assertErrors( | 3219 assertErrors( |
3125 source, [CompileTimeErrorCode.INVALID_TYPE_ARGUMENT_IN_CONST_LIST]); | 3220 source, [CompileTimeErrorCode.INVALID_TYPE_ARGUMENT_IN_CONST_LIST]); |
3126 verify([source]); | 3221 verify([source]); |
3127 } | 3222 } |
3128 | 3223 |
3129 void test_invalidTypeArgumentInConstMap() { | 3224 void test_invalidTypeArgumentInConstMap() { |
3130 Source source = addSource(r''' | 3225 Source source = addSource(r''' |
3131 class A<E> { | 3226 class A<E> { |
3132 m() { | 3227 m() { |
3133 return const <String, E>{}; | 3228 return const <String, E>{}; |
3134 } | 3229 } |
3135 }'''); | 3230 }'''); |
3136 resolve(source); | 3231 computeLibrarySourceErrors(source); |
3137 assertErrors( | 3232 assertErrors( |
3138 source, [CompileTimeErrorCode.INVALID_TYPE_ARGUMENT_IN_CONST_MAP]); | 3233 source, [CompileTimeErrorCode.INVALID_TYPE_ARGUMENT_IN_CONST_MAP]); |
3139 verify([source]); | 3234 verify([source]); |
3140 } | 3235 } |
3141 | 3236 |
3142 void test_invalidUri_export() { | 3237 void test_invalidUri_export() { |
3143 Source source = addSource("export 'ht:';"); | 3238 Source source = addSource("export 'ht:';"); |
3144 resolve(source); | 3239 computeLibrarySourceErrors(source); |
3145 assertErrors(source, [CompileTimeErrorCode.INVALID_URI]); | 3240 assertErrors(source, [CompileTimeErrorCode.INVALID_URI]); |
3146 } | 3241 } |
3147 | 3242 |
3148 void test_invalidUri_import() { | 3243 void test_invalidUri_import() { |
3149 Source source = addSource("import 'ht:';"); | 3244 Source source = addSource("import 'ht:';"); |
3150 resolve(source); | 3245 computeLibrarySourceErrors(source); |
3151 assertErrors(source, [CompileTimeErrorCode.INVALID_URI]); | 3246 assertErrors(source, [CompileTimeErrorCode.INVALID_URI]); |
3152 } | 3247 } |
3153 | 3248 |
3154 void test_invalidUri_part() { | 3249 void test_invalidUri_part() { |
3155 Source source = addSource("part 'ht:';"); | 3250 Source source = addSource("part 'ht:';"); |
3156 resolve(source); | 3251 computeLibrarySourceErrors(source); |
3157 assertErrors(source, [CompileTimeErrorCode.INVALID_URI]); | 3252 assertErrors(source, [CompileTimeErrorCode.INVALID_URI]); |
3158 } | 3253 } |
3159 | 3254 |
3160 void test_isInConstInstanceCreation_restored() { | 3255 void test_isInConstInstanceCreation_restored() { |
3161 // If ErrorVerifier._isInConstInstanceCreation is not properly restored on | 3256 // If ErrorVerifier._isInConstInstanceCreation is not properly restored on |
3162 // exit from visitInstanceCreationExpression, the error at (1) will be | 3257 // exit from visitInstanceCreationExpression, the error at (1) will be |
3163 // treated as a warning rather than an error. | 3258 // treated as a warning rather than an error. |
3164 Source source = addSource(r''' | 3259 Source source = addSource(r''' |
3165 class Foo<T extends num> { | 3260 class Foo<T extends num> { |
3166 const Foo(x, y); | 3261 const Foo(x, y); |
3167 } | 3262 } |
3168 const x = const Foo<int>(const Foo<int>(0, 1), | 3263 const x = const Foo<int>(const Foo<int>(0, 1), |
3169 const <Foo<String>>[]); // (1) | 3264 const <Foo<String>>[]); // (1) |
3170 '''); | 3265 '''); |
3171 resolve(source); | 3266 computeLibrarySourceErrors(source); |
3172 assertErrors( | 3267 assertErrors( |
3173 source, [CompileTimeErrorCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS]); | 3268 source, [CompileTimeErrorCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS]); |
3174 verify([source]); | 3269 verify([source]); |
3175 } | 3270 } |
3176 | 3271 |
3177 void test_isInInstanceVariableInitializer_restored() { | 3272 void test_isInInstanceVariableInitializer_restored() { |
3178 // If ErrorVerifier._isInInstanceVariableInitializer is not properly | 3273 // If ErrorVerifier._isInInstanceVariableInitializer is not properly |
3179 // restored on exit from visitVariableDeclaration, the error at (1) | 3274 // restored on exit from visitVariableDeclaration, the error at (1) |
3180 // won't be detected. | 3275 // won't be detected. |
3181 Source source = addSource(r''' | 3276 Source source = addSource(r''' |
3182 class Foo { | 3277 class Foo { |
3183 var bar; | 3278 var bar; |
3184 Map foo = { | 3279 Map foo = { |
3185 'bar': () { | 3280 'bar': () { |
3186 var _bar; | 3281 var _bar; |
3187 }, | 3282 }, |
3188 'bop': _foo // (1) | 3283 'bop': _foo // (1) |
3189 }; | 3284 }; |
3190 _foo() { | 3285 _foo() { |
3191 } | 3286 } |
3192 }'''); | 3287 }'''); |
3193 resolve(source); | 3288 computeLibrarySourceErrors(source); |
3194 assertErrors( | 3289 assertErrors( |
3195 source, [CompileTimeErrorCode.IMPLICIT_THIS_REFERENCE_IN_INITIALIZER]); | 3290 source, [CompileTimeErrorCode.IMPLICIT_THIS_REFERENCE_IN_INITIALIZER]); |
3196 verify([source]); | 3291 verify([source]); |
3197 } | 3292 } |
3198 | 3293 |
3199 void test_labelInOuterScope() { | 3294 void test_labelInOuterScope() { |
3200 Source source = addSource(r''' | 3295 Source source = addSource(r''' |
3201 class A { | 3296 class A { |
3202 void m(int i) { | 3297 void m(int i) { |
3203 l: while (i > 0) { | 3298 l: while (i > 0) { |
3204 void f() { | 3299 void f() { |
3205 break l; | 3300 break l; |
3206 }; | 3301 }; |
3207 } | 3302 } |
3208 } | 3303 } |
3209 }'''); | 3304 }'''); |
3210 resolve(source); | 3305 computeLibrarySourceErrors(source); |
3211 assertErrors(source, [CompileTimeErrorCode.LABEL_IN_OUTER_SCOPE]); | 3306 assertErrors(source, [CompileTimeErrorCode.LABEL_IN_OUTER_SCOPE]); |
3212 // We cannot verify resolution with unresolvable labels | 3307 // We cannot verify resolution with unresolvable labels |
3213 } | 3308 } |
3214 | 3309 |
3215 void test_labelUndefined_break() { | 3310 void test_labelUndefined_break() { |
3216 Source source = addSource(r''' | 3311 Source source = addSource(r''' |
3217 f() { | 3312 f() { |
3218 x: while (true) { | 3313 x: while (true) { |
3219 break y; | 3314 break y; |
3220 } | 3315 } |
3221 }'''); | 3316 }'''); |
3222 resolve(source); | 3317 computeLibrarySourceErrors(source); |
3223 assertErrors(source, [CompileTimeErrorCode.LABEL_UNDEFINED]); | 3318 assertErrors(source, [CompileTimeErrorCode.LABEL_UNDEFINED]); |
3224 // We cannot verify resolution with undefined labels | 3319 // We cannot verify resolution with undefined labels |
3225 } | 3320 } |
3226 | 3321 |
3227 void test_labelUndefined_continue() { | 3322 void test_labelUndefined_continue() { |
3228 Source source = addSource(r''' | 3323 Source source = addSource(r''' |
3229 f() { | 3324 f() { |
3230 x: while (true) { | 3325 x: while (true) { |
3231 continue y; | 3326 continue y; |
3232 } | 3327 } |
3233 }'''); | 3328 }'''); |
3234 resolve(source); | 3329 computeLibrarySourceErrors(source); |
3235 assertErrors(source, [CompileTimeErrorCode.LABEL_UNDEFINED]); | 3330 assertErrors(source, [CompileTimeErrorCode.LABEL_UNDEFINED]); |
3236 // We cannot verify resolution with undefined labels | 3331 // We cannot verify resolution with undefined labels |
3237 } | 3332 } |
3238 | 3333 |
3239 void test_length_of_erroneous_constant() { | 3334 void test_length_of_erroneous_constant() { |
3240 // Attempting to compute the length of constant that couldn't be evaluated | 3335 // Attempting to compute the length of constant that couldn't be evaluated |
3241 // (due to an error) should not crash the analyzer (see dartbug.com/23383) | 3336 // (due to an error) should not crash the analyzer (see dartbug.com/23383) |
3242 Source source = addSource("const int i = (1 ? 'alpha' : 'beta').length;"); | 3337 Source source = addSource("const int i = (1 ? 'alpha' : 'beta').length;"); |
3243 resolve(source); | 3338 computeLibrarySourceErrors(source); |
3244 assertErrors(source, [ | 3339 assertErrors(source, [ |
3245 CompileTimeErrorCode.CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE, | 3340 CompileTimeErrorCode.CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE, |
3246 CompileTimeErrorCode.CONST_EVAL_TYPE_BOOL, | 3341 CompileTimeErrorCode.CONST_EVAL_TYPE_BOOL, |
3247 StaticTypeWarningCode.NON_BOOL_CONDITION | 3342 StaticTypeWarningCode.NON_BOOL_CONDITION |
3248 ]); | 3343 ]); |
3249 verify([source]); | 3344 verify([source]); |
3250 } | 3345 } |
3251 | 3346 |
3252 void test_memberWithClassName_field() { | 3347 void test_memberWithClassName_field() { |
3253 Source source = addSource(r''' | 3348 Source source = addSource(r''' |
3254 class A { | 3349 class A { |
3255 int A = 0; | 3350 int A = 0; |
3256 }'''); | 3351 }'''); |
3257 resolve(source); | 3352 computeLibrarySourceErrors(source); |
3258 assertErrors(source, [CompileTimeErrorCode.MEMBER_WITH_CLASS_NAME]); | 3353 assertErrors(source, [CompileTimeErrorCode.MEMBER_WITH_CLASS_NAME]); |
3259 verify([source]); | 3354 verify([source]); |
3260 } | 3355 } |
3261 | 3356 |
3262 void test_memberWithClassName_field2() { | 3357 void test_memberWithClassName_field2() { |
3263 Source source = addSource(r''' | 3358 Source source = addSource(r''' |
3264 class A { | 3359 class A { |
3265 int z, A, b = 0; | 3360 int z, A, b = 0; |
3266 }'''); | 3361 }'''); |
3267 resolve(source); | 3362 computeLibrarySourceErrors(source); |
3268 assertErrors(source, [CompileTimeErrorCode.MEMBER_WITH_CLASS_NAME]); | 3363 assertErrors(source, [CompileTimeErrorCode.MEMBER_WITH_CLASS_NAME]); |
3269 verify([source]); | 3364 verify([source]); |
3270 } | 3365 } |
3271 | 3366 |
3272 void test_memberWithClassName_getter() { | 3367 void test_memberWithClassName_getter() { |
3273 Source source = addSource(r''' | 3368 Source source = addSource(r''' |
3274 class A { | 3369 class A { |
3275 get A => 0; | 3370 get A => 0; |
3276 }'''); | 3371 }'''); |
3277 resolve(source); | 3372 computeLibrarySourceErrors(source); |
3278 assertErrors(source, [CompileTimeErrorCode.MEMBER_WITH_CLASS_NAME]); | 3373 assertErrors(source, [CompileTimeErrorCode.MEMBER_WITH_CLASS_NAME]); |
3279 verify([source]); | 3374 verify([source]); |
3280 } | 3375 } |
3281 | 3376 |
3282 void test_memberWithClassName_method() { | 3377 void test_memberWithClassName_method() { |
3283 // no test because indistinguishable from constructor | 3378 // no test because indistinguishable from constructor |
3284 } | 3379 } |
3285 | 3380 |
3286 void test_methodAndGetterWithSameName() { | 3381 void test_methodAndGetterWithSameName() { |
3287 Source source = addSource(r''' | 3382 Source source = addSource(r''' |
3288 class A { | 3383 class A { |
3289 get x => 0; | 3384 get x => 0; |
3290 x(y) {} | 3385 x(y) {} |
3291 }'''); | 3386 }'''); |
3292 resolve(source); | 3387 computeLibrarySourceErrors(source); |
3293 assertErrors( | 3388 assertErrors( |
3294 source, [CompileTimeErrorCode.METHOD_AND_GETTER_WITH_SAME_NAME]); | 3389 source, [CompileTimeErrorCode.METHOD_AND_GETTER_WITH_SAME_NAME]); |
3295 verify([source]); | 3390 verify([source]); |
3296 } | 3391 } |
3297 | 3392 |
3298 void test_missingEnumConstantInSwitch() { | 3393 void test_missingEnumConstantInSwitch() { |
3299 Source source = addSource(r''' | 3394 Source source = addSource(r''' |
3300 enum E { ONE, TWO, THREE, FOUR } | 3395 enum E { ONE, TWO, THREE, FOUR } |
3301 bool odd(E e) { | 3396 bool odd(E e) { |
3302 switch (e) { | 3397 switch (e) { |
3303 case E.ONE: | 3398 case E.ONE: |
3304 case E.THREE: return true; | 3399 case E.THREE: return true; |
3305 } | 3400 } |
3306 return false; | 3401 return false; |
3307 }'''); | 3402 }'''); |
3308 resolve(source); | 3403 computeLibrarySourceErrors(source); |
3309 assertErrors(source, [ | 3404 assertErrors(source, [ |
3310 CompileTimeErrorCode.MISSING_ENUM_CONSTANT_IN_SWITCH, | 3405 CompileTimeErrorCode.MISSING_ENUM_CONSTANT_IN_SWITCH, |
3311 CompileTimeErrorCode.MISSING_ENUM_CONSTANT_IN_SWITCH | 3406 CompileTimeErrorCode.MISSING_ENUM_CONSTANT_IN_SWITCH |
3312 ]); | 3407 ]); |
3313 verify([source]); | 3408 verify([source]); |
3314 } | 3409 } |
3315 | 3410 |
3316 void test_mixinDeclaresConstructor_classDeclaration() { | 3411 void test_mixinDeclaresConstructor_classDeclaration() { |
3317 Source source = addSource(r''' | 3412 Source source = addSource(r''' |
3318 class A { | 3413 class A { |
3319 A() {} | 3414 A() {} |
3320 } | 3415 } |
3321 class B extends Object with A {}'''); | 3416 class B extends Object with A {}'''); |
3322 resolve(source); | 3417 computeLibrarySourceErrors(source); |
3323 assertErrors(source, [CompileTimeErrorCode.MIXIN_DECLARES_CONSTRUCTOR]); | 3418 assertErrors(source, [CompileTimeErrorCode.MIXIN_DECLARES_CONSTRUCTOR]); |
3324 verify([source]); | 3419 verify([source]); |
3325 } | 3420 } |
3326 | 3421 |
3327 void test_mixinDeclaresConstructor_typeAlias() { | 3422 void test_mixinDeclaresConstructor_typeAlias() { |
3328 Source source = addSource(r''' | 3423 Source source = addSource(r''' |
3329 class A { | 3424 class A { |
3330 A() {} | 3425 A() {} |
3331 } | 3426 } |
3332 class B = Object with A;'''); | 3427 class B = Object with A;'''); |
3333 resolve(source); | 3428 computeLibrarySourceErrors(source); |
3334 assertErrors(source, [CompileTimeErrorCode.MIXIN_DECLARES_CONSTRUCTOR]); | 3429 assertErrors(source, [CompileTimeErrorCode.MIXIN_DECLARES_CONSTRUCTOR]); |
3335 verify([source]); | 3430 verify([source]); |
3336 } | 3431 } |
3337 | 3432 |
3338 void test_mixinDeferredClass() { | 3433 void test_mixinDeferredClass() { |
3339 resolveWithErrors(<String>[ | 3434 resolveWithErrors(<String>[ |
3340 r''' | 3435 r''' |
3341 library lib1; | 3436 library lib1; |
3342 class A {}''', | 3437 class A {}''', |
3343 r''' | 3438 r''' |
(...skipping 17 matching lines...) Expand all Loading... |
3361 } | 3456 } |
3362 | 3457 |
3363 void test_mixinHasNoConstructors_mixinApp() { | 3458 void test_mixinHasNoConstructors_mixinApp() { |
3364 Source source = addSource(r''' | 3459 Source source = addSource(r''' |
3365 class B { | 3460 class B { |
3366 B({x}); | 3461 B({x}); |
3367 } | 3462 } |
3368 class M {} | 3463 class M {} |
3369 class C = B with M; | 3464 class C = B with M; |
3370 '''); | 3465 '''); |
3371 resolve(source); | 3466 computeLibrarySourceErrors(source); |
3372 assertErrors(source, [CompileTimeErrorCode.MIXIN_HAS_NO_CONSTRUCTORS]); | 3467 assertErrors(source, [CompileTimeErrorCode.MIXIN_HAS_NO_CONSTRUCTORS]); |
3373 verify([source]); | 3468 verify([source]); |
3374 } | 3469 } |
3375 | 3470 |
3376 void test_mixinHasNoConstructors_mixinClass() { | 3471 void test_mixinHasNoConstructors_mixinClass() { |
3377 Source source = addSource(r''' | 3472 Source source = addSource(r''' |
3378 class B { | 3473 class B { |
3379 B({x}); | 3474 B({x}); |
3380 } | 3475 } |
3381 class M {} | 3476 class M {} |
3382 class C extends B with M {} | 3477 class C extends B with M {} |
3383 '''); | 3478 '''); |
3384 // Note: the implicit call from C's default constructor to B() should not | 3479 // Note: the implicit call from C's default constructor to B() should not |
3385 // generate a further error (despite the fact that it's not forwarded), | 3480 // generate a further error (despite the fact that it's not forwarded), |
3386 // since CompileTimeErrorCode.MIXIN_HAS_NO_CONSTRUCTORS does a better job | 3481 // since CompileTimeErrorCode.MIXIN_HAS_NO_CONSTRUCTORS does a better job |
3387 // of explaining the probem to the user. | 3482 // of explaining the probem to the user. |
3388 resolve(source); | 3483 computeLibrarySourceErrors(source); |
3389 assertErrors(source, [CompileTimeErrorCode.MIXIN_HAS_NO_CONSTRUCTORS]); | 3484 assertErrors(source, [CompileTimeErrorCode.MIXIN_HAS_NO_CONSTRUCTORS]); |
3390 verify([source]); | 3485 verify([source]); |
3391 } | 3486 } |
3392 | 3487 |
3393 void test_mixinHasNoConstructors_mixinClass_explicitSuperCall() { | 3488 void test_mixinHasNoConstructors_mixinClass_explicitSuperCall() { |
3394 Source source = addSource(r''' | 3489 Source source = addSource(r''' |
3395 class B { | 3490 class B { |
3396 B({x}); | 3491 B({x}); |
3397 } | 3492 } |
3398 class M {} | 3493 class M {} |
3399 class C extends B with M { | 3494 class C extends B with M { |
3400 C() : super(); | 3495 C() : super(); |
3401 } | 3496 } |
3402 '''); | 3497 '''); |
3403 // Note: the explicit call from C() to B() should not generate a further | 3498 // Note: the explicit call from C() to B() should not generate a further |
3404 // error (despite the fact that it's not forwarded), since | 3499 // error (despite the fact that it's not forwarded), since |
3405 // CompileTimeErrorCode.MIXIN_HAS_NO_CONSTRUCTORS does a better job of | 3500 // CompileTimeErrorCode.MIXIN_HAS_NO_CONSTRUCTORS does a better job of |
3406 // explaining the error to the user. | 3501 // explaining the error to the user. |
3407 resolve(source); | 3502 computeLibrarySourceErrors(source); |
3408 assertErrors(source, [CompileTimeErrorCode.MIXIN_HAS_NO_CONSTRUCTORS]); | 3503 assertErrors(source, [CompileTimeErrorCode.MIXIN_HAS_NO_CONSTRUCTORS]); |
3409 verify([source]); | 3504 verify([source]); |
3410 } | 3505 } |
3411 | 3506 |
3412 void test_mixinHasNoConstructors_mixinClass_implicitSuperCall() { | 3507 void test_mixinHasNoConstructors_mixinClass_implicitSuperCall() { |
3413 Source source = addSource(r''' | 3508 Source source = addSource(r''' |
3414 class B { | 3509 class B { |
3415 B({x}); | 3510 B({x}); |
3416 } | 3511 } |
3417 class M {} | 3512 class M {} |
3418 class C extends B with M { | 3513 class C extends B with M { |
3419 C(); | 3514 C(); |
3420 } | 3515 } |
3421 '''); | 3516 '''); |
3422 // Note: the implicit call from C() to B() should not generate a further | 3517 // Note: the implicit call from C() to B() should not generate a further |
3423 // error (despite the fact that it's not forwarded), since | 3518 // error (despite the fact that it's not forwarded), since |
3424 // CompileTimeErrorCode.MIXIN_HAS_NO_CONSTRUCTORS does a better job of | 3519 // CompileTimeErrorCode.MIXIN_HAS_NO_CONSTRUCTORS does a better job of |
3425 // explaining the error to the user. | 3520 // explaining the error to the user. |
3426 resolve(source); | 3521 computeLibrarySourceErrors(source); |
3427 assertErrors(source, [CompileTimeErrorCode.MIXIN_HAS_NO_CONSTRUCTORS]); | 3522 assertErrors(source, [CompileTimeErrorCode.MIXIN_HAS_NO_CONSTRUCTORS]); |
3428 verify([source]); | 3523 verify([source]); |
3429 } | 3524 } |
3430 | 3525 |
3431 void test_mixinHasNoConstructors_mixinClass_namedSuperCall() { | 3526 void test_mixinHasNoConstructors_mixinClass_namedSuperCall() { |
3432 Source source = addSource(r''' | 3527 Source source = addSource(r''' |
3433 class B { | 3528 class B { |
3434 B.named({x}); | 3529 B.named({x}); |
3435 } | 3530 } |
3436 class M {} | 3531 class M {} |
3437 class C extends B with M { | 3532 class C extends B with M { |
3438 C() : super.named(); | 3533 C() : super.named(); |
3439 } | 3534 } |
3440 '''); | 3535 '''); |
3441 // Note: the explicit call from C() to B.named() should not generate a | 3536 // Note: the explicit call from C() to B.named() should not generate a |
3442 // further error (despite the fact that it's not forwarded), since | 3537 // further error (despite the fact that it's not forwarded), since |
3443 // CompileTimeErrorCode.MIXIN_HAS_NO_CONSTRUCTORS does a better job of | 3538 // CompileTimeErrorCode.MIXIN_HAS_NO_CONSTRUCTORS does a better job of |
3444 // explaining the error to the user. | 3539 // explaining the error to the user. |
3445 resolve(source); | 3540 computeLibrarySourceErrors(source); |
3446 assertErrors(source, [CompileTimeErrorCode.MIXIN_HAS_NO_CONSTRUCTORS]); | 3541 assertErrors(source, [CompileTimeErrorCode.MIXIN_HAS_NO_CONSTRUCTORS]); |
3447 verify([source]); | 3542 verify([source]); |
3448 } | 3543 } |
3449 | 3544 |
3450 void test_mixinInheritsFromNotObject_classDeclaration_extends() { | 3545 void test_mixinInheritsFromNotObject_classDeclaration_extends() { |
3451 Source source = addSource(r''' | 3546 Source source = addSource(r''' |
3452 class A {} | 3547 class A {} |
3453 class B extends A {} | 3548 class B extends A {} |
3454 class C extends Object with B {}'''); | 3549 class C extends Object with B {}'''); |
3455 resolve(source); | 3550 computeLibrarySourceErrors(source); |
3456 assertErrors(source, [CompileTimeErrorCode.MIXIN_INHERITS_FROM_NOT_OBJECT]); | 3551 assertErrors(source, [CompileTimeErrorCode.MIXIN_INHERITS_FROM_NOT_OBJECT]); |
3457 verify([source]); | 3552 verify([source]); |
3458 } | 3553 } |
3459 | 3554 |
3460 void test_mixinInheritsFromNotObject_classDeclaration_with() { | 3555 void test_mixinInheritsFromNotObject_classDeclaration_with() { |
3461 Source source = addSource(r''' | 3556 Source source = addSource(r''' |
3462 class A {} | 3557 class A {} |
3463 class B extends Object with A {} | 3558 class B extends Object with A {} |
3464 class C extends Object with B {}'''); | 3559 class C extends Object with B {}'''); |
3465 resolve(source); | 3560 computeLibrarySourceErrors(source); |
3466 assertErrors(source, [CompileTimeErrorCode.MIXIN_INHERITS_FROM_NOT_OBJECT]); | 3561 assertErrors(source, [CompileTimeErrorCode.MIXIN_INHERITS_FROM_NOT_OBJECT]); |
3467 verify([source]); | 3562 verify([source]); |
3468 } | 3563 } |
3469 | 3564 |
3470 void test_mixinInheritsFromNotObject_typeAlias_extends() { | 3565 void test_mixinInheritsFromNotObject_typeAlias_extends() { |
3471 Source source = addSource(r''' | 3566 Source source = addSource(r''' |
3472 class A {} | 3567 class A {} |
3473 class B extends A {} | 3568 class B extends A {} |
3474 class C = Object with B;'''); | 3569 class C = Object with B;'''); |
3475 resolve(source); | 3570 computeLibrarySourceErrors(source); |
3476 assertErrors(source, [CompileTimeErrorCode.MIXIN_INHERITS_FROM_NOT_OBJECT]); | 3571 assertErrors(source, [CompileTimeErrorCode.MIXIN_INHERITS_FROM_NOT_OBJECT]); |
3477 verify([source]); | 3572 verify([source]); |
3478 } | 3573 } |
3479 | 3574 |
3480 void test_mixinInheritsFromNotObject_typeAlias_with() { | 3575 void test_mixinInheritsFromNotObject_typeAlias_with() { |
3481 Source source = addSource(r''' | 3576 Source source = addSource(r''' |
3482 class A {} | 3577 class A {} |
3483 class B extends Object with A {} | 3578 class B extends Object with A {} |
3484 class C = Object with B;'''); | 3579 class C = Object with B;'''); |
3485 resolve(source); | 3580 computeLibrarySourceErrors(source); |
3486 assertErrors(source, [CompileTimeErrorCode.MIXIN_INHERITS_FROM_NOT_OBJECT]); | 3581 assertErrors(source, [CompileTimeErrorCode.MIXIN_INHERITS_FROM_NOT_OBJECT]); |
3487 verify([source]); | 3582 verify([source]); |
3488 } | 3583 } |
3489 | 3584 |
3490 void test_mixinOfDisallowedClass_class_bool() { | 3585 void test_mixinOfDisallowedClass_class_bool() { |
3491 Source source = addSource("class A extends Object with bool {}"); | 3586 Source source = addSource("class A extends Object with bool {}"); |
3492 resolve(source); | 3587 computeLibrarySourceErrors(source); |
3493 assertErrors(source, [CompileTimeErrorCode.MIXIN_OF_DISALLOWED_CLASS]); | 3588 assertErrors(source, [CompileTimeErrorCode.MIXIN_OF_DISALLOWED_CLASS]); |
3494 verify([source]); | 3589 verify([source]); |
3495 } | 3590 } |
3496 | 3591 |
3497 void test_mixinOfDisallowedClass_class_double() { | 3592 void test_mixinOfDisallowedClass_class_double() { |
3498 Source source = addSource("class A extends Object with double {}"); | 3593 Source source = addSource("class A extends Object with double {}"); |
3499 resolve(source); | 3594 computeLibrarySourceErrors(source); |
3500 assertErrors(source, [CompileTimeErrorCode.MIXIN_OF_DISALLOWED_CLASS]); | 3595 assertErrors(source, [CompileTimeErrorCode.MIXIN_OF_DISALLOWED_CLASS]); |
3501 verify([source]); | 3596 verify([source]); |
3502 } | 3597 } |
3503 | 3598 |
3504 void test_mixinOfDisallowedClass_class_int() { | 3599 void test_mixinOfDisallowedClass_class_int() { |
3505 Source source = addSource("class A extends Object with int {}"); | 3600 Source source = addSource("class A extends Object with int {}"); |
3506 resolve(source); | 3601 computeLibrarySourceErrors(source); |
3507 assertErrors(source, [CompileTimeErrorCode.MIXIN_OF_DISALLOWED_CLASS]); | 3602 assertErrors(source, [CompileTimeErrorCode.MIXIN_OF_DISALLOWED_CLASS]); |
3508 verify([source]); | 3603 verify([source]); |
3509 } | 3604 } |
3510 | 3605 |
3511 void test_mixinOfDisallowedClass_class_Null() { | 3606 void test_mixinOfDisallowedClass_class_Null() { |
3512 Source source = addSource("class A extends Object with Null {}"); | 3607 Source source = addSource("class A extends Object with Null {}"); |
3513 resolve(source); | 3608 computeLibrarySourceErrors(source); |
3514 assertErrors(source, [CompileTimeErrorCode.MIXIN_OF_DISALLOWED_CLASS]); | 3609 assertErrors(source, [CompileTimeErrorCode.MIXIN_OF_DISALLOWED_CLASS]); |
3515 verify([source]); | 3610 verify([source]); |
3516 } | 3611 } |
3517 | 3612 |
3518 void test_mixinOfDisallowedClass_class_num() { | 3613 void test_mixinOfDisallowedClass_class_num() { |
3519 Source source = addSource("class A extends Object with num {}"); | 3614 Source source = addSource("class A extends Object with num {}"); |
3520 resolve(source); | 3615 computeLibrarySourceErrors(source); |
3521 assertErrors(source, [CompileTimeErrorCode.MIXIN_OF_DISALLOWED_CLASS]); | 3616 assertErrors(source, [CompileTimeErrorCode.MIXIN_OF_DISALLOWED_CLASS]); |
3522 verify([source]); | 3617 verify([source]); |
3523 } | 3618 } |
3524 | 3619 |
3525 void test_mixinOfDisallowedClass_class_String() { | 3620 void test_mixinOfDisallowedClass_class_String() { |
3526 Source source = addSource("class A extends Object with String {}"); | 3621 Source source = addSource("class A extends Object with String {}"); |
3527 resolve(source); | 3622 computeLibrarySourceErrors(source); |
3528 assertErrors(source, [CompileTimeErrorCode.MIXIN_OF_DISALLOWED_CLASS]); | 3623 assertErrors(source, [CompileTimeErrorCode.MIXIN_OF_DISALLOWED_CLASS]); |
3529 verify([source]); | 3624 verify([source]); |
3530 } | 3625 } |
3531 | 3626 |
3532 void test_mixinOfDisallowedClass_classTypeAlias_bool() { | 3627 void test_mixinOfDisallowedClass_classTypeAlias_bool() { |
3533 Source source = addSource(r''' | 3628 Source source = addSource(r''' |
3534 class A {} | 3629 class A {} |
3535 class C = A with bool;'''); | 3630 class C = A with bool;'''); |
3536 resolve(source); | 3631 computeLibrarySourceErrors(source); |
3537 assertErrors(source, [CompileTimeErrorCode.MIXIN_OF_DISALLOWED_CLASS]); | 3632 assertErrors(source, [CompileTimeErrorCode.MIXIN_OF_DISALLOWED_CLASS]); |
3538 verify([source]); | 3633 verify([source]); |
3539 } | 3634 } |
3540 | 3635 |
3541 void test_mixinOfDisallowedClass_classTypeAlias_double() { | 3636 void test_mixinOfDisallowedClass_classTypeAlias_double() { |
3542 Source source = addSource(r''' | 3637 Source source = addSource(r''' |
3543 class A {} | 3638 class A {} |
3544 class C = A with double;'''); | 3639 class C = A with double;'''); |
3545 resolve(source); | 3640 computeLibrarySourceErrors(source); |
3546 assertErrors(source, [CompileTimeErrorCode.MIXIN_OF_DISALLOWED_CLASS]); | 3641 assertErrors(source, [CompileTimeErrorCode.MIXIN_OF_DISALLOWED_CLASS]); |
3547 verify([source]); | 3642 verify([source]); |
3548 } | 3643 } |
3549 | 3644 |
3550 void test_mixinOfDisallowedClass_classTypeAlias_int() { | 3645 void test_mixinOfDisallowedClass_classTypeAlias_int() { |
3551 Source source = addSource(r''' | 3646 Source source = addSource(r''' |
3552 class A {} | 3647 class A {} |
3553 class C = A with int;'''); | 3648 class C = A with int;'''); |
3554 resolve(source); | 3649 computeLibrarySourceErrors(source); |
3555 assertErrors(source, [CompileTimeErrorCode.MIXIN_OF_DISALLOWED_CLASS]); | 3650 assertErrors(source, [CompileTimeErrorCode.MIXIN_OF_DISALLOWED_CLASS]); |
3556 verify([source]); | 3651 verify([source]); |
3557 } | 3652 } |
3558 | 3653 |
3559 void test_mixinOfDisallowedClass_classTypeAlias_Null() { | 3654 void test_mixinOfDisallowedClass_classTypeAlias_Null() { |
3560 Source source = addSource(r''' | 3655 Source source = addSource(r''' |
3561 class A {} | 3656 class A {} |
3562 class C = A with Null;'''); | 3657 class C = A with Null;'''); |
3563 resolve(source); | 3658 computeLibrarySourceErrors(source); |
3564 assertErrors(source, [CompileTimeErrorCode.MIXIN_OF_DISALLOWED_CLASS]); | 3659 assertErrors(source, [CompileTimeErrorCode.MIXIN_OF_DISALLOWED_CLASS]); |
3565 verify([source]); | 3660 verify([source]); |
3566 } | 3661 } |
3567 | 3662 |
3568 void test_mixinOfDisallowedClass_classTypeAlias_num() { | 3663 void test_mixinOfDisallowedClass_classTypeAlias_num() { |
3569 Source source = addSource(r''' | 3664 Source source = addSource(r''' |
3570 class A {} | 3665 class A {} |
3571 class C = A with num;'''); | 3666 class C = A with num;'''); |
3572 resolve(source); | 3667 computeLibrarySourceErrors(source); |
3573 assertErrors(source, [CompileTimeErrorCode.MIXIN_OF_DISALLOWED_CLASS]); | 3668 assertErrors(source, [CompileTimeErrorCode.MIXIN_OF_DISALLOWED_CLASS]); |
3574 verify([source]); | 3669 verify([source]); |
3575 } | 3670 } |
3576 | 3671 |
3577 void test_mixinOfDisallowedClass_classTypeAlias_String() { | 3672 void test_mixinOfDisallowedClass_classTypeAlias_String() { |
3578 Source source = addSource(r''' | 3673 Source source = addSource(r''' |
3579 class A {} | 3674 class A {} |
3580 class C = A with String;'''); | 3675 class C = A with String;'''); |
3581 resolve(source); | 3676 computeLibrarySourceErrors(source); |
3582 assertErrors(source, [CompileTimeErrorCode.MIXIN_OF_DISALLOWED_CLASS]); | 3677 assertErrors(source, [CompileTimeErrorCode.MIXIN_OF_DISALLOWED_CLASS]); |
3583 verify([source]); | 3678 verify([source]); |
3584 } | 3679 } |
3585 | 3680 |
3586 void test_mixinOfDisallowedClass_classTypeAlias_String_num() { | 3681 void test_mixinOfDisallowedClass_classTypeAlias_String_num() { |
3587 Source source = addSource(r''' | 3682 Source source = addSource(r''' |
3588 class A {} | 3683 class A {} |
3589 class C = A with String, num;'''); | 3684 class C = A with String, num;'''); |
3590 resolve(source); | 3685 computeLibrarySourceErrors(source); |
3591 assertErrors(source, [ | 3686 assertErrors(source, [ |
3592 CompileTimeErrorCode.MIXIN_OF_DISALLOWED_CLASS, | 3687 CompileTimeErrorCode.MIXIN_OF_DISALLOWED_CLASS, |
3593 CompileTimeErrorCode.MIXIN_OF_DISALLOWED_CLASS | 3688 CompileTimeErrorCode.MIXIN_OF_DISALLOWED_CLASS |
3594 ]); | 3689 ]); |
3595 verify([source]); | 3690 verify([source]); |
3596 } | 3691 } |
3597 | 3692 |
3598 void test_mixinOfEnum() { | 3693 void test_mixinOfEnum() { |
3599 Source source = addSource(r''' | 3694 Source source = addSource(r''' |
3600 enum E { ONE } | 3695 enum E { ONE } |
3601 class A extends Object with E {}'''); | 3696 class A extends Object with E {}'''); |
3602 resolve(source); | 3697 computeLibrarySourceErrors(source); |
3603 assertErrors(source, [CompileTimeErrorCode.MIXIN_OF_ENUM]); | 3698 assertErrors(source, [CompileTimeErrorCode.MIXIN_OF_ENUM]); |
3604 verify([source]); | 3699 verify([source]); |
3605 } | 3700 } |
3606 | 3701 |
3607 void test_mixinOfNonClass_class() { | 3702 void test_mixinOfNonClass_class() { |
3608 Source source = addSource(r''' | 3703 Source source = addSource(r''' |
3609 int A; | 3704 int A; |
3610 class B extends Object with A {}'''); | 3705 class B extends Object with A {}'''); |
3611 resolve(source); | 3706 computeLibrarySourceErrors(source); |
3612 assertErrors(source, [CompileTimeErrorCode.MIXIN_OF_NON_CLASS]); | 3707 assertErrors(source, [CompileTimeErrorCode.MIXIN_OF_NON_CLASS]); |
3613 verify([source]); | 3708 verify([source]); |
3614 } | 3709 } |
3615 | 3710 |
3616 void test_mixinOfNonClass_typeAlias() { | 3711 void test_mixinOfNonClass_typeAlias() { |
3617 Source source = addSource(r''' | 3712 Source source = addSource(r''' |
3618 class A {} | 3713 class A {} |
3619 int B; | 3714 int B; |
3620 class C = A with B;'''); | 3715 class C = A with B;'''); |
3621 resolve(source); | 3716 computeLibrarySourceErrors(source); |
3622 assertErrors(source, [CompileTimeErrorCode.MIXIN_OF_NON_CLASS]); | 3717 assertErrors(source, [CompileTimeErrorCode.MIXIN_OF_NON_CLASS]); |
3623 verify([source]); | 3718 verify([source]); |
3624 } | 3719 } |
3625 | 3720 |
3626 void test_mixinReferencesSuper() { | 3721 void test_mixinReferencesSuper() { |
3627 Source source = addSource(r''' | 3722 Source source = addSource(r''' |
3628 class A { | 3723 class A { |
3629 toString() => super.toString(); | 3724 toString() => super.toString(); |
3630 } | 3725 } |
3631 class B extends Object with A {}'''); | 3726 class B extends Object with A {}'''); |
3632 resolve(source); | 3727 computeLibrarySourceErrors(source); |
3633 assertErrors(source, [CompileTimeErrorCode.MIXIN_REFERENCES_SUPER]); | 3728 assertErrors(source, [CompileTimeErrorCode.MIXIN_REFERENCES_SUPER]); |
3634 verify([source]); | 3729 verify([source]); |
3635 } | 3730 } |
3636 | 3731 |
3637 void test_mixinWithNonClassSuperclass_class() { | 3732 void test_mixinWithNonClassSuperclass_class() { |
3638 Source source = addSource(r''' | 3733 Source source = addSource(r''' |
3639 int A; | 3734 int A; |
3640 class B {} | 3735 class B {} |
3641 class C extends A with B {}'''); | 3736 class C extends A with B {}'''); |
3642 resolve(source); | 3737 computeLibrarySourceErrors(source); |
3643 assertErrors( | 3738 assertErrors( |
3644 source, [CompileTimeErrorCode.MIXIN_WITH_NON_CLASS_SUPERCLASS]); | 3739 source, [CompileTimeErrorCode.MIXIN_WITH_NON_CLASS_SUPERCLASS]); |
3645 verify([source]); | 3740 verify([source]); |
3646 } | 3741 } |
3647 | 3742 |
3648 void test_mixinWithNonClassSuperclass_typeAlias() { | 3743 void test_mixinWithNonClassSuperclass_typeAlias() { |
3649 Source source = addSource(r''' | 3744 Source source = addSource(r''' |
3650 int A; | 3745 int A; |
3651 class B {} | 3746 class B {} |
3652 class C = A with B;'''); | 3747 class C = A with B;'''); |
3653 resolve(source); | 3748 computeLibrarySourceErrors(source); |
3654 assertErrors( | 3749 assertErrors( |
3655 source, [CompileTimeErrorCode.MIXIN_WITH_NON_CLASS_SUPERCLASS]); | 3750 source, [CompileTimeErrorCode.MIXIN_WITH_NON_CLASS_SUPERCLASS]); |
3656 verify([source]); | 3751 verify([source]); |
3657 } | 3752 } |
3658 | 3753 |
3659 void test_multipleRedirectingConstructorInvocations() { | 3754 void test_multipleRedirectingConstructorInvocations() { |
3660 Source source = addSource(r''' | 3755 Source source = addSource(r''' |
3661 class A { | 3756 class A { |
3662 A() : this.a(), this.b(); | 3757 A() : this.a(), this.b(); |
3663 A.a() {} | 3758 A.a() {} |
3664 A.b() {} | 3759 A.b() {} |
3665 }'''); | 3760 }'''); |
3666 resolve(source); | 3761 computeLibrarySourceErrors(source); |
3667 assertErrors(source, | 3762 assertErrors(source, |
3668 [CompileTimeErrorCode.MULTIPLE_REDIRECTING_CONSTRUCTOR_INVOCATIONS]); | 3763 [CompileTimeErrorCode.MULTIPLE_REDIRECTING_CONSTRUCTOR_INVOCATIONS]); |
3669 verify([source]); | 3764 verify([source]); |
3670 } | 3765 } |
3671 | 3766 |
3672 void test_multipleSuperInitializers() { | 3767 void test_multipleSuperInitializers() { |
3673 Source source = addSource(r''' | 3768 Source source = addSource(r''' |
3674 class A {} | 3769 class A {} |
3675 class B extends A { | 3770 class B extends A { |
3676 B() : super(), super() {} | 3771 B() : super(), super() {} |
3677 }'''); | 3772 }'''); |
3678 resolve(source); | 3773 computeLibrarySourceErrors(source); |
3679 assertErrors(source, [CompileTimeErrorCode.MULTIPLE_SUPER_INITIALIZERS]); | 3774 assertErrors(source, [CompileTimeErrorCode.MULTIPLE_SUPER_INITIALIZERS]); |
3680 verify([source]); | 3775 verify([source]); |
3681 } | 3776 } |
3682 | 3777 |
3683 void test_nativeClauseInNonSDKCode() { | 3778 void test_nativeClauseInNonSDKCode() { |
3684 // TODO(jwren) Move this test somewhere else: This test verifies a parser | 3779 // TODO(jwren) Move this test somewhere else: This test verifies a parser |
3685 // error code is generated through the ErrorVerifier, it is not a | 3780 // error code is generated through the ErrorVerifier, it is not a |
3686 // CompileTimeErrorCode. | 3781 // CompileTimeErrorCode. |
3687 Source source = addSource("class A native 'string' {}"); | 3782 Source source = addSource("class A native 'string' {}"); |
3688 resolve(source); | 3783 computeLibrarySourceErrors(source); |
3689 assertErrors(source, [ParserErrorCode.NATIVE_CLAUSE_IN_NON_SDK_CODE]); | 3784 assertErrors(source, [ParserErrorCode.NATIVE_CLAUSE_IN_NON_SDK_CODE]); |
3690 verify([source]); | 3785 verify([source]); |
3691 } | 3786 } |
3692 | 3787 |
3693 void test_nativeFunctionBodyInNonSDKCode_function() { | 3788 void test_nativeFunctionBodyInNonSDKCode_function() { |
3694 // TODO(jwren) Move this test somewhere else: This test verifies a parser | 3789 // TODO(jwren) Move this test somewhere else: This test verifies a parser |
3695 // error code is generated through the ErrorVerifier, it is not a | 3790 // error code is generated through the ErrorVerifier, it is not a |
3696 // CompileTimeErrorCode. | 3791 // CompileTimeErrorCode. |
3697 Source source = addSource("int m(a) native 'string';"); | 3792 Source source = addSource("int m(a) native 'string';"); |
3698 resolve(source); | 3793 computeLibrarySourceErrors(source); |
3699 assertErrors( | 3794 assertErrors( |
3700 source, [ParserErrorCode.NATIVE_FUNCTION_BODY_IN_NON_SDK_CODE]); | 3795 source, [ParserErrorCode.NATIVE_FUNCTION_BODY_IN_NON_SDK_CODE]); |
3701 verify([source]); | 3796 verify([source]); |
3702 } | 3797 } |
3703 | 3798 |
3704 void test_nativeFunctionBodyInNonSDKCode_method() { | 3799 void test_nativeFunctionBodyInNonSDKCode_method() { |
3705 // TODO(jwren) Move this test somewhere else: This test verifies a parser | 3800 // TODO(jwren) Move this test somewhere else: This test verifies a parser |
3706 // error code is generated through the ErrorVerifier, it is not a | 3801 // error code is generated through the ErrorVerifier, it is not a |
3707 // CompileTimeErrorCode. | 3802 // CompileTimeErrorCode. |
3708 Source source = addSource(r''' | 3803 Source source = addSource(r''' |
3709 class A{ | 3804 class A{ |
3710 static int m(a) native 'string'; | 3805 static int m(a) native 'string'; |
3711 }'''); | 3806 }'''); |
3712 resolve(source); | 3807 computeLibrarySourceErrors(source); |
3713 assertErrors( | 3808 assertErrors( |
3714 source, [ParserErrorCode.NATIVE_FUNCTION_BODY_IN_NON_SDK_CODE]); | 3809 source, [ParserErrorCode.NATIVE_FUNCTION_BODY_IN_NON_SDK_CODE]); |
3715 verify([source]); | 3810 verify([source]); |
3716 } | 3811 } |
3717 | 3812 |
3718 void test_noAnnotationConstructorArguments() { | 3813 void test_noAnnotationConstructorArguments() { |
3719 Source source = addSource(r''' | 3814 Source source = addSource(r''' |
3720 class A { | 3815 class A { |
3721 const A(); | 3816 const A(); |
3722 } | 3817 } |
3723 @A | 3818 @A |
3724 main() { | 3819 main() { |
3725 }'''); | 3820 }'''); |
3726 resolve(source); | 3821 computeLibrarySourceErrors(source); |
3727 assertErrors( | 3822 assertErrors( |
3728 source, [CompileTimeErrorCode.NO_ANNOTATION_CONSTRUCTOR_ARGUMENTS]); | 3823 source, [CompileTimeErrorCode.NO_ANNOTATION_CONSTRUCTOR_ARGUMENTS]); |
3729 verify([source]); | 3824 verify([source]); |
3730 } | 3825 } |
3731 | 3826 |
3732 void test_noDefaultSuperConstructorExplicit() { | 3827 void test_noDefaultSuperConstructorExplicit() { |
3733 Source source = addSource(r''' | 3828 Source source = addSource(r''' |
3734 class A { | 3829 class A { |
3735 A(p); | 3830 A(p); |
3736 } | 3831 } |
3737 class B extends A { | 3832 class B extends A { |
3738 B() {} | 3833 B() {} |
3739 }'''); | 3834 }'''); |
3740 resolve(source); | 3835 computeLibrarySourceErrors(source); |
3741 assertErrors( | 3836 assertErrors( |
3742 source, [CompileTimeErrorCode.NO_DEFAULT_SUPER_CONSTRUCTOR_EXPLICIT]); | 3837 source, [CompileTimeErrorCode.NO_DEFAULT_SUPER_CONSTRUCTOR_EXPLICIT]); |
3743 verify([source]); | 3838 verify([source]); |
3744 } | 3839 } |
3745 | 3840 |
3746 void test_noDefaultSuperConstructorExplicit_MixinAppWithDirectSuperCall() { | 3841 void test_noDefaultSuperConstructorExplicit_MixinAppWithDirectSuperCall() { |
3747 Source source = addSource(r''' | 3842 Source source = addSource(r''' |
3748 class M {} | 3843 class M {} |
3749 class B { | 3844 class B { |
3750 B({x}); | 3845 B({x}); |
3751 B.named(); // To avoid MIXIN_HAS_NO_CONSTRUCTORS | 3846 B.named(); // To avoid MIXIN_HAS_NO_CONSTRUCTORS |
3752 } | 3847 } |
3753 class Mixed = B with M; | 3848 class Mixed = B with M; |
3754 class C extends Mixed { | 3849 class C extends Mixed { |
3755 C(x) : super(); | 3850 C(x) : super(); |
3756 } | 3851 } |
3757 '''); | 3852 '''); |
3758 resolve(source); | 3853 computeLibrarySourceErrors(source); |
3759 assertErrors(source, | 3854 assertErrors(source, |
3760 [CompileTimeErrorCode.UNDEFINED_CONSTRUCTOR_IN_INITIALIZER_DEFAULT]); | 3855 [CompileTimeErrorCode.UNDEFINED_CONSTRUCTOR_IN_INITIALIZER_DEFAULT]); |
3761 verify([source]); | 3856 verify([source]); |
3762 } | 3857 } |
3763 | 3858 |
3764 void test_noDefaultSuperConstructorExplicit_mixinAppWithNamedParam() { | 3859 void test_noDefaultSuperConstructorExplicit_mixinAppWithNamedParam() { |
3765 Source source = addSource(r''' | 3860 Source source = addSource(r''' |
3766 class M {} | 3861 class M {} |
3767 class B { | 3862 class B { |
3768 B({x}); | 3863 B({x}); |
3769 B.named(); // To avoid MIXIN_HAS_NO_CONSTRUCTORS | 3864 B.named(); // To avoid MIXIN_HAS_NO_CONSTRUCTORS |
3770 } | 3865 } |
3771 class Mixed = B with M; | 3866 class Mixed = B with M; |
3772 class C extends Mixed { | 3867 class C extends Mixed { |
3773 C(); | 3868 C(); |
3774 } | 3869 } |
3775 '''); | 3870 '''); |
3776 resolve(source); | 3871 computeLibrarySourceErrors(source); |
3777 assertErrors(source, | 3872 assertErrors(source, |
3778 [CompileTimeErrorCode.UNDEFINED_CONSTRUCTOR_IN_INITIALIZER_DEFAULT]); | 3873 [CompileTimeErrorCode.UNDEFINED_CONSTRUCTOR_IN_INITIALIZER_DEFAULT]); |
3779 verify([source]); | 3874 verify([source]); |
3780 } | 3875 } |
3781 | 3876 |
3782 void test_noDefaultSuperConstructorExplicit_MixinAppWithNamedSuperCall() { | 3877 void test_noDefaultSuperConstructorExplicit_MixinAppWithNamedSuperCall() { |
3783 Source source = addSource(r''' | 3878 Source source = addSource(r''' |
3784 class M {} | 3879 class M {} |
3785 class B { | 3880 class B { |
3786 B.named({x}); | 3881 B.named({x}); |
3787 B.named2(); // To avoid MIXIN_HAS_NO_CONSTRUCTORS | 3882 B.named2(); // To avoid MIXIN_HAS_NO_CONSTRUCTORS |
3788 } | 3883 } |
3789 class Mixed = B with M; | 3884 class Mixed = B with M; |
3790 class C extends Mixed { | 3885 class C extends Mixed { |
3791 C(x) : super.named(); | 3886 C(x) : super.named(); |
3792 } | 3887 } |
3793 '''); | 3888 '''); |
3794 resolve(source); | 3889 computeLibrarySourceErrors(source); |
3795 assertErrors( | 3890 assertErrors( |
3796 source, [CompileTimeErrorCode.UNDEFINED_CONSTRUCTOR_IN_INITIALIZER]); | 3891 source, [CompileTimeErrorCode.UNDEFINED_CONSTRUCTOR_IN_INITIALIZER]); |
3797 // Don't verify since call to super.named() can't be resolved. | 3892 // Don't verify since call to super.named() can't be resolved. |
3798 } | 3893 } |
3799 | 3894 |
3800 void test_noDefaultSuperConstructorExplicit_mixinAppWithOptionalParam() { | 3895 void test_noDefaultSuperConstructorExplicit_mixinAppWithOptionalParam() { |
3801 Source source = addSource(r''' | 3896 Source source = addSource(r''' |
3802 class M {} | 3897 class M {} |
3803 class B { | 3898 class B { |
3804 B([x]); | 3899 B([x]); |
3805 B.named(); // To avoid MIXIN_HAS_NO_CONSTRUCTORS | 3900 B.named(); // To avoid MIXIN_HAS_NO_CONSTRUCTORS |
3806 } | 3901 } |
3807 class Mixed = B with M; | 3902 class Mixed = B with M; |
3808 class C extends Mixed { | 3903 class C extends Mixed { |
3809 C(); | 3904 C(); |
3810 } | 3905 } |
3811 '''); | 3906 '''); |
3812 resolve(source); | 3907 computeLibrarySourceErrors(source); |
3813 assertErrors(source, | 3908 assertErrors(source, |
3814 [CompileTimeErrorCode.UNDEFINED_CONSTRUCTOR_IN_INITIALIZER_DEFAULT]); | 3909 [CompileTimeErrorCode.UNDEFINED_CONSTRUCTOR_IN_INITIALIZER_DEFAULT]); |
3815 verify([source]); | 3910 verify([source]); |
3816 } | 3911 } |
3817 | 3912 |
3818 void test_noDefaultSuperConstructorExplicit_MixinWithDirectSuperCall() { | 3913 void test_noDefaultSuperConstructorExplicit_MixinWithDirectSuperCall() { |
3819 Source source = addSource(r''' | 3914 Source source = addSource(r''' |
3820 class M {} | 3915 class M {} |
3821 class B { | 3916 class B { |
3822 B({x}); | 3917 B({x}); |
3823 B.other(); | 3918 B.other(); |
3824 } | 3919 } |
3825 class C extends B with M { | 3920 class C extends B with M { |
3826 C(x) : super(); | 3921 C(x) : super(); |
3827 } | 3922 } |
3828 '''); | 3923 '''); |
3829 resolve(source); | 3924 computeLibrarySourceErrors(source); |
3830 assertErrors(source, | 3925 assertErrors(source, |
3831 [CompileTimeErrorCode.UNDEFINED_CONSTRUCTOR_IN_INITIALIZER_DEFAULT]); | 3926 [CompileTimeErrorCode.UNDEFINED_CONSTRUCTOR_IN_INITIALIZER_DEFAULT]); |
3832 verify([source]); | 3927 verify([source]); |
3833 } | 3928 } |
3834 | 3929 |
3835 void test_noDefaultSuperConstructorExplicit_mixinWithNamedParam() { | 3930 void test_noDefaultSuperConstructorExplicit_mixinWithNamedParam() { |
3836 Source source = addSource(r''' | 3931 Source source = addSource(r''' |
3837 class M {} | 3932 class M {} |
3838 class B { | 3933 class B { |
3839 B({x}); | 3934 B({x}); |
3840 B.named(); | 3935 B.named(); |
3841 } | 3936 } |
3842 class C extends B with M { | 3937 class C extends B with M { |
3843 C(); | 3938 C(); |
3844 } | 3939 } |
3845 '''); | 3940 '''); |
3846 resolve(source); | 3941 computeLibrarySourceErrors(source); |
3847 assertErrors( | 3942 assertErrors( |
3848 source, [CompileTimeErrorCode.NO_DEFAULT_SUPER_CONSTRUCTOR_EXPLICIT]); | 3943 source, [CompileTimeErrorCode.NO_DEFAULT_SUPER_CONSTRUCTOR_EXPLICIT]); |
3849 verify([source]); | 3944 verify([source]); |
3850 } | 3945 } |
3851 | 3946 |
3852 void test_noDefaultSuperConstructorExplicit_MixinWithNamedSuperCall() { | 3947 void test_noDefaultSuperConstructorExplicit_MixinWithNamedSuperCall() { |
3853 Source source = addSource(r''' | 3948 Source source = addSource(r''' |
3854 class M {} | 3949 class M {} |
3855 class B { | 3950 class B { |
3856 B.named({x}); | 3951 B.named({x}); |
3857 B.other(); | 3952 B.other(); |
3858 } | 3953 } |
3859 class C extends B with M { | 3954 class C extends B with M { |
3860 C(x) : super.named(); | 3955 C(x) : super.named(); |
3861 } | 3956 } |
3862 '''); | 3957 '''); |
3863 resolve(source); | 3958 computeLibrarySourceErrors(source); |
3864 assertErrors( | 3959 assertErrors( |
3865 source, [CompileTimeErrorCode.UNDEFINED_CONSTRUCTOR_IN_INITIALIZER]); | 3960 source, [CompileTimeErrorCode.UNDEFINED_CONSTRUCTOR_IN_INITIALIZER]); |
3866 // Don't verify since call to super.named() can't be resolved. | 3961 // Don't verify since call to super.named() can't be resolved. |
3867 } | 3962 } |
3868 | 3963 |
3869 void test_noDefaultSuperConstructorExplicit_mixinWithOptionalParam() { | 3964 void test_noDefaultSuperConstructorExplicit_mixinWithOptionalParam() { |
3870 Source source = addSource(r''' | 3965 Source source = addSource(r''' |
3871 class M {} | 3966 class M {} |
3872 class B { | 3967 class B { |
3873 B([x]); | 3968 B([x]); |
3874 B.other(); | 3969 B.other(); |
3875 } | 3970 } |
3876 class C extends B with M { | 3971 class C extends B with M { |
3877 C(); | 3972 C(); |
3878 } | 3973 } |
3879 '''); | 3974 '''); |
3880 resolve(source); | 3975 computeLibrarySourceErrors(source); |
3881 assertErrors( | 3976 assertErrors( |
3882 source, [CompileTimeErrorCode.NO_DEFAULT_SUPER_CONSTRUCTOR_EXPLICIT]); | 3977 source, [CompileTimeErrorCode.NO_DEFAULT_SUPER_CONSTRUCTOR_EXPLICIT]); |
3883 verify([source]); | 3978 verify([source]); |
3884 } | 3979 } |
3885 | 3980 |
3886 void test_noDefaultSuperConstructorImplicit_mixinAppWithNamedParam() { | 3981 void test_noDefaultSuperConstructorImplicit_mixinAppWithNamedParam() { |
3887 Source source = addSource(r''' | 3982 Source source = addSource(r''' |
3888 class M {} | 3983 class M {} |
3889 class B { | 3984 class B { |
3890 B({x}); | 3985 B({x}); |
3891 B.named(); // To avoid MIXIN_HAS_NO_CONSTRUCTORS | 3986 B.named(); // To avoid MIXIN_HAS_NO_CONSTRUCTORS |
3892 } | 3987 } |
3893 class Mixed = B with M; | 3988 class Mixed = B with M; |
3894 class C extends Mixed {} | 3989 class C extends Mixed {} |
3895 '''); | 3990 '''); |
3896 resolve(source); | 3991 computeLibrarySourceErrors(source); |
3897 assertErrors( | 3992 assertErrors( |
3898 source, [CompileTimeErrorCode.NO_DEFAULT_SUPER_CONSTRUCTOR_IMPLICIT]); | 3993 source, [CompileTimeErrorCode.NO_DEFAULT_SUPER_CONSTRUCTOR_IMPLICIT]); |
3899 verify([source]); | 3994 verify([source]); |
3900 } | 3995 } |
3901 | 3996 |
3902 void test_noDefaultSuperConstructorImplicit_mixinAppWithOptionalParam() { | 3997 void test_noDefaultSuperConstructorImplicit_mixinAppWithOptionalParam() { |
3903 Source source = addSource(r''' | 3998 Source source = addSource(r''' |
3904 class M {} | 3999 class M {} |
3905 class B { | 4000 class B { |
3906 B([x]); | 4001 B([x]); |
3907 B.named(); // To avoid MIXIN_HAS_NO_CONSTRUCTORS | 4002 B.named(); // To avoid MIXIN_HAS_NO_CONSTRUCTORS |
3908 } | 4003 } |
3909 class Mixed = B with M; | 4004 class Mixed = B with M; |
3910 class C extends Mixed {} | 4005 class C extends Mixed {} |
3911 '''); | 4006 '''); |
3912 resolve(source); | 4007 computeLibrarySourceErrors(source); |
3913 assertErrors( | 4008 assertErrors( |
3914 source, [CompileTimeErrorCode.NO_DEFAULT_SUPER_CONSTRUCTOR_IMPLICIT]); | 4009 source, [CompileTimeErrorCode.NO_DEFAULT_SUPER_CONSTRUCTOR_IMPLICIT]); |
3915 verify([source]); | 4010 verify([source]); |
3916 } | 4011 } |
3917 | 4012 |
3918 void test_noDefaultSuperConstructorImplicit_mixinWithNamedParam() { | 4013 void test_noDefaultSuperConstructorImplicit_mixinWithNamedParam() { |
3919 Source source = addSource(r''' | 4014 Source source = addSource(r''' |
3920 class M {} | 4015 class M {} |
3921 class B { | 4016 class B { |
3922 B({x}); | 4017 B({x}); |
3923 B.other(); | 4018 B.other(); |
3924 } | 4019 } |
3925 class C extends B with M {} | 4020 class C extends B with M {} |
3926 '''); | 4021 '''); |
3927 resolve(source); | 4022 computeLibrarySourceErrors(source); |
3928 assertErrors( | 4023 assertErrors( |
3929 source, [CompileTimeErrorCode.NO_DEFAULT_SUPER_CONSTRUCTOR_IMPLICIT]); | 4024 source, [CompileTimeErrorCode.NO_DEFAULT_SUPER_CONSTRUCTOR_IMPLICIT]); |
3930 verify([source]); | 4025 verify([source]); |
3931 } | 4026 } |
3932 | 4027 |
3933 void test_noDefaultSuperConstructorImplicit_mixinWithOptionalParam() { | 4028 void test_noDefaultSuperConstructorImplicit_mixinWithOptionalParam() { |
3934 Source source = addSource(r''' | 4029 Source source = addSource(r''' |
3935 class M {} | 4030 class M {} |
3936 class B { | 4031 class B { |
3937 B([x]); | 4032 B([x]); |
3938 B.other(); | 4033 B.other(); |
3939 } | 4034 } |
3940 class C extends B with M {} | 4035 class C extends B with M {} |
3941 '''); | 4036 '''); |
3942 resolve(source); | 4037 computeLibrarySourceErrors(source); |
3943 assertErrors( | 4038 assertErrors( |
3944 source, [CompileTimeErrorCode.NO_DEFAULT_SUPER_CONSTRUCTOR_IMPLICIT]); | 4039 source, [CompileTimeErrorCode.NO_DEFAULT_SUPER_CONSTRUCTOR_IMPLICIT]); |
3945 verify([source]); | 4040 verify([source]); |
3946 } | 4041 } |
3947 | 4042 |
3948 void test_noDefaultSuperConstructorImplicit_superHasParameters() { | 4043 void test_noDefaultSuperConstructorImplicit_superHasParameters() { |
3949 Source source = addSource(r''' | 4044 Source source = addSource(r''' |
3950 class A { | 4045 class A { |
3951 A(p); | 4046 A(p); |
3952 } | 4047 } |
3953 class B extends A { | 4048 class B extends A { |
3954 }'''); | 4049 }'''); |
3955 resolve(source); | 4050 computeLibrarySourceErrors(source); |
3956 assertErrors( | 4051 assertErrors( |
3957 source, [CompileTimeErrorCode.NO_DEFAULT_SUPER_CONSTRUCTOR_IMPLICIT]); | 4052 source, [CompileTimeErrorCode.NO_DEFAULT_SUPER_CONSTRUCTOR_IMPLICIT]); |
3958 verify([source]); | 4053 verify([source]); |
3959 } | 4054 } |
3960 | 4055 |
3961 void test_noDefaultSuperConstructorImplicit_superOnlyNamed() { | 4056 void test_noDefaultSuperConstructorImplicit_superOnlyNamed() { |
3962 Source source = addSource(r''' | 4057 Source source = addSource(r''' |
3963 class A { A.named() {} } | 4058 class A { A.named() {} } |
3964 class B extends A {}'''); | 4059 class B extends A {}'''); |
3965 resolve(source); | 4060 computeLibrarySourceErrors(source); |
3966 assertErrors( | 4061 assertErrors( |
3967 source, [CompileTimeErrorCode.NO_DEFAULT_SUPER_CONSTRUCTOR_IMPLICIT]); | 4062 source, [CompileTimeErrorCode.NO_DEFAULT_SUPER_CONSTRUCTOR_IMPLICIT]); |
3968 verify([source]); | 4063 verify([source]); |
3969 } | 4064 } |
3970 | 4065 |
3971 void test_nonConstantAnnotationConstructor_named() { | 4066 void test_nonConstantAnnotationConstructor_named() { |
3972 Source source = addSource(r''' | 4067 Source source = addSource(r''' |
3973 class A { | 4068 class A { |
3974 A.fromInt() {} | 4069 A.fromInt() {} |
3975 } | 4070 } |
3976 @A.fromInt() | 4071 @A.fromInt() |
3977 main() { | 4072 main() { |
3978 }'''); | 4073 }'''); |
3979 resolve(source); | 4074 computeLibrarySourceErrors(source); |
3980 assertErrors( | 4075 assertErrors( |
3981 source, [CompileTimeErrorCode.NON_CONSTANT_ANNOTATION_CONSTRUCTOR]); | 4076 source, [CompileTimeErrorCode.NON_CONSTANT_ANNOTATION_CONSTRUCTOR]); |
3982 verify([source]); | 4077 verify([source]); |
3983 } | 4078 } |
3984 | 4079 |
3985 void test_nonConstantAnnotationConstructor_unnamed() { | 4080 void test_nonConstantAnnotationConstructor_unnamed() { |
3986 Source source = addSource(r''' | 4081 Source source = addSource(r''' |
3987 class A { | 4082 class A { |
3988 A() {} | 4083 A() {} |
3989 } | 4084 } |
3990 @A() | 4085 @A() |
3991 main() { | 4086 main() { |
3992 }'''); | 4087 }'''); |
3993 resolve(source); | 4088 computeLibrarySourceErrors(source); |
3994 assertErrors( | 4089 assertErrors( |
3995 source, [CompileTimeErrorCode.NON_CONSTANT_ANNOTATION_CONSTRUCTOR]); | 4090 source, [CompileTimeErrorCode.NON_CONSTANT_ANNOTATION_CONSTRUCTOR]); |
3996 verify([source]); | 4091 verify([source]); |
3997 } | 4092 } |
3998 | 4093 |
3999 void test_nonConstantDefaultValue_function_named() { | 4094 void test_nonConstantDefaultValue_function_named() { |
4000 Source source = addSource(r''' | 4095 Source source = addSource(r''' |
4001 int y; | 4096 int y; |
4002 f({x : y}) {}'''); | 4097 f({x : y}) {}'''); |
4003 resolve(source); | 4098 computeLibrarySourceErrors(source); |
4004 assertErrors(source, [CompileTimeErrorCode.NON_CONSTANT_DEFAULT_VALUE]); | 4099 assertErrors(source, [CompileTimeErrorCode.NON_CONSTANT_DEFAULT_VALUE]); |
4005 verify([source]); | 4100 verify([source]); |
4006 } | 4101 } |
4007 | 4102 |
4008 void test_nonConstantDefaultValue_function_positional() { | 4103 void test_nonConstantDefaultValue_function_positional() { |
4009 Source source = addSource(r''' | 4104 Source source = addSource(r''' |
4010 int y; | 4105 int y; |
4011 f([x = y]) {}'''); | 4106 f([x = y]) {}'''); |
4012 resolve(source); | 4107 computeLibrarySourceErrors(source); |
4013 assertErrors(source, [CompileTimeErrorCode.NON_CONSTANT_DEFAULT_VALUE]); | 4108 assertErrors(source, [CompileTimeErrorCode.NON_CONSTANT_DEFAULT_VALUE]); |
4014 verify([source]); | 4109 verify([source]); |
4015 } | 4110 } |
4016 | 4111 |
4017 void test_nonConstantDefaultValue_inConstructor_named() { | 4112 void test_nonConstantDefaultValue_inConstructor_named() { |
4018 Source source = addSource(r''' | 4113 Source source = addSource(r''' |
4019 class A { | 4114 class A { |
4020 int y; | 4115 int y; |
4021 A({x : y}) {} | 4116 A({x : y}) {} |
4022 }'''); | 4117 }'''); |
4023 resolve(source); | 4118 computeLibrarySourceErrors(source); |
4024 assertErrors(source, [CompileTimeErrorCode.NON_CONSTANT_DEFAULT_VALUE]); | 4119 assertErrors(source, [CompileTimeErrorCode.NON_CONSTANT_DEFAULT_VALUE]); |
4025 verify([source]); | 4120 verify([source]); |
4026 } | 4121 } |
4027 | 4122 |
4028 void test_nonConstantDefaultValue_inConstructor_positional() { | 4123 void test_nonConstantDefaultValue_inConstructor_positional() { |
4029 Source source = addSource(r''' | 4124 Source source = addSource(r''' |
4030 class A { | 4125 class A { |
4031 int y; | 4126 int y; |
4032 A([x = y]) {} | 4127 A([x = y]) {} |
4033 }'''); | 4128 }'''); |
4034 resolve(source); | 4129 computeLibrarySourceErrors(source); |
4035 assertErrors(source, [CompileTimeErrorCode.NON_CONSTANT_DEFAULT_VALUE]); | 4130 assertErrors(source, [CompileTimeErrorCode.NON_CONSTANT_DEFAULT_VALUE]); |
4036 verify([source]); | 4131 verify([source]); |
4037 } | 4132 } |
4038 | 4133 |
4039 void test_nonConstantDefaultValue_method_named() { | 4134 void test_nonConstantDefaultValue_method_named() { |
4040 Source source = addSource(r''' | 4135 Source source = addSource(r''' |
4041 class A { | 4136 class A { |
4042 int y; | 4137 int y; |
4043 m({x : y}) {} | 4138 m({x : y}) {} |
4044 }'''); | 4139 }'''); |
4045 resolve(source); | 4140 computeLibrarySourceErrors(source); |
4046 assertErrors(source, [CompileTimeErrorCode.NON_CONSTANT_DEFAULT_VALUE]); | 4141 assertErrors(source, [CompileTimeErrorCode.NON_CONSTANT_DEFAULT_VALUE]); |
4047 verify([source]); | 4142 verify([source]); |
4048 } | 4143 } |
4049 | 4144 |
4050 void test_nonConstantDefaultValue_method_positional() { | 4145 void test_nonConstantDefaultValue_method_positional() { |
4051 Source source = addSource(r''' | 4146 Source source = addSource(r''' |
4052 class A { | 4147 class A { |
4053 int y; | 4148 int y; |
4054 m([x = y]) {} | 4149 m([x = y]) {} |
4055 }'''); | 4150 }'''); |
4056 resolve(source); | 4151 computeLibrarySourceErrors(source); |
4057 assertErrors(source, [CompileTimeErrorCode.NON_CONSTANT_DEFAULT_VALUE]); | 4152 assertErrors(source, [CompileTimeErrorCode.NON_CONSTANT_DEFAULT_VALUE]); |
4058 verify([source]); | 4153 verify([source]); |
4059 } | 4154 } |
4060 | 4155 |
4061 void test_nonConstantDefaultValueFromDeferredLibrary() { | 4156 void test_nonConstantDefaultValueFromDeferredLibrary() { |
4062 resolveWithErrors(<String>[ | 4157 resolveWithErrors(<String>[ |
4063 r''' | 4158 r''' |
4064 library lib1; | 4159 library lib1; |
4065 const V = 1;''', | 4160 const V = 1;''', |
4066 r''' | 4161 r''' |
(...skipping 20 matching lines...) Expand all Loading... |
4087 } | 4182 } |
4088 | 4183 |
4089 void test_nonConstCaseExpression() { | 4184 void test_nonConstCaseExpression() { |
4090 Source source = addSource(r''' | 4185 Source source = addSource(r''' |
4091 f(int p, int q) { | 4186 f(int p, int q) { |
4092 switch (p) { | 4187 switch (p) { |
4093 case 3 + q: | 4188 case 3 + q: |
4094 break; | 4189 break; |
4095 } | 4190 } |
4096 }'''); | 4191 }'''); |
4097 resolve(source); | 4192 computeLibrarySourceErrors(source); |
4098 assertErrors(source, [CompileTimeErrorCode.NON_CONSTANT_CASE_EXPRESSION]); | 4193 assertErrors(source, [CompileTimeErrorCode.NON_CONSTANT_CASE_EXPRESSION]); |
4099 verify([source]); | 4194 verify([source]); |
4100 } | 4195 } |
4101 | 4196 |
4102 void test_nonConstCaseExpressionFromDeferredLibrary() { | 4197 void test_nonConstCaseExpressionFromDeferredLibrary() { |
4103 resolveWithErrors(<String>[ | 4198 resolveWithErrors(<String>[ |
4104 r''' | 4199 r''' |
4105 library lib1; | 4200 library lib1; |
4106 const int c = 1;''', | 4201 const int c = 1;''', |
4107 r''' | 4202 r''' |
(...skipping 27 matching lines...) Expand all Loading... |
4135 ], <ErrorCode>[ | 4230 ], <ErrorCode>[ |
4136 CompileTimeErrorCode.NON_CONSTANT_CASE_EXPRESSION_FROM_DEFERRED_LIBRARY | 4231 CompileTimeErrorCode.NON_CONSTANT_CASE_EXPRESSION_FROM_DEFERRED_LIBRARY |
4137 ]); | 4232 ]); |
4138 } | 4233 } |
4139 | 4234 |
4140 void test_nonConstListElement() { | 4235 void test_nonConstListElement() { |
4141 Source source = addSource(r''' | 4236 Source source = addSource(r''' |
4142 f(a) { | 4237 f(a) { |
4143 return const [a]; | 4238 return const [a]; |
4144 }'''); | 4239 }'''); |
4145 resolve(source); | 4240 computeLibrarySourceErrors(source); |
4146 assertErrors(source, [CompileTimeErrorCode.NON_CONSTANT_LIST_ELEMENT]); | 4241 assertErrors(source, [CompileTimeErrorCode.NON_CONSTANT_LIST_ELEMENT]); |
4147 verify([source]); | 4242 verify([source]); |
4148 } | 4243 } |
4149 | 4244 |
4150 void test_nonConstListElementFromDeferredLibrary() { | 4245 void test_nonConstListElementFromDeferredLibrary() { |
4151 resolveWithErrors(<String>[ | 4246 resolveWithErrors(<String>[ |
4152 r''' | 4247 r''' |
4153 library lib1; | 4248 library lib1; |
4154 const int c = 1;''', | 4249 const int c = 1;''', |
4155 r''' | 4250 r''' |
(...skipping 21 matching lines...) Expand all Loading... |
4177 ], <ErrorCode>[ | 4272 ], <ErrorCode>[ |
4178 CompileTimeErrorCode.NON_CONSTANT_LIST_ELEMENT_FROM_DEFERRED_LIBRARY | 4273 CompileTimeErrorCode.NON_CONSTANT_LIST_ELEMENT_FROM_DEFERRED_LIBRARY |
4179 ]); | 4274 ]); |
4180 } | 4275 } |
4181 | 4276 |
4182 void test_nonConstMapAsExpressionStatement_begin() { | 4277 void test_nonConstMapAsExpressionStatement_begin() { |
4183 Source source = addSource(r''' | 4278 Source source = addSource(r''' |
4184 f() { | 4279 f() { |
4185 {'a' : 0, 'b' : 1}.length; | 4280 {'a' : 0, 'b' : 1}.length; |
4186 }'''); | 4281 }'''); |
4187 resolve(source); | 4282 computeLibrarySourceErrors(source); |
4188 assertErrors( | 4283 assertErrors( |
4189 source, [CompileTimeErrorCode.NON_CONST_MAP_AS_EXPRESSION_STATEMENT]); | 4284 source, [CompileTimeErrorCode.NON_CONST_MAP_AS_EXPRESSION_STATEMENT]); |
4190 verify([source]); | 4285 verify([source]); |
4191 } | 4286 } |
4192 | 4287 |
4193 void test_nonConstMapAsExpressionStatement_only() { | 4288 void test_nonConstMapAsExpressionStatement_only() { |
4194 Source source = addSource(r''' | 4289 Source source = addSource(r''' |
4195 f() { | 4290 f() { |
4196 {'a' : 0, 'b' : 1}; | 4291 {'a' : 0, 'b' : 1}; |
4197 }'''); | 4292 }'''); |
4198 resolve(source); | 4293 computeLibrarySourceErrors(source); |
4199 assertErrors( | 4294 assertErrors( |
4200 source, [CompileTimeErrorCode.NON_CONST_MAP_AS_EXPRESSION_STATEMENT]); | 4295 source, [CompileTimeErrorCode.NON_CONST_MAP_AS_EXPRESSION_STATEMENT]); |
4201 verify([source]); | 4296 verify([source]); |
4202 } | 4297 } |
4203 | 4298 |
4204 void test_nonConstMapKey() { | 4299 void test_nonConstMapKey() { |
4205 Source source = addSource(r''' | 4300 Source source = addSource(r''' |
4206 f(a) { | 4301 f(a) { |
4207 return const {a : 0}; | 4302 return const {a : 0}; |
4208 }'''); | 4303 }'''); |
4209 resolve(source); | 4304 computeLibrarySourceErrors(source); |
4210 assertErrors(source, [CompileTimeErrorCode.NON_CONSTANT_MAP_KEY]); | 4305 assertErrors(source, [CompileTimeErrorCode.NON_CONSTANT_MAP_KEY]); |
4211 verify([source]); | 4306 verify([source]); |
4212 } | 4307 } |
4213 | 4308 |
4214 void test_nonConstMapKeyFromDeferredLibrary() { | 4309 void test_nonConstMapKeyFromDeferredLibrary() { |
4215 resolveWithErrors(<String>[ | 4310 resolveWithErrors(<String>[ |
4216 r''' | 4311 r''' |
4217 library lib1; | 4312 library lib1; |
4218 const int c = 1;''', | 4313 const int c = 1;''', |
4219 r''' | 4314 r''' |
(...skipping 21 matching lines...) Expand all Loading... |
4241 ], <ErrorCode>[ | 4336 ], <ErrorCode>[ |
4242 CompileTimeErrorCode.NON_CONSTANT_MAP_KEY_FROM_DEFERRED_LIBRARY | 4337 CompileTimeErrorCode.NON_CONSTANT_MAP_KEY_FROM_DEFERRED_LIBRARY |
4243 ]); | 4338 ]); |
4244 } | 4339 } |
4245 | 4340 |
4246 void test_nonConstMapValue() { | 4341 void test_nonConstMapValue() { |
4247 Source source = addSource(r''' | 4342 Source source = addSource(r''' |
4248 f(a) { | 4343 f(a) { |
4249 return const {'a' : a}; | 4344 return const {'a' : a}; |
4250 }'''); | 4345 }'''); |
4251 resolve(source); | 4346 computeLibrarySourceErrors(source); |
4252 assertErrors(source, [CompileTimeErrorCode.NON_CONSTANT_MAP_VALUE]); | 4347 assertErrors(source, [CompileTimeErrorCode.NON_CONSTANT_MAP_VALUE]); |
4253 verify([source]); | 4348 verify([source]); |
4254 } | 4349 } |
4255 | 4350 |
4256 void test_nonConstMapValueFromDeferredLibrary() { | 4351 void test_nonConstMapValueFromDeferredLibrary() { |
4257 resolveWithErrors(<String>[ | 4352 resolveWithErrors(<String>[ |
4258 r''' | 4353 r''' |
4259 library lib1; | 4354 library lib1; |
4260 const int c = 1;''', | 4355 const int c = 1;''', |
4261 r''' | 4356 r''' |
(...skipping 22 matching lines...) Expand all Loading... |
4284 CompileTimeErrorCode.NON_CONSTANT_MAP_VALUE_FROM_DEFERRED_LIBRARY | 4379 CompileTimeErrorCode.NON_CONSTANT_MAP_VALUE_FROM_DEFERRED_LIBRARY |
4285 ]); | 4380 ]); |
4286 } | 4381 } |
4287 | 4382 |
4288 void test_nonConstValueInInitializer_binary_notBool_left() { | 4383 void test_nonConstValueInInitializer_binary_notBool_left() { |
4289 Source source = addSource(r''' | 4384 Source source = addSource(r''' |
4290 class A { | 4385 class A { |
4291 final bool a; | 4386 final bool a; |
4292 const A(String p) : a = p && true; | 4387 const A(String p) : a = p && true; |
4293 }'''); | 4388 }'''); |
4294 resolve(source); | 4389 computeLibrarySourceErrors(source); |
4295 assertErrors(source, [ | 4390 assertErrors(source, [ |
4296 CompileTimeErrorCode.CONST_EVAL_TYPE_BOOL, | 4391 CompileTimeErrorCode.CONST_EVAL_TYPE_BOOL, |
4297 StaticTypeWarningCode.NON_BOOL_OPERAND | 4392 StaticTypeWarningCode.NON_BOOL_OPERAND |
4298 ]); | 4393 ]); |
4299 verify([source]); | 4394 verify([source]); |
4300 } | 4395 } |
4301 | 4396 |
4302 void test_nonConstValueInInitializer_binary_notBool_right() { | 4397 void test_nonConstValueInInitializer_binary_notBool_right() { |
4303 Source source = addSource(r''' | 4398 Source source = addSource(r''' |
4304 class A { | 4399 class A { |
4305 final bool a; | 4400 final bool a; |
4306 const A(String p) : a = true && p; | 4401 const A(String p) : a = true && p; |
4307 }'''); | 4402 }'''); |
4308 resolve(source); | 4403 computeLibrarySourceErrors(source); |
4309 assertErrors(source, [ | 4404 assertErrors(source, [ |
4310 CompileTimeErrorCode.CONST_EVAL_TYPE_BOOL, | 4405 CompileTimeErrorCode.CONST_EVAL_TYPE_BOOL, |
4311 StaticTypeWarningCode.NON_BOOL_OPERAND | 4406 StaticTypeWarningCode.NON_BOOL_OPERAND |
4312 ]); | 4407 ]); |
4313 verify([source]); | 4408 verify([source]); |
4314 } | 4409 } |
4315 | 4410 |
4316 void test_nonConstValueInInitializer_binary_notInt() { | 4411 void test_nonConstValueInInitializer_binary_notInt() { |
4317 Source source = addSource(r''' | 4412 Source source = addSource(r''' |
4318 class A { | 4413 class A { |
4319 final int a; | 4414 final int a; |
4320 const A(String p) : a = 5 & p; | 4415 const A(String p) : a = 5 & p; |
4321 }'''); | 4416 }'''); |
4322 resolve(source); | 4417 computeLibrarySourceErrors(source); |
4323 assertErrors(source, [ | 4418 assertErrors(source, [ |
4324 CompileTimeErrorCode.CONST_EVAL_TYPE_INT, | 4419 CompileTimeErrorCode.CONST_EVAL_TYPE_INT, |
4325 StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE | 4420 StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE |
4326 ]); | 4421 ]); |
4327 verify([source]); | 4422 verify([source]); |
4328 } | 4423 } |
4329 | 4424 |
4330 void test_nonConstValueInInitializer_binary_notNum() { | 4425 void test_nonConstValueInInitializer_binary_notNum() { |
4331 Source source = addSource(r''' | 4426 Source source = addSource(r''' |
4332 class A { | 4427 class A { |
4333 final int a; | 4428 final int a; |
4334 const A(String p) : a = 5 + p; | 4429 const A(String p) : a = 5 + p; |
4335 }'''); | 4430 }'''); |
4336 resolve(source); | 4431 computeLibrarySourceErrors(source); |
4337 assertErrors(source, [ | 4432 assertErrors(source, [ |
4338 CompileTimeErrorCode.CONST_EVAL_TYPE_NUM, | 4433 CompileTimeErrorCode.CONST_EVAL_TYPE_NUM, |
4339 StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE | 4434 StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE |
4340 ]); | 4435 ]); |
4341 verify([source]); | 4436 verify([source]); |
4342 } | 4437 } |
4343 | 4438 |
4344 void test_nonConstValueInInitializer_field() { | 4439 void test_nonConstValueInInitializer_field() { |
4345 Source source = addSource(r''' | 4440 Source source = addSource(r''' |
4346 class A { | 4441 class A { |
4347 static int C; | 4442 static int C; |
4348 final int a; | 4443 final int a; |
4349 const A() : a = C; | 4444 const A() : a = C; |
4350 }'''); | 4445 }'''); |
4351 resolve(source); | 4446 computeLibrarySourceErrors(source); |
4352 assertErrors( | 4447 assertErrors( |
4353 source, [CompileTimeErrorCode.NON_CONSTANT_VALUE_IN_INITIALIZER]); | 4448 source, [CompileTimeErrorCode.NON_CONSTANT_VALUE_IN_INITIALIZER]); |
4354 verify([source]); | 4449 verify([source]); |
4355 } | 4450 } |
4356 | 4451 |
4357 void test_nonConstValueInInitializer_instanceCreation() { | 4452 void test_nonConstValueInInitializer_instanceCreation() { |
4358 Source source = addSource(r''' | 4453 Source source = addSource(r''' |
4359 class A { | 4454 class A { |
4360 A(); | 4455 A(); |
4361 } | 4456 } |
4362 class B { | 4457 class B { |
4363 const B() : a = new A(); | 4458 const B() : a = new A(); |
4364 final a; | 4459 final a; |
4365 } | 4460 } |
4366 var b = const B();'''); | 4461 var b = const B();'''); |
4367 resolve(source); | 4462 computeLibrarySourceErrors(source); |
4368 // TODO(paulberry): the error INVALID_CONSTAT is redundant and ought to be | 4463 // TODO(paulberry): the error INVALID_CONSTAT is redundant and ought to be |
4369 // suppressed. | 4464 // suppressed. |
4370 assertErrors(source, [ | 4465 assertErrors(source, [ |
4371 CompileTimeErrorCode.NON_CONSTANT_VALUE_IN_INITIALIZER, | 4466 CompileTimeErrorCode.NON_CONSTANT_VALUE_IN_INITIALIZER, |
4372 CompileTimeErrorCode.INVALID_CONSTANT | 4467 CompileTimeErrorCode.INVALID_CONSTANT |
4373 ]); | 4468 ]); |
4374 verify([source]); | 4469 verify([source]); |
4375 } | 4470 } |
4376 | 4471 |
4377 void test_nonConstValueInInitializer_redirecting() { | 4472 void test_nonConstValueInInitializer_redirecting() { |
4378 Source source = addSource(r''' | 4473 Source source = addSource(r''' |
4379 class A { | 4474 class A { |
4380 static var C; | 4475 static var C; |
4381 const A.named(p); | 4476 const A.named(p); |
4382 const A() : this.named(C); | 4477 const A() : this.named(C); |
4383 }'''); | 4478 }'''); |
4384 resolve(source); | 4479 computeLibrarySourceErrors(source); |
4385 assertErrors( | 4480 assertErrors( |
4386 source, [CompileTimeErrorCode.NON_CONSTANT_VALUE_IN_INITIALIZER]); | 4481 source, [CompileTimeErrorCode.NON_CONSTANT_VALUE_IN_INITIALIZER]); |
4387 verify([source]); | 4482 verify([source]); |
4388 } | 4483 } |
4389 | 4484 |
4390 void test_nonConstValueInInitializer_super() { | 4485 void test_nonConstValueInInitializer_super() { |
4391 Source source = addSource(r''' | 4486 Source source = addSource(r''' |
4392 class A { | 4487 class A { |
4393 const A(p); | 4488 const A(p); |
4394 } | 4489 } |
4395 class B extends A { | 4490 class B extends A { |
4396 static var C; | 4491 static var C; |
4397 const B() : super(C); | 4492 const B() : super(C); |
4398 }'''); | 4493 }'''); |
4399 resolve(source); | 4494 computeLibrarySourceErrors(source); |
4400 assertErrors( | 4495 assertErrors( |
4401 source, [CompileTimeErrorCode.NON_CONSTANT_VALUE_IN_INITIALIZER]); | 4496 source, [CompileTimeErrorCode.NON_CONSTANT_VALUE_IN_INITIALIZER]); |
4402 verify([source]); | 4497 verify([source]); |
4403 } | 4498 } |
4404 | 4499 |
4405 void test_nonConstValueInInitializerFromDeferredLibrary_field() { | 4500 void test_nonConstValueInInitializerFromDeferredLibrary_field() { |
4406 resolveWithErrors(<String>[ | 4501 resolveWithErrors(<String>[ |
4407 r''' | 4502 r''' |
4408 library lib1; | 4503 library lib1; |
4409 const int c = 1;''', | 4504 const int c = 1;''', |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4473 } | 4568 } |
4474 | 4569 |
4475 void test_nonGenerativeConstructor_explicit() { | 4570 void test_nonGenerativeConstructor_explicit() { |
4476 Source source = addSource(r''' | 4571 Source source = addSource(r''' |
4477 class A { | 4572 class A { |
4478 factory A.named() {} | 4573 factory A.named() {} |
4479 } | 4574 } |
4480 class B extends A { | 4575 class B extends A { |
4481 B() : super.named(); | 4576 B() : super.named(); |
4482 }'''); | 4577 }'''); |
4483 resolve(source); | 4578 computeLibrarySourceErrors(source); |
4484 assertErrors(source, [CompileTimeErrorCode.NON_GENERATIVE_CONSTRUCTOR]); | 4579 assertErrors(source, [CompileTimeErrorCode.NON_GENERATIVE_CONSTRUCTOR]); |
4485 verify([source]); | 4580 verify([source]); |
4486 } | 4581 } |
4487 | 4582 |
4488 void test_nonGenerativeConstructor_implicit() { | 4583 void test_nonGenerativeConstructor_implicit() { |
4489 Source source = addSource(r''' | 4584 Source source = addSource(r''' |
4490 class A { | 4585 class A { |
4491 factory A() {} | 4586 factory A() {} |
4492 } | 4587 } |
4493 class B extends A { | 4588 class B extends A { |
4494 B(); | 4589 B(); |
4495 }'''); | 4590 }'''); |
4496 resolve(source); | 4591 computeLibrarySourceErrors(source); |
4497 assertErrors(source, [CompileTimeErrorCode.NON_GENERATIVE_CONSTRUCTOR]); | 4592 assertErrors(source, [CompileTimeErrorCode.NON_GENERATIVE_CONSTRUCTOR]); |
4498 verify([source]); | 4593 verify([source]); |
4499 } | 4594 } |
4500 | 4595 |
4501 void test_nonGenerativeConstructor_implicit2() { | 4596 void test_nonGenerativeConstructor_implicit2() { |
4502 Source source = addSource(r''' | 4597 Source source = addSource(r''' |
4503 class A { | 4598 class A { |
4504 factory A() {} | 4599 factory A() {} |
4505 } | 4600 } |
4506 class B extends A { | 4601 class B extends A { |
4507 }'''); | 4602 }'''); |
4508 resolve(source); | 4603 computeLibrarySourceErrors(source); |
4509 assertErrors(source, [CompileTimeErrorCode.NON_GENERATIVE_CONSTRUCTOR]); | 4604 assertErrors(source, [CompileTimeErrorCode.NON_GENERATIVE_CONSTRUCTOR]); |
4510 verify([source]); | 4605 verify([source]); |
4511 } | 4606 } |
4512 | 4607 |
4513 void test_notEnoughRequiredArguments_const() { | 4608 void test_notEnoughRequiredArguments_const() { |
4514 Source source = addSource(r''' | 4609 Source source = addSource(r''' |
4515 class A { | 4610 class A { |
4516 const A(int p); | 4611 const A(int p); |
4517 } | 4612 } |
4518 main() { | 4613 main() { |
4519 const A(); | 4614 const A(); |
4520 }'''); | 4615 }'''); |
4521 resolve(source); | 4616 computeLibrarySourceErrors(source); |
4522 assertErrors(source, [CompileTimeErrorCode.NOT_ENOUGH_REQUIRED_ARGUMENTS]); | 4617 assertErrors(source, [CompileTimeErrorCode.NOT_ENOUGH_REQUIRED_ARGUMENTS]); |
4523 verify([source]); | 4618 verify([source]); |
4524 } | 4619 } |
4525 | 4620 |
4526 void test_notEnoughRequiredArguments_const_super() { | 4621 void test_notEnoughRequiredArguments_const_super() { |
4527 Source source = addSource(r''' | 4622 Source source = addSource(r''' |
4528 class A { | 4623 class A { |
4529 const A(int p); | 4624 const A(int p); |
4530 } | 4625 } |
4531 class B extends A { | 4626 class B extends A { |
4532 const B() : super(); | 4627 const B() : super(); |
4533 }'''); | 4628 }'''); |
4534 resolve(source); | 4629 computeLibrarySourceErrors(source); |
4535 assertErrors(source, [CompileTimeErrorCode.NOT_ENOUGH_REQUIRED_ARGUMENTS]); | 4630 assertErrors(source, [CompileTimeErrorCode.NOT_ENOUGH_REQUIRED_ARGUMENTS]); |
4536 verify([source]); | 4631 verify([source]); |
4537 } | 4632 } |
4538 | 4633 |
4539 void test_optionalParameterInOperator_named() { | 4634 void test_optionalParameterInOperator_named() { |
4540 Source source = addSource(r''' | 4635 Source source = addSource(r''' |
4541 class A { | 4636 class A { |
4542 operator +({p}) {} | 4637 operator +({p}) {} |
4543 }'''); | 4638 }'''); |
4544 resolve(source); | 4639 computeLibrarySourceErrors(source); |
4545 assertErrors(source, [CompileTimeErrorCode.OPTIONAL_PARAMETER_IN_OPERATOR]); | 4640 assertErrors(source, [CompileTimeErrorCode.OPTIONAL_PARAMETER_IN_OPERATOR]); |
4546 verify([source]); | 4641 verify([source]); |
4547 } | 4642 } |
4548 | 4643 |
4549 void test_optionalParameterInOperator_positional() { | 4644 void test_optionalParameterInOperator_positional() { |
4550 Source source = addSource(r''' | 4645 Source source = addSource(r''' |
4551 class A { | 4646 class A { |
4552 operator +([p]) {} | 4647 operator +([p]) {} |
4553 }'''); | 4648 }'''); |
4554 resolve(source); | 4649 computeLibrarySourceErrors(source); |
4555 assertErrors(source, [CompileTimeErrorCode.OPTIONAL_PARAMETER_IN_OPERATOR]); | 4650 assertErrors(source, [CompileTimeErrorCode.OPTIONAL_PARAMETER_IN_OPERATOR]); |
4556 verify([source]); | 4651 verify([source]); |
4557 } | 4652 } |
4558 | 4653 |
4559 void test_partOfNonPart() { | 4654 void test_partOfNonPart() { |
4560 Source source = addSource(r''' | 4655 Source source = addSource(r''' |
4561 library l1; | 4656 library l1; |
4562 part 'l2.dart';'''); | 4657 part 'l2.dart';'''); |
4563 addNamedSource("/l2.dart", "library l2;"); | 4658 addNamedSource("/l2.dart", "library l2;"); |
4564 resolve(source); | 4659 computeLibrarySourceErrors(source); |
4565 assertErrors(source, [CompileTimeErrorCode.PART_OF_NON_PART]); | 4660 assertErrors(source, [CompileTimeErrorCode.PART_OF_NON_PART]); |
4566 verify([source]); | 4661 verify([source]); |
4567 } | 4662 } |
4568 | 4663 |
4569 void test_prefixCollidesWithTopLevelMembers_functionTypeAlias() { | 4664 void test_prefixCollidesWithTopLevelMembers_functionTypeAlias() { |
4570 addNamedSource("/lib.dart", r''' | 4665 addNamedSource("/lib.dart", r''' |
4571 library lib; | 4666 library lib; |
4572 class A{}'''); | 4667 class A{}'''); |
4573 Source source = addSource(r''' | 4668 Source source = addSource(r''' |
4574 import 'lib.dart' as p; | 4669 import 'lib.dart' as p; |
4575 typedef p(); | 4670 typedef p(); |
4576 p.A a;'''); | 4671 p.A a;'''); |
4577 resolve(source); | 4672 computeLibrarySourceErrors(source); |
4578 assertErrors( | 4673 assertErrors( |
4579 source, [CompileTimeErrorCode.PREFIX_COLLIDES_WITH_TOP_LEVEL_MEMBER]); | 4674 source, [CompileTimeErrorCode.PREFIX_COLLIDES_WITH_TOP_LEVEL_MEMBER]); |
4580 verify([source]); | 4675 verify([source]); |
4581 } | 4676 } |
4582 | 4677 |
4583 void test_prefixCollidesWithTopLevelMembers_topLevelFunction() { | 4678 void test_prefixCollidesWithTopLevelMembers_topLevelFunction() { |
4584 addNamedSource("/lib.dart", r''' | 4679 addNamedSource("/lib.dart", r''' |
4585 library lib; | 4680 library lib; |
4586 class A{}'''); | 4681 class A{}'''); |
4587 Source source = addSource(r''' | 4682 Source source = addSource(r''' |
4588 import 'lib.dart' as p; | 4683 import 'lib.dart' as p; |
4589 p() {} | 4684 p() {} |
4590 p.A a;'''); | 4685 p.A a;'''); |
4591 resolve(source); | 4686 computeLibrarySourceErrors(source); |
4592 assertErrors( | 4687 assertErrors( |
4593 source, [CompileTimeErrorCode.PREFIX_COLLIDES_WITH_TOP_LEVEL_MEMBER]); | 4688 source, [CompileTimeErrorCode.PREFIX_COLLIDES_WITH_TOP_LEVEL_MEMBER]); |
4594 verify([source]); | 4689 verify([source]); |
4595 } | 4690 } |
4596 | 4691 |
4597 void test_prefixCollidesWithTopLevelMembers_topLevelVariable() { | 4692 void test_prefixCollidesWithTopLevelMembers_topLevelVariable() { |
4598 addNamedSource("/lib.dart", r''' | 4693 addNamedSource("/lib.dart", r''' |
4599 library lib; | 4694 library lib; |
4600 class A{}'''); | 4695 class A{}'''); |
4601 Source source = addSource(r''' | 4696 Source source = addSource(r''' |
4602 import 'lib.dart' as p; | 4697 import 'lib.dart' as p; |
4603 var p = null; | 4698 var p = null; |
4604 p.A a;'''); | 4699 p.A a;'''); |
4605 resolve(source); | 4700 computeLibrarySourceErrors(source); |
4606 assertErrors( | 4701 assertErrors( |
4607 source, [CompileTimeErrorCode.PREFIX_COLLIDES_WITH_TOP_LEVEL_MEMBER]); | 4702 source, [CompileTimeErrorCode.PREFIX_COLLIDES_WITH_TOP_LEVEL_MEMBER]); |
4608 verify([source]); | 4703 verify([source]); |
4609 } | 4704 } |
4610 | 4705 |
4611 void test_prefixCollidesWithTopLevelMembers_type() { | 4706 void test_prefixCollidesWithTopLevelMembers_type() { |
4612 addNamedSource("/lib.dart", r''' | 4707 addNamedSource("/lib.dart", r''' |
4613 library lib; | 4708 library lib; |
4614 class A{}'''); | 4709 class A{}'''); |
4615 Source source = addSource(r''' | 4710 Source source = addSource(r''' |
4616 import 'lib.dart' as p; | 4711 import 'lib.dart' as p; |
4617 class p {} | 4712 class p {} |
4618 p.A a;'''); | 4713 p.A a;'''); |
4619 resolve(source); | 4714 computeLibrarySourceErrors(source); |
4620 assertErrors( | 4715 assertErrors( |
4621 source, [CompileTimeErrorCode.PREFIX_COLLIDES_WITH_TOP_LEVEL_MEMBER]); | 4716 source, [CompileTimeErrorCode.PREFIX_COLLIDES_WITH_TOP_LEVEL_MEMBER]); |
4622 verify([source]); | 4717 verify([source]); |
4623 } | 4718 } |
4624 | 4719 |
4625 void test_privateOptionalParameter() { | 4720 void test_privateOptionalParameter() { |
4626 Source source = addSource("f({var _p}) {}"); | 4721 Source source = addSource("f({var _p}) {}"); |
4627 resolve(source); | 4722 computeLibrarySourceErrors(source); |
4628 assertErrors(source, [CompileTimeErrorCode.PRIVATE_OPTIONAL_PARAMETER]); | 4723 assertErrors(source, [CompileTimeErrorCode.PRIVATE_OPTIONAL_PARAMETER]); |
4629 verify([source]); | 4724 verify([source]); |
4630 } | 4725 } |
4631 | 4726 |
4632 void test_privateOptionalParameter_fieldFormal() { | 4727 void test_privateOptionalParameter_fieldFormal() { |
4633 Source source = addSource(r''' | 4728 Source source = addSource(r''' |
4634 class A { | 4729 class A { |
4635 var _p; | 4730 var _p; |
4636 A({this._p: 0}); | 4731 A({this._p: 0}); |
4637 }'''); | 4732 }'''); |
4638 resolve(source); | 4733 computeLibrarySourceErrors(source); |
4639 assertErrors(source, [CompileTimeErrorCode.PRIVATE_OPTIONAL_PARAMETER]); | 4734 assertErrors(source, [CompileTimeErrorCode.PRIVATE_OPTIONAL_PARAMETER]); |
4640 verify([source]); | 4735 verify([source]); |
4641 } | 4736 } |
4642 | 4737 |
4643 void test_privateOptionalParameter_withDefaultValue() { | 4738 void test_privateOptionalParameter_withDefaultValue() { |
4644 Source source = addSource("f({_p : 0}) {}"); | 4739 Source source = addSource("f({_p : 0}) {}"); |
4645 resolve(source); | 4740 computeLibrarySourceErrors(source); |
4646 assertErrors(source, [CompileTimeErrorCode.PRIVATE_OPTIONAL_PARAMETER]); | 4741 assertErrors(source, [CompileTimeErrorCode.PRIVATE_OPTIONAL_PARAMETER]); |
4647 verify([source]); | 4742 verify([source]); |
4648 } | 4743 } |
4649 | 4744 |
4650 void test_recursiveCompileTimeConstant() { | 4745 void test_recursiveCompileTimeConstant() { |
4651 Source source = addSource(r''' | 4746 Source source = addSource(r''' |
4652 class A { | 4747 class A { |
4653 const A(); | 4748 const A(); |
4654 final m = const A(); | 4749 final m = const A(); |
4655 }'''); | 4750 }'''); |
4656 resolve(source); | 4751 computeLibrarySourceErrors(source); |
4657 assertErrors( | 4752 assertErrors( |
4658 source, [CompileTimeErrorCode.RECURSIVE_COMPILE_TIME_CONSTANT]); | 4753 source, [CompileTimeErrorCode.RECURSIVE_COMPILE_TIME_CONSTANT]); |
4659 verify([source]); | 4754 verify([source]); |
4660 } | 4755 } |
4661 | 4756 |
4662 void test_recursiveCompileTimeConstant_cycle() { | 4757 void test_recursiveCompileTimeConstant_cycle() { |
4663 Source source = addSource(r''' | 4758 Source source = addSource(r''' |
4664 const x = y + 1; | 4759 const x = y + 1; |
4665 const y = x + 1;'''); | 4760 const y = x + 1;'''); |
4666 resolve(source); | 4761 computeLibrarySourceErrors(source); |
4667 assertErrors(source, [ | 4762 assertErrors(source, [ |
4668 CompileTimeErrorCode.RECURSIVE_COMPILE_TIME_CONSTANT, | 4763 CompileTimeErrorCode.RECURSIVE_COMPILE_TIME_CONSTANT, |
4669 CompileTimeErrorCode.RECURSIVE_COMPILE_TIME_CONSTANT | 4764 CompileTimeErrorCode.RECURSIVE_COMPILE_TIME_CONSTANT |
4670 ]); | 4765 ]); |
4671 verify([source]); | 4766 verify([source]); |
4672 } | 4767 } |
4673 | 4768 |
4674 void test_recursiveCompileTimeConstant_initializer_after_toplevel_var() { | 4769 void test_recursiveCompileTimeConstant_initializer_after_toplevel_var() { |
4675 Source source = addSource(''' | 4770 Source source = addSource(''' |
4676 const y = const C(); | 4771 const y = const C(); |
4677 class C { | 4772 class C { |
4678 const C() : x = y; | 4773 const C() : x = y; |
4679 final x; | 4774 final x; |
4680 } | 4775 } |
4681 '''); | 4776 '''); |
4682 resolve(source); | 4777 computeLibrarySourceErrors(source); |
4683 assertErrors( | 4778 assertErrors( |
4684 source, [CompileTimeErrorCode.RECURSIVE_COMPILE_TIME_CONSTANT]); | 4779 source, [CompileTimeErrorCode.RECURSIVE_COMPILE_TIME_CONSTANT]); |
4685 verify([source]); | 4780 verify([source]); |
4686 } | 4781 } |
4687 | 4782 |
4688 void test_recursiveCompileTimeConstant_singleVariable() { | 4783 void test_recursiveCompileTimeConstant_singleVariable() { |
4689 Source source = addSource(r''' | 4784 Source source = addSource(r''' |
4690 const x = x; | 4785 const x = x; |
4691 '''); | 4786 '''); |
4692 resolve(source); | 4787 computeLibrarySourceErrors(source); |
4693 assertErrors( | 4788 assertErrors( |
4694 source, [CompileTimeErrorCode.RECURSIVE_COMPILE_TIME_CONSTANT]); | 4789 source, [CompileTimeErrorCode.RECURSIVE_COMPILE_TIME_CONSTANT]); |
4695 verify([source]); | 4790 verify([source]); |
4696 } | 4791 } |
4697 | 4792 |
4698 void test_recursiveConstructorRedirect() { | 4793 void test_recursiveConstructorRedirect() { |
4699 Source source = addSource(r''' | 4794 Source source = addSource(r''' |
4700 class A { | 4795 class A { |
4701 A.a() : this.b(); | 4796 A.a() : this.b(); |
4702 A.b() : this.a(); | 4797 A.b() : this.a(); |
4703 }'''); | 4798 }'''); |
4704 resolve(source); | 4799 computeLibrarySourceErrors(source); |
4705 assertErrors(source, [ | 4800 assertErrors(source, [ |
4706 CompileTimeErrorCode.RECURSIVE_CONSTRUCTOR_REDIRECT, | 4801 CompileTimeErrorCode.RECURSIVE_CONSTRUCTOR_REDIRECT, |
4707 CompileTimeErrorCode.RECURSIVE_CONSTRUCTOR_REDIRECT | 4802 CompileTimeErrorCode.RECURSIVE_CONSTRUCTOR_REDIRECT |
4708 ]); | 4803 ]); |
4709 verify([source]); | 4804 verify([source]); |
4710 } | 4805 } |
4711 | 4806 |
4712 void test_recursiveConstructorRedirect_directSelfReference() { | 4807 void test_recursiveConstructorRedirect_directSelfReference() { |
4713 Source source = addSource(r''' | 4808 Source source = addSource(r''' |
4714 class A { | 4809 class A { |
4715 A() : this(); | 4810 A() : this(); |
4716 }'''); | 4811 }'''); |
4717 resolve(source); | 4812 computeLibrarySourceErrors(source); |
4718 assertErrors(source, [CompileTimeErrorCode.RECURSIVE_CONSTRUCTOR_REDIRECT]); | 4813 assertErrors(source, [CompileTimeErrorCode.RECURSIVE_CONSTRUCTOR_REDIRECT]); |
4719 verify([source]); | 4814 verify([source]); |
4720 } | 4815 } |
4721 | 4816 |
4722 void test_recursiveFactoryRedirect() { | 4817 void test_recursiveFactoryRedirect() { |
4723 Source source = addSource(r''' | 4818 Source source = addSource(r''' |
4724 class A implements B { | 4819 class A implements B { |
4725 factory A() = C; | 4820 factory A() = C; |
4726 } | 4821 } |
4727 class B implements C { | 4822 class B implements C { |
4728 factory B() = A; | 4823 factory B() = A; |
4729 } | 4824 } |
4730 class C implements A { | 4825 class C implements A { |
4731 factory C() = B; | 4826 factory C() = B; |
4732 }'''); | 4827 }'''); |
4733 resolve(source); | 4828 computeLibrarySourceErrors(source); |
4734 assertErrors(source, [ | 4829 assertErrors(source, [ |
4735 CompileTimeErrorCode.RECURSIVE_FACTORY_REDIRECT, | 4830 CompileTimeErrorCode.RECURSIVE_FACTORY_REDIRECT, |
4736 CompileTimeErrorCode.RECURSIVE_FACTORY_REDIRECT, | 4831 CompileTimeErrorCode.RECURSIVE_FACTORY_REDIRECT, |
4737 CompileTimeErrorCode.RECURSIVE_FACTORY_REDIRECT, | 4832 CompileTimeErrorCode.RECURSIVE_FACTORY_REDIRECT, |
4738 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE, | 4833 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE, |
4739 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE, | 4834 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE, |
4740 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE | 4835 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE |
4741 ]); | 4836 ]); |
4742 verify([source]); | 4837 verify([source]); |
4743 } | 4838 } |
4744 | 4839 |
4745 void test_recursiveFactoryRedirect_directSelfReference() { | 4840 void test_recursiveFactoryRedirect_directSelfReference() { |
4746 Source source = addSource(r''' | 4841 Source source = addSource(r''' |
4747 class A { | 4842 class A { |
4748 factory A() = A; | 4843 factory A() = A; |
4749 }'''); | 4844 }'''); |
4750 resolve(source); | 4845 computeLibrarySourceErrors(source); |
4751 assertErrors(source, [CompileTimeErrorCode.RECURSIVE_FACTORY_REDIRECT]); | 4846 assertErrors(source, [CompileTimeErrorCode.RECURSIVE_FACTORY_REDIRECT]); |
4752 verify([source]); | 4847 verify([source]); |
4753 } | 4848 } |
4754 | 4849 |
4755 void test_recursiveFactoryRedirect_diverging() { | 4850 void test_recursiveFactoryRedirect_diverging() { |
4756 // Analysis should terminate even though the redirections don't reach a | 4851 // Analysis should terminate even though the redirections don't reach a |
4757 // fixed point. (C<int> redirects to C<C<int>>, then to C<C<C<int>>>, and | 4852 // fixed point. (C<int> redirects to C<C<int>>, then to C<C<C<int>>>, and |
4758 // so on). | 4853 // so on). |
4759 Source source = addSource(''' | 4854 Source source = addSource(''' |
4760 class C<T> { | 4855 class C<T> { |
4761 const factory C() = C<C<T>>; | 4856 const factory C() = C<C<T>>; |
4762 } | 4857 } |
4763 main() { | 4858 main() { |
4764 const C<int>(); | 4859 const C<int>(); |
4765 } | 4860 } |
4766 '''); | 4861 '''); |
4767 resolve(source); | 4862 computeLibrarySourceErrors(source); |
4768 assertErrors(source, [CompileTimeErrorCode.RECURSIVE_FACTORY_REDIRECT]); | 4863 assertErrors(source, [CompileTimeErrorCode.RECURSIVE_FACTORY_REDIRECT]); |
4769 verify([source]); | 4864 verify([source]); |
4770 } | 4865 } |
4771 | 4866 |
4772 void test_recursiveFactoryRedirect_generic() { | 4867 void test_recursiveFactoryRedirect_generic() { |
4773 Source source = addSource(r''' | 4868 Source source = addSource(r''' |
4774 class A<T> implements B<T> { | 4869 class A<T> implements B<T> { |
4775 factory A() = C; | 4870 factory A() = C; |
4776 } | 4871 } |
4777 class B<T> implements C<T> { | 4872 class B<T> implements C<T> { |
4778 factory B() = A; | 4873 factory B() = A; |
4779 } | 4874 } |
4780 class C<T> implements A<T> { | 4875 class C<T> implements A<T> { |
4781 factory C() = B; | 4876 factory C() = B; |
4782 }'''); | 4877 }'''); |
4783 resolve(source); | 4878 computeLibrarySourceErrors(source); |
4784 assertErrors(source, [ | 4879 assertErrors(source, [ |
4785 CompileTimeErrorCode.RECURSIVE_FACTORY_REDIRECT, | 4880 CompileTimeErrorCode.RECURSIVE_FACTORY_REDIRECT, |
4786 CompileTimeErrorCode.RECURSIVE_FACTORY_REDIRECT, | 4881 CompileTimeErrorCode.RECURSIVE_FACTORY_REDIRECT, |
4787 CompileTimeErrorCode.RECURSIVE_FACTORY_REDIRECT, | 4882 CompileTimeErrorCode.RECURSIVE_FACTORY_REDIRECT, |
4788 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE, | 4883 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE, |
4789 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE, | 4884 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE, |
4790 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE | 4885 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE |
4791 ]); | 4886 ]); |
4792 verify([source]); | 4887 verify([source]); |
4793 } | 4888 } |
4794 | 4889 |
4795 void test_recursiveFactoryRedirect_named() { | 4890 void test_recursiveFactoryRedirect_named() { |
4796 Source source = addSource(r''' | 4891 Source source = addSource(r''' |
4797 class A implements B { | 4892 class A implements B { |
4798 factory A.nameA() = C.nameC; | 4893 factory A.nameA() = C.nameC; |
4799 } | 4894 } |
4800 class B implements C { | 4895 class B implements C { |
4801 factory B.nameB() = A.nameA; | 4896 factory B.nameB() = A.nameA; |
4802 } | 4897 } |
4803 class C implements A { | 4898 class C implements A { |
4804 factory C.nameC() = B.nameB; | 4899 factory C.nameC() = B.nameB; |
4805 }'''); | 4900 }'''); |
4806 resolve(source); | 4901 computeLibrarySourceErrors(source); |
4807 assertErrors(source, [ | 4902 assertErrors(source, [ |
4808 CompileTimeErrorCode.RECURSIVE_FACTORY_REDIRECT, | 4903 CompileTimeErrorCode.RECURSIVE_FACTORY_REDIRECT, |
4809 CompileTimeErrorCode.RECURSIVE_FACTORY_REDIRECT, | 4904 CompileTimeErrorCode.RECURSIVE_FACTORY_REDIRECT, |
4810 CompileTimeErrorCode.RECURSIVE_FACTORY_REDIRECT, | 4905 CompileTimeErrorCode.RECURSIVE_FACTORY_REDIRECT, |
4811 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE, | 4906 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE, |
4812 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE, | 4907 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE, |
4813 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE | 4908 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE |
4814 ]); | 4909 ]); |
4815 verify([source]); | 4910 verify([source]); |
4816 } | 4911 } |
4817 | 4912 |
4818 /** | 4913 /** |
4819 * "A" references "C" which has cycle with "B". But we should not report probl
em for "A" - it is | 4914 * "A" references "C" which has cycle with "B". But we should not report probl
em for "A" - it is |
4820 * not the part of a cycle. | 4915 * not the part of a cycle. |
4821 */ | 4916 */ |
4822 void test_recursiveFactoryRedirect_outsideCycle() { | 4917 void test_recursiveFactoryRedirect_outsideCycle() { |
4823 Source source = addSource(r''' | 4918 Source source = addSource(r''' |
4824 class A { | 4919 class A { |
4825 factory A() = C; | 4920 factory A() = C; |
4826 } | 4921 } |
4827 class B implements C { | 4922 class B implements C { |
4828 factory B() = C; | 4923 factory B() = C; |
4829 } | 4924 } |
4830 class C implements A, B { | 4925 class C implements A, B { |
4831 factory C() = B; | 4926 factory C() = B; |
4832 }'''); | 4927 }'''); |
4833 resolve(source); | 4928 computeLibrarySourceErrors(source); |
4834 assertErrors(source, [ | 4929 assertErrors(source, [ |
4835 CompileTimeErrorCode.RECURSIVE_FACTORY_REDIRECT, | 4930 CompileTimeErrorCode.RECURSIVE_FACTORY_REDIRECT, |
4836 CompileTimeErrorCode.RECURSIVE_FACTORY_REDIRECT, | 4931 CompileTimeErrorCode.RECURSIVE_FACTORY_REDIRECT, |
4837 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE, | 4932 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE, |
4838 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE | 4933 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE |
4839 ]); | 4934 ]); |
4840 verify([source]); | 4935 verify([source]); |
4841 } | 4936 } |
4842 | 4937 |
4843 void test_recursiveInterfaceInheritance_extends() { | 4938 void test_recursiveInterfaceInheritance_extends() { |
4844 Source source = addSource(r''' | 4939 Source source = addSource(r''' |
4845 class A extends B {} | 4940 class A extends B {} |
4846 class B extends A {}'''); | 4941 class B extends A {}'''); |
4847 resolve(source); | 4942 computeLibrarySourceErrors(source); |
4848 assertErrors(source, [ | 4943 assertErrors(source, [ |
4849 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE, | 4944 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE, |
4850 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE | 4945 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE |
4851 ]); | 4946 ]); |
4852 verify([source]); | 4947 verify([source]); |
4853 } | 4948 } |
4854 | 4949 |
4855 void test_recursiveInterfaceInheritance_extends_implements() { | 4950 void test_recursiveInterfaceInheritance_extends_implements() { |
4856 Source source = addSource(r''' | 4951 Source source = addSource(r''' |
4857 class A extends B {} | 4952 class A extends B {} |
4858 class B implements A {}'''); | 4953 class B implements A {}'''); |
4859 resolve(source); | 4954 computeLibrarySourceErrors(source); |
4860 assertErrors(source, [ | 4955 assertErrors(source, [ |
4861 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE, | 4956 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE, |
4862 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE | 4957 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE |
4863 ]); | 4958 ]); |
4864 verify([source]); | 4959 verify([source]); |
4865 } | 4960 } |
4866 | 4961 |
4867 void test_recursiveInterfaceInheritance_implements() { | 4962 void test_recursiveInterfaceInheritance_implements() { |
4868 Source source = addSource(r''' | 4963 Source source = addSource(r''' |
4869 class A implements B {} | 4964 class A implements B {} |
4870 class B implements A {}'''); | 4965 class B implements A {}'''); |
4871 resolve(source); | 4966 computeLibrarySourceErrors(source); |
4872 assertErrors(source, [ | 4967 assertErrors(source, [ |
4873 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE, | 4968 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE, |
4874 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE | 4969 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE |
4875 ]); | 4970 ]); |
4876 verify([source]); | 4971 verify([source]); |
4877 } | 4972 } |
4878 | 4973 |
4879 void test_recursiveInterfaceInheritance_mixin() { | 4974 void test_recursiveInterfaceInheritance_mixin() { |
4880 Source source = addSource(r''' | 4975 Source source = addSource(r''' |
4881 class M1 = Object with M2; | 4976 class M1 = Object with M2; |
4882 class M2 = Object with M1;'''); | 4977 class M2 = Object with M1;'''); |
4883 resolve(source); | 4978 computeLibrarySourceErrors(source); |
4884 assertErrors(source, [ | 4979 assertErrors(source, [ |
4885 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE, | 4980 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE, |
4886 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE | 4981 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE |
4887 ]); | 4982 ]); |
4888 verify([source]); | 4983 verify([source]); |
4889 } | 4984 } |
4890 | 4985 |
4891 void test_recursiveInterfaceInheritance_tail() { | 4986 void test_recursiveInterfaceInheritance_tail() { |
4892 Source source = addSource(r''' | 4987 Source source = addSource(r''' |
4893 abstract class A implements A {} | 4988 abstract class A implements A {} |
4894 class B implements A {}'''); | 4989 class B implements A {}'''); |
4895 resolve(source); | 4990 computeLibrarySourceErrors(source); |
4896 assertErrors(source, [ | 4991 assertErrors(source, [ |
4897 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE_BASE_CASE_IMPLEMENTS | 4992 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE_BASE_CASE_IMPLEMENTS |
4898 ]); | 4993 ]); |
4899 verify([source]); | 4994 verify([source]); |
4900 } | 4995 } |
4901 | 4996 |
4902 void test_recursiveInterfaceInheritance_tail2() { | 4997 void test_recursiveInterfaceInheritance_tail2() { |
4903 Source source = addSource(r''' | 4998 Source source = addSource(r''' |
4904 abstract class A implements B {} | 4999 abstract class A implements B {} |
4905 abstract class B implements A {} | 5000 abstract class B implements A {} |
4906 class C implements A {}'''); | 5001 class C implements A {}'''); |
4907 resolve(source); | 5002 computeLibrarySourceErrors(source); |
4908 assertErrors(source, [ | 5003 assertErrors(source, [ |
4909 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE, | 5004 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE, |
4910 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE | 5005 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE |
4911 ]); | 5006 ]); |
4912 verify([source]); | 5007 verify([source]); |
4913 } | 5008 } |
4914 | 5009 |
4915 void test_recursiveInterfaceInheritance_tail3() { | 5010 void test_recursiveInterfaceInheritance_tail3() { |
4916 Source source = addSource(r''' | 5011 Source source = addSource(r''' |
4917 abstract class A implements B {} | 5012 abstract class A implements B {} |
4918 abstract class B implements C {} | 5013 abstract class B implements C {} |
4919 abstract class C implements A {} | 5014 abstract class C implements A {} |
4920 class D implements A {}'''); | 5015 class D implements A {}'''); |
4921 resolve(source); | 5016 computeLibrarySourceErrors(source); |
4922 assertErrors(source, [ | 5017 assertErrors(source, [ |
4923 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE, | 5018 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE, |
4924 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE, | 5019 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE, |
4925 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE | 5020 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE |
4926 ]); | 5021 ]); |
4927 verify([source]); | 5022 verify([source]); |
4928 } | 5023 } |
4929 | 5024 |
4930 void test_recursiveInterfaceInheritanceBaseCaseExtends() { | 5025 void test_recursiveInterfaceInheritanceBaseCaseExtends() { |
4931 Source source = addSource("class A extends A {}"); | 5026 Source source = addSource("class A extends A {}"); |
4932 resolve(source); | 5027 computeLibrarySourceErrors(source); |
4933 assertErrors(source, [ | 5028 assertErrors(source, [ |
4934 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE_BASE_CASE_EXTENDS | 5029 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE_BASE_CASE_EXTENDS |
4935 ]); | 5030 ]); |
4936 verify([source]); | 5031 verify([source]); |
4937 } | 5032 } |
4938 | 5033 |
4939 void test_recursiveInterfaceInheritanceBaseCaseImplements() { | 5034 void test_recursiveInterfaceInheritanceBaseCaseImplements() { |
4940 Source source = addSource("class A implements A {}"); | 5035 Source source = addSource("class A implements A {}"); |
4941 resolve(source); | 5036 computeLibrarySourceErrors(source); |
4942 assertErrors(source, [ | 5037 assertErrors(source, [ |
4943 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE_BASE_CASE_IMPLEMENTS | 5038 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE_BASE_CASE_IMPLEMENTS |
4944 ]); | 5039 ]); |
4945 verify([source]); | 5040 verify([source]); |
4946 } | 5041 } |
4947 | 5042 |
4948 void test_recursiveInterfaceInheritanceBaseCaseImplements_typeAlias() { | 5043 void test_recursiveInterfaceInheritanceBaseCaseImplements_typeAlias() { |
4949 Source source = addSource(r''' | 5044 Source source = addSource(r''' |
4950 class A {} | 5045 class A {} |
4951 class M {} | 5046 class M {} |
4952 class B = A with M implements B;'''); | 5047 class B = A with M implements B;'''); |
4953 resolve(source); | 5048 computeLibrarySourceErrors(source); |
4954 assertErrors(source, [ | 5049 assertErrors(source, [ |
4955 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE_BASE_CASE_IMPLEMENTS | 5050 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE_BASE_CASE_IMPLEMENTS |
4956 ]); | 5051 ]); |
4957 verify([source]); | 5052 verify([source]); |
4958 } | 5053 } |
4959 | 5054 |
4960 void test_recursiveInterfaceInheritanceBaseCaseWith() { | 5055 void test_recursiveInterfaceInheritanceBaseCaseWith() { |
4961 Source source = addSource("class M = Object with M;"); | 5056 Source source = addSource("class M = Object with M;"); |
4962 resolve(source); | 5057 computeLibrarySourceErrors(source); |
4963 assertErrors(source, | 5058 assertErrors(source, |
4964 [CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE_BASE_CASE_WITH]); | 5059 [CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE_BASE_CASE_WITH]); |
4965 verify([source]); | 5060 verify([source]); |
4966 } | 5061 } |
4967 | 5062 |
4968 void test_redirectGenerativeToMissingConstructor() { | 5063 void test_redirectGenerativeToMissingConstructor() { |
4969 Source source = addSource(r''' | 5064 Source source = addSource(r''' |
4970 class A { | 5065 class A { |
4971 A() : this.noSuchConstructor(); | 5066 A() : this.noSuchConstructor(); |
4972 }'''); | 5067 }'''); |
4973 resolve(source); | 5068 computeLibrarySourceErrors(source); |
4974 assertErrors(source, | 5069 assertErrors(source, |
4975 [CompileTimeErrorCode.REDIRECT_GENERATIVE_TO_MISSING_CONSTRUCTOR]); | 5070 [CompileTimeErrorCode.REDIRECT_GENERATIVE_TO_MISSING_CONSTRUCTOR]); |
4976 } | 5071 } |
4977 | 5072 |
4978 void test_redirectGenerativeToNonGenerativeConstructor() { | 5073 void test_redirectGenerativeToNonGenerativeConstructor() { |
4979 Source source = addSource(r''' | 5074 Source source = addSource(r''' |
4980 class A { | 5075 class A { |
4981 A() : this.x(); | 5076 A() : this.x(); |
4982 factory A.x() => null; | 5077 factory A.x() => null; |
4983 }'''); | 5078 }'''); |
4984 resolve(source); | 5079 computeLibrarySourceErrors(source); |
4985 assertErrors(source, [ | 5080 assertErrors(source, [ |
4986 CompileTimeErrorCode.REDIRECT_GENERATIVE_TO_NON_GENERATIVE_CONSTRUCTOR | 5081 CompileTimeErrorCode.REDIRECT_GENERATIVE_TO_NON_GENERATIVE_CONSTRUCTOR |
4987 ]); | 5082 ]); |
4988 verify([source]); | 5083 verify([source]); |
4989 } | 5084 } |
4990 | 5085 |
4991 void test_redirectToMissingConstructor_named() { | 5086 void test_redirectToMissingConstructor_named() { |
4992 Source source = addSource(r''' | 5087 Source source = addSource(r''' |
4993 class A implements B{ | 5088 class A implements B{ |
4994 A() {} | 5089 A() {} |
4995 } | 5090 } |
4996 class B { | 5091 class B { |
4997 const factory B() = A.name; | 5092 const factory B() = A.name; |
4998 }'''); | 5093 }'''); |
4999 resolve(source); | 5094 computeLibrarySourceErrors(source); |
5000 assertErrors( | 5095 assertErrors( |
5001 source, [CompileTimeErrorCode.REDIRECT_TO_MISSING_CONSTRUCTOR]); | 5096 source, [CompileTimeErrorCode.REDIRECT_TO_MISSING_CONSTRUCTOR]); |
5002 } | 5097 } |
5003 | 5098 |
5004 void test_redirectToMissingConstructor_unnamed() { | 5099 void test_redirectToMissingConstructor_unnamed() { |
5005 Source source = addSource(r''' | 5100 Source source = addSource(r''' |
5006 class A implements B{ | 5101 class A implements B{ |
5007 A.name() {} | 5102 A.name() {} |
5008 } | 5103 } |
5009 class B { | 5104 class B { |
5010 const factory B() = A; | 5105 const factory B() = A; |
5011 }'''); | 5106 }'''); |
5012 resolve(source); | 5107 computeLibrarySourceErrors(source); |
5013 assertErrors( | 5108 assertErrors( |
5014 source, [CompileTimeErrorCode.REDIRECT_TO_MISSING_CONSTRUCTOR]); | 5109 source, [CompileTimeErrorCode.REDIRECT_TO_MISSING_CONSTRUCTOR]); |
5015 } | 5110 } |
5016 | 5111 |
5017 void test_redirectToNonClass_notAType() { | 5112 void test_redirectToNonClass_notAType() { |
5018 Source source = addSource(r''' | 5113 Source source = addSource(r''' |
5019 int A; | 5114 int A; |
5020 class B { | 5115 class B { |
5021 const factory B() = A; | 5116 const factory B() = A; |
5022 }'''); | 5117 }'''); |
5023 resolve(source); | 5118 computeLibrarySourceErrors(source); |
5024 assertErrors(source, [CompileTimeErrorCode.REDIRECT_TO_NON_CLASS]); | 5119 assertErrors(source, [CompileTimeErrorCode.REDIRECT_TO_NON_CLASS]); |
5025 verify([source]); | 5120 verify([source]); |
5026 } | 5121 } |
5027 | 5122 |
5028 void test_redirectToNonClass_undefinedIdentifier() { | 5123 void test_redirectToNonClass_undefinedIdentifier() { |
5029 Source source = addSource(r''' | 5124 Source source = addSource(r''' |
5030 class B { | 5125 class B { |
5031 const factory B() = A; | 5126 const factory B() = A; |
5032 }'''); | 5127 }'''); |
5033 resolve(source); | 5128 computeLibrarySourceErrors(source); |
5034 assertErrors(source, [CompileTimeErrorCode.REDIRECT_TO_NON_CLASS]); | 5129 assertErrors(source, [CompileTimeErrorCode.REDIRECT_TO_NON_CLASS]); |
5035 verify([source]); | 5130 verify([source]); |
5036 } | 5131 } |
5037 | 5132 |
5038 void test_redirectToNonConstConstructor() { | 5133 void test_redirectToNonConstConstructor() { |
5039 Source source = addSource(r''' | 5134 Source source = addSource(r''' |
5040 class A { | 5135 class A { |
5041 A.a() {} | 5136 A.a() {} |
5042 const factory A.b() = A.a; | 5137 const factory A.b() = A.a; |
5043 }'''); | 5138 }'''); |
5044 resolve(source); | 5139 computeLibrarySourceErrors(source); |
5045 assertErrors( | 5140 assertErrors( |
5046 source, [CompileTimeErrorCode.REDIRECT_TO_NON_CONST_CONSTRUCTOR]); | 5141 source, [CompileTimeErrorCode.REDIRECT_TO_NON_CONST_CONSTRUCTOR]); |
5047 verify([source]); | 5142 verify([source]); |
5048 } | 5143 } |
5049 | 5144 |
5050 void test_referencedBeforeDeclaration_hideInBlock_function() { | 5145 void test_referencedBeforeDeclaration_hideInBlock_function() { |
5051 Source source = addSource(r''' | 5146 Source source = addSource(r''' |
5052 var v = 1; | 5147 var v = 1; |
5053 main() { | 5148 main() { |
5054 print(v); | 5149 print(v); |
5055 v() {} | 5150 v() {} |
5056 } | 5151 } |
5057 print(x) {}'''); | 5152 print(x) {}'''); |
5058 resolve(source); | 5153 computeLibrarySourceErrors(source); |
5059 assertErrors(source, [CompileTimeErrorCode.REFERENCED_BEFORE_DECLARATION]); | 5154 assertErrors(source, [CompileTimeErrorCode.REFERENCED_BEFORE_DECLARATION]); |
5060 } | 5155 } |
5061 | 5156 |
5062 void test_referencedBeforeDeclaration_hideInBlock_local() { | 5157 void test_referencedBeforeDeclaration_hideInBlock_local() { |
5063 Source source = addSource(r''' | 5158 Source source = addSource(r''' |
5064 var v = 1; | 5159 var v = 1; |
5065 main() { | 5160 main() { |
5066 print(v); | 5161 print(v); |
5067 var v = 2; | 5162 var v = 2; |
5068 } | 5163 } |
5069 print(x) {}'''); | 5164 print(x) {}'''); |
5070 resolve(source); | 5165 computeLibrarySourceErrors(source); |
5071 assertErrors(source, [CompileTimeErrorCode.REFERENCED_BEFORE_DECLARATION]); | 5166 assertErrors(source, [CompileTimeErrorCode.REFERENCED_BEFORE_DECLARATION]); |
5072 } | 5167 } |
5073 | 5168 |
5074 void test_referencedBeforeDeclaration_hideInBlock_subBlock() { | 5169 void test_referencedBeforeDeclaration_hideInBlock_subBlock() { |
5075 Source source = addSource(r''' | 5170 Source source = addSource(r''' |
5076 var v = 1; | 5171 var v = 1; |
5077 main() { | 5172 main() { |
5078 { | 5173 { |
5079 print(v); | 5174 print(v); |
5080 } | 5175 } |
5081 var v = 2; | 5176 var v = 2; |
5082 } | 5177 } |
5083 print(x) {}'''); | 5178 print(x) {}'''); |
5084 resolve(source); | 5179 computeLibrarySourceErrors(source); |
5085 assertErrors(source, [CompileTimeErrorCode.REFERENCED_BEFORE_DECLARATION]); | 5180 assertErrors(source, [CompileTimeErrorCode.REFERENCED_BEFORE_DECLARATION]); |
5086 } | 5181 } |
5087 | 5182 |
5088 void test_referencedBeforeDeclaration_inInitializer_closure() { | 5183 void test_referencedBeforeDeclaration_inInitializer_closure() { |
5089 Source source = addSource(r''' | 5184 Source source = addSource(r''' |
5090 main() { | 5185 main() { |
5091 var v = () => v; | 5186 var v = () => v; |
5092 }'''); | 5187 }'''); |
5093 resolve(source); | 5188 computeLibrarySourceErrors(source); |
5094 assertErrors(source, [CompileTimeErrorCode.REFERENCED_BEFORE_DECLARATION]); | 5189 assertErrors(source, [CompileTimeErrorCode.REFERENCED_BEFORE_DECLARATION]); |
5095 } | 5190 } |
5096 | 5191 |
5097 void test_referencedBeforeDeclaration_inInitializer_directly() { | 5192 void test_referencedBeforeDeclaration_inInitializer_directly() { |
5098 Source source = addSource(r''' | 5193 Source source = addSource(r''' |
5099 main() { | 5194 main() { |
5100 var v = v; | 5195 var v = v; |
5101 }'''); | 5196 }'''); |
5102 resolve(source); | 5197 computeLibrarySourceErrors(source); |
5103 assertErrors(source, [CompileTimeErrorCode.REFERENCED_BEFORE_DECLARATION]); | 5198 assertErrors(source, [CompileTimeErrorCode.REFERENCED_BEFORE_DECLARATION]); |
5104 } | 5199 } |
5105 | 5200 |
5106 void test_rethrowOutsideCatch() { | 5201 void test_rethrowOutsideCatch() { |
5107 Source source = addSource(r''' | 5202 Source source = addSource(r''' |
5108 f() { | 5203 f() { |
5109 rethrow; | 5204 rethrow; |
5110 }'''); | 5205 }'''); |
5111 resolve(source); | 5206 computeLibrarySourceErrors(source); |
5112 assertErrors(source, [CompileTimeErrorCode.RETHROW_OUTSIDE_CATCH]); | 5207 assertErrors(source, [CompileTimeErrorCode.RETHROW_OUTSIDE_CATCH]); |
5113 verify([source]); | 5208 verify([source]); |
5114 } | 5209 } |
5115 | 5210 |
5116 void test_returnInGenerativeConstructor() { | 5211 void test_returnInGenerativeConstructor() { |
5117 Source source = addSource(r''' | 5212 Source source = addSource(r''' |
5118 class A { | 5213 class A { |
5119 A() { return 0; } | 5214 A() { return 0; } |
5120 }'''); | 5215 }'''); |
5121 resolve(source); | 5216 computeLibrarySourceErrors(source); |
5122 assertErrors( | 5217 assertErrors( |
5123 source, [CompileTimeErrorCode.RETURN_IN_GENERATIVE_CONSTRUCTOR]); | 5218 source, [CompileTimeErrorCode.RETURN_IN_GENERATIVE_CONSTRUCTOR]); |
5124 verify([source]); | 5219 verify([source]); |
5125 } | 5220 } |
5126 | 5221 |
5127 void test_returnInGenerativeConstructor_expressionFunctionBody() { | 5222 void test_returnInGenerativeConstructor_expressionFunctionBody() { |
5128 Source source = addSource(r''' | 5223 Source source = addSource(r''' |
5129 class A { | 5224 class A { |
5130 A() => null; | 5225 A() => null; |
5131 }'''); | 5226 }'''); |
5132 resolve(source); | 5227 computeLibrarySourceErrors(source); |
5133 assertErrors( | 5228 assertErrors( |
5134 source, [CompileTimeErrorCode.RETURN_IN_GENERATIVE_CONSTRUCTOR]); | 5229 source, [CompileTimeErrorCode.RETURN_IN_GENERATIVE_CONSTRUCTOR]); |
5135 verify([source]); | 5230 verify([source]); |
5136 } | 5231 } |
5137 | 5232 |
5138 void test_returnInGenerator_asyncStar() { | 5233 void test_returnInGenerator_asyncStar() { |
5139 Source source = addSource(r''' | 5234 Source source = addSource(r''' |
5140 f() async* { | 5235 f() async* { |
5141 return 0; | 5236 return 0; |
5142 }'''); | 5237 }'''); |
5143 resolve(source); | 5238 computeLibrarySourceErrors(source); |
5144 assertErrors(source, [CompileTimeErrorCode.RETURN_IN_GENERATOR]); | 5239 assertErrors(source, [CompileTimeErrorCode.RETURN_IN_GENERATOR]); |
5145 verify([source]); | 5240 verify([source]); |
5146 } | 5241 } |
5147 | 5242 |
5148 void test_returnInGenerator_syncStar() { | 5243 void test_returnInGenerator_syncStar() { |
5149 Source source = addSource(r''' | 5244 Source source = addSource(r''' |
5150 f() sync* { | 5245 f() sync* { |
5151 return 0; | 5246 return 0; |
5152 }'''); | 5247 }'''); |
5153 resolve(source); | 5248 computeLibrarySourceErrors(source); |
5154 assertErrors(source, [CompileTimeErrorCode.RETURN_IN_GENERATOR]); | 5249 assertErrors(source, [CompileTimeErrorCode.RETURN_IN_GENERATOR]); |
5155 verify([source]); | 5250 verify([source]); |
5156 } | 5251 } |
5157 | 5252 |
5158 void test_sharedDeferredPrefix() { | 5253 void test_sharedDeferredPrefix() { |
5159 resolveWithErrors(<String>[ | 5254 resolveWithErrors(<String>[ |
5160 r''' | 5255 r''' |
5161 library lib1; | 5256 library lib1; |
5162 f1() {}''', | 5257 f1() {}''', |
5163 r''' | 5258 r''' |
5164 library lib2; | 5259 library lib2; |
5165 f2() {}''', | 5260 f2() {}''', |
5166 r''' | 5261 r''' |
5167 library root; | 5262 library root; |
5168 import 'lib1.dart' deferred as lib; | 5263 import 'lib1.dart' deferred as lib; |
5169 import 'lib2.dart' as lib; | 5264 import 'lib2.dart' as lib; |
5170 main() { lib.f1(); lib.f2(); }''' | 5265 main() { lib.f1(); lib.f2(); }''' |
5171 ], <ErrorCode>[CompileTimeErrorCode.SHARED_DEFERRED_PREFIX]); | 5266 ], <ErrorCode>[CompileTimeErrorCode.SHARED_DEFERRED_PREFIX]); |
5172 } | 5267 } |
5173 | 5268 |
5174 void test_superInInvalidContext_binaryExpression() { | 5269 void test_superInInvalidContext_binaryExpression() { |
5175 Source source = addSource("var v = super + 0;"); | 5270 Source source = addSource("var v = super + 0;"); |
5176 resolve(source); | 5271 computeLibrarySourceErrors(source); |
5177 assertErrors(source, [CompileTimeErrorCode.SUPER_IN_INVALID_CONTEXT]); | 5272 assertErrors(source, [CompileTimeErrorCode.SUPER_IN_INVALID_CONTEXT]); |
5178 // no verify(), 'super.v' is not resolved | 5273 // no verify(), 'super.v' is not resolved |
5179 } | 5274 } |
5180 | 5275 |
5181 void test_superInInvalidContext_constructorFieldInitializer() { | 5276 void test_superInInvalidContext_constructorFieldInitializer() { |
5182 Source source = addSource(r''' | 5277 Source source = addSource(r''' |
5183 class A { | 5278 class A { |
5184 m() {} | 5279 m() {} |
5185 } | 5280 } |
5186 class B extends A { | 5281 class B extends A { |
5187 var f; | 5282 var f; |
5188 B() : f = super.m(); | 5283 B() : f = super.m(); |
5189 }'''); | 5284 }'''); |
5190 resolve(source); | 5285 computeLibrarySourceErrors(source); |
5191 assertErrors(source, [CompileTimeErrorCode.SUPER_IN_INVALID_CONTEXT]); | 5286 assertErrors(source, [CompileTimeErrorCode.SUPER_IN_INVALID_CONTEXT]); |
5192 // no verify(), 'super.m' is not resolved | 5287 // no verify(), 'super.m' is not resolved |
5193 } | 5288 } |
5194 | 5289 |
5195 void test_superInInvalidContext_factoryConstructor() { | 5290 void test_superInInvalidContext_factoryConstructor() { |
5196 Source source = addSource(r''' | 5291 Source source = addSource(r''' |
5197 class A { | 5292 class A { |
5198 m() {} | 5293 m() {} |
5199 } | 5294 } |
5200 class B extends A { | 5295 class B extends A { |
5201 factory B() { | 5296 factory B() { |
5202 super.m(); | 5297 super.m(); |
5203 } | 5298 } |
5204 }'''); | 5299 }'''); |
5205 resolve(source); | 5300 computeLibrarySourceErrors(source); |
5206 assertErrors(source, [CompileTimeErrorCode.SUPER_IN_INVALID_CONTEXT]); | 5301 assertErrors(source, [CompileTimeErrorCode.SUPER_IN_INVALID_CONTEXT]); |
5207 // no verify(), 'super.m' is not resolved | 5302 // no verify(), 'super.m' is not resolved |
5208 } | 5303 } |
5209 | 5304 |
5210 void test_superInInvalidContext_instanceVariableInitializer() { | 5305 void test_superInInvalidContext_instanceVariableInitializer() { |
5211 Source source = addSource(r''' | 5306 Source source = addSource(r''' |
5212 class A { | 5307 class A { |
5213 var a; | 5308 var a; |
5214 } | 5309 } |
5215 class B extends A { | 5310 class B extends A { |
5216 var b = super.a; | 5311 var b = super.a; |
5217 }'''); | 5312 }'''); |
5218 resolve(source); | 5313 computeLibrarySourceErrors(source); |
5219 assertErrors(source, [CompileTimeErrorCode.SUPER_IN_INVALID_CONTEXT]); | 5314 assertErrors(source, [CompileTimeErrorCode.SUPER_IN_INVALID_CONTEXT]); |
5220 // no verify(), 'super.a' is not resolved | 5315 // no verify(), 'super.a' is not resolved |
5221 } | 5316 } |
5222 | 5317 |
5223 void test_superInInvalidContext_staticMethod() { | 5318 void test_superInInvalidContext_staticMethod() { |
5224 Source source = addSource(r''' | 5319 Source source = addSource(r''' |
5225 class A { | 5320 class A { |
5226 static m() {} | 5321 static m() {} |
5227 } | 5322 } |
5228 class B extends A { | 5323 class B extends A { |
5229 static n() { return super.m(); } | 5324 static n() { return super.m(); } |
5230 }'''); | 5325 }'''); |
5231 resolve(source); | 5326 computeLibrarySourceErrors(source); |
5232 assertErrors(source, [CompileTimeErrorCode.SUPER_IN_INVALID_CONTEXT]); | 5327 assertErrors(source, [CompileTimeErrorCode.SUPER_IN_INVALID_CONTEXT]); |
5233 // no verify(), 'super.m' is not resolved | 5328 // no verify(), 'super.m' is not resolved |
5234 } | 5329 } |
5235 | 5330 |
5236 void test_superInInvalidContext_staticVariableInitializer() { | 5331 void test_superInInvalidContext_staticVariableInitializer() { |
5237 Source source = addSource(r''' | 5332 Source source = addSource(r''' |
5238 class A { | 5333 class A { |
5239 static int a = 0; | 5334 static int a = 0; |
5240 } | 5335 } |
5241 class B extends A { | 5336 class B extends A { |
5242 static int b = super.a; | 5337 static int b = super.a; |
5243 }'''); | 5338 }'''); |
5244 resolve(source); | 5339 computeLibrarySourceErrors(source); |
5245 assertErrors(source, [CompileTimeErrorCode.SUPER_IN_INVALID_CONTEXT]); | 5340 assertErrors(source, [CompileTimeErrorCode.SUPER_IN_INVALID_CONTEXT]); |
5246 // no verify(), 'super.a' is not resolved | 5341 // no verify(), 'super.a' is not resolved |
5247 } | 5342 } |
5248 | 5343 |
5249 void test_superInInvalidContext_topLevelFunction() { | 5344 void test_superInInvalidContext_topLevelFunction() { |
5250 Source source = addSource(r''' | 5345 Source source = addSource(r''' |
5251 f() { | 5346 f() { |
5252 super.f(); | 5347 super.f(); |
5253 }'''); | 5348 }'''); |
5254 resolve(source); | 5349 computeLibrarySourceErrors(source); |
5255 assertErrors(source, [CompileTimeErrorCode.SUPER_IN_INVALID_CONTEXT]); | 5350 assertErrors(source, [CompileTimeErrorCode.SUPER_IN_INVALID_CONTEXT]); |
5256 // no verify(), 'super.f' is not resolved | 5351 // no verify(), 'super.f' is not resolved |
5257 } | 5352 } |
5258 | 5353 |
5259 void test_superInInvalidContext_topLevelVariableInitializer() { | 5354 void test_superInInvalidContext_topLevelVariableInitializer() { |
5260 Source source = addSource("var v = super.y;"); | 5355 Source source = addSource("var v = super.y;"); |
5261 resolve(source); | 5356 computeLibrarySourceErrors(source); |
5262 assertErrors(source, [CompileTimeErrorCode.SUPER_IN_INVALID_CONTEXT]); | 5357 assertErrors(source, [CompileTimeErrorCode.SUPER_IN_INVALID_CONTEXT]); |
5263 // no verify(), 'super.y' is not resolved | 5358 // no verify(), 'super.y' is not resolved |
5264 } | 5359 } |
5265 | 5360 |
5266 void test_superInRedirectingConstructor_redirectionSuper() { | 5361 void test_superInRedirectingConstructor_redirectionSuper() { |
5267 Source source = addSource(r''' | 5362 Source source = addSource(r''' |
5268 class A {} | 5363 class A {} |
5269 class B { | 5364 class B { |
5270 B() : this.name(), super(); | 5365 B() : this.name(), super(); |
5271 B.name() {} | 5366 B.name() {} |
5272 }'''); | 5367 }'''); |
5273 resolve(source); | 5368 computeLibrarySourceErrors(source); |
5274 assertErrors( | 5369 assertErrors( |
5275 source, [CompileTimeErrorCode.SUPER_IN_REDIRECTING_CONSTRUCTOR]); | 5370 source, [CompileTimeErrorCode.SUPER_IN_REDIRECTING_CONSTRUCTOR]); |
5276 verify([source]); | 5371 verify([source]); |
5277 } | 5372 } |
5278 | 5373 |
5279 void test_superInRedirectingConstructor_superRedirection() { | 5374 void test_superInRedirectingConstructor_superRedirection() { |
5280 Source source = addSource(r''' | 5375 Source source = addSource(r''' |
5281 class A {} | 5376 class A {} |
5282 class B { | 5377 class B { |
5283 B() : super(), this.name(); | 5378 B() : super(), this.name(); |
5284 B.name() {} | 5379 B.name() {} |
5285 }'''); | 5380 }'''); |
5286 resolve(source); | 5381 computeLibrarySourceErrors(source); |
5287 assertErrors( | 5382 assertErrors( |
5288 source, [CompileTimeErrorCode.SUPER_IN_REDIRECTING_CONSTRUCTOR]); | 5383 source, [CompileTimeErrorCode.SUPER_IN_REDIRECTING_CONSTRUCTOR]); |
5289 verify([source]); | 5384 verify([source]); |
5290 } | 5385 } |
5291 | 5386 |
5292 void test_symbol_constructor_badArgs() { | 5387 void test_symbol_constructor_badArgs() { |
5293 Source source = addSource(r''' | 5388 Source source = addSource(r''' |
5294 var s1 = const Symbol('3'); | 5389 var s1 = const Symbol('3'); |
5295 var s2 = const Symbol(3); | 5390 var s2 = const Symbol(3); |
5296 var s3 = const Symbol(); | 5391 var s3 = const Symbol(); |
5297 var s4 = const Symbol('x', 'y'); | 5392 var s4 = const Symbol('x', 'y'); |
5298 var s5 = const Symbol('x', foo: 'x');'''); | 5393 var s5 = const Symbol('x', foo: 'x');'''); |
5299 resolve(source); | 5394 computeLibrarySourceErrors(source); |
5300 assertErrors(source, [ | 5395 assertErrors(source, [ |
5301 CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION, | 5396 CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION, |
5302 CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION, | 5397 CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION, |
5303 StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE, | 5398 StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE, |
5304 CompileTimeErrorCode.NOT_ENOUGH_REQUIRED_ARGUMENTS, | 5399 CompileTimeErrorCode.NOT_ENOUGH_REQUIRED_ARGUMENTS, |
5305 CompileTimeErrorCode.EXTRA_POSITIONAL_ARGUMENTS, | 5400 CompileTimeErrorCode.EXTRA_POSITIONAL_ARGUMENTS, |
5306 CompileTimeErrorCode.UNDEFINED_NAMED_PARAMETER | 5401 CompileTimeErrorCode.UNDEFINED_NAMED_PARAMETER |
5307 ]); | 5402 ]); |
5308 verify([source]); | 5403 verify([source]); |
5309 } | 5404 } |
5310 | 5405 |
5311 void test_typeAliasCannotReferenceItself_11987() { | 5406 void test_typeAliasCannotReferenceItself_11987() { |
5312 Source source = addSource(r''' | 5407 Source source = addSource(r''' |
5313 typedef void F(List<G> l); | 5408 typedef void F(List<G> l); |
5314 typedef void G(List<F> l); | 5409 typedef void G(List<F> l); |
5315 main() { | 5410 main() { |
5316 F foo(G g) => g; | 5411 F foo(G g) => g; |
5317 }'''); | 5412 }'''); |
5318 resolve(source); | 5413 computeLibrarySourceErrors(source); |
5319 assertErrors(source, [ | 5414 assertErrors(source, [ |
5320 CompileTimeErrorCode.TYPE_ALIAS_CANNOT_REFERENCE_ITSELF, | 5415 CompileTimeErrorCode.TYPE_ALIAS_CANNOT_REFERENCE_ITSELF, |
5321 CompileTimeErrorCode.TYPE_ALIAS_CANNOT_REFERENCE_ITSELF | 5416 CompileTimeErrorCode.TYPE_ALIAS_CANNOT_REFERENCE_ITSELF |
5322 ]); | 5417 ]); |
5323 verify([source]); | 5418 verify([source]); |
5324 } | 5419 } |
5325 | 5420 |
5326 void test_typeAliasCannotReferenceItself_19459() { | 5421 void test_typeAliasCannotReferenceItself_19459() { |
5327 // A complex example involving multiple classes. This is legal, since | 5422 // A complex example involving multiple classes. This is legal, since |
5328 // typedef F references itself only via a class. | 5423 // typedef F references itself only via a class. |
5329 Source source = addSource(r''' | 5424 Source source = addSource(r''' |
5330 class A<B, C> {} | 5425 class A<B, C> {} |
5331 abstract class D { | 5426 abstract class D { |
5332 f(E e); | 5427 f(E e); |
5333 } | 5428 } |
5334 abstract class E extends A<dynamic, F> {} | 5429 abstract class E extends A<dynamic, F> {} |
5335 typedef D F(); | 5430 typedef D F(); |
5336 '''); | 5431 '''); |
5337 resolve(source); | 5432 computeLibrarySourceErrors(source); |
5338 assertNoErrors(source); | 5433 assertNoErrors(source); |
5339 verify([source]); | 5434 verify([source]); |
5340 } | 5435 } |
5341 | 5436 |
5342 void test_typeAliasCannotReferenceItself_parameterType_named() { | 5437 void test_typeAliasCannotReferenceItself_parameterType_named() { |
5343 Source source = addSource("typedef A({A a});"); | 5438 Source source = addSource("typedef A({A a});"); |
5344 resolve(source); | 5439 computeLibrarySourceErrors(source); |
5345 assertErrors( | 5440 assertErrors( |
5346 source, [CompileTimeErrorCode.TYPE_ALIAS_CANNOT_REFERENCE_ITSELF]); | 5441 source, [CompileTimeErrorCode.TYPE_ALIAS_CANNOT_REFERENCE_ITSELF]); |
5347 verify([source]); | 5442 verify([source]); |
5348 } | 5443 } |
5349 | 5444 |
5350 void test_typeAliasCannotReferenceItself_parameterType_positional() { | 5445 void test_typeAliasCannotReferenceItself_parameterType_positional() { |
5351 Source source = addSource("typedef A([A a]);"); | 5446 Source source = addSource("typedef A([A a]);"); |
5352 resolve(source); | 5447 computeLibrarySourceErrors(source); |
5353 assertErrors( | 5448 assertErrors( |
5354 source, [CompileTimeErrorCode.TYPE_ALIAS_CANNOT_REFERENCE_ITSELF]); | 5449 source, [CompileTimeErrorCode.TYPE_ALIAS_CANNOT_REFERENCE_ITSELF]); |
5355 verify([source]); | 5450 verify([source]); |
5356 } | 5451 } |
5357 | 5452 |
5358 void test_typeAliasCannotReferenceItself_parameterType_required() { | 5453 void test_typeAliasCannotReferenceItself_parameterType_required() { |
5359 Source source = addSource("typedef A(A a);"); | 5454 Source source = addSource("typedef A(A a);"); |
5360 resolve(source); | 5455 computeLibrarySourceErrors(source); |
5361 assertErrors( | 5456 assertErrors( |
5362 source, [CompileTimeErrorCode.TYPE_ALIAS_CANNOT_REFERENCE_ITSELF]); | 5457 source, [CompileTimeErrorCode.TYPE_ALIAS_CANNOT_REFERENCE_ITSELF]); |
5363 verify([source]); | 5458 verify([source]); |
5364 } | 5459 } |
5365 | 5460 |
5366 void test_typeAliasCannotReferenceItself_parameterType_typeArgument() { | 5461 void test_typeAliasCannotReferenceItself_parameterType_typeArgument() { |
5367 Source source = addSource("typedef A(List<A> a);"); | 5462 Source source = addSource("typedef A(List<A> a);"); |
5368 resolve(source); | 5463 computeLibrarySourceErrors(source); |
5369 assertErrors( | 5464 assertErrors( |
5370 source, [CompileTimeErrorCode.TYPE_ALIAS_CANNOT_REFERENCE_ITSELF]); | 5465 source, [CompileTimeErrorCode.TYPE_ALIAS_CANNOT_REFERENCE_ITSELF]); |
5371 verify([source]); | 5466 verify([source]); |
5372 } | 5467 } |
5373 | 5468 |
5374 void test_typeAliasCannotReferenceItself_returnClass_withTypeAlias() { | 5469 void test_typeAliasCannotReferenceItself_returnClass_withTypeAlias() { |
5375 // A typedef is allowed to indirectly reference itself via a class. | 5470 // A typedef is allowed to indirectly reference itself via a class. |
5376 Source source = addSource(r''' | 5471 Source source = addSource(r''' |
5377 typedef C A(); | 5472 typedef C A(); |
5378 typedef A B(); | 5473 typedef A B(); |
5379 class C { | 5474 class C { |
5380 B a; | 5475 B a; |
5381 }'''); | 5476 }'''); |
5382 resolve(source); | 5477 computeLibrarySourceErrors(source); |
5383 assertNoErrors(source); | 5478 assertNoErrors(source); |
5384 verify([source]); | 5479 verify([source]); |
5385 } | 5480 } |
5386 | 5481 |
5387 void test_typeAliasCannotReferenceItself_returnType() { | 5482 void test_typeAliasCannotReferenceItself_returnType() { |
5388 Source source = addSource("typedef A A();"); | 5483 Source source = addSource("typedef A A();"); |
5389 resolve(source); | 5484 computeLibrarySourceErrors(source); |
5390 assertErrors( | 5485 assertErrors( |
5391 source, [CompileTimeErrorCode.TYPE_ALIAS_CANNOT_REFERENCE_ITSELF]); | 5486 source, [CompileTimeErrorCode.TYPE_ALIAS_CANNOT_REFERENCE_ITSELF]); |
5392 verify([source]); | 5487 verify([source]); |
5393 } | 5488 } |
5394 | 5489 |
5395 void test_typeAliasCannotReferenceItself_returnType_indirect() { | 5490 void test_typeAliasCannotReferenceItself_returnType_indirect() { |
5396 Source source = addSource(r''' | 5491 Source source = addSource(r''' |
5397 typedef B A(); | 5492 typedef B A(); |
5398 typedef A B();'''); | 5493 typedef A B();'''); |
5399 resolve(source); | 5494 computeLibrarySourceErrors(source); |
5400 assertErrors(source, [ | 5495 assertErrors(source, [ |
5401 CompileTimeErrorCode.TYPE_ALIAS_CANNOT_REFERENCE_ITSELF, | 5496 CompileTimeErrorCode.TYPE_ALIAS_CANNOT_REFERENCE_ITSELF, |
5402 CompileTimeErrorCode.TYPE_ALIAS_CANNOT_REFERENCE_ITSELF | 5497 CompileTimeErrorCode.TYPE_ALIAS_CANNOT_REFERENCE_ITSELF |
5403 ]); | 5498 ]); |
5404 verify([source]); | 5499 verify([source]); |
5405 } | 5500 } |
5406 | 5501 |
5407 void test_typeAliasCannotReferenceItself_typeVariableBounds() { | 5502 void test_typeAliasCannotReferenceItself_typeVariableBounds() { |
5408 Source source = addSource("typedef A<T extends A>();"); | 5503 Source source = addSource("typedef A<T extends A>();"); |
5409 resolve(source); | 5504 computeLibrarySourceErrors(source); |
5410 assertErrors( | 5505 assertErrors( |
5411 source, [CompileTimeErrorCode.TYPE_ALIAS_CANNOT_REFERENCE_ITSELF]); | 5506 source, [CompileTimeErrorCode.TYPE_ALIAS_CANNOT_REFERENCE_ITSELF]); |
5412 verify([source]); | 5507 verify([source]); |
5413 } | 5508 } |
5414 | 5509 |
5415 void test_typeArgumentNotMatchingBounds_const() { | 5510 void test_typeArgumentNotMatchingBounds_const() { |
5416 Source source = addSource(r''' | 5511 Source source = addSource(r''' |
5417 class A {} | 5512 class A {} |
5418 class B {} | 5513 class B {} |
5419 class G<E extends A> { | 5514 class G<E extends A> { |
5420 const G(); | 5515 const G(); |
5421 } | 5516 } |
5422 f() { return const G<B>(); }'''); | 5517 f() { return const G<B>(); }'''); |
5423 resolve(source); | 5518 computeLibrarySourceErrors(source); |
5424 assertErrors( | 5519 assertErrors( |
5425 source, [CompileTimeErrorCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS]); | 5520 source, [CompileTimeErrorCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS]); |
5426 verify([source]); | 5521 verify([source]); |
5427 } | 5522 } |
5428 | 5523 |
5429 void test_undefinedClass_const() { | 5524 void test_undefinedClass_const() { |
5430 Source source = addSource(r''' | 5525 Source source = addSource(r''' |
5431 f() { | 5526 f() { |
5432 return const A(); | 5527 return const A(); |
5433 }'''); | 5528 }'''); |
5434 resolve(source); | 5529 computeLibrarySourceErrors(source); |
5435 assertErrors(source, [CompileTimeErrorCode.UNDEFINED_CLASS]); | 5530 assertErrors(source, [CompileTimeErrorCode.UNDEFINED_CLASS]); |
5436 verify([source]); | 5531 verify([source]); |
5437 } | 5532 } |
5438 | 5533 |
5439 void test_undefinedConstructorInInitializer_explicit_named() { | 5534 void test_undefinedConstructorInInitializer_explicit_named() { |
5440 Source source = addSource(r''' | 5535 Source source = addSource(r''' |
5441 class A {} | 5536 class A {} |
5442 class B extends A { | 5537 class B extends A { |
5443 B() : super.named(); | 5538 B() : super.named(); |
5444 }'''); | 5539 }'''); |
5445 resolve(source); | 5540 computeLibrarySourceErrors(source); |
5446 assertErrors( | 5541 assertErrors( |
5447 source, [CompileTimeErrorCode.UNDEFINED_CONSTRUCTOR_IN_INITIALIZER]); | 5542 source, [CompileTimeErrorCode.UNDEFINED_CONSTRUCTOR_IN_INITIALIZER]); |
5448 // no verify(), "super.named()" is not resolved | 5543 // no verify(), "super.named()" is not resolved |
5449 } | 5544 } |
5450 | 5545 |
5451 void test_undefinedConstructorInInitializer_explicit_unnamed() { | 5546 void test_undefinedConstructorInInitializer_explicit_unnamed() { |
5452 Source source = addSource(r''' | 5547 Source source = addSource(r''' |
5453 class A { | 5548 class A { |
5454 A.named() {} | 5549 A.named() {} |
5455 } | 5550 } |
5456 class B extends A { | 5551 class B extends A { |
5457 B() : super(); | 5552 B() : super(); |
5458 }'''); | 5553 }'''); |
5459 resolve(source); | 5554 computeLibrarySourceErrors(source); |
5460 assertErrors(source, | 5555 assertErrors(source, |
5461 [CompileTimeErrorCode.UNDEFINED_CONSTRUCTOR_IN_INITIALIZER_DEFAULT]); | 5556 [CompileTimeErrorCode.UNDEFINED_CONSTRUCTOR_IN_INITIALIZER_DEFAULT]); |
5462 verify([source]); | 5557 verify([source]); |
5463 } | 5558 } |
5464 | 5559 |
5465 void test_undefinedConstructorInInitializer_implicit() { | 5560 void test_undefinedConstructorInInitializer_implicit() { |
5466 Source source = addSource(r''' | 5561 Source source = addSource(r''' |
5467 class A { | 5562 class A { |
5468 A.named() {} | 5563 A.named() {} |
5469 } | 5564 } |
5470 class B extends A { | 5565 class B extends A { |
5471 B(); | 5566 B(); |
5472 }'''); | 5567 }'''); |
5473 resolve(source); | 5568 computeLibrarySourceErrors(source); |
5474 assertErrors(source, | 5569 assertErrors(source, |
5475 [CompileTimeErrorCode.UNDEFINED_CONSTRUCTOR_IN_INITIALIZER_DEFAULT]); | 5570 [CompileTimeErrorCode.UNDEFINED_CONSTRUCTOR_IN_INITIALIZER_DEFAULT]); |
5476 verify([source]); | 5571 verify([source]); |
5477 } | 5572 } |
5478 | 5573 |
5479 void test_undefinedNamedParameter() { | 5574 void test_undefinedNamedParameter() { |
5480 Source source = addSource(r''' | 5575 Source source = addSource(r''' |
5481 class A { | 5576 class A { |
5482 const A(); | 5577 const A(); |
5483 } | 5578 } |
5484 main() { | 5579 main() { |
5485 const A(p: 0); | 5580 const A(p: 0); |
5486 }'''); | 5581 }'''); |
5487 resolve(source); | 5582 computeLibrarySourceErrors(source); |
5488 assertErrors(source, [CompileTimeErrorCode.UNDEFINED_NAMED_PARAMETER]); | 5583 assertErrors(source, [CompileTimeErrorCode.UNDEFINED_NAMED_PARAMETER]); |
5489 // no verify(), 'p' is not resolved | 5584 // no verify(), 'p' is not resolved |
5490 } | 5585 } |
5491 | 5586 |
5492 void test_uriDoesNotExist_export() { | 5587 void test_uriDoesNotExist_export() { |
5493 Source source = addSource("export 'unknown.dart';"); | 5588 Source source = addSource("export 'unknown.dart';"); |
5494 resolve(source); | 5589 computeLibrarySourceErrors(source); |
5495 assertErrors(source, [CompileTimeErrorCode.URI_DOES_NOT_EXIST]); | 5590 assertErrors(source, [CompileTimeErrorCode.URI_DOES_NOT_EXIST]); |
5496 } | 5591 } |
5497 | 5592 |
5498 void test_uriDoesNotExist_import() { | 5593 void test_uriDoesNotExist_import() { |
5499 Source source = addSource("import 'unknown.dart';"); | 5594 Source source = addSource("import 'unknown.dart';"); |
5500 resolve(source); | 5595 computeLibrarySourceErrors(source); |
5501 assertErrors(source, [CompileTimeErrorCode.URI_DOES_NOT_EXIST]); | 5596 assertErrors(source, [CompileTimeErrorCode.URI_DOES_NOT_EXIST]); |
5502 } | 5597 } |
5503 | 5598 |
5504 void test_uriDoesNotExist_part() { | 5599 void test_uriDoesNotExist_part() { |
5505 Source source = addSource("part 'unknown.dart';"); | 5600 Source source = addSource("part 'unknown.dart';"); |
5506 resolve(source); | 5601 computeLibrarySourceErrors(source); |
5507 assertErrors(source, [CompileTimeErrorCode.URI_DOES_NOT_EXIST]); | 5602 assertErrors(source, [CompileTimeErrorCode.URI_DOES_NOT_EXIST]); |
5508 } | 5603 } |
5509 | 5604 |
5510 void test_uriWithInterpolation_constant() { | 5605 void test_uriWithInterpolation_constant() { |
5511 Source source = addSource("import 'stuff_\$platform.dart';"); | 5606 Source source = addSource("import 'stuff_\$platform.dart';"); |
5512 resolve(source); | 5607 computeLibrarySourceErrors(source); |
5513 assertErrors(source, [ | 5608 assertErrors(source, [ |
5514 CompileTimeErrorCode.URI_WITH_INTERPOLATION, | 5609 CompileTimeErrorCode.URI_WITH_INTERPOLATION, |
5515 StaticWarningCode.UNDEFINED_IDENTIFIER | 5610 StaticWarningCode.UNDEFINED_IDENTIFIER |
5516 ]); | 5611 ]); |
5517 // We cannot verify resolution with an unresolvable | 5612 // We cannot verify resolution with an unresolvable |
5518 // URI: 'stuff_$platform.dart' | 5613 // URI: 'stuff_$platform.dart' |
5519 } | 5614 } |
5520 | 5615 |
5521 void test_uriWithInterpolation_nonConstant() { | 5616 void test_uriWithInterpolation_nonConstant() { |
5522 Source source = addSource(r''' | 5617 Source source = addSource(r''' |
5523 library lib; | 5618 library lib; |
5524 part '${'a'}.dart';'''); | 5619 part '${'a'}.dart';'''); |
5525 resolve(source); | 5620 computeLibrarySourceErrors(source); |
5526 assertErrors(source, [CompileTimeErrorCode.URI_WITH_INTERPOLATION]); | 5621 assertErrors(source, [CompileTimeErrorCode.URI_WITH_INTERPOLATION]); |
5527 // We cannot verify resolution with an unresolvable URI: '${'a'}.dart' | 5622 // We cannot verify resolution with an unresolvable URI: '${'a'}.dart' |
5528 } | 5623 } |
5529 | 5624 |
5530 void test_wrongNumberOfParametersForOperator1() { | 5625 void test_wrongNumberOfParametersForOperator1() { |
5531 _check_wrongNumberOfParametersForOperator1("<"); | 5626 _check_wrongNumberOfParametersForOperator1("<"); |
5532 _check_wrongNumberOfParametersForOperator1(">"); | 5627 _check_wrongNumberOfParametersForOperator1(">"); |
5533 _check_wrongNumberOfParametersForOperator1("<="); | 5628 _check_wrongNumberOfParametersForOperator1("<="); |
5534 _check_wrongNumberOfParametersForOperator1(">="); | 5629 _check_wrongNumberOfParametersForOperator1(">="); |
5535 _check_wrongNumberOfParametersForOperator1("+"); | 5630 _check_wrongNumberOfParametersForOperator1("+"); |
5536 _check_wrongNumberOfParametersForOperator1("/"); | 5631 _check_wrongNumberOfParametersForOperator1("/"); |
5537 _check_wrongNumberOfParametersForOperator1("~/"); | 5632 _check_wrongNumberOfParametersForOperator1("~/"); |
5538 _check_wrongNumberOfParametersForOperator1("*"); | 5633 _check_wrongNumberOfParametersForOperator1("*"); |
5539 _check_wrongNumberOfParametersForOperator1("%"); | 5634 _check_wrongNumberOfParametersForOperator1("%"); |
5540 _check_wrongNumberOfParametersForOperator1("|"); | 5635 _check_wrongNumberOfParametersForOperator1("|"); |
5541 _check_wrongNumberOfParametersForOperator1("^"); | 5636 _check_wrongNumberOfParametersForOperator1("^"); |
5542 _check_wrongNumberOfParametersForOperator1("&"); | 5637 _check_wrongNumberOfParametersForOperator1("&"); |
5543 _check_wrongNumberOfParametersForOperator1("<<"); | 5638 _check_wrongNumberOfParametersForOperator1("<<"); |
5544 _check_wrongNumberOfParametersForOperator1(">>"); | 5639 _check_wrongNumberOfParametersForOperator1(">>"); |
5545 _check_wrongNumberOfParametersForOperator1("[]"); | 5640 _check_wrongNumberOfParametersForOperator1("[]"); |
5546 } | 5641 } |
5547 | 5642 |
5548 void test_wrongNumberOfParametersForOperator_minus() { | 5643 void test_wrongNumberOfParametersForOperator_minus() { |
5549 Source source = addSource(r''' | 5644 Source source = addSource(r''' |
5550 class A { | 5645 class A { |
5551 operator -(a, b) {} | 5646 operator -(a, b) {} |
5552 }'''); | 5647 }'''); |
5553 resolve(source); | 5648 computeLibrarySourceErrors(source); |
5554 assertErrors(source, | 5649 assertErrors(source, |
5555 [CompileTimeErrorCode.WRONG_NUMBER_OF_PARAMETERS_FOR_OPERATOR_MINUS]); | 5650 [CompileTimeErrorCode.WRONG_NUMBER_OF_PARAMETERS_FOR_OPERATOR_MINUS]); |
5556 verify([source]); | 5651 verify([source]); |
5557 reset(); | 5652 reset(); |
5558 } | 5653 } |
5559 | 5654 |
5560 void test_wrongNumberOfParametersForOperator_tilde() { | 5655 void test_wrongNumberOfParametersForOperator_tilde() { |
5561 _check_wrongNumberOfParametersForOperator("~", "a"); | 5656 _check_wrongNumberOfParametersForOperator("~", "a"); |
5562 _check_wrongNumberOfParametersForOperator("~", "a, b"); | 5657 _check_wrongNumberOfParametersForOperator("~", "a, b"); |
5563 } | 5658 } |
5564 | 5659 |
5565 void test_wrongNumberOfParametersForSetter_function_named() { | 5660 void test_wrongNumberOfParametersForSetter_function_named() { |
5566 Source source = addSource("set x({p}) {}"); | 5661 Source source = addSource("set x({p}) {}"); |
5567 resolve(source); | 5662 computeLibrarySourceErrors(source); |
5568 assertErrors( | 5663 assertErrors( |
5569 source, [CompileTimeErrorCode.WRONG_NUMBER_OF_PARAMETERS_FOR_SETTER]); | 5664 source, [CompileTimeErrorCode.WRONG_NUMBER_OF_PARAMETERS_FOR_SETTER]); |
5570 verify([source]); | 5665 verify([source]); |
5571 } | 5666 } |
5572 | 5667 |
5573 void test_wrongNumberOfParametersForSetter_function_optional() { | 5668 void test_wrongNumberOfParametersForSetter_function_optional() { |
5574 Source source = addSource("set x([p]) {}"); | 5669 Source source = addSource("set x([p]) {}"); |
5575 resolve(source); | 5670 computeLibrarySourceErrors(source); |
5576 assertErrors( | 5671 assertErrors( |
5577 source, [CompileTimeErrorCode.WRONG_NUMBER_OF_PARAMETERS_FOR_SETTER]); | 5672 source, [CompileTimeErrorCode.WRONG_NUMBER_OF_PARAMETERS_FOR_SETTER]); |
5578 verify([source]); | 5673 verify([source]); |
5579 } | 5674 } |
5580 | 5675 |
5581 void test_wrongNumberOfParametersForSetter_function_tooFew() { | 5676 void test_wrongNumberOfParametersForSetter_function_tooFew() { |
5582 Source source = addSource("set x() {}"); | 5677 Source source = addSource("set x() {}"); |
5583 resolve(source); | 5678 computeLibrarySourceErrors(source); |
5584 assertErrors( | 5679 assertErrors( |
5585 source, [CompileTimeErrorCode.WRONG_NUMBER_OF_PARAMETERS_FOR_SETTER]); | 5680 source, [CompileTimeErrorCode.WRONG_NUMBER_OF_PARAMETERS_FOR_SETTER]); |
5586 verify([source]); | 5681 verify([source]); |
5587 } | 5682 } |
5588 | 5683 |
5589 void test_wrongNumberOfParametersForSetter_function_tooMany() { | 5684 void test_wrongNumberOfParametersForSetter_function_tooMany() { |
5590 Source source = addSource("set x(a, b) {}"); | 5685 Source source = addSource("set x(a, b) {}"); |
5591 resolve(source); | 5686 computeLibrarySourceErrors(source); |
5592 assertErrors( | 5687 assertErrors( |
5593 source, [CompileTimeErrorCode.WRONG_NUMBER_OF_PARAMETERS_FOR_SETTER]); | 5688 source, [CompileTimeErrorCode.WRONG_NUMBER_OF_PARAMETERS_FOR_SETTER]); |
5594 verify([source]); | 5689 verify([source]); |
5595 } | 5690 } |
5596 | 5691 |
5597 void test_wrongNumberOfParametersForSetter_method_named() { | 5692 void test_wrongNumberOfParametersForSetter_method_named() { |
5598 Source source = addSource(r''' | 5693 Source source = addSource(r''' |
5599 class A { | 5694 class A { |
5600 set x({p}) {} | 5695 set x({p}) {} |
5601 }'''); | 5696 }'''); |
5602 resolve(source); | 5697 computeLibrarySourceErrors(source); |
5603 assertErrors( | 5698 assertErrors( |
5604 source, [CompileTimeErrorCode.WRONG_NUMBER_OF_PARAMETERS_FOR_SETTER]); | 5699 source, [CompileTimeErrorCode.WRONG_NUMBER_OF_PARAMETERS_FOR_SETTER]); |
5605 verify([source]); | 5700 verify([source]); |
5606 } | 5701 } |
5607 | 5702 |
5608 void test_wrongNumberOfParametersForSetter_method_optional() { | 5703 void test_wrongNumberOfParametersForSetter_method_optional() { |
5609 Source source = addSource(r''' | 5704 Source source = addSource(r''' |
5610 class A { | 5705 class A { |
5611 set x([p]) {} | 5706 set x([p]) {} |
5612 }'''); | 5707 }'''); |
5613 resolve(source); | 5708 computeLibrarySourceErrors(source); |
5614 assertErrors( | 5709 assertErrors( |
5615 source, [CompileTimeErrorCode.WRONG_NUMBER_OF_PARAMETERS_FOR_SETTER]); | 5710 source, [CompileTimeErrorCode.WRONG_NUMBER_OF_PARAMETERS_FOR_SETTER]); |
5616 verify([source]); | 5711 verify([source]); |
5617 } | 5712 } |
5618 | 5713 |
5619 void test_wrongNumberOfParametersForSetter_method_tooFew() { | 5714 void test_wrongNumberOfParametersForSetter_method_tooFew() { |
5620 Source source = addSource(r''' | 5715 Source source = addSource(r''' |
5621 class A { | 5716 class A { |
5622 set x() {} | 5717 set x() {} |
5623 }'''); | 5718 }'''); |
5624 resolve(source); | 5719 computeLibrarySourceErrors(source); |
5625 assertErrors( | 5720 assertErrors( |
5626 source, [CompileTimeErrorCode.WRONG_NUMBER_OF_PARAMETERS_FOR_SETTER]); | 5721 source, [CompileTimeErrorCode.WRONG_NUMBER_OF_PARAMETERS_FOR_SETTER]); |
5627 verify([source]); | 5722 verify([source]); |
5628 } | 5723 } |
5629 | 5724 |
5630 void test_wrongNumberOfParametersForSetter_method_tooMany() { | 5725 void test_wrongNumberOfParametersForSetter_method_tooMany() { |
5631 Source source = addSource(r''' | 5726 Source source = addSource(r''' |
5632 class A { | 5727 class A { |
5633 set x(a, b) {} | 5728 set x(a, b) {} |
5634 }'''); | 5729 }'''); |
5635 resolve(source); | 5730 computeLibrarySourceErrors(source); |
5636 assertErrors( | 5731 assertErrors( |
5637 source, [CompileTimeErrorCode.WRONG_NUMBER_OF_PARAMETERS_FOR_SETTER]); | 5732 source, [CompileTimeErrorCode.WRONG_NUMBER_OF_PARAMETERS_FOR_SETTER]); |
5638 verify([source]); | 5733 verify([source]); |
5639 } | 5734 } |
5640 | 5735 |
5641 void test_yield_used_as_identifier_in_async_method() { | 5736 void test_yield_used_as_identifier_in_async_method() { |
5642 Source source = addSource(''' | 5737 Source source = addSource(''' |
5643 f() async { | 5738 f() async { |
5644 var yield = 1; | 5739 var yield = 1; |
5645 } | 5740 } |
5646 '''); | 5741 '''); |
5647 resolve(source); | 5742 computeLibrarySourceErrors(source); |
5648 assertErrors(source, [ParserErrorCode.ASYNC_KEYWORD_USED_AS_IDENTIFIER]); | 5743 assertErrors(source, [ParserErrorCode.ASYNC_KEYWORD_USED_AS_IDENTIFIER]); |
5649 verify([source]); | 5744 verify([source]); |
5650 } | 5745 } |
5651 | 5746 |
5652 void test_yield_used_as_identifier_in_async_star_method() { | 5747 void test_yield_used_as_identifier_in_async_star_method() { |
5653 Source source = addSource(''' | 5748 Source source = addSource(''' |
5654 f() async* { | 5749 f() async* { |
5655 var yield = 1; | 5750 var yield = 1; |
5656 } | 5751 } |
5657 '''); | 5752 '''); |
5658 resolve(source); | 5753 computeLibrarySourceErrors(source); |
5659 assertErrors(source, [ParserErrorCode.ASYNC_KEYWORD_USED_AS_IDENTIFIER]); | 5754 assertErrors(source, [ParserErrorCode.ASYNC_KEYWORD_USED_AS_IDENTIFIER]); |
5660 verify([source]); | 5755 verify([source]); |
5661 } | 5756 } |
5662 | 5757 |
5663 void test_yield_used_as_identifier_in_sync_star_method() { | 5758 void test_yield_used_as_identifier_in_sync_star_method() { |
5664 Source source = addSource(''' | 5759 Source source = addSource(''' |
5665 f() sync* { | 5760 f() sync* { |
5666 var yield = 1; | 5761 var yield = 1; |
5667 } | 5762 } |
5668 '''); | 5763 '''); |
5669 resolve(source); | 5764 computeLibrarySourceErrors(source); |
5670 assertErrors(source, [ParserErrorCode.ASYNC_KEYWORD_USED_AS_IDENTIFIER]); | 5765 assertErrors(source, [ParserErrorCode.ASYNC_KEYWORD_USED_AS_IDENTIFIER]); |
5671 verify([source]); | 5766 verify([source]); |
5672 } | 5767 } |
5673 | 5768 |
5674 void _check_constEvalThrowsException_binary_null(String expr, bool resolved) { | 5769 void _check_constEvalThrowsException_binary_null(String expr, bool resolved) { |
5675 Source source = addSource("const C = $expr;"); | 5770 Source source = addSource("const C = $expr;"); |
5676 resolve(source); | 5771 computeLibrarySourceErrors(source); |
5677 if (resolved) { | 5772 if (resolved) { |
5678 assertErrors(source, [CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION]); | 5773 assertErrors(source, [CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION]); |
5679 verify([source]); | 5774 verify([source]); |
5680 } else { | 5775 } else { |
5681 assertErrors(source, [CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION]); | 5776 assertErrors(source, [CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION]); |
5682 // no verify(), 'null x' is not resolved | 5777 // no verify(), 'null x' is not resolved |
5683 } | 5778 } |
5684 reset(); | 5779 reset(); |
5685 } | 5780 } |
5686 | 5781 |
5687 void _check_constEvalTypeBool_withParameter_binary(String expr) { | 5782 void _check_constEvalTypeBool_withParameter_binary(String expr) { |
5688 Source source = addSource(''' | 5783 Source source = addSource(''' |
5689 class A { | 5784 class A { |
5690 final a; | 5785 final a; |
5691 const A(bool p) : a = $expr; | 5786 const A(bool p) : a = $expr; |
5692 }'''); | 5787 }'''); |
5693 resolve(source); | 5788 computeLibrarySourceErrors(source); |
5694 assertErrors(source, [ | 5789 assertErrors(source, [ |
5695 CompileTimeErrorCode.CONST_EVAL_TYPE_BOOL, | 5790 CompileTimeErrorCode.CONST_EVAL_TYPE_BOOL, |
5696 StaticTypeWarningCode.NON_BOOL_OPERAND | 5791 StaticTypeWarningCode.NON_BOOL_OPERAND |
5697 ]); | 5792 ]); |
5698 verify([source]); | 5793 verify([source]); |
5699 reset(); | 5794 reset(); |
5700 } | 5795 } |
5701 | 5796 |
5702 void _check_constEvalTypeInt_withParameter_binary(String expr) { | 5797 void _check_constEvalTypeInt_withParameter_binary(String expr) { |
5703 Source source = addSource(''' | 5798 Source source = addSource(''' |
5704 class A { | 5799 class A { |
5705 final a; | 5800 final a; |
5706 const A(int p) : a = $expr; | 5801 const A(int p) : a = $expr; |
5707 }'''); | 5802 }'''); |
5708 resolve(source); | 5803 computeLibrarySourceErrors(source); |
5709 assertErrors(source, [ | 5804 assertErrors(source, [ |
5710 CompileTimeErrorCode.CONST_EVAL_TYPE_INT, | 5805 CompileTimeErrorCode.CONST_EVAL_TYPE_INT, |
5711 StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE | 5806 StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE |
5712 ]); | 5807 ]); |
5713 verify([source]); | 5808 verify([source]); |
5714 reset(); | 5809 reset(); |
5715 } | 5810 } |
5716 | 5811 |
5717 void _check_constEvalTypeNum_withParameter_binary(String expr) { | 5812 void _check_constEvalTypeNum_withParameter_binary(String expr) { |
5718 Source source = addSource(''' | 5813 Source source = addSource(''' |
5719 class A { | 5814 class A { |
5720 final a; | 5815 final a; |
5721 const A(num p) : a = $expr; | 5816 const A(num p) : a = $expr; |
5722 }'''); | 5817 }'''); |
5723 resolve(source); | 5818 computeLibrarySourceErrors(source); |
5724 assertErrors(source, [ | 5819 assertErrors(source, [ |
5725 CompileTimeErrorCode.CONST_EVAL_TYPE_NUM, | 5820 CompileTimeErrorCode.CONST_EVAL_TYPE_NUM, |
5726 StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE | 5821 StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE |
5727 ]); | 5822 ]); |
5728 verify([source]); | 5823 verify([source]); |
5729 reset(); | 5824 reset(); |
5730 } | 5825 } |
5731 | 5826 |
5732 void _check_wrongNumberOfParametersForOperator( | 5827 void _check_wrongNumberOfParametersForOperator( |
5733 String name, String parameters) { | 5828 String name, String parameters) { |
5734 Source source = addSource(''' | 5829 Source source = addSource(''' |
5735 class A { | 5830 class A { |
5736 operator $name($parameters) {} | 5831 operator $name($parameters) {} |
5737 }'''); | 5832 }'''); |
5738 resolve(source); | 5833 computeLibrarySourceErrors(source); |
5739 assertErrors( | 5834 assertErrors( |
5740 source, [CompileTimeErrorCode.WRONG_NUMBER_OF_PARAMETERS_FOR_OPERATOR]); | 5835 source, [CompileTimeErrorCode.WRONG_NUMBER_OF_PARAMETERS_FOR_OPERATOR]); |
5741 verify([source]); | 5836 verify([source]); |
5742 reset(); | 5837 reset(); |
5743 } | 5838 } |
5744 | 5839 |
5745 void _check_wrongNumberOfParametersForOperator1(String name) { | 5840 void _check_wrongNumberOfParametersForOperator1(String name) { |
5746 _check_wrongNumberOfParametersForOperator(name, ""); | 5841 _check_wrongNumberOfParametersForOperator(name, ""); |
5747 _check_wrongNumberOfParametersForOperator(name, "a, b"); | 5842 _check_wrongNumberOfParametersForOperator(name, "a, b"); |
5748 } | 5843 } |
5749 } | 5844 } |
OLD | NEW |