@@ -2569,84 +2569,13 @@ bool ContextualFailure::tryRawRepresentableFixIts(
2569
2569
} else if (!fromTypeIsOptional) {
2570
2570
diagnostic.fixItInsert (exprRange.Start , convWrapBefore);
2571
2571
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);
2589
2572
}
2590
2573
};
2591
2574
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
-
2629
2575
if (auto rawTy = isRawRepresentable (fromType, rawRepresentableProtocol)) {
2630
2576
if (conformsToKnownProtocol (toType, rawRepresentableProtocol)) {
2631
2577
std::string convWrapBefore;
2632
2578
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
-
2650
2579
if (auto *E = getAsExpr (anchor))
2651
2580
fixIt (convWrapBefore, convWrapAfter, E);
2652
2581
return true ;
0 commit comments