浏览代码

fix array comprehension for a chain of `if..else if` without final `else`
(closes #9040)

Aleksandr Kuzmenko 5 年之前
父节点
当前提交
f59dda59c0
共有 2 个文件被更改,包括 9 次插入0 次删除
  1. 1 0
      src/typing/typer.ml
  2. 8 0
      tests/unit/src/unit/issues/Issue9040.hx

+ 1 - 0
src/typing/typer.ml

@@ -2219,6 +2219,7 @@ and type_array_comprehension ctx e with_type p =
 		| EFor(it,e2) -> (EFor (it, map_compr e2),p)
 		| EWhile(cond,e2,flag) -> (EWhile (cond,map_compr e2,flag),p)
 		| EIf (cond,e2,None) -> (EIf (cond,map_compr e2,None),p)
+		| EIf (cond,e2,Some e3) -> (EIf (cond,map_compr e2,Some (map_compr e3)),p)
 		| EBlock [e] -> (EBlock [map_compr e],p)
 		| EBlock el -> begin match List.rev el with
 			| e :: el -> (EBlock ((List.rev el) @ [map_compr e]),p)

+ 8 - 0
tests/unit/src/unit/issues/Issue9040.hx

@@ -0,0 +1,8 @@
+package unit.issues;
+
+class Issue9040 extends unit.Test {
+	static var to:Int = 10;
+	function test() {
+		aeq([0, 2, 3, 4, 6, 8, 9], [for (i in 0...10) if(i % 2 == 0) i else if(i % 3 == 0) i]);
+	}
+}