Skip to content

Commit c3c55b0

Browse files
authored
Fixes #2388. Add tests for the new method/setter rules. Update assertions (#2393)
Add tests for the new method/setter rules. Update assertions
1 parent d19c447 commit c3c55b0

13 files changed

+619
-52
lines changed

LanguageFeatures/Extension-types/static_analysis_member_invocation_A06_t01.dart

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
/// @assertion We say that an extension type declaration DV has a non-extension
6-
/// type member named n in the case where DV does not declare a member named n,
7-
/// but DV has a direct extension type superinterface V that has a non-extension
8-
/// type member named n, or DV has a direct non-extension type superinterface T
9-
/// whose interface contains a member signature named n.
5+
/// @assertion We say that an extension type declaration DV has an extension
6+
/// type member named n in the cases where:
7+
/// - DV declares a member named n.
8+
/// - DV has no such declaration, but DV has a direct extension type
9+
/// superinterface V that has an extension type member named n due to a member
10+
/// declaration DM2, and DV does not declare a member that precludes DM2.
1011
///
1112
/// @description Checks that if an extension type `ET` has a superinterface with
12-
/// a member `m` then this member is also presents in `ET`
13+
/// a member `m` then this member is also present in `ET`
1314
/// @author [email protected]
1415
1516
// SharedOptions=--enable-experiment=inline-class

LanguageFeatures/Extension-types/static_analysis_member_invocation_A06_t03.dart

