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 @@ -5,11 +5,13 @@
/// @description Common library for augmentation tests.
/// @author sgrekhov22@gmail.com

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

library augmentation_libraries_lib;

class AL {}
class AL {
const AL();
}

final class FinalClass {}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
// 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 We say that an augmenting function or constructor's signature
/// matches if:
/// - It has the same number of type parameters with the same type parameter
/// names (same identifiers) and bounds (after type annotation inheritance),
/// if any (same types, even if they may not be written exactly the same in
/// case one of the declarations needs to refer to a type using an import
/// prefix).
/// - The return type (if not omitted) is the same as the augmented
/// declaration's return type.
/// - It has the same number of positional and optional parameters as the
/// augmented declaration.
/// - It has the same set of named parameter names as the augmented declaration.
/// - For all corresponding pairs of parameters:
/// - They have the same type (if not omitted in the augmenting declaration).
/// - They have the same `required` and `covariant` modifiers.
/// - For all positional parameters:
/// - The augmenting function's parameter name is `_`, or
/// - The augmenting function's parameter name is the same as the name of the
/// corresponding positional parameter in every preceding declaration that
/// doesn't have `_` as its name.
/// ...
/// It is a compile-time error if:
/// - The signature of the augmenting function does not match the signature of
/// the augmented function.
///
/// @description Checks that it is not an error if an augmentation uses a
/// parameter whose type annotation uses an import prefix.
/// @author sgrekhov22@gmail.com

// SharedOptions=--enable-experiment=augmentations,enhanced-parts

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

part 'augmenting_constructors_A01_t19_part.dart';

class C {
AL? a;
C(this.a);
C.foo([this.a]);
C.bar({this.a});
C.baz({required this.a});
}

enum E {
e0(const AL()),
e1.foo(const AL()),
e2.bar(a: const AL()),
e3.baz(a: const AL());

final AL? a;
const E(this.a);
const E.foo([this.a]);
const E.bar({this.a});
const E.baz({required this.a});
}

extension type ET._(AL? a) {
ET(this.a);
ET.foo([this.a]);
ET.bar({this.a});
ET.baz({required this.a});
}

