Skip to content
Open
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
102 changes: 47 additions & 55 deletions LanguageFeatures/Augmentations/augmenting_functions_A02_t01.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,73 +2,65 @@
// 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 Inside the augmenting function’s body, a special `augmented(…)`
/// expression may be used to execute the augmented function body. That
/// expression takes an argument list matching the augmented function's
/// parameter list, and it has the same return type as the enclosing function.
/// @assertion More precisely, a function or constructor declaration
/// (introductory or augmenting) is incomplete if all of:
/// - It has no body. That means no `{ ... }` or `=> ...;` but only `;`.
/// - The function is not marked external. An external function is considered to
/// have a body, just not one that is visible as Dart code.
/// - There is no redirection, initializer list, initializing formals, field
/// parameters, or super parameters. Obviously, this only applies to
/// constructor declarations.
///
/// @description Checks that inside an augmentation body of a top-level function
/// `augmented()` expression executes the original function body.
/// If a declaration is not incomplete then it is complete.
///
/// It's a compile-time error if an augmentation is complete and any declaration
/// before it in the augmentation chain is also complete.
///
/// @description Checks that it is a compile-time error to add a body to an
/// already complete top level function.
/// @author sgrekhov22@gmail.com

// SharedOptions=--enable-experiment=macros

import '../../Utils/expect.dart';
part 'augmenting_functions_A02_t01_lib.dart';
// SharedOptions=--enable-experiment=augmentations

String _log = "";
void topLevelFunction1() {}

void clearLog() {
_log = "";
}

String topLevelFunction1() {
_log += "topLevelFunction1();";
return "Original;";
}
augment void topLevelFunction1() {}
// ^
// [analyzer] unspecified
// [cfe] unspecified

String topLevelFunction2(String v) {
_log += "topLevelFunction2($v);";
return "Original v=$v;";
}
void topLevelFunction2(String v) {}

String topLevelFunction3(String v1, [String v2 = "v2 def"]) {
_log += "topLevelFunction3($v1, [$v2]);";
return "Original v1=$v1, [v2=$v2];";
}
augment void topLevelFunction2(String v) {}
// ^
// [analyzer] unspecified
// [cfe] unspecified

String topLevelFunction4(String v1, {String v2 = "v2 def"}) {
_log += "topLevelFunction4($v1, {$v2});";
return "Original v1=$v1, {v2=$v2};";
}
void topLevelFunction3(String v1, [String v2 = "v2 def"]) {}

String topLevelFunction5(String v1, {required String v2}) {
_log += "topLevelFunction5($v1, {required $v2});";
return "Original v1=$v1, {required v2=$v2};";
}
augment void topLevelFunction3(String v1, [String v2 = "v2 def"]) {}
// ^
// [analyzer] unspecified
// [cfe] unspecified

