Skip to content

Commit

Permalink
#2275. More noSuchMethod tests added. Part 2 (#2288)
Browse files Browse the repository at this point in the history
More `noSuchMethod` tests added. Part 2
  • Loading branch information
sgrekhov authored Sep 28, 2023
1 parent cb63ec0 commit dcc3cbe
Show file tree
Hide file tree
Showing 13 changed files with 711 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
/// @description Checks that it is possible to define a `noSuchMethod` which
/// is a correct override of `noSuchMethod` in `Object`.
/// @author [email protected]
/// @issue 53640
import "../../../../Utils/expect.dart";

Expand Down Expand Up @@ -50,6 +51,68 @@ class C5 {
int noSuchMethod(Invocation i) => 5;
}

mixin M1 {
int m();
void noSuchMethod(Invocation i) {}
}

mixin M2 {
int m();
Object? noSuchMethod(Invocation i) => 2;
}

mixin M3 {
int m();
Null noSuchMethod(Invocation i) => null;
}

mixin M4 {
int m();
Never noSuchMethod(Invocation i) => throw 42;
}

mixin M5 {
int m();
int noSuchMethod(Invocation i) => 5;
}

class MA1 = Object with M1;
class MA2 = Object with M2;
class MA3 = Object with M3;
class MA4 = Object with M4;
class MA5 = Object with M5;

enum E1 {
e1, e2;
int m();
void noSuchMethod(Invocation i) {}
}

enum E2 {
e1, e2;
int m();
Object? noSuchMethod(Invocation i) => 2;
}

enum E3 {
e1, e2;
int m();
Null noSuchMethod(Invocation i) => null;
}

enum E4 {
e1, e2;
int m();
Never noSuchMethod(Invocation i) => throw 42;
}

enum E5 {
e1, e2;
int m();
int noSuchMethod(Invocation i) => 5;
}


main() {
Expect.throws(() {
C1().m();
Expand All @@ -62,4 +125,28 @@ main() {
C4().m();
});
Expect.equals(5, C5().m());

Expect.throws(() {
MA1().m();
});
Expect.equals(2, MA2().m());
Expect.throws(() {
MA3().m();
});
Expect.throws(() {
MA4().m();
});
Expect.equals(5, MA5().m());

Expect.throws(() {
E1.e1.m();
});
Expect.equals(2, E2.e1.m());
Expect.throws(() {
E3.e1.m();
});
Expect.throws(() {
E4.e1.m();
});
Expect.equals(5, E5.e1.m());
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,40 @@ class C2 {
dynamic noSuchMethod(Invocation i, {int x = 2}) => x;
}

mixin M1 {
int m();
dynamic noSuchMethod(Invocation i, [int x = 1]) {
return x;
}
}

mixin M2 {
int m();
dynamic noSuchMethod(Invocation i, {int x = 2}) => x;
}

class MA1 = Object with M1;
class MA2 = Object with M2;

enum E1 {
e1, e2;
int m();
dynamic noSuchMethod(Invocation i, [int x = 1]) {
return x;
}
}

enum E2 {
e1, e2;
int m();
dynamic noSuchMethod(Invocation i, {int x = 2}) => x;
}

main() {
Expect.equals(1, C1().m());
Expect.equals(2, C2().m());
Expect.equals(1, MA1().m());
Expect.equals(2, MA2().m());
Expect.equals(1, E1.e1.m());
Expect.equals(2, E2.e2.m());
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,42 @@ class C2 {
dynamic noSuchMethod(covariant Invocation i) => 2;
}

mixin M1 {
int m();
external dynamic noSuchMethod(Invocation i);
}

mixin M2 {
int m();
dynamic noSuchMethod(covariant Invocation i) => 2;
}

class MA1 = Object with M1;
class MA2 = Object with M2;

enum E1 {
e1, e2;
int m();
external dynamic noSuchMethod(Invocation i);
}

enum E2 {
e1, e2;
int m();
dynamic noSuchMethod(covariant Invocation i) => 2;
}

main() {
Expect.throws(() {
C1().m();
});
Expect.equals(2, C2().m());
Expect.throws(() {
MA1().m();
});
Expect.equals(2, MA2().m());
Expect.throws(() {
E1.e1.m();
});
Expect.equals(2, E2.e2.m());
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,36 @@
/// @description Checks that it is possible to define a `noSuchMethod` which
/// is a correct override of `noSuchMethod` in `Object`.
/// @author [email protected]
/// @issue 53640
import "../../../../Utils/expect.dart";

class C1 {
class C {
int m();
dynamic noSuchMethod(covariant Object o) => o;
}

mixin M {
int m();
dynamic noSuchMethod(covariant Object o) => o;
}

class MA = Object with M;

enum E {
e1, e2;
int m();
dynamic noSuchMethod(covariant Object o) => o;
}

main() {
Expect.throws(() {
C1().m();
C().m();
});
Expect.throws(() {
print(MA().m());
});
Expect.throws(() {
E.e1.m();
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,77 @@ class C4 {
// [cfe] unspecified
}

mixin M1 {
void noSuchMethod() {}
// ^^^^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
}

mixin M2 {
void noSuchMethod(Invocation i, String s) {}
// ^^^^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
}

mixin M3 {
void noSuchMethod(Invocation i, {required String s}) {}
// ^^^^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
}

mixin M4 {
dynamic noSuchMethod(int i) => i;
// ^^^^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
}

enum E1 {
e1, e2;
void noSuchMethod() {}
// ^^^^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
}

enum E2 {
e1, e2;
void noSuchMethod(Invocation i, String s) {}
// ^^^^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
}

enum E3 {
e1, e2;
void noSuchMethod(Invocation i, {required String s}) {}
// ^^^^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
}

enum E4 {
e1, e2;
dynamic noSuchMethod(int i) => i;
// ^^^^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
}

main() {
print(C1);
print(C2);
print(C3);
print(C4);
print(M1);
print(M2);
print(M3);
print(M4);
print(E1);
print(E2);
print(E3);
print(E4);
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,77 @@ class C4 {
// [cfe] unspecified
}

mixin M1 {
external void noSuchMethod();
// ^^^^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
}

mixin M2 {
external void noSuchMethod(Invocation i, String s);
// ^^^^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
}

mixin M3 {
external void noSuchMethod(Invocation i, {required String s});
// ^^^^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
}

mixin M4 {
external dynamic noSuchMethod(int i);
// ^^^^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
}

enum E1 {
e1, e2;
external void noSuchMethod();
// ^^^^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
}

enum E2 {
e1, e2;
external void noSuchMethod(Invocation i, String s);
// ^^^^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
}

enum E3 {
e1, e2;
external void noSuchMethod(Invocation i, {required String s});
// ^^^^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
}

enum E4 {
e1, e2;
external dynamic noSuchMethod(int i);
// ^^^^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
}

main() {
print(C1);
print(C2);
print(C3);
print(C4);
print(M1);
print(M2);
print(M3);
print(M4);
print(E1);
print(E2);
print(E3);
print(E4);
}
Loading

0 comments on commit dcc3cbe

Please sign in to comment.