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

[BUG] -XOverloadedRecordDot doesn't handle properly #28

Open
s-and-witch opened this issue Oct 6, 2023 · 5 comments
Open

[BUG] -XOverloadedRecordDot doesn't handle properly #28

s-and-witch opened this issue Oct 6, 2023 · 5 comments
Labels
bug Something isn't working

Comments

@s-and-witch
Copy link

Description

Attempt to use -XOverloadedRecordDot inside the interpolation would cause an error, because foo.bar is parsed as foo . bar

To Reproduce

{-# LANGUAGE QuasiQuotes, TemplateHaskell, OverloadedRecordDot, NoFieldSelectors #-}
module Main where
import Text.Interpolation.Nyan
import Data.Text (Text)

main :: IO ()
main = pure ()

data X = MkX { field :: Int }

foo :: X -> Text
foo x = [int|| X is #{x.field} |]

This would cause an error:

    • Variable not in scope: field :: a0 -> b0

If you try to remove -XNoFieldSelectors, then there would be an error about types mismatch

    • Couldn't match expected type ‘Int -> c0’ with actual type ‘X’
    • In the first argument of ‘(.)’, namely ‘x’

Expected behavior

Successful compilation, like in foo x = let f = x.field in [int|| X is #{f} |]

@s-and-witch s-and-witch added the bug Something isn't working label Oct 6, 2023
@Martoon-00
Copy link
Member

A quick check: do you depend on template-haskell and haskell-src-meta versions that support OverloadedRecordDot extension?

@s-and-witch
Copy link
Author

s-and-witch commented Oct 6, 2023

do you depend on template-haskell

template-haskell library comes with GHC and definitely supports -XOverloadedRecordDot

and haskell-src-meta

haskell-src-meta uses haskell-src-exts (which is not a Haskell parser) to parse Haskell code. HSE was not updated since 2020 and cannot support -XOverloadedRecordDot because GHC 9.2.1 (which introduces -XOverloadedRecordDot) was released in 29th October 2021.

@Martoon-00
Copy link
Member

Ah yeah, haskell-src-exts rather matters here, and I use it as a parser here.

So, that's unfortunate 🤔 If you can recommend which library to use for parsing Haskell, that could also account for the currently enabled extensions (till now I obtained them from TH context), that would be a good starting point for the fix.

@s-and-witch
Copy link
Author

I don't know such libraries.

I'm scary that we would have to come with GHC proposal that will expose parsing API, because GHC seems to be the only way to parse GHC/Haskell and depending on the whole ghc-lib is too excessive for just a library for interpolation.

@Martoon-00
Copy link
Member

Yeeah

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants