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,12 +2,8 @@
// 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 top-level function, static method, instance method, operator,
/// getter, or setter may be augmented to provide a body or add metadata.
/// ...
/// Augmenting constructors works similar to augmenting a function, with some
/// extra rules to handle features unique to constructors like redirections and
/// initializer lists.
/// @assertion An incomplete constructor can be completed by adding an
/// initializer list and/or a body, or by adding a redirection.
///
/// @description Checks that the augmenting constructor may provide a body.
/// @author [email protected]
Expand Down
54 changes: 35 additions & 19 deletions LanguageFeatures/Augmentations/augmenting_constructors_A11_t01.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,52 @@
// 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:
/// ...
/// - Add initializers (and/or asserts) to the initializer list, as well as a
/// `super` call at the end of the initializer list.
/// @assertion An incomplete constructor can be completed by adding an
/// initializer list and/or a body, or by adding a redirection.
///
/// @description Checks that augmenting constructor may add initializers to the
/// initializer list.
/// @description Checks that augmenting constructor may add initializer list and
/// the body.
/// @author [email protected]

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

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

class C {
String x, y;
C(): x = "Original";
String x = "Original", y;
C();
}

augment class C {
augment C(): y = "Augmented" {
Expect.equals("Original", x);
Expect.equals("Augmented", y);
x = "x";
y = "y";
}
}

enum E {
e0;
final String x, y;
const E(): x = "Original";
final String x = "Original", y;
const E();
}

augment enum E {
augment const E(): y = "Augmented";
}

bool executed = false;

extension type ET(int v) {
ET.foo() : v = 0;
ET.foo();
}

augment extension type ET {
augment ET.foo() : v = 0 {
Expect.equals(0, v);
executed = true;
}
}

main() {
Expand All @@ -39,9 +57,7 @@ main() {

Expect.equals("Original", E.e0.x);
Expect.equals("Augmented", E.e0.y);
if (assertStatementsEnabled) {
Expect.throws(() {
ET.foo();
});
}

Expect.equals(0, ET.foo().v);
Expect.isTrue(executed);
}

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@
// 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:
/// ...
/// - Add initializers (and/or asserts) to the initializer list, as well as a
/// `super` call at the end of the initializer list.
/// @assertion The general rule is that compile-time errors apply to semantic
/// definitions whenever possible. In other words, if the library is
/// syntactically well-formed enough that augmentations can be applied, then
/// they should be. And if doing so eliminates what would otherwise be a
/// compile-time error, then that error should not be reported.
///
/// @description Checks that it is still a compile-time error if the augmenting
/// constructor has a super-initializer not at the last position in the
/// initializer list.
/// @author [email protected]

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

class A {
int x;
Expand Down

This file was deleted.

Loading
Loading