Browse Source

[typeload] make sure to actually init the context at some point

closes #9012
Simon Krajewski 5 years ago
parent
commit
7f0a2796ef

+ 1 - 0
src/context/display/displayTexpr.ml

@@ -56,6 +56,7 @@ let check_display_field ctx sc c cf =
 	let ctx,cctx = TypeloadFields.create_class_context ctx c context_init cf.cf_pos in
 	let ctx,fctx = TypeloadFields.create_field_context (ctx,cctx) c cff in
 	let cf = TypeloadFields.init_field (ctx,cctx,fctx) cff in
+	flush_pass ctx PTypeField "check_display_field";
 	ignore(follow cf.cf_type)
 
 let check_display_class ctx cc cfile c =

+ 3 - 1
src/typing/typeloadModule.ml

@@ -827,7 +827,9 @@ let module_pass_2 ctx m decls tdecls p =
 	) decls;
 	(* setup module types *)
 	let context_init = new TypeloadFields.context_init in
-	List.iter (init_module_type ctx context_init) tdecls
+	List.iter (init_module_type ctx context_init) tdecls;
+	(* Make sure that we actually init the context at some point (issue #9012) *)
+	delay ctx PConnectField (fun () -> context_init#run)
 
 (*
 	Creates a module context for [m] and types [tdecls] using it.

+ 14 - 0
tests/server/src/DisplayTests.hx

@@ -280,4 +280,18 @@ typedef Foo = {
 		var result = parseHover().result;
 		Assert.equals(DisplayItemKind.ClassField, result.item.kind);
 	}
+
+	function testIssue9012() {
+		vfs.putContent("Some.hx", "class Some { public static function func():String return 'hello'; }");
+
+		var content = "import Some.func; class Main { static function main() { fu{-1-}nc(); } }";
+		var transform = Marker.extractMarkers(content);
+		vfs.putContent("Main.hx", transform.source);
+
+		runHaxe(["--no-output", "-main", "Main"]); // commenting this makes it work
+		runHaxeJson([], DisplayMethods.Hover, {file: new FsPath("Main.hx"), offset: transform.markers[1]});
+		var result = parseHover().result;
+
+		Assert.equals(DisplayItemKind.ClassField, result.item.kind);
+	}
 }

+ 0 - 1
tests/server/src/Main.hx

@@ -106,7 +106,6 @@ class ServerTests extends HaxeServerTestCase {
 		assertSuccess();
 	}
 
-
 	#if false // @see https://github.com/HaxeFoundation/haxe/issues/8596#issuecomment-518815594
 	function testDisplayModuleRecache() {
 		vfs.putContent("HelloWorld.hx", getTemplate("HelloWorld.hx"));