ソースを参照

[display inspect generated expression when displaying safe-nav

closes #11205
Simon Krajewski 1 年間 前
コミット
bc2d41e18e
2 ファイル変更42 行追加2 行削除
  1. 20 2
      src/typing/typerDisplay.ml
  2. 22 0
      tests/display/src/cases/Issue11205.hx

+ 20 - 2
src/typing/typerDisplay.ml

@@ -354,9 +354,23 @@ and display_expr ctx e_ast e dk mode with_type p =
 		| _ ->
 		| _ ->
 			e
 			e
 	in
 	in
-	let e,el_typed = match e.eexpr with
-		| TMeta((Meta.StaticExtension,[e_self],_),e1) ->
+	let e,el_typed = match fst e_ast,e.eexpr with
+		| _,TMeta((Meta.StaticExtension,[e_self],_),e1) ->
 			e1,[type_stored_expr ctx e_self]
 			e1,[type_stored_expr ctx e_self]
+		| EField((_,_,EFSafe)),e1 ->
+			(* For ?. we want to extract the then-expression of the TIf. *)
+			let rec loop e1 = match e1.eexpr with
+				| TIf({eexpr = TBinop(OpNotEq,_,{eexpr = TConst TNull})},e1,Some _) ->
+					e1
+				| TBlock el ->
+					begin match List.rev el with
+						| e :: _ -> loop e
+						| _ -> e
+					end
+				| _ ->
+					e
+			in
+			loop e,[]
 		| _ ->
 		| _ ->
 			e,[]
 			e,[]
 	in
 	in
@@ -411,6 +425,8 @@ and display_expr ctx e_ast e dk mode with_type p =
 			end
 			end
 		| TCall(e1,_) ->
 		| TCall(e1,_) ->
 			loop e1
 			loop e1
+		| TCast(e1,_) ->
+			loop e1
 		| _ ->
 		| _ ->
 			()
 			()
 		in
 		in
@@ -466,6 +482,8 @@ and display_expr ctx e_ast e dk mode with_type p =
 			end
 			end
 		| TCall(e1,_) ->
 		| TCall(e1,_) ->
 			loop e1
 			loop e1
+		| TCast(e1,_) ->
+			loop e1
 		| _ ->
 		| _ ->
 			[]
 			[]
 		in
 		in

+ 22 - 0
tests/display/src/cases/Issue11205.hx

@@ -0,0 +1,22 @@
+package cases;
+
+class Issue11205 extends DisplayTestCase {
+	/**
+		typedef Foo = {
+			var {-1-}bar{-2-}:{
+				var {-3-}value{-4-}:Int;
+			};
+		}
+		function main() {
+			final foo:Foo = cast null;
+			foo?.b{-5-}ar?.v{-6-}alue;
+		}
+	**/
+	function test() {
+		eq(range(1, 2), position(pos(5)));
+		eq("{ value : Int }", type(pos(5)));
+
+		eq(range(3, 4), position(pos(6)));
+		eq("Null<Int>", type(pos(6)));
+	}
+}