2
0
Эх сурвалжийг харах

Don't lose typing proces information on EDisplay (#8507)

* don't break typing process flow on EDisplay

* cleanup
Aleksandr Kuzmenko 6 жил өмнө
parent
commit
4b9939e09c

+ 6 - 3
src/typing/typer.ml

@@ -1427,6 +1427,9 @@ and type_access ctx e p mode =
 		handle_efield ctx e p mode
 	| 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 (type_expr ctx (e,p) WithType.value)
 
@@ -2395,7 +2398,7 @@ and type_call ctx e el (with_type:WithType.t) inline p =
 	| _ ->
 		def ()
 
-and type_expr ctx (e,p) (with_type:WithType.t) =
+and type_expr ?(mode=MGet) ctx (e,p) (with_type:WithType.t) =
 	match e with
 	| EField ((EConst (String s),ps),"code") ->
 		if UTF8.length s <> 1 then error "String must be a single UTF8 char" ps;
@@ -2404,11 +2407,11 @@ and type_expr ctx (e,p) (with_type:WithType.t) =
 		error "Field names starting with $ are not allowed" p
 	| EConst (Ident s) ->
 		if s = "super" && with_type <> WithType.NoValue && not ctx.in_display then error "Cannot use super as value" p;
-		let e = maybe_type_against_enum ctx (fun () -> type_ident ctx s p MGet) with_type false p in
+		let e = maybe_type_against_enum ctx (fun () -> type_ident ctx s p mode) with_type false p in
 		acc_get ctx e p
 	| EField _
 	| EArray _ ->
-		acc_get ctx (type_access ctx e p MGet) p
+		acc_get ctx (type_access ctx e p mode) p
 	| EConst (Regexp (r,opt)) ->
 		let str = mk (TConst (TString r)) ctx.t.tstring p in
 		let opt = mk (TConst (TString opt)) ctx.t.tstring p in

+ 10 - 3
src/typing/typerDisplay.ml

@@ -452,7 +452,7 @@ let handle_structure_display ctx e fields origin =
 	| _ ->
 		error "Expected object expression" p
 
-let handle_display ctx e_ast dk with_type =
+let handle_display ?resume_typing ctx e_ast dk with_type =
 	let old = ctx.in_display,ctx.in_call_args in
 	ctx.in_display <- true;
 	ctx.in_call_args <- false;
@@ -482,7 +482,9 @@ let handle_display 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
-		type_expr ctx e_ast with_type
+		match resume_typing with
+		| None -> type_expr ctx e_ast with_type
+		| Some fn -> fn ctx e_ast with_type
 	with Error (Unknown_ident n,_) when ctx.com.display.dms_kind = DMDefault ->
         if dk = DKDot && ctx.com.json_out = None then raise (Parser.TypePath ([n],None,false,p))
 		else raise_toplevel ctx dk with_type (Some p) p
@@ -563,7 +565,12 @@ let handle_display ctx e_ast dk with_type =
 	ctx.in_call_args <- snd old;
 	display_expr ctx e_ast e dk with_type p
 
-let handle_edisplay ctx e dk with_type =
+let handle_edisplay ?resume_typing ctx e dk 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
+	in
 	match dk,ctx.com.display.dms_kind with
 	| DKCall,(DMSignature | DMDefault) -> handle_signature_display ctx e with_type
 	| DKStructure,DMDefault ->