Reject abstract function definitions (#4350)

Not sure about error recovery options - can/should we drop the
definition as a means of recovery when building the SemIR? I guess
probably not, so I guess this change is about right.

Phrasing of the error message I'm certainly open to.
This commit is contained in:
David Blaikie
2024-10-03 22:50:46 +00:00
committed by GitHub
parent 8f547365f5
commit eab5dd6112
3 changed files with 59 additions and 3 deletions
+10
View File
@@ -299,6 +299,16 @@ static auto BuildFunctionDecl(Context& context,
// Write the function ID into the FunctionDecl.
context.ReplaceInstBeforeConstantUse(decl_id, function_decl);
// Diagnose 'definition of `abstract` function' using the canonical Function's
// modifiers.
if (is_definition &&
context.functions().Get(function_decl.function_id).virtual_modifier ==
SemIR::Function::VirtualModifier::Abstract) {
CARBON_DIAGNOSTIC(DefinedAbstractFunction, Error,
"definition of `abstract` function");
context.emitter().Emit(TokenOnly(node_id), DefinedAbstractFunction);
}
// Check if we need to add this to name lookup, now that the function decl is
// done.
if (!name_context.prev_inst_id().is_valid()) {