[beta][vm] Fix call-through-getter runtime handling.
This should look for `dyn:call` instead of `call`. If it was a non-dynamic call, we would hit an invoke-field-dispatcher instead.
TEST=ci
Bug: https://github.com/dart-lang/sdk/issues/50697
Cherry-pick: https://dart-review.googlesource.com/c/sdk/+/274265
Change-Id: I3219819c8239774dae82840d810ff715b02165d3
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/275843
Reviewed-by: Siva Annamalai <asiva@google.com>
Commit-Queue: Kevin Chisholm <kevinjchisholm@google.com>
diff --git a/runtime/vm/object.cc b/runtime/vm/object.cc
index df8fb57..665ba2d 100644
--- a/runtime/vm/object.cc
+++ b/runtime/vm/object.cc
@@ -20332,7 +20332,7 @@
// Try to resolve a "call" method.
Zone* zone = Thread::Current()->zone();
Function& call_function = Function::Handle(
- zone, Resolver::ResolveDynamicAnyArgs(zone, cls, Symbols::call(),
+ zone, Resolver::ResolveDynamicAnyArgs(zone, cls, Symbols::DynamicCall(),
/*allow_add=*/false));
if (call_function.IsNull()) {
return false;
diff --git a/tests/language/call/dynamic_call_through_getter_test.dart b/tests/language/call/dynamic_call_through_getter_test.dart
new file mode 100644
index 0000000..cf70299
--- /dev/null
+++ b/tests/language/call/dynamic_call_through_getter_test.dart
@@ -0,0 +1,26 @@
+// Copyright (c) 2022, 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.
+
+// Reduction of https://github.com/flutter/flutter/issues/116405
+
+import "package:expect/expect.dart";
+
+class Foo {
+ Foo(this.bar);
+ Bar bar;
+}
+
+class Bar {
+ int call(int x) => x * 2;
+}
+
+@pragma("vm:never-inline")
+@pragma("dart2js:noInline")
+int doCallThroughGetter(dynamic foo, int x) {
+ return foo.bar(x);
+}
+
+void main() {
+ Expect.equals(4, doCallThroughGetter(Foo(Bar()), 2));
+}
diff --git a/tests/language_2/call/dynamic_call_through_getter_test.dart b/tests/language_2/call/dynamic_call_through_getter_test.dart
new file mode 100644
index 0000000..48dc8ce
--- /dev/null
+++ b/tests/language_2/call/dynamic_call_through_getter_test.dart
@@ -0,0 +1,28 @@
+// Copyright (c) 2022, 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.
+
+// @dart = 2.9
+
+// Reduction of https://github.com/flutter/flutter/issues/116405
+
+import "package:expect/expect.dart";
+
+class Foo {
+ Foo(this.bar);
+ Bar bar;
+}
+
+class Bar {
+ int call(int x) => x * 2;
+}
+
+@pragma("vm:never-inline")
+@pragma("dart2js:noInline")
+int doCallThroughGetter(dynamic foo, int x) {
+ return foo.bar(x);
+}
+
+void main() {
+ Expect.equals(4, doCallThroughGetter(Foo(Bar()), 2));
+}