Skip to content

Commit a304e5b

Browse files
dcharkesCommit Bot
authored andcommitted
[cfe/ffi] Test Finalizables in extension methods
`Finalizable`s with extension methods work by virtue of being desugared into static methods and the `Finalizable`s being normal arguments. If we ever change the representation of extension methods, `Finalizable`s would need to be treated specially. This test will catch that. TEST=pkg/vm/test/transformations/ffi_test.dart Bug: #49643 (comment) Change-Id: I68cfbc098386a88495d37417c6eb7295b89bfb95 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/255123 Reviewed-by: Tess Strickland <[email protected]> Commit-Queue: Daco Harkes <[email protected]>
1 parent bc090dc commit a304e5b

File tree

2 files changed

+90
-0
lines changed

2 files changed

+90
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Copyright (c) 2022, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
// @dart=2.16
6+
7+
import 'dart:ffi';
8+
9+
class Foo implements Finalizable {}
10+
11+
void main() {
12+
final foo = Foo();
13+
foo.bar();
14+
Object().baz(foo);
15+
}
16+
17+
extension on Finalizable {
18+
int bar() {
19+
print('123');
20+
// Should generate a fence for `this` before returning 4.
21+
return 4;
22+
}
23+
}
24+
25+
extension on Object {
26+
int baz(Foo foo) {
27+
print('456');
28+
// Should generate a fence for `foo` before returning 5.
29+
return 5;
30+
}
31+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
library #lib /*isNonNullableByDefault*/;
2+
import self as self;
3+
import "dart:core" as core;
4+
import "dart:ffi" as ffi;
5+
import "dart:_internal" as _in;
6+
7+
import "dart:ffi";
8+
9+
class Foo extends core::Object implements ffi::Finalizable {
10+
synthetic constructor •() → self::Foo
11+
: super core::Object::•()
12+
;
13+
}
14+
extension _extension#0 on ffi::Finalizable {
15+
method bar = self::_extension#0|bar;
16+
tearoff bar = self::_extension#0|get#bar;
17+
}
18+
extension _extension#1 on core::Object {
19+
method baz = self::_extension#1|baz;
20+
tearoff baz = self::_extension#1|get#baz;
21+
}
22+
static method main() → void {
23+
final self::Foo foo = new self::Foo::•();
24+
self::_extension#0|bar(foo);
25+
self::_extension#1|baz(new core::Object::•(), foo);
26+
_in::reachabilityFence(foo);
27+
}
28+
static method _extension#0|bar(lowered final ffi::Finalizable #this) → core::int {
29+
core::print("123");
30+
return block {
31+
final core::int :expressionValueWrappedFinalizable = 4;
32+
_in::reachabilityFence(#this);
33+
} =>:expressionValueWrappedFinalizable;
34+
}
35+
static method _extension#0|get#bar(lowered final ffi::Finalizable #this) → () → core::int {
36+
return block {
37+
final () → core::int :expressionValueWrappedFinalizable = () → core::int {
38+
return block {
39+
final core::int :expressionValueWrappedFinalizable = self::_extension#0|bar(#this);
40+
_in::reachabilityFence(#this);
41+
} =>:expressionValueWrappedFinalizable;
42+
};
43+
_in::reachabilityFence(#this);
44+
} =>:expressionValueWrappedFinalizable;
45+
}
46+
static method _extension#1|baz(lowered final core::Object #this, self::Foo foo) → core::int {
47+
core::print("456");
48+
return block {
49+
final core::int :expressionValueWrappedFinalizable = 5;
50+
_in::reachabilityFence(foo);
51+
} =>:expressionValueWrappedFinalizable;
52+
}
53+
static method _extension#1|get#baz(lowered final core::Object #this) → (self::Foo) → core::int
54+
return (self::Foo foo) → core::int {
55+
return block {
56+
final core::int :expressionValueWrappedFinalizable = self::_extension#1|baz(#this, foo);
57+
_in::reachabilityFence(foo);
58+
} =>:expressionValueWrappedFinalizable;
59+
};

0 commit comments

Comments
 (0)