Browse Source

Revert "don't generate TLocal twice for rvalue named functions"
reopend #8359

This reverts commit 410a442d495d9a2da9115b5d2b67e7c99ab68a58.

Aleksandr Kuzmenko 6 years ago
parent
commit
edbcda27d1
2 changed files with 14 additions and 42 deletions
  1. 14 17
      src/typing/typer.ml
  2. 0 25
      tests/display/src/cases/Issue8359.hx

+ 14 - 17
src/typing/typer.ml

@@ -2038,7 +2038,7 @@ and type_local_function ctx name inline f with_type p =
 		tf_expr = e;
 	} in
 	let e = mk (TFunction tf) ft p in
-	match v with
+	(match v with
 	| None -> e
 	| Some v ->
 		Typeload.generate_value_meta ctx.com None (fun m -> v.v_meta <- m :: v.v_meta) f.f_args;
@@ -2050,24 +2050,21 @@ and type_local_function ctx name inline f with_type p =
 			| LocalUsage.Use _ | LocalUsage.Assign _ | LocalUsage.Declare _ -> ()
 		in
 		let is_rec = (try local_usage loop e; false with Exit -> true) in
-		let exprs =
-			if with_type <> WithType.NoValue && not inline then [mk (TLocal v) v.v_type p]
-			else []
-		in
-		let exprs =
-			if is_rec then begin
-				if inline then display_error ctx "Inline function cannot be recursive" e.epos;
+		let decl = (if is_rec then begin
+			if inline then display_error ctx "Inline function cannot be recursive" e.epos;
+			let el =
 				(mk (TVar (v,Some (mk (TConst TNull) ft p))) ctx.t.tvoid p) ::
 				(mk (TBinop (OpAssign,mk (TLocal v) ft p,e)) ft p) ::
-				exprs
-			end else if inline && not ctx.com.display.dms_display then
-				(mk (TBlock []) ctx.t.tvoid p) :: exprs (* do not add variable since it will be inlined *)
-			else
-				(mk (TVar (v,Some e)) ctx.t.tvoid p) :: exprs
-		in
-		match exprs with
-		| [e] -> e
-		| _ -> mk (TBlock exprs) v.v_type p
+				(if with_type = WithType.NoValue then [] else [mk (TLocal v) ft p])
+			in
+			let e = mk (TBlock el) ft p in
+			{e with eexpr = TMeta((Meta.MergeBlock,[],null_pos),e)}
+		end else if inline && not ctx.com.display.dms_display then
+			mk (TBlock []) ctx.t.tvoid p (* do not add variable since it will be inlined *)
+		else
+			mk (TVar (v,Some e)) ctx.t.tvoid p
+		) in
+		if with_type <> WithType.NoValue && not inline then mk (TBlock [decl;mk (TLocal v) v.v_type p]) v.v_type p else decl)
 
 and type_array_decl ctx el with_type p =
 	let tp = (match with_type with

+ 0 - 25
tests/display/src/cases/Issue8359.hx

@@ -1,25 +0,0 @@
-package cases;
-
-class Issue8359 extends DisplayTestCase {
-	/**
-		class Main {
-			static function main() {
-				var active = false;
-				var callback: ()->Void;
-				callback = function original(){
-					if( active ){ return; }
-					active = true;
-					callback = function(){
-						active = false;
-						callback = original;
-					};
-				};
-				callback();
-				callback();
-			}
-		}
-	**/
-	function test() {
-		arrayEq([], diagnostics());
-	}
-}