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:uri"; | 5 import "dart:uri"; |
6 import "../../../sdk/lib/_internal/compiler/implementation/elements/elements.dar
t"; | 6 import "../../../sdk/lib/_internal/compiler/implementation/elements/elements.dar
t"; |
7 import '../../../sdk/lib/_internal/compiler/implementation/scanner/scannerlib.da
rt'; | 7 import '../../../sdk/lib/_internal/compiler/implementation/scanner/scannerlib.da
rt'; |
8 import '../../../sdk/lib/_internal/compiler/implementation/source_file.dart'; | 8 import '../../../sdk/lib/_internal/compiler/implementation/source_file.dart'; |
9 import '../../../sdk/lib/_internal/compiler/implementation/types/types.dart'; | 9 import '../../../sdk/lib/_internal/compiler/implementation/types/types.dart'; |
10 import '../../../sdk/lib/_internal/compiler/implementation/tree/tree.dart'; | 10 import '../../../sdk/lib/_internal/compiler/implementation/tree/tree.dart'; |
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
347 result.checkFieldHasType('A', 'y', [result.string, new NullBaseType()]); | 347 result.checkFieldHasType('A', 'y', [result.string, new NullBaseType()]); |
348 result.checkFieldHasType('A', 'z', [result.string]); | 348 result.checkFieldHasType('A', 'z', [result.string]); |
349 } | 349 } |
350 | 350 |
351 testGetters() { | 351 testGetters() { |
352 final String source = r""" | 352 final String source = r""" |
353 class A { | 353 class A { |
354 var x; | 354 var x; |
355 A(this.x); | 355 A(this.x); |
356 get y => x; | 356 get y => x; |
| 357 get z => y; |
357 } | 358 } |
358 main() { | 359 main() { |
359 var a = new A(42); | 360 var a = new A(42); |
360 var foo = a.x; | 361 var foo = a.x; |
361 var bar = a.y; | 362 var bar = a.y; |
362 foo; bar; | 363 var baz = a.z; |
| 364 foo; bar; baz; |
363 } | 365 } |
364 """; | 366 """; |
365 AnalysisResult result = analyze(source); | 367 AnalysisResult result = analyze(source); |
366 result.checkNodeHasType('foo', [result.int]); | 368 result.checkNodeHasType('foo', [result.int]); |
367 result.checkNodeHasType('bar', [result.int]); | 369 result.checkNodeHasType('bar', [result.int]); |
| 370 result.checkNodeHasType('baz', [result.int]); |
368 } | 371 } |
369 | 372 |
370 testSetters() { | 373 testSetters() { |
371 final String source = r""" | 374 final String source = r""" |
372 class A { | 375 class A { |
373 var x; | 376 var x; |
374 A(this.x); | 377 var w; |
375 set y(a) { x = a; } | 378 A(this.x, this.w); |
| 379 set y(a) { x = a; z = a; } |
| 380 set z(a) { w = a; } |
376 } | 381 } |
377 main() { | 382 main() { |
378 var a = new A(42); | 383 var a = new A(42, 42); |
379 a.x = 'abc'; | 384 a.x = 'abc'; |
380 a.y = true; | 385 a.y = true; |
381 } | 386 } |
382 """; | 387 """; |
383 AnalysisResult result = analyze(source); | 388 AnalysisResult result = analyze(source); |
384 result.checkFieldHasType('A', 'x', [result.int, result.string, result.bool]); | 389 result.checkFieldHasType('A', 'x', [result.int, result.string, result.bool]); |
| 390 result.checkFieldHasType('A', 'w', [result.int, result.bool]); |
385 } | 391 } |
386 | 392 |
387 testNamedParameters() { | 393 testNamedParameters() { |
388 final String source = r""" | 394 final String source = r""" |
389 class A { | 395 class A { |
390 var x, y, z, w; | 396 var x, y, z, w; |
391 A(this.x, {this.y, this.z, this.w}); | 397 A(this.x, {this.y, this.z, this.w}); |
392 } | 398 } |
393 main() { | 399 main() { |
394 new A(42); | 400 new A(42); |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
514 var x = new A() < "foo"; | 520 var x = new A() < "foo"; |
515 var y = new A() << "foo"; | 521 var y = new A() << "foo"; |
516 x; y; | 522 x; y; |
517 } | 523 } |
518 """; | 524 """; |
519 AnalysisResult result = analyze(source); | 525 AnalysisResult result = analyze(source); |
520 result.checkNodeHasType('x', [result.int]); | 526 result.checkNodeHasType('x', [result.int]); |
521 result.checkNodeHasType('y', [result.string]); | 527 result.checkNodeHasType('y', [result.string]); |
522 } | 528 } |
523 | 529 |
| 530 testCompoundOperators1() { |
| 531 final String source = r""" |
| 532 class A { |
| 533 operator +(x) => "foo"; |
| 534 } |
| 535 main() { |
| 536 var x1 = 1; x1++; |
| 537 var x2 = 1; ++x2; |
| 538 var x3 = new A(); x3++; |
| 539 var x4 = new A(); ++x4; |
| 540 |
| 541 x1; x2; x3; x4; |
| 542 } |
| 543 """; |
| 544 AnalysisResult result = analyze(source); |
| 545 result.checkNodeHasType('x1', [result.int]); |
| 546 result.checkNodeHasType('x2', [result.int]); |
| 547 result.checkNodeHasType('x3', [result.string]); |
| 548 result.checkNodeHasType('x4', [result.string]); |
| 549 } |
| 550 |
| 551 |
| 552 testCompoundOperators2() { |
| 553 final String source = r""" |
| 554 class A { |
| 555 var xx; |
| 556 var witness1; |
| 557 var witness2; |
| 558 |
| 559 A(this.xx); |
| 560 get x { witness1 = "foo"; return xx; } |
| 561 set x(y) { witness2 = "foo"; xx = y; } |
| 562 } |
| 563 main () { |
| 564 var a = new A(1); |
| 565 a.x++; |
| 566 } |
| 567 """; |
| 568 AnalysisResult result = analyze(source); |
| 569 result.checkFieldHasType('A', 'xx', [result.int]); |
| 570 // TODO(polux): the two following results should be {null, string}, see |
| 571 // fieldInitialization(). |
| 572 result.checkFieldHasType('A', 'witness1', [result.string]); |
| 573 result.checkFieldHasType('A', 'witness2', [result.string]); |
| 574 } |
| 575 |
| 576 testFieldInitialization() { |
| 577 final String source = r""" |
| 578 class A { |
| 579 var x; |
| 580 var y = 1; |
| 581 } |
| 582 main () { |
| 583 new A(); |
| 584 } |
| 585 """; |
| 586 AnalysisResult result = analyze(source); |
| 587 result.checkFieldHasType('A', 'x', [result.nullType]); |
| 588 result.checkFieldHasType('A', 'y', [result.int]); |
| 589 } |
| 590 |
524 void main() { | 591 void main() { |
525 testLiterals(); | 592 testLiterals(); |
526 testRedefinition(); | 593 testRedefinition(); |
527 testIfThenElse(); | 594 testIfThenElse(); |
528 testTernaryIf(); | 595 testTernaryIf(); |
529 testWhile(); | 596 testWhile(); |
530 testFor1(); | 597 testFor1(); |
531 testFor2(); | 598 testFor2(); |
532 testNonRecusiveFunction(); | 599 testNonRecusiveFunction(); |
533 testRecusiveFunction(); | 600 testRecusiveFunction(); |
534 testMutuallyRecusiveFunction(); | 601 testMutuallyRecusiveFunction(); |
535 testSendToThis1(); | 602 testSendToThis1(); |
536 testSendToThis2(); | 603 testSendToThis2(); |
537 testConstructor(); | 604 testConstructor(); |
538 testGetters(); | 605 testGetters(); |
539 testSetters(); | 606 testSetters(); |
540 testNamedParameters(); | 607 testNamedParameters(); |
541 testListLiterals(); | 608 testListLiterals(); |
542 testMapLiterals(); | 609 testMapLiterals(); |
543 testReturn(); | 610 testReturn(); |
544 // testNoReturn(); // right now we infer the empty type instead of null | 611 // testNoReturn(); // right now we infer the empty type instead of null |
545 testArithmeticOperators(); | 612 testArithmeticOperators(); |
546 testOperators(); | 613 testOperators(); |
| 614 testCompoundOperators1(); |
| 615 testCompoundOperators2(); |
| 616 // testFieldInitialization(); // TODO(polux) |
547 } | 617 } |
OLD | NEW |