Skip to content

Commit 03938f9

Browse files
committed
[Diagnostics] NFC: Remove obsolete logic from ContextualFailure::tryRawRepresentableFixIts
1 parent f048652 commit 03938f9

File tree

1 file changed

+0
-71
lines changed

1 file changed

+0
-71
lines changed

lib/Sema/CSDiagnostics.cpp

Lines changed: 0 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -2569,84 +2569,13 @@ bool ContextualFailure::tryRawRepresentableFixIts(
25692569
} else if (!fromTypeIsOptional) {
25702570
diagnostic.fixItInsert(exprRange.Start, convWrapBefore);
25712571
diagnostic.fixItInsertAfter(exprRange.End, convWrapAfter);
2572-
} else {
2573-
SmallString<16> fixItBefore(convWrapBefore);
2574-
SmallString<16> fixItAfter;
2575-
2576-
if (!expr->canAppendPostfixExpression(true)) {
2577-
fixItBefore += "(";
2578-
fixItAfter = ")";
2579-
}
2580-
2581-
fixItAfter += "!" + convWrapAfter.str();
2582-
2583-
diagnostic.flush();
2584-
emitDiagnostic(diag::construct_raw_representable_from_unwrapped_value,
2585-
toType, fromType)
2586-
.highlight(exprRange)
2587-
.fixItInsert(exprRange.Start, fixItBefore)
2588-
.fixItInsertAfter(exprRange.End, fixItAfter);
25892572
}
25902573
};
25912574

2592-
if (conformsToKnownProtocol(fromType, rawRepresentableProtocol)) {
2593-
if (conformsToKnownProtocol(fromType, KnownProtocolKind::OptionSet) &&
2594-
isExpr<IntegerLiteralExpr>(anchor) &&
2595-
castToExpr<IntegerLiteralExpr>(anchor)->getDigitsText() == "0") {
2596-
diagnostic.fixItReplace(::getSourceRange(anchor), "[]");
2597-
return true;
2598-
}
2599-
if (auto rawTy = isRawRepresentable(toType, rawRepresentableProtocol)) {
2600-
// Produce before/after strings like 'Result(rawValue: RawType(<expr>))'
2601-
// or just 'Result(rawValue: <expr>)'.
2602-
std::string convWrapBefore = toType.getString();
2603-
convWrapBefore += "(rawValue: ";
2604-
std::string convWrapAfter = ")";
2605-
if (!isExpr<LiteralExpr>(anchor) &&
2606-
!TypeChecker::isConvertibleTo(fromType, rawTy, getDC())) {
2607-
// Only try to insert a converting construction if the protocol is a
2608-
// literal protocol and not some other known protocol.
2609-
switch (rawRepresentableProtocol) {
2610-
#define EXPRESSIBLE_BY_LITERAL_PROTOCOL_WITH_NAME(name, _, __, ___) \
2611-
case KnownProtocolKind::name: \
2612-
break;
2613-
#define PROTOCOL_WITH_NAME(name, _) \
2614-
case KnownProtocolKind::name: \
2615-
return false;
2616-
#include "swift/AST/KnownProtocols.def"
2617-
}
2618-
convWrapBefore += rawTy->getString();
2619-
convWrapBefore += "(";
2620-
convWrapAfter += ")";
2621-
}
2622-
2623-
if (auto *E = getAsExpr(anchor))
2624-
fixIt(convWrapBefore, convWrapAfter, E);
2625-
return true;
2626-
}
2627-
}
2628-
26292575
if (auto rawTy = isRawRepresentable(fromType, rawRepresentableProtocol)) {
26302576
if (conformsToKnownProtocol(toType, rawRepresentableProtocol)) {
26312577
std::string convWrapBefore;
26322578
std::string convWrapAfter = ".rawValue";
2633-
if (!TypeChecker::isConvertibleTo(rawTy, toType, getDC())) {
2634-
// Only try to insert a converting construction if the protocol is a
2635-
// literal protocol and not some other known protocol.
2636-
switch (rawRepresentableProtocol) {
2637-
#define EXPRESSIBLE_BY_LITERAL_PROTOCOL_WITH_NAME(name, _, __, ___) \
2638-
case KnownProtocolKind::name: \
2639-
break;
2640-
#define PROTOCOL_WITH_NAME(name, _) \
2641-
case KnownProtocolKind::name: \
2642-
return false;
2643-
#include "swift/AST/KnownProtocols.def"
2644-
}
2645-
convWrapBefore += toType->getString();
2646-
convWrapBefore += "(";
2647-
convWrapAfter += ")";
2648-
}
2649-
26502579
if (auto *E = getAsExpr(anchor))
26512580
fixIt(convWrapBefore, convWrapAfter, E);
26522581
return true;

0 commit comments

Comments
 (0)