Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ unreleased

+ merlin binary
- Update internal typer to match OCaml 4.14.1 release. (#1557)
- Improve type-enclosing behaviour when used on records' labels (#1565,
fixes #1564)

merlin 4.7
==========
Expand Down
5 changes: 5 additions & 0 deletions src/analysis/type_enclosing.ml
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,11 @@ let from_reconstructed ~nodes ~cursor ~verbosity exprs =
let ppf, to_string = Format.to_string () in
Type_utils.print_constr ~verbosity env ppf cd;
Some (loc, String (to_string ()), `No)
| Some (Context.Label { lbl_name; lbl_arg; _ }) ->
log ~title:"from_reconstructed" "ctx: label %s" lbl_name;
let ppf, to_string = Format.to_string () in
Type_utils.print_type_with_decl ~verbosity env ppf lbl_arg;
Some (loc, String (to_string ()), `No)
| Some Context.Constant -> None
| _ ->
let context = Option.value ~default:Context.Expr context in
Expand Down
53 changes: 53 additions & 0 deletions tests/test-dirs/type-enclosing/issue1564.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
$ cat >main.ml <<EOF
> module Kind = struct
> type t =
> | A
> | B
> end
> type t = { kind : Kind.t }
> let x = { kind = A }
> let y = x.kind
> let z = { kind = B }.kind
> EOF

On `let |y = x.kind`
Verbosity 0 stops at Kind.t
$ $MERLIN single type-enclosing -position 8:4 -verbosity 0 \
> -filename ./main.ml < ./main.ml | tr '\r\n' ' ' | jq ".value[0].type"
"Kind.t"

On `let |y = x.kind`
Verbosity 1 shows the actual type definition of Kind.t
$ $MERLIN single type-enclosing -position 8:4 -verbosity 1 \
> -filename ./main.ml < ./main.ml | tr '\r\n' ' ' | jq ".value[0].type"
"type t = A | B"

On `let y = x.k|ind`
$ $MERLIN single type-enclosing -position 8:11 -verbosity 0 \
> -filename ./main.ml < ./main.ml | tr '\r\n' ' ' | jq ".value[0].type"
"Kind.t"

On `let y = x.k|ind`
$ $MERLIN single type-enclosing -position 8:11 -verbosity 1 \
> -filename ./main.ml < ./main.ml | tr '\r\n' ' ' | jq ".value[0].type"
"type t = A | B"

On `let z = { kind = B }.k|ind`
$ $MERLIN single type-enclosing -position 9:22 -verbosity 0 \
> -filename ./main.ml < ./main.ml | tr '\r\n' ' ' | jq ".value[0].type"
"Kind.t"

On `let z = { kind = B }.k|ind`
$ $MERLIN single type-enclosing -position 9:22 -verbosity 1 \
> -filename ./main.ml < ./main.ml | tr '\r\n' ' ' | jq ".value[0].type"
"type t = A | B"

On `let x = { k|ind = A }`
$ $MERLIN single type-enclosing -position 7:12 -verbosity 0 \
> -filename ./main.ml < ./main.ml | tr '\r\n' ' ' | jq ".value[0].type"
"Kind.t"

On `let x = { k|ind = A }`
$ $MERLIN single type-enclosing -position 7:12 -verbosity 1 \
> -filename ./main.ml < ./main.ml | tr '\r\n' ' ' | jq ".value[0].type"
"type t = A | B"
2 changes: 1 addition & 1 deletion tests/test-dirs/type-enclosing/record.t/run.t
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ FIXME: The following results are not entirely satisfying (`foo.Bar -> foo` could
"line": 12,
"col": 18
},
"type": "unit",
"type": "type unit = ()",
"tail": "no"
},
{
Expand Down