@@ -556,7 +556,7 @@ class SyntacticElementConstraintGenerator
556
556
}
557
557
558
558
void visitDecl (Decl *decl) {
559
- if (isSupportedMultiStatementClosure ()) {
559
+ if (! isInSingleExpressionClosure ()) {
560
560
if (auto patternBinding = dyn_cast<PatternBindingDecl>(decl)) {
561
561
if (locator->isLastElement <LocatorPathElt::PatternBindingElement>())
562
562
visitPatternBindingElement (patternBinding);
@@ -585,23 +585,15 @@ class SyntacticElementConstraintGenerator
585
585
}
586
586
587
587
void visitBreakStmt (BreakStmt *breakStmt) {
588
- assert (isSupportedMultiStatementClosure () &&
589
- " Unsupported statement: Break" );
590
588
}
591
589
592
590
void visitContinueStmt (ContinueStmt *continueStmt) {
593
- assert (isSupportedMultiStatementClosure () &&
594
- " Unsupported statement: Continue" );
595
591
}
596
592
597
593
void visitDeferStmt (DeferStmt *deferStmt) {
598
- assert (isSupportedMultiStatementClosure () &&
599
- " Unsupported statement: Defer" );
600
594
}
601
595
602
596
void visitFallthroughStmt (FallthroughStmt *fallthroughStmt) {
603
- assert (isSupportedMultiStatementClosure () &&
604
- " Unsupported statement: Fallthrough" );
605
597
}
606
598
607
599
void visitStmtCondition (LabeledConditionalStmt *S,
@@ -614,9 +606,6 @@ class SyntacticElementConstraintGenerator
614
606
}
615
607
616
608
void visitIfStmt (IfStmt *ifStmt) {
617
- assert (isSupportedMultiStatementClosure () &&
618
- " Unsupported statement: If" );
619
-
620
609
SmallVector<ElementInfo, 4 > elements;
621
610
622
611
// Condition
@@ -640,9 +629,6 @@ class SyntacticElementConstraintGenerator
640
629
}
641
630
642
631
void visitGuardStmt (GuardStmt *guardStmt) {
643
- assert (isSupportedMultiStatementClosure () &&
644
- " Unsupported statement: Guard" );
645
-
646
632
SmallVector<ElementInfo, 4 > elements;
647
633
648
634
visitStmtCondition (guardStmt, elements, locator);
@@ -652,9 +638,6 @@ class SyntacticElementConstraintGenerator
652
638
}
653
639
654
640
void visitWhileStmt (WhileStmt *whileStmt) {
655
- assert (isSupportedMultiStatementClosure () &&
656
- " Unsupported statement: While" );
657
-
658
641
SmallVector<ElementInfo, 4 > elements;
659
642
660
643
visitStmtCondition (whileStmt, elements, locator);
@@ -664,16 +647,10 @@ class SyntacticElementConstraintGenerator
664
647
}
665
648
666
649
void visitDoStmt (DoStmt *doStmt) {
667
- assert (isSupportedMultiStatementClosure () &&
668
- " Unsupported statement: Do" );
669
-
670
650
visitBraceStmt (doStmt->getBody ());
671
651
}
672
652
673
653
void visitRepeatWhileStmt (RepeatWhileStmt *repeatWhileStmt) {
674
- assert (isSupportedMultiStatementClosure () &&
675
- " Unsupported statement: RepeatWhile" );
676
-
677
654
createConjunction (cs,
678
655
{makeElement (repeatWhileStmt->getCond (),
679
656
cs.getConstraintLocator (
@@ -684,9 +661,6 @@ class SyntacticElementConstraintGenerator
684
661
}
685
662
686
663
void visitPoundAssertStmt (PoundAssertStmt *poundAssertStmt) {
687
- assert (isSupportedMultiStatementClosure () &&
688
- " Unsupported statement: PoundAssert" );
689
-
690
664
createConjunction (cs,
691
665
{makeElement (poundAssertStmt->getCondition (),
692
666
cs.getConstraintLocator (
@@ -696,9 +670,6 @@ class SyntacticElementConstraintGenerator
696
670
}
697
671
698
672
void visitThrowStmt (ThrowStmt *throwStmt) {
699
- assert (isSupportedMultiStatementClosure () &&
700
- " Unsupported statement: Throw" );
701
-
702
673
if (!cs.getASTContext ().getErrorDecl ()) {
703
674
hadError = true ;
704
675
return ;
@@ -718,9 +689,6 @@ class SyntacticElementConstraintGenerator
718
689
}
719
690
720
691
void visitForEachStmt (ForEachStmt *forEachStmt) {
721
- assert (isSupportedMultiStatementClosure () &&
722
- " Unsupported statement: ForEach" );
723
-
724
692
auto *stmtLoc = cs.getConstraintLocator (locator);
725
693
726
694
SmallVector<ElementInfo, 4 > elements;
@@ -738,9 +706,6 @@ class SyntacticElementConstraintGenerator
738
706
}
739
707
740
708
void visitSwitchStmt (SwitchStmt *switchStmt) {
741
- assert (isSupportedMultiStatementClosure () &&
742
- " Unsupported statement: Switch" );
743
-
744
709
auto *switchLoc = cs.getConstraintLocator (
745
710
locator, LocatorPathElt::SyntacticElement (switchStmt));
746
711
@@ -765,9 +730,6 @@ class SyntacticElementConstraintGenerator
765
730
}
766
731
767
732
void visitDoCatchStmt (DoCatchStmt *doStmt) {
768
- assert (isSupportedMultiStatementClosure () &&
769
- " Unsupported statement: DoCatch" );
770
-
771
733
auto *doLoc = cs.getConstraintLocator (
772
734
locator, LocatorPathElt::SyntacticElement (doStmt));
773
735
@@ -785,9 +747,6 @@ class SyntacticElementConstraintGenerator
785
747
}
786
748
787
749
void visitCaseStmt (CaseStmt *caseStmt) {
788
- assert (isSupportedMultiStatementClosure () &&
789
- " Unsupported statement: Case" );
790
-
791
750
Type contextualTy;
792
751
793
752
{
@@ -821,56 +780,56 @@ class SyntacticElementConstraintGenerator
821
780
}
822
781
823
782
void visitBraceStmt (BraceStmt *braceStmt) {
824
- if (isSupportedMultiStatementClosure ()) {
825
- auto &ctx = cs.getASTContext ();
826
-
827
- if (isChildOf (StmtKind::Case)) {
828
- auto *caseStmt = cast<CaseStmt>(
829
- locator->castLastElementTo <LocatorPathElt::SyntacticElement>()
830
- .asStmt ());
831
-
832
- if (recordInferredSwitchCasePatternVars (caseStmt)) {
833
- hadError = true ;
783
+ if (isInSingleExpressionClosure ()) {
784
+ for (auto node : braceStmt->getElements ()) {
785
+ if (auto expr = node.dyn_cast <Expr *>()) {
786
+ auto generatedExpr = cs.generateConstraints (
787
+ expr, context.getAsDeclContext (), /* isInputExpression=*/ false );
788
+ if (!generatedExpr) {
789
+ hadError = true ;
790
+ }
791
+ } else if (auto stmt = node.dyn_cast <Stmt *>()) {
792
+ visit (stmt);
793
+ } else {
794
+ visitDecl (node.get <Decl *>());
834
795
}
835
796
}
797
+ return ;
798
+ }
836
799
837
- SmallVector<ElementInfo, 4 > elements;
838
- for (auto element : braceStmt->getElements ()) {
839
- bool isDiscarded =
840
- element.is <Expr *>() &&
841
- (!ctx.LangOpts .Playground && !ctx.LangOpts .DebuggerSupport );
800
+ auto &ctx = cs.getASTContext ();
842
801
843
- if (auto *decl = element.dyn_cast <Decl *>()) {
844
- if (auto *PDB = dyn_cast<PatternBindingDecl>(decl)) {
845
- visitPatternBinding (PDB, elements);
846
- continue ;
847
- }
848
- }
802
+ if (isChildOf (StmtKind::Case)) {
803
+ auto *caseStmt = cast<CaseStmt>(
804
+ locator->castLastElementTo <LocatorPathElt::SyntacticElement>()
805
+ .asStmt ());
849
806
850
- elements.push_back (makeElement (
851
- element,
852
- cs.getConstraintLocator (
853
- locator, LocatorPathElt::SyntacticElement (element)),
854
- /* contextualInfo=*/ {}, isDiscarded));
807
+ if (recordInferredSwitchCasePatternVars (caseStmt)) {
808
+ hadError = true ;
855
809
}
856
-
857
- createConjunction (cs, elements, locator);
858
- return ;
859
810
}
860
811
861
- for (auto node : braceStmt->getElements ()) {
862
- if (auto expr = node.dyn_cast <Expr *>()) {
863
- auto generatedExpr = cs.generateConstraints (
864
- expr, context.getAsDeclContext (), /* isInputExpression=*/ false );
865
- if (!generatedExpr) {
866
- hadError = true ;
812
+ SmallVector<ElementInfo, 4 > elements;
813
+ for (auto element : braceStmt->getElements ()) {
814
+ bool isDiscarded =
815
+ element.is <Expr *>() &&
816
+ (!ctx.LangOpts .Playground && !ctx.LangOpts .DebuggerSupport );
817
+
818
+ if (auto *decl = element.dyn_cast <Decl *>()) {
819
+ if (auto *PDB = dyn_cast<PatternBindingDecl>(decl)) {
820
+ visitPatternBinding (PDB, elements);
821
+ continue ;
867
822
}
868
- } else if (auto stmt = node.dyn_cast <Stmt *>()) {
869
- visit (stmt);
870
- } else {
871
- visitDecl (node.get <Decl *>());
872
823
}
824
+
825
+ elements.push_back (
826
+ makeElement (element,
827
+ cs.getConstraintLocator (
828
+ locator, LocatorPathElt::SyntacticElement (element)),
829
+ /* contextualInfo=*/ {}, isDiscarded));
873
830
}
831
+
832
+ createConjunction (cs, elements, locator);
874
833
}
875
834
876
835
void visitReturnStmt (ReturnStmt *returnStmt) {
@@ -946,18 +905,6 @@ class SyntacticElementConstraintGenerator
946
905
return context.getBodyResultType ();
947
906
}
948
907
949
- bool isSupportedMultiStatementClosure () const {
950
- if (cs.getAppliedResultBuilderTransform (context))
951
- return true ;
952
-
953
- if (auto *closure =
954
- getAsExpr<ClosureExpr>(context.getAbstractClosureExpr ())) {
955
- return !closure->hasSingleExpressionBody () &&
956
- cs.participatesInInference (closure);
957
- }
958
- return true ;
959
- }
960
-
961
908
#define UNSUPPORTED_STMT (STMT ) void visit##STMT##Stmt(STMT##Stmt *) { \
962
909
llvm_unreachable (" Unsupported statement kind " #STMT); \
963
910
}
0 commit comments