Skip to content

Commit 24aa67e

Browse files
authored
Fixes #2304. Add more Object member tests (#2312)
Add more `Object` member tests
1 parent e705ec1 commit 24aa67e

8 files changed

+448
-4
lines changed

LanguageFeatures/Extension-types/static_analysis_member_invocation_A01_t01.dart

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,18 @@
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 If the name of m is a name in the interface of Object (that is,
6-
/// toString, ==, hashCode, runtimeType, or noSuchMethod), the static analysis
7-
/// of the invocation is treated as an ordinary instance member invocation on a
8-
/// receiver of type Object? and with the same args or typeArgs, if any.
5+
/// @assertion Consider an invocation of the extension type member m on the
6+
/// receiver expression e according to the extension type declaration V with the
7+
/// actual type arguments T1, ..., Ts. If the invocation includes an actual
8+
/// argument part (possibly including some actual type arguments) then call it
9+
/// args. If the invocation does not include an actual argument part, but it
10+
/// does include a list of actual type arguments, call it typeArgs. Finally,
11+
/// assume that V declares the type variables X1, ..., Xs.
12+
///
13+
/// Note that if the name of m is a name in the interface of Object (that is,
14+
/// toString, ==, hashCode, runtimeType, or noSuchMethod), the denoted member is
15+
/// necessarily a non-extension type member, which determines the static
16+
/// analysis and dynamic semantics.
917
///
1018
/// @description Checks that members of an `Object` class can be called
1119
/// @author [email protected]
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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 Consider an invocation of the extension type member m on the
6+
/// receiver expression e according to the extension type declaration V with the
7+
/// actual type arguments T1, ..., Ts. If the invocation includes an actual
8+
/// argument part (possibly including some actual type arguments) then call it
9+
/// args. If the invocation does not include an actual argument part, but it
10+
/// does include a list of actual type arguments, call it typeArgs. Finally,
11+
/// assume that V declares the type variables X1, ..., Xs.
12+
///
13+
/// Note that if the name of m is a name in the interface of Object (that is,
14+
/// toString, ==, hashCode, runtimeType, or noSuchMethod), the denoted member is
15+
/// necessarily a non-extension type member, which determines the static
16+
/// analysis and dynamic semantics.
17+
///
18+
/// @description Checks that members of an `Object` are treated as all other
19+
/// non-extension type members. Check `toString()`
20+
/// @author [email protected]
21+
/// @issue 53740
22+
23+
// SharedOptions=--enable-experiment=inline-class
24+
25+
class A {
26+
}
27+
28+
class B implements A {
29+
@override
30+
String toString([bool whatever = true]) => super.toString();
31+
}
32+
33+
extension type ET1(B b) implements A {}
34+
35+
extension type ET2(B b) implements ET1, B {}
36+
37+
void main() {
38+
var e2 = ET2(B());
39+
ET1 e1 = e2;
40+
41+
e2.toString(true); // OK, signature is `String toString([bool])`.
42+
43+
e1.toString(true); // Compile-time error, signature is `String toString()`.
44+
// ^^^^^^^^
45+
// [analyzer] unspecified
46+
// [cfe] unspecified
47+
}
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
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 Consider an invocation of the extension type member m on the
6+
/// receiver expression e according to the extension type declaration V with the
7+
/// actual type arguments T1, ..., Ts. If the invocation includes an actual
8+
/// argument part (possibly including some actual type arguments) then call it
9+
/// args. If the invocation does not include an actual argument part, but it
10+
/// does include a list of actual type arguments, call it typeArgs. Finally,
11+
/// assume that V declares the type variables X1, ..., Xs.
12+
///
13+
/// Note that if the name of m is a name in the interface of Object (that is,
14+
/// toString, ==, hashCode, runtimeType, or noSuchMethod), the denoted member is
15+
/// necessarily a non-extension type member, which determines the static
16+
/// analysis and dynamic semantics.
17+
///
18+
/// @description Checks that members of an `Object` are treated as all other
19+
/// non-extension type members. Test dynamic behavior
20+
/// @author [email protected]
21+
22+
// SharedOptions=--enable-experiment=inline-class
23+
24+
import "../../Utils/expect.dart";
25+
26+
String log = "";
27+
28+
class A {
29+
}
30+
31+
class B implements A {
32+
@override
33+
int get hashCode {
34+
log += "B.hashCode";
35+
return super.hashCode;
36+
}
37+
38+
@override
39+
Type get runtimeType {
40+
log += "B.runtimeType";
41+
return super.runtimeType;
42+
}
43+
44+
@override
45+
bool operator ==(Object? other) {
46+
log += "B.==";
47+
return other == this;
48+
}
49+
}
50+
51+
extension type ET1(B b) implements A {}
52+
53+
extension type ET2(B b) implements ET1, B {}
54+
55+
void main() {
56+
var e2 = ET2(B());
57+
ET1 e1 = e2;
58+
59+
e2.hashCode;
60+
Expect.equals("B.hashCode", log);
61+
log = "";
62+
e1.hashCode;
63+
Expect.equals("B.hashCode", log);
64+
log = "";
65+
66+
e2.runtimeType;
67+
Expect.equals("B.runtimeType", log);
68+
log = "";
69+
e1.runtimeType;
70+
Expect.equals("B.runtimeType", log);
71+
log = "";
72+
73+
e2 == Object();
74+
Expect.equals("B.==", log);
75+
log = "";
76+
e1 == Object();
77+
Expect.equals("B.==", log);
78+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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 Consider an invocation of the extension type member m on the
6+
/// receiver expression e according to the extension type declaration V with the
7+
/// actual type arguments T1, ..., Ts. If the invocation includes an actual
8+
/// argument part (possibly including some actual type arguments) then call it
9+
/// args. If the invocation does not include an actual argument part, but it
10+
/// does include a list of actual type arguments, call it typeArgs. Finally,
11+
/// assume that V declares the type variables X1, ..., Xs.
12+
///
13+
/// Note that if the name of m is a name in the interface of Object (that is,
14+
/// toString, ==, hashCode, runtimeType, or noSuchMethod), the denoted member is
15+
/// necessarily a non-extension type member, which determines the static
16+
/// analysis and dynamic semantics.
17+
///
18+
/// @description Checks that members of an `Object` are treated as all other
19+
/// non-extension type members. Check `noSuchMethod()`
20+
/// @author [email protected]
21+
/// @issue 53740
22+
23+
// SharedOptions=--enable-experiment=inline-class
24+
25+
class A {
26+
}
27+
28+
class B implements A {
29+
@override
30+
noSuchMethod(Invocation inv, [bool whatever = true]) {}
31+
}
32+
33+
extension type ET1(B b) implements A {}
34+
35+
extension type ET2(B b) implements ET1, B {}
36+
37+
void main() {
38+
var e2 = ET2(B());
39+
ET1 e1 = e2;
40+
41+
// OK, signature is `noSuchMethod(Invocation, [bool])`.
42+
e2.noSuchMethod(Invocation.method(Symbol("test"), []), true);
43+
44+
// Compile-time error, signature is `noSuchMethod(Invocation)`.
45+
e1.noSuchMethod(Invocation.method(Symbol("test"), []), true);
46+
// ^^^^^^^^
47+
// [analyzer] unspecified
48+
// [cfe] unspecified
49+
}
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 Consider an invocation of the extension type member m on the
6+
/// receiver expression e according to the extension type declaration V with the
7+
/// actual type arguments T1, ..., Ts. If the invocation includes an actual
8+
/// argument part (possibly including some actual type arguments) then call it
9+
/// args. If the invocation does not include an actual argument part, but it
10+
/// does include a list of actual type arguments, call it typeArgs. Finally,
11+
/// assume that V declares the type variables X1, ..., Xs.
12+
///
13+
/// Note that if the name of m is a name in the interface of Object (that is,
14+
/// toString, ==, hashCode, runtimeType, or noSuchMethod), the denoted member is
15+
/// necessarily a non-extension type member, which determines the static
16+
/// analysis and dynamic semantics.
17+
///
18+
/// @description Checks that members of an `Object` are treated as all other
19+
/// non-extension type members. Test static behavior
20+
/// @author [email protected]
21+
/// @issue 53740
22+
23+
// SharedOptions=--enable-experiment=inline-class
24+
25+
class A {
26+
}
27+
28+
class B implements A {
29+
@override
30+
IntET get hashCode => IntET(super.hashCode);
31+
32+
@override
33+
TypeET get runtimeType => TypeET(super.runtimeType);
34+
35+
@override
36+
BoolET operator ==(Object? other) => BoolET(other == this);
37+
}
38+
39+
extension type ET1(B b) implements A {}
40+
41+
extension type ET2(B b) implements ET1, B {}
42+
43+
extension type IntET(int i) implements int {}
44+
45+
extension type TypeET(Type t) implements Type {}
46+
47+
extension type BoolET(bool b) implements bool {}
48+
49+
void main() {
50+
var e2 = ET2(B());
51+
ET1 e1 = e2;
52+
53+
int hc1 = e1.hashCode;
54+
IntET hc2 = e2.hashCode;
55+
56+
Type t1 = e1.runtimeType;
57+
TypeET t2 = e2.runtimeType;
58+
59+
bool b1 = e1 == e1;
60+
BoolET b2 = e2 == e2;
61+
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
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 Consider an invocation of the extension type member m on the
6+
/// receiver expression e according to the extension type declaration V with the
7+
/// actual type arguments T1, ..., Ts. If the invocation includes an actual
8+
/// argument part (possibly including some actual type arguments) then call it
9+
/// args. If the invocation does not include an actual argument part, but it
10+
/// does include a list of actual type arguments, call it typeArgs. Finally,
11+
/// assume that V declares the type variables X1, ..., Xs.
12+
///
13+
/// Note that if the name of m is a name in the interface of Object (that is,
14+
/// toString, ==, hashCode, runtimeType, or noSuchMethod), the denoted member is
15+
/// necessarily a non-extension type member, which determines the static
16+
/// analysis and dynamic semantics.
17+
///
18+
/// @description Checks that members of an `Object` are treated as all other
19+
/// non-extension type members. Test static behavior
20+
/// @author [email protected]
21+
22+
// SharedOptions=--enable-experiment=inline-class
23+
24+
class A {
25+
}
26+
27+
class B implements A {
28+
@override
29+
IntET get hashCode => IntET(super.hashCode);
30+
31+
@override
32+
TypeET get runtimeType => TypeET(super.runtimeType);
33+
34+
@override
35+
BoolET operator ==(Object? other) => BoolET(other == this);
36+
}
37+
38+
extension type ET1(B b) implements A {}
39+
40+
extension type ET2(B b) implements ET1, B {}
41+
42+
extension type IntET(int i) implements int {}
43+
44+
extension type TypeET(Type t) implements Type {}
45+
46+
extension type BoolET(bool b) implements bool {}
47+
48+
void main() {
49+
var e2 = ET2(B());
50+
ET1 e1 = e2;
51+
52+
IntET hc1 = e1.hashCode;
53+
// ^^^^^^^^
54+
// [analyzer] unspecified
55+
// [cfe] unspecified
56+
57+
TypeET t1 = e1.runtimeType;
58+
// ^^^^^^^^^^^
59+
// [analyzer] unspecified
60+
// [cfe] unspecified
61+
62+
BoolET b1 = e1 == e1;
63+
// ^^
64+
// [analyzer] unspecified
65+
// [cfe] unspecified
66+
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
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 Consider an invocation of the extension type member m on the
6+
/// receiver expression e according to the extension type declaration V with the
7+
/// actual type arguments T1, ..., Ts. If the invocation includes an actual
8+
/// argument part (possibly including some actual type arguments) then call it
9+
/// args. If the invocation does not include an actual argument part, but it
10+
/// does include a list of actual type arguments, call it typeArgs. Finally,
11+
/// assume that V declares the type variables X1, ..., Xs.
12+
///
13+
/// Note that if the name of m is a name in the interface of Object (that is,
14+
/// toString, ==, hashCode, runtimeType, or noSuchMethod), the denoted member is
15+
/// necessarily a non-extension type member, which determines the static
16+
/// analysis and dynamic semantics.
17+
///
18+
/// @description Checks that members of an `Object` are treated as all other
19+
/// non-extension type members. Test dynamic behavior of `==` operator
20+
/// @author [email protected]
21+
22+
// SharedOptions=--enable-experiment=inline-class
23+
24+
import "../../Utils/expect.dart";
25+
26+
String log = "";
27+
28+
class A {
29+
}
30+
31+
class B implements A {
32+
@override
33+
bool operator ==(covariant A other) {
34+
log += "B.==";
35+
return true;
36+
}
37+
}
38+
39+
class C {}
40+
41+
extension type ET1(B b) implements A {}
42+
43+
extension type ET2(B b) implements ET1, B {}
44+
45+
void main() {
46+
var e2 = ET2(B());
47+
ET1 e1 = e2;
48+
49+
e2 == A();
50+
Expect.equals("B.==", log);
51+
log = "";
52+
e2 == B();
53+
Expect.equals("B.==", log);
54+
log = "";
55+
Expect.throws(() {e2 == Object();});
56+
Expect.throws(() {e2 == C();});
57+
58+
e1 == A();
59+
Expect.equals("B.==", log);
60+
log = "";
61+
e1 == B();
62+
Expect.equals("B.==", log);
63+
log = "";
64+
Expect.throws(() {e1 == Object();});
65+
Expect.throws(() {e1 == C();});
66+
}

0 commit comments

Comments
 (0)