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

+7 -4
View File
@@ -55,11 +55,14 @@ static auto HandleReturnDecl(Context& context, Parse::AnyReturnDeclId node_id)
-> bool {
auto [expr_node_id, expr_inst_id] = context.node_stack().PopExprWithNodeId();
Context::FormExpr form_expr = [&] {
// `-> T` provides a type expression, whereas `-> ref T` and `->? F`
// provide a form.
// `-> T` provides a type expression, whereas `-> val T`, `-> ref T`,
// `-> var T`, and `->? F` provide a form.
auto expr_kind = context.parse_tree().node_kind(expr_node_id);
bool is_primitive_form = expr_kind == Parse::ValPrimitiveFormId::Kind ||
expr_kind == Parse::RefPrimitiveFormId::Kind ||
expr_kind == Parse::VarPrimitiveFormId::Kind;
if (context.parse_tree().node_kind(node_id) == Parse::ReturnTypeId::Kind &&
context.parse_tree().node_kind(expr_node_id) !=
Parse::RefPrimitiveFormId::Kind) {
!is_primitive_form) {
return ReturnExprAsForm(context, expr_node_id, expr_inst_id);
} else {
return FormExprAsForm(context, expr_node_id, expr_inst_id);