@@ -37,6 +37,7 @@ import '../fasta_codes.dart'
37
37
38
38
import '../kernel/body_builder.dart' ;
39
39
import '../kernel/constructor_tearoff_lowering.dart' ;
40
+ import '../kernel/expression_generator_helper.dart' ;
40
41
import '../kernel/kernel_helper.dart' ;
41
42
import '../kernel/internal_ast.dart' ;
42
43
@@ -253,7 +254,20 @@ class SourceEnumBuilder extends SourceClassBuilder {
253
254
members["values" ] = valuesBuilder;
254
255
255
256
DeclaredSourceConstructorBuilder ? synthesizedDefaultConstructorBuilder;
256
- if (constructorScope.local.isEmpty) {
257
+
258
+ // The default constructor is added if no generative or unnamed factory
259
+ // constructors are declared.
260
+ bool needsSynthesizedDefaultConstructor = true ;
261
+ if (constructorScope.local.isNotEmpty) {
262
+ for (MemberBuilder constructorBuilder in constructorScope.local.values) {
263
+ if (! constructorBuilder.isFactory || constructorBuilder.name == "" ) {
264
+ needsSynthesizedDefaultConstructor = false ;
265
+ break ;
266
+ }
267
+ }
268
+ }
269
+
270
+ if (needsSynthesizedDefaultConstructor) {
257
271
synthesizedDefaultConstructorBuilder =
258
272
new DeclaredSourceConstructorBuilder (
259
273
/* metadata = */ null ,
@@ -540,6 +554,13 @@ class SourceEnumBuilder extends SourceClassBuilder {
540
554
if (enumConstantInfos != null ) {
541
555
for (EnumConstantInfo ? enumConstantInfo in enumConstantInfos! ) {
542
556
if (enumConstantInfo != null ) {
557
+ if (enumConstantInfo.argumentsBeginToken == null &&
558
+ enumConstantInfo.constructorReferenceBuilder? .typeArguments !=
559
+ null ) {
560
+ addProblem (messageEnumEntryWithTypeArgumentsWithoutArguments,
561
+ enumConstantInfo.charOffset, noLength);
562
+ }
563
+
543
564
String constant = enumConstantInfo.name;
544
565
Builder declaration = firstMemberNamed (constant)! ;
545
566
SourceFieldBuilder field;
@@ -554,63 +575,69 @@ class SourceEnumBuilder extends SourceClassBuilder {
554
575
MemberBuilder ? constructorBuilder =
555
576
constructorScopeBuilder[constructorName];
556
577
557
- if (constructorBuilder == null ||
558
- constructorBuilder is ! SourceConstructorBuilder ) {
559
- // TODO(cstefantsova): Report an error.
560
- } else {
561
- if (enumConstantInfo.argumentsBeginToken == null &&
562
- enumConstantInfo.constructorReferenceBuilder? .typeArguments !=
563
- null ) {
564
- addProblem (messageEnumEntryWithTypeArgumentsWithoutArguments,
565
- enumConstantInfo.charOffset, noLength);
566
- }
567
-
568
- Arguments arguments;
569
- List <Expression > enumSyntheticArguments = < Expression > [
570
- new IntLiteral (index++ ),
571
- new StringLiteral (constant),
572
- ];
573
- List <DartType >? typeArguments;
574
- List <TypeBuilder >? typeArgumentBuilders =
575
- enumConstantInfo.constructorReferenceBuilder? .typeArguments;
576
- if (typeArgumentBuilders != null ) {
577
- typeArguments = < DartType > [];
578
- for (TypeBuilder typeBuilder in typeArgumentBuilders) {
579
- typeArguments.add (typeBuilder.build (library));
580
- }
581
- }
582
- BodyBuilder ? bodyBuilder;
583
- if (enumConstantInfo.argumentsBeginToken != null ||
584
- typeArgumentBuilders == null && cls.typeParameters.isNotEmpty) {
585
- // We need to create a BodyBuilder in two cases: 1) if the
586
- // arguments token is provided, we'll use the BodyBuilder to
587
- // parse them and perform inference, 2) if the type arguments
588
- // aren't provided, but required, we'll use it to infer them.
589
- bodyBuilder = library.loader
590
- .createBodyBuilderForOutlineExpression (
591
- library, this , this , scope, fileUri);
592
- bodyBuilder.constantContext = ConstantContext .required ;
578
+ Arguments arguments;
579
+ List <Expression > enumSyntheticArguments = < Expression > [
580
+ new IntLiteral (index++ ),
581
+ new StringLiteral (constant),
582
+ ];
583
+ List <DartType >? typeArguments;
584
+ List <TypeBuilder >? typeArgumentBuilders =
585
+ enumConstantInfo.constructorReferenceBuilder? .typeArguments;
586
+ if (typeArgumentBuilders != null ) {
587
+ typeArguments = < DartType > [];
588
+ for (TypeBuilder typeBuilder in typeArgumentBuilders) {
589
+ typeArguments.add (typeBuilder.build (library));
593
590
}
591
+ }
592
+ BodyBuilder ? bodyBuilder;
593
+ if (enumConstantInfo.argumentsBeginToken != null ||
594
+ typeArgumentBuilders == null && cls.typeParameters.isNotEmpty) {
595
+ // We need to create a BodyBuilder in two cases: 1) if the
596
+ // arguments token is provided, we'll use the BodyBuilder to
597
+ // parse them and perform inference, 2) if the type arguments
598
+ // aren't provided, but required, we'll use it to infer them.
599
+ bodyBuilder = library.loader.createBodyBuilderForOutlineExpression (
600
+ library, this , this , scope, fileUri);
601
+ bodyBuilder.constantContext = ConstantContext .required ;
602
+ }
594
603
595
- if (enumConstantInfo.argumentsBeginToken != null ) {
596
- arguments = bodyBuilder!
597
- .parseArguments (enumConstantInfo.argumentsBeginToken! );
598
- bodyBuilder.performBacklogComputations (delayedActionPerformers);
604
+ if (enumConstantInfo.argumentsBeginToken != null ) {
605
+ arguments = bodyBuilder!
606
+ .parseArguments (enumConstantInfo.argumentsBeginToken! );
607
+ bodyBuilder.performBacklogComputations (delayedActionPerformers);
599
608
600
- arguments.positional.insertAll (0 , enumSyntheticArguments);
601
- } else {
602
- arguments = new ArgumentsImpl (enumSyntheticArguments);
603
- }
609
+ arguments.positional.insertAll (0 , enumSyntheticArguments);
610
+ } else {
611
+ arguments = new ArgumentsImpl (enumSyntheticArguments);
612
+ }
604
613
605
- if (typeArguments != null && arguments is ArgumentsImpl ) {
606
- ArgumentsImpl .setNonInferrableArgumentTypes (
607
- arguments, typeArguments);
608
- } else if (cls.typeParameters.isNotEmpty) {
609
- arguments.types.addAll (new List <DartType >.filled (
610
- cls.typeParameters.length, const UnknownType ()));
611
- }
612
- setParents (enumSyntheticArguments, arguments);
614
+ if (typeArguments != null && arguments is ArgumentsImpl ) {
615
+ ArgumentsImpl .setNonInferrableArgumentTypes (
616
+ arguments, typeArguments);
617
+ } else if (cls.typeParameters.isNotEmpty) {
618
+ arguments.types.addAll (new List <DartType >.filled (
619
+ cls.typeParameters.length, const UnknownType ()));
620
+ }
621
+ setParents (enumSyntheticArguments, arguments);
613
622
623
+ if (constructorBuilder == null ||
624
+ constructorBuilder is ! SourceConstructorBuilder ) {
625
+ bodyBuilder ?? = library.loader
626
+ .createBodyBuilderForOutlineExpression (
627
+ library, this , this , scope, fileUri)
628
+ ..constantContext = ConstantContext .required ;
629
+ field.buildBody (
630
+ classHierarchy.coreTypes,
631
+ bodyBuilder.buildUnresolvedError (
632
+ new NullLiteral (),
633
+ enumConstantInfo
634
+ .constructorReferenceBuilder? .fullNameForErrors ??
635
+ constructorName,
636
+ arguments,
637
+ enumConstantInfo.constructorReferenceBuilder? .charOffset ??
638
+ enumConstantInfo.charOffset,
639
+ kind: UnresolvedKind .Constructor ));
640
+ } else {
614
641
Expression initializer = new ConstructorInvocation (
615
642
constructorBuilder.constructor, arguments,
616
643
isConst: true )
0 commit comments