Validate method substitution before definition updates and execution

This commit is contained in:
2026-10-22 14:13:46 +08:00
parent 6b4cce1fee
commit e26e227dd0
14 changed files with 803 additions and 14 deletions
+25 -4
View File
@@ -166,14 +166,29 @@ impl Vm {
for value in arguments {
self.validate_value(value)?;
}
let receiver = arguments
.first()
.or_else(|| {
if required == 0 {
data.defaults().first()
} else {
None
}
})
.and_then(|value| match value {
Value::Object(receiver) => Some(*receiver),
_ => None,
});
if self.source_type_checks
&& let Some(receiver) = receiver
{
self.objects
.check_method_override_call(function, receiver)?;
}
let mut return_type = None;
if self.source_type_checks
&& let Some(signature) = executable.source_signature()
{
let receiver = arguments.first().and_then(|value| match value {
Value::Object(object) => Some(*object),
_ => None,
});
for (index, expected_name) in signature.parameters.iter().enumerate() {
let value = arguments
.get(index)
@@ -262,6 +277,12 @@ impl Vm {
for argument in arguments {
self.validate_value(argument)?;
}
if self.source_type_checks
&& let Some(Value::Object(receiver)) = arguments.first()
{
self.objects
.check_method_override_call(function, *receiver)?;
}
if let Some(arity) = self.objects.call_arity(function)?
&& !arity.accepts(arguments.len())
{