[408516] No implicit user conversion from or to interfaces
authorMarek Safar <marek.safar@gmail.com>
Mon, 16 Aug 2010 12:52:42 +0000 (13:52 +0100)
committerMarek Safar <marek.safar@gmail.com>
Mon, 16 Aug 2010 12:54:10 +0000 (13:54 +0100)
mcs/errors/gcs0266-6.cs [new file with mode: 0644]
mcs/mcs/convert.cs
mcs/tests/test-794.cs [new file with mode: 0644]
mcs/tests/test-796.cs [new file with mode: 0644]

diff --git a/mcs/errors/gcs0266-6.cs b/mcs/errors/gcs0266-6.cs
new file mode 100644 (file)
index 0000000..efa355d
--- /dev/null
@@ -0,0 +1,22 @@
+// CS0266: Cannot implicitly convert type `System.Collections.Generic.IList<int>' to `Hoge<System.Collections.Generic.IList<int>>'. An explicit conversion exists (are you missing a cast?)
+// Line: 20
+
+using System;
+using System.Collections.Generic;
+
+public class Hoge<T>
+{
+       public static implicit operator Hoge<T> (T value)
+       {
+               return null;
+       }
+}
+
+public class Test
+{
+       static void Main ()
+       {
+               IList<int> x = new List<int> ();
+               Hoge<IList<int>> hoge = x;
+       }
+}
index 95bb9b2b0664f0760896f53f3a597cfc5815fded..78ed4aa7cb64eb001c1223782f8ecaa211fe4183 100644 (file)
@@ -978,6 +978,10 @@ namespace Mono.CSharp {
                                        target = TypeManager.uint64_type;
                        }
 
+                       // Neither A nor B are interface-types
+                       if (source.Type.IsInterface)
+                               return;
+
                        // For a conversion operator to be applicable, it must be possible
                        // to perform a standard conversion from the source type to
                        // the operand type of the operator, and it must be possible
@@ -1007,6 +1011,9 @@ namespace Mono.CSharp {
                                if (t == TypeManager.uint32_type && source.Type == TypeManager.uintptr_type)
                                        continue;
 
+                               if (t.IsInterface)
+                                       continue;
+
                                if (target != t && !ImplicitStandardConversionExists (new EmptyExpression (t), target)) {
                                        if (implicitOnly)
                                                continue;
diff --git a/mcs/tests/test-794.cs b/mcs/tests/test-794.cs
new file mode 100644 (file)
index 0000000..293c0f1
--- /dev/null
@@ -0,0 +1,30 @@
+using System;
+
+internal interface IA
+{
+       void SomeMethod ();
+}
+
+public class C : IA
+{
+       public static void Main ()
+       {
+               new C ().TestCallOnly ();
+       }
+
+       // The body should contain call (not callvirt) only
+       void TestCallOnly ()
+       {
+               int i = 0;
+               var v = new int[0].GetType ();
+
+               new C ().SomeMethod ();
+               this.SomeMethod ();
+               typeof (C).GetType ();
+               new Action (SomeMethod).GetType ();
+       }
+
+       public void SomeMethod ()
+       {
+       }
+}
diff --git a/mcs/tests/test-796.cs b/mcs/tests/test-796.cs
new file mode 100644 (file)
index 0000000..c4eae06
--- /dev/null
@@ -0,0 +1,22 @@
+// Compiler options: -warnaserror -warn:4
+
+// No CS0649 warnings
+
+using System;
+
+[Foo (Product = "Mono")]
+class Program
+{
+       static void Main ()
+       {
+       }
+}
+
+class FooAttribute : Attribute
+{
+       public string Product;
+
+       public FooAttribute ()
+       {
+       }
+}