Browse Source

even more display mode fixes

closes #5615
closes #5616
closes #5617
closes #5618
closes #5621
Simon Krajewski 9 years ago
parent
commit
a1c5bf71fd
4 changed files with 36 additions and 33 deletions
  1. 4 6
      src/syntax/ast.ml
  2. 5 0
      src/typing/typecore.ml
  3. 13 14
      src/typing/typeload.ml
  4. 14 13
      src/typing/typer.ml

+ 4 - 6
src/syntax/ast.ml

@@ -844,12 +844,10 @@ let s_expr e =
 	and s_expr_list tabs el sep =
 		(String.concat sep (List.map (s_expr_inner tabs) el))
 	and s_complex_type_path tabs (t,_) =
-		(String.concat "." t.tpackage) ^ if List.length t.tpackage > 0 then "." else "" ^
-		t.tname ^
-		match t.tsub with
-		| Some s -> "." ^ s
-		| None -> "" ^
-		s_type_param_or_consts tabs t.tparams
+		Printf.sprintf "%s%s%s"
+			(s_type_path (t.tpackage,t.tname))
+			(Option.map_default (fun s -> "." ^ s) "" t.tsub)
+			(s_type_param_or_consts tabs t.tparams)
 	and s_type_param_or_consts tabs pl =
 		if List.length pl > 0
 		then "<" ^ (String.concat "," (List.map (s_type_param_or_const tabs) pl)) ^ ">"

+ 5 - 0
src/typing/typecore.ml

@@ -292,6 +292,11 @@ let add_local ctx n t p =
 	ctx.locals <- PMap.add n v ctx.locals;
 	v
 
+let add_unbound_local ctx n t p =
+	let v = add_local ctx n t p in
+	v.v_meta <- (Ast.Meta.Unbound,[],Ast.null_pos) :: v.v_meta;
+	v
+
 let gen_local_prefix = "`"
 
 let gen_local ctx t p =

+ 13 - 14
src/typing/typeload.ml

@@ -237,13 +237,13 @@ let parse_file_from_lexbuf com file p lexbuf =
 	Lexer.init file true;
 	incr stats.s_files_parsed;
 	let data = (try Parser.parse com lexbuf with e -> t(); raise e) in
-    begin match !display_default with
-        | DMModuleSymbols filter when filter <> None || Display.is_display_file file ->
-            let ds = Display.DocumentSymbols.collect_module_symbols data in
+	begin match !display_default with
+		| DMModuleSymbols filter when filter <> None || Display.is_display_file file ->
+			let ds = Display.DocumentSymbols.collect_module_symbols data in
 			com.shared.shared_display_information.document_symbols <- (file,ds) :: com.shared.shared_display_information.document_symbols;
-        | _ ->
-            ()
-    end;
+		| _ ->
+			()
+	end;
 	t();
 	Common.log com ("Parsed " ^ file);
 	data
@@ -2180,6 +2180,10 @@ module ClassInitializer = struct
 			end
 		end
 
+	let check_field_display ctx p cf =
+ 		if Display.is_display_position p then
+			Display.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
@@ -2293,16 +2297,13 @@ 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;
 				end;
 				t
 			) "bind_var" in
 			if not fctx.is_static then cctx.force_constructor <- true;
 			bind_type (ctx,cctx,fctx) cf r (snd e)
 
-	let check_field_display com p cf =
- 		if Display.is_display_position p then
-			Display.display_field com.display cf p
-
 	let create_variable (ctx,cctx,fctx) c f t eo p =
 		if not fctx.is_static && cctx.abstract <> None then error (fst f.cff_name ^ ": Cannot declare member variable in abstract") p;
 		if fctx.is_inline && not fctx.is_static then error (fst f.cff_name ^ ": Inline variable must be static") p;
@@ -2339,7 +2340,6 @@ module ClassInitializer = struct
 		} in
 		ctx.curfield <- cf;
 		bind_var (ctx,cctx,fctx) cf eo;
-		if fctx.is_display_field then check_field_display ctx.com (pos f.cff_name) cf;
 		cf
 
 	let check_abstract (ctx,cctx,fctx) c cf fd t ret p =
@@ -2604,11 +2604,11 @@ 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;
 			end;
 			t
 		) "type_fun" in
 		if fctx.do_bind then bind_type (ctx,cctx,fctx) cf r (match fd.f_expr with Some e -> snd e | None -> f.cff_pos);
-		if fctx.is_display_field then check_field_display ctx.com (pos f.cff_name) cf;
 		cf
 
 	let create_property (ctx,cctx,fctx) c f (get,set,t,eo) p =
