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. Add augmenting expression tests for fields
- Loading branch information
Showing
13 changed files
with
927 additions
and
0 deletions.
There are no files selected for viewing
75 changes: 75 additions & 0 deletions
75
LanguageFeatures/Augmentation-libraries/augmented_expression_A03_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,75 @@ | ||
// 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. | ||
/// | ||
/// It is a compile-time error to use augmented in an augmenting field's | ||
/// initializer if the member being augmented is not a field with an initializer | ||
/// | ||
/// @description Checks that within an augmenting field `augmented` invokes the | ||
/// original field's initializer expression. | ||
/// @author sgrekhov22@gmail.com | ||
// SharedOptions=--enable-experiment=macros | ||
|
||
import augment 'augmented_expression_A03_t01_lib.dart'; | ||
import '../../Utils/expect.dart'; | ||
|
||
final String augmented = "Augmented variable"; | ||
|
||
String topLevelVariable = "Original"; | ||
final String finalTopLevelVariable = "Original"; | ||
|
||
class C { | ||
static String staticVariable = "Original"; | ||
static final String finalStaticVariable = "Original"; | ||
String instanceVariable = "Original"; | ||
final String finalInstanceVariable = "Original"; | ||
} | ||
|
||
mixin M { | ||
static String staticVariable = "Original"; | ||
static final String finalStaticVariable = "Original"; | ||
String instanceVariable = "Original"; | ||
final String finalInstanceVariable = "Original"; | ||
} | ||
|
||
enum E { | ||
e1; | ||
|
||
static String staticVariable = "Original"; | ||
static final String finalStaticVariable = "Original"; | ||
final String finalInstanceVariable = "Original"; | ||
} | ||
|
||
class A {} | ||
|
||
extension Ext on A { | ||
static String staticVariable = "Original"; | ||
static final String finalStaticVariable = "Original"; | ||
} | ||
|
||
class MA = Object with M; | ||
|
||
main() { | ||
Expect.equals("Augment: Original", topLevelVariable); | ||
Expect.equals("Augment: Original", finalTopLevelVariable); | ||
Expect.equals("Augment: Original", C.staticVariable); | ||
Expect.equals("Augment: Original", C.finalStaticVariable); | ||
Expect.equals("Augment: Original", C().instanceVariable); | ||
Expect.equals("Augment: Original", C().finalInstanceVariable); | ||
Expect.equals("Augment: Original", M.staticVariable); | ||
Expect.equals("Augment: Original", M.finalStaticVariable); | ||
Expect.equals("Augment: Original", MA().instanceVariable); | ||
Expect.equals("Augment: Original", MA().finalInstanceVariable); | ||
Expect.equals("Augment: Original", E.staticVariable); | ||
Expect.equals("Augment: Original", E.finalStaticVariable); | ||
Expect.equals("Augment: Original", E.e1.finalInstanceVariable); | ||
} |
52 changes: 52 additions & 0 deletions
52
LanguageFeatures/Augmentation-libraries/augmented_expression_A03_t01_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,52 @@ | ||
// 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. | ||
/// | ||
/// It is a compile-time error to use augmented in an augmenting field's | ||
/// initializer if the member being augmented is not a field with an initializer | ||
/// | ||
/// @description Checks that within an augmenting field `augmented` invokes the | ||
/// original field's initializer expression. | ||
/// @author sgrekhov22@gmail.com | ||
// SharedOptions=--enable-experiment=macros | ||
|
||
augment library 'augmented_expression_A03_t01.dart'; | ||
|
||
augment String topLevelVariable = "Augment: $augmented"; | ||
augment final String finalTopLevelVariable = "Augment: $augmented"; | ||
|
||
augment class C { | ||
augment static String staticVariable = "Augment: $augmented"; | ||
augment static final String finalStaticVariable = "Augment: $augmented"; | ||
augment String instanceVariable = "Augment: $augmented"; | ||
augment final String finalInstanceVariable = "Augment: $augmented"; | ||
} | ||
|
||
augment mixin M { | ||
augment static String staticVariable = "Augment: $augmented"; | ||
augment static final String finalStaticVariable = "Augment: $augmented"; | ||
augment String instanceVariable = "Augment: $augmented"; | ||
augment final String finalInstanceVariable = "Augment: $augmented"; | ||
} | ||
|
||
augment enum E { | ||
augment e1; | ||
|
||
augment static String staticVariable = "Augment: $augmented"; | ||
augment static final String finalStaticVariable = "Augment: $augmented"; | ||
augment final String finalInstanceVariable = "Augment: $augmented"; | ||
} | ||
|
||
augment extension Ext { | ||
augment static String staticVariable = "Augment: $augmented"; | ||
augment static final String finalStaticVariable = "Augment: $augmented"; | ||
} |
77 changes: 77 additions & 0 deletions
77
LanguageFeatures/Augmentation-libraries/augmented_expression_A03_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,77 @@ | ||
// 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. | ||
/// | ||
/// It is a compile-time error to use augmented in an augmenting field's | ||
/// initializer if the member being augmented is not a field with an initializer | ||
/// | ||
/// @description Checks that within an augmenting field `augmented` invokes the | ||
/// original field's initializer expression. | ||
/// @author sgrekhov22@gmail.com | ||
// SharedOptions=--enable-experiment=macros | ||
|
||
import augment 'augmented_expression_A03_t02_lib.dart'; | ||
import '../../Utils/expect.dart'; | ||
|
||
String augmented() => "Wrong augmented() call!"; | ||
|
||
String foo() => "Original"; | ||
|
||
var topLevelVariable = foo; | ||
final finalTopLevelVariable = foo; | ||
|
||
class C { | ||
static var staticVariable = foo; | ||
static final finalStaticVariable = foo; | ||
var instanceVariable = foo; | ||
final finalInstanceVariable = foo; | ||
} | ||
|
||
mixin M { | ||
static var staticVariable = foo; | ||
static final finalStaticVariable = foo; | ||
var instanceVariable = foo; | ||
final finalInstanceVariable = foo; | ||
} | ||
|
||
enum E { | ||
e1; | ||
|
||
static var staticVariable = foo; | ||
static final finalStaticVariable = foo; | ||
final finalInstanceVariable = foo; | ||
} | ||
|
||
class A {} | ||
|
||
extension Ext on A { | ||
static var staticVariable = foo; | ||
static final finalStaticVariable = foo; | ||
} | ||
|
||
class MA = Object with M; | ||
|
||
main() { | ||
Expect.equals("Augment: Original", topLevelVariable()); | ||
Expect.equals("Augment: Original", finalTopLevelVariable()); | ||
Expect.equals("Augment: Original", C.staticVariable()); | ||
Expect.equals("Augment: Original", C.finalStaticVariable()); | ||
Expect.equals("Augment: Original", C().instanceVariable()); | ||
Expect.equals("Augment: Original", C().finalInstanceVariable()); | ||
Expect.equals("Augment: Original", M.staticVariable()); | ||
Expect.equals("Augment: Original", M.finalStaticVariable()); | ||
Expect.equals("Augment: Original", MA().instanceVariable()); | ||
Expect.equals("Augment: Original", MA().finalInstanceVariable()); | ||
Expect.equals("Augment: Original", E.staticVariable()); | ||
Expect.equals("Augment: Original", E.finalStaticVariable()); | ||
Expect.equals("Augment: Original", E.e1.finalInstanceVariable()); | ||
} |
82 changes: 82 additions & 0 deletions
82
LanguageFeatures/Augmentation-libraries/augmented_expression_A03_t02_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,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 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. | ||
/// | ||
/// It is a compile-time error to use augmented in an augmenting field's | ||
/// initializer if the member being augmented is not a field with an initializer | ||
/// | ||
/// @description Checks that within an augmenting field `augmented` invokes the | ||
/// original field's initializer expression. | ||
/// @author sgrekhov22@gmail.com | ||
// SharedOptions=--enable-experiment=macros | ||
|
||
augment library 'augmented_expression_A03_t02.dart'; | ||
|
||
augment var topLevelVariable = () { | ||
return "Augment: " + augmented(); | ||
}; | ||
augment final finalTopLevelVariable = () { | ||
return "Augment: " + augmented(); | ||
}; | ||
|
||
augment class C { | ||
augment static var staticVariable = () { | ||
return "Augment: " + augmented(); | ||
}; | ||
augment static final finalStaticVariable = () { | ||
return "Augment: " + augmented(); | ||
}; | ||
augment var instanceVariable = () { | ||
return "Augment: " + augmented(); | ||
}; | ||
augment final finalInstanceVariable = () { | ||
return "Augment: " + augmented(); | ||
}; | ||
} | ||
|
||
augment mixin M { | ||
augment static var staticVariable = () { | ||
return "Augment: " + augmented(); | ||
}; | ||
augment static final finalStaticVariable = () { | ||
return "Augment: " + augmented(); | ||
}; | ||
augment var instanceVariable = () { | ||
return "Augment: " + augmented(); | ||
}; | ||
augment final finalInstanceVariable = () { | ||
return "Augment: " + augmented(); | ||
}; | ||
} | ||
|
||
augment enum E { | ||
augment e1; | ||
|
||
augment static var staticVariable = () { | ||
return "Augment: " + augmented(); | ||
}; | ||
augment static final finalStaticVariable = () { | ||
return "Augment: " + augmented(); | ||
}; | ||
augment final finalInstanceVariable = () { | ||
return "Augment: " + augmented(); | ||
}; | ||
} | ||
|
||
augment extension Ext { | ||
augment static var staticVariable = () { | ||
return "Augment: " + augmented(); | ||
}; | ||
augment static final finalStaticVariable = () { | ||
return "Augment: " + augmented(); | ||
}; | ||
} |
66 changes: 66 additions & 0 deletions
66
LanguageFeatures/Augmentation-libraries/augmented_expression_A03_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,66 @@ | ||
// 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. | ||
/// | ||
/// It is a compile-time error to use augmented in an augmenting field's | ||
/// initializer if the member being augmented is not a field with an initializer | ||
/// | ||
/// @description Checks that it is a compile-time error to use `augmented()` | ||
/// within an augmenting field if the original field's initializer expression is | ||
/// not callable | ||
/// @author sgrekhov22@gmail.com | ||
// SharedOptions=--enable-experiment=macros | ||
|
||
import augment 'augmented_expression_A03_t03_lib.dart'; | ||
|
||
String augmented() => "Wrong augmented() call!"; | ||
|
||
String topLevelVariable = "Original"; | ||
final String finalTopLevelVariable = "Original"; | ||
|
||
class C { | ||
static String staticVariable = "Original"; | ||
static final String finalStaticVariable = "Original"; | ||
String instanceVariable = "Original"; | ||
final String finalInstanceVariable = "Original"; | ||
} | ||
|
||
mixin M { | ||
static String staticVariable = "Original"; | ||
static final String finalStaticVariable = "Original"; | ||
String instanceVariable = "Original"; | ||
final String finalInstanceVariable = "Original"; | ||
} | ||
|
||
enum E { | ||
e1; | ||
|
||
static String staticVariable = "Original"; | ||
static final String finalStaticVariable = "Original"; | ||
final String finalInstanceVariable = "Original"; | ||
} | ||
|
||
class A {} | ||
|
||
extension Ext on A { | ||
static String staticVariable = "Original"; | ||
static final String finalStaticVariable = "Original"; | ||
} | ||
|
||
main() { | ||
print(topLevelVariable); | ||
print(finalTopLevelVariable); | ||
print(C); | ||
print(M); | ||
print(E); | ||
print(A); | ||
} |
Oops, something went wrong.