@@ -852,30 +852,8 @@ bool TypeChecker::typeCheckBinding(Pattern *&pattern, Expr *&initializer,
852
852
return false ;
853
853
}
854
854
855
- auto &Context = DC->getASTContext ();
856
855
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 ();
879
857
return true ;
880
858
}
881
859
@@ -927,25 +905,14 @@ bool TypeChecker::typeCheckForEachPreamble(DeclContext *dc, ForEachStmt *stmt) {
927
905
FrontendStatsTracer statsTracer (Context.Stats , " typecheck-for-each" , stmt);
928
906
PrettyStackTraceStmt stackTrace (Context, " type-checking-for-each" , stmt);
929
907
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
-
941
908
auto target = SyntacticElementTarget::forForEachPreamble (stmt, dc);
942
909
if (!typeCheckTarget (target))
943
- return failed () ;
910
+ return true ;
944
911
945
912
if (auto *where = stmt->getWhere ()) {
946
913
auto boolType = dc->getASTContext ().getBoolType ();
947
914
if (!boolType)
948
- return failed () ;
915
+ return true ;
949
916
950
917
SyntacticElementTarget whereClause (where, dc, {boolType, CTP_Condition},
951
918
/* isDiscarded=*/ false );
@@ -959,7 +926,7 @@ bool TypeChecker::typeCheckForEachPreamble(DeclContext *dc, ForEachStmt *stmt) {
959
926
// Check to see if the sequence expr is throwing (in async context),
960
927
// if so require the stmt to have a `try`.
961
928
if (diagnoseUnhandledThrowsInAsyncContext (dc, stmt))
962
- return failed () ;
929
+ return true ;
963
930
964
931
return false ;
965
932
}
0 commit comments