[Mono-dev] Methods implementing interfaces are emitted twice
Zac Bowling
zac at zacbowling.com
Mon May 29 20:31:07 EDT 2006
One is just an implicate interface override and the other is just an
override on object's version of to string. There really isn't any harm
in having the two versions since they both do the same thing but its
easily fixable.
But if you they did do something different you could access the the
IConvertable version by casting it to that interface to
(somestring.ToString(..) instead of
((IConvertable)something).ToString(..)).
It's completely reproducible outside of mscorlib if you do something
like
public class MyStuff : IConvertable
{
...
public override string ToString(FormatProvider fm)
{
...
}
string IConvertable.ToString(FormatProvider fm)
{
...
}
...
}
On Mon, 2006-05-29 at 17:05 +0200, Gert Driesen wrote:
> Hi,
>
> I noticed that methods that implement an interface member are emitted twice
> by mcs: once as a normal method and once as an explicit inteface
> implementation.
>
> For example, take a look at the IL for System.String in mscorlib. It
> contains the following methods:
>
> // method line 741
> .method private final virtual hidebysig newslot
> instance default string System.IConvertible.ToString (class
> System.IFormatProvider format) cil managed
> {
> // Method begins at RVA 0xa740
> .override class System.IConvertible::ToString
> // Code size 2 (0x2)
> .maxstack 8
> IL_0000: ldarg.0
> IL_0001: ret
> } // end of method String::instance default string
> System.IConvertible.ToString (class System.IFormatProvider format)
>
> .method public hidebysig
> instance default string ToString (class System.IFormatProvider
> provider) cil managed
> {
> // Method begins at RVA 0xb7ec
> // Code size 2 (0x2)
> .maxstack 8
> IL_0000: ldarg.0
> IL_0001: ret
> } // end of method String::instance default string ToString (class
> System.IFormatProvider provider)
>
> while there should have only been this method:
>
> .method public hidebysig newslot virtual final
> instance string ToString(class System.IFormatProvider
> provider) cil managed
> {
> .maxstack 8
> IL_0000: ldarg.0
> IL_0001: ret
> }
>
> Problem is that I can only see evidence of this in mscorlib, and I cannot
> reproduce it using another custom-built assembly.
>
> Can someone look into this ?
>
> As a result of this issue, we get quite some bogus warnings in the class
> status pages for the NET_1_1 profile
> (http://mono.ximian.com/class-status/mono-HEAD-vs-fx-1-1/class-status-mscorl
> ib.html), as corcompare is complaining that the Mono methods are not virtual
> final.
>
> As for the class status page warnings: there's an easy workaround to get rid
> of the warnings, but it would need a rebuild of the masterinfos for MS.NET.
>
> Let me know if you want me to submit a patch for that workaround (but I'd
> prefer a real fix for the issue instead).
>
> Gert
>
> _______________________________________________
> Mono-devel-list mailing list
> Mono-devel-list at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-devel-list
>
--
Zac Bowling <zac at zacbowling.com>
More information about the Mono-devel-list
mailing list