浏览代码

[analyzer] propagate TTypeExpr

closes #5582
Simon Krajewski 7 年之前
父节点
当前提交
f86e13c474
共有 2 个文件被更改,包括 23 次插入0 次删除
  1. 7 0
      src/optimization/analyzer.ml
  2. 16 0
      tests/optimization/src/issues/Issue5582.hx

+ 7 - 0
src/optimization/analyzer.ml

@@ -351,6 +351,7 @@ module ConstPropagation = DataFlow(struct
 		| Null of Type.t
 		| Null of Type.t
 		| Const of tconstant
 		| Const of tconstant
 		| EnumValue of int * t list
 		| EnumValue of int * t list
+		| ModuleType of module_type * Type.t
 
 
 	let conditional = true
 	let conditional = true
 	let flag = FlagExecutable
 	let flag = FlagExecutable
@@ -368,6 +369,7 @@ module ConstPropagation = DataFlow(struct
 		| Const ct1,Const ct2 -> ct1 = ct2
 		| Const ct1,Const ct2 -> ct1 = ct2
 		| Null t1,Null t2 -> t1 == t2
 		| Null t1,Null t2 -> t1 == t2
 		| EnumValue(i1,_),EnumValue(i2,_) -> i1 = i2
 		| EnumValue(i1,_),EnumValue(i2,_) -> i1 = i2
+		| ModuleType(mt1,_),ModuleType (mt2,_) -> mt1 == mt2
 		| _ -> false
 		| _ -> false
 
 
 	let transfer ctx bb e =
 	let transfer ctx bb e =
@@ -388,6 +390,8 @@ module ConstPropagation = DataFlow(struct
 				Null e.etype
 				Null e.etype
 			| TConst ct ->
 			| TConst ct ->
 				Const ct
 				Const ct
+			| TTypeExpr mt ->
+				ModuleType(mt,e.etype)
 			| TLocal v ->
 			| TLocal v ->
 				if (follow v.v_type) == t_dynamic || v.v_capture then
 				if (follow v.v_type) == t_dynamic || v.v_capture then
 					Bottom
 					Bottom
@@ -476,6 +480,9 @@ module ConstPropagation = DataFlow(struct
 				let e' = Texpr.type_constant ctx.com.basic (tconst_to_const ct) e.epos in
 				let e' = Texpr.type_constant ctx.com.basic (tconst_to_const ct) e.epos in
 				if not (type_change_ok ctx.com e'.etype e.etype) then raise Not_found;
 				if not (type_change_ok ctx.com e'.etype e.etype) then raise Not_found;
 				e'
 				e'
+			| ModuleType(mt,t) ->
+				if not (type_change_ok ctx.com t e.etype) then raise Not_found;
+				mk (TTypeExpr mt) t e.epos
 		in
 		in
 		let is_special_var v = v.v_capture || is_asvar_type v.v_type in
 		let is_special_var v = v.v_capture || is_asvar_type v.v_type in
 		let rec commit e = match e.eexpr with
 		let rec commit e = match e.eexpr with

+ 16 - 0
tests/optimization/src/issues/Issue5582.hx

@@ -0,0 +1,16 @@
+package issues;
+
+class Issue5582 {
+	@:js('
+		issues_Issue5582.set_i(issues_Issue5582.i + 1);
+	')
+	static function test() {
+        i += 1;
+	}
+
+    static var i(default, set):Int = 0;
+
+    static function set_i(i:Int):Int {
+        return Issue5582.i = i;
+    }
+}