Skip to content

Commit

Permalink
Fixes #2436. Add tests for external and redirecting constructors with…
Browse files Browse the repository at this point in the history
… initializing formals (#2460)
  • Loading branch information
sgrekhov authored Jan 2, 2024
1 parent c9d0099 commit 2ea77ca
Show file tree
Hide file tree
Showing 8 changed files with 284 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Copyright (c) 2024, 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 It is a compile-time error for an initializing formal parameter
/// to occur in a redirecting or external constructor.
///
/// @description Checks that it is a compile-time error when the initializing
/// formal parameter occurs in a redirecting constructor.
/// @author [email protected]
class C {
int? x;

C(this.x);
C.n(this.x) : this(0);
// ^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
}

enum E {
a(1);

final int x;
const E(this.x);
const E.n(this.x) : this(1);
// ^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
}

main() {
print(C);
print(E);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Copyright (c) 2024, 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 It is a compile-time error for an initializing formal parameter
/// to occur in a redirecting or external constructor.
///
/// @description Checks that it is a compile-time error when the initializing
/// formal parameter occurs in a redirecting constructor.
/// @author [email protected]
class C {
int x;

C({this.x = 0});
C.n({this.x = 1}) : this(x: 0);
// ^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
}

enum E {
a(x: 1);

final int x;
const E({this.x = 0});
const E.n({this.x = 2}) : this(x: 1);
// ^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
}

main() {
print(C);
print(E);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Copyright (c) 2024, 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 It is a compile-time error for an initializing formal parameter
/// to occur in a redirecting or external constructor.
///
/// @description Checks that it is a compile-time error when the initializing
/// formal parameter occurs in a redirecting constructor.
/// @author [email protected]
class C {
int x;

C({required this.x});
C.n({required this.x}) : this(x: 0);
// ^^^^^^^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
}

enum E {
a(x: 1);

final int x;
const E({required this.x});
const E.n({required this.x}) : this(x: 1);
// ^^^^^^^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
}

main() {
print(C);
print(E);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Copyright (c) 2024, 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 It is a compile-time error for an initializing formal parameter
/// to occur in a redirecting or external constructor.
///
/// @description Checks that it is a compile-time error when the initializing
/// formal parameter occurs in a redirecting constructor.
/// @author [email protected]
class C {
int x;

C([this.x = 0]);
C.n([this.x = 1]) : this(0);
// ^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
}

enum E {
a(1);

final int x;
const E([this.x = 0]);
const E.n([this.x = 2]) : this(1);
// ^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
}

main() {
print(C);
print(E);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Copyright (c) 2024, 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 It is a compile-time error for an initializing formal parameter
/// to occur in a redirecting or external constructor.
///
/// @description Checks that it is a compile-time error when the initializing
/// formal parameter occurs in an external constructor.
/// @author [email protected]
/// @issue 54485
class C {
int? x;

external C(this.x);
// ^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
}

enum E {
a(1);

final int x;
external const E(this.x);
// ^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
}

main() {
print(C);
print(E);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Copyright (c) 2024, 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 It is a compile-time error for an initializing formal parameter
/// to occur in a redirecting or external constructor.
///
/// @description Checks that it is a compile-time error when the initializing
/// formal parameter occurs in an external constructor.
/// @author [email protected]
/// @issue 54485
class C {
int x;

external C({this.x = 0});
// ^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
}

enum E {
a(x: 1);

final int x;
external const E({this.x = 0});
// ^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
}

main() {
print(C);
print(E);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Copyright (c) 2024, 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 It is a compile-time error for an initializing formal parameter
/// to occur in a redirecting or external constructor.
///
/// @description Checks that it is a compile-time error when the initializing
/// formal parameter occurs in an external constructor.
/// @author [email protected]
/// @issue 54485
class C {
int x;

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

enum E {
a(x: 1);

final int x;
external const E({required this.x});
// ^^^^^^^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
}

main() {
print(C);
print(E);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Copyright (c) 2024, 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 It is a compile-time error for an initializing formal parameter
/// to occur in a redirecting or external constructor.
///
/// @description Checks that it is a compile-time error when the initializing
/// formal parameter occurs in an external constructor.
/// @author [email protected]
/// @issue 54485
class C {
int x;

external C([this.x = 0]);
// ^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
}

enum E {
a(1);

final int x;
external const E([this.x = 0]);
// ^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
}

main() {
print(C);
print(E);
}

0 comments on commit 2ea77ca

Please sign in to comment.