-
Notifications
You must be signed in to change notification settings - Fork 350
Misleading ArgumentTypeException message when calling C# method #1660
Comments
Are you sure your minimal example is correct? Seems to me like |
I'm pretty confident it is correct, yes. If you change Of course, passing EDIT: furthermore, if you change the Python part to leave out the third parameter, again everything works flawlessly. |
Ah I see. I ran a few more tests and it seems to be an issue only when using char and float together in the definition. Seems like a bug. Here's the amended test code: class Program
{
static void Main(string[] args)
{
var engine = IronPython.Hosting.Python.CreateEngine();
var foo = new Foo();
var locals = new Dictionary<string, object> { { "foo", foo } };
var scope = engine.CreateScope(locals);
var result = engine.Execute(@"
print foo.Bar(x='a')
print foo.Bar(y=7.2)
print foo.Bar(x='a', y=7.2)
", scope);
Console.ReadLine();
}
}
public class Foo
{
public string Bar(char x='0', float y=0) => string.Format("{0}, {1}", x, y);
} |
Yes, to my untrained eye it really does look like some weird interaction taking place when a The first parameter to |
After doing a bit of digging, it appears that the DLR uses different "narrowing levels" to figure out what type conversions are allowed. Looking at |
This issue was moved to IronLanguages/ironpython2#15 |
Hello, this is not a bug per se, but rather something I just noticed. I'm including a minimal example console app that will throw with the unexpected message Expected Char, got str, further discussion below the code.
By the way, this is IronPython v2.7.7 on .NET 4.
Now, the signature of method
Bar
of classFoo
is of course wrong, in that the last parameter should bedouble
rather thanfloat
(or we would need to pass in aSystem.Single
to begin with).The exception message is a bit misleading, though: Expected Char, got str is not really the hint I would expect. I scratched my head for a minute before realizing I had made a dumb mistake. It seems like it should say something along the lines of Expected Single, got Double.
Just thought I would let you guys know.
The text was updated successfully, but these errors were encountered: