Support for terse => function bodies (#7895)

Treat the function as having a `-> auto` return type. Reject calls to
functions that still have a non-deduced `-> auto` return type, and
rewrite the function to have the actual return type once it is known.

Assisted-by: Gemini via Antigravity
This commit is contained in:
Richard Smith authored and GitHub committed 2026-10-16 21:48:48 +00:00
1 parent d08805f1a6
commit b766aa4d16
30 files changed
+1323 -322

No files matched your search

+4 -4
View File
@@ -29,7 +29,7 @@ var d: auto = fn (ref x: i32) ->? ref i32 { return x; };
require j%-fn->>
// CHECK:STDERR: fail_unconsumed_lambda_introducer.carbon:[[@LINE+6]]:1: error: expected expression [ExpectedExpr]
// CHECK:STDERR:
// CHECK:STDERR: fail_unconsumed_lambda_introducer.carbon:[[@LINE+4]]:1: error: expected `=>` or `{` after return type [ExpectedLambdaBodyAfterReturnType]
// CHECK:STDERR: fail_unconsumed_lambda_introducer.carbon:[[@LINE+4]]:1: error: expected `{` after return type [ExpectedLambdaBodyAfterReturnType]
// CHECK:STDERR:
// CHECK:STDERR: fail_unconsumed_lambda_introducer.carbon:[[@LINE+2]]:1: error: expected `impls` in `require` declaration [RequireExpectedImpls]
// CHECK:STDERR:
@@ -45,7 +45,7 @@ fn F() {
// --- fail_expected_body_after_return_type.carbon
fn G() {
// CHECK:STDERR: fail_expected_body_after_return_type.carbon:[[@LINE+2]]:27: error: expected `=>` or `{` after return type [ExpectedLambdaBodyAfterReturnType]
// CHECK:STDERR: fail_expected_body_after_return_type.carbon:[[@LINE+2]]:27: error: expected `{` after return type [ExpectedLambdaBodyAfterReturnType]
// CHECK:STDERR:
var x: auto = fn -> i32 ;
}
@@ -94,9 +94,9 @@ fn G() {
// CHECK:STDOUT: │ │ │ │ ├─IntTypeLiteral 'i32'
// CHECK:STDOUT: │ │ │ ├─LetBindingPattern ':'
// CHECK:STDOUT: │ │ ├─ExplicitParamList ')'
// CHECK:STDOUT: │ │ ╭─LambdaDefinitionStart '=>'
// CHECK:STDOUT: │ │ ╭─LambdaTerseDefinitionStart '=>'
// CHECK:STDOUT: │ │ ├─IdentifierNameExpr 'x'
// CHECK:STDOUT: │ ├─Lambda 'fn'
// CHECK:STDOUT: │ ├─LambdaTerseDefinition 'fn'
// CHECK:STDOUT: ├─VariableDecl ';'
// CHECK:STDOUT: │ ╭─VariableIntroducer 'var'
// CHECK:STDOUT: │ │ ╭─IdentifierNameNotBeforeSignature 'c'