Skip to content

Commit 56cb980

Browse files
authored
Merge pull request #74564 from gottesmm/pr-9be87019f95149167c2e03043b7a86b82f9d282c
Follow up fixes with feedback from #74129
2 parents 0c7621d + 9b0e0f5 commit 56cb980

File tree

5 files changed

+38
-66
lines changed

5 files changed

+38
-66
lines changed

include/swift/Sema/CSFix.h

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "swift/AST/Type.h"
2525
#include "swift/AST/Types.h"
2626
#include "swift/Basic/Debug.h"
27+
#include "swift/Sema/Constraint.h"
2728
#include "swift/Sema/ConstraintLocator.h"
2829
#include "swift/Sema/FixBehavior.h"
2930
#include "llvm/ADT/ArrayRef.h"
@@ -479,8 +480,8 @@ enum class FixKind : uint8_t {
479480
/// parameter.
480481
///
481482
/// 2. Where we have a function that expects a function typed parameter with a
482-
/// sending result, but is passed a function typeed parameter without a
483-
/// sending result.
483+
/// sending result, but is passed a function typed parameter without a sending
484+
/// result.
484485
AllowSendingMismatch,
485486
};
486487

@@ -2636,26 +2637,16 @@ class TreatEphemeralAsNonEphemeral final : public AllowArgumentMismatch {
26362637
/// non-Sendable is safe to transfer onto other situations. The caller though
26372638
/// that this is being sent to does not enforce that invariants within its body.
26382639
class AllowSendingMismatch final : public ContextualMismatch {
2639-
public:
2640-
enum class Kind {
2641-
Parameter,
2642-
Result,
2643-
};
2644-
2645-
private:
2646-
Kind kind;
2647-
26482640
AllowSendingMismatch(ConstraintSystem &cs, Type argType, Type paramType,
2649-
ConstraintLocator *locator, Kind kind,
2650-
FixBehavior fixBehavior)
2641+
ConstraintLocator *locator, FixBehavior fixBehavior)
26512642
: ContextualMismatch(cs, FixKind::AllowSendingMismatch, argType,
2652-
paramType, locator, fixBehavior),
2653-
kind(kind) {}
2643+
paramType, locator, fixBehavior) {}
26542644

26552645
public:
26562646
std::string getName() const override {
2657-
return "treat a function argument with sending parameter as a function "
2658-
"argument without sending parameters";
2647+
return "treat a function argument with sending parameters and results as a "
2648+
"function "
2649+
"argument without sending parameters and results";
26592650
}
26602651

26612652
bool diagnose(const Solution &solution, bool asNote = false) const override;
@@ -2664,9 +2655,8 @@ class AllowSendingMismatch final : public ContextualMismatch {
26642655
return diagnose(*commonFixes.front().first);
26652656
}
26662657

2667-
static AllowSendingMismatch *create(ConstraintSystem &cs,
2668-
ConstraintLocator *locator, Type srcType,
2669-
Type dstType, Kind kind);
2658+
static AllowSendingMismatch *create(ConstraintSystem &cs, Type srcType,
2659+
Type dstType, ConstraintLocator *locator);
26702660

