@@ -784,46 +784,39 @@ ConcreteDeclRef TypeChecker::getReferencedDeclForHasSymbolCondition(Expr *E) {
784
784
return ConcreteDeclRef ();
785
785
}
786
786
787
- bool TypeChecker::typeCheckStmtConditionElement (StmtConditionElement &elt,
788
- bool &isFalsable,
789
- DeclContext *dc) {
790
- auto &Context = dc->getASTContext ();
791
-
792
- // Typecheck a #available or #unavailable condition.
793
- if (elt.getKind () == StmtConditionElement::CK_Availability) {
794
- isFalsable = true ;
787
+ static bool typeCheckHasSymbolStmtConditionElement (StmtConditionElement &elt,
788
+ DeclContext *dc) {
789
+ auto Info = elt.getHasSymbolInfo ();
790
+ auto E = Info->getSymbolExpr ();
791
+ if (!E)
795
792
return false ;
796
- }
797
793
798
- // Typecheck a #_hasSymbol condition.
799
- if (elt.getKind () == StmtConditionElement::CK_HasSymbol) {
800
- isFalsable = true ;
794
+ auto exprTy = TypeChecker::typeCheckExpression (E, dc);
795
+ Info->setSymbolExpr (E);
801
796
802
- auto Info = elt.getHasSymbolInfo ();
803
- auto E = Info->getSymbolExpr ();
804
- if (!E)
805
- return false ;
806
-
807
- auto exprTy = TypeChecker::typeCheckExpression (E, dc);
808
- Info->setSymbolExpr (E);
797
+ if (!exprTy) {
798
+ Info->setInvalid ();
799
+ return true ;
800
+ }
809
801
810
- if (!exprTy) {
811
- Info-> setInvalid ( );
812
- return true ;
813
- }
802
+ Info-> setReferencedDecl (
803
+ TypeChecker::getReferencedDeclForHasSymbolCondition (E) );
804
+ return false ;
805
+ }
814
806
815
- Info->setReferencedDecl (getReferencedDeclForHasSymbolCondition (E));
816
- return false ;
817
- }
807
+ static bool typeCheckBooleanStmtConditionElement (StmtConditionElement &elt,
808
+ DeclContext *dc) {
809
+ Expr *E = elt.getBoolean ();
810
+ assert (!E->getType () && " the bool condition is already type checked" );
811
+ bool hadError = TypeChecker::typeCheckCondition (E, dc);
812
+ elt.setBoolean (E);
813
+ return hadError;
814
+ }
818
815
819
- if (auto E = elt.getBooleanOrNull ()) {
820
- assert (!E->getType () && " the bool condition is already type checked" );
821
- bool hadError = TypeChecker::typeCheckCondition (E, dc);
822
- elt.setBoolean (E);
823
- isFalsable = true ;
824
- return hadError;
825
- }
826
- assert (elt.getKind () != StmtConditionElement::CK_Boolean);
816
+ static bool
817
+ typeCheckPatternBindingStmtConditionElement (StmtConditionElement &elt,
818
+ bool &isFalsable, DeclContext *dc) {
819
+ auto &Context = dc->getASTContext ();
827
820
828
821
// This is cleanup goop run on the various paths where type checking of the
829
822
// pattern binding fails.
@@ -871,6 +864,24 @@ bool TypeChecker::typeCheckStmtConditionElement(StmtConditionElement &elt,
871
864
return hadError;
872
865
}
873
866
867
+ bool TypeChecker::typeCheckStmtConditionElement (StmtConditionElement &elt,
868
+ bool &isFalsable,
869
+ DeclContext *dc) {
870
+ switch (elt.getKind ()) {
871
+ case StmtConditionElement::CK_Availability:
872
+ isFalsable = true ;
873
+ return false ;
874
+ case StmtConditionElement::CK_HasSymbol:
875
+ isFalsable = true ;
876
+ return typeCheckHasSymbolStmtConditionElement (elt, dc);
877
+ case StmtConditionElement::CK_Boolean:
878
+ isFalsable = true ;
879
+ return typeCheckBooleanStmtConditionElement (elt, dc);
880
+ case StmtConditionElement::CK_PatternBinding:
881
+ return typeCheckPatternBindingStmtConditionElement (elt, isFalsable, dc);
882
+ }
883
+ }
884
+
874
885
// / Type check the given 'if', 'while', or 'guard' statement condition.
875
886
// /
876
887
// / \param stmt The conditional statement to type-check, which will be modified
0 commit comments