Skip to content

Conversation

@9999years
Copy link
Member

Haskell source paths, as GHC understands them, are remarkably permissive: they must end with one of the source extensions (now more accurately listed here, with references to the upstream GHC code), but can otherwise contain quirks up to and including multiple extensions, whitespace, and newlines.

GHCi is actually even more lenient than this in what it accepts; it'll automatically append .hs and .lhs to paths you give it and check if those exist, but fortunately they get printed out in :show targets and diagnostics as the resolved source paths:

ghci> :add src/MyLib
[1 of 1] Compiling MyLib            ( src/MyLib.hs, interpreted )

ghci> :show targets
src/MyLib.hs

ghci> :add src/Foo
target ‘src/Foo’ is not a module name or a source file

ghci> :add src/MyLib.lhs
File src/MyLib.lhs not found

ghci> :add "src/ Foo.hs"
File src/ Foo.hs not found

ghci> :add "src\n/Foo.hs"
File src
/Foo.hs not found

Split off of #297

@linear
Copy link

linear bot commented Jun 21, 2024

@9999years 9999years requested a review from Gabriella439 June 21, 2024 20:56
@github-actions github-actions bot added the patch Bug fixes or non-functional changes label Jun 21, 2024
Haskell source paths, as GHC understands them, are remarkably
permissive: they must end with one of the source extensions (now more
accurately listed here, with references to the upstream GHC code), but
can otherwise contain quirks up to and including multiple extensions,
whitespace, and newlines.

GHCi is actually even more lenient than this in what it accepts; it'll
automatically append `.hs` and `.lhs` to paths you give it and check if
those exist, but fortunately they get printed out in `:show targets` and
diagnostics as the resolved source paths:

```text
ghci> :add src/MyLib
[1 of 1] Compiling MyLib            ( src/MyLib.hs, interpreted )

ghci> :show targets
src/MyLib.hs

ghci> :add src/Foo
target ‘src/Foo’ is not a module name or a source file

ghci> :add src/MyLib.lhs
File src/MyLib.lhs not found

ghci> :add "src/ Foo.hs"
File src/ Foo.hs not found

ghci> :add "src\n/Foo.hs"
File src
/Foo.hs not found
```
@9999years 9999years force-pushed the wiggles/dux-2349-parse-haskell-source-paths-more-reliably branch from 1e3dda0 to 13747a1 Compare June 21, 2024 21:02
@9999years 9999years mentioned this pull request Jun 21, 2024
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

patch Bug fixes or non-functional changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant