merlin icon indicating copy to clipboard operation
merlin copied to clipboard

Failure to report short paths with intervening packages

Open goldfirere opened this issue 2 years ago • 10 comments

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

goldfirere avatar Jun 28 '23 11:06 goldfirere

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.

voodoos avatar Jun 28 '23 13:06 voodoos

But Base.string is an abbreviation for string. Is that not what -short-paths is trying to address?

goldfirere avatar Jun 29 '23 13:06 goldfirere

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.

trefis avatar Jun 29 '23 13:06 trefis

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).

goldfirere avatar Jun 29 '23 14:06 goldfirere

In my attempt I was able to get the short paths by doing:

open Base
open Core

let _ = Filename.dirname

voodoos avatar Jul 05 '23 13:07 voodoos

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.

goldfirere avatar Jul 05 '23 13:07 goldfirere

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.

goldfirere avatar Jul 05 '23 13:07 goldfirere