Add error for virtual member function without self (#5005)

This tripped over a lowering crash when a member function with self was
declared-but-not-defined, so that's why some test cases were updated to
have (empty) function definitions.

I'll follow-up with/look into a fix for the
self-declared-but-not-defined cases separately.

---------

Co-authored-by: Jon Ross-Perkins <jperkins@google.com>
Co-authored-by: Carbon Infra Bot <carbon-external-infra@google.com>
This commit is contained in:
David Blaikie
2025-02-27 17:01:29 +00:00
committed by GitHub
co-authored by Jon Ross-Perkins Carbon Infra Bot
parent 467e510d40
commit f97f1a3e11
13 changed files with 649 additions and 194 deletions
+5
View File
@@ -278,6 +278,11 @@ static auto BuildFunctionDecl(Context& context,
self_param_id = *i;
}
if (virtual_modifier != SemIR::Function::VirtualModifier::None &&
!self_param_id.has_value()) {
CARBON_DIAGNOSTIC(VirtualWithoutSelf, Error, "virtual class function");
context.emitter().Build(node_id, VirtualWithoutSelf).Emit();
}
// Build the function entity. This will be merged into an existing function if
// there is one, or otherwise added to the function store.
auto function_info =