| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 import 'dart:async'; | 5 import 'dart:async'; |
| 6 import 'package:expect/expect.dart'; | 6 import 'package:expect/expect.dart'; |
| 7 import 'package:async_helper/async_helper.dart'; | 7 import 'package:async_helper/async_helper.dart'; |
| 8 import 'package:compiler/src/compiler.dart'; | 8 import 'package:compiler/src/compiler.dart'; |
| 9 import 'package:compiler/src/diagnostics/messages.dart' show MessageKind; | 9 import 'package:compiler/src/diagnostics/messages.dart' show MessageKind; |
| 10 import 'package:compiler/src/elements/elements.dart'; | 10 import 'package:compiler/src/elements/elements.dart'; |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 expectIsPatch: true, checkHasBody: true); | 128 expectIsPatch: true, checkHasBody: true); |
| 129 | 129 |
| 130 DiagnosticCollector collector = compiler.diagnosticCollector; | 130 DiagnosticCollector collector = compiler.diagnosticCollector; |
| 131 Expect.isTrue( | 131 Expect.isTrue( |
| 132 collector.warnings.isEmpty, "Unexpected warnings: ${collector.warnings}"); | 132 collector.warnings.isEmpty, "Unexpected warnings: ${collector.warnings}"); |
| 133 Expect.isTrue( | 133 Expect.isTrue( |
| 134 collector.errors.isEmpty, "Unexpected errors: ${collector.errors}"); | 134 collector.errors.isEmpty, "Unexpected errors: ${collector.errors}"); |
| 135 } | 135 } |
| 136 | 136 |
| 137 Future testPatchFunctionMetadata() async { | 137 Future testPatchFunctionMetadata() async { |
| 138 dynamic compiler = await applyPatch( | 138 dynamic compiler = await applyPatch(""" |
| 139 """ | |
| 140 const a = 0; | 139 const a = 0; |
| 141 @a external test(); | 140 @a external test(); |
| 142 """, | 141 """, """ |
| 143 """ | |
| 144 const _b = 1; | 142 const _b = 1; |
| 145 @patch @_b test() {} | 143 @patch @_b test() {} |
| 146 """); | 144 """); |
| 147 Element origin = ensure( | 145 Element origin = ensure( |
| 148 compiler, "test", compiler.resolution.commonElements.coreLibrary.find, | 146 compiler, "test", compiler.resolution.commonElements.coreLibrary.find, |
| 149 expectIsPatched: true, checkHasBody: true); | 147 expectIsPatched: true, checkHasBody: true); |
| 150 Element patch = ensure(compiler, "test", | 148 Element patch = ensure(compiler, "test", |
| 151 compiler.resolution.commonElements.coreLibrary.patch.find, | 149 compiler.resolution.commonElements.coreLibrary.patch.find, |
| 152 expectIsPatch: true, checkHasBody: true); | 150 expectIsPatch: true, checkHasBody: true); |
| 153 | 151 |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 213 | 211 |
| 214 DiagnosticCollector collector = compiler.diagnosticCollector; | 212 DiagnosticCollector collector = compiler.diagnosticCollector; |
| 215 Expect.isTrue( | 213 Expect.isTrue( |
| 216 collector.warnings.isEmpty, "Unexpected warnings: ${collector.warnings}"); | 214 collector.warnings.isEmpty, "Unexpected warnings: ${collector.warnings}"); |
| 217 Expect.equals(1, collector.errors.length); | 215 Expect.equals(1, collector.errors.length); |
| 218 Expect.isTrue(collector.errors.first.message.kind == | 216 Expect.isTrue(collector.errors.first.message.kind == |
| 219 MessageKind.PATCH_TYPE_VARIABLES_MISMATCH); | 217 MessageKind.PATCH_TYPE_VARIABLES_MISMATCH); |
| 220 } | 218 } |
| 221 | 219 |
| 222 Future testPatchConstructor() async { | 220 Future testPatchConstructor() async { |
| 223 dynamic compiler = await applyPatch( | 221 dynamic compiler = await applyPatch(""" |
| 224 """ | |
| 225 class Class { | 222 class Class { |
| 226 external Class(); | 223 external Class(); |
| 227 } | 224 } |
| 228 """, | 225 """, """ |
| 229 """ | |
| 230 @patch class Class { | 226 @patch class Class { |
| 231 @patch Class(); | 227 @patch Class(); |
| 232 } | 228 } |
| 233 """); | 229 """); |
| 234 dynamic classOrigin = ensure( | 230 dynamic classOrigin = ensure( |
| 235 compiler, "Class", compiler.resolution.commonElements.coreLibrary.find, | 231 compiler, "Class", compiler.resolution.commonElements.coreLibrary.find, |
| 236 expectIsPatched: true); | 232 expectIsPatched: true); |
| 237 classOrigin.ensureResolved(compiler.resolution); | 233 classOrigin.ensureResolved(compiler.resolution); |
| 238 dynamic classPatch = ensure(compiler, "Class", | 234 dynamic classPatch = ensure(compiler, "Class", |
| 239 compiler.resolution.commonElements.coreLibrary.patch.find, | 235 compiler.resolution.commonElements.coreLibrary.patch.find, |
| (...skipping 13 matching lines...) Expand all Loading... |
| 253 Expect.equals(constructorOrigin, constructorPatch.origin); | 249 Expect.equals(constructorOrigin, constructorPatch.origin); |
| 254 | 250 |
| 255 DiagnosticCollector collector = compiler.diagnosticCollector; | 251 DiagnosticCollector collector = compiler.diagnosticCollector; |
| 256 Expect.isTrue( | 252 Expect.isTrue( |
| 257 collector.warnings.isEmpty, "Unexpected warnings: ${collector.warnings}"); | 253 collector.warnings.isEmpty, "Unexpected warnings: ${collector.warnings}"); |
| 258 Expect.isTrue( | 254 Expect.isTrue( |
| 259 collector.errors.isEmpty, "Unexpected errors: ${collector.errors}"); | 255 collector.errors.isEmpty, "Unexpected errors: ${collector.errors}"); |
| 260 } | 256 } |
| 261 | 257 |
| 262 Future testPatchRedirectingConstructor() async { | 258 Future testPatchRedirectingConstructor() async { |
| 263 dynamic compiler = await applyPatch( | 259 dynamic compiler = await applyPatch(""" |
| 264 """ | |
| 265 class Class { | 260 class Class { |
| 266 Class(x) : this._(x, false); | 261 Class(x) : this._(x, false); |
| 267 | 262 |
| 268 external Class._(x, y); | 263 external Class._(x, y); |
| 269 } | 264 } |
| 270 """, | 265 """, r""" |
| 271 r""" | |
| 272 @patch class Class { | 266 @patch class Class { |
| 273 @patch Class._(x, y) { print('$x,$y'); } | 267 @patch Class._(x, y) { print('$x,$y'); } |
| 274 } | 268 } |
| 275 """); | 269 """); |
| 276 dynamic classOrigin = ensure( | 270 dynamic classOrigin = ensure( |
| 277 compiler, "Class", compiler.resolution.commonElements.coreLibrary.find, | 271 compiler, "Class", compiler.resolution.commonElements.coreLibrary.find, |
| 278 expectIsPatched: true); | 272 expectIsPatched: true); |
| 279 classOrigin.ensureResolved(compiler.resolution); | 273 classOrigin.ensureResolved(compiler.resolution); |
| 280 | 274 |
| 281 dynamic classPatch = ensure(compiler, "Class", | 275 dynamic classPatch = ensure(compiler, "Class", |
| (...skipping 17 matching lines...) Expand all Loading... |
| 299 compiler.resolver.resolve(constructorRedirecting); | 293 compiler.resolver.resolve(constructorRedirecting); |
| 300 | 294 |
| 301 DiagnosticCollector collector = compiler.diagnosticCollector; | 295 DiagnosticCollector collector = compiler.diagnosticCollector; |
| 302 Expect.isTrue( | 296 Expect.isTrue( |
| 303 collector.warnings.isEmpty, "Unexpected warnings: ${collector.warnings}"); | 297 collector.warnings.isEmpty, "Unexpected warnings: ${collector.warnings}"); |
| 304 Expect.isTrue( | 298 Expect.isTrue( |
| 305 collector.errors.isEmpty, "Unexpected errors: ${collector.errors}"); | 299 collector.errors.isEmpty, "Unexpected errors: ${collector.errors}"); |
| 306 } | 300 } |
| 307 | 301 |
| 308 Future testPatchMember() async { | 302 Future testPatchMember() async { |
| 309 dynamic compiler = await applyPatch( | 303 dynamic compiler = await applyPatch(""" |
| 310 """ | |
| 311 class Class { | 304 class Class { |
| 312 external String toString(); | 305 external String toString(); |
| 313 } | 306 } |
| 314 """, | 307 """, """ |
| 315 """ | |
| 316 @patch class Class { | 308 @patch class Class { |
| 317 @patch String toString() => 'string'; | 309 @patch String toString() => 'string'; |
| 318 } | 310 } |
| 319 """); | 311 """); |
| 320 dynamic container = ensure( | 312 dynamic container = ensure( |
| 321 compiler, "Class", compiler.resolution.commonElements.coreLibrary.find, | 313 compiler, "Class", compiler.resolution.commonElements.coreLibrary.find, |
| 322 expectIsPatched: true); | 314 expectIsPatched: true); |
| 323 container.parseNode(compiler.parsingContext); | 315 container.parseNode(compiler.parsingContext); |
| 324 ensure(compiler, "Class", | 316 ensure(compiler, "Class", |
| 325 compiler.resolution.commonElements.coreLibrary.patch.find, | 317 compiler.resolution.commonElements.coreLibrary.patch.find, |
| 326 expectIsPatch: true); | 318 expectIsPatch: true); |
| 327 | 319 |
| 328 ensure(compiler, "toString", container.lookupLocalMember, | 320 ensure(compiler, "toString", container.lookupLocalMember, |
| 329 expectIsPatched: true, checkHasBody: true); | 321 expectIsPatched: true, checkHasBody: true); |
| 330 ensure(compiler, "toString", container.patch.lookupLocalMember, | 322 ensure(compiler, "toString", container.patch.lookupLocalMember, |
| 331 expectIsPatch: true, checkHasBody: true); | 323 expectIsPatch: true, checkHasBody: true); |
| 332 | 324 |
| 333 DiagnosticCollector collector = compiler.diagnosticCollector; | 325 DiagnosticCollector collector = compiler.diagnosticCollector; |
| 334 Expect.isTrue( | 326 Expect.isTrue( |
| 335 collector.warnings.isEmpty, "Unexpected warnings: ${collector.warnings}"); | 327 collector.warnings.isEmpty, "Unexpected warnings: ${collector.warnings}"); |
| 336 Expect.isTrue( | 328 Expect.isTrue( |
| 337 collector.errors.isEmpty, "Unexpected errors: ${collector.errors}"); | 329 collector.errors.isEmpty, "Unexpected errors: ${collector.errors}"); |
| 338 } | 330 } |
| 339 | 331 |
| 340 Future testPatchGetter() async { | 332 Future testPatchGetter() async { |
| 341 dynamic compiler = await applyPatch( | 333 dynamic compiler = await applyPatch(""" |
| 342 """ | |
| 343 class Class { | 334 class Class { |
| 344 external int get field; | 335 external int get field; |
| 345 } | 336 } |
| 346 """, | 337 """, """ |
| 347 """ | |
| 348 @patch class Class { | 338 @patch class Class { |
| 349 @patch int get field => 5; | 339 @patch int get field => 5; |
| 350 } | 340 } |
| 351 """); | 341 """); |
| 352 dynamic container = ensure( | 342 dynamic container = ensure( |
| 353 compiler, "Class", compiler.resolution.commonElements.coreLibrary.find, | 343 compiler, "Class", compiler.resolution.commonElements.coreLibrary.find, |
| 354 expectIsPatched: true); | 344 expectIsPatched: true); |
| 355 container.parseNode(compiler.parsingContext); | 345 container.parseNode(compiler.parsingContext); |
| 356 ensure(compiler, "field", container.lookupLocalMember, | 346 ensure(compiler, "field", container.lookupLocalMember, |
| 357 expectIsGetter: true, expectIsPatched: true, checkHasBody: true); | 347 expectIsGetter: true, expectIsPatched: true, checkHasBody: true); |
| 358 ensure(compiler, "field", container.patch.lookupLocalMember, | 348 ensure(compiler, "field", container.patch.lookupLocalMember, |
| 359 expectIsGetter: true, expectIsPatch: true, checkHasBody: true); | 349 expectIsGetter: true, expectIsPatch: true, checkHasBody: true); |
| 360 | 350 |
| 361 DiagnosticCollector collector = compiler.diagnosticCollector; | 351 DiagnosticCollector collector = compiler.diagnosticCollector; |
| 362 Expect.isTrue( | 352 Expect.isTrue( |
| 363 collector.warnings.isEmpty, "Unexpected warnings: ${collector.warnings}"); | 353 collector.warnings.isEmpty, "Unexpected warnings: ${collector.warnings}"); |
| 364 Expect.isTrue( | 354 Expect.isTrue( |
| 365 collector.errors.isEmpty, "Unexpected errors: ${collector.errors}"); | 355 collector.errors.isEmpty, "Unexpected errors: ${collector.errors}"); |
| 366 } | 356 } |
| 367 | 357 |
| 368 Future testRegularMember() async { | 358 Future testRegularMember() async { |
| 369 dynamic compiler = await applyPatch( | 359 dynamic compiler = await applyPatch(""" |
| 370 """ | |
| 371 class Class { | 360 class Class { |
| 372 void regular() {} | 361 void regular() {} |
| 373 } | 362 } |
| 374 """, | 363 """, """ |
| 375 """ | |
| 376 @patch class Class { | 364 @patch class Class { |
| 377 } | 365 } |
| 378 """); | 366 """); |
| 379 dynamic container = ensure( | 367 dynamic container = ensure( |
| 380 compiler, "Class", compiler.resolution.commonElements.coreLibrary.find, | 368 compiler, "Class", compiler.resolution.commonElements.coreLibrary.find, |
| 381 expectIsPatched: true); | 369 expectIsPatched: true); |
| 382 container.parseNode(compiler.parsingContext); | 370 container.parseNode(compiler.parsingContext); |
| 383 ensure(compiler, "Class", | 371 ensure(compiler, "Class", |
| 384 compiler.resolution.commonElements.coreLibrary.patch.find, | 372 compiler.resolution.commonElements.coreLibrary.patch.find, |
| 385 expectIsPatch: true); | 373 expectIsPatch: true); |
| 386 | 374 |
| 387 ensure(compiler, "regular", container.lookupLocalMember, | 375 ensure(compiler, "regular", container.lookupLocalMember, |
| 388 checkHasBody: true, expectIsRegular: true); | 376 checkHasBody: true, expectIsRegular: true); |
| 389 ensure(compiler, "regular", container.patch.lookupLocalMember, | 377 ensure(compiler, "regular", container.patch.lookupLocalMember, |
| 390 checkHasBody: true, expectIsRegular: true); | 378 checkHasBody: true, expectIsRegular: true); |
| 391 | 379 |
| 392 DiagnosticCollector collector = compiler.diagnosticCollector; | 380 DiagnosticCollector collector = compiler.diagnosticCollector; |
| 393 Expect.isTrue( | 381 Expect.isTrue( |
| 394 collector.warnings.isEmpty, "Unexpected warnings: ${collector.warnings}"); | 382 collector.warnings.isEmpty, "Unexpected warnings: ${collector.warnings}"); |
| 395 Expect.isTrue( | 383 Expect.isTrue( |
| 396 collector.errors.isEmpty, "Unexpected errors: ${collector.errors}"); | 384 collector.errors.isEmpty, "Unexpected errors: ${collector.errors}"); |
| 397 } | 385 } |
| 398 | 386 |
| 399 Future testInjectedMember() async { | 387 Future testInjectedMember() async { |
| 400 dynamic compiler = await applyPatch( | 388 dynamic compiler = await applyPatch(""" |
| 401 """ | |
| 402 class Class { | 389 class Class { |
| 403 } | 390 } |
| 404 """, | 391 """, """ |
| 405 """ | |
| 406 @patch class Class { | 392 @patch class Class { |
| 407 void _injected() {} | 393 void _injected() {} |
| 408 } | 394 } |
| 409 """); | 395 """); |
| 410 dynamic container = ensure( | 396 dynamic container = ensure( |
| 411 compiler, "Class", compiler.resolution.commonElements.coreLibrary.find, | 397 compiler, "Class", compiler.resolution.commonElements.coreLibrary.find, |
| 412 expectIsPatched: true); | 398 expectIsPatched: true); |
| 413 container.parseNode(compiler.parsingContext); | 399 container.parseNode(compiler.parsingContext); |
| 414 ensure(compiler, "Class", | 400 ensure(compiler, "Class", |
| 415 compiler.resolution.commonElements.coreLibrary.patch.find, | 401 compiler.resolution.commonElements.coreLibrary.patch.find, |
| 416 expectIsPatch: true); | 402 expectIsPatch: true); |
| 417 | 403 |
| 418 ensure(compiler, "_injected", container.lookupLocalMember, | 404 ensure(compiler, "_injected", container.lookupLocalMember, |
| 419 expectIsFound: false); | 405 expectIsFound: false); |
| 420 ensure(compiler, "_injected", container.patch.lookupLocalMember, | 406 ensure(compiler, "_injected", container.patch.lookupLocalMember, |
| 421 checkHasBody: true, expectIsRegular: true); | 407 checkHasBody: true, expectIsRegular: true); |
| 422 | 408 |
| 423 DiagnosticCollector collector = compiler.diagnosticCollector; | 409 DiagnosticCollector collector = compiler.diagnosticCollector; |
| 424 Expect.isTrue( | 410 Expect.isTrue( |
| 425 collector.warnings.isEmpty, "Unexpected warnings: ${collector.warnings}"); | 411 collector.warnings.isEmpty, "Unexpected warnings: ${collector.warnings}"); |
| 426 Expect.isTrue( | 412 Expect.isTrue( |
| 427 collector.errors.isEmpty, "Unexpected errors: ${collector.errors}"); | 413 collector.errors.isEmpty, "Unexpected errors: ${collector.errors}"); |
| 428 } | 414 } |
| 429 | 415 |
| 430 Future testInjectedPublicMember() async { | 416 Future testInjectedPublicMember() async { |
| 431 dynamic compiler = await applyPatch( | 417 dynamic compiler = await applyPatch(""" |
| 432 """ | |
| 433 class Class { | 418 class Class { |
| 434 } | 419 } |
| 435 """, | 420 """, """ |
| 436 """ | |
| 437 @patch class Class { | 421 @patch class Class { |
| 438 void injected() {} | 422 void injected() {} |
| 439 } | 423 } |
| 440 """); | 424 """); |
| 441 dynamic container = ensure( | 425 dynamic container = ensure( |
| 442 compiler, "Class", compiler.resolution.commonElements.coreLibrary.find, | 426 compiler, "Class", compiler.resolution.commonElements.coreLibrary.find, |
| 443 expectIsPatched: true); | 427 expectIsPatched: true); |
| 444 container.parseNode(compiler.parsingContext); | 428 container.parseNode(compiler.parsingContext); |
| 445 ensure(compiler, "Class", | 429 ensure(compiler, "Class", |
| 446 compiler.resolution.commonElements.coreLibrary.patch.find, | 430 compiler.resolution.commonElements.coreLibrary.patch.find, |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 488 DiagnosticCollector collector = compiler.diagnosticCollector; | 472 DiagnosticCollector collector = compiler.diagnosticCollector; |
| 489 Expect.isTrue( | 473 Expect.isTrue( |
| 490 collector.warnings.isEmpty, "Unexpected warnings: ${collector.warnings}"); | 474 collector.warnings.isEmpty, "Unexpected warnings: ${collector.warnings}"); |
| 491 Expect.equals( | 475 Expect.equals( |
| 492 1, collector.errors.length, "Unexpected errors: ${collector.errors}"); | 476 1, collector.errors.length, "Unexpected errors: ${collector.errors}"); |
| 493 Expect.isTrue(collector.errors.first.message.kind == | 477 Expect.isTrue(collector.errors.first.message.kind == |
| 494 MessageKind.INJECTED_PUBLIC_MEMBER); | 478 MessageKind.INJECTED_PUBLIC_MEMBER); |
| 495 } | 479 } |
| 496 | 480 |
| 497 Future testPatchSignatureCheck() async { | 481 Future testPatchSignatureCheck() async { |
| 498 dynamic compiler = await applyPatch( | 482 dynamic compiler = await applyPatch(""" |
| 499 """ | |
| 500 class Class { | 483 class Class { |
| 501 external String method1(); | 484 external String method1(); |
| 502 external void method2(String str); | 485 external void method2(String str); |
| 503 external void method3(String s1); | 486 external void method3(String s1); |
| 504 external void method4([String str]); | 487 external void method4([String str]); |
| 505 external void method5({String str}); | 488 external void method5({String str}); |
| 506 external void method6({String str}); | 489 external void method6({String str}); |
| 507 external void method7([String s1]); | 490 external void method7([String s1]); |
| 508 external void method8({String s1}); | 491 external void method8({String s1}); |
| 509 external void method9(String str); | 492 external void method9(String str); |
| 510 external void method10([String str]); | 493 external void method10([String str]); |
| 511 external void method11({String str}); | 494 external void method11({String str}); |
| 512 } | 495 } |
| 513 """, | 496 """, """ |
| 514 """ | |
| 515 @patch class Class { | 497 @patch class Class { |
| 516 @patch int method1() => 0; | 498 @patch int method1() => 0; |
| 517 @patch void method2() {} | 499 @patch void method2() {} |
| 518 @patch void method3(String s2) {} | 500 @patch void method3(String s2) {} |
| 519 @patch void method4([String str, int i]) {} | 501 @patch void method4([String str, int i]) {} |
| 520 @patch void method5() {} | 502 @patch void method5() {} |
| 521 @patch void method6([String str]) {} | 503 @patch void method6([String str]) {} |
| 522 @patch void method7([String s2]) {} | 504 @patch void method7([String s2]) {} |
| 523 @patch void method8({String s2}) {} | 505 @patch void method8({String s2}) {} |
| 524 @patch void method9(int str) {} | 506 @patch void method9(int str) {} |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 564 [MessageKind.PATCH_PARAMETER_MISMATCH]); | 546 [MessageKind.PATCH_PARAMETER_MISMATCH]); |
| 565 expect("method9", [MessageKind.PATCH_POINT_TO_PARAMETER], | 547 expect("method9", [MessageKind.PATCH_POINT_TO_PARAMETER], |
| 566 [MessageKind.PATCH_PARAMETER_TYPE_MISMATCH]); | 548 [MessageKind.PATCH_PARAMETER_TYPE_MISMATCH]); |
| 567 expect("method10", [MessageKind.PATCH_POINT_TO_PARAMETER], | 549 expect("method10", [MessageKind.PATCH_POINT_TO_PARAMETER], |
| 568 [MessageKind.PATCH_PARAMETER_TYPE_MISMATCH]); | 550 [MessageKind.PATCH_PARAMETER_TYPE_MISMATCH]); |
| 569 expect("method11", [MessageKind.PATCH_POINT_TO_PARAMETER], | 551 expect("method11", [MessageKind.PATCH_POINT_TO_PARAMETER], |
| 570 [MessageKind.PATCH_PARAMETER_TYPE_MISMATCH]); | 552 [MessageKind.PATCH_PARAMETER_TYPE_MISMATCH]); |
| 571 } | 553 } |
| 572 | 554 |
| 573 Future testExternalWithoutImplementationTopLevel() async { | 555 Future testExternalWithoutImplementationTopLevel() async { |
| 574 dynamic compiler = await applyPatch( | 556 dynamic compiler = await applyPatch(""" |
| 575 """ | |
| 576 external void foo(); | 557 external void foo(); |
| 577 """, | 558 """, """ |
| 578 """ | |
| 579 // @patch void foo() {} | 559 // @patch void foo() {} |
| 580 """); | 560 """); |
| 581 dynamic function = ensure( | 561 dynamic function = ensure( |
| 582 compiler, "foo", compiler.resolution.commonElements.coreLibrary.find); | 562 compiler, "foo", compiler.resolution.commonElements.coreLibrary.find); |
| 583 compiler.resolver.resolve(function); | 563 compiler.resolver.resolve(function); |
| 584 DiagnosticCollector collector = compiler.diagnosticCollector; | 564 DiagnosticCollector collector = compiler.diagnosticCollector; |
| 585 Expect.isTrue( | 565 Expect.isTrue( |
| 586 collector.warnings.isEmpty, "Unexpected warnings: ${collector.warnings}"); | 566 collector.warnings.isEmpty, "Unexpected warnings: ${collector.warnings}"); |
| 587 print('testExternalWithoutImplementationTopLevel:${collector.errors}'); | 567 print('testExternalWithoutImplementationTopLevel:${collector.errors}'); |
| 588 Expect.equals(1, collector.errors.length); | 568 Expect.equals(1, collector.errors.length); |
| 589 Expect.isTrue(collector.errors.first.message.kind == | 569 Expect.isTrue(collector.errors.first.message.kind == |
| 590 MessageKind.PATCH_EXTERNAL_WITHOUT_IMPLEMENTATION); | 570 MessageKind.PATCH_EXTERNAL_WITHOUT_IMPLEMENTATION); |
| 591 Expect.stringEquals('External method without an implementation.', | 571 Expect.stringEquals('External method without an implementation.', |
| 592 collector.errors.first.message.toString()); | 572 collector.errors.first.message.toString()); |
| 593 } | 573 } |
| 594 | 574 |
| 595 Future testExternalWithoutImplementationMember() async { | 575 Future testExternalWithoutImplementationMember() async { |
| 596 dynamic compiler = await applyPatch( | 576 dynamic compiler = await applyPatch(""" |
| 597 """ | |
| 598 class Class { | 577 class Class { |
| 599 external void foo(); | 578 external void foo(); |
| 600 } | 579 } |
| 601 """, | 580 """, """ |
| 602 """ | |
| 603 @patch class Class { | 581 @patch class Class { |
| 604 // @patch void foo() {} | 582 // @patch void foo() {} |
| 605 } | 583 } |
| 606 """); | 584 """); |
| 607 dynamic container = ensure( | 585 dynamic container = ensure( |
| 608 compiler, "Class", compiler.resolution.commonElements.coreLibrary.find, | 586 compiler, "Class", compiler.resolution.commonElements.coreLibrary.find, |
| 609 expectIsPatched: true); | 587 expectIsPatched: true); |
| 610 container.parseNode(compiler.parsingContext); | 588 container.parseNode(compiler.parsingContext); |
| 611 DiagnosticCollector collector = compiler.diagnosticCollector; | 589 DiagnosticCollector collector = compiler.diagnosticCollector; |
| 612 collector.clear(); | 590 collector.clear(); |
| 613 compiler.resolver.resolveMethodElement( | 591 compiler.resolver.resolveMethodElement( |
| 614 ensure(compiler, "foo", container.lookupLocalMember)); | 592 ensure(compiler, "foo", container.lookupLocalMember)); |
| 615 Expect.isTrue( | 593 Expect.isTrue( |
| 616 collector.warnings.isEmpty, "Unexpected warnings: ${collector.warnings}"); | 594 collector.warnings.isEmpty, "Unexpected warnings: ${collector.warnings}"); |
| 617 print('testExternalWithoutImplementationMember:${collector.errors}'); | 595 print('testExternalWithoutImplementationMember:${collector.errors}'); |
| 618 Expect.equals(1, collector.errors.length); | 596 Expect.equals(1, collector.errors.length); |
| 619 Expect.isTrue(collector.errors.first.message.kind == | 597 Expect.isTrue(collector.errors.first.message.kind == |
| 620 MessageKind.PATCH_EXTERNAL_WITHOUT_IMPLEMENTATION); | 598 MessageKind.PATCH_EXTERNAL_WITHOUT_IMPLEMENTATION); |
| 621 Expect.stringEquals('External method without an implementation.', | 599 Expect.stringEquals('External method without an implementation.', |
| 622 collector.errors.first.message.toString()); | 600 collector.errors.first.message.toString()); |
| 623 } | 601 } |
| 624 | 602 |
| 625 Future testIsSubclass() async { | 603 Future testIsSubclass() async { |
| 626 dynamic compiler = await applyPatch( | 604 dynamic compiler = await applyPatch(""" |
| 627 """ | |
| 628 class A {} | 605 class A {} |
| 629 """, | 606 """, """ |
| 630 """ | |
| 631 @patch class A {} | 607 @patch class A {} |
| 632 """); | 608 """); |
| 633 ClassElement cls = ensure( | 609 ClassElement cls = ensure( |
| 634 compiler, "A", compiler.resolution.commonElements.coreLibrary.find, | 610 compiler, "A", compiler.resolution.commonElements.coreLibrary.find, |
| 635 expectIsPatched: true); | 611 expectIsPatched: true); |
| 636 ClassElement patch = cls.patch; | 612 ClassElement patch = cls.patch; |
| 637 Expect.isTrue(cls != patch); | 613 Expect.isTrue(cls != patch); |
| 638 Expect.isTrue(cls.isSubclassOf(patch)); | 614 Expect.isTrue(cls.isSubclassOf(patch)); |
| 639 Expect.isTrue(patch.isSubclassOf(cls)); | 615 Expect.isTrue(patch.isSubclassOf(cls)); |
| 640 } | 616 } |
| 641 | 617 |
| 642 Future testPatchNonExistingTopLevel() async { | 618 Future testPatchNonExistingTopLevel() async { |
| 643 dynamic compiler = await applyPatch( | 619 dynamic compiler = await applyPatch(""" |
| 644 """ | |
| 645 // class Class {} | 620 // class Class {} |
| 646 """, | 621 """, """ |
| 647 """ | |
| 648 @patch class Class {} | 622 @patch class Class {} |
| 649 """); | 623 """); |
| 650 DiagnosticCollector collector = compiler.diagnosticCollector; | 624 DiagnosticCollector collector = compiler.diagnosticCollector; |
| 651 Expect.isTrue( | 625 Expect.isTrue( |
| 652 collector.warnings.isEmpty, "Unexpected warnings: ${collector.warnings}"); | 626 collector.warnings.isEmpty, "Unexpected warnings: ${collector.warnings}"); |
| 653 print('testPatchNonExistingTopLevel:${collector.errors}'); | 627 print('testPatchNonExistingTopLevel:${collector.errors}'); |
| 654 Expect.equals(1, collector.errors.length); | 628 Expect.equals(1, collector.errors.length); |
| 655 Expect.isTrue( | 629 Expect.isTrue( |
| 656 collector.errors.first.message.kind == MessageKind.PATCH_NON_EXISTING); | 630 collector.errors.first.message.kind == MessageKind.PATCH_NON_EXISTING); |
| 657 } | 631 } |
| 658 | 632 |
| 659 Future testPatchNonExistingMember() async { | 633 Future testPatchNonExistingMember() async { |
| 660 dynamic compiler = await applyPatch( | 634 dynamic compiler = await applyPatch(""" |
| 661 """ | |
| 662 class Class {} | 635 class Class {} |
| 663 """, | 636 """, """ |
| 664 """ | |
| 665 @patch class Class { | 637 @patch class Class { |
| 666 @patch void foo() {} | 638 @patch void foo() {} |
| 667 } | 639 } |
| 668 """); | 640 """); |
| 669 dynamic container = ensure( | 641 dynamic container = ensure( |
| 670 compiler, "Class", compiler.resolution.commonElements.coreLibrary.find, | 642 compiler, "Class", compiler.resolution.commonElements.coreLibrary.find, |
| 671 expectIsPatched: true); | 643 expectIsPatched: true); |
| 672 container.parseNode(compiler.parsingContext); | 644 container.parseNode(compiler.parsingContext); |
| 673 DiagnosticCollector collector = compiler.diagnosticCollector; | 645 DiagnosticCollector collector = compiler.diagnosticCollector; |
| 674 | 646 |
| 675 Expect.isTrue( | 647 Expect.isTrue( |
| 676 collector.warnings.isEmpty, "Unexpected warnings: ${collector.warnings}"); | 648 collector.warnings.isEmpty, "Unexpected warnings: ${collector.warnings}"); |
| 677 print('testPatchNonExistingMember:${collector.errors}'); | 649 print('testPatchNonExistingMember:${collector.errors}'); |
| 678 Expect.equals(1, collector.errors.length); | 650 Expect.equals(1, collector.errors.length); |
| 679 Expect.isTrue( | 651 Expect.isTrue( |
| 680 collector.errors.first.message.kind == MessageKind.PATCH_NON_EXISTING); | 652 collector.errors.first.message.kind == MessageKind.PATCH_NON_EXISTING); |
| 681 } | 653 } |
| 682 | 654 |
| 683 Future testPatchNonPatchablePatch() async { | 655 Future testPatchNonPatchablePatch() async { |
| 684 dynamic compiler = await applyPatch( | 656 dynamic compiler = await applyPatch(""" |
| 685 """ | |
| 686 external get foo; | 657 external get foo; |
| 687 """, | 658 """, """ |
| 688 """ | |
| 689 @patch var foo; | 659 @patch var foo; |
| 690 """); | 660 """); |
| 691 ensure(compiler, "foo", compiler.resolution.commonElements.coreLibrary.find); | 661 ensure(compiler, "foo", compiler.resolution.commonElements.coreLibrary.find); |
| 692 | 662 |
| 693 DiagnosticCollector collector = compiler.diagnosticCollector; | 663 DiagnosticCollector collector = compiler.diagnosticCollector; |
| 694 Expect.isTrue( | 664 Expect.isTrue( |
| 695 collector.warnings.isEmpty, "Unexpected warnings: ${collector.warnings}"); | 665 collector.warnings.isEmpty, "Unexpected warnings: ${collector.warnings}"); |
| 696 print('testPatchNonPatchablePatch:${collector.errors}'); | 666 print('testPatchNonPatchablePatch:${collector.errors}'); |
| 697 Expect.equals(1, collector.errors.length); | 667 Expect.equals(1, collector.errors.length); |
| 698 Expect.isTrue( | 668 Expect.isTrue( |
| 699 collector.errors.first.message.kind == MessageKind.PATCH_NONPATCHABLE); | 669 collector.errors.first.message.kind == MessageKind.PATCH_NONPATCHABLE); |
| 700 } | 670 } |
| 701 | 671 |
| 702 Future testPatchNonPatchableOrigin() async { | 672 Future testPatchNonPatchableOrigin() async { |
| 703 dynamic compiler = await applyPatch( | 673 dynamic compiler = await applyPatch(""" |
| 704 """ | |
| 705 external var foo; | 674 external var foo; |
| 706 """, | 675 """, """ |
| 707 """ | |
| 708 @patch get foo => 0; | 676 @patch get foo => 0; |
| 709 """); | 677 """); |
| 710 ensure(compiler, "foo", compiler.resolution.commonElements.coreLibrary.find); | 678 ensure(compiler, "foo", compiler.resolution.commonElements.coreLibrary.find); |
| 711 | 679 |
| 712 DiagnosticCollector collector = compiler.diagnosticCollector; | 680 DiagnosticCollector collector = compiler.diagnosticCollector; |
| 713 Expect.isTrue( | 681 Expect.isTrue( |
| 714 collector.warnings.isEmpty, "Unexpected warnings: ${collector.warnings}"); | 682 collector.warnings.isEmpty, "Unexpected warnings: ${collector.warnings}"); |
| 715 print('testPatchNonPatchableOrigin:${collector.errors}'); | 683 print('testPatchNonPatchableOrigin:${collector.errors}'); |
| 716 Expect.equals(2, collector.errors.length); | 684 Expect.equals(2, collector.errors.length); |
| 717 Expect.equals( | 685 Expect.equals( |
| 718 MessageKind.EXTRANEOUS_MODIFIER, collector.errors.first.message.kind); | 686 MessageKind.EXTRANEOUS_MODIFIER, collector.errors.first.message.kind); |
| 719 Expect.equals( | 687 Expect.equals( |
| 720 // TODO(ahe): Eventually, this error should be removed as it will be | 688 // TODO(ahe): Eventually, this error should be removed as it will be |
| 721 // handled by the regular parser. | 689 // handled by the regular parser. |
| 722 MessageKind.PATCH_NONPATCHABLE, | 690 MessageKind.PATCH_NONPATCHABLE, |
| 723 collector.errors.elementAt(1).message.kind); | 691 collector.errors.elementAt(1).message.kind); |
| 724 } | 692 } |
| 725 | 693 |
| 726 Future testPatchNonExternalTopLevel() async { | 694 Future testPatchNonExternalTopLevel() async { |
| 727 dynamic compiler = await applyPatch( | 695 dynamic compiler = await applyPatch(""" |
| 728 """ | |
| 729 void foo() {} | 696 void foo() {} |
| 730 """, | 697 """, """ |
| 731 """ | |
| 732 @patch void foo() {} | 698 @patch void foo() {} |
| 733 """); | 699 """); |
| 734 DiagnosticCollector collector = compiler.diagnosticCollector; | 700 DiagnosticCollector collector = compiler.diagnosticCollector; |
| 735 print('testPatchNonExternalTopLevel.errors:${collector.errors}'); | 701 print('testPatchNonExternalTopLevel.errors:${collector.errors}'); |
| 736 print('testPatchNonExternalTopLevel.warnings:${collector.warnings}'); | 702 print('testPatchNonExternalTopLevel.warnings:${collector.warnings}'); |
| 737 Expect.equals(1, collector.errors.length); | 703 Expect.equals(1, collector.errors.length); |
| 738 Expect.isTrue( | 704 Expect.isTrue( |
| 739 collector.errors.first.message.kind == MessageKind.PATCH_NON_EXTERNAL); | 705 collector.errors.first.message.kind == MessageKind.PATCH_NON_EXTERNAL); |
| 740 Expect.equals(0, collector.warnings.length); | 706 Expect.equals(0, collector.warnings.length); |
| 741 Expect.equals(1, collector.infos.length); | 707 Expect.equals(1, collector.infos.length); |
| 742 Expect.isTrue(collector.infos.first.message.kind == | 708 Expect.isTrue(collector.infos.first.message.kind == |
| 743 MessageKind.PATCH_POINT_TO_FUNCTION); | 709 MessageKind.PATCH_POINT_TO_FUNCTION); |
| 744 } | 710 } |
| 745 | 711 |
| 746 Future testPatchNonExternalMember() async { | 712 Future testPatchNonExternalMember() async { |
| 747 dynamic compiler = await applyPatch( | 713 dynamic compiler = await applyPatch(""" |
| 748 """ | |
| 749 class Class { | 714 class Class { |
| 750 void foo() {} | 715 void foo() {} |
| 751 } | 716 } |
| 752 """, | 717 """, """ |
| 753 """ | |
| 754 @patch class Class { | 718 @patch class Class { |
| 755 @patch void foo() {} | 719 @patch void foo() {} |
| 756 } | 720 } |
| 757 """); | 721 """); |
| 758 dynamic container = ensure( | 722 dynamic container = ensure( |
| 759 compiler, "Class", compiler.resolution.commonElements.coreLibrary.find, | 723 compiler, "Class", compiler.resolution.commonElements.coreLibrary.find, |
| 760 expectIsPatched: true); | 724 expectIsPatched: true); |
| 761 container.parseNode(compiler.parsingContext); | 725 container.parseNode(compiler.parsingContext); |
| 762 | 726 |
| 763 DiagnosticCollector collector = compiler.diagnosticCollector; | 727 DiagnosticCollector collector = compiler.diagnosticCollector; |
| 764 print('testPatchNonExternalMember.errors:${collector.errors}'); | 728 print('testPatchNonExternalMember.errors:${collector.errors}'); |
| 765 print('testPatchNonExternalMember.warnings:${collector.warnings}'); | 729 print('testPatchNonExternalMember.warnings:${collector.warnings}'); |
| 766 Expect.equals(1, collector.errors.length); | 730 Expect.equals(1, collector.errors.length); |
| 767 Expect.isTrue( | 731 Expect.isTrue( |
| 768 collector.errors.first.message.kind == MessageKind.PATCH_NON_EXTERNAL); | 732 collector.errors.first.message.kind == MessageKind.PATCH_NON_EXTERNAL); |
| 769 Expect.equals(0, collector.warnings.length); | 733 Expect.equals(0, collector.warnings.length); |
| 770 Expect.equals(1, collector.infos.length); | 734 Expect.equals(1, collector.infos.length); |
| 771 Expect.isTrue(collector.infos.first.message.kind == | 735 Expect.isTrue(collector.infos.first.message.kind == |
| 772 MessageKind.PATCH_POINT_TO_FUNCTION); | 736 MessageKind.PATCH_POINT_TO_FUNCTION); |
| 773 } | 737 } |
| 774 | 738 |
| 775 Future testPatchNonClass() async { | 739 Future testPatchNonClass() async { |
| 776 dynamic compiler = await applyPatch( | 740 dynamic compiler = await applyPatch(""" |
| 777 """ | |
| 778 external void Class() {} | 741 external void Class() {} |
| 779 """, | 742 """, """ |
| 780 """ | |
| 781 @patch class Class {} | 743 @patch class Class {} |
| 782 """); | 744 """); |
| 783 DiagnosticCollector collector = compiler.diagnosticCollector; | 745 DiagnosticCollector collector = compiler.diagnosticCollector; |
| 784 print('testPatchNonClass.errors:${collector.errors}'); | 746 print('testPatchNonClass.errors:${collector.errors}'); |
| 785 print('testPatchNonClass.warnings:${collector.warnings}'); | 747 print('testPatchNonClass.warnings:${collector.warnings}'); |
| 786 Expect.equals(1, collector.errors.length); | 748 Expect.equals(1, collector.errors.length); |
| 787 Expect.isTrue( | 749 Expect.isTrue( |
| 788 collector.errors.first.message.kind == MessageKind.PATCH_NON_CLASS); | 750 collector.errors.first.message.kind == MessageKind.PATCH_NON_CLASS); |
| 789 Expect.equals(0, collector.warnings.length); | 751 Expect.equals(0, collector.warnings.length); |
| 790 Expect.equals(1, collector.infos.length); | 752 Expect.equals(1, collector.infos.length); |
| 791 Expect.isTrue( | 753 Expect.isTrue( |
| 792 collector.infos.first.message.kind == MessageKind.PATCH_POINT_TO_CLASS); | 754 collector.infos.first.message.kind == MessageKind.PATCH_POINT_TO_CLASS); |
| 793 } | 755 } |
| 794 | 756 |
| 795 Future testPatchNonGetter() async { | 757 Future testPatchNonGetter() async { |
| 796 dynamic compiler = await applyPatch( | 758 dynamic compiler = await applyPatch(""" |
| 797 """ | |
| 798 external void foo() {} | 759 external void foo() {} |
| 799 """, | 760 """, """ |
| 800 """ | |
| 801 @patch get foo => 0; | 761 @patch get foo => 0; |
| 802 """); | 762 """); |
| 803 DiagnosticCollector collector = compiler.diagnosticCollector; | 763 DiagnosticCollector collector = compiler.diagnosticCollector; |
| 804 print('testPatchNonClass.errors:${collector.errors}'); | 764 print('testPatchNonClass.errors:${collector.errors}'); |
| 805 print('testPatchNonClass.warnings:${collector.warnings}'); | 765 print('testPatchNonClass.warnings:${collector.warnings}'); |
| 806 Expect.equals(1, collector.errors.length); | 766 Expect.equals(1, collector.errors.length); |
| 807 Expect.isTrue( | 767 Expect.isTrue( |
| 808 collector.errors.first.message.kind == MessageKind.PATCH_NON_GETTER); | 768 collector.errors.first.message.kind == MessageKind.PATCH_NON_GETTER); |
| 809 Expect.equals(0, collector.warnings.length); | 769 Expect.equals(0, collector.warnings.length); |
| 810 Expect.equals(1, collector.infos.length); | 770 Expect.equals(1, collector.infos.length); |
| 811 Expect.isTrue( | 771 Expect.isTrue( |
| 812 collector.infos.first.message.kind == MessageKind.PATCH_POINT_TO_GETTER); | 772 collector.infos.first.message.kind == MessageKind.PATCH_POINT_TO_GETTER); |
| 813 } | 773 } |
| 814 | 774 |
| 815 Future testPatchNoGetter() async { | 775 Future testPatchNoGetter() async { |
| 816 dynamic compiler = await applyPatch( | 776 dynamic compiler = await applyPatch(""" |
| 817 """ | |
| 818 external set foo(var value) {} | 777 external set foo(var value) {} |
| 819 """, | 778 """, """ |
| 820 """ | |
| 821 @patch get foo => 0; | 779 @patch get foo => 0; |
| 822 """); | 780 """); |
| 823 DiagnosticCollector collector = compiler.diagnosticCollector; | 781 DiagnosticCollector collector = compiler.diagnosticCollector; |
| 824 print('testPatchNonClass.errors:${collector.errors}'); | 782 print('testPatchNonClass.errors:${collector.errors}'); |
| 825 print('testPatchNonClass.warnings:${collector.warnings}'); | 783 print('testPatchNonClass.warnings:${collector.warnings}'); |
| 826 Expect.equals(1, collector.errors.length); | 784 Expect.equals(1, collector.errors.length); |
| 827 Expect.isTrue( | 785 Expect.isTrue( |
| 828 collector.errors.first.message.kind == MessageKind.PATCH_NO_GETTER); | 786 collector.errors.first.message.kind == MessageKind.PATCH_NO_GETTER); |
| 829 Expect.equals(0, collector.warnings.length); | 787 Expect.equals(0, collector.warnings.length); |
| 830 Expect.equals(1, collector.infos.length); | 788 Expect.equals(1, collector.infos.length); |
| 831 Expect.isTrue( | 789 Expect.isTrue( |
| 832 collector.infos.first.message.kind == MessageKind.PATCH_POINT_TO_GETTER); | 790 collector.infos.first.message.kind == MessageKind.PATCH_POINT_TO_GETTER); |
| 833 } | 791 } |
| 834 | 792 |
| 835 Future testPatchNonSetter() async { | 793 Future testPatchNonSetter() async { |
| 836 dynamic compiler = await applyPatch( | 794 dynamic compiler = await applyPatch(""" |
| 837 """ | |
| 838 external void foo() {} | 795 external void foo() {} |
| 839 """, | 796 """, """ |
| 840 """ | |
| 841 @patch set foo(var value) {} | 797 @patch set foo(var value) {} |
| 842 """); | 798 """); |
| 843 DiagnosticCollector collector = compiler.diagnosticCollector; | 799 DiagnosticCollector collector = compiler.diagnosticCollector; |
| 844 print('testPatchNonClass.errors:${collector.errors}'); | 800 print('testPatchNonClass.errors:${collector.errors}'); |
| 845 print('testPatchNonClass.warnings:${collector.warnings}'); | 801 print('testPatchNonClass.warnings:${collector.warnings}'); |
| 846 Expect.equals(1, collector.errors.length); | 802 Expect.equals(1, collector.errors.length); |
| 847 Expect.isTrue( | 803 Expect.isTrue( |
| 848 collector.errors.first.message.kind == MessageKind.PATCH_NON_SETTER); | 804 collector.errors.first.message.kind == MessageKind.PATCH_NON_SETTER); |
| 849 Expect.equals(0, collector.warnings.length); | 805 Expect.equals(0, collector.warnings.length); |
| 850 Expect.equals(1, collector.infos.length); | 806 Expect.equals(1, collector.infos.length); |
| 851 Expect.isTrue( | 807 Expect.isTrue( |
| 852 collector.infos.first.message.kind == MessageKind.PATCH_POINT_TO_SETTER); | 808 collector.infos.first.message.kind == MessageKind.PATCH_POINT_TO_SETTER); |
| 853 } | 809 } |
| 854 | 810 |
| 855 Future testPatchNoSetter() async { | 811 Future testPatchNoSetter() async { |
| 856 dynamic compiler = await applyPatch( | 812 dynamic compiler = await applyPatch(""" |
| 857 """ | |
| 858 external get foo; | 813 external get foo; |
| 859 """, | 814 """, """ |
| 860 """ | |
| 861 @patch set foo(var value) {} | 815 @patch set foo(var value) {} |
| 862 """); | 816 """); |
| 863 DiagnosticCollector collector = compiler.diagnosticCollector; | 817 DiagnosticCollector collector = compiler.diagnosticCollector; |
| 864 print('testPatchNonClass.errors:${collector.errors}'); | 818 print('testPatchNonClass.errors:${collector.errors}'); |
| 865 print('testPatchNonClass.warnings:${collector.warnings}'); | 819 print('testPatchNonClass.warnings:${collector.warnings}'); |
| 866 Expect.equals(1, collector.errors.length); | 820 Expect.equals(1, collector.errors.length); |
| 867 Expect.isTrue( | 821 Expect.isTrue( |
| 868 collector.errors.first.message.kind == MessageKind.PATCH_NO_SETTER); | 822 collector.errors.first.message.kind == MessageKind.PATCH_NO_SETTER); |
| 869 Expect.equals(0, collector.warnings.length); | 823 Expect.equals(0, collector.warnings.length); |
| 870 Expect.equals(1, collector.infos.length); | 824 Expect.equals(1, collector.infos.length); |
| 871 Expect.isTrue( | 825 Expect.isTrue( |
| 872 collector.infos.first.message.kind == MessageKind.PATCH_POINT_TO_SETTER); | 826 collector.infos.first.message.kind == MessageKind.PATCH_POINT_TO_SETTER); |
| 873 } | 827 } |
| 874 | 828 |
| 875 Future testPatchNonFunction() async { | 829 Future testPatchNonFunction() async { |
| 876 dynamic compiler = await applyPatch( | 830 dynamic compiler = await applyPatch(""" |
| 877 """ | |
| 878 external get foo; | 831 external get foo; |
| 879 """, | 832 """, """ |
| 880 """ | |
| 881 @patch void foo() {} | 833 @patch void foo() {} |
| 882 """); | 834 """); |
| 883 DiagnosticCollector collector = compiler.diagnosticCollector; | 835 DiagnosticCollector collector = compiler.diagnosticCollector; |
| 884 print('testPatchNonClass.errors:${collector.errors}'); | 836 print('testPatchNonClass.errors:${collector.errors}'); |
| 885 print('testPatchNonClass.warnings:${collector.warnings}'); | 837 print('testPatchNonClass.warnings:${collector.warnings}'); |
| 886 Expect.equals(1, collector.errors.length); | 838 Expect.equals(1, collector.errors.length); |
| 887 Expect.isTrue( | 839 Expect.isTrue( |
| 888 collector.errors.first.message.kind == MessageKind.PATCH_NON_FUNCTION); | 840 collector.errors.first.message.kind == MessageKind.PATCH_NON_FUNCTION); |
| 889 Expect.equals(0, collector.warnings.length); | 841 Expect.equals(0, collector.warnings.length); |
| 890 Expect.equals(1, collector.infos.length); | 842 Expect.equals(1, collector.infos.length); |
| 891 Expect.isTrue(collector.infos.first.message.kind == | 843 Expect.isTrue(collector.infos.first.message.kind == |
| 892 MessageKind.PATCH_POINT_TO_FUNCTION); | 844 MessageKind.PATCH_POINT_TO_FUNCTION); |
| 893 } | 845 } |
| 894 | 846 |
| 895 Future testPatchAndSelector() async { | 847 Future testPatchAndSelector() async { |
| 896 dynamic compiler = await applyPatch( | 848 dynamic compiler = await applyPatch(""" |
| 897 """ | |
| 898 class A { | 849 class A { |
| 899 external void clear(); | 850 external void clear(); |
| 900 } | 851 } |
| 901 class B extends A { | 852 class B extends A { |
| 902 } | 853 } |
| 903 """, | 854 """, """ |
| 904 """ | |
| 905 @patch class A { | 855 @patch class A { |
| 906 int method() => 0; | 856 int method() => 0; |
| 907 @patch void clear() {} | 857 @patch void clear() {} |
| 908 } | 858 } |
| 909 """, | 859 """, main: """ |
| 910 main: """ | |
| 911 main () { | 860 main () { |
| 912 new A(); // ensure A and B are instantiated | 861 new A(); // ensure A and B are instantiated |
| 913 new B(); | 862 new B(); |
| 914 } | 863 } |
| 915 """, | 864 """, runCompiler: true, analyzeOnly: true); |
| 916 runCompiler: true, | |
| 917 analyzeOnly: true); | |
| 918 compiler.closeResolution( | 865 compiler.closeResolution( |
| 919 compiler.frontendStrategy.elementEnvironment.mainFunction); | 866 compiler.frontendStrategy.elementEnvironment.mainFunction); |
| 920 ClosedWorld world = compiler.resolutionWorldBuilder.closedWorldForTesting; | 867 ClosedWorld world = compiler.resolutionWorldBuilder.closedWorldForTesting; |
| 921 | 868 |
| 922 ClassElement cls = ensure( | 869 ClassElement cls = ensure( |
| 923 compiler, "A", compiler.resolution.commonElements.coreLibrary.find, | 870 compiler, "A", compiler.resolution.commonElements.coreLibrary.find, |
| 924 expectIsPatched: true); | 871 expectIsPatched: true); |
| 925 cls.ensureResolved(compiler.resolution); | 872 cls.ensureResolved(compiler.resolution); |
| 926 | 873 |
| 927 ensure(compiler, "method", cls.patch.lookupLocalMember, | 874 ensure(compiler, "method", cls.patch.lookupLocalMember, |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 972 dynamic compiler = | 919 dynamic compiler = |
| 973 await applyPatch('', patchText, analyzeAll: true, analyzeOnly: true); | 920 await applyPatch('', patchText, analyzeAll: true, analyzeOnly: true); |
| 974 compiler.librariesToAnalyzeWhenRun = [Uri.parse('dart:core')]; | 921 compiler.librariesToAnalyzeWhenRun = [Uri.parse('dart:core')]; |
| 975 await compiler.run(null); | 922 await compiler.run(null); |
| 976 DiagnosticCollector collector = compiler.diagnosticCollector; | 923 DiagnosticCollector collector = compiler.diagnosticCollector; |
| 977 compareWarningKinds(patchText, expectedWarnings, collector.warnings); | 924 compareWarningKinds(patchText, expectedWarnings, collector.warnings); |
| 978 } | 925 } |
| 979 | 926 |
| 980 await expect('String s = 0;', MessageKind.NOT_ASSIGNABLE); | 927 await expect('String s = 0;', MessageKind.NOT_ASSIGNABLE); |
| 981 await expect('void method() { String s = 0; }', MessageKind.NOT_ASSIGNABLE); | 928 await expect('void method() { String s = 0; }', MessageKind.NOT_ASSIGNABLE); |
| 982 await expect( | 929 await expect(''' |
| 983 ''' | |
| 984 class Class { | 930 class Class { |
| 985 String s = 0; | 931 String s = 0; |
| 986 } | 932 } |
| 987 ''', | 933 ''', MessageKind.NOT_ASSIGNABLE); |
| 988 MessageKind.NOT_ASSIGNABLE); | 934 await expect(''' |
| 989 await expect( | |
| 990 ''' | |
| 991 class Class { | 935 class Class { |
| 992 void method() { | 936 void method() { |
| 993 String s = 0; | 937 String s = 0; |
| 994 } | 938 } |
| 995 } | 939 } |
| 996 ''', | 940 ''', MessageKind.NOT_ASSIGNABLE); |
| 997 MessageKind.NOT_ASSIGNABLE); | |
| 998 } | 941 } |
| 999 | 942 |
| 1000 Future testEffectiveTarget() async { | 943 Future testEffectiveTarget() async { |
| 1001 String origin = """ | 944 String origin = """ |
| 1002 class A { | 945 class A { |
| 1003 A() : super(); | 946 A() : super(); |
| 1004 factory A.forward() = B.patchTarget; | 947 factory A.forward() = B.patchTarget; |
| 1005 factory A.forwardOne() = B.patchFactory; | 948 factory A.forwardOne() = B.patchFactory; |
| 1006 factory A.forwardTwo() = B.reflectBack; | 949 factory A.forwardTwo() = B.reflectBack; |
| 1007 factory A.forwardThree() = B.patchInjected; | 950 factory A.forwardThree() = B.patchInjected; |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1116 await testPatchNonFunction(); | 1059 await testPatchNonFunction(); |
| 1117 | 1060 |
| 1118 await testPatchAndSelector(); | 1061 await testPatchAndSelector(); |
| 1119 | 1062 |
| 1120 await testEffectiveTarget(); | 1063 await testEffectiveTarget(); |
| 1121 | 1064 |
| 1122 await testAnalyzeAllInjectedMembers(); | 1065 await testAnalyzeAllInjectedMembers(); |
| 1123 await testTypecheckPatchedMembers(); | 1066 await testTypecheckPatchedMembers(); |
| 1124 }); | 1067 }); |
| 1125 } | 1068 } |
| OLD | NEW |