Skip to content

Commit

Permalink
#2559. Add augmenting types tests. Part 4 (#2571)
Browse files Browse the repository at this point in the history
  • Loading branch information
sgrekhov authored Mar 15, 2024
1 parent 2064db7 commit 07f7a4d
Show file tree
Hide file tree
Showing 8 changed files with 229 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// 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:
/// ...
/// - The type parameters of the type augmentation do not match the original
/// type's type parameters. This means there must be the same number of type
/// parameters with the same bounds and names.
///
/// @description Checks that it is a compile-time error if an augmenting type
/// declares wrong number of type parameters
/// @author [email protected]
// SharedOptions=--enable-experiment=macros

import augment 'augmenting_types_A05_t01_lib.dart';

class C<T> {}

main() {
print(C);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// 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:
/// ...
/// - The type parameters of the type augmentation do not match the original
/// type's type parameters. This means there must be the same number of type
/// parameters with the same bounds and names.
///
/// @description Checks that it is a compile-time error if an augmenting type
/// declares wrong number of type parameters
/// @author [email protected]
// SharedOptions=--enable-experiment=macros

library augment 'augmenting_types_A05_t01.dart';

augment class C {}
// ^
// [analyzer] unspecified
// [cfe] unspecified

augment class C<T, X> {}
// ^^^^
// [analyzer] unspecified
// [cfe] unspecified
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// 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:
/// ...
/// - The type parameters of the type augmentation do not match the original
/// type's type parameters. This means there must be the same number of type
/// parameters with the same bounds and names.
///
/// @description Checks that it is a compile-time error if an augmenting type
/// declares type parameters with different bounds
/// @author [email protected]
// SharedOptions=--enable-experiment=macros

import augment 'augmenting_types_A05_t02_lib.dart';

class A {}
class B extends A {}
class C<T extends A> {}

main() {
print(C);
}
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:
/// ...
/// - The type parameters of the type augmentation do not match the original
/// type's type parameters. This means there must be the same number of type
/// parameters with the same bounds and names.
///
/// @description Checks that it is a compile-time error if an augmenting type
/// declares type parameters with different bounds
/// @author [email protected]
// SharedOptions=--enable-experiment=macros

library augment 'augmenting_types_A05_t02.dart';

augment class C<T extends B> {}
// ^
// [analyzer] unspecified
// [cfe] unspecified

augment class C<T extends Object> {}
// ^^^^^^
// [analyzer] unspecified
// [cfe] unspecified

augment class C<T extends List> {}
// ^^^^
// [analyzer] unspecified
// [cfe] unspecified
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// 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:
/// ...
/// - The type parameters of the type augmentation do not match the original
/// type's type parameters. This means there must be the same number of type
/// parameters with the same bounds and names.
///
/// @description Checks that it is a compile-time error if an augmenting type
/// declares type parameters with different names
/// @author [email protected]
// SharedOptions=--enable-experiment=macros

import augment 'augmenting_types_A05_t03_lib.dart';

class A {}
class C<X extends A, Y> {}

main() {
print(C);
}
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:
/// ...
/// - The type parameters of the type augmentation do not match the original
/// type's type parameters. This means there must be the same number of type
/// parameters with the same bounds and names.
///
/// @description Checks that it is a compile-time error if an augmenting type
/// declares type parameters with different names
/// @author [email protected]
// SharedOptions=--enable-experiment=macros

library augment 'augmenting_types_A05_t03.dart';

augment class C<X extends A, Z> {}
// ^
// [analyzer] unspecified
// [cfe] unspecified

augment class C<T extends A, Y> {}
// ^
// [analyzer] unspecified
// [cfe] unspecified

augment class C<Y extends A, X> {}
// ^
// [analyzer] unspecified
// [cfe] unspecified
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// 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:
/// ...
/// - The type parameters of the type augmentation do not match the original
/// type's type parameters. This means there must be the same number of type
/// parameters with the same bounds and names.
///
/// @description Checks that it is not an error if an augmenting type
/// declares the same number of type parameters with the same names and bounds
/// @author [email protected]
// SharedOptions=--enable-experiment=macros

import '../../Utils/expect.dart';
import augment 'augmenting_types_A05_t04_lib.dart';

class A {}
typedef AAlias = A;
class B extends A {}

class C1<T extends A> {}
class C2<T extends AAlias> {}

main() {
Expect.equals("C1<B>", C1<B>().name1);
Expect.equals("C1<B>", C1<B>().name2());
Expect.equals("C1<A>", C1<AAlias>().name1);
Expect.equals("C1<A>", C1<AAlias>().name2());
Expect.equals("C2<B>", C2<B>().name1);
Expect.equals("C2<B>", C2<B>().name2());
Expect.equals("C2<A>", C2<AAlias>().name1);
Expect.equals("C2<A>", C2<AAlias>().name2());
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// 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:
/// ...
/// - The type parameters of the type augmentation do not match the original
/// type's type parameters. This means there must be the same number of type
/// parameters with the same bounds and names.
///
/// @description Checks that it is not an error if an augmenting type
/// declares the same number of type parameters with the same names and bounds
/// @author [email protected]
// SharedOptions=--enable-experiment=macros

library augment 'augmenting_types_A05_t04.dart';

augment class C1<T extends A> {
String get name1 => 'C1<$T>';
}
augment class C1<T extends AAlias> {
String name2() => 'C1<$T>';
}
augment class C2<T extends A> {
String get name1 => 'C2<$T>';
}
augment class C2<T extends AAlias> {
String name2() => 'C2<$T>';
}

0 comments on commit 07f7a4d

Please sign in to comment.