| // Copyright (c) 2026, 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 The following errors apply to formal parameters of a primary |
| /// constructor. Let `p` be a formal parameter of a primary constructor in a |
| /// class, mixin class, enum, or extension type declaration `D` named `C`: |
| /// ... |
| /// A compile-time error occurs if `p` has the modifier covariant, but not `var`. |
| /// |
| /// @description Check that it is a compile-time error if a formal parameters of |
| /// a primary constructor has the modifier `covariant`, but not `var`. Test |
| /// classes. |
| /// @author sgrekhov22@gmail.com |
| |
| // SharedOptions=--enable-experiment=primary-constructors |
| |
| class C1(covariant x) {} |
| // ^^^^^^^^^ |
| // [analyzer] unspecified |
| // [cfe] unspecified |
| |
| class C2([covariant x]) {} |
| // ^^^^^^^^^ |
| // [analyzer] unspecified |
| // [cfe] unspecified |
| |
| class C3({covariant x = ''}) {} |
| // ^^^^^^^^^ |
| // [analyzer] unspecified |
| // [cfe] unspecified |
| |
| class C4({required covariant x}) {} |
| // ^^^^^^^^^ |
| // [analyzer] unspecified |
| // [cfe] unspecified |
| |
| main() { |
| print(C1); |
| print(C2); |
| print(C3); |
| print(C4); |
| } |