diff --git a/TypeSystem/type-variance/declaration_A01_t01.dart b/TypeSystem/type-variance/declaration_A01_t01.dart new file mode 100644 index 0000000000..2885425812 --- /dev/null +++ b/TypeSystem/type-variance/declaration_A01_t01.dart @@ -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 on List {} +// ^^ +// [analyzer] unspecified +// [cfe] unspecified + +extension ExtList2 on List {} +// ^^^ +// [analyzer] unspecified +// [cfe] unspecified + +extension ExtList3 on List {} +// ^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + +void main() { + print(List); +} diff --git a/TypeSystem/type-variance/declaration_A01_t02.dart b/TypeSystem/type-variance/declaration_A01_t02.dart new file mode 100644 index 0000000000..1bec297d81 --- /dev/null +++ b/TypeSystem/type-variance/declaration_A01_t02.dart @@ -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(); +// ^^ +// [analyzer] unspecified +// [cfe] unspecified + +typedef F2(); +// ^^^ +// [analyzer] unspecified +// [cfe] unspecified + +typedef F3(); +// ^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + +typedef F4 = void Function(T); +// ^^ +// [analyzer] unspecified +// [cfe] unspecified + +typedef F5 = void Function(T); +// ^^^ +// [analyzer] unspecified +// [cfe] unspecified + +typedef F6 = void Function(T); +// ^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + +main() { + print(F1); + print(F2); + print(F3); + print(F4); + print(F5); + print(F6); +} diff --git a/TypeSystem/type-variance/declaration_A01_t03.dart b/TypeSystem/type-variance/declaration_A01_t03.dart new file mode 100644 index 0000000000..923af417be --- /dev/null +++ b/TypeSystem/type-variance/declaration_A01_t03.dart @@ -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(T t) {} +// ^^ +// [analyzer] unspecified +// [cfe] unspecified + +void f2(T t) {} +// ^^^ +// [analyzer] unspecified +// [cfe] unspecified + +void f3(T t) {} +// ^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + +main() { + print(f1); + print(f2); + print(f3); +} diff --git a/TypeSystem/type-variance/declaration_A01_t04.dart b/TypeSystem/type-variance/declaration_A01_t04.dart new file mode 100644 index 0000000000..ecfa7a2729 --- /dev/null +++ b/TypeSystem/type-variance/declaration_A01_t04.dart @@ -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(T t) {} +// ^^ +// [analyzer] unspecified +// [cfe] unspecified + + static void s2(T t) {} +// ^^^ +// [analyzer] unspecified +// [cfe] unspecified + + static void s3(T t) {} +// ^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + + void f1(T t) {} +// ^^ +// [analyzer] unspecified +// [cfe] unspecified + + void f2(T t) {} +// ^^^ +// [analyzer] unspecified +// [cfe] unspecified + + void f3(T t) {} +// ^^^^^ +// [analyzer] unspecified +// [cfe] unspecified +} +main() { + print(C); +} diff --git a/TypeSystem/type-variance/declaration_A01_t05.dart b/TypeSystem/type-variance/declaration_A01_t05.dart new file mode 100644 index 0000000000..3bde1dd485 --- /dev/null +++ b/TypeSystem/type-variance/declaration_A01_t05.dart @@ -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 = List; +// ^^ +// [analyzer] unspecified +// [cfe] unspecified + +typedef AList2 = List; +// ^^^ +// [analyzer] unspecified +// [cfe] unspecified + +typedef AList3 = List; +// ^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + +main() { + print(AList1); + print(AList2); + print(AList3); +}