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

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

Issue 2869733006: Revert "Revert "fix #27256, track type bounds for generic functions"" (Closed)
Patch Set: Created 3 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
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 define(['dart_sdk'], function(dart_sdk) { 5 define(['dart_sdk'], function(dart_sdk) {
6 const assert = chai.assert; 6 const assert = chai.assert;
7 const async = dart_sdk.async; 7 const async = dart_sdk.async;
8 const core = dart_sdk.core; 8 const core = dart_sdk.core;
9 const collection = dart_sdk.collection; 9 const collection = dart_sdk.collection;
10 const dart = dart_sdk.dart; 10 const dart = dart_sdk.dart;
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 }); 152 });
153 153
154 let expect = assert.equal; 154 let expect = assert.equal;
155 let isGroundType = dart.isGroundType; 155 let isGroundType = dart.isGroundType;
156 let generic = dart.generic; 156 let generic = dart.generic;
157 let intIsNonNullable = false; 157 let intIsNonNullable = false;
158 let cast = dart.as; 158 let cast = dart.as;
159 let instanceOf = dart.is; 159 let instanceOf = dart.is;
160 let strongInstanceOf = dart.strongInstanceOf; 160 let strongInstanceOf = dart.strongInstanceOf;
161 let getReifiedType = dart.getReifiedType; 161 let getReifiedType = dart.getReifiedType;
162 let functionType = dart.functionType; 162 let fnTypeFuzzy = dart.fnTypeFuzzy;
163 let typedef = dart.typedef; 163 let typedef = dart.typedef;
164 let isSubtype = dart.isSubtype; 164 let isSubtype = dart.isSubtype;
165 165
166 let Object = core.Object; 166 let Object = core.Object;
167 let String = core.String; 167 let String = core.String;
168 let dynamic = dart.dynamic; 168 let dynamic = dart.dynamic;
169 let List = core.List; 169 let List = core.List;
170 let Map = core.Map; 170 let Map = core.Map;
171 let Map$ = core.Map$; 171 let Map$ = core.Map$;
172 let double = core.double; 172 let double = core.double;
173 let int = core.int; 173 let int = core.int;
174 let num = core.num; 174 let num = core.num;
175 let bool = core.bool; 175 let bool = core.bool;
176 176
177 class A {} 177 class A {}
178 class B extends A {} 178 class B extends A {}
179 class C extends B {} 179 class C extends B {}
180 180
181 let AA$ = generic((T, U) => class AA extends core.Object {}); 181 let AA$ = generic((T, U) => class AA extends core.Object {});
182 let AA = AA$(); 182 let AA = AA$();
183 let BB$ = generic((T, U) => class BB extends AA$(U, T) {}); 183 let BB$ = generic((T, U) => class BB extends AA$(U, T) {});
184 let BB = BB$(); 184 let BB = BB$();
185 class CC extends BB$(String, List) {} 185 class CC extends BB$(String, List) {}
186 186
187 let Func2 = typedef('Func2', () => functionType(dynamic, [dynamic, dynamic]) ); 187 let Func2 = typedef('Func2', () => fnTypeFuzzy(dynamic, [dynamic, dynamic])) ;
188 let Foo = typedef('Foo', () => functionType(B, [B, String])); 188 let Foo = typedef('Foo', () => fnTypeFuzzy(B, [B, String]));
189 189
190 let FuncG$ = generic((T, U) => typedef('FuncG', () => functionType(T, [T, U] ))) 190 let FuncG$ = generic((T, U) => typedef('FuncG', () => fnTypeFuzzy(T, [T, U]) ))
191 let FuncG = FuncG$(); 191 let FuncG = FuncG$();
192 192
193 // TODO(vsm): Revisit when we encode types on functions properly. 193 // TODO(vsm): Revisit when we encode types on functions properly.
194 // A bar1(C c, String s) => null; 194 // A bar1(C c, String s) => null;
195 function bar1(c, s) { return null; } 195 function bar1(c, s) { return null; }
196 dart.fn(bar1, dart.definiteFunctionType(A, [C, String])); 196 dart.fn(bar1, dart.fnType(A, [C, String]));
197 197
198 // bar2(B b, String s) => null; 198 // bar2(B b, String s) => null;
199 function bar2(b, s) { return null; } 199 function bar2(b, s) { return null; }
200 dart.fn(bar2, dart.definiteFunctionType(dynamic, [B, String])); 200 dart.fn(bar2, dart.fnType(dynamic, [B, String]));
201 201
202 // B bar3(B b, Object o) => null; 202 // B bar3(B b, Object o) => null;
203 function bar3(b, o) { return null; } 203 function bar3(b, o) { return null; }
204 dart.fn(bar3, dart.definiteFunctionType(B, [B, Object])); 204 dart.fn(bar3, dart.fnType(B, [B, Object]));
205 205
206 // B bar4(B b, o) => null; 206 // B bar4(B b, o) => null;
207 function bar4(b, o) { return null; } 207 function bar4(b, o) { return null; }
208 dart.fn(bar4, dart.definiteFunctionType(B, [B, dynamic])); 208 dart.fn(bar4, dart.fnType(B, [B, dynamic]));
209 209
210 // C bar5(A a, Object o) => null; 210 // C bar5(A a, Object o) => null;
211 function bar5(a, o) { return null; } 211 function bar5(a, o) { return null; }
212 dart.fn(bar5, dart.definiteFunctionType(C, [A, Object])); 212 dart.fn(bar5, dart.fnType(C, [A, Object]));
213 213
214 // B bar6(B b, String s, String o) => null; 214 // B bar6(B b, String s, String o) => null;
215 function bar6(b, s, o) { return null; } 215 function bar6(b, s, o) { return null; }
216 dart.fn(bar6, dart.definiteFunctionType(B, [B, String, String])); 216 dart.fn(bar6, dart.fnType(B, [B, String, String]));
217 217
218 // B bar7(B b, String s, [Object o]) => null; 218 // B bar7(B b, String s, [Object o]) => null;
219 function bar7(b, s, o) { return null; } 219 function bar7(b, s, o) { return null; }
220 dart.fn(bar7, dart.definiteFunctionType(B, [B, String], [Object])); 220 dart.fn(bar7, dart.fnType(B, [B, String], [Object]));
221 221
222 // B bar8(B b, String s, {Object p}) => null; 222 // B bar8(B b, String s, {Object p}) => null;
223 function bar8(b, s, o) { return null; } 223 function bar8(b, s, o) { return null; }
224 dart.fn(bar8, dart.definiteFunctionType(B, [B, String], {p: Object})); 224 dart.fn(bar8, dart.fnType(B, [B, String], {p: Object}));
225 225
226 let cls1 = dart.fn((c, s) => { return null; }, 226 let cls1 = dart.fn((c, s) => { return null; },
227 dart.definiteFunctionType(A, [C, String])); 227 dart.fnType(A, [C, String]));
228 228
229 let cls2 = dart.fn((b, s) => { return null; }, 229 let cls2 = dart.fn((b, s) => { return null; },
230 dart.definiteFunctionType(dynamic, [B, String])); 230 dart.fnType(dynamic, [B, String]));
231 231
232 let cls3 = dart.fn((b, o) => { return null; }, 232 let cls3 = dart.fn((b, o) => { return null; },
233 dart.definiteFunctionType(B, [B, Object])); 233 dart.fnType(B, [B, Object]));
234 234
235 let cls4 = dart.fn((b, o) => { return null; }, 235 let cls4 = dart.fn((b, o) => { return null; },
236 dart.definiteFunctionType(B, [B, dynamic])); 236 dart.fnType(B, [B, dynamic]));
237 237
238 let cls5 = dart.fn((a, o) => { return null; }, 238 let cls5 = dart.fn((a, o) => { return null; },
239 dart.definiteFunctionType(C, [A, Object])); 239 dart.fnType(C, [A, Object]));
240 240
241 let cls6 = dart.fn((b, s, o) => { return null; }, 241 let cls6 = dart.fn((b, s, o) => { return null; },
242 dart.definiteFunctionType(B, [B, String, String])); 242 dart.fnType(B, [B, String, String]));
243 243
244 let cls7 = dart.fn((b, s, o) => { return null; }, 244 let cls7 = dart.fn((b, s, o) => { return null; },
245 dart.definiteFunctionType(B, [B, String], [Object])); 245 dart.fnType(B, [B, String], [Object]));
246 246
247 let cls8 = 247 let cls8 =
248 dart.fn((b, s, o) => { return null; }, 248 dart.fn((b, s, o) => { return null; },
249 dart.definiteFunctionType(B, [B, String], {p: Object})); 249 dart.fnType(B, [B, String], {p: Object}));
250 250
251 function checkType(x, type, expectedTrue, strongOnly) { 251 function checkType(x, type, expectedTrue, strongOnly) {
252 if (expectedTrue === undefined) expectedTrue = true; 252 if (expectedTrue === undefined) expectedTrue = true;
253 if (strongOnly === undefined) strongOnly = false; 253 if (strongOnly === undefined) strongOnly = false;
254 if (!strongOnly) { 254 if (!strongOnly) {
255 assert.doesNotThrow(() => instanceOf(x, type)); 255 assert.doesNotThrow(() => instanceOf(x, type));
256 expect(instanceOf(x, type), expectedTrue, 256 expect(instanceOf(x, type), expectedTrue,
257 '"' + x + '" ' + 257 '"' + x + '" ' +
258 (expectedTrue ? 'should' : 'should not') + 258 (expectedTrue ? 'should' : 'should not') +
259 ' be an instance of "' + dart.typeName(type) + '"'); 259 ' be an instance of "' + dart.typeName(type) + '"');
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
404 }); 404 });
405 405
406 test('constructors', () => { 406 test('constructors', () => {
407 class C extends core.Object { 407 class C extends core.Object {
408 new(x) {}; 408 new(x) {};
409 named(x, y) {}; 409 named(x, y) {};
410 } 410 }
411 dart.defineNamedConstructor(C, 'named'); 411 dart.defineNamedConstructor(C, 'named');
412 dart.setSignature(C, { 412 dart.setSignature(C, {
413 constructors: () => ({ 413 constructors: () => ({
414 new: dart.definiteFunctionType(C, [core.int]), 414 new: dart.fnType(C, [core.int]),
415 named: dart.definiteFunctionType(C, [core.int, core.int]) 415 named: dart.fnType(C, [core.int, core.int])
416 }) 416 })
417 }); 417 });
418 let getType = dart.classGetConstructorType; 418 let getType = dart.classGetConstructorType;
419 isSubtype(getType(C), dart.functionType(C, [core.int])); 419 isSubtype(getType(C), dart.fnTypeFuzzy(C, [core.int]));
420 isSubtype(getType(C), dart.functionType(C, [core.String]), false); 420 isSubtype(getType(C), dart.fnTypeFuzzy(C, [core.String]), false);
421 isSubtype(getType(C, 'new'), dart.functionType(C, [core.int])); 421 isSubtype(getType(C, 'new'), dart.fnTypeFuzzy(C, [core.int]));
422 isSubtype(getType(C, 'new'), dart.functionType(C, [core.String]), false); 422 isSubtype(getType(C, 'new'), dart.fnTypeFuzzy(C, [core.String]), false);
423 isSubtype(getType(C, 'named'), dart.functionType(C, [core.int, core.int])) ; 423 isSubtype(getType(C, 'named'), dart.fnTypeFuzzy(C, [core.int, core.int]));
424 isSubtype(getType(C, 'named'), 424 isSubtype(getType(C, 'named'),
425 dart.functionType(C, [core.int, core.String]), false); 425 dart.fnTypeFuzzy(C, [core.int, core.String]), false);
426 }); 426 });
427 427
428 test('generic and inheritance', () => { 428 test('generic and inheritance', () => {
429 let aaraw = new AA(); 429 let aaraw = new AA();
430 let aarawtype = getReifiedType(aaraw); 430 let aarawtype = getReifiedType(aaraw);
431 let aadynamic = new (AA$(dynamic, dynamic))(); 431 let aadynamic = new (AA$(dynamic, dynamic))();
432 let aadynamictype = getReifiedType(aadynamic); 432 let aadynamictype = getReifiedType(aadynamic);
433 let aa = new (AA$(String, List))(); 433 let aa = new (AA$(String, List))();
434 let aatype = getReifiedType(aa); 434 let aatype = getReifiedType(aa);
435 let bb = new (BB$(String, List))(); 435 let bb = new (BB$(String, List))();
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
492 checkType(int, core.Type, true); 492 checkType(int, core.Type, true);
493 checkType(num, core.Type, true); 493 checkType(num, core.Type, true);
494 checkType(bool, core.Type, true); 494 checkType(bool, core.Type, true);
495 checkType(String, core.Type, true); 495 checkType(String, core.Type, true);
496 checkType(dynamic, core.Type, true); 496 checkType(dynamic, core.Type, true);
497 checkType(Object, core.Type, true); 497 checkType(Object, core.Type, true);
498 checkType(List, core.Type, true); 498 checkType(List, core.Type, true);
499 checkType(Map, core.Type, true); 499 checkType(Map, core.Type, true);
500 checkType(Map$(int, String), core.Type, true); 500 checkType(Map$(int, String), core.Type, true);
501 checkType(Func2, core.Type, true); 501 checkType(Func2, core.Type, true);
502 checkType(functionType(dynamic, [dynamic]), core.Type, true); 502 checkType(fnTypeFuzzy(dynamic, [dynamic]), core.Type, true);
503 checkType(core.Type, core.Type, true); 503 checkType(core.Type, core.Type, true);
504 504
505 checkType(3, core.Type, false); 505 checkType(3, core.Type, false);
506 checkType("hello", core.Type, false); 506 checkType("hello", core.Type, false);
507 }) 507 })
508 508
509 test('Functions', () => { 509 test('Functions', () => {
510 // - return type: Dart is bivariant. We're covariant. 510 // - return type: Dart is bivariant. We're covariant.
511 // - param types: Dart is bivariant. We're contravariant. 511 // - param types: Dart is bivariant. We're contravariant.
512 expect(isGroundType(Func2), true); 512 expect(isGroundType(Func2), true);
513 expect(isGroundType(Foo), false); 513 expect(isGroundType(Foo), false);
514 expect(isGroundType(functionType(B, [B, String])), false); 514 expect(isGroundType(fnTypeFuzzy(B, [B, String])), false);
515 checkType(bar1, Foo, false, true); 515 checkType(bar1, Foo, false, true);
516 checkType(cls1, Foo, false, true); 516 checkType(cls1, Foo, false, true);
517 checkType(bar1, functionType(B, [B, String]), false, true); 517 checkType(bar1, fnTypeFuzzy(B, [B, String]), false, true);
518 checkType(cls1, functionType(B, [B, String]), false, true); 518 checkType(cls1, fnTypeFuzzy(B, [B, String]), false, true);
519 checkType(bar2, Foo, false, true); 519 checkType(bar2, Foo, false, true);
520 checkType(cls2, Foo, false, true); 520 checkType(cls2, Foo, false, true);
521 checkType(bar2, functionType(B, [B, String]), false, true); 521 checkType(bar2, fnTypeFuzzy(B, [B, String]), false, true);
522 checkType(cls2, functionType(B, [B, String]), false, true); 522 checkType(cls2, fnTypeFuzzy(B, [B, String]), false, true);
523 checkType(bar3, Foo); 523 checkType(bar3, Foo);
524 checkType(cls3, Foo); 524 checkType(cls3, Foo);
525 checkType(bar3, functionType(B, [B, String])); 525 checkType(bar3, fnTypeFuzzy(B, [B, String]));
526 checkType(cls3, functionType(B, [B, String])); 526 checkType(cls3, fnTypeFuzzy(B, [B, String]));
527 checkType(bar4, Foo, true); 527 checkType(bar4, Foo, true);
528 checkType(cls4, Foo, true); 528 checkType(cls4, Foo, true);
529 checkType(bar4, functionType(B, [B, String]), true); 529 checkType(bar4, fnTypeFuzzy(B, [B, String]), true);
530 checkType(cls4, functionType(B, [B, String]), true); 530 checkType(cls4, fnTypeFuzzy(B, [B, String]), true);
531 checkType(bar5, Foo); 531 checkType(bar5, Foo);
532 checkType(cls5, Foo); 532 checkType(cls5, Foo);
533 checkType(bar5, functionType(B, [B, String])); 533 checkType(bar5, fnTypeFuzzy(B, [B, String]));
534 checkType(cls5, functionType(B, [B, String])); 534 checkType(cls5, fnTypeFuzzy(B, [B, String]));
535 checkType(bar6, Foo, false); 535 checkType(bar6, Foo, false);
536 checkType(cls6, Foo, false); 536 checkType(cls6, Foo, false);
537 checkType(bar6, functionType(B, [B, String]), false); 537 checkType(bar6, fnTypeFuzzy(B, [B, String]), false);
538 checkType(cls6, functionType(B, [B, String]), false); 538 checkType(cls6, fnTypeFuzzy(B, [B, String]), false);
539 checkType(bar7, Foo); 539 checkType(bar7, Foo);
540 checkType(cls7, Foo); 540 checkType(cls7, Foo);
541 checkType(bar7, functionType(B, [B, String])); 541 checkType(bar7, fnTypeFuzzy(B, [B, String]));
542 checkType(cls7, functionType(B, [B, String])); 542 checkType(cls7, fnTypeFuzzy(B, [B, String]));
543 checkType(bar7, getReifiedType(bar6)); 543 checkType(bar7, getReifiedType(bar6));
544 checkType(cls7, getReifiedType(bar6)); 544 checkType(cls7, getReifiedType(bar6));
545 checkType(bar8, Foo); 545 checkType(bar8, Foo);
546 checkType(cls8, Foo); 546 checkType(cls8, Foo);
547 checkType(bar8, functionType(B, [B, String])); 547 checkType(bar8, fnTypeFuzzy(B, [B, String]));
548 checkType(cls8, functionType(B, [B, String])); 548 checkType(cls8, fnTypeFuzzy(B, [B, String]));
549 checkType(bar8, getReifiedType(bar6), false); 549 checkType(bar8, getReifiedType(bar6), false);
550 checkType(cls8, getReifiedType(bar6), false); 550 checkType(cls8, getReifiedType(bar6), false);
551 checkType(bar7, getReifiedType(bar8), false); 551 checkType(bar7, getReifiedType(bar8), false);
552 checkType(cls7, getReifiedType(bar8), false); 552 checkType(cls7, getReifiedType(bar8), false);
553 checkType(bar8, getReifiedType(bar7), false); 553 checkType(bar8, getReifiedType(bar7), false);
554 checkType(cls8, getReifiedType(bar7), false); 554 checkType(cls8, getReifiedType(bar7), false);
555 555
556 // Parameterized typedefs 556 // Parameterized typedefs
557 expect(isGroundType(FuncG), true); 557 expect(isGroundType(FuncG), true);
558 expect(isGroundType(FuncG$(B, String)), false); 558 expect(isGroundType(FuncG$(B, String)), false);
559 checkType(bar1, FuncG$(B, String), false, true); 559 checkType(bar1, FuncG$(B, String), false, true);
560 checkType(cls1, FuncG$(B, String), false, true); 560 checkType(cls1, FuncG$(B, String), false, true);
561 checkType(bar3, FuncG$(B, String)); 561 checkType(bar3, FuncG$(B, String));
562 checkType(cls3, FuncG$(B, String)); 562 checkType(cls3, FuncG$(B, String));
563 }); 563 });
564 564
565 test('dcall', () => { 565 test('dcall', () => {
566 function dd2d(x, y) {return x}; 566 function dd2d(x, y) {return x};
567 dart.fn(dd2d); 567 dart.fn(dd2d);
568 function ii2i(x, y) {return x}; 568 function ii2i(x, y) {return x};
569 dart.fn(ii2i, dart.definiteFunctionType(core.int, [core.int, core.int])); 569 dart.fn(ii2i, dart.fnType(core.int, [core.int, core.int]));
570 function ii_2i(x, y) {return x}; 570 function ii_2i(x, y) {return x};
571 dart.fn(ii_2i, dart.definiteFunctionType(core.int, [core.int], [core.int]) ); 571 dart.fn(ii_2i, dart.fnType(core.int, [core.int], [core.int]));
572 function i_i2i(x, opts) {return x}; 572 function i_i2i(x, opts) {return x};
573 dart.fn(i_i2i, 573 dart.fn(i_i2i,
574 dart.definiteFunctionType(core.int, [core.int], {extra: core.int}) ); 574 dart.fnType(core.int, [core.int], {extra: core.int}));
575 575
576 assert.equal(dart.dcall(dd2d, 0, 1), 0); 576 assert.equal(dart.dcall(dd2d, 0, 1), 0);
577 assert.equal(dart.dcall(dd2d, "hello", "world"), "hello"); 577 assert.equal(dart.dcall(dd2d, "hello", "world"), "hello");
578 assert.throws(() => dart.dcall(dd2d, 0)); 578 assert.throws(() => dart.dcall(dd2d, 0));
579 assert.throws(() => dart.dcall(dd2d, 0, 1, 2)); 579 assert.throws(() => dart.dcall(dd2d, 0, 1, 2));
580 assert.throws(() => dart.dcall(dd2d, 0, 1, {extra : 3})); 580 assert.throws(() => dart.dcall(dd2d, 0, 1, {extra : 3}));
581 // This should throw but currently doesn't. 581 // This should throw but currently doesn't.
582 // assert.throws(() => dart.dcall(dd2d, 0, {extra:3})); 582 // assert.throws(() => dart.dcall(dd2d, 0, {extra:3}));
583 583
584 assert.equal(dart.dcall(ii2i, 0, 1), 0); 584 assert.equal(dart.dcall(ii2i, 0, 1), 0);
(...skipping 10 matching lines...) Expand all
595 assert.throws(() => dart.dcall(i_i2i, "hello", "world")); 595 assert.throws(() => dart.dcall(i_i2i, "hello", "world"));
596 assert.equal(dart.dcall(i_i2i, 0), 0); 596 assert.equal(dart.dcall(i_i2i, 0), 0);
597 assert.throws(() => dart.dcall(i_i2i, 0, 1, 2)); 597 assert.throws(() => dart.dcall(i_i2i, 0, 1, 2));
598 assert.equal(dart.dcall(i_i2i, 0, {extra: 3}), 0); 598 assert.equal(dart.dcall(i_i2i, 0, {extra: 3}), 0);
599 }); 599 });
600 600
601 test('dsend', () => { 601 test('dsend', () => {
602 class Tester extends core.Object { 602 class Tester extends core.Object {
603 new() { 603 new() {
604 this.f = dart.fn(x => x, 604 this.f = dart.fn(x => x,
605 dart.definiteFunctionType(core.int, [core.int])); 605 dart.fnType(core.int, [core.int]));
606 this.me = this; 606 this.me = this;
607 } 607 }
608 m(x, y) {return x;} 608 m(x, y) {return x;}
609 call(x) {return x;} 609 call(x) {return x;}
610 static s(x, y) { return x;} 610 static s(x, y) { return x;}
611 } 611 }
612 dart.setSignature(Tester, { 612 dart.setSignature(Tester, {
613 methods: () => ({ 613 methods: () => ({
614 m: dart.definiteFunctionType(core.int, [core.int, core.int]), 614 m: dart.fnType(core.int, [core.int, core.int]),
615 call: dart.definiteFunctionType(core.int, [core.int]) 615 call: dart.fnType(core.int, [core.int])
616 }), 616 }),
617 statics: () => ({ 617 statics: () => ({
618 s: dart.definiteFunctionType(core.String, [core.String]) 618 s: dart.fnType(core.String, [core.String])
619 }), 619 }),
620 names: ['s'] 620 names: ['s']
621 }) 621 })
622 let o = new Tester(); 622 let o = new Tester();
623 623
624 // Method send 624 // Method send
625 assert.equal(dart.dsend(o, 'm', 3, 4), 3); 625 assert.equal(dart.dsend(o, 'm', 3, 4), 3);
626 assert.equal(dart.dsend(o, 'm', null, 4), null); 626 assert.equal(dart.dsend(o, 'm', null, 4), null);
627 assert.throws(() => dart.dsend(o, 'm', 3)); 627 assert.throws(() => dart.dsend(o, 'm', 3));
628 assert.throws(() => dart.dsend(o, 'm', "hello", "world")); 628 assert.throws(() => dart.dsend(o, 'm', "hello", "world"));
(...skipping 21 matching lines...) Expand all
650 assert.equal(dart.dsend(o, 'me', 3), 3); 650 assert.equal(dart.dsend(o, 'me', 3), 3);
651 assert.equal(dart.dsend(o, 'me', null), null); 651 assert.equal(dart.dsend(o, 'me', null), null);
652 assert.throws(() => dart.dsend(o, 'me', "hello")); 652 assert.throws(() => dart.dsend(o, 'me', "hello"));
653 assert.throws(() => dart.dsend(o, 'me', 3, 4)); 653 assert.throws(() => dart.dsend(o, 'me', 3, 4));
654 }); 654 });
655 655
656 test('Types on top level functions', () => { 656 test('Types on top level functions', () => {
657 // Test some generated code 657 // Test some generated code
658 // Test the lazy path 658 // Test the lazy path
659 checkType(core.identityHashCode, 659 checkType(core.identityHashCode,
660 dart.functionType(core.int, [core.Object])); 660 dart.fnTypeFuzzy(core.int, [core.Object]));
661 // Test the normal path 661 // Test the normal path
662 checkType(core.identical, 662 checkType(core.identical,
663 dart.functionType(core.bool, 663 dart.fnTypeFuzzy(core.bool,
664 [core.Object, core.Object])); 664 [core.Object, core.Object]));
665 665
666 // Hand crafted tests 666 // Hand crafted tests
667 // All dynamic 667 // All dynamic
668 function dd2d(x, y) {return x}; 668 function dd2d(x, y) {return x};
669 dart.fn(dd2d); 669 dart.fn(dd2d);
670 checkType(dd2d, dart.functionType(dart.dynamic, 670 checkType(dd2d, dart.fnTypeFuzzy(dart.dynamic,
671 [dart.dynamic, dart.dynamic])); 671 [dart.dynamic, dart.dynamic]));
672 672
673 // Set the type eagerly 673 // Set the type eagerly
674 function ii2i(x, y) {return x}; 674 function ii2i(x, y) {return x};
675 dart.fn(ii2i, dart.definiteFunctionType(core.int, [core.int, core.int])); 675 dart.fn(ii2i, dart.fnType(core.int, [core.int, core.int]));
676 checkType(ii2i, dart.functionType(core.int, 676 checkType(ii2i, dart.fnTypeFuzzy(core.int,
677 [core.int, core.int])); 677 [core.int, core.int]));
678 678
679 // Set the type lazily 679 // Set the type lazily
680 function ss2s(x, y) {return x}; 680 function ss2s(x, y) {return x};
681 var coreString; 681 var coreString;
682 dart.lazyFn(ss2s, 682 dart.lazyFn(ss2s,
683 () => dart.definiteFunctionType(coreString, 683 () => dart.fnType(coreString,
684 [coreString, coreString])); 684 [coreString, coreString]));
685 coreString = core.String; 685 coreString = core.String;
686 checkType(ss2s, dart.functionType(core.String, 686 checkType(ss2s, dart.fnTypeFuzzy(core.String,
687 [core.String, core.String])); 687 [core.String, core.String]));
688 688
689 // Optional types 689 // Optional types
690 function ii_2i(x, y) {return x}; 690 function ii_2i(x, y) {return x};
691 dart.fn(ii_2i, dart.definiteFunctionType(core.int, [core.int], [core.int]) ); 691 dart.fn(ii_2i, dart.fnType(core.int, [core.int], [core.int]));
692 checkType(ii_2i, dart.functionType(core.int, [core.int], 692 checkType(ii_2i, dart.fnTypeFuzzy(core.int, [core.int],
693 [core.int])); 693 [core.int]));
694 checkType(ii_2i, dart.functionType(core.int, [core.int, 694 checkType(ii_2i, dart.fnTypeFuzzy(core.int, [core.int,
695 core.int])); 695 core.int]));
696 checkType(ii_2i, dart.functionType(core.int, [], [core.int, 696 checkType(ii_2i, dart.fnTypeFuzzy(core.int, [], [core.int,
697 core.int]), 697 core.int]),
698 false); 698 false);
699 checkType(ii_2i, dart.functionType(core.int, [core.int], 699 checkType(ii_2i, dart.fnTypeFuzzy(core.int, [core.int],
700 {extra: core.int}), false); 700 {extra: core.int}), false);
701 701
702 // Named types 702 // Named types
703 function i_i2i(x, opts) {return x}; 703 function i_i2i(x, opts) {return x};
704 dart.fn(i_i2i, dart.definiteFunctionType(core.int, [core.int], 704 dart.fn(i_i2i, dart.fnType(core.int, [core.int],
705 {extra: core.int})); 705 {extra: core.int}));
706 checkType(i_i2i, dart.functionType(core.int, [core.int], 706 checkType(i_i2i, dart.fnTypeFuzzy(core.int, [core.int],
707 {extra: core.int})); 707 {extra: core.int}));
708 checkType(i_i2i, dart.functionType(core.int, 708 checkType(i_i2i, dart.fnTypeFuzzy(core.int,
709 [core.int, core.int]), false); 709 [core.int, core.int]), false);
710 checkType(i_i2i, dart.functionType(core.int, [core.int], {})); 710 checkType(i_i2i, dart.fnTypeFuzzy(core.int, [core.int], {}));
711 checkType(i_i2i, 711 checkType(i_i2i,
712 dart.functionType(core.int, [], {extra: core.int, 712 dart.fnTypeFuzzy(core.int, [], {extra: core.int,
713 also: core.int}), false); 713 also: core.int}), false);
714 checkType(i_i2i, 714 checkType(i_i2i,
715 dart.functionType(core.int, [core.int], [core.int]), false); 715 dart.fnTypeFuzzy(core.int, [core.int], [core.int]), false);
716 }); 716 });
717 717
718 test('Method tearoffs', () => { 718 test('Method tearoffs', () => {
719 let c = collection; 719 let c = collection;
720 // Tear off of an inherited method 720 // Tear off of an inherited method
721 let map = new (Map$(core.int, core.String))(); 721 let map = new (Map$(core.int, core.String))();
722 checkType(dart.bind(map, 'toString'), 722 checkType(dart.bind(map, 'toString'),
723 dart.functionType(String, [])); 723 dart.fnTypeFuzzy(String, []));
724 checkType(dart.bind(map, 'toString'), 724 checkType(dart.bind(map, 'toString'),
725 dart.functionType(int, []), false, true); 725 dart.fnTypeFuzzy(int, []), false, true);
726 726
727 // Tear off of a method directly on the object 727 // Tear off of a method directly on the object
728 let smap = new (c.SplayTreeMap$(core.int, core.String))(); 728 let smap = new (c.SplayTreeMap$(core.int, core.String))();
729 checkType(dart.bind(smap, 'forEach'), 729 checkType(dart.bind(smap, 'forEach'),
730 dart.functionType(dart.void, 730 dart.fnTypeFuzzy(dart.void,
731 [dart.functionType(dart.void, [core.int, core.String ])])); 731 [dart.fnTypeFuzzy(dart.void, [core.int, core.String] )]));
732 checkType(dart.bind(smap, 'forEach'), 732 checkType(dart.bind(smap, 'forEach'),
733 dart.functionType(dart.void, 733 dart.fnTypeFuzzy(dart.void,
734 [dart.functionType(dart.void, 734 [dart.fnTypeFuzzy(dart.void,
735 [core.String, core.String])]), false, true); 735 [core.String, core.String])]), false, true);
736 736
737 // Tear off of a mixed in method 737 // Tear off of a mixed in method
738 let mapB = new (c.MapBase$(core.int, core.int))(); 738 let mapB = new (c.MapBase$(core.int, core.int))();
739 checkType(dart.bind(mapB, 'forEach'), 739 checkType(dart.bind(mapB, 'forEach'),
740 dart.functionType(dart.void, [ 740 dart.fnTypeFuzzy(dart.void, [
741 dart.functionType(dart.void, [core.int, core.int])])); 741 dart.fnTypeFuzzy(dart.void, [core.int, core.int])]));
742 checkType(dart.bind(mapB, 'forEach'), 742 checkType(dart.bind(mapB, 'forEach'),
743 dart.functionType(dart.void, [ 743 dart.fnTypeFuzzy(dart.void, [
744 dart.functionType(dart.void, [core.int, core.String])]), 744 dart.fnTypeFuzzy(dart.void, [core.int, core.String])]),
745 false, true); 745 false, true);
746 746
747 // Tear off of a method with a symbol name 747 // Tear off of a method with a symbol name
748 let listB = new (c.ListBase$(core.int))(); 748 let listB = new (c.ListBase$(core.int))();
749 checkType(dart.bind(listB, dartx.add), 749 checkType(dart.bind(listB, dartx.add),
750 dart.functionType(dart.void, [core.int])); 750 dart.fnTypeFuzzy(dart.void, [core.int]));
751 checkType(dart.bind(listB, dartx.add), 751 checkType(dart.bind(listB, dartx.add),
752 dart.functionType(dart.void, [core.String]), false, true); 752 dart.fnTypeFuzzy(dart.void, [core.String]), false, true);
753 753
754 // Tear off of a static method 754 // Tear off of a static method
755 checkType(c.ListBase.listToString, 755 checkType(c.ListBase.listToString,
756 dart.functionType(core.String, [core.List])); 756 dart.fnTypeFuzzy(core.String, [core.List]));
757 checkType(c.ListBase.listToString, 757 checkType(c.ListBase.listToString,
758 dart.functionType(core.String, [core.String]), false, true); 758 dart.fnTypeFuzzy(core.String, [core.String]), false, true);
759 759
760 // Tear-off of extension methods on primitives 760 // Tear-off of extension methods on primitives
761 checkType(dart.bind(3.0, dartx.floor), 761 checkType(dart.bind(3.0, dartx.floor),
762 dart.functionType(core.int, [])); 762 dart.fnTypeFuzzy(core.int, []));
763 checkType(dart.bind(3.0, dartx.floor), 763 checkType(dart.bind(3.0, dartx.floor),
764 dart.functionType(core.String, []), false, true); 764 dart.fnTypeFuzzy(core.String, []), false, true);
765 checkType(dart.bind("", dartx.endsWith), 765 checkType(dart.bind("", dartx.endsWith),
766 dart.functionType(core.bool, [core.String])); 766 dart.fnTypeFuzzy(core.bool, [core.String]));
767 checkType(dart.bind("", dartx.endsWith), 767 checkType(dart.bind("", dartx.endsWith),
768 dart.functionType(core.bool, [core.int]), false, true); 768 dart.fnTypeFuzzy(core.bool, [core.int]), false, true);
769 769
770 // Tear off a mixin method 770 // Tear off a mixin method
771 class Base { 771 class Base {
772 m(x) {return x;} 772 m(x) {return x;}
773 }; 773 };
774 dart.setSignature(Base, { 774 dart.setSignature(Base, {
775 methods: () => ({ 775 methods: () => ({
776 m: dart.definiteFunctionType(core.int, [core.int]), 776 m: dart.fnType(core.int, [core.int]),
777 }) 777 })
778 }); 778 });
779 779
780 class M1 { 780 class M1 {
781 m(x) {return x;} 781 m(x) {return x;}
782 }; 782 };
783 dart.setSignature(M1, { 783 dart.setSignature(M1, {
784 methods: () => ({ 784 methods: () => ({
785 m: dart.definiteFunctionType(core.num, [core.int]), 785 m: dart.fnType(core.num, [core.int]),
786 }) 786 })
787 }); 787 });
788 788
789 class M2 { 789 class M2 {
790 m(x) {return x;} 790 m(x) {return x;}
791 }; 791 };
792 dart.setSignature(M2, { 792 dart.setSignature(M2, {
793 methods: () => ({ 793 methods: () => ({
794 m: dart.definiteFunctionType(core.Object, [core.int]), 794 m: dart.fnType(core.Object, [core.int]),
795 }) 795 })
796 }); 796 });
797 797
798 class O extends dart.mixin(Base, M1, M2) { 798 class O extends dart.mixin(Base, M1, M2) {
799 new() {}; 799 new() {};
800 }; 800 };
801 dart.setSignature(O, {}); 801 dart.setSignature(O, {});
802 var obj = new O(); 802 var obj = new O();
803 var m = dart.bind(obj, 'm'); 803 var m = dart.bind(obj, 'm');
804 checkType(m, dart.functionType(core.Object, [core.int])); 804 checkType(m, dart.fnTypeFuzzy(core.Object, [core.int]));
805 checkType(m, dart.functionType(core.int, [core.int]), false, true); 805 checkType(m, dart.fnTypeFuzzy(core.int, [core.int]), false, true);
806 806
807 // Test inherited signatures 807 // Test inherited signatures
808 class P extends O { 808 class P extends O {
809 new() {}; 809 new() {};
810 m(x) {return x;}; 810 m(x) {return x;};
811 }; 811 };
812 dart.setSignature(P, {}); 812 dart.setSignature(P, {});
813 var obj = new P(); 813 var obj = new P();
814 var m = dart.bind(obj, 'm'); 814 var m = dart.bind(obj, 'm');
815 checkType(m, dart.functionType(core.Object, [core.int])); 815 checkType(m, dart.fnTypeFuzzy(core.Object, [core.int]));
816 checkType(m, dart.functionType(core.int, [core.int]), false, true); 816 checkType(m, dart.fnTypeFuzzy(core.int, [core.int]), false, true);
817 }); 817 });
818 818
819 test('Object members', () => { 819 test('Object members', () => {
820 let nullHash = dart.hashCode(null); 820 let nullHash = dart.hashCode(null);
821 assert.equal(nullHash, 0); 821 assert.equal(nullHash, 0);
822 let nullString = dart.toString(null); 822 let nullString = dart.toString(null);
823 assert.equal(nullString, 'null'); 823 assert.equal(nullString, 'null');
824 824
825 let map = new Map(); 825 let map = new Map();
826 let mapHash = dart.hashCode(map); 826 let mapHash = dart.hashCode(map);
(...skipping 17 matching lines...) Expand all
844 checkType(intHash, core.int); 844 checkType(intHash, core.int);
845 845
846 let intString = dart.toString(n); 846 let intString = dart.toString(n);
847 assert.equal(intString, '42'); 847 assert.equal(intString, '42');
848 }); 848 });
849 }); 849 });
850 850
851 suite('subtyping', function() { 851 suite('subtyping', function() {
852 'use strict'; 852 'use strict';
853 853
854 let functionType = dart.functionType; 854 let fnTypeFuzzy = dart.fnTypeFuzzy;
855 let definiteFunctionType = dart.definiteFunctionType; 855 let fnType = dart.fnType;
856 let typedef = dart.typedef; 856 let typedef = dart.typedef;
857 let isSubtype = dart.isSubtype; 857 let isSubtype = dart.isSubtype;
858 let int = core.int; 858 let int = core.int;
859 let num = core.num; 859 let num = core.num;
860 let dyn = dart.dynamic; 860 let dyn = dart.dynamic;
861 861
862 function always(t1, t2) { 862 function always(t1, t2) {
863 assert.equal(isSubtype(t1, t2), true, 863 assert.equal(isSubtype(t1, t2), true,
864 dart.toString(t1) + 864 dart.toString(t1) +
865 " should always be a subtype of " + 865 " should always be a subtype of " +
866 dart.toString(t2)); 866 dart.toString(t2));
867 } 867 }
868 function never(t1, t2) { 868 function never(t1, t2) {
869 assert.equal(isSubtype(t1, t2), false, 869 assert.equal(isSubtype(t1, t2), false,
870 dart.toString(t1) + 870 dart.toString(t1) +
871 " should never be a subtype of " + 871 " should never be a subtype of " +
872 dart.toString(t2)); 872 dart.toString(t2));
873 } 873 }
874 function maybe(t1, t2) { 874 function maybe(t1, t2) {
875 assert.equal(isSubtype(t1, t2), null, 875 assert.equal(isSubtype(t1, t2), null,
876 dart.toString(t1) + 876 dart.toString(t1) +
877 " should maybe be a subtype of " + 877 " should maybe be a subtype of " +
878 dart.toString(t2)); 878 dart.toString(t2));
879 } 879 }
880 880
881 function always2(t1, t2) { 881 function always2(t1, t2) {
882 always(t1, t2); 882 always(t1, t2);
883 always(functionType(t1, [t2]), functionType(t2, [t1])); 883 always(fnTypeFuzzy(t1, [t2]), fnTypeFuzzy(t2, [t1]));
884 } 884 }
885 function never2(t1, t2) { 885 function never2(t1, t2) {
886 never(t1, t2); 886 never(t1, t2);
887 maybe(functionType(t1, [t2]), functionType(t2, [t1])); 887 maybe(fnTypeFuzzy(t1, [t2]), fnTypeFuzzy(t2, [t1]));
888 } 888 }
889 function maybe2(t1, t2) { 889 function maybe2(t1, t2) {
890 maybe(t1, t2); 890 maybe(t1, t2);
891 maybe(functionType(t1, [t2]), functionType(t2, [t1])); 891 maybe(fnTypeFuzzy(t1, [t2]), fnTypeFuzzy(t2, [t1]));
892 } 892 }
893 893
894 function run_test(func1, func2, func2opt, func1extra, func2extra) { 894 function run_test(func1, func2, func2opt, func1extra, func2extra) {
895 always2(func2(int, int), func2(int, int)); 895 always2(func2(int, int), func2(int, int));
896 always2(func2(int, num), func2(int, int)); 896 always2(func2(int, num), func2(int, int));
897 always2(func2(int, int), func2(num, int)); 897 always2(func2(int, int), func2(num, int));
898 898
899 always2(func2opt(int, int), func2opt(int, int)); 899 always2(func2opt(int, int), func2opt(int, int));
900 always2(func2opt(int, num), func2opt(int, int)); 900 always2(func2opt(int, num), func2opt(int, int));
901 always2(func2opt(int, int), func2opt(num, int)); 901 always2(func2opt(int, int), func2opt(num, int));
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
958 never2(func2(num, int), func1extra(int)); 958 never2(func2(num, int), func1extra(int));
959 never2(func2(num, num), func1extra(num)); 959 never2(func2(num, num), func1extra(num));
960 960
961 never2(func2(int, int), func2extra(int, int)); 961 never2(func2(int, int), func2extra(int, int));
962 never2(func2(num, int), func2extra(int, int)); 962 never2(func2(num, int), func2extra(int, int));
963 never2(func2(num, num), func2extra(num, num)); 963 never2(func2(num, num), func2extra(num, num));
964 }; 964 };
965 965
966 test('basic function types', () => { 966 test('basic function types', () => {
967 function func1(S) { 967 function func1(S) {
968 return functionType(S, []); 968 return fnTypeFuzzy(S, []);
969 } 969 }
970 970
971 function func2(S, T) { 971 function func2(S, T) {
972 return functionType(S, [T]); 972 return fnTypeFuzzy(S, [T]);
973 } 973 }
974 974
975 function func2opt(S, T) { 975 function func2opt(S, T) {
976 return functionType(S, [], [T]); 976 return fnTypeFuzzy(S, [], [T]);
977 } 977 }
978 978
979 function func1extra(S) { 979 function func1extra(S) {
980 return functionType(S, [], {extra: int}); 980 return fnTypeFuzzy(S, [], {extra: int});
981 } 981 }
982 982
983 function func2extra(S, T) { 983 function func2extra(S, T) {
984 return functionType(S, [T], {extra: int}); 984 return fnTypeFuzzy(S, [T], {extra: int});
985 } 985 }
986 986
987 run_test(func1, func2, func2opt, func1extra, func2extra); 987 run_test(func1, func2, func2opt, func1extra, func2extra);
988 }); 988 });
989 989
990 test('top and bottom types', () => { 990 test('top and bottom types', () => {
991 let FutureOr = async.FutureOr$; 991 let FutureOr = async.FutureOr$;
992 let tops = [ 992 let tops = [
993 dart.dynamic, 993 dart.dynamic,
994 core.Object, 994 core.Object,
995 dart.void, 995 dart.void,
996 FutureOr(dart.dynamic), 996 FutureOr(dart.dynamic),
997 FutureOr(core.Object), 997 FutureOr(core.Object),
998 FutureOr(dart.void), 998 FutureOr(dart.void),
999 FutureOr(FutureOr(core.Object)), 999 FutureOr(FutureOr(core.Object)),
1000 // ... skip the (infinite) rest of the top types :D 1000 // ... skip the (infinite) rest of the top types :D
1001 ]; 1001 ];
1002 let bottoms = [dart.bottom, core.Null]; 1002 let bottoms = [dart.bottom, core.Null];
1003 1003
1004 for (let top of tops) { 1004 for (let top of tops) {
1005 for (let bottom of bottoms) { 1005 for (let bottom of bottoms) {
1006 always(bottom, top); 1006 always(bottom, top);
1007 always( 1007 always(
1008 definiteFunctionType(bottom, [top]), 1008 fnType(bottom, [top]),
1009 definiteFunctionType(top, [bottom])); 1009 fnType(top, [bottom]));
1010 } 1010 }
1011 } 1011 }
1012 1012
1013 for (let equalTypes of [tops, bottoms]) { 1013 for (let equalTypes of [tops, bottoms]) {
1014 for (let t1 of equalTypes) { 1014 for (let t1 of equalTypes) {
1015 for (let t2 of equalTypes) { 1015 for (let t2 of equalTypes) {
1016 always(t1, t2); 1016 always(t1, t2);
1017 always(t2, t1); 1017 always(t2, t1);
1018 1018
1019 let t11 = definiteFunctionType(t1, [t1]); 1019 let t11 = fnType(t1, [t1]);
1020 let t22 = definiteFunctionType(t2, [t2]); 1020 let t22 = fnType(t2, [t2]);
1021 always(t11, t22); 1021 always(t11, t22);
1022 always(t22, t11); 1022 always(t22, t11);
1023 } 1023 }
1024 } 1024 }
1025 } 1025 }
1026 }); 1026 });
1027 1027
1028 test('basic typedefs', () => { 1028 test('basic typedefs', () => {
1029 function func1(S) { 1029 function func1(S) {
1030 return dart.typedef('Func1', () => functionType(S, [])) 1030 return dart.typedef('Func1', () => fnTypeFuzzy(S, []))
1031 } 1031 }
1032 1032
1033 function func2(S, T) { 1033 function func2(S, T) {
1034 return dart.typedef('Func2', () => functionType(S, [T])) 1034 return dart.typedef('Func2', () => fnTypeFuzzy(S, [T]))
1035 } 1035 }
1036 1036
1037 function func2opt(S, T) { 1037 function func2opt(S, T) {
1038 return dart.typedef('Func2', () => functionType(S, [], [T])) 1038 return dart.typedef('Func2', () => fnTypeFuzzy(S, [], [T]))
1039 } 1039 }
1040 1040
1041 function func1extra(S) { 1041 function func1extra(S) {
1042 return dart.typedef('Func1', () => functionType(S, [], {extra: int})) 1042 return dart.typedef('Func1', () => fnTypeFuzzy(S, [], {extra: int}))
1043 } 1043 }
1044 1044
1045 function func2extra(S, T) { 1045 function func2extra(S, T) {
1046 return dart.typedef('Func2', () => functionType(S, [T], {extra: int})) 1046 return dart.typedef('Func2', () => fnTypeFuzzy(S, [T], {extra: int}))
1047 } 1047 }
1048 1048
1049 run_test(func1, func2, func2opt, func1extra, func2extra); 1049 run_test(func1, func2, func2opt, func1extra, func2extra);
1050 }); 1050 });
1051 1051
1052 test('basic generic typedefs', () => { 1052 test('basic generic typedefs', () => {
1053 let func1 = dart.generic( 1053 let func1 = dart.generic(
1054 (S) => dart.typedef('Func1', () => functionType(S, []))); 1054 (S) => dart.typedef('Func1', () => fnTypeFuzzy(S, [])));
1055 1055
1056 let func2 = dart.generic( 1056 let func2 = dart.generic(
1057 (S, T) => dart.typedef('Func2', () => functionType(S, [T]))); 1057 (S, T) => dart.typedef('Func2', () => fnTypeFuzzy(S, [T])));
1058 1058
1059 let func2opt = dart.generic( 1059 let func2opt = dart.generic(
1060 (S, T) => dart.typedef('Func2', () => functionType(S, [], [T]))); 1060 (S, T) => dart.typedef('Func2', () => fnTypeFuzzy(S, [], [T])));
1061 1061
1062 let func1extra = dart.generic( 1062 let func1extra = dart.generic(
1063 (S) => dart.typedef('Func1', () => functionType(S, [], {extra: int}))); 1063 (S) => dart.typedef('Func1', () => fnTypeFuzzy(S, [], {extra: int})));
1064 1064
1065 let func2extra = dart.generic( 1065 let func2extra = dart.generic(
1066 (S, T) => dart.typedef('Func2', 1066 (S, T) => dart.typedef('Func2',
1067 () => functionType(S, [T], {extra: int}))); 1067 () => fnTypeFuzzy(S, [T], {extra: int})));
1068 1068
1069 run_test(func1, func2, func2opt, func1extra, func2extra); 1069 run_test(func1, func2, func2opt, func1extra, func2extra);
1070 }); 1070 });
1071 1071
1072 test('fuzzy function types', () => { 1072 test('fuzzy function types', () => {
1073 always(functionType(int, [int]), functionType(dyn, [dyn])); 1073 always(fnTypeFuzzy(int, [int]), fnTypeFuzzy(dyn, [dyn]));
1074 always(functionType(int, [], [int]), functionType(dyn, [], [dyn])); 1074 always(fnTypeFuzzy(int, [], [int]), fnTypeFuzzy(dyn, [], [dyn]));
1075 always(functionType(int, [], [int]), functionType(dyn, [dyn])); 1075 always(fnTypeFuzzy(int, [], [int]), fnTypeFuzzy(dyn, [dyn]));
1076 always(functionType(int, [], [int]), functionType(dyn, [])); 1076 always(fnTypeFuzzy(int, [], [int]), fnTypeFuzzy(dyn, []));
1077 always(functionType(int, [int], {extra: int}), functionType(dyn, [dyn])); 1077 always(fnTypeFuzzy(int, [int], {extra: int}), fnTypeFuzzy(dyn, [dyn]));
1078 1078
1079 always(functionType(dyn, [dyn]), functionType(dyn, [dyn])); 1079 always(fnTypeFuzzy(dyn, [dyn]), fnTypeFuzzy(dyn, [dyn]));
1080 always(functionType(dyn, [], [dyn]), functionType(dyn, [], [dyn])); 1080 always(fnTypeFuzzy(dyn, [], [dyn]), fnTypeFuzzy(dyn, [], [dyn]));
1081 always(functionType(dyn, [], [dyn]), functionType(dyn, [dyn])); 1081 always(fnTypeFuzzy(dyn, [], [dyn]), fnTypeFuzzy(dyn, [dyn]));
1082 always(functionType(dyn, [], [dyn]), functionType(dyn, [])); 1082 always(fnTypeFuzzy(dyn, [], [dyn]), fnTypeFuzzy(dyn, []));
1083 always(functionType(dyn, [dyn], {extra: dyn}), functionType(dyn, [dyn])); 1083 always(fnTypeFuzzy(dyn, [dyn], {extra: dyn}), fnTypeFuzzy(dyn, [dyn]));
1084 }); 1084 });
1085 1085
1086 test('void function types', () => { 1086 test('void function types', () => {
1087 always(functionType(int, [int]), functionType(dart.void, [dyn])); 1087 always(fnTypeFuzzy(int, [int]), fnTypeFuzzy(dart.void, [dyn]));
1088 always(functionType(int, [], [int]), functionType(dart.void, [], [dyn])); 1088 always(fnTypeFuzzy(int, [], [int]), fnTypeFuzzy(dart.void, [], [dyn]));
1089 always(functionType(int, [], [int]), functionType(dart.void, [dyn])); 1089 always(fnTypeFuzzy(int, [], [int]), fnTypeFuzzy(dart.void, [dyn]));
1090 always(functionType(int, [], [int]), functionType(dart.void, [])); 1090 always(fnTypeFuzzy(int, [], [int]), fnTypeFuzzy(dart.void, []));
1091 always(functionType(int, [int], {extra: int}), functionType(dart.void, [dy n])); 1091 always(fnTypeFuzzy(int, [int], {extra: int}), fnTypeFuzzy(dart.void, [dyn] ));
1092 1092
1093 always(functionType(dart.void, [int]), functionType(dart.void, [dyn])); 1093 always(fnTypeFuzzy(dart.void, [int]), fnTypeFuzzy(dart.void, [dyn]));
1094 always(functionType(dart.void, [], [int]), functionType(dart.void, [], [dy n])); 1094 always(fnTypeFuzzy(dart.void, [], [int]), fnTypeFuzzy(dart.void, [], [dyn] ));
1095 always(functionType(dart.void, [], [int]), functionType(dart.void, [dyn])) ; 1095 always(fnTypeFuzzy(dart.void, [], [int]), fnTypeFuzzy(dart.void, [dyn]));
1096 always(functionType(dart.void, [], [int]), functionType(dart.void, [])); 1096 always(fnTypeFuzzy(dart.void, [], [int]), fnTypeFuzzy(dart.void, []));
1097 always(functionType(dart.void, [int], {extra: int}), functionType(dart.voi d, [dyn])); 1097 always(fnTypeFuzzy(dart.void, [int], {extra: int}), fnTypeFuzzy(dart.void, [dyn]));
1098 1098
1099 always(functionType(dyn, [dyn]), functionType(dart.void, [dyn])); 1099 always(fnTypeFuzzy(dyn, [dyn]), fnTypeFuzzy(dart.void, [dyn]));
1100 always(functionType(dyn, [], [dyn]), functionType(dart.void, [], [dyn])); 1100 always(fnTypeFuzzy(dyn, [], [dyn]), fnTypeFuzzy(dart.void, [], [dyn]));
1101 always(functionType(dyn, [], [dyn]), functionType(dart.void, [dyn])); 1101 always(fnTypeFuzzy(dyn, [], [dyn]), fnTypeFuzzy(dart.void, [dyn]));
1102 always(functionType(dyn, [], [dyn]), functionType(dart.void, [])); 1102 always(fnTypeFuzzy(dyn, [], [dyn]), fnTypeFuzzy(dart.void, []));
1103 always(functionType(dyn, [dyn], {extra: dyn}), functionType(dart.void, [dy n])); 1103 always(fnTypeFuzzy(dyn, [dyn], {extra: dyn}), fnTypeFuzzy(dart.void, [dyn] ));
1104 1104
1105 always(functionType(dart.void, [dyn]), functionType(dart.void, [dyn])); 1105 always(fnTypeFuzzy(dart.void, [dyn]), fnTypeFuzzy(dart.void, [dyn]));
1106 always(functionType(dart.void, [], [dyn]), functionType(dart.void, [], [dy n])); 1106 always(fnTypeFuzzy(dart.void, [], [dyn]), fnTypeFuzzy(dart.void, [], [dyn] ));
1107 always(functionType(dart.void, [], [dyn]), functionType(dart.void, [dyn])) ; 1107 always(fnTypeFuzzy(dart.void, [], [dyn]), fnTypeFuzzy(dart.void, [dyn]));
1108 always(functionType(dart.void, [], [dyn]), functionType(dart.void, [])); 1108 always(fnTypeFuzzy(dart.void, [], [dyn]), fnTypeFuzzy(dart.void, []));
1109 always(functionType(dart.void, [dyn], {extra: dyn}), functionType(dart.voi d, [dyn])); 1109 always(fnTypeFuzzy(dart.void, [dyn], {extra: dyn}), fnTypeFuzzy(dart.void, [dyn]));
1110 1110
1111 always(functionType(dart.void, [int]), functionType(dyn, [dyn])); 1111 always(fnTypeFuzzy(dart.void, [int]), fnTypeFuzzy(dyn, [dyn]));
1112 always(functionType(dart.void, [], [int]), functionType(dyn, [], [dyn])); 1112 always(fnTypeFuzzy(dart.void, [], [int]), fnTypeFuzzy(dyn, [], [dyn]));
1113 always(functionType(dart.void, [], [int]), functionType(dyn, [dyn])); 1113 always(fnTypeFuzzy(dart.void, [], [int]), fnTypeFuzzy(dyn, [dyn]));
1114 always(functionType(dart.void, [], [int]), functionType(dyn, [])); 1114 always(fnTypeFuzzy(dart.void, [], [int]), fnTypeFuzzy(dyn, []));
1115 always(functionType(dart.void, [int], {extra: int}), functionType(dyn, [dy n])); 1115 always(fnTypeFuzzy(dart.void, [int], {extra: int}), fnTypeFuzzy(dyn, [dyn] ));
1116 1116
1117 never(functionType(dart.void, [int]), functionType(int, [dyn])); 1117 never(fnTypeFuzzy(dart.void, [int]), fnTypeFuzzy(int, [dyn]));
1118 never(functionType(dart.void, [], [int]), functionType(int, [], [dyn])); 1118 never(fnTypeFuzzy(dart.void, [], [int]), fnTypeFuzzy(int, [], [dyn]));
1119 never(functionType(dart.void, [], [int]), functionType(int, [dyn])); 1119 never(fnTypeFuzzy(dart.void, [], [int]), fnTypeFuzzy(int, [dyn]));
1120 never(functionType(dart.void, [], [int]), functionType(int, [])); 1120 never(fnTypeFuzzy(dart.void, [], [int]), fnTypeFuzzy(int, []));
1121 never(functionType(dart.void, [int], {extra: int}), functionType(int, [dyn ])); 1121 never(fnTypeFuzzy(dart.void, [int], {extra: int}), fnTypeFuzzy(int, [dyn]) );
1122 1122
1123 never(functionType(dart.void, [int]), functionType(int, [int])); 1123 never(fnTypeFuzzy(dart.void, [int]), fnTypeFuzzy(int, [int]));
1124 never(functionType(dart.void, [], [int]), functionType(int, [], [int])); 1124 never(fnTypeFuzzy(dart.void, [], [int]), fnTypeFuzzy(int, [], [int]));
1125 never(functionType(dart.void, [], [int]), functionType(int, [int])); 1125 never(fnTypeFuzzy(dart.void, [], [int]), fnTypeFuzzy(int, [int]));
1126 never(functionType(dart.void, [], [int]), functionType(int, [])); 1126 never(fnTypeFuzzy(dart.void, [], [int]), fnTypeFuzzy(int, []));
1127 never(functionType(dart.void, [int], {extra: int}), functionType(int, [int ])); 1127 never(fnTypeFuzzy(dart.void, [int], {extra: int}), fnTypeFuzzy(int, [int]) );
1128 }); 1128 });
1129 1129
1130 test('higher-order typedef', () => { 1130 test('higher-order typedef', () => {
1131 let Func$ = dart.generic((S, T) => 1131 let Func$ = dart.generic((S, T) =>
1132 dart.typedef('Func', () => 1132 dart.typedef('Func', () =>
1133 functionType(T, [S]))); 1133 fnTypeFuzzy(T, [S])));
1134 let Func2$ = dart.generic((R, S, T) => 1134 let Func2$ = dart.generic((R, S, T) =>
1135 dart.typedef('Func2', () => 1135 dart.typedef('Func2', () =>
1136 functionType(T, [Func$(R, S)]))); 1136 fnTypeFuzzy(T, [Func$(R, S)])));
1137 1137
1138 maybe(functionType(int, [functionType(int, [num])]), 1138 maybe(fnTypeFuzzy(int, [fnTypeFuzzy(int, [num])]),
1139 functionType(num, [functionType(int, [int])])); 1139 fnTypeFuzzy(num, [fnTypeFuzzy(int, [int])]));
1140 maybe(functionType(int, [Func$(num, int)]), 1140 maybe(fnTypeFuzzy(int, [Func$(num, int)]),
1141 functionType(num, [Func$(int, int)])); 1141 fnTypeFuzzy(num, [Func$(int, int)]));
1142 maybe(Func2$(num, int, int), Func2$(int, int, num)); 1142 maybe(Func2$(num, int, int), Func2$(int, int, num));
1143 }); 1143 });
1144 1144
1145 test('mixed types', () => { 1145 test('mixed types', () => {
1146 let AA$ = dart.generic((T) => class AA extends core.Object {}); 1146 let AA$ = dart.generic((T) => class AA extends core.Object {});
1147 1147
1148 always(int, dyn); 1148 always(int, dyn);
1149 maybe(dyn, int); 1149 maybe(dyn, int);
1150 1150
1151 never(functionType(int, [int]), int); 1151 never(fnTypeFuzzy(int, [int]), int);
1152 1152
1153 never(int, functionType(int, [int])); 1153 never(int, fnTypeFuzzy(int, [int]));
1154 1154
1155 always(AA$(int), AA$(dyn)); 1155 always(AA$(int), AA$(dyn));
1156 maybe(AA$(dyn), AA$(int)); 1156 maybe(AA$(dyn), AA$(int));
1157 never(AA$(core.Object), AA$(int)); 1157 never(AA$(core.Object), AA$(int));
1158 1158
1159 always(AA$(functionType(int, [int])), AA$(dyn)); 1159 always(AA$(fnTypeFuzzy(int, [int])), AA$(dyn));
1160 maybe(AA$(dyn), AA$(functionType(int, [int]))); 1160 maybe(AA$(dyn), AA$(fnTypeFuzzy(int, [int])));
1161 never(AA$(core.Object), AA$(functionType(int, [int]))); 1161 never(AA$(core.Object), AA$(fnTypeFuzzy(int, [int])));
1162 1162
1163 always(AA$(functionType(int, [int])), AA$(functionType(dyn, [dyn]))); 1163 always(AA$(fnTypeFuzzy(int, [int])), AA$(fnTypeFuzzy(dyn, [dyn])));
1164 maybe(AA$(functionType(dyn, [dyn])), AA$(functionType(int, [int]))); 1164 maybe(AA$(fnTypeFuzzy(dyn, [dyn])), AA$(fnTypeFuzzy(int, [int])));
1165 maybe(AA$(functionType(core.Object, [core.Object])), 1165 maybe(AA$(fnTypeFuzzy(core.Object, [core.Object])),
1166 AA$(functionType(int, [int]))); 1166 AA$(fnTypeFuzzy(int, [int])));
1167 }); 1167 });
1168 }); 1168 });
1169 1169
1170 suite('canonicalization', function() { 1170 suite('canonicalization', function() {
1171 'use strict'; 1171 'use strict';
1172 let functionType = dart.functionType; 1172 let fnTypeFuzzy = dart.fnTypeFuzzy;
1173 let definiteFunctionType = dart.definiteFunctionType; 1173 let fnType = dart.fnType;
1174 let typedef = dart.typedef; 1174 let typedef = dart.typedef;
1175 let generic = dart.generic; 1175 let generic = dart.generic;
1176 1176
1177 let Object = core.Object; 1177 let Object = core.Object;
1178 let String = core.String; 1178 let String = core.String;
1179 let int = core.int; 1179 let int = core.int;
1180 let dynamic = dart.dynamic; 1180 let dynamic = dart.dynamic;
1181 let bottom = dart.bottom; 1181 let bottom = dart.bottom;
1182 let Map = core.Map; 1182 let Map = core.Map;
1183 let Map$ = core.Map$; 1183 let Map$ = core.Map$;
1184 1184
1185 class A {} 1185 class A {}
1186 1186
1187 let AA$ = generic((T, U) => class AA extends core.Object {}); 1187 let AA$ = generic((T, U) => class AA extends core.Object {});
1188 let AA = AA$(); 1188 let AA = AA$();
1189 1189
1190 let Func2 = typedef('Func2', () => functionType(dynamic, [dynamic, dynamic]) ); 1190 let Func2 = typedef('Func2', () => fnTypeFuzzy(dynamic, [dynamic, dynamic])) ;
1191 1191
1192 let FuncG$ = generic((T, U) => typedef('FuncG', () => functionType(T, [T, U] ))) 1192 let FuncG$ = generic((T, U) => typedef('FuncG', () => fnTypeFuzzy(T, [T, U]) ))
1193 let FuncG = FuncG$(); 1193 let FuncG = FuncG$();
1194 1194
1195 test('base types', () => { 1195 test('base types', () => {
1196 assert.equal(Object, Object); 1196 assert.equal(Object, Object);
1197 assert.equal(String, String); 1197 assert.equal(String, String);
1198 assert.equal(dynamic, dynamic); 1198 assert.equal(dynamic, dynamic);
1199 }); 1199 });
1200 1200
1201 test('class types', () => { 1201 test('class types', () => {
1202 assert.equal(A, A); 1202 assert.equal(A, A);
(...skipping 10 matching lines...) Expand all
1213 }); 1213 });
1214 1214
1215 test('typedefs', () => { 1215 test('typedefs', () => {
1216 assert.equal(Func2, Func2); 1216 assert.equal(Func2, Func2);
1217 assert.equal(FuncG, FuncG$(dynamic, dynamic)); 1217 assert.equal(FuncG, FuncG$(dynamic, dynamic));
1218 assert.equal(FuncG$(dynamic, dynamic), FuncG$(dynamic, dynamic)); 1218 assert.equal(FuncG$(dynamic, dynamic), FuncG$(dynamic, dynamic));
1219 assert.equal(FuncG$(String, Func2), FuncG$(String, Func2)); 1219 assert.equal(FuncG$(String, Func2), FuncG$(String, Func2));
1220 }); 1220 });
1221 1221
1222 test('function types', () => { 1222 test('function types', () => {
1223 assert.equal(functionType(dynamic, [dynamic, dynamic]), 1223 assert.equal(fnTypeFuzzy(dynamic, [dynamic, dynamic]),
1224 functionType(dynamic, [dynamic, dynamic])) 1224 fnTypeFuzzy(dynamic, [dynamic, dynamic]))
1225 1225
1226 assert.notEqual(definiteFunctionType(dynamic, [dynamic, dynamic]), 1226 assert.notEqual(fnType(dynamic, [dynamic, dynamic]),
1227 functionType(dynamic, [dynamic, dynamic])) 1227 fnTypeFuzzy(dynamic, [dynamic, dynamic]))
1228 1228
1229 assert.equal(functionType(dynamic, [dynamic, dynamic]), 1229 assert.equal(fnTypeFuzzy(dynamic, [dynamic, dynamic]),
1230 functionType(dynamic, [bottom, bottom])) 1230 fnTypeFuzzy(dynamic, [bottom, bottom]))
1231 1231
1232 assert.equal(functionType(dynamic, [], [dynamic, dynamic]), 1232 assert.equal(fnTypeFuzzy(dynamic, [], [dynamic, dynamic]),
1233 functionType(dynamic, [], [dynamic, dynamic])) 1233 fnTypeFuzzy(dynamic, [], [dynamic, dynamic]))
1234 1234
1235 assert.notEqual(definiteFunctionType(dynamic, [], [dynamic, dynamic]), 1235 assert.notEqual(fnType(dynamic, [], [dynamic, dynamic]),
1236 functionType(dynamic, [], [dynamic, dynamic])) 1236 fnTypeFuzzy(dynamic, [], [dynamic, dynamic]))
1237 1237
1238 assert.equal(functionType(dynamic, [], [dynamic, dynamic]), 1238 assert.equal(fnTypeFuzzy(dynamic, [], [dynamic, dynamic]),
1239 functionType(dynamic, [], [bottom, bottom])) 1239 fnTypeFuzzy(dynamic, [], [bottom, bottom]))
1240 1240
1241 assert.equal(functionType(dynamic, [], {extra: dynamic}), 1241 assert.equal(fnTypeFuzzy(dynamic, [], {extra: dynamic}),
1242 functionType(dynamic, [], {extra: dynamic})) 1242 fnTypeFuzzy(dynamic, [], {extra: dynamic}))
1243 1243
1244 assert.notEqual(definiteFunctionType(dynamic, [], {extra: dynamic}), 1244 assert.notEqual(fnType(dynamic, [], {extra: dynamic}),
1245 functionType(dynamic, [], {extra: dynamic})) 1245 fnTypeFuzzy(dynamic, [], {extra: dynamic}))
1246 1246
1247 assert.equal(functionType(dynamic, [], {extra: dynamic}), 1247 assert.equal(fnTypeFuzzy(dynamic, [], {extra: dynamic}),
1248 functionType(dynamic, [], {extra: bottom})) 1248 fnTypeFuzzy(dynamic, [], {extra: bottom}))
1249 1249
1250 assert.equal(functionType(int, [int, int]), 1250 assert.equal(fnTypeFuzzy(int, [int, int]),
1251 functionType(int, [int, int])) 1251 fnTypeFuzzy(int, [int, int]))
1252 1252
1253 assert.equal(functionType(int, [], [int, int]), 1253 assert.equal(fnTypeFuzzy(int, [], [int, int]),
1254 functionType(int, [], [int, int])) 1254 fnTypeFuzzy(int, [], [int, int]))
1255 1255
1256 assert.equal(functionType(int, [int, int], {extra: int}), 1256 assert.equal(fnTypeFuzzy(int, [int, int], {extra: int}),
1257 functionType(int, [int, int], {extra: int})) 1257 fnTypeFuzzy(int, [int, int], {extra: int}))
1258 1258
1259 assert.equal(functionType(int, [int, int, int, int, int]), 1259 assert.equal(fnTypeFuzzy(int, [int, int, int, int, int]),
1260 functionType(int, [int, int, int, int, int])) 1260 fnTypeFuzzy(int, [int, int, int, int, int]))
1261 1261
1262 assert.notEqual(functionType(int, [int, int, int, int, int]), 1262 assert.notEqual(fnTypeFuzzy(int, [int, int, int, int, int]),
1263 functionType(int, [int, int, int], [int, int])) 1263 fnTypeFuzzy(int, [int, int, int], [int, int]))
1264 1264
1265 assert.notEqual(functionType(String, [int, int, int, int, int]), 1265 assert.notEqual(fnTypeFuzzy(String, [int, int, int, int, int]),
1266 functionType(int, [int, int, int, int, int])) 1266 fnTypeFuzzy(int, [int, int, int, int, int]))
1267 1267
1268 assert.notEqual(functionType(String, []), 1268 assert.notEqual(fnTypeFuzzy(String, []),
1269 functionType(int, [])) 1269 fnTypeFuzzy(int, []))
1270 }); 1270 });
1271 }); 1271 });
1272 1272
1273 suite('primitives', function() { 1273 suite('primitives', function() {
1274 'use strict'; 1274 'use strict';
1275 1275
1276 test('fixed length list', () => { 1276 test('fixed length list', () => {
1277 let list = new core.List(10); 1277 let list = new core.List(10);
1278 list[0] = 42; 1278 list[0] = 42;
1279 assert.throws(() => list.add(42)); 1279 assert.throws(() => list.add(42));
1280 }); 1280 });
1281 1281
1282 test('toString on ES Symbol', () => { 1282 test('toString on ES Symbol', () => {
1283 let sym = Symbol('_foobar'); 1283 let sym = Symbol('_foobar');
1284 assert.equal(dart.toString(sym), 'Symbol(_foobar)'); 1284 assert.equal(dart.toString(sym), 'Symbol(_foobar)');
1285 }); 1285 });
1286 }); 1286 });
1287 }); 1287 });
OLDNEW
« no previous file with comments | « pkg/dev_compiler/lib/src/compiler/code_generator.dart ('k') | pkg/dev_compiler/test/codegen_expected/BenchmarkBase.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698