Skip to content

Commit

Permalink
Fixes dart-lang#2388. Add tests for the new method/setter rules. Upda…
Browse files Browse the repository at this point in the history
…te assertions
  • Loading branch information
sgrekhov committed Nov 22, 2023
1 parent 55f9ad0 commit 7f7a798
Show file tree
Hide file tree
Showing 7 changed files with 198 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

/// @assertion We say that an extension type declaration DV has a non-extension
/// type member named n in the case where DV does not declare a member named n,
/// but DV has a direct extension type superinterface V that has a non-extension
/// type member named n, or DV has a direct non-extension type superinterface T
/// whose interface contains a member signature named n.
/// @assertion We say that an extension type declaration DV has an extension
/// type member named n in the cases where:
/// - DV declares a member named n.
/// - DV has no such declaration, but DV has a direct extension type
/// superinterface V that has an extension type member named n due to a member
/// declaration DM2, and DV does not declare a member that precludes DM2.
///
/// @description Checks that if an extension type `ET` has a superinterface with
/// a member `m` then this member is also presents in `ET`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

/// @assertion We say that an extension type declaration DV has a non-extension
/// type member named n in the case where DV does not declare a member named n,
/// but DV has a direct extension type superinterface V that has a non-extension
/// type member named n, or DV has a direct non-extension type superinterface T
/// whose interface contains a member signature named n.
/// @assertion We say that an extension type declaration DV has an extension
/// type member named n in the cases where:
/// - DV declares a member named n.
/// - DV has no such declaration, but DV has a direct extension type
/// superinterface V that has an extension type member named n due to a member
/// declaration DM2, and DV does not declare a member that precludes DM2.
///
/// @description Checks that if an extension type `ET` has a superinterface with
/// a member `m` then this member is also presents in `ET`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

/// @assertion We say that an extension type declaration DV has a non-extension
/// type member named n in the case where DV does not declare a member named n,
/// but DV has a direct extension type superinterface V that has a non-extension
/// type member named n, or DV has a direct non-extension type superinterface T
/// whose interface contains a member signature named n.
/// @assertion We say that an extension type declaration DV has an extension
/// type member named n in the cases where:
/// - DV declares a member named n.
/// - DV has no such declaration, but DV has a direct extension type
/// superinterface V that has an extension type member named n due to a member
/// declaration DM2, and DV does not declare a member that precludes DM2.
///
/// @description Checks that if an extension type `ET` has a superinterface with
/// a member `m` then this member is also presents in `ET`v but members of its
/// a member `m` then this member is also presents in `ET` but members of its
/// representation type are not
/// @author sgrekhov22@gmail.com
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

/// @assertion We say that an extension type declaration DV has a non-extension
/// type member named n in the case where DV does not declare a member named n,
/// but DV has a direct extension type superinterface V that has a non-extension
/// type member named n, or DV has a direct non-extension type superinterface T
/// whose interface contains a member signature named n.
/// @assertion We say that an extension type declaration DV has an extension
/// type member named n in the cases where:
/// - DV declares a member named n.
/// - DV has no such declaration, but DV has a direct extension type
/// superinterface V that has an extension type member named n due to a member
/// declaration DM2, and DV does not declare a member that precludes DM2.
///
/// @description Checks that method inherited from superinterface can be
/// abstract
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

/// @assertion We say that an extension type declaration DV has an extension
/// type member named n in the cases where:
/// - DV declares a member named n.
/// - DV has no such declaration, but DV has a direct extension type
/// superinterface V that has an extension type member named n due to a member
/// declaration DM2, and DV does not declare a member that precludes DM2.
///
/// @description Checks that it is no error if an extension type declares a
/// getter that precludes inherited members
/// @author sgrekhov22@gmail.com
// SharedOptions=--enable-experiment=inline-class

import "../../Utils/expect.dart";

extension type V1(int id) {
void n(int n) {}
}

extension type V2(int id) {
String get n => "V2";
}

extension type V3(int id) {
void set n(int n) {}
}

extension type ET1(int id) implements V1 {
bool get n => true;
}

extension type ET2(int id) implements V2 {
bool get n => true;
}

extension type ET3(int id) implements V3 {
bool get n => true;
}

extension type ET4(int id) implements V1, V2, V3 {
bool get n => true;
}

main() {
Expect.isTrue(ET1(42).n);
Expect.isTrue(ET2(42).n);
Expect.isTrue(ET3(42).n);
Expect.isTrue(ET4(42).n);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

/// @assertion We say that an extension type declaration DV has an extension
/// type member named n in the cases where:
/// - DV declares a member named n.
/// - DV has no such declaration, but DV has a direct extension type
/// superinterface V that has an extension type member named n due to a member
/// declaration DM2, and DV does not declare a member that precludes DM2.
///
/// @description Checks that it is no error if an extension type declares a
/// method that precludes inherited members
/// @author sgrekhov22@gmail.com
// SharedOptions=--enable-experiment=inline-class

import "../../Utils/expect.dart";

extension type V1(int id) {
void n(int n) {}
}

extension type V2(int id) {
String get n => "V2";
}

extension type V3(int id) {
void set n(int n) {}
}

extension type ET1(int id) implements V1 {
T n<T>(T t) => t;
}

extension type ET2(int id) implements V2 {
T n<T>(T t) => t;
}

extension type ET3(int id) implements V3 {
T n<T>(T t) => t;
}

extension type ET4(int id) implements V1, V2, V3 {
T n<T>(T t) => t;
}

main() {
Expect.isTrue(ET1(42).n<bool>(true));
Expect.isTrue(ET2(42).n<bool>(true));
Expect.isTrue(ET3(42).n<bool>(true));
Expect.isTrue(ET4(42).n<bool>(true));
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

/// @assertion We say that an extension type declaration DV has an extension
/// type member named n in the cases where:
/// - DV declares a member named n.
/// - DV has no such declaration, but DV has a direct extension type
/// superinterface V that has an extension type member named n due to a member
/// declaration DM2, and DV does not declare a member that precludes DM2.
///
/// @description Checks that it is no error if an extension type declares a
/// setter that precludes inherited members
/// @author sgrekhov22@gmail.com
// SharedOptions=--enable-experiment=inline-class

import "../../Utils/expect.dart";

String log = "";

extension type V1(int id) {
void n(int n) {}
}

extension type V2(int id) {
String get n => "V2";
}

extension type V3(int id) {
void set n(int n) {}
}

extension type ET1(int id) implements V1 {
void set n(String v) {
log += v;
}
}

extension type ET2(int id) implements V2 {
void set n(String v) {
log += v;
}
}

extension type ET3(int id) implements V3 {
void set n(String v) {
log += v;
}
}

extension type ET4(int id) implements V1, V2, V3 {
void set n(String v) {
log += v;
}
}

main() {
Expect.equals("1", ET1(42).n = "1");
log = "";
Expect.equals("2", ET2(42).n = "2");
log = "";
Expect.equals("3", ET3(42).n = "3");
log = "";
Expect.equals("4", ET4(42).n = "4");
log = "";
}

0 comments on commit 7f7a798

Please sign in to comment.