[Mono-bugs] [Bug 80518][Nor] New - GMCS doesn't use constraints from base classes

bugzilla-daemon at bugzilla.ximian.com bugzilla-daemon at bugzilla.ximian.com
Sun Jan 14 10:25:49 EST 2007


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 se at unicom.tomica.ru.

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

--- shadow/80518	2007-01-14 10:25:49.000000000 -0500
+++ shadow/80518.tmp.19947	2007-01-14 10:25:49.000000000 -0500
@@ -0,0 +1,130 @@
+Bug#: 80518
+Product: Mono: Compilers
+Version: 1.2
+OS: 
+OS Details: 
+Status: NEW   
+Resolution: 
+Severity: 
+Priority: Normal
+Component: C#
+AssignedTo: rharinath at novell.com                            
+ReportedBy: se at unicom.tomica.ru               
+QAContact: mono-bugs at ximian.com
+TargetMilestone: ---
+URL: 
+Cc: 
+Summary: GMCS doesn't use constraints from base classes
+
+Description of Problem:
+
+
+Steps to reproduce the problem:
+
+First problem:
+
+try to compile:
+// BEGIN OF CODE
+using System;
+
+namespace test
+{
+    public class BaseClass
+    {
+	public BaseClass()
+	{
+	}
+	public string Hello { get { return "Hello"; } }
+    }
+
+    public abstract class Printer
+    {
+	public abstract void Print<T>(T obj) where T: BaseClass;
+    } 
+    
+    public class PrinterImpl : Printer
+    {
+	public override void Print<T>(T obj) 
+	{
+	    Console.WriteLine(obj.Hello);
+	}
+    }
+
+    public class Starter
+    {
+	public static void Main( string[] args )
+	{
+	    BaseClass bc = new BaseClass();
+	    Printer p = new PrinterImpl();
+	    p.Print<BaseClass>(bc);
+	}	
+    }
+}
+// END OF CODE
+
+It will lead to exception:
+test.cs(22,28): error CS0117: `T' does not contain a definition for `Hello'
+Compilation failed: 1 error(s), 0 warnings
+
+Second problem:
+
+try to compile:
+// BEGIN OF CODE
+using System;
+
+namespace test
+{
+    public class BaseClass
+    {
+	public BaseClass()
+	{
+	}
+	public string Hello { get { return "Hello"; } }
+    }
+
+    public abstract class Printer
+    {
+	public abstract void Print<T>(object x) where T: BaseClass;
+    } 
+    
+    public class PrinterImpl: Printer
+    {
+	public override void Print<T>(object x)
+	{
+	    Console.WriteLine((x as T).Hello);
+	}
+    }
+
+    public class Starter
+    {
+	public static void Main( string[] args )
+	{
+	    BaseClass bc = new BaseClass();
+	    Printer p = new PrinterImpl();
+	    p.Print<BaseClass>(bc);
+	}	
+    }
+}
+// END OF CODE
+It raises the following exception:
+test2.cs(22,27): error CS0413: The as operator requires that the `T' type
+parameter be constrained by a class
+Compilation failed: 1 error(s), 0 warnings
+
+Actual Results:
+It doesn't compile under mono 1.2.2.1.
+
+Expected Results:
+It should compile. At least it compiles under csc 2.0.
+
+How often does this happen? 
+always
+
+Additional Information:
+
+I found two occurances of this problem. More may exists.
+I try to figure out the problem and think that it is in the way generic.cs
+works with GenericConstraints (gc) and Constraints(constraints) in
+TypeParameter class.
+
+(sorry for bad English)


More information about the mono-bugs mailing list