@@ -2739,7 +2739,6 @@ module ClassInitializer = struct
 		} in
 		ctx.curfield <- cf;
 		bind_var (ctx,cctx,fctx) cf eo;
-		if fctx.is_display_field then check_field_display ctx.com (pos f.cff_name) cf;
 		cf
 
 	let init_field (ctx,cctx,fctx) f =
@@ -3933,7 +3932,7 @@ let rec build_generic ctx c p tl =
 		List.iter loop tl;
 		let build_field cf_old =
 			(* We have to clone the type parameters (issue #4672). We cannot substitute the constraints immediately because
-		       we need the full substitution list first. *)
+			   we need the full substitution list first. *)
 			let param_subst,params = List.fold_left (fun (subst,params) (s,t) -> match follow t with
 				| TInst(c,tl) as t ->
 					let t2 = TInst({c with cl_pos = c.cl_pos;},tl) in

+ 14 - 13
src/typing/typer.ml

@@ -1735,7 +1735,7 @@ let type_bind ctx (e : texpr) params p =
 	let vexpr v = mk (TLocal v) v.v_type p in
 	let acount = ref 0 in
 	let alloc_name n =
-		if n = "" || String.length n > 2 then begin
+		if n = "" || String.length n > 2 && not ctx.is_display_file then begin
 			incr acount;
 			"a" ^ string_of_int !acount;
 		end else
@@ -2676,11 +2676,11 @@ and type_ident ctx i p mode =
 						let cl = StringError.filter_similar (fun (s,_) r -> r > 0 && r <= (min (String.length s) (String.length i)) / 3) cl in
 						ctx.com.display_information.unresolved_identifiers <- (i,p,cl) :: ctx.com.display_information.unresolved_identifiers;
 						let t = mk_mono() in
-						AKExpr (mk (TLocal (add_local ctx i t p)) t p)
+						AKExpr (mk (TLocal (add_unbound_local ctx i t p)) t p)
 					| _ ->
 						display_error ctx (error_msg err) p;
 						let t = mk_mono() in
-						AKExpr (mk (TLocal (add_local ctx i t p)) t p)
+						AKExpr (mk (TLocal (add_unbound_local ctx i t p)) t p)
 			end
 		end
 
@@ -2908,7 +2908,7 @@ and type_vars ctx vl p =
 		with
 			Error (e,p) ->
 				display_error ctx (error_msg e) p;
-				add_local ctx v t_dynamic pv, None
+				add_unbound_local ctx v t_dynamic pv, None
 	) vl in
 	match vl with
 	| [v,eo] ->
@@ -3842,15 +3842,15 @@ and handle_display ctx e_ast iscall with_type =
 		) tl in
 		tl
 	in
-	begin match e_ast with
-		| EConst (Ident "$type"),_ ->
-			let mono = mk_mono() in
-			raise (Display.DisplaySignatures [(TFun(["expression",false,mono],mono),Some "Outputs type of argument as a warning and uses argument as value")])
-		| EConst (Ident "trace"),_ ->
-			raise (Display.DisplaySignatures [(tfun [t_dynamic] ctx.com.basic.tvoid,Some "Print given arguments")])
-		| _ -> ()
-	end;
-	let e = try
+	let e = match e_ast,with_type with
+	| (EConst (Ident "$type"),_),_ ->
+		let mono = mk_mono() in
+		raise (Display.DisplaySignatures [(TFun(["expression",false,mono],mono),Some "Outputs type of argument as a warning and uses argument as value")])
+	| (EConst (Ident "trace"),_),_ ->
+		raise (Display.DisplaySignatures [(tfun [t_dynamic] ctx.com.basic.tvoid,Some "Print given arguments")])
+	| (EConst (Ident "_"),p),WithType t ->
+		mk (TConst TNull) t p (* This is "probably" a bind skip, let's just use the expected type *)
+	| _ -> try
 		type_expr ctx e_ast with_type
 	with Error (Unknown_ident n,_) when not iscall ->
 		raise (Parser.TypePath ([n],None,false))
@@ -3888,6 +3888,7 @@ and handle_display ctx e_ast iscall with_type =
 		let t = match e.eexpr with
 			| TVar(v,_) -> v.v_type
 			| TCall({eexpr = TConst TSuper; etype = t},_) -> t
+			| TNew({cl_kind = KAbstractImpl a},tl,_) -> TType(abstract_module_type a,tl)
 			| TNew(c,tl,_) -> TInst(c,tl)
 			| TTypeExpr (TClassDecl {cl_kind = KAbstractImpl a}) -> TType(abstract_module_type a,List.map snd a.a_params)
 			| TField(e1,FDynamic "bind") when (match follow e1.etype with TFun _ -> true | _ -> false) -> e1.etype