merlin icon indicating copy to clipboard operation
merlin copied to clipboard

Short-paths handles `open` poorly

Open liam923 opened this issue 1 year ago • 1 comments

Here's a cram test demonstrating the issue:

We get a bad path for `hello`

  $ cat > foo.ml <<EOF
  > module Foo = struct
  >   type t
  > end
  > 
  > module Bar = struct
  >   module Foo = struct
  >     type t = Foo.t
  >   end
  > end
  > 
  > open! Bar
  > 
  > let hello : Foo.t = 0
  > EOF

It happens regardless of whether short-paths is enabled
  $ $MERLIN single type-enclosing -position 13:5 -filename foo.ml < foo.ml | jq .value[0].type -r
  Bar.Foo.t

  $ echo "FLG -short-paths" > .merlin
  $ $MERLIN single type-enclosing -position 13:5 -filename foo.ml < foo.ml | jq .value[0].type -r
  Bar.Foo.t

It seems to be related to shadowing somehow. This works:
  $ cat > foo.ml <<EOF
  > module Foo = struct
  >   type t
  > end
  > 
  > module Bar = struct
  >   module Baz = struct
  >     type t = Foo.t
  >   end
  > end
  > 
  > open! Bar
  > 
  > let hello : Baz.t = 0
  > EOF

  $ $MERLIN single type-enclosing -position 13:5 -filename foo.ml < foo.ml | jq .value[0].type -r
  Foo.t

I gave a bit of a go at debugging this, but I got stuck. It seems that short paths tries to write the type in terms of the first Foo.t, but it recognizes that the first Foo isn't visible, so it invalidates that path. Then, it doesn't ever try writing in terms of the second Foo, which comes into scope via the open.

liam923 avatar Dec 12 '24 17:12 liam923

Thanks @liam923, I will add these to the testsuite.

voodoos avatar Dec 18 '24 09:12 voodoos