Skip to content

Commit 2c0ac69

Browse files
committed
[CS] Add conversion for ErrorExpr's original expr
Make sure we don't produce unnecessary diagnostics while still allowing things like cursor info to work. No test change since it's covered by the next commit.
1 parent 82f4a10 commit 2c0ac69

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

lib/Sema/CSGen.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1322,7 +1322,18 @@ namespace {
13221322
}
13231323

13241324
virtual Type visitErrorExpr(ErrorExpr *E) {
1325-
return recordInvalidNode(E);
1325+
auto ty = recordInvalidNode(E);
1326+
// If we have an original expression, introduce a conversion to the hole
1327+
// type of the ErrorExpr. This avoids unnecessary diagnostics for the
1328+
// original expression in cases where the ErrorExpr could have provided
1329+
// contextual info, while also still allowing the original expression to
1330+
// be solved without holes being introduced prematurely, allowing e.g
1331+
// cursor info to work correctly.
1332+
if (auto *orig = E->getOriginalExpr()) {
1333+
CS.addConstraint(ConstraintKind::Conversion, CS.getType(orig), ty,
1334+
CS.getConstraintLocator(E));
1335+
}
1336+
return ty;
13261337
}
13271338

13281339
virtual Type visitCodeCompletionExpr(CodeCompletionExpr *E) {

lib/Sema/CSSimplify.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5582,6 +5582,10 @@ bool ConstraintSystem::repairFailures(
55825582
if (!anchor)
55835583
return false;
55845584

5585+
// If we have an ErrorExpr anchor, we don't need to do any more fixes.
5586+
if (isExpr<ErrorExpr>(anchor))
5587+
return true;
5588+
55855589
// This could be:
55865590
// - `InOutExpr` used with r-value e.g. `foo(&x)` where `x` is a `let`.
55875591
// - `ForceValueExpr` e.g. `foo.bar! = 42` where `bar` or `foo` are

0 commit comments

Comments
 (0)