Skip to content

Commit 3088b85

Browse files
committed
Don't crash if there's a request cycle with DefaultArgumentExprRequest.
1 parent 5f3120b commit 3088b85

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

lib/AST/Decl.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9443,7 +9443,18 @@ void ParamDecl::setDefaultExpr(Expr *E) {
94439443
}
94449444

94459445
void ParamDecl::setTypeCheckedDefaultExpr(Expr *E) {
9446-
assert(E || getDefaultArgumentKind() == DefaultArgumentKind::Inherited);
9446+
// The type-checker will only produce a null expression here if the
9447+
// default argument is inherited, so if we're called with a null pointer
9448+
// in any other case, it must be from a request cycle. Don't crash;
9449+
// just wrap the original expression with an ErrorExpr and proceed.
9450+
if (!E && getDefaultArgumentKind() != DefaultArgumentKind::Inherited) {
9451+
auto *initExpr = getStructuralDefaultExpr();
9452+
assert(initExpr);
9453+
auto &ctx = getASTContext();
9454+
E = new (ctx) ErrorExpr(initExpr->getSourceRange(), ErrorType::get(ctx),
9455+
initExpr);
9456+
}
9457+
94479458
setDefaultExpr(E);
94489459

94499460
auto *defaultInfo = DefaultValueAndFlags.getPointer();
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
// {"kind":"typecheck","signature":"swift::ParamDecl::setTypeCheckedDefaultExpr(swift::Expr*)","signatureAssert":"Assertion failed: (E || getDefaultArgumentKind() == DefaultArgumentKind::Inherited), function setTypeCheckedDefaultExpr"}
2-
// RUN: not --crash %target-swift-frontend -typecheck %s
2+
// RUN: not %target-swift-frontend -typecheck %s
33
func a<b>(b= a(

0 commit comments

Comments
 (0)