|
| 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 | + |
| 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 | +} |
0 commit comments