Переглянути джерело

[typer] mode more, less resume_typing

Simon Krajewski 5 роки тому
батько
коміт
3664af48be
4 змінених файлів з 16 додано та 21 видалено
  1. 2 2
      src/typing/forLoop.ml
  2. 4 4
      src/typing/matcher.ml
  3. 4 5
      src/typing/typer.ml
  4. 6 10
      src/typing/typerDisplay.ml

+ 2 - 2
src/typing/forLoop.ml

@@ -472,7 +472,7 @@ let type_for_loop ctx handle_display it e2 p =
 		| EBinop(OpArrow,ei1,(EBinop(OpIn,ei2,e2),_)) -> IKKeyValue(loop_ident None ei1,loop_ident None ei2),e2
 		| _ ->
 			begin match dko with
-			| Some dk -> ignore(handle_display ctx e1 dk WithType.value);
+			| Some dk -> ignore(handle_display ctx e1 dk MGet WithType.value);
 			| None -> ()
 			end;
 			error "For expression should be 'v in expr'" (snd it)
@@ -485,7 +485,7 @@ let type_for_loop ctx handle_display it e2 p =
 	let e2 = Expr.ensure_block e2 in
 	let check_display (i,pi,dko) = match dko with
 		| None -> ()
-		| Some dk -> ignore(handle_display ctx (EConst(Ident i.v_name),i.v_pos) dk (WithType.with_type i.v_type))
+		| Some dk -> ignore(handle_display ctx (EConst(Ident i.v_name),i.v_pos) dk MGet (WithType.with_type i.v_type))
 	in
 	match ik with
 	| IKNormal(i,pi,dko) ->

+ 4 - 4
src/typing/matcher.ml

@@ -480,7 +480,7 @@ module Pattern = struct
 						let v = add_local false s p in
 						begin match dko with
 						| None -> ()
-						| Some dk -> ignore(TyperDisplay.display_expr ctx e (mk (TLocal v) v.v_type p) dk (WithType.with_type t) p);
+						| Some dk -> ignore(TyperDisplay.display_expr ctx e (mk (TLocal v) v.v_type p) dk (MSet None) (WithType.with_type t) p);
 						end;
 						let pat = make pctx false t e2 in
 						PatBind(v,pat)
@@ -509,18 +509,18 @@ module Pattern = struct
 				let pat = loop e in
 				let locals' = ctx.locals in
 				ctx.locals <- locals;
