dart-sdk/tests/language/closure/dynamic_test.dart
Tess Strickland d06d627c79 [vm] Remove --[no-]lazy-dispatchers flag.
No client of the VM uses this flag, only tests, and this flag was always
set to false in AOT mode. Thus, remove uses of this flag and instead
always lazily create dispatchers as needed when resolving method names
in JIT mode.

Remove the implicit value of `allow_add` for some Resolver
static methods. For callers that previously depended on the implicit
`true` value (which includes the AOT precompilier), pass `true` for
uses in the compiler and pass `!FLAG_precompiled_mode` for uses in the
runtime. Assert that `allow_add` is false when these methods are invoked
from the precompiled runtime.

Remove Resolver static methods that are no longer used.

TEST=ci

Change-Id: Ib6a7354f7a859e86743c381513a4129c14895753
Cq-Include-Trybots: luci.dart.try:vm-linux-debug-x64-try,vm-linux-release-x64-try,vm-aot-linux-debug-x64-try,vm-aot-linux-release-x64-try,vm-aot-mac-release-arm64-try,vm-mac-debug-arm64-try,vm-mac-release-arm64-try
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/366668
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Tess Strickland <sstrickl@google.com>
2024-06-06 10:56:12 +00:00

61 lines
2 KiB
Dart

// Copyright (c) 2020, 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.
//
// Test that dynamic invocation of closures works as expected, including
// appropriate type checks.
import 'package:expect/expect.dart';
class A {
final int nonce_;
const A(this.nonce_);
}
class B {
final int nonce_;
const B(this.nonce_);
}
class C extends A {
const C(int nonce) : super(nonce);
}
void main() {
dynamic f = (String a1, int a2, A a3,
{String n1 = "default_named", int n2 = -1, A n3 = const A(-1)}) {};
f("test_fixed", 1, A(1), n1: "test_named", n2: 2, n3: A(2));
// Test named argument permutations
f("test_fixed", 1, A(1), n1: "test_named", n3: A(2), n2: 2);
f("test_fixed", 1, A(1), n2: 2, n1: "test_named", n3: A(2));
f("test_fixed", 1, A(1), n2: 2, n3: A(2), n1: "test_named");
f("test_fixed", 1, A(1), n3: A(2), n1: "test_named", n2: 2);
f("test_fixed", 1, A(1), n3: A(2), n2: 2, n1: "test_named");
// Test subclasses match the type
f("test_fixed", 1, C(1), n1: "test_named", n2: 2, n3: A(2));
f("test_fixed", 1, A(1), n1: "test_named", n2: 2, n3: C(2));
// Should fail with no such method errors
Expect.throwsNoSuchMethodError(() => f());
Expect.throwsNoSuchMethodError(() => f("test_fixed", 1, A(1), n4: 4));
// Should fail with type errors
Expect.throwsTypeError(
() => f(100, 1, A(1), n1: "test_named", n2: 2, n3: A(2)));
Expect.throwsTypeError(
() => f("test_fixed", 1.1, A(1), n1: "test_named", n2: 2, n3: A(2)));
Expect.throwsTypeError(
() => f("test_fixed", 1, B(1), n1: "test_named", n2: 2, n3: A(2)));
Expect.throwsTypeError(
() => f("test_fixed", 1, A(1), n1: 100, n2: 2, n3: A(2)));
Expect.throwsTypeError(
() => f("test_fixed", 1, A(1), n1: "test_named", n2: 2.2, n3: A(2)));
Expect.throwsTypeError(
() => f("test_fixed", 1, A(1), n1: "test_named", n2: 2, n3: B(2)));
}