Skip to content

Commit

Permalink
#2548. Add variance modifier declaration tests (#2554)
Browse files Browse the repository at this point in the history
Add variance modifier declaration tests
  • Loading branch information
sgrekhov committed Feb 22, 2024
1 parent e6c435f commit 7b84042
Show file tree
Hide file tree
Showing 5 changed files with 200 additions and 0 deletions.
32 changes: 32 additions & 0 deletions TypeSystem/type-variance/declaration_A01_t01.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// 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 It is a compile-time error if a variance modifier is specified
/// for a type parameter declared by a static extension, a generic function
/// type, a generic function or method, or a type alias.
///
/// @description Check that it is a compile-time error if a variance modifier is
/// specified for a type parameter declared by a static extension
/// @author sgrekhov22@gmail.com
// SharedOptions=--enable-experiment=variance

extension ExtList1<in T> on List<T> {}
// ^^
// [analyzer] unspecified
// [cfe] unspecified

extension ExtList2<out T> on List<T> {}
// ^^^
// [analyzer] unspecified
// [cfe] unspecified

extension ExtList3<inout T> on List<T> {}
// ^^^^^
// [analyzer] unspecified
// [cfe] unspecified

void main() {
print(List);
}
52 changes: 52 additions & 0 deletions TypeSystem/type-variance/declaration_A01_t02.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// 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 It is a compile-time error if a variance modifier is specified
/// for a type parameter declared by a static extension, a generic function
/// type, a generic function or method, or a type alias.
///
/// @description Check that it is a compile-time error if a variance modifier is
/// specified for a type parameter declared by a generic function type
/// @author sgrekhov22@gmail.com
// SharedOptions=--enable-experiment=variance

typedef F1<in T>();
// ^^
// [analyzer] unspecified
// [cfe] unspecified

typedef F2<out T>();
// ^^^
// [analyzer] unspecified
// [cfe] unspecified

typedef F3<inout T>();
// ^^^^^
// [analyzer] unspecified
// [cfe] unspecified

typedef F4<in T> = void Function(T);
// ^^
// [analyzer] unspecified
// [cfe] unspecified

typedef F5<out T> = void Function(T);
// ^^^
// [analyzer] unspecified
// [cfe] unspecified

typedef F6<inout T> = void Function(T);
// ^^^^^
// [analyzer] unspecified
// [cfe] unspecified

main() {
print(F1);
print(F2);
print(F3);
print(F4);
print(F5);
print(F6);
}
34 changes: 34 additions & 0 deletions TypeSystem/type-variance/declaration_A01_t03.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// 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 It is a compile-time error if a variance modifier is specified
/// for a type parameter declared by a static extension, a generic function
/// type, a generic function or method, or a type alias.
///
/// @description Check that it is a compile-time error if a variance modifier is
/// specified for a type parameter declared by a generic function
/// @author sgrekhov22@gmail.com
// SharedOptions=--enable-experiment=variance

void f1<in T>(T t) {}
// ^^
// [analyzer] unspecified
// [cfe] unspecified

void f2<out T>(T t) {}
// ^^^
// [analyzer] unspecified
// [cfe] unspecified

void f3<inout T>(T t) {}
// ^^^^^
// [analyzer] unspecified
// [cfe] unspecified

main() {
print(f1);
print(f2);
print(f3);
}
48 changes: 48 additions & 0 deletions TypeSystem/type-variance/declaration_A01_t04.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// 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 It is a compile-time error if a variance modifier is specified
/// for a type parameter declared by a static extension, a generic function
/// type, a generic function or method, or a type alias.
///
/// @description Check that it is a compile-time error if a variance modifier is
/// specified for a type parameter declared by a generic method
/// @author sgrekhov22@gmail.com
// SharedOptions=--enable-experiment=variance

class C {
static void s1<in T>(T t) {}
// ^^
// [analyzer] unspecified
// [cfe] unspecified

static void s2<out T>(T t) {}
// ^^^
// [analyzer] unspecified
// [cfe] unspecified

static void s3<inout T>(T t) {}
// ^^^^^
// [analyzer] unspecified
// [cfe] unspecified

void f1<in T>(T t) {}
// ^^
// [analyzer] unspecified
// [cfe] unspecified

void f2<out T>(T t) {}
// ^^^
// [analyzer] unspecified
// [cfe] unspecified

void f3<inout T>(T t) {}
// ^^^^^
// [analyzer] unspecified
// [cfe] unspecified
}
main() {
print(C);
}
34 changes: 34 additions & 0 deletions TypeSystem/type-variance/declaration_A01_t05.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// 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 It is a compile-time error if a variance modifier is specified
/// for a type parameter declared by a static extension, a generic function
/// type, a generic function or method, or a type alias.
///
/// @description Check that it is a compile-time error if a variance modifier is
/// specified for a type parameter declared by a type alias
/// @author sgrekhov22@gmail.com
// SharedOptions=--enable-experiment=variance

typedef AList1<in T> = List<T>;
// ^^
// [analyzer] unspecified
// [cfe] unspecified

typedef AList2<out T> = List<T>;
// ^^^
// [analyzer] unspecified
// [cfe] unspecified

typedef AList3<inout T> = List<T>;
// ^^^^^
// [analyzer] unspecified
// [cfe] unspecified

main() {
print(AList1);
print(AList2);
print(AList3);
}

0 comments on commit 7b84042

Please sign in to comment.