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

fails to build with aeson-2.0 #72

Open
juhp opened this issue Nov 28, 2021 · 1 comment
Open

fails to build with aeson-2.0 #72

juhp opened this issue Nov 28, 2021 · 1 comment

Comments

@juhp
Copy link

juhp commented Nov 28, 2021

etc                            > Building library for etc-0.4.1.0..
etc                            > [ 1 of 13] Compiling Paths_etc
etc                            > [ 2 of 13] Compiling System.Etc.Internal.Spec.Types
etc                            > 
etc                            > /tmp/stack-118e294368372c73/etc-0.4.1.0/src/System/Etc/Internal/Spec/Types.hs:50:10: warning: [-Wmissing-methods]
etc                            >     • No explicit implementation for
etc                            >         ‘liftTyped’
etc                            >     • In the instance declaration for ‘Lift CliOptMetadata’
etc                            >    |
etc                            > 50 | instance Lift CliOptMetadata where
etc                            >    |          ^^^^^^^^^^^^^^^^^^^
etc                            > 
etc                            > /tmp/stack-118e294368372c73/etc-0.4.1.0/src/System/Etc/Internal/Spec/Types.hs:73:10: warning: [-Wmissing-methods]
etc                            >     • No explicit implementation for
etc                            >         ‘liftTyped’
etc                            >     • In the instance declaration for ‘Lift CliArgMetadata’
etc                            >    |
etc                            > 73 | instance Lift CliArgMetadata where
etc                            >    |          ^^^^^^^^^^^^^^^^^^^
etc                            > 
etc                            > /tmp/stack-118e294368372c73/etc-0.4.1.0/src/System/Etc/Internal/Spec/Types.hs:92:10: warning: [-Wmissing-methods]
etc                            >     • No explicit implementation for
etc                            >         ‘liftTyped’
etc                            >     • In the instance declaration for ‘Lift CliSwitchMetadata’
etc                            >    |
etc                            > 92 | instance Lift CliSwitchMetadata where
etc                            >    |          ^^^^^^^^^^^^^^^^^^^^^^
etc                            > 
etc                            > /tmp/stack-118e294368372c73/etc-0.4.1.0/src/System/Etc/Internal/Spec/Types.hs:109:10: warning: [-Wmissing-methods]
etc                            >     • No explicit implementation for
etc                            >         ‘liftTyped’
etc                            >     • In the instance declaration for ‘Lift CliEntryMetadata’
etc                            >     |
etc                            > 109 | instance Lift CliEntryMetadata where
etc                            >     |          ^^^^^^^^^^^^^^^^^^^^^
etc                            > 
etc                            > /tmp/stack-118e294368372c73/etc-0.4.1.0/src/System/Etc/Internal/Spec/Types.hs:124:10: warning: [-Wmissing-methods]
etc                            >     • No explicit implementation for
etc                            >         ‘liftTyped’
etc                            >     • In the instance declaration for ‘Lift (CliEntrySpec cmd)’
etc                            >     |
etc                            > 124 | instance Lift cmd => Lift (CliEntrySpec cmd) where
etc                            >     |          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
etc                            > 
etc                            > /tmp/stack-118e294368372c73/etc-0.4.1.0/src/System/Etc/Internal/Spec/Types.hs:140:10: warning: [-Wmissing-methods]
etc                            >     • No explicit implementation for
etc                            >         ‘liftTyped’
etc                            >     • In the instance declaration for ‘Lift CliCmdSpec’
etc                            >     |
etc                            > 140 | instance Lift CliCmdSpec where
etc                            >     |          ^^^^^^^^^^^^^^^
etc                            > 
etc                            > /tmp/stack-118e294368372c73/etc-0.4.1.0/src/System/Etc/Internal/Spec/Types.hs:156:10: warning: [-Wmissing-methods]
etc                            >     • No explicit implementation for
etc                            >         ‘liftTyped’
etc                            >     • In the instance declaration for ‘Lift (ConfigSources cmd)’
etc                            >     |
etc                            > 156 | instance Lift cmd => Lift (ConfigSources cmd) where
etc                            >     |          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
etc                            > 
etc                            > /tmp/stack-118e294368372c73/etc-0.4.1.0/src/System/Etc/Internal/Spec/Types.hs:200:10: warning: [-Wmissing-methods]
etc                            >     • No explicit implementation for
etc                            >         ‘liftTyped’
etc                            >     • In the instance declaration for ‘Lift (ConfigValue cmd)’
etc                            >     |
etc                            > 200 | instance Lift cmd => Lift (ConfigValue cmd) where
etc                            >     |          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
etc                            > 
etc                            > /tmp/stack-118e294368372c73/etc-0.4.1.0/src/System/Etc/Internal/Spec/Types.hs:216:10: warning: [-Wmissing-methods]
etc                            >     • No explicit implementation for
etc                            >         ‘liftTyped’
etc                            >     • In the instance declaration for ‘Lift CliProgramSpec’
etc                            >     |
etc                            > 216 | instance Lift CliProgramSpec where
etc                            >     |          ^^^^^^^^^^^^^^^^^^^
etc                            > 
etc                            > /tmp/stack-118e294368372c73/etc-0.4.1.0/src/System/Etc/Internal/Spec/Types.hs:231:10: warning: [-Wmissing-methods]
etc                            >     • No explicit implementation for
etc                            >         ‘liftTyped’
etc                            >     • In the instance declaration for ‘Lift FilesSpec’
etc                            >     |
etc                            > 231 | instance Lift FilesSpec where
etc                            >     |          ^^^^^^^^^^^^^^
etc                            > 
etc                            > /tmp/stack-118e294368372c73/etc-0.4.1.0/src/System/Etc/Internal/Spec/Types.hs:251:10: warning: [-Wmissing-methods]
etc                            >     • No explicit implementation for
etc                            >         ‘liftTyped’
etc                            >     • In the instance declaration for ‘Lift (ConfigSpec cmd)’
etc                            >     |
etc                            > 251 | instance Lift cmd => Lift (ConfigSpec cmd) where
etc                            >     |          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
etc                            > [ 3 of 13] Compiling System.Etc.Internal.Errors
etc                            > [ 4 of 13] Compiling System.Etc.Internal.Spec.Parser
etc                            > 
etc                            > /tmp/stack-118e294368372c73/etc-0.4.1.0/src/System/Etc/Internal/Spec/Parser.hs:108:37: error:
etc                            >     • Couldn't match type: Data.Aeson.KeyMap.KeyMap JSON.Value
etc                            >                      with: HashMap Text v1
etc                            >       Expected: HashMap Text v1
etc                            >         Actual: JSON.Object
etc                            >     • In the first argument of ‘HashMap.keys’, namely ‘object’
etc                            >       In the first argument of ‘forM_’, namely ‘(HashMap.keys object)’
etc                            >       In the first argument of ‘($)’, namely
etc                            >         ‘forM_ (HashMap.keys object)’
etc                            >     |
etc                            > 108 |                 forM_ (HashMap.keys object) $ \key ->
etc                            >     |                                     ^^^^^^
etc                            > 
etc                            > /tmp/stack-118e294368372c73/etc-0.4.1.0/src/System/Etc/Internal/Spec/Parser.hs:115:37: error:
etc                            >     • Couldn't match type: Data.Aeson.KeyMap.KeyMap JSON.Value
etc                            >                      with: HashMap Text v2
etc                            >       Expected: HashMap Text v2
etc                            >         Actual: JSON.Object
etc                            >     • In the first argument of ‘HashMap.keys’, namely ‘object’
etc                            >       In the first argument of ‘forM_’, namely ‘(HashMap.keys object)’
etc                            >       In the first argument of ‘($)’, namely
etc                            >         ‘forM_ (HashMap.keys object)’
etc                            >     |
etc                            > 115 |                 forM_ (HashMap.keys object) $ \key ->
etc                            >     |                                     ^^^^^^
etc                            > 
etc                            > /tmp/stack-118e294368372c73/etc-0.4.1.0/src/System/Etc/Internal/Spec/Parser.hs:122:37: error:
etc                            >     • Couldn't match type: Data.Aeson.KeyMap.KeyMap JSON.Value
etc                            >                      with: HashMap Text v3
etc                            >       Expected: HashMap Text v3
etc                            >         Actual: JSON.Object
etc                            >     • In the first argument of ‘HashMap.keys’, namely ‘object’
etc                            >       In the first argument of ‘forM_’, namely ‘(HashMap.keys object)’
etc                            >       In the first argument of ‘($)’, namely
etc                            >         ‘forM_ (HashMap.keys object)’
etc                            >     |
etc                            > 122 |                 forM_ (HashMap.keys object) $ \key ->
etc                            >     |                                     ^^^^^^
etc                            > 
etc                            > /tmp/stack-118e294368372c73/etc-0.4.1.0/src/System/Etc/Internal/Spec/Parser.hs:221:40: error:
etc                            >     • Couldn't match type: Data.Aeson.KeyMap.KeyMap JSON.Value
etc                            >                      with: HashMap k1 JSON.Value
etc                            >       Expected: HashMap k1 JSON.Value
etc                            >         Actual: JSON.Object
etc                            >     • In the second argument of ‘HashMap.lookup’, namely ‘object’
etc                            >       In the expression: HashMap.lookup "etc/spec" object
etc                            >       In the expression:
etc                            >         case HashMap.lookup "etc/spec" object of
etc                            >           Nothing
etc                            >             -> do subConfigMap <- foldM
etc                            >                                     (\ subConfigMap (key, value) -> ...) HashMap.empty
etc                            >                                     (HashMap.toList object)
etc                            >                   if HashMap.null subConfigMap then
etc                            >                       fail "Entries cannot have empty maps as values"
etc                            >                   else
etc                            >                       return (SubConfig subConfigMap)
etc                            >           Just (JSON.Object fieldSpec)
etc                            >             -> if HashMap.size object == 1 then
etc                            >                    do let ...
etc                            >                       ....
etc                            >                else
etc                            >                    fail "etc/spec object can only contain one key"
etc                            >           Just _ -> fail "etc/spec value must be a JSON object"
etc                            >     |
etc                            > 221 |         case HashMap.lookup "etc/spec" object of
etc                            >     |                                        ^^^^^^
etc                            > 
etc                            > /tmp/stack-118e294368372c73/etc-0.4.1.0/src/System/Etc/Internal/Spec/Parser.hs:229:41: error:
etc                            >     • Couldn't match type: Data.Aeson.KeyMap.KeyMap JSON.Value
etc                            >                      with: HashMap Text JSON.Value
etc                            >       Expected: HashMap Text JSON.Value
etc                            >         Actual: JSON.Object
etc                            >     • In the first argument of ‘HashMap.toList’, namely ‘object’
etc                            >       In the third argument of ‘foldM’, namely ‘(HashMap.toList object)’
etc                            >       In a stmt of a 'do' block:
etc                            >         subConfigMap <- foldM
etc                            >                           (\ subConfigMap (key, value)
etc                            >                              -> do innerValue <- JSON.parseJSON value
etc                            >                                    return $ HashMap.insert key innerValue subConfigMap)
etc                            >                           HashMap.empty (HashMap.toList object)
etc                            >     |
etc                            > 229 |                         (HashMap.toList object)
etc                            >     |                                         ^^^^^^
etc                            > 
etc                            > /tmp/stack-118e294368372c73/etc-0.4.1.0/src/System/Etc/Internal/Spec/Parser.hs:237:29: error:
etc                            >     • Couldn't match type: Data.Aeson.KeyMap.KeyMap JSON.Value
etc                            >                      with: HashMap k0 v0
etc                            >       Expected: HashMap k0 v0
etc                            >         Actual: JSON.Object
etc                            >     • In the first argument of ‘HashMap.size’, namely ‘object’
etc                            >       In the first argument of ‘(==)’, namely ‘HashMap.size object’
etc                            >       In the expression: HashMap.size object == 1
etc                            >     |
etc                            > 237 |             if HashMap.size object == 1 then do
etc                            >     |                             ^^^^^^
etc                            > 
etc                            > /tmp/stack-118e294368372c73/etc-0.4.1.0/src/System/Etc/Internal/Spec/Parser.hs:240:81: error:
etc                            >     • Couldn't match type: Data.Aeson.KeyMap.KeyMap JSON.Value
etc                            >                      with: HashMap k2 a
etc                            >       Expected: HashMap k2 a
etc                            >         Actual: JSON.Object
etc                            >     • In the second argument of ‘HashMap.lookup’, namely ‘fieldSpec’
etc                            >       In the second argument of ‘($)’, namely
etc                            >         ‘HashMap.lookup "default" fieldSpec’
etc                            >       In the expression:
etc                            >         maybe Nothing Just $ HashMap.lookup "default" fieldSpec
etc                            >     • Relevant bindings include
etc                            >         mDefaultValue :: Maybe a
etc                            >           (bound at src/System/Etc/Internal/Spec/Parser.hs:240:19)
etc                            >     |
etc                            > 240 |               let mDefaultValue = maybe Nothing Just $ HashMap.lookup "default" fieldSpec
etc                            >     |                                                                                 ^^^^^^^^^
@nineonine
Copy link