main() {
Expect.equals("augment;", topLevelFunction1());
Expect.equals("topLevelFunction1();Original;augmented;", _log);
clearLog();
void topLevelFunction4(String v1, {String v2 = "v2 def"}) {}

Expect.equals("augment v=A;", topLevelFunction2("A"));
Expect.equals("topLevelFunction2(A);Original v=A;augmented;", _log);
clearLog();
augment void topLevelFunction4(String v1, {String v2 = "v2 def"}) {}
// ^
// [analyzer] unspecified
// [cfe] unspecified

Expect.equals("augment v1=B, [v2=C]", topLevelFunction3("B", "C"));
Expect.equals("topLevelFunction3(B, [C]);Original v1=B, [v2=C];augmented;",
_log);
clearLog();
void topLevelFunction5(String v1, {required String v2}) {}

Expect.equals("augment v1=D, {v2=E}", topLevelFunction4("D", v2: "E"));
Expect.equals("topLevelFunction4(D, {E});Original v1=D, {v2=E};augmented;",
_log);
clearLog();
augment void topLevelFunction5(String v1, {required String v2}) {}
// ^
// [analyzer] unspecified
// [cfe] unspecified

Expect.equals("augment v1=F, {required v2=G}",
topLevelFunction5("F", v2: "G"));
Expect.equals(
"topLevelFunction5(F, {required G});Original v1=F, {required v2=G};" +
"augmented;", _log);
main() {
print(topLevelFunction1);
print(topLevelFunction2);
print(topLevelFunction3);
print(topLevelFunction4);
print(topLevelFunction5);
}

This file was deleted.

119 changes: 68 additions & 51 deletions LanguageFeatures/Augmentations/augmenting_functions_A02_t02.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,72 +2,89 @@
// 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 Inside the augmenting function’s body, a special `augmented(…)`
/// expression may be used to execute the augmented function body. That
/// expression takes an argument list matching the augmented function's
/// parameter list, and it has the same return type as the enclosing function.
/// @assertion More precisely, a function or constructor declaration
/// (introductory or augmenting) is incomplete if all of:
/// - It has no body. That means no `{ ... }` or `=> ...;` but only `;`.
/// - The function is not marked external. An external function is considered to
/// have a body, just not one that is visible as Dart code.
/// - There is no redirection, initializer list, initializing formals, field
/// parameters, or super parameters. Obviously, this only applies to
/// constructor declarations.
///
/// @description Checks that inside an augmentation body of a static method
/// `augmented()` expression executes the original method body. Test a class.
/// If a declaration is not incomplete then it is complete.
///
/// It's a compile-time error if an augmentation is complete and any declaration
/// before it in the augmentation chain is also complete.
///
/// @description Checks that it is a compile-time error to add a body to an
/// already complete static method.
/// @author sgrekhov22@gmail.com

// SharedOptions=--enable-experiment=macros
// SharedOptions=--enable-experiment=augmentations

import '../../Utils/expect.dart';
part 'augmenting_functions_A02_t02_lib.dart';
class C {
static void staticMethod() {}
}

String _log = "";
augment class C {
augment static void staticMethod() {}
// ^
// [analyzer] unspecified
// [cfe] unspecified
}

void clearLog() {
_log = "";
mixin M {
static void staticMethod() {}
}

class C {
static String staticMethod1() {
_log += "staticMethod1();";
return "Original;";
}
augment mixin M {
augment static void staticMethod() {}
// ^
// [analyzer] unspecified
// [cfe] unspecified
}

static String staticMethod2(String v) {
_log += "staticMethod2($v);";
return "Original v=$v;";
}
enum E {
e0;
static void staticMethod() {}
}

static String staticMethod3(String v1, [String v2 = "v2 def"]) {
_log += "staticMethod3($v1, [$v2]);";
return "Original v1=$v1, [v2=$v2];";
}
augment enum E {
;
augment static void staticMethod() {}
// ^
// [analyzer] unspecified
// [cfe] unspecified
}

static String staticMethod4(String v1, {String v2 = "v2 def"}) {
_log += "staticMethod4($v1, {$v2});";
return "Original v1=$v1, {v2=$v2};";
}
class A {}

static String staticMethod5(String v1, {required String v2}) {
_log += "staticMethod5($v1, {required $v2});";
return "Original v1=$v1, {required v2=$v2};";
}
extension Ext on A {
static void staticMethod() {}
}

main() {
Expect.equals("augment;", C.staticMethod1());
Expect.equals("staticMethod1();Original;augmented;", _log);
clearLog();

Expect.equals("augment v=A;", C.staticMethod2("A"));
Expect.equals("staticMethod2(A);Original v=A;augmented;", _log);
clearLog();
augment extension Ext {
augment static void staticMethod() {}
// ^
// [analyzer] unspecified
// [cfe] unspecified
}

Expect.equals("augment v1=B, [v2=C]", C.staticMethod3("B", "C"));
Expect.equals("staticMethod3(B, [C]);Original v1=B, [v2=C];augmented;", _log);
clearLog();
extension type ET(int _) {
static void staticMethod() {}
}

Expect.equals("augment v1=D, {v2=E}", C.staticMethod4("D", v2: "E"));
Expect.equals("staticMethod4(D, {E});Original v1=D, {v2=E};augmented;", _log);
clearLog();
augment extension type ET {
augment static void staticMethod() {}
// ^
// [analyzer] unspecified
// [cfe] unspecified
}

Expect.equals("augment v1=F, {required v2=G}", C.staticMethod5("F", v2: "G"));
Expect.equals(
"staticMethod5(F, {required G});Original v1=F, {required v2=G};" +
"augmented;", _log);
main() {
print(C);
print(M);
print(E);
print(A);
print(ET);
}

This file was deleted.

Loading
Loading