@@ -2713,134 +2713,6 @@ diagnoseSingleCandidateFailures(CalleeCandidateInfo &CCI, Expr *fnExpr,
2713
2713
.diagnose ();
2714
2714
}
2715
2715
2716
- namespace {
2717
- enum class RawRepresentableMismatch {
2718
- NotApplicable,
2719
- Convertible,
2720
- ExactMatch
2721
- };
2722
- }
2723
-
2724
- static RawRepresentableMismatch
2725
- checkRawRepresentableMismatch (Type fromType, Type toType,
2726
- KnownProtocolKind kind,
2727
- ConstraintSystem &CS) {
2728
- toType = toType->lookThroughAllOptionalTypes ();
2729
- fromType = fromType->lookThroughAllOptionalTypes ();
2730
-
2731
- // First check if this is an attempt to convert from something to
2732
- // raw representable.
2733
- if (conformsToKnownProtocol (CS, fromType, kind)) {
2734
- if (auto rawType = isRawRepresentable (CS, toType, kind)) {
2735
- if (rawType->isEqual (fromType))
2736
- return RawRepresentableMismatch::ExactMatch;
2737
- return RawRepresentableMismatch::Convertible;
2738
- }
2739
- }
2740
-
2741
- // Otherwise, it might be an attempt to convert from raw representable
2742
- // to its raw value.
2743
- if (auto rawType = isRawRepresentable (CS, fromType, kind)) {
2744
- if (conformsToKnownProtocol (CS, toType, kind)) {
2745
- if (rawType->isEqual (toType))
2746
- return RawRepresentableMismatch::ExactMatch;
2747
- return RawRepresentableMismatch::Convertible;
2748
- }
2749
- }
2750
-
2751
- return RawRepresentableMismatch::NotApplicable;
2752
- }
2753
-
2754
- static bool diagnoseRawRepresentableMismatch (CalleeCandidateInfo &CCI,
2755
- Expr *argExpr,
2756
- ArrayRef<Identifier> argLabels) {
2757
- // We are only interested in cases which are
2758
- // unrelated to argument count or label mismatches.
2759
- switch (CCI.closeness ) {
2760
- case CC_OneArgumentNearMismatch:
2761
- case CC_OneArgumentMismatch:
2762
- case CC_OneGenericArgumentNearMismatch:
2763
- case CC_OneGenericArgumentMismatch:
2764
- case CC_ArgumentNearMismatch:
2765
- case CC_ArgumentMismatch:
2766
- break ;
2767
-
2768
- default :
2769
- return false ;
2770
- }
2771
-
2772
- auto argType = CCI.CS .getType (argExpr);
2773
- if (!argType || argType->hasTypeVariable () || argType->hasUnresolvedType ())
2774
- return false ;
2775
-
2776
- KnownProtocolKind rawRepresentableProtocols[] = {
2777
- KnownProtocolKind::ExpressibleByStringLiteral,
2778
- KnownProtocolKind::ExpressibleByIntegerLiteral};
2779
-
2780
- auto &CS = CCI.CS ;
2781
- auto arguments = decomposeArgType (argType, argLabels);
2782
-
2783
- auto bestMatchKind = RawRepresentableMismatch::NotApplicable;
2784
- const OverloadCandidate *bestMatchCandidate = nullptr ;
2785
- KnownProtocolKind bestMatchProtocol;
2786
- size_t bestMatchIndex;
2787
-
2788
- for (auto &candidate : CCI.candidates ) {
2789
- auto *decl = candidate.getDecl ();
2790
- if (!decl)
2791
- continue ;
2792
-
2793
- if (!candidate.hasParameters ())
2794
- continue ;
2795
-
2796
- auto parameters = candidate.getParameters ();
2797
- // FIXME: Default arguments?
2798
- if (parameters.size () != arguments.size ())
2799
- continue ;
2800
-
2801
- for (unsigned i = 0 , n = parameters.size (); i != n; ++i) {
2802
- auto paramType = parameters[i].getOldType ();
2803
- auto argType = arguments[i].getOldType ();
2804
-
2805
- for (auto kind : rawRepresentableProtocols) {
2806
- // If trying to convert from raw type to raw representable,
2807
- // or vice versa from raw representable (e.g. enum) to raw type.
2808
- auto matchKind = checkRawRepresentableMismatch (argType, paramType, kind,
2809
- CS);
2810
- if (matchKind > bestMatchKind) {
2811
- bestMatchKind = matchKind;
2812
- bestMatchProtocol = kind;
2813
- bestMatchCandidate = &candidate;
2814
- bestMatchIndex = i;
2815
- }
2816
- }
2817
- }
2818
- }
2819
-
2820
- if (bestMatchKind == RawRepresentableMismatch::NotApplicable)
2821
- return false ;
2822
-
2823
- Expr *expr = argExpr;
2824
- if (auto *tupleArgs = dyn_cast<TupleExpr>(argExpr))
2825
- expr = tupleArgs->getElement (bestMatchIndex);
2826
-
2827
- expr = expr->getValueProvidingExpr ();
2828
-
2829
- auto parameters = bestMatchCandidate->getParameters ();
2830
- auto paramType = parameters[bestMatchIndex].getOldType ();
2831
- auto singleArgType = arguments[bestMatchIndex].getOldType ();
2832
-
2833
- auto diag = CS.TC .diagnose (expr->getLoc (),
2834
- diag::cannot_convert_argument_value,
2835
- singleArgType, paramType);
2836
-
2837
- ContextualFailure failure (expr, CS, singleArgType, paramType,
2838
- CS.getConstraintLocator (expr));
2839
-
2840
- (void )failure.tryRawRepresentableFixIts (diag, bestMatchProtocol);
2841
- return true ;
2842
- }
2843
-
2844
2716
// Extract expression for failed argument number
2845
2717
static Expr *getFailedArgumentExpr (CalleeCandidateInfo CCI, Expr *argExpr) {
2846
2718
if (auto *TE = dyn_cast<TupleExpr>(argExpr))
@@ -4117,9 +3989,6 @@ bool FailureDiagnosis::visitApplyExpr(ApplyExpr *callExpr) {
4117
3989
if (isContextualConversionFailure (argTuple))
4118
3990
return false ;
4119
3991
4120
- if (diagnoseRawRepresentableMismatch (calleeInfo, argExpr, argLabels))
4121
- return true ;
4122
-
4123
3992
if (!lhsType->isEqual (rhsType)) {
4124
3993
auto diag = diagnose (callExpr->getLoc (), diag::cannot_apply_binop_to_args,
4125
3994
overloadName, lhsType, rhsType);
@@ -4219,9 +4088,6 @@ bool FailureDiagnosis::visitApplyExpr(ApplyExpr *callExpr) {
4219
4088
if (CS.getType (argExpr)->hasUnresolvedType ())
4220
4089
return false ;
4221
4090
4222
- if (diagnoseRawRepresentableMismatch (calleeInfo, argExpr, argLabels))
4223
- return true ;
4224
-
4225
4091
SmallVector<AnyFunctionType::Param, 8 > params;
4226
4092
AnyFunctionType::decomposeInput (CS.getType (argExpr), params);
4227
4093
auto argString = AnyFunctionType::getParamListAsString (params);
0 commit comments