@@ -150,6 +150,18 @@ Type FailureDiagnostic::restoreGenericParameters(
150
150
});
151
151
}
152
152
153
+ bool FailureDiagnostic::conformsToKnownProtocol (
154
+ Type type, KnownProtocolKind protocol) const {
155
+ auto &cs = getConstraintSystem ();
156
+ return constraints::conformsToKnownProtocol (cs, type, protocol);
157
+ }
158
+
159
+ Type FailureDiagnostic::isRawRepresentable (Type type,
160
+ KnownProtocolKind protocol) const {
161
+ auto &cs = getConstraintSystem ();
162
+ return constraints::isRawRepresentable (cs, type, protocol);
163
+ }
164
+
153
165
Type RequirementFailure::getOwnerType () const {
154
166
auto anchor = getRawAnchor ();
155
167
@@ -2406,9 +2418,8 @@ bool ContextualFailure::diagnoseConversionToBool() const {
2406
2418
2407
2419
// If we're trying to convert something from optional type to an integer, then
2408
2420
// a comparison against nil was probably expected.
2409
- auto &cs = getConstraintSystem ();
2410
- if (conformsToKnownProtocol (cs, fromType, KnownProtocolKind::BinaryInteger) &&
2411
- conformsToKnownProtocol (cs, fromType,
2421
+ if (conformsToKnownProtocol (fromType, KnownProtocolKind::BinaryInteger) &&
2422
+ conformsToKnownProtocol (fromType,
2412
2423
KnownProtocolKind::ExpressibleByIntegerLiteral)) {
2413
2424
StringRef prefix = " ((" ;
2414
2425
StringRef suffix;
@@ -2503,7 +2514,6 @@ bool ContextualFailure::diagnoseYieldByReferenceMismatch() const {
2503
2514
bool ContextualFailure::tryRawRepresentableFixIts (
2504
2515
InFlightDiagnostic &diagnostic,
2505
2516
KnownProtocolKind rawRepresentableProtocol) const {
2506
- auto &CS = getConstraintSystem ();
2507
2517
auto anchor = getAnchor ();
2508
2518
auto fromType = getFromType ();
2509
2519
auto toType = getToType ();
@@ -2558,14 +2568,14 @@ bool ContextualFailure::tryRawRepresentableFixIts(
2558
2568
}
2559
2569
};
2560
2570
2561
- if (conformsToKnownProtocol (CS, fromType, rawRepresentableProtocol)) {
2562
- if (conformsToKnownProtocol (CS, fromType, KnownProtocolKind::OptionSet) &&
2571
+ if (conformsToKnownProtocol (fromType, rawRepresentableProtocol)) {
2572
+ if (conformsToKnownProtocol (fromType, KnownProtocolKind::OptionSet) &&
2563
2573
isExpr<IntegerLiteralExpr>(anchor) &&
2564
2574
castToExpr<IntegerLiteralExpr>(anchor)->getDigitsText () == " 0" ) {
2565
2575
diagnostic.fixItReplace (::getSourceRange (anchor), " []" );
2566
2576
return true ;
2567
2577
}
2568
- if (auto rawTy = isRawRepresentable (CS, toType, rawRepresentableProtocol)) {
2578
+ if (auto rawTy = isRawRepresentable (toType, rawRepresentableProtocol)) {
2569
2579
// Produce before/after strings like 'Result(rawValue: RawType(<expr>))'
2570
2580
// or just 'Result(rawValue: <expr>)'.
2571
2581
std::string convWrapBefore = toType.getString ();
@@ -2595,8 +2605,8 @@ bool ContextualFailure::tryRawRepresentableFixIts(
2595
2605
}
2596
2606
}
2597
2607
2598
- if (auto rawTy = isRawRepresentable (CS, fromType, rawRepresentableProtocol)) {
2599
- if (conformsToKnownProtocol (CS, toType, rawRepresentableProtocol)) {
2608
+ if (auto rawTy = isRawRepresentable (fromType, rawRepresentableProtocol)) {
2609
+ if (conformsToKnownProtocol (toType, rawRepresentableProtocol)) {
2600
2610
std::string convWrapBefore;
2601
2611
std::string convWrapAfter = " .rawValue" ;
2602
2612
if (!TypeChecker::isConvertibleTo (rawTy, toType, getDC ())) {
@@ -2877,12 +2887,11 @@ void ContextualFailure::tryComputedPropertyFixIts() const {
2877
2887
}
2878
2888
2879
2889
bool ContextualFailure::isIntegerToStringIndexConversion () const {
2880
- auto &cs = getConstraintSystem ();
2881
2890
auto kind = KnownProtocolKind::ExpressibleByIntegerLiteral;
2882
2891
2883
2892
auto fromType = getFromType ();
2884
2893
auto toType = getToType ()->getCanonicalType ();
2885
- return (conformsToKnownProtocol (cs, fromType, kind) &&
2894
+ return (conformsToKnownProtocol (fromType, kind) &&
2886
2895
toType.getString () == " String.CharacterView.Index" );
2887
2896
}
2888
2897
0 commit comments