浏览代码

[server] but still fail if both contexts are in_macro (#8254)

Aleksandr Kuzmenko 6 年之前
父节点
当前提交
af7b3f853e
共有 1 个文件被更改,包括 11 次插入0 次删除
  1. 11 0
      src/compiler/server.ml

+ 11 - 0
src/compiler/server.ml

@@ -10,6 +10,7 @@ open DisplayOutput
 open Json
 open Json
 
 
 exception Dirty of module_def
 exception Dirty of module_def
+exception ServerError of string
 
 
 let measure_times = ref false
 let measure_times = ref false
 let prompt = ref false
 let prompt = ref false
@@ -300,6 +301,16 @@ let rec wait_loop process_params verbose accept =
 				| MCode -> check_module_shadowing com2 directories m
 				| MCode -> check_module_shadowing com2 directories m
 				| MMacro when ctx.Typecore.in_macro -> check_module_shadowing com2 directories m
 				| MMacro when ctx.Typecore.in_macro -> check_module_shadowing com2 directories m
 				| MMacro ->
 				| MMacro ->
+					(*
+						Creating another context while the previous one is incomplete means we have an infinite loop in the compiler.
+						Most likely because of circular dependencies in base modules (e.g. `StdTypes` or `String`)
+						Prevents spending another 5 hours for debugging.
+						@see https://github.com/HaxeFoundation/haxe/issues/8174
+					*)
+					if not ctx.g.complete && ctx.in_macro then
+						raise (ServerError ("Infinite loop in Haxe server detected. "
+							^ "Probably caused by shadowing a module of the standard library. "
+							^ "Make sure shadowed module does not pull macro context."));
 					let _, mctx = MacroContext.get_macro_context ctx p in
 					let _, mctx = MacroContext.get_macro_context ctx p in
 					check_module_shadowing mctx.Typecore.com (get_changed_directories mctx) m
 					check_module_shadowing mctx.Typecore.com (get_changed_directories mctx) m
 			in
 			in