Skip to content

Commit b73fbfa

Browse files
committed
#3330. Add test for the lexical lookup
1 parent 467016a commit b73fbfa

13 files changed

+431
-17
lines changed
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
// Copyright (c) 2025, 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 In addition to the member invocations specified above, it is also
6+
/// possible to invoke a static member of the enclosing declaration based on
7+
/// lexical lookup. This case is applicable when an expression in an extension
8+
/// declaration resolves to an invocation of a static member of the enclosing
9+
/// extension.
10+
///
11+
/// @description Checks that a static member of an extension can be invoked if
12+
/// an expression in an extension declaration resolves to an invocation of a
13+
/// static member of the enclosing extension. Test a static variable invocation.
14+
/// @author [email protected]
15+
16+
// SharedOptions=--enable-experiment=static-extensions
17+
18+
import '../../Utils/expect.dart';
19+
20+
class C {
21+
static String foo = "C";
22+
23+
void test() {
24+
Expect.equals("C", foo);
25+
}
26+
}
27+
28+
mixin M {
29+
static String foo = "M";
30+
31+
void test() {
32+
Expect.equals("M", foo);
33+
}
34+
}
35+
36+
extension type ET(int _) {
37+
static String foo = "ET";
38+
39+
void test() {
40+
Expect.equals("ET", foo);
41+
}
42+
}
43+
44+
enum E {
45+
e0;
46+
static String foo = "E";
47+
48+
void test() {
49+
Expect.equals("E", foo);
50+
}
51+
}
52+
53+
extension ExtC on C {
54+
static String foo = "ExtC";
55+
56+
void testExtension() {
57+
Expect.equals("ExtC", foo);
58+
}
59+
}
60+
61+
extension ExtM on M {
62+
static String foo = "ExtM";
63+
64+
void testExtension() {
65+
Expect.equals("ExtM", foo);
66+
}
67+
}
68+
69+
extension ExtET on ET {
70+
static String foo = "ExtET";
71+
72+
void testExtension() {
73+
Expect.equals("ExtET", foo);
74+
}
75+
}
76+
77+
extension ExtE on E {
78+
static String foo = "ExtET";
79+
80+
void testExtension() {
81+
Expect.equals("ExtET", foo);
82+
}
83+
}
84+
85+
class MA = Object with M;
86+
87+
main() {
88+
C().test();
89+
MA().test();
90+
ET(0).test();
91+
E.e0.test();
92+
93+
C().testExtension();
94+
MA().testExtension();
95+
ET(0).testExtension();
96+
E.e0.testExtension();
97+
}
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
// Copyright (c) 2025, 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 In addition to the member invocations specified above, it is also
6+
/// possible to invoke a static member of the enclosing declaration based on
7+
/// lexical lookup. This case is applicable when an expression in an extension
8+
/// declaration resolves to an invocation of a static member of the enclosing
9+
/// extension.
10+
///
11+
/// @description Checks that a static member of an extension can be invoked if
12+
/// an expression in an extension declaration resolves to an invocation of a
13+
/// static member of the enclosing extension. Test a static getter invocation.
14+
/// @author [email protected]
15+
16+
// SharedOptions=--enable-experiment=static-extensions
17+
18+
import '../../Utils/expect.dart';
19+
20+
class C {
21+
static String get foo => "C";
22+
23+
void test() {
24+
Expect.equals("C", foo);
25+
}
26+
}
27+
28+
mixin M {
29+
static String get foo => "M";
30+
31+
void test() {
32+
Expect.equals("M", foo);
33+
}
34+
}
35+
36+
extension type ET(int _) {
37+
static String get foo => "ET";
38+
39+
void test() {
40+
Expect.equals("ET", foo);
41+
}
42+
}
43+
44+
enum E {
45+
e0;
46+
static String get foo => "E";
47+
48+
void test() {
49+
Expect.equals("E", foo);
50+
}
51+
}
52+
53+
extension ExtC on C {
54+
static String get foo => "ExtC";
55+
56+
void testExtension() {
57+
Expect.equals("ExtC", foo);
58+
}
59+
}
60+
61+
extension ExtM on M {
62+
static String get foo => "ExtM";
63+
64+
void testExtension() {
65+
Expect.equals("ExtM", foo);
66+
}
67+
}
68+
69+
extension ExtET on ET {
70+
static String get foo => "ExtET";
71+
72+
void testExtension() {
73+
Expect.equals("ExtET", foo);
74+
}
75+
}
76+
77+
extension ExtE on E {
78+
static String foo = "ExtET";
79+
80+
void testExtension() {
81+
Expect.equals("ExtET", foo);
82+
}
83+
}
84+
85+
class MA = Object with M;
86+
87+
main() {
88+
C().test();
89+
MA().test();
90+
ET(0).test();
91+
E.e0.test();
92+
93+
C().testExtension();
94+
MA().testExtension();
95+
ET(0).testExtension();
96+
E.e0.testExtension();
97+
}
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
// Copyright (c) 2025, 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 In addition to the member invocations specified above, it is also
6+
/// possible to invoke a static member of the enclosing declaration based on
7+
/// lexical lookup. This case is applicable when an expression in an extension
8+
/// declaration resolves to an invocation of a static member of the enclosing
9+
/// extension.
10+
///
11+
/// @description Checks that a static member of an extension can be invoked if
12+
/// an expression in an extension declaration resolves to an invocation of a
13+
/// static member of the enclosing extension. Test a static method invocation.
14+
/// @author [email protected]
15+
16+
// SharedOptions=--enable-experiment=static-extensions
17+
18+
import '../../Utils/expect.dart';
19+
20+
class C {
21+
static String foo() => "C";
22+
23+
void test() {
24+
Expect.equals("C", foo());
25+
}
26+
}
27+
28+
mixin M {
29+
static String foo() => "M";
30+
31+
void test() {
32+
Expect.equals("M", foo());
33+
}
34+
}
35+
36+
extension type ET(int _) {
37+
static String foo() => "ET";
38+
39+
void test() {
40+
Expect.equals("ET", foo());
41+
}
42+
}
43+
44+
enum E {
45+
e0;
46+
static String foo() => "E";
47+
48+
void test() {
49+
Expect.equals("E", foo());
50+
}
51+
}
52+
53+
extension ExtC on C {
54+
static String foo() => "ExtC";
55+
56+
void testExtension() {
57+
Expect.equals("ExtC", foo());
58+
}
59+
}
60+
61+
extension ExtM on M {
62+
static String foo() => "ExtM";
63+
64+
void testExtension() {
65+
Expect.equals("ExtM", foo());
66+
}
67+
}
68+
69+
extension ExtET on ET {
70+
static String foo() => "ExtET";
71+
72+
void testExtension() {
73+
Expect.equals("ExtET", foo());
74+
}
75+
}
76+
77+
extension ExtE on E {
78+
static String foo() => "ExtE";
79+
80+
void testExtension() {
81+
Expect.equals("ExtE", foo());
82+
}
83+
}
84+
85+
class MA = Object with M;
86+
87+
main() {
88+
C().test();
89+
MA().test();
90+
ET(0).test();
91+
E.e0.test();
92+
93+
C().testExtension();
94+
MA().testExtension();
95+
ET(0).testExtension();
96+
E.e0.testExtension();
97+
}

0 commit comments

Comments
 (0)