mirror of
https://github.com/dart-lang/sdk
synced 2024-09-05 00:13:50 +00:00
![Alexander Markov](/assets/img/avatar_default.png)
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>
44 lines
974 B
Dart
44 lines
974 B
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.
|
|
|
|
import "package:expect/expect.dart";
|
|
|
|
@pragma('weak-tearoff-reference')
|
|
Function? weakRef(Function? x) => x;
|
|
|
|
int used1() => 10;
|
|
int used2() => 20;
|
|
int unused1() => 30;
|
|
int unused2() => 40;
|
|
|
|
void test(int expectedResult, bool isUsed, Function? ref) {
|
|
print(ref);
|
|
if (isUsed) {
|
|
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();
|
|
}
|