OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file |
| 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. |
| 4 // VMOptions=--reify-generic-functions --optimization-counter-threshold=10 --no-
use-osr --no-background-compilation |
| 5 |
| 6 import "package:expect/expect.dart"; |
| 7 |
| 8 // Test that noSuchMethod dispatching and auto-closurization work correctly |
| 9 // with generic functions. |
| 10 |
| 11 class A { |
| 12 noSuchMethod(m) { |
| 13 return 123; |
| 14 } |
| 15 |
| 16 bar<U, V>(x) => x + 1; |
| 17 } |
| 18 |
| 19 class B extends A {} |
| 20 |
| 21 class C { |
| 22 C(this.typeArgs, this.posArgs, this.namedArgs); |
| 23 List typeArgs; |
| 24 List posArgs; |
| 25 Map namedArgs; |
| 26 noSuchMethod(m) { |
| 27 Expect.equals(typeArgs.length, m.typeArguments.length); |
| 28 for (var i = 0; i < typeArgs.length; ++i) { |
| 29 Expect.equals(typeArgs[i], m.typeArguments[i]); |
| 30 } |
| 31 Expect.equals(posArgs.length, m.positionalArguments.length); |
| 32 for (var i = 0; i < posArgs.length; ++i) { |
| 33 Expect.equals(posArgs[i], m.positionalArguments[i]); |
| 34 } |
| 35 Expect.equals(namedArgs.length, m.namedArguments.length); |
| 36 for (var k in namedArgs.keys) { |
| 37 Expect.equals(namedArgs[k], m.namedArguments[new Symbol(k)]); |
| 38 } |
| 39 return 123; |
| 40 } |
| 41 } |
| 42 |
| 43 main() { |
| 44 var a = new A(); |
| 45 for (var i = 0; i < 20; ++i) Expect.equals(123, a.foo<int, A>()); |
| 46 Expect.throws(() => (a.foo)()); |
| 47 Expect.throws(() => (a.foo)<int, A>()); |
| 48 Expect.equals("123", (a.foo).toString()); |
| 49 |
| 50 var b = new B(); |
| 51 for (var i = 0; i < 20; ++i) { |
| 52 Expect.equals(2, b.bar<int, A>(1)); |
| 53 Expect.equals(2, b.bar(1)); |
| 54 Expect.equals(123, b.bar<int, A>()); |
| 55 Expect.equals(3, b.bar<int, A>(2)); |
| 56 Expect.equals(123, b.bar<int>(1)); |
| 57 } |
| 58 |
| 59 for (var i = 0; i < 20; ++i) { |
| 60 Expect.equals(123, b.bar<int, A>(1, 2, 3)); |
| 61 Expect.equals(123, b.bar<int, A>(1, 2, foo: 3)); |
| 62 Expect.equals(123, b.bar<int>(1)); |
| 63 } |
| 64 |
| 65 // Test type, named, and positional arguments. |
| 66 var c = new C([int, A], [100], {"n1": 101, "n2": 102}); |
| 67 for (var i = 0; i < 20; ++i) { |
| 68 Expect.equals(123, c.bar<int, A>(100, n1: 101, n2: 102)); |
| 69 Expect.equals(123, c.bar<int, A>(100, n2: 102, n1: 101)); |
| 70 } |
| 71 } |
OLD | NEW |