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

@@ -7563,6 +7563,13 @@ ERROR(result_builder_buildpartialblock_accumulated_not_accessible,none,
"expression shuffles the elements of this tuple; "
"this behavior is deprecated", ())
//------------------------------------------------------------------------------
// MARK: Implicit conversion diagnostics
//------------------------------------------------------------------------------
ERROR(cannot_implicitly_convert_in_optional_context,none,
"cannot implicitly convert value of type %0 to expected type %1",
(Type, Type))
//------------------------------------------------------------------------------
// MARK: marker protocol diagnostics
//------------------------------------------------------------------------------

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.