Implement lock statement over generic type parameter
authorMarek Safar <marek.safar@gmail.com>
Wed, 3 Nov 2010 16:50:19 +0000 (16:50 +0000)
committerMarek Safar <marek.safar@gmail.com>
Wed, 3 Nov 2010 16:50:19 +0000 (16:50 +0000)
mcs/mcs/statement.cs
mcs/tests/gtest-547.cs [new file with mode: 0644]
mcs/tests/ver-il-gmcs.xml

index d57f2d92231084c7c5dbfa48afa1ce989b1e301c..ad65ad783def7348a091c095dc9f9f2ba3e02da0 100644 (file)
@@ -4110,6 +4110,10 @@ namespace Mono.CSharp {
                                        expr.Type.GetSignatureForError ());
                        }
 
+                       if (expr.Type.IsGenericParameter) {
+                               expr = Convert.ImplicitTypeParameterConversion (expr, TypeManager.object_type);
+                       }
+
                        VariableReference lv = expr as VariableReference;
                        bool locked;
                        if (lv != null) {
@@ -4134,7 +4138,7 @@ namespace Mono.CSharp {
                        // Have to keep original lock value around to unlock same location
                        // in the case the original has changed or is null
                        //
-                       expr_copy = TemporaryVariableReference.Create (expr.Type, ec.CurrentBlock.Parent, loc);
+                       expr_copy = TemporaryVariableReference.Create (TypeManager.object_type, ec.CurrentBlock.Parent, loc);
                        expr_copy.Resolve (ec);
 
                        //
diff --git a/mcs/tests/gtest-547.cs b/mcs/tests/gtest-547.cs
new file mode 100644 (file)
index 0000000..b745555
--- /dev/null
@@ -0,0 +1,16 @@
+using System;
+
+public class Foo
+{
+       static void GenericLock<T> (T t) where T : class
+       {
+               lock (t)
+               {
+               }
+       }
+       
+       public static void Main ()
+       {
+               GenericLock ("s");
+       }
+}
\ No newline at end of file
index 9ee557c533d0809f869d78f49611ab032b079176..5c8f6c730f77372605009484c16f8d303245e332 100644 (file)
       </method>
     </type>
   </test>
+  <test name="gtest-547.cs">
+    <type name="Foo">
+      <method name="Void GenericLock[T](T)">
+        <size>26</size>
+      </method>
+      <method name="Void Main()">
+        <size>11</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()">
         <size>7</size>
       </method>
       <method name="Int32 Main()">
-        <size>42</size>
+        <size>91</size>
       </method>
     </type>
   </test>