[Mono-bugs] [Bug 40793][Nor] New - mcs doesn't detect interface member name collisions

bugzilla-daemon@rocky.ximian.com bugzilla-daemon@rocky.ximian.com
Fri, 4 Apr 2003 15:48:37 -0500 (EST)


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 eureko@grmexico.com.mx.

http://bugzilla.ximian.com/show_bug.cgi?id=40793

--- shadow/40793	Fri Apr  4 15:48:37 2003
+++ shadow/40793.tmp.21342	Fri Apr  4 15:48:37 2003
@@ -0,0 +1,94 @@
+Bug#: 40793
+Product: Mono/MCS
+Version: unspecified
+OS: Mandrake 9.0
+OS Details: 
+Status: NEW   
+Resolution: 
+Severity: 
+Priority: Normal
+Component: Misc
+AssignedTo: mono-bugs@ximian.com                            
+ReportedBy: eureko@grmexico.com.mx               
+QAContact: mono-bugs@ximian.com
+TargetMilestone: ---
+URL: 
+Cc: 
+Summary: mcs doesn't detect interface member name collisions
+
+Description of Problem: mcs doesn't drop with an error when there is a
+interface member name collision
+
+Steps to reproduce the problem: Run the provided test
+
+Actual Results: The code compiles, without an error, or at least, a warning
+
+Expected Results: A warning or error
+
+How often does this happen? Always
+
+Additional Information:
+/*
+Name collision test
+Gustavo Ramos (eureko@grmexico.com.mx)
+This test shows a name collision not validated by mono. Run it, and see
+comments at the end.
+*/
+using System;
+
+namespace Eureko.Samples {
+
+interface ISerializable {
+	void SaveData();
+}
+
+interface IDataStore {
+	void SaveData();
+}
+
+class Test : ISerializable, IDataStore {
+	public void SaveData() {
+		Console.WriteLine("SaveData executed");
+	}
+}
+
+class NameCollisions {
+	public static void Main() {
+		Test test = new Test();
+		
+		Console.Write("Calling test.SaveData() without casting...\t");
+		test.SaveData();
+		
+		Console.Write("Calling ((ISerializable)test).SaveData()...\t");
+		((ISerializable)test).SaveData();
+
+		Console.Write("Calling ((IDataStore)test).SaveData()...\t");
+		((IDataStore)test).SaveData();
+	}
+}
+
+}
+/*
+This code compiles, and runs, but mono doesn't figure out that both
+SaveData methods
+aren't implemented, just one, and it can't tell which one is, since its
+name isn't
+explicitly qualified. Tom Archer writes on his book "Inside C#", 1st
+edition, p.177:
+
+"At the time of this writing, this code does compile. However, I'm told
+that in a future
+build of the C# compiler, the code will result in a compile-time error
+because of the
+ambiguity of the implemented SaveData method. Regardless of whether this code
+compiles, you'd have a problem at run time because the resulting behavior
+of calling
+the SaveData method would not be clear to the programmer attempting to use the
+class. Would you get the SaveData that serializes the object to disk, or
+would you get
+the data that saves to a database?
+
+This test is a modified version of the sample provided by Tom Archer in his
+book
+"Inside C#", and it is only intended to help debug the mono compiler.
+*/