@@ -251,6 +251,10 @@ enum class FixKind : uint8_t {
251
251
252
252
// / A warning fix that allows a coercion to perform a force-cast.
253
253
AllowCoercionToForceCast,
254
+
255
+ // / Allow key path root type mismatch when applying a key path with a
256
+ // / root type not convertible to the type of the base instance.
257
+ AllowKeyPathRootTypeMismatch,
254
258
};
255
259
256
260
class ConstraintFix {
@@ -1768,6 +1772,32 @@ class AllowCoercionToForceCast final : public ContextualMismatch {
1768
1772
ConstraintLocator *locator);
1769
1773
};
1770
1774
1775
+ // / Attempt to fix a key path application where the key path type cannot be
1776
+ // / applied to a base instance of another type.
1777
+ // /
1778
+ // / \code
1779
+ // / func f (_ bar: Bar , keyPath: KeyPath<Foo, Int> ) {
1780
+ // / bar[keyPath: keyPath]
1781
+ // / }
1782
+ // / \endcode
1783
+ class AllowKeyPathRootTypeMismatch : public ContextualMismatch {
1784
+ protected:
1785
+ AllowKeyPathRootTypeMismatch (ConstraintSystem &cs, Type lhs, Type rhs,
1786
+ ConstraintLocator *locator)
1787
+ : ContextualMismatch(cs, FixKind::AllowKeyPathRootTypeMismatch, lhs, rhs,
1788
+ locator) {}
1789
+
1790
+ public:
1791
+ std::string getName () const override {
1792
+ return " allow key path root type mismatch" ;
1793
+ }
1794
+
1795
+ bool diagnose (const Solution &solution, bool asNote = false ) const override ;
1796
+
1797
+ static AllowKeyPathRootTypeMismatch *
1798
+ create (ConstraintSystem &cs, Type lhs, Type rhs, ConstraintLocator *locator);
1799
+ };
1800
+
1771
1801
} // end namespace constraints
1772
1802
} // end namespace swift
1773
1803
0 commit comments