Browse Source

[typer] allow importing statics from abstracts

closes #5009

Also try to pass the Gama-test by supporting display modes on it right away.
Simon Krajewski 7 years ago
parent
commit
3fac36bffe

+ 6 - 2
src/compiler/displayOutput.ml

@@ -405,7 +405,7 @@ module TypePathHandler = struct
 				let tinfos = t_infos t in
 				let is_module_type = snd tinfos.mt_path = c in
 				if is_import && is_module_type then begin match t with
-					| TClassDecl c ->
+					| TClassDecl c | TAbstractDecl {a_impl = Some c} ->
 						ignore(c.cl_build());
 						statics := Some c
 					| TEnumDecl en ->
@@ -422,8 +422,12 @@ module TypePathHandler = struct
 						make_ci_type (CompletionItem.CompletionModuleType.of_module_type mt) ImportStatus.Imported None
 					) public_types
 			in
+			let class_origin c = match c.cl_kind with
+				| KAbstractImpl a -> Self (TAbstractDecl a)
+				| _ -> Self (TClassDecl c)
+			in
 			let make_field_doc c cf =
-				make_ci_class_field (CompletionClassField.make cf CFSStatic (Self (TClassDecl c)) true) cf.cf_type
+				make_ci_class_field (CompletionClassField.make cf CFSStatic (class_origin c) true) cf.cf_type
 			in
 			let fields = match !statics with
 				| None -> types

+ 12 - 3
src/typing/typeload.ml

@@ -780,6 +780,15 @@ let string_list_of_expr_path (e,p) =
 
 let handle_path_display ctx path p =
 	let open ImportHandling in
+	let class_field c name =
+		ignore(c.cl_build());
+		let cf = PMap.find name c.cl_statics in
+		let origin = match c.cl_kind with
+			| KAbstractImpl a -> Self (TAbstractDecl a)
+			| _ -> Self (TClassDecl c)
+		in
+		DisplayEmitter.display_field ctx origin CFSStatic cf p
+	in
 	match ImportHandling.convert_import_to_something_usable !DisplayPosition.display_position path,ctx.com.display.dms_kind with
 		| (IDKPackage [_],p),DMDefault ->
 			let fields = DisplayToplevel.collect ctx None Typecore.NoValue in
@@ -827,9 +836,9 @@ let handle_path_display ctx path p =
 			let m = ctx.g.do_load_module ctx (sl,sm) p in
 			List.iter (fun t -> match t with
 				| TClassDecl c when snd c.cl_path = st ->
-					ignore(c.cl_build());
-					let cf = PMap.find sf c.cl_statics in
-					DisplayEmitter.display_field ctx (Self (TClassDecl c)) CFSStatic cf p
+					class_field c sf
+				| TAbstractDecl {a_impl = Some c; a_path = (_,st')} when st' = st ->
+					class_field c sf
 				| _ ->
 					()
 			) m.m_types;

+ 1 - 1
src/typing/typeloadModule.ml

@@ -399,7 +399,7 @@ let init_module_type ctx context_init do_init (decl,p) =
 			let add_static_init t name s =
 				let name = (match name with None -> s | Some (n,_) -> n) in
 				match resolve_typedef t with
-				| TClassDecl c ->
+				| TClassDecl c | TAbstractDecl {a_impl = Some c} ->
 					ignore(c.cl_build());
 					ignore(PMap.find s c.cl_statics);
 					ctx.m.module_globals <- PMap.add name (TClassDecl c,s,p) ctx.m.module_globals

+ 9 - 0
tests/unit/src/unit/issues/Issue5009.hx

@@ -0,0 +1,9 @@
+package unit.issues;
+
+import unit.issues.misc.Issue5009Assert.ASSert;
+
+class Issue5009 extends unit.Test {
+	function test() {
+		ASSert(true);
+	}
+}

+ 7 - 0
tests/unit/src/unit/issues/misc/Issue5009Assert.hx

@@ -0,0 +1,7 @@
+package unit.issues.misc;
+
+@:callable
+abstract Issue5009Assert(Bool->Void) {
+    public static var ASSert = new Issue5009Assert();
+    function new() this = function(b) if (!b) throw "assert";
+}