Browse Source

[java] Test java.Lib.lock code and fix class lock. Closes #2772

Cauê Waneck 10 years ago
parent
commit
37289facec
2 changed files with 26 additions and 1 deletions
  1. 11 1
      genjava.ml
  2. 15 0
      tests/unit/src/unit/issues/Issue2772.hx

+ 11 - 1
genjava.ml

@@ -1140,6 +1140,7 @@ let configure gen =
 		match e.eexpr with
 			| TLocal { v_name = "__fallback__" }
 			| TCall ({ eexpr = TLocal( { v_name = "__label__" } ) }, [ { eexpr = TConst(TInt _) } ] ) -> false
+			| TCall ({ eexpr = TLocal( { v_name = "__lock__" } ) }, _ ) -> false
 			| TBlock _ | TFor _ | TSwitch _ | TTry _ | TIf _ -> false
 			| TWhile (_,_,flag) when flag = Ast.NormalWhile -> false
 			| _ -> true
@@ -1303,7 +1304,16 @@ let configure gen =
 					Codegen.interpolate_code gen.gcon s tl (write w) (expr_s w) e.epos
 				| TCall ({ eexpr = TLocal( { v_name = "__lock__" } ) }, [ eobj; eblock ] ) ->
 					write w "synchronized(";
-					expr_s w eobj;
+					let rec loop eobj = match eobj.eexpr with
+						| TTypeExpr md ->
+							expr_s w eobj;
+							write w ".class"
+						| TMeta(_,e) | TParenthesis(e) ->
+							loop e
+						| _ ->
+							expr_s w eobj
+					in
+					loop eobj;
 					write w ")";
 					(match eblock.eexpr with
 					| TBlock(_ :: _) ->

+ 15 - 0
tests/unit/src/unit/issues/Issue2772.hx

@@ -0,0 +1,15 @@
+package unit.issues;
+
+class Issue2772 extends Test
+{
+#if java
+	public function test()
+	{
+		var f = false;
+		java.Lib.lock(Issue2772, f = true);
+		t(f);
+		java.Lib.lock(this, f = false);
+		this.f(f);
+	}
+#end
+}