26712661
static bool classof(const ConstraintFix *fix) {
26722662
return fix->getKind() == FixKind::AllowSendingMismatch;

lib/Sema/CSDiagnostics.cpp

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7919,21 +7919,25 @@ bool NonEphemeralConversionFailure::diagnoseAsError() {
79197919
return true;
79207920
}
79217921

7922-
bool SendingOnFunctionParameterMismatchFail::diagnoseAsError() {
7923-
emitDiagnosticAt(getLoc(), diag::sending_function_wrong_sending,
7924-
getFromType(), getToType())
7922+
bool SendingMismatchFailure::diagnoseAsError() {
7923+
if (getLocator()->getLastElementAs<LocatorPathElt::FunctionArgument>())
7924+
return diagnoseArgFailure();
7925+
return diagnoseResultFailure();
7926+
}
7927+
7928+
bool SendingMismatchFailure::diagnoseArgFailure() {
7929+
emitDiagnostic(diag::sending_function_wrong_sending, getFromType(),
7930+
getToType())
79257931
.warnUntilSwiftVersion(6);
7926-
emitDiagnosticAt(getLoc(),
7927-
diag::sending_function_param_with_sending_param_note);
7932+
emitDiagnostic(diag::sending_function_param_with_sending_param_note);
79287933
return true;
79297934
}
79307935

7931-
bool SendingOnFunctionResultMismatchFailure::diagnoseAsError() {
7932-
emitDiagnosticAt(getLoc(), diag::sending_function_wrong_sending,
7933-
getFromType(), getToType())
7936+
bool SendingMismatchFailure::diagnoseResultFailure() {
7937+
emitDiagnostic(diag::sending_function_wrong_sending, getFromType(),
7938+
getToType())
79347939
.warnUntilSwiftVersion(6);
7935-
emitDiagnosticAt(getLoc(),
7936-
diag::sending_function_result_with_sending_param_note);
7940+
emitDiagnostic(diag::sending_function_result_with_sending_param_note);
79377941
return true;
79387942
}
79397943

lib/Sema/CSDiagnostics.h

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2292,26 +2292,17 @@ class NonEphemeralConversionFailure final : public ArgumentMismatchFailure {
22922292
void emitSuggestionNotes() const;
22932293
};
22942294

2295-
class SendingOnFunctionParameterMismatchFail final : public ContextualFailure {
2295+
class SendingMismatchFailure final : public ContextualFailure {
22962296
public:
2297-
SendingOnFunctionParameterMismatchFail(const Solution &solution, Type srcType,
2298-
Type dstType,
2299-
ConstraintLocator *locator,
2300-
FixBehavior fixBehavior)
2297+
SendingMismatchFailure(const Solution &solution, Type srcType, Type dstType,
2298+
ConstraintLocator *locator, FixBehavior fixBehavior)
23012299
: ContextualFailure(solution, srcType, dstType, locator, fixBehavior) {}
23022300

23032301
bool diagnoseAsError() override;
2304-
};
2305-
2306-
class SendingOnFunctionResultMismatchFailure final : public ContextualFailure {
2307-
public:
2308-
SendingOnFunctionResultMismatchFailure(const Solution &solution, Type srcType,
2309-
Type dstType,
2310-
ConstraintLocator *locator,
2311-
FixBehavior fixBehavior)
2312-
: ContextualFailure(solution, srcType, dstType, locator, fixBehavior) {}
23132302

2314-
bool diagnoseAsError() override;
2303+
private:
2304+
bool diagnoseArgFailure();
2305+
bool diagnoseResultFailure();
23152306
};
23162307

23172308
class AssignmentTypeMismatchFailure final : public ContextualFailure {

lib/Sema/CSFix.cpp

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1848,30 +1848,19 @@ std::string TreatEphemeralAsNonEphemeral::getName() const {
18481848

18491849
bool AllowSendingMismatch::diagnose(const Solution &solution,
18501850
bool asNote) const {
1851-
switch (kind) {
1852-
case Kind::Parameter: {
1853-
SendingOnFunctionParameterMismatchFail failure(
1854-
solution, getFromType(), getToType(), getLocator(), fixBehavior);
1855-
return failure.diagnose(asNote);
1856-
}
1857-
case Kind::Result: {
1858-
SendingOnFunctionResultMismatchFailure failure(
1859-
solution, getFromType(), getToType(), getLocator(), fixBehavior);
1860-
return failure.diagnose(asNote);
1861-
}
1862-
}
1863-
llvm_unreachable("Covered switch isn't covered?!");
1851+
SendingMismatchFailure failure(solution, getFromType(), getToType(),
1852+
getLocator(), fixBehavior);
1853+
return failure.diagnose(asNote);
18641854
}
18651855

18661856
AllowSendingMismatch *AllowSendingMismatch::create(ConstraintSystem &cs,
1867-
ConstraintLocator *locator,
18681857
Type srcType, Type dstType,
1869-
Kind kind) {
1858+
ConstraintLocator *locator) {
18701859
auto fixBehavior = cs.getASTContext().LangOpts.isSwiftVersionAtLeast(6)
18711860
? FixBehavior::Error
18721861
: FixBehavior::DowngradeToWarning;
18731862
return new (cs.getAllocator())
1874-
AllowSendingMismatch(cs, srcType, dstType, locator, kind, fixBehavior);
1863+
AllowSendingMismatch(cs, srcType, dstType, locator, fixBehavior);
18751864
}
18761865

18771866
bool SpecifyBaseTypeForContextualMember::diagnose(const Solution &solution,

lib/Sema/CSSimplify.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3239,9 +3239,8 @@ ConstraintSystem::matchFunctionTypes(FunctionType *func1, FunctionType *func2,
32393239
// () -> sending T can be a subtype of () -> T... but not vis-a-versa.
32403240
if (func1->hasSendingResult() != func2->hasSendingResult() &&
32413241
(!func1->hasSendingResult() || kind < ConstraintKind::Subtype)) {
3242-
auto *fix = AllowSendingMismatch::create(
3243-
*this, getConstraintLocator(locator), func1, func2,
3244-
AllowSendingMismatch::Kind::Result);
3242+
auto *fix = AllowSendingMismatch::create(*this, func1, func2,
3243+
getConstraintLocator(locator));
32453244
if (recordFix(fix))
32463245
return getTypeMatchFailure(locator);
32473246
}
@@ -3681,8 +3680,7 @@ ConstraintSystem::matchFunctionTypes(FunctionType *func1, FunctionType *func2,
36813680
if (func1Param.getParameterFlags().isSending() &&
36823681
!func2Param.getParameterFlags().isSending()) {
36833682
auto *fix = AllowSendingMismatch::create(
3684-
*this, getConstraintLocator(argumentLocator), func1, func2,
3685-
AllowSendingMismatch::Kind::Parameter);
3683+
*this, func1, func2, getConstraintLocator(argumentLocator));
36863684
if (recordFix(fix))
36873685
return getTypeMatchFailure(argumentLocator);
36883686
}

0 commit comments

Comments
 (0)