@@ -852,30 +852,8 @@ bool TypeChecker::typeCheckBinding(Pattern *&pattern, Expr *&initializer,
852852 return false ;
853853 }
854854
855- auto &Context = DC->getASTContext ();
856855 initializer = target.getAsExpr ();
857-
858- if (!initializer->getType ())
859- initializer->setType (ErrorType::get (Context));
860-
861- // Assign error types to the pattern and its variables, to prevent it from
862- // being referenced by the constraint system.
863- if (patternType->hasUnresolvedType () ||
864- patternType->hasPlaceholder () ||
865- patternType->hasUnboundGenericType ()) {
866- pattern->setType (ErrorType::get (Context));
867- }
868-
869- pattern->forEachVariable ([&](VarDecl *var) {
870- // Don't change the type of a variable that we've been able to
871- // compute a type for.
872- if (var->hasInterfaceType () &&
873- !var->getTypeInContext ()->hasUnboundGenericType () &&
874- !var->isInvalid ())
875- return ;
876-
877- var->setInvalid ();
878- });
856+ pattern = target.getInitializationPattern ();
879857 return true ;
880858}
881859
@@ -927,25 +905,14 @@ bool TypeChecker::typeCheckForEachPreamble(DeclContext *dc, ForEachStmt *stmt) {
927905 FrontendStatsTracer statsTracer (Context.Stats , " typecheck-for-each" , stmt);
928906 PrettyStackTraceStmt stackTrace (Context, " type-checking-for-each" , stmt);
929907
930- auto failed = [&]() -> bool {
931- // Invalidate the pattern and the var decl.
932- stmt->getPattern ()->setType (ErrorType::get (Context));
933- stmt->getPattern ()->forEachVariable ([&](VarDecl *var) {
934- if (var->hasInterfaceType () && !var->isInvalid ())
935- return ;
936- var->setInvalid ();
937- });
938- return true ;
939- };
940-
941908 auto target = SyntacticElementTarget::forForEachPreamble (stmt, dc);
942909 if (!typeCheckTarget (target))
943- return failed () ;
910+ return true ;
944911
945912 if (auto *where = stmt->getWhere ()) {
946913 auto boolType = dc->getASTContext ().getBoolType ();
947914 if (!boolType)
948- return failed () ;
915+ return true ;
949916
950917 SyntacticElementTarget whereClause (where, dc, {boolType, CTP_Condition},
951918 /* isDiscarded=*/ false );
@@ -959,7 +926,7 @@ bool TypeChecker::typeCheckForEachPreamble(DeclContext *dc, ForEachStmt *stmt) {
959926 // Check to see if the sequence expr is throwing (in async context),
960927 // if so require the stmt to have a `try`.
961928 if (diagnoseUnhandledThrowsInAsyncContext (dc, stmt))
962- return failed () ;
929+ return true ;
963930
964931 return false ;
965932}
0 commit comments