Skip to content
This repository has been archived by the owner on Sep 14, 2018. It is now read-only.

When initializing multiple properties, exception is thrown for wrong assignment #1177

Open
DanielSWolf opened this issue Mar 4, 2015 · 3 comments

Comments

@DanielSWolf
Copy link

Consider the following C# class:

public class Foo {
    public bool MyBool { get; set; }
    public int MyInt { get; set; }
}

The following IronPython tries to create an instance of Foo, using the keyword argument syntax to set its properties:

foo = Foo(
    MyBool = 1,     # correct, passing int instead of Bool
    MyInt = "Oops"  # incorrect, passing string instead of int
)

The first assignment is correct: we're passing an int, which can be converted to a bool. The second assignment is incorrect: we're passing a string instead of an int.

That second assignment results in a BaseException with the following message:

expected bool, got int

However, that message describes the first (legal) assignment, while it should be describing the second (illegal) assignment.

It seems to me that the code generating the message just describes the first assignment whose type isn't a perfect match rather than the assignment that actually failed.

@paweljasinski: I see that you're currently re-writing the error reporting logic: paweljasinski/IronLanguages@5aacd8d. Will that fix this issue, too?

@paweljasinski
Copy link
Contributor

with my patch the error is:

TypeError: expected bool, got int, at arg: 0
expected int, got str, at arg: 1

which can be confusing as well. The first message is effectively false positive. At least it doesn't hide the real problem.

@paweljasinski
Copy link
Contributor

see also #1151

@slide
Copy link
Contributor

slide commented Aug 9, 2016

@paweljasinski Any updates on this one? Can you remove the "untriaged" label once you've looked and determined what needs to be done?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants