-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Add more constant evaluation tests
- Loading branch information
Showing
2 changed files
with
77 additions
and
0 deletions.
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
LanguageFeatures/Extension-types/static_analysis_extension_types_A20_t07.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file | ||
// for details. All rights reserved. Use of this source code is governed by a | ||
// BSD-style license that can be found in the LICENSE file. | ||
|
||
/// @assertion The extension type erasure of an extension type V is obtained by | ||
/// recursively replacing every subterm of V which is an extension type by the | ||
/// corresponding representation type. | ||
/// | ||
/// Let X1 extends B1, .. Xs extends Bs be a declaration of the type parameters | ||
/// of a generic entity (it could be a generic class, extension type, mixin, | ||
/// typedef, or function). Let BBj be the extension type erasure of | ||
/// Bj, for j in 1 .. s. It is a compile-time error if | ||
/// X1 extends BB1, .. Xs extends BBs has any compile-time errors. | ||
/// | ||
/// @description Check that the erasure of an extension type `V` is obtained by | ||
/// recursively replacing every subterm of `V` which is an extension type by the | ||
/// corresponding representation type. | ||
/// @author sgrekhov22@gmail.com | ||
// SharedOptions=--enable-experiment=inline-class | ||
|
||
class Check { | ||
const Check(Object? v, {required Object? eq}) | ||
: assert(v == eq, "Not equal ${(v, eq: eq)}"); | ||
} | ||
|
||
extension type const Ext1(Object? value) {} | ||
extension type const Ext2(Object value) implements Object {} | ||
|
||
void main() { | ||
const Check([Ext1(1)], eq: <Object?>[1,]); | ||
const Check([Ext2(1)], eq: <Object>[1,]); | ||
const Check({Ext1(1)}, eq: <Object?>{1,}); | ||
const Check({Ext2(1)}, eq: <Object>{1,}); | ||
const Check({Ext1(1): Ext1(2)}, eq: <Object?, Object?>{1: 2}); | ||
const Check({Ext2(1): Ext1(2)}, eq: <Object, Object?>{1: 2}); | ||
const Check({Ext1(1): Ext2(2)}, eq: <Object?, Object>{1: 2}); | ||
const Check({Ext2(1): Ext2(2)}, eq: <Object, Object>{1: 2}); | ||
} |
38 changes: 38 additions & 0 deletions
38
LanguageFeatures/Extension-types/static_analysis_extension_types_A20_t08.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file | ||
// for details. All rights reserved. Use of this source code is governed by a | ||
// BSD-style license that can be found in the LICENSE file. | ||
|
||
/// @assertion The extension type erasure of an extension type V is obtained by | ||
/// recursively replacing every subterm of V which is an extension type by the | ||
/// corresponding representation type. | ||
/// | ||
/// Let X1 extends B1, .. Xs extends Bs be a declaration of the type parameters | ||
/// of a generic entity (it could be a generic class, extension type, mixin, | ||
/// typedef, or function). Let BBj be the extension type erasure of | ||
/// Bj, for j in 1 .. s. It is a compile-time error if | ||
/// X1 extends BB1, .. Xs extends BBs has any compile-time errors. | ||
/// | ||
/// @description Check that the erasure of an extension type `V` is obtained by | ||
/// recursively replacing every subterm of `V` which is an extension type by the | ||
/// corresponding representation type. | ||
/// @author sgrekhov22@gmail.com | ||
// SharedOptions=--enable-experiment=inline-class | ||
|
||
class Check { | ||
const Check(Object? v, {required Object? eq}) | ||
: assert(v == eq, "Not equal ${(v, eq: eq)}"); | ||
} | ||
|
||
extension type const IntET1(int _) {} | ||
extension type const IntET2(int _) implements int {} | ||
|
||
extension type const MapET1<X>(Map<IntET1, X> _) {} | ||
extension type const MapET2<X>(Map<IntET2, X> _) {} | ||
|
||
void main() { | ||
const Check([MapET1<List<IntET1>>({})], eq: [<int, List<int>>{}]); | ||
const Check([MapET1<List<IntET2>>({})], eq: [<int, List<int>>{}]); | ||
const Check([MapET2<List<IntET1>>({})], eq: [<int, List<int>>{}]); | ||
const Check([MapET2<List<IntET2>>({})], eq: [<int, List<int>>{}]); | ||
} |