Skip to content

Commit 3fac0fe

Browse files
committed
[CSFix] Add a skeleton of weak pattern with non-optional type fix
1 parent 54a7577 commit 3fac0fe

File tree

3 files changed

+31
-2
lines changed

3 files changed

+31
-2
lines changed

include/swift/Sema/CSFix.h

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,10 @@ enum class FixKind : uint8_t {
331331

332332
/// Specify a type for an explicitly written placeholder that could not be
333333
/// resolved.
334-
SpecifyTypeForPlaceholder
334+
SpecifyTypeForPlaceholder,
335+
336+
/// Allow `weak` declarations to be bound to a non-optional type.
337+
AllowNonOptionalWeak,
335338
};
336339

337340
class ConstraintFix {
@@ -2424,6 +2427,21 @@ class AllowInvalidStaticMemberRefOnProtocolMetatype final
24242427
create(ConstraintSystem &cs, ConstraintLocator *locator);
24252428
};
24262429

2430+
class AllowNonOptionalWeak final : public ConstraintFix {
2431+
AllowNonOptionalWeak(ConstraintSystem &cs, ConstraintLocator *locator)
2432+
: ConstraintFix(cs, FixKind::AllowNonOptionalWeak, locator) {}
2433+
2434+
public:
2435+
std::string getName() const override {
2436+
return "allow `weak` with non-optional type";
2437+
}
2438+
2439+
bool diagnose(const Solution &solution, bool asNote = false) const override;
2440+
2441+
static AllowNonOptionalWeak *create(ConstraintSystem &cs,
2442+
ConstraintLocator *locator);
2443+
};
2444+
24272445
} // end namespace constraints
24282446
} // end namespace swift
24292447

lib/Sema/CSFix.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1989,3 +1989,13 @@ AllowInvalidStaticMemberRefOnProtocolMetatype::create(
19891989
return new (cs.getAllocator())
19901990
AllowInvalidStaticMemberRefOnProtocolMetatype(cs, locator);
19911991
}
1992+
1993+
bool AllowNonOptionalWeak::diagnose(const Solution &solution,
1994+
bool asNote) const {
1995+
return false;
1996+
}
1997+
1998+
AllowNonOptionalWeak *AllowNonOptionalWeak::create(ConstraintSystem &cs,
1999+
ConstraintLocator *locator) {
2000+
return new (cs.getAllocator()) AllowNonOptionalWeak(cs, locator);
2001+
}

lib/Sema/CSSimplify.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11544,7 +11544,8 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyFixConstraint(
1154411544
case FixKind::AllowInvalidStaticMemberRefOnProtocolMetatype:
1154511545
case FixKind::AllowWrappedValueMismatch:
1154611546
case FixKind::RemoveExtraneousArguments:
11547-
case FixKind::SpecifyTypeForPlaceholder: {
11547+
case FixKind::SpecifyTypeForPlaceholder:
11548+
case FixKind::AllowNonOptionalWeak: {
1154811549
return recordFix(fix) ? SolutionKind::Error : SolutionKind::Solved;
1154911550
}
1155011551

0 commit comments

Comments
 (0)