dart-sdk/tests/language/static_weak_reference_function_apply_test.dart
Alexander Markov e27923a5a0 [dart2js] Static weak references to method tearoffs
TEST=language/static_weak_reference_test
TEST=language/static_weak_reference_error_test

Bug: b/269223463

Cq-Include-Trybots: luci.dart.try:vm-kernel-precomp-nnbd-linux-release-x64-try
Change-Id: I760476a7c81751f6c302f21251b525cb5c916c02
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/284489
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Stephen Adams <sra@google.com>
2023-03-02 20:04:19 +00:00

38 lines
1.1 KiB
Dart

// 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.
// Test 'weak-tearoff-reference' pragma on tear-offs,
// which results are passed to Function.apply.
import "package:expect/expect.dart";
typedef FF = int Function({int x, int y});
typedef GG = FF Function();
@pragma('weak-tearoff-reference')
GG? weakRef(GG? x) => x;
FF foo1() => ({int x = 100, int y = 10}) => 1000 + x + y;
FF foo2() => ({int x = 200, int y = 20}) => 2000 + x + y;
FF foo3() => ({int x = 300, int y = 30}) => 3000 + x + y;
main() {
print(foo1()());
print(foo2()());
// No call to foo3(), should be removed.
final f1 = foo1;
Expect.isNotNull(f1);
Expect.equals(101010, Function.apply(f1(), [], {#x: 100000}));
final f2 = weakRef(foo2);
Expect.isNotNull(f2);
Expect.equals(202020, Function.apply(f2!(), [], {#x: 200000}));
final f3 = weakRef(foo3);
Expect.isNull(f3);
if (f3 != null) print(Function.apply(f3(), [], {#x: 300000}));
}