Skip to content

Commit e98701e

Browse files
Dmitry Stefantsovcommit-bot@chromium.org
Dmitry Stefantsov
authored andcommitted
[fasta] Allow const constructors in mixin applications
Closes #33644, closes #33645, closes #32223. Bug: http://dartbug.com/33644 Bug: http://dartbug.com/33645 Bug: http://dartbug.com/32223 Change-Id: Ia30efb8f450e62bfeb65c8b7fd7e23871ef0e87e Reviewed-on: https://dart-review.googlesource.com/c/68368 Reviewed-by: Peter von der Ahé <[email protected]> Reviewed-by: Erik Ernst <[email protected]> Reviewed-by: Konstantin Shcheglov <[email protected]> Commit-Queue: Dmitry Stefantsov <[email protected]>
1 parent 07ae5ad commit e98701e

File tree

81 files changed

+484
-415
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+484
-415
lines changed

pkg/front_end/lib/src/fasta/fasta_codes_generated.dart

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -922,18 +922,6 @@ const MessageCode messageConstClass = const MessageCode("ConstClass",
922922
tip:
923923
r"""Try removing the 'const' keyword. If you're trying to indicate that instances of the class can be constants, place the 'const' keyword on the class' constructor(s).""");
924924

925-
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
926-
const Code<Null> codeConstConstructorInSubclassOfMixinApplication =
927-
messageConstConstructorInSubclassOfMixinApplication;
928-
929-
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
930-
const MessageCode messageConstConstructorInSubclassOfMixinApplication =
931-
const MessageCode("ConstConstructorInSubclassOfMixinApplication",
932-
analyzerCodes: <String>[
933-
"CONST_CONSTRUCTOR_IN_SUBCLASS_OF_MIXIN_APPLICATION"
934-
],
935-
message: r"""Can't extend a mixin application and be 'const'.""");
936-
937925
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
938926
const Code<Null> codeConstConstructorNonFinalField =
939927
messageConstConstructorNonFinalField;

