-
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 augmenting expression tests for fields with no initializers (
#2626) Add augmenting expression tests for fields with no initializers
- Loading branch information
Showing
8 changed files
with
418 additions
and
0 deletions.
There are no files selected for viewing
63 changes: 63 additions & 0 deletions
63
LanguageFeatures/Augmentation-libraries/augmented_expression_A03_t07.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,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 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 if an `augmented` is used in an augmenting field's | ||
/// initializer and the member being augmented is a nullable field with no | ||
/// initializer then `augmented` evaluates to `null`. | ||
/// @author sgrekhov22@gmail.com | ||
// SharedOptions=--enable-experiment=macros | ||
|
||
import augment 'augmented_expression_A03_t07_lib.dart'; | ||
import '../../Utils/expect.dart'; | ||
|
||
final String augmented = "Augmented variable, should not be used"; | ||
|
||
String? topLevelVariable; | ||
|
||
class C { | ||
static String? staticVariable; | ||
String? instanceVariable; | ||
} | ||
|
||
mixin M { | ||
static String? staticVariable; | ||
String? instanceVariable; | ||
} | ||
|
||
enum E { | ||
e1; | ||
static String? staticVariable; | ||
} | ||
|
||
class A {} | ||
|
||
extension Ext on A { | ||
static String? staticVariable; | ||
} | ||
|
||
class MA = Object with M; | ||
|
||
main() { | ||
Expect.equals("Augment: null", topLevelVariable); | ||
Expect.equals("Augment: null", C.staticVariable); | ||
Expect.equals("Augment: null", C().instanceVariable); | ||
Expect.equals("Augment: null", M.staticVariable); | ||
Expect.equals("Augment: null", MA().instanceVariable); | ||
Expect.equals("Augment: null", E.staticVariable); | ||
Expect.equals("Augment: null", Ext.staticVariable); | ||
} |
47 changes: 47 additions & 0 deletions
47
LanguageFeatures/Augmentation-libraries/augmented_expression_A03_t07_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,47 @@ | ||
// 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 if an `augmented` is used in an augmenting field's | ||
/// initializer and the member being augmented is a nullable field with no | ||
/// initializer then `augmented` evaluates to `null`. | ||
/// @author sgrekhov22@gmail.com | ||
// SharedOptions=--enable-experiment=macros | ||
|
||
augment library 'augmented_expression_A03_t07.dart'; | ||
|
||
augment String? topLevelVariable = "Augment: $augmented"; | ||
|
||
augment class C { | ||
augment static String? staticVariable = "Augment: $augmented"; | ||
augment String? instanceVariable = "Augment: $augmented"; | ||
} | ||
|
||
augment mixin M { | ||
augment static String? staticVariable = "Augment: $augmented"; | ||
augment String? instanceVariable = "Augment: $augmented"; | ||
} | ||
|
||
augment enum E { | ||
augment e1; | ||
|
||
augment static String? staticVariable = "Augment: $augmented"; | ||
} | ||
|
||
augment extension Ext { | ||
augment static String? staticVariable = "Augment: $augmented"; | ||
} |
63 changes: 63 additions & 0 deletions
63
LanguageFeatures/Augmentation-libraries/augmented_expression_A03_t08.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,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 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 if an `augmented` is used in an augmenting field's | ||
/// initializer and the member being augmented is a nullable field with no | ||
/// initializer then `augmented` evaluates to `null`. | ||
/// @author sgrekhov22@gmail.com | ||
// SharedOptions=--enable-experiment=macros | ||
|
||
import augment 'augmented_expression_A03_t08_lib.dart'; | ||
import '../../Utils/expect.dart'; | ||
|
||
final String augmented = "Augmented variable, should not be used"; | ||
|
||
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; | ||
} | ||
|
||
class MA = Object with M; | ||
|
||
main() { | ||
Expect.equals("Augment: null", topLevelVariable()); | ||
Expect.equals("Augment: null", C.staticVariable()); | ||
Expect.equals("Augment: null", C().instanceVariable()); | ||
Expect.equals("Augment: null", M.staticVariable()); | ||
Expect.equals("Augment: null", MA().instanceVariable()); | ||
Expect.equals("Augment: null", E.staticVariable()); | ||
Expect.equals("Augment: null", Ext.staticVariable()); | ||
} |
60 changes: 60 additions & 0 deletions
60
LanguageFeatures/Augmentation-libraries/augmented_expression_A03_t08_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,60 @@ | ||
// 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 if an `augmented` is used in an augmenting field's | ||
/// initializer and the member being augmented is a nullable field with no | ||
/// initializer then `augmented` evaluates to `null`. | ||
/// @author sgrekhov22@gmail.com | ||
// SharedOptions=--enable-experiment=macros | ||
|
||
augment library 'augmented_expression_A03_t08.dart'; | ||
|
||
augment Function? topLevelVariable = () { | ||
return "Augment: $augmented"; | ||
}; | ||
|
||
augment class C { | ||
augment static Function? staticVariable = () { | ||
return "Augment: $augmented"; | ||
}; | ||
augment Function? instanceVariable = () { | ||
return "Augment: $augmented"; | ||
}; | ||
} | ||
|
||
augment mixin M { | ||
augment static Function? staticVariable = () { | ||
return "Augment: $augmented"; | ||
}; | ||
augment Function? instanceVariable = () { | ||
return "Augment: $augmented"; | ||
}; | ||
} | ||
|
||
augment enum E { | ||
augment e1; | ||
augment static Function? staticVariable = () { | ||
return "Augment: $augmented"; | ||
}; | ||
} | ||
|
||
augment extension Ext { | ||
augment static Function? staticVariable = () { | ||
return "Augment: $augmented"; | ||
}; | ||
} |
44 changes: 44 additions & 0 deletions
44
LanguageFeatures/Augmentation-libraries/augmented_expression_A03_t10.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,44 @@ | ||
// 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 to use `augmented` in an | ||
/// augmenting field's initializer if the member being augmented is not a field | ||
/// with an initializer and the variable's type is not-nullable | ||
/// @author sgrekhov22@gmail.com | ||
// SharedOptions=--enable-experiment=macros | ||
|
||
import augment 'augmented_expression_A03_t10_lib.dart'; | ||
|
||
final String augmented = "Augmented variable, should not be used"; | ||
|
||
class C { | ||
String instanceVariable; | ||
final String finalInstanceVariable; | ||
C(this.instanceVariable, this.finalInstanceVariable); | ||
} | ||
|
||
enum E { | ||
e1("x"); | ||
final String finalInstanceVariable; | ||
const E(this.finalInstanceVariable); | ||
} | ||
|
||
main() { | ||
print(C); | ||
print(E); | ||
} |
45 changes: 45 additions & 0 deletions
45
LanguageFeatures/Augmentation-libraries/augmented_expression_A03_t10_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,45 @@ | ||
// 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 to use `augmented` in an | ||
/// augmenting field's initializer if the member being augmented is not a field | ||
/// with an initializer and the variable's type is not-nullable | ||
/// @author sgrekhov22@gmail.com | ||
// SharedOptions=--enable-experiment=macros | ||
|
||
augment library 'augmented_expression_A03_t10.dart'; | ||
|
||
augment class C { | ||
augment String instanceVariable = "Augment: $augmented"; | ||
// ^^^^^^^^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
augment final String finalInstanceVariable = "Augment: $augmented"; | ||
// ^^^^^^^^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
} | ||
|
||
augment enum E { | ||
augment e1("x"); | ||
|
||
augment final String finalInstanceVariable = "Augment: $augmented"; | ||
// ^^^^^^^^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
} |
46 changes: 46 additions & 0 deletions
46
LanguageFeatures/Augmentation-libraries/augmented_expression_A03_t11.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,46 @@ | ||
// 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 to use `augmented` in an | ||
/// augmenting field's initializer if the member being augmented is not a field | ||
/// with an initializer and the variable's type is not-nullable | ||
/// @author sgrekhov22@gmail.com | ||
// SharedOptions=--enable-experiment=macros | ||
|
||
import augment 'augmented_expression_A03_t11_lib.dart'; | ||
|
||
final String augmented = "Augmented variable, should not be used"; | ||
|
||
class C { | ||
Function instanceVariable; | ||
final Function finalInstanceVariable; | ||
C(this.instanceVariable, this.finalInstanceVariable); | ||
} | ||
|
||
void foo() {} | ||
|
||
enum E { | ||
e1(foo); | ||
final Function finalInstanceVariable; | ||
const E(this.finalInstanceVariable); | ||
} | ||
|
||
main() { | ||
print(C); | ||
print(E); | ||
} |
Oops, something went wrong.