Browse Source

[matcher] fix extractor variable lazification recursion

closes #7367
Simon Krajewski 7 năm trước cách đây
mục cha
commit
79a5b3cecd
2 tập tin đã thay đổi với 22 bổ sung1 xóa
  1. 1 1
      src/filters/varLazifier.ml
  2. 21 0
      tests/unit/src/unit/issues/Issue7367.hx

+ 1 - 1
src/filters/varLazifier.ml

@@ -4,12 +4,12 @@ open Type
 let apply com e =
 	let rec loop var_inits e = match e.eexpr with
 		| TVar(v,Some e1) when v.v_kind = VExtractorVariable ->
-			let var_inits,e1 = loop var_inits e1 in
 			let var_inits = PMap.add v.v_id e1 var_inits in
 			var_inits,{e with eexpr = TVar(v,None)}
 		| TLocal v ->
 			begin try
 				let e_init = PMap.find v.v_id var_inits in
+				let var_inits,e_init = loop var_inits e_init in
 				let e = {e with eexpr = TBinop(OpAssign,e,e_init)} in
 				let e = {e with eexpr = TParenthesis e} in
 				let var_inits = PMap.remove v.v_id var_inits in

+ 21 - 0
tests/unit/src/unit/issues/Issue7367.hx

@@ -0,0 +1,21 @@
+package unit.issues;
+
+private abstract Foo (String) {
+    public function new (s) {this = s;}
+    public function getFoo ():String return this;
+}
+
+private abstract Bar ({a:Foo, b:Foo}) {
+    public  function new (s) {this = s;}
+    public function getBar ():{a:Foo, b:Foo} return this;
+}
+
+class Issue7367 extends unit.Test {
+	function test() {
+		var x = new Bar({a:new Foo("hello"), b: new Foo("hello2")});
+        var s = switch x {
+            case _.getBar() => {a:_.getFoo() => s1, b:_.getFoo() => s2}: s1+s2;
+        }
+        eq("hellohello2", s);
+	}
+}