pkg/front_end/lib/src/fasta/kernel/body_builder.dart

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -599,11 +599,6 @@ abstract class BodyBuilder extends ScopeListener<JumpTarget>
599599
ProcedureBuilder<TypeBuilder> member = this.member;
600600
scope = member.computeFormalParameterInitializerScope(scope);
601601
if (member is KernelConstructorBuilder) {
602-
if (member.isConst &&
603-
(classBuilder.cls.superclass?.isMixinApplication ?? false)) {
604-
addProblem(fasta.messageConstConstructorInSubclassOfMixinApplication,
605-
member.charOffset, member.name.length);
606-
}
607602
if (member.formals != null) {
608603
for (KernelFormalParameterBuilder formal in member.formals) {
609604
if (formal.isInitializingFormal) {

pkg/front_end/lib/src/fasta/kernel/kernel_target.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,8 @@ class KernelTarget extends TargetImplementation {
533533
return new Constructor(function,
534534
name: constructor.name,
535535
initializers: <Initializer>[initializer],
536-
isSynthetic: true);
536+
isSynthetic: true,
537+
isConst: constructor.isConst && mixin.fields.isEmpty);
537538
}
538539

539540
void finishClonedParameters() {

pkg/front_end/messages.yaml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2665,10 +2665,6 @@ ConstConstructorNonFinalFieldCause:
26652665
template: "Field isn't final, but constructor is 'const'."
26662666
severity: CONTEXT
26672667

2668-
ConstConstructorInSubclassOfMixinApplication:
2669-
template: "Can't extend a mixin application and be 'const'."
2670-
analyzerCode: CONST_CONSTRUCTOR_IN_SUBCLASS_OF_MIXIN_APPLICATION
2671-
26722668
ConstConstructorRedirectionToNonConst:
26732669
template: "A constant constructor can't call a non-constant constructor."
26742670
script:

pkg/front_end/testcases/bug33099.dart.outline.expect

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class MyTest extends core::Object {
1414
;
1515
}
1616
abstract class _MyTest2&Object&MyTest = core::Object with self::MyTest {
17-
synthetic constructor •() → self::_MyTest2&Object&MyTest
17+
const synthetic constructor •() → self::_MyTest2&Object&MyTest
1818
: super core::Object::•()
1919
;
2020
}

pkg/front_end/testcases/bug33099.dart.strong.expect

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class MyTest extends core::Object {
1616
method foo() → void {}
1717
}
1818
abstract class _MyTest2&Object&MyTest = core::Object with self::MyTest {
19-
synthetic constructor •() → self::_MyTest2&Object&MyTest
19+
const synthetic constructor •() → self::_MyTest2&Object&MyTest
2020
: super core::Object::•()
2121
;
2222
}

pkg/front_end/testcases/bug33099.dart.strong.transformed.expect

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class MyTest extends core::Object {
1616
method foo() → void {}
1717
}
1818
abstract class _MyTest2&Object&MyTest extends core::Object implements self::MyTest {
19-
synthetic constructor •() → self::_MyTest2&Object&MyTest
19+
const synthetic constructor •() → self::_MyTest2&Object&MyTest
2020
: super core::Object::•()
2121
;
2222
@self::failingTest

pkg/front_end/testcases/bug34511.dart.legacy.expect

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class A<X extends core::Object = dynamic> extends core::Object {
88
;
99
}
1010
abstract class _B&Object&A<Z extends core::Object = dynamic> = core::Object with self::A<() → self::_B&Object&A::Z> {
11-
synthetic constructor •() → self::_B&Object&A<self::_B&Object&A::Z>
11+
const synthetic constructor •() → self::_B&Object&A<self::_B&Object&A::Z>
1212
: super core::Object::•()
1313
;
1414
}

pkg/front_end/testcases/bug34511.dart.legacy.transformed.expect

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class A<X extends core::Object = dynamic> extends core::Object {
88
;
99
}
1010
abstract class _B&Object&A<Z extends core::Object = dynamic> extends core::Object implements self::A<() → self::_B&Object&A::Z> {
11-
synthetic constructor •() → self::_B&Object&A<self::_B&Object&A::Z>
11+
const synthetic constructor •() → self::_B&Object&A<self::_B&Object&A::Z>
1212
: super core::Object::•()
1313
;
1414
}

pkg/front_end/testcases/bug34511.dart.outline.expect

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ class A<X extends core::Object = dynamic> extends core::Object {
77
;
88
}
99
abstract class _B&Object&A<Z extends core::Object = dynamic> = core::Object with self::A<() → self::_B&Object&A::Z> {
10-
synthetic constructor •() → self::_B&Object&A<self::_B&Object&A::Z>
10+
const synthetic constructor •() → self::_B&Object&A<self::_B&Object&A::Z>
1111
: super core::Object::•()
1212
;
1313
}

pkg/front_end/testcases/bug34511.dart.strong.expect

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class A<X extends core::Object = dynamic> extends core::Object {
88
;
99
}
1010
abstract class _B&Object&A<Z extends core::Object = dynamic> = core::Object with self::A<() → self::_B&Object&A::Z> {
11-
synthetic constructor •() → self::_B&Object&A<self::_B&Object&A::Z>
11+
const synthetic constructor •() → self::_B&Object&A<self::_B&Object&A::Z>
1212
: super core::Object::•()
1313
;
1414
}

pkg/front_end/testcases/bug34511.dart.strong.transformed.expect

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class A<X extends core::Object = dynamic> extends core::Object {
88
;
99
}
1010
abstract class _B&Object&A<Z extends core::Object = dynamic> extends core::Object implements self::A<() → self::_B&Object&A::Z> {
11-
synthetic constructor •() → self::_B&Object&A<self::_B&Object&A::Z>
11+
const synthetic constructor •() → self::_B&Object&A<self::_B&Object&A::Z>
1212
: super core::Object::•()
1313
;
1414
}

0 commit comments

Comments
 (0)