forked from dart-lang/co19
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
dart-lang#2548. Add variance modifier declaration tests
- Loading branch information
Showing
6 changed files
with
234 additions
and
0 deletions.
There are no files selected for viewing
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,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 [email protected] | ||
// 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); | ||
} |
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,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 [email protected] | ||
// 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); | ||
} |
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,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 [email protected] | ||
// 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); | ||
} |
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,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 [email protected] | ||
// 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); | ||
} |
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,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 an enum | ||
/// @author [email protected] | ||
// SharedOptions=--enable-experiment=variance | ||
|
||
enum E1<in T> {e;} | ||
// ^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
|
||
enum E2<out T> {e;} | ||
// ^^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
|
||
enum E3<inout T> {e;} | ||
// ^^^^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
|
||
main() { | ||
print(E1); | ||
print(E2); | ||
print(E3); | ||
} |
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,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 [email protected] | ||
// 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); | ||
} |