Răsfoiți Sursa

avoid more typing/errors in display mode

Simon Krajewski 9 ani în urmă
părinte
comite
c0367c5d12
2 a modificat fișierele cu 19 adăugiri și 5 ștergeri
  1. 12 4
      src/typing/matcher.ml
  2. 7 1
      src/typing/typer.ml

+ 12 - 4
src/typing/matcher.ml

@@ -1226,12 +1226,20 @@ module TexprConverter = struct
 		let p = dt.dt_pos in
 		let c_type = match follow (Typeload.load_instance ctx ({ tpackage = ["std"]; tname="Type"; tparams=[]; tsub = None},p) true) with TInst(c,_) -> c | t -> assert false in
 		let mk_index_call e =
-			let cf = PMap.find "enumIndex" c_type.cl_statics in
-			make_static_call ctx c_type cf (fun t -> t) [e] com.basic.tint e.epos
+			if ctx.com.display <> DMNone then
+				(* If we are in display mode there's a chance that these fields don't exist. Let's just use a
+				   (correctly typed) neutral value because it doesn't actually matter. *)
+				mk (TConst (TInt (Int32.of_int 0))) ctx.t.tint e.epos
+			else
+				let cf = PMap.find "enumIndex" c_type.cl_statics in
+				make_static_call ctx c_type cf (fun t -> t) [e] com.basic.tint e.epos
 		in
 		let mk_name_call e =
-			let cf = PMap.find "enumConstructor" c_type.cl_statics in
-			make_static_call ctx c_type cf (fun t -> t) [e] com.basic.tstring e.epos
+			if ctx.com.display <> DMNone then
+				mk (TConst (TString "")) ctx.t.tstring e.epos
+			else
+				let cf = PMap.find "enumConstructor" c_type.cl_statics in
+				make_static_call ctx c_type cf (fun t -> t) [e] com.basic.tstring e.epos
 		in
 		let rec loop toplevel params dt = match dt.dt_t with
 			| Leaf case ->

+ 7 - 1
src/typing/typer.ml

@@ -3512,7 +3512,13 @@ and type_expr ctx (e,p) (with_type:with_type) =
 		let old_locals = save_locals ctx in
 		ctx.in_loop <- true;
 		let e2 = Expr.ensure_block e2 in
-		let e = (match Optimizer.optimize_for_loop ctx (i,pi) e1 e2 p with
+		let e = if ctx.com.display <> DMNone then begin
+			(* Don't be fancy in display mode because there's no point. *)
+			let t, pt = Typeload.t_iterator ctx in
+			let i = add_local ctx i pt pi in
+			let e2 = type_expr ctx e2 NoValue in
+			mk (TFor (i,e1,e2)) ctx.t.tvoid p
+		end else (match Optimizer.optimize_for_loop ctx (i,pi) e1 e2 p with
 			| Some e -> e
 			| None ->
 				let t, pt = Typeload.t_iterator ctx in