Skip to content

Commit

Permalink
#2275. Add noSuchMethod tests. Part 4 (dynamic semantics) (#2296)
Browse files Browse the repository at this point in the history
Add `noSuchMethod` tests. Part 4 (dynamic semantics)
  • Loading branch information
sgrekhov authored Oct 10, 2023
1 parent 167b1d6 commit 0690b19
Show file tree
Hide file tree
Showing 21 changed files with 2,249 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ enum E5 {
int noSuchMethod(Invocation i) => 5;
}


main() {
Expect.throws(() {
C1().m();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
// Copyright (c) 2023, 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 For the dynamic semantics, assume that a class C has an
/// implicitly induced noSuchMethod forwarder named m, with formal type
/// parameters X1, . . . , Xr, positional formal parameters a1, . . . , ak (some
/// of which may be optional when n = 0), and named formal parameters with names
/// x1, . . . , xn
///
/// The execution of the body of m creates an instance im of the predefined im
/// class Invocation such that:
/// • im.isMethod evaluates to true iff m is a method.
///
/// @description Checks that `im.isMethod` evaluates to `true` iff `m` is a
/// method
/// @author [email protected]
import "../../../../Utils/expect.dart";

bool log = false;

mixin class A {
bool m();
bool get g;
void set s(bool i);

dynamic noSuchMethod(Invocation i) {
log = i.isMethod;
return i.isMethod;
}
}

class C1 extends A {}

class C2 with A {}

mixin M on A {}

class MA = A with M;

enum E with A {
e1, e2;
}

main() {
Expect.isTrue(A().m());
Expect.isFalse(A().g);
A().s = true;
Expect.isFalse(log);
Expect.isTrue(A().m is bool Function()); // tear-off, no `noSuchMethod` invoked

Expect.isTrue(C1().m());
Expect.isFalse(C1().g);
C1().s = true;
Expect.isFalse(log);
Expect.isTrue(C1().m is bool Function());

Expect.isTrue(C2().m());
Expect.isFalse(C2().g);
C2().s = true;
Expect.isFalse(log);
Expect.isTrue(C2().m is bool Function());

Expect.isTrue(MA().m());
Expect.isFalse(MA().g);
MA().s = true;
Expect.isFalse(log);
Expect.isTrue(MA().m is bool Function());

Expect.isTrue(E.e1.m());
Expect.isFalse(E.e1.g);
E.e1.s = true;
Expect.isFalse(log);
Expect.isTrue(E.e1.m is bool Function());
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
// Copyright (c) 2023, 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 For the dynamic semantics, assume that a class C has an
/// implicitly induced noSuchMethod forwarder named m, with formal type
/// parameters X1, . . . , Xr, positional formal parameters a1, . . . , ak (some
/// of which may be optional when n = 0), and named formal parameters with names
/// x1, . . . , xn
///
/// The execution of the body of m creates an instance im of the predefined im
/// class Invocation such that:
/// ...
/// • im.isGetter evaluates to true iff m is a getter.
///
/// @description Checks that `im.isGetter` evaluates to `true` iff `m` is a
/// getter
/// @author [email protected]
import "../../../../Utils/expect.dart";

bool log = false;

mixin class A {
bool m();
bool get g;
void set s(bool i);

dynamic noSuchMethod(Invocation i) {
log = i.isGetter;
return i.isGetter;
}
}

class C1 extends A {}

class C2 with A {}

mixin M on A {}

class MA = A with M;

enum E with A {
e1, e2;
}

main() {
Expect.isFalse(A().m());
Expect.isTrue(A().g);
A().s = true;
Expect.isFalse(log);

Expect.isFalse(C1().m());
Expect.isTrue(C1().g);
C1().s = true;
Expect.isFalse(log);

Expect.isFalse(C2().m());
Expect.isTrue(C2().g);
C2().s = true;
Expect.isFalse(log);

Expect.isFalse(MA().m());
Expect.isTrue(MA().g);
MA().s = true;
Expect.isFalse(log);

Expect.isFalse(E.e1.m());
Expect.isTrue(E.e1.g);
E.e1.s = true;
Expect.isFalse(log);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
// Copyright (c) 2023, 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 For the dynamic semantics, assume that a class C has an
/// implicitly induced noSuchMethod forwarder named m, with formal type
/// parameters X1, . . . , Xr, positional formal parameters a1, . . . , ak (some
/// of which may be optional when n = 0), and named formal parameters with names
/// x1, . . . , xn
///
/// The execution of the body of m creates an instance im of the predefined im
/// class Invocation such that:
/// ...
/// • im.isSetter evaluates to true iff m is a setter
///
/// @description Checks that `im.isSetter` evaluates to `true` iff `m` is a
/// setter
/// @author [email protected]
import "../../../../Utils/expect.dart";

bool log = false;

mixin class A {
bool m();
bool get g;
void set s(bool i);

dynamic noSuchMethod(Invocation i) {
log = i.isSetter;
return i.isSetter;
}
}

class C1 extends A {}

class C2 with A {}

mixin M on A {}

class MA = A with M;

enum E with A {
e1, e2;
}

main() {
Expect.isFalse(A().m());
Expect.isFalse(A().g);
A().s = true;
Expect.isTrue(log);

Expect.isFalse(C1().m());
Expect.isFalse(C1().g);
C1().s = true;
Expect.isTrue(log);

Expect.isFalse(C2().m());
Expect.isFalse(C2().g);
C2().s = true;
Expect.isTrue(log);

Expect.isFalse(MA().m());
Expect.isFalse(MA().g);
MA().s = true;
Expect.isTrue(log);

Expect.isFalse(E.e1.m());
Expect.isFalse(E.e1.g);
E.e1.s = true;
Expect.isTrue(log);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
// Copyright (c) 2023, 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 For the dynamic semantics, assume that a class C has an
/// implicitly induced noSuchMethod forwarder named m, with formal type
/// parameters X1, . . . , Xr, positional formal parameters a1, . . . , ak (some
/// of which may be optional when n = 0), and named formal parameters with names
/// x1, . . . , xn
///
/// The execution of the body of m creates an instance im of the predefined im
/// class Invocation such that:
/// ...
/// • im.memberName evaluates to the symbol m.
///
/// @description Checks that `im.memberName` evaluates to the symbol `m`.
/// @author [email protected]
import "../../../../Utils/expect.dart";

late Symbol log;

mixin class A {
Symbol m();
Symbol get g;
void set s(String s);

dynamic noSuchMethod(Invocation i) {
log = i.memberName;
return i.memberName;
}
}

class C1 extends A {}

class C2 with A {}

mixin M on A {}

class MA = A with M;

enum E with A {
e1, e2;
}

main() {
Expect.equals(#m, A().m());
Expect.equals(#g, A().g);
A().s = "";
Expect.equals(Symbol("s="), log);

Expect.equals(#m, C1().m());
Expect.equals(#g, C1().g);
C1().s = "";
Expect.equals(Symbol("s="), log);

Expect.equals(#m, C2().m());
Expect.equals(#g, C2().g);
C2().s = "";
Expect.equals(Symbol("s="), log);

Expect.equals(#m, MA().m());
Expect.equals(#g, MA().g);
MA().s = "";
Expect.equals(Symbol("s="), log);

Expect.equals(#m, E.e1.m());
Expect.equals(#g, E.e2.g);
E.e1.s = "";
Expect.equals(Symbol("s="), log);
}
Loading

0 comments on commit 0690b19

Please sign in to comment.