main() {
C(AL());
C.foo(AL());
C.bar(a: AL());
C.baz(a: AL());

print(E);

ET(AL());
ET.foo(AL());
ET.bar(a: AL());
ET.baz(a: AL());
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// 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 We say that an augmenting function or constructor's signature
/// matches if:
/// - It has the same number of type parameters with the same type parameter
/// names (same identifiers) and bounds (after type annotation inheritance),
/// if any (same types, even if they may not be written exactly the same in
/// case one of the declarations needs to refer to a type using an import
/// prefix).
/// - The return type (if not omitted) is the same as the augmented
/// declaration's return type.
/// - It has the same number of positional and optional parameters as the
/// augmented declaration.
/// - It has the same set of named parameter names as the augmented declaration.
/// - For all corresponding pairs of parameters:
/// - They have the same type (if not omitted in the augmenting declaration).
/// - They have the same `required` and `covariant` modifiers.
/// - For all positional parameters:
/// - The augmenting function's parameter name is `_`, or
/// - The augmenting function's parameter name is the same as the name of the
/// corresponding positional parameter in every preceding declaration that
/// doesn't have `_` as its name.
/// ...
/// It is a compile-time error if:
/// - The signature of the augmenting function does not match the signature of
/// the augmented function.
///
/// @description Checks that it is not an error if an augmentation uses a
/// parameter whose type annotation uses an import prefix.
/// @author sgrekhov22@gmail.com

// SharedOptions=--enable-experiment=augmentations,enhanced-parts

part of 'augmenting_constructors_A01_t19.dart';
import 'augmentation_libraries_lib.dart' as l;

augment class C {
augment C(l.AL? a);
augment C.foo([l.AL? a]);
augment C.bar({l.AL? a});
augment C.baz({required l.AL? a});
}

augment enum E {
;
augment const E(l.AL? a);
augment const E.foo([l.AL? a]);
augment const E.bar({l.AL? a});
augment const E.baz({required l.AL? a});
}

augment extension type ET {
augment ET(l.AL? a);
augment ET.foo([l.AL? a]);
augment ET.bar({l.AL? a});
augment ET.baz({required l.AL? a});
}
136 changes: 136 additions & 0 deletions LanguageFeatures/Augmentations/augmenting_functions_A01_t13.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
// 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 A top-level function, static method, instance method, operator,
/// getter, or setter may be augmented to provide a body or add metadata.
///
/// @description Checks that it is not an error if an augmentation uses a
/// parameter whose type annotation uses an import prefix.
/// @author sgrekhov22@gmail.com

// SharedOptions=--enable-experiment=augmentations,enhanced-parts

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

part 'augmenting_functions_A01_t13_part.dart';

void topLevelFunction1(AL a);
void topLevelFunction2([AL? a]);
void topLevelFunction3({AL? a});
void topLevelFunction4({required AL a});

class C {
static void staticMethod1(AL a);
static void staticMethod2([AL? a]);
static void staticMethod3({AL? a});
static void staticMethod4({required AL a});
void instanceMethod1(AL a);
void instanceMethod2([AL? a]);
void instanceMethod3({AL? a});
void instanceMethod4({required AL a});
}

mixin M {
static void staticMethod1(AL a);
static void staticMethod2([AL? a]);
static void staticMethod3({AL? a});
static void staticMethod4({required AL a});
void instanceMethod1(AL a);
void instanceMethod2([AL? a]);
void instanceMethod3({AL? a});
void instanceMethod4({required AL a});
}

enum E {
e1;

static void staticMethod1(AL a);
static void staticMethod2([AL? a]);
static void staticMethod3({AL? a});
static void staticMethod4({required AL a});
void instanceMethod1(AL a);
void instanceMethod2([AL? a]);
void instanceMethod3({AL? a});
void instanceMethod4({required AL a});
}

class A {}

extension Ext on A {
static void staticMethod1(AL a);
static void staticMethod2([AL? a]);
static void staticMethod3({AL? a});
static void staticMethod4({required AL a});
void instanceMethod1(AL a);
void instanceMethod2([AL? a]);
void instanceMethod3({AL? a});
void instanceMethod4({required AL a});
}

extension type ET(int _) {
static void staticMethod1(AL a);
static void staticMethod2([AL? a]);
static void staticMethod3({AL? a});
static void staticMethod4({required AL a});
void instanceMethod1(AL a);
void instanceMethod2([AL? a]);
void instanceMethod3({AL? a});
void instanceMethod4({required AL a});
}

class MA = Object with M;

main() {
const a = AL();
topLevelFunction1(a);
topLevelFunction2(a);
topLevelFunction3(a: a);
topLevelFunction4(a: a);

C.staticMethod1(a);
C.staticMethod2(a);
C.staticMethod3(a: a);
C.staticMethod4(a: a);
C().instanceMethod1(a);
C().instanceMethod2(a);
C().instanceMethod3(a: a);
C().instanceMethod4(a: a);

M.staticMethod1(a);
M.staticMethod2(a);
M.staticMethod3(a: a);
M.staticMethod4(a: a);
MA().instanceMethod1(a);
MA().instanceMethod2(a);
MA().instanceMethod3(a: a);
MA().instanceMethod4(a: a);

E.staticMethod1(a);
E.staticMethod2(a);
E.staticMethod3(a: a);
E.staticMethod4(a: a);
E.e1.instanceMethod1(a);
E.e1.instanceMethod2(a);
E.e1.instanceMethod3(a: a);
E.e1.instanceMethod4(a: a);

Ext.staticMethod1(a);
Ext.staticMethod2(a);
Ext.staticMethod3(a: a);
Ext.staticMethod4(a: a);
A().instanceMethod1(a);
A().instanceMethod2(a);
A().instanceMethod3(a: a);
A().instanceMethod4(a: a);

ET.staticMethod1(a);
ET.staticMethod2(a);
ET.staticMethod3(a: a);
ET.staticMethod4(a: a);
ET(0).instanceMethod1(a);
ET(0).instanceMethod2(a);
ET(0).instanceMethod3(a: a);
ET(0).instanceMethod4(a: a);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
// 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 A top-level function, static method, instance method, operator,
/// getter, or setter may be augmented to provide a body or add metadata.
///
/// @description Checks that it is not an error if an augmentation uses a
/// parameter whose type annotation uses an import prefix.
/// @author sgrekhov22@gmail.com

// SharedOptions=--enable-experiment=augmentations,enhanced-parts

import 'augmentation_libraries_lib.dart' as l;

part of 'augmenting_functions_A01_t13.dart';

augment void topLevelFunction1(l.AL a) {}
augment void topLevelFunction2([l.AL? a]) {}
augment void topLevelFunction3({l.AL? a}) {}
augment void topLevelFunction4({required l.AL a}) {}

augment class C {
augment static void staticMethod1(l.AL a) {}
augment static void staticMethod2([l.AL? a]) {}
augment static void staticMethod3({l.AL? a}) {}
augment static void staticMethod4({required l.AL a}) {}
augment void instanceMethod1(l.AL a) {}
augment void instanceMethod2([l.AL? a]) {}
augment void instanceMethod3({l.AL? a}) {}
augment void instanceMethod4({required l.AL a}) {}
}

augment mixin M {
augment static void staticMethod1(l.AL a) {}
augment static void staticMethod2([l.AL? a]) {}
augment static void staticMethod3({l.AL? a}) {}
augment static void staticMethod4({required l.AL a}) {}
augment void instanceMethod1(l.AL a) {}
augment void instanceMethod2([l.AL? a]) {}
augment void instanceMethod3({l.AL? a}) {}
augment void instanceMethod4({required l.AL a}) {}
}

augment enum E {
;
augment static void staticMethod1(l.AL a) {}
augment static void staticMethod2([l.AL? a]) {}
augment static void staticMethod3({l.AL? a}) {}
augment static void staticMethod4({required l.AL a}) {}
augment void instanceMethod1(l.AL a) {}
augment void instanceMethod2([l.AL? a]) {}
augment void instanceMethod3({l.AL? a}) {}
augment void instanceMethod4({required l.AL a}) {}
}

augment extension Ext {
augment static void staticMethod1(l.AL a) {}
augment static void staticMethod2([l.AL? a]) {}
augment static void staticMethod3({l.AL? a}) {}
augment static void staticMethod4({required l.AL a}) {}
augment void instanceMethod1(l.AL a) {}
augment void instanceMethod2([l.AL? a]) {}
augment void instanceMethod3({l.AL? a}) {}
augment void instanceMethod4({required l.AL a}) {}
}

augment extension type ET {
augment static void staticMethod1(l.AL a) {}
augment static void staticMethod2([l.AL? a]) {}
augment static void staticMethod3({l.AL? a}) {}
augment static void staticMethod4({required l.AL a}) {}
augment void instanceMethod1(l.AL a) {}
augment void instanceMethod2([l.AL? a]) {}
augment void instanceMethod3({l.AL? a}) {}
augment void instanceMethod4({required l.AL a}) {}
}
Loading