-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#2641. Check that it is still an error to declare more than one class…
… member named `_` (#2669) Check that it is still an error to declare more than one class member named `_`
- Loading branch information
Showing
12 changed files
with
1,612 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file | ||
// for details. All rights reserved. Use of this source code is governed by a | ||
// BSD-style license that can be found in the LICENSE file. | ||
|
||
/// @assertion Other declarations: top-level variables, top-level function | ||
/// names, type names, member names, etc. are unchanged. They can be named `_` | ||
/// as they are today. | ||
/// | ||
/// @description Checks that a member named `_` is still accessible and its | ||
/// value can be used. Test mixin members | ||
/// @author sgrekhov22@gmail.com | ||
// SharedOptions=--enable-experiment=wildcard-variables | ||
|
||
import '../../Utils/expect.dart'; | ||
|
||
mixin M1 { | ||
static int _ = 1; | ||
} | ||
|
||
mixin M2 { | ||
static int _() => 2; | ||
} | ||
|
||
mixin M3 { | ||
static int get _ => 3; | ||
} | ||
|
||
mixin M4 { | ||
static void set _(int v) {} | ||
} | ||
|
||
mixin M5 { | ||
int _ = 5; | ||
} | ||
|
||
mixin M6 { | ||
int _() => 6; | ||
} | ||
|
||
mixin M7 { | ||
int get _ => 7; | ||
} | ||
|
||
mixin M8 { | ||
void set _(int v) {} | ||
} | ||
|
||
class MA5 = Object with M5; | ||
class MA6 = Object with M6; | ||
class MA7 = Object with M7; | ||
class MA8 = Object with M8; | ||
|
||
main() { | ||
Expect.equals(1, M1._); | ||
Expect.equals(2, M2._()); | ||
Expect.equals(3, M3._); | ||
M4._ = 42; | ||
Expect.equals(5, MA5()._); | ||
Expect.equals(6, MA6()._()); | ||
Expect.equals(7, MA7()._); | ||
MA8()._ = 42; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file | ||
// for details. All rights reserved. Use of this source code is governed by a | ||
// BSD-style license that can be found in the LICENSE file. | ||
|
||
/// @assertion Other declarations: top-level variables, top-level function | ||
/// names, type names, member names, etc. are unchanged. They can be named `_` | ||
/// as they are today. | ||
/// | ||
/// @description Checks that a member named `_` is still accessible and its | ||
/// value can be used. Test enum members | ||
/// @author sgrekhov22@gmail.com | ||
// SharedOptions=--enable-experiment=wildcard-variables | ||
|
||
import '../../Utils/expect.dart'; | ||
|
||
enum E1 { | ||
e1; | ||
static int _ = 1; | ||
} | ||
|
||
enum E2 { | ||
e1; | ||
static int _() => 2; | ||
} | ||
|
||
enum E3 { | ||
e1; | ||
static int get _ => 3; | ||
} | ||
|
||
enum E4 { | ||
e1; | ||
static void set _(int v) {} | ||
} | ||
|
||
enum E5 { | ||
e1; | ||
final int _ = 5; | ||
} | ||
|
||
enum E6 { | ||
e1; | ||
int _() => 6; | ||
} | ||
|
||
enum E7 { | ||
e1; | ||
int get _ => 7; | ||
} | ||
|
||
enum E8 { | ||
e1; | ||
void set _(int v) {} | ||
} | ||
|
||
main() { | ||
Expect.equals(1, E1._); | ||
Expect.equals(2, E2._()); | ||
Expect.equals(3, E3._); | ||
E4._ = 42; | ||
Expect.equals(5, E5.e1._); | ||
Expect.equals(6, E6.e1._()); | ||
Expect.equals(7, E7.e1._); | ||
E8.e1._ = 42; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file | ||
// for details. All rights reserved. Use of this source code is governed by a | ||
// BSD-style license that can be found in the LICENSE file. | ||
|
||
/// @assertion Other declarations: top-level variables, top-level function | ||
/// names, type names, member names, etc. are unchanged. They can be named `_` | ||
/// as they are today. | ||
/// | ||
/// @description Checks that a member named `_` is still accessible and its | ||
/// value can be used. Test extension type members | ||
/// @author sgrekhov22@gmail.com | ||
// SharedOptions=--enable-experiment=wildcard-variables | ||
|
||
import '../../Utils/expect.dart'; | ||
|
||
extension type ET1(int id) { | ||
static int _ = 1; | ||
} | ||
|
||
extension type ET2(int id) { | ||
static int _() => 2; | ||
} | ||
|
||
extension type ET3(int id) { | ||
static int get _ => 3; | ||
} | ||
|
||
extension type ET4(int id) { | ||
static void set _(int v) {} | ||
} | ||
|
||
extension type ET5(int id) { | ||
int _() => 5; | ||
} | ||
|
||
extension type ET6(int id) { | ||
int get _ => 6; | ||
} | ||
|
||
extension type ET7(int id) { | ||
void set _(int v) {} | ||
} | ||
|
||
main() { | ||
Expect.equals(1, ET1._); | ||
Expect.equals(2, ET2._()); | ||
Expect.equals(3, ET3._); | ||
ET4._ = 42; | ||
Expect.equals(5, ET5(1)._()); | ||
Expect.equals(6, ET6(1)._); | ||
ET7(1)._ = 42; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file | ||
// for details. All rights reserved. Use of this source code is governed by a | ||
// BSD-style license that can be found in the LICENSE file. | ||
|
||
/// @assertion Other declarations: top-level variables, top-level function | ||
/// names, type names, member names, etc. are unchanged. They can be named `_` | ||
/// as they are today. | ||
/// | ||
/// @description Checks that a member named `_` is still accessible and its | ||
/// value can be used. Test extension members | ||
/// @author sgrekhov22@gmail.com | ||
// SharedOptions=--enable-experiment=wildcard-variables | ||
|
||
import '../../Utils/expect.dart'; | ||
|
||
class A1 {} | ||
extension Ext1 on A1 { | ||
static int _ = 1; | ||
} | ||
|
||
class A2 {} | ||
extension Ext2 on A2 { | ||
static int _() => 2; | ||
} | ||
|
||
class A3 {} | ||
extension Ext3 on A3 { | ||
static int get _ => 3; | ||
} | ||
|
||
class A4 {} | ||
extension Ext4 on A4 { | ||
static void set _(int v) {} | ||
} | ||
|
||
class A5 {} | ||
extension Ext5 on A5 { | ||
int _() => 5; | ||
} | ||
|
||
class A6 {} | ||
extension Ext6 on A6 { | ||
int get _ => 6; | ||
} | ||
|
||
class A7 {} | ||
extension Ext7 on A7 { | ||
void set _(int v) {} | ||
} | ||
|
||
main() { | ||
Expect.equals(1, Ext1._); | ||
Expect.equals(2, Ext2._()); | ||
Expect.equals(3, Ext3._); | ||
Ext4._ = 42; | ||
Expect.equals(5, A5()._()); | ||
Expect.equals(6, A6()._); | ||
A7()._ = 42; | ||
} |
Oops, something went wrong.