Probing dynamic compatibility is identical to object
authorMarek Safar <marek.safar@gmail.com>
Tue, 24 Aug 2010 14:23:50 +0000 (15:23 +0100)
committerMarek Safar <marek.safar@gmail.com>
Wed, 25 Aug 2010 09:21:12 +0000 (10:21 +0100)
mcs/errors/dcs1980.cs
mcs/errors/dcs1981.cs [new file with mode: 0644]
mcs/mcs/convert.cs
mcs/mcs/expression.cs
mcs/mcs/report.cs
mcs/mcs/typemanager.cs
mcs/tests/dtest-023.cs [new file with mode: 0644]
mcs/tests/ver-il-dmcs.xml

index 9a19b3c0ea68fd166c5ab04455db27d792ff90bd..643039ac9231499593949e84c3b7c867d2cf235d 100644 (file)
@@ -1,4 +1,4 @@
-// CS19806: Dynamic keyword requires `System.Runtime.CompilerServices.DynamicAttribute' to be defined. Are you missing System.Core.dll assembly reference?
+// CS1980: Dynamic keyword requires `System.Runtime.CompilerServices.DynamicAttribute' to be defined. Are you missing System.Core.dll assembly reference?
 // Line: 8
 // Compiler options: -noconfig
 
diff --git a/mcs/errors/dcs1981.cs b/mcs/errors/dcs1981.cs
new file mode 100644 (file)
index 0000000..6507a09
--- /dev/null
@@ -0,0 +1,12 @@
+// CS1981: Using `is' to test compatibility with `dynamic' is identical to testing compatibility with `object'
+// Line: 10
+// Compiler options: -warnaserror
+
+class C
+{
+       public static void Main ()
+       {
+               object o = null;
+               bool b = o is dynamic;
+       }
+}
index a543ce73f0b879bba99de21a9371a7a7d39fd640..ce2b8ecb675a57f43d148092c33b89adccef975f 100644 (file)
@@ -1655,9 +1655,9 @@ namespace Mono.CSharp {
                                return source == null ? EmptyExpression.Null : new UnboxCast (source, target_type);
 
                        //
-                       // From object to any reference type or value type (unboxing)
+                       // From object or dynamic to any reference type or value type (unboxing)
                        //
-                       if (source_type == TypeManager.object_type)
+                       if (source_type == TypeManager.object_type || source_type == InternalType.Dynamic)
                                return
                                        source == null ? EmptyExpression.Null :
                                        target_is_value_type ? new UnboxCast (source, target_type) :
index 38ec8e37d2bf11dfd594da791e9e1a4ac971fc97..ada2a1a6aa86714df85898d5d4279caead24f638 100644 (file)
@@ -1342,6 +1342,12 @@ namespace Mono.CSharp {
                                if (TypeManager.IsGenericParameter (t))
                                        return ResolveGenericParameter (ec, d, (TypeParameterSpec) t);
 
+                               if (t == InternalType.Dynamic) {
+                                       ec.Report.Warning (1981, 3, loc,
+                                               "Using `{0}' to test compatibility with `{1}' is identical to testing compatibility with `object'",
+                                               OperatorName, t.GetSignatureForError ());
+                               }
+
                                if (TypeManager.IsStruct (d)) {
                                        if (Convert.ImplicitBoxingConversion (null, d, t) != null)
                                                return CreateConstantResult (ec, true);
index 236446ace99b46e51447f2318499389926caa67f..ed57dc23a388e646bd8f623c32ecb77ae21969a6 100644 (file)
@@ -62,7 +62,7 @@ namespace Mono.CSharp {
                        1522, 1570, 1571, 1572, 1573, 1574, 1580, 1581, 1584, 1587, 1589, 1590, 1591, 1592,
                        1616, 1633, 1634, 1635, 1685, 1690, 1691, 1692, 1695, 1696, 1699,
                        1700, 1709, 1717, 1718, 1720,
-                       1901,
+                       1901, 1981,
                        2002, 2023, 2029,
                        3000, 3001, 3002, 3003, 3005, 3006, 3007, 3008, 3009,
                        3010, 3011, 3012, 3013, 3014, 3015, 3016, 3017, 3018, 3019,
index a42b7e41e34f741bbcb3e62785ed7ebb520da9e0..25fe7d780c846a7de3e899dd299bcd001d011c74 100644 (file)
@@ -370,7 +370,7 @@ namespace Mono.CSharp {
                if (InternalType.Dynamic.GetMetaInfo () == null) {
                        InternalType.Dynamic.SetMetaInfo (object_type.GetMetaInfo ());
 
-                       if (RootContext.StdLib)
+                       if (object_type.MemberDefinition.IsImported)
                                InternalType.Dynamic.MemberCache = object_type.MemberCache;
 
                        InternalType.Null.SetMetaInfo (object_type.GetMetaInfo ());
diff --git a/mcs/tests/dtest-023.cs b/mcs/tests/dtest-023.cs
new file mode 100644 (file)
index 0000000..9b4602c
--- /dev/null
@@ -0,0 +1,16 @@
+struct S
+{
+}
+
+class C
+{
+       public static int Main ()
+       {
+               dynamic d = new S ();
+               bool b = d is S;
+               if (!b)
+                       return 1;
+               
+               return 0;
+       }
+}
index 4c57ef02dd82ca290d08ad8084c6db223c2f3ed1..908c93a95bd4a4a64fe9d4aed513836fc6df2b42 100644 (file)
       </method>
     </type>
   </test>
+  <test name="dtest-022.cs">
+    <type name="C">
+      <method name="Void M[T](T)">
+        <size>1</size>
+      </method>
+      <method name="Int32 Main()">
+        <size>8</size>
+      </method>
+      <method name="Void .ctor()">
+        <size>7</size>
+      </method>
+    </type>
+  </test>
+  <test name="dtest-023.cs">
+    <type name="C">
+      <method name="Int32 Main()">
+        <size>35</size>
+      </method>
+      <method name="Void .ctor()">
+        <size>7</size>
+      </method>
+    </type>
+  </test>
   <test name="dtest-error-01.cs">
     <type name="Helper">
       <method name="Int32* Foo(Int32)">
       </method>
     </type>
   </test>
+  <test name="gtest-532.cs">
+    <type name="DictionaryServicesContainer">
+      <method name="Void Register[I,T]()">
+        <size>6</size>
+      </method>
+      <method name="Void Register[I](System.Object)">
+        <size>6</size>
+      </method>
+      <method name="I Resolve[I]()">
+        <size>6</size>
+      </method>
+      <method name="Void Main()">
+        <size>7</size>
+      </method>
+      <method name="Void .ctor()">
+        <size>7</size>
+      </method>
+    </type>
+  </test>
   <test name="gtest-anon-1.cs">
     <type name="X">
       <method name="Void .ctor()">
       </method>
     </type>
   </test>
+  <test name="gtest-iter-15.cs">
+    <type name="C`1[TFirst]">
+      <method name="IEnumerable`1 GetEnumerable[V](IEnumerable`1)">
+        <size>30</size>
+      </method>
+      <method name="Void .ctor()">
+        <size>7</size>
+      </method>
+    </type>
+    <type name="C`1+VSlot`1[TFirst,T]">
+      <method name="Void .ctor(T)">
+        <size>8</size>
+      </method>
+    </type>
+    <type name="C">
+      <method name="Int32 Main()">
+        <size>111</size>
+      </method>
+      <method name="Void .ctor()">
+        <size>7</size>
+      </method>
+    </type>
+    <type name="C`1+&lt;GetEnumerable&gt;c__Iterator0`1[TFirst,V]">
+      <method name="V System.Collections.Generic.IEnumerator&lt;V&gt;.get_Current()">
+        <size>7</size>
+      </method>
+      <method name="System.Object System.Collections.IEnumerator.get_Current()">
+        <size>12</size>
+      </method>
+      <method name="IEnumerator System.Collections.IEnumerable.GetEnumerator()">
+        <size>7</size>
+      </method>
+      <method name="IEnumerator`1 System.Collections.Generic.IEnumerable&lt;V&gt;.GetEnumerator()">
+        <size>40</size>
+      </method>
+      <method name="Boolean MoveNext()">
+        <size>181</size>
+      </method>
+      <method name="Void Dispose()">
+        <size>62</size>
+      </method>
+      <method name="Void Reset()">
+        <size>6</size>
+      </method>
+      <method name="Void .ctor()">
+        <size>7</size>
+      </method>
+    </type>
+  </test>
   <test name="gtest-lambda-01.cs">
     <type name="X">
       <method name="Int32 Main()">
       </method>
     </type>
   </test>
+  <test name="gtest-named-03.cs">
+    <type name="C">
+      <method name="Int32 Foo(Int32, Int32, Int32)">
+        <size>2</size>
+      </method>
+      <method name="Int32 Main()">
+        <size>38</size>
+      </method>
+      <method name="Void .ctor()">
+        <size>7</size>
+      </method>
+    </type>
+  </test>
   <test name="gtest-optional-01.cs">
     <type name="C">
       <method name="Void TestA(Int32)">
       </method>
     </type>
   </test>
+  <test name="gtest-optional-11.cs">
+    <type name="C">
+      <method name="Int32 TestA(Int32)">
+        <size>2</size>
+      </method>
+      <method name="T TestB[T](T, T)">
+        <size>2</size>
+      </method>
+      <method name="System.Object TestC(System.Object)">
+        <size>2</size>
+      </method>
+      <method name="Int32 Main()">
+        <size>76</size>
+      </method>
+      <method name="Void .ctor()">
+        <size>7</size>
+      </method>
+    </type>
+  </test>
+  <test name="gtest-optional-12.cs">
+    <type name="C">
+      <method name="Int32 M(System.String, Int32, System.Int32[])">
+        <size>4</size>
+      </method>
+      <method name="Int32 Main()">
+        <size>41</size>
+      </method>
+      <method name="Void .ctor()">
+        <size>7</size>
+      </method>
+    </type>
+    <type name="&lt;PrivateImplementationDetails&gt;">
+      <method name="Void .ctor()">
+        <size>7</size>
+      </method>
+    </type>
+  </test>
   <test name="gtest-partial-01.cs">
     <type name="B`1[U]">
       <method name="Void .ctor()">
       </method>
     </type>
   </test>
+  <test name="gtest-variance-14.cs">
+    <type name="A">
+      <method name="Void .ctor()">
+        <size>7</size>
+      </method>
+    </type>
+    <type name="B">
+      <method name="Void .ctor()">
+        <size>7</size>
+      </method>
+    </type>
+    <type name="C">
+      <method name="Int32 Main()">
+        <size>28</size>
+      </method>
+      <method name="Void .ctor()">
+        <size>7</size>
+      </method>
+    </type>
+    <type name="C+D`1[T]">
+      <method name="Void Invoke(T)">
+        <size>0</size>
+      </method>
+      <method name="IAsyncResult BeginInvoke(T, System.AsyncCallback, System.Object)">
+        <size>0</size>
+      </method>
+      <method name="Void EndInvoke(IAsyncResult)">
+        <size>0</size>
+      </method>
+      <method name="Void .ctor(Object, IntPtr)">
+        <size>0</size>
+      </method>
+    </type>
+    <type name="C+D`2[T,U]">
+      <method name="T Invoke(U)">
+        <size>0</size>
+      </method>
+      <method name="IAsyncResult BeginInvoke(U, System.AsyncCallback, System.Object)">
+        <size>0</size>
+      </method>
+      <method name="T EndInvoke(IAsyncResult)">
+        <size>0</size>
+      </method>
+      <method name="Void .ctor(Object, IntPtr)">
+        <size>0</size>
+      </method>
+    </type>
+  </test>
+  <test name="gtest-variance-15.cs">
+    <type name="C">
+      <method name="Void M[T](T ByRef, C+D`1[T])">
+        <size>13</size>
+      </method>
+      <method name="Void M2[T](T, C+D`1[T])">
+        <size>8</size>
+      </method>
+      <method name="Void MethodArg(System.Object)">
+        <size>1</size>
+      </method>
+      <method name="Int32 Main()">
+        <size>53</size>
+      </method>
+      <method name="Void &lt;Main&gt;m__0(System.Object)">
+        <size>7</size>
+      </method>
+      <method name="Void .ctor()">
+        <size>7</size>
+      </method>
+    </type>
+    <type name="C+D`1[T]">
+      <method name="Void Invoke(T)">
+        <size>0</size>
+      </method>
+      <method name="IAsyncResult BeginInvoke(T, System.AsyncCallback, System.Object)">
+        <size>0</size>
+      </method>
+      <method name="Void EndInvoke(IAsyncResult)">
+        <size>0</size>
+      </method>
+      <method name="Void .ctor(Object, IntPtr)">
+        <size>0</size>
+      </method>
+    </type>
+  </test>
+  <test name="gtest-variance-16.cs">
+    <type name="S">
+      <method name="System.String op_Implicit(S)">
+        <size>6</size>
+      </method>
+    </type>
+    <type name="C">
+      <method name="T Foo[T](T, I`1)">
+        <size>2</size>
+      </method>
+      <method name="Int32 Main()">
+        <size>45</size>
+      </method>
+      <method name="Void .ctor()">
+        <size>7</size>
+      </method>
+    </type>
+  </test>
   <test name="gtest-variance-2.cs">
     <type name="Foo">
       <method name="System.String Bar(System.Object)">
   <test name="test-anon-94.cs">
     <type name="Program">
       <method name="Int32 Main()">
-        <size>29</size>
+        <size>57</size>
       </method>
       <method name="Void .ctor()">
         <size>7</size>
         <size>7</size>
       </method>
     </type>
+    <type name="Program+DerivedLibrary">
+      <method name="Void Print(Int32)">
+        <size>20</size>
+      </method>
+      <method name="Void &lt;Print&gt;__BaseCallProxy0(Int32)">
+        <size>8</size>
+      </method>
+      <method name="Void &lt;Print&gt;m__1()">
+        <size>9</size>
+      </method>
+      <method name="Void .ctor()">
+        <size>7</size>
+      </method>
+    </type>
   </test>
   <test name="test-anon-95.cs">
     <type name="D">