Skip to content

Commit 213cde4

Browse files
authored
Fixes #2909. Fix extension applicability tests according to the updated spec (#2911)
Fixes #2909. Fix extension applicability tests according to the updated spec
1 parent 4134cea commit 213cde4

File tree

2 files changed

+59
-55
lines changed

2 files changed

+59
-55
lines changed

LanguageFeatures/Extension-methods/applicability_A01_t01.dart

Lines changed: 24 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -6,46 +6,44 @@
66
/// invocation with corresponding member basename m and target expression `e`,
77
/// where `e` has static type `S`, if
88
/// ...
9-
/// - The type S does not have a member with the basename m. For this, the type
10-
/// `dynamic` is considered as having all member names, and an expression of
11-
/// type `Never` or `void` cannot occur as the target of a member invocation,
12-
/// so none of these can ever have applicable extensions. Function types and
13-
/// the type `Function` are considered as having a `call` member. This ensure
14-
/// that if there is an applicable extension, the existing invocation would
15-
/// otherwise be a compile-time error. Members of `Object` exists on all
16-
/// types, so they can never be the target of implicit member invocations
17-
/// (they can also not be declared as extension members).
9+
/// - The type S does not have an instance member with the basename m. For this,
10+
/// the type `dynamic` is considered as having all member names, and an
11+
/// expression of type `Never` or `void` cannot occur as the target of a
12+
/// member invocation, so none of these can ever have applicable extensions.
13+
/// Function types and the type `Function` are considered as having a `call`
14+
/// member. This ensure that if there is an applicable extension, the existing
15+
/// invocation would otherwise be a compile-time error. Members of `Object`
16+
/// exists on all types, so they can never be the target of implicit member
17+
/// invocations (they can also not be declared as extension members).
1818
///
19-
/// @description Check that an extension member with the basename `m` is not
20-
/// applicable if on type has a static member with the same basename.
19+
/// @description Check that an extension member with the basename `m` is
20+
/// applicable even if the on type has a static member with the same basename.
2121
/// @author [email protected]
2222
/// @issue 56818
2323
24+
import '../../Utils/expect.dart';
25+
26+
String _log = "";
27+
2428
class C {
2529
static String get m1 => "m1";
2630
static String m2() => "m2";
27-
static void set m3(String _) {}
31+
static void set m3(String _) {
32+
_log = "m3";
33+
}
2834
}
2935

3036
extension Ext on C {
3137
String get m1 => "Ext.m1";
3238
String m2() => "Ext.m2";
33-
void set m3(String _) {}
39+
void set m3(String _) {
40+
_log = "Ext.m3";
41+
}
3442
}
3543

3644
main() {
37-
print(C().m1);
38-
// ^^
39-
// [analyzer] unspecified
40-
// [cfe] unspecified
41-
42-
print(C().m2());
43-
// ^^
44-
// [analyzer] unspecified
45-
// [cfe] unspecified
46-
45+
Expect.equals("Ext.m1", C().m1);
46+
Expect.equals("Ext.m2", C().m2());
4747
C().m3 = "";
48-
// ^^
49-
// [analyzer] unspecified
50-
// [cfe] unspecified
48+
Expect.equals("Ext.m3", _log);
5149
}

LanguageFeatures/Extension-methods/applicability_A01_t02.dart

Lines changed: 35 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -6,45 +6,51 @@
66
/// invocation with corresponding member basename m and target expression `e`,
77
/// where `e` has static type `S`, if
88
/// ...
9-
/// - The type S does not have a member with the basename m. For this, the type
10-
/// `dynamic` is considered as having all member names, and an expression of
11-
/// type `Never` or `void` cannot occur as the target of a member invocation,
12-
/// so none of these can ever have applicable extensions. Function types and
13-
/// the type `Function` are considered as having a `call` member. This ensure
14-
/// that if there is an applicable extension, the existing invocation would
15-
/// otherwise be a compile-time error. Members of `Object` exists on all
16-
/// types, so they can never be the target of implicit member invocations
17-
/// (they can also not be declared as extension members).
9+
/// - The type S does not have an instance member with the basename m. For this,
10+
/// the type `dynamic` is considered as having all member names, and an
11+
/// expression of type `Never` or `void` cannot occur as the target of a
12+
/// member invocation, so none of these can ever have applicable extensions.
13+
/// Function types and the type `Function` are considered as having a `call`
14+
/// member. This ensure that if there is an applicable extension, the existing
15+
/// invocation would otherwise be a compile-time error. Members of `Object`
16+
/// exists on all types, so they can never be the target of implicit member
17+
/// invocations (they can also not be declared as extension members).
1818
///
19-
/// @description Check that an extension member with the basename `m` is not
20-
/// applicable if on type has a static member with the same basename.
19+
/// @description Check that an extension member with the basename `m` is
20+
/// applicable even if the on type has a static member with the same basename.
2121
/// @author [email protected]
2222
23+
import '../../Utils/expect.dart';
24+
25+
String _log = "";
26+
2327
class C {
2428
static String get m1 => "m1";
2529
static String m2() => "m2";
26-
static void set m3(String _) {}
30+
static void set m3(String _) {
31+
_log = "m3";
32+
}
33+
static void set m4(String _) {
34+
_log = "m4";
35+
}
2736
}
2837

2938
extension Ext on C {
30-
void set m1(String _) {}
31-
void set m2(String _) {}
32-
String m3() => "Ext.m2";
39+
void set m1(String _) {
40+
_log = "Ext.m1";
41+
}
42+
void set m2(String _) {
43+
_log = "Ext.m2";
44+
}
45+
String m3() => "Ext.m3";
46+
String get m4 => "Ext.m4";
3347
}
3448

3549
main() {
36-
print(C().m1);
37-
// ^^
38-
// [analyzer] unspecified
39-
// [cfe] unspecified
40-
41-
print(C().m2());
42-
// ^^
43-
// [analyzer] unspecified
44-
// [cfe] unspecified
45-
46-
C().m3 = "";
47-
// ^^
48-
// [analyzer] unspecified
49-
// [cfe] unspecified
50+
C().m1 = "";
51+
Expect.equals("Ext.m1", _log);
52+
C().m2 = "";
53+
Expect.equals("Ext.m2", _log);
54+
Expect.equals("Ext.m3", C().m3());
55+
Expect.equals("Ext.m4", C().m4);
5056
}

0 commit comments

Comments
 (0)