@@ -852,31 +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
856
pattern = target.getInitializationPattern ();
858
-
859
- if (!initializer->getType ())
860
- initializer->setType (ErrorType::get (Context));
861
-
862
- // Assign error types to the pattern and its variables, to prevent it from
863
- // being referenced by the constraint system.
864
- if (patternType->hasUnresolvedType () ||
865
- patternType->hasPlaceholder () ||
866
- patternType->hasUnboundGenericType ()) {
867
- pattern->setType (ErrorType::get (Context));
868
- }
869
-
870
- pattern->forEachVariable ([&](VarDecl *var) {
871
- // Don't change the type of a variable that we've been able to
872
- // compute a type for.
873
- if (var->hasInterfaceType () &&
874
- !var->getTypeInContext ()->hasUnboundGenericType () &&
875
- !var->isInvalid ())
876
- return ;
877
-
878
- var->setInvalid ();
879
- });
880
857
return true ;
881
858
}
882
859
@@ -928,25 +905,14 @@ bool TypeChecker::typeCheckForEachPreamble(DeclContext *dc, ForEachStmt *stmt) {
928
905
FrontendStatsTracer statsTracer (Context.Stats , " typecheck-for-each" , stmt);
929
906
PrettyStackTraceStmt stackTrace (Context, " type-checking-for-each" , stmt);
930
907
931
- auto failed = [&]() -> bool {
932
- // Invalidate the pattern and the var decl.
933
- stmt->getPattern ()->setType (ErrorType::get (Context));
934
- stmt->getPattern ()->forEachVariable ([&](VarDecl *var) {
935
- if (var->hasInterfaceType () && !var->isInvalid ())
936
- return ;
937
- var->setInvalid ();
938
- });
939
- return true ;
940
- };
941
-
942
908
auto target = SyntacticElementTarget::forForEachPreamble (stmt, dc);
943
909
if (!typeCheckTarget (target))
944
- return failed () ;
910
+ return true ;
945
911
946
912
if (auto *where = stmt->getWhere ()) {
947
913
auto boolType = dc->getASTContext ().getBoolType ();
948
914
if (!boolType)
949
- return failed () ;
915
+ return true ;
950
916
951
917
SyntacticElementTarget whereClause (where, dc, {boolType, CTP_Condition},
952
918
/* isDiscarded=*/ false );
@@ -960,7 +926,7 @@ bool TypeChecker::typeCheckForEachPreamble(DeclContext *dc, ForEachStmt *stmt) {
960
926
// Check to see if the sequence expr is throwing (in async context),
961
927
// if so require the stmt to have a `try`.
962
928
if (diagnoseUnhandledThrowsInAsyncContext (dc, stmt))
963
- return failed () ;
929
+ return true ;
964
930
965
931
return false ;
966
932
}
0 commit comments