blob: 52151eefb84bc28eb06a411526cb8a50326bd823 [file] [edit]
// 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 sgrekhov22@gmail.com
// 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
}