|
| 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