浏览代码

php: issues with closing brackets (closed #1535)

Franco Ponticelli 12 年之前
父节点
当前提交
d0a9628bee
共有 2 个文件被更改,包括 21 次插入2 次删除
  1. 5 2
      genphp.ml
  2. 16 0
      tests/unit/TestPhp.hx

+ 5 - 2
genphp.ml

@@ -401,8 +401,11 @@ let unsupported msg p = error ("This expression cannot be generated to PHP: " ^
 
 
 let newline ctx =
 let newline ctx =
 	match Buffer.nth ctx.buf (Buffer.length ctx.buf - 1) with
 	match Buffer.nth ctx.buf (Buffer.length ctx.buf - 1) with
-	| '}' | '{' | ':' | ' ' -> print ctx "\n%s" ctx.tabs
-	| _ -> print ctx ";\n%s" ctx.tabs
+	| '{' | ':' | ' '
+	| '}' when Buffer.nth ctx.buf (Buffer.length ctx.buf - 2) != '"' ->
+		print ctx "\n%s" ctx.tabs
+	| _ ->
+		print ctx ";\n%s" ctx.tabs
 
 
 let rec concat ctx s f = function
 let rec concat ctx s f = function
 	| [] -> ()
 	| [] -> ()

+ 16 - 0
tests/unit/TestPhp.hx

@@ -2,6 +2,8 @@ package unit;
 
 
 class TestPhp extends Test
 class TestPhp extends Test
 {
 {
+	var list : Array<Dynamic>;
+	var list2 : Array<Dynamic>;
 	function empty() return true;
 	function empty() return true;
 	function testAbstractEnum()
 	function testAbstractEnum()
 	{
 	{
@@ -12,6 +14,20 @@ class TestPhp extends Test
 	{
 	{
 		t(empty());
 		t(empty());
 	}
 	}
+
+	function testList2()
+	{
+		list2 = new Array<Dynamic>();
+		for( l in list2 ) {} // fails here
+		t(true);
+	}
+
+	function testList()
+	{
+		list = new Array<Dynamic>();
+		for( l in list ) {} // fails here
+		t(true);
+	}
 }
 }
 
 
 enum Annotation {
 enum Annotation {