Skip to content

Commit

Permalink
#2559. Add more augmenting functions tests (#2615)
Browse files Browse the repository at this point in the history
Add more augmenting functions tests
  • Loading branch information
sgrekhov committed Apr 22, 2024
1 parent 9ca77ed commit 1999ed9
Show file tree
Hide file tree
Showing 16 changed files with 1,602 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
// 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 It is a compile-time error if:
/// - The signature of the function augmentation does not exactly match the
/// original function. This means the return types must be the same; there
/// must be the same number of positional, optional, and named parameters; the
/// types of corresponding positional and optional parameters must be the
/// same; the names and types of named parameters must be the same; any type
/// parameters and bounds must be the same; and any required or covariant
/// modifiers must match.
///
/// @description Checks that it is not an error if return type and parameters
/// of an augmentation exactly matches the original function. Test implicit
/// `dynamic`.
/// @author sgrekhov22@gmail.com
// SharedOptions=--enable-experiment=macros

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

topLevelFunction1() => "original";
String topLevelFunction2(var s) => "original";
String topLevelFunction3(_) => "original";

class C {
static staticMethod1() => "original";
static String staticMethod2(var s) => "original";
static String staticMethod3(_) => "original";
instanceMethod1() => "original";
String instanceMethod2(var s) => "original";
String instanceMethod3(_) => "original";
}

mixin M {
static staticMethod1() => "original";
static String staticMethod2(var s) => "original";
static String staticMethod3(_) => "original";
instanceMethod1() => "original";
String instanceMethod2(var s) => "original";
String instanceMethod3(_) => "original";
}

enum E {
e1;

static staticMethod1() => "original";
static String staticMethod2(var s) => "original";
static String staticMethod3(_) => "original";
instanceMethod1() => "original";
String instanceMethod2(var s) => "original";
String instanceMethod3(_) => "original";
}

class A {}

extension Ext on A {
static staticMethod1() => "original";
static String staticMethod2(var s) => "original";
static String staticMethod3(_) => "original";
instanceMethod1() => "original";
String instanceMethod2(var s) => "original";
String instanceMethod3(_) => "original";
}

class MA = Object with M;

