diff --git a/src/script_opt/CPP/Exprs.cc b/src/script_opt/CPP/Exprs.cc index f86dfeab84..a35b2a46e2 100644 --- a/src/script_opt/CPP/Exprs.cc +++ b/src/script_opt/CPP/Exprs.cc @@ -351,7 +351,7 @@ string CPPCompile::GenCallExpr(const CallExpr* c, GenType gt, bool top_level) if ( is_async ) invoke_func = "when_invoke__CPP"; - else if ( t->Tag() == TYPE_VOID ) + else if ( top_level || t->Tag() == TYPE_VOID ) { ASSERT(top_level); invoke_func = "invoke_void__CPP"; diff --git a/src/script_opt/CPP/Stmts.cc b/src/script_opt/CPP/Stmts.cc index b9666573a3..af9ba0baed 100644 --- a/src/script_opt/CPP/Stmts.cc +++ b/src/script_opt/CPP/Stmts.cc @@ -444,10 +444,16 @@ void CPPCompile::GenWhenStmt(const WhenStmt* w) if ( ret_type && ret_type->Tag() != TYPE_VOID ) { + // Note, ret_type can be active but we *still* don't have + // a return type, due to the faked-up "any" return type + // associated with "when" lambdas, so check for that case. + Emit("if ( curr_t )"); + StartBlock(); Emit("ValPtr retval = {NewRef{}, curr_t->Lookup(curr_assoc)};"); Emit("if ( ! retval )"); Emit("\tthrow CPPDelayedCallException();"); Emit("return %s;", GenericValPtrToGT("retval", ret_type, GEN_NATIVE)); + EndBlock(); } Emit("}");