Skip to content

Commit

Permalink
dart-lang#2559. Add augmenting types tests. Part 6
Browse files Browse the repository at this point in the history
  • Loading branch information
sgrekhov committed Mar 29, 2024
1 parent 947af2a commit 364f1b4
Show file tree
Hide file tree
Showing 14 changed files with 449 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// 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 A class, enum, extension, or mixin augmentation may specify
/// extends, implements, on, and with clauses (when generally supported). The
/// types in these clauses are appended to the original declarations clauses of
/// the same kind, and if that clause did not exist previously then it is added
/// with the new types. All regular rules apply after this appending process, so
/// you cannot have multiple extends on a class, or an on clause on an enum, etc
///
/// @description Checks that a class augment may specify `extends` clause
/// @author [email protected]
// SharedOptions=--enable-experiment=macros

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

class A {}

class C {}

main() {
Expect.isTrue(C() is A);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// 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 A class, enum, extension, or mixin augmentation may specify
/// extends, implements, on, and with clauses (when generally supported). The
/// types in these clauses are appended to the original declarations clauses of
/// the same kind, and if that clause did not exist previously then it is added
/// with the new types. All regular rules apply after this appending process, so
/// you cannot have multiple extends on a class, or an on clause on an enum, etc
///
/// @description Checks that a class augment may specify `extends` clause
/// @author [email protected]
// SharedOptions=--enable-experiment=macros

augment library 'augmenting_types_A06_t01.dart';

augment class C extends A {}
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 A class, enum, extension, or mixin augmentation may specify
/// extends, implements, on, and with clauses (when generally supported). The
/// types in these clauses are appended to the original declarations clauses of
/// the same kind, and if that clause did not exist previously then it is added
/// with the new types. All regular rules apply after this appending process, so
/// you cannot have multiple extends on a class, or an on clause on an enum, etc
///
/// @description Checks that it is a compile-time error if a class augment
/// specifies a final class in an `extends` clause
/// @author [email protected]
// SharedOptions=--enable-experiment=macros

import augment 'augmenting_types_A06_t02_lib.dart';

class A {}

class C {}

main() {
print(A);
print(C);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// 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 A class, enum, extension, or mixin augmentation may specify
/// extends, implements, on, and with clauses (when generally supported). The
/// types in these clauses are appended to the original declarations clauses of
/// the same kind, and if that clause did not exist previously then it is added
/// with the new types. All regular rules apply after this appending process, so
/// you cannot have multiple extends on a class, or an on clause on an enum, etc
///
/// @description Checks that it is a compile-time error if a class augment
/// specifies a final class in an `extends` clause
/// @author [email protected]
// SharedOptions=--enable-experiment=macros

augment library 'augmenting_types_A06_t02.dart';
import 'augmentation_libraries_lib.dart';

augment class A extends FinalClass {}
// ^^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified

augment class C extends String {}
// ^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// 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 A class, enum, extension, or mixin augmentation may specify
/// extends, implements, on, and with clauses (when generally supported). The
/// types in these clauses are appended to the original declarations clauses of
/// the same kind, and if that clause did not exist previously then it is added
/// with the new types. All regular rules apply after this appending process, so
/// you cannot have multiple extends on a class, or an on clause on an enum, etc
///
/// @description Checks that a class, mixin and enum augment may specify
/// `implements` clause
/// @author [email protected]
// SharedOptions=--enable-experiment=macros

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

interface class I {
String get id => "I";
}

class C {}

mixin M {}

enum E {
e1;
}

class MA = Object with M;

main() {
I c = C();
I m = MA();
I e = E.e1;
Expect.equals("C", c.id);
Expect.equals("M", m.id);
Expect.equals("E", e.id);
}
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 A class, enum, extension, or mixin augmentation may specify
/// extends, implements, on, and with clauses (when generally supported). The
/// types in these clauses are appended to the original declarations clauses of
/// the same kind, and if that clause did not exist previously then it is added
/// with the new types. All regular rules apply after this appending process, so
/// you cannot have multiple extends on a class, or an on clause on an enum, etc
///
/// @description Checks that a class, mixin and enum augment may specify
/// `implements` clause
/// @author [email protected]
// SharedOptions=--enable-experiment=macros

augment library 'augmenting_types_A06_t03.dart';

augment class C implements I {
String get id => "C";
}

augment mixin M implements I {
String get id => "M";
}

augment enum E implements I {
String get id => "E";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// 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 A class, enum, extension, or mixin augmentation may specify
/// extends, implements, on, and with clauses (when generally supported). The
/// types in these clauses are appended to the original declarations clauses of
/// the same kind, and if that clause did not exist previously then it is added
/// with the new types. All regular rules apply after this appending process, so
/// you cannot have multiple extends on a class, or an on clause on an enum, etc
///
/// @description Checks that a class, mixin and enum augment may specify
/// additional `implements` clause
/// @author [email protected]
// SharedOptions=--enable-experiment=macros

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

interface class I1 {
String get id1 => "I1";
}

class C implements I1 {
String get id1 => "C";
}

mixin M implements I1 {
String get id1 => "M";
}

enum E implements I1 {
e1;
String get id1 => "E";
}

class MA = Object with M;

main() {
I1 c1 = C();
I1 m1 = MA();
I1 e1 = E.e1;
Expect.equals("C", c1.id1);
Expect.equals("M", m1.id1);
Expect.equals("E", e1.id1);

I2 c2 = C();
I2 m2 = MA();
I2 e2 = E.e1;
Expect.equals("C from I2", c2.id2);
Expect.equals("M from I2", m2.id2);
Expect.equals("E from I2", e2.id2);
}
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 A class, enum, extension, or mixin augmentation may specify
/// extends, implements, on, and with clauses (when generally supported). The
/// types in these clauses are appended to the original declarations clauses of
/// the same kind, and if that clause did not exist previously then it is added
/// with the new types. All regular rules apply after this appending process, so
/// you cannot have multiple extends on a class, or an on clause on an enum, etc
///
/// @description Checks that a class, mixin and enum augment may specify
/// additional `implements` clause
/// @author [email protected]
// SharedOptions=--enable-experiment=macros

augment library 'augmenting_types_A06_t04.dart';

interface class I2 {
String id2 => "I2";
}

augment class C implements I2 {
String get id2 => "C from I2";
}

augment mixin M implements I2 {
String get id2 => "M from I2";
}

augment enum E implements I2 {
String get id2 => "E from I2";
}
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 A class, enum, extension, or mixin augmentation may specify
/// extends, implements, on, and with clauses (when generally supported). The
/// types in these clauses are appended to the original declarations clauses of
/// the same kind, and if that clause did not exist previously then it is added
/// with the new types. All regular rules apply after this appending process, so
/// you cannot have multiple extends on a class, or an on clause on an enum, etc
///
/// @description Checks that it is a compile-time error if a class, mixin or
/// enum augment may specifies `implements` clause but doesn't implement this
/// interface
/// @author [email protected]
// SharedOptions=--enable-experiment=macros

import augment 'augmenting_types_A06_t05_lib.dart';

interface class I {
String get id => "I";
}

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

mixin M {}

enum E {
// ^
// [analyzer] unspecified
// [cfe] unspecified
e1;
}

class MA = Object with M;
// ^^
// [analyzer] unspecified
// [cfe] unspecified

main() {
print(C);
print(MA);
print(E);
}
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 A class, enum, extension, or mixin augmentation may specify
/// extends, implements, on, and with clauses (when generally supported). The
/// types in these clauses are appended to the original declarations clauses of
/// the same kind, and if that clause did not exist previously then it is added
/// with the new types. All regular rules apply after this appending process, so
/// you cannot have multiple extends on a class, or an on clause on an enum, etc
///
/// @description Checks that it is a compile-time error if a class, mixin or
/// enum augment may specifies `implements` clause but doesn't implement this
/// interface
/// @author [email protected]
// SharedOptions=--enable-experiment=macros

augment library 'augmenting_types_A06_t05.dart';

augment class C implements I {}

augment mixin M implements I {}

augment enum E implements I {}
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 A class, enum, extension, or mixin augmentation may specify
/// extends, implements, on, and with clauses (when generally supported). The
/// types in these clauses are appended to the original declarations clauses of
/// the same kind, and if that clause did not exist previously then it is added
/// with the new types. All regular rules apply after this appending process, so
/// you cannot have multiple extends on a class, or an on clause on an enum, etc
///
/// @description Checks that it is a compile-time error if a class, mixin or
/// enum augment specifies a base class in an `implements` clause
/// @author [email protected]
// SharedOptions=--enable-experiment=macros

import augment 'augmenting_types_A06_t06_lib.dart';

class C {}

mixin M {}

enum E {e1;}

main() {
print(C);
print(M);
print(E);
}
Loading

0 comments on commit 364f1b4

Please sign in to comment.