Skip to content

Cleaning up anchor finding in interpolated strings #41723

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 9, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 4 additions & 14 deletions lib/Sema/TypeCheckEffects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2071,7 +2071,8 @@ class CheckEffectsCoverage : public EffectsHandlingWalker<CheckEffectsCoverage>
llvm::DenseMap<Expr *, Expr *> parentMap;

static bool isEffectAnchor(Expr *e) {
return isa<AbstractClosureExpr>(e) || isa<DiscardAssignmentExpr>(e) || isa<AssignExpr>(e);
return isa<AbstractClosureExpr>(e) || isa<DiscardAssignmentExpr>(e) ||
isa<AssignExpr>(e);
}

static bool isAnchorTooEarly(Expr *e) {
Expand All @@ -2091,24 +2092,13 @@ class CheckEffectsCoverage : public EffectsHandlingWalker<CheckEffectsCoverage>
if (parent && !isAnchorTooEarly(parent)) {
return parent;
}

if (isInterpolatedString) {
// TODO: I'm being gentle with the casts to avoid breaking things
// If we see incorrect fix-it locations in string interpolations
// we need to change how this behaves
// Assert builds will crash giving us a bug to fix, non-asserts will
// quietly "just work".
assert(parent == nullptr && "Expected to be at top of expression");
assert(isa<CallExpr>(lastParent) &&
"Expected top of string interpolation to be CalExpr");
assert(cast<CallExpr>(lastParent)->getArgs()->isUnlabeledUnary() &&
"Expected unary arg in string interpolation call");
if (auto *callExpr = dyn_cast<CallExpr>(lastParent)) {
if (auto *unaryArg = callExpr->getArgs()->getUnlabeledUnaryExpr())
if (ArgumentList *args = lastParent->getArgs()) {
if (Expr *unaryArg = args->getUnlabeledUnaryExpr())
return unaryArg;
}
}

return lastParent;
}

Expand Down