-				ignore(TyperDisplay.handle_edisplay ctx e (display_mode()) (WithType.with_type t));
+				ignore(TyperDisplay.handle_edisplay ctx e (display_mode()) MGet (WithType.with_type t));
 				ctx.locals <- locals';
 				pat
 			(* For signature completion, we don't want to recurse into the inner pattern because there's probably
 			   a EDisplay(_,DMMarked) in there. We can handle display immediately because inner patterns should not
 			   matter (#7326) *)
 			| EDisplay(e1,DKCall) ->
-				ignore(TyperDisplay.handle_edisplay ctx e (display_mode()) (WithType.with_type t));
+				ignore(TyperDisplay.handle_edisplay ctx e (display_mode()) MGet (WithType.with_type t));
 				loop e1
 			| EDisplay(e,dk) ->
 				let pat = loop e in
-				ignore(TyperDisplay.handle_edisplay ctx e (display_mode()) (WithType.with_type t));
+				ignore(TyperDisplay.handle_edisplay ctx e (display_mode()) MGet (WithType.with_type t));
 				pat
 			| EMeta((Meta.StoredTypedExpr,_,_),e1) ->
 				let e1 = MacroContext.type_stored_expr ctx e1 in

+ 4 - 5
src/typing/typer.ml

@@ -586,8 +586,7 @@ and type_access ctx e p mode with_type =
 	| EArray (e1,e2) ->
 		type_array_access ctx e1 e2 p mode
 	| EDisplay (e,dk) ->
-		let resume_typing = type_expr ~mode in
-		AKExpr (TyperDisplay.handle_edisplay ~resume_typing ctx e dk WithType.value)
+		AKExpr (TyperDisplay.handle_edisplay ctx e dk mode WithType.value)
 	| _ ->
 		AKExpr (type_expr ~mode ctx (e,p) WithType.value)
 
@@ -1074,7 +1073,7 @@ and type_try ctx e1 catches with_type p =
 		let e = type_expr ctx e_ast with_type in
 		(* If the catch position is the display position it means we get completion on the catch keyword or some
 		   punctuation. Otherwise we wouldn't reach this point. *)
-		if ctx.is_display_file && DisplayPosition.display_position#enclosed_in pc then ignore(TyperDisplay.display_expr ctx e_ast e DKMarked with_type pc);
+		if ctx.is_display_file && DisplayPosition.display_position#enclosed_in pc then ignore(TyperDisplay.display_expr ctx e_ast e DKMarked MGet with_type pc);
 		v.v_type <- t2;
 		locals();
 		((v,e) :: acc1),(e :: acc2)
@@ -1627,7 +1626,7 @@ and type_call ?(mode=MGet) ctx e el (with_type:WithType.t) inline p =
 		else
 			e
 	| (EDisplay((EConst (Ident "super"),_ as e1),dk),_),_ ->
-		TyperDisplay.handle_display ctx (ECall(e1,el),p) dk with_type
+		TyperDisplay.handle_display ctx (ECall(e1,el),p) dk mode with_type
 	| (EConst (Ident "super"),sp) , el ->
 		if ctx.curfun <> FunConstructor then error "Cannot call super constructor outside class constructor" p;
 		let el, t = (match ctx.curclass.cl_super with
@@ -1795,7 +1794,7 @@ and type_expr ?(mode=MGet) ctx (e,p) (with_type:WithType.t) =
 	| ECast (e, Some t) ->
 		type_cast ctx e t p
 	| EDisplay (e,dk) ->
-		TyperDisplay.handle_edisplay ctx e dk with_type
+		TyperDisplay.handle_edisplay ctx e dk mode with_type
 	| EDisplayNew t ->
 		die "" __LOC__
 	| ECheckType (e,t) ->

+ 6 - 10
src/typing/typerDisplay.ml

@@ -300,7 +300,7 @@ let rec handle_signature_display ctx e_ast with_type =
 			end
 		| _ -> error "Call expected" p
 
-and display_expr ctx e_ast e dk with_type p =
+and display_expr ctx e_ast e dk mode with_type p =
 	let get_super_constructor () = match ctx.curclass.cl_super with
 		| None -> error "Current class does not have a super" p
 		| Some (c,params) ->
@@ -502,7 +502,7 @@ let handle_structure_display ctx e fields origin =
 	| _ ->
 		error "Expected object expression" p
 
-let handle_display ?resume_typing ctx e_ast dk with_type =
+let handle_display ctx e_ast dk mode with_type =
 	let old = ctx.in_display,ctx.in_call_args in
 	ctx.in_display <- true;
 	ctx.in_call_args <- false;
@@ -532,9 +532,7 @@ let handle_display ?resume_typing ctx e_ast dk with_type =
 	| (EConst (Ident "_"),p),WithType.WithType(t,_) ->
 		mk (TConst TNull) t p (* This is "probably" a bind skip, let's just use the expected type *)
 	| (_,p),_ -> try
-		match resume_typing with
-		| None -> type_expr ctx e_ast with_type
-		| Some fn -> fn ctx e_ast with_type
+		type_expr ~mode ctx e_ast with_type
 	with Error (Unknown_ident n,_) when ctx.com.display.dms_kind = DMDefault ->
         if dk = DKDot && is_legacy_completion ctx.com then raise (Parser.TypePath ([n],None,false,p))
 		else raise_toplevel ctx dk with_type (n,p)
@@ -622,13 +620,11 @@ let handle_display ?resume_typing ctx e_ast dk with_type =
 	end;
 	ctx.in_display <- fst old;
 	ctx.in_call_args <- snd old;
-	display_expr ctx e_ast e dk with_type p
+	display_expr ctx e_ast e dk mode with_type p
 
-let handle_edisplay ?resume_typing ctx e dk with_type =
+let handle_edisplay ctx e dk mode with_type =
 	let handle_display ctx e dk with_type =
-		match resume_typing with
-		| Some resume_typing -> handle_display ~resume_typing ctx e dk with_type
-		| None -> handle_display ctx e dk with_type
+		handle_display ctx e dk mode with_type
 	in
 	match dk,ctx.com.display.dms_kind with
 	| DKCall,(DMSignature | DMDefault) -> handle_signature_display ctx e with_type