2007-01-16 Sergey P. Kondratyev <se@unicom.tomica.ru>
authorMiguel de Icaza <miguel@gnome.org>
Tue, 16 Jan 2007 16:14:05 +0000 (16:14 -0000)
committerMiguel de Icaza <miguel@gnome.org>
Tue, 16 Jan 2007 16:14:05 +0000 (16:14 -0000)
* expression.cs (As.DoResolve): Use GenericConstraints instead of
Constraints, solves the problem where the compiler incorrectly
reported that a type parameter was not constrained to a class (Bug
80518)

2007-01-16  Sergey P. Kondratyev <se@unicom.tomica.ru>

* generic.cs (TypeParameter.FindMembers): Use the generic
constraints, not the constraints to check for methods (first fix
of 80518).

svn path=/trunk/mcs/; revision=71148

mcs/gmcs/ChangeLog
mcs/gmcs/generic.cs
mcs/mcs/ChangeLog
mcs/mcs/expression.cs
mcs/tests/gtest-303.cs [new file with mode: 0644]
mcs/tests/gtest-304.cs [new file with mode: 0644]

index 9486896281d7eaa8b7b692fe7d3516bf6bace301..382d5471cb61b708edac46377dc68776f2a98154 100644 (file)
@@ -1,3 +1,9 @@
+2007-01-16  Sergey P. Kondratyev <se@unicom.tomica.ru>
+
+       * generic.cs (TypeParameter.FindMembers): Use the generic
+       constraints, not the constraints to check for methods (first fix
+       of 80518).
+
 2006-12-30  Marek Safar  <marek.safar@gmail.com>
 
        * cs-parser.jay: Better syntax errors handling.
index b75b603d295d3d632b991773039f878eec285206..7b5f74c2e05b8b3e4fbdc8de4c2afb657f80d088 100644 (file)
@@ -901,7 +901,7 @@ namespace Mono.CSharp {
                public MemberList FindMembers (MemberTypes mt, BindingFlags bf,
                                               MemberFilter filter, object criteria)
                {
-                       if (constraints == null)
+                       if (gc == null)
                                return MemberList.Empty;
 
                        ArrayList members = new ArrayList ();
index 9b4aa24ca05a35576c618c0e3f957b10f292bcf6..245620f409bfb66b634d8838d43b8c2b7de18de3 100644 (file)
@@ -1,3 +1,10 @@
+2007-01-16  Sergey P. Kondratyev <se@unicom.tomica.ru>
+
+       * expression.cs (As.DoResolve): Use GenericConstraints instead of
+       Constraints, solves the problem where the compiler incorrectly
+       reported that a type parameter was not constrained to a class (Bug
+       80518)
+
 2007-01-14  Marek Habersack  <grendello@gmail.com>
 
        * doc-bootstrap.cs: Fix a compilation problem in the bootstrap phase.
index b9603f1dbc30ba5623de169ac4f1d877046bf73f..685673069c1581165be9b9c734f55500557dc693 100644 (file)
@@ -1262,7 +1262,7 @@ namespace Mono.CSharp {
                        //
                        TypeParameterExpr tpe = probe_type_expr as TypeParameterExpr;
                        if (tpe != null){
-                               Constraints constraints = tpe.TypeParameter.Constraints;
+                               GenericConstraints constraints = tpe.TypeParameter.GenericConstraints;
                                bool error = false;
                                
                                if (constraints == null)
diff --git a/mcs/tests/gtest-303.cs b/mcs/tests/gtest-303.cs
new file mode 100644 (file)
index 0000000..3f57bb3
--- /dev/null
@@ -0,0 +1,39 @@
+//
+// Test case from bug 80518
+//
+
+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);
+       }       
+    }
+}
diff --git a/mcs/tests/gtest-304.cs b/mcs/tests/gtest-304.cs
new file mode 100644 (file)
index 0000000..8f7c71f
--- /dev/null
@@ -0,0 +1,38 @@
+//
+// Second test from bug 80518
+//
+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);
+       }       
+    }
+}