瀏覽代碼

[display] return abstract type instead of its impl class when querying @type on the name in a declaration

Dan Korostelev 9 年之前
父節點
當前提交
52e7e24b3f
共有 2 個文件被更改,包括 12 次插入1 次删除
  1. 2 1
      src/typing/typeload.ml
  2. 10 0
      tests/display/src/cases/Type.hx

+ 2 - 1
src/typing/typeload.ml

@@ -3048,7 +3048,8 @@ let init_module_type ctx context_init do_init (decl,p) =
 		context_init := (fun() -> ctx.m.module_using <- filter_classes types @ ctx.m.module_using) :: !context_init
 	| EClass d ->
 		let c = (match get_type (fst d.d_name) with TClassDecl c -> c | _ -> assert false) in
-		if Display.is_display_position (pos d.d_name) then Display.display_module_type ctx.com.display (TClassDecl c) (pos d.d_name);
+		if Display.is_display_position (pos d.d_name) then
+			Display.display_module_type ctx.com.display (match c.cl_kind with KAbstractImpl a -> TAbstractDecl a | _ -> TClassDecl c) (pos d.d_name);
 		check_global_metadata ctx (fun m -> c.cl_meta <- m :: c.cl_meta) c.cl_module.m_path c.cl_path None;
 		let herits = d.d_flags in
 		if Meta.has Meta.Generic c.cl_meta && c.cl_params <> [] then c.cl_kind <- KGeneric;

+ 10 - 0
tests/display/src/cases/Type.hx

@@ -0,0 +1,10 @@
+package cases;
+
+class Type extends DisplayTestCase {
+	/**
+	abstract A{-1-}(Int) {}
+	**/
+	function testAbstractDecl() {
+		eq("cases.A", type(pos(1)));
+	}
+}