[Mono-bugs] [Bug 77593][Nor] New - Mixing implicit operator type conversions with sub-classes fails in mono

bugzilla-daemon at bugzilla.ximian.com bugzilla-daemon at bugzilla.ximian.com
Sat Feb 18 15:20:02 EST 2006


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 peter at drealm.org.uk.

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

--- shadow/77593	2006-02-18 15:20:02.000000000 -0500
+++ shadow/77593.tmp.20451	2006-02-18 15:20:02.000000000 -0500
@@ -0,0 +1,103 @@
+Bug#: 77593
+Product: Mono: Compilers
+Version: unspecified
+OS: 
+OS Details: WinXPSP2
+Status: NEW   
+Resolution: 
+Severity: 
+Priority: Normal
+Component: C#
+AssignedTo: rharinath at novell.com                            
+ReportedBy: peter at drealm.org.uk               
+QAContact: mono-bugs at ximian.com
+TargetMilestone: ---
+URL: 
+Cc: 
+Summary: Mixing implicit operator type conversions with sub-classes fails in mono
+
+Please fill in this template when reporting a bug, unless you know what you
+are doing.
+Description of Problem:
+
+An abstract class is extended by sub-classes.  The abstract class has a
+static implicit operator method to convert another class to the abstract
+class.  That method chooses one of the sub-classes based on attributes of
+the other class.  However, one of the sub-classes has a protected
+constructor, so the abstract (parent) class cannot simply create a new
+instance.
+
+All sub-classes provide implicit operator conversion from the other class
+to themselves.
+
+On MSVC#, this arrangement compiles without warning or error and the
+resulting code works.  (The VC# object browser has some difficulty,
+however, displaying the class.)
+
+In mono, gmsc produces the following output:
+test1.cs(15,26): warning CS0108: `plj.realClass1.implicit operator
+plj.realClass1(plj.fromClass)' hides inherited member `plj.aClass.mplicit'.
+Use the new keyword if hiding was intended
+test1.cs(8,26):: `plj.aClass.implicit operator plj.aClass(plj.fromClass)',
+name of symbol related to previous warning
+test1.cs(15,26): error CS0115: `plj.realClass1.implicit operator
+plj.realClass1(plj.fromClass)': no suitable method found to override
+test1.cs(26,26): warning CS0108: `plj.aClass2.implicit operator
+plj.aClass2(plj.fromClass)' hides inherited member `plj.aClass.mplicit'.
+Use the new keyword if hiding was intended
+test1.cs(8,26):: `plj.aClass.implicit operator plj.aClass(plj.fromClass)',
+name of symbol related to previous warning
+test1.cs(26,26): error CS0115: `plj.aClass2.implicit operator
+plj.aClass2(plj.fromClass)': no suitable method found to override
+
+
+Steps to reproduce the problem:
+1. Compile the sample source
+
+Actual Results:
+Compilation fails with above error.
+
+Expected Results:
+Compilation to succeed.
+
+How often does this happen? 
+Every time.
+
+Additional Information:
+Sample source:
+using System;
+
+namespace plj
+{
+	public abstract class aClass
+	{
+		protected aClass() { }
+		public static implicit operator aClass(fromClass o)
+			{ return (o.f < 0) ? (aClass)(realClass1)o : (aClass)(aClass2)o; }
+	}
+	
+	public class realClass1 : aClass
+	{
+		public realClass1() { }
+		public static implicit operator realClass1(fromClass o)
+		{
+			if (o.f >= 0) throw new Exception("That shouldn't happen");
+			return new realClass1();
+		}
+	}
+	
+	public abstract class aClass2 : aClass
+	{
+		protected aClass2() { }
+		
+		public static implicit operator aClass2(fromClass o)
+		{
+			if (o.f < 0) throw new Exception("That shouldn't happen, either");
+			return new realClass2();
+		}
+	}
+	
+	public class realClass2 : aClass2 { public realClass2() { } }
+	
+	public class fromClass { public int f; }
+}


More information about the mono-bugs mailing list