-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Add more `noSuchMethod` tests
- Loading branch information
Showing
14 changed files
with
934 additions
and
0 deletions.
There are no files selected for viewing
65 changes: 65 additions & 0 deletions
65
Language/Classes/Instance_Methods/Method_noSuchMethod/definition_A01_t01.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// 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 We say that a class C has a non-trivial `noSuchMethod` if C has a | ||
/// concrete member named noSuchMethod which is distinct from the one declared | ||
/// in the built-in class [Object] | ||
/// | ||
/// Note that it must be a method that accepts one positional argument, in order | ||
/// to correctly override noSuchMethod in Object. For instance, it can have | ||
/// signature noSuchMethod(Invocation i) or | ||
/// noSuchMethod(Object i, [String s = ”]), but not | ||
/// noSuchMethod(Invocation i, String s). This implies that the situation where | ||
/// noSuchMethod is invoked (explicitly or implicitly) with one actual argument | ||
/// cannot fail for the reason that “there is no such method”, such that we | ||
/// would enter an infinite loop trying to invoke noSuchMethod. It is possible, | ||
/// however, to encounter a dynamic error during an invocation of noSuchMethod | ||
/// because the actual argument fails to satisfy a type check, but that | ||
/// situation will give rise to a dynamic type error rather than a repeated | ||
/// attempt to invoke noSuchMethod | ||
/// | ||
/// @description Checks that it is possible to define a `noSuchMethod` which | ||
/// is a correct override of `noSuchMethod` in `Object`. | ||
/// @author [email protected] | ||
import "../../../../Utils/expect.dart"; | ||
|
||
class C1 { | ||
int m(); | ||
void noSuchMethod(Invocation i) {} | ||
} | ||
|
||
class C2 { | ||
int m(); | ||
Object? noSuchMethod(Invocation i) => 2; | ||
} | ||
|
||
class C3 { | ||
int m(); | ||
Null noSuchMethod(Invocation i) => null; | ||
} | ||
|
||
class C4 { | ||
int m(); | ||
Never noSuchMethod(Invocation i) => throw 42; | ||
} | ||
|
||
class C5 { | ||
int m(); | ||
int noSuchMethod(Invocation i) => 5; | ||
} | ||
|
||
main() { | ||
Expect.throws(() { | ||
C1().m(); | ||
}); | ||
Expect.equals(2, C2().m()); | ||
Expect.throws(() { | ||
C3().m(); | ||
}); | ||
Expect.throws(() { | ||
C4().m(); | ||
}); | ||
Expect.equals(5, C5().m()); | ||
} |
43 changes: 43 additions & 0 deletions
43
Language/Classes/Instance_Methods/Method_noSuchMethod/definition_A01_t02.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// 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 We say that a class C has a non-trivial `noSuchMethod` if C has a | ||
/// concrete member named noSuchMethod which is distinct from the one declared | ||
/// in the built-in class [Object] | ||
/// | ||
/// Note that it must be a method that accepts one positional argument, in order | ||
/// to correctly override noSuchMethod in Object. For instance, it can have | ||
/// signature noSuchMethod(Invocation i) or | ||
/// noSuchMethod(Object i, [String s = ”]), but not | ||
/// noSuchMethod(Invocation i, String s). This implies that the situation where | ||
/// noSuchMethod is invoked (explicitly or implicitly) with one actual argument | ||
/// cannot fail for the reason that “there is no such method”, such that we | ||
/// would enter an infinite loop trying to invoke noSuchMethod. It is possible, | ||
/// however, to encounter a dynamic error during an invocation of noSuchMethod | ||
/// because the actual argument fails to satisfy a type check, but that | ||
/// situation will give rise to a dynamic type error rather than a repeated | ||
/// attempt to invoke noSuchMethod | ||
/// | ||
/// @description Checks that it is possible to define a `noSuchMethod` which | ||
/// is a correct override of `noSuchMethod` in `Object`. | ||
/// @author [email protected] | ||
import "../../../../Utils/expect.dart"; | ||
|
||
class C1 { | ||
int m(); | ||
dynamic noSuchMethod(Invocation i, [int x = 1]) { | ||
return x; | ||
} | ||
} | ||
|
||
class C2 { | ||
int m(); | ||
dynamic noSuchMethod(Invocation i, {int x = 2}) => x; | ||
} | ||
|
||
main() { | ||
Expect.equals(1, C1().m()); | ||
Expect.equals(2, C2().m()); | ||
} |
43 changes: 43 additions & 0 deletions
43
Language/Classes/Instance_Methods/Method_noSuchMethod/definition_A01_t03.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// 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 We say that a class C has a non-trivial `noSuchMethod` if C has a | ||
/// concrete member named noSuchMethod which is distinct from the one declared | ||
/// in the built-in class [Object] | ||
/// | ||
/// Note that it must be a method that accepts one positional argument, in order | ||
/// to correctly override noSuchMethod in Object. For instance, it can have | ||
/// signature noSuchMethod(Invocation i) or | ||
/// noSuchMethod(Object i, [String s = ”]), but not | ||
/// noSuchMethod(Invocation i, String s). This implies that the situation where | ||
/// noSuchMethod is invoked (explicitly or implicitly) with one actual argument | ||
/// cannot fail for the reason that “there is no such method”, such that we | ||
/// would enter an infinite loop trying to invoke noSuchMethod. It is possible, | ||
/// however, to encounter a dynamic error during an invocation of noSuchMethod | ||
/// because the actual argument fails to satisfy a type check, but that | ||
/// situation will give rise to a dynamic type error rather than a repeated | ||
/// attempt to invoke noSuchMethod | ||
/// | ||
/// @description Checks that it is possible to define a `noSuchMethod` which | ||
/// is a correct override of `noSuchMethod` in `Object`. | ||
/// @author [email protected] | ||
import "../../../../Utils/expect.dart"; | ||
|
||
class C1 { | ||
int m(); | ||
external dynamic noSuchMethod(Invocation i); | ||
} | ||
|
||
class C2 { | ||
int m(); | ||
dynamic noSuchMethod(covariant Invocation i) => 2; | ||
} | ||
|
||
main() { | ||
Expect.throws(() { | ||
C1().m(); | ||
}); | ||
Expect.equals(2, C2().m()); | ||
} |
37 changes: 37 additions & 0 deletions
37
Language/Classes/Instance_Methods/Method_noSuchMethod/definition_A01_t04.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// 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 We say that a class C has a non-trivial `noSuchMethod` if C has a | ||
/// concrete member named noSuchMethod which is distinct from the one declared | ||
/// in the built-in class [Object] | ||
/// | ||
/// Note that it must be a method that accepts one positional argument, in order | ||
/// to correctly override noSuchMethod in Object. For instance, it can have | ||
/// signature noSuchMethod(Invocation i) or | ||
/// noSuchMethod(Object i, [String s = ”]), but not | ||
/// noSuchMethod(Invocation i, String s). This implies that the situation where | ||
/// noSuchMethod is invoked (explicitly or implicitly) with one actual argument | ||
/// cannot fail for the reason that “there is no such method”, such that we | ||
/// would enter an infinite loop trying to invoke noSuchMethod. It is possible, | ||
/// however, to encounter a dynamic error during an invocation of noSuchMethod | ||
/// because the actual argument fails to satisfy a type check, but that | ||
/// situation will give rise to a dynamic type error rather than a repeated | ||
/// attempt to invoke noSuchMethod | ||
/// | ||
/// @description Checks that it is possible to define a `noSuchMethod` which | ||
/// is a correct override of `noSuchMethod` in `Object`. | ||
/// @author [email protected] | ||
import "../../../../Utils/expect.dart"; | ||
|
||
class C1 { | ||
int m(); | ||
dynamic noSuchMethod(covariant Object o) => o; | ||
} | ||
|
||
main() { | ||
Expect.throws(() { | ||
C1().m(); | ||
}); | ||
} |
59 changes: 59 additions & 0 deletions
59
Language/Classes/Instance_Methods/Method_noSuchMethod/definition_A02_t01.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// 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 We say that a class C has a non-trivial `noSuchMethod` if C has a | ||
/// concrete member named noSuchMethod which is distinct from the one declared | ||
/// in the built-in class [Object] | ||
/// | ||
/// Note that it must be a method that accepts one positional argument, in order | ||
/// to correctly override noSuchMethod in Object. For instance, it can have | ||
/// signature noSuchMethod(Invocation i) or | ||
/// noSuchMethod(Object i, [String s = ”]), but not | ||
/// noSuchMethod(Invocation i, String s). This implies that the situation where | ||
/// noSuchMethod is invoked (explicitly or implicitly) with one actual argument | ||
/// cannot fail for the reason that “there is no such method”, such that we | ||
/// would enter an infinite loop trying to invoke noSuchMethod. It is possible, | ||
/// however, to encounter a dynamic error during an invocation of noSuchMethod | ||
/// because the actual argument fails to satisfy a type check, but that | ||
/// situation will give rise to a dynamic type error rather than a repeated | ||
/// attempt to invoke noSuchMethod | ||
/// | ||
/// @description Checks that it is a compile-time error to define a | ||
/// `noSuchMethod` which is not a correct override of `noSuchMethod` in `Object` | ||
/// @author [email protected] | ||
class C1 { | ||
void noSuchMethod() {} | ||
// ^^^^^^^^^^^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
} | ||
|
||
class C2 { | ||
void noSuchMethod(Invocation i, String s) {} | ||
// ^^^^^^^^^^^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
} | ||
|
||
class C3 { | ||
void noSuchMethod(Invocation i, {required String s}) {} | ||
// ^^^^^^^^^^^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
} | ||
|
||
class C4 { | ||
dynamic noSuchMethod(int i) => i; | ||
// ^^^^^^^^^^^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
} | ||
|
||
main() { | ||
print(C1); | ||
print(C2); | ||
print(C3); | ||
print(C4); | ||
} |
59 changes: 59 additions & 0 deletions
59
Language/Classes/Instance_Methods/Method_noSuchMethod/definition_A02_t02.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// 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 We say that a class C has a non-trivial `noSuchMethod` if C has a | ||
/// concrete member named noSuchMethod which is distinct from the one declared | ||
/// in the built-in class [Object] | ||
/// | ||
/// Note that it must be a method that accepts one positional argument, in order | ||
/// to correctly override noSuchMethod in Object. For instance, it can have | ||
/// signature noSuchMethod(Invocation i) or | ||
/// noSuchMethod(Object i, [String s = ”]), but not | ||
/// noSuchMethod(Invocation i, String s). This implies that the situation where | ||
/// noSuchMethod is invoked (explicitly or implicitly) with one actual argument | ||
/// cannot fail for the reason that “there is no such method”, such that we | ||
/// would enter an infinite loop trying to invoke noSuchMethod. It is possible, | ||
/// however, to encounter a dynamic error during an invocation of noSuchMethod | ||
/// because the actual argument fails to satisfy a type check, but that | ||
/// situation will give rise to a dynamic type error rather than a repeated | ||
/// attempt to invoke noSuchMethod | ||
/// | ||
/// @description Checks that it is a compile-time error to define a | ||
/// `noSuchMethod` which is not a correct override of `noSuchMethod` in `Object` | ||
/// @author [email protected] | ||
class C1 { | ||
external void noSuchMethod(); | ||
// ^^^^^^^^^^^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
} | ||
|
||
class C2 { | ||
external void noSuchMethod(Invocation i, String s); | ||
// ^^^^^^^^^^^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
} | ||
|
||
class C3 { | ||
external void noSuchMethod(Invocation i, {required String s}); | ||
// ^^^^^^^^^^^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
} | ||
|
||
class C4 { | ||
external dynamic noSuchMethod(int i); | ||
// ^^^^^^^^^^^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
} | ||
|
||
main() { | ||
print(C1); | ||
print(C2); | ||
print(C3); | ||
print(C4); | ||
} |
Oops, something went wrong.