Fix parse support for 'fn F[];' (#5135)

According to approved syntax at
https://github.com/carbon-language/carbon-lang/blob/trunk/proposals/p3848.md#syntax-defined,
`fn F[]` without explicit parameters should be valid. This makes it
work, then adds some validation to prevent `class C[]` in check.

Note that for `fn`, positional parameters are a TODO -- but this allows
me to test validation in `fn destroy[]` which is rejected, not just a
TODO.
This commit is contained in:
Jon Ross-Perkins
2025-03-18 00:31:17 +00:00
committed by GitHub
parent a584ee120e
commit 8738497301
15 changed files with 402 additions and 93 deletions
+13
View File
@@ -532,4 +532,17 @@ auto GetInstForSpecific(Context& context, SemIR::SpecificId specific_id)
}
}
auto DiagnoseIfGenericMissingExplicitParameters(
Context& context, SemIR::EntityWithParamsBase& entity_base) -> void {
if (!entity_base.implicit_param_patterns_id.has_value() ||
entity_base.param_patterns_id.has_value()) {
return;
}
CARBON_DIAGNOSTIC(GenericMissingExplicitParameters, Error,
"expected explicit parameters after implicit parameters");
context.emitter().Emit(entity_base.last_param_node_id,
GenericMissingExplicitParameters);
}
} // namespace Carbon::Check