Skip to content

Commit 7851a29

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

File tree

5 files changed

+349
-1
lines changed

5 files changed

+349
-1
lines changed

LanguageFeatures/Generic-functions-as-type-args/typedef3_A01_t01.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class C<T> {
4747
C(expected) { Expect.equals(expected, T); }
4848
}
4949

50-
typedef C1<X extends T Function<T>(T)> = C<X>;
50+
typedef C1<X extends int> = C<X>;
5151

5252
typedef C2<X extends void Function<T>()> = C<X>;
5353

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
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+
* dynamically.
35+
36+
*/
37+
// SharedOptions=--enable-experiment=generic-metadata
38+
39+
import "../../Utils/expect.dart";
40+
41+
typedef exp1 = T Function<T>(T);
42+
typedef exp2 = void Function<T>();
43+
typedef exp3 = T Function<T>();
44+
typedef exp4 = void Function<T>(T);
45+
46+
class C<T> {
47+
C(expected) { Expect.equals(expected, T); }
48+
}
49+
50+
typedef C1<X extends T Function<T>(T)> = C<X>;
51+
52+
typedef C2<X extends void Function<T>()> = C<X>;
53+
54+
typedef C3<X extends T Function<T>()> = C<X>;
55+
56+
typedef C4<X extends void Function<T>(T)> = C<X>;
57+
58+
main() {
59+
C1 c1 = C1<exp1>(exp1);
60+
C2 c3 = C2<exp2>(exp2);
61+
C3 c5 = C3<exp3>(exp3);
62+
C4 c7 = C4<exp4>(exp4);
63+
}
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
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 exp1> = 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+
// [analyzer] unspecified
70+
// [cfe] unspecified
71+
}
72+
73+
test2() {
74+
C1<int>();
75+
// ^
76+
// [analyzer] unspecified
77+
// [cfe] unspecified
78+
79+
C1<exp1>();
80+
81+
C1<exp2>();
82+
// ^
83+
// [analyzer] unspecified
84+
// [cfe] unspecified
85+
86+
C1<exp3>();
87+
// ^
88+
// [analyzer] unspecified
89+
// [cfe] unspecified
90+
91+
C1<exp4>();
92+
// ^
93+
// [analyzer] unspecified
94+
// [cfe] unspecified
95+
}
96+
97+
main() {}
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 exp2> = 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+
// [analyzer] unspecified
58+
// [cfe] unspecified
59+
60+
C1 c2 = C1<exp2>();
61+
62+
C1 c3 = C1<exp3>();
63+
64+
C1 c4 = C1<exp4>();
65+
// ^
66+
// [analyzer] unspecified
67+
// [cfe] unspecified
68+
}
69+
70+
test2() {
71+
C1<int>();
72+
// ^
73+
// [analyzer] unspecified
74+
// [cfe] unspecified
75+
76+
C1<exp1>();
77+
// ^
78+
// [analyzer] unspecified
79+
// [cfe] unspecified
80+
81+
C1<exp2>();
82+
83+
C1<exp3>();
84+
85+
C1<exp4>();
86+
// ^
87+
// [analyzer] unspecified
88+
// [cfe] unspecified
89+
}
90+
91+
main() {}
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
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 exp3> = 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+
// [analyzer] unspecified
58+
// [cfe] unspecified
59+
60+
C1 c2 = C1<exp2>();
61+
// ^
62+
// [analyzer] unspecified
63+
// [cfe] unspecified
64+
65+
C1 c3 = C1<exp3>();
66+
67+
C1 c4 = C1<exp4>();
68+
// ^
69+
// [analyzer] unspecified
70+
// [cfe] unspecified
71+
}
72+
73+
test2() {
74+
C1<int>();
75+
// ^
76+
// [analyzer] unspecified
77+
// [cfe] unspecified
78+
79+
C1<exp1>();
80+
// ^
81+
// [analyzer] unspecified
82+
// [cfe] unspecified
83+
84+
C1<exp2>();
85+
// ^
86+
// [analyzer] unspecified
87+
// [cfe] unspecified
88+
89+
C1<exp3>();
90+
91+
C1<exp4>();
92+
// ^
93+
// [analyzer] unspecified
94+
// [cfe] unspecified
95+
}
96+
97+
main() {}

0 commit comments

Comments
 (0)