Skip to content

Commit

Permalink
dart-lang#2559. Make more augmented expression tests stronger
Browse files Browse the repository at this point in the history
  • Loading branch information
sgrekhov committed May 1, 2024
1 parent 6066581 commit 56f915c
Show file tree
Hide file tree
Showing 6 changed files with 158 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,29 +25,33 @@
import augment 'augmented_expression_A03_t07_lib.dart';
import '../../Utils/expect.dart';

final String augmented = "Augmented variable, should not be used";
const augmented = "Augmented constant, should not be used";

String? topLevelVariable;

class C {
static String? staticVariable;
String? instanceVariable;
final augmented = "C.augmented, should not be used";
}

mixin M {
static String? staticVariable;
String? instanceVariable;
final augmented = "M.augmented, should not be used";
}

enum E {
e1;
static String? staticVariable;
static final augmented = "E.augmented, should not be used";
}

class A {}

extension Ext on A {
static String? staticVariable;
static final augmented = "Ext.augmented, should not be used";
}

class MA = Object with M;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,29 +25,33 @@
import augment 'augmented_expression_A03_t08_lib.dart';
import '../../Utils/expect.dart';

final String augmented = "Augmented variable, should not be used";
const augmented = "Augmented constant, should not be used";

Function? topLevelVariable;

class C {
static Function? staticVariable;
Function? instanceVariable;
static final augmented = "C.augmented, should not be used";
}

mixin M {
static Function? staticVariable;
Function? instanceVariable;
static final augmented = "M.augmented, should not be used";
}

enum E {
e1;
static Function? staticVariable;
static final augmented = "E.augmented, should not be used";
}

class A {}

extension Ext on A {
static Function? staticVariable;
static final augmented = "Ext.augmented, should not be used";
}

class MA = Object with M;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,19 @@

import augment 'augmented_expression_A03_t10_lib.dart';

final String augmented = "Augmented variable, should not be used";
const augmented = "Augmented constant, should not be used";

class C {
String instanceVariable;
final String finalInstanceVariable;
final augmented = "C.augmented, should not be used";
C(this.instanceVariable, this.finalInstanceVariable);
}

enum E {
e1("x");
final String finalInstanceVariable;
final augmented = "E.augmented, should not be used";
const E(this.finalInstanceVariable);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,12 @@

import augment 'augmented_expression_A03_t11_lib.dart';

final String augmented = "Augmented variable, should not be used";
const augmented = "Augmented constant, should not be used";

class C {
Function instanceVariable;
final Function finalInstanceVariable;
final augmented = "C.augmented, should not be used";
C(this.instanceVariable, this.finalInstanceVariable);
}

Expand All @@ -37,6 +38,7 @@ void foo() {}
enum E {
e1(foo);
final Function finalInstanceVariable;
final augmented = "E.augmented, should not be used";
const E(this.finalInstanceVariable);
}

Expand Down
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);
}
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";
};
}

0 comments on commit 56f915c

Please sign in to comment.