mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-09-24 22:02:23 +01:00
Support signature mismatch between virtual fn and override fn. (#7198)
For now, hide `override fn`s from name lookup, so that the base class version is always used, as the derived-class version does not have its own vptr entry and so would not do the right thing if a further-derived class adds a new override. This is implemented via a new access kind of `Hidden`. When checking the overriding function, pass in the expected `Self` type and check the `self` parameter against that; the signature that we generate for the thunk in the derived class is the base class signature with the `self` parameter's type changed to the derived class. When we generate a thunk for a virtual function, the thunk is assigned a `virtual_index`, and the virtual function itself is not. When the thunk makes a direct call to the virtual function, recognize this situation by checking for a `virtual_index`, and perform a non-virtual call if there isn't one. Assisted-by: Gemini via Antigravity
This commit is contained in:
@@ -304,11 +304,12 @@ auto CheckFunctionTypeMatches(Context& context,
|
||||
const SemIR::Function& new_function,
|
||||
const SemIR::Function& prev_function,
|
||||
SemIR::SpecificId prev_specific_id,
|
||||
bool check_syntax, bool check_self, bool diagnose)
|
||||
-> bool {
|
||||
bool check_syntax,
|
||||
SemIR::TypeId self_type_override_id,
|
||||
bool diagnose) -> bool {
|
||||
if (!CheckRedeclParamsMatch(context, DeclParams(new_function),
|
||||
DeclParams(prev_function), prev_specific_id,
|
||||
diagnose, check_syntax, check_self)) {
|
||||
diagnose, check_syntax, self_type_override_id)) {
|
||||
return false;
|
||||
}
|
||||
if (!CheckFunctionReturnTypeMatches(context, new_function, prev_function,
|
||||
|
||||
Reference in New Issue
Block a user