|
| 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 | +/// @assertion Assume that DV is an extension type declaration named Name, and |
| 6 | +/// V1 occurs as one of the <type>s in the <interfaces> of DV. In this case we |
| 7 | +/// say that V1 is a superinterface of DV. |
| 8 | +/// ... |
| 9 | +/// Assume that DV is an extension type declaration named Name, and the type V1, |
| 10 | +/// declared by DV1, is a superinterface of DV (V1 could be an extension type or |
| 11 | +/// a non-extension type). Let m be the name of a member of V1. If DV also |
| 12 | +/// declares a member named m then the latter may be considered similar to a |
| 13 | +/// declaration that "overrides" the former. However, it should be noted that |
| 14 | +/// extension type method invocation is resolved statically, and hence there is |
| 15 | +/// no override relationship among the two in the traditional object-oriented |
| 16 | +/// sense (that is, it will never occur that the statically known declaration is |
| 17 | +/// the member of V1, and the member invoked at run time is the one in DV). A |
| 18 | +/// receiver with static type V1 will invoke the declaration in DV1, and a |
| 19 | +/// receiver with a static type which is a reference to DV (like Name or |
| 20 | +/// Name<...>) will invoke the one in DV. |
| 21 | +/// |
| 22 | +/// Hence, we use a different word to describe the relationship between a member |
| 23 | +/// named m of a superinterface, and a member named m which is declared by the |
| 24 | +/// subinterface: We say that the latter redeclares the former. |
| 25 | +/// |
| 26 | +/// In particular, if two different declarations of m are inherited from two |
| 27 | +/// superinterfaces then the subinterface can resolve the conflict by |
| 28 | +/// redeclaring m. |
| 29 | +/// |
| 30 | +/// There is no notion of having a 'correct override relation' here. With |
| 31 | +/// extension types, any member signature can redeclare any other member |
| 32 | +/// signature with the same name, including the case where a method is |
| 33 | +/// redeclared by a getter, or vice versa. |
| 34 | +/// |
| 35 | +/// @description Checks that it is a compile-time error if an extension type |
| 36 | +/// declaration `DV` declares a member that conflicts with an inherited one |
| 37 | + |
| 38 | +
|
| 39 | +// SharedOptions=--enable-experiment=inline-class |
| 40 | + |
| 41 | +extension type V(int id) { |
| 42 | + external int id2; |
| 43 | +} |
| 44 | + |
| 45 | +extension type ET(int id) implements V { |
| 46 | + int id2() => id; |
| 47 | +// ^^^ |
| 48 | +// [analyzer] unspecified |
| 49 | +// [cfe] unspecified |
| 50 | +} |
| 51 | + |
| 52 | +main() { |
| 53 | + print(ET); |
| 54 | +} |
0 commit comments