Skip to content

Commit a92e62f

Browse files
Fixing formatting issues
1 parent 5d1eeac commit a92e62f

File tree

3 files changed

+31
-28
lines changed

3 files changed

+31
-28
lines changed

lib/Sema/CSFix.cpp

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -867,22 +867,24 @@ bool RemoveUnnecessaryCoercion::diagnose(Expr *root, bool asNote) const {
867867
bool RemoveUnnecessaryCoercion::attempt(ConstraintSystem &cs, Type fromType,
868868
Type toType,
869869
ConstraintLocatorBuilder locator) {
870-
if (auto last = locator.last()) {
871-
if (last->is<LocatorPathElt::ExplicitTypeCoercion>()) {
872-
auto expr = cast<CoerceExpr>(locator.getAnchor());
873-
auto toTypeRepr = expr->getCastTypeLoc().getTypeRepr();
874-
875-
// only diagnosing for coercion where the left-side is a DeclRefExpr
876-
// or a explicit/implicit coercion e.g. Double(1) as Double
877-
if (!isa<ImplicitlyUnwrappedOptionalTypeRepr>(toTypeRepr) &&
878-
(isa<DeclRefExpr>(expr->getSubExpr()) ||
879-
isa<CoerceExpr>(expr->getSubExpr()))) {
880-
auto *fix = new (cs.getAllocator()) RemoveUnnecessaryCoercion(
881-
cs, fromType, toType, cs.getConstraintLocator(locator));
882-
883-
return cs.recordFix(fix);
884-
}
885-
}
870+
auto last = locator.last();
871+
bool isExplicitCoercion =
872+
last && last->is<LocatorPathElt::ExplicitTypeCoercion>();
873+
if (!isExplicitCoercion)
874+
return false;
875+
876+
auto expr = cast<CoerceExpr>(locator.getAnchor());
877+
auto toTypeRepr = expr->getCastTypeLoc().getTypeRepr();
878+
879+
// only diagnosing for coercion where the left-side is a DeclRefExpr
880+
// or a explicit/implicit coercion e.g. Double(1) as Double
881+
if (!isa<ImplicitlyUnwrappedOptionalTypeRepr>(toTypeRepr) &&
882+
(isa<DeclRefExpr>(expr->getSubExpr()) ||
883+
isa<CoerceExpr>(expr->getSubExpr()))) {
884+
auto *fix = new (cs.getAllocator()) RemoveUnnecessaryCoercion(
885+
cs, fromType, toType, cs.getConstraintLocator(locator));
886+
887+
return cs.recordFix(fix);
886888
}
887889
return false;
888890
}

lib/Sema/CSFix.h

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,8 @@ enum class FixKind : uint8_t {
197197
/// by forming all of the given arguments into a single tuple.
198198
AllowTupleSplatForSingleParameter,
199199

200-
/// Remove an unnecessary coercion ('as') if the types are already equal. e.g. Double(1) as Double
200+
/// Remove an unnecessary coercion ('as') if the types are already equal.
201+
/// e.g. Double(1) as Double
201202
RemoveUnnecessaryCoercion,
202203

203204
/// Allow a single argument type mismatch. This is the most generic
@@ -1345,19 +1346,19 @@ class IgnoreContextualType : public ContextualMismatch {
13451346

13461347
class RemoveUnnecessaryCoercion : public ContextualMismatch {
13471348
protected:
1348-
RemoveUnnecessaryCoercion(ConstraintSystem &cs,
1349-
Type fromType, Type toType,
1349+
RemoveUnnecessaryCoercion(ConstraintSystem &cs, Type fromType, Type toType,
13501350
ConstraintLocator *locator)
1351-
: ContextualMismatch(cs, FixKind::RemoveUnnecessaryCoercion, fromType, toType,
1352-
locator, /*isWarning*/ true) {}
1353-
1351+
: ContextualMismatch(cs, FixKind::RemoveUnnecessaryCoercion, fromType,
1352+
toType, locator, /*isWarning*/ true) {}
1353+
13541354
public:
1355-
std::string getName() const override { return "remove unnecessary explicit type coercion"; }
1356-
1355+
std::string getName() const override {
1356+
return "remove unnecessary explicit type coercion";
1357+
}
1358+
13571359
bool diagnose(Expr *root, bool asNote = false) const override;
1358-
1359-
static bool attempt(ConstraintSystem &cs,
1360-
Type fromType, Type toType,
1360+
1361+
static bool attempt(ConstraintSystem &cs, Type fromType, Type toType,
13611362
ConstraintLocatorBuilder locator);
13621363
};
13631364

lib/Sema/CSSimplify.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2588,7 +2588,7 @@ bool ConstraintSystem::repairFailures(
25882588
};
25892589

25902590
if (path.empty() ||
2591-
path.back().getKind() == ConstraintLocator::ExplicitTypeCoercion) {
2591+
path.back().is<LocatorPathElt::ExplicitTypeCoercion>()) {
25922592
if (!anchor)
25932593
return false;
25942594

0 commit comments

Comments
 (0)