Skip to content

Commit

Permalink
dart-lang#2559. Add tests for reserved word augmented in constructo…
Browse files Browse the repository at this point in the history
…rs. Part 1.
  • Loading branch information
sgrekhov committed Dec 12, 2024
1 parent ee06c5d commit 711e38f
Show file tree
Hide file tree
Showing 20 changed files with 1,704 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
// 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 to use an `augmented` in
/// the body of augmenting non-redirecting generative constructor.
/// @author sgrekhov22@gmail.com
// SharedOptions=--enable-experiment=macros

class C {
C() {
var augmented = "Ok, not augmenting declaration";
print(augmented);
}
C.foo() {
var augmented = "Ok, not augmenting declaration";
print(augmented);
}
}

augment class C {
augment C() {
var augmented = "Error, within the scope of an augmenting declaration";
// ^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
}
augment C.foo() {
var augmented = "Error, within the scope of an augmenting declaration";
// ^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
}
C.bar() {
var augmented = "Error, within the scope of an augmenting declaration";
// ^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
}
}

extension type ET1(int _) {
ET1.foo(this._) {
var augmented = "Ok, not augmenting declaration";
print(augmented);
}
}

augment extension type ET1 {
augment ET1(int _) {
var augmented = "Error, within the scope of an augmenting declaration";
// ^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
}
augment ET1.foo(this._) {
var augmented = "Error, within the scope of an augmenting declaration";
// ^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
}
ET1.bar(this._) {
var augmented = "Error, within the scope of an augmenting declaration";
// ^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
}
}

extension type ET2.id(int _) {
ET2.new(this._) {
var augmented = "Ok, not augmenting declaration";
print(augmented);
}
}

augment extension type ET2 {
augment ET2.id(this._) {
var augmented = "Error, within the scope of an augmenting declaration";
// ^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
}
augment ET2(this._) {
var augmented = "Error, within the scope of an augmenting declaration";
// ^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
}
}

main() {
print(C);
print(ET1);
print(ET2);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
// 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 to call an `augmented()`
/// expression in the body of augmenting non-redirecting generative constructor.
/// @author sgrekhov22@gmail.com
// SharedOptions=--enable-experiment=macros

class C {
C();
C.foo();
String augmented() => "Ok, non-augmenting declaration";
}

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

extension type ET1(String _) {
ET1.foo(this._) {
augmented("Ok, non-augmenting declaration");
}
void augmented(String _) {}
}

augment extension type ET1 {
augment ET1(int _) {
augmented("Error!");
// ^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
}
augment ET1.foo(this._) {
augmented("Error!");
// ^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
}
ET1.bar(this._) {
augmented("Error!");
// ^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
}
}

extension type ET2.foo(String _) {
ET2.new(this._) {
augmented("Ok, non-augmenting declaration");
}
void augmented(String _) {}
}

augment extension type ET2 {
augment ET2.foo(this._) {
augmented("Error!");
// ^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
}
augment ET2(this._) {
augmented("Error!");
// ^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
}
}

main() {
print(C);
print(ET1);
print(ET2);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
// 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 to tear-off a function
/// named `augmented()` in the body of augmenting non-redirecting generative
/// constructor.
/// @author sgrekhov22@gmail.com
// SharedOptions=--enable-experiment=macros

class C {
C();
C.foo();
String augmented() => "Ok, non-augmenting declaration";
}

augment class C {
augment C() {
var v = augmented;
// ^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
}
augment C.foo() {
augmented.toString();
// ^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
}
C.bar() {
augmented.toString();
// ^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
}
}

extension type ET(String _) {
ET.foo(this._) {
augmented("Ok, non-augmenting declaration");
}
void augmented(String _) {}
}

augment extension type ET {
augment ET(int _) {
var v = augmented;
// ^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
}
augment ET.foo(this._) {
augmented.toString();
// ^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
}
ET.bar(this._) {
augmented.toString();
// ^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
}
}

main() {
print(C);
print(ET);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
// 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 to declare a local
/// function named `augmented()` in the body of augmenting non-redirecting
/// generative constructor.
/// @author sgrekhov22@gmail.com
// SharedOptions=--enable-experiment=macros

class C {
C() {
String augmented() => "Ok, non-augmenting declaration";
}
C.foo() {
String augmented() => "Ok, non-augmenting declaration";
}
}

augment class C {
augment C() {
String augmented() => "Error!";
// ^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
}
augment C.foo() {
String augmented() => "Error!";
// ^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
}
C.bar() {
String augmented() => "Error!";
// ^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
}
}

extension type ET(String _) {
ET.foo(this._) {
String augmented() => "Ok, non-augmenting declaration";
}
}

augment extension type ET {
augment ET(int _) {
String augmented() => "Error!";
// ^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
}
augment ET.foo(this._) {
String augmented() => "Error!";
// ^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
}
ET.bar(this._) {
String augmented() => "Error!";
// ^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
}
}

main() {
print(C);
print(ET);
}
Loading

0 comments on commit 711e38f

Please sign in to comment.