Skip to content

Commit d87d22d

Browse files
committed
[ConstraintSystem] Intoduce a fix for incorrect use of trailing closures
1 parent 6bddac3 commit d87d22d

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

lib/Sema/CSFix.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -994,3 +994,15 @@ RemoveInvalidCall *RemoveInvalidCall::create(ConstraintSystem &cs,
994994
ConstraintLocator *locator) {
995995
return new (cs.getAllocator()) RemoveInvalidCall(cs, locator);
996996
}
997+
998+
bool AllowInvalidUseOfTrailingClosure::diagnose(Expr *expr, bool asNote) const {
999+
return false;
1000+
}
1001+
1002+
AllowInvalidUseOfTrailingClosure *
1003+
AllowInvalidUseOfTrailingClosure::create(ConstraintSystem &cs, Type argType,
1004+
Type paramType,
1005+
ConstraintLocator *locator) {
1006+
return new (cs.getAllocator())
1007+
AllowInvalidUseOfTrailingClosure(cs, argType, paramType, locator);
1008+
}

lib/Sema/CSFix.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,8 @@ enum class FixKind : uint8_t {
215215
/// Remove extraneous call to something which can't be invoked e.g.
216216
/// a variable, a property etc.
217217
RemoveCall,
218+
219+
AllowInvalidUseOfTrailingClosure,
218220
};
219221

220222
class ConstraintFix {
@@ -1488,6 +1490,24 @@ class RemoveInvalidCall final : public ConstraintFix {
14881490
ConstraintLocator *locator);
14891491
};
14901492

1493+
class AllowInvalidUseOfTrailingClosure final : public AllowArgumentMismatch {
1494+
AllowInvalidUseOfTrailingClosure(ConstraintSystem &cs, Type argType,
1495+
Type paramType, ConstraintLocator *locator)
1496+
: AllowArgumentMismatch(cs, FixKind::AllowInvalidUseOfTrailingClosure,
1497+
argType, paramType, locator) {}
1498+
1499+
public:
1500+
std::string getName() const {
1501+
return "allow invalid use of trailing closure";
1502+
}
1503+
1504+
bool diagnose(Expr *root, bool asNote = false) const;
1505+
1506+
static AllowInvalidUseOfTrailingClosure *create(ConstraintSystem &cs,
1507+
Type argType, Type paramType,
1508+
ConstraintLocator *locator);
1509+
};
1510+
14911511
} // end namespace constraints
14921512
} // end namespace swift
14931513

0 commit comments

Comments
 (0)