Support -> val T and -> var T return forms (#7912)

Proposal p5434 specifies `-> val T`, `-> ref T`, and `-> var T` as
return forms. `-> ref T` is parsed as a `RefPrimitiveForm`; extend that
to parse a leading `val` or `var` after `->` as a `ValPrimitiveForm` or
`VarPrimitiveForm`, reusing the nodes produced by `form(val T)` and
`form(var T)`, and check them as forms.

---------

Co-authored-by: josh11b <15258583+josh11b@users.noreply.github.com>
This commit is contained in:
David Blaikieandjosh11b authored and GitHub committed 2026-10-14 23:19:16 +00:00
1 parent 831a2aee9f
commit 1c69fe3447
6 files changed
+414 -8

No files matched your search

+4 -2
View File
@@ -35,8 +35,10 @@ auto HandleFunctionAfterParams(Context& context) -> void {
auto HandleReturnTypeOrFormExpr(Context& context) -> void {
context.PopAndDiscardState();
// `-> ref T` specifies a primitive return form.
if (context.PositionIs(Lex::TokenKind::Ref)) {
// `-> val T`, `-> ref T`, and `-> var T` specify a primitive return form.
if (context.PositionIs(Lex::TokenKind::Val) ||
context.PositionIs(Lex::TokenKind::Ref) ||
context.PositionIs(Lex::TokenKind::Var)) {
context.PushState(StateKind::PrimitiveFormFinish, context.Consume());
}
context.PushStateForExpr(PrecedenceGroup::ForType());