In case someone needs a patch for this:

diff --git a/etc/src/System/Etc/Internal/Config.hs b/etc/src/System/Etc/Internal/Config.hs
index ed54c6b..1bee172 100644
--- a/etc/src/System/Etc/Internal/Config.hs
+++ b/etc/src/System/Etc/Internal/Config.hs
@@ -12,6 +12,8 @@ import qualified RIO.Text    as Text
 import qualified Data.Aeson          as JSON
 import qualified Data.Aeson.Internal as JSON (IResult (..), formatError, iparse)
 import qualified Data.Aeson.Types    as JSON (Parser)
+import qualified Data.Aeson.KeyMap   as KeyMap
+import qualified Data.Aeson.Key      as Key
 
 import System.Etc.Internal.Errors
 import System.Etc.Internal.Types
@@ -29,9 +31,9 @@ configValueToJsonObject configValue = case configValue of
     configm
       & HashMap.foldrWithKey
           (\key innerConfigValue acc ->
-            HashMap.insert key (configValueToJsonObject innerConfigValue) acc
+            KeyMap.insert (Key.fromText key) (configValueToJsonObject innerConfigValue) acc
           )
-          HashMap.empty
+          KeyMap.empty
       & JSON.Object
 
 _getConfigValueWith
diff --git a/etc/src/System/Etc/Internal/Extra/Printer.hs b/etc/src/System/Etc/Internal/Extra/Printer.hs
index 852aa52..a75ce32 100644
--- a/etc/src/System/Etc/Internal/Extra/Printer.hs
+++ b/etc/src/System/Etc/Internal/Extra/Printer.hs
@@ -19,6 +19,8 @@ import qualified RIO.Vector        as Vector
 import qualified RIO.Vector.Unsafe as Vector (unsafeHead)
 
 import qualified Data.Aeson as JSON
