Skip to content

Commit f12fa86

Browse files
kallentuCommit Queue
authored and
Commit Queue
committed
[cfe] Make named mixin applications non-constructable and abstract if sealed.
Special syntax for mixin applications should be also abstract if we add the sealed modifier. Change-Id: I3af3e997734f4bc762dc29bfc3f61f2e691ca41b Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/271840 Reviewed-by: Johnni Winther <[email protected]> Commit-Queue: Kallen Tu <[email protected]>
1 parent 2b7b4dc commit f12fa86

8 files changed

+15
-6
lines changed

pkg/front_end/lib/src/fasta/source/outline_builder.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2209,6 +2209,9 @@ class OutlineBuilder extends StackListenerImpl {
22092209
}
22102210
}
22112211
}
2212+
if (sealedToken != null) {
2213+
modifiers |= abstractMask;
2214+
}
22122215

22132216
int startCharOffset = beginToken.charOffset;
22142217
int charEndOffset = endToken.charOffset;

pkg/front_end/testcases/sealed_class/sealed_class_declaration.dart.strong.expect

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ abstract sealed class A extends core::Object {
99
}
1010
abstract class M extends core::Object /*isMixinDeclaration*/ {
1111
}
12-
sealed class B = core::Object with self::M /*hasConstConstructor*/ {
12+
abstract sealed class B = core::Object with self::M /*hasConstConstructor*/ {
1313
const synthetic constructor •() → self::B
1414
: super core::Object::•()
1515
;

pkg/front_end/testcases/sealed_class/sealed_class_declaration.dart.strong.transformed.expect

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ abstract sealed class A extends core::Object {
99
}
1010
abstract class M extends core::Object /*isMixinDeclaration*/ {
1111
}
12-
sealed class B extends core::Object implements self::M /*isEliminatedMixin,hasConstConstructor*/ {
12+
abstract sealed class B extends core::Object implements self::M /*isEliminatedMixin,hasConstConstructor*/ {
1313
const synthetic constructor •() → self::B
1414
: super core::Object::•()
1515
;

pkg/front_end/testcases/sealed_class/sealed_class_declaration.dart.weak.expect

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ abstract sealed class A extends core::Object {
99
}
1010
abstract class M extends core::Object /*isMixinDeclaration*/ {
1111
}
12-
sealed class B = core::Object with self::M /*hasConstConstructor*/ {
12+
abstract sealed class B = core::Object with self::M /*hasConstConstructor*/ {
1313
const synthetic constructor •() → self::B
1414
: super core::Object::•()
1515
;

pkg/front_end/testcases/sealed_class/sealed_class_declaration.dart.weak.modular.expect

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ abstract sealed class A extends core::Object {
99
}
1010
abstract class M extends core::Object /*isMixinDeclaration*/ {
1111
}
12-
sealed class B = core::Object with self::M /*hasConstConstructor*/ {
12+
abstract sealed class B = core::Object with self::M /*hasConstConstructor*/ {
1313
const synthetic constructor •() → self::B
1414
: super core::Object::•()
1515
;

pkg/front_end/testcases/sealed_class/sealed_class_declaration.dart.weak.outline.expect

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ abstract sealed class A extends core::Object {
88
}
99
abstract class M extends core::Object /*isMixinDeclaration*/ {
1010
}
11-
sealed class B = core::Object with self::M /*hasConstConstructor*/ {
11+
abstract sealed class B = core::Object with self::M /*hasConstConstructor*/ {
1212
const synthetic constructor •() → self::B
1313
: super core::Object::•()
1414
;

pkg/front_end/testcases/sealed_class/sealed_class_declaration.dart.weak.transformed.expect

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ abstract sealed class A extends core::Object {
99
}
1010
abstract class M extends core::Object /*isMixinDeclaration*/ {
1111
}
12-
sealed class B extends core::Object implements self::M /*isEliminatedMixin,hasConstConstructor*/ {
12+
abstract sealed class B extends core::Object implements self::M /*isEliminatedMixin,hasConstConstructor*/ {
1313
const synthetic constructor •() → self::B
1414
: super core::Object::•()
1515
;

tests/language/sealed_class/sealed_class_construct_error_test.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ sealed class NotConstructable {}
1111

1212
sealed mixin AlsoNotConstructable {}
1313

14+
mixin M {}
15+
sealed class NotConstructableWithMixin = Object with M;
16+
1417
main() {
1518
var error = NotConstructable();
1619
// ^
@@ -19,4 +22,7 @@ main() {
1922
// ^^^^^^^^^^^^^^^^^^^^
2023
// [analyzer] COMPILE_TIME_ERROR.MIXIN_INSTANTIATE
2124
// [cfe] Couldn't find constructor 'AlsoNotConstructable'.
25+
var error3 = NotConstructableWithMixin();
26+
// ^
27+
// [cfe] The class 'NotConstructableWithMixin' is abstract and can't be instantiated.
2228
}

0 commit comments

Comments
 (0)