diff --git a/bin/BootstrapTypes/Globals.cpp b/bin/BootstrapTypes/Globals.cpp index 7406e2e0..f6963c92 100644 --- a/bin/BootstrapTypes/Globals.cpp +++ b/bin/BootstrapTypes/Globals.cpp @@ -1238,6 +1238,7 @@ std::set> kCanReturnNullptr{ {"OpaqueValueExpr", "SourceExpression"}, {"DependentSizedArrayType", "SizeExpression"}, {"CXXRecordDecl", "LambdaStaticInvoker"}, + {"CoroutineBodyStmt", "ResultDeclaration"}, // {"FunctionProtoType", "EllipsisToken"}, // {"FunctionDecl", "EllipsisToken"}, diff --git a/include/pasta/AST/Stmt.h b/include/pasta/AST/Stmt.h index 0a49cb6c..1a2b5a5b 100644 --- a/include/pasta/AST/Stmt.h +++ b/include/pasta/AST/Stmt.h @@ -1293,7 +1293,7 @@ class CoroutineBodyStmt : public Stmt { std::vector<::pasta::Stmt> ParameterMoves(void) const; ::pasta::VarDecl PromiseDeclaration(void) const; ::pasta::Stmt PromiseDeclarationStatement(void) const; - ::pasta::Stmt ResultDeclaration(void) const; + std::optional<::pasta::Stmt> ResultDeclaration(void) const; ::pasta::Stmt ReturnStatement(void) const; ::pasta::Stmt ReturnStatementOnAllocFailure(void) const; ::pasta::Expr ReturnValue(void) const; diff --git a/lib/AST/Stmt.cpp b/lib/AST/Stmt.cpp index 35323284..74988339 100644 --- a/lib/AST/Stmt.cpp +++ b/lib/AST/Stmt.cpp @@ -2861,13 +2861,15 @@ ::pasta::Stmt CoroutineBodyStmt::PromiseDeclarationStatement(void) const { throw std::runtime_error("CoroutineBodyStmt::PromiseDeclarationStatement can return nullptr!"); } -::pasta::Stmt CoroutineBodyStmt::ResultDeclaration(void) const { +std::optional<::pasta::Stmt> CoroutineBodyStmt::ResultDeclaration(void) const { auto &self = *const_cast(u.CoroutineBodyStmt); decltype(auto) val = self.getResultDecl(); + if (!val) { + return std::nullopt; + } if (val) { return StmtBuilder::Create<::pasta::Stmt>(ast, val); } - throw std::runtime_error("CoroutineBodyStmt::ResultDeclaration can return nullptr!"); } ::pasta::Stmt CoroutineBodyStmt::ReturnStatement(void) const {