Skip to content

Commit

Permalink
[display inspect generated expression when displaying safe-nav
Browse files Browse the repository at this point in the history
closes #11205
  • Loading branch information
Simn authored and kLabz committed Mar 4, 2024
1 parent 333cc39 commit bc2d41e
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 2 deletions.
22 changes: 20 additions & 2 deletions src/typing/typerDisplay.ml
Original file line number Diff line number Diff line change
Expand Up @@ -354,9 +354,23 @@ and display_expr ctx e_ast e dk mode with_type p =
| _ ->
e
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]
| 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,[]
in
Expand Down Expand Up @@ -411,6 +425,8 @@ and display_expr ctx e_ast e dk mode with_type p =
end
| TCall(e1,_) ->
loop e1
| TCast(e1,_) ->
loop e1
| _ ->
()
in
Expand Down Expand Up @@ -466,6 +482,8 @@ and display_expr ctx e_ast e dk mode with_type p =
end
| TCall(e1,_) ->
loop e1
| TCast(e1,_) ->
loop e1
| _ ->
[]
in
Expand Down
22 changes: 22 additions & 0 deletions tests/display/src/cases/Issue11205.hx
Original file line number Diff line number Diff line change
@@ -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)));
}
}

0 comments on commit bc2d41e

Please sign in to comment.