浏览代码

error if we inline a static local

closes #11725
Simon Krajewski 1 年之前
父节点
当前提交
15fb5830b5

+ 1 - 0
src/optimization/inline.ml

@@ -700,6 +700,7 @@ let rec type_inline ctx cf f ethis params tret config p ?(self_calling_closure=f
 				typing_error "Could not inline `this` outside of an instance context" po
 				typing_error "Could not inline `this` outside of an instance context" po
 			)
 			)
 		| TVar (v,eo) ->
 		| TVar (v,eo) ->
+			if has_var_flag v VStatic then typing_error "Inline functions cannot have static locals" v.v_pos;
 			{ e with eexpr = TVar ((state#declare v).i_subst,opt (map false false) eo)}
 			{ e with eexpr = TVar ((state#declare v).i_subst,opt (map false false) eo)}
 		| TReturn eo when not state#in_local_fun ->
 		| TReturn eo when not state#in_local_fun ->
 			if not term then begin
 			if not term then begin

+ 6 - 0
tests/misc/projects/Issue11725/Main.hx

@@ -0,0 +1,6 @@
+function main() foo();
+
+inline function foo() {
+	static var count = 5;
+	trace(--count);
+}

+ 2 - 0
tests/misc/projects/Issue11725/compile-fail.hxml

@@ -0,0 +1,2 @@
+--main Main
+--interp

+ 1 - 0
tests/misc/projects/Issue11725/compile-fail.hxml.stderr

@@ -0,0 +1 @@
+Main.hx:4: characters 13-18 : Inline functions cannot have static locals