Browse Source

fix metadata/field name display in structures (closes #5796)

Simon Krajewski 8 years ago
parent
commit
1c1ef54bbb
3 changed files with 27 additions and 7 deletions
  1. 3 0
      src/display/display.ml
  2. 7 7
      src/typing/typeload.ml
  3. 17 0
      tests/display/src/cases/Issue5796.hx

+ 3 - 0
src/display/display.ml

@@ -175,6 +175,9 @@ module DisplayEmitter = struct
 		| DMType -> raise (DisplayType (cf.cf_type,p,cf.cf_doc))
 		| _ -> ()
 
+	let maybe_display_field ctx p cf =
+		if is_display_position p then display_field ctx.com.display cf p
+
 	let display_enum_field dm ef p = match dm.dms_kind with
 		| DMPosition -> raise (DisplayPosition [p]);
 		| DMUsage _ -> ef.ef_meta <- (Meta.Usage,[],p) :: ef.ef_meta;

+ 7 - 7
src/typing/typeload.ml

@@ -663,6 +663,10 @@ and load_complex_type ctx allow_display p (t,pn) =
 				cf_overloads = [];
 			} in
 			init_meta_overloads ctx None cf;
+			if ctx.is_display_file then begin
+				Display.DisplayEmitter.check_display_metadata ctx cf.cf_meta;
+				Display.DisplayEmitter.maybe_display_field ctx (cf.cf_name_pos) cf;
+			end;
 			PMap.add n cf acc
 		in
 		mk_anon (List.fold_left loop PMap.empty l)
@@ -2128,10 +2132,6 @@ module ClassInitializer = struct
 			end
 		end
 
-	let check_field_display ctx p cf =
- 		if Display.is_display_position p then
-			Display.DisplayEmitter.display_field ctx.com.display cf p
-
 	let bind_var (ctx,cctx,fctx) cf e =
 		let c = cctx.tclass in
 		let p = cf.cf_pos in
@@ -2163,7 +2163,7 @@ module ClassInitializer = struct
 
 		match e with
 		| None ->
-			if fctx.is_display_field then check_field_display ctx (cf.cf_name_pos) cf;
+			if fctx.is_display_field then Display.DisplayEmitter.maybe_display_field ctx (cf.cf_name_pos) cf;
 		| Some e ->
 			if requires_value_meta ctx.com (Some c) then cf.cf_meta <- ((Meta.Value,[e],null_pos) :: cf.cf_meta);
 			let check_cast e =
@@ -2245,7 +2245,7 @@ module ClassInitializer = struct
 					let e = check_cast e in
 					cf.cf_expr <- Some e;
 					cf.cf_type <- t;
-					if fctx.is_display_field then check_field_display ctx (cf.cf_name_pos) cf;
+					if fctx.is_display_field then Display.DisplayEmitter.maybe_display_field ctx (cf.cf_name_pos) cf;
 				end;
 				t
 			) "bind_var" in
@@ -2554,7 +2554,7 @@ module ClassInitializer = struct
 							| _ -> c.cl_init <- Some e);
 						cf.cf_expr <- Some (mk (TFunction tf) t p);
 						cf.cf_type <- t;
-						if fctx.is_display_field then check_field_display ctx (cf.cf_name_pos) cf;
+						if fctx.is_display_field then Display.DisplayEmitter.maybe_display_field ctx (cf.cf_name_pos) cf;
 			end;
 			t
 		) "type_fun" in

+ 17 - 0
tests/display/src/cases/Issue5796.hx

@@ -0,0 +1,17 @@
+package cases;
+
+class Issue5796 extends DisplayTestCase {
+	/**
+	class Main {
+		static function main() {}
+	}
+
+	typedef Test = {
+		@:gen{-1-}eric var f{-2-}oo:Int;
+	}
+	**/
+	function test() {
+		eq("Marks a class or class field as generic so each type parameter combination generates its own type/field", metadataDoc(pos(1)));
+		eq("Int", type(pos(2)));
+	}
+}