[svn] r6166: nemerle/trunk: macros/core.n ncc/testsuite/negative/lock.n

nazgul svnadmin at nemerle.org
Sun Mar 26 16:04:20 CEST 2006


Log:
Do not evaluate expression in lock twice. Forbid value types in lock

Author: nazgul
Date: Sun Mar 26 16:04:18 2006
New Revision: 6166

Added:
   nemerle/trunk/ncc/testsuite/negative/lock.n
Modified:
   nemerle/trunk/macros/core.n

Modified: nemerle/trunk/macros/core.n
==============================================================================
--- nemerle/trunk/macros/core.n	(original)
+++ nemerle/trunk/macros/core.n	Sun Mar 26 16:04:18 2006
@@ -293,14 +293,34 @@
   macro @lock (x, body)
   syntax ("lock", "(", x, ")", body)
   {
+    def typer = Macros.ImplicitCTX ();
+    def tx = typer.TypeExpr (x);
+    typer.DelayMacro (fun (fail_loud) {
+      match (tx.Type.Hint) {
+        | Some (Class (tc, _)) when tc.IsValueType =>
+          when (fail_loud) 
+            Message.Error (x.Location, $"`$tc' is not a reference type as required by the lock expression");
+          None ()
+          
+        | None =>
+          when (fail_loud) 
+            Message.Error (x.Location, "compiler was unable to analyze type of locked object, but it must verify that it is reference type");
+          None ()
+        
+        | _ =>
+          def result = 
     <[ 
-      System.Threading.Monitor.Enter ($x);
+              def to_lock = $(tx : typed);
+              System.Threading.Monitor.Enter (to_lock);
       try {
         $body
       } finally {
-        System.Threading.Monitor.Exit ($x);
+                System.Threading.Monitor.Exit (to_lock);
       }
-    ]>
+            ]>;
+          Some (result)
+      }
+    });
   }
 
   macro dowhile (cond, body) 

Added: nemerle/trunk/ncc/testsuite/negative/lock.n
==============================================================================
--- (empty file)
+++ nemerle/trunk/ncc/testsuite/negative/lock.n	Sun Mar 26 16:04:18 2006
@@ -0,0 +1,9 @@
+
+
+def l = [1];
+l.Iter (fun (x) {
+  lock (x) { // E: `System.Int32' is not a reference type as required by the lock expression
+    System.Console.WriteLine ("x");
+  }
+});
+



More information about the svn mailing list