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