+import qualified Data.Aeson.KeyMap as KeyMap
+import qualified Data.Aeson.Key    as Key
 
 import Text.PrettyPrint.ANSI.Leijen
 
@@ -87,7 +89,8 @@ renderConfigValueJSON value = case value of
       --
       _            -> text (Text.unpack k) <> ":" <+> renderConfigValueJSON v
     )
-    (HashMap.toList obj)
+    (map (\(k,v) -> (Key.toText k, v)) $
+      KeyMap.toList obj)
 
 
 renderConfigValue :: (JSON.Value -> Doc) -> Value JSON.Value -> [Doc]
diff --git a/etc/src/System/Etc/Internal/Resolver/File.hs b/etc/src/System/Etc/Internal/Resolver/File.hs
index 3a32c8b..9122fbf 100644
--- a/etc/src/System/Etc/Internal/Resolver/File.hs
+++ b/etc/src/System/Etc/Internal/Resolver/File.hs
@@ -17,6 +17,8 @@ import System.Etc.Internal.Spec.YAML (decodeYaml)
 #endif
 
 import qualified Data.Aeson as JSON
+import qualified Data.Aeson.KeyMap as KeyMap
+import qualified Data.Aeson.Key    as Key
 -- import qualified Data.Aeson.Internal as JSON (IResult (..), iparse)
 import qualified RIO.ByteString.Lazy as LB8
 
