Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(416)

Side by Side Diff: tests/compiler/dart2js/cpa_inference_test.dart

Issue 11272032: Handle compound operators. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 "../../../lib/compiler/implementation/elements/elements.dart"; 6 import "../../../lib/compiler/implementation/elements/elements.dart";
7 import '../../../lib/compiler/implementation/scanner/scannerlib.dart'; 7 import '../../../lib/compiler/implementation/scanner/scannerlib.dart';
8 import '../../../lib/compiler/implementation/source_file.dart'; 8 import '../../../lib/compiler/implementation/source_file.dart';
9 import '../../../lib/compiler/implementation/types/types.dart'; 9 import '../../../lib/compiler/implementation/types/types.dart';
10 import '../../../lib/compiler/implementation/tree/tree.dart'; 10 import '../../../lib/compiler/implementation/tree/tree.dart';
(...skipping 502 matching lines...) Expand 10 before | Expand all | Expand 10 after
513 var x = new A() < "foo"; 513 var x = new A() < "foo";
514 var y = new A() << "foo"; 514 var y = new A() << "foo";
515 x; y; 515 x; y;
516 } 516 }
517 """; 517 """;
518 AnalysisResult result = analyze(source); 518 AnalysisResult result = analyze(source);
519 result.checkNodeHasType('x', [result.int]); 519 result.checkNodeHasType('x', [result.int]);
520 result.checkNodeHasType('y', [result.string]); 520 result.checkNodeHasType('y', [result.string]);
521 } 521 }
522 522
523 testCompoundOperators1() {
524 final String source = r"""
525 class A {
526 operator +(x) => "foo";
527 }
528 main() {
529 var x1 = 1; x1++;
530 var x2 = 1; ++x2;
531 var x3 = new A(); x3++;
532 var x4 = new A(); ++x4;
533
534 x1; x2; x3; x4;
535 }
536 """;
537 AnalysisResult result = analyze(source);
538 result.checkNodeHasType('x1', [result.int]);
539 result.checkNodeHasType('x2', [result.int]);
540 result.checkNodeHasType('x3', [result.string]);
541 result.checkNodeHasType('x4', [result.string]);
542 }
543
544
545 testCompoundOperators2() {
546 final String source = r"""
547 class A {
548 var _x;
karlklose 2012/11/08 10:45:31 It is unnecessary to use privacy here; using a nor
polux 2012/11/08 14:04:50 Done.
549 var witness1;
550 var witness2;
karlklose 2012/11/08 10:45:31 witness2 is unused. Did you want to use it in the
polux 2012/11/08 14:04:50 Done.
551
552 A(this._x);
553 get x { witness1 = "foo"; return _x; }
554 set x(y) { witness1 = "foo"; _x = y; }
555 }
556 main () {
557 var a = new A(1);
558 a.x++;
559 }
560 """;
561 AnalysisResult result = analyze(source);
562 result.checkFieldHasType('A', '_x', [result.int]);
563 // TODO(polux): the two following results should be {null, string}, see
564 // fieldInitialization().
565 result.checkFieldHasType('A', 'witness1', [result.string]);
566 result.checkFieldHasType('A', 'witness1', [result.string]);
karlklose 2012/11/08 10:45:31 witness2?
polux 2012/11/08 14:04:50 Done.
567 }
568
569 testFieldInitialization() {
570 final String source = r"""
571 class A {
572 var x;
573 var y = 1;
574 }
575 main () {
576 new A();
577 }
578 """;
579 AnalysisResult result = analyze(source);
580 result.checkFieldHasType('A', 'x', [result.nullType]);
581 result.checkFieldHasType('A', 'y', [result.int]);
582 }
583
523 void main() { 584 void main() {
524 testLiterals(); 585 testLiterals();
525 testRedefinition(); 586 testRedefinition();
526 testIfThenElse(); 587 testIfThenElse();
527 testTernaryIf(); 588 testTernaryIf();
528 testWhile(); 589 testWhile();
529 testFor1(); 590 testFor1();
530 testFor2(); 591 testFor2();
531 testNonRecusiveFunction(); 592 testNonRecusiveFunction();
532 testRecusiveFunction(); 593 testRecusiveFunction();
533 testMutuallyRecusiveFunction(); 594 testMutuallyRecusiveFunction();
534 testSendToThis1(); 595 testSendToThis1();
535 testSendToThis2(); 596 testSendToThis2();
536 testConstructor(); 597 testConstructor();
537 testGetters(); 598 testGetters();
538 testSetters(); 599 testSetters();
539 testNamedParameters(); 600 testNamedParameters();
540 testListLiterals(); 601 testListLiterals();
541 testMapLiterals(); 602 testMapLiterals();
542 testReturn(); 603 testReturn();
543 // testNoReturn(); // right now we infer the empty type instead of null 604 // testNoReturn(); // right now we infer the empty type instead of null
544 testArithmeticOperators(); 605 testArithmeticOperators();
545 testOperators(); 606 testOperators();
607 testCompoundOperators1();
608 testCompoundOperators2();
609 // testFieldInitialization(); // TODO(polux)
546 } 610 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698