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

Side by Side Diff: test/browser/runtime_tests.js

Issue 1945113003: Better is/as check handling. With this CL, the subtype function in (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: Update new tests after rebase Created 4 years, 7 months 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
« no previous file with comments | « test/browser/language_tests.js ('k') | test/codegen/language/type_literal_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, 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 var assert = chai.assert; 5 var assert = chai.assert;
6 var dart_sdk = dart_library.import('dart_sdk'); 6 var dart_sdk = dart_library.import('dart_sdk');
7 var core = dart_sdk.core; 7 var core = dart_sdk.core;
8 var collection = dart_sdk.collection; 8 var collection = dart_sdk.collection;
9 var dart = dart_sdk.dart; 9 var dart = dart_sdk.dart;
10 var dartx = dart.dartx; 10 var dartx = dart.dartx;
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 197
198 let cls7 = dart.fn((b, s, o) => { return null; }, B, [B, String], [Object]); 198 let cls7 = dart.fn((b, s, o) => { return null; }, B, [B, String], [Object]);
199 199
200 let cls8 = 200 let cls8 =
201 dart.fn((b, s, o) => { return null; }, B, [B, String], {p: Object}); 201 dart.fn((b, s, o) => { return null; }, B, [B, String], {p: Object});
202 202
203 function checkType(x, type, expectedTrue, strongOnly) { 203 function checkType(x, type, expectedTrue, strongOnly) {
204 if (expectedTrue === undefined) expectedTrue = true; 204 if (expectedTrue === undefined) expectedTrue = true;
205 if (strongOnly == undefined) strongOnly = false; 205 if (strongOnly == undefined) strongOnly = false;
206 if (!strongOnly) { 206 if (!strongOnly) {
207 assert.doesNotThrow(() => instanceOf(x, type));
207 expect(instanceOf(x, type), expectedTrue); 208 expect(instanceOf(x, type), expectedTrue);
208 } else { 209 } else {
209 assert.throws(() => instanceOf(x, type), dart.StrongModeError); 210 assert.throws(() => instanceOf(x, type), dart.StrongModeError);
210 expect(strongInstanceOf(x, type), expectedTrue); 211 expect(expectedTrue, false);
212 expect(strongInstanceOf(x, type), null);
211 } 213 }
212 } 214 }
213 215
214 test('int', () => { 216 test('int', () => {
215 expect(isGroundType(int), true); 217 expect(isGroundType(int), true);
216 expect(isGroundType(getReifiedType(5)), true); 218 expect(isGroundType(getReifiedType(5)), true);
217 219
218 checkType(5, int); 220 checkType(5, int);
219 checkType(5, dynamic); 221 checkType(5, dynamic);
220 checkType(5, Object); 222 checkType(5, Object);
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 298
297 // Instance of self 299 // Instance of self
298 checkType(m1, getReifiedType(m1)); 300 checkType(m1, getReifiedType(m1));
299 checkType(m1, Map$(String, String)); 301 checkType(m1, Map$(String, String));
300 302
301 // Covariance on generics 303 // Covariance on generics
302 checkType(m1, getReifiedType(m2)); 304 checkType(m1, getReifiedType(m2));
303 checkType(m1, Map$(Object, Object)); 305 checkType(m1, Map$(Object, Object));
304 306
305 // No contravariance on generics. 307 // No contravariance on generics.
306 checkType(m2, getReifiedType(m1), false, true); 308 checkType(m2, getReifiedType(m1), false);
307 checkType(m2, Map$(String, String), false, true); 309 checkType(m2, Map$(String, String), false);
308 310
309 // null is! Map 311 // null is! Map
310 checkType(null, Map, false); 312 checkType(null, Map, false);
311 313
312 // Raw generic types 314 // Raw generic types
313 checkType(m5, Map); 315 checkType(m5, Map);
314 checkType(m4, Map); 316 checkType(m4, Map);
315 317
316 // Is checks 318 // Is checks
317 assert.throws(() => dart.is(m3, Map$(String, String)), 319 assert.throws(() => dart.is(m3, Map$(String, String)),
318 dart.StrongModeError); 320 dart.StrongModeError);
319 assert.throws(() => dart.is(m6, Map$(String, String)), 321 assert.throws(() => dart.is(m6, Map$(String, String)),
320 dart.StrongModeError); 322 dart.StrongModeError);
321 assert.isTrue(dart.is(m1, Map$(String, String))); 323 assert.isTrue(dart.is(m1, Map$(String, String)));
322 assert.throws(() => dart.is(m2, Map$(String, String)), 324 assert.isFalse(dart.is(m2, Map$(String, String)));
323 dart.StrongModeError);
324 325
325 // As checks 326 // As checks
326 // TODO(vsm): Enable these. We're currently only logging warnings on 327 // TODO(vsm): Enable these. We're currently only logging warnings on
327 // StrongModeErrors. 328 // StrongModeErrors.
328 // assert.throws(() => dart.as(m3, Map$(String, String)), 329 // assert.throws(() => dart.as(m3, Map$(String, String)),
329 // dart.StrongModeError); 330 // dart.StrongModeError);
330 // assert.throws(() => dart.as(m6, Map$(String, String)), 331 // assert.throws(() => dart.as(m6, Map$(String, String)),
331 // dart.StrongModeError); 332 // dart.StrongModeError);
332 assert.equal(dart.as(m1, Map$(String, String)), m1); 333 assert.equal(dart.as(m1, Map$(String, String)), m1);
333 // assert.throws(() => dart.as(m2, Map$(String, String)), 334 // assert.throws(() => dart.as(m2, Map$(String, String)),
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
371 // This was AA<String> in Dart (wrong number of type args). 372 // This was AA<String> in Dart (wrong number of type args).
372 let aabad = new (AA$(dart.dynamic, dart.dynamic))(); 373 let aabad = new (AA$(dart.dynamic, dart.dynamic))();
373 let aabadtype = getReifiedType(aabad); 374 let aabadtype = getReifiedType(aabad);
374 375
375 expect(isGroundType(aatype), false); 376 expect(isGroundType(aatype), false);
376 expect(isGroundType(AA$(String, List)), false); 377 expect(isGroundType(AA$(String, List)), false);
377 expect(isGroundType(bbtype), false); 378 expect(isGroundType(bbtype), false);
378 expect(isGroundType(BB$(String, List)), false); 379 expect(isGroundType(BB$(String, List)), false);
379 expect(isGroundType(cctype), true); 380 expect(isGroundType(cctype), true);
380 expect(isGroundType(CC), true); 381 expect(isGroundType(CC), true);
381 checkType(cc, aatype, false, true); 382 checkType(cc, aatype, false);
382 checkType(cc, AA$(String, List), false, true); 383 checkType(cc, AA$(String, List), false);
383 checkType(cc, bbtype); 384 checkType(cc, bbtype);
384 checkType(cc, BB$(String, List)); 385 checkType(cc, BB$(String, List));
385 checkType(aa, cctype, false); 386 checkType(aa, cctype, false);
386 checkType(aa, CC, false); 387 checkType(aa, CC, false);
387 checkType(aa, bbtype, false, true); 388 checkType(aa, bbtype, false);
388 checkType(aa, BB$(String, List), false, true); 389 checkType(aa, BB$(String, List), false);
389 checkType(bb, cctype, false); 390 checkType(bb, cctype, false);
390 checkType(bb, CC, false); 391 checkType(bb, CC, false);
391 checkType(aa, aabadtype); 392 checkType(aa, aabadtype);
392 checkType(aa, dynamic); 393 checkType(aa, dynamic);
393 checkType(aabad, aatype, false, true); 394 checkType(aabad, aatype, false, true);
394 checkType(aabad, AA$(String, List), false, true); 395 checkType(aabad, AA$(String, List), false, true);
395 checkType(aabad, aarawtype); 396 checkType(aabad, aarawtype);
396 checkType(aabad, AA); 397 checkType(aabad, AA);
397 checkType(aaraw, aabadtype); 398 checkType(aaraw, aabadtype);
398 checkType(aaraw, AA$(dart.dynamic, dart.dynamic)); 399 checkType(aaraw, AA$(dart.dynamic, dart.dynamic));
399 checkType(aaraw, aadynamictype); 400 checkType(aaraw, aadynamictype);
400 checkType(aaraw, AA$(dynamic, dynamic)); 401 checkType(aaraw, AA$(dynamic, dynamic));
401 checkType(aadynamic, aarawtype); 402 checkType(aadynamic, aarawtype);
402 checkType(aadynamic, AA); 403 checkType(aadynamic, AA);
403 }); 404 });
404 405
405 test('void', () => { 406 test('void', () => {
406 //checkType((x) => x, type((void _(x)) {})); 407 //checkType((x) => x, type((void _(x)) {}));
407 }); 408 });
408 409
409 test('mixins', () => { 410 test('mixins', () => {
410 let c = collection; 411 let c = collection;
411 var s1 = new (c.SplayTreeSet$(String))(); 412 var s1 = new (c.SplayTreeSet$(String))();
412 413
413 checkType(s1, c.IterableMixin); 414 checkType(s1, c.IterableMixin);
414 checkType(s1, c.IterableMixin$(String)); 415 checkType(s1, c.IterableMixin$(String));
415 checkType(s1, c.IterableMixin$(int), false, true); 416 checkType(s1, c.IterableMixin$(int), false);
416 417
417 checkType(s1, c.SetMixin); 418 checkType(s1, c.SetMixin);
418 checkType(s1, c.SetMixin$(String)); 419 checkType(s1, c.SetMixin$(String));
419 checkType(s1, c.SetMixin$(int), false, true); 420 checkType(s1, c.SetMixin$(int), false);
420 }); 421 });
421 422
422 test('Type', () => { 423 test('Type', () => {
423 checkType(int, core.Type, true); 424 checkType(int, core.Type, true);
424 checkType(num, core.Type, true); 425 checkType(num, core.Type, true);
425 checkType(bool, core.Type, true); 426 checkType(bool, core.Type, true);
426 checkType(String, core.Type, true); 427 checkType(String, core.Type, true);
427 checkType(dynamic, core.Type, true); 428 checkType(dynamic, core.Type, true);
428 checkType(Object, core.Type, true); 429 checkType(Object, core.Type, true);
429 checkType(List, core.Type, true); 430 checkType(List, core.Type, true);
(...skipping 26 matching lines...) Expand all
456 checkType(bar3, functionType(B, [B, String])); 457 checkType(bar3, functionType(B, [B, String]));
457 checkType(cls3, functionType(B, [B, String])); 458 checkType(cls3, functionType(B, [B, String]));
458 checkType(bar4, Foo, true); 459 checkType(bar4, Foo, true);
459 checkType(cls4, Foo, true); 460 checkType(cls4, Foo, true);
460 checkType(bar4, functionType(B, [B, String]), true); 461 checkType(bar4, functionType(B, [B, String]), true);
461 checkType(cls4, functionType(B, [B, String]), true); 462 checkType(cls4, functionType(B, [B, String]), true);
462 checkType(bar5, Foo); 463 checkType(bar5, Foo);
463 checkType(cls5, Foo); 464 checkType(cls5, Foo);
464 checkType(bar5, functionType(B, [B, String])); 465 checkType(bar5, functionType(B, [B, String]));
465 checkType(cls5, functionType(B, [B, String])); 466 checkType(cls5, functionType(B, [B, String]));
466 checkType(bar6, Foo, false, true); 467 checkType(bar6, Foo, false);
467 checkType(cls6, Foo, false, true); 468 checkType(cls6, Foo, false);
468 checkType(bar6, functionType(B, [B, String]), false, true); 469 checkType(bar6, functionType(B, [B, String]), false);
469 checkType(cls6, functionType(B, [B, String]), false, true); 470 checkType(cls6, functionType(B, [B, String]), false);
470 checkType(bar7, Foo); 471 checkType(bar7, Foo);
471 checkType(cls7, Foo); 472 checkType(cls7, Foo);
472 checkType(bar7, functionType(B, [B, String])); 473 checkType(bar7, functionType(B, [B, String]));
473 checkType(cls7, functionType(B, [B, String])); 474 checkType(cls7, functionType(B, [B, String]));
474 checkType(bar7, getReifiedType(bar6)); 475 checkType(bar7, getReifiedType(bar6));
475 checkType(cls7, getReifiedType(bar6)); 476 checkType(cls7, getReifiedType(bar6));
476 checkType(bar8, Foo); 477 checkType(bar8, Foo);
477 checkType(cls8, Foo); 478 checkType(cls8, Foo);
478 checkType(bar8, functionType(B, [B, String])); 479 checkType(bar8, functionType(B, [B, String]));
479 checkType(cls8, functionType(B, [B, String])); 480 checkType(cls8, functionType(B, [B, String]));
480 checkType(bar8, getReifiedType(bar6), false, true); 481 checkType(bar8, getReifiedType(bar6), false);
481 checkType(cls8, getReifiedType(bar6), false, true); 482 checkType(cls8, getReifiedType(bar6), false);
482 checkType(bar7, getReifiedType(bar8), false, true); 483 checkType(bar7, getReifiedType(bar8), false);
483 checkType(cls7, getReifiedType(bar8), false, true); 484 checkType(cls7, getReifiedType(bar8), false);
484 checkType(bar8, getReifiedType(bar7), false, true); 485 checkType(bar8, getReifiedType(bar7), false);
485 checkType(cls8, getReifiedType(bar7), false, true); 486 checkType(cls8, getReifiedType(bar7), false);
486 487
487 // Parameterized typedefs 488 // Parameterized typedefs
488 expect(isGroundType(FuncG), true); 489 expect(isGroundType(FuncG), true);
489 expect(isGroundType(FuncG$(B, String)), false); 490 expect(isGroundType(FuncG$(B, String)), false);
490 checkType(bar1, FuncG$(B, String), false, true); 491 checkType(bar1, FuncG$(B, String), false, true);
491 checkType(cls1, FuncG$(B, String), false, true); 492 checkType(cls1, FuncG$(B, String), false, true);
492 checkType(bar3, FuncG$(B, String)); 493 checkType(bar3, FuncG$(B, String));
493 checkType(cls3, FuncG$(B, String)); 494 checkType(cls3, FuncG$(B, String));
494 }); 495 });
495 496
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
615 616
616 // Optional types 617 // Optional types
617 function ii_2i(x, y) {return x}; 618 function ii_2i(x, y) {return x};
618 dart.fn(ii_2i, core.int, [core.int], [core.int]); 619 dart.fn(ii_2i, core.int, [core.int], [core.int]);
619 checkType(ii_2i, dart.functionType(core.int, [core.int], 620 checkType(ii_2i, dart.functionType(core.int, [core.int],
620 [core.int])); 621 [core.int]));
621 checkType(ii_2i, dart.functionType(core.int, [core.int, 622 checkType(ii_2i, dart.functionType(core.int, [core.int,
622 core.int])); 623 core.int]));
623 checkType(ii_2i, dart.functionType(core.int, [], [core.int, 624 checkType(ii_2i, dart.functionType(core.int, [], [core.int,
624 core.int]), 625 core.int]),
625 false, true); 626 false);
626 checkType(ii_2i, dart.functionType(core.int, [core.int], 627 checkType(ii_2i, dart.functionType(core.int, [core.int],
627 {extra: core.int}), false, true); 628 {extra: core.int}), false);
628 629
629 // Named types 630 // Named types
630 function i_i2i(x, opts) {return x}; 631 function i_i2i(x, opts) {return x};
631 dart.fn(i_i2i, core.int, [core.int], {extra: core.int}); 632 dart.fn(i_i2i, core.int, [core.int], {extra: core.int});
632 checkType(i_i2i, dart.functionType(core.int, [core.int], 633 checkType(i_i2i, dart.functionType(core.int, [core.int],
633 {extra: core.int})); 634 {extra: core.int}));
634 checkType(i_i2i, dart.functionType(core.int, 635 checkType(i_i2i, dart.functionType(core.int,
635 [core.int, core.int]), false, true); 636 [core.int, core.int]), false);
636 checkType(i_i2i, dart.functionType(core.int, [core.int], {})); 637 checkType(i_i2i, dart.functionType(core.int, [core.int], {}));
637 checkType(i_i2i, 638 checkType(i_i2i,
638 dart.functionType(core.int, [], {extra: core.int, 639 dart.functionType(core.int, [], {extra: core.int,
639 also: core.int}), false, true); 640 also: core.int}), false);
640 checkType(i_i2i, 641 checkType(i_i2i,
641 dart.functionType(core.int, [core.int], [core.int]), false, true); 642 dart.functionType(core.int, [core.int], [core.int]), false);
642 }); 643 });
643 644
644 test('Method tearoffs', () => { 645 test('Method tearoffs', () => {
645 let c = collection; 646 let c = collection;
646 // Tear off of an inherited method 647 // Tear off of an inherited method
647 let map = new (Map$(core.int, core.String))(); 648 let map = new (Map$(core.int, core.String))();
648 checkType(dart.bind(map, 'toString'), 649 checkType(dart.bind(map, 'toString'),
649 dart.functionType(String, [])); 650 dart.functionType(String, []));
650 checkType(dart.bind(map, 'toString'), 651 checkType(dart.bind(map, 'toString'),
651 dart.functionType(int, []), false, true); 652 dart.functionType(int, []), false, true);
652 653
653 // Tear off of a method directly on the object 654 // Tear off of a method directly on the object
654 let smap = new (c.SplayTreeMap$(core.int, core.String))(); 655 let smap = new (c.SplayTreeMap$(core.int, core.String))();
655 checkType(dart.bind(smap, 'forEach'), 656 checkType(dart.bind(smap, 'forEach'),
656 dart.functionType(dart.void, 657 dart.functionType(dart.void,
657 [dart.functionType(dart.void, [core.int, core.String])])); 658 [dart.functionType(dart.void, [core.int, core.String]) ]));
658 checkType(dart.bind(smap, 'forEach'), 659 checkType(dart.bind(smap, 'forEach'),
659 dart.functionType(dart.void, 660 dart.functionType(dart.void,
660 [dart.functionType(dart.void, 661 [dart.functionType(dart.void,
661 [core.String, core.String])]), false, true); 662 [core.String, core.String])]), false, true);
662 663
663 // Tear off of a mixed in method 664 // Tear off of a mixed in method
664 let mapB = new (c.MapBase$(core.int, core.int))(); 665 let mapB = new (c.MapBase$(core.int, core.int))();
665 checkType(dart.bind(mapB, 'forEach'), 666 checkType(dart.bind(mapB, 'forEach'),
666 dart.functionType(dart.void, [ 667 dart.functionType(dart.void, [
667 dart.functionType(dart.void, [core.int, core.int])])); 668 dart.functionType(dart.void, [core.int, core.int])]));
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
767 768
768 let n = 42; 769 let n = 42;
769 let intHash = dart.hashCode(n); 770 let intHash = dart.hashCode(n);
770 checkType(intHash, core.int); 771 checkType(intHash, core.int);
771 772
772 let intString = dart.toString(n); 773 let intString = dart.toString(n);
773 assert.equal(intString, '42'); 774 assert.equal(intString, '42');
774 }); 775 });
775 }); 776 });
776 777
778 suite('subtyping', function() {
779 'use strict';
780
781 let functionType = dart.functionType;
782 let definiteFunctionType = dart.definiteFunctionType;
783 let typedef = dart.typedef;
784 let isSubtype = dart.isSubtype;
785 let int = core.int;
786 let num = core.num;
787 let dyn = dart.dynamic;
788
789 function always(t1, t2) {
790 assert.equal(isSubtype(t1, t2), true);
791 }
792 function never(t1, t2) {
793 assert.equal(isSubtype(t1, t2), false);
794 }
795 function maybe(t1, t2) {
796 assert.equal(isSubtype(t1, t2), null);
797 }
798
799 function always2(t1, t2) {
800 assert.equal(isSubtype(t1, t2), true);
801 always(functionType(t1, [t2]), functionType(t2, [t1]));
802 }
803 function never2(t1, t2) {
804 assert.equal(isSubtype(t1, t2), false);
805 maybe(functionType(t1, [t2]), functionType(t2, [t1]));
806 }
807 function maybe2(t1, t2) {
808 assert.equal(isSubtype(t1, t2), null);
809 maybe(functionType(t1, [t2]), functionType(t2, [t1]));
810 }
811
812 test('basic function types', () => {
813 always2(functionType(int, [int]), functionType(int, [int]));
814 always2(functionType(int, [num]), functionType(int, [int]));
815 always2(functionType(int, [int]), functionType(num, [int]));
816
817 always2(functionType(int, [], [int]), functionType(int, [], [int]));
818 always2(functionType(int, [], [num]), functionType(int, [], [int]));
819 always2(functionType(int, [], [int]), functionType(num, [], [int]));
820
821 always2(functionType(int, [], [int]), functionType(int, [int]));
822 always2(functionType(int, [], [num]), functionType(int, [int]));
823 always2(functionType(int, [], [int]), functionType(num, [int]));
824
825 always2(functionType(int, [], [int]), functionType(int, []));
826 always2(functionType(int, [], [num]), functionType(int, []));
827 always2(functionType(int, [], [int]), functionType(num, []));
828
829 always2(functionType(int, [int], {extra: int}), functionType(int, [int]));
830 always2(functionType(int, [num], {extra: int}), functionType(int, [int]));
831 always2(functionType(int, [int], {extra: int}), functionType(num, [int]));
832
833 maybe2(functionType(int, [int]), functionType(int, [num]));
834 maybe2(functionType(num, [int]), functionType(int, [int]));
835
836 maybe2(functionType(num, [], [num]), functionType(int, []));
837
838 maybe2(functionType(int, [], [int]), functionType(int, [], [num]));
839 maybe2(functionType(num, [], [int]), functionType(int, [], [int]));
840
841 maybe2(functionType(int, [], [int]), functionType(int, [num]));
842 maybe2(functionType(num, [], [int]), functionType(int, [int]));
843
844 maybe2(functionType(int, [int], {extra: int}), functionType(int, [num]));
845 maybe2(functionType(num, [int], {extra: int}), functionType(int, [int]));
846
847 never2(functionType(int, []), functionType(int, [num]));
848 never2(functionType(num, []), functionType(int, [int]));
849 never2(functionType(num, []), functionType(num, [num]));
850
851 never2(functionType(int, [int]), functionType(int, []));
852 never2(functionType(num, [int]), functionType(int, []));
853 never2(functionType(num, [num]), functionType(num, []));
854
855 never2(functionType(int, []), functionType(int, [], [num]));
856 never2(functionType(num, []), functionType(int, [], [int]));
857 never2(functionType(num, []), functionType(num, [], [num]));
858
859 never2(functionType(int, [int]), functionType(int, [], [num]));
860 never2(functionType(num, [int]), functionType(int, [], [int]));
861 never2(functionType(num, [num]), functionType(num, [], [num]));
862
863 never2(functionType(int, [], {extra: int}), functionType(int, [num]));
864 never2(functionType(num, [], {extra: int}), functionType(int, [int]));
865 never2(functionType(num, [], {extra: int}), functionType(num, [num]));
866
867 never2(functionType(int, [], {extra: int}), functionType(int, [], [num]));
868 never2(functionType(num, [], {extra: int}), functionType(int, [], [int]));
869 never2(functionType(num, [], {extra: int}), functionType(num, [], [num]));
870
871 never2(functionType(int, []), functionType(int, [], {extra: int}));
872 never2(functionType(num, []), functionType(int, [], {extra: int}));
873 never2(functionType(num, []), functionType(num, [], {extra: int}));
874
875 never2(functionType(int, [int]), functionType(int, [], {extra: int}));
876 never2(functionType(num, [int]), functionType(int, [], {extra: int}));
877 never2(functionType(num, [num]), functionType(num, [], {extra: int}));
878
879 never2(functionType(int, [int]), functionType(int, [int], {extra: int}));
880 never2(functionType(num, [int]), functionType(int, [int], {extra: int}));
881 never2(functionType(num, [num]), functionType(num, [num], {extra: int}));
882 });
883
884 test('fuzzy function types', () => {
885 always(functionType(int, [int]), functionType(dyn, [dyn]));
886
887 always(functionType(int, [], [int]), functionType(dyn, [], [dyn]));
888
889 always(functionType(int, [], [int]), functionType(dyn, [dyn]));
890
891 always(functionType(int, [], [int]), functionType(dyn, []));
892
893 always(functionType(int, [int], {extra: int}), functionType(dyn, [dyn]));
894
895 });
896
897 test('mixed types', () => {
898 let AA$ = dart.generic((T) => class AA extends core.Object {});
899
900 always(int, dyn);
901 maybe(dyn, int);
902
903 never(functionType(int, [int]), int);
904
905 never(int, functionType(int, [int]));
906
907 always(AA$(int), AA$(dyn));
908 maybe(AA$(dyn), AA$(int));
909 never(AA$(core.Object), AA$(int));
910
911 always(AA$(functionType(int, [int])), AA$(dyn));
912 maybe(AA$(dyn), AA$(functionType(int, [int])));
913 never(AA$(core.Object), AA$(functionType(int, [int])));
914
915 always(AA$(functionType(int, [int])), AA$(functionType(dyn, [dyn])));
916 maybe(AA$(functionType(dyn, [dyn])), AA$(functionType(int, [int])));
917 maybe(AA$(functionType(core.Object, [core.Object])),
918 AA$(functionType(int, [int])));
919
920
921 });
922
923 });
924
777 suite('primitives', function() { 925 suite('primitives', function() {
778 'use strict'; 926 'use strict';
779 927
780 test('fixed length list', () => { 928 test('fixed length list', () => {
781 let list = new core.List(10); 929 let list = new core.List(10);
782 list[0] = 42; 930 list[0] = 42;
783 assert.throws(() => list.add(42)); 931 assert.throws(() => list.add(42));
784 }); 932 });
785 }); 933 });
OLDNEW
« no previous file with comments | « test/browser/language_tests.js ('k') | test/codegen/language/type_literal_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698