-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Open
Labels
area-dart2wasmIssues for the dart2wasm compiler.Issues for the dart2wasm compiler.area-web-jsIssues related to JavaScript support for Dart Web, including DDC, dart2js, and JS interop.Issues related to JavaScript support for Dart Web, including DDC, dart2js, and JS interop.legacy-area-front-endLegacy: Use area-dart-model instead.Legacy: Use area-dart-model instead.web-dart2js
Description
The test method_must_not_be_field_test checks that dynamic invocations do not implicitly access the field "call":
sdk/tests/language/call/method_must_not_be_field_test.dart
Lines 13 to 28 in 0c32c7f
C c = new C(); | |
dynamic d = c; | |
// The presence of a field named `call` does not permit the class `C` to be | |
// implicitly called. | |
c(); //# 01: compile-time error | |
// Nor does it permit an implicit tear-off of `call`. | |
void Function() f = c; //# 02: compile-time error | |
// Nor does it permit a dynamic invocation of `call`. | |
Expect.throws(() => d()); //# 03: ok | |
// However, all these things are possible if `call` is mentioned explicitly. | |
c.call(); //# 04: ok | |
void Function() f = c.call; //# 05: ok | |
d.call(); //# 06: ok | |
(d.call)(); //# 07: ok |
This test was introduced in https://dart-review.googlesource.com/c/sdk/+/42020, and it currently fails in VM, dart2js (at least on dartpad), and dart2wasm.
This test is in sync with the static call semantics when the receiver has a "call" field but not a method, e.g.
class C {
void Function() call = () {};
}
main() {
C()();
}
Fails with compile-time error:
test.dart:6:6: Error: Cannot invoke an instance of 'C' because it declares 'call' to be something other than a method.
- 'C' is from 'test.dart'.
Try changing 'call' to a method or explicitly invoke 'call'.
C()();
^
Metadata
Metadata
Assignees
Labels
area-dart2wasmIssues for the dart2wasm compiler.Issues for the dart2wasm compiler.area-web-jsIssues related to JavaScript support for Dart Web, including DDC, dart2js, and JS interop.Issues related to JavaScript support for Dart Web, including DDC, dart2js, and JS interop.legacy-area-front-endLegacy: Use area-dart-model instead.Legacy: Use area-dart-model instead.web-dart2js