Skip to content

Commit 2fd6863

Browse files
committed
[CS] Remove AutoClosureForwarding fix
The fix is currently unused, and the FailureDiagnostic can be inlined into MissingCallFailure.
1 parent 86e8165 commit 2fd6863

File tree

5 files changed

+4
-72
lines changed

5 files changed

+4
-72
lines changed

include/swift/Sema/CSFix.h

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -109,12 +109,6 @@ enum class FixKind : uint8_t {
109109
/// Fix up the generic arguments of two types so they match each other.
110110
GenericArgumentsMismatch,
111111

112-
/// Fix up @autoclosure argument to the @autoclosure parameter,
113-
/// to for a call to be able to forward it properly, since
114-
/// @autoclosure conversions are unsupported starting from
115-
/// Swift version 5.
116-
AutoClosureForwarding,
117-
118112
/// Remove `!` or `?` because base is not an optional type.
119113
RemoveUnwrap,
120114

@@ -1219,33 +1213,6 @@ class GenericArgumentsMismatch final
12191213
}
12201214
};
12211215

1222-
/// Detect situations when argument of the @autoclosure parameter is itself
1223-
/// marked as @autoclosure and is not applied. Form a fix which suggests a
1224-
/// proper way to forward such arguments, e.g.:
1225-
///
1226-
/// ```swift
1227-
/// func foo(_ fn: @autoclosure () -> Int) {}
1228-
/// func bar(_ fn: @autoclosure () -> Int) {
1229-
/// foo(fn) // error - fn should be called
1230-
/// }
1231-
/// ```
1232-
class AutoClosureForwarding final : public ConstraintFix {
1233-
AutoClosureForwarding(ConstraintSystem &cs, ConstraintLocator *locator)
1234-
: ConstraintFix(cs, FixKind::AutoClosureForwarding, locator) {}
1235-
1236-
public:
1237-
std::string getName() const override { return "fix @autoclosure forwarding"; }
1238-
1239-
bool diagnose(const Solution &solution, bool asNote = false) const override;
1240-
1241-
static AutoClosureForwarding *create(ConstraintSystem &cs,
1242-
ConstraintLocator *locator);
1243-
1244-
static bool classof(const ConstraintFix *fix) {
1245-
return fix->getKind() == FixKind::AutoClosureForwarding;
1246-
}
1247-
};
1248-
12491216
class AllowAutoClosurePointerConversion final : public ContextualMismatch {
12501217
AllowAutoClosurePointerConversion(ConstraintSystem &cs, Type pointeeType,
12511218
Type pointerType,

lib/Sema/CSDiagnostics.cpp

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3832,14 +3832,6 @@ bool FunctionTypeMismatch::diagnoseAsError() {
38323832
return true;
38333833
}
38343834

3835-
bool AutoClosureForwardingFailure::diagnoseAsError() {
3836-
auto argRange = getSourceRange();
3837-
emitDiagnostic(diag::invalid_autoclosure_forwarding)
3838-
.highlight(argRange)
3839-
.fixItInsertAfter(argRange.End, "()");
3840-
return true;
3841-
}
3842-
38433835
bool AutoClosurePointerConversionFailure::diagnoseAsError() {
38443836
auto diagnostic = diag::invalid_autoclosure_pointer_conversion;
38453837
emitDiagnostic(diagnostic, getFromType(), getToType())
@@ -3904,9 +3896,10 @@ bool MissingCallFailure::diagnoseAsError() {
39043896
}
39053897

39063898
case ConstraintLocator::AutoclosureResult: {
3907-
auto loc = getConstraintLocator(getRawAnchor(), path.drop_back());
3908-
AutoClosureForwardingFailure failure(getSolution(), loc);
3909-
return failure.diagnoseAsError();
3899+
emitDiagnostic(diag::invalid_autoclosure_forwarding)
3900+
.highlight(getSourceRange())
3901+
.fixItInsertAfter(insertLoc, "()");
3902+
return true;
39103903
}
39113904
default:
39123905
break;

lib/Sema/CSDiagnostics.h

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1078,17 +1078,6 @@ class FunctionTypeMismatch final : public ContextualFailure {
10781078
bool diagnoseAsError() override;
10791079
};
10801080

1081-
/// Diagnose situations when @autoclosure argument is passed to @autoclosure
1082-
/// parameter directly without calling it first.
1083-
class AutoClosureForwardingFailure final : public FailureDiagnostic {
1084-
public:
1085-
AutoClosureForwardingFailure(const Solution &solution,
1086-
ConstraintLocator *locator)
1087-
: FailureDiagnostic(solution, locator) {}
1088-
1089-
bool diagnoseAsError() override;
1090-
};
1091-
10921081
/// Diagnose invalid pointer conversions for an autoclosure result type.
10931082
///
10941083
/// \code

lib/Sema/CSFix.cpp

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -802,17 +802,6 @@ GenericArgumentsMismatch *GenericArgumentsMismatch::create(
802802
GenericArgumentsMismatch(cs, actual, required, mismatches, locator);
803803
}
804804

805-
bool AutoClosureForwarding::diagnose(const Solution &solution,
806-
bool asNote) const {
807-
AutoClosureForwardingFailure failure(solution, getLocator());
808-
return failure.diagnose(asNote);
809-
}
810-
811-
AutoClosureForwarding *AutoClosureForwarding::create(ConstraintSystem &cs,
812-
ConstraintLocator *locator) {
813-
return new (cs.getAllocator()) AutoClosureForwarding(cs, locator);
814-
}
815-
816805
bool AllowAutoClosurePointerConversion::diagnose(const Solution &solution,
817806
bool asNote) const {
818807
AutoClosurePointerConversionFailure failure(solution, getFromType(),

lib/Sema/CSSimplify.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15254,12 +15254,6 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyFixConstraint(
1525415254
return result;
1525515255
}
1525615256

15257-
case FixKind::AutoClosureForwarding: {
15258-
if (recordFix(fix))
15259-
return SolutionKind::Error;
15260-
return matchTypes(type1, type2, matchKind, subflags, locator);
15261-
}
15262-
1526315257
case FixKind::AllowTupleTypeMismatch: {
1526415258
if (fix->getAs<AllowTupleTypeMismatch>()->isElementMismatch()) {
1526515259
auto *locator = fix->getLocator();

0 commit comments

Comments
 (0)