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

[DUX-2916] Single file with --enable-eval errors #335

Open
cideM opened this issue Dec 30, 2024 · 1 comment
Open

[DUX-2916] Single file with --enable-eval errors #335

cideM opened this issue Dec 30, 2024 · 1 comment
Labels
linear Created by Linear-GitHub Sync Low priority Created by Linear-GitHub Sync

Comments

@cideM
Copy link

cideM commented Dec 30, 2024

What happened?

Given this file foo.hs

myGreeting :: String
myGreeting = "Hello"

-- $> putStrLn (myGreeting <> " " <> myGreeting)

I get the following output

❯ ghciwatch foo.hs --enable-eval --clear
GHCi, version 9.6.6: https://www.haskell.org/ghc/  :? for help
[1 of 2] Compiling Main             ( foo.hs, interpreted )
Ok, one module loaded.
• All good! Finished starting up in 6.09s
• foo.hs:4:7: putStrLn (myGreeting <> " " <> myGreeting)
[1 of 2] Compiling Main             ( foo.hs, interpreted )
Ok, one module loaded.
Error:   × Tasks failed:
  │ • run_ghci: Couldn't convert /Users/fbs/private/advent_of_code/aoc2024-haskell/foo to
  │ module name

What did you expect to happen?

See the output from the example:

• src/MyLib.hs:9:7: putStrLn (myGreeting <> " " <> myGreeting)
Hello Hello

Steps to reproduce the issue

No response

The version of ghciwatch with the bug

ghciwatch 1.0.2

DUX-2916

@github-actions github-actions bot added the linear Created by Linear-GitHub Sync label Dec 30, 2024
@cideM cideM changed the title enable-eval results in error --enable-eval doesn't work for example Dec 30, 2024
@9999years 9999years changed the title --enable-eval doesn't work for example Single file with --enable-eval errors Jan 3, 2025
@9999years 9999years added linear Created by Linear-GitHub Sync and removed linear Created by Linear-GitHub Sync labels Jan 3, 2025
@9999years 9999years changed the title Single file with --enable-eval errors [DUX-2916] Single file with --enable-eval errors Jan 3, 2025
@9999years 9999years added the Low priority Created by Linear-GitHub Sync label Jan 3, 2025
@9999years
Copy link
Member

Thanks for the report! Looks like ghciwatch is trying to convert foo.hs to a module name in the GHCi search paths, which isn't working because we're not in a cabal project.

Related: #69, #238

Not sure how easy this would be to fix, but you're welcome to take a stab at it. Maybe the :module + *MODULE_NAME syntax doesn't work with paths? If it's not possible to make that work, there's a few options:

  • Print a warning explaining why it won't work instead of failing the whole program.
  • Maybe print a warning explaining that unexported top-level bindings won't be available and skip the :module + *MODULE_NAME command?

Here's the responsible code:

ghciwatch/src/ghci/mod.rs

Lines 571 to 584 in 2d61403

// If the `module` was already compiled, `ghci` may have loaded the interface file instead
// of the interpreted bytecode, giving us this error message when we attempt to
// load the top-level scope with `:module + *{module}`:
//
// module 'Mercury.Typescript.Golden' is not interpreted
//
// We use `:add *{module}` to force interpreting the module. We do this here instead of in
// `add_module` to save time if eval commands aren't used (or aren't needed for a
// particular module).
self.interpret_module(&path, log).await?;
let module = self.search_paths.path_to_module(&path)?;
self.stdin
.eval(&mut self.stdout, &module, &command.command, log)
.await?;

self.write_line(stdout, &format!(":module + *{module_name}\n"), log)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
linear Created by Linear-GitHub Sync Low priority Created by Linear-GitHub Sync
Projects
None yet
Development

No branches or pull requests

2 participants