|
| 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 inline class declaration named Inline, 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 | +/// A compile-time error occurs if an inline class declaration DV has two |
| 10 | +/// superinterfaces V1 and V2, where both V1 and V2 have a member named m, and |
| 11 | +/// the two declarations of m are distinct declarations, and DV does not declare |
| 12 | +/// a member named m. |
| 13 | +/// |
| 14 | +/// @description Checks that it is no an error if an inline class declaration |
| 15 | +/// `DV` has superinterface `V` with member `m` and redeclares this member even |
| 16 | +/// this is not a correct override for a regular class |
| 17 | + |
| 18 | +
|
| 19 | +// SharedOptions=--enable-experiment=inline-class |
| 20 | + |
| 21 | +import "../../Utils/expect.dart"; |
| 22 | + |
| 23 | +String log = ""; |
| 24 | + |
| 25 | +inline class V { |
| 26 | + final int id; |
| 27 | + V(this.id); |
| 28 | + |
| 29 | + int foo() => 0; |
| 30 | + int bar(num n) => 0; |
| 31 | + void set setter(num i) { |
| 32 | + log += "V.setter="; |
| 33 | + } |
| 34 | +} |
| 35 | + |
| 36 | +inline class C1 implements V { |
| 37 | + final int id; |
| 38 | + C1(this.id); |
| 39 | + |
| 40 | + num foo() => 1; |
| 41 | + int bar(int n) => 1; |
| 42 | + void set setter(int i) { |
| 43 | + log += "C1.setter="; |
| 44 | + } |
| 45 | +} |
| 46 | + |
| 47 | +inline class C2 implements V { |
| 48 | + final int id; |
| 49 | + C2(this.id); |
| 50 | + |
| 51 | + int get foo => 2; |
| 52 | + String get bar => "2"; |
| 53 | + void set setter(String s) { |
| 54 | + log += "C2.setter="; |
| 55 | + } |
| 56 | +} |
| 57 | + |
| 58 | +main() { |
| 59 | + V v1 = C1(0); |
| 60 | + Expect.equals(0, v1.foo()); |
| 61 | + Expect.equals(0, v1.bar(3.14)); |
| 62 | + v1.setter = 1; |
| 63 | + Expect.equals("V.setter=", log); |
| 64 | + log = ""; |
| 65 | + |
| 66 | + V v2 = C2(0); |
| 67 | + Expect.equals(0, v2.foo()); |
| 68 | + Expect.equals(0, v2.bar(3.14)); |
| 69 | + v2.setter = 1; |
| 70 | + Expect.equals("V.setter=", log); |
| 71 | + log = ""; |
| 72 | + |
| 73 | + C1 c1 = C1(0); |
| 74 | + Expect.equals(1, c1.foo()); |
| 75 | + Expect.equals(1, c1.bar(42)); |
| 76 | + c1.setter = 1; |
| 77 | + Expect.equals("C1.setter=", log); |
| 78 | + log = ""; |
| 79 | + |
| 80 | + C2 c2 = C2(0); |
| 81 | + Expect.equals(2, c2.foo); |
| 82 | + Expect.equals("2", c2.bar); |
| 83 | + c2.setter = "1"; |
| 84 | + Expect.equals("C2.setter=", log); |
| 85 | + log = ""; |
| 86 | +} |
0 commit comments