Initial support for fn expressions. (#7893)

Support for `fn` expressions with the same feature set as `fn`
declarations. In particular, there is no support for captures,
positional parameters, `=>` bodies, or `auto` return types.

Note that this results in two parse nodes for each `=>` token. That's a
bug, but it matches the behavior of function declarations, and will be
fixed in a follow-up change.

Assisted-by: Gemini via Antigravity
This commit is contained in:
Richard Smith authored and GitHub committed 2026-10-06 20:12:58 +00:00
1 parent 66bf1415ac
commit 1b0a5709e6
24 files changed
+2015 -308

No files matched your search

+11 -10
View File
@@ -75,16 +75,17 @@ var b: auto = fn (x: i32 = 0) => x;
// CHECK:STDOUT: │ │ ╭─VarBindingPattern ':'
// CHECK:STDOUT: │ ├─VariablePattern 'var'
// CHECK:STDOUT: │ ├─VariableInitializer '='
// CHECK:STDOUT: │ │ ╭─LambdaIntroducer 'fn'
// CHECK:STDOUT: │ │ │ ╭─ExplicitParamListStart '('
// CHECK:STDOUT: │ │ │ │ ╭─IdentifierNameNotBeforeSignature 'x'
// CHECK:STDOUT: │ │ │ │ ├─BindingPatternTypeStart ':'
// CHECK:STDOUT: │ │ │ │ ├─IntTypeLiteral 'i32'
// CHECK:STDOUT: │ │ │ │ ╭─LetBindingPattern ':'
// CHECK:STDOUT: │ │ │ │ ├─DefaultValueExprStart '='
// CHECK:STDOUT: │ │ │ │ ├─IntLiteral '0'
// CHECK:STDOUT: │ │ │ ├─DefaultValuePattern '='
// CHECK:STDOUT: │ │ ├─ExplicitParamList ')'
// CHECK:STDOUT: │ │ ╭─LambdaIntroducer 'fn'
// CHECK:STDOUT: │ │ │ ╭─ExplicitParamListStart '('
// CHECK:STDOUT: │ │ │ │ ╭─IdentifierNameNotBeforeSignature 'x'
// CHECK:STDOUT: │ │ │ │ ├─BindingPatternTypeStart ':'
// CHECK:STDOUT: │ │ │ │ ├─IntTypeLiteral 'i32'
// CHECK:STDOUT: │ │ │ │ ╭─LetBindingPattern ':'
// CHECK:STDOUT: │ │ │ │ ├─DefaultValueExprStart '='
// CHECK:STDOUT: │ │ │ │ ├─IntLiteral '0'
// CHECK:STDOUT: │ │ │ ├─DefaultValuePattern '='
// CHECK:STDOUT: │ │ ├─ExplicitParamList ')'
// CHECK:STDOUT: │ │ ╭─LambdaDefinitionStart '=>'
// CHECK:STDOUT: │ │ ├─TerseBodyArrow '=>'
// CHECK:STDOUT: │ │ ├─IdentifierNameExpr 'x'
// CHECK:STDOUT: │ ├─Lambda 'fn'