Skip to content

Commit 0dd784e

Browse files
authored
#1952. Constructor of classes that cannot be constructed cannot be torn off (#2063)
1 parent e22ff5f commit 0dd784e

8 files changed

+189
-1
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
/// @assertion Abstract base class can be extended but not constructed,
6+
/// implemented or mixed in and is not exhaustive
7+
///
8+
/// @description Checks that it is a compile-time error to tear off constructor
9+
/// of an `abstract base class`
10+
/// @author [email protected]
11+
12+
abstract base class AbstractBaseClass {
13+
AbstractBaseClass();
14+
AbstractBaseClass.x();
15+
}
16+
17+
main() {
18+
var tf1 = AbstractBaseClass.new;
19+
// ^^^^^^^^^^^^^^^^^^^^^
20+
// [analyzer] unspecified
21+
// [cfe] unspecified
22+
23+
var tf2 = AbstractBaseClass.x;
24+
// ^^^^^^^^^^^^^^^^^^^
25+
// [analyzer] unspecified
26+
// [cfe] unspecified
27+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
/// @assertion Abstract base mixin class can be extended and mixed in but not
6+
/// constructed, implemented and is not exhaustive
7+
///
8+
/// @description Checks that it is a compile-time error to tear off constructor
9+
/// of an `abstract base mixin class`
10+
/// @author [email protected]
11+
12+
abstract base mixin class AbstractBaseMixinClass {
13+
AbstractBaseMixinClass();
14+
AbstractBaseMixinClass.x();
15+
}
16+
17+
main() {
18+
var tf1 = AbstractBaseMixinClass.new;
19+
// ^^^^^^^^^^^^^^^^^^^^^^^^^^
20+
// [analyzer] unspecified
21+
// [cfe] unspecified
22+
23+
var tf2 = AbstractBaseMixinClass.x;
24+
// ^^^^^^^^^^^^^^^^^^^^^^^^
25+
// [analyzer] unspecified
26+
// [cfe] unspecified
27+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
/// @assertion Abstract class can be extended and implemented but not
6+
/// constructed, mixed in and is not exhaustive
7+
///
8+
/// @description Checks that it is a compile-time error to tear off constructor
9+
/// of an `abstract class`
10+
/// @author [email protected]
11+
12+
abstract class AbstractClass {
13+
AbstractClass();
14+
AbstractClass.x();
15+
}
16+
17+
main() {
18+
var tf1 = AbstractClass.new;
19+
// ^^^^^^^^^^^^^^^^^
20+
// [analyzer] unspecified
21+
// [cfe] unspecified
22+
23+
var tf2 = AbstractClass.x;
24+
// ^^^^^^^^^^^^^^^
25+
// [analyzer] unspecified
26+
// [cfe] unspecified
27+
}

LanguageFeatures/Class-modifiers/syntax_abstract_final_class_A01_t01.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import "class_modifiers_lib.dart";
1212

1313
abstract final class LocalAbstractFinalClass {}
1414

15-
1615
main() {
1716
AbstractFinalClass();
1817
//^^^^^^^^^^^^^^^^^^
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
/// @assertion Abstract final class cannot be constructed, extended, implemented
6+
/// or mixed in and is not exhaustive
7+
///
8+
/// @description Checks that it is a compile-time error to tear off constructor
9+
/// of an `abstract final class`
10+
/// @author [email protected]
11+
12+
abstract final class AbstractFinalClass {
13+
AbstractFinalClass();
14+
AbstractFinalClass.x();
15+
}
16+
17+
main() {
18+
var tf1 = AbstractFinalClass.new;
19+
// ^^^^^^^^^^^^^^^^^^^^^^
20+
// [analyzer] unspecified
21+
// [cfe] unspecified
22+
23+
var tf2 = AbstractFinalClass.x;
24+
// ^^^^^^^^^^^^^^^^^^^^
25+
// [analyzer] unspecified
26+
// [cfe] unspecified
27+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
/// @assertion Abstract interface class can be implemented but not constructed,
6+
/// extended or mixed in and is not exhaustive
7+
///
8+
/// @description Checks that it is a compile-time error to tear off constructor
9+
/// of an `abstract interface class`
10+
/// @author [email protected]
11+
12+
abstract interface class AbstractInterfaceClass {
13+
AbstractInterfaceClass();
14+
AbstractInterfaceClass.x();
15+
}
16+
17+
main() {
18+
var tf1 = AbstractInterfaceClass.new;
19+
// ^^^^^^^^^^^^^^^^^^^^^^^^^^
20+
// [analyzer] unspecified
21+
// [cfe] unspecified
22+
23+
var tf2 = AbstractInterfaceClass.x;
24+
// ^^^^^^^^^^^^^^^^^^^^^^^^
25+
// [analyzer] unspecified
26+
// [cfe] unspecified
27+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
/// @assertion Abstract mixin class can be extended, implemented and mixed in
6+
/// but not constructed and is not exhaustive
7+
///
8+
/// @description Checks that it is a compile-time error to tear off constructor
9+
/// of an `abstract mixin class`
10+
/// @author [email protected]
11+
12+
abstract mixin class AbstractMixinClass {
13+
AbstractMixinClass();
14+
AbstractMixinClass.x();
15+
}
16+
17+
main() {
18+
var tf1 = AbstractMixinClass.new;
19+
// ^^^^^^^^^^^^^^^^^^^^^^
20+
// [analyzer] unspecified
21+
// [cfe] unspecified
22+
23+
var tf2 = AbstractMixinClass.x;
24+
// ^^^^^^^^^^^^^^^^^^^^
25+
// [analyzer] unspecified
26+
// [cfe] unspecified
27+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
/// @assertion Sealed class cannot be constructed, extended, implemented or
6+
/// mixed in but is exhaustive
7+
///
8+
/// @description Checks that it is a compile-time error to tear off constructor
9+
/// of a `sealed class`
10+
/// @author [email protected]
11+
12+
sealed class SealedClass {
13+
SealedClass();
14+
SealedClass.x();
15+
}
16+
17+
main() {
18+
var tf1 = SealedClass.new;
19+
// ^^^^^^^^^^^^^^^
20+
// [analyzer] unspecified
21+
// [cfe] unspecified
22+
23+
var tf2 = SealedClass.x;
24+
// ^^^^^^^^^^^^^
25+
// [analyzer] unspecified
26+
// [cfe] unspecified
27+
}

0 commit comments

Comments
 (0)