Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// Copyright (c) 2025, 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 Given a named initializing formal or field parameter (for a
/// primary constructor) with private name `p` in constructor `C`:
/// - If `p` has no corresponding public name `n`, then compile-time error.
///
/// @description Check that it is a compile-time error if a named initializing
/// formal parameter with private name has no corresponding public name.
/// @author [email protected]

// SharedOptions=--enable-experiment=private-named-parameters

class C {
String __p;
C({this._p = ""});
// ^^
// [analyzer] unspecified
// [cfe] unspecified

C._({required this._p});
// ^^
// [analyzer] unspecified
// [cfe] unspecified
}

extension type ET._(String __p) {
ET({this._p = ""});
// ^^
// [analyzer] unspecified
// [cfe] unspecified

ET.named({required this._p});
// ^^
// [analyzer] unspecified
// [cfe] unspecified
}

enum E {
e0;

final String __p;
const E({this._p = ""});
// ^^
// [analyzer] unspecified
// [cfe] unspecified

const E.named({required this._p});
// ^^
// [analyzer] unspecified
// [cfe] unspecified
}

main() {
print(C);
print(ET);
print(E);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// Copyright (c) 2025, 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 Given a named initializing formal or field parameter (for a
/// primary constructor) with private name `p` in constructor `C`:
/// - If `p` has no corresponding public name `n`, then compile-time error.
///
/// @description Check that it is a compile-time error if a named initializing
/// formal parameter with private name has no corresponding public name.
/// @author [email protected]
// SharedOptions=--enable-experiment=private-named-parameters

class C {
String _1;
C({this._1 = ""});
// ^^
// [analyzer] unspecified
// [cfe] unspecified

C._({required this._1});
// ^^
// [analyzer] unspecified
// [cfe] unspecified
}

extension type ET._(String _1) {
ET({this._1 = ""});
// ^^
// [analyzer] unspecified
// [cfe] unspecified

ET.named({required this._1});
// ^^
// [analyzer] unspecified
// [cfe] unspecified
}

enum E {
e0;

final String _1;
const E({this._1 = ""});
// ^^
// [analyzer] unspecified
// [cfe] unspecified

const E.named({required this._1});
// ^^
// [analyzer] unspecified
// [cfe] unspecified
}

main() {
print(C);
print(ET);
print(E);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
// Copyright (c) 2025, 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 Given a named initializing formal or field parameter (for a
/// primary constructor) with private name `p` in constructor `C`:
/// - If `p` has no corresponding public name `n`, then compile-time error.
///
/// @description Check that it is a compile-time error if a named formal
/// parameter of a declaring constructor with private name has no corresponding
/// public name.
/// @author [email protected]

// SharedOptions=--enable-experiment=private-named-parameters,declaring-constructors

class C1({var String __p}) {
// ^^^
// [analyzer] unspecified
// [cfe] unspecified
}

class C2({required final String _1}) {
// ^^
// [analyzer] unspecified
// [cfe] unspecified
}

class C3 {
this({required final String __p});
// ^^^
// [analyzer] unspecified
// [cfe] unspecified
}

class C4 {
this({var String _1 = ""});
// ^^
// [analyzer] unspecified
// [cfe] unspecified
}

extension type ET1 {
this({final String __p = ""});
}

extension type ET2 {
this({final String _1 = ""});
}

enum E1({required final String __p}) {
// ^^^
// [analyzer] unspecified
// [cfe] unspecified
e0(_p: "");
// ^^
// [analyzer] unspecified
// [cfe] unspecified
}

enum E2 {
e0;

const this({final String _1 = ""});
// ^^
// [analyzer] unspecified
// [cfe] unspecified
}

main() {
print(C1);
print(C2);
print(C3);
print(C4);
print(ET1);
print(ET2);
print(E1);
print(E2);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// Copyright (c) 2025, 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 Given a named initializing formal or field parameter (for a
/// primary constructor) with private name `p` in constructor `C`:
/// - If `p` has no corresponding public name `n`, then compile-time error. You
/// can't use a private name for a named parameter unless there is a valid
/// public name that could be used at the call site.
/// - If any other parameter in `C` has declared name `p` or `n`, then
/// compile-time error.
///
/// @description Check that it is a compile-time error if any other parameter in
/// `C` has declared name `p` or `n`.
/// @author [email protected]

// SharedOptions=--enable-experiment=private-named-parameters

class C {
String _p;
String p;
C({this._p = "", int? _p}) : p = "";
// ^^
// [analyzer] unspecified
// [cfe] unspecified

C._({required this._p, this.p});
// ^
// [analyzer] unspecified
// [cfe] unspecified
}

extension type ET._(String _p) {
ET({this._p = "", int _p = 0});
// ^^
// [analyzer] unspecified
// [cfe] unspecified

ET.named({required this._p, int? p});
// ^
// [analyzer] unspecified
// [cfe] unspecified
}

enum E {
e0;

final String _p;
final int? p;
const E({this._p = "", int? _p});
// ^^
// [analyzer] unspecified
// [cfe] unspecified

const E.named({required this._p, this.p});
// ^
// [analyzer] unspecified
// [cfe] unspecified
}

main() {
print(C);
print(ET);
print(E);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
// Copyright (c) 2025, 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 Given a named initializing formal or field parameter (for a
/// primary constructor) with private name `p` in constructor `C`:
/// - If `p` has no corresponding public name `n`, then compile-time error. You
/// can't use a private name for a named parameter unless there is a valid
/// public name that could be used at the call site.
/// - If any other parameter in `C` has declared name `p` or `n`, then
/// compile-time error.
///
/// @description Check that it is a compile-time error if any other parameter in
/// `C` has declared name `p` or `n`.
/// @author [email protected]

// SharedOptions=--enable-experiment=private-named-parameters,declaring-constructors

class C1({var String _p = "", int? _p}) {
// ^^
// [analyzer] unspecified
// [cfe] unspecified
}

class C2 {
this({final String _p = "", int p = 0});
// ^
// [analyzer] unspecified
// [cfe] unspecified
}

extension type ET1 {
this({final String _p = "", int _p = 0});
// ^^
// [analyzer] unspecified
// [cfe] unspecified
}

extension type ET2 {
this({final String _p = "", int p = 0});
// ^
// [analyzer] unspecified
// [cfe] unspecified
}

enum E1({final String _p = "", int? _p}) {
// ^^
// [analyzer] unspecified
// [cfe] unspecified
e0;
}

enum E2 {
e0;

const this({final String _p = "", final int? p});
// ^
// [analyzer] unspecified
// [cfe] unspecified
}

main() {
print(C1);
print(C2);
print(ET1);
print(ET2);
print(E1);
print(E2);
}