[Mono-bugs] [Bug 74773][Nor] New - casting to interface doesn't pick up overridden methods
bugzilla-daemon@bugzilla.ximian.com
bugzilla-daemon@bugzilla.ximian.com
Fri, 29 Apr 2005 18:49:58 -0400 (EDT)
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 vgough@pobox.com.
http://bugzilla.ximian.com/show_bug.cgi?id=74773
--- shadow/74773 2005-04-29 18:49:58.000000000 -0400
+++ shadow/74773.tmp.14791 2005-04-29 18:49:58.000000000 -0400
@@ -0,0 +1,93 @@
+Bug#: 74773
+Product: Mono: Compilers
+Version: 1.1
+OS:
+OS Details: Suse 9.2
+Status: NEW
+Resolution:
+Severity:
+Priority: Normal
+Component: C#
+AssignedTo: mono-bugs@ximian.com
+ReportedBy: vgough@pobox.com
+QAContact: mono-bugs@ximian.com
+TargetMilestone: ---
+URL:
+Cc:
+Summary: casting to interface doesn't pick up overridden methods
+
+Description of Problem:
+
+An interface hierarchy seems to confuse mcs. It proceeds without any errors, but
+seems to generate incorrect code. A derived class's overridden method is not called
+when it should be. I've reduced the problem to a small test case.
+
+Steps to reproduce the problem:
+Build the following code. With mcs 1.1.6, it produces:
+WorkingTest -- Passed
+FailingTest -- FAILED
+
+I believe both tests should succeed -- or if this is not possible for some reason, then
+mcs should provide an error message.
+
+
+// Some interfaces, one is a superset of the other
+public interface Node
+{
+ int GetStat();
+}
+public interface FileNode : Node
+{
+ int NotUsed();
+}
+
+// Some basic implementations, one is a superset of the other
+public class GenericNode : Node
+{
+ public virtual int GetStat() { return 0; }
+}
+
+public class GenericFileNode : GenericNode , FileNode
+{
+ public virtual int NotUsed() { return -1; }
+}
+
+
+// Now the ability to override a method depends on if we specify again that we
+// implement an interface -- although we must because we derive from a class
+// that does.
+public class WorkingTest : GenericFileNode , FileNode
+{
+ public override int GetStat() { return 42; }
+}
+
+public class FailingTest : GenericFileNode
+{
+ // This never gets called, but it builds, so what did we override?!!!
+ public override int GetStat() { return 42; }
+}
+
+public class TestWrapper
+{
+ static bool Test(Node inst, string name)
+ {
+ if(inst.GetStat() == 42)
+ {
+ System.Console.WriteLine("{0} -- Passed", name);
+ return true;
+ } else
+ {
+ System.Console.WriteLine("{0} -- FAILED", name);
+ return false;
+ }
+ }
+
+ public static int Main()
+ {
+ if( Test(new WorkingTest(), "WorkingTest")
+ && Test(new FailingTest(), "FailingTest") )
+ return 0; // everything worked
+ else
+ return 1;
+ }
+}