diff --git a/lib/Sema/CSFix.cpp b/lib/Sema/CSFix.cpp index 46eb921a3a984..9491907ad3a1b 100644 --- a/lib/Sema/CSFix.cpp +++ b/lib/Sema/CSFix.cpp @@ -881,6 +881,13 @@ bool RemoveUnnecessaryCoercion::attempt(ConstraintSystem &cs, Type fromType, if (!isa(toTypeRepr) && (isa(expr->getSubExpr()) || isa(expr->getSubExpr()))) { + + // If coerced type is not known upfront let's not warn + // because the type could be inferred from coercion. + auto coercedType = cs.getType(expr->getSubExpr()); + if (coercedType->is()) + return false; + auto *fix = new (cs.getAllocator()) RemoveUnnecessaryCoercion( cs, fromType, toType, cs.getConstraintLocator(locator));