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
@@ -0,0 +1,56 @@
// Copyright (c) 2025, 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 It is a compile-time error if:
/// ...
/// - The augmentation chain has exactly one specification of a default value
/// for an optional parameter, and the constructor is a redirecting factory.
///
/// @description Checks that it is a compile-time error if the augmentation
/// chain has exactly one specification of a default value for an optional
/// parameter, but the constructor is a redirecting factory.
/// @author sgrekhov22@gmail.com

// SharedOptions=--enable-experiment=augmentations

class C {
C([int x = 0]);
C._({int x = 0});
factory C.foo([int x]) = C;
factory C.bar({int x}) = C._;
}

augment class C {
augment factory C.foo([int x = 0]);
// ^^^^^
// [analyzer] unspecified
// [cfe] unspecified
augment factory C.bar({int x = 0});
// ^^^^^
// [analyzer] unspecified
// [cfe] unspecified
}

extension type ET(int x) {
ET.c1([this.x = 0]);
ET.c2({this.x = 0});
factory ET.foo([int x]) = ET.c1;
factory ET.bar({int x}) = ET.c2;
}

augment extension type ET {
augment ET.foo([int x = 0]);
// ^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
augment ET.bar({int x = 0});
// ^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
}

main() {
print(C);
print(ET);
}
124 changes: 124 additions & 0 deletions LanguageFeatures/Augmentations/augmenting_constructors_A06_t01.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
// Copyright (c) 2025, 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 It is a compile-time error if:
/// ...
/// - No declaration in the augmentation chain specifies a default value for an
/// optional parameter whose declared type is potentially non-nullable, and
/// the constructor is not a redirecting factory.
///
/// @description Checks that it is a compile-time error if no declaration in the
/// augmentation chain specifies a default value for an optional parameter whose
/// declared type is potentially non-nullable, and the constructor is not a
/// redirecting factory.
/// @author sgrekhov22@gmail.com

// SharedOptions=--enable-experiment=augmentations

class C {
C(int x);
C.c1([int x]);
// ^
// [analyzer] unspecified
// [cfe] unspecified
C.c2({int x});
// ^
// [analyzer] unspecified
// [cfe] unspecified
C.c3([int x]) : this(x);
// ^
// [analyzer] unspecified
// [cfe] unspecified
C.c4({int x}) : this(x);
// ^
// [analyzer] unspecified
// [cfe] unspecified
factory C.c5([int x]) => C(x);
// ^
// [analyzer] unspecified
// [cfe] unspecified
factory C.c6({int x}) => C(x);
// ^
// [analyzer] unspecified
// [cfe] unspecified
}

augment class C {
augment C.c1([int x]) {}
augment C.c2({int x}) {}
augment C.c3([int x]);
augment C.c4({int x});
augment factory C.c5([int x]);
augment factory C.c6({int x});
}

enum E {
e0(0);

const E(int x);
const E.c1([int x]);
// ^
// [analyzer] unspecified
// [cfe] unspecified
const E.c2({int x});
// ^
// [analyzer] unspecified
// [cfe] unspecified
const E.c3([int x]) : this(x);
// ^
// [analyzer] unspecified
// [cfe] unspecified
const E.c4({int x}) : this(x);
// ^
// [analyzer] unspecified
// [cfe] unspecified
}

augment enum E {
augment const E.c1([int x]) {}
augment const E.c2({int x}) {}
augment const E.c3([int x]);
augment const E.c4({int x});
}

extension type ET(int x) {
ET.c1([this.x]);
// ^
// [analyzer] unspecified
// [cfe] unspecified
ET.c2({this.x});
// ^
// [analyzer] unspecified
// [cfe] unspecified
ET.c3([int x]) : this(x);
// ^
// [analyzer] unspecified
// [cfe] unspecified
ET.c4({int x}) : this(x);
// ^
// [analyzer] unspecified
// [cfe] unspecified
factory ET.c5([int x]) => ET(x);
// ^
// [analyzer] unspecified
// [cfe] unspecified
factory ET.c6({int x}) => ET(x);
// ^
// [analyzer] unspecified
// [cfe] unspecified
}

augment extension type ET {
augment ET.c1([this.x]) {}
augment ET.c2({this.x}) {}
augment ET.c3([int x]);
augment ET.c4({int x});
augment factory ET.c5([int x]);
augment factory ET.c6({int x});
}

main() {
print(C);
print(ET);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// Copyright (c) 2025, 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 It is a compile-time error if:
/// ...
/// - A factory constructor is incomplete after all augmentations are applied.
///
/// @description Checks that it is a compile-time error if a factory constructor
/// is incomplete after all augmentations are applied.
/// @author sgrekhov22@gmail.com

// SharedOptions=--enable-experiment=augmentations

class C {
C(int x);
factory C.f1();
// ^^^^
// [analyzer] unspecified
// [cfe] unspecified
factory C.f2([int x]);
// ^^^^
// [analyzer] unspecified
// [cfe] unspecified
factory C.f3({int x});
// ^^^^
// [analyzer] unspecified
// [cfe] unspecified
}

augment class C {
augment factory C.f1();
augment factory C.f2([int x = 0]);
augment factory C.f3({int x = 0});
}

extension type ET(int x) {
factory ET.f1();
// ^^^^^
// [analyzer] unspecified
// [cfe] unspecified
factory ET.f2([int x]);
// ^^^^^
// [analyzer] unspecified
// [cfe] unspecified
factory ET.f3({int x});
// ^^^^^
// [analyzer] unspecified
// [cfe] unspecified
}

augment extension type ET {
augment factory ET.f1();
augment factory ET.f2([int x = 0]);
augment factory ET.f3({int x = 0});
}

main() {
print(C);
print(ET);
}
Loading