merlin
merlin copied to clipboard
correct fields of incorrect record expression are dropped
In the following example:
type t = C of int
type record = { field : t; other : bool; }
let f () =
let field = 42 in
{ field (* <--- asking the type for this field *) = C field ; other = true }
We get int
instead of t
. I get this result both with Emacs and VSCode.
Note that, if we remove field other
, then getting a code like this:
type t = C of int
type record = { field : t; }
let f () =
let field = 42 in
{ field (* <--- asking the type for this field *) = C field }
We correctly get t
.
Other behavior, if we remove the local field
variable, thus getting the following code:
type t = C of int
type record = { field : t; other : bool; }
let f () =
{ field (* <--- asking the type for this field *) = C 42 ; other = true }
We get the error Unbound value field
on Emacs and I can't ask the type of field
on VSCode.
I found an issue that seems to be related: https://github.com/ocaml/merlin/issues/864. It was fixed in https://github.com/ocaml/merlin/pull/1108, thus Merlin version 3.3.5. I am currently using 4.2-411 with OCaml 4.11.0.
I do observe the behaviour you are describing when using vscode (and thus ocaml-lsp).
But everything works well in Emacs when using merlin-mode
, are you sure that is not the case for you ?
Or maybe you use OCaml-LSP for emacs too ?
When adding a case to the test suite Merlin gives the correct answer:
$ cat >test.ml <<EOF
> type t = C of int
> type record = { field : t; other : bool; }
>
> let f () =
> let field = 42 in
> { field = C field ; other = true }
> EOF
$ ocamlmerlin single type-enclosing -verbosity 0 \
> -filename test.ml -position 6:8 < test.ml | jq '.value[0]'
{
"start": {
"line": 6,
"col": 5
},
"end": {
"line": 6,
"col": 10
},
"type": "t",
"tail": "no"
}
My guess would be that this is not a Merlin issue but an OCaml-LSP one... @ulugbekna ?
Seems fine to me with the ocaml-lsp master (and latest release 1.6.1). Since the user reported a specific merlin version, I think they don't use ocaml-lsp.
@voodoos with which ocaml-lsp version do you observe this?
I was on your construct branch :-)
But the issue persists after upgrading to 1.7.0:
(new file, no build)
Since the user reported a specific merlin version, I think they don't use ocaml-lsp.
He also mentioned VSCode so he is probably using ocaml-lsp
too ?
I was on your construct branch :-)
I should've let you know that we merged it into master (along with refactor-open
support and other cool things), so you can pin master now :-)
He also mentioned VSCode so he is probably using ocaml-lsp too ?
Sorry, I missed it.
The ocaml-lsp master branch doesn't have this problem, so @AllanBlanchard you can opam pin
the master of ocaml-lsp, if you want.
We can probably close this issue.
Or maybe you use OCaml-LSP for emacs too ?
I don't. I just created a fresh Ocaml 4.11.0 switch on a virtual machine with:
- emacs fresh install,
- merlin 4.2-411
- tuareg 2.2.0
- user-setup
There is no Ocaml LSP server on this switch. I get this:
I tried your command above:
Thanks for the screenshot!
The issue here is that the record fails to type as is (some fields are missing), and our recovery is not smart enough to keep the fields, so it drops the whole record. We hope to improve on this at some point, but I don't know when that will happen.
Argh, I took the wrong screenshot ... So with a well-typed record:
Ah indeed! Well this is fixed on master, since 24fa9a04648df92a1d3770e568762f8cf7db74c0 apparently. The fix is included in the 4.3 release which reached opam 3 days ago, so if you update, you should be good!
Good to know! Thank you for your time :)