Skip to content

Dynamic invocations incorrectly access "call" field in VM, dart2js, dart2wasm #51517

@osa1

Description

@osa1

The test method_must_not_be_field_test checks that dynamic invocations do not implicitly access the field "call":

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

No one assigned

    Labels

    area-dart2wasmIssues for the dart2wasm compiler.area-web-jsIssues related to JavaScript support for Dart Web, including DDC, dart2js, and JS interop.legacy-area-front-endLegacy: Use area-dart-model instead.web-dart2js

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions