Skip to content

Question about detecting the best overload #1975

@KAS1990

Description

@KAS1990

Hello. I need to migrate from MVEL to Python script language. I have my own functions, which can be called from script.
One of my function has these two overloads.

public string Foo(string alias, int mode, object defaultValue, bool flag)
{

}
public string Foo(string alias, int mode, string extraParam, object defaultValue)
{

}

If i send to IronPython next code, exception is raised: "Multiple targets could match: Val(str, Int32, object, bool), Val(str, Int32, str, object)"

alias = "D"
mode = 1
defaultValue = "abc"
flag = true
Foo(alias, mode, defaultValue, flag)

It is happened, because "defaultValue" is string, but it can be converted to object, and "flag" is bool and can be converted to object too.
MVEL choose the 1st overload correctly in this case, because MVEL does not try to cast function types to it's parent types.
It is not possible to swap parameters in function Foo, because it is used in production - my target is just change script language without changing functions API. But maybe possible to change type of argument "defaultValue" to something else. Because "Foo" is my function and i can change its code.

Can you suggest any workaround for this case in IronPython?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions