mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-11-15 04:48:32 +00:00
Add support for -> auto deduced return types. (#7931)
The return type is deduced from the function's `return` statements (currently required to all have the same type), or from its first `returned var`. Calls to generic functions with deduced return types are not yet supported. When a function has a deduced return type, we defer the return type portion of the callee pattern match until deduction, and during deduction we extend the decl block and the pattern block with the return-related instructions. Conversions for `return expr;` statements are deferred until the return type has been deduced. The design requires that we take the common type of the returned types as the deduced return type, so we can't in general perform any conversions for returned expressions until we reach the end of the function. This is accomplished by inserting a `splice_block` where the conversions will go, and later updating that instruction to contain the conversion. Assisted-by: Claude Opus 5.5 via Antigravity
This commit is contained in:
1 parent
1c69fe3447
commit
bf5d2a2ace
41 files changed
+2631
-214
No files matched your search
@@ -1539,6 +1539,13 @@ static auto ExportGenericFunctionToCpp(Context& context, SemIR::LocId loc_id,
|
||||
static auto ExportFunctionToCpp(Context& context, SemIR::LocId loc_id,
|
||||
SemIR::FunctionId callee_function_id)
|
||||
-> clang::NamedDecl* {
|
||||
if (const auto& callee = context.functions().Get(callee_function_id);
|
||||
callee.has_pending_deduced_return_type() ||
|
||||
(callee.has_deduced_return_type && callee.generic_id.has_value())) {
|
||||
context.TODO(loc_id, "export of function with deduced return type");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto target = BuildFunctionInfo(context, loc_id, callee_function_id);
|
||||
if (!target) {
|
||||
return nullptr;
|
||||
|
||||
Reference in new issue
Block a user