serokell / nyan-interpolation

Flexible and extensible interpolation for Haskell
Mozilla Public License 2.0
4 stars 2 forks source link

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

Open s-and-witch opened 1 year ago

s-and-witch commented 1 year ago

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} |]

Martoon-00 commented 1 year ago

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

s-and-witch commented 1 year ago

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 commented 1 year ago

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

So, that's unfortunate :thinking: 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 commented 1 year ago

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 commented 1 year ago

Yeeah