-
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 more augmented expression tests for local variables in fie…
…ld initializers (#2634)
- Loading branch information
Showing
16 changed files
with
987 additions
and
2 deletions.
There are no files selected for viewing
55 changes: 55 additions & 0 deletions
55
LanguageFeatures/Augmentation-libraries/augmented_expression_A03_t14.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 to declare a local | ||
/// function named `augmented()` in an augmenting field initializer | ||
/// @author sgrekhov22@gmail.com | ||
// SharedOptions=--enable-experiment=macros | ||
|
||
import augment 'augmented_expression_A03_t14_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); | ||
} |
80 changes: 80 additions & 0 deletions
80
LanguageFeatures/Augmentation-libraries/augmented_expression_A03_t14_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,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 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 declare a local | ||
/// function named `augmented()` in an augmenting field initializer | ||
/// @author sgrekhov22@gmail.com | ||
// SharedOptions=--enable-experiment=macros | ||
|
||
augment library 'augmented_expression_A03_t14.dart'; | ||
|
||
augment Function? topLevelVariable = () { | ||
int augmented() => 42; | ||
// ^^^^^^^^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
}; | ||
|
||
augment class C { | ||
augment static Function? staticVariable = () { | ||
int augmented() => 42; | ||
// ^^^^^^^^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
}; | ||
augment Function? instanceVariable = () { | ||
int augmented() => 42; | ||
// ^^^^^^^^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
}; | ||
} | ||
|
||
augment mixin M { | ||
augment static Function? staticVariable = () { | ||
int augmented() => 42; | ||
// ^^^^^^^^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
}; | ||
augment Function? instanceVariable = () { | ||
int augmented() => 42; | ||
// ^^^^^^^^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
}; | ||
} | ||
|
||
augment enum E { | ||
augment e1; | ||
augment static Function? staticVariable = () { | ||
int augmented() => 42; | ||
// ^^^^^^^^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
}; | ||
} | ||
|
||
augment extension Ext { | ||
augment static Function? staticVariable = () { | ||
int augmented() => 42; | ||
// ^^^^^^^^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
}; | ||
} |
56 changes: 56 additions & 0 deletions
56
LanguageFeatures/Augmentation-libraries/augmented_expression_A03_t15.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,56 @@ | ||
// 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 declare a local | ||
/// variable named `augmented` in an augmenting field initializer. Test a | ||
/// variable pattern. | ||
/// @author sgrekhov22@gmail.com | ||
// SharedOptions=--enable-experiment=macros | ||
|
||
import augment 'augmented_expression_A03_t15_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); | ||
} |
95 changes: 95 additions & 0 deletions
95
LanguageFeatures/Augmentation-libraries/augmented_expression_A03_t15_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,95 @@ | ||
// 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 declare a local | ||
/// variable named `augmented` in an augmenting field initializer. Test a | ||
/// variable pattern. | ||
/// @author sgrekhov22@gmail.com | ||
// SharedOptions=--enable-experiment=macros | ||
|
||
augment library 'augmented_expression_A03_t15.dart'; | ||
|
||
augment Function? topLevelVariable = () { | ||
switch((1,)) { | ||
case (var augmented,): | ||
// ^^^^^^^^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
} | ||
}; | ||
|
||
augment class C { | ||
augment static Function? staticVariable = () { | ||
switch((1,)) { | ||
case (var augmented,): | ||
// ^^^^^^^^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
} | ||
}; | ||
augment Function? instanceVariable = () { | ||
switch((1,)) { | ||
case (var augmented,): | ||
// ^^^^^^^^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
} | ||
}; | ||
} | ||
|
||
augment mixin M { | ||
augment static Function? staticVariable = () { | ||
switch((1,)) { | ||
case (var augmented,): | ||
// ^^^^^^^^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
} | ||
}; | ||
augment Function? instanceVariable = () { | ||
switch((1,)) { | ||
case (var augmented,): | ||
// ^^^^^^^^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
} | ||
}; | ||
} | ||
|
||
augment enum E { | ||
augment e1; | ||
augment static Function? staticVariable = () { | ||
switch((1,)) { | ||
case (var augmented,): | ||
// ^^^^^^^^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
} | ||
}; | ||
} | ||
|
||
augment extension Ext { | ||
augment static Function? staticVariable = () { | ||
switch((1,)) { | ||
case (var augmented,): | ||
// ^^^^^^^^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
} | ||
}; | ||
} |
56 changes: 56 additions & 0 deletions
56
LanguageFeatures/Augmentation-libraries/augmented_expression_A03_t16.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,56 @@ | ||
// 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 declare a local | ||
/// variable named `augmented` in an augmenting field initializer. Test a | ||
/// parenthesized pattern. | ||
/// @author sgrekhov22@gmail.com | ||
// SharedOptions=--enable-experiment=macros | ||
|
||
import augment 'augmented_expression_A03_t16_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); | ||
} |
Oops, something went wrong.