Skip to content

Commit f789974

Browse files
committed
Cleaning up anchor finding in interpolated strings
The arglist didn't exist when I originally wrote this. Most of the assertions were there to check my assumptions about the dyn-casts that were being performed originally. In a non-asserts build, the dyn-casts would not crash, but would emit the `await` insertion fix-it into the wrong location. In an asserts build, it would crash instead. I haven't heard about crashes, or misplaced fix-its from this for roughly a year now, so I think it's safe to clean it up. I'm keeping the `parent == nullptr` check since that would indicate an issue in the implementation of `isEffectAnchor`.
1 parent 7abc8a4 commit f789974

File tree

1 file changed

+4
-14
lines changed

1 file changed

+4
-14
lines changed

lib/Sema/TypeCheckEffects.cpp

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2071,7 +2071,8 @@ class CheckEffectsCoverage : public EffectsHandlingWalker<CheckEffectsCoverage>
20712071
llvm::DenseMap<Expr *, Expr *> parentMap;
20722072

20732073
static bool isEffectAnchor(Expr *e) {
2074-
return isa<AbstractClosureExpr>(e) || isa<DiscardAssignmentExpr>(e) || isa<AssignExpr>(e);
2074+
return isa<AbstractClosureExpr>(e) || isa<DiscardAssignmentExpr>(e) ||
2075+
isa<AssignExpr>(e);
20752076
}
20762077

20772078
static bool isAnchorTooEarly(Expr *e) {
@@ -2091,24 +2092,13 @@ class CheckEffectsCoverage : public EffectsHandlingWalker<CheckEffectsCoverage>
20912092
if (parent && !isAnchorTooEarly(parent)) {
20922093
return parent;
20932094
}
2094-
20952095
if (isInterpolatedString) {
2096-
// TODO: I'm being gentle with the casts to avoid breaking things
2097-
// If we see incorrect fix-it locations in string interpolations
2098-
// we need to change how this behaves
2099-
// Assert builds will crash giving us a bug to fix, non-asserts will
2100-
// quietly "just work".
21012096
assert(parent == nullptr && "Expected to be at top of expression");
2102-
assert(isa<CallExpr>(lastParent) &&
2103-
"Expected top of string interpolation to be CalExpr");
2104-
assert(cast<CallExpr>(lastParent)->getArgs()->isUnlabeledUnary() &&
2105-
"Expected unary arg in string interpolation call");
2106-
if (auto *callExpr = dyn_cast<CallExpr>(lastParent)) {
2107-
if (auto *unaryArg = callExpr->getArgs()->getUnlabeledUnaryExpr())
2097+
if (ArgumentList *args = lastParent->getArgs()) {
2098+
if (Expr *unaryArg = args->getUnlabeledUnaryExpr())
21082099
return unaryArg;
21092100
}
21102101
}
2111-
21122102
return lastParent;
21132103
}
21142104

0 commit comments

Comments
 (0)