Browse Source

[typer] revert map comprehension change (see #6620)

Simon Krajewski 8 năm trước cách đây
mục cha
commit
43e4ed6853
2 tập tin đã thay đổi với 17 bổ sung37 xóa
  1. 1 21
      src/typing/typer.ml
  2. 16 16
      tests/unit/src/unit/TestMapComprehension.hx

+ 1 - 21
src/typing/typer.ml

@@ -3433,15 +3433,6 @@ and type_expr ctx (e,p) (with_type:with_type) =
 			| 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)
-			| ESwitch(e1,cases,eo) ->
-				let cases = List.map (fun (el,eg,e,p) -> el,eg,Option.map map_compr e,p) cases in
-				let eo = Option.map (fun (eo,p) -> Option.map map_compr eo,p) eo in
-				ESwitch(e1,cases,eo),p
-			| ETry(e1,catches) ->
-				let catches = List.map (fun (n,ct,e,p) -> n,ct,map_compr e,p) catches in
-				ETry(map_compr e1,catches),p
-			| ETernary (cond,e2,e3) -> (ETernary (cond,map_compr e2,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)
@@ -3451,18 +3442,7 @@ and type_expr ctx (e,p) (with_type:with_type) =
 			| EBinop(OpArrow,a,b) ->
 				et := (ENew(({tpackage=["haxe";"ds"];tname="Map";tparams=[];tsub=None},null_pos),[]),p);
 				(ECall ((EField ((EConst (Ident v.v_name),p),"set"),p),[a;b]),p)
-			| EContinue | EBreak | EReturn _ | EThrow _ ->
-				(e,p)
-			| ECast(e1,tho) ->
-				ECast(map_compr e1,tho),p
-			| EUntyped e1 ->
-				EUntyped(map_compr e1),p
-			| EDisplay(e1,b) ->
-				EDisplay(map_compr e1,b),p
-			| EMeta(m,e1) ->
-				EMeta(m,map_compr e1),p
-			| EConst _ | EArray _ | EBinop _ | EField _ | EObjectDecl _ | EArrayDecl _
-			| ECall _ | ENew _ | EUnop _ | EVars _ | EFunction _ | EDisplayNew _ | ECheckType _ ->
+			| _ ->
 				et := (EArrayDecl [],p);
 				(ECall ((EField ((EConst (Ident v.v_name),p),"push"),p),[(e,p)]),p)
 		in

+ 16 - 16
tests/unit/src/unit/TestMapComprehension.hx

@@ -4,26 +4,26 @@ class TestMapComprehension extends unit.Test {
 	public function testBasic() {
 		mapEq([for (i in 0...2) i => i], [0 => 0, 1 => 1]);
 		mapEq([for (i in 0...2) (i => i)], [0 => 0, 1 => 1]);
-		mapEq([for (i in 0...2) cast i => i], [0 => 0, 1 => 1]);
-		mapEq([for (i in 0...2) untyped i => i], [0 => 0, 1 => 1]);
+		// mapEq([for (i in 0...2) cast i => i], [0 => 0, 1 => 1]);
+		// mapEq([for (i in 0...2) untyped i => i], [0 => 0, 1 => 1]);
 		mapEq([for (i in 0...2) if (i == 1) i => i], [1 => 1]);
-		mapEq([for (i in 0...2) if (i == 0) i => i else i => i * 2], [0 => 0, 1 => 2]);
-		mapEq([for (i in 0...2) (i == 0) ? i => i : i => i * 2], [0 => 0, 1 => 2]);
-		mapEq([for (i in 0...2) switch i { case 0: i => i; case _: i => i * 2; }], [0 => 0, 1 => 2]);
-		mapEq([for (i in 0...2) try i => i catch(e:Dynamic) i => i * 2], [0 => 0, 1 => 1]);
-		mapEq([for (i in 0...2) try { throw null; i => i; } catch(e:Dynamic) i => i * 2], [0 => 0, 1 => 2]);
-		mapEq([for (i in 0...2) try { throw null; } catch(e:Dynamic) i => i * 2], [0 => 0, 1 => 2]);
+		// mapEq([for (i in 0...2) if (i == 0) i => i else i => i * 2], [0 => 0, 1 => 2]);
+		// mapEq([for (i in 0...2) (i == 0) ? i => i : i => i * 2], [0 => 0, 1 => 2]);
+		// mapEq([for (i in 0...2) switch i { case 0: i => i; case _: i => i * 2; }], [0 => 0, 1 => 2]);
+		// mapEq([for (i in 0...2) try i => i catch(e:Dynamic) i => i * 2], [0 => 0, 1 => 1]);
+		// mapEq([for (i in 0...2) try { throw null; i => i; } catch(e:Dynamic) i => i * 2], [0 => 0, 1 => 2]);
+		// mapEq([for (i in 0...2) try { throw null; } catch(e:Dynamic) i => i * 2], [0 => 0, 1 => 2]);
 
-		mapEq([for (i in 0...2) { continue; i => i; }], new Map<Int, Int>());
+		// mapEq([for (i in 0...2) { continue; i => i; }], new Map<Int, Int>());
 	}
 
-	public function testMark() {
-		var specialValue = null;
-		function doSomething(i:Int) specialValue = ("special" + i);
-		var m = [for(i in 0...3) if (i != 1) i => 'number $i' else { doSomething(i); continue; }];
-		mapEq(m, [0 => "number 0", 2 => "number 2"]);
-		eq(specialValue, "special1");
-	}
+	// public function testMark() {
+	// 	var specialValue = null;
+	// 	function doSomething(i:Int) specialValue = ("special" + i);
+	// 	var m = [for(i in 0...3) if (i != 1) i => 'number $i' else { doSomething(i); continue; }];
+	// 	mapEq(m, [0 => "number 0", 2 => "number 2"]);
+	// 	eq(specialValue, "special1");
+	// }
 
 	function mapEq<K, V>(m1:Map<K, V>, m2:Map<K, V>, ?p:haxe.PosInfos) {
 		for (k1 in m1.keys()) {