@@ -2801,8 +2801,6 @@ bool TypeChecker::typeCheckBinding(Pattern *&pattern, Expr *&initializer,
2801
2801
? TypeResolverContext::EditorPlaceholderExpr
2802
2802
: TypeResolverContext::InExpression;
2803
2803
options |= TypeResolutionFlags::OverrideType;
2804
- options |= TypeResolutionFlags::AllowUnspecifiedTypes;
2805
- options |= TypeResolutionFlags::AllowUnboundGenerics;
2806
2804
2807
2805
// FIXME: initTy should be the same as resultTy; now that typeCheckExpression()
2808
2806
// returns a Type and not bool, we should be able to simplify the listener
@@ -2812,8 +2810,12 @@ bool TypeChecker::typeCheckBinding(Pattern *&pattern, Expr *&initializer,
2812
2810
return true ;
2813
2811
2814
2812
// Apply the solution to the pattern as well.
2815
- if (coercePatternToType (pattern, TypeResolution::forContextual (DC), initTy,
2816
- options, TypeLoc ())) {
2813
+ auto contextualPattern =
2814
+ ContextualPattern::forRawPattern (pattern, DC);
2815
+ if (auto coercedPattern = TypeChecker::coercePatternToType (
2816
+ contextualPattern, initTy, options)) {
2817
+ pattern = coercedPattern;
2818
+ } else {
2817
2819
return true ;
2818
2820
}
2819
2821
}
@@ -3063,13 +3065,11 @@ bool TypeChecker::typeCheckForEachBinding(DeclContext *dc, ForEachStmt *stmt) {
3063
3065
Pattern *pattern = Stmt->getPattern ();
3064
3066
TypeResolutionOptions options (TypeResolverContext::ForEachStmt);
3065
3067
options |= TypeResolutionFlags::OverrideType;
3066
- options |= TypeResolutionFlags::AllowUnboundGenerics;
3067
- options |= TypeResolutionFlags::AllowUnspecifiedTypes;
3068
- if (TypeChecker::coercePatternToType (pattern,
3069
- TypeResolution::forContextual (DC),
3070
- InitType, options)) {
3068
+ auto contextualPattern = ContextualPattern::forRawPattern (pattern, DC);
3069
+ pattern = TypeChecker::coercePatternToType (contextualPattern,
3070
+ InitType, options);
3071
+ if (!pattern)
3071
3072
return nullptr ;
3072
- }
3073
3073
Stmt->setPattern (pattern);
3074
3074
3075
3075
// Get the conformance of the sequence type to the Sequence protocol.
@@ -3189,6 +3189,7 @@ bool TypeChecker::typeCheckStmtCondition(StmtCondition &cond, DeclContext *dc,
3189
3189
hadAnyFalsable = true ;
3190
3190
continue ;
3191
3191
}
3192
+ assert (elt.getKind () != StmtConditionElement::CK_Boolean);
3192
3193
3193
3194
// This is cleanup goop run on the various paths where type checking of the
3194
3195
// pattern binding fails.
0 commit comments