merlin
merlin copied to clipboard
Failure to report short paths with intervening packages
Suppose I have
open Core
let _ = Filename.dirname
and ask for the type of the _ (with -short-paths). I get Base.string -> Base.string, instead of the desired string -> string. This seems like a bug.
My testing setup: a dune project, with this dune file:
(library
(public_name merlin_bug)
(name merlin_bug)
(libraries core))
After building, this invocation shows the Base.string -> Base.string type:
ocamlmerlin single type-enclosing -position 3:4 -index 0 -filename merlin_bug.ml -verbosity 0 -short-paths < merlin_bug.ml
I don't think this is an issue with -short-paths. The type of Core.Filename.dirname really is Base.string -> Base.string: https://ocaml.org/p/core/v0.16.0/doc/Core/Filename/index.html#val-dirname
Since Base is not opened there is no reason for short path to remove these prefixes.
But Base.string is an abbreviation for string. Is that not what -short-paths is trying to address?
But has base actually been loaded?
The aim of -short-paths is to use the information it already has in the typing environment but to avoid loading any more cmi files.
Ah -- I didn't realize that.
I edited the file to be
open Core
module Foo = Base.Int
let _ = Filename.dirname
which would seem to force loading of Base. But I still see Base.string -> Base.string in the output (after adjusting the line number).
In my attempt I was able to get the short paths by doing:
open Base
open Core
let _ = Filename.dirname
That doesn't surprise me. But I would expect not to need to open Base to get the short paths -- that is, unless I'm misunderstanding the goal of -short-paths.
To expand a bit: My understanding of -short-paths is that it instructs OCaml / merlin to produce the shortest path it knows that is equal to a given path. string is definitely shorter than Base.string. And, regardless of what is opened, the compiler has access to the knowledge that Base.string = string. So, perhaps I have my picture of -short-paths wrong, or maybe my picture of what the compiler knows is wrong. But my last example above, which uses Base directly, seems to suggest that even if Base is all loaded (and thus that the compiler really does know that Base.string = string), it still doesn't produce the shortest path.