main() {
Expect.equals("augmented", topLevelFunction1());
Expect.equals("augmented X", topLevelFunction2("X"));
Expect.equals("augmented Y", topLevelFunction3("Y"));

Expect.equals("augmented", C.staticMethod1());
Expect.equals("augmented X", C.staticMethod2("X"));
Expect.equals("augmented Y", C.staticMethod3("Y"));
Expect.equals("augmented", C().instanceMethod1());
Expect.equals("augmented X", C().instanceMethod2("X"));
Expect.equals("augmented Y", C().instanceMethod3("Y"));

Expect.equals("augmented", M.staticMethod1());
Expect.equals("augmented X", M.staticMethod2("X"));
Expect.equals("augmented Y", M.staticMethod3("Y"));
Expect.equals("augmented", MA().instanceMethod1());
Expect.equals("augmented X", MA().instanceMethod2("X"));
Expect.equals("augmented Y", MA().instanceMethod3("Y"));

Expect.equals("augmented", E.staticMethod1());
Expect.equals("augmented X", E.staticMethod2("X"));
Expect.equals("augmented Y", E.staticMethod3("Y"));
Expect.equals("augmented", E.e1.instanceMethod1());
Expect.equals("augmented X", E.e1.instanceMethod2("X"));
Expect.equals("augmented Y", E.e1.instanceMethod3("Y"));

Expect.equals("augmented", Ext.staticMethod1());
Expect.equals("augmented X", Ext.staticMethod2("X"));
Expect.equals("augmented Y", Ext.staticMethod3("Y"));
Expect.equals("augmented", A().instanceMethod1());
Expect.equals("augmented X", A().instanceMethod2("X"));
Expect.equals("augmented Y", A().instanceMethod3("Y"));
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// 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 It is a compile-time error if:
/// - The signature of the function augmentation does not exactly match the
/// original function. This means the return types must be the same; there
/// must be the same number of positional, optional, and named parameters; the
/// types of corresponding positional and optional parameters must be the
/// same; the names and types of named parameters must be the same; any type
/// parameters and bounds must be the same; and any required or covariant
/// modifiers must match.
///
/// @description Checks that it is not an error if return type and parameters
/// of an augmentation exactly matches the original function. Test implicit
/// `dynamic`.
/// @author sgrekhov22@gmail.com
// SharedOptions=--enable-experiment=macros

augment library 'augmenting_functions_A04_t22.dart';

augment dynamic topLevelFunction1() => "augmented";
augment String topLevelFunction2(dynamic s0) => "augmented $s0";
augment String topLevelFunction3(dynamic v) => "augmented $v";

augment class C {
augment static dynamic staticMethod1() => "augmented";
augment static String staticMethod2(dynamic s0) => "augmented $s0";
augment static String staticMethod3(dynamic v) => "augmented $v";

augment dynamic instanceMethod1() => "augmented";
augment String instanceMethod2(dynamic s0) => "augmented $s0";
augment String instanceMethod3(dynamic v) => "augmented $v";
}

augment mixin M {
augment static dynamic staticMethod1() => "augmented";
augment static String staticMethod2(dynamic s0) => "augmented $s0";
augment static String staticMethod3(dynamic v) => "augmented $v";

augment dynamic instanceMethod1() => "augmented";
augment String instanceMethod2(dynamic s0) => "augmented $s0";
augment String instanceMethod3(dynamic v) => "augmented $v";
}

augment enum E {
augment e1;

augment static dynamic staticMethod1() => "augmented";
augment static String staticMethod2(dynamic s0) => "augmented $s0";
augment static String staticMethod3(dynamic v) => "augmented $v";

augment dynamic instanceMethod1() => "augmented";
augment String instanceMethod2(dynamic s0) => "augmented $s0";
augment String instanceMethod3(dynamic v) => "augmented $v";
}

augment extension Ext {
augment static dynamic staticMethod1() => "augmented";
augment static String staticMethod2(dynamic s0) => "augmented $s0";
augment static String staticMethod3(dynamic v) => "augmented $v";

augment dynamic instanceMethod1() => "augmented";
augment String instanceMethod2(dynamic s0) => "augmented $s0";
augment String instanceMethod3(dynamic v) => "augmented $v";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
// 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 It is a compile-time error if:
/// - The signature of the function augmentation does not exactly match the
/// original function. This means the return types must be the same; there
/// must be the same number of positional, optional, and named parameters; the
/// types of corresponding positional and optional parameters must be the
/// same; the names and types of named parameters must be the same; any type
/// parameters and bounds must be the same; and any required or covariant
/// modifiers must match.
///
/// @description Checks that it is a compile-time error if type of parameters of
/// an augmentation doesn't exactly match the original function. Test the case
/// when return type is a top type.
/// @author sgrekhov22@gmail.com
/// @issue 55478
// SharedOptions=--enable-experiment=macros

import augment 'augmenting_functions_A04_t23_lib1.dart';
import augment 'augmenting_functions_A04_t23_lib2.dart';

Object? topLevelFunction1() => 0;
dynamic topLevelFunction2() => 0;
void topLevelFunction3() => 0;

class C {
static Object? staticMethod1() => 0;
static dynamic staticMethod2() => 0;
static void staticMethod3() => 0;
Object? instanceMethod1() => 0;
dynamic instanceMethod2() => 0;
void instanceMethod3() => 0;
}

mixin M {
static Object? staticMethod1() => 0;
static dynamic staticMethod2() => 0;
static void staticMethod3() => 0;
Object? instanceMethod1() => 0;
dynamic instanceMethod2() => 0;
void instanceMethod3() => 0;
}

enum E {
e1;

static Object? staticMethod1() => 0;
static dynamic staticMethod2() => 0;
static void staticMethod3() => 0;
Object? instanceMethod1() => 0;
dynamic instanceMethod2() => 0;
void instanceMethod3() => 0;
}

class A {}

extension Ext on A {
static Object? staticMethod1() => 0;
static dynamic staticMethod2() => 0;
static void staticMethod3() => 0;
Object? instanceMethod1() => 0;
dynamic instanceMethod2() => 0;
void instanceMethod3() => 0;
}

main() {
print(topLevelFunction1);
print(topLevelFunction2);
print(topLevelFunction3);
print(C);
print(M);
print(E);
print(A);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
// 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 It is a compile-time error if:
/// - The signature of the function augmentation does not exactly match the
/// original function. This means the return types must be the same; there
/// must be the same number of positional, optional, and named parameters; the
/// types of corresponding positional and optional parameters must be the
/// same; the names and types of named parameters must be the same; any type
/// parameters and bounds must be the same; and any required or covariant
/// modifiers must match.
///
/// @description Checks that it is a compile-time error if type of parameters of
/// an augmentation doesn't exactly match the original function. Test top types
/// @author sgrekhov22@gmail.com
/// @issue 55478
// SharedOptions=--enable-experiment=macros

augment library 'augmenting_functions_A04_t23.dart';

augment void topLevelFunction1() => 1;
// ^^^^^^^^^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
augment Object? topLevelFunction2() => 1;
// ^^^^^^^^^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
augment dynamic topLevelFunction3() => 1;
// ^^^^^^^^^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified

augment class C {
augment static void staticMethod1() => 1;
// ^^^^^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
augment static Object? staticMethod2() => 1;
// ^^^^^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
augment static dynamic staticMethod3() => 1;
// ^^^^^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified

augment void instanceMethod1() => 1;
// ^^^^^^^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
augment Object? instanceMethod2() => 1;
// ^^^^^^^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
augment dynamic instanceMethod3() => 1;
// ^^^^^^^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
}

augment mixin M {
augment static void staticMethod1() => 1;
// ^^^^^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
augment static Object? staticMethod2() => 1;
// ^^^^^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
augment static dynamic staticMethod3() => 1;
// ^^^^^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified

augment void instanceMethod1() => 1;
// ^^^^^^^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
augment Object? instanceMethod2() => 1;
// ^^^^^^^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
augment dynamic instanceMethod3() => 1;
// ^^^^^^^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
}

augment enum E {
augment e1;

augment static void staticMethod1() => 1;
// ^^^^^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
augment static Object? staticMethod2() => 1;
// ^^^^^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
augment static dynamic staticMethod3() => 1;
// ^^^^^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified

augment void instanceMethod1() => 1;
// ^^^^^^^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
augment Object? instanceMethod2() => 1;
// ^^^^^^^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
augment dynamic instanceMethod3() => 1;
// ^^^^^^^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
}

augment extension Ext {
augment static void staticMethod1() => 1;
// ^^^^^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
augment static Object? staticMethod2() => 1;
// ^^^^^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
augment static dynamic staticMethod3() => 1;
// ^^^^^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified

augment void instanceMethod1() => 1;
// ^^^^^^^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
augment Object? instanceMethod2() => 1;
// ^^^^^^^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
augment dynamic instanceMethod3() => 1;
// ^^^^^^^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
}

0 comments on commit 1999ed9

Please sign in to comment.