Revert "Sema: Remove dead diagnostic"

This reverts commit d56d7045a2.
This commit is contained in:
Pavel Yaskevich
2025-03-31 14:34:20 -07:00
parent 35077a01d1
commit 05798e5f45
2 changed files with 23 additions and 0 deletions

View File

@@ -2852,6 +2852,22 @@ bool ContextualFailure::diagnoseAsError() {
break;
}
case ConstraintLocator::OptionalInjection: {
// If this is an attempt at a Double <-> CGFloat conversion
// through optional chaining, let's produce a tailored diagnostic.
if (isExpr<OptionalEvaluationExpr>(getAnchor())) {
if ((fromType->isDouble() || fromType->isCGFloat()) &&
(toType->isDouble() || toType->isCGFloat())) {
fromType = OptionalType::get(fromType);
toType = OptionalType::get(toType);
diagnostic = diag::cannot_implicitly_convert_in_optional_context;
break;
}
}
return false;
}
case ConstraintLocator::EnumPatternImplicitCastMatch: {
// In this case, the types are reversed, as we are checking whether we
// can convert the pattern type to the context type.