Skip to content

Commit 481797d

Browse files
author
Sergey G. Grekhov
committed
Fixes #497. Null-aware operators are allowed for explicit extension invocation
1 parent d9f16c8 commit 481797d

5 files changed

+55
-33
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
3+
* for details. All rights reserved. Use of this source code is governed by a
4+
* BSD-style license that can be found in the LICENSE file.
5+
*/
6+
/**
7+
* @assertion It is a compile-time error if the corresponding class constructor
8+
* invocation would be a compile-time error.
9+
*
10+
* @description Check that it is a compile-time error if the corresponding class
11+
* constructor invocation would be a compile-time error.
12+
13+
*/
14+
// SharedOptions=--enable-experiment=extension-methods
15+
16+
class C {
17+
String name = "My name is C";
18+
}
19+
20+
extension Ext on C {
21+
String checkme() => this.name;
22+
}
23+
24+
main() {
25+
C c = new C();
26+
Ext(Ext(c)).checkme();
27+
// ^^^^^^
28+
// [analyzer] unspecified
29+
// [cfe] unspecified
30+
}

LanguageFeatures/Extension-methods/explicit_extension_member_invocation_A20_t01.dart

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,16 @@
99
* invocation. That is, the only valid use of an extension application is to
1010
* invoke members on it. This is similar to how prefix names can also only be
1111
* used as member invocation targets. The main difference is that extensions can
12-
* also declare operators. This also includes null-aware member access like
13-
* E(o)?.id or E(o)?.[v] because those need to evaluate the target to a value
14-
* and extension applications cannot evaluate to a value.
12+
* also declare operators.
1513
*
16-
* @description Check that it is a compile-time error if null-aware member
17-
* access like E(o)?.id is used for explicit extension invocation
14+
* @description Check that it is no compile-time error if null-aware member
15+
* access like E(o)?.id() is used for explicit extension invocation
1816
* @issue 39325
17+
* https://github.com/dart-lang/language/issues/677
1918
2019
*/
2120
// SharedOptions=--enable-experiment=extension-methods
21+
import "../../Utils/expect.dart";
2222

2323
class C {
2424
}
@@ -29,8 +29,5 @@ extension Ext on C {
2929

3030
main() {
3131
C c = C();
32-
Ext(c)?.id();
33-
//^^^^^^^^^^^^
34-
// [analyzer] unspecified
35-
// [cfe] unspecified}
32+
Expect.equals(42, Ext(c)?.id());
3633
}

LanguageFeatures/Extension-methods/explicit_extension_member_invocation_A20_t02.dart

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,16 @@
99
* invocation. That is, the only valid use of an extension application is to
1010
* invoke members on it. This is similar to how prefix names can also only be
1111
* used as member invocation targets. The main difference is that extensions can
12-
* also declare operators. This also includes null-aware member access like
13-
* E(o)?.id or E(o)?.[v] because those need to evaluate the target to a value
14-
* and extension applications cannot evaluate to a value.
12+
* also declare operators.
1513
*
16-
* @description Check that it is a compile-time error if null-aware member
14+
* @description Check that it is no compile-time error if null-aware member
1715
* access like E(o)?.id is used for explicit extension invocation
1816
* @issue 39325
17+
* https://github.com/dart-lang/language/issues/677
1918
2019
*/
2120
// SharedOptions=--enable-experiment=extension-methods
21+
import "../../Utils/expect.dart";
2222

2323
class C {
2424
}
@@ -29,8 +29,5 @@ extension Ext on C {
2929

3030
main() {
3131
C c = C();
32-
Ext(c)?.id;
33-
//^^^^^^^^^^^^
34-
// [analyzer] unspecified
35-
// [cfe] unspecified}
32+
Expect.equals(42, Ext(c)?.id);
3633
}

LanguageFeatures/Extension-methods/explicit_extension_member_invocation_A20_t03.dart

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,28 +9,29 @@
99
* invocation. That is, the only valid use of an extension application is to
1010
* invoke members on it. This is similar to how prefix names can also only be
1111
* used as member invocation targets. The main difference is that extensions can
12-
* also declare operators. This also includes null-aware member access like
13-
* E(o)?.id or E(o)?.[v] because those need to evaluate the target to a value
14-
* and extension applications cannot evaluate to a value.
12+
* also declare operators.
1513
*
16-
* @description Check that it is a compile-time error if null-aware member
14+
* @description Check that it is no compile-time error if null-aware member
1715
* access like E(o)?.id is used for explicit extension invocation
1816
* @issue 39325
17+
* https://github.com/dart-lang/language/issues/677
1918
2019
*/
2120
// SharedOptions=--enable-experiment=extension-methods
21+
import "../../Utils/expect.dart";
2222

2323
class C {
24+
int v = 0;
2425
}
2526

2627
extension Ext on C {
27-
void set id(int val) {}
28+
void set id(int val) {
29+
this.v = val;
30+
}
2831
}
2932

3033
main() {
3134
C c = C();
3235
Ext(c)?.id = 42;
33-
//^^^^^^^^^^
34-
// [analyzer] unspecified
35-
// [cfe] unspecified}
36+
Expect.equals(42, c.v);
3637
}

LanguageFeatures/Extension-methods/explicit_extension_member_invocation_A20_t04.dart

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,16 @@
99
* invocation. That is, the only valid use of an extension application is to
1010
* invoke members on it. This is similar to how prefix names can also only be
1111
* used as member invocation targets. The main difference is that extensions can
12-
* also declare operators. This also includes null-aware member access like
13-
* E(o)?.id or E(o)?.[v] because those need to evaluate the target to a value
14-
* and extension applications cannot evaluate to a value.
12+
* also declare operators.
1513
*
16-
* @description Check that it is a compile-time error if null-aware member
14+
* @description Check that it is no compile-time error if null-aware member
1715
* access like E(o)?.[v] is used for explicit extension invocation
1816
* @issue 39326
17+
* https://github.com/dart-lang/language/issues/677
1918
2019
*/
2120
// SharedOptions=--enable-experiment=extension-methods
21+
import "../../Utils/expect.dart";
2222

2323
class C {
2424
}
@@ -29,8 +29,5 @@ extension Ext on C {
2929

3030
main() {
3131
C c = C();
32-
Ext(c)?.[42];
33-
//^^^^^^^^^^^^
34-
// [analyzer] unspecified
35-
// [cfe] unspecified}
32+
Expect.equals(42, Ext(c)?.[42]);
3633
}

0 commit comments

Comments
 (0)