| OLD | NEW |
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 library analyzer.test.generated.non_hint_code_test; | 5 library analyzer.test.generated.non_hint_code_test; |
| 6 | 6 |
| 7 import 'package:analyzer/error/error.dart'; | 7 import 'package:analyzer/error/error.dart'; |
| 8 import 'package:analyzer/src/error/codes.dart'; | 8 import 'package:analyzer/src/error/codes.dart'; |
| 9 import 'package:analyzer/src/generated/engine.dart'; | 9 import 'package:analyzer/src/generated/engine.dart'; |
| 10 import 'package:analyzer/src/generated/source_io.dart'; | 10 import 'package:analyzer/src/generated/source_io.dart'; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 Source source = addSource(r''' | 25 Source source = addSource(r''' |
| 26 abstract class A { | 26 abstract class A { |
| 27 void test(); | 27 void test(); |
| 28 } | 28 } |
| 29 class B extends A { | 29 class B extends A { |
| 30 void test() { | 30 void test() { |
| 31 super.test; | 31 super.test; |
| 32 } | 32 } |
| 33 } | 33 } |
| 34 '''); | 34 '''); |
| 35 await assertNoErrors(source); | 35 await computeAnalysisResult(source); |
| 36 assertNoErrors(source); |
| 36 verify([source]); | 37 verify([source]); |
| 37 } | 38 } |
| 38 | 39 |
| 39 test_deadCode_afterTryCatch() async { | 40 test_deadCode_afterTryCatch() async { |
| 40 Source source = addSource(''' | 41 Source source = addSource(''' |
| 41 main() { | 42 main() { |
| 42 try { | 43 try { |
| 43 return f(); | 44 return f(); |
| 44 } catch (e) { | 45 } catch (e) { |
| 45 print(e); | 46 print(e); |
| 46 } | 47 } |
| 47 print('not dead'); | 48 print('not dead'); |
| 48 } | 49 } |
| 49 f() { | 50 f() { |
| 50 throw 'foo'; | 51 throw 'foo'; |
| 51 } | 52 } |
| 52 '''); | 53 '''); |
| 53 await assertNoErrors(source); | 54 await computeAnalysisResult(source); |
| 55 assertNoErrors(source); |
| 54 verify([source]); | 56 verify([source]); |
| 55 } | 57 } |
| 56 | 58 |
| 57 test_deadCode_deadBlock_conditionalElse_debugConst() async { | 59 test_deadCode_deadBlock_conditionalElse_debugConst() async { |
| 58 Source source = addSource(r''' | 60 Source source = addSource(r''' |
| 59 const bool DEBUG = true; | 61 const bool DEBUG = true; |
| 60 f() { | 62 f() { |
| 61 DEBUG ? 1 : 2; | 63 DEBUG ? 1 : 2; |
| 62 }'''); | 64 }'''); |
| 63 await assertNoErrors(source); | 65 await computeAnalysisResult(source); |
| 66 assertNoErrors(source); |
| 64 verify([source]); | 67 verify([source]); |
| 65 } | 68 } |
| 66 | 69 |
| 67 test_deadCode_deadBlock_conditionalIf_debugConst() async { | 70 test_deadCode_deadBlock_conditionalIf_debugConst() async { |
| 68 Source source = addSource(r''' | 71 Source source = addSource(r''' |
| 69 const bool DEBUG = false; | 72 const bool DEBUG = false; |
| 70 f() { | 73 f() { |
| 71 DEBUG ? 1 : 2; | 74 DEBUG ? 1 : 2; |
| 72 }'''); | 75 }'''); |
| 73 await assertNoErrors(source); | 76 await computeAnalysisResult(source); |
| 77 assertNoErrors(source); |
| 74 verify([source]); | 78 verify([source]); |
| 75 } | 79 } |
| 76 | 80 |
| 77 test_deadCode_deadBlock_else() async { | 81 test_deadCode_deadBlock_else() async { |
| 78 Source source = addSource(r''' | 82 Source source = addSource(r''' |
| 79 const bool DEBUG = true; | 83 const bool DEBUG = true; |
| 80 f() { | 84 f() { |
| 81 if(DEBUG) {} else {} | 85 if(DEBUG) {} else {} |
| 82 }'''); | 86 }'''); |
| 83 await assertNoErrors(source); | 87 await computeAnalysisResult(source); |
| 88 assertNoErrors(source); |
| 84 verify([source]); | 89 verify([source]); |
| 85 } | 90 } |
| 86 | 91 |
| 87 test_deadCode_deadBlock_if_debugConst_prefixedIdentifier() async { | 92 test_deadCode_deadBlock_if_debugConst_prefixedIdentifier() async { |
| 88 Source source = addSource(r''' | 93 Source source = addSource(r''' |
| 89 class A { | 94 class A { |
| 90 static const bool DEBUG = false; | 95 static const bool DEBUG = false; |
| 91 } | 96 } |
| 92 f() { | 97 f() { |
| 93 if(A.DEBUG) {} | 98 if(A.DEBUG) {} |
| 94 }'''); | 99 }'''); |
| 95 await assertNoErrors(source); | 100 await computeAnalysisResult(source); |
| 101 assertNoErrors(source); |
| 96 verify([source]); | 102 verify([source]); |
| 97 } | 103 } |
| 98 | 104 |
| 99 test_deadCode_deadBlock_if_debugConst_prefixedIdentifier2() async { | 105 test_deadCode_deadBlock_if_debugConst_prefixedIdentifier2() async { |
| 100 Source source = addSource(r''' | 106 Source source = addSource(r''' |
| 101 library L; | 107 library L; |
| 102 import 'lib2.dart'; | 108 import 'lib2.dart'; |
| 103 f() { | 109 f() { |
| 104 if(A.DEBUG) {} | 110 if(A.DEBUG) {} |
| 105 }'''); | 111 }'''); |
| 106 addNamedSource( | 112 addNamedSource( |
| 107 "/lib2.dart", | 113 "/lib2.dart", |
| 108 r''' | 114 r''' |
| 109 library lib2; | 115 library lib2; |
| 110 class A { | 116 class A { |
| 111 static const bool DEBUG = false; | 117 static const bool DEBUG = false; |
| 112 }'''); | 118 }'''); |
| 113 await assertNoErrors(source); | 119 await computeAnalysisResult(source); |
| 120 assertNoErrors(source); |
| 114 verify([source]); | 121 verify([source]); |
| 115 } | 122 } |
| 116 | 123 |
| 117 test_deadCode_deadBlock_if_debugConst_propertyAccessor() async { | 124 test_deadCode_deadBlock_if_debugConst_propertyAccessor() async { |
| 118 Source source = addSource(r''' | 125 Source source = addSource(r''' |
| 119 library L; | 126 library L; |
| 120 import 'lib2.dart' as LIB; | 127 import 'lib2.dart' as LIB; |
| 121 f() { | 128 f() { |
| 122 if(LIB.A.DEBUG) {} | 129 if(LIB.A.DEBUG) {} |
| 123 }'''); | 130 }'''); |
| 124 addNamedSource( | 131 addNamedSource( |
| 125 "/lib2.dart", | 132 "/lib2.dart", |
| 126 r''' | 133 r''' |
| 127 library lib2; | 134 library lib2; |
| 128 class A { | 135 class A { |
| 129 static const bool DEBUG = false; | 136 static const bool DEBUG = false; |
| 130 }'''); | 137 }'''); |
| 131 await assertNoErrors(source); | 138 await computeAnalysisResult(source); |
| 139 assertNoErrors(source); |
| 132 verify([source]); | 140 verify([source]); |
| 133 } | 141 } |
| 134 | 142 |
| 135 test_deadCode_deadBlock_if_debugConst_simpleIdentifier() async { | 143 test_deadCode_deadBlock_if_debugConst_simpleIdentifier() async { |
| 136 Source source = addSource(r''' | 144 Source source = addSource(r''' |
| 137 const bool DEBUG = false; | 145 const bool DEBUG = false; |
| 138 f() { | 146 f() { |
| 139 if(DEBUG) {} | 147 if(DEBUG) {} |
| 140 }'''); | 148 }'''); |
| 141 await assertNoErrors(source); | 149 await computeAnalysisResult(source); |
| 150 assertNoErrors(source); |
| 142 verify([source]); | 151 verify([source]); |
| 143 } | 152 } |
| 144 | 153 |
| 145 test_deadCode_deadBlock_while_debugConst() async { | 154 test_deadCode_deadBlock_while_debugConst() async { |
| 146 Source source = addSource(r''' | 155 Source source = addSource(r''' |
| 147 const bool DEBUG = false; | 156 const bool DEBUG = false; |
| 148 f() { | 157 f() { |
| 149 while(DEBUG) {} | 158 while(DEBUG) {} |
| 150 }'''); | 159 }'''); |
| 151 await assertNoErrors(source); | 160 await computeAnalysisResult(source); |
| 161 assertNoErrors(source); |
| 152 verify([source]); | 162 verify([source]); |
| 153 } | 163 } |
| 154 | 164 |
| 155 test_deadCode_deadCatch_onCatchSubtype() async { | 165 test_deadCode_deadCatch_onCatchSubtype() async { |
| 156 Source source = addSource(r''' | 166 Source source = addSource(r''' |
| 157 class A {} | 167 class A {} |
| 158 class B extends A {} | 168 class B extends A {} |
| 159 f() { | 169 f() { |
| 160 try {} on B catch (e) {} on A catch (e) {} catch (e) {} | 170 try {} on B catch (e) {} on A catch (e) {} catch (e) {} |
| 161 }'''); | 171 }'''); |
| 162 await assertNoErrors(source); | 172 await computeAnalysisResult(source); |
| 173 assertNoErrors(source); |
| 163 verify([source]); | 174 verify([source]); |
| 164 } | 175 } |
| 165 | 176 |
| 166 test_deadCode_deadFinalBreakInCase() async { | 177 test_deadCode_deadFinalBreakInCase() async { |
| 167 Source source = addSource(r''' | 178 Source source = addSource(r''' |
| 168 f() { | 179 f() { |
| 169 switch (true) { | 180 switch (true) { |
| 170 case true: | 181 case true: |
| 171 try { | 182 try { |
| 172 int a = 1; | 183 int a = 1; |
| 173 } finally { | 184 } finally { |
| 174 return; | 185 return; |
| 175 } | 186 } |
| 176 break; | 187 break; |
| 177 default: | 188 default: |
| 178 break; | 189 break; |
| 179 } | 190 } |
| 180 }'''); | 191 }'''); |
| 181 await assertNoErrors(source); | 192 await computeAnalysisResult(source); |
| 193 assertNoErrors(source); |
| 182 verify([source]); | 194 verify([source]); |
| 183 } | 195 } |
| 184 | 196 |
| 185 test_deadCode_deadOperandLHS_and_debugConst() async { | 197 test_deadCode_deadOperandLHS_and_debugConst() async { |
| 186 Source source = addSource(r''' | 198 Source source = addSource(r''' |
| 187 const bool DEBUG = false; | 199 const bool DEBUG = false; |
| 188 f() { | 200 f() { |
| 189 bool b = DEBUG && false; | 201 bool b = DEBUG && false; |
| 190 }'''); | 202 }'''); |
| 191 await assertNoErrors(source); | 203 await computeAnalysisResult(source); |
| 204 assertNoErrors(source); |
| 192 verify([source]); | 205 verify([source]); |
| 193 } | 206 } |
| 194 | 207 |
| 195 test_deadCode_deadOperandLHS_or_debugConst() async { | 208 test_deadCode_deadOperandLHS_or_debugConst() async { |
| 196 Source source = addSource(r''' | 209 Source source = addSource(r''' |
| 197 const bool DEBUG = true; | 210 const bool DEBUG = true; |
| 198 f() { | 211 f() { |
| 199 bool b = DEBUG || true; | 212 bool b = DEBUG || true; |
| 200 }'''); | 213 }'''); |
| 201 await assertNoErrors(source); | 214 await computeAnalysisResult(source); |
| 215 assertNoErrors(source); |
| 202 verify([source]); | 216 verify([source]); |
| 203 } | 217 } |
| 204 | 218 |
| 205 test_deadCode_statementAfterIfWithoutElse() async { | 219 test_deadCode_statementAfterIfWithoutElse() async { |
| 206 Source source = addSource(r''' | 220 Source source = addSource(r''' |
| 207 f() { | 221 f() { |
| 208 if (1 < 0) { | 222 if (1 < 0) { |
| 209 return; | 223 return; |
| 210 } | 224 } |
| 211 int a = 1; | 225 int a = 1; |
| 212 }'''); | 226 }'''); |
| 213 await assertNoErrors(source); | 227 await computeAnalysisResult(source); |
| 228 assertNoErrors(source); |
| 214 verify([source]); | 229 verify([source]); |
| 215 } | 230 } |
| 216 | 231 |
| 217 test_deprecatedMemberUse_inDeprecatedClass() async { | 232 test_deprecatedMemberUse_inDeprecatedClass() async { |
| 218 Source source = addSource(r''' | 233 Source source = addSource(r''' |
| 219 @deprecated | 234 @deprecated |
| 220 f() {} | 235 f() {} |
| 221 | 236 |
| 222 @deprecated | 237 @deprecated |
| 223 class C { | 238 class C { |
| 224 m() { | 239 m() { |
| 225 f(); | 240 f(); |
| 226 } | 241 } |
| 227 } | 242 } |
| 228 '''); | 243 '''); |
| 229 await assertNoErrors(source); | 244 await computeAnalysisResult(source); |
| 245 assertNoErrors(source); |
| 230 verify([source]); | 246 verify([source]); |
| 231 } | 247 } |
| 232 | 248 |
| 233 test_deprecatedMemberUse_inDeprecatedFunction() async { | 249 test_deprecatedMemberUse_inDeprecatedFunction() async { |
| 234 Source source = addSource(r''' | 250 Source source = addSource(r''' |
| 235 @deprecated | 251 @deprecated |
| 236 f() {} | 252 f() {} |
| 237 | 253 |
| 238 @deprecated | 254 @deprecated |
| 239 g() { | 255 g() { |
| 240 f(); | 256 f(); |
| 241 } | 257 } |
| 242 '''); | 258 '''); |
| 243 await assertNoErrors(source); | 259 await computeAnalysisResult(source); |
| 260 assertNoErrors(source); |
| 244 verify([source]); | 261 verify([source]); |
| 245 } | 262 } |
| 246 | 263 |
| 247 test_deprecatedMemberUse_inDeprecatedLibrary() async { | 264 test_deprecatedMemberUse_inDeprecatedLibrary() async { |
| 248 Source source = addSource(r''' | 265 Source source = addSource(r''' |
| 249 @deprecated | 266 @deprecated |
| 250 library lib; | 267 library lib; |
| 251 | 268 |
| 252 @deprecated | 269 @deprecated |
| 253 f() {} | 270 f() {} |
| 254 | 271 |
| 255 class C { | 272 class C { |
| 256 m() { | 273 m() { |
| 257 f(); | 274 f(); |
| 258 } | 275 } |
| 259 } | 276 } |
| 260 '''); | 277 '''); |
| 261 await assertNoErrors(source); | 278 await computeAnalysisResult(source); |
| 279 assertNoErrors(source); |
| 262 verify([source]); | 280 verify([source]); |
| 263 } | 281 } |
| 264 | 282 |
| 265 test_deprecatedMemberUse_inDeprecatedMethod() async { | 283 test_deprecatedMemberUse_inDeprecatedMethod() async { |
| 266 Source source = addSource(r''' | 284 Source source = addSource(r''' |
| 267 @deprecated | 285 @deprecated |
| 268 f() {} | 286 f() {} |
| 269 | 287 |
| 270 class C { | 288 class C { |
| 271 @deprecated | 289 @deprecated |
| 272 m() { | 290 m() { |
| 273 f(); | 291 f(); |
| 274 } | 292 } |
| 275 } | 293 } |
| 276 '''); | 294 '''); |
| 277 await assertNoErrors(source); | 295 await computeAnalysisResult(source); |
| 296 assertNoErrors(source); |
| 278 verify([source]); | 297 verify([source]); |
| 279 } | 298 } |
| 280 | 299 |
| 281 test_deprecatedMemberUse_inDeprecatedMethod_inDeprecatedClass() async { | 300 test_deprecatedMemberUse_inDeprecatedMethod_inDeprecatedClass() async { |
| 282 Source source = addSource(r''' | 301 Source source = addSource(r''' |
| 283 @deprecated | 302 @deprecated |
| 284 f() {} | 303 f() {} |
| 285 | 304 |
| 286 @deprecated | 305 @deprecated |
| 287 class C { | 306 class C { |
| 288 @deprecated | 307 @deprecated |
| 289 m() { | 308 m() { |
| 290 f(); | 309 f(); |
| 291 } | 310 } |
| 292 } | 311 } |
| 293 '''); | 312 '''); |
| 294 await assertNoErrors(source); | 313 await computeAnalysisResult(source); |
| 314 assertNoErrors(source); |
| 295 verify([source]); | 315 verify([source]); |
| 296 } | 316 } |
| 297 | 317 |
| 298 test_divisionOptimization() async { | 318 test_divisionOptimization() async { |
| 299 Source source = addSource(r''' | 319 Source source = addSource(r''' |
| 300 f(int x, int y) { | 320 f(int x, int y) { |
| 301 var v = x / y.toInt(); | 321 var v = x / y.toInt(); |
| 302 }'''); | 322 }'''); |
| 303 await assertNoErrors(source); | 323 await computeAnalysisResult(source); |
| 324 assertNoErrors(source); |
| 304 verify([source]); | 325 verify([source]); |
| 305 } | 326 } |
| 306 | 327 |
| 307 test_divisionOptimization_supressIfDivisionNotDefinedInCore() async { | 328 test_divisionOptimization_supressIfDivisionNotDefinedInCore() async { |
| 308 Source source = addSource(r''' | 329 Source source = addSource(r''' |
| 309 f(x, y) { | 330 f(x, y) { |
| 310 var v = (x / y).toInt(); | 331 var v = (x / y).toInt(); |
| 311 }'''); | 332 }'''); |
| 312 await assertNoErrors(source); | 333 await computeAnalysisResult(source); |
| 334 assertNoErrors(source); |
| 313 verify([source]); | 335 verify([source]); |
| 314 } | 336 } |
| 315 | 337 |
| 316 test_divisionOptimization_supressIfDivisionOverridden() async { | 338 test_divisionOptimization_supressIfDivisionOverridden() async { |
| 317 Source source = addSource(r''' | 339 Source source = addSource(r''' |
| 318 class A { | 340 class A { |
| 319 num operator /(x) { return x; } | 341 num operator /(x) { return x; } |
| 320 } | 342 } |
| 321 f(A x, A y) { | 343 f(A x, A y) { |
| 322 var v = (x / y).toInt(); | 344 var v = (x / y).toInt(); |
| 323 }'''); | 345 }'''); |
| 324 await assertNoErrors(source); | 346 await computeAnalysisResult(source); |
| 347 assertNoErrors(source); |
| 325 verify([source]); | 348 verify([source]); |
| 326 } | 349 } |
| 327 | 350 |
| 328 test_duplicateImport_as() async { | 351 test_duplicateImport_as() async { |
| 329 Source source = addSource(r''' | 352 Source source = addSource(r''' |
| 330 library L; | 353 library L; |
| 331 import 'lib1.dart'; | 354 import 'lib1.dart'; |
| 332 import 'lib1.dart' as one; | 355 import 'lib1.dart' as one; |
| 333 A a; | 356 A a; |
| 334 one.A a2;'''); | 357 one.A a2;'''); |
| 335 addNamedSource( | 358 addNamedSource( |
| 336 "/lib1.dart", | 359 "/lib1.dart", |
| 337 r''' | 360 r''' |
| 338 library lib1; | 361 library lib1; |
| 339 class A {}'''); | 362 class A {}'''); |
| 340 await assertNoErrors(source); | 363 await computeAnalysisResult(source); |
| 364 assertNoErrors(source); |
| 341 verify([source]); | 365 verify([source]); |
| 342 } | 366 } |
| 343 | 367 |
| 344 test_duplicateImport_hide() async { | 368 test_duplicateImport_hide() async { |
| 345 Source source = addSource(r''' | 369 Source source = addSource(r''' |
| 346 library L; | 370 library L; |
| 347 import 'lib1.dart'; | 371 import 'lib1.dart'; |
| 348 import 'lib1.dart' hide A; | 372 import 'lib1.dart' hide A; |
| 349 A a; | 373 A a; |
| 350 B b;'''); | 374 B b;'''); |
| 351 addNamedSource( | 375 addNamedSource( |
| 352 "/lib1.dart", | 376 "/lib1.dart", |
| 353 r''' | 377 r''' |
| 354 library lib1; | 378 library lib1; |
| 355 class A {} | 379 class A {} |
| 356 class B {}'''); | 380 class B {}'''); |
| 357 await assertNoErrors(source); | 381 await computeAnalysisResult(source); |
| 382 assertNoErrors(source); |
| 358 verify([source]); | 383 verify([source]); |
| 359 } | 384 } |
| 360 | 385 |
| 361 test_duplicateImport_show() async { | 386 test_duplicateImport_show() async { |
| 362 Source source = addSource(r''' | 387 Source source = addSource(r''' |
| 363 library L; | 388 library L; |
| 364 import 'lib1.dart'; | 389 import 'lib1.dart'; |
| 365 import 'lib1.dart' show A; | 390 import 'lib1.dart' show A; |
| 366 A a; | 391 A a; |
| 367 B b;'''); | 392 B b;'''); |
| 368 addNamedSource( | 393 addNamedSource( |
| 369 "/lib1.dart", | 394 "/lib1.dart", |
| 370 r''' | 395 r''' |
| 371 library lib1; | 396 library lib1; |
| 372 class A {} | 397 class A {} |
| 373 class B {}'''); | 398 class B {}'''); |
| 374 await assertNoErrors(source); | 399 await computeAnalysisResult(source); |
| 400 assertNoErrors(source); |
| 375 verify([source]); | 401 verify([source]); |
| 376 } | 402 } |
| 377 | 403 |
| 378 test_importDeferredLibraryWithLoadFunction() async { | 404 test_importDeferredLibraryWithLoadFunction() async { |
| 379 await resolveWithErrors(<String>[ | 405 await resolveWithErrors(<String>[ |
| 380 r''' | 406 r''' |
| 381 library lib1; | 407 library lib1; |
| 382 f() {}''', | 408 f() {}''', |
| 383 r''' | 409 r''' |
| 384 library root; | 410 library root; |
| 385 import 'lib1.dart' deferred as lib1; | 411 import 'lib1.dart' deferred as lib1; |
| 386 main() { lib1.f(); }''' | 412 main() { lib1.f(); }''' |
| 387 ], const <ErrorCode>[]); | 413 ], const <ErrorCode>[]); |
| 388 } | 414 } |
| 389 | 415 |
| 390 test_issue20904BuggyTypePromotionAtIfJoin_1() async { | 416 test_issue20904BuggyTypePromotionAtIfJoin_1() async { |
| 391 // https://code.google.com/p/dart/issues/detail?id=20904 | 417 // https://code.google.com/p/dart/issues/detail?id=20904 |
| 392 Source source = addSource(r''' | 418 Source source = addSource(r''' |
| 393 f(var message, var dynamic_) { | 419 f(var message, var dynamic_) { |
| 394 if (message is Function) { | 420 if (message is Function) { |
| 395 message = dynamic_; | 421 message = dynamic_; |
| 396 } | 422 } |
| 397 int s = message; | 423 int s = message; |
| 398 }'''); | 424 }'''); |
| 399 await assertNoErrors(source); | 425 await computeAnalysisResult(source); |
| 426 assertNoErrors(source); |
| 400 verify([source]); | 427 verify([source]); |
| 401 } | 428 } |
| 402 | 429 |
| 403 test_issue20904BuggyTypePromotionAtIfJoin_3() async { | 430 test_issue20904BuggyTypePromotionAtIfJoin_3() async { |
| 404 // https://code.google.com/p/dart/issues/detail?id=20904 | 431 // https://code.google.com/p/dart/issues/detail?id=20904 |
| 405 Source source = addSource(r''' | 432 Source source = addSource(r''' |
| 406 f(var message) { | 433 f(var message) { |
| 407 var dynamic_; | 434 var dynamic_; |
| 408 if (message is Function) { | 435 if (message is Function) { |
| 409 message = dynamic_; | 436 message = dynamic_; |
| 410 } else { | 437 } else { |
| 411 return; | 438 return; |
| 412 } | 439 } |
| 413 int s = message; | 440 int s = message; |
| 414 }'''); | 441 }'''); |
| 415 await assertNoErrors(source); | 442 await computeAnalysisResult(source); |
| 443 assertNoErrors(source); |
| 416 verify([source]); | 444 verify([source]); |
| 417 } | 445 } |
| 418 | 446 |
| 419 test_issue20904BuggyTypePromotionAtIfJoin_4() async { | 447 test_issue20904BuggyTypePromotionAtIfJoin_4() async { |
| 420 // https://code.google.com/p/dart/issues/detail?id=20904 | 448 // https://code.google.com/p/dart/issues/detail?id=20904 |
| 421 Source source = addSource(r''' | 449 Source source = addSource(r''' |
| 422 f(var message) { | 450 f(var message) { |
| 423 if (message is Function) { | 451 if (message is Function) { |
| 424 message = ''; | 452 message = ''; |
| 425 } else { | 453 } else { |
| 426 return; | 454 return; |
| 427 } | 455 } |
| 428 String s = message; | 456 String s = message; |
| 429 }'''); | 457 }'''); |
| 430 await assertNoErrors(source); | 458 await computeAnalysisResult(source); |
| 459 assertNoErrors(source); |
| 431 verify([source]); | 460 verify([source]); |
| 432 } | 461 } |
| 433 | 462 |
| 434 test_missingReturn_emptyFunctionBody() async { | 463 test_missingReturn_emptyFunctionBody() async { |
| 435 Source source = addSource(r''' | 464 Source source = addSource(r''' |
| 436 abstract class A { | 465 abstract class A { |
| 437 int m(); | 466 int m(); |
| 438 }'''); | 467 }'''); |
| 439 await assertNoErrors(source); | 468 await computeAnalysisResult(source); |
| 469 assertNoErrors(source); |
| 440 verify([source]); | 470 verify([source]); |
| 441 } | 471 } |
| 442 | 472 |
| 443 test_missingReturn_expressionFunctionBody() async { | 473 test_missingReturn_expressionFunctionBody() async { |
| 444 Source source = addSource("int f() => 0;"); | 474 Source source = addSource("int f() => 0;"); |
| 445 await assertNoErrors(source); | 475 await computeAnalysisResult(source); |
| 476 assertNoErrors(source); |
| 446 verify([source]); | 477 verify([source]); |
| 447 } | 478 } |
| 448 | 479 |
| 449 test_missingReturn_noReturnType() async { | 480 test_missingReturn_noReturnType() async { |
| 450 Source source = addSource("f() {}"); | 481 Source source = addSource("f() {}"); |
| 451 await assertNoErrors(source); | 482 await computeAnalysisResult(source); |
| 483 assertNoErrors(source); |
| 452 verify([source]); | 484 verify([source]); |
| 453 } | 485 } |
| 454 | 486 |
| 455 test_missingReturn_voidReturnType() async { | 487 test_missingReturn_voidReturnType() async { |
| 456 Source source = addSource("void f() {}"); | 488 Source source = addSource("void f() {}"); |
| 457 await assertNoErrors(source); | 489 await computeAnalysisResult(source); |
| 490 assertNoErrors(source); |
| 458 verify([source]); | 491 verify([source]); |
| 459 } | 492 } |
| 460 | 493 |
| 461 test_nullAwareInCondition_for_noCondition() async { | 494 test_nullAwareInCondition_for_noCondition() async { |
| 462 Source source = addSource(r''' | 495 Source source = addSource(r''' |
| 463 m(x) { | 496 m(x) { |
| 464 for (var v = x; ; v++) {} | 497 for (var v = x; ; v++) {} |
| 465 } | 498 } |
| 466 '''); | 499 '''); |
| 467 await assertNoErrors(source); | 500 await computeAnalysisResult(source); |
| 501 assertNoErrors(source); |
| 468 verify([source]); | 502 verify([source]); |
| 469 } | 503 } |
| 470 | 504 |
| 471 test_nullAwareInCondition_if_notTopLevel() async { | 505 test_nullAwareInCondition_if_notTopLevel() async { |
| 472 Source source = addSource(r''' | 506 Source source = addSource(r''' |
| 473 m(x) { | 507 m(x) { |
| 474 if (x?.y == null) {} | 508 if (x?.y == null) {} |
| 475 } | 509 } |
| 476 '''); | 510 '''); |
| 477 await assertNoErrors(source); | 511 await computeAnalysisResult(source); |
| 512 assertNoErrors(source); |
| 478 verify([source]); | 513 verify([source]); |
| 479 } | 514 } |
| 480 | 515 |
| 481 test_overrideEqualsButNotHashCode() async { | 516 test_overrideEqualsButNotHashCode() async { |
| 482 Source source = addSource(r''' | 517 Source source = addSource(r''' |
| 483 class A { | 518 class A { |
| 484 bool operator ==(x) { return x; } | 519 bool operator ==(x) { return x; } |
| 485 get hashCode => 0; | 520 get hashCode => 0; |
| 486 }'''); | 521 }'''); |
| 487 await assertNoErrors(source); | 522 await computeAnalysisResult(source); |
| 523 assertNoErrors(source); |
| 488 verify([source]); | 524 verify([source]); |
| 489 } | 525 } |
| 490 | 526 |
| 491 test_overrideOnNonOverridingField_inInterface() async { | 527 test_overrideOnNonOverridingField_inInterface() async { |
| 492 Source source = addSource(r''' | 528 Source source = addSource(r''' |
| 493 class A { | 529 class A { |
| 494 int get a => 0; | 530 int get a => 0; |
| 495 void set b(_) {} | 531 void set b(_) {} |
| 496 int c; | 532 int c; |
| 497 } | 533 } |
| 498 class B implements A { | 534 class B implements A { |
| 499 @override | 535 @override |
| 500 final int a = 1; | 536 final int a = 1; |
| 501 @override | 537 @override |
| 502 int b; | 538 int b; |
| 503 @override | 539 @override |
| 504 int c; | 540 int c; |
| 505 }'''); | 541 }'''); |
| 506 await assertNoErrors(source); | 542 await computeAnalysisResult(source); |
| 543 assertNoErrors(source); |
| 507 verify([source]); | 544 verify([source]); |
| 508 } | 545 } |
| 509 | 546 |
| 510 test_overrideOnNonOverridingField_inSuperclass() async { | 547 test_overrideOnNonOverridingField_inSuperclass() async { |
| 511 Source source = addSource(r''' | 548 Source source = addSource(r''' |
| 512 class A { | 549 class A { |
| 513 int get a => 0; | 550 int get a => 0; |
| 514 void set b(_) {} | 551 void set b(_) {} |
| 515 int c; | 552 int c; |
| 516 } | 553 } |
| 517 class B extends A { | 554 class B extends A { |
| 518 @override | 555 @override |
| 519 final int a = 1; | 556 final int a = 1; |
| 520 @override | 557 @override |
| 521 int b; | 558 int b; |
| 522 @override | 559 @override |
| 523 int c; | 560 int c; |
| 524 }'''); | 561 }'''); |
| 525 await assertNoErrors(source); | 562 await computeAnalysisResult(source); |
| 563 assertNoErrors(source); |
| 526 verify([source]); | 564 verify([source]); |
| 527 } | 565 } |
| 528 | 566 |
| 529 test_overrideOnNonOverridingGetter_inInterface() async { | 567 test_overrideOnNonOverridingGetter_inInterface() async { |
| 530 Source source = addSource(r''' | 568 Source source = addSource(r''' |
| 531 class A { | 569 class A { |
| 532 int get m => 0; | 570 int get m => 0; |
| 533 } | 571 } |
| 534 class B implements A { | 572 class B implements A { |
| 535 @override | 573 @override |
| 536 int get m => 1; | 574 int get m => 1; |
| 537 }'''); | 575 }'''); |
| 538 await assertNoErrors(source); | 576 await computeAnalysisResult(source); |
| 577 assertNoErrors(source); |
| 539 verify([source]); | 578 verify([source]); |
| 540 } | 579 } |
| 541 | 580 |
| 542 test_overrideOnNonOverridingGetter_inSuperclass() async { | 581 test_overrideOnNonOverridingGetter_inSuperclass() async { |
| 543 Source source = addSource(r''' | 582 Source source = addSource(r''' |
| 544 class A { | 583 class A { |
| 545 int get m => 0; | 584 int get m => 0; |
| 546 } | 585 } |
| 547 class B extends A { | 586 class B extends A { |
| 548 @override | 587 @override |
| 549 int get m => 1; | 588 int get m => 1; |
| 550 }'''); | 589 }'''); |
| 551 await assertNoErrors(source); | 590 await computeAnalysisResult(source); |
| 591 assertNoErrors(source); |
| 552 verify([source]); | 592 verify([source]); |
| 553 } | 593 } |
| 554 | 594 |
| 555 test_overrideOnNonOverridingMethod_inInterface() async { | 595 test_overrideOnNonOverridingMethod_inInterface() async { |
| 556 Source source = addSource(r''' | 596 Source source = addSource(r''' |
| 557 class A { | 597 class A { |
| 558 int m() => 0; | 598 int m() => 0; |
| 559 } | 599 } |
| 560 class B implements A { | 600 class B implements A { |
| 561 @override | 601 @override |
| 562 int m() => 1; | 602 int m() => 1; |
| 563 }'''); | 603 }'''); |
| 564 await assertNoErrors(source); | 604 await computeAnalysisResult(source); |
| 605 assertNoErrors(source); |
| 565 verify([source]); | 606 verify([source]); |
| 566 } | 607 } |
| 567 | 608 |
| 568 test_overrideOnNonOverridingMethod_inSuperclass() async { | 609 test_overrideOnNonOverridingMethod_inSuperclass() async { |
| 569 Source source = addSource(r''' | 610 Source source = addSource(r''' |
| 570 class A { | 611 class A { |
| 571 int m() => 0; | 612 int m() => 0; |
| 572 } | 613 } |
| 573 class B extends A { | 614 class B extends A { |
| 574 @override | 615 @override |
| 575 int m() => 1; | 616 int m() => 1; |
| 576 }'''); | 617 }'''); |
| 577 await assertNoErrors(source); | 618 await computeAnalysisResult(source); |
| 619 assertNoErrors(source); |
| 578 verify([source]); | 620 verify([source]); |
| 579 } | 621 } |
| 580 | 622 |
| 581 test_overrideOnNonOverridingMethod_inSuperclass_abstract() async { | 623 test_overrideOnNonOverridingMethod_inSuperclass_abstract() async { |
| 582 Source source = addSource(r''' | 624 Source source = addSource(r''' |
| 583 abstract class A { | 625 abstract class A { |
| 584 int m(); | 626 int m(); |
| 585 } | 627 } |
| 586 class B extends A { | 628 class B extends A { |
| 587 @override | 629 @override |
| 588 int m() => 1; | 630 int m() => 1; |
| 589 }'''); | 631 }'''); |
| 590 await assertNoErrors(source); | 632 await computeAnalysisResult(source); |
| 633 assertNoErrors(source); |
| 591 verify([source]); | 634 verify([source]); |
| 592 } | 635 } |
| 593 | 636 |
| 594 test_overrideOnNonOverridingSetter_inInterface() async { | 637 test_overrideOnNonOverridingSetter_inInterface() async { |
| 595 Source source = addSource(r''' | 638 Source source = addSource(r''' |
| 596 class A { | 639 class A { |
| 597 set m(int x) {} | 640 set m(int x) {} |
| 598 } | 641 } |
| 599 class B implements A { | 642 class B implements A { |
| 600 @override | 643 @override |
| 601 set m(int x) {} | 644 set m(int x) {} |
| 602 }'''); | 645 }'''); |
| 603 await assertNoErrors(source); | 646 await computeAnalysisResult(source); |
| 647 assertNoErrors(source); |
| 604 verify([source]); | 648 verify([source]); |
| 605 } | 649 } |
| 606 | 650 |
| 607 test_overrideOnNonOverridingSetter_inSuperclass() async { | 651 test_overrideOnNonOverridingSetter_inSuperclass() async { |
| 608 Source source = addSource(r''' | 652 Source source = addSource(r''' |
| 609 class A { | 653 class A { |
| 610 set m(int x) {} | 654 set m(int x) {} |
| 611 } | 655 } |
| 612 class B extends A { | 656 class B extends A { |
| 613 @override | 657 @override |
| 614 set m(int x) {} | 658 set m(int x) {} |
| 615 }'''); | 659 }'''); |
| 616 await assertNoErrors(source); | 660 await computeAnalysisResult(source); |
| 661 assertNoErrors(source); |
| 617 verify([source]); | 662 verify([source]); |
| 618 } | 663 } |
| 619 | 664 |
| 620 test_propagatedFieldType() async { | 665 test_propagatedFieldType() async { |
| 621 Source source = addSource(r''' | 666 Source source = addSource(r''' |
| 622 class A { } | 667 class A { } |
| 623 class X<T> { | 668 class X<T> { |
| 624 final x = new List<T>(); | 669 final x = new List<T>(); |
| 625 } | 670 } |
| 626 class Z { | 671 class Z { |
| 627 final X<A> y = new X<A>(); | 672 final X<A> y = new X<A>(); |
| 628 foo() { | 673 foo() { |
| 629 y.x.add(new A()); | 674 y.x.add(new A()); |
| 630 } | 675 } |
| 631 }'''); | 676 }'''); |
| 632 await assertNoErrors(source); | 677 await computeAnalysisResult(source); |
| 678 assertNoErrors(source); |
| 633 verify([source]); | 679 verify([source]); |
| 634 } | 680 } |
| 635 | 681 |
| 636 test_proxy_annotation_prefixed() async { | 682 test_proxy_annotation_prefixed() async { |
| 637 Source source = addSource(r''' | 683 Source source = addSource(r''' |
| 638 library L; | 684 library L; |
| 639 @proxy | 685 @proxy |
| 640 class A {} | 686 class A {} |
| 641 f(var a) { | 687 f(var a) { |
| 642 a = new A(); | 688 a = new A(); |
| 643 a.m(); | 689 a.m(); |
| 644 var x = a.g; | 690 var x = a.g; |
| 645 a.s = 1; | 691 a.s = 1; |
| 646 var y = a + a; | 692 var y = a + a; |
| 647 a++; | 693 a++; |
| 648 ++a; | 694 ++a; |
| 649 }'''); | 695 }'''); |
| 650 await assertNoErrors(source); | 696 await computeAnalysisResult(source); |
| 697 assertNoErrors(source); |
| 651 } | 698 } |
| 652 | 699 |
| 653 test_proxy_annotation_prefixed2() async { | 700 test_proxy_annotation_prefixed2() async { |
| 654 Source source = addSource(r''' | 701 Source source = addSource(r''' |
| 655 library L; | 702 library L; |
| 656 @proxy | 703 @proxy |
| 657 class A {} | 704 class A {} |
| 658 class B { | 705 class B { |
| 659 f(var a) { | 706 f(var a) { |
| 660 a = new A(); | 707 a = new A(); |
| 661 a.m(); | 708 a.m(); |
| 662 var x = a.g; | 709 var x = a.g; |
| 663 a.s = 1; | 710 a.s = 1; |
| 664 var y = a + a; | 711 var y = a + a; |
| 665 a++; | 712 a++; |
| 666 ++a; | 713 ++a; |
| 667 } | 714 } |
| 668 }'''); | 715 }'''); |
| 669 await assertNoErrors(source); | 716 await computeAnalysisResult(source); |
| 717 assertNoErrors(source); |
| 670 } | 718 } |
| 671 | 719 |
| 672 test_proxy_annotation_prefixed3() async { | 720 test_proxy_annotation_prefixed3() async { |
| 673 Source source = addSource(r''' | 721 Source source = addSource(r''' |
| 674 library L; | 722 library L; |
| 675 class B { | 723 class B { |
| 676 f(var a) { | 724 f(var a) { |
| 677 a = new A(); | 725 a = new A(); |
| 678 a.m(); | 726 a.m(); |
| 679 var x = a.g; | 727 var x = a.g; |
| 680 a.s = 1; | 728 a.s = 1; |
| 681 var y = a + a; | 729 var y = a + a; |
| 682 a++; | 730 a++; |
| 683 ++a; | 731 ++a; |
| 684 } | 732 } |
| 685 } | 733 } |
| 686 @proxy | 734 @proxy |
| 687 class A {}'''); | 735 class A {}'''); |
| 688 await assertNoErrors(source); | 736 await computeAnalysisResult(source); |
| 737 assertNoErrors(source); |
| 689 } | 738 } |
| 690 | 739 |
| 691 test_undefinedGetter_inSubtype() async { | 740 test_undefinedGetter_inSubtype() async { |
| 692 Source source = addSource(r''' | 741 Source source = addSource(r''' |
| 693 class A {} | 742 class A {} |
| 694 class B extends A { | 743 class B extends A { |
| 695 get b => 0; | 744 get b => 0; |
| 696 } | 745 } |
| 697 f(var a) { | 746 f(var a) { |
| 698 if(a is A) { | 747 if(a is A) { |
| 699 return a.b; | 748 return a.b; |
| 700 } | 749 } |
| 701 }'''); | 750 }'''); |
| 702 await assertNoErrors(source); | 751 await computeAnalysisResult(source); |
| 752 assertNoErrors(source); |
| 703 } | 753 } |
| 704 | 754 |
| 705 test_undefinedMethod_assignmentExpression_inSubtype() async { | 755 test_undefinedMethod_assignmentExpression_inSubtype() async { |
| 706 Source source = addSource(r''' | 756 Source source = addSource(r''' |
| 707 class A {} | 757 class A {} |
| 708 class B extends A { | 758 class B extends A { |
| 709 operator +(B b) {return new B();} | 759 operator +(B b) {return new B();} |
| 710 } | 760 } |
| 711 f(var a, var a2) { | 761 f(var a, var a2) { |
| 712 a = new A(); | 762 a = new A(); |
| 713 a2 = new A(); | 763 a2 = new A(); |
| 714 a += a2; | 764 a += a2; |
| 715 }'''); | 765 }'''); |
| 716 await assertNoErrors(source); | 766 await computeAnalysisResult(source); |
| 767 assertNoErrors(source); |
| 717 } | 768 } |
| 718 | 769 |
| 719 test_undefinedMethod_dynamic() async { | 770 test_undefinedMethod_dynamic() async { |
| 720 Source source = addSource(r''' | 771 Source source = addSource(r''' |
| 721 class D<T extends dynamic> { | 772 class D<T extends dynamic> { |
| 722 fieldAccess(T t) => t.abc; | 773 fieldAccess(T t) => t.abc; |
| 723 methodAccess(T t) => t.xyz(1, 2, 'three'); | 774 methodAccess(T t) => t.xyz(1, 2, 'three'); |
| 724 }'''); | 775 }'''); |
| 725 await assertNoErrors(source); | 776 await computeAnalysisResult(source); |
| 777 assertNoErrors(source); |
| 726 } | 778 } |
| 727 | 779 |
| 728 test_undefinedMethod_inSubtype() async { | 780 test_undefinedMethod_inSubtype() async { |
| 729 Source source = addSource(r''' | 781 Source source = addSource(r''' |
| 730 class A {} | 782 class A {} |
| 731 class B extends A { | 783 class B extends A { |
| 732 b() {} | 784 b() {} |
| 733 } | 785 } |
| 734 f() { | 786 f() { |
| 735 var a = new A(); | 787 var a = new A(); |
| 736 a.b(); | 788 a.b(); |
| 737 }'''); | 789 }'''); |
| 738 await assertNoErrors(source); | 790 await computeAnalysisResult(source); |
| 791 assertNoErrors(source); |
| 739 } | 792 } |
| 740 | 793 |
| 741 test_undefinedMethod_unionType_all() async { | 794 test_undefinedMethod_unionType_all() async { |
| 742 Source source = addSource(r''' | 795 Source source = addSource(r''' |
| 743 class A { | 796 class A { |
| 744 int m(int x) => 0; | 797 int m(int x) => 0; |
| 745 } | 798 } |
| 746 class B { | 799 class B { |
| 747 String m() => '0'; | 800 String m() => '0'; |
| 748 } | 801 } |
| 749 f(A a, B b) { | 802 f(A a, B b) { |
| 750 var ab; | 803 var ab; |
| 751 if (0 < 1) { | 804 if (0 < 1) { |
| 752 ab = a; | 805 ab = a; |
| 753 } else { | 806 } else { |
| 754 ab = b; | 807 ab = b; |
| 755 } | 808 } |
| 756 ab.m(); | 809 ab.m(); |
| 757 }'''); | 810 }'''); |
| 758 await assertNoErrors(source); | 811 await computeAnalysisResult(source); |
| 812 assertNoErrors(source); |
| 759 } | 813 } |
| 760 | 814 |
| 761 test_undefinedMethod_unionType_some() async { | 815 test_undefinedMethod_unionType_some() async { |
| 762 Source source = addSource(r''' | 816 Source source = addSource(r''' |
| 763 class A { | 817 class A { |
| 764 int m(int x) => 0; | 818 int m(int x) => 0; |
| 765 } | 819 } |
| 766 class B {} | 820 class B {} |
| 767 f(A a, B b) { | 821 f(A a, B b) { |
| 768 var ab; | 822 var ab; |
| 769 if (0 < 1) { | 823 if (0 < 1) { |
| 770 ab = a; | 824 ab = a; |
| 771 } else { | 825 } else { |
| 772 ab = b; | 826 ab = b; |
| 773 } | 827 } |
| 774 ab.m(0); | 828 ab.m(0); |
| 775 }'''); | 829 }'''); |
| 776 await assertNoErrors(source); | 830 await computeAnalysisResult(source); |
| 831 assertNoErrors(source); |
| 777 } | 832 } |
| 778 | 833 |
| 779 test_undefinedOperator_binaryExpression_inSubtype() async { | 834 test_undefinedOperator_binaryExpression_inSubtype() async { |
| 780 Source source = addSource(r''' | 835 Source source = addSource(r''' |
| 781 class A {} | 836 class A {} |
| 782 class B extends A { | 837 class B extends A { |
| 783 operator +(B b) {} | 838 operator +(B b) {} |
| 784 } | 839 } |
| 785 f(var a) { | 840 f(var a) { |
| 786 if(a is A) { | 841 if(a is A) { |
| 787 a + 1; | 842 a + 1; |
| 788 } | 843 } |
| 789 }'''); | 844 }'''); |
| 790 await assertNoErrors(source); | 845 await computeAnalysisResult(source); |
| 846 assertNoErrors(source); |
| 791 } | 847 } |
| 792 | 848 |
| 793 test_undefinedOperator_indexBoth_inSubtype() async { | 849 test_undefinedOperator_indexBoth_inSubtype() async { |
| 794 Source source = addSource(r''' | 850 Source source = addSource(r''' |
| 795 class A {} | 851 class A {} |
| 796 class B extends A { | 852 class B extends A { |
| 797 operator [](int index) {} | 853 operator [](int index) {} |
| 798 } | 854 } |
| 799 f(var a) { | 855 f(var a) { |
| 800 if(a is A) { | 856 if(a is A) { |
| 801 a[0]++; | 857 a[0]++; |
| 802 } | 858 } |
| 803 }'''); | 859 }'''); |
| 804 await assertNoErrors(source); | 860 await computeAnalysisResult(source); |
| 861 assertNoErrors(source); |
| 805 } | 862 } |
| 806 | 863 |
| 807 test_undefinedOperator_indexGetter_inSubtype() async { | 864 test_undefinedOperator_indexGetter_inSubtype() async { |
| 808 Source source = addSource(r''' | 865 Source source = addSource(r''' |
| 809 class A {} | 866 class A {} |
| 810 class B extends A { | 867 class B extends A { |
| 811 operator [](int index) {} | 868 operator [](int index) {} |
| 812 } | 869 } |
| 813 f(var a) { | 870 f(var a) { |
| 814 if(a is A) { | 871 if(a is A) { |
| 815 a[0]; | 872 a[0]; |
| 816 } | 873 } |
| 817 }'''); | 874 }'''); |
| 818 await assertNoErrors(source); | 875 await computeAnalysisResult(source); |
| 876 assertNoErrors(source); |
| 819 } | 877 } |
| 820 | 878 |
| 821 test_undefinedOperator_indexSetter_inSubtype() async { | 879 test_undefinedOperator_indexSetter_inSubtype() async { |
| 822 Source source = addSource(r''' | 880 Source source = addSource(r''' |
| 823 class A {} | 881 class A {} |
| 824 class B extends A { | 882 class B extends A { |
| 825 operator []=(i, v) {} | 883 operator []=(i, v) {} |
| 826 } | 884 } |
| 827 f(var a) { | 885 f(var a) { |
| 828 if(a is A) { | 886 if(a is A) { |
| 829 a[0] = 1; | 887 a[0] = 1; |
| 830 } | 888 } |
| 831 }'''); | 889 }'''); |
| 832 await assertNoErrors(source); | 890 await computeAnalysisResult(source); |
| 891 assertNoErrors(source); |
| 833 } | 892 } |
| 834 | 893 |
| 835 test_undefinedOperator_postfixExpression() async { | 894 test_undefinedOperator_postfixExpression() async { |
| 836 Source source = addSource(r''' | 895 Source source = addSource(r''' |
| 837 class A {} | 896 class A {} |
| 838 class B extends A { | 897 class B extends A { |
| 839 operator +(B b) {return new B();} | 898 operator +(B b) {return new B();} |
| 840 } | 899 } |
| 841 f(var a) { | 900 f(var a) { |
| 842 if(a is A) { | 901 if(a is A) { |
| 843 a++; | 902 a++; |
| 844 } | 903 } |
| 845 }'''); | 904 }'''); |
| 846 await assertNoErrors(source); | 905 await computeAnalysisResult(source); |
| 906 assertNoErrors(source); |
| 847 } | 907 } |
| 848 | 908 |
| 849 test_undefinedOperator_prefixExpression() async { | 909 test_undefinedOperator_prefixExpression() async { |
| 850 Source source = addSource(r''' | 910 Source source = addSource(r''' |
| 851 class A {} | 911 class A {} |
| 852 class B extends A { | 912 class B extends A { |
| 853 operator +(B b) {return new B();} | 913 operator +(B b) {return new B();} |
| 854 } | 914 } |
| 855 f(var a) { | 915 f(var a) { |
| 856 if(a is A) { | 916 if(a is A) { |
| 857 ++a; | 917 ++a; |
| 858 } | 918 } |
| 859 }'''); | 919 }'''); |
| 860 await assertNoErrors(source); | 920 await computeAnalysisResult(source); |
| 921 assertNoErrors(source); |
| 861 } | 922 } |
| 862 | 923 |
| 863 test_undefinedSetter_inSubtype() async { | 924 test_undefinedSetter_inSubtype() async { |
| 864 Source source = addSource(r''' | 925 Source source = addSource(r''' |
| 865 class A {} | 926 class A {} |
| 866 class B extends A { | 927 class B extends A { |
| 867 set b(x) {} | 928 set b(x) {} |
| 868 } | 929 } |
| 869 f(var a) { | 930 f(var a) { |
| 870 if(a is A) { | 931 if(a is A) { |
| 871 a.b = 0; | 932 a.b = 0; |
| 872 } | 933 } |
| 873 }'''); | 934 }'''); |
| 874 await assertNoErrors(source); | 935 await computeAnalysisResult(source); |
| 936 assertNoErrors(source); |
| 875 } | 937 } |
| 876 | 938 |
| 877 test_unnecessaryCast_13855_parameter_A() async { | 939 test_unnecessaryCast_13855_parameter_A() async { |
| 878 // dartbug.com/13855, dartbug.com/13732 | 940 // dartbug.com/13855, dartbug.com/13732 |
| 879 Source source = addSource(r''' | 941 Source source = addSource(r''' |
| 880 class A{ | 942 class A{ |
| 881 a() {} | 943 a() {} |
| 882 } | 944 } |
| 883 class B<E> { | 945 class B<E> { |
| 884 E e; | 946 E e; |
| 885 m() { | 947 m() { |
| 886 (e as A).a(); | 948 (e as A).a(); |
| 887 } | 949 } |
| 888 }'''); | 950 }'''); |
| 889 await assertNoErrors(source); | 951 await computeAnalysisResult(source); |
| 952 assertNoErrors(source); |
| 890 verify([source]); | 953 verify([source]); |
| 891 } | 954 } |
| 892 | 955 |
| 893 test_unnecessaryCast_conditionalExpression() async { | 956 test_unnecessaryCast_conditionalExpression() async { |
| 894 Source source = addSource(r''' | 957 Source source = addSource(r''' |
| 895 abstract class I {} | 958 abstract class I {} |
| 896 class A implements I {} | 959 class A implements I {} |
| 897 class B implements I {} | 960 class B implements I {} |
| 898 I m(A a, B b) { | 961 I m(A a, B b) { |
| 899 return a == null ? b as I : a as I; | 962 return a == null ? b as I : a as I; |
| 900 }'''); | 963 }'''); |
| 901 await assertNoErrors(source); | 964 await computeAnalysisResult(source); |
| 965 assertNoErrors(source); |
| 902 verify([source]); | 966 verify([source]); |
| 903 } | 967 } |
| 904 | 968 |
| 905 test_unnecessaryCast_dynamic_type() async { | 969 test_unnecessaryCast_dynamic_type() async { |
| 906 Source source = addSource(r''' | 970 Source source = addSource(r''' |
| 907 m(v) { | 971 m(v) { |
| 908 var b = v as Object; | 972 var b = v as Object; |
| 909 }'''); | 973 }'''); |
| 910 await assertNoErrors(source); | 974 await computeAnalysisResult(source); |
| 975 assertNoErrors(source); |
| 911 verify([source]); | 976 verify([source]); |
| 912 } | 977 } |
| 913 | 978 |
| 914 test_unnecessaryCast_generics() async { | 979 test_unnecessaryCast_generics() async { |
| 915 // dartbug.com/18953 | 980 // dartbug.com/18953 |
| 916 Source source = addSource(r''' | 981 Source source = addSource(r''' |
| 917 import 'dart:async'; | 982 import 'dart:async'; |
| 918 Future<int> f() => new Future.value(0); | 983 Future<int> f() => new Future.value(0); |
| 919 void g(bool c) { | 984 void g(bool c) { |
| 920 (c ? f(): new Future.value(0) as Future<int>).then((int value) {}); | 985 (c ? f(): new Future.value(0) as Future<int>).then((int value) {}); |
| 921 }'''); | 986 }'''); |
| 922 await assertNoErrors(source); | 987 await computeAnalysisResult(source); |
| 988 assertNoErrors(source); |
| 923 verify([source]); | 989 verify([source]); |
| 924 } | 990 } |
| 925 | 991 |
| 926 test_unnecessaryCast_type_dynamic() async { | 992 test_unnecessaryCast_type_dynamic() async { |
| 927 Source source = addSource(r''' | 993 Source source = addSource(r''' |
| 928 m(v) { | 994 m(v) { |
| 929 var b = Object as dynamic; | 995 var b = Object as dynamic; |
| 930 }'''); | 996 }'''); |
| 931 await assertNoErrors(source); | 997 await computeAnalysisResult(source); |
| 998 assertNoErrors(source); |
| 932 verify([source]); | 999 verify([source]); |
| 933 } | 1000 } |
| 934 | 1001 |
| 935 test_unnecessaryNoSuchMethod_blockBody_notReturnStatement() async { | 1002 test_unnecessaryNoSuchMethod_blockBody_notReturnStatement() async { |
| 936 Source source = addSource(r''' | 1003 Source source = addSource(r''' |
| 937 class A { | 1004 class A { |
| 938 noSuchMethod(x) => super.noSuchMethod(x); | 1005 noSuchMethod(x) => super.noSuchMethod(x); |
| 939 } | 1006 } |
| 940 class B extends A { | 1007 class B extends A { |
| 941 mmm(); | 1008 mmm(); |
| 942 noSuchMethod(y) { | 1009 noSuchMethod(y) { |
| 943 print(y); | 1010 print(y); |
| 944 } | 1011 } |
| 945 }'''); | 1012 }'''); |
| 946 await assertNoErrors(source); | 1013 await computeAnalysisResult(source); |
| 1014 assertNoErrors(source); |
| 947 verify([source]); | 1015 verify([source]); |
| 948 } | 1016 } |
| 949 | 1017 |
| 950 test_unnecessaryNoSuchMethod_blockBody_notSingleStatement() async { | 1018 test_unnecessaryNoSuchMethod_blockBody_notSingleStatement() async { |
| 951 Source source = addSource(r''' | 1019 Source source = addSource(r''' |
| 952 class A { | 1020 class A { |
| 953 noSuchMethod(x) => super.noSuchMethod(x); | 1021 noSuchMethod(x) => super.noSuchMethod(x); |
| 954 } | 1022 } |
| 955 class B extends A { | 1023 class B extends A { |
| 956 mmm(); | 1024 mmm(); |
| 957 noSuchMethod(y) { | 1025 noSuchMethod(y) { |
| 958 print(y); | 1026 print(y); |
| 959 return super.noSuchMethod(y); | 1027 return super.noSuchMethod(y); |
| 960 } | 1028 } |
| 961 }'''); | 1029 }'''); |
| 962 await assertNoErrors(source); | 1030 await computeAnalysisResult(source); |
| 1031 assertNoErrors(source); |
| 963 verify([source]); | 1032 verify([source]); |
| 964 } | 1033 } |
| 965 | 1034 |
| 966 test_unnecessaryNoSuchMethod_expressionBody_notNoSuchMethod() async { | 1035 test_unnecessaryNoSuchMethod_expressionBody_notNoSuchMethod() async { |
| 967 Source source = addSource(r''' | 1036 Source source = addSource(r''' |
| 968 class A { | 1037 class A { |
| 969 noSuchMethod(x) => super.noSuchMethod(x); | 1038 noSuchMethod(x) => super.noSuchMethod(x); |
| 970 } | 1039 } |
| 971 class B extends A { | 1040 class B extends A { |
| 972 mmm(); | 1041 mmm(); |
| 973 noSuchMethod(y) => super.hashCode; | 1042 noSuchMethod(y) => super.hashCode; |
| 974 }'''); | 1043 }'''); |
| 975 await assertNoErrors(source); | 1044 await computeAnalysisResult(source); |
| 1045 assertNoErrors(source); |
| 976 verify([source]); | 1046 verify([source]); |
| 977 } | 1047 } |
| 978 | 1048 |
| 979 test_unnecessaryNoSuchMethod_expressionBody_notSuper() async { | 1049 test_unnecessaryNoSuchMethod_expressionBody_notSuper() async { |
| 980 Source source = addSource(r''' | 1050 Source source = addSource(r''' |
| 981 class A { | 1051 class A { |
| 982 noSuchMethod(x) => super.noSuchMethod(x); | 1052 noSuchMethod(x) => super.noSuchMethod(x); |
| 983 } | 1053 } |
| 984 class B extends A { | 1054 class B extends A { |
| 985 mmm(); | 1055 mmm(); |
| 986 noSuchMethod(y) => 42; | 1056 noSuchMethod(y) => 42; |
| 987 }'''); | 1057 }'''); |
| 988 await assertNoErrors(source); | 1058 await computeAnalysisResult(source); |
| 1059 assertNoErrors(source); |
| 989 verify([source]); | 1060 verify([source]); |
| 990 } | 1061 } |
| 991 | 1062 |
| 992 test_unusedImport_annotationOnDirective() async { | 1063 test_unusedImport_annotationOnDirective() async { |
| 993 Source source = addSource(r''' | 1064 Source source = addSource(r''' |
| 994 library L; | 1065 library L; |
| 995 @A() | 1066 @A() |
| 996 import 'lib1.dart';'''); | 1067 import 'lib1.dart';'''); |
| 997 Source source2 = addNamedSource( | 1068 Source source2 = addNamedSource( |
| 998 "/lib1.dart", | 1069 "/lib1.dart", |
| 999 r''' | 1070 r''' |
| 1000 library lib1; | 1071 library lib1; |
| 1001 class A { | 1072 class A { |
| 1002 const A() {} | 1073 const A() {} |
| 1003 }'''); | 1074 }'''); |
| 1004 await assertErrors(source); | 1075 await computeAnalysisResult(source); |
| 1076 await computeAnalysisResult(source2); |
| 1077 assertErrors(source); |
| 1005 verify([source, source2]); | 1078 verify([source, source2]); |
| 1006 } | 1079 } |
| 1007 | 1080 |
| 1008 test_unusedImport_as_equalPrefixes() async { | 1081 test_unusedImport_as_equalPrefixes() async { |
| 1009 // 18818 | 1082 // 18818 |
| 1010 Source source = addSource(r''' | 1083 Source source = addSource(r''' |
| 1011 library L; | 1084 library L; |
| 1012 import 'lib1.dart' as one; | 1085 import 'lib1.dart' as one; |
| 1013 import 'lib2.dart' as one; | 1086 import 'lib2.dart' as one; |
| 1014 one.A a; | 1087 one.A a; |
| 1015 one.B b;'''); | 1088 one.B b;'''); |
| 1016 Source source2 = addNamedSource( | 1089 Source source2 = addNamedSource( |
| 1017 "/lib1.dart", | 1090 "/lib1.dart", |
| 1018 r''' | 1091 r''' |
| 1019 library lib1; | 1092 library lib1; |
| 1020 class A {}'''); | 1093 class A {}'''); |
| 1021 Source source3 = addNamedSource( | 1094 Source source3 = addNamedSource( |
| 1022 "/lib2.dart", | 1095 "/lib2.dart", |
| 1023 r''' | 1096 r''' |
| 1024 library lib2; | 1097 library lib2; |
| 1025 class B {}'''); | 1098 class B {}'''); |
| 1026 await assertErrors(source); | 1099 await computeAnalysisResult(source); |
| 1027 await assertNoErrors(source2); | 1100 await computeAnalysisResult(source2); |
| 1028 await assertNoErrors(source3); | 1101 await computeAnalysisResult(source3); |
| 1102 assertErrors(source); |
| 1103 assertNoErrors(source2); |
| 1104 assertNoErrors(source3); |
| 1029 verify([source, source2, source3]); | 1105 verify([source, source2, source3]); |
| 1030 } | 1106 } |
| 1031 | 1107 |
| 1032 test_unusedImport_core_library() async { | 1108 test_unusedImport_core_library() async { |
| 1033 Source source = addSource(r''' | 1109 Source source = addSource(r''' |
| 1034 library L; | 1110 library L; |
| 1035 import 'dart:core';'''); | 1111 import 'dart:core';'''); |
| 1036 await assertNoErrors(source); | 1112 await computeAnalysisResult(source); |
| 1113 assertNoErrors(source); |
| 1037 verify([source]); | 1114 verify([source]); |
| 1038 } | 1115 } |
| 1039 | 1116 |
| 1040 test_unusedImport_export() async { | 1117 test_unusedImport_export() async { |
| 1041 Source source = addSource(r''' | 1118 Source source = addSource(r''' |
| 1042 library L; | 1119 library L; |
| 1043 import 'lib1.dart'; | 1120 import 'lib1.dart'; |
| 1044 Two two;'''); | 1121 Two two;'''); |
| 1045 addNamedSource( | 1122 addNamedSource( |
| 1046 "/lib1.dart", | 1123 "/lib1.dart", |
| 1047 r''' | 1124 r''' |
| 1048 library lib1; | 1125 library lib1; |
| 1049 export 'lib2.dart'; | 1126 export 'lib2.dart'; |
| 1050 class One {}'''); | 1127 class One {}'''); |
| 1051 addNamedSource( | 1128 addNamedSource( |
| 1052 "/lib2.dart", | 1129 "/lib2.dart", |
| 1053 r''' | 1130 r''' |
| 1054 library lib2; | 1131 library lib2; |
| 1055 class Two {}'''); | 1132 class Two {}'''); |
| 1056 await assertNoErrors(source); | 1133 await computeAnalysisResult(source); |
| 1134 assertNoErrors(source); |
| 1057 verify([source]); | 1135 verify([source]); |
| 1058 } | 1136 } |
| 1059 | 1137 |
| 1060 test_unusedImport_export2() async { | 1138 test_unusedImport_export2() async { |
| 1061 Source source = addSource(r''' | 1139 Source source = addSource(r''' |
| 1062 library L; | 1140 library L; |
| 1063 import 'lib1.dart'; | 1141 import 'lib1.dart'; |
| 1064 Three three;'''); | 1142 Three three;'''); |
| 1065 addNamedSource( | 1143 addNamedSource( |
| 1066 "/lib1.dart", | 1144 "/lib1.dart", |
| 1067 r''' | 1145 r''' |
| 1068 library lib1; | 1146 library lib1; |
| 1069 export 'lib2.dart'; | 1147 export 'lib2.dart'; |
| 1070 class One {}'''); | 1148 class One {}'''); |
| 1071 addNamedSource( | 1149 addNamedSource( |
| 1072 "/lib2.dart", | 1150 "/lib2.dart", |
| 1073 r''' | 1151 r''' |
| 1074 library lib2; | 1152 library lib2; |
| 1075 export 'lib3.dart'; | 1153 export 'lib3.dart'; |
| 1076 class Two {}'''); | 1154 class Two {}'''); |
| 1077 addNamedSource( | 1155 addNamedSource( |
| 1078 "/lib3.dart", | 1156 "/lib3.dart", |
| 1079 r''' | 1157 r''' |
| 1080 library lib3; | 1158 library lib3; |
| 1081 class Three {}'''); | 1159 class Three {}'''); |
| 1082 await assertNoErrors(source); | 1160 await computeAnalysisResult(source); |
| 1161 assertNoErrors(source); |
| 1083 verify([source]); | 1162 verify([source]); |
| 1084 } | 1163 } |
| 1085 | 1164 |
| 1086 test_unusedImport_export_infiniteLoop() async { | 1165 test_unusedImport_export_infiniteLoop() async { |
| 1087 Source source = addSource(r''' | 1166 Source source = addSource(r''' |
| 1088 library L; | 1167 library L; |
| 1089 import 'lib1.dart'; | 1168 import 'lib1.dart'; |
| 1090 Two two;'''); | 1169 Two two;'''); |
| 1091 addNamedSource( | 1170 addNamedSource( |
| 1092 "/lib1.dart", | 1171 "/lib1.dart", |
| 1093 r''' | 1172 r''' |
| 1094 library lib1; | 1173 library lib1; |
| 1095 export 'lib2.dart'; | 1174 export 'lib2.dart'; |
| 1096 class One {}'''); | 1175 class One {}'''); |
| 1097 addNamedSource( | 1176 addNamedSource( |
| 1098 "/lib2.dart", | 1177 "/lib2.dart", |
| 1099 r''' | 1178 r''' |
| 1100 library lib2; | 1179 library lib2; |
| 1101 export 'lib3.dart'; | 1180 export 'lib3.dart'; |
| 1102 class Two {}'''); | 1181 class Two {}'''); |
| 1103 addNamedSource( | 1182 addNamedSource( |
| 1104 "/lib3.dart", | 1183 "/lib3.dart", |
| 1105 r''' | 1184 r''' |
| 1106 library lib3; | 1185 library lib3; |
| 1107 export 'lib2.dart'; | 1186 export 'lib2.dart'; |
| 1108 class Three {}'''); | 1187 class Three {}'''); |
| 1109 await assertNoErrors(source); | 1188 await computeAnalysisResult(source); |
| 1189 assertNoErrors(source); |
| 1110 verify([source]); | 1190 verify([source]); |
| 1111 } | 1191 } |
| 1112 | 1192 |
| 1113 test_unusedImport_metadata() async { | 1193 test_unusedImport_metadata() async { |
| 1114 Source source = addSource(r''' | 1194 Source source = addSource(r''' |
| 1115 library L; | 1195 library L; |
| 1116 @A(x) | 1196 @A(x) |
| 1117 import 'lib1.dart'; | 1197 import 'lib1.dart'; |
| 1118 class A { | 1198 class A { |
| 1119 final int value; | 1199 final int value; |
| 1120 const A(this.value); | 1200 const A(this.value); |
| 1121 }'''); | 1201 }'''); |
| 1122 addNamedSource( | 1202 addNamedSource( |
| 1123 "/lib1.dart", | 1203 "/lib1.dart", |
| 1124 r''' | 1204 r''' |
| 1125 library lib1; | 1205 library lib1; |
| 1126 const x = 0;'''); | 1206 const x = 0;'''); |
| 1127 await assertNoErrors(source); | 1207 await computeAnalysisResult(source); |
| 1208 assertNoErrors(source); |
| 1128 verify([source]); | 1209 verify([source]); |
| 1129 } | 1210 } |
| 1130 | 1211 |
| 1131 test_unusedImport_prefix_topLevelFunction() async { | 1212 test_unusedImport_prefix_topLevelFunction() async { |
| 1132 Source source = addSource(r''' | 1213 Source source = addSource(r''' |
| 1133 library L; | 1214 library L; |
| 1134 import 'lib1.dart' hide topLevelFunction; | 1215 import 'lib1.dart' hide topLevelFunction; |
| 1135 import 'lib1.dart' as one show topLevelFunction; | 1216 import 'lib1.dart' as one show topLevelFunction; |
| 1136 class A { | 1217 class A { |
| 1137 static void x() { | 1218 static void x() { |
| 1138 One o; | 1219 One o; |
| 1139 one.topLevelFunction(); | 1220 one.topLevelFunction(); |
| 1140 } | 1221 } |
| 1141 }'''); | 1222 }'''); |
| 1142 addNamedSource( | 1223 addNamedSource( |
| 1143 "/lib1.dart", | 1224 "/lib1.dart", |
| 1144 r''' | 1225 r''' |
| 1145 library lib1; | 1226 library lib1; |
| 1146 class One {} | 1227 class One {} |
| 1147 topLevelFunction() {}'''); | 1228 topLevelFunction() {}'''); |
| 1148 await assertNoErrors(source); | 1229 await computeAnalysisResult(source); |
| 1230 assertNoErrors(source); |
| 1149 verify([source]); | 1231 verify([source]); |
| 1150 } | 1232 } |
| 1151 | 1233 |
| 1152 test_unusedImport_prefix_topLevelFunction2() async { | 1234 test_unusedImport_prefix_topLevelFunction2() async { |
| 1153 Source source = addSource(r''' | 1235 Source source = addSource(r''' |
| 1154 library L; | 1236 library L; |
| 1155 import 'lib1.dart' hide topLevelFunction; | 1237 import 'lib1.dart' hide topLevelFunction; |
| 1156 import 'lib1.dart' as one show topLevelFunction; | 1238 import 'lib1.dart' as one show topLevelFunction; |
| 1157 import 'lib1.dart' as two show topLevelFunction; | 1239 import 'lib1.dart' as two show topLevelFunction; |
| 1158 class A { | 1240 class A { |
| 1159 static void x() { | 1241 static void x() { |
| 1160 One o; | 1242 One o; |
| 1161 one.topLevelFunction(); | 1243 one.topLevelFunction(); |
| 1162 two.topLevelFunction(); | 1244 two.topLevelFunction(); |
| 1163 } | 1245 } |
| 1164 }'''); | 1246 }'''); |
| 1165 addNamedSource( | 1247 addNamedSource( |
| 1166 "/lib1.dart", | 1248 "/lib1.dart", |
| 1167 r''' | 1249 r''' |
| 1168 library lib1; | 1250 library lib1; |
| 1169 class One {} | 1251 class One {} |
| 1170 topLevelFunction() {}'''); | 1252 topLevelFunction() {}'''); |
| 1171 await assertNoErrors(source); | 1253 await computeAnalysisResult(source); |
| 1254 assertNoErrors(source); |
| 1172 verify([source]); | 1255 verify([source]); |
| 1173 } | 1256 } |
| 1174 | 1257 |
| 1175 test_useOfVoidResult_implicitReturnValue() async { | 1258 test_useOfVoidResult_implicitReturnValue() async { |
| 1176 Source source = addSource(r''' | 1259 Source source = addSource(r''' |
| 1177 f() {} | 1260 f() {} |
| 1178 class A { | 1261 class A { |
| 1179 n() { | 1262 n() { |
| 1180 var a = f(); | 1263 var a = f(); |
| 1181 } | 1264 } |
| 1182 }'''); | 1265 }'''); |
| 1183 await assertNoErrors(source); | 1266 await computeAnalysisResult(source); |
| 1267 assertNoErrors(source); |
| 1184 verify([source]); | 1268 verify([source]); |
| 1185 } | 1269 } |
| 1186 | 1270 |
| 1187 test_useOfVoidResult_nonVoidReturnValue() async { | 1271 test_useOfVoidResult_nonVoidReturnValue() async { |
| 1188 Source source = addSource(r''' | 1272 Source source = addSource(r''' |
| 1189 int f() => 1; | 1273 int f() => 1; |
| 1190 g() { | 1274 g() { |
| 1191 var a = f(); | 1275 var a = f(); |
| 1192 }'''); | 1276 }'''); |
| 1193 await assertNoErrors(source); | 1277 await computeAnalysisResult(source); |
| 1278 assertNoErrors(source); |
| 1194 verify([source]); | 1279 verify([source]); |
| 1195 } | 1280 } |
| 1196 } | 1281 } |
| 1197 | 1282 |
| 1198 class PubSuggestionCodeTest extends ResolverTestCase { | 1283 class PubSuggestionCodeTest extends ResolverTestCase { |
| 1199 test_import_package() async { | 1284 test_import_package() async { |
| 1200 Source source = addSource("import 'package:somepackage/other.dart';"); | 1285 Source source = addSource("import 'package:somepackage/other.dart';"); |
| 1201 await assertErrors(source, [CompileTimeErrorCode.URI_DOES_NOT_EXIST]); | 1286 await computeAnalysisResult(source); |
| 1287 assertErrors(source, [CompileTimeErrorCode.URI_DOES_NOT_EXIST]); |
| 1202 } | 1288 } |
| 1203 | 1289 |
| 1204 test_import_packageWithDotDot() async { | 1290 test_import_packageWithDotDot() async { |
| 1205 Source source = addSource("import 'package:somepackage/../other.dart';"); | 1291 Source source = addSource("import 'package:somepackage/../other.dart';"); |
| 1206 await assertErrors(source, [ | 1292 await computeAnalysisResult(source); |
| 1293 assertErrors(source, [ |
| 1207 CompileTimeErrorCode.URI_DOES_NOT_EXIST, | 1294 CompileTimeErrorCode.URI_DOES_NOT_EXIST, |
| 1208 HintCode.PACKAGE_IMPORT_CONTAINS_DOT_DOT | 1295 HintCode.PACKAGE_IMPORT_CONTAINS_DOT_DOT |
| 1209 ]); | 1296 ]); |
| 1210 } | 1297 } |
| 1211 | 1298 |
| 1212 test_import_packageWithLeadingDotDot() async { | 1299 test_import_packageWithLeadingDotDot() async { |
| 1213 Source source = addSource("import 'package:../other.dart';"); | 1300 Source source = addSource("import 'package:../other.dart';"); |
| 1214 await assertErrors(source, [ | 1301 await computeAnalysisResult(source); |
| 1302 assertErrors(source, [ |
| 1215 CompileTimeErrorCode.URI_DOES_NOT_EXIST, | 1303 CompileTimeErrorCode.URI_DOES_NOT_EXIST, |
| 1216 HintCode.PACKAGE_IMPORT_CONTAINS_DOT_DOT | 1304 HintCode.PACKAGE_IMPORT_CONTAINS_DOT_DOT |
| 1217 ]); | 1305 ]); |
| 1218 } | 1306 } |
| 1219 | 1307 |
| 1220 test_import_referenceIntoLibDirectory() async { | 1308 test_import_referenceIntoLibDirectory() async { |
| 1221 cacheSource("/myproj/pubspec.yaml", ""); | 1309 cacheSource("/myproj/pubspec.yaml", ""); |
| 1222 cacheSource("/myproj/lib/other.dart", ""); | 1310 cacheSource("/myproj/lib/other.dart", ""); |
| 1223 Source source = | 1311 Source source = |
| 1224 addNamedSource("/myproj/web/test.dart", "import '../lib/other.dart';"); | 1312 addNamedSource("/myproj/web/test.dart", "import '../lib/other.dart';"); |
| 1225 await assertErrors( | 1313 await computeAnalysisResult(source); |
| 1314 assertErrors( |
| 1226 source, [HintCode.FILE_IMPORT_OUTSIDE_LIB_REFERENCES_FILE_INSIDE]); | 1315 source, [HintCode.FILE_IMPORT_OUTSIDE_LIB_REFERENCES_FILE_INSIDE]); |
| 1227 } | 1316 } |
| 1228 | 1317 |
| 1229 test_import_referenceIntoLibDirectory_no_pubspec() async { | 1318 test_import_referenceIntoLibDirectory_no_pubspec() async { |
| 1230 cacheSource("/myproj/lib/other.dart", ""); | 1319 cacheSource("/myproj/lib/other.dart", ""); |
| 1231 Source source = | 1320 Source source = |
| 1232 addNamedSource("/myproj/web/test.dart", "import '../lib/other.dart';"); | 1321 addNamedSource("/myproj/web/test.dart", "import '../lib/other.dart';"); |
| 1233 await assertNoErrors(source); | 1322 await computeAnalysisResult(source); |
| 1323 assertNoErrors(source); |
| 1234 } | 1324 } |
| 1235 | 1325 |
| 1236 test_import_referenceOutOfLibDirectory() async { | 1326 test_import_referenceOutOfLibDirectory() async { |
| 1237 cacheSource("/myproj/pubspec.yaml", ""); | 1327 cacheSource("/myproj/pubspec.yaml", ""); |
| 1238 cacheSource("/myproj/web/other.dart", ""); | 1328 cacheSource("/myproj/web/other.dart", ""); |
| 1239 Source source = | 1329 Source source = |
| 1240 addNamedSource("/myproj/lib/test.dart", "import '../web/other.dart';"); | 1330 addNamedSource("/myproj/lib/test.dart", "import '../web/other.dart';"); |
| 1241 await assertErrors( | 1331 await computeAnalysisResult(source); |
| 1332 assertErrors( |
| 1242 source, [HintCode.FILE_IMPORT_INSIDE_LIB_REFERENCES_FILE_OUTSIDE]); | 1333 source, [HintCode.FILE_IMPORT_INSIDE_LIB_REFERENCES_FILE_OUTSIDE]); |
| 1243 } | 1334 } |
| 1244 | 1335 |
| 1245 test_import_referenceOutOfLibDirectory_no_pubspec() async { | 1336 test_import_referenceOutOfLibDirectory_no_pubspec() async { |
| 1246 cacheSource("/myproj/web/other.dart", ""); | 1337 cacheSource("/myproj/web/other.dart", ""); |
| 1247 Source source = | 1338 Source source = |
| 1248 addNamedSource("/myproj/lib/test.dart", "import '../web/other.dart';"); | 1339 addNamedSource("/myproj/lib/test.dart", "import '../web/other.dart';"); |
| 1249 await assertNoErrors(source); | 1340 await computeAnalysisResult(source); |
| 1341 assertNoErrors(source); |
| 1250 } | 1342 } |
| 1251 | 1343 |
| 1252 test_import_valid_inside_lib1() async { | 1344 test_import_valid_inside_lib1() async { |
| 1253 cacheSource("/myproj/pubspec.yaml", ""); | 1345 cacheSource("/myproj/pubspec.yaml", ""); |
| 1254 cacheSource("/myproj/lib/other.dart", ""); | 1346 cacheSource("/myproj/lib/other.dart", ""); |
| 1255 Source source = | 1347 Source source = |
| 1256 addNamedSource("/myproj/lib/test.dart", "import 'other.dart';"); | 1348 addNamedSource("/myproj/lib/test.dart", "import 'other.dart';"); |
| 1257 await assertNoErrors(source); | 1349 await computeAnalysisResult(source); |
| 1350 assertNoErrors(source); |
| 1258 } | 1351 } |
| 1259 | 1352 |
| 1260 test_import_valid_inside_lib2() async { | 1353 test_import_valid_inside_lib2() async { |
| 1261 cacheSource("/myproj/pubspec.yaml", ""); | 1354 cacheSource("/myproj/pubspec.yaml", ""); |
| 1262 cacheSource("/myproj/lib/bar/other.dart", ""); | 1355 cacheSource("/myproj/lib/bar/other.dart", ""); |
| 1263 Source source = addNamedSource( | 1356 Source source = addNamedSource( |
| 1264 "/myproj/lib/foo/test.dart", "import '../bar/other.dart';"); | 1357 "/myproj/lib/foo/test.dart", "import '../bar/other.dart';"); |
| 1265 await assertNoErrors(source); | 1358 await computeAnalysisResult(source); |
| 1359 assertNoErrors(source); |
| 1266 } | 1360 } |
| 1267 | 1361 |
| 1268 test_import_valid_outside_lib() async { | 1362 test_import_valid_outside_lib() async { |
| 1269 cacheSource("/myproj/pubspec.yaml", ""); | 1363 cacheSource("/myproj/pubspec.yaml", ""); |
| 1270 cacheSource("/myproj/web/other.dart", ""); | 1364 cacheSource("/myproj/web/other.dart", ""); |
| 1271 Source source = | 1365 Source source = |
| 1272 addNamedSource("/myproj/lib2/test.dart", "import '../web/other.dart';"); | 1366 addNamedSource("/myproj/lib2/test.dart", "import '../web/other.dart';"); |
| 1273 await assertNoErrors(source); | 1367 await computeAnalysisResult(source); |
| 1368 assertNoErrors(source); |
| 1274 } | 1369 } |
| 1275 } | 1370 } |
| OLD | NEW |