Skip to content

Commit c1328ef

Browse files
committed
Fixes #996: more tests added.
1 parent 9726793 commit c1328ef

File tree

1 file changed

+91
-0
lines changed

1 file changed

+91
-0
lines changed
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
/*
2+
* Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file
3+
* for details. All rights reserved. Use of this source code is governed by a
4+
* BSD-style license that can be found in the LICENSE file.
5+
*/
6+
/**
7+
* @assertion Allow generic function types as type arguments and bounds
8+
*
9+
* The language disallows generic function types as type arguments and bounds.
10+
*
11+
* late List<T Function<T>(T)> idFunctions; // INVALID.
12+
* var callback = [foo<T>(T value) => value]; // Inferred as above, then invalid.
13+
* late S Function<S extends T Function<T>(T)>(S) f; // INVALID.
14+
*
15+
* We remove that restriction, so a type argument and a bound can be a generic
16+
* function type.
17+
*
18+
* This requires no new syntax, and in some cases only the removal of a single
19+
* check. There might be some platforms where the implementation currently
20+
* assumes that generic function types cannot occur as the value of type
21+
* variables (an proof-of-concept attempt hit an assert in the VM). Such
22+
* assumptions will need to be flushed out with tests and fixed.
23+
*
24+
* Because we already infer List<T Function<T>(T)> in the code above, this
25+
* change will not affect type inference, it will just make the inferred type
26+
* not be an error afterwards.
27+
*
28+
* We do not expect the removal of this restriction to affect the feasibility of
29+
* type inference. After all, it's already possible to have a generic function
30+
* type occurring covariantly in a type argument, like List<T Function<T>(T)
31+
* Function()>.
32+
* @description Checks that generic function can be a non-function typedef type
33+
* argument and bound: test extends clause in the typedef declaration
34+
* statically.
35+
* @Issue 45065
36+
37+
*/
38+
// SharedOptions=--enable-experiment=generic-metadata
39+
40+
typedef exp1 = T Function<T>(T);
41+
typedef exp2 = void Function<T>();
42+
typedef exp3 = T Function<T>();
43+
typedef exp4 = void Function<T>(T);
44+
45+
class C<T> {}
46+
47+
typedef C1<X extends exp4> = C<X>;
48+
49+
test1() {
50+
C1 c = C1<int>();
51+
// ^
52+
// [analyzer] unspecified
53+
// [cfe] unspecified
54+
55+
C1 c1 = C1<exp1>();
56+
57+
C1 c2 = C1<exp2>();
58+
// ^
59+
// [analyzer] unspecified
60+
// [cfe] unspecified
61+
62+
C1 c3 = C1<exp3>();
63+
// ^
64+
// [analyzer] unspecified
65+
// [cfe] unspecified
66+
67+
C1 c4 = C1<exp4>();
68+
}
69+
70+
test2() {
71+
C1<int>();
72+
// ^
73+
// [analyzer] unspecified
74+
// [cfe] unspecified
75+
76+
C1<exp1>();
77+
78+
C1<exp2>();
79+
// ^
80+
// [analyzer] unspecified
81+
// [cfe] unspecified
82+
83+
C1<exp3>();
84+
// ^
85+
// [analyzer] unspecified
86+
// [cfe] unspecified
87+
88+
C1<exp4>();
89+
}
90+
91+
main() {}

0 commit comments

Comments
 (0)