Skip to content

Commit f0052ef

Browse files
stereotype441commit-bot@chromium.org
authored andcommitted
Add cycle detection test cases for nonfunction type aliases.
Change-Id: I4375c3374ba5d51b4431dbe22a0e8c867a4eb03d Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/167720 Reviewed-by: Erik Ernst <eernst@google.com> Commit-Queue: Paul Berry <paulberry@google.com>
1 parent 7c01226 commit f0052ef

File tree

3 files changed

+201
-0
lines changed

3 files changed

+201
-0
lines changed
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
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+
// SharedOptions=--enable-experiment=nonfunction-type-aliases
6+
7+
// This test verifies that cyclic type alias definitions cause a compile-time
8+
// error, when the cycle occurs via the bound.
9+
10+
typedef T1<X extends T1<Never>> = List<X>;
11+
// ^
12+
// [analyzer] unspecified
13+
// [cfe] unspecified
14+
15+
// Note: when the cycle involves two typedefs, the CFE only reports an error for
16+
// one of them; that's ok.
17+
typedef T2<X extends T3> = List<X>;
18+
// ^
19+
// [analyzer] unspecified
20+
21+
typedef T3 = T2<Never>;
22+
// ^
23+
// [analyzer] unspecified
24+
// [cfe] unspecified
25+
26+
typedef T4<X extends List<T4<Never>>> = List<X>;
27+
// ^
28+
// [analyzer] unspecified
29+
// [cfe] unspecified
30+
31+
typedef T5<X extends T5<Never> Function()> = List<X>;
32+
// ^
33+
// [analyzer] unspecified
34+
// [cfe] unspecified
35+
36+
typedef T6<X extends void Function(T6<Never>)> = List<X>;
37+
// ^
38+
// [analyzer] unspecified
39+
// [cfe] unspecified
40+
41+
// Note: not an error because T7 is the name of the parameter.
42+
typedef T7<X extends void Function(int T7)> = List<X>;
43+
44+
typedef T8<X extends void Function([T8<Never>])> = List<X>;
45+
// ^
46+
// [analyzer] unspecified
47+
// [cfe] unspecified
48+
49+
// Note: not an error because T9 is the name of the parameter.
50+
typedef T9<X extends void Function([int T9])> = List<X>;
51+
52+
typedef T10<X extends void Function({T10<Never> x})> = List<X>;
53+
// ^
54+
// [analyzer] unspecified
55+
// [cfe] unspecified
56+
57+
// Note: not an error because T11 is the name of the parameter.
58+
typedef T11<X extends void Function({int T11})> = List<X>;
59+
60+
// Note: we have to use `void Function<...>() Function()` because a generic
61+
// function can't directly be used as a bound.
62+
typedef T12<X extends void Function<Y extends T12<Never>>() Function()> = List<X>;
63+
// ^
64+
// [analyzer] unspecified
65+
// [cfe] unspecified
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
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+
// SharedOptions=--enable-experiment=nonfunction-type-aliases
6+
7+
// This test verifies that cyclic type alias definitions cause a compile-time
8+
// error, when the cycle occurs via the bound, even if the bound variable is not
9+
// used in the expansion.
10+
11+
typedef T1<X extends T1<Never>> = int;
12+
// ^
13+
// [analyzer] unspecified
14+
// [cfe] unspecified
15+
16+
// Note: when the cycle involves two typedefs, the CFE only reports an error for
17+
// one of them; that's ok.
18+
typedef T2<X extends T3> = int;
19+
// ^
20+
// [analyzer] unspecified
21+
22+
typedef T3 = T2<Never>;
23+
// ^
24+
// [analyzer] unspecified
25+
// [cfe] unspecified
26+
27+
typedef T4<X extends List<T4<Never>>> = int;
28+
// ^
29+
// [analyzer] unspecified
30+
// [cfe] unspecified
31+
32+
typedef T5<X extends T5<Never> Function()> = int;
33+
// ^
34+
// [analyzer] unspecified
35+
// [cfe] unspecified
36+
37+
typedef T6<X extends void Function(T6<Never>)> = int;
38+
// ^
39+
// [analyzer] unspecified
40+
// [cfe] unspecified
41+
42+
// Note: not an error because T7 is the name of the parameter.
43+
typedef T7<X extends void Function(int T7)> = int;
44+
45+
typedef T8<X extends void Function([T8<Never>])> = int;
46+
// ^
47+
// [analyzer] unspecified
48+
// [cfe] unspecified
49+
50+
// Note: not an error because T9 is the name of the parameter.
51+
typedef T9<X extends void Function([int T9])> = int;
52+
53+
typedef T10<X extends void Function({T10<Never> x})> = int;
54+
// ^
55+
// [analyzer] unspecified
56+
// [cfe] unspecified
57+
58+
// Note: not an error because T11 is the name of the parameter.
59+
typedef T11<X extends void Function({int T11})> = int;
60+
61+
// Note: we have to use `void Function<...>() Function()` because a generic
62+
// function can't directly be used as a bound.
63+
typedef T12<X extends void Function<Y extends T12<Never>>() Function()> = int;
64+
// ^
65+
// [analyzer] unspecified
66+
// [cfe] unspecified
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
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+
// SharedOptions=--enable-experiment=nonfunction-type-aliases
6+
7+
// This test verifies that cyclic type alias definitions cause a compile-time
8+
// error, when the cycle occurs via the expansion of the type.
9+
10+
typedef T1 = List<T1>;
11+
// ^
12+
// [analyzer] unspecified
13+
// [cfe] unspecified
14+
15+
typedef T2 = List<T3>;
16+
// ^
17+
// [analyzer] unspecified
18+
// [cfe] unspecified
19+
20+
// Note: when the cycle involves two typedefs, the CFE only reports an error for
21+
// one of them; that's ok.
22+
typedef T3 = List<T2>;
23+
// ^
24+
// [analyzer] unspecified
25+
26+
typedef T4 = T4;
27+
// ^
28+
// [analyzer] unspecified
29+
// [cfe] unspecified
30+
31+
typedef T5 = T5?;
32+
// ^
33+
// [analyzer] unspecified
34+
// [cfe] unspecified
35+
36+
typedef T6 = List<T6 Function()>;
37+
// ^
38+
// [analyzer] unspecified
39+
// [cfe] unspecified
40+
41+
typedef T7 = List<void Function(T7)>;
42+
// ^
43+
// [analyzer] unspecified
44+
// [cfe] unspecified
45+
46+
// Note: not an error because T8 is the name of the parameter.
47+
typedef T8 = List<void Function(int T8)>;
48+
49+
typedef T9 = List<void Function([T9])>;
50+
// ^
51+
// [analyzer] unspecified
52+
// [cfe] unspecified
53+
54+
// Note: not an error because T10 is the name of the parameter.
55+
typedef T10 = List<void Function([int T10])>;
56+
57+
typedef T11 = List<void Function({T11 x})>;
58+
// ^
59+
// [analyzer] unspecified
60+
// [cfe] unspecified
61+
62+
// Note: not an error because T12 is the name of the parameter.
63+
typedef T12 = List<void Function({int T12})>;
64+
65+
// Note: we have to use `void Function<...>() Function()` because a generic
66+
// function can't directly be used as a type argument.
67+
typedef T13 = List<void Function<X extends T13>() Function()>;
68+
// ^
69+
// [analyzer] unspecified
70+
// [cfe] unspecified

0 commit comments

Comments
 (0)