Selaa lähdekoodia

[analyzer] fix dynamic method handling (closes #5556)

Simon Krajewski 9 vuotta sitten
vanhempi
commit
f5066187b2

+ 5 - 0
src/optimization/analyzerTexpr.ml

@@ -858,6 +858,11 @@ module Cleanup = struct
 					| _ ->
 					| _ ->
 						{e with eexpr = TWhile(e1,e2,NormalWhile)}
 						{e with eexpr = TWhile(e1,e2,NormalWhile)}
 				end
 				end
+			| TField({eexpr = TTypeExpr _},_) ->
+				e
+			| TTypeExpr (TClassDecl c) ->
+				List.iter (fun cf -> if not (Meta.has Meta.MaybeUsed cf.cf_meta) then cf.cf_meta <- (Meta.MaybeUsed,[],cf.cf_pos) :: cf.cf_meta;) c.cl_ordered_statics;
+				e
 			| _ ->
 			| _ ->
 				Type.map_expr loop e
 				Type.map_expr loop e
 		in
 		in

+ 1 - 3
src/optimization/analyzerTexprTransformer.ml

@@ -162,9 +162,6 @@ let rec func ctx bb tf t p =
 			bb_next,ec
 			bb_next,ec
 		(*| TTypeExpr(TClassDecl {cl_kind = KAbstractImpl a}) when not (Meta.has Meta.RuntimeValue a.a_meta) ->
 		(*| TTypeExpr(TClassDecl {cl_kind = KAbstractImpl a}) when not (Meta.has Meta.RuntimeValue a.a_meta) ->
 			error "Cannot use abstract as value" e.epos*)
 			error "Cannot use abstract as value" e.epos*)
-		| TTypeExpr(TClassDecl c) ->
-			List.iter (fun cf -> if not (Meta.has Meta.MaybeUsed cf.cf_meta) then cf.cf_meta <- (Meta.MaybeUsed,[],cf.cf_pos) :: cf.cf_meta;) c.cl_ordered_statics;
-			bb,e
 		| TConst _ | TTypeExpr _ ->
 		| TConst _ | TTypeExpr _ ->
 			bb,e
 			bb,e
 		| TThrow _ | TReturn _ | TBreak | TContinue ->
 		| TThrow _ | TReturn _ | TBreak | TContinue ->
@@ -201,6 +198,7 @@ let rec func ctx bb tf t p =
 	and bind_to_temp bb sequential e =
 	and bind_to_temp bb sequential e =
 		let is_probably_not_affected e e1 fa = match fa with
 		let is_probably_not_affected e e1 fa = match fa with
 			| FAnon cf | FInstance (_,_,cf) | FStatic (_,cf) | FClosure (_,cf) when cf.cf_kind = Method MethNormal -> true
 			| FAnon cf | FInstance (_,_,cf) | FStatic (_,cf) | FClosure (_,cf) when cf.cf_kind = Method MethNormal -> true
+			| FStatic(_,{cf_kind = Method MethDynamic}) -> false
 			| FEnum _ -> true
 			| FEnum _ -> true
 			| FDynamic ("cca" | "__Index" | "__s") -> true (* This is quite retarded, but we have to deal with this somehow... *)
 			| FDynamic ("cca" | "__Index" | "__s") -> true (* This is quite retarded, but we have to deal with this somehow... *)
 			| _ -> match follow e.etype,follow e1.etype with
 			| _ -> match follow e.etype,follow e1.etype with

+ 15 - 0
tests/unit/src/unit/issues/Issue5556.hx

@@ -0,0 +1,15 @@
+package unit.issues;
+
+class Issue5556 extends unit.Test {
+	function test() {
+		var x = dynamicFunc(randomCall());
+		eq(1, x);
+	}
+
+	static function randomCall() {
+		dynamicFunc = function(x:Int) return x * 2;
+		return 1;
+	}
+
+	static dynamic function dynamicFunc(x) return x;
+}