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

regression: defaultInterpretOptions is not inherited from parent record #2470

Open
smarwei opened this issue Nov 10, 2022 · 1 comment
Open

Comments

@smarwei
Copy link

smarwei commented Nov 10, 2022

It seems like I stumbled upon a bug, which was already fixed in #33 a few years ago.
I slightly adjusted the old example:

{-# LANGUAGE DeriveGeneric     #-}
{-# LANGUAGE OverloadedStrings #-}
 
module Main where

import Dhall
import qualified Data.Text


data GitRepo
  = GitRepo
  { _host :: Text
  , _repo :: Text
  } deriving (Generic, Show)

data BoxConfig
  = BoxConfig
  { _userName        :: Text
  , _dotfilesRepo    :: GitRepo
  } deriving (Generic, Show)

instance FromDhall GitRepo
instance FromDhall BoxConfig


main :: IO ()
main = do
    let auto' = genericAutoWith
            (defaultInterpretOptions { fieldModifier = Data.Text.dropWhile (== '_') })
    x <- input auto' "./config.dhall"
    print (x :: BoxConfig)

Prepending _ only works for top-level attributes.

@Gabriella439
Copy link
Collaborator

Yeah, this change in behavior was intentional and is due to:

#1696

The basic idea is that InterpretOptions are no longer applied globally but are now specified on a type-by-type basis, so the way you would fix your example is to do this:

{-# LANGUAGE DeriveGeneric     #-}
{-# LANGUAGE OverloadedStrings #-}
 
module Main where

import Dhall
import qualified Data.Text


data GitRepo
  = GitRepo
  { _host :: Text
  , _repo :: Text
  } deriving (Generic, Show)

data BoxConfig
  = BoxConfig
  { _userName        :: Text
  , _dotfilesRepo    :: GitRepo
  } deriving (Generic, Show)

instance FromDhall GitRepo where
    autoWith =
      genericAutoWithInputNormalizer defaultInterpretOptions
        { fieldModifier = Data.Text.dropWhile (== '_') }

instance FromDhall BoxConfig where
    autoWith =
      genericAutoWithInputNormalizer defaultInterpretOptions
        { fieldModifier = Data.Text.dropWhile (== '_') }


main :: IO ()
main = do
    x <- input auto "./config.dhall"
    print (x :: BoxConfig)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants