Saltarelle / SaltarelleCompiler

C# to JavaScript compiler – Now http://bridge.net
http://saltarelle-compiler.com
Other
297 stars 74 forks source link

InlineCode GeneratedMethodName on imported interfaces #284

Open n9 opened 10 years ago

n9 commented 10 years ago

I have an [Imported] interface and I am getting:

The member Test.get_X needs a GeneratedMethodName property for its [InlineCodeAttribute] because it is an interface method.

Is GeneratedMethodName really required also for [Imported] interfaces?

erik-kallen commented 10 years ago

No, that probably is a bug. Can you send the entire interface definition?

n9 commented 10 years ago
[Imported]
public interface Test
{
    int X { [InlineCode("{this}[0]")] get; }
}
erik-kallen commented 10 years ago

Actually, I mixed up [Imported] and [Serializable].

Yes, GeneratedMethodName is currently required for all interface methods, the intended use for being able to specify inline code on interface methods at all is to enable eg. IComparable, where call to the interface methods must go to a global method, which will in turn (sometimes) delegate to the implementation method.

n9 commented 10 years ago

Not sure whether I understand properly: For what is the GeneratedMethodName used in my imported interface? If it is required for something, could it just take as a default value "get_X" or something similar?

erik-kallen commented 10 years ago

The problem is that your imported interface can be implemented:

class C : Test {
    public int X { get { return 42; } }
}

and the implementer/caller expects that ((Test)new C()).X should return 42.

n9 commented 10 years ago

But in case it contains [InlineCode], should it return error when being implemented? Could GeneratedMethodName have some default value e.g. name of the member?

erik-kallen commented 10 years ago

I don't like the idea of a default value for the GeneratedMethodName, that name has to be used (directly or indirectly) by the code specified as the inline implementation.

But I guess we could allow methods for imported methods to not specify it, and then make it an error for non-imported types to implement those interfaces.

n9 commented 10 years ago

Ok.