Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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,52 @@
// 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 there is no error then:
/// - The parameter name of the parameter in the constructor is the public name
/// `n`. This means that the parameter has a public name in the constructor's
/// function signature, and arguments for this parameter are given using the
/// public name. All uses of the constructor, outside of its own code, see
/// only the public name.
///
/// @description Check that the name of the parameter in the constructor
/// signature is a corresponding public name `n`.
/// @author [email protected]

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

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

class C {
String? _p;

C({this._p});
C.named({required this._p});
}

extension type ET._(String? _p) {
ET({this._p});
ET.named({required this._p});
}

enum E {
e0(p: "0"), e1.named(p: "1");

final String? _p;

const E({this._p});
const E.named({required this._p});
}

main() {
C.new.expectStaticType<Exactly<C Function({String? p})>>();
C.named.expectStaticType<Exactly<C Function({required String? p})>>();
ET.new.expectStaticType<Exactly<ET Function({String? p})>>();
ET.named.expectStaticType<Exactly<ET Function({required String? p})>>();
Expect.equals("0", E.e0._p);
Expect.equals("1", E.e1._p);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// 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 there is no error then:
/// - The parameter name of the parameter in the constructor is the public name
/// `n`. This means that the parameter has a public name in the constructor's
/// function signature, and arguments for this parameter are given using the
/// public name. All uses of the constructor, outside of its own code, see
/// only the public name.
///
/// @description Check that the name of the parameter in the constructor
/// signature is a corresponding public name `n`. Test declaring constructors.
/// @author [email protected]

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

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

class C1({var String?_p});

class C2 {
this({required final String _p});
}

extension type ET1 {
this({final String? _p});
}

extension type ET2 {
this({required final String _p});
}

enum E1({final String? _p}) {
e0(p: "E1");
}

enum E2 {
e0(p: "E2");

const this({required final String _p});
}

main() {
C1.new.expectStaticType<Exactly<C1 Function({String? p})>>();
C2.new.expectStaticType<Exactly<C2 Function({required String p})>>();
ET1.new.expectStaticType<Exactly<ET1 Function({String? p})>>();
ET2.new.expectStaticType<Exactly<ET2 Function({required String p})>>();
Expect.equals("E1", E1.e0._p);
Expect.equals("E2", E2.e1._p);
}
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 there is no error then:
/// - The parameter name of the parameter in the constructor is the public name
/// `n`. This means that the parameter has a public name in the constructor's
/// function signature, and arguments for this parameter are given using the
/// public name. All uses of the constructor, outside of its own code, see
/// only the public name.
///
/// @description Check that it is a compile-time error to use a private name `p`
/// as the name of the parameter in the constructor signature.
/// @author [email protected]

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

class C {
String? _p;

C({this._p});
C.named({required this._p});
}

extension type ET._(String? _p) {
ET({this._p});
ET.named({required this._p});
}

enum E {
e0(_p: "0"),
// ^^
// [analyzer] unspecified
// [cfe] unspecified
e1.named(_p: "1");
// ^^
// [analyzer] unspecified
// [cfe] unspecified

final String? _p;

const E({this._p});
const E.named({required this._p});
}

main() {
C(_p: "");
// ^^
// [analyzer] unspecified
// [cfe] unspecified

C.named(_p: "");
// ^^
// [analyzer] unspecified
// [cfe] unspecified

ET(_p: "");
// ^^
// [analyzer] unspecified
// [cfe] unspecified

ET.named(_p: "");
// ^^
// [analyzer] unspecified
// [cfe] unspecified
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
// 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 there is no error then:
/// - The parameter name of the parameter in the constructor is the public name
/// `n`. This means that the parameter has a public name in the constructor's
/// function signature, and arguments for this parameter are given using the
/// public name. All uses of the constructor, outside of its own code, see
/// only the public name.
///
/// @description Check that it is a compile-time error to use a private name `p`
/// as the name of the parameter in the constructor signature. Test declaring
/// constructors.
/// @author [email protected]

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

class C1({var String?_p});

class C2 {
this({required final String _p});
}

extension type ET1 {
this({final String? _p});
}

extension type ET2 {
this({required final String _p});
}

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

enum E2 {
e0(_p: "E2");
// ^^
// [analyzer] unspecified
// [cfe] unspecified

const this({required final String _p});
}

main() {
C1(_p: "");
// ^^
// [analyzer] unspecified
// [cfe] unspecified

C2(_p: "");
// ^^
// [analyzer] unspecified
// [cfe] unspecified

ET1(_p: "");
// ^^
// [analyzer] unspecified
// [cfe] unspecified

ET2(_p: "");
// ^^
// [analyzer] unspecified
// [cfe] unspecified
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// 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 there is no error then:
/// ...
/// - The local variable introduced by the parameter, accessible only in the
/// initializer list, still has the private name `p`.
///
/// @description Check that in the initializer list the name of the local
/// variable introduced by the parameter is the private name `p`.
/// @author [email protected]

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

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

class C {
String? _p1;
String? p2;

C({this._p1}) : p2 = _p1;
C.named({required this._p1}) : p2 = _p1;
}

String log = "";

extension type ET._(String? _p) {
ET({this._p}) : assert(() {log = _p; return true;}());
ET.named({required this._p}) : assert(() {log = _p; return true;}());
}

enum E {
e0(p: "0"), e1.named(p: "1");

final String? _p1;
final String? p2;

const E({this._p1}) : p2 = _p1;
const E.named({required this._p1}) : p2 = _p1;
}

main() {
Expect.equals("one", C(p1: "one").p2);
Expect.equals("two", C.named(p1: "two").p2);
ET(p: "one");
if (log.isNotEmpty) {
Expect.equals("one", log);
log = "";
}
ET.named(p: "two");
if (log.isNotEmpty) {
Expect.equals("two", log);
}
Expect.equals("0", E.e0.p2);
Expect.equals("1", E.e1.p2);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
// 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 there is no error then:
/// ...
/// - The local variable introduced by the parameter, accessible only in the
/// initializer list, still has the private name `p`.
///
/// @description Check that in the initializer list the name of the local
/// variable introduced by the parameter is the private name `p`. Test declaring
/// constructors.
/// @author [email protected]

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

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

class C1({var String? _p1}) {
String? p2;
this : p2 = _p1;
}

class C2 {
String p2;
this({required final String _p1}) : p2 = _p1;
}

String log = "";

extension type ET1 {
this({final String? _p}) : assert(() {log = _p; return true;}());
}

extension type ET2 {
this({required final String _p}) : assert(() {log = _p; return true;}());
}

enum E1({final String? _p1}) {
e0(p1: "E1");

final String? p2;
this : p2 = _p1;
}

enum E2 {
e0(p1: "E2");

final String p2;
const this({final String? _p1}) : p2 = _p1;
}

main() {
Expect.equals("one", C1(p1: "one").p2);
Expect.equals("two", C2(p1: "two").p2);
ET1(p: "one");
if (log.isNotEmpty) {
Expect.equals("one", log);
log = "";
}
ET2(p: "two");
if (log.isNotEmpty) {
Expect.equals("two", log);
}
Expect.equals("E1", E1.e0.p2);
Expect.equals("E2", E2.e0.p2);
}
Loading