Lines changed: 7 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
/// @assertion We say that an extension type declaration DV has a non-extension
6-
/// type member named n in the case where DV does not declare a member named n,
7-
/// but DV has a direct extension type superinterface V that has a non-extension
8-
/// type member named n, or DV has a direct non-extension type superinterface T
9-
/// whose interface contains a member signature named n.
5+
/// @assertion We say that an extension type declaration DV has an extension
6+
/// type member named n in the cases where:
7+
/// - DV declares a member named n.
8+
/// - DV has no such declaration, but DV has a direct extension type
9+
/// superinterface V that has an extension type member named n due to a member
10+
/// declaration DM2, and DV does not declare a member that precludes DM2.
1011
///
1112
/// @description Checks that if an extension type `ET` has a superinterface with
12-
/// a member `m` then this member is also presents in `ET`v but members of its
13+
/// a member `m` then this member is also present in `ET` but members of its
1314
/// representation type are not
1415
/// @author [email protected]
1516
@@ -23,20 +24,6 @@ extension type ET0(int id) {
2324

2425
extension type ET1(int id) implements ET0 {}
2526

26-
extension type ET2(int id) implements num {}
27-
28-
class I {
29-
int i = 0;
30-
}
31-
32-
class J extends I {
33-
int j = 1;
34-
}
35-
36-
extension type ET3(J rep) implements I {
37-
int get jOfEt3 => rep.j;
38-
}
39-
4027
main() {
4128
ET1 et1 = ET1(42);
4229
et1.m1();
@@ -45,21 +32,5 @@ main() {
4532
et1.ceil();
4633
// ^^^^
4734
// [analyzer] unspecified
48-
// [cfe] unspecified
49-
50-
ET2 et2 = ET2(42);
51-
et2.ceil();
52-
et2.isOdd;
53-
// ^^^^^
54-
// [analyzer] unspecified
55-
// [cfe] unspecified
56-
57-
var et3 = ET3(J());
58-
et3.rep;
59-
et3.i;
60-
et3.jOfEt3;
61-
et3.j;
62-
// ^
63-
// [analyzer] unspecified
6435
// [cfe] unspecified
6536
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
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 We say that an extension type declaration DV has an extension
6+
/// type member named n in the cases where:
7+
/// - DV declares a member named n.
8+
/// - DV has no such declaration, but DV has a direct extension type
9+
/// superinterface V that has an extension type member named n due to a member
10+
/// declaration DM2, and DV does not declare a member that precludes DM2.
11+
///
12+
/// @description Checks that a getter doesn't preclude setter and vice versa
13+
/// @author [email protected]
14+
15+
// SharedOptions=--enable-experiment=inline-class
16+
17+
import "../../Utils/expect.dart";
18+
19+
String log = "";
20+
21+
extension type V1(int _) {
22+
String get n => "V1";
23+
}
24+
25+
extension type V2(int _) {
26+
void set n(String n) {
27+
log = "V2: $n";
28+
}
29+
}
30+
31+
extension type V0(int _) implements V1, V2 {}
32+
33+
extension type ET1(V1 _) implements V1 {
34+
void set n(String v) {
35+
log = "ET1: $v";
36+
}
37+
}
38+
39+
extension type ET2(V2 _) implements V2 {
40+
String get n => "ET2";
41+
}
42+
43+
extension type ET3(V0 _) implements V1, V2 {
44+
String get n => "ET3";
45+
}
46+
47+
extension type ET4(V0 _) implements V1, V2 {
48+
void set n(String v) {
49+
log = "ET4: $v";
50+
}
51+
}
52+
53+
main() {
54+
final v = V0(0);
55+
Expect.equals("V1", ET1(v).n);
56+
ET1(v).n = "a";
57+
Expect.equals("ET1: a", log);
58+
log = "";
59+
60+
Expect.equals("ET2", ET2(v).n);
61+
ET2(v).n = "b";
62+
Expect.equals("V2: b", log);
63+
log = "";
64+
65+
Expect.equals("ET3", ET3(v).n);
66+
ET3(v).n = "c";
67+
Expect.equals("V2: c", log);
68+
log = "";
69+
70+
Expect.equals("V1", ET4(v).n);
71+
ET4(v).n = "d";
72+
Expect.equals("ET4: d", log);
73+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
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 We say that an extension type declaration DV has an extension
6+
/// type member named n in the cases where:
7+
/// - DV declares a member named n.
8+
/// - DV has no such declaration, but DV has a direct extension type
9+
/// superinterface V that has an extension type member named n due to a member
10+
/// declaration DM2, and DV does not declare a member that precludes DM2.
11+
///
12+
/// @description Checks that an extension type declares a method or setter then
13+
/// they preclude inherited members
14+
/// @author [email protected]
15+
16+
// SharedOptions=--enable-experiment=inline-class
17+
18+
import "../../Utils/expect.dart";
19+
20+
String log = "";
21+
22+
extension type V1(int _) {
23+
String n() => "V1";
24+
}
25+
26+
extension type V2(int _) {
27+
void set n(String v) {
28+
log = "V2: $v";
29+
}
30+
}
31+
32+
extension type ET1(V1 _) implements V1 {
33+
void set n(String v) {
34+
log = "ET1: $v";
35+
}
36+
}
37+
38+
extension type ET2(V2 _) implements V2 {
39+
String n() => "ET2";
40+
}
41+
42+
extension type ET3(V1 _) implements V1 {
43+
void set n(int v) {
44+
log = "ET3: $v";
45+
}
46+
}
47+
48+
extension type ET4(V2 _) implements V2 {
49+
T n<T>(T t) => t;
50+
}
51+
52+
main() {
53+
ET1(V1(0)).n = "1";
54+
Expect.equals("ET1: 1", log);
55+
log = "";
56+
Expect.equals("ET2", ET2(V2(0)).n());
57+
ET3(V1(0)).n = 3;
58+
Expect.equals("ET3: 3", log);
59+
Expect.equals(42, ET4(V2(0)).n<int>(42));
60+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
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 We say that an extension type declaration DV has an extension
6+
/// type member named n in the cases where:
7+
/// - DV declares a member named n.
8+
/// - DV has no such declaration, but DV has a direct extension type
9+
/// superinterface V that has an extension type member named n due to a member
10+
/// declaration DM2, and DV does not declare a member that precludes DM2.
11+
///
12+
/// @description Checks that an extension type declares a method it precludes
13+
/// inherited members
14+
/// @author [email protected]
15+
16+
// SharedOptions=--enable-experiment=inline-class
17+
18+
extension type V1(int _) {
19+
String n() => "V1";
20+
}
21+
22+
extension type V2(int _) {
23+
void set n(String v) {}
24+
}
25+
26+
extension type ET1(V1 _) implements V1 {
27+
void set n(String v) {}
28+
}
29+
30+
extension type ET2(V2 _) implements V2 {
31+
String n() => "ET2";
32+
}
33+
34+
extension type ET3(V1 _) implements V1 {
35+
void set n(int v) {}
36+
}
37+
38+
extension type ET4(V2 _) implements V2 {
39+
int n() => 42;
40+
}
41+
42+
main() {
43+
ET1(V1(0)).n();
44+
// ^
45+
// [analyzer] unspecified
46+
// [cfe] unspecified
47+
48+
ET2(V2(0)).n = "42";
49+
// ^
50+
// [analyzer] unspecified
51+
// [cfe] unspecified
52+
53+
ET3(V1(0)).n();
54+
// ^
55+
// [analyzer] unspecified
56+
// [cfe] unspecified
57+
58+
ET4(V2(0)).n = "42";
59+
// ^
60+
// [analyzer] unspecified
61+
// [cfe] unspecified
62+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
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 We say that an extension type declaration DV has an extension
6+
/// type member named n in the cases where:
7+
/// - DV declares a member named n.
8+
/// - DV has no such declaration, but DV has a direct extension type
9+
/// superinterface V that has an extension type member named n due to a member
10+
/// declaration DM2, and DV does not declare a member that precludes DM2.
11+
///
12+
/// @description Checks that a getter doesn't preclude setter and vice versa,
13+
/// and hence the `ET*` types have a getter/setter signature conflict.
14+
/// @author [email protected]
15+
16+
// SharedOptions=--enable-experiment=inline-class
17+
18+
extension type V1(int _) {
19+
String get n => "V1";
20+
}
21+
22+
extension type V2(int _) {
23+
void set n(String n) {}
24+
}
25+
26+
extension type V0(int _) implements V1, V2 {}
27+
28+
extension type ET1(V1 _) implements V1 {
29+
void set n(int v) {}
30+
// ^
31+
// [analyzer] unspecified
32+
// [cfe] unspecified
33+
}
34+
35+
extension type ET2(V2 _) implements V2 {
36+
int get n => 2;
37+
// ^
38+
// [analyzer] unspecified
39+
// [cfe] unspecified
40+
}
41+
42+
extension type ET3(V0 _) implements V1, V2 {
43+
int get n => 3;
44+
// ^
45+
// [analyzer] unspecified
46+
// [cfe] unspecified
47+
}
48+
49+
extension type ET4(V0 _) implements V1, V2 {
50+
void set n(int v) {}
51+
// ^
52+
// [analyzer] unspecified
53+
// [cfe] unspecified
54+
}
55+
56+
main() {
57+
print(ET1);
58+
print(ET2);
59+
print(ET3);
60+
print(ET4);
61+
}

LanguageFeatures/Extension-types/static_analysis_member_invocation_A06_t02.dart renamed to LanguageFeatures/Extension-types/static_analysis_member_invocation_A08_t01.dart

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,16 @@
44

55
/// @assertion We say that an extension type declaration DV has a non-extension
66
/// type member named n in the case where DV does not declare a member named n,
7-
/// but DV has a direct extension type superinterface V that has a non-extension
8-
/// type member named n, or DV has a direct non-extension type superinterface T
9-
/// whose interface contains a member signature named n.
7+
/// and one of the following criteria is satisfied:
8+
/// - DV has a direct extension type superinterface V that has a non-extension
9+
/// type member with signature m and name n, and DV does not declare a member
10+
/// that precludes m.
11+
/// - DV has a direct non-extension type superinterface whose interface contains
12+
/// a member signature m named n, and DV does not declare a member that
13+
/// precludes m.
1014
///
1115
/// @description Checks that if an extension type `ET` has a superinterface with
12-
/// a member `m` then this member is also presents in `ET`
16+
/// a member `m` then this member is also present in `ET`
1317
/// @author [email protected]
1418
1519
// SharedOptions=--enable-experiment=inline-class

0 commit comments

Comments
 (0)