MercuryTechnologies / ghciwatch

Load a GHCi session for a Haskell project and reload it when source files change
https://mercurytechnologies.github.io/ghciwatch/
MIT License
105 stars 9 forks source link

Fix "module defined in multiple files" AGAIN!!!! #237

Closed 9999years closed 4 months ago

9999years commented 4 months ago

In https://github.com/MercuryTechnologies/ghciwatch/pull/214, we had a situation where modules were loaded:

ghci> :show targets
Foo
Bar
Baz

And then an eval comment in (e.g.) Foo causes the module to be added and explicitly interpreted by path:

ghci> :add *src/Foo.hs

Then, we have Foo loaded by name (Foo) and by path (src/Foo.hs), which triggers the dreaded bug.

At the time I proposed this fix, correctly:

I think we can fix this by keeping track of how each module is added to the session — as a path or as a module name — and then only using that form going forward.

I threaded some extra information to the :show targets parser to track if modules were listed as names or paths, but then at the end of Ghci::interpret_module I would always insert the module into the target set as a TargetKind::Path, meaning that the next time the comment was evaluated, the module would be loaded as a path, causing the error.

https://github.com/MercuryTechnologies/ghciwatch/blob/dbba61bbdec9a86f97051b12647e51b7be4fd484/src/ghci/mod.rs#L698-L699

This fixes the bug and adds an assert! to fail faster and more obviously if it happens again.

Prior art

linear[bot] commented 4 months ago

DUX-2298 Fix "module defined in multiple files"

github-actions[bot] commented 4 months ago

A PR to release these changes has been created, bumping the version from 0.5.11 to 0.5.12.