Skip to content
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

[AST, Sema] Replace HoleType with PlaceholderType #35589

Merged
merged 14 commits into from
Feb 22, 2021
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
[Sema] Rework DiscardAssignmentExpr checking wrt SequenceExpr folding
Now that we're checking DiscardAssignmentExprs in PreCheckExpr, we have to be careful to make sure we don't diagnose anything until after SequenceExprs have been folded, since the relevant AssignExprs won't even have a "right hand side" and "left hand side" until after folding.
  • Loading branch information
Jumhyn committed Feb 17, 2021
commit be2aeb513b439cd756eb14ae2c2ff32b4b437e03
20 changes: 20 additions & 0 deletions lib/Sema/PreCheckExpr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -814,6 +814,9 @@ namespace {
/// Keep track of acceptable DiscardAssignmentExpr's.
llvm::SmallPtrSet<DiscardAssignmentExpr*, 2> CorrectDiscardAssignmentExprs;

/// The current number of nested \c SequenceExprs that we're within.
unsigned SequenceExprDepth = 0;

/// Simplify expressions which are type sugar productions that got parsed
/// as expressions due to the parser not knowing which identifiers are
/// type names.
Expand Down Expand Up @@ -1145,6 +1148,9 @@ namespace {
if (auto *assignment = dyn_cast<AssignExpr>(expr))
markAcceptableDiscardExprs(assignment->getDest());

if (isa<SequenceExpr>(expr))
SequenceExprDepth++;

return finish(true, expr);
}

Expand All @@ -1160,6 +1166,7 @@ namespace {
// Fold sequence expressions.
if (auto *seqExpr = dyn_cast<SequenceExpr>(expr)) {
auto result = TypeChecker::foldSequence(seqExpr, DC);
SequenceExprDepth--;
return result->walk(*this);
}

Expand Down Expand Up @@ -1280,6 +1287,19 @@ namespace {
if (auto *simplified = simplifyTypeExpr(expr))
return simplified;

// Diagnose a '_' that isn't on the immediate LHS of an assignment. We
// skip diagnostics if we've explicitly marked the expression as valid,
// or if we're inside a SequenceExpr (since the whole tree will be
// re-checked when we finish folding anyway).
if (auto *DAE = dyn_cast<DiscardAssignmentExpr>(expr)) {
if (!CorrectDiscardAssignmentExprs.count(DAE) &&
SequenceExprDepth == 0) {
ctx.Diags.diagnose(expr->getLoc(),
diag::discard_expr_outside_of_assignment);
return nullptr;
}
}

if (auto KPE = dyn_cast<KeyPathExpr>(expr)) {
resolveKeyPathExpr(KPE);
return KPE;
Expand Down