Skip to content

Commit 4f6acbc

Browse files
committed
Don't crash if there's a request cycle with DefaultArgumentExprRequest.
1 parent f72fd5a commit 4f6acbc

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

lib/AST/Decl.cpp

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

94079407
void ParamDecl::setTypeCheckedDefaultExpr(Expr *E) {
9408-
assert(E || getDefaultArgumentKind() == DefaultArgumentKind::Inherited);
9408+
// The type-checker will only produce a null expression here if the
9409+
// default argument is inherited, so if we're called with a null pointer
9410+
// in any other case, it must be from a request cycle. Don't crash;
9411+
// just wrap the original expression with an ErrorExpr and proceed.
9412+
if (!E && getDefaultArgumentKind() != DefaultArgumentKind::Inherited) {
9413+
auto *initExpr = getStructuralDefaultExpr();
9414+
assert(initExpr);
9415+
auto &ctx = getASTContext();
9416+
E = new (ctx) ErrorExpr(initExpr->getSourceRange(), ErrorType::get(ctx),
9417+
initExpr);
9418+
}
9419+
94099420
setDefaultExpr(E);
94109421

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

0 commit comments

Comments
 (0)