[Mono-bugs] [Bug 26204] New - Problem when finding an inherited method
bugzilla-daemon@rocky.ximian.com
bugzilla-daemon@rocky.ximian.com
13 Jun 2002 10:40:14 -0000
Please do not reply to this email- if you want to comment on the bug, go to the
URL shown below and enter your comments there.
Changed by lupus@ximian.com.
http://bugzilla.ximian.com/show_bug.cgi?id=26204
--- shadow/26204 Thu Jun 13 06:40:14 2002
+++ shadow/26204.tmp.6611 Thu Jun 13 06:40:14 2002
@@ -0,0 +1,71 @@
+Bug#: 26204
+Product: Mono/MCS
+Version: unspecified
+OS: other
+OS Details:
+Status: NEW
+Resolution:
+Severity:
+Priority: Normal
+Component: Misc
+AssignedTo: mono-bugs@ximian.com
+ReportedBy: lupus@ximian.com
+QAContact: mono-bugs@ximian.com
+TargetMilestone: ---
+URL:
+Cc:
+Summary: Problem when finding an inherited method
+
+This bug was posted by Jeroen Frijters" <mono@jeroen.nu> on mono-list.
+If you compile the attached files, like this:
+
+mcs --target library testdll.cs
+mcs -r testdll.dll usedll.cs
+
+And then disassemble usedll.exe, you'll see that ToString calls
+[mscorlib]System.Object::ToString() instead of
+[testdll]testdll::ToString() (as csc does). This will cause version
+problems, if a new version of the dll overrides ToString, it will not be
+called.
+
+The problem is that, AFAIK, Reflection.Emit doesn't have the ability to
+create a MethodInfo for an inherited method, but I hope I'm wrong.
+
+== cut testdll.cs
+public class testdll
+{
+}
+
+== cut usedll.cs
+class test : testdll
+{
+ public static void Main()
+ {
+ System.Console.WriteLine("hello from test: " + new test());
+ }
+
+ public override string ToString()
+ {
+ return "it's me: " + base.ToString();
+ }
+}
+
+My reply:
+Interesting bug. I added support in the runtime to execute code like
+that (that reference methods in an inherited class instead of in the
+declaring class), but I didn't understand why one would produce such code
+and how until your sample test. I even asked about the issue on the
+DOTNET list but no one replied. Thanks!
+
+The Reflection API provides support for such cases in this way: if you
+call FindMembers() for the ToString() method starting from the testdll
+type (the base type for type test), you'll get a MethodInfo that has:
+
+ DeclaringType: System.Object
+ ReflectedType: testdll
+
+So the info is there in the first place. My guess is that mcs sets the
+DeclaredOnly binding flag and loops until it finds the method, so
+ReflectedType is always equal to the DeclaringType. After mcs is fixed
+I'll change our Reflection.Emit code to take into account the
+ReflectedType when emitting the memberref token.