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