|
| 1 | +// Copyright (c) 2020, 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 | + |
| 5 | +// This test is the same as 41449a_test.dart without forcing `-O0`. |
| 6 | +// |
| 7 | +// Regression test for passing type parameters through call-through stub. |
| 8 | +// |
| 9 | +// We use an abstract class with two implementations to avoid the optimizer |
| 10 | +// 'inlining' the call-through stub, so we are testing that the stub itself |
| 11 | +// passes through the type parameters. |
| 12 | + |
| 13 | +import 'package:expect/expect.dart'; |
| 14 | + |
| 15 | +abstract class AAA { |
| 16 | + dynamic get foo; |
| 17 | +} |
| 18 | + |
| 19 | +class B1 implements AAA { |
| 20 | + final dynamic foo; |
| 21 | + B1(this.foo); |
| 22 | +} |
| 23 | + |
| 24 | +class B2 implements AAA { |
| 25 | + final dynamic _arr; |
| 26 | + B2(foo) : _arr = [foo]; |
| 27 | + dynamic get foo => _arr.first; |
| 28 | +} |
| 29 | + |
| 30 | +class B3 implements AAA { |
| 31 | + final dynamic __foo; |
| 32 | + B3(this.__foo); |
| 33 | + dynamic get _foo => __foo; |
| 34 | + dynamic get foo => _foo; |
| 35 | +} |
| 36 | + |
| 37 | +@pragma('dart2js:noInline') |
| 38 | +test1<T>(AAA a, String expected) { |
| 39 | + // call-through getter 'foo' with one type argument. |
| 40 | + Expect.equals(expected, a.foo<T>()); |
| 41 | +} |
| 42 | + |
| 43 | +@pragma('dart2js:noInline') |
| 44 | +test2<U, V>(AAA a, String expected) { |
| 45 | + // call-through getter 'foo' with two type arguments. |
| 46 | + Expect.equals(expected, a.foo<U, V>()); |
| 47 | +} |
| 48 | + |
| 49 | +main() { |
| 50 | + test1<int>(B1(<P>() => '$P'), 'int'); |
| 51 | + test1<num>(B2(<Q>() => '$Q'), 'num'); |
| 52 | + test1<double>(B3(<R>() => '$R'), 'double'); |
| 53 | + |
| 54 | + test2<int, num>(B1(<A, B>() => '$A $B'), 'int num'); |
| 55 | + test2<num, int>(B2(<X, Y>() => '$X $Y'), 'num int'); |
| 56 | + test2<double, String>(B3(<C, D>() => '$C $D'), 'double String'); |
| 57 | +} |
0 commit comments