Skip to content

Commit 05798e5

Browse files
committed
Revert "Sema: Remove dead diagnostic"
This reverts commit d56d704.
1 parent 35077a0 commit 05798e5

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7563,6 +7563,13 @@ ERROR(result_builder_buildpartialblock_accumulated_not_accessible,none,
75637563
"expression shuffles the elements of this tuple; "
75647564
"this behavior is deprecated", ())
75657565

7566+
//------------------------------------------------------------------------------
7567+
// MARK: Implicit conversion diagnostics
7568+
//------------------------------------------------------------------------------
7569+
ERROR(cannot_implicitly_convert_in_optional_context,none,
7570+
"cannot implicitly convert value of type %0 to expected type %1",
7571+
(Type, Type))
7572+
75667573
//------------------------------------------------------------------------------
75677574
// MARK: marker protocol diagnostics
75687575
//------------------------------------------------------------------------------

lib/Sema/CSDiagnostics.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2852,6 +2852,22 @@ bool ContextualFailure::diagnoseAsError() {
28522852
break;
28532853
}
28542854

2855+
case ConstraintLocator::OptionalInjection: {
2856+
// If this is an attempt at a Double <-> CGFloat conversion
2857+
// through optional chaining, let's produce a tailored diagnostic.
2858+
if (isExpr<OptionalEvaluationExpr>(getAnchor())) {
2859+
if ((fromType->isDouble() || fromType->isCGFloat()) &&
2860+
(toType->isDouble() || toType->isCGFloat())) {
2861+
fromType = OptionalType::get(fromType);
2862+
toType = OptionalType::get(toType);
2863+
diagnostic = diag::cannot_implicitly_convert_in_optional_context;
2864+
break;
2865+
}
2866+
}
2867+
2868+
return false;
2869+
}
2870+
28552871
case ConstraintLocator::EnumPatternImplicitCastMatch: {
28562872
// In this case, the types are reversed, as we are checking whether we
28572873
// can convert the pattern type to the context type.

0 commit comments

Comments
 (0)