Files
sdk/tests/language/vm/static_weak_reference_test.dart
T
Alexander Markov 143e4e9dc8 [vm/aot/tfa] Static weak references to method tearoffs
TEST=pkg/vm/testcases/transformations/type_flow/transformer/weak.dart
TEST=language/vm/static_weak_reference_test
TEST=language/vm/static_weak_reference_error_test

Bug: b/269223463
Change-Id: I23c8229c39217aa1c3f9fb576d8eefa5ceb1d8ad
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/283421
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Slava Egorov <vegorov@google.com>
2023-02-22 01:01:29 +00:00

48 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 'vm:weak-tearoff-reference' pragma.
import 'dart:io' show Platform;
import "package:expect/expect.dart";
@pragma('vm:weak-tearoff-reference')
Function? weakRef(Function? x) => x;
int used1() => 10;
int used2() => 20;
int unused1() => 30;
int unused2() => 40;
final bool isAot = Platform.executable.contains('dart_precompiled_runtime');
void test(int expectedResult, bool isUsed, Function? ref) {
print(ref);
if (isUsed || !isAot) {
Expect.isNotNull(ref);
Expect.equals(expectedResult, ref!());
} else {
Expect.isNull(ref);
}
}
class A {
int foo1() => used1() + 1;
Function foo2() => used2;
int bar1() => unused1() + 1;
Function bar2() => unused2;
}
main() {
test(10, true, weakRef(used1));
test(20, true, weakRef(used2));
test(30, false, weakRef(unused1));
test(40, false, weakRef(unused2));
A a = A();
a.foo1();
a.foo2();
}