@@ -61,7 +63,8 @@ parseConfigValue keys spec fileIndex fileSource json =
               return $ HashMap.insert key value1 acc
           )
           HashMap.empty
-          (HashMap.toList object)
+          (map (\(k,v) -> (Key.toText k, v)) $
+            KeyMap.toList object)
 
         (Spec.SubConfig{}, _) -> throwM $ SubConfigEntryExpected currentKey json
 
diff --git a/etc/src/System/Etc/Internal/Spec/Parser.hs b/etc/src/System/Etc/Internal/Spec/Parser.hs
index dd983fc..799186c 100644
--- a/etc/src/System/Etc/Internal/Spec/Parser.hs
+++ b/etc/src/System/Etc/Internal/Spec/Parser.hs
@@ -18,8 +18,10 @@ import qualified RIO.Vector.Partial as Vector (head)
 
 import Data.Aeson ((.:), (.:?))
 
-import qualified Data.Aeson       as JSON
-import qualified Data.Aeson.Types as JSON (Parser, typeMismatch)
+import qualified Data.Aeson        as JSON
+import qualified Data.Aeson.Types  as JSON (Parser, typeMismatch)
+import qualified Data.Aeson.KeyMap as KeyMap
+import qualified Data.Aeson.Key    as Key
 
 import System.Etc.Internal.Errors
 import System.Etc.Internal.Spec.Types
@@ -108,22 +110,22 @@ instance JSON.FromJSON cmd => JSON.FromJSON (CliEntrySpec cmd) where
           case value of
             JSON.String inputName
               | inputName == "option" -> do
-                forM_ (HashMap.keys object) $ \key ->
-                  when (not (key `elem` cliOptKeys))
+                forM_ (KeyMap.keys object) $ \key ->
+                  when (not (Key.toText key `elem` cliOptKeys))
                     (fail $ "cli option contains invalid key " ++ show key)
 
                 optParseEntryCtor <$> cliOptParser object
 
               | inputName == "argument" -> do
