Skip to content

Commit 95141a4

Browse files
authored
Fixes #2383. Add more constant evaluation tests (#2396)
Add more constant evaluation tests
1 parent 2ba55b4 commit 95141a4

5 files changed

+293
-0
lines changed
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
// Copyright (c) 2023, 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+
/// @assertion The extension type erasure of an extension type V is obtained by
6+
/// recursively replacing every subterm of V which is an extension type by the
7+
/// corresponding representation type.
8+
///
9+
/// Let X1 extends B1, .. Xs extends Bs be a declaration of the type parameters
10+
/// of a generic entity (it could be a generic class, extension type, mixin,
11+
/// typedef, or function). Let BBj be the extension type erasure of
12+
/// Bj, for j in 1 .. s. It is a compile-time error if
13+
/// X1 extends BB1, .. Xs extends BBs has any compile-time errors.
14+
///
15+
/// @description Check that the erasure of an extension type `V` is obtained by
16+
/// recursively replacing every subterm of `V` which is an extension type by the
17+
/// corresponding representation type
18+
/// @author [email protected]
19+
20+
// SharedOptions=--enable-experiment=inline-class
21+
22+
extension type const Check._(Object? _) {
23+
const Check(Object? object, {required Object? expected}) : _ = object,
24+
assert(identical(expected, object));
25+
}
26+
27+
extension type const ExtInt1(int _) implements int {}
28+
extension type const ExtInt2(int _) {}
29+
extension type const ExtString1(String _) implements String {}
30+
extension type const ExtString2(String _) {}
31+
extension type const ExtList1<T>(List<T> _) implements List<T> {}
32+
extension type const ExtList2<T>(List<T> _) {}
33+
extension type const ExtMap1<K, V>(Map<K, V> _) implements Map<K, V> {}
34+
extension type const ExtMap2<K, V>(Map<K, V> _) {}
35+
36+
void main() {
37+
// Base case.
38+
const Check(ExtInt1, expected: int);
39+
const Check(ExtInt2, expected: int);
40+
// Generics.
41+
const Check(ExtList1<int>, expected: List<int>);
42+
const Check(ExtList2<int>, expected: List<int>);
43+
const Check(List<ExtInt1>, expected: List<int>);
44+
const Check(List<ExtInt2>, expected: List<int>);
45+
const Check(ExtList1<ExtInt1>, expected: List<int>);
46+
const Check(ExtList1<ExtInt2>, expected: List<int>);
47+
const Check(ExtList2<ExtInt1>, expected: List<int>);
48+
const Check(ExtList2<ExtInt2>, expected: List<int>);
49+
// Multiple arguments.
50+
const Check(Map<ExtInt1, String>, expected: Map<int, String>);
51+
const Check(Map<ExtInt2, String>, expected: Map<int, String>);
52+
const Check(Map<ExtInt1, ExtString1>, expected: Map<int, String>);
53+
const Check(Map<ExtInt1, ExtString2>, expected: Map<int, String>);
54+
const Check(Map<ExtInt2, ExtString1>, expected: Map<int, String>);
55+
const Check(Map<ExtInt2, ExtString2>, expected: Map<int, String>);
56+
const Check(ExtMap1<int, String>, expected: Map<int, String>);
57+
const Check(ExtMap2<int, String>, expected: Map<int, String>);
58+
const Check(ExtMap1<int, ExtString1>, expected: Map<int, String>);
59+
const Check(ExtMap2<int, ExtString1>, expected: Map<int, String>);
60+
const Check(ExtMap1<int, ExtString2>, expected: Map<int, String>);
61+
const Check(ExtMap2<int, ExtString2>, expected: Map<int, String>);
62+
const Check(ExtMap1<ExtInt1, String>, expected: Map<int, String>);
63+
const Check(ExtMap1<ExtInt2, String>, expected: Map<int, String>);
64+
const Check(ExtMap2<ExtInt1, String>, expected: Map<int, String>);
65+
const Check(ExtMap2<ExtInt2, String>, expected: Map<int, String>);
66+
const Check(ExtMap1<ExtInt1, ExtString1>, expected: Map<int, String>);
67+
const Check(ExtMap1<ExtInt1, ExtString2>, expected: Map<int, String>);
68+
const Check(ExtMap1<ExtInt2, ExtString2>, expected: Map<int, String>);
69+
const Check(ExtMap1<ExtInt2, ExtString1>, expected: Map<int, String>);
70+
const Check(ExtMap2<ExtInt1, ExtString1>, expected: Map<int, String>);
71+
const Check(ExtMap2<ExtInt1, ExtString2>, expected: Map<int, String>);
72+
const Check(ExtMap2<ExtInt2, ExtString2>, expected: Map<int, String>);
73+
const Check(ExtMap2<ExtInt2, ExtString1>, expected: Map<int, String>);
74+
// Generic twice.
75+
const Check(List<List<ExtInt1>>, expected: List<List<int>>);
76+
const Check(List<List<ExtInt2>>, expected: List<List<int>>);
77+
const Check(List<ExtList1<int>>, expected: List<List<int>>);
78+
const Check(List<ExtList2<int>>, expected: List<List<int>>);
79+
const Check(ExtList1<List<int>>, expected: List<List<int>>);
80+
const Check(ExtList2<List<int>>, expected: List<List<int>>);
81+
const Check(ExtList1<List<ExtInt1>>, expected: List<List<int>>);
82+
const Check(ExtList1<List<ExtInt2>>, expected: List<List<int>>);
83+
const Check(ExtList2<List<ExtInt1>>, expected: List<List<int>>);
84+
const Check(ExtList2<List<ExtInt2>>, expected: List<List<int>>);
85+
const Check(List<ExtList1<ExtInt1>>, expected: List<List<int>>);
86+
const Check(List<ExtList1<ExtInt2>>, expected: List<List<int>>);
87+
const Check(List<ExtList2<ExtInt1>>, expected: List<List<int>>);
88+
const Check(List<ExtList2<ExtInt2>>, expected: List<List<int>>);
89+
const Check(ExtList1<ExtList1<int>>, expected: List<List<int>>);
90+
const Check(ExtList1<ExtList2<int>>, expected: List<List<int>>);
91+
const Check(ExtList2<ExtList1<int>>, expected: List<List<int>>);
92+
const Check(ExtList2<ExtList2<int>>, expected: List<List<int>>);
93+
const Check(ExtList1<ExtList1<ExtInt1>>, expected: List<List<int>>);
94+
const Check(ExtList1<ExtList1<ExtInt2>>, expected: List<List<int>>);
95+
const Check(ExtList1<ExtList2<ExtInt2>>, expected: List<List<int>>);
96+
const Check(ExtList2<ExtList1<ExtInt1>>, expected: List<List<int>>);
97+
const Check(ExtList2<ExtList1<ExtInt2>>, expected: List<List<int>>);
98+
const Check(ExtList2<ExtList2<ExtInt2>>, expected: List<List<int>>);
99+
const Check(ExtList2<ExtList2<ExtInt1>>, expected: List<List<int>>);
100+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
// Copyright (c) 2023, 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+
/// @assertion The extension type erasure of an extension type V is obtained by
6+
/// recursively replacing every subterm of V which is an extension type by the
7+
/// corresponding representation type.
8+
///
9+
/// Let X1 extends B1, .. Xs extends Bs be a declaration of the type parameters
10+
/// of a generic entity (it could be a generic class, extension type, mixin,
11+
/// typedef, or function). Let BBj be the extension type erasure of
12+
/// Bj, for j in 1 .. s. It is a compile-time error if
13+
/// X1 extends BB1, .. Xs extends BBs has any compile-time errors.
14+
///
15+
/// @description Check that the erasure of an extension type `V` is obtained by
16+
/// recursively replacing every subterm of `V` which is an extension type by the
17+
/// corresponding representation type. Test function types
18+
/// @author [email protected]
19+
20+
// SharedOptions=--enable-experiment=inline-class
21+
22+
extension type const Check._(Object? _) {
23+
const Check(Object? object, {required Object? expected}) : _ = object,
24+
assert(identical(expected, object));
25+
}
26+
27+
typedef int IntFunction(int);
28+
typedef T GenFunction<T>();
29+
typedef List<T> ListFunction<T>();
30+
typedef Map<K, V> MapFunction<K, V>();
31+
32+
extension type const ExtFuncInt(IntFunction _) {}
33+
extension type const ExtFuncGen<T>(GenFunction<T> _) {}
34+
extension type const ExtFuncList<T>(ListFunction<T> _) {}
35+
extension type const ExtFuncMap<K, V>(MapFunction<K, V> _) {}
36+
37+
void main() {
38+
// Base case.
39+
const Check(ExtFuncInt, expected: IntFunction);
40+
// Generics.
41+
const Check(ExtFuncGen<int>, expected: GenFunction<int>);
42+
const Check(ExtFuncList<String>, expected: ListFunction<String>);
43+
const Check(ExtFuncMap<String, num>, expected: MapFunction<String, num>);
44+
// Multiple arguments.
45+
const Check(Map<ExtFuncInt, String>, expected: Map<IntFunction, String>);
46+
const Check(Map<ExtFuncInt, ExtFuncGen<String>>,
47+
expected: Map<IntFunction, GenFunction<String>>);
48+
const Check(ExtFuncMap<ExtFuncInt, ExtFuncGen<String>>,
49+
expected: MapFunction<IntFunction, GenFunction<String>>);
50+
// Generic twice.
51+
const Check(List<List<ExtFuncInt>>, expected: List<List<IntFunction>>);
52+
const Check(List<ExtFuncGen<int>>, expected: List<GenFunction<int>>);
53+
const Check(ExtFuncGen<List<int>>, expected: GenFunction<List<int>>);
54+
const Check(ExtFuncList<List<ExtFuncInt>>,
55+
expected: ListFunction<List<IntFunction>>);
56+
const Check(List<ExtFuncGen<ExtFuncInt>>,
57+
expected: List<GenFunction<IntFunction>>);
58+
const Check(ExtFuncList<ExtFuncList<int>>,
59+
expected: ListFunction<ListFunction<int>>);
60+
const Check(ExtFuncList<ExtFuncList<ExtFuncInt>>,
61+
expected: ListFunction<ListFunction<IntFunction>>);
62+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// Copyright (c) 2023, 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+
/// @assertion The extension type erasure of an extension type V is obtained by
6+
/// recursively replacing every subterm of V which is an extension type by the
7+
/// corresponding representation type.
8+
///
9+
/// Let X1 extends B1, .. Xs extends Bs be a declaration of the type parameters
10+
/// of a generic entity (it could be a generic class, extension type, mixin,
11+
/// typedef, or function). Let BBj be the extension type erasure of
12+
/// Bj, for j in 1 .. s. It is a compile-time error if
13+
/// X1 extends BB1, .. Xs extends BBs has any compile-time errors.
14+
///
15+
/// @description Check that the erasure of an extension type `V` is obtained by
16+
/// recursively replacing every subterm of `V` which is an extension type by the
17+
/// corresponding representation type. Test function types
18+
/// @author [email protected]
19+
20+
// SharedOptions=--enable-experiment=inline-class
21+
22+
extension type const Check._(Object? _) {
23+
const Check(Object? object, {required Object? expected}) : _ = object,
24+
assert(identical(expected, object));
25+
}
26+
27+
typedef GenFunction = X Function<X>(X x);
28+
typedef ListFunction = X Function<X>(List<X> v);
29+
typedef MapFunction = void Function<K, V>(Map<K, V> v);
30+
31+
extension type const ExtFuncGen(GenFunction _) {}
32+
extension type const ExtFuncList(ListFunction _) {}
33+
extension type const ExtFuncMap(MapFunction _) {}
34+
35+
void main() {
36+
const Check(ExtFuncGen, expected: GenFunction);
37+
const Check(ExtFuncList, expected: ListFunction);
38+
const Check(ExtFuncMap, expected: MapFunction);
39+
40+
const Check(List<ExtFuncGen>, expected: List<GenFunction>);
41+
const Check(Map<ExtFuncGen, String>, expected: Map<GenFunction, String>);
42+
const Check(Map<String, ExtFuncGen>, expected: Map<String, GenFunction>);
43+
const Check(Map<ExtFuncList, ExtFuncGen>,
44+
expected: Map<ListFunction, GenFunction>);
45+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// Copyright (c) 2023, 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+
/// @assertion The extension type erasure of an extension type V is obtained by
6+
/// recursively replacing every subterm of V which is an extension type by the
7+
/// corresponding representation type.
8+
///
9+
/// Let X1 extends B1, .. Xs extends Bs be a declaration of the type parameters
10+
/// of a generic entity (it could be a generic class, extension type, mixin,
11+
/// typedef, or function). Let BBj be the extension type erasure of
12+
/// Bj, for j in 1 .. s. It is a compile-time error if
13+
/// X1 extends BB1, .. Xs extends BBs has any compile-time errors.
14+
///
15+
/// @description Check that the erasure of an extension type `V` is obtained by
16+
/// recursively replacing every subterm of `V` which is an extension type by the
17+
/// corresponding representation type. Test function types
18+
/// @author [email protected]
19+
20+
// SharedOptions=--enable-experiment=inline-class
21+
22+
extension type const Check._(Object? _) {
23+
const Check(Object? object, {required Object? expected}) : _ = object,
24+
assert(identical(expected, object));
25+
}
26+
27+
extension type const ExtInt(int _) {}
28+
29+
typedef ExtIntFunc1 = ExtInt Function(ExtInt _, [ExtInt __]);
30+
typedef ExtIntFunc2 = ExtInt Function(ExtInt _, {ExtInt n});
31+
typedef ExtIntFunc3 = ExtInt Function(ExtInt _, {required ExtInt n});
32+
33+
typedef IntFunc1 = int Function(int _, [int __]);
34+
typedef IntFunc2 = int Function(int _, {int n});
35+
typedef IntFunc3 = int Function(int _, {required int n});
36+
37+
void main() {
38+
const Check(ExtIntFunc1, expected: IntFunc1);
39+
const Check(ExtIntFunc2, expected: IntFunc2);
40+
const Check(ExtIntFunc3, expected: IntFunc3);
41+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// Copyright (c) 2023, 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+
/// @assertion The extension type erasure of an extension type V is obtained by
6+
/// recursively replacing every subterm of V which is an extension type by the
7+
/// corresponding representation type.
8+
///
9+
/// Let X1 extends B1, .. Xs extends Bs be a declaration of the type parameters
10+
/// of a generic entity (it could be a generic class, extension type, mixin,
11+
/// typedef, or function). Let BBj be the extension type erasure of
12+
/// Bj, for j in 1 .. s. It is a compile-time error if
13+
/// X1 extends BB1, .. Xs extends BBs has any compile-time errors.
14+
///
15+
/// @description Check that the erasure of an extension type `V` is obtained by
16+
/// recursively replacing every subterm of `V` which is an extension type by the
17+
/// corresponding representation type. Test function types
18+
/// @author [email protected]
19+
20+
// SharedOptions=--enable-experiment=inline-class
21+
22+
extension type const Check._(Object? _) {
23+
const Check(Object? object, {required Object? expected}) : _ = object,
24+
assert(identical(expected, object));
25+
}
26+
27+
extension type const ExtInt(int _) {}
28+
extension type const ExtList<T>(List<T> _) {}
29+
30+
typedef ExtListFunc1 = ExtList<ExtInt> Function(ExtList<ExtInt> _,
31+
[ExtList<ExtInt> __]);
32+
typedef ExtListFunc2 = ExtList<ExtInt> Function(ExtList<ExtInt> _,
33+
{ExtList<ExtInt> n});
34+
typedef ExtListFunc3 = ExtList<ExtInt> Function(ExtList<ExtInt> _,
35+
{required ExtList<ExtInt> n});
36+
37+
typedef ErasedFunc1 = List<int> Function(List<int> _, [List<int> __]);
38+
typedef ErasedFunc2 = List<int> Function(List<int> _, {List<int> n});
39+
typedef ErasedFunc3 = List<int> Function(List<int> _, {required List<int> n});
40+
41+
void main() {
42+
const Check(ExtListFunc1, expected: ErasedFunc1);
43+
const Check(ExtListFunc2, expected: ErasedFunc2);
44+
const Check(ExtListFunc3, expected: ErasedFunc3);
45+
}

0 commit comments

Comments
 (0)