fjgandrade / sharpkit

Automatically exported from code.google.com/p/sharpkit
0 stars 0 forks source link

Operator overloading issue #239

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
[JsType(JsMode.Global)]
    public static class Global
    {
        public static void Main()
        {
            MyClass a = new MyClass();
            MyClass b = -a;
            MyClass c = new MyClass();
            c += a;
        }
    }
    [JsType(JsMode.Clr)]
    public class MyClass
    {

        public static MyClass operator +(MyClass value1, MyClass value2)
        {
            return null;
        }
        public static MyClass operator -(MyClass value)
        {
            return null;
        }
    }

This compiles to:
/*Generated by SharpKit 5 v4.30.1000*/
function Main()
{
    var a = new SharpkitTest.MyClass.ctor();
    var b = -a;
    var c = new SharpkitTest.MyClass.ctor();
    SharpkitTest.MyClass.op_Addition(c, a);
};
if (typeof(JsTypes) == "undefined")
    var JsTypes = [];
var SharpkitTest$MyClass =
{
    fullname: "SharpkitTest.MyClass",
    baseTypeName: "System.Object",
    staticDefinition:
    {
        op_Addition: function (value1, value2)
        {
            return null;
        },
        op_UnaryNegation: function (value)
        {
            return null;
        }
    },
    assemblyName: "SharpkitTest",
    Kind: "Class",
    definition:
    {
        ctor: function ()
        {
            System.Object.ctor.call(this);
        }
    }
};
JsTypes.push(SharpkitTest$MyClass);

As you can see, the op_UnaryNegation was not called. For the += operator, the 
op_Addition was called, but the results were not assigned to 'c'

Original issue reported on code.google.com by DanelK...@gmail.com on 24 Oct 2012 at 2:28

GoogleCodeExporter commented 9 years ago

Original comment by DanelK...@gmail.com on 21 Jun 2013 at 4:56

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
The UnaryNegation is now generating correctly. However, there's still an issue 
with at least the += operator

    var a = new SharpKitWebApp3.MyClass.ctor();
    var b = SharpKitWebApp3.MyClass.op_UnaryNegation(a);
    var c = new SharpKitWebApp3.MyClass.ctor();
    SharpKitWebApp3.MyClass.op_Addition(c, a);
    $(document.body).append("Hello world<br/> - ");

It should generate something like

c = SharpKitWebApp3.MyClass.op_Addition(c, a);

/*Generated by SharpKit 5 v5.01.8000*/

Original comment by co...@gravill.com on 3 Jul 2013 at 5:25

GoogleCodeExporter commented 9 years ago

Original comment by DanelK...@gmail.com on 4 Jul 2013 at 6:48

GoogleCodeExporter commented 9 years ago
Verified and fixed. Thanks!

Original comment by DanelK...@gmail.com on 4 Jul 2013 at 7:04