@@ -2717,42 +2717,47 @@ ConstraintSystem::matchFunctionTypes(FunctionType *func1, FunctionType *func2,
2717
2717
}
2718
2718
2719
2719
/// The behavior limit to apply to a concurrency check.
2720
- auto getConcurrencyFixBehavior = [&](bool forSendable) {
2721
- // We can only handle the downgrade for conversions.
2722
- switch (kind) {
2723
- case ConstraintKind::Conversion:
2724
- case ConstraintKind::ArgumentConversion:
2725
- break;
2720
+ auto getConcurrencyFixBehavior = [&](
2721
+ bool forSendable
2722
+ ) -> Optional<FixBehavior> {
2723
+ // We can only handle the downgrade for conversions.
2724
+ switch (kind) {
2725
+ case ConstraintKind::Conversion:
2726
+ case ConstraintKind::ArgumentConversion:
2727
+ break;
2726
2728
2727
- default:
2728
- return FixBehavior::Error;
2729
- }
2729
+ default:
2730
+ if (!shouldAttemptFixes())
2731
+ return None;
2732
+
2733
+ return FixBehavior::Error;
2734
+ }
2730
2735
2731
- // For a @preconcurrency callee outside of a strict concurrency context,
2732
- // ignore.
2733
- if (hasPreconcurrencyCallee(this, locator) &&
2734
- !contextRequiresStrictConcurrencyChecking(DC, GetClosureType{*this}))
2735
- return FixBehavior::Suppress;
2736
+ // For a @preconcurrency callee outside of a strict concurrency
2737
+ // context, ignore.
2738
+ if (hasPreconcurrencyCallee(this, locator) &&
2739
+ !contextRequiresStrictConcurrencyChecking(DC, GetClosureType{*this}))
2740
+ return FixBehavior::Suppress;
2736
2741
2737
- // Otherwise, warn until Swift 6.
2738
- if (!getASTContext().LangOpts.isSwiftVersionAtLeast(6))
2739
- return FixBehavior::DowngradeToWarning;
2742
+ // Otherwise, warn until Swift 6.
2743
+ if (!getASTContext().LangOpts.isSwiftVersionAtLeast(6))
2744
+ return FixBehavior::DowngradeToWarning;
2740
2745
2741
- return FixBehavior::Error;
2746
+ return FixBehavior::Error;
2742
2747
};
2743
2748
2744
2749
// A @Sendable function can be a subtype of a non-@Sendable function.
2745
2750
if (func1->isSendable() != func2->isSendable()) {
2746
2751
// Cannot add '@Sendable'.
2747
2752
if (func2->isSendable() || kind < ConstraintKind::Subtype) {
2748
- if (!shouldAttemptFixes())
2749
- return getTypeMatchFailure(locator);
2750
-
2751
- auto *fix = AddSendableAttribute::create(
2752
- *this, func1, func2, getConstraintLocator(locator),
2753
- getConcurrencyFixBehavior(true));
2754
- if (recordFix(fix))
2753
+ if (auto fixBehavior = getConcurrencyFixBehavior(true)) {
2754
+ auto *fix = AddSendableAttribute::create(
2755
+ *this, func1, func2, getConstraintLocator(locator), *fixBehavior);
2756
+ if (recordFix(fix))
2757
+ return getTypeMatchFailure(locator);
2758
+ } else {
2755
2759
return getTypeMatchFailure(locator);
2760
+ }
2756
2761
}
2757
2762
}
2758
2763
@@ -2780,15 +2785,16 @@ ConstraintSystem::matchFunctionTypes(FunctionType *func1, FunctionType *func2,
2780
2785
return getTypeMatchFailure(locator);
2781
2786
} else if (func1->getGlobalActor() && !func2->isAsync()) {
2782
2787
// Cannot remove a global actor from a synchronous function.
2783
- if (!shouldAttemptFixes())
2784
- return getTypeMatchFailure(locator);
2788
+ if (auto fixBehavior = getConcurrencyFixBehavior(false)) {
2789
+ auto *fix = MarkGlobalActorFunction::create(
2790
+ *this, func1, func2, getConstraintLocator(locator),
2791
+ *fixBehavior);
2785
2792
2786
- auto *fix = MarkGlobalActorFunction::create(
2787
- *this, func1, func2, getConstraintLocator(locator),
2788
- getConcurrencyFixBehavior(false));
2789
-
2790
- if (recordFix(fix))
2793
+ if (recordFix(fix))
2794
+ return getTypeMatchFailure(locator);
2795
+ } else {
2791
2796
return getTypeMatchFailure(locator);
2797
+ }
2792
2798
} else if (kind < ConstraintKind::Subtype) {
2793
2799
return getTypeMatchFailure(locator);
2794
2800
}
0 commit comments