forked from dart-lang/co19
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
dart-lang#2559. Make more augmented expression tests stronger
- Loading branch information
Showing
6 changed files
with
158 additions
and
4 deletions.
There are no files selected for viewing
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
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
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
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
55 changes: 55 additions & 0 deletions
55
LanguageFeatures/Augmentation-libraries/augmented_expression_A03_t13.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,55 @@ | ||
// 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 fields: Within an augmenting field, augmented can only be used | ||
/// in an initializer expression, and refers to the original field's | ||
/// initializer expression, which is immediately evaluated. | ||
/// | ||
/// If augmented refers to a variable declaration (as defined by a declaration | ||
/// and a number of prior augmentations) with no initializer expression, and the | ||
/// variable's type is nullable, augmented evaluates to null. If the variable's | ||
/// type is not nullable, then it's a compile-time error. | ||
/// | ||
/// @description Checks that it is a compile-time error ot declare a local | ||
/// variable named `augmented` in an augmenting field initializer | ||
/// @author sgrekhov22@gmail.com | ||
// SharedOptions=--enable-experiment=macros | ||
|
||
import augment 'augmented_expression_A03_t13_lib.dart'; | ||
|
||
Function? topLevelVariable; | ||
|
||
class C { | ||
static Function? staticVariable; | ||
Function? instanceVariable; | ||
} | ||
|
||
mixin M { | ||
static Function? staticVariable; | ||
Function? instanceVariable; | ||
} | ||
|
||
enum E { | ||
e1; | ||
static Function? staticVariable; | ||
} | ||
|
||
class A {} | ||
|
||
extension Ext on A { | ||
static Function? staticVariable; | ||
} | ||
|
||
main() { | ||
print(topLevelVariable); | ||
print(C); | ||
print(M); | ||
print(E); | ||
print(A); | ||
} |
87 changes: 87 additions & 0 deletions
87
LanguageFeatures/Augmentation-libraries/augmented_expression_A03_t13_lib.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,87 @@ | ||
// 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 fields: Within an augmenting field, augmented can only be used | ||
/// in an initializer expression, and refers to the original field's | ||
/// initializer expression, which is immediately evaluated. | ||
/// | ||
/// If augmented refers to a variable declaration (as defined by a declaration | ||
/// and a number of prior augmentations) with no initializer expression, and the | ||
/// variable's type is nullable, augmented evaluates to null. If the variable's | ||
/// type is not nullable, then it's a compile-time error. | ||
/// | ||
/// @description Checks that it is a compile-time error ot declare a local | ||
/// variable named `augmented` in an augmenting field initializer | ||
/// @author sgrekhov22@gmail.com | ||
// SharedOptions=--enable-experiment=macros | ||
|
||
augment library 'augmented_expression_A03_t13.dart'; | ||
|
||
augment Function? topLevelVariable = () { | ||
var augmented = 42; | ||
// ^^^^^^^^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
return "Augmented"; | ||
}; | ||
|
||
augment class C { | ||
augment static Function? staticVariable = () { | ||
var augmented = 42; | ||
// ^^^^^^^^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
return "Augmented"; | ||
}; | ||
augment Function? instanceVariable = () { | ||
var augmented = 42; | ||
// ^^^^^^^^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
return "Augmented"; | ||
}; | ||
} | ||
|
||
augment mixin M { | ||
augment static Function? staticVariable = () { | ||
var augmented = 42; | ||
// ^^^^^^^^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
return "Augmented"; | ||
}; | ||
augment Function? instanceVariable = () { | ||
var augmented = 42; | ||
// ^^^^^^^^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
return "Augmented"; | ||
}; | ||
} | ||
|
||
augment enum E { | ||
augment e1; | ||
augment static Function? staticVariable = () { | ||
var augmented = 42; | ||
// ^^^^^^^^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
return "Augmented"; | ||
}; | ||
} | ||
|
||
augment extension Ext { | ||
augment static Function? staticVariable = () { | ||
var augmented = 42; | ||
// ^^^^^^^^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
return "Augmented"; | ||
}; | ||
} |