-                forM_ (HashMap.keys object) $ \key ->
-                  when (not (key `elem` cliArgKeys))
+                forM_ (KeyMap.keys object) $ \key ->
+                  when (not (Key.toText key `elem` cliArgKeys))
                     (fail $ "cli option contains invalid key " ++ show key)
 
                 optParseEntryCtor <$> cliArgParser object
 
               | inputName == "switch" -> do
-                forM_ (HashMap.keys object) $ \key ->
-                  when (not (key `elem` cliOptKeys))
+                forM_ (KeyMap.keys object) $ \key ->
+                  when (not (Key.toText key `elem` cliOptKeys))
                     (fail $ "cli option contains invalid key " ++ show key)
 
                 optParseEntryCtor <$> cliSwitchParser object
@@ -221,15 +223,15 @@ instance JSON.FromJSON cmd => JSON.FromJSON (ConfigValue cmd) where
   parseJSON json  =
     case json of
       JSON.Object object ->
-        case HashMap.lookup "etc/spec" object of
+        case KeyMap.lookup "etc/spec" object of
           -- normal object
           Nothing -> do
             subConfigMap <- foldM
                         (\subConfigMap (key, value) -> do
                             innerValue <- JSON.parseJSON value
-                            return $ HashMap.insert key innerValue subConfigMap)
+                            return $ HashMap.insert (Key.toText key) innerValue subConfigMap)
                         HashMap.empty
-                        (HashMap.toList object)
+                        (KeyMap.toList object)
             if HashMap.null subConfigMap then
               fail "Entries cannot have empty maps as values"
             else
@@ -237,10 +239,10 @@ instance JSON.FromJSON cmd => JSON.FromJSON (ConfigValue cmd) where
 
           -- etc spec value object
           Just (JSON.Object fieldSpec) ->
-            if HashMap.size object == 1 then do
+            if KeyMap.size object == 1 then do
               -- NOTE: not using .:? here as it casts JSON.Null to Nothing, we
               -- want (Just JSON.Null) returned
-              let mDefaultValue = maybe Nothing Just $ HashMap.lookup "default" fieldSpec
+              let mDefaultValue = maybe Nothing Just $ KeyMap.lookup (Key.fromText "default") fieldSpec
               mSensitive    <- fieldSpec .:? "sensitive"
               mCvType       <- fieldSpec .:? "type"
               let sensitive = fromMaybe False mSensitive
diff --git a/etc/src/System/Etc/Spec.hs b/etc/src/System/Etc/Spec.hs
index c430bc2..136c732 100644
--- a/etc/src/System/Etc/Spec.hs
+++ b/etc/src/System/Etc/Spec.hs
@@ -14,8 +14,6 @@ import qualified Data.Text.IO as Text (readFile)
 import           RIO
 import qualified RIO.Text     as Text
 
-import Data.Proxy (Proxy)
-
 import Language.Haskell.TH        (ExpQ)
 import Language.Haskell.TH.Syntax (Lift)
 
diff --git a/examples/etc-command-example/src/Main.hs b/examples/etc-command-example/src/Main.hs
index 87b629a..17626d7 100644
--- a/examples/etc-command-example/src/Main.hs
+++ b/examples/etc-command-example/src/Main.hs
@@ -10,7 +10,6 @@ import qualified RIO.Text as Text
 
 import qualified Data.Aeson       as JSON
 import qualified Data.Aeson.Types as JSON (typeMismatch)
-import           GHC.Generics     (Generic)
 import qualified System.Etc       as Etc
 
 import Paths_etc_command_example (getDataFileName)
diff --git a/stack.yaml b/stack.yaml
index b41d5ad..8f0acdb 100644
--- a/stack.yaml
+++ b/stack.yaml
@@ -15,7 +15,7 @@
 # resolver:
 #  name: custom-snapshot
 #  location: "./custom-snapshot.yaml"
-resolver: lts-12.8
+resolver: lts-20.10
 
 # User packages to be built.
 # Various formats can be used as shown in the example below.
@@ -44,10 +44,10 @@ packages:
 # Dependency packages to be pulled from upstream that are not in the resolver
 # (e.g., acme-missiles-0.3)
 extra-deps:
-  - rio-0.1.2.0
-  - typed-process-0.2.2.0
-  - unliftio-0.2.6.0
-  - unliftio-core-0.1.1.0
+  # - rio-0.1.2.0
+  # - typed-process-0.2.2.0
+  # - unliftio-0.2.6.0
+  # - unliftio-core-0.1.1.0
 
 # Override default flag values for local packages and extra-deps
 flags:

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