Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#2559. Add more test cases for augmented expression #2738

Merged
merged 4 commits into from
Jul 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 getters: Within an augmenting getter `augmented` invokes the
/// getter and evaluates to the return value. If augmenting a field with a
/// getter, this will invoke the implicit getter from the augmented field.
///
/// @description Checks that it is a compile-time error to call a function which
/// has a named formal parameter with the name `augmented` in the body of an
/// augmenting getter.
/// @author sgrekhov22@gmail.com

// SharedOptions=--enable-experiment=macros

import augment 'augmented_expression_A01_t21_lib.dart';

int foo({int augmented = 0}) => augmented + 42;

String get topLevelGetter => "Original";

class C {
static String get staticGetter => "Original";
String get instanceGetter => "Original";
}

mixin M {
static String get staticGetter => "Original";
String get instanceGetter => "Original";
}

enum E {
e1;

static String get staticGetter => "Original";
String get instanceGetter => "Original";
}

class A {}

extension Ext on A {
static String get staticGetter => "Original";
String get instanceGetter => "Original";
}

main() {
print(topLevelGetter);
print(C);
print(M);
print(E);
print(A);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
// 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 getters: Within an augmenting getter `augmented` invokes the
/// getter and evaluates to the return value. If augmenting a field with a
/// getter, this will invoke the implicit getter from the augmented field.
///
/// @description Checks that it is a compile-time error to call a function which
/// has a named formal parameter with the name `augmented` in the body of an
/// augmenting getter.
/// @author sgrekhov22@gmail.com

// SharedOptions=--enable-experiment=macros

augment library 'augmented_expression_A01_t21.dart';

augment String get topLevelGetter {
foo(); // Ok
foo(augmented: 1);
// ^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
return "Augmented";
}

augment class C {
augment static String get staticGetter {
foo(); // Ok
foo(augmented: 1);
// ^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
return "Augmented";
}

augment String get instanceGetter {
foo(); // Ok
foo(augmented: 1);
// ^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
return "Augmented";
}
}

augment mixin M {
augment static String get staticGetter {
foo(); // Ok
foo(augmented: 1);
// ^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
return "Augmented";
}

augment String get instanceGetter {
foo(); // Ok
foo(augmented: 1);
// ^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
return "Augmented";
}
}

augment enum E1 {
e1;

augment static String get staticGetter {
foo(); // Ok
foo(augmented: 1);
// ^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
return "Augmented";
}

augment String get instanceGetter {
foo(); // Ok
foo(augmented: 1);
// ^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
return "Augmented";
}
}

augment extension Ext1 {
augment static String get staticGetter {
foo(); // Ok
foo(augmented: 1);
// ^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
return "Augmented";
}

augment String get instanceGetter {
foo(); // Ok
foo(augmented: 1);
// ^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
return "Augmented";
}
}
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 getters: Within an augmenting getter `augmented` invokes the
/// getter and evaluates to the return value. If augmenting a field with a
/// getter, this will invoke the implicit getter from the augmented field.
///
/// @description Checks that it is a compile-time error to use a record which
/// has a field with the name `augmented` in a body of an augmenting getter.
/// @author sgrekhov22@gmail.com

// SharedOptions=--enable-experiment=macros

import augment 'augmented_expression_A01_t22_lib.dart';

String get topLevelGetter => "Original";

class C {
static String get staticGetter => "Original";
String get instanceGetter => "Original";
}

mixin M {
static String get staticGetter => "Original";
String get instanceGetter => "Original";
}

enum E {
e1;

static String get staticGetter => "Original";
String get instanceGetter => "Original";
}

class A {}

extension Ext on A {
static String get staticGetter => "Original";
String get instanceGetter => "Original";
}

main() {
print(topLevelGetter);
print(C);
print(M);
print(E);
print(A);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
// 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 getters: Within an augmenting getter `augmented` invokes the
/// getter and evaluates to the return value. If augmenting a field with a
/// getter, this will invoke the implicit getter from the augmented field.
///
/// @description Checks that it is a compile-time error to use a record which
/// has a field with the name `augmented` in a body of an augmenting getter.
/// @author sgrekhov22@gmail.com

// SharedOptions=--enable-experiment=macros

augment library 'augmented_expression_A01_t22.dart';

augment String get topLevelGetter {
print((augmented: 1));
// ^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
return "Augmented";
}

augment class C {
augment static String get staticGetter {
print((augmented: 1));
// ^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
return "Augmented";
}

augment String get instanceGetter {
print((augmented: 1));
// ^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
return "Augmented";
}
}

augment mixin M {
augment static String get staticGetter {
print((augmented: 1));
// ^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
return "Augmented";
}

augment String get instanceGetter {
print((augmented: 1));
// ^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
return "Augmented";
}
}

augment enum E1 {
e1;

augment static String get staticGetter {
print((augmented: 1));
// ^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
return "Augmented";
}

augment String get instanceGetter {
print((augmented: 1));
// ^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
return "Augmented";
}
}

augment extension Ext1 {
augment static String get staticGetter {
print((augmented: 1));
// ^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
return "Augmented";
}

augment String get instanceGetter {
print((augmented: 1));
// ^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
return "Augmented";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ augment mixin M2 {
}

augment enum E1 {
e1;
augment e1;
augment static void set augmented(String value) {}
// ^^^^^^^^^
// [analyzer] unspecified
Expand Down
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 setters: Within an augmenting setter `augmented` must be
/// followed by an `=` and will directly invoke the augmented setter. If
/// augmenting a field with a setter, this will invoke the implicit setter
/// from the augmented field.
///
/// @description Checks that it is a compile-time error to call a function which
/// has a named formal parameter with the name `augmented` in the body of an
/// augmenting setter.
/// @author sgrekhov22@gmail.com

// SharedOptions=--enable-experiment=macros

import augment 'augmented_expression_A02_t20_lib.dart';

int foo({int augmented = 0}) => augmented + 42;

void set topLevelSetter(String _) {}

class C {
static void set staticSetter(String _) {}
void set instanceSetter(String _) {}
}

mixin M {
static void set staticSetter(String _) {}
void set instanceSetter(String _) {}
}

enum E {
e1;

static void set staticSetter(String _) {}
void set instanceSetter(String _) {}
}

class A {}

extension Ext on A {
static void set staticSetter(String _) {}
void set instanceSetter(String _) {}
}

main() {
print(C);
print(M);
print(E);
print(A);
}
Loading