@@ -2102,6 +2102,30 @@ class UnableToInferKeyPathRootFailure final : public FailureDiagnostic {
2102
2102
bool diagnoseAsError () override ;
2103
2103
};
2104
2104
2105
+ class AbstractRawRepresentableFailure : public FailureDiagnostic {
2106
+ protected:
2107
+ Type RawReprType;
2108
+ Type ValueType;
2109
+
2110
+ AbstractRawRepresentableFailure (const Solution &solution, Type rawReprType,
2111
+ Type valueType, ConstraintLocator *locator)
2112
+ : FailureDiagnostic(solution, locator),
2113
+ RawReprType (resolveType(rawReprType)),
2114
+ ValueType(resolveType(valueType)) {}
2115
+
2116
+ public:
2117
+ virtual Type getFromType () const = 0;
2118
+ virtual Type getToType () const = 0;
2119
+
2120
+ bool diagnoseAsError () override ;
2121
+ bool diagnoseAsNote () override { return false ; }
2122
+
2123
+ protected:
2124
+ Optional<Diag<Type, Type>> getDiagnostic () const ;
2125
+
2126
+ virtual void fixIt (InFlightDiagnostic &diagnostic) const = 0;
2127
+ };
2128
+
2105
2129
// / Diagnose an attempt to initialize raw representable type or convert to it
2106
2130
// / a value of some other type that matches its `RawValue` type.
2107
2131
// /
@@ -2115,23 +2139,22 @@ class UnableToInferKeyPathRootFailure final : public FailureDiagnostic {
2115
2139
// /
2116
2140
// / `0` has to be wrapped into `E(rawValue: 0)` and either defaulted via `??` or
2117
2141
// / force unwrapped to constitute a valid binding.
2118
- class MissingRawRepresentativeInitFailure final : public FailureDiagnostic {
2119
- Type RawReprType;
2120
- Type ValueType;
2121
-
2142
+ class MissingRawRepresentativeInitFailure final
2143
+ : public AbstractRawRepresentableFailure {
2122
2144
public:
2123
2145
MissingRawRepresentativeInitFailure (const Solution &solution,
2124
2146
Type rawReprType, Type valueType,
2125
2147
ConstraintLocator *locator)
2126
- : FailureDiagnostic(solution, locator),
2127
- RawReprType (resolveType(rawReprType)),
2128
- ValueType(resolveType(valueType)) {}
2148
+ : AbstractRawRepresentableFailure(solution, rawReprType, valueType,
2149
+ locator) {}
2150
+
2151
+ Type getFromType () const override { return ValueType; }
2152
+ Type getToType () const override { return RawReprType; }
2129
2153
2130
- bool diagnoseAsError () override ;
2131
2154
bool diagnoseAsNote () override ;
2132
2155
2133
- private :
2134
- void fixIt (InFlightDiagnostic &diagnostic) const ;
2156
+ protected :
2157
+ void fixIt (InFlightDiagnostic &diagnostic) const override ;
2135
2158
};
2136
2159
2137
2160
} // end namespace constraints
0 commit comments