| OLD | NEW |
| 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 core = dart_library.import('dart/core'); | 6 var core = dart_library.import('dart/core'); |
| 7 var collection = dart_library.import('dart/collection'); | 7 var collection = dart_library.import('dart/collection'); |
| 8 var dart = dart_library.import('dart_runtime/dart'); | 8 var dart = dart_library.import('dart_runtime/dart'); |
| 9 var dartx = dart.dartx; | 9 var dartx = dart.dartx; |
| 10 | 10 |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 | 102 |
| 103 suite('instanceOf', () => { | 103 suite('instanceOf', () => { |
| 104 "use strict"; | 104 "use strict"; |
| 105 | 105 |
| 106 let expect = assert.equal; | 106 let expect = assert.equal; |
| 107 let isGroundType = types.isGroundType; | 107 let isGroundType = types.isGroundType; |
| 108 let generic = dart.generic; | 108 let generic = dart.generic; |
| 109 let intIsNonNullable = false; | 109 let intIsNonNullable = false; |
| 110 let cast = dart.as; | 110 let cast = dart.as; |
| 111 let instanceOf = dart.is; | 111 let instanceOf = dart.is; |
| 112 let strongInstanceOf = dart.strongInstanceOf; |
| 112 let runtimeType = dart.realRuntimeType; | 113 let runtimeType = dart.realRuntimeType; |
| 113 let functionType = dart.functionType; | 114 let functionType = dart.functionType; |
| 114 let typedef = dart.typedef; | 115 let typedef = dart.typedef; |
| 115 let isSubtype = types.isSubtype; | 116 let isSubtype = types.isSubtype; |
| 116 | 117 |
| 117 let Object = core.Object; | 118 let Object = core.Object; |
| 118 let String = core.String; | 119 let String = core.String; |
| 119 let dynamic = dart.dynamic; | 120 let dynamic = dart.dynamic; |
| 120 let List = core.List; | 121 let List = core.List; |
| 121 let Map = core.Map; | 122 let Map = core.Map; |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 183 | 184 |
| 184 let cls5 = dart.fn((a, o) => { return null; }, C, [A, Object]); | 185 let cls5 = dart.fn((a, o) => { return null; }, C, [A, Object]); |
| 185 | 186 |
| 186 let cls6 = dart.fn((b, s, o) => { return null; }, B, [B, String, String]); | 187 let cls6 = dart.fn((b, s, o) => { return null; }, B, [B, String, String]); |
| 187 | 188 |
| 188 let cls7 = dart.fn((b, s, o) => { return null; }, B, [B, String], [Object]); | 189 let cls7 = dart.fn((b, s, o) => { return null; }, B, [B, String], [Object]); |
| 189 | 190 |
| 190 let cls8 = | 191 let cls8 = |
| 191 dart.fn((b, s, o) => { return null; }, B, [B, String], {p: Object}); | 192 dart.fn((b, s, o) => { return null; }, B, [B, String], {p: Object}); |
| 192 | 193 |
| 193 function checkType(x, type, expectedTrue) { | 194 function checkType(x, type, expectedTrue, strongOnly) { |
| 194 if (expectedTrue === undefined) expectedTrue = true; | 195 if (expectedTrue === undefined) expectedTrue = true; |
| 195 expect(instanceOf(x, type), expectedTrue); | 196 if (strongOnly == undefined) strongOnly = false; |
| 197 if (!strongOnly) { |
| 198 expect(instanceOf(x, type), expectedTrue); |
| 199 } else { |
| 200 assert.throws(() => instanceOf(x, type), dart_utils.StrongModeError); |
| 201 expect(strongInstanceOf(x, type), expectedTrue); |
| 202 } |
| 196 } | 203 } |
| 197 | 204 |
| 198 test('int', () => { | 205 test('int', () => { |
| 199 expect(isGroundType(int), true); | 206 expect(isGroundType(int), true); |
| 200 expect(isGroundType(runtimeType(5)), true); | 207 expect(isGroundType(runtimeType(5)), true); |
| 201 | 208 |
| 202 checkType(5, int); | 209 checkType(5, int); |
| 203 checkType(5, dynamic); | 210 checkType(5, dynamic); |
| 204 checkType(5, Object); | 211 checkType(5, Object); |
| 205 checkType(5, num); | 212 checkType(5, num); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 251 | 258 |
| 252 expect(cast(null, String), null); | 259 expect(cast(null, String), null); |
| 253 }); | 260 }); |
| 254 | 261 |
| 255 test('Map', () => { | 262 test('Map', () => { |
| 256 let m1 = new (Map$(String, String))(); | 263 let m1 = new (Map$(String, String))(); |
| 257 let m2 = new (Map$(Object, Object))(); | 264 let m2 = new (Map$(Object, Object))(); |
| 258 let m3 = new Map(); | 265 let m3 = new Map(); |
| 259 let m4 = new (collection.HashMap$(dart.dynamic, dart.dynamic))(); | 266 let m4 = new (collection.HashMap$(dart.dynamic, dart.dynamic))(); |
| 260 let m5 = new collection.LinkedHashMap(); | 267 let m5 = new collection.LinkedHashMap(); |
| 268 let m6 = new (Map$(String, dart.dynamic))(); |
| 269 |
| 261 | 270 |
| 262 expect(isGroundType(Map), true); | 271 expect(isGroundType(Map), true); |
| 263 expect(isGroundType(runtimeType(m1)), false); | 272 expect(isGroundType(runtimeType(m1)), false); |
| 264 expect(isGroundType(Map$(String, String)), false); | 273 expect(isGroundType(Map$(String, String)), false); |
| 265 expect(isGroundType(runtimeType(m2)), true); | 274 expect(isGroundType(runtimeType(m2)), true); |
| 266 expect(isGroundType(Map$(Object, Object)), true); | 275 expect(isGroundType(Map$(Object, Object)), true); |
| 267 expect(isGroundType(runtimeType(m3)), true); | 276 expect(isGroundType(runtimeType(m3)), true); |
| 268 expect(isGroundType(Map), true); | 277 expect(isGroundType(Map), true); |
| 269 expect(isGroundType(runtimeType(m4)), true); | 278 expect(isGroundType(runtimeType(m4)), true); |
| 270 expect(isGroundType(collection.HashMap$(dynamic, dynamic)), true); | 279 expect(isGroundType(collection.HashMap$(dynamic, dynamic)), true); |
| 271 expect(isGroundType(runtimeType(m5)), true); | 280 expect(isGroundType(runtimeType(m5)), true); |
| 272 expect(isGroundType(collection.LinkedHashMap), true); | 281 expect(isGroundType(collection.LinkedHashMap), true); |
| 273 expect(isGroundType(collection.LinkedHashMap), true); | 282 expect(isGroundType(collection.LinkedHashMap), true); |
| 274 | 283 |
| 275 // Map<T1,T2> <: Map | 284 // Map<T1,T2> <: Map |
| 276 checkType(m1, Map); | 285 checkType(m1, Map); |
| 277 checkType(m1, Object); | 286 checkType(m1, Object); |
| 278 | 287 |
| 279 // Instance of self | 288 // Instance of self |
| 280 checkType(m1, runtimeType(m1)); | 289 checkType(m1, runtimeType(m1)); |
| 281 checkType(m1, Map$(String, String)); | 290 checkType(m1, Map$(String, String)); |
| 282 | 291 |
| 283 // Covariance on generics | 292 // Covariance on generics |
| 284 checkType(m1, runtimeType(m2)); | 293 checkType(m1, runtimeType(m2)); |
| 285 checkType(m1, Map$(Object, Object)); | 294 checkType(m1, Map$(Object, Object)); |
| 286 | 295 |
| 287 // No contravariance on generics. | 296 // No contravariance on generics. |
| 288 checkType(m2, runtimeType(m1), false); | 297 checkType(m2, runtimeType(m1), false, true); |
| 289 checkType(m2, Map$(String, String), false); | 298 checkType(m2, Map$(String, String), false, true); |
| 290 | 299 |
| 291 // null is! Map | 300 // null is! Map |
| 292 checkType(null, Map, false); | 301 checkType(null, Map, false); |
| 293 | 302 |
| 294 // Raw generic types | 303 // Raw generic types |
| 295 checkType(m5, Map); | 304 checkType(m5, Map); |
| 296 checkType(m4, Map); | 305 checkType(m4, Map); |
| 306 |
| 307 // Is checks |
| 308 assert.throws(() => dart.is(m3, Map$(String, String)), |
| 309 dart_utils.StrongModeError); |
| 310 assert.throws(() => dart.is(m6, Map$(String, String)), |
| 311 dart_utils.StrongModeError); |
| 312 assert.isTrue(dart.is(m1, Map$(String, String))); |
| 313 assert.throws(() => dart.is(m2, Map$(String, String)), |
| 314 dart_utils.StrongModeError); |
| 315 |
| 316 // As checks |
| 317 // TODO(vsm): Enable these. We're currently only logging warnings on |
| 318 // StrongModeErrors. |
| 319 // assert.throws(() => dart.as(m3, Map$(String, String)), |
| 320 // dart_utils.StrongModeError); |
| 321 // assert.throws(() => dart.as(m6, Map$(String, String)), |
| 322 // dart_utils.StrongModeError); |
| 323 assert.equal(dart.as(m1, Map$(String, String)), m1); |
| 324 // assert.throws(() => dart.as(m2, Map$(String, String)), |
| 325 // dart_utils.StrongModeError); |
| 297 }); | 326 }); |
| 298 | 327 |
| 299 test('constructors', () => { | 328 test('constructors', () => { |
| 300 class C extends core.Object { | 329 class C extends core.Object { |
| 301 C(x) {}; | 330 C(x) {}; |
| 302 named(x, y) {}; | 331 named(x, y) {}; |
| 303 } | 332 } |
| 304 dart.defineNamedConstructor(C, 'named'); | 333 dart.defineNamedConstructor(C, 'named'); |
| 305 dart.setSignature(C, { | 334 dart.setSignature(C, { |
| 306 constructors: () => ({ | 335 constructors: () => ({ |
| (...skipping 26 matching lines...) Expand all Loading... |
| 333 // This was AA<String> in Dart (wrong number of type args). | 362 // This was AA<String> in Dart (wrong number of type args). |
| 334 let aabad = new (AA$(dart.dynamic, dart.dynamic))(); | 363 let aabad = new (AA$(dart.dynamic, dart.dynamic))(); |
| 335 let aabadtype = runtimeType(aabad); | 364 let aabadtype = runtimeType(aabad); |
| 336 | 365 |
| 337 expect(isGroundType(aatype), false); | 366 expect(isGroundType(aatype), false); |
| 338 expect(isGroundType(AA$(String, List)), false); | 367 expect(isGroundType(AA$(String, List)), false); |
| 339 expect(isGroundType(bbtype), false); | 368 expect(isGroundType(bbtype), false); |
| 340 expect(isGroundType(BB$(String, List)), false); | 369 expect(isGroundType(BB$(String, List)), false); |
| 341 expect(isGroundType(cctype), true); | 370 expect(isGroundType(cctype), true); |
| 342 expect(isGroundType(CC), true); | 371 expect(isGroundType(CC), true); |
| 343 checkType(cc, aatype, false); | 372 checkType(cc, aatype, false, true); |
| 344 checkType(cc, AA$(String, List), false); | 373 checkType(cc, AA$(String, List), false, true); |
| 345 checkType(cc, bbtype); | 374 checkType(cc, bbtype); |
| 346 checkType(cc, BB$(String, List)); | 375 checkType(cc, BB$(String, List)); |
| 347 checkType(aa, cctype, false); | 376 checkType(aa, cctype, false); |
| 348 checkType(aa, CC, false); | 377 checkType(aa, CC, false); |
| 349 checkType(aa, bbtype, false); | 378 checkType(aa, bbtype, false, true); |
| 350 checkType(aa, BB$(String, List), false); | 379 checkType(aa, BB$(String, List), false, true); |
| 351 checkType(bb, cctype, false); | 380 checkType(bb, cctype, false); |
| 352 checkType(bb, CC, false); | 381 checkType(bb, CC, false); |
| 353 checkType(aa, aabadtype); | 382 checkType(aa, aabadtype); |
| 354 checkType(aa, dynamic); | 383 checkType(aa, dynamic); |
| 355 checkType(aabad, aatype, false); | 384 checkType(aabad, aatype, false, true); |
| 356 checkType(aabad, AA$(String, List), false); | 385 checkType(aabad, AA$(String, List), false, true); |
| 357 checkType(aabad, aarawtype); | 386 checkType(aabad, aarawtype); |
| 358 checkType(aabad, AA); | 387 checkType(aabad, AA); |
| 359 checkType(aaraw, aabadtype); | 388 checkType(aaraw, aabadtype); |
| 360 checkType(aaraw, AA$(dart.dynamic, dart.dynamic)); | 389 checkType(aaraw, AA$(dart.dynamic, dart.dynamic)); |
| 361 checkType(aaraw, aadynamictype); | 390 checkType(aaraw, aadynamictype); |
| 362 checkType(aaraw, AA$(dynamic, dynamic)); | 391 checkType(aaraw, AA$(dynamic, dynamic)); |
| 363 checkType(aadynamic, aarawtype); | 392 checkType(aadynamic, aarawtype); |
| 364 checkType(aadynamic, AA); | 393 checkType(aadynamic, AA); |
| 365 }); | 394 }); |
| 366 | 395 |
| 367 test('void', () => { | 396 test('void', () => { |
| 368 //checkType((x) => x, type((void _(x)) {})); | 397 //checkType((x) => x, type((void _(x)) {})); |
| 369 }); | 398 }); |
| 370 | 399 |
| 371 test('mixins', () => { | 400 test('mixins', () => { |
| 372 let c = collection; | 401 let c = collection; |
| 373 var s1 = new (c.SplayTreeSet$(String))(); | 402 var s1 = new (c.SplayTreeSet$(String))(); |
| 374 | 403 |
| 375 checkType(s1, c.IterableMixin); | 404 checkType(s1, c.IterableMixin); |
| 376 checkType(s1, c.IterableMixin$(String)); | 405 checkType(s1, c.IterableMixin$(String)); |
| 377 checkType(s1, c.IterableMixin$(int), false); | 406 checkType(s1, c.IterableMixin$(int), false, true); |
| 378 | 407 |
| 379 checkType(s1, c.SetMixin); | 408 checkType(s1, c.SetMixin); |
| 380 checkType(s1, c.SetMixin$(String)); | 409 checkType(s1, c.SetMixin$(String)); |
| 381 checkType(s1, c.SetMixin$(int), false); | 410 checkType(s1, c.SetMixin$(int), false, true); |
| 382 }); | 411 }); |
| 383 | 412 |
| 384 test('Type', () => { | 413 test('Type', () => { |
| 385 checkType(int, core.Type, true); | 414 checkType(int, core.Type, true); |
| 386 checkType(num, core.Type, true); | 415 checkType(num, core.Type, true); |
| 387 checkType(bool, core.Type, true); | 416 checkType(bool, core.Type, true); |
| 388 checkType(String, core.Type, true); | 417 checkType(String, core.Type, true); |
| 389 checkType(dynamic, core.Type, true); | 418 checkType(dynamic, core.Type, true); |
| 390 checkType(Object, core.Type, true); | 419 checkType(Object, core.Type, true); |
| 391 checkType(List, core.Type, true); | 420 checkType(List, core.Type, true); |
| 392 checkType(Map, core.Type, true); | 421 checkType(Map, core.Type, true); |
| 393 checkType(Map$(int, String), core.Type, true); | 422 checkType(Map$(int, String), core.Type, true); |
| 394 checkType(Func2, core.Type, true); | 423 checkType(Func2, core.Type, true); |
| 395 checkType(functionType(dynamic, [dynamic]), core.Type, true); | 424 checkType(functionType(dynamic, [dynamic]), core.Type, true); |
| 396 checkType(core.Type, core.Type, true); | 425 checkType(core.Type, core.Type, true); |
| 397 | 426 |
| 398 checkType(3, core.Type, false); | 427 checkType(3, core.Type, false); |
| 399 checkType("hello", core.Type, false); | 428 checkType("hello", core.Type, false); |
| 400 }) | 429 }) |
| 401 | 430 |
| 402 test('Functions', () => { | 431 test('Functions', () => { |
| 403 // - return type: Dart is bivariant. We're covariant. | 432 // - return type: Dart is bivariant. We're covariant. |
| 404 // - param types: Dart is bivariant. We're contravariant. | 433 // - param types: Dart is bivariant. We're contravariant. |
| 405 expect(isGroundType(Func2), true); | 434 expect(isGroundType(Func2), true); |
| 406 expect(isGroundType(Foo), false); | 435 expect(isGroundType(Foo), false); |
| 407 expect(isGroundType(functionType(B, [B, String])), false); | 436 expect(isGroundType(functionType(B, [B, String])), false); |
| 408 checkType(bar1, Foo, false); | 437 checkType(bar1, Foo, false, true); |
| 409 checkType(cls1, Foo, false); | 438 checkType(cls1, Foo, false, true); |
| 410 checkType(bar1, functionType(B, [B, String]), false); | 439 checkType(bar1, functionType(B, [B, String]), false, true); |
| 411 checkType(cls1, functionType(B, [B, String]), false); | 440 checkType(cls1, functionType(B, [B, String]), false, true); |
| 412 checkType(bar2, Foo, false); | 441 checkType(bar2, Foo, false, true); |
| 413 checkType(cls2, Foo, false); | 442 checkType(cls2, Foo, false, true); |
| 414 checkType(bar2, functionType(B, [B, String]), false); | 443 checkType(bar2, functionType(B, [B, String]), false, true); |
| 415 checkType(cls2, functionType(B, [B, String]), false); | 444 checkType(cls2, functionType(B, [B, String]), false, true); |
| 416 checkType(bar3, Foo); | 445 checkType(bar3, Foo); |
| 417 checkType(cls3, Foo); | 446 checkType(cls3, Foo); |
| 418 checkType(bar3, functionType(B, [B, String])); | 447 checkType(bar3, functionType(B, [B, String])); |
| 419 checkType(cls3, functionType(B, [B, String])); | 448 checkType(cls3, functionType(B, [B, String])); |
| 420 checkType(bar4, Foo, true); | 449 checkType(bar4, Foo, true); |
| 421 checkType(cls4, Foo, true); | 450 checkType(cls4, Foo, true); |
| 422 checkType(bar4, functionType(B, [B, String]), true); | 451 checkType(bar4, functionType(B, [B, String]), true); |
| 423 checkType(cls4, functionType(B, [B, String]), true); | 452 checkType(cls4, functionType(B, [B, String]), true); |
| 424 checkType(bar5, Foo); | 453 checkType(bar5, Foo); |
| 425 checkType(cls5, Foo); | 454 checkType(cls5, Foo); |
| 426 checkType(bar5, functionType(B, [B, String])); | 455 checkType(bar5, functionType(B, [B, String])); |
| 427 checkType(cls5, functionType(B, [B, String])); | 456 checkType(cls5, functionType(B, [B, String])); |
| 428 checkType(bar6, Foo, false); | 457 checkType(bar6, Foo, false, true); |
| 429 checkType(cls6, Foo, false); | 458 checkType(cls6, Foo, false, true); |
| 430 checkType(bar6, functionType(B, [B, String]), false); | 459 checkType(bar6, functionType(B, [B, String]), false, true); |
| 431 checkType(cls6, functionType(B, [B, String]), false); | 460 checkType(cls6, functionType(B, [B, String]), false, true); |
| 432 checkType(bar7, Foo); | 461 checkType(bar7, Foo); |
| 433 checkType(cls7, Foo); | 462 checkType(cls7, Foo); |
| 434 checkType(bar7, functionType(B, [B, String])); | 463 checkType(bar7, functionType(B, [B, String])); |
| 435 checkType(cls7, functionType(B, [B, String])); | 464 checkType(cls7, functionType(B, [B, String])); |
| 436 checkType(bar7, runtimeType(bar6)); | 465 checkType(bar7, runtimeType(bar6)); |
| 437 checkType(cls7, runtimeType(bar6)); | 466 checkType(cls7, runtimeType(bar6)); |
| 438 checkType(bar8, Foo); | 467 checkType(bar8, Foo); |
| 439 checkType(cls8, Foo); | 468 checkType(cls8, Foo); |
| 440 checkType(bar8, functionType(B, [B, String])); | 469 checkType(bar8, functionType(B, [B, String])); |
| 441 checkType(cls8, functionType(B, [B, String])); | 470 checkType(cls8, functionType(B, [B, String])); |
| 442 checkType(bar8, runtimeType(bar6), false); | 471 checkType(bar8, runtimeType(bar6), false, true); |
| 443 checkType(cls8, runtimeType(bar6), false); | 472 checkType(cls8, runtimeType(bar6), false, true); |
| 444 checkType(bar7, runtimeType(bar8), false); | 473 checkType(bar7, runtimeType(bar8), false, true); |
| 445 checkType(cls7, runtimeType(bar8), false); | 474 checkType(cls7, runtimeType(bar8), false, true); |
| 446 checkType(bar8, runtimeType(bar7), false); | 475 checkType(bar8, runtimeType(bar7), false, true); |
| 447 checkType(cls8, runtimeType(bar7), false); | 476 checkType(cls8, runtimeType(bar7), false, true); |
| 448 | 477 |
| 449 // Parameterized typedefs | 478 // Parameterized typedefs |
| 450 expect(isGroundType(FuncG), true); | 479 expect(isGroundType(FuncG), true); |
| 451 expect(isGroundType(FuncG$(B, String)), false); | 480 expect(isGroundType(FuncG$(B, String)), false); |
| 452 checkType(bar1, FuncG$(B, String), false); | 481 checkType(bar1, FuncG$(B, String), false, true); |
| 453 checkType(cls1, FuncG$(B, String), false); | 482 checkType(cls1, FuncG$(B, String), false, true); |
| 454 checkType(bar3, FuncG$(B, String)); | 483 checkType(bar3, FuncG$(B, String)); |
| 455 checkType(cls3, FuncG$(B, String)); | 484 checkType(cls3, FuncG$(B, String)); |
| 456 }); | 485 }); |
| 457 | 486 |
| 458 test('dcall', () => { | 487 test('dcall', () => { |
| 459 function dd2d(x, y) {return x}; | 488 function dd2d(x, y) {return x}; |
| 460 dart.fn(dd2d); | 489 dart.fn(dd2d); |
| 461 function ii2i(x, y) {return x}; | 490 function ii2i(x, y) {return x}; |
| 462 dart.fn(ii2i, core.int, [core.int, core.int]); | 491 dart.fn(ii2i, core.int, [core.int, core.int]); |
| 463 function ii_2i(x, y) {return x}; | 492 function ii_2i(x, y) {return x}; |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 578 | 607 |
| 579 // Optional types | 608 // Optional types |
| 580 function ii_2i(x, y) {return x}; | 609 function ii_2i(x, y) {return x}; |
| 581 dart.fn(ii_2i, core.int, [core.int], [core.int]); | 610 dart.fn(ii_2i, core.int, [core.int], [core.int]); |
| 582 checkType(ii_2i, dart.functionType(core.int, [core.int], | 611 checkType(ii_2i, dart.functionType(core.int, [core.int], |
| 583 [core.int])); | 612 [core.int])); |
| 584 checkType(ii_2i, dart.functionType(core.int, [core.int, | 613 checkType(ii_2i, dart.functionType(core.int, [core.int, |
| 585 core.int])); | 614 core.int])); |
| 586 checkType(ii_2i, dart.functionType(core.int, [], [core.int, | 615 checkType(ii_2i, dart.functionType(core.int, [], [core.int, |
| 587 core.int]), | 616 core.int]), |
| 588 false); | 617 false, true); |
| 589 checkType(ii_2i, dart.functionType(core.int, [core.int], | 618 checkType(ii_2i, dart.functionType(core.int, [core.int], |
| 590 {extra: core.int}), false); | 619 {extra: core.int}), false, true); |
| 591 | 620 |
| 592 // Named types | 621 // Named types |
| 593 function i_i2i(x, opts) {return x}; | 622 function i_i2i(x, opts) {return x}; |
| 594 dart.fn(i_i2i, core.int, [core.int], {extra: core.int}); | 623 dart.fn(i_i2i, core.int, [core.int], {extra: core.int}); |
| 595 checkType(i_i2i, dart.functionType(core.int, [core.int], | 624 checkType(i_i2i, dart.functionType(core.int, [core.int], |
| 596 {extra: core.int})); | 625 {extra: core.int})); |
| 597 checkType(i_i2i, dart.functionType(core.int, | 626 checkType(i_i2i, dart.functionType(core.int, |
| 598 [core.int, core.int]), false); | 627 [core.int, core.int]), false, true); |
| 599 checkType(i_i2i, dart.functionType(core.int, [core.int], {})); | 628 checkType(i_i2i, dart.functionType(core.int, [core.int], {})); |
| 600 checkType(i_i2i, | 629 checkType(i_i2i, |
| 601 dart.functionType(core.int, [], {extra: core.int, | 630 dart.functionType(core.int, [], {extra: core.int, |
| 602 also: core.int}), false); | 631 also: core.int}), false, true); |
| 603 checkType(i_i2i, | 632 checkType(i_i2i, |
| 604 dart.functionType(core.int, [core.int], [core.int]), false); | 633 dart.functionType(core.int, [core.int], [core.int]), false, true); |
| 605 }); | 634 }); |
| 606 | 635 |
| 607 test('Method tearoffs', () => { | 636 test('Method tearoffs', () => { |
| 608 let c = collection; | 637 let c = collection; |
| 609 // Tear off of an inherited method | 638 // Tear off of an inherited method |
| 610 let map = new (Map$(core.int, core.String))(); | 639 let map = new (Map$(core.int, core.String))(); |
| 611 checkType(dart.bind(map, 'toString'), | 640 checkType(dart.bind(map, 'toString'), |
| 612 dart.functionType(String, [])); | 641 dart.functionType(String, [])); |
| 613 checkType(dart.bind(map, 'toString'), | 642 checkType(dart.bind(map, 'toString'), |
| 614 dart.functionType(int, []), false); | 643 dart.functionType(int, []), false, true); |
| 615 | 644 |
| 616 // Tear off of a method directly on the object | 645 // Tear off of a method directly on the object |
| 617 let smap = new (c.SplayTreeMap$(core.int, core.String))(); | 646 let smap = new (c.SplayTreeMap$(core.int, core.String))(); |
| 618 checkType(dart.bind(smap, 'forEach'), | 647 checkType(dart.bind(smap, 'forEach'), |
| 619 dart.functionType(dart.void, | 648 dart.functionType(dart.void, |
| 620 [dart.functionType(dart.void, [core.int, core.String])])); | 649 [dart.functionType(dart.void, [core.int, core.String])])); |
| 621 checkType(dart.bind(smap, 'forEach'), | 650 checkType(dart.bind(smap, 'forEach'), |
| 622 dart.functionType(dart.void, | 651 dart.functionType(dart.void, |
| 623 [dart.functionType(dart.void, | 652 [dart.functionType(dart.void, |
| 624 [core.String, core.String])]), false); | 653 [core.String, core.String])]), false, true); |
| 625 | 654 |
| 626 // Tear off of a mixed in method | 655 // Tear off of a mixed in method |
| 627 let mapB = new (c.MapBase$(core.int, core.int))(); | 656 let mapB = new (c.MapBase$(core.int, core.int))(); |
| 628 checkType(dart.bind(mapB, 'forEach'), | 657 checkType(dart.bind(mapB, 'forEach'), |
| 629 dart.functionType(dart.void, [ | 658 dart.functionType(dart.void, [ |
| 630 dart.functionType(dart.void, [core.int, core.int])])); | 659 dart.functionType(dart.void, [core.int, core.int])])); |
| 631 checkType(dart.bind(mapB, 'forEach'), | 660 checkType(dart.bind(mapB, 'forEach'), |
| 632 dart.functionType(dart.void, [ | 661 dart.functionType(dart.void, [ |
| 633 dart.functionType(dart.void, [core.int, core.String])]), | 662 dart.functionType(dart.void, [core.int, core.String])]), |
| 634 false); | 663 false, true); |
| 635 | 664 |
| 636 // Tear off of a method with a symbol name | 665 // Tear off of a method with a symbol name |
| 637 let listB = new (c.ListBase$(core.int))(); | 666 let listB = new (c.ListBase$(core.int))(); |
| 638 checkType(dart.bind(listB, dartx.add), | 667 checkType(dart.bind(listB, dartx.add), |
| 639 dart.functionType(dart.void, [core.int])); | 668 dart.functionType(dart.void, [core.int])); |
| 640 checkType(dart.bind(listB, dartx.add), | 669 checkType(dart.bind(listB, dartx.add), |
| 641 dart.functionType(dart.void, [core.String]), false); | 670 dart.functionType(dart.void, [core.String]), false, true); |
| 642 | 671 |
| 643 // Tear off of a static method | 672 // Tear off of a static method |
| 644 checkType(c.ListBase.listToString, | 673 checkType(c.ListBase.listToString, |
| 645 dart.functionType(core.String, [core.List])); | 674 dart.functionType(core.String, [core.List])); |
| 646 checkType(c.ListBase.listToString, | 675 checkType(c.ListBase.listToString, |
| 647 dart.functionType(core.String, [core.String]), false); | 676 dart.functionType(core.String, [core.String]), false, true); |
| 648 | 677 |
| 649 // Tear off a mixin method | 678 // Tear off a mixin method |
| 650 class Base { | 679 class Base { |
| 651 m(x) {return x;} | 680 m(x) {return x;} |
| 652 }; | 681 }; |
| 653 dart.setSignature(Base, { | 682 dart.setSignature(Base, { |
| 654 methods: () => ({ | 683 methods: () => ({ |
| 655 m: [core.int, [core.int]], | 684 m: [core.int, [core.int]], |
| 656 }) | 685 }) |
| 657 }); | 686 }); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 674 }) | 703 }) |
| 675 }); | 704 }); |
| 676 | 705 |
| 677 class O extends dart.mixin(Base, M1, M2) { | 706 class O extends dart.mixin(Base, M1, M2) { |
| 678 O() {}; | 707 O() {}; |
| 679 }; | 708 }; |
| 680 dart.setSignature(O, {}); | 709 dart.setSignature(O, {}); |
| 681 var obj = new O(); | 710 var obj = new O(); |
| 682 var m = dart.bind(obj, 'm'); | 711 var m = dart.bind(obj, 'm'); |
| 683 checkType(m, dart.functionType(core.Object, [core.int])); | 712 checkType(m, dart.functionType(core.Object, [core.int])); |
| 684 checkType(m, dart.functionType(core.int, [core.int]), false); | 713 checkType(m, dart.functionType(core.int, [core.int]), false, true); |
| 685 | 714 |
| 686 // Test inherited signatures | 715 // Test inherited signatures |
| 687 class P extends O { | 716 class P extends O { |
| 688 P() {}; | 717 P() {}; |
| 689 m(x) {return x;}; | 718 m(x) {return x;}; |
| 690 }; | 719 }; |
| 691 dart.setSignature(P, {}); | 720 dart.setSignature(P, {}); |
| 692 var obj = new P(); | 721 var obj = new P(); |
| 693 var m = dart.bind(obj, 'm'); | 722 var m = dart.bind(obj, 'm'); |
| 694 checkType(m, dart.functionType(core.Object, [core.int])); | 723 checkType(m, dart.functionType(core.Object, [core.int])); |
| 695 checkType(m, dart.functionType(core.int, [core.int]), false); | 724 checkType(m, dart.functionType(core.int, [core.int]), false, true); |
| 696 }); | 725 }); |
| 697 | 726 |
| 698 test('Object members', () => { | 727 test('Object members', () => { |
| 699 let nullHash = dart.hashCode(null); | 728 let nullHash = dart.hashCode(null); |
| 700 assert.equal(nullHash, 0); | 729 assert.equal(nullHash, 0); |
| 701 let nullString = dart.toString(null); | 730 let nullString = dart.toString(null); |
| 702 assert.equal(nullString, 'null'); | 731 assert.equal(nullString, 'null'); |
| 703 let nullType = dart.runtimeType(null); | 732 let nullType = dart.runtimeType(null); |
| 704 assert.equal(nullType, core.Null); | 733 assert.equal(nullType, core.Null); |
| 705 | 734 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 737 | 766 |
| 738 suite('primitives', function() { | 767 suite('primitives', function() { |
| 739 'use strict'; | 768 'use strict'; |
| 740 | 769 |
| 741 test('fixed length list', () => { | 770 test('fixed length list', () => { |
| 742 let list = new core.List(10); | 771 let list = new core.List(10); |
| 743 list[0] = 42; | 772 list[0] = 42; |
| 744 assert.throws(() => list.add(42)); | 773 assert.throws(() => list.add(42)); |
| 745 }); | 774 }); |
| 746 }); | 775 }); |
| OLD | NEW |