guibou / PyF

Haskell QuasiQuoter for String Formatting
BSD 3-Clause "New" or "Revised" License
66 stars 13 forks source link

Variable scoping broken? #111

Closed michaelpj closed 2 years ago

michaelpj commented 2 years ago

Updating to 0.11, all our uses of PyF broke. I can't even make the example from the README work any more:

GHCi, version 8.10.7: https://www.haskell.org/ghc/  :? for help
Prelude> import PyF
Prelude PyF> :set -XQuasiQuotes
Prelude PyF> name = "Dave"
Prelude PyF> age = 54
Prelude PyF> [fmt|Person's name is {name}, age is {age}|]

<interactive>:5:24: error:
    • Variable not in scope: name
    • In the quasi-quotation:
        [fmt|Person's name is {name}, age is {age}|]
Prelude PyF> 

This is very weird!

guibou commented 2 years ago

Thank you for this report.

That's indeed really weird.

I'm using some magic with template Haskell to check for name and apparently this is broken in the context of GHCI.

I cannot reproduce using cabal repl:

$ nix develop .#pyf_810
$ cabal repl
GHCi, version 8.10.7: https://www.haskell.org/ghc/  :? for help

... build output
Ok, 8 modules loaded.
*PyF> :set -XQuasiQuotes 
*PyF> age = 54
*PyF> name = "Dave"
*PyF> [fmt|Persan's name is {name}, age is {age}|]
(... defaulting warnings)
"Persan's name is Dave, age is 54"

I will investigate what is happening with a different ghci or cabal setup.

guibou commented 2 years ago

Does it works outside of a repl, when compiling the file?

michaelpj commented 2 years ago

Hmmmm, my initial problem was in a compiled file (I think all of them). I just reported the GHCi example because it seemed like a smoking gun! I'll see if I can make a smaller reproducer.

michaelpj commented 2 years ago

Some confusing progress... it works on macos and not on linux! :scream:

michaelpj commented 2 years ago

Notes:

Overall I think this is likely something very specific on our end, rather than a problem in PyF. I'll reopen if we find something.