[Mono-bugs] [Bug 37014][Nor] New - Cannot convert from struct to interface problem
bugzilla-daemon@rocky.ximian.com
bugzilla-daemon@rocky.ximian.com
Tue, 21 Jan 2003 13:34:42 -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 seank@users.sf.net.
http://bugzilla.ximian.com/show_bug.cgi?id=37014
--- shadow/37014 Tue Jan 21 13:34:42 2003
+++ shadow/37014.tmp.32728 Tue Jan 21 13:34:42 2003
@@ -0,0 +1,54 @@
+Bug#: 37014
+Product: Mono/MCS
+Version: unspecified
+OS:
+OS Details:
+Status: NEW
+Resolution:
+Severity:
+Priority: Normal
+Component: Misc
+AssignedTo: mono-bugs@ximian.com
+ReportedBy: seank@users.sf.net
+QAContact: mono-bugs@ximian.com
+TargetMilestone: ---
+URL:
+Cc:
+Summary: Cannot convert from struct to interface problem
+
+There is a strange bug that doesn't allow you to reference a struct as its
+interface in some cases. The only way I can explain it is via code:
+
+using System;
+public interface TestInterface
+{
+ int X{ get; }
+}
+
+public struct TestStruct : TestInterface
+{
+ public TestStruct( int x ) { }
+ public int X { get { return 0; } }
+}
+
+public class TestClass
+{
+ public TestClass( TestInterface iface ) { }
+}
+public class Test
+{
+ private TestClass t;
+ Test() { t=new TestClass(new TestStruct(250)); }
+ private TestClass t2=new TestClass(new TestStruct(250));
+}
+
+
+You'll notice that the code inside Test's ctor compiles just fine in MCS,
+but the t2 definition gives an error:
+error CS1502: The best overloaded match for method ' TestClass..ctor
+(TestInterface)' has some invalid arguments
+error CS1503: Argument 1: Cannot convert from 'object' to 'TestInterface'
+
+If you change TestStruct from a struct to a class, everything compiles
+fine, so this seems to be specific to structs that are initialized outside
+of a method.