File tree Expand file tree Collapse file tree 2 files changed +34
-0
lines changed
Expand file tree Collapse file tree 2 files changed +34
-0
lines changed Original file line number Diff line number Diff line change @@ -1603,3 +1603,14 @@ IgnoreInvalidFunctionBuilderBody *IgnoreInvalidFunctionBuilderBody::create(
16031603 return new (cs.getAllocator ())
16041604 IgnoreInvalidFunctionBuilderBody (cs, phase, locator);
16051605}
1606+
1607+ bool SpecifyContextualTypeForNil::diagnose (const Solution &solution,
1608+ bool asNote) const {
1609+ return false ;
1610+ }
1611+
1612+ SpecifyContextualTypeForNil *
1613+ SpecifyContextualTypeForNil::create (ConstraintSystem &cs,
1614+ ConstraintLocator *locator) {
1615+ return new (cs.getAllocator ()) SpecifyContextualTypeForNil (cs, locator);
1616+ }
Original file line number Diff line number Diff line change @@ -279,6 +279,9 @@ enum class FixKind : uint8_t {
279279
280280 // / Ignore function builder body which fails `pre-check` call.
281281 IgnoreInvalidFunctionBuilderBody,
282+
283+ // / Resolve type of `nil` by providing a contextual type.
284+ SpecifyContextualTypeForNil,
282285};
283286
284287class ConstraintFix {
@@ -2026,6 +2029,26 @@ class IgnoreInvalidFunctionBuilderBody final : public ConstraintFix {
20262029 create (ConstraintSystem &cs, ErrorInPhase phase, ConstraintLocator *locator);
20272030};
20282031
2032+ class SpecifyContextualTypeForNil final : public ConstraintFix {
2033+ SpecifyContextualTypeForNil (ConstraintSystem &cs,
2034+ ConstraintLocator *locator)
2035+ : ConstraintFix(cs, FixKind::SpecifyContextualTypeForNil, locator) {}
2036+
2037+ public:
2038+ std::string getName () const override {
2039+ return " specify contextual type to resolve `nil` literal" ;
2040+ }
2041+
2042+ bool diagnose (const Solution &solution, bool asNote = false ) const override ;
2043+
2044+ bool diagnoseForAmbiguity (CommonFixesArray commonFixes) const override {
2045+ return diagnose (*commonFixes.front ().first );
2046+ }
2047+
2048+ static SpecifyContextualTypeForNil *create (ConstraintSystem & cs,
2049+ ConstraintLocator * locator);
2050+ };
2051+
20292052} // end namespace constraints
20302053} // end namespace swift
20312054
You can’t perform that action at this time.
0 commit comments