Skip to content

Commit f644a30

Browse files
stereotype441Commit Queue
authored and
Commit Queue
committed
Test field promotability for fields "passed through" extension types via "implements".
Change-Id: Ic5bbb5eb12259d076b697bce7624cde181d7beb6 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/332484 Commit-Queue: Paul Berry <[email protected]> Reviewed-by: Erik Ernst <[email protected]>
1 parent 5cebb0f commit f644a30

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
// Copyright (c) 2023, 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+
// Verifies that when an extension type declaration includes an "implements"
6+
// clause, and an attempt is made to promote a property of the underlying
7+
// representation type, the promotability is inherited from the underlying
8+
// representation type member.
9+
10+
// SharedOptions=--enable-experiment=inline-class
11+
12+
import '../static_type_helper.dart';
13+
14+
class C {
15+
final int? _promotable = 0;
16+
int? _notPromotable = 0;
17+
}
18+
19+
extension type E(C c) implements C {
20+
void viaImplicitThis() {
21+
if (_promotable != null) {
22+
_promotable.expectStaticType<Exactly<int>>();
23+
}
24+
if (_notPromotable != null) {
25+
_notPromotable.expectStaticType<Exactly<int?>>();
26+
}
27+
}
28+
29+
void viaExplicitThis() {
30+
if (this._promotable != null) {
31+
this._promotable.expectStaticType<Exactly<int>>();
32+
}
33+
if (this._notPromotable != null) {
34+
this._notPromotable.expectStaticType<Exactly<int?>>();
35+
}
36+
}
37+
}
38+
39+
void viaGeneralPropertyAccess(E e) {
40+
if ((e)._promotable != null) {
41+
(e)._promotable.expectStaticType<Exactly<int>>();
42+
}
43+
if ((e)._notPromotable != null) {
44+
(e)._notPromotable.expectStaticType<Exactly<int?>>();
45+
}
46+
}
47+
48+
void viaPrefixedIdentifier(E e) {
49+
// Note: the analyzer has a special representation for property accesses of
50+
// the form `IDENTIFIER.IDENTIFIER`, so we test this form separately.
51+
if (e._promotable != null) {
52+
e._promotable.expectStaticType<Exactly<int>>();
53+
}
54+
if (e._notPromotable != null) {
55+
e._notPromotable.expectStaticType<Exactly<int?>>();
56+
}
57+
}
58+
59+
main() {
60+
E(C()).viaImplicitThis();
61+
E(C()).viaExplicitThis();
62+
viaGeneralPropertyAccess(E(C()));
63+
viaPrefixedIdentifier(E(C()));
64+
}

0 commit comments

Comments
 (0)