Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #2388. Add tests for the new method/setter rules. Update assertions #2393

Merged
merged 3 commits into from
Nov 23, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
eernstg marked this conversation as resolved.
Show resolved Hide resolved
///
/// @description Checks that if an extension type `ET` has a superinterface with
/// a member `m` then this member is also presents in `ET`
/// a member `m` then this member is also present in `ET`
/// @author sgrekhov22@gmail.com

// SharedOptions=--enable-experiment=inline-class
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 present in `ET` but members of its
/// representation type are not
/// @author sgrekhov22@gmail.com

Expand All @@ -25,18 +26,6 @@ extension type ET1(int id) implements ET0 {}

extension type ET2(int id) implements num {}
eernstg marked this conversation as resolved.
Show resolved Hide resolved

class I {
int i = 0;
}

class J extends I {
int j = 1;
}

extension type ET3(J rep) implements I {
int get jOfEt3 => rep.j;
}

main() {
ET1 et1 = ET1(42);
et1.m1();
Expand All @@ -45,21 +34,5 @@ main() {
et1.ceil();
// ^^^^
// [analyzer] unspecified
// [cfe] unspecified

ET2 et2 = ET2(42);
et2.ceil();
et2.isOdd;
// ^^^^^
// [analyzer] unspecified
// [cfe] unspecified

var et3 = ET3(J());
et3.rep;
et3.i;
et3.jOfEt3;
et3.j;
// ^
// [analyzer] unspecified
// [cfe] unspecified
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
// 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 a getter doesn't preclude setter and vice versa
/// @author sgrekhov22@gmail.com

// SharedOptions=--enable-experiment=inline-class

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

String log = "";

extension type V1(int _) {
String get n => "V1";
}

extension type V2(int _) {
void set n(String n) {
log = "V2: $n";
}
}

extension type V0(int _) implements V1, V2 {}

extension type ET1(V1 _) implements V1 {
void set n(String v) {
log = "ET1: $v";
}
}

extension type ET2(V2 _) implements V2 {
String get n => "ET2";
}

extension type ET3(V0 _) implements V1, V2 {
String get n => "ET3";
}

extension type ET4(V0 _) implements V1, V2 {
void set n(String v) {
log = "ET4: $v";
}
}

main() {
final v = V0(0);
Expect.equals("V1", ET1(v).n);
ET1(v).n = "a";
Expect.equals("ET1: a", log);
log = "";

Expect.equals("ET2", ET2(v).n);
ET2(v).n = "b";
Expect.equals("V2: b", log);
log = "";

Expect.equals("ET3", ET3(v).n);
ET3(v).n = "c";
Expect.equals("V2: c", log);
log = "";

Expect.equals("V1", ET4(v).n);
ET4(v).n = "d";
Expect.equals("ET4: d", log);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// 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 an extension type declares a method or setter then
/// they preclude inherited members
/// @author sgrekhov22@gmail.com

// SharedOptions=--enable-experiment=inline-class

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

String log = "";

extension type V1(int _) {
String n() => "V1";
}

extension type V2(int _) {
void set n(String v) {
log = "V2: $v";
}
}

extension type ET1(V1 _) implements V1 {
void set n(String v) {
log = "ET1: $v";
}
}

extension type ET2(V2 _) implements V2 {
String n() => "ET2";
}

extension type ET3(V1 _) implements V1 {
void set n(int v) {
log = "ET3: $v";
}
}

extension type ET4(V2 _) implements V2 {
T n<T>(T t) => t;
}

main() {
ET1(V1(0)).n = "1";
Expect.equals("ET1: 1", log);
log = "";
Expect.equals("ET2", ET2(V2(0)).n());
ET3(V1(0)).n = 3;
Expect.equals("ET3: 3", log);
Expect.equals(42, ET4(V2(0)).n<int>(42));
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// 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 an extension type declares a method it precludes
/// inherited members
/// @author sgrekhov22@gmail.com

// SharedOptions=--enable-experiment=inline-class

extension type V1(int _) {
String n() => "V1";
}

extension type V2(int _) {
void set n(String v) {}
}

extension type ET1(V1 _) implements V1 {
void set n(String v) {}
}

extension type ET2(V2 _) implements V2 {
String n() => "ET2";
}

extension type ET3(V1 _) implements V1 {
void set n(int v) {}
}

extension type ET4(V2 _) implements V2 {
int n() => 42;
}

main() {
ET1(V1(0)).n();
// ^
// [analyzer] unspecified
// [cfe] unspecified

ET2(V2(0)).n = "42";
// ^
// [analyzer] unspecified
// [cfe] unspecified

ET3(V1(0)).n();
// ^
// [analyzer] unspecified
// [cfe] unspecified

ET4(V2(0)).n = "42";
// ^
// [analyzer] unspecified
// [cfe] unspecified
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// 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 a getter doesn't preclude setter and vice versa
eernstg marked this conversation as resolved.
Show resolved Hide resolved
/// @author sgrekhov22@gmail.com

// SharedOptions=--enable-experiment=inline-class

extension type V1(int _) {
String get n => "V1";
}

extension type V2(int _) {
void set n(String n) {}
}

extension type V0(int _) implements V1, V2 {}

extension type ET1(V1 _) implements V1 {
void set n(int v) {}
// ^
// [analyzer] unspecified
// [cfe] unspecified
}

extension type ET2(V2 _) implements V2 {
int get n => 2;
// ^
// [analyzer] unspecified
// [cfe] unspecified
}

extension type ET3(V0 _) implements V1, V2 {
int get n => 3;
// ^
// [analyzer] unspecified
// [cfe] unspecified
}

extension type ET4(V0 _) implements V1, V2 {
void set n(int v) {}
// ^
// [analyzer] unspecified
// [cfe] unspecified
}

main() {
print(ET1);
print(ET2);
print(ET3);
print(ET4);
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,16 @@

/// @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.
/// and one of the following criteria is satisfied:
/// - DV has a direct extension type superinterface V that has a non-extension
/// type member with signature m and name n, and DV does not declare a member
/// that precludes m.
/// - DV has a direct non-extension type superinterface whose interface contains
/// a member signature m named n, and DV does not declare a member that
/// precludes m.
///
/// @description Checks that if an extension type `ET` has a superinterface with
/// a member `m` then this member is also presents in `ET`
/// a member `m` then this member is also present in `ET`
/// @author sgrekhov22@gmail.com

// SharedOptions=--enable-experiment=inline-class
Expand Down
Loading