Skip to content

Commit

Permalink
#2559. Add more augmented expression tests for local variables in fie…
Browse files Browse the repository at this point in the history
…ld initializers (#2634)
  • Loading branch information
sgrekhov committed May 2, 2024
1 parent bc72dc2 commit 802c5a6
Show file tree
Hide file tree
Showing 16 changed files with 987 additions and 2 deletions.
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);
}
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
};
}
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);
}
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
}
};
}
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);
}

0 comments on commit 802c5a6

Please sign in to comment.