Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Short-paths handles open poorly #1873

Open
liam923 opened this issue Dec 12, 2024 · 0 comments
Open

Short-paths handles open poorly #1873

liam923 opened this issue Dec 12, 2024 · 0 comments

Comments

@liam923
Copy link
Contributor

liam923 commented Dec 12, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant