-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#2559. Add tests for reserved word
augmented
in constructors. Part …
…1. (#3014) Add tests for reserved word `augmented` in constructors. Part 1.
- Loading branch information
Showing
22 changed files
with
1,711 additions
and
2 deletions.
There are no files selected for viewing
107 changes: 107 additions & 0 deletions
107
LanguageFeatures/Augmentation-libraries/augmented_expression_A11_t01.dart
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,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 an augmenting non-redirecting generative constructor. | ||
/// @author [email protected] | ||
// 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); | ||
} |
103 changes: 103 additions & 0 deletions
103
LanguageFeatures/Augmentation-libraries/augmented_expression_A11_t02.dart
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,103 @@ | ||
// 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 an augmenting non-redirecting generative | ||
/// constructor. | ||
/// @author [email protected] | ||
// 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); | ||
} |
80 changes: 80 additions & 0 deletions
80
LanguageFeatures/Augmentation-libraries/augmented_expression_A11_t03.dart
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,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 an augmenting non-redirecting generative | ||
/// constructor. | ||
/// @author [email protected] | ||
// 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); | ||
} |
82 changes: 82 additions & 0 deletions
82
LanguageFeatures/Augmentation-libraries/augmented_expression_A11_t04.dart
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,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 an augmenting non-redirecting | ||
/// generative constructor. | ||
/// @author [email protected] | ||
// 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); | ||
} |
Oops, something went wrong.