Skip to content

Commit 057563e

Browse files
committed
[CSFix] Add a specific kind for AddSendableAttribute
1 parent 1039b76 commit 057563e

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

include/swift/Sema/CSFix.h

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,10 @@ enum class FixKind : uint8_t {
335335

336336
/// Allow `weak` declarations to be bound to a non-optional type.
337337
AllowNonOptionalWeak,
338+
339+
/// Fix conversion from non-Sendable to Sendable by adding explicit
340+
/// @Sendable attribute to the source function.
341+
AddSendableAttribute,
338342
};
339343

340344
class ConstraintFix {
@@ -735,8 +739,9 @@ class ForceOptional final : public ContextualMismatch {
735739
/// function types, repair it by adding @Sendable attribute.
736740
class AddSendableAttribute final : public ContextualMismatch {
737741
AddSendableAttribute(ConstraintSystem &cs, FunctionType *fromType,
738-
FunctionType *toType, ConstraintLocator *locator)
739-
: ContextualMismatch(cs, fromType, toType, locator) {
742+
FunctionType *toType, ConstraintLocator *locator)
743+
: ContextualMismatch(cs, FixKind::AddSendableAttribute, fromType, toType,
744+
locator) {
740745
assert(fromType->isSendable() != toType->isSendable());
741746
}
742747

@@ -746,9 +751,13 @@ class AddSendableAttribute final : public ContextualMismatch {
746751
bool diagnose(const Solution &solution, bool asNote = false) const override;
747752

748753
static AddSendableAttribute *create(ConstraintSystem &cs,
749-
FunctionType *fromType,
750-
FunctionType *toType,
751-
ConstraintLocator *locator);
754+
FunctionType *fromType,
755+
FunctionType *toType,
756+
ConstraintLocator *locator);
757+
758+
static bool classof(ConstraintFix *fix) {
759+
return fix->getKind() == FixKind::AddSendableAttribute;
760+
}
752761
};
753762

754763
/// This is a contextual mismatch between throwing and non-throwing

lib/Sema/CSSimplify.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11764,6 +11764,7 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyFixConstraint(
1176411764
case FixKind::SpecifyClosureParameterType:
1176511765
case FixKind::SpecifyClosureReturnType:
1176611766
case FixKind::AddQualifierToAccessTopLevelName:
11767+
case FixKind::AddSendableAttribute:
1176711768
llvm_unreachable("handled elsewhere");
1176811769
}
1176911770

0 commit comments

Comments
 (0)