mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-11-17 05:48:12 +00:00
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:
1 parent
831a2aee9f
commit
1c69fe3447
6 files changed
+414
-8
No files matched your search
@@ -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);
|
||||
|
||||
Reference in new issue
Block a user