Skip to content

Commit

Permalink
dart-lang#2641. Check that it is still an error to declare more than …
Browse files Browse the repository at this point in the history
…one class member named `_`
  • Loading branch information
sgrekhov committed May 16, 2024
1 parent e9bb3ed commit bee8c28
Show file tree
Hide file tree
Showing 12 changed files with 950 additions and 0 deletions.
63 changes: 63 additions & 0 deletions LanguageFeatures/Wildcards/unchanged_A05_t02.dart
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;
}
66 changes: 66 additions & 0 deletions LanguageFeatures/Wildcards/unchanged_A05_t03.dart
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;
}
53 changes: 53 additions & 0 deletions LanguageFeatures/Wildcards/unchanged_A05_t04.dart
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;
}
60 changes: 60 additions & 0 deletions LanguageFeatures/Wildcards/unchanged_A05_t05.dart
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;
}
92 changes: 92 additions & 0 deletions LanguageFeatures/Wildcards/unchanged_A05_t06.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
// 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 it is a compile-time error to declare more than one
/// member named `_`. Test a static variable vs other class members conflict.
/// @author sgrekhov22@gmail.com
// SharedOptions=--enable-experiment=wildcard-variables

class C1 {
static int _ = 1;
static int _ = 1;
// ^
// [analyzer] unspecified
// [cfe] unspecified
}

class C2 {
static int _ = 1;
static int _() => 2;
// ^
// [analyzer] unspecified
// [cfe] unspecified
}

class C3 {
static int _ = 1;
static int get _ => 3;
// ^
// [analyzer] unspecified
// [cfe] unspecified
}

class C4 {
static int _ = 1;
static void set _(int v) {}
// ^
// [analyzer] unspecified
// [cfe] unspecified
}

class C5 {
static int _ = 1;
// ^
// [analyzer] unspecified
int _ = 5;
// ^
// [cfe] unspecified
}

class C6 {
static int _ = 1;
// ^
// [analyzer] unspecified
int _() => 6;
// ^
// [cfe] unspecified
}

class C7 {
static int _ = 1;
// ^
// [analyzer] unspecified
int get _ => 7;
// ^
// [cfe] unspecified
}

class C8 {
static int _ = 1;
// ^
// [analyzer] unspecified
void set _(int v) {}
// ^
// [cfe] unspecified
}

main() {
print(C1);
print(C2);
print(C3);
print(C4);
print(C5);
print(C6);
print(C7);
print(C8);
}

0 comments on commit bee8c28

Please sign in to comment.