Hi ironpython,

Here's your Daily Digest of new issues for project "IronPython".

In today's digest:ISSUES

1. [New issue] IronPython ignores overridden TryUnaryOperation of DynamicObject 
that overrides TryUnaryOperation

----------------------------------------------

ISSUES

1. [New issue] IronPython ignores overridden TryUnaryOperation of DynamicObject 
that overrides TryUnaryOperation
http://ironpython.codeplex.com/workitem/33978
User Rauhotz has proposed the issue:

"IronPython (2.7.3) seems to not check the TryUnaryOperation with 
ExpressionType.IsFalse and ExpressionType.IsTrue for performing short-circuit 
evaluation of the logical AND and OR operations.

Here's an example that uses a class that inherits from DynamicObject. In C#, it 
works perfectly, but produces a wrong result if used in an IronPython 
expression. Is that behavior expected or a bug? How can i get IronPython to 
behave the same way as C#?

The class:
public class Dyn : DynamicObject
{
    private readonly string text;

    public Dyn(string text)
    {
        this.text = text;
    }

    public override string ToString()
    {
        return this.text;
    }

    public override bool TryBinaryOperation(BinaryOperationBinder binder, 
object arg, out object result)
    {
        result = new Dyn(this + " " + binder.Operation + " " + arg);
        return true;
    }

    public override bool TryUnaryOperation(UnaryOperationBinder binder, out 
object result)
    {
        switch (binder.Operation)
        {
            case ExpressionType.IsFalse:
            case ExpressionType.IsTrue:
                result = false;
                return true;
        }

        return base.TryUnaryOperation(binder, out result);
    }
}

The usage:
dynamic a = new Dyn("a");
dynamic b = new Dyn("b");
dynamic c = new Dyn("c");

var correct = a && b || c;

var engine = Python.CreateEngine();
var scope = engine.CreateScope();
scope.SetVariable("a", a);
scope.SetVariable("b", b);
scope.SetVariable("c", c);
var incorrect = engine.Execute("a and b or c", scope);

Console.WriteLine("Correct: " + correct);
Console.WriteLine("Incorrect: " + incorrect);

Prints:
Correct: a And b Or c
Incorrect: b
"
----------------------------------------------



----------------------------------------------
You are receiving this email because you subscribed to notifications on 
CodePlex.

To report a bug, request a feature, or add a comment, visit IronPython Issue 
Tracker. You can unsubscribe or change your issue notification settings on 
CodePlex.com.
_______________________________________________
Ironpython-users mailing list
[email protected]
http://mail.python.org/mailman/listinfo/ironpython-users

Reply via email to