Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#2559. Add more augmented expression tests #3016

Merged
merged 1 commit into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 A compile-time error occurs if a declaration with the basename
/// `augmented` occurs in a location where any enclosing declaration is
/// augmenting.
///
/// @description Checks that it is a compile-time error to augment a class named
/// `augmented`.
/// @author sgrekhov22@gmail.com

// SharedOptions=--enable-experiment=macros

class augmented {}

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

main() {
print(augmented);
}
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 A compile-time error occurs if a declaration with the basename
/// `augmented` occurs in a location where any enclosing declaration is
/// augmenting.
///
/// @description Checks that it is a compile-time error to augment a mixin named
/// `augmented`.
/// @author sgrekhov22@gmail.com

// SharedOptions=--enable-experiment=macros

mixin augmented {}

augment mixin augmented {}
// ^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified

main() {
print(augmented);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// 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 compile-time error occurs if a declaration with the basename
/// `augmented` occurs in a location where any enclosing declaration is
/// augmenting.
///
/// @description Checks that it is a compile-time error to augment an enum named
/// `augmented`.
/// @author sgrekhov22@gmail.com

// SharedOptions=--enable-experiment=macros

enum augmented {
e0;
}

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

main() {
print(augmented);
}
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 compile-time error occurs if a declaration with the basename
/// `augmented` occurs in a location where any enclosing declaration is
/// augmenting.
///
/// @description Checks that it is a compile-time error to augment an extension
/// named `augmented`.
/// @author sgrekhov22@gmail.com

// SharedOptions=--enable-experiment=macros

class A {}

extension augmented on A {}

augment extension augmented {}
// ^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified

main() {
print(A);
}
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 A compile-time error occurs if a declaration with the basename
/// `augmented` occurs in a location where any enclosing declaration is
/// augmenting.
///
/// @description Checks that it is a compile-time error to augment an extension
/// type named `augmented`.
/// @author sgrekhov22@gmail.com

// SharedOptions=--enable-experiment=macros

extension type augmented(int _) {}

augment extension type augmented {}
// ^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified

main() {
print(augmented);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// 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 The exact result of an `augmented` expression depends on what is
/// being augmented, but it generally follows the same rules as any normal
/// identifier:
/// ...
/// - Augmenting non-redirecting generative constructors: Unlike other
/// functions, `augmented` has no special meaning in non-redirecting
/// generative constructors. It is still a reserved word inside the body of
/// these constructors, since they are within the scope of an augmenting
/// declaration.
///
/// @description Checks that it is a compile-time error for an augmenting
/// non-redirecting generative constructor to initialize a member named
/// `augmented` in the initializer list.
/// @author sgrekhov22@gmail.com

// SharedOptions=--enable-experiment=macros

class C {
int augmented;
C(this.augmented);
}

augment class C {
C.foo() : augmented = 1;
// ^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
}

enum E {
a0(0);
final int augmented;
const E(this.augmented);
}

augment enum E {
a1.foo();
const E.foo() : augmented = 1;
// ^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
}

extension type ET(int augmented) {}

augment extension type ET {
ET.foo() : augmented = 1 {}
// ^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
}

main() {
print(C);
print(E);
print(ET);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// 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 The exact result of an `augmented` expression depends on what is
/// being augmented, but it generally follows the same rules as any normal
/// identifier:
/// ...
/// - Augmenting non-redirecting generative constructors: Unlike other
/// functions, `augmented` has no special meaning in non-redirecting
/// generative constructors. It is still a reserved word inside the body of
/// these constructors, since they are within the scope of an augmenting
/// declaration.
///
/// @description Checks that it is a compile-time error for an augmenting
/// non-redirecting generative constructor to use a variable named `augmented`
/// in the initializer list.
/// @author sgrekhov22@gmail.com

// SharedOptions=--enable-experiment=macros

const augmented = 1;

class C {
int id;
C(this.id);
}

augment class C {
C.foo() : id = augmented;
// ^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
}

enum E {
a0(0);
final int id;
const E(this.id);
}

augment enum E {
a1.foo();
const E.foo() : id = augmented;
// ^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
}

extension type ET(int id) {}

augment extension type ET {
ET.foo() : id = augmented;
// ^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
}

main() {
print(C);
print(E);
print(ET);
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,9 @@ extension type ET(int id) {}

main() {
Expect.equals(1, ET(1).id);
if (assertStatementsEnabled) {
Expect.throws(() {
ET(-1);
});
}
}
Loading