Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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 has a private name that has no corresponding public name.
/// @author [email protected]

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

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

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

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

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

enum E {
e0;

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

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

main() {
print(C);
print(ET);
print(E);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
// 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 declaring named
/// formal parameter of a declaring constructor has a private name with no
/// corresponding public name.
/// @author [email protected]

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

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

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

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

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

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

extension type ET2 {
this({final String _ = ""});
// ^
// [analyzer] unspecified
// [cfe] unspecified
}

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

enum E2 {
e0;

const this({final String _ = ""});
// ^
// [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`. Test initializing formals.
/// @author [email protected]

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

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

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

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

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

enum E {
e0(1);

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

const E.named(this.p, {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,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`. Test declaring parameters.
/// @author [email protected]

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

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

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

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

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

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

enum E2 {
e0(2);

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

main() {
print(C1);
print(C2);
print(ET1);
print(ET2);
print(E1);
print(E2);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// 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 A super parameter generates an implicit argument that forwards to
/// a superclass constructor. The super constructor's argument name is always
/// public, even if the corresponding constructor parameter uses this feature
/// and has a private name. Thus, super parameters continue to always use public
/// names.
///
/// @description Check that private super parameter can be invoked using its
/// public name.
/// @author [email protected]

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

import '../../Utils/expect.dart';

class A1 {
String _p;
A1({this._p = ""});
}

class A2 {
String _p;
A2({required this._p});
}

class C1 extends A1 {
C1({super.p});
C1.named({super.p});
}

class C2 extends A2 {
C2({required super.p});
C2.named({required super.p});
}

class C3 extends A1 {
C3(String p) : super(p: p);
C3.named(String p) : super(p: p);
}

class C4 extends A2 {
C4(String p) : super(p: p);
C4.named(String p) : super(p: p);
}

main() {
Expect.equals("a", C1(p: "a")._p);
Expect.equals("b", C1.named(p: "b")._p);
Expect.equals("c", C2(p: "c")._p);
Expect.equals("d", C2.named(p: "d")._p);
Expect.equals("e", C3("e")._p);
Expect.equals("f", C3.named("f")._p);
Expect.equals("g", C4("g")._p);
Expect.equals("h", C4.named("h")._p);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// 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 A super parameter generates an implicit argument that forwards to
/// a superclass constructor. The super constructor's argument name is always
/// public, even if the corresponding constructor parameter uses this feature
/// and has a private name. Thus, super parameters continue to always use public
/// names.
///
/// @description Check that private super parameter can be invoked using its
/// public name. Test declaring constructors.
/// @author [email protected]

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

import '../../Utils/expect.dart';

class A1 {
String _p;
A1({this._p = ""});
}

class A2 {
String _p;
A2({required this._p});
}

class C1({super.p}) extends A1;

class C2 extends A2 {
this({required super.p});
}

main() {
Expect.equals("a", C1(p: "a")._p);
Expect.equals("b", C2(p: "b")._p);
}