Skip to content

Commit 8fafa52

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 f39a889 commit 8fafa52

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
@@ -5905,19 +5905,6 @@ bool ExtraneousCallFailure::diagnoseAsError() {
59055905
return true;
59065906
}
59075907

5908-
bool InvalidUseOfTrailingClosure::diagnoseAsError() {
5909-
emitDiagnostic(diag::trailing_closure_bad_param, getToType())
5910-
.highlight(getSourceRange());
5911-
5912-
if (auto overload = getCalleeOverloadChoiceIfAvailable(getLocator())) {
5913-
if (auto *decl = overload->choice.getDeclOrNull()) {
5914-
emitDiagnosticAt(decl, diag::decl_declared_here, decl->getName());
5915-
}
5916-
}
5917-
5918-
return true;
5919-
}
5920-
59215908
void NonEphemeralConversionFailure::emitSuggestionNotes() const {
59225909
auto getPointerKind = [](Type ty) -> PointerTypeKind {
59235910
PointerTypeKind pointerKind;

lib/Sema/CSFix.cpp

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

1190-
bool AllowInvalidUseOfTrailingClosure::diagnose(const Solution &solution,
1191-
bool asNote) const {
1192-
InvalidUseOfTrailingClosure failure(solution, getFromType(), getToType(),
1193-
getLocator());
1194-
return failure.diagnose(asNote);
1195-
}
1196-
1197-
AllowInvalidUseOfTrailingClosure *
1198-
AllowInvalidUseOfTrailingClosure::create(ConstraintSystem &cs, Type argType,
1199-
Type paramType,
1200-
ConstraintLocator *locator) {
1201-
return new (cs.getAllocator())
1202-
AllowInvalidUseOfTrailingClosure(cs, argType, paramType, locator);
1203-
}
1204-
12051190
bool TreatEphemeralAsNonEphemeral::diagnose(const Solution &solution,
12061191
bool asNote) const {
12071192
NonEphemeralConversionFailure failure(solution, getLocator(), getFromType(),

lib/Sema/CSFix.h

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -222,8 +222,6 @@ enum class FixKind : uint8_t {
222222
/// a variable, a property etc.
223223
RemoveCall,
224224

225-
AllowInvalidUseOfTrailingClosure,
226-
227225
/// Allow an ephemeral argument conversion for a parameter marked as being
228226
/// non-ephemeral.
229227
TreatEphemeralAsNonEphemeral,
@@ -1656,24 +1654,6 @@ class RemoveInvalidCall final : public ConstraintFix {
16561654
ConstraintLocator *locator);
16571655
};
16581656

1659-
class AllowInvalidUseOfTrailingClosure final : public AllowArgumentMismatch {
1660-
AllowInvalidUseOfTrailingClosure(ConstraintSystem &cs, Type argType,
1661-
Type paramType, ConstraintLocator *locator)
1662-
: AllowArgumentMismatch(cs, FixKind::AllowInvalidUseOfTrailingClosure,
1663-
argType, paramType, locator) {}
1664-
1665-
public:
1666-
std::string getName() const {
1667-
return "allow invalid use of trailing closure";
1668-
}
1669-
1670-
bool diagnose(const Solution &solution, bool asNote = false) const;
1671-
1672-
static AllowInvalidUseOfTrailingClosure *create(ConstraintSystem &cs,
1673-
Type argType, Type paramType,
1674-
ConstraintLocator *locator);
1675-
};
1676-
16771657
class TreatEphemeralAsNonEphemeral final : public AllowArgumentMismatch {
16781658
ConversionRestrictionKind ConversionKind;
16791659

lib/Sema/CSSimplify.cpp

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

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

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

3354-
if (hasFixFor(loc, FixKind::AllowInvalidUseOfTrailingClosure))
3355-
return true;
3356-
33573318
// Don't attempt to fix an argument being passed to a
33583319
// _OptionalNilComparisonType parameter. Such an overload should only take
33593320
// effect when a nil literal is used in valid code, and doesn't offer any
@@ -9601,7 +9562,6 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyFixConstraint(
96019562
case FixKind::GenericArgumentsMismatch:
96029563
case FixKind::AllowMutatingMemberOnRValueBase:
96039564
case FixKind::AllowTupleSplatForSingleParameter:
9604-
case FixKind::AllowInvalidUseOfTrailingClosure:
96059565
case FixKind::AllowNonClassTypeToConvertToAnyObject:
96069566
case FixKind::SpecifyClosureParameterType:
96079567
case FixKind::SpecifyClosureReturnType:

lib/Sema/ConstraintSystem.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4907,13 +4907,6 @@ class MatchCallArgumentListener {
49074907
/// \returns true to indicate that this should cause a failure, false
49084908
/// otherwise.
49094909
virtual bool relabelArguments(ArrayRef<Identifier> newNames);
4910-
4911-
/// Indicates that the trailing closure argument at the given \c argIdx
4912-
/// cannot be passed to the last parameter at \c paramIdx.
4913-
///
4914-
/// \returns true to indicate that this should cause a failure, false
4915-
/// otherwise.
4916-
virtual bool trailingClosureMismatch(unsigned paramIdx, unsigned argIdx);
49174910
};
49184911

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

0 commit comments

Comments
 (0)