Skip to content
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
Expand Up @@ -2,56 +2,61 @@
// 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 A non-redirecting generative constructor marked `augment` may:
/// ...
/// - If the augmenting constructor has an explicit block body, then that body
/// replaces any existing constructor body.
/// @assertion At a high level, a non-redirecting generative constructor marked
/// `augment` may:
/// - Augment the constructor with an additional constructor body (bodies are
/// invoked in augmentation order, starting at the introductory declaration).
///
/// @description Checks that if the augmenting constructor has an explicit block
/// body, then that body replaces any existing constructor body.
/// body, then that body is executed after the body of the introductory
/// constructor.
/// @author sgrekhov22@gmail.com

// SharedOptions=--enable-experiment=macros

import '../../Utils/expect.dart';
part 'augmenting_constructors_A09_t01_lib.dart';

String _log = "";
String log = "";

class C1 {
C1() {
_log += "Original";
log += "Original;";
}
}

class C2 {
C2() {
_log += "Original";
log += "Original;";
}
}

class C3 {
C3.new() {
_log += "Original";
log += "Original;";
}
}

extension type ET(int id) {
ET.foo(this.id) {
_log += "Original";
log += "Original;";
}
}

void checkLog(String expected) {
Expect.equals(expected, log);
log = "";
}

main() {
C1();
Expect.equals("Augmented", _log);
_log = "";
checkLog("Original;Augmented");
C2();
Expect.equals("Augmented", _log);
_log = "";
checkLog("Original;Augmented");
C3();
Expect.equals("Augmented", _log);
_log = "";
checkLog("Original;Augmented");
ET(0);
Expect.equals("Augmented", _log);
checkLog("Augmented");
ET.foo(0);
checkLog("Original;Augmented");
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@
// 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 A non-redirecting generative constructor marked `augment` may:
/// ...
/// - If the augmenting constructor has an explicit block body, then that body
/// replaces any existing constructor body.
/// @assertion At a high level, a non-redirecting generative constructor marked
/// `augment` may:
/// - Augment the constructor with an additional constructor body (bodies are
/// invoked in augmentation order, starting at the introductory declaration).
///
/// @description Checks that if the augmenting constructor has an explicit block
/// body, then that body replaces any existing constructor body.
/// body, then that body is executed after the body of the introductory
/// constructor.
/// @author sgrekhov22@gmail.com

// SharedOptions=--enable-experiment=macros
Expand All @@ -17,24 +18,27 @@ part of 'augmenting_constructors_A09_t01.dart';

augment class C1 {
augment C1() {
_log += "Augmented";
log += "Augmented";
}
}

augment class C2 {
augment C2.new() {
_log += "Augmented";
log += "Augmented";
}
}

augment class C3 {
augment C3() {
_log += "Augmented";
log += "Augmented";
}
}

augment extension type ET {
augment ET(int id) {
log += "Augmented";
}
augment ET.foo(this.id) {
_log += "Augmented";
log += "Augmented";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
// 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 A non-redirecting generative constructor marked `augment` may:
/// - Add or replace the body of the augmented constructor with a new body.
/// @assertion At a high level, a non-redirecting generative constructor marked
/// `augment` may:
/// - Augment the constructor with an additional constructor body (bodies are
/// invoked in augmentation order, starting at the introductory declaration).
///
/// @description Checks that an augmenting constructor may add a body to an
/// augmented constructor.
Expand All @@ -14,7 +16,7 @@
import '../../Utils/expect.dart';
part 'augmenting_constructors_A09_t02_lib.dart';

String _log = "";
String log = "";

class C1 {
C1();
Expand All @@ -32,16 +34,20 @@ extension type ET(int id) {
ET.foo(this.id);
}

void checkLog(String expected) {
Expect.equals(expected, log);
log = "";
}

main() {
C1();
Expect.equals("Augmented", _log);
_log = "";
checkLog("Augmented");
C2();
Expect.equals("Augmented", _log);
_log = "";
checkLog("Augmented");
C3();
Expect.equals("Augmented", _log);
_log = "";
checkLog("Augmented");
ET(0);
Expect.equals("Augmented", _log);
checkLog("Augmented");
ET.foo(0);
checkLog("Augmented");
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
// 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 A non-redirecting generative constructor marked `augment` may:
/// - Add or replace the body of the augmented constructor with a new body.
/// @assertion At a high level, a non-redirecting generative constructor marked
/// `augment` may:
/// - Augment the constructor with an additional constructor body (bodies are
/// invoked in augmentation order, starting at the introductory declaration).
///
/// @description Checks that an augmenting constructor may add a body to an
/// augmented constructor.
Expand All @@ -15,24 +17,27 @@ part of 'augmenting_constructors_A09_t02.dart';

augment class C1 {
augment C1() {
_log += "Augmented";
log += "Augmented";
}
}

augment class C2 {
augment C2.new() {
_log += "Augmented";
log += "Augmented";
}
}

augment class C3 {
augment C3() {
_log += "Augmented";
log += "Augmented";
}
}

augment extension type ET {
augment ET.new(int id) {
log += "Augmented";
}
augment ET.foo(this.id) {
_log += "Augmented";
log += "Augmented";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
// 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 A non-redirecting generative constructor marked `augment` may:
/// - Add or replace the body of the augmented constructor with a new body.
/// @assertion At a high level, a non-redirecting generative constructor marked
/// `augment` may:
/// - Augment the constructor with an additional constructor body (bodies are
/// invoked in augmentation order, starting at the introductory declaration).
///
/// @description Checks that it is a compile-time error to augment a default
/// unnamed constructor (that doesn't exist during augmentation).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
// 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 A non-redirecting generative constructor marked `augment` may:
/// - Add or replace the body of the augmented constructor with a new body.
/// @assertion At a high level, a non-redirecting generative constructor marked
/// `augment` may:
/// - Augment the constructor with an additional constructor body (bodies are
/// invoked in augmentation order, starting at the introductory declaration).
///
/// @description Checks that it is a compile-time error to augment a default
/// unnamed constructor (that doesn't exist during augmentation).
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// 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 At a high level, a non-redirecting generative constructor marked
/// `augment` may:
/// - Augment the constructor with an additional constructor body (bodies are
/// invoked in augmentation order, starting at the introductory declaration).
///
/// @description Checks that it is not an error if an augmenting constructor has
/// no body.
/// @author sgrekhov22@gmail.com

// SharedOptions=--enable-experiment=macros

import '../../Utils/expect.dart';

class C {
int v;
C() : v = 0;
C.id(this.v) {
v++;
}
}

augment class C {
augment C();
augment C.id(this.v);
}

enum E {
e0, e1.id();
const E();
const E.id();
}

augment enum E {
e2;
augment const E();
augment const E.id();
}

extension type ET(int v) {
ET.foo(this.v) {
assert(v > 0);
}
}

augment extension type ET {
augment ET(int v);
augment ET.foo(this.v);
}

main() {
Expect.equals(0, C().v);
Expect.equals(2, C.id(1).v);
Expect.equals(1, ET(1).v);
Expect.equals(2, ET.foo(2).v);
if (assertStatementsEnabled) {
Expect.throws(() {
ET.foo(0);
});
}
}
Loading
Loading