Skip to content

Commit 7f2d4e0

Browse files
committed
[Diagnostics] Remove the now-unused AllowInvalidUseOfTrailingClosure
Diagnosis for invalid uses of trailing closures has been folded in with argument-matching diagnostics, so remove all of the machinery around the syntactic "mismatched trailing closure" logic.
1 parent 2395225 commit 7f2d4e0

File tree

5 files changed

+0
-95
lines changed

5 files changed

+0
-95
lines changed

lib/Sema/CSDiagnostics.cpp

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5888,19 +5888,6 @@ bool ExtraneousCallFailure::diagnoseAsError() {
58885888
return true;
58895889
}
58905890

5891-
bool InvalidUseOfTrailingClosure::diagnoseAsError() {
5892-
emitDiagnostic(diag::trailing_closure_bad_param, getToType())
5893-
.highlight(getSourceRange());
5894-
5895-
if (auto overload = getCalleeOverloadChoiceIfAvailable(getLocator())) {
5896-
if (auto *decl = overload->choice.getDeclOrNull()) {
5897-
emitDiagnosticAt(decl, diag::decl_declared_here, decl->getName());
5898-
}
5899-
}
5900-
5901-
return true;
5902-
}
5903-
59045891
void NonEphemeralConversionFailure::emitSuggestionNotes() const {
59055892
auto getPointerKind = [](Type ty) -> PointerTypeKind {
59065893
PointerTypeKind pointerKind;

lib/Sema/CSFix.cpp

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1317,21 +1317,6 @@ RemoveInvalidCall *RemoveInvalidCall::create(ConstraintSystem &cs,
13171317
return new (cs.getAllocator()) RemoveInvalidCall(cs, locator);
13181318
}
13191319

1320-
bool AllowInvalidUseOfTrailingClosure::diagnose(const Solution &solution,
1321-
bool asNote) const {
1322-
InvalidUseOfTrailingClosure failure(solution, getFromType(), getToType(),
1323-
getLocator());
1324-
return failure.diagnose(asNote);
1325-
}
1326-
1327-
AllowInvalidUseOfTrailingClosure *
1328-
AllowInvalidUseOfTrailingClosure::create(ConstraintSystem &cs, Type argType,
1329-
Type paramType,
1330-
ConstraintLocator *locator) {
1331-
return new (cs.getAllocator())
1332-
AllowInvalidUseOfTrailingClosure(cs, argType, paramType, locator);
1333-
}
1334-
13351320
bool TreatEphemeralAsNonEphemeral::diagnose(const Solution &solution,
13361321
bool asNote) const {
13371322
NonEphemeralConversionFailure failure(solution, getLocator(), getFromType(),

lib/Sema/CSFix.h

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -225,8 +225,6 @@ enum class FixKind : uint8_t {
225225
/// a variable, a property etc.
226226
RemoveCall,
227227

228-
AllowInvalidUseOfTrailingClosure,
229-
230228
/// Allow an ephemeral argument conversion for a parameter marked as being
231229
/// non-ephemeral.
232230
TreatEphemeralAsNonEphemeral,
@@ -1715,24 +1713,6 @@ class RemoveInvalidCall final : public ConstraintFix {
17151713
ConstraintLocator *locator);
17161714
};
17171715

1718-
class AllowInvalidUseOfTrailingClosure final : public AllowArgumentMismatch {
1719-
AllowInvalidUseOfTrailingClosure(ConstraintSystem &cs, Type argType,
1720-
Type paramType, ConstraintLocator *locator)
1721-
: AllowArgumentMismatch(cs, FixKind::AllowInvalidUseOfTrailingClosure,
1722-
argType, paramType, locator) {}
1723-
1724-
public:
1725-
std::string getName() const {
1726-
return "allow invalid use of trailing closure";
1727-
}
1728-
1729-
bool diagnose(const Solution &solution, bool asNote = false) const;
1730-
1731-
static AllowInvalidUseOfTrailingClosure *create(ConstraintSystem &cs,
1732-
Type argType, Type paramType,
1733-
ConstraintLocator *locator);
1734-
};
1735-
17361716
class TreatEphemeralAsNonEphemeral final : public AllowArgumentMismatch {
17371717
ConversionRestrictionKind ConversionKind;
17381718

lib/Sema/CSSimplify.cpp

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,6 @@ bool MatchCallArgumentListener::relabelArguments(ArrayRef<Identifier> newNames){
6161
return true;
6262
}
6363

64-
bool MatchCallArgumentListener::trailingClosureMismatch(
65-
unsigned paramIdx, unsigned argIdx) {
66-
return true;
67-
}
68-
6964
/// Produce a score (smaller is better) comparing a parameter name and
7065
/// potentially-typo'd argument name.
7166
///
@@ -950,37 +945,6 @@ class ArgumentFailureTracker : public MatchCallArgumentListener {
950945
return CS.recordFix(fix, impact);
951946
}
952947

953-
bool trailingClosureMismatch(unsigned paramIdx, unsigned argIdx) override {
954-
if (!CS.shouldAttemptFixes())
955-
return true;
956-
957-
const auto &param = Parameters[paramIdx];
958-
959-
auto *argLoc = CS.getConstraintLocator(
960-
Locator.withPathElement(LocatorPathElt::ApplyArgToParam(
961-
argIdx, paramIdx, param.getParameterFlags())));
962-
963-
// TODO(diagnostics): This fix should be attempted later
964-
// when the argument is matched to a parameter. Doing that
965-
// would not require special handling of the closure type.
966-
Type argType;
967-
if (auto *closure =
968-
getAsExpr<ClosureExpr>(simplifyLocatorToAnchor(argLoc))) {
969-
argType = CS.getClosureType(closure);
970-
} else {
971-
argType = Arguments[argIdx].getPlainType();
972-
}
973-
974-
argType.visit([&](Type type) {
975-
if (auto *typeVar = type->getAs<TypeVariableType>())
976-
CS.recordPotentialHole(typeVar);
977-
});
978-
979-
auto *fix = AllowInvalidUseOfTrailingClosure::create(
980-
CS, argType, param.getPlainType(), argLoc);
981-
return CS.recordFix(fix, /*impact=*/3);
982-
}
983-
984948
ArrayRef<std::pair<unsigned, AnyFunctionType::Param>>
985949
getExtraneousArguments() const {
986950
return ExtraArguments;
@@ -3481,9 +3445,6 @@ bool ConstraintSystem::repairFailures(
34813445
case ConstraintLocator::ApplyArgToParam: {
34823446
auto loc = getConstraintLocator(locator);
34833447

3484-
if (hasFixFor(loc, FixKind::AllowInvalidUseOfTrailingClosure))
3485-
return true;
3486-
34873448
// Don't attempt to fix an argument being passed to a
34883449
// _OptionalNilComparisonType parameter. Such an overload should only take
34893450
// effect when a nil literal is used in valid code, and doesn't offer any
@@ -9858,7 +9819,6 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyFixConstraint(
98589819
case FixKind::GenericArgumentsMismatch:
98599820
case FixKind::AllowMutatingMemberOnRValueBase:
98609821
case FixKind::AllowTupleSplatForSingleParameter:
9861-
case FixKind::AllowInvalidUseOfTrailingClosure:
98629822
case FixKind::AllowNonClassTypeToConvertToAnyObject:
98639823
case FixKind::SpecifyClosureParameterType:
98649824
case FixKind::SpecifyClosureReturnType:

lib/Sema/ConstraintSystem.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5210,13 +5210,6 @@ class MatchCallArgumentListener {
52105210
/// \returns true to indicate that this should cause a failure, false
52115211
/// otherwise.
52125212
virtual bool relabelArguments(ArrayRef<Identifier> newNames);
5213-
5214-
/// Indicates that the trailing closure argument at the given \c argIdx
5215-
/// cannot be passed to the last parameter at \c paramIdx.
5216-
///
5217-
/// \returns true to indicate that this should cause a failure, false
5218-
/// otherwise.
5219-
virtual bool trailingClosureMismatch(unsigned paramIdx, unsigned argIdx);
52205213
};
52215214

52225215
/// Match the call arguments (as described by the given argument type) to

0 commit comments

Comments
 (0)