sonygod / sharpkit

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

Incorrect compiled code when calling an overloaded method that implements an interface #106

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Let's say I have an interface IShape that has a single method Rotate. I have a 
Rectangle class that implements IShape and also adds an overloaded Rotate 
method. Now I use the Rectangle class as an IShape and call Rotate. The 
compiler emits two method names for Rectange: Rotate$Int32 and 
Rotate$Int32$Int32 but fails to emit a Rotate method. This results in a 
JavaScript error when calling IShape.Rotate since it doesn't exist.

I think the correct fix would be to preserve method names that are interface 
implementations and not add the overloaded parameters to the name.

Here's the C# code:

using SharpKit.JavaScript;
using SharpKit.Html4;
using SharpKit.jQuery;

namespace MyNamespace
{
    [JsType(JsMode.Clr)]
    public interface IShape
    {
        void Rotate(int newDirection);
    }

    [JsType(JsMode.Clr)]
    public class Rectangle : IShape
    {
        public void Rotate(int newDirection)
        {
            this.Rotate(newDirection);
        }

        public void Rotate(int newDirection, int currentDirection)
        {
        }
    }

    [JsType(JsMode.Clr)]
    public class Canvas
    {
        public void Layout()
        {
            IShape rect = new Rectangle();
            rect.Rotate(90);
        }
    }
}

Here's the compiled code:

/*@Generated by SharpKit v4.23.4000*/
if(typeof(JsTypes) == "undefined")
    JsTypes = [];
var 
MyNamespace$IShape={fullname:"MyNamespace.IShape",baseTypeName:"System.Object",a
ssemblyName:"7f520817fe1c4234af725dc812dc73bc",Kind:"Interface"};
JsTypes.push(MyNamespace$IShape);
var MyNamespace$Rectangle=
{
    fullname:"MyNamespace.Rectangle",
    baseTypeName:"System.Object",
    assemblyName:"7f520817fe1c4234af725dc812dc73bc",
    interfaceNames:["MyNamespace.IShape"],
    Kind:"Class",
    definition:
    {
        ctor:function()
        {
            System.Object.ctor.call(this);
        },
        Rotate$$Int32:function(newDirection)
        {
            this.Rotate$$Int32(newDirection);
        },
        Rotate$$Int32$$Int32:function(newDirection,currentDirection)
        {
        }
    }
};
JsTypes.push(MyNamespace$Rectangle);
var MyNamespace$Canvas=
{
    fullname:"MyNamespace.Canvas",
    baseTypeName:"System.Object",
    assemblyName:"7f520817fe1c4234af725dc812dc73bc",
    Kind:"Class",
    definition:
    {
        ctor:function()
        {
            System.Object.ctor.call(this);
        },
        Layout:function()
        {
            var rect=new MyNamespace.Rectangle.ctor();
            rect.Rotate(90);
        }
    }
};
JsTypes.push(MyNamespace$Canvas);

Original issue reported on code.google.com by warthog1...@gmail.com on 28 Feb 2012 at 7:22

GoogleCodeExporter commented 9 years ago
Dan-el, this is Justin Rockwood, by the way. I thought it made more sense to 
log bugs directly instead of via email. That way I can track when they're 
fixed. :)

Original comment by warthog1...@gmail.com on 28 Feb 2012 at 7:24

GoogleCodeExporter commented 9 years ago
Oh, and I just noticed a bug in my example code. Rotate$Int32 is calling itself 
instead of the overloaded method. However, that doesn't effect this bug.

Original comment by warthog1...@gmail.com on 28 Feb 2012 at 7:25

GoogleCodeExporter commented 9 years ago
Ok, I'll check it out thanks!

Original comment by DanelK...@gmail.com on 29 Feb 2012 at 10:27

GoogleCodeExporter commented 9 years ago

Original comment by yvan.rod...@gmail.com on 12 Jan 2013 at 11:51