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

Ambiguous TargetSelector crash #6874

Closed
lukel97 opened this issue Jun 4, 2020 · 5 comments · Fixed by #6875
Closed

Ambiguous TargetSelector crash #6874

lukel97 opened this issue Jun 4, 2020 · 5 comments · Fixed by #6875

Comments

@lukel97
Copy link
Contributor

lukel97 commented Jun 4, 2020

Describe the bug
In the project haskell-language-server, calling cabal repl exe/Arguments.hs from the root directory will give this error:

$ cabal repl exe/Arguments.hs 
TargetSelector: internal error: NoMatch
CallStack (from HasCallStack):
  error, called at ./Distribution/Client/TargetSelector.hs:669:3 in main:Distribution.Client.TargetSelector

This is because a subproject ghcide which is included in the packages field of cabal.project also has a module in a folder ghcide/exe/Arguments.hs.
This doesn't happen when calling cabal repl exe/Arguments.hs from inside ghcide.

Steps to reproduce
Working on getting a minimal test case

Expected behavior
Presumably in this scenario, cabal repl src/Arguments.hs should resolve to the src/Arguments.hs in the root project.

System information

  • cabal HEAD
@lukel97
Copy link
Contributor Author

lukel97 commented Jun 4, 2020

Turns out this is actually caused because there are two executables that build the same module, which in this case is indeed actually ambiguous. However it looks like the error is getting mangled and an internal one is thrown instead whenever the modules are located within a hs-source-dirs.

$ tree
.
├── cabal-ambig-sel.cabal
└── src
    └── F.hs

1 directory, 2 files
$ cat cabal-ambig-sel.cabal 
cabal-version:       >=1.10
-- Initial package description 'cabal-ambig-sel.cabal' generated by 'cabal
-- init'.  For further documentation, see
name:                cabal-ambig-sel
version:             0.1.0.0

executable A
  main-is: Main.hs
  hs-source-dirs: src
  other-modules: F

executable B
  main-is: Main.hs
  hs-source-dirs: src
  other-modules: F

In this test case, removing the hs-source-dirs and placing F.hs in the root produces the proper error

$ cabal repl F.hs
cabal: Ambiguous target 'F.hs'. It could be:
:pkg:cabal-ambig-sel:exe:A:file:F (file)
:pkg:cabal-ambig-sel:exe:B:file:F (file)

cabal-ambig-sel.tar.gz

@phadej
Copy link
Collaborator

phadej commented Jun 4, 2020

Have you tried with current master. There were patches improving how target selection for files behave.

@lukel97
Copy link
Contributor Author

lukel97 commented Jun 4, 2020

Yeah this is happening with 07c1a43
I've been poking through TargetSelector.hs and I'm still trying to wrap my head around what is making this an internal error, rather than a genuine ambiguous selector error

@phadej
Copy link
Collaborator

phadej commented Jun 4, 2020

Write a test case :)

lukel97 added a commit to lukel97/cabal that referenced this issue Jun 5, 2020
These should have been returning an error message but instead were
causing an internal error because disambiguateTargetSelectors was
rendering syntax and rematching on it, which isn't equivalent. Due to
the way syntaxForm1File renders, it does not add a FileStatus to its
TargetStringFileStatus and so cannot be matched upon again.
The fix is to just copy over the FileStatus from the match input.
This fixes haskell#6874
@lukel97
Copy link
Contributor Author

lukel97 commented Jun 5, 2020

PR created for fix. The reason why this was working with the case where there was no hs-source-dir was by coincidence --- since files Foo.hs are rendered as Foo, this just happened to match the module syntax.

lukel97 added a commit to lukel97/cabal that referenced this issue Jun 5, 2020
These should have been returning an error message but instead were
causing an internal error because disambiguateTargetSelectors was
rendering syntax and rematching on it, which isn't equivalent. Due to
the way syntaxForm1File renders, it does not add a FileStatus to its
TargetStringFileStatus and so cannot be matched upon again.
The fix is to just copy over the FileStatus from the match input.
This fixes haskell#6874
lukel97 added a commit to lukel97/cabal that referenced this issue Jun 5, 2020
These should have been returning an error message but instead were
causing an internal error because disambiguateTargetSelectors was
rendering syntax and rematching on it, which isn't equivalent. Due to
the way syntaxForm1File renders, it does not add a FileStatus to its
TargetStringFileStatus and so cannot be matched upon again.
The fix is to just copy over the FileStatus from the match input.
This fixes haskell#6874
lukel97 added a commit to lukel97/cabal that referenced this issue Jun 6, 2020
These should have been returning an error message but instead were
causing an internal error because disambiguateTargetSelectors was
rendering syntax and rematching on it, which isn't equivalent. Due to
the way syntaxForm1File renders, it does not add a FileStatus to its
TargetStringFileStatus and so cannot be matched upon again.
The fix is to just copy over the FileStatus from the match input.
This fixes haskell#6874
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

Successfully merging a pull request may close this issue.

2 participants