Skip to content

Commit d1d2846

Browse files
committed
[CSFix] Add a specific kind for DropThrowsAttribute
1 parent 057563e commit d1d2846

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

include/swift/Sema/CSFix.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,10 @@ enum class FixKind : uint8_t {
339339
/// Fix conversion from non-Sendable to Sendable by adding explicit
340340
/// @Sendable attribute to the source function.
341341
AddSendableAttribute,
342+
343+
/// Fix conversion from throwing to non-throwing by removing explicit
344+
/// `throws` attribute from the source function.
345+
DropThrowsAttribute,
342346
};
343347

344348
class ConstraintFix {
@@ -765,7 +769,8 @@ class AddSendableAttribute final : public ContextualMismatch {
765769
class DropThrowsAttribute final : public ContextualMismatch {
766770
DropThrowsAttribute(ConstraintSystem &cs, FunctionType *fromType,
767771
FunctionType *toType, ConstraintLocator *locator)
768-
: ContextualMismatch(cs, fromType, toType, locator) {
772+
: ContextualMismatch(cs, FixKind::DropThrowsAttribute, fromType, toType,
773+
locator) {
769774
assert(fromType->isThrowing() != toType->isThrowing());
770775
}
771776

@@ -778,6 +783,10 @@ class DropThrowsAttribute final : public ContextualMismatch {
778783
FunctionType *fromType,
779784
FunctionType *toType,
780785
ConstraintLocator *locator);
786+
787+
static bool classof(ConstraintFix *fix) {
788+
return fix->getKind() == FixKind::DropThrowsAttribute;
789+
}
781790
};
782791

783792
/// This is a contextual mismatch between async and non-async

lib/Sema/CSSimplify.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11765,6 +11765,7 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyFixConstraint(
1176511765
case FixKind::SpecifyClosureReturnType:
1176611766
case FixKind::AddQualifierToAccessTopLevelName:
1176711767
case FixKind::AddSendableAttribute:
11768+
case FixKind::DropThrowsAttribute:
1176811769
llvm_unreachable("handled elsewhere");
1176911770
}
1177011771

0 commit comments

Comments
 (0)