Yield Type_Error on wrong self argument

This commit is contained in:
Jaroslav Tulach 2024-02-22 16:20:01 +01:00
parent 6b41eaa036
commit e279793d95
2 changed files with 15 additions and 0 deletions

View File

@ -850,6 +850,17 @@ public abstract class InvokeMethodNode extends BaseNode {
instanceof Function function) {
if (function.getSchema().getArgumentsCount() == arguments.length - 1
&& "self".equals(function.getSchema().getArgumentInfos()[0].getName())) {
var ok = false;
try {
if (interop.isMetaInstance(arguments[0], arguments[1])) {
ok = true;
}
} catch (UnsupportedMessageException ex) {
}
if (!ok) {
var err = ctx.getBuiltins().error().makeTypeError(arguments[0], arguments[1], "self");
throw new PanicException(err, this);
}
var lessArgs = Arrays.copyOfRange(arguments, 1, arguments.length);
var lessSchema =
Arrays.copyOfRange(

View File

@ -1,4 +1,5 @@
from Standard.Base import all
import Standard.Base.Errors.Common.Type_Error
from Standard.Test import all
from project.Data.Polyglot_Extensions import all
@ -52,6 +53,9 @@ add_specs suite_builder = suite_builder.group "Polyglot" group_builder->
v = IntHolder.value_plus hold 3
v . should_equal 45
group_builder.specify "extension method (static syntax) checks self type" <|
Test.expect_panic Type_Error (IntHolder.value_plus 10 12)
group_builder.specify "static extension method on IntHolder" <|
hold = IntHolder.create (6 * 7)
